From ddd03a050bfaaffef9abd573fe6c8e1af3948048 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 18 Jan 2014 20:58:26 +0000 Subject: Minecart collision and general improvements + Implemented collision on one type of rail * Improved curved rails somewhat * Fixed a crash bug --- src/Entities/Minecart.cpp | 305 +++++++++++++++++++++++++++++++++++----------- src/Entities/Minecart.h | 7 +- 2 files changed, 242 insertions(+), 70 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 7f3fea5ec..ad63f848e 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -19,6 +19,70 @@ +class cMinecartCollisionCallback : + public cEntityCallback +{ +public: + cMinecartCollisionCallback(Vector3d a_Pos, double a_Height, double a_Width, int a_UniqueID, int a_AttacheeUniqueID) : + m_Pos(a_Pos), + m_Height(a_Height), + m_Width(a_Width), + m_DoesInteserct(false), + m_CollidedEntityPos(0, 0, 0), + m_UniqueID(a_UniqueID), + m_AttacheeUniqueID(a_AttacheeUniqueID) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + ASSERT(a_Entity != NULL); + + if (!a_Entity->IsPlayer() && !a_Entity->IsMob() && !a_Entity->IsMinecart() && !a_Entity->IsBoat()) + { + return false; + } + else if ((a_Entity->GetUniqueID() == m_UniqueID) || (a_Entity->GetUniqueID() == m_AttacheeUniqueID)) + { + return false; + } + + cBoundingBox bbEntity(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight()); + cBoundingBox bbMinecart(Vector3d(m_Pos.x, floor(m_Pos.y), m_Pos.z), m_Width / 2, m_Height); + + if (bbEntity.DoesIntersect(bbMinecart)) + { + m_CollidedEntityPos = a_Entity->GetPosition(); + m_DoesInteserct = true; + return true; + } + return false; + } + + bool FoundIntersection(void) const + { + return m_DoesInteserct; + } + + Vector3d GetCollidedEntityPosition(void) const + { + return m_CollidedEntityPos; + } + +protected: + bool m_DoesInteserct; + + Vector3d m_CollidedEntityPos; + + Vector3d m_Pos; + double m_Height, m_Width; + int m_UniqueID; + int m_AttacheeUniqueID; +}; + + + + cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) : super(etMinecart, a_X, a_Y, a_Z, 0.98, 0.7), @@ -30,7 +94,7 @@ cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) : SetMass(20.f); SetMaxHealth(6); SetHealth(6); - SetWidth(1.2); + SetWidth(1); SetHeight(0.9); } @@ -153,7 +217,9 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) SetSpeedY(0); // Don't move vertically as on ground SetSpeedX(0); // Correct diagonal movement from curved rails - if (TestBlockCollision(a_RailMeta)) return; + // Execute both the entity and block collision checks + bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); + if (EntCol || BlckCol) return; if (GetSpeedZ() != 0) // Don't do anything if cart is stationary { @@ -177,7 +243,8 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) SetSpeedY(0); SetSpeedZ(0); - if (TestBlockCollision(a_RailMeta)) return; + bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); + if (EntCol || BlckCol) return; if (GetSpeedX() != 0) { @@ -281,24 +348,11 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) SetRotation(315); // Set correct rotation server side SetPosY(floor(GetPosY()) + 0.55); // Levitate dat cart - if (TestBlockCollision(a_RailMeta)) return; + TestBlockCollision(a_RailMeta); + TestEntityCollision(a_RailMeta); + + // SnapToRail handles turning - if (GetSpeedZ() > 0) // Cart moving south - { - int OldX = (int)floor(GetPosX()); - AddSpeedX(-GetSpeedZ() + 0.5); // See below - AddPosX(-GetSpeedZ() * (a_Dt / 1000)); // Diagonally move southwest (which will make cart hit a southwest rail) - // If we are already at southwest rail, set Z speed to zero as we can be moving so fast, MCS doesn't tick fast enough to active the handle for the rail... - // ...and so we derail unexpectedly. - if (GetPosX() <= OldX - 1) SetSpeedZ(0); - } - else if (GetSpeedX() > 0) // Cart moving east - { - int OldZ = (int)floor(GetPosZ()); - AddSpeedZ(-GetSpeedX() + 0.5); - AddPosZ(-GetSpeedX() * (a_Dt / 1000)); // Diagonally move northeast - if (GetPosZ() <= OldZ - 1) SetSpeedX(0); - } break; } case E_META_RAIL_CURVED_ZM_XP: // Curved NORTH EAST @@ -306,22 +360,9 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) SetRotation(225); SetPosY(floor(GetPosY()) + 0.55); - if (TestBlockCollision(a_RailMeta)) return; + TestBlockCollision(a_RailMeta); + TestEntityCollision(a_RailMeta); - if (GetSpeedZ() > 0) - { - int OldX = (int)floor(GetPosX()); - AddSpeedX(GetSpeedZ() - 0.5); - AddPosX(GetSpeedZ() * (a_Dt / 1000)); - if (GetPosX() >= OldX + 1) SetSpeedZ(0); - } - else if (GetSpeedX() < 0) - { - int OldZ = (int)floor(GetPosZ()); - AddSpeedZ(GetSpeedX() + 0.5); - AddPosZ(GetSpeedX() * (a_Dt / 1000)); - if (GetPosZ() <= OldZ - 1) SetSpeedX(0); - } break; } case E_META_RAIL_CURVED_ZP_XM: // Curved SOUTH WEST @@ -329,22 +370,9 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) SetRotation(135); SetPosY(floor(GetPosY()) + 0.55); - if (TestBlockCollision(a_RailMeta)) return; + TestBlockCollision(a_RailMeta); + TestEntityCollision(a_RailMeta); - if (GetSpeedZ() < 0) - { - int OldX = (int)floor(GetPosX()); - AddSpeedX(GetSpeedZ() + 0.5); - AddPosX(GetSpeedZ() * (a_Dt / 1000)); - if (GetPosX() <= OldX - 1) SetSpeedZ(0); - } - else if (GetSpeedX() > 0) - { - int OldZ = (int)floor(GetPosZ()); - AddSpeedZ(GetSpeedX() - 0.5); - AddPosZ(GetSpeedX() * (a_Dt / 1000)); - if (GetPosZ() >= OldZ + 1) SetSpeedX(0); - } break; } case E_META_RAIL_CURVED_ZP_XP: // Curved SOUTH EAST @@ -352,22 +380,9 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) SetRotation(45); SetPosY(floor(GetPosY()) + 0.55); - if (TestBlockCollision(a_RailMeta)) return; + TestBlockCollision(a_RailMeta); + TestEntityCollision(a_RailMeta); - if (GetSpeedZ() < 0) - { - int OldX = (int)floor(GetPosX()); - AddSpeedX(-GetSpeedZ() - 0.5); - AddPosX(-GetSpeedZ() * (a_Dt / 1000)); - if (GetPosX() >= OldX + 1) SetSpeedZ(0); - } - else if (GetSpeedX() < 0) - { - int OldZ = (int)floor(GetPosZ()); - AddSpeedZ(-GetSpeedX() - 0.5); - AddPosZ(-GetSpeedX() * (a_Dt / 1000)); - if (GetPosZ() >= OldZ + 1) SetSpeedX(0); - } break; } default: @@ -481,6 +496,102 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) SetPosX(floor(GetPosX()) + 0.5); break; } + case E_META_RAIL_CURVED_ZM_XM: + { + if (GetPosZ() < floor(GetPosZ()) + 0.5) + { + if (GetSpeedX() > 0) + { + SetSpeedZ(-GetSpeedX() * 0.7); + } + + SetSpeedX(0); + SetPosX(floor(GetPosX()) + 0.5); + } + else + { + if (GetSpeedZ() > 0) + { + SetSpeedX(-GetSpeedZ() * 0.7); + } + + SetSpeedZ(0); + SetPosZ(floor(GetPosZ()) + 0.5); + } + break; + } + case E_META_RAIL_CURVED_ZM_XP: + { + if (GetPosZ() < floor(GetPosZ()) + 0.5) + { + if (GetSpeedX() < 0) + { + SetSpeedZ(GetSpeedX() * 0.7); + } + + SetSpeedX(0); + SetPosX(floor(GetPosX()) + 0.5); + } + else + { + if (GetSpeedZ() > 0) + { + SetSpeedX(GetSpeedZ() * 0.7); + } + + SetSpeedZ(0); + SetPosZ(floor(GetPosZ()) + 0.5); + } + break; + } + case E_META_RAIL_CURVED_ZP_XM: + { + if (GetPosZ() < floor(GetPosZ()) + 0.5) + { + if (GetSpeedZ() < 0) + { + SetSpeedX(GetSpeedZ() * 0.7); + } + + SetSpeedZ(0); + SetPosZ(floor(GetPosZ()) + 0.5); + } + else + { + if (GetSpeedX() > 0) + { + SetSpeedZ(GetSpeedX() * 0.7); + } + + SetSpeedX(0); + SetPosX(floor(GetPosX()) + 0.5); + } + break; + } + case E_META_RAIL_CURVED_ZP_XP: + { + if (GetPosZ() < floor(GetPosZ()) + 0.5) + { + if (GetSpeedZ() < 0) + { + SetSpeedX(-GetSpeedZ() * 0.7); + } + + SetSpeedZ(0); + SetPosZ(floor(GetPosZ()) + 0.5); + } + else + { + if (GetSpeedX() < 0) + { + SetSpeedZ(-GetSpeedX() * 0.7); + } + + SetSpeedX(0); + SetPosX(floor(GetPosX()) + 0.5); + } + break; + } default: break; } } @@ -512,7 +623,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) } } } - else + else if (GetSpeedZ() < 0) { BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1); if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) @@ -548,7 +659,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) } } } - else + else if (GetSpeedX() < 0) { BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) @@ -596,10 +707,68 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) +bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) +{ + switch (a_RailMeta) + { + case E_META_RAIL_ZM_ZP: + { + cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == NULL) ? -1 : m_Attachee->GetUniqueID())); + m_World->ForEachEntity(MinecartCollisionCallback); + + if (MinecartCollisionCallback.FoundIntersection()) + { + if (MinecartCollisionCallback.GetCollidedEntityPosition().z >= GetPosZ()) + { + if (((-GetSpeedZ()) * 0.4) < 0.01) + { + AddSpeedZ(-4); + } + else + { + SetSpeedZ((-GetSpeedZ()) * 0.4); + } + } + else + { + if ((GetSpeedZ() * 0.4) < 0.01) + { + AddSpeedZ(4); + } + else + { + SetSpeedZ(GetSpeedZ() * 0.4); + } + } + return true; + } + break; + } + case E_META_RAIL_XM_XP: + { + + break; + } + case E_META_RAIL_CURVED_ZM_XM: + case E_META_RAIL_CURVED_ZM_XP: + case E_META_RAIL_CURVED_ZP_XM: + case E_META_RAIL_CURVED_ZP_XP: + { + + break; + } + default: break; + } + return false; +} + + + + void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) { - if (TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative()) + if ((TDI.Attacker != NULL) && TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative()) { Destroy(); TDI.FinalDamage = GetMaxHealth(); // Instant hit for creative diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index 1ebddfdda..1c3ea3220 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -79,10 +79,13 @@ protected: */ void HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt); - /** Snaps a minecart to a rail's axis, resetting its speed */ + /** Snaps a mincecart to a rail's axis, resetting its speed + For curved rails, it changes the cart's direction as well as snapping it to axis */ void SnapToRail(NIBBLETYPE a_RailMeta); - /** Tests is a solid block is in front of a cart, and stops the cart (and returns true) if so; returns false if no obstruction*/ + /** Tests if a solid block is in front of a cart, and stops the cart (and returns true) if so; returns false if no obstruction */ bool TestBlockCollision(NIBBLETYPE a_RailMeta); + /** Tests if this mincecart's bounding box is intersecting another entity's bounding box (collision) and pushes mincecart away */ + bool TestEntityCollision(NIBBLETYPE a_RailMeta); } ; -- cgit v1.2.3 From 2b943610598c193a349107fd9345d321724aff98 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 19 Jan 2014 14:20:57 +0200 Subject: Basic scoreboard implementation --- src/Entities/Player.cpp | 52 +++++++++ src/Entities/Player.h | 11 +- src/Scoreboard.cpp | 301 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Scoreboard.h | 207 +++++++++++++++++++++++++++++++++ src/World.h | 6 + 5 files changed, 576 insertions(+), 1 deletion(-) create mode 100644 src/Scoreboard.cpp create mode 100644 src/Scoreboard.h diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c1f2456eb..4f3c6138b 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -74,6 +74,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_IsChargingBow(false) , m_BowCharge(0) , m_FloaterID(-1) + , m_Team(NULL) { LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d", a_PlayerName.c_str(), a_Client->GetIPString().c_str(), @@ -790,6 +791,20 @@ void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) return; } } + + if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) + { + cPlayer* Attacker = (cPlayer*) a_TDI.Attacker; + + if ((m_Team != NULL) && (m_Team == Attacker->m_Team)) + { + if (!m_Team->GetFriendlyFire()) + { + // Friendly fire is disabled + return; + } + } + } super::DoTakeDamage(a_TDI); @@ -836,6 +851,24 @@ void cPlayer::KilledBy(cEntity * a_Killer) GetWorld()->BroadcastChat(Printf("%s[DEATH] %s%s was killed by a %s", cChatColor::Red.c_str(), cChatColor::White.c_str(), GetName().c_str(), KillerClass.c_str())); } + + class cIncrementCounterCB + : public cObjectiveCallback + { + AString m_Name; + public: + cIncrementCounterCB(const AString & a_Name) : m_Name(a_Name) {} + + virtual bool Item(cObjective * a_Objective) override + { + a_Objective->AddScore(m_Name, 1); + } + } IncrementCounter (GetName()); + + cScoreboard* Scoreboard = m_World->GetScoreBoard(); + + // Update scoreboard objectives + Scoreboard->ForEachObjectiveWith(E_OBJECTIVE_DEATH_COUNT, IncrementCounter); } @@ -916,6 +949,25 @@ bool cPlayer::IsGameModeAdventure(void) const +void cPlayer::SetTeam(cTeam* a_Team) +{ + if (m_Team) + { + m_Team->RemovePlayer(this); + } + + m_Team = a_Team; + + if (m_Team) + { + m_Team->AddPlayer(this); + } +} + + + + + void cPlayer::OpenWindow(cWindow * a_Window) { if (a_Window != m_CurrentWindow) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index bf3ca08e8..52e629dc3 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -13,6 +13,7 @@ class cGroup; class cWindow; class cClientHandle; +class cTeam; @@ -153,6 +154,12 @@ public: AString GetIP(void) const { return m_IP; } // tolua_export + /// Returns the associated team, NULL if none + cTeam* GetTeam(void) { return m_Team; } // tolua_export + + /// Sets the player team, NULL if none + void SetTeam(cTeam* a_Team); + // tolua_end void SetIP(const AString & a_IP); @@ -456,6 +463,8 @@ protected: int m_FloaterID; + cTeam* m_Team; + void ResolvePermissions(void); @@ -463,7 +472,7 @@ protected: virtual void Destroyed(void); - /// Filters out damage for creative mode + /// Filters out damage for creative mode/friendly fire virtual void DoTakeDamage(TakeDamageInfo & TDI) override; /// Called in each tick to handle food-related processing diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp new file mode 100644 index 000000000..1d2711ca0 --- /dev/null +++ b/src/Scoreboard.cpp @@ -0,0 +1,301 @@ + +// Scoreboard.cpp + +// Implementation of a scoreboard that keeps track of specified objectives + +#include "Globals.h" + +#include "Scoreboard.h" + + + + + +cObjective::cObjective(eObjectiveType a_Type) : m_Type(a_Type) +{} + + + + + +void cObjective::SetDisplaySlot(eDisplaySlot a_Display) +{ + m_Display = a_Display; +} + + + + + +void cObjective::Reset(void) +{ + m_Scores.clear(); +} + + + + + +cObjective::Score cObjective::GetScore(const AString & a_Name) const +{ + ScoreMap::const_iterator it = m_Scores.find(a_Name); + + if (it == m_Scores.end()) + { + return 0; + } + else + { + return it->second; + } +} + + + + + +void cObjective::SetScore(const AString & a_Name, cObjective::Score a_Score) +{ + m_Scores[a_Name] = a_Score; +} + + + + + +void cObjective::ResetScore(const AString & a_Name) +{ + m_Scores.erase(a_Name); +} + + + + + +cObjective::Score cObjective::AddScore(const AString & a_Name, cObjective::Score a_Delta) +{ + // TODO 2014-01-19 xdot: Potential optimization - Reuse iterator + Score NewScore = m_Scores[a_Name] + a_Delta; + + m_Scores[a_Name] = NewScore; + + return NewScore; +} + + + + + +cObjective::Score cObjective::SubScore(const AString & a_Name, cObjective::Score a_Delta) +{ + // TODO 2014-01-19 xdot: Potential optimization - Reuse iterator + Score NewScore = m_Scores[a_Name] - a_Delta; + + m_Scores[a_Name] = NewScore; + + return NewScore; +} + + + + + +cTeam::cTeam(const AString & a_Name, const AString & a_DisplayName, + const AString & a_Prefix, const AString & a_Suffix) + : m_FriendlyFire(true) + , m_SeeFriendlyInvisible(false) + , m_Name(a_Name) + , m_DisplayName(a_DisplayName) + , m_Prefix(a_Prefix) + , m_Suffix(a_Suffix) +{} + + + + + +bool cTeam::AddPlayer(cPlayer * a_Player) +{ + return m_Players.insert(a_Player).second; +} + + + + + +bool cTeam::RemovePlayer(cPlayer * a_Player) +{ + return m_Players.erase(a_Player) > 0; +} + + + + + +void cTeam::Reset(void) +{ + m_Players.clear(); +} + + + + +unsigned int cTeam::GetNumPlayers(void) const +{ + return m_Players.size(); +} + + + + + +cScoreboard::~cScoreboard() +{ + for (ObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it) + { + delete it->second; + } + + for (TeamMap::iterator it = m_Teams.begin(); it != m_Teams.end(); ++it) + { + delete it->second; + } +} + + + + + +cObjective* cScoreboard::RegisterObjective(const AString & a_Name, eObjectiveType a_Type) +{ + cObjective* Objective = new cObjective(a_Type); + + bool Status = m_Objectives.insert(NamedObjective(a_Name, Objective)).second; + + if (Status) + { + return Objective; + } + else + { + delete Objective; + return NULL; + } +} + + + + + +bool cScoreboard::RemoveObjective(const AString & a_Name) +{ + ObjectiveMap::iterator it = m_Objectives.find(a_Name); + + if (it == m_Objectives.end()) + { + return false; + } + + m_Objectives.erase(it); + + return true; +} + + + + + +cObjective* cScoreboard::GetObjective(const AString & a_Name) +{ + ObjectiveMap::iterator it = m_Objectives.find(a_Name); + + if (it == m_Objectives.end()) + { + return NULL; + } + else + { + return it->second; + } +} + + + + + +cTeam* cScoreboard::RegisterTeam(const AString & a_Name, const AString & a_DisplayName, + const AString & a_Prefix, const AString & a_Suffix) +{ + cTeam* Team = new cTeam(a_Name, a_DisplayName, a_Prefix, a_Suffix); + + bool Status = m_Teams.insert(NamedTeam(a_Name, Team)).second; + + if (Status) + { + return Team; + } + else + { + delete Team; + return NULL; + } +} + + + + + +bool cScoreboard::RemoveTeam(const AString & a_Name) +{ + TeamMap::iterator it = m_Teams.find(a_Name); + + if (it == m_Teams.end()) + { + return false; + } + + m_Teams.erase(it); + + return true; +} + + + + + +cTeam* cScoreboard::GetTeam(const AString & a_Name) +{ + TeamMap::iterator it = m_Teams.find(a_Name); + + if (it == m_Teams.end()) + { + return NULL; + } + else + { + return it->second; + } +} + + + + + +void cScoreboard::ForEachObjectiveWith(eObjectiveType a_Type, cObjectiveCallback& a_Callback) +{ + for (ObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it) + { + if (it->second->GetType() == a_Type) + { + // Call callback + if (a_Callback.Item(it->second)) + { + return; + } + } + } +} + + + + diff --git a/src/Scoreboard.h b/src/Scoreboard.h new file mode 100644 index 000000000..8ab298a07 --- /dev/null +++ b/src/Scoreboard.h @@ -0,0 +1,207 @@ + +// Scoreboard.h + +// Implementation of a scoreboard that keeps track of specified objectives + + + + + +#pragma once + + + + + +class cPlayer; +class cObjective; + +typedef std::set< cPlayer * > cPlayerSet; +typedef cItemCallback cObjectiveCallback; + + + + + +enum eObjectiveType +{ + E_OBJECTIVE_DUMMY, + + E_OBJECTIVE_DEATH_COUNT, + E_OBJECTIVE_PLAYER_KILL_COUNT, + E_OBJECTIVE_TOTAL_KILL_COUNT, + E_OBJECTIVE_HEALTH, + + E_OBJECTIVE_ACHIEVEMENT, + + E_OBJECTIVE_STAT, + E_OBJECTIVE_STAT_ITEM_CRAFT, + E_OBJECTIVE_STAT_ITEM_USE, + E_OBJECTIVE_STAT_ITEM_BREAK, + + E_OBJECTIVE_STAT_BLOCK_MINE, + E_OBJECTIVE_STAT_ENTITY_KILL, + E_OBJECTIVE_STAT_ENTITY_KILLED_BY +}; + + + + + +enum eDisplaySlot +{ + E_DISPLAY_SLOT_LIST, + E_DISPLAY_SLOT_SIDEBAR, + E_DISPLAY_SLOT_NAME +}; + + + + + +class cObjective +{ +public: + typedef int Score; + +public: + cObjective(eObjectiveType a_Type); + + eObjectiveType GetType(void) const { return m_Type; } + + eDisplaySlot GetDisplaySlot(void) const { return m_Display; } + + void SetDisplaySlot(eDisplaySlot a_Display); + + /// Resets the objective + void Reset(void); + + /// Returns the score of the specified player + Score GetScore(const AString & a_Name) const; + + /// Sets the score of the specified player + void SetScore(const AString & a_Name, Score a_Score); + + /// Resets the score of the specified player + void ResetScore(const AString & a_Name); + + /// Adds a_Delta and returns the new score + Score AddScore(const AString & a_Name, Score a_Delta); + + /// Subtracts a_Delta and returns the new score + Score SubScore(const AString & a_Name, Score a_Delta); + +private: + typedef std::pair TrackedPlayer; + + typedef std::map ScoreMap; + + ScoreMap m_Scores; + + eObjectiveType m_Type; + + eDisplaySlot m_Display; +}; + + + + + +class cTeam +{ +public: + cTeam(const AString & a_Name, const AString & a_DisplayName, + const AString & a_Prefix, const AString & a_Suffix); + + /// Adds a new player to the team + bool AddPlayer(cPlayer * a_Player); + + /// Removes a player from the team + bool RemovePlayer(cPlayer * a_Player); + + /// Removes all registered players + void Reset(void); + + /// Returns the number of registered players + unsigned int GetNumPlayers(void) const; + + bool GetFriendlyFire(void) const { return m_FriendlyFire; } + bool GetCanSeeFriendlyInvisible(void) const { return m_SeeFriendlyInvisible; } + + const AString & GetDisplayName(void) const { return m_Name; } + const AString & GetName(void) const { return m_DisplayName; } + + const AString & GetPrefix(void) const { return m_Prefix; } + const AString & GetSuffix(void) const { return m_Suffix; } + + void SetFriendlyFire(bool a_Flag); + void SetCanSeeFriendlyInvisible(bool a_Flag); + + void SetDisplayName(const AString & a_Name); + + void SetPrefix(const AString & a_Prefix); + void SetSuffix(const AString & a_Suffix); + +private: + + bool m_FriendlyFire; + bool m_SeeFriendlyInvisible; + + AString m_DisplayName; + AString m_Name; + + AString m_Prefix; + AString m_Suffix; + + // TODO 2014-01-19 xdot: Potential optimization - vector/list + cPlayerSet m_Players; +}; + + + + + +class cScoreboard +{ +public: + cScoreboard() {} + virtual ~cScoreboard(); + + /// Registers a new scoreboard objective, returns the cObjective instance + cObjective* RegisterObjective(const AString & a_Name, eObjectiveType a_Type); + + /// Removes a registered objective, returns true if operation was successful + bool RemoveObjective(const AString & a_Name); + + /// Retrieves the objective with the specified name, NULL if not found + cObjective* GetObjective(const AString & a_Name); + + /// Registers a new team, returns the cTeam instance + cTeam* RegisterTeam(const AString & a_Name, const AString & a_DisplayName, + const AString & a_Prefix, const AString & a_Suffix); + + /// Removes a registered team, returns true if operation was successful + bool RemoveTeam(const AString & a_Name); + + /// Retrieves the team with the specified name, NULL if not found + cTeam* GetTeam(const AString & a_Name); + + /// Execute callback for each objective with the specified type + void ForEachObjectiveWith(eObjectiveType a_Type, cObjectiveCallback& a_Callback); + +private: + typedef std::pair NamedObjective; + typedef std::pair NamedTeam; + + typedef std::map ObjectiveMap; + typedef std::map TeamMap; + + // TODO 2014-01-19 xdot: Potential optimization - Sort objectives based on type + ObjectiveMap m_Objectives; + + TeamMap m_Teams; +} ; + + + + diff --git a/src/World.h b/src/World.h index 1a7ad0cb1..1dcbac8e4 100644 --- a/src/World.h +++ b/src/World.h @@ -22,6 +22,7 @@ #include "Item.h" #include "Mobs/Monster.h" #include "Entities/ProjectileEntity.h" +#include "Scoreboard.h" @@ -513,6 +514,9 @@ public: /// Returns the name of the world.ini file used by this world const AString & GetIniFileName(void) const {return m_IniFileName; } + + /// Returns the associated scoreboard instance + cScoreboard* GetScoreBoard(void) { return &m_Scoreboard; } // tolua_end @@ -757,6 +761,8 @@ private: sSetBlockList m_FastSetBlockQueue; cChunkGenerator m_Generator; + + cScoreboard m_Scoreboard; /** The callbacks that the ChunkGenerator uses to store new chunks and interface to plugins */ cChunkGeneratorCallbacks m_GeneratorCallbacks; -- cgit v1.2.3 From f321b5d224cb4a6d562cfb32850bf752ddd69f61 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 19 Jan 2014 16:02:37 +0200 Subject: Scoreboard improvements --- src/Entities/Player.cpp | 8 ++-- src/Scoreboard.cpp | 79 +++++++++++------------------------ src/Scoreboard.h | 108 +++++++++++++++++++++++------------------------- 3 files changed, 79 insertions(+), 116 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 4f3c6138b..d2fdba909 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -798,7 +798,7 @@ void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) if ((m_Team != NULL) && (m_Team == Attacker->m_Team)) { - if (!m_Team->GetFriendlyFire()) + if (!m_Team->AllowsFriendlyFire()) { // Friendly fire is disabled return; @@ -868,7 +868,7 @@ void cPlayer::KilledBy(cEntity * a_Killer) cScoreboard* Scoreboard = m_World->GetScoreBoard(); // Update scoreboard objectives - Scoreboard->ForEachObjectiveWith(E_OBJECTIVE_DEATH_COUNT, IncrementCounter); + Scoreboard->ForEachObjectiveWith(cObjective::E_TYPE_DEATH_COUNT, IncrementCounter); } @@ -953,14 +953,14 @@ void cPlayer::SetTeam(cTeam* a_Team) { if (m_Team) { - m_Team->RemovePlayer(this); + m_Team->RemovePlayer(GetName()); } m_Team = a_Team; if (m_Team) { - m_Team->AddPlayer(this); + m_Team->AddPlayer(GetName()); } } diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 1d2711ca0..539316356 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -11,14 +11,14 @@ -cObjective::cObjective(eObjectiveType a_Type) : m_Type(a_Type) +cObjective::cObjective(cObjective::eType a_Type) : m_Type(a_Type) {} -void cObjective::SetDisplaySlot(eDisplaySlot a_Display) +void cObjective::SetDisplaySlot(cObjective::eDisplaySlot a_Display) { m_Display = a_Display; } @@ -102,8 +102,8 @@ cObjective::Score cObjective::SubScore(const AString & a_Name, cObjective::Score cTeam::cTeam(const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix) - : m_FriendlyFire(true) - , m_SeeFriendlyInvisible(false) + : m_AllowsFriendlyFire(true) + , m_CanSeeFriendlyInvisible(false) , m_Name(a_Name) , m_DisplayName(a_DisplayName) , m_Prefix(a_Prefix) @@ -114,18 +114,18 @@ cTeam::cTeam(const AString & a_Name, const AString & a_DisplayName, -bool cTeam::AddPlayer(cPlayer * a_Player) +bool cTeam::AddPlayer(const AString & a_Name) { - return m_Players.insert(a_Player).second; + return m_Players.insert(a_Name).second; } -bool cTeam::RemovePlayer(cPlayer * a_Player) +bool cTeam::RemovePlayer(const AString & a_Name) { - return m_Players.erase(a_Player) > 0; + return m_Players.erase(a_Name) > 0; } @@ -149,38 +149,13 @@ unsigned int cTeam::GetNumPlayers(void) const -cScoreboard::~cScoreboard() +cObjective* cScoreboard::RegisterObjective(const AString & a_Name, cObjective::eType a_Type) { - for (ObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it) - { - delete it->second; - } - - for (TeamMap::iterator it = m_Teams.begin(); it != m_Teams.end(); ++it) - { - delete it->second; - } -} + cObjective Objective(a_Type); + std::pair Status = m_Objectives.insert(NamedObjective(a_Name, Objective)); - - - -cObjective* cScoreboard::RegisterObjective(const AString & a_Name, eObjectiveType a_Type) -{ - cObjective* Objective = new cObjective(a_Type); - - bool Status = m_Objectives.insert(NamedObjective(a_Name, Objective)).second; - - if (Status) - { - return Objective; - } - else - { - delete Objective; - return NULL; - } + return Status.second ? &Status.first->second : NULL; } @@ -215,7 +190,7 @@ cObjective* cScoreboard::GetObjective(const AString & a_Name) } else { - return it->second; + return &it->second; } } @@ -223,22 +198,16 @@ cObjective* cScoreboard::GetObjective(const AString & a_Name) -cTeam* cScoreboard::RegisterTeam(const AString & a_Name, const AString & a_DisplayName, - const AString & a_Prefix, const AString & a_Suffix) +cTeam* cScoreboard::RegisterTeam( + const AString & a_Name, const AString & a_DisplayName, + const AString & a_Prefix, const AString & a_Suffix +) { - cTeam* Team = new cTeam(a_Name, a_DisplayName, a_Prefix, a_Suffix); + cTeam Team(a_Name, a_DisplayName, a_Prefix, a_Suffix); - bool Status = m_Teams.insert(NamedTeam(a_Name, Team)).second; + std::pair Status = m_Teams.insert(NamedTeam(a_Name, Team)); - if (Status) - { - return Team; - } - else - { - delete Team; - return NULL; - } + return Status.second ? &Status.first->second : NULL; } @@ -273,7 +242,7 @@ cTeam* cScoreboard::GetTeam(const AString & a_Name) } else { - return it->second; + return &it->second; } } @@ -281,14 +250,14 @@ cTeam* cScoreboard::GetTeam(const AString & a_Name) -void cScoreboard::ForEachObjectiveWith(eObjectiveType a_Type, cObjectiveCallback& a_Callback) +void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback) { for (ObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it) { - if (it->second->GetType() == a_Type) + if (it->second.GetType() == a_Type) { // Call callback - if (a_Callback.Item(it->second)) + if (a_Callback.Item(&it->second)) { return; } diff --git a/src/Scoreboard.h b/src/Scoreboard.h index 8ab298a07..7993b1333 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -13,61 +13,51 @@ -class cPlayer; class cObjective; -typedef std::set< cPlayer * > cPlayerSet; typedef cItemCallback cObjectiveCallback; -enum eObjectiveType +class cObjective { - E_OBJECTIVE_DUMMY, - - E_OBJECTIVE_DEATH_COUNT, - E_OBJECTIVE_PLAYER_KILL_COUNT, - E_OBJECTIVE_TOTAL_KILL_COUNT, - E_OBJECTIVE_HEALTH, - - E_OBJECTIVE_ACHIEVEMENT, - - E_OBJECTIVE_STAT, - E_OBJECTIVE_STAT_ITEM_CRAFT, - E_OBJECTIVE_STAT_ITEM_USE, - E_OBJECTIVE_STAT_ITEM_BREAK, - - E_OBJECTIVE_STAT_BLOCK_MINE, - E_OBJECTIVE_STAT_ENTITY_KILL, - E_OBJECTIVE_STAT_ENTITY_KILLED_BY -}; - - - - +public: + typedef int Score; -enum eDisplaySlot -{ - E_DISPLAY_SLOT_LIST, - E_DISPLAY_SLOT_SIDEBAR, - E_DISPLAY_SLOT_NAME -}; + enum eType + { + E_TYPE_DUMMY, + E_TYPE_DEATH_COUNT, + E_TYPE_PLAYER_KILL_COUNT, + E_TYPE_TOTAL_KILL_COUNT, + E_TYPE_HEALTH, + E_TYPE_ACHIEVEMENT, + E_TYPE_STAT, + E_TYPE_STAT_ITEM_CRAFT, + E_TYPE_STAT_ITEM_USE, + E_TYPE_STAT_ITEM_BREAK, + E_TYPE_STAT_BLOCK_MINE, + E_TYPE_STAT_ENTITY_KILL, + E_TYPE_STAT_ENTITY_KILLED_BY + }; -class cObjective -{ -public: - typedef int Score; + enum eDisplaySlot + { + E_DISPLAY_SLOT_LIST, + E_DISPLAY_SLOT_SIDEBAR, + E_DISPLAY_SLOT_NAME + }; public: - cObjective(eObjectiveType a_Type); + cObjective(eType a_Type); - eObjectiveType GetType(void) const { return m_Type; } + eType GetType(void) const { return m_Type; } eDisplaySlot GetDisplaySlot(void) const { return m_Display; } @@ -98,7 +88,7 @@ private: ScoreMap m_Scores; - eObjectiveType m_Type; + eType m_Type; eDisplaySlot m_Display; }; @@ -110,14 +100,17 @@ private: class cTeam { public: - cTeam(const AString & a_Name, const AString & a_DisplayName, - const AString & a_Prefix, const AString & a_Suffix); + + cTeam( + const AString & a_Name, const AString & a_DisplayName, + const AString & a_Prefix, const AString & a_Suffix + ); /// Adds a new player to the team - bool AddPlayer(cPlayer * a_Player); + bool AddPlayer(const AString & a_Name); /// Removes a player from the team - bool RemovePlayer(cPlayer * a_Player); + bool RemovePlayer(const AString & a_Name); /// Removes all registered players void Reset(void); @@ -125,10 +118,10 @@ public: /// Returns the number of registered players unsigned int GetNumPlayers(void) const; - bool GetFriendlyFire(void) const { return m_FriendlyFire; } - bool GetCanSeeFriendlyInvisible(void) const { return m_SeeFriendlyInvisible; } + bool AllowsFriendlyFire(void) const { return m_AllowsFriendlyFire; } + bool CanSeeFriendlyInvisible(void) const { return m_CanSeeFriendlyInvisible; } - const AString & GetDisplayName(void) const { return m_Name; } + const AString & GetDisplayName(void) const { return m_DisplayName; } const AString & GetName(void) const { return m_DisplayName; } const AString & GetPrefix(void) const { return m_Prefix; } @@ -144,8 +137,8 @@ public: private: - bool m_FriendlyFire; - bool m_SeeFriendlyInvisible; + bool m_AllowsFriendlyFire; + bool m_CanSeeFriendlyInvisible; AString m_DisplayName; AString m_Name; @@ -154,7 +147,9 @@ private: AString m_Suffix; // TODO 2014-01-19 xdot: Potential optimization - vector/list - cPlayerSet m_Players; + typedef std::set PlayerNameSet; + + PlayerNameSet m_Players; }; @@ -165,10 +160,9 @@ class cScoreboard { public: cScoreboard() {} - virtual ~cScoreboard(); - /// Registers a new scoreboard objective, returns the cObjective instance - cObjective* RegisterObjective(const AString & a_Name, eObjectiveType a_Type); + /// Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision + cObjective* RegisterObjective(const AString & a_Name, cObjective::eType a_Type); /// Removes a registered objective, returns true if operation was successful bool RemoveObjective(const AString & a_Name); @@ -176,7 +170,7 @@ public: /// Retrieves the objective with the specified name, NULL if not found cObjective* GetObjective(const AString & a_Name); - /// Registers a new team, returns the cTeam instance + /// Registers a new team, returns the cTeam instance, NULL on name collision cTeam* RegisterTeam(const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix); @@ -187,14 +181,14 @@ public: cTeam* GetTeam(const AString & a_Name); /// Execute callback for each objective with the specified type - void ForEachObjectiveWith(eObjectiveType a_Type, cObjectiveCallback& a_Callback); + void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback); private: - typedef std::pair NamedObjective; - typedef std::pair NamedTeam; + typedef std::pair NamedObjective; + typedef std::pair NamedTeam; - typedef std::map ObjectiveMap; - typedef std::map TeamMap; + typedef std::map ObjectiveMap; + typedef std::map TeamMap; // TODO 2014-01-19 xdot: Potential optimization - Sort objectives based on type ObjectiveMap m_Objectives; -- cgit v1.2.3 From 8467f5dfaea596a0b7e294cf1b7dce224c41d7b9 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Jan 2014 14:52:45 +0000 Subject: Added more rail functionality --- src/Blocks/BlockRail.h | 8 ++++---- src/Defines.h | 18 ++++++++++++++++++ src/Entities/Minecart.h | 14 -------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 55cadfa48..f13e987b7 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -204,7 +204,7 @@ public: bool IsUnstable(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) { - if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_RAIL) + if (!IsBlockRail(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ))) { return false; } @@ -339,11 +339,11 @@ public: { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, false); NIBBLETYPE Meta; - if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_RAIL) + if (!IsBlockRail(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ))) { - if ((a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ) != E_BLOCK_RAIL) || (a_Pure != E_PURE_UPDOWN)) + if (!IsBlockRail(a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)) || (a_Pure != E_PURE_UPDOWN)) { - if ((a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) != E_BLOCK_RAIL) || (a_Pure == E_PURE_NONE)) + if (!IsBlockRail(a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ)) || (a_Pure == E_PURE_NONE)) { return true; } diff --git a/src/Defines.h b/src/Defines.h index 7a86f499e..298180fb1 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -282,6 +282,24 @@ inline bool IsBlockLiquid(BLOCKTYPE a_BlockType) +inline bool IsBlockRail(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_RAIL: + case E_BLOCK_ACTIVATOR_RAIL: + case E_BLOCK_DETECTOR_RAIL: + case E_BLOCK_POWERED_RAIL: + { + return true; + } + default: return false; + } +} + + + + inline bool IsBlockTypeOfDirt(BLOCKTYPE a_BlockType) { diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index a4ecb33ad..87f785538 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -15,20 +15,6 @@ -inline bool IsBlockRail(BLOCKTYPE a_BlockType) - { - return ( - (a_BlockType == E_BLOCK_RAIL) || - (a_BlockType == E_BLOCK_ACTIVATOR_RAIL) || - (a_BlockType == E_BLOCK_DETECTOR_RAIL) || - (a_BlockType == E_BLOCK_POWERED_RAIL) - ) ; - } - - - - - class cMinecart : public cEntity { -- cgit v1.2.3 From fc622ce1940c392dd5a049b8bd1c3017927894dd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Jan 2014 18:24:56 +0000 Subject: Fixed weird meta with curved rails --- src/Blocks/BlockRail.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index f13e987b7..da3783d08 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -186,22 +186,32 @@ public: } if (RailsCnt > 1) { - if (Neighbors[3] && Neighbors[0]) return E_META_RAIL_CURVED_ZP_XP; - else if (Neighbors[3] && Neighbors[1]) return E_META_RAIL_CURVED_ZP_XM; - else if (Neighbors[2] && Neighbors[0]) return E_META_RAIL_CURVED_ZM_XP; - else if (Neighbors[2] && Neighbors[1]) return E_META_RAIL_CURVED_ZM_XM; + if (Neighbors[3] && Neighbors[0] && CanThisRailCurve()) return E_META_RAIL_CURVED_ZP_XP; + else if (Neighbors[3] && Neighbors[1] && CanThisRailCurve()) return E_META_RAIL_CURVED_ZP_XM; + else if (Neighbors[2] && Neighbors[0] && CanThisRailCurve()) return E_META_RAIL_CURVED_ZM_XP; + else if (Neighbors[2] && Neighbors[1] && CanThisRailCurve()) return E_META_RAIL_CURVED_ZM_XM; else if (Neighbors[7] && Neighbors[2]) return E_META_RAIL_ASCEND_ZP; else if (Neighbors[3] && Neighbors[6]) return E_META_RAIL_ASCEND_ZM; else if (Neighbors[5] && Neighbors[0]) return E_META_RAIL_ASCEND_XM; else if (Neighbors[4] && Neighbors[1]) return E_META_RAIL_ASCEND_XP; else if (Neighbors[0] && Neighbors[1]) return E_META_RAIL_XM_XP; else if (Neighbors[2] && Neighbors[3]) return E_META_RAIL_ZM_ZP; - ASSERT(!"Weird neighbor count"); + + if (CanThisRailCurve()) + { + ASSERT(!"Weird neighbor count"); + } } return Meta; } + inline bool CanThisRailCurve(void) + { + return m_BlockType == E_BLOCK_RAIL; + } + + bool IsUnstable(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) { if (!IsBlockRail(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ))) -- cgit v1.2.3 From 9a580146e43cc5cf6c84455b75976020467da32f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Jan 2014 18:27:06 +0000 Subject: Minecart improvements and fixes * Fixed curved rails * Fixed detector rails in certain situations * Fixed powered rails and others passing bad meta to SnapToRail() --- src/Entities/Minecart.cpp | 76 +++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index c8f43a3e6..643eefb39 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -160,10 +160,17 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) if (IsBlockRail(InsideType)) AddPosY(1); // Push cart upwards } + bool WasDetectorRail = false; if (IsBlockRail(InsideType)) { - bool WasDetectorRail = false; - SnapToRail(InsideMeta); + if (InsideType == E_BLOCK_RAIL) + { + SnapToRail(InsideMeta); + } + else + { + SnapToRail(InsideMeta & 0x07); + } switch (InsideType) { @@ -180,12 +187,6 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) } AddPosition(GetSpeed() * (a_Dt / 1000)); // Commit changes; as we use our own engine when on rails, this needs to be done, whereas it is normally in Entity.cpp - - if (m_bIsOnDetectorRail && !WasDetectorRail) - { - m_World->SetBlock(m_DetectorRailPosition.x, m_DetectorRailPosition.y, m_DetectorRailPosition.z, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07); - m_bIsOnDetectorRail = false; - } } else { @@ -193,6 +194,17 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) SetPosY(floor(GetPosY()) + 0.35); // HandlePhysics overrides this if minecart can fall, else, it is to stop ground clipping minecart bottom when off-rail super::HandlePhysics(a_Dt, *Chunk); } + + if (m_bIsOnDetectorRail && !Vector3i((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())).Equals(m_DetectorRailPosition)) + { + m_World->SetBlock(m_DetectorRailPosition.x, m_DetectorRailPosition.y, m_DetectorRailPosition.z, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07); + m_bIsOnDetectorRail = false; + } + else if (WasDetectorRail) + { + m_bIsOnDetectorRail = true; + m_DetectorRailPosition = Vector3i((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); + } // Broadcast positioning changes to client BroadcastMovementUpdate(); @@ -425,11 +437,11 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) { if (GetSpeedZ() > 0) { - AddSpeedZ(AccelDecelNegSpeed); + AddSpeedZ(AccelDecelSpeed); } else { - AddSpeedZ(AccelDecelSpeed); + AddSpeedZ(AccelDecelNegSpeed); } } break; @@ -465,9 +477,6 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) void cMinecart::HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) { - m_bIsOnDetectorRail = true; - m_DetectorRailPosition = Vector3i((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); - m_World->SetBlockMeta(m_DetectorRailPosition, a_RailMeta | 0x08); HandleRailPhysics(a_RailMeta & 0x07, a_Dt); @@ -497,9 +506,20 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) SetPosX(floor(GetPosX()) + 0.5); break; } + // Curved rail physics: once minecart has reached more than half of the block in the direction that it is travelling in, jerk it in the direction of curvature case E_META_RAIL_CURVED_ZM_XM: { - if (GetPosZ() < floor(GetPosZ()) + 0.5) + if (GetPosZ() > floor(GetPosZ()) + 0.5) + { + if (GetSpeedZ() > 0) + { + SetSpeedX(-GetSpeedZ() * 0.7); + } + + SetSpeedZ(0); + SetPosZ(floor(GetPosZ()) + 0.5); + } + else if (GetPosX() > floor(GetPosX()) + 0.5) { if (GetSpeedX() > 0) { @@ -509,21 +529,21 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) SetSpeedX(0); SetPosX(floor(GetPosX()) + 0.5); } - else + break; + } + case E_META_RAIL_CURVED_ZM_XP: + { + if (GetPosZ() > floor(GetPosZ()) + 0.5) { if (GetSpeedZ() > 0) { - SetSpeedX(-GetSpeedZ() * 0.7); + SetSpeedX(GetSpeedZ() * 0.7); } SetSpeedZ(0); SetPosZ(floor(GetPosZ()) + 0.5); } - break; - } - case E_META_RAIL_CURVED_ZM_XP: - { - if (GetPosZ() < floor(GetPosZ()) + 0.5) + else if (GetPosX() < floor(GetPosX()) + 0.5) { if (GetSpeedX() < 0) { @@ -533,16 +553,6 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) SetSpeedX(0); SetPosX(floor(GetPosX()) + 0.5); } - else - { - if (GetSpeedZ() > 0) - { - SetSpeedX(GetSpeedZ() * 0.7); - } - - SetSpeedZ(0); - SetPosZ(floor(GetPosZ()) + 0.5); - } break; } case E_META_RAIL_CURVED_ZP_XM: @@ -557,7 +567,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) SetSpeedZ(0); SetPosZ(floor(GetPosZ()) + 0.5); } - else + else if (GetPosX() > floor(GetPosX()) + 0.5) { if (GetSpeedX() > 0) { @@ -581,7 +591,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) SetSpeedZ(0); SetPosZ(floor(GetPosZ()) + 0.5); } - else + else if (GetPosX() < floor(GetPosX()) + 0.5) { if (GetSpeedX() < 0) { -- cgit v1.2.3 From 3700ad8546dfa7649bb172610dfef4b365eb2a7b Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Jan 2014 18:42:05 +0000 Subject: Added one more direction into collision checks * Added direction XM_XP * Improved performance, thanks STR and xoft --- src/Entities/Minecart.cpp | 77 +++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 643eefb39..df1e48a60 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -720,56 +720,81 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) { + cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == NULL) ? -1 : m_Attachee->GetUniqueID())); + int ChunkX, ChunkZ; + cChunkDef::BlockToChunk((int)floor(GetPosX()), (int)floor(GetPosZ()), ChunkX, ChunkZ); + m_World->ForEachEntityInChunk(ChunkX, ChunkZ, MinecartCollisionCallback); + + if (!MinecartCollisionCallback.FoundIntersection()) + { + return false; + } + switch (a_RailMeta) { case E_META_RAIL_ZM_ZP: { - cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == NULL) ? -1 : m_Attachee->GetUniqueID())); - m_World->ForEachEntity(MinecartCollisionCallback); - - if (MinecartCollisionCallback.FoundIntersection()) + if (MinecartCollisionCallback.GetCollidedEntityPosition().z >= GetPosZ()) { - if (MinecartCollisionCallback.GetCollidedEntityPosition().z >= GetPosZ()) + if ((-GetSpeedZ() * 0.4) < 0.01) { - if (((-GetSpeedZ()) * 0.4) < 0.01) - { - AddSpeedZ(-4); - } - else - { - SetSpeedZ((-GetSpeedZ()) * 0.4); - } + AddSpeedZ(-4); } else { - if ((GetSpeedZ() * 0.4) < 0.01) - { - AddSpeedZ(4); - } - else - { - SetSpeedZ(GetSpeedZ() * 0.4); - } + SetSpeedZ(-GetSpeedZ() * 0.4); } - return true; } - break; + else + { + if ((GetSpeedZ() * 0.4) < 0.01) + { + AddSpeedZ(4); + } + else + { + SetSpeedZ(GetSpeedZ() * 0.4); + } + } + return true; } case E_META_RAIL_XM_XP: { - - break; + if (MinecartCollisionCallback.GetCollidedEntityPosition().x >= GetPosX()) + { + if ((-GetSpeedX() * 0.4) < 0.01) + { + AddSpeedX(-4); + } + else + { + SetSpeedX(-GetSpeedX() * 0.4); + } + } + else + { + if ((GetSpeedX() * 0.4) < 0.01) + { + AddSpeedX(4); + } + else + { + SetSpeedX(GetSpeedX() * 0.4); + } + } + return true; } case E_META_RAIL_CURVED_ZM_XM: case E_META_RAIL_CURVED_ZM_XP: case E_META_RAIL_CURVED_ZP_XM: case E_META_RAIL_CURVED_ZP_XP: { - + // TODO - simply can't be bothered right now break; } default: break; } + return false; } -- cgit v1.2.3 From 83cbe8c13996747a49e940f77282ef68de87eba0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Jan 2014 19:31:17 +0000 Subject: Begin implementing ascending rails --- src/Entities/Minecart.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- src/Entities/Minecart.h | 3 +++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index df1e48a60..6477fb1ca 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -360,6 +360,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) { SetYaw(315); // Set correct rotation server side SetPosY(floor(GetPosY()) + 0.55); // Levitate dat cart + SetSpeedY(0); TestBlockCollision(a_RailMeta); TestEntityCollision(a_RailMeta); @@ -372,6 +373,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) { SetYaw(225); SetPosY(floor(GetPosY()) + 0.55); + SetSpeedY(0); TestBlockCollision(a_RailMeta); TestEntityCollision(a_RailMeta); @@ -382,6 +384,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) { SetYaw(135); SetPosY(floor(GetPosY()) + 0.55); + SetSpeedY(0); TestBlockCollision(a_RailMeta); TestEntityCollision(a_RailMeta); @@ -392,6 +395,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) { SetYaw(45); SetPosY(floor(GetPosY()) + 0.55); + SetSpeedY(0); TestBlockCollision(a_RailMeta); TestEntityCollision(a_RailMeta); @@ -431,7 +435,8 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) SetSpeedY(0); SetSpeedX(0); - if (TestBlockCollision(a_RailMeta)) return; + bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); + if (EntCol || BlckCol) return; if (GetSpeedZ() != 0) { @@ -453,7 +458,8 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) SetSpeedY(0); SetSpeedZ(0); - if (TestBlockCollision(a_RailMeta)) return; + bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); + if (EntCol || BlckCol) return; if (GetSpeedX() != 0) { @@ -468,6 +474,27 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) } break; } + case E_META_RAIL_ASCEND_XM: + { + SetYaw(180); + SetSpeedZ(0); + + if (GetSpeedX() >= 0) + { + if (GetSpeedX() <= MAX_SPEED) + { + AddSpeedX(1); + SetSpeedY(-GetSpeedX()); + } + } + else + { + AddSpeedX(-1); + SetSpeedY(-GetSpeedX()); + } + break; + } + default: ASSERT(!"Unhandled powered rail metadata!"); break; } } @@ -479,6 +506,15 @@ void cMinecart::HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) { m_World->SetBlockMeta(m_DetectorRailPosition, a_RailMeta | 0x08); + // No special handling + HandleRailPhysics(a_RailMeta & 0x07, a_Dt); +} + + + + +void cMinecart::HandleActivatorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) +{ HandleRailPhysics(a_RailMeta & 0x07, a_Dt); } @@ -529,6 +565,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) SetSpeedX(0); SetPosX(floor(GetPosX()) + 0.5); } + SetSpeedY(0); break; } case E_META_RAIL_CURVED_ZM_XP: @@ -553,6 +590,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) SetSpeedX(0); SetPosX(floor(GetPosX()) + 0.5); } + SetSpeedY(0); break; } case E_META_RAIL_CURVED_ZP_XM: @@ -577,6 +615,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) SetSpeedX(0); SetPosX(floor(GetPosX()) + 0.5); } + SetSpeedY(0); break; } case E_META_RAIL_CURVED_ZP_XP: @@ -601,6 +640,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) SetSpeedX(0); SetPosX(floor(GetPosX()) + 0.5); } + SetSpeedY(0); break; } default: break; diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index 87f785538..073e78953 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -65,6 +65,9 @@ protected: */ void HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt); + /** Handles activator rails - placeholder for future implementation */ + void HandleActivatorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt); + /** Snaps a mincecart to a rail's axis, resetting its speed For curved rails, it changes the cart's direction as well as snapping it to axis */ void SnapToRail(NIBBLETYPE a_RailMeta); -- cgit v1.2.3 From 2aa28ad6f453f65bdbf682a62ffae26fcecaa437 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 19 Jan 2014 12:50:07 -0800 Subject: First attempt at Compiling Generator seperatly --- CMakeLists.txt | 4 ++++ Tools/GeneratorPerformanceTest/CMakeLists.txt | 12 ++++++++++++ Tools/GeneratorPerformanceTest/GeneratorPerformanceTest.cpp | 7 +++++++ 3 files changed, 23 insertions(+) create mode 100644 Tools/GeneratorPerformanceTest/CMakeLists.txt create mode 100644 Tools/GeneratorPerformanceTest/GeneratorPerformanceTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ddd34db3..14db055ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,5 +203,9 @@ if (NOT MSVC) string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") endif() +if(${BUILD_TOOLS}) +add_subdirectory(Tools/GeneratorPerformanceTest/) +endif() + add_subdirectory (src) diff --git a/Tools/GeneratorPerformanceTest/CMakeLists.txt b/Tools/GeneratorPerformanceTest/CMakeLists.txt new file mode 100644 index 000000000..8adc88882 --- /dev/null +++ b/Tools/GeneratorPerformanceTest/CMakeLists.txt @@ -0,0 +1,12 @@ + +cmake_minimum_required(VERSION 2.8) +project(GeneratorPerformanceTest) + +include_directories(../../src/Generating) +include_directories(../../src) +include_directories(../../lib) + +add_executable(GeneratorPerformanceTest GeneratorPerformanceTest.cpp ../../src/StringUtils ../../src/MCLogger ../../src/Log ../../src/BlockID ../../src/Noise ../../src/Enchantments ../../src/BlockArea) + +target_link_libraries(GeneratorPerformanceTest Generating) + diff --git a/Tools/GeneratorPerformanceTest/GeneratorPerformanceTest.cpp b/Tools/GeneratorPerformanceTest/GeneratorPerformanceTest.cpp new file mode 100644 index 000000000..75d18149f --- /dev/null +++ b/Tools/GeneratorPerformanceTest/GeneratorPerformanceTest.cpp @@ -0,0 +1,7 @@ + +#include "Globals.h" +#include "ChunkGenerator.h" + +int main(int argc, char * argv[]) { + cChunkGenerator Generator = cChunkGenerator(); +} -- cgit v1.2.3 From bd4278aca18e4c1d6517eec04583d1aef8800aea Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 19 Jan 2014 12:51:23 -0800 Subject: Added Inifile and OSSupport Linking --- src/Generating/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Generating/CMakeLists.txt b/src/Generating/CMakeLists.txt index e1ba299fc..793f48890 100644 --- a/src/Generating/CMakeLists.txt +++ b/src/Generating/CMakeLists.txt @@ -9,3 +9,5 @@ file(GLOB SOURCE ) add_library(Generating ${SOURCE}) + +target_link_libraries(Generating OSSupport iniFile) -- cgit v1.2.3 From 7728f4bcbee7fa61f005c7b972685deb4bf04f2a Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 20 Jan 2014 16:10:39 +0200 Subject: Scoreboard deserialization --- src/Entities/Player.cpp | 22 ++- src/Entities/Player.h | 7 +- src/Scoreboard.cpp | 166 ++++++++++++++-- src/Scoreboard.h | 85 +++++--- src/WorldStorage/ScoreboardSerializer.cpp | 317 ++++++++++++++++++++++++++++++ src/WorldStorage/ScoreboardSerializer.h | 48 +++++ src/WorldStorage/WSSAnvil.cpp | 2 +- 7 files changed, 599 insertions(+), 48 deletions(-) create mode 100644 src/WorldStorage/ScoreboardSerializer.cpp create mode 100644 src/WorldStorage/ScoreboardSerializer.h diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index d2fdba909..285aefd25 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -111,6 +111,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) m_LastJumpHeight = (float)(GetPosY()); m_LastGroundHeight = (float)(GetPosY()); m_Stance = GetPosY() + 1.62; + + // UpdateTeam(); cRoot::Get()->GetServer()->PlayerCreated(this); } @@ -949,8 +951,13 @@ bool cPlayer::IsGameModeAdventure(void) const -void cPlayer::SetTeam(cTeam* a_Team) +void cPlayer::SetTeam(cTeam * a_Team) { + if (m_Team == a_Team) + { + return; + } + if (m_Team) { m_Team->RemovePlayer(GetName()); @@ -968,6 +975,19 @@ void cPlayer::SetTeam(cTeam* a_Team) +cTeam * cPlayer::UpdateTeam(void) +{ + cScoreboard * Scoreboard = m_World->GetScoreBoard(); + + m_Team = Scoreboard->QueryPlayerTeam(GetName()); + + return m_Team; +} + + + + + void cPlayer::OpenWindow(cWindow * a_Window) { if (a_Window != m_CurrentWindow) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 52e629dc3..52ba2065c 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -155,10 +155,13 @@ public: AString GetIP(void) const { return m_IP; } // tolua_export /// Returns the associated team, NULL if none - cTeam* GetTeam(void) { return m_Team; } // tolua_export + cTeam * GetTeam(void) { return m_Team; } // tolua_export /// Sets the player team, NULL if none - void SetTeam(cTeam* a_Team); + void SetTeam(cTeam * a_Team); + + /// Forces the player to query the scoreboard for his team + cTeam * UpdateTeam(void); // tolua_end diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 539316356..864837d3d 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -11,22 +11,74 @@ -cObjective::cObjective(cObjective::eType a_Type) : m_Type(a_Type) -{} +AString cObjective::TypeToString(eType a_Type) +{ + switch (a_Type) + { + case E_TYPE_DUMMY: return "dummy"; + case E_TYPE_DEATH_COUNT: return "deathCount"; + case E_TYPE_PLAYER_KILL_COUNT: return "playerKillCount"; + case E_TYPE_TOTAL_KILL_COUNT: return "totalKillCount"; + case E_TYPE_HEALTH: return "health"; + case E_TYPE_ACHIEVEMENT: return "achievement"; + case E_TYPE_STAT: return "stat"; + case E_TYPE_STAT_ITEM_CRAFT: return "stat.craftItem"; + case E_TYPE_STAT_ITEM_USE: return "stat.useItem"; + case E_TYPE_STAT_ITEM_BREAK: return "stat.breakItem"; + case E_TYPE_STAT_BLOCK_MINE: return "stat.mineBlock"; + case E_TYPE_STAT_ENTITY_KILL: return "stat.killEntity"; + case E_TYPE_STAT_ENTITY_KILLED_BY: return "stat.entityKilledBy"; + + default: return ""; + } +} -void cObjective::SetDisplaySlot(cObjective::eDisplaySlot a_Display) +cObjective::eType cObjective::StringToType(const AString & a_Name) { - m_Display = a_Display; + static struct { + eType m_Type; + const char * m_String; + } TypeMap [] = + { + {E_TYPE_DUMMY, "dummy"}, + {E_TYPE_DEATH_COUNT, "deathCount"}, + {E_TYPE_PLAYER_KILL_COUNT, "playerKillCount"}, + {E_TYPE_TOTAL_KILL_COUNT, "totalKillCount"}, + {E_TYPE_HEALTH, "health"}, + {E_TYPE_ACHIEVEMENT, "achievement"}, + {E_TYPE_STAT, "stat"}, + {E_TYPE_STAT_ITEM_CRAFT, "stat.craftItem"}, + {E_TYPE_STAT_ITEM_USE, "stat.useItem"}, + {E_TYPE_STAT_ITEM_BREAK, "stat.breakItem"}, + {E_TYPE_STAT_BLOCK_MINE, "stat.mineBlock"}, + {E_TYPE_STAT_ENTITY_KILL, "stat.killEntity"}, + {E_TYPE_STAT_ENTITY_KILLED_BY, "stat.entityKilledBy"} + }; + for (size_t i = 0; i < ARRAYCOUNT(TypeMap); i++) + { + if (NoCaseCompare(TypeMap[i].m_String, a_Name) == 0) + { + return TypeMap[i].m_Type; + } + } // for i - TypeMap[] + return E_TYPE_DUMMY; } +cObjective::cObjective(const AString & a_DisplayName, cObjective::eType a_Type) : m_DisplayName(a_DisplayName), m_Type(a_Type) +{} + + + + + void cObjective::Reset(void) { m_Scores.clear(); @@ -132,6 +184,17 @@ bool cTeam::RemovePlayer(const AString & a_Name) +bool cTeam::HasPlayer(const AString & a_Name) const +{ + cPlayerNameSet::const_iterator it = m_Players.find(a_Name); + + return it != m_Players.end(); +} + + + + + void cTeam::Reset(void) { m_Players.clear(); @@ -149,11 +212,23 @@ unsigned int cTeam::GetNumPlayers(void) const -cObjective* cScoreboard::RegisterObjective(const AString & a_Name, cObjective::eType a_Type) +cScoreboard::cScoreboard() { - cObjective Objective(a_Type); + for (int i = 0; i < (int) E_DISPLAY_SLOT_COUNT; ++i) + { + m_Display[i] = NULL; + } +} + + + - std::pair Status = m_Objectives.insert(NamedObjective(a_Name, Objective)); + +cObjective* cScoreboard::RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type) +{ + cObjective Objective(a_DisplayName, a_Type); + + std::pair Status = m_Objectives.insert(cNamedObjective(a_Name, Objective)); return Status.second ? &Status.first->second : NULL; } @@ -164,7 +239,7 @@ cObjective* cScoreboard::RegisterObjective(const AString & a_Name, cObjective::e bool cScoreboard::RemoveObjective(const AString & a_Name) { - ObjectiveMap::iterator it = m_Objectives.find(a_Name); + cObjectiveMap::iterator it = m_Objectives.find(a_Name); if (it == m_Objectives.end()) { @@ -180,9 +255,9 @@ bool cScoreboard::RemoveObjective(const AString & a_Name) -cObjective* cScoreboard::GetObjective(const AString & a_Name) +cObjective * cScoreboard::GetObjective(const AString & a_Name) { - ObjectiveMap::iterator it = m_Objectives.find(a_Name); + cObjectiveMap::iterator it = m_Objectives.find(a_Name); if (it == m_Objectives.end()) { @@ -198,14 +273,14 @@ cObjective* cScoreboard::GetObjective(const AString & a_Name) -cTeam* cScoreboard::RegisterTeam( +cTeam * cScoreboard::RegisterTeam( const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix ) { cTeam Team(a_Name, a_DisplayName, a_Prefix, a_Suffix); - std::pair Status = m_Teams.insert(NamedTeam(a_Name, Team)); + std::pair Status = m_Teams.insert(cNamedTeam(a_Name, Team)); return Status.second ? &Status.first->second : NULL; } @@ -216,7 +291,7 @@ cTeam* cScoreboard::RegisterTeam( bool cScoreboard::RemoveTeam(const AString & a_Name) { - TeamMap::iterator it = m_Teams.find(a_Name); + cTeamMap::iterator it = m_Teams.find(a_Name); if (it == m_Teams.end()) { @@ -232,9 +307,9 @@ bool cScoreboard::RemoveTeam(const AString & a_Name) -cTeam* cScoreboard::GetTeam(const AString & a_Name) +cTeam * cScoreboard::GetTeam(const AString & a_Name) { - TeamMap::iterator it = m_Teams.find(a_Name); + cTeamMap::iterator it = m_Teams.find(a_Name); if (it == m_Teams.end()) { @@ -250,9 +325,50 @@ cTeam* cScoreboard::GetTeam(const AString & a_Name) +cTeam * cScoreboard::QueryPlayerTeam(const AString & a_Name) +{ + for (cTeamMap::iterator it = m_Teams.begin(); it != m_Teams.end(); ++it) + { + if (it->second.HasPlayer(a_Name)) + { + return &it->second; + } + } + + return NULL; +} + + + + + +void cScoreboard::SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot) +{ + ASSERT(a_Slot < E_DISPLAY_SLOT_COUNT); + + cObjective * Objective = GetObjective(a_Objective); + + m_Display[a_Slot] = Objective; +} + + + + + +cObjective* cScoreboard::GetObjectiveIn(eDisplaySlot a_Slot) +{ + ASSERT(a_Slot < E_DISPLAY_SLOT_COUNT); + + return m_Display[a_Slot]; +} + + + + + void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback) { - for (ObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it) + for (cObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it) { if (it->second.GetType() == a_Type) { @@ -268,3 +384,21 @@ void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallb + +unsigned int cScoreboard::GetNumObjectives(void) const +{ + return m_Objectives.size(); +} + + + + + +unsigned int cScoreboard::GetNumTeams(void) const +{ + return m_Teams.size(); +} + + + + diff --git a/src/Scoreboard.h b/src/Scoreboard.h index 7993b1333..f7285a9cf 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -24,6 +24,7 @@ typedef cItemCallback cObjectiveCallback; class cObjective { public: + typedef int Score; enum eType @@ -47,21 +48,17 @@ public: E_TYPE_STAT_ENTITY_KILLED_BY }; - enum eDisplaySlot - { - E_DISPLAY_SLOT_LIST, - E_DISPLAY_SLOT_SIDEBAR, - E_DISPLAY_SLOT_NAME - }; + static AString TypeToString(eType a_Type); + + static eType StringToType(const AString & a_Name); public: - cObjective(eType a_Type); - eType GetType(void) const { return m_Type; } + cObjective(const AString & a_DisplayName, eType a_Type); - eDisplaySlot GetDisplaySlot(void) const { return m_Display; } + eType GetType(void) const { return m_Type; } - void SetDisplaySlot(eDisplaySlot a_Display); + const AString & GetDisplayName(void) const { return m_DisplayName; } /// Resets the objective void Reset(void); @@ -82,15 +79,17 @@ public: Score SubScore(const AString & a_Name, Score a_Delta); private: + typedef std::pair TrackedPlayer; typedef std::map ScoreMap; ScoreMap m_Scores; + AString m_DisplayName; + eType m_Type; - eDisplaySlot m_Display; }; @@ -112,6 +111,9 @@ public: /// Removes a player from the team bool RemovePlayer(const AString & a_Name); + /// Returns whether the specified player is in this team + bool HasPlayer(const AString & a_Name) const; + /// Removes all registered players void Reset(void); @@ -127,8 +129,8 @@ public: const AString & GetPrefix(void) const { return m_Prefix; } const AString & GetSuffix(void) const { return m_Suffix; } - void SetFriendlyFire(bool a_Flag); - void SetCanSeeFriendlyInvisible(bool a_Flag); + void SetFriendlyFire(bool a_Flag) { m_AllowsFriendlyFire = a_Flag; } + void SetCanSeeFriendlyInvisible(bool a_Flag) { m_CanSeeFriendlyInvisible = a_Flag; } void SetDisplayName(const AString & a_Name); @@ -137,6 +139,8 @@ public: private: + typedef std::set cPlayerNameSet; + bool m_AllowsFriendlyFire; bool m_CanSeeFriendlyInvisible; @@ -146,10 +150,8 @@ private: AString m_Prefix; AString m_Suffix; - // TODO 2014-01-19 xdot: Potential optimization - vector/list - typedef std::set PlayerNameSet; + cPlayerNameSet m_Players; - PlayerNameSet m_Players; }; @@ -159,41 +161,68 @@ private: class cScoreboard { public: - cScoreboard() {} + + enum eDisplaySlot + { + E_DISPLAY_SLOT_LIST = 0, + E_DISPLAY_SLOT_SIDEBAR, + E_DISPLAY_SLOT_NAME, + + E_DISPLAY_SLOT_COUNT + }; + + +public: + + cScoreboard(); /// Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision - cObjective* RegisterObjective(const AString & a_Name, cObjective::eType a_Type); + cObjective * RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type); /// Removes a registered objective, returns true if operation was successful bool RemoveObjective(const AString & a_Name); /// Retrieves the objective with the specified name, NULL if not found - cObjective* GetObjective(const AString & a_Name); + cObjective * GetObjective(const AString & a_Name); /// Registers a new team, returns the cTeam instance, NULL on name collision - cTeam* RegisterTeam(const AString & a_Name, const AString & a_DisplayName, - const AString & a_Prefix, const AString & a_Suffix); + cTeam * RegisterTeam(const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix); /// Removes a registered team, returns true if operation was successful bool RemoveTeam(const AString & a_Name); /// Retrieves the team with the specified name, NULL if not found - cTeam* GetTeam(const AString & a_Name); + cTeam * GetTeam(const AString & a_Name); + + cTeam * QueryPlayerTeam(const AString & a_Name); // WARNING: O(n logn) + + void SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot); + + cObjective* GetObjectiveIn(eDisplaySlot a_Slot); /// Execute callback for each objective with the specified type void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback); + unsigned int GetNumObjectives(void) const; + + unsigned int GetNumTeams(void) const; + + private: - typedef std::pair NamedObjective; - typedef std::pair NamedTeam; - typedef std::map ObjectiveMap; - typedef std::map TeamMap; + typedef std::pair cNamedObjective; + typedef std::pair cNamedTeam; + + typedef std::map cObjectiveMap; + typedef std::map cTeamMap; // TODO 2014-01-19 xdot: Potential optimization - Sort objectives based on type - ObjectiveMap m_Objectives; + cObjectiveMap m_Objectives; + + cTeamMap m_Teams; + + cObjective* m_Display[E_DISPLAY_SLOT_COUNT]; - TeamMap m_Teams; } ; diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp new file mode 100644 index 000000000..c2f13a092 --- /dev/null +++ b/src/WorldStorage/ScoreboardSerializer.cpp @@ -0,0 +1,317 @@ + +// ScoreboardSerializer.cpp + + +#include "Globals.h" +#include "ScoreboardSerializer.h" +#include "../StringCompression.h" +#include "zlib/zlib.h" +#include "FastNBT.h" + +#include "../Scoreboard.h" + + + + +#define SCOREBOARD_INFLATE_MAX 16 KiB + + + + + +cScoreboardSerializer::cScoreboardSerializer(const AString & a_WorldName, cScoreboard* a_ScoreBoard) + : m_ScoreBoard(a_ScoreBoard) +{ + Printf(m_Path, "%s/data/scoreboard.dat", a_WorldName.c_str()); +} + + + + + +bool cScoreboardSerializer::Load(void) +{ + cFile File; + + if (!File.Open(m_Path, cFile::fmReadWrite)) + { + return false; + } + + AString Data; + + File.ReadRestOfFile(Data); + + File.Close(); + + char Uncompressed[SCOREBOARD_INFLATE_MAX]; + z_stream strm; + strm.zalloc = (alloc_func)NULL; + strm.zfree = (free_func)NULL; + strm.opaque = NULL; + inflateInit(&strm); + strm.next_out = (Bytef *)Uncompressed; + strm.avail_out = sizeof(Uncompressed); + strm.next_in = (Bytef *)Data.data(); + strm.avail_in = Data.size(); + int res = inflate(&strm, Z_FINISH); + inflateEnd(&strm); + if (res != Z_STREAM_END) + { + return false; + } + + // Parse the NBT data: + cParsedNBT NBT(Uncompressed, strm.total_out); + if (!NBT.IsValid()) + { + // NBT Parsing failed + return false; + } + + return LoadScoreboardFromNBT(NBT); +} + + + + + +bool cScoreboardSerializer::Save(void) +{ + cFastNBTWriter Writer; + + Writer.BeginCompound(""); + + SaveScoreboardToNBT(Writer); + + Writer.EndCompound(); + Writer.Finish(); + + #ifdef _DEBUG + cParsedNBT TestParse(Writer.GetResult().data(), Writer.GetResult().size()); + ASSERT(TestParse.IsValid()); + #endif // _DEBUG + + gzFile gz = gzopen((FILE_IO_PREFIX + m_Path).c_str(), "wb"); + if (gz != NULL) + { + gzwrite(gz, Writer.GetResult().data(), Writer.GetResult().size()); + } + gzclose(gz); + + return true; +} + + + + + +void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer) +{ + a_Writer.BeginCompound("Data"); + a_Writer.BeginList("Objectives", TAG_Compound); + + a_Writer.EndList(); + + a_Writer.BeginList("PlayerScores", TAG_Compound); + + a_Writer.EndList(); + + a_Writer.BeginList("Teams", TAG_Compound); + + a_Writer.EndList(); + a_Writer.EndCompound(); + + a_Writer.BeginCompound("DisplaySlots"); + + a_Writer.EndCompound(); +} + + + + + +bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT) +{ + int Data = a_NBT.FindChildByName(0, "Data"); + if (Data < 0) + { + return false; + } + + int Objectives = a_NBT.FindChildByName(Data, "Objectives"); + if (Objectives < 0) + { + return false; + } + + for (int Child = a_NBT.GetFirstChild(Objectives); Child >= 0; Child = a_NBT.GetNextSibling(Child)) + { + AString CriteriaName, DisplayName, Name; + + int CurrLine = a_NBT.FindChildByName(Child, "CriteriaName"); + if (CurrLine >= 0) + { + CriteriaName = a_NBT.GetString(CurrLine); + } + + CurrLine = a_NBT.FindChildByName(Child, "DisplayName"); + if (CurrLine >= 0) + { + DisplayName = a_NBT.GetString(CurrLine); + } + + CurrLine = a_NBT.FindChildByName(Child, "Name"); + if (CurrLine >= 0) + { + Name = a_NBT.GetString(CurrLine); + } + + cObjective::eType Type = cObjective::StringToType(CriteriaName); + + m_ScoreBoard->RegisterObjective(Name, DisplayName, Type); + } + + int PlayerScores = a_NBT.FindChildByName(Data, "PlayerScores"); + if (PlayerScores < 0) + { + return false; + } + + for (int Child = a_NBT.GetFirstChild(PlayerScores); Child >= 0; Child = a_NBT.GetNextSibling(Child)) + { + AString Name, ObjectiveName; + + cObjective::Score Score; + + int CurrLine = a_NBT.FindChildByName(Child, "Score"); + if (CurrLine >= 0) + { + Score = a_NBT.GetInt(CurrLine); + } + + CurrLine = a_NBT.FindChildByName(Child, "Name"); + if (CurrLine >= 0) + { + Name = a_NBT.GetString(CurrLine); + } + + CurrLine = a_NBT.FindChildByName(Child, "Objective"); + if (CurrLine >= 0) + { + ObjectiveName = a_NBT.GetString(CurrLine); + } + + cObjective * Objective = m_ScoreBoard->GetObjective(ObjectiveName); + + if (Objective) + { + Objective->SetScore(Name, Score); + } + } + + int Teams = a_NBT.FindChildByName(Data, "Teams"); + if (Teams < 0) + { + return false; + } + + for (int Child = a_NBT.GetFirstChild(Teams); Child >= 0; Child = a_NBT.GetNextSibling(Child)) + { + AString Name, DisplayName, Prefix, Suffix; + + bool AllowsFriendlyFire, CanSeeFriendlyInvisible; + + int CurrLine = a_NBT.FindChildByName(Child, "Name"); + if (CurrLine >= 0) + { + Name = a_NBT.GetInt(CurrLine); + } + + CurrLine = a_NBT.FindChildByName(Child, "DisplayName"); + if (CurrLine >= 0) + { + DisplayName = a_NBT.GetInt(CurrLine); + } + + CurrLine = a_NBT.FindChildByName(Child, "Prefix"); + if (CurrLine >= 0) + { + Prefix = a_NBT.GetInt(CurrLine); + } + + CurrLine = a_NBT.FindChildByName(Child, "Suffix"); + if (CurrLine >= 0) + { + Suffix = a_NBT.GetInt(CurrLine); + } + + CurrLine = a_NBT.FindChildByName(Child, "AllowFriendlyFire"); + if (CurrLine >= 0) + { + AllowsFriendlyFire = a_NBT.GetInt(CurrLine); + } + + CurrLine = a_NBT.FindChildByName(Child, "SeeFriendlyInvisibles"); + if (CurrLine >= 0) + { + CanSeeFriendlyInvisible = a_NBT.GetInt(CurrLine); + } + + cTeam * Team = m_ScoreBoard->RegisterTeam(Name, DisplayName, Prefix, Suffix); + + Team->SetFriendlyFire(AllowsFriendlyFire); + Team->SetCanSeeFriendlyInvisible(CanSeeFriendlyInvisible); + + int Players = a_NBT.FindChildByName(Child, "Players"); + if (Players < 0) + { + continue; + } + + for (int ChildB = a_NBT.GetFirstChild(Players); ChildB >= 0; ChildB = a_NBT.GetNextSibling(ChildB)) + { + Team->AddPlayer(a_NBT.GetString(ChildB)); + } + } + + int DisplaySlots = a_NBT.FindChildByName(0, "DisplaySlots"); + if (DisplaySlots < 0) + { + return false; + } + + int CurrLine = a_NBT.FindChildByName(DisplaySlots, "slot_0"); + if (CurrLine >= 0) + { + AString Name = a_NBT.GetString(CurrLine); + + m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_LIST); + } + + CurrLine = a_NBT.FindChildByName(DisplaySlots, "slot_1"); + if (CurrLine >= 0) + { + AString Name = a_NBT.GetString(CurrLine); + + m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_SIDEBAR); + } + + CurrLine = a_NBT.FindChildByName(DisplaySlots, "slot_2"); + if (CurrLine >= 0) + { + AString Name = a_NBT.GetString(CurrLine); + + m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_NAME); + } + + return true; +} + + + + + + + + diff --git a/src/WorldStorage/ScoreboardSerializer.h b/src/WorldStorage/ScoreboardSerializer.h new file mode 100644 index 000000000..2a4e0767e --- /dev/null +++ b/src/WorldStorage/ScoreboardSerializer.h @@ -0,0 +1,48 @@ + +// ScoreboardSerializer.h + +// Declares the cScoreboardSerializer class that is used for saving scoreboards into NBT format used by Anvil + + + + + +#pragma once + + + + + +// fwd: +class cFastNBTWriter; +class cParsedNBT; +class cScoreboard; + + + + +class cScoreboardSerializer +{ +public: + cScoreboardSerializer(const AString & a_WorldName, cScoreboard* a_ScoreBoard); + + /// Try to load the scoreboard + bool Load(void); + + /// Try to save the scoreboard + bool Save(void); + +private: + + void SaveScoreboardToNBT(cFastNBTWriter & a_Writer); + + bool LoadScoreboardFromNBT(const cParsedNBT & a_NBT); + + cScoreboard* m_ScoreBoard; + + AString m_Path; +} ; + + + + diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 96a77152b..600eb0a51 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1935,7 +1935,7 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N return false; } a_Entity.SetYaw(Rotation[0]); - a_Entity.SetRoll (Rotation[1]); + a_Entity.SetRoll(Rotation[1]); return true; } -- cgit v1.2.3 From ff2302ebd53453242175683587b19ae5de5d1aed Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 20 Jan 2014 16:45:40 +0200 Subject: Scoreboard serialization --- src/Scoreboard.cpp | 11 +++-- src/Scoreboard.h | 18 ++++++-- src/WorldStorage/ScoreboardSerializer.cpp | 77 +++++++++++++++++++++++++++++-- 3 files changed, 92 insertions(+), 14 deletions(-) diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 864837d3d..3ddf146a6 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -72,7 +72,10 @@ cObjective::eType cObjective::StringToType(const AString & a_Name) -cObjective::cObjective(const AString & a_DisplayName, cObjective::eType a_Type) : m_DisplayName(a_DisplayName), m_Type(a_Type) +cObjective::cObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type) + : m_DisplayName(a_DisplayName) + , m_Name(a_Name) + , m_Type(a_Type) {} @@ -90,7 +93,7 @@ void cObjective::Reset(void) cObjective::Score cObjective::GetScore(const AString & a_Name) const { - ScoreMap::const_iterator it = m_Scores.find(a_Name); + cScoreMap::const_iterator it = m_Scores.find(a_Name); if (it == m_Scores.end()) { @@ -226,7 +229,7 @@ cScoreboard::cScoreboard() cObjective* cScoreboard::RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type) { - cObjective Objective(a_DisplayName, a_Type); + cObjective Objective(a_Name, a_DisplayName, a_Type); std::pair Status = m_Objectives.insert(cNamedObjective(a_Name, Objective)); @@ -355,7 +358,7 @@ void cScoreboard::SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot) -cObjective* cScoreboard::GetObjectiveIn(eDisplaySlot a_Slot) +cObjective * cScoreboard::GetObjectiveIn(eDisplaySlot a_Slot) { ASSERT(a_Slot < E_DISPLAY_SLOT_COUNT); diff --git a/src/Scoreboard.h b/src/Scoreboard.h index f7285a9cf..2ce614de7 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -54,10 +54,11 @@ public: public: - cObjective(const AString & a_DisplayName, eType a_Type); + cObjective(const AString & a_Name, const AString & a_DisplayName, eType a_Type); eType GetType(void) const { return m_Type; } + const AString & GetName(void) const { return m_Name; } const AString & GetDisplayName(void) const { return m_DisplayName; } /// Resets the objective @@ -80,16 +81,19 @@ public: private: - typedef std::pair TrackedPlayer; + typedef std::pair cTrackedPlayer; - typedef std::map ScoreMap; + typedef std::map cScoreMap; - ScoreMap m_Scores; + cScoreMap m_Scores; AString m_DisplayName; + AString m_Name; eType m_Type; + friend class cScoreboardSerializer; + }; @@ -152,6 +156,8 @@ private: cPlayerNameSet m_Players; + friend class cScoreboardSerializer; + }; @@ -198,7 +204,7 @@ public: void SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot); - cObjective* GetObjectiveIn(eDisplaySlot a_Slot); + cObjective * GetObjectiveIn(eDisplaySlot a_Slot); /// Execute callback for each objective with the specified type void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback); @@ -223,6 +229,8 @@ private: cObjective* m_Display[E_DISPLAY_SLOT_COUNT]; + friend class cScoreboardSerializer; + } ; diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp index c2f13a092..bcac50bb6 100644 --- a/src/WorldStorage/ScoreboardSerializer.cpp +++ b/src/WorldStorage/ScoreboardSerializer.cpp @@ -109,21 +109,88 @@ bool cScoreboardSerializer::Save(void) void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer) { a_Writer.BeginCompound("Data"); - a_Writer.BeginList("Objectives", TAG_Compound); + a_Writer.BeginList("Objectives", TAG_Compound); + + for (cScoreboard::cObjectiveMap::const_iterator it = m_ScoreBoard->m_Objectives.begin(); it != m_ScoreBoard->m_Objectives.end(); ++it) + { + const cObjective & Objective = it->second; - a_Writer.EndList(); + a_Writer.BeginCompound(""); - a_Writer.BeginList("PlayerScores", TAG_Compound); + a_Writer.AddString("CriteriaName", cObjective::TypeToString(Objective.GetType())); - a_Writer.EndList(); + a_Writer.AddString("DisplayName", Objective.GetDisplayName()); + a_Writer.AddString("Name", it->first); - a_Writer.BeginList("Teams", TAG_Compound); + a_Writer.EndCompound(); + } + + a_Writer.EndList(); + + a_Writer.BeginList("PlayerScores", TAG_Compound); + + for (cScoreboard::cObjectiveMap::const_iterator it = m_ScoreBoard->m_Objectives.begin(); it != m_ScoreBoard->m_Objectives.end(); ++it) + { + const cObjective & Objective = it->second; + + for (cObjective::cScoreMap::const_iterator it2 = Objective.m_Scores.begin(); it2 != Objective.m_Scores.end(); ++it2) + { + a_Writer.BeginCompound(""); + + a_Writer.AddInt("Score", it2->second); + + a_Writer.AddString("Name", it2->first); + a_Writer.AddString("Objective", it->first); + + a_Writer.EndCompound(); + } + } + + a_Writer.EndList(); + + a_Writer.BeginList("Teams", TAG_Compound); + + for (cScoreboard::cTeamMap::const_iterator it = m_ScoreBoard->m_Teams.begin(); it != m_ScoreBoard->m_Teams.end(); ++it) + { + const cTeam & Team = it->second; + + a_Writer.BeginCompound(""); + + a_Writer.AddByte("AllowFriendlyFire", Team.AllowsFriendlyFire() ? 1 : 0); + a_Writer.AddByte("SeeFriendlyInvisibles", Team.CanSeeFriendlyInvisible() ? 1 : 0); + + a_Writer.AddString("DisplayName", Team.GetDisplayName()); + a_Writer.AddString("Name", it->first); + + a_Writer.AddString("Prefix", Team.GetPrefix()); + a_Writer.AddString("Suffix", Team.GetSuffix()); + + a_Writer.BeginList("Players", TAG_String); + + for (cTeam::cPlayerNameSet::const_iterator it2 = Team.m_Players.begin(); it2 != Team.m_Players.end(); ++it2) + { + a_Writer.AddString("", *it2); + } a_Writer.EndList(); + + a_Writer.EndCompound(); + } + + a_Writer.EndList(); a_Writer.EndCompound(); a_Writer.BeginCompound("DisplaySlots"); + cObjective * Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_LIST); + a_Writer.AddString("slot_0", (Objective == NULL) ? "" : Objective->GetName()); + + Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_SIDEBAR); + a_Writer.AddString("slot_1", (Objective == NULL) ? "" : Objective->GetName()); + + Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_NAME); + a_Writer.AddString("slot_2", (Objective == NULL) ? "" : Objective->GetName()); + a_Writer.EndCompound(); } -- cgit v1.2.3 From 9bb61e6e2e23fc8a66dbc95d918f23b89ba60314 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 20 Jan 2014 09:17:24 -0800 Subject: Seperated BlockArea From World If anyone can come up with a better name for the interface I'll change it, It contians to methods which do compleatly unrelated things --- src/BlockArea.cpp | 9 ++++----- src/BlockArea.h | 9 +++------ src/ForEachChunkProvider.h | 10 ++++++++++ src/World.h | 6 +++--- 4 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 src/ForEachChunkProvider.h diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 910661f60..c33d2712b 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -6,7 +6,6 @@ #include "Globals.h" #include "BlockArea.h" -#include "World.h" #include "OSSupport/GZipFile.h" #include "WorldStorage/FastNBT.h" #include "Blocks/BlockHandler.h" @@ -266,7 +265,7 @@ void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ) -bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes) +bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes) { // Normalize the coords: if (a_MinBlockX > a_MaxBlockX) @@ -327,7 +326,7 @@ bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_ cChunkDef::AbsoluteToRelative(a_MaxBlockX, a_MaxBlockY, a_MaxBlockZ, MaxChunkX, MaxChunkZ); // Query block data: - if (!a_World->ForEachChunkInRect(MinChunkX, MaxChunkX, MinChunkZ, MaxChunkZ, Reader)) + if (!a_ForEachChunkProvider->ForEachChunkInRect(MinChunkX, MaxChunkX, MinChunkZ, MaxChunkZ, Reader)) { Clear(); return false; @@ -340,7 +339,7 @@ bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_ -bool cBlockArea::Write(cWorld * a_World, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) +bool cBlockArea::Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) { ASSERT((a_DataTypes & GetDataTypes()) == a_DataTypes); // Are you requesting only the data that I have? a_DataTypes = a_DataTypes & GetDataTypes(); // For release builds, silently cut off the datatypes that I don't have @@ -357,7 +356,7 @@ bool cBlockArea::Write(cWorld * a_World, int a_MinBlockX, int a_MinBlockY, int a a_MinBlockY = cChunkDef::Height - m_SizeY; } - return a_World->WriteBlockArea(*this, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes); + return a_ForEachChunkProvider->WriteBlockArea(*this, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes); } diff --git a/src/BlockArea.h b/src/BlockArea.h index 075cc99ec..ae23c76c6 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -12,13 +12,10 @@ #pragma once +#include "ForEachChunkProvider.h" - -// fwd: World.h -class cWorld; - // fwd: FastNBT.h class cParsedNBT; @@ -68,13 +65,13 @@ public: void SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ); /// Reads an area of blocks specified. Returns true if successful. All coords are inclusive. - bool Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes = baTypes | baMetas); + bool Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes = baTypes | baMetas); // TODO: Write() is not too good an interface: if it fails, there's no way to repeat only for the parts that didn't write // A better way may be to return a list of cBlockAreas for each part that didn't succeed writing, so that the caller may try again /// Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all - bool Write(cWorld * a_World, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes = baTypes | baMetas); + bool Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes = baTypes | baMetas); /// Copies this object's contents into the specified BlockArea. void CopyTo(cBlockArea & a_Into) const; diff --git a/src/ForEachChunkProvider.h b/src/ForEachChunkProvider.h new file mode 100644 index 000000000..9092fcb0a --- /dev/null +++ b/src/ForEachChunkProvider.h @@ -0,0 +1,10 @@ + +class cBlockArea; + +class cForEachChunkProvider +{ +public: + virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) = 0; + + virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) = 0; +}; diff --git a/src/World.h b/src/World.h index ef74a65c7..f5134c223 100644 --- a/src/World.h +++ b/src/World.h @@ -59,7 +59,7 @@ typedef cItemCallback cNoteBlockCallback; // tolua_begin -class cWorld +class cWorld : public cForEachChunkProvider { public: @@ -315,7 +315,7 @@ public: bool IsChunkLighted(int a_ChunkX, int a_ChunkZ); /// Calls the callback for each chunk in the coords specified (all cords are inclusive). Returns true if all chunks have been processed successfully - bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback); + virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback); // tolua_begin @@ -361,7 +361,7 @@ public: Prefer cBlockArea::Write() instead, this is the internal implementation; cBlockArea does error checking, too. a_DataTypes is a bitmask of cBlockArea::baXXX constants ORed together. */ - bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes); + virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes); // tolua_begin -- cgit v1.2.3 From 4f09e8df6ecf20bd50573b7bf40c46f5ade21124 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 20 Jan 2014 09:59:12 -0800 Subject: Moved Schematic file methods to seperate class --- src/BlockArea.cpp | 159 +--------------------------- src/BlockArea.h | 18 +--- src/WorldStorage/SchematicFileSerilizer.cpp | 155 +++++++++++++++++++++++++++ src/WorldStorage/SchematicFileSerilizer.h | 20 ++++ 4 files changed, 177 insertions(+), 175 deletions(-) create mode 100644 src/WorldStorage/SchematicFileSerilizer.cpp create mode 100644 src/WorldStorage/SchematicFileSerilizer.h diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index c33d2712b..194e2d68a 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -7,7 +7,6 @@ #include "Globals.h" #include "BlockArea.h" #include "OSSupport/GZipFile.h" -#include "WorldStorage/FastNBT.h" #include "Blocks/BlockHandler.h" @@ -447,85 +446,12 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName) -bool cBlockArea::LoadFromSchematicFile(const AString & a_FileName) -{ - // Un-GZip the contents: - AString Contents; - cGZipFile File; - if (!File.Open(a_FileName, cGZipFile::fmRead)) - { - LOG("Cannot open the schematic file \"%s\".", a_FileName.c_str()); - return false; - } - int NumBytesRead = File.ReadRestOfFile(Contents); - if (NumBytesRead < 0) - { - LOG("Cannot read GZipped data in the schematic file \"%s\", error %d", a_FileName.c_str(), NumBytesRead); - return false; - } - File.Close(); - - // Parse the NBT: - cParsedNBT NBT(Contents.data(), Contents.size()); - if (!NBT.IsValid()) - { - LOG("Cannot parse the NBT in the schematic file \"%s\".", a_FileName.c_str()); - return false; - } - - return LoadFromSchematicNBT(NBT); -} -bool cBlockArea::SaveToSchematicFile(const AString & a_FileName) -{ - cFastNBTWriter Writer("Schematic"); - Writer.AddShort("Width", m_SizeX); - Writer.AddShort("Height", m_SizeY); - Writer.AddShort("Length", m_SizeZ); - Writer.AddString("Materials", "Alpha"); - if (HasBlockTypes()) - { - Writer.AddByteArray("Blocks", (const char *)m_BlockTypes, GetBlockCount()); - } - else - { - AString Dummy(GetBlockCount(), 0); - Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size()); - } - if (HasBlockMetas()) - { - Writer.AddByteArray("Data", (const char *)m_BlockMetas, GetBlockCount()); - } - else - { - AString Dummy(GetBlockCount(), 0); - Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); - } - // TODO: Save entities and block entities - Writer.BeginList("Entities", TAG_Compound); - Writer.EndList(); - Writer.BeginList("TileEntities", TAG_Compound); - Writer.EndList(); - Writer.Finish(); - - // Save to file - cGZipFile File; - if (!File.Open(a_FileName, cGZipFile::fmWrite)) - { - LOG("Cannot open file \"%s\" for writing.", a_FileName.c_str()); - return false; - } - if (!File.Write(Writer.GetResult())) - { - LOG("Cannot write data to file \"%s\".", a_FileName.c_str()); - return false; - } - return true; -} + @@ -2017,89 +1943,6 @@ void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMa } - - - -bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT) -{ - int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials"); - if ((TMaterials > 0) && (a_NBT.GetType(TMaterials) == TAG_String)) - { - AString Materials = a_NBT.GetString(TMaterials); - if (Materials.compare("Alpha") != 0) - { - LOG("Materials tag is present and \"%s\" instead of \"Alpha\". Possibly a wrong-format schematic file.", Materials.c_str()); - return false; - } - } - int TSizeX = a_NBT.FindChildByName(a_NBT.GetRoot(), "Width"); - int TSizeY = a_NBT.FindChildByName(a_NBT.GetRoot(), "Height"); - int TSizeZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "Length"); - if ( - (TSizeX < 0) || (TSizeY < 0) || (TSizeZ < 0) || - (a_NBT.GetType(TSizeX) != TAG_Short) || - (a_NBT.GetType(TSizeY) != TAG_Short) || - (a_NBT.GetType(TSizeZ) != TAG_Short) - ) - { - LOG("Dimensions are missing from the schematic file (%d, %d, %d), (%d, %d, %d)", - TSizeX, TSizeY, TSizeZ, - a_NBT.GetType(TSizeX), a_NBT.GetType(TSizeY), a_NBT.GetType(TSizeZ) - ); - return false; - } - - int SizeX = a_NBT.GetShort(TSizeX); - int SizeY = a_NBT.GetShort(TSizeY); - int SizeZ = a_NBT.GetShort(TSizeZ); - if ((SizeX < 1) || (SizeY < 1) || (SizeZ < 1)) - { - LOG("Dimensions are invalid in the schematic file: %d, %d, %d", SizeX, SizeY, SizeZ); - return false; - } - - int TBlockTypes = a_NBT.FindChildByName(a_NBT.GetRoot(), "Blocks"); - int TBlockMetas = a_NBT.FindChildByName(a_NBT.GetRoot(), "Data"); - if ((TBlockTypes < 0) || (a_NBT.GetType(TBlockTypes) != TAG_ByteArray)) - { - LOG("BlockTypes are invalid in the schematic file: %d", TBlockTypes); - return false; - } - bool AreMetasPresent = (TBlockMetas > 0) && (a_NBT.GetType(TBlockMetas) == TAG_ByteArray); - - Clear(); - SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (baTypes | baMetas) : baTypes); - - // Copy the block types and metas: - int NumBytes = m_SizeX * m_SizeY * m_SizeZ; - if (a_NBT.GetDataLength(TBlockTypes) < NumBytes) - { - LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.", - NumBytes, a_NBT.GetDataLength(TBlockTypes) - ); - NumBytes = a_NBT.GetDataLength(TBlockTypes); - } - memcpy(m_BlockTypes, a_NBT.GetData(TBlockTypes), NumBytes); - - if (AreMetasPresent) - { - int NumBytes = m_SizeX * m_SizeY * m_SizeZ; - if (a_NBT.GetDataLength(TBlockMetas) < NumBytes) - { - LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.", - NumBytes, a_NBT.GetDataLength(TBlockMetas) - ); - NumBytes = a_NBT.GetDataLength(TBlockMetas); - } - memcpy(m_BlockMetas, a_NBT.GetData(TBlockMetas), NumBytes); - } - - return true; -} - - - - void cBlockArea::RelSetData( int a_RelX, int a_RelY, int a_RelZ, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, diff --git a/src/BlockArea.h b/src/BlockArea.h index ae23c76c6..59bc0f241 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -15,14 +15,6 @@ #include "ForEachChunkProvider.h" - -// fwd: FastNBT.h -class cParsedNBT; - - - - - // tolua_begin class cBlockArea { @@ -82,12 +74,6 @@ public: /// For testing purposes only, dumps the area into a file. void DumpToRawFile(const AString & a_FileName); - /// Loads an area from a .schematic file. Returns true if successful - bool LoadFromSchematicFile(const AString & a_FileName); - - /// Saves the area into a .schematic file. Returns true if successful - bool SaveToSchematicFile(const AString & a_FileName); - /// Crops the internal contents by the specified amount of blocks from each border. void Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ); @@ -230,6 +216,7 @@ public: protected: friend class cChunkDesc; + friend class cSchematicFileSerializer; class cChunkReader : public cChunkDataCallback @@ -288,9 +275,6 @@ protected: // Expand helpers: void ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ); void ExpandNibbles (NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ); - - /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful. - bool LoadFromSchematicNBT(cParsedNBT & a_NBT); /// Sets the specified datatypes at the specified location. void RelSetData( diff --git a/src/WorldStorage/SchematicFileSerilizer.cpp b/src/WorldStorage/SchematicFileSerilizer.cpp new file mode 100644 index 000000000..bce0119ec --- /dev/null +++ b/src/WorldStorage/SchematicFileSerilizer.cpp @@ -0,0 +1,155 @@ + +bool cSchematicFileSerializer::LoadFromSchematicFile(const AString & a_FileName) +{ + // Un-GZip the contents: + AString Contents; + cGZipFile File; + if (!File.Open(a_FileName, cGZipFile::fmRead)) + { + LOG("Cannot open the schematic file \"%s\".", a_FileName.c_str()); + return false; + } + int NumBytesRead = File.ReadRestOfFile(Contents); + if (NumBytesRead < 0) + { + LOG("Cannot read GZipped data in the schematic file \"%s\", error %d", a_FileName.c_str(), NumBytesRead); + return false; + } + File.Close(); + + // Parse the NBT: + cParsedNBT NBT(Contents.data(), Contents.size()); + if (!NBT.IsValid()) + { + LOG("Cannot parse the NBT in the schematic file \"%s\".", a_FileName.c_str()); + return false; + } + + return LoadFromSchematicNBT(NBT); +} + +bool cSchematicFileSerializer::SaveToSchematicFile(const AString & a_FileName) +{ + cFastNBTWriter Writer("Schematic"); + Writer.AddShort("Width", m_SizeX); + Writer.AddShort("Height", m_SizeY); + Writer.AddShort("Length", m_SizeZ); + Writer.AddString("Materials", "Alpha"); + if (HasBlockTypes()) + { + Writer.AddByteArray("Blocks", (const char *)m_BlockTypes, GetBlockCount()); + } + else + { + AString Dummy(GetBlockCount(), 0); + Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size()); + } + if (HasBlockMetas()) + { + Writer.AddByteArray("Data", (const char *)m_BlockMetas, GetBlockCount()); + } + else + { + AString Dummy(GetBlockCount(), 0); + Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); + } + // TODO: Save entities and block entities + Writer.BeginList("Entities", TAG_Compound); + Writer.EndList(); + Writer.BeginList("TileEntities", TAG_Compound); + Writer.EndList(); + Writer.Finish(); + + // Save to file + cGZipFile File; + if (!File.Open(a_FileName, cGZipFile::fmWrite)) + { + LOG("Cannot open file \"%s\" for writing.", a_FileName.c_str()); + return false; + } + if (!File.Write(Writer.GetResult())) + { + LOG("Cannot write data to file \"%s\".", a_FileName.c_str()); + return false; + } + return true; +} + +bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT) +{ + int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials"); + if ((TMaterials > 0) && (a_NBT.GetType(TMaterials) == TAG_String)) + { + AString Materials = a_NBT.GetString(TMaterials); + if (Materials.compare("Alpha") != 0) + { + LOG("Materials tag is present and \"%s\" instead of \"Alpha\". Possibly a wrong-format schematic file.", Materials.c_str()); + return false; + } + } + int TSizeX = a_NBT.FindChildByName(a_NBT.GetRoot(), "Width"); + int TSizeY = a_NBT.FindChildByName(a_NBT.GetRoot(), "Height"); + int TSizeZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "Length"); + if ( + (TSizeX < 0) || (TSizeY < 0) || (TSizeZ < 0) || + (a_NBT.GetType(TSizeX) != TAG_Short) || + (a_NBT.GetType(TSizeY) != TAG_Short) || + (a_NBT.GetType(TSizeZ) != TAG_Short) + ) + { + LOG("Dimensions are missing from the schematic file (%d, %d, %d), (%d, %d, %d)", + TSizeX, TSizeY, TSizeZ, + a_NBT.GetType(TSizeX), a_NBT.GetType(TSizeY), a_NBT.GetType(TSizeZ) + ); + return false; + } + + int SizeX = a_NBT.GetShort(TSizeX); + int SizeY = a_NBT.GetShort(TSizeY); + int SizeZ = a_NBT.GetShort(TSizeZ); + if ((SizeX < 1) || (SizeY < 1) || (SizeZ < 1)) + { + LOG("Dimensions are invalid in the schematic file: %d, %d, %d", SizeX, SizeY, SizeZ); + return false; + } + + int TBlockTypes = a_NBT.FindChildByName(a_NBT.GetRoot(), "Blocks"); + int TBlockMetas = a_NBT.FindChildByName(a_NBT.GetRoot(), "Data"); + if ((TBlockTypes < 0) || (a_NBT.GetType(TBlockTypes) != TAG_ByteArray)) + { + LOG("BlockTypes are invalid in the schematic file: %d", TBlockTypes); + return false; + } + bool AreMetasPresent = (TBlockMetas > 0) && (a_NBT.GetType(TBlockMetas) == TAG_ByteArray); + + Clear(); + SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (baTypes | baMetas) : baTypes); + + // Copy the block types and metas: + int NumBytes = m_SizeX * m_SizeY * m_SizeZ; + if (a_NBT.GetDataLength(TBlockTypes) < NumBytes) + { + LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.", + NumBytes, a_NBT.GetDataLength(TBlockTypes) + ); + NumBytes = a_NBT.GetDataLength(TBlockTypes); + } + memcpy(m_BlockTypes, a_NBT.GetData(TBlockTypes), NumBytes); + + if (AreMetasPresent) + { + int NumBytes = m_SizeX * m_SizeY * m_SizeZ; + if (a_NBT.GetDataLength(TBlockMetas) < NumBytes) + { + LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.", + NumBytes, a_NBT.GetDataLength(TBlockMetas) + ); + NumBytes = a_NBT.GetDataLength(TBlockMetas); + } + memcpy(m_BlockMetas, a_NBT.GetData(TBlockMetas), NumBytes); + } + + return true; +} + + diff --git a/src/WorldStorage/SchematicFileSerilizer.h b/src/WorldStorage/SchematicFileSerilizer.h new file mode 100644 index 000000000..b8a7162c6 --- /dev/null +++ b/src/WorldStorage/SchematicFileSerilizer.h @@ -0,0 +1,20 @@ + +#include "../BlockArea.h" + +// fwd: FastNBT.h +class cParsedNBT; + +class cSchematicFileSerializer +{ +public: + + /// Loads an area from a .schematic file. Returns true if successful + static bool LoadFromSchematicFile(const AString & a_FileName); + + /// Saves the area into a .schematic file. Returns true if successful + static bool SaveToSchematicFile(const AString & a_FileName); + +private: + /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful. + static bool LoadFromSchematicNBT(cBlockArea& a_BlockArea, cParsedNBT & a_NBT); +}; -- cgit v1.2.3 From ca3389231e111d8ca0bf4ca60ae4f96896da48b0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 20 Jan 2014 10:15:19 -0800 Subject: Actually implemented interfaces --- src/ForEachChunkProvider.h | 4 +++ src/World.h | 1 + src/WorldStorage/SchematicFileSerilizer.cpp | 45 +++++++++++++++++------------ src/WorldStorage/SchematicFileSerilizer.h | 4 +-- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/ForEachChunkProvider.h b/src/ForEachChunkProvider.h index 9092fcb0a..70cd2196a 100644 --- a/src/ForEachChunkProvider.h +++ b/src/ForEachChunkProvider.h @@ -1,4 +1,8 @@ +#pragma once + +class cChunkDataCallback; + class cBlockArea; class cForEachChunkProvider diff --git a/src/World.h b/src/World.h index 9d342aceb..f0dd45c90 100644 --- a/src/World.h +++ b/src/World.h @@ -22,6 +22,7 @@ #include "Item.h" #include "Mobs/Monster.h" #include "Entities/ProjectileEntity.h" +#include "ForEachChunkProvider.h" diff --git a/src/WorldStorage/SchematicFileSerilizer.cpp b/src/WorldStorage/SchematicFileSerilizer.cpp index bce0119ec..df68f3436 100644 --- a/src/WorldStorage/SchematicFileSerilizer.cpp +++ b/src/WorldStorage/SchematicFileSerilizer.cpp @@ -1,5 +1,12 @@ -bool cSchematicFileSerializer::LoadFromSchematicFile(const AString & a_FileName) +#include "Globals.h" + +#include "OSSupport/GZipFile.h" +#include "FastNBT.h" + +#include "SchematicFileSerilizer.h" + +bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName) { // Un-GZip the contents: AString Contents; @@ -25,32 +32,32 @@ bool cSchematicFileSerializer::LoadFromSchematicFile(const AString & a_FileName) return false; } - return LoadFromSchematicNBT(NBT); + return LoadFromSchematicNBT(a_BlockArea, NBT); } -bool cSchematicFileSerializer::SaveToSchematicFile(const AString & a_FileName) +bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName) { cFastNBTWriter Writer("Schematic"); - Writer.AddShort("Width", m_SizeX); - Writer.AddShort("Height", m_SizeY); - Writer.AddShort("Length", m_SizeZ); + Writer.AddShort("Width", a_BlockArea.m_SizeX); + Writer.AddShort("Height", a_BlockArea.m_SizeY); + Writer.AddShort("Length", a_BlockArea.m_SizeZ); Writer.AddString("Materials", "Alpha"); - if (HasBlockTypes()) + if (a_BlockArea.HasBlockTypes()) { - Writer.AddByteArray("Blocks", (const char *)m_BlockTypes, GetBlockCount()); + Writer.AddByteArray("Blocks", (const char *)a_BlockArea.m_BlockTypes, a_BlockArea.GetBlockCount()); } else { - AString Dummy(GetBlockCount(), 0); + AString Dummy(a_BlockArea.GetBlockCount(), 0); Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size()); } - if (HasBlockMetas()) + if (a_BlockArea.HasBlockMetas()) { - Writer.AddByteArray("Data", (const char *)m_BlockMetas, GetBlockCount()); + Writer.AddByteArray("Data", (const char *)a_BlockArea.m_BlockMetas, a_BlockArea.GetBlockCount()); } else { - AString Dummy(GetBlockCount(), 0); + AString Dummy(a_BlockArea.GetBlockCount(), 0); Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); } // TODO: Save entities and block entities @@ -75,7 +82,7 @@ bool cSchematicFileSerializer::SaveToSchematicFile(const AString & a_FileName) return true; } -bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT) +bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea& a_BlockArea, cParsedNBT & a_NBT) { int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials"); if ((TMaterials > 0) && (a_NBT.GetType(TMaterials) == TAG_String)) @@ -122,11 +129,11 @@ bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT) } bool AreMetasPresent = (TBlockMetas > 0) && (a_NBT.GetType(TBlockMetas) == TAG_ByteArray); - Clear(); - SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (baTypes | baMetas) : baTypes); + a_BlockArea.Clear(); + a_BlockArea.SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes); // Copy the block types and metas: - int NumBytes = m_SizeX * m_SizeY * m_SizeZ; + int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ; if (a_NBT.GetDataLength(TBlockTypes) < NumBytes) { LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.", @@ -134,11 +141,11 @@ bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT) ); NumBytes = a_NBT.GetDataLength(TBlockTypes); } - memcpy(m_BlockTypes, a_NBT.GetData(TBlockTypes), NumBytes); + memcpy(a_BlockArea.m_BlockTypes, a_NBT.GetData(TBlockTypes), NumBytes); if (AreMetasPresent) { - int NumBytes = m_SizeX * m_SizeY * m_SizeZ; + int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ; if (a_NBT.GetDataLength(TBlockMetas) < NumBytes) { LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.", @@ -146,7 +153,7 @@ bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT) ); NumBytes = a_NBT.GetDataLength(TBlockMetas); } - memcpy(m_BlockMetas, a_NBT.GetData(TBlockMetas), NumBytes); + memcpy(a_BlockArea.m_BlockMetas, a_NBT.GetData(TBlockMetas), NumBytes); } return true; diff --git a/src/WorldStorage/SchematicFileSerilizer.h b/src/WorldStorage/SchematicFileSerilizer.h index b8a7162c6..e4dcf3eb9 100644 --- a/src/WorldStorage/SchematicFileSerilizer.h +++ b/src/WorldStorage/SchematicFileSerilizer.h @@ -9,10 +9,10 @@ class cSchematicFileSerializer public: /// Loads an area from a .schematic file. Returns true if successful - static bool LoadFromSchematicFile(const AString & a_FileName); + static bool LoadFromSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName); /// Saves the area into a .schematic file. Returns true if successful - static bool SaveToSchematicFile(const AString & a_FileName); + static bool SaveToSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName); private: /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful. -- cgit v1.2.3 From 9c93ab15ab6ea4131de5af275fdc759bb49ec648 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Mon, 20 Jan 2014 19:02:37 +0000 Subject: Fix a crash but somewhere... --- src/Protocol/Protocol17x.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index e5a380f8a..fefcb9396 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1,4 +1,3 @@ - // Protocol17x.cpp /* @@ -124,7 +123,7 @@ void cProtocol172::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, cha void cProtocol172::SendBlockBreakAnim(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) { cPacketizer Pkt(*this, 0x25); // Block Break Animation packet - Pkt.WriteInt(a_EntityID); + Pkt.WriteVarInt(a_EntityID); Pkt.WriteInt(a_BlockX); Pkt.WriteInt(a_BlockY); Pkt.WriteInt(a_BlockZ); -- cgit v1.2.3 From aa61f55b743a8ecf3cd8e1f99e1d9a0308f6d014 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 21 Jan 2014 15:58:17 +0200 Subject: Scoreboard protocol support --- src/ClientHandle.cpp | 30 +++++++++++++++ src/ClientHandle.h | 4 ++ src/Entities/Player.cpp | 17 ++++++--- src/Protocol/Protocol.h | 4 ++ src/Protocol/Protocol125.h | 7 +++- src/Protocol/Protocol15x.cpp | 54 ++++++++++++++++++++++++++- src/Protocol/Protocol15x.h | 3 ++ src/Protocol/Protocol17x.cpp | 40 ++++++++++++++++++++ src/Protocol/Protocol17x.h | 3 ++ src/Protocol/ProtocolRecognizer.cpp | 32 +++++++++++++++- src/Protocol/ProtocolRecognizer.h | 3 ++ src/Scoreboard.cpp | 66 +++++++++++++++++++++++++++++---- src/Scoreboard.h | 13 ++++++- src/Server.cpp | 2 +- src/World.cpp | 57 +++++++++++++++++++++++++++- src/World.h | 5 ++- src/WorldStorage/ScoreboardSerializer.h | 4 ++ 17 files changed, 321 insertions(+), 23 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index faf583fbb..30d1bdaa4 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -267,6 +267,9 @@ void cClientHandle::Authenticate(void) m_Player->Initialize(World); m_State = csAuthenticated; + // Query player team + m_Player->UpdateTeam(); + cRoot::Get()->GetPluginManager()->CallHookPlayerSpawned(*m_Player); } @@ -2105,6 +2108,33 @@ void cClientHandle::SendExperienceOrb(const cExpOrb & a_ExpOrb) +void cClientHandle::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) +{ + m_Protocol->SendScoreboardObjective(a_Name, a_DisplayName, a_Mode); +} + + + + + +void cClientHandle::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) +{ + m_Protocol->SendScoreUpdate(a_Objective, a_Player, a_Score, a_Mode); +} + + + + + +void cClientHandle::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) +{ + m_Protocol->SendDisplayObjective(a_Objective, a_Display); +} + + + + + void cClientHandle::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) { m_Protocol->SendSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 373ca9e2e..636934f6f 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -16,6 +16,7 @@ #include "OSSupport/SocketThreads.h" #include "ChunkDef.h" #include "ByteBuffer.h" +#include "Scoreboard.h" @@ -125,6 +126,9 @@ public: void SendRespawn (void); void SendExperience (void); void SendExperienceOrb (const cExpOrb & a_ExpOrb); + void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode); + void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode); + void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display); void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch); // a_Src coords are Block * 8 void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data); void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 285aefd25..c6b24a465 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -111,8 +111,6 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) m_LastJumpHeight = (float)(GetPosY()); m_LastGroundHeight = (float)(GetPosY()); m_Stance = GetPosY() + 1.62; - - // UpdateTeam(); cRoot::Get()->GetServer()->PlayerCreated(this); } @@ -867,10 +865,10 @@ void cPlayer::KilledBy(cEntity * a_Killer) } } IncrementCounter (GetName()); - cScoreboard* Scoreboard = m_World->GetScoreBoard(); + cScoreboard & Scoreboard = m_World->GetScoreBoard(); // Update scoreboard objectives - Scoreboard->ForEachObjectiveWith(cObjective::E_TYPE_DEATH_COUNT, IncrementCounter); + Scoreboard.ForEachObjectiveWith(cObjective::E_TYPE_DEATH_COUNT, IncrementCounter); } @@ -977,9 +975,16 @@ void cPlayer::SetTeam(cTeam * a_Team) cTeam * cPlayer::UpdateTeam(void) { - cScoreboard * Scoreboard = m_World->GetScoreBoard(); + if (m_World == NULL) + { + SetTeam(NULL); + } + else + { + cScoreboard & Scoreboard = m_World->GetScoreBoard(); - m_Team = Scoreboard->QueryPlayerTeam(GetName()); + SetTeam(Scoreboard.QueryPlayerTeam(GetName())); + } return m_Team; } diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 3293da32c..0a213f476 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -12,6 +12,7 @@ #include "../Defines.h" #include "../Endianness.h" +#include "../Scoreboard.h" @@ -92,6 +93,9 @@ public: virtual void SendRespawn (void) = 0; virtual void SendExperience (void) = 0; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) = 0; + virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) = 0; + virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) = 0; + virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) = 0; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) = 0; // a_Src coords are Block * 8 virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) = 0; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0; diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index d0e5c9428..fb08fb120 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -68,6 +68,9 @@ public: virtual void SendRespawn (void) override; virtual void SendExperience (void) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; + virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override {} // This protocol doesn't support such message + virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override {} // This protocol doesn't support such message + virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override {} // This protocol doesn't support such message virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; @@ -82,8 +85,8 @@ public: virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override; virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) override; virtual void SendWeather (eWeather a_Weather) override; - virtual void SendWholeInventory (const cWindow & a_Window) override; - virtual void SendWindowClose (const cWindow & a_Window) override; + virtual void SendWholeInventory (const cWindow & a_Window) override; + virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (const cWindow & a_Window) override; virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; diff --git a/src/Protocol/Protocol15x.cpp b/src/Protocol/Protocol15x.cpp index 0f1e59f10..c33aec7d5 100644 --- a/src/Protocol/Protocol15x.cpp +++ b/src/Protocol/Protocol15x.cpp @@ -35,8 +35,11 @@ Implements the 1.5.x protocol classes: enum { - PACKET_WINDOW_OPEN = 0x64, - PACKET_PARTICLE_EFFECT = 0x3F, + PACKET_WINDOW_OPEN = 0x64, + PACKET_PARTICLE_EFFECT = 0x3F, + PACKET_SCOREBOARD_OBJECTIVE = 0x3B, + PACKET_SCORE_UPDATE = 0x3C, + PACKET_DISPLAY_OBJECTIVE = 0x3D } ; @@ -97,6 +100,53 @@ void cProtocol150::SendParticleEffect(const AString & a_ParticleName, float a_Sr +void cProtocol150::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) +{ + cCSLock Lock(m_CSPacket); + WriteByte(PACKET_SCOREBOARD_OBJECTIVE); + WriteString(a_Name); + WriteString(a_DisplayName); + WriteByte(a_Mode); + Flush(); +} + + + + + +void cProtocol150::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) +{ + cCSLock Lock(m_CSPacket); + WriteByte(PACKET_SCORE_UPDATE); + WriteString(a_Player); + WriteByte(a_Mode); + + if (a_Mode != 1) + { + WriteString(a_Objective); + WriteInt((int) a_Score); + } + + Flush(); +} + + + + + +void cProtocol150::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) +{ + cCSLock Lock(m_CSPacket); + WriteByte(PACKET_DISPLAY_OBJECTIVE); + WriteByte((int) a_Display); + WriteString(a_Objective); + Flush(); +} + + + + + int cProtocol150::ParseWindowClick(void) { HANDLE_PACKET_READ(ReadChar, char, WindowID); diff --git a/src/Protocol/Protocol15x.h b/src/Protocol/Protocol15x.h index 0074b3a83..0d171a67c 100644 --- a/src/Protocol/Protocol15x.h +++ b/src/Protocol/Protocol15x.h @@ -30,6 +30,9 @@ public: virtual void SendWindowOpen (const cWindow & a_Window) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override; + virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; + virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override; + virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override; virtual int ParseWindowClick(void); } ; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 5b3a79555..d5ed1a0aa 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -705,6 +705,46 @@ void cProtocol172::SendExperienceOrb(const cExpOrb & a_ExpOrb) +void cProtocol172::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) +{ + cPacketizer Pkt(*this, 0x3b); + Pkt.WriteString(a_Name); + Pkt.WriteString(a_DisplayName); + Pkt.WriteByte(a_Mode); +} + + + + + +void cProtocol172::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) +{ + cPacketizer Pkt(*this, 0x3c); + Pkt.WriteString(a_Player); + Pkt.WriteByte(a_Mode); + + if (a_Mode != 1) + { + Pkt.WriteString(a_Objective); + Pkt.WriteInt((int) a_Score); + } +} + + + + + +void cProtocol172::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) +{ + cPacketizer Pkt(*this, 0x3d); + Pkt.WriteByte((int) a_Display); + Pkt.WriteString(a_Objective); +} + + + + + void cProtocol172::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) // a_Src coords are Block * 8 { cPacketizer Pkt(*this, 0x29); // Sound Effect packet diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 07dba834b..bbbf820a6 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -92,6 +92,9 @@ public: virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 virtual void SendExperience (void) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; + virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; + virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override; + virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnMob (const cMonster & a_Mob) override; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index a21f4f042..04db2a995 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -526,6 +526,36 @@ void cProtocolRecognizer::SendExperienceOrb(const cExpOrb & a_ExpOrb) +void cProtocolRecognizer::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendScoreboardObjective(a_Name, a_DisplayName, a_Mode); +} + + + + + +void cProtocolRecognizer::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendScoreUpdate(a_Objective, a_Player, a_Score, a_Mode); +} + + + + + +void cProtocolRecognizer::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendDisplayObjective(a_Objective, a_Display); +} + + + + + void cProtocolRecognizer::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) { ASSERT(m_Protocol != NULL); @@ -797,7 +827,7 @@ bool cProtocolRecognizer::TryRecognizeLengthlessProtocol(void) } switch (ch) { - case PROTO_VERSION_1_3_2: + case PROTO_VERSION_1_3_2: { m_Protocol = new cProtocol132(m_Client); return true; diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index e94f4cde8..0b811f4c6 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -103,6 +103,9 @@ public: virtual void SendRespawn (void) override; virtual void SendExperience (void) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; + virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; + virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override; + virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 3ddf146a6..7fa1eab99 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -6,6 +6,7 @@ #include "Globals.h" #include "Scoreboard.h" +#include "World.h" @@ -72,11 +73,13 @@ cObjective::eType cObjective::StringToType(const AString & a_Name) -cObjective::cObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type) +cObjective::cObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type, cWorld * a_World) : m_DisplayName(a_DisplayName) , m_Name(a_Name) , m_Type(a_Type) -{} + , m_World(a_World) +{ +} @@ -84,6 +87,11 @@ cObjective::cObjective(const AString & a_Name, const AString & a_DisplayName, cO void cObjective::Reset(void) { + for (cScoreMap::iterator it = m_Scores.begin(); it != m_Scores.end(); ++it) + { + m_World->BroadcastScoreUpdate(m_Name, it->first, 0, 1); + } + m_Scores.clear(); } @@ -112,6 +120,8 @@ cObjective::Score cObjective::GetScore(const AString & a_Name) const void cObjective::SetScore(const AString & a_Name, cObjective::Score a_Score) { m_Scores[a_Name] = a_Score; + + m_World->BroadcastScoreUpdate(m_Name, a_Name, a_Score, 0); } @@ -121,6 +131,8 @@ void cObjective::SetScore(const AString & a_Name, cObjective::Score a_Score) void cObjective::ResetScore(const AString & a_Name) { m_Scores.erase(a_Name); + + m_World->BroadcastScoreUpdate(m_Name, a_Name, 0, 1); } @@ -132,7 +144,7 @@ cObjective::Score cObjective::AddScore(const AString & a_Name, cObjective::Score // TODO 2014-01-19 xdot: Potential optimization - Reuse iterator Score NewScore = m_Scores[a_Name] + a_Delta; - m_Scores[a_Name] = NewScore; + SetScore(a_Name, NewScore); return NewScore; } @@ -146,7 +158,7 @@ cObjective::Score cObjective::SubScore(const AString & a_Name, cObjective::Score // TODO 2014-01-19 xdot: Potential optimization - Reuse iterator Score NewScore = m_Scores[a_Name] - a_Delta; - m_Scores[a_Name] = NewScore; + SetScore(a_Name, NewScore); return NewScore; } @@ -155,6 +167,17 @@ cObjective::Score cObjective::SubScore(const AString & a_Name, cObjective::Score +void cObjective::SetDisplayName(const AString & a_Name) +{ + m_DisplayName = a_Name; + + m_World->BroadcastScoreboardObjective(m_Name, m_DisplayName, 2); +} + + + + + cTeam::cTeam(const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix) : m_AllowsFriendlyFire(true) @@ -215,7 +238,7 @@ unsigned int cTeam::GetNumPlayers(void) const -cScoreboard::cScoreboard() +cScoreboard::cScoreboard(cWorld * a_World) : m_World(a_World) { for (int i = 0; i < (int) E_DISPLAY_SLOT_COUNT; ++i) { @@ -229,11 +252,21 @@ cScoreboard::cScoreboard() cObjective* cScoreboard::RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type) { - cObjective Objective(a_Name, a_DisplayName, a_Type); + cObjective Objective(a_Name, a_DisplayName, a_Type, m_World); std::pair Status = m_Objectives.insert(cNamedObjective(a_Name, Objective)); - return Status.second ? &Status.first->second : NULL; + if (Status.second) + { + ASSERT(m_World != NULL); + m_World->BroadcastScoreboardObjective(a_Name, a_DisplayName, 0); + + return &Status.first->second; + } + else + { + return NULL; + } } @@ -242,6 +275,8 @@ cObjective* cScoreboard::RegisterObjective(const AString & a_Name, const AString bool cScoreboard::RemoveObjective(const AString & a_Name) { + cCSLock Lock(m_CSObjectives); + cObjectiveMap::iterator it = m_Objectives.find(a_Name); if (it == m_Objectives.end()) @@ -251,6 +286,9 @@ bool cScoreboard::RemoveObjective(const AString & a_Name) m_Objectives.erase(it); + ASSERT(m_World != NULL); + m_World->BroadcastScoreboardObjective(it->second.GetName(), it->second.GetDisplayName(), 1); + return true; } @@ -260,6 +298,8 @@ bool cScoreboard::RemoveObjective(const AString & a_Name) cObjective * cScoreboard::GetObjective(const AString & a_Name) { + cCSLock Lock(m_CSObjectives); + cObjectiveMap::iterator it = m_Objectives.find(a_Name); if (it == m_Objectives.end()) @@ -294,6 +334,8 @@ cTeam * cScoreboard::RegisterTeam( bool cScoreboard::RemoveTeam(const AString & a_Name) { + cCSLock Lock(m_CSTeams); + cTeamMap::iterator it = m_Teams.find(a_Name); if (it == m_Teams.end()) @@ -312,6 +354,8 @@ bool cScoreboard::RemoveTeam(const AString & a_Name) cTeam * cScoreboard::GetTeam(const AString & a_Name) { + cCSLock Lock(m_CSTeams); + cTeamMap::iterator it = m_Teams.find(a_Name); if (it == m_Teams.end()) @@ -330,6 +374,8 @@ cTeam * cScoreboard::GetTeam(const AString & a_Name) cTeam * cScoreboard::QueryPlayerTeam(const AString & a_Name) { + cCSLock Lock(m_CSTeams); + for (cTeamMap::iterator it = m_Teams.begin(); it != m_Teams.end(); ++it) { if (it->second.HasPlayer(a_Name)) @@ -352,6 +398,10 @@ void cScoreboard::SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot) cObjective * Objective = GetObjective(a_Objective); m_Display[a_Slot] = Objective; + + ASSERT(m_World != NULL); + m_World->BroadcastDisplayObjective(Objective ? a_Objective : "", a_Slot); + } @@ -371,6 +421,8 @@ cObjective * cScoreboard::GetObjectiveIn(eDisplaySlot a_Slot) void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback) { + cCSLock Lock(m_CSObjectives); + for (cObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it) { if (it->second.GetType() == a_Type) diff --git a/src/Scoreboard.h b/src/Scoreboard.h index 2ce614de7..b92642a9a 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -14,6 +14,7 @@ class cObjective; +class cWorld; typedef cItemCallback cObjectiveCallback; @@ -54,7 +55,7 @@ public: public: - cObjective(const AString & a_Name, const AString & a_DisplayName, eType a_Type); + cObjective(const AString & a_Name, const AString & a_DisplayName, eType a_Type, cWorld * a_World); eType GetType(void) const { return m_Type; } @@ -79,6 +80,8 @@ public: /// Subtracts a_Delta and returns the new score Score SubScore(const AString & a_Name, Score a_Delta); + void SetDisplayName(const AString & a_Name); + private: typedef std::pair cTrackedPlayer; @@ -92,6 +95,8 @@ private: eType m_Type; + cWorld * m_World; + friend class cScoreboardSerializer; }; @@ -180,7 +185,7 @@ public: public: - cScoreboard(); + cScoreboard(cWorld * a_World); /// Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision cObjective * RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type); @@ -223,10 +228,14 @@ private: typedef std::map cTeamMap; // TODO 2014-01-19 xdot: Potential optimization - Sort objectives based on type + cCriticalSection m_CSObjectives; cObjectiveMap m_Objectives; + cCriticalSection m_CSTeams; cTeamMap m_Teams; + cWorld * m_World; + cObjective* m_Display[E_DISPLAY_SLOT_COUNT]; friend class cScoreboardSerializer; diff --git a/src/Server.cpp b/src/Server.cpp index 5280270b9..eb76fcaeb 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -501,7 +501,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac } } #endif - + if (cPluginManager::Get()->ExecuteConsoleCommand(split, a_Output)) { a_Output.Finished(); diff --git a/src/World.cpp b/src/World.cpp index 8e7b6171c..fb20e2242 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -242,7 +242,8 @@ cWorld::cWorld(const AString & a_WorldName) : m_Weather(eWeather_Sunny), m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :) m_GeneratorCallbacks(*this), - m_TickThread(*this) + m_TickThread(*this), + m_Scoreboard(this) { LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str()); @@ -1982,6 +1983,60 @@ void cWorld::BroadcastRemoveEntityEffect(const cEntity & a_Entity, int a_EffectI +void cWorld::BroadcastScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) +{ + cCSLock Lock(m_CSPlayers); + for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) + { + cClientHandle * ch = (*itr)->GetClientHandle(); + if ((ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed()) + { + continue; + } + ch->SendScoreboardObjective(a_Name, a_DisplayName, a_Mode); + } +} + + + + + +void cWorld::BroadcastScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) +{ + cCSLock Lock(m_CSPlayers); + for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) + { + cClientHandle * ch = (*itr)->GetClientHandle(); + if ((ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed()) + { + continue; + } + ch->SendScoreUpdate(a_Objective, a_Player, a_Score, a_Mode); + } +} + + + + + +void cWorld::BroadcastDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) +{ + cCSLock Lock(m_CSPlayers); + for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) + { + cClientHandle * ch = (*itr)->GetClientHandle(); + if ((ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed()) + { + continue; + } + ch->SendDisplayObjective(a_Objective, a_Display); + } +} + + + + + void cWorld::BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude) { m_ChunkMap->BroadcastSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch, a_Exclude); diff --git a/src/World.h b/src/World.h index 1dcbac8e4..51c3af8cb 100644 --- a/src/World.h +++ b/src/World.h @@ -179,6 +179,9 @@ public: void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL); void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL); + void BroadcastScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode); + void BroadcastScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode); + void BroadcastDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display); void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // tolua_export a_Src coords are Block * 8 void BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL); // tolua_export void BroadcastSpawnEntity (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); @@ -516,7 +519,7 @@ public: const AString & GetIniFileName(void) const {return m_IniFileName; } /// Returns the associated scoreboard instance - cScoreboard* GetScoreBoard(void) { return &m_Scoreboard; } + cScoreboard & GetScoreBoard(void) { return m_Scoreboard; } // tolua_end diff --git a/src/WorldStorage/ScoreboardSerializer.h b/src/WorldStorage/ScoreboardSerializer.h index 2a4e0767e..048fa3ab4 100644 --- a/src/WorldStorage/ScoreboardSerializer.h +++ b/src/WorldStorage/ScoreboardSerializer.h @@ -24,6 +24,7 @@ class cScoreboard; class cScoreboardSerializer { public: + cScoreboardSerializer(const AString & a_WorldName, cScoreboard* a_ScoreBoard); /// Try to load the scoreboard @@ -32,6 +33,7 @@ public: /// Try to save the scoreboard bool Save(void); + private: void SaveScoreboardToNBT(cFastNBTWriter & a_Writer); @@ -41,6 +43,8 @@ private: cScoreboard* m_ScoreBoard; AString m_Path; + + } ; -- cgit v1.2.3 From fa4750f015f1fed0937ba9fe80fc183c27d9e929 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 21 Jan 2014 19:43:13 +0200 Subject: Scoreboard SendTo() --- src/ClientHandle.cpp | 3 +++ src/Protocol/Protocol17x.cpp | 6 ++--- src/Scoreboard.cpp | 54 +++++++++++++++++++++++++++++++++++++++++--- src/Scoreboard.h | 17 ++++++++++++++ 4 files changed, 74 insertions(+), 6 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 30d1bdaa4..b06dbc84a 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -270,6 +270,9 @@ void cClientHandle::Authenticate(void) // Query player team m_Player->UpdateTeam(); + // Send scoreboard data + World->GetScoreBoard().SendTo(*this); + cRoot::Get()->GetPluginManager()->CallHookPlayerSpawned(*m_Player); } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index d5ed1a0aa..926be6027 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -707,7 +707,7 @@ void cProtocol172::SendExperienceOrb(const cExpOrb & a_ExpOrb) void cProtocol172::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) { - cPacketizer Pkt(*this, 0x3b); + cPacketizer Pkt(*this, 0x3B); Pkt.WriteString(a_Name); Pkt.WriteString(a_DisplayName); Pkt.WriteByte(a_Mode); @@ -719,7 +719,7 @@ void cProtocol172::SendScoreboardObjective(const AString & a_Name, const AString void cProtocol172::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) { - cPacketizer Pkt(*this, 0x3c); + cPacketizer Pkt(*this, 0x3C); Pkt.WriteString(a_Player); Pkt.WriteByte(a_Mode); @@ -736,7 +736,7 @@ void cProtocol172::SendScoreUpdate(const AString & a_Objective, const AString & void cProtocol172::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) { - cPacketizer Pkt(*this, 0x3d); + cPacketizer Pkt(*this, 0x3D); Pkt.WriteByte((int) a_Display); Pkt.WriteString(a_Objective); } diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 7fa1eab99..e6812d3d7 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -7,6 +7,7 @@ #include "Scoreboard.h" #include "World.h" +#include "ClientHandle.h" @@ -178,6 +179,20 @@ void cObjective::SetDisplayName(const AString & a_Name) +void cObjective::SendTo(cClientHandle & a_Client) +{ + a_Client.SendScoreboardObjective(m_Name, m_DisplayName, 0); + + for (cScoreMap::const_iterator it = m_Scores.begin(); it != m_Scores.end(); ++it) + { + a_Client.SendScoreUpdate(m_Name, it->first, it->second, 0); + } +} + + + + + cTeam::cTeam(const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix) : m_AllowsFriendlyFire(true) @@ -397,11 +412,19 @@ void cScoreboard::SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot) cObjective * Objective = GetObjective(a_Objective); - m_Display[a_Slot] = Objective; + SetDisplay(Objective, a_Slot); +} + + + + + +void cScoreboard::SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot) +{ + m_Display[a_Slot] = a_Objective; ASSERT(m_World != NULL); - m_World->BroadcastDisplayObjective(Objective ? a_Objective : "", a_Slot); - + m_World->BroadcastDisplayObjective(a_Objective ? a_Objective->GetName() : "", a_Slot); } @@ -440,6 +463,31 @@ void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallb +void cScoreboard::SendTo(cClientHandle & a_Client) +{ + cCSLock Lock(m_CSObjectives); + + for (cObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it) + { + it->second.SendTo(a_Client); + } + + for (int i = 0; i < (int) E_DISPLAY_SLOT_COUNT; ++i) + { + // Avoid race conditions + cObjective * Objective = m_Display[i]; + + if (Objective) + { + a_Client.SendDisplayObjective(Objective->GetName(), (eDisplaySlot) i); + } + } +} + + + + + unsigned int cScoreboard::GetNumObjectives(void) const { return m_Objectives.size(); diff --git a/src/Scoreboard.h b/src/Scoreboard.h index b92642a9a..11b456739 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -22,10 +22,13 @@ typedef cItemCallback cObjectiveCallback; +// tolua_begin class cObjective { public: + // tolua_end + typedef int Score; enum eType @@ -82,6 +85,9 @@ public: void SetDisplayName(const AString & a_Name); + /// Send this objective to the specified client + void SendTo(cClientHandle & a_Client); + private: typedef std::pair cTrackedPlayer; @@ -105,10 +111,13 @@ private: +// tolua_begin class cTeam { public: + // tolua_end + cTeam( const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix @@ -169,10 +178,13 @@ private: +// tolua_begin class cScoreboard { public: + // tolua_end + enum eDisplaySlot { E_DISPLAY_SLOT_LIST = 0, @@ -209,11 +221,16 @@ public: void SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot); + void SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot); + cObjective * GetObjectiveIn(eDisplaySlot a_Slot); /// Execute callback for each objective with the specified type void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback); + /// Send this scoreboard to the specified client + void SendTo(cClientHandle & a_Client); + unsigned int GetNumObjectives(void) const; unsigned int GetNumTeams(void) const; -- cgit v1.2.3 From 2a018cfa49e0a85d2984f6daf6ee3c3372bdafda Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 21 Jan 2014 22:59:08 +0100 Subject: Implemented cPluginManager:CallPlugin() API. This function supersedes cPlugin:Call(), is safer to use in regards to multithreading and once again removes the need for the cPlugin class being exported at all. --- MCServer/Plugins/APIDump/APIDesc.lua | 3 +- MCServer/Plugins/Debuggers/Debuggers.lua | 35 +++++- src/Bindings/LuaState.cpp | 199 ++++++++++++++++++++++++++++--- src/Bindings/LuaState.h | 143 +++++++++++++--------- src/Bindings/ManualBindings.cpp | 196 +++++++++++++++--------------- src/Bindings/PluginLua.cpp | 34 ++++++ src/Bindings/PluginLua.h | 42 ++++--- src/Bindings/PluginManager.cpp | 15 +++ src/Bindings/PluginManager.h | 56 +++++---- 9 files changed, 507 insertions(+), 216 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 347299a50..07345d51e 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1667,7 +1667,7 @@ a_Player:OpenWindow(Window); ]], Functions = { - Call = { Params = "Function name, [All the parameters divided with commas]", Notes = "This function allows you to call a function from another plugin. It can only use pass: integers, booleans, strings and usertypes (cPlayer, cEntity, cCuboid, etc.)." }, + Call = { Params = "Function name, [All the parameters divided with commas]", Notes = "(OBSOLETE) This function allows you to call a function from another plugin. It can only use pass: integers, booleans, strings and usertypes (cPlayer, cEntity, cCuboid, etc.).

This function is obsolete and unsafe, use {{cPluginManager}}:CallPlugin() instead!" }, GetDirectory = { Return = "string", Notes = "Returns the name of the folder where the plugin's files are. (APIDump)" }, GetLocalDirectory = { Notes = "OBSOLETE use GetLocalFolder instead." }, GetLocalFolder = { Return = "string", Notes = "Returns the path where the plugin's files are. (Plugins/APIDump)" }, @@ -1719,6 +1719,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); { Params = "Command, Callback, HelpString", Return = "", Notes = "(STATIC) Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command." }, { Params = "Command, Callback, HelpString", Return = "", Notes = "Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command." }, }, + CallPlugin = { Params = "PluginName, FunctionName, [FunctionArgs...]", Return = "[FunctionRets]", Notes = "(STATIC) Calls the specified function in the specified plugin, passing all the given arguments to it. If it succeeds, it returns all the values returned by that function. If it fails, returns no value at all. Note that only strings, numbers, bools, nils and classes can be used for parameters and return values; tables and functions cannot be copied across plugins." }, DisablePlugin = { Params = "PluginName", Return = "bool", Notes = "Disables a plugin specified by its name. Returns true if the plugin was disabled, false if it wasn't found or wasn't active." }, ExecuteCommand = { Params = "{{cPlayer|Player}}, CommandStr", Return = "bool", Notes = "Executes the command as if given by the specified Player. Checks permissions. Returns true if executed." }, FindPlugins = { Params = "", Return = "", Notes = "Refreshes the list of plugins to include all folders inside the Plugins folder (potentially new disabled plugins)" }, diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 2d2d2736d..624261cbf 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -64,7 +64,8 @@ function Initialize(Plugin) -- TestBlockAreas(); -- TestSQLiteBindings(); -- TestExpatBindings(); - + TestPluginCalls(); + return true end; @@ -72,6 +73,38 @@ end; +function TestPluginCalls() + -- In order to test the inter-plugin communication, we're going to call Core's ReturnColorFromChar() function + -- It is a rather simple function that doesn't need any tables as its params and returns a value, too + -- Note the signature: function ReturnColorFromChar( Split, char ) ... return cChatColog.Gray ... end + -- The Split parameter should be a table, but it is not used in that function anyway, + -- so we can get away with passing nil to it. + + -- Use the old, deprecated and unsafe method: + local Core = cPluginManager:Get():GetPlugin("Core") + if (Core ~= nil) then + LOGINFO("Calling Core::ReturnColorFromChar() the old-fashioned way...") + local Gray = Core:Call("ReturnColorFromChar", nil, "8") + if (Gray ~= cChatColor.Gray) then + LOGWARNING("Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "")) + else + LOGINFO("Call succeeded") + end + end + + -- Use the new method: + LOGINFO("Calling Core::ReturnColorFromChar() the recommended way...") + local Gray = cPluginManager:CallPlugin("Core", "ReturnColorFromChar", nil, "8") + if (Gray ~= cChatColor.Gray) then + LOGWARNING("Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "")) + else + LOGINFO("Call succeeded") + end +end + + + + function TestBlockAreas() LOG("Testing block areas..."); diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index bfee1d037..2fca7142c 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -235,7 +235,7 @@ bool cLuaState::PushFunction(const char * a_FunctionName) if (!lua_isfunction(m_LuaState, -1)) { LOGWARNING("Error in %s: Could not find function %s()", m_SubsystemName.c_str(), a_FunctionName); - lua_pop(m_LuaState, 1); + lua_pop(m_LuaState, 2); return false; } m_CurrentFunctionName.assign(a_FunctionName); @@ -258,7 +258,7 @@ bool cLuaState::PushFunction(int a_FnRef) lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, a_FnRef); // same as lua_getref() if (!lua_isfunction(m_LuaState, -1)) { - lua_pop(m_LuaState, 1); + lua_pop(m_LuaState, 2); return false; } m_CurrentFunctionName = ""; @@ -282,7 +282,7 @@ bool cLuaState::PushFunction(const cTableRef & a_TableRef) if (!lua_istable(m_LuaState, -1)) { // Not a table, bail out - lua_pop(m_LuaState, 1); + lua_pop(m_LuaState, 2); return false; } lua_getfield(m_LuaState, -1, a_TableRef.GetFnName()); @@ -742,6 +742,10 @@ bool cLuaState::CallFunction(int a_NumResults) } m_NumCurrentFunctionArgs = -1; m_CurrentFunctionName.clear(); + + // Remove the error handler from the stack: + lua_remove(m_LuaState, -a_NumResults - 1); + return true; } @@ -1025,21 +1029,184 @@ void cLuaState::LogStackTrace(lua_State * a_LuaState) AString cLuaState::GetTypeText(int a_StackPos) { - int Type = lua_type(m_LuaState, a_StackPos); - switch (Type) + return lua_typename(m_LuaState, lua_type(m_LuaState, a_StackPos)); +} + + + + + +int cLuaState::CallFunctionWithForeignParams( + const AString & a_FunctionName, + cLuaState & a_SrcLuaState, + int a_SrcParamStart, + int a_SrcParamEnd +) +{ + ASSERT(IsValid()); + ASSERT(a_SrcLuaState.IsValid()); + + // Store the stack position before any changes + int OldTop = lua_gettop(m_LuaState); + + // Push the function to call, including the error handler: + if (!PushFunction(a_FunctionName.c_str())) + { + LOGWARNING("Function '%s' not found", a_FunctionName.c_str()); + lua_pop(m_LuaState, 2); + return -1; + } + + // Copy the function parameters to the target state + if (CopyStackFrom(a_SrcLuaState, a_SrcParamStart, a_SrcParamEnd) < 0) { - case LUA_TNONE: return "TNONE"; - case LUA_TNIL: return "TNIL"; - case LUA_TBOOLEAN: return "TBOOLEAN"; - case LUA_TLIGHTUSERDATA: return "TLIGHTUSERDATA"; - case LUA_TNUMBER: return "TNUMBER"; - case LUA_TSTRING: return "TSTRING"; - case LUA_TTABLE: return "TTABLE"; - case LUA_TFUNCTION: return "TFUNCTION"; - case LUA_TUSERDATA: return "TUSERDATA"; - case LUA_TTHREAD: return "TTHREAD"; + // Something went wrong, fix the stack and exit + lua_pop(m_LuaState, 2); + return -1; + } + + // Call the function, with an error handler: + int s = lua_pcall(m_LuaState, a_SrcParamEnd - a_SrcParamStart + 1, LUA_MULTRET, OldTop); + if (ReportErrors(s)) + { + LOGWARN("Error while calling function '%s' in '%s'", a_FunctionName.c_str(), m_SubsystemName.c_str()); + // Fix the stack. + // We don't know how many values have been pushed, so just get rid of any that weren't there initially + int CurTop = lua_gettop(m_LuaState); + if (CurTop > OldTop) + { + lua_pop(m_LuaState, CurTop - OldTop); + } + return -1; } - return Printf("Unknown (%d)", Type); + + // Reset the internal checking mechanisms: + m_NumCurrentFunctionArgs = -1; + + // Remove the error handler from the stack: + lua_remove(m_LuaState, OldTop + 1); + + // Return the number of return values: + return lua_gettop(m_LuaState) - OldTop; +} + + + + + +int cLuaState::CopyStackFrom(cLuaState & a_SrcLuaState, int a_SrcStart, int a_SrcEnd) +{ + /* + // DEBUG: + LOGD("Copying stack values from %d to %d", a_SrcStart, a_SrcEnd); + a_SrcLuaState.LogStack("Src stack before copying:"); + LogStack("Dst stack before copying:"); + */ + for (int i = a_SrcStart; i <= a_SrcEnd; ++i) + { + int t = lua_type(a_SrcLuaState, i); + switch (t) + { + case LUA_TNIL: + { + lua_pushnil(m_LuaState); + break; + } + case LUA_TSTRING: + { + AString s; + a_SrcLuaState.ToString(i, s); + Push(s); + break; + } + case LUA_TBOOLEAN: + { + bool b = (tolua_toboolean(a_SrcLuaState, i, false) != 0); + Push(b); + break; + } + case LUA_TNUMBER: + { + lua_Number d = tolua_tonumber(a_SrcLuaState, i, 0); + Push(d); + break; + } + case LUA_TUSERDATA: + { + // Get the class name: + const char * type = NULL; + if (lua_getmetatable(a_SrcLuaState, i) == 0) + { + LOGWARNING("%s: Unknown class in pos %d, cannot copy.", __FUNCTION__, i); + lua_pop(m_LuaState, i - a_SrcStart); + return -1; + } + lua_rawget(a_SrcLuaState, LUA_REGISTRYINDEX); // Stack +1 + type = lua_tostring(a_SrcLuaState, -1); + lua_pop(a_SrcLuaState, 1); // Stack -1 + + // Copy the value: + void * ud = tolua_touserdata(a_SrcLuaState, i, NULL); + tolua_pushusertype(m_LuaState, ud, type); + } + default: + { + LOGWARNING("%s: Unsupported value: '%s' at stack position %d. Can only copy numbers, strings, bools and classes!", + __FUNCTION__, lua_typename(a_SrcLuaState, t), i + ); + a_SrcLuaState.LogStack("Stack where copying failed:"); + lua_pop(m_LuaState, i - a_SrcStart); + return -1; + } + } + } + return a_SrcEnd - a_SrcStart + 1; +} + + + + + +void cLuaState::ToString(int a_StackPos, AString & a_String) +{ + size_t len; + const char * s = lua_tolstring(m_LuaState, a_StackPos, &len); + if (s != NULL) + { + a_String.assign(s, len); + } +} + + + + + +void cLuaState::LogStack(const char * a_Header) +{ + LogStack(m_LuaState, a_Header); +} + + + + + +void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header) +{ + LOGD((a_Header != NULL) ? a_Header : "Lua C API Stack contents:"); + for (int i = lua_gettop(a_LuaState); i >= 0; i--) + { + AString Value; + int Type = lua_type(a_LuaState, i); + switch (Type) + { + case LUA_TBOOLEAN: Value.assign((lua_toboolean(a_LuaState, i) != 0) ? "true" : "false"); break; + case LUA_TLIGHTUSERDATA: Printf(Value, "%p", lua_touserdata(a_LuaState, i)); break; + case LUA_TNUMBER: Printf(Value, "%f", (double)lua_tonumber(a_LuaState, i)); break; + case LUA_TSTRING: Printf(Value, "%s", lua_tostring(a_LuaState, i)); break; + default: break; + } + LOGD(" Idx %d: type %d (%s) %s", i, Type, lua_typename(a_LuaState, Type), Value.c_str()); + } // for i - stack idx } diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index f8b67f5cd..dda45bb28 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -60,23 +60,23 @@ class cBlockEntity; -/// Encapsulates a Lua state and provides some syntactic sugar for common operations +/** Encapsulates a Lua state and provides some syntactic sugar for common operations */ class cLuaState { public: - /// Used for storing references to object in the global registry + /** Used for storing references to object in the global registry */ class cRef { public: - /// Creates a reference in the specified LuaState for object at the specified StackPos + /** Creates a reference in the specified LuaState for object at the specified StackPos */ cRef(cLuaState & a_LuaState, int a_StackPos); ~cRef(); - /// Returns true if the reference is valid + /** Returns true if the reference is valid */ bool IsValid(void) const {return (m_Ref != LUA_REFNIL); } - /// Allows to use this class wherever an int (i. e. ref) is to be used + /** Allows to use this class wherever an int (i. e. ref) is to be used */ operator int(void) const { return m_Ref; } protected: @@ -102,7 +102,7 @@ public: } ; - /// A dummy class that's used only to delimit function args from return values for cLuaState::Call() + /** A dummy class that's used only to delimit function args from return values for cLuaState::Call() */ class cRet { } ; @@ -123,22 +123,22 @@ public: ~cLuaState(); - /// Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions + /** Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions */ operator lua_State * (void) { return m_LuaState; } - /// Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor + /** Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor */ void Create(void); - /// Closes the m_LuaState, if not closed already + /** Closes the m_LuaState, if not closed already */ void Close(void); - /// Attaches the specified state. Operations will be carried out on this state, but it will not be closed in the destructor + /** Attaches the specified state. Operations will be carried out on this state, but it will not be closed in the destructor */ void Attach(lua_State * a_State); - /// Detaches a previously attached state. + /** Detaches a previously attached state. */ void Detach(void); - /// Returns true if the m_LuaState is valid + /** Returns true if the m_LuaState is valid */ bool IsValid(void) const { return (m_LuaState != NULL); } /** Loads the specified file @@ -147,7 +147,7 @@ public: */ bool LoadFile(const AString & a_FileName); - /// Returns true if a_FunctionName is a valid Lua function that can be called + /** Returns true if a_FunctionName is a valid Lua function that can be called */ bool HasFunction(const char * a_FunctionName); // Push a value onto the stack @@ -182,7 +182,7 @@ public: void Push(cHopperEntity * a_Hopper); void Push(cBlockEntity * a_BlockEntity); - /// Call any 0-param 0-return Lua function in a single line: + /** Call any 0-param 0-return Lua function in a single line: */ template bool Call(FnT a_FnName) { @@ -193,7 +193,7 @@ public: return CallFunction(0); } - /// Call any 1-param 0-return Lua function in a single line: + /** Call any 1-param 0-return Lua function in a single line: */ template< typename FnT, typename ArgT1 @@ -208,7 +208,7 @@ public: return CallFunction(0); } - /// Call any 2-param 0-return Lua function in a single line: + /** Call any 2-param 0-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2 > @@ -223,7 +223,7 @@ public: return CallFunction(0); } - /// Call any 3-param 0-return Lua function in a single line: + /** Call any 3-param 0-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3 > @@ -239,7 +239,7 @@ public: return CallFunction(0); } - /// Call any 0-param 1-return Lua function in a single line: + /** Call any 0-param 1-return Lua function in a single line: */ template< typename FnT, typename RetT1 > @@ -259,12 +259,13 @@ public: return true; } - /// Call any 1-param 1-return Lua function in a single line: + /** Call any 1-param 1-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename RetT1 > bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1) { + int InitialTop = lua_gettop(m_LuaState); UNUSED(a_Mark); if (!PushFunction(a_FnName)) { @@ -277,10 +278,11 @@ public: } GetReturn(-1, a_Ret1); lua_pop(m_LuaState, 1); + ASSERT(InitialTop == lua_gettop(m_LuaState)); return true; } - /// Call any 2-param 1-return Lua function in a single line: + /** Call any 2-param 1-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename RetT1 > @@ -302,7 +304,7 @@ public: return true; } - /// Call any 3-param 1-return Lua function in a single line: + /** Call any 3-param 1-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename RetT1 > @@ -325,7 +327,7 @@ public: return true; } - /// Call any 4-param 1-return Lua function in a single line: + /** Call any 4-param 1-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename RetT1 > @@ -349,7 +351,7 @@ public: return true; } - /// Call any 5-param 1-return Lua function in a single line: + /** Call any 5-param 1-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename RetT1 > @@ -374,7 +376,7 @@ public: return true; } - /// Call any 6-param 1-return Lua function in a single line: + /** Call any 6-param 1-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename RetT1 @@ -401,7 +403,7 @@ public: return true; } - /// Call any 7-param 1-return Lua function in a single line: + /** Call any 7-param 1-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename RetT1 @@ -429,7 +431,7 @@ public: return true; } - /// Call any 8-param 1-return Lua function in a single line: + /** Call any 8-param 1-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename ArgT8, typename RetT1 @@ -458,7 +460,7 @@ public: return true; } - /// Call any 9-param 1-return Lua function in a single line: + /** Call any 9-param 1-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9, typename RetT1 @@ -488,7 +490,7 @@ public: return true; } - /// Call any 10-param 1-return Lua function in a single line: + /** Call any 10-param 1-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9, typename ArgT10, typename RetT1 @@ -519,7 +521,7 @@ public: return true; } - /// Call any 1-param 2-return Lua function in a single line: + /** Call any 1-param 2-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename RetT1, typename RetT2 > @@ -541,7 +543,7 @@ public: return true; } - /// Call any 2-param 2-return Lua function in a single line: + /** Call any 2-param 2-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename RetT1, typename RetT2 > @@ -564,7 +566,7 @@ public: return true; } - /// Call any 3-param 2-return Lua function in a single line: + /** Call any 3-param 2-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename RetT1, typename RetT2 @@ -589,7 +591,7 @@ public: return true; } - /// Call any 4-param 2-return Lua function in a single line: + /** Call any 4-param 2-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename RetT1, typename RetT2 @@ -615,7 +617,7 @@ public: return true; } - /// Call any 5-param 2-return Lua function in a single line: + /** Call any 5-param 2-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename RetT1, typename RetT2 @@ -642,7 +644,7 @@ public: return true; } - /// Call any 6-param 2-return Lua function in a single line: + /** Call any 6-param 2-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, @@ -671,7 +673,7 @@ public: return true; } - /// Call any 7-param 2-return Lua function in a single line: + /** Call any 7-param 2-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, @@ -701,7 +703,7 @@ public: return true; } - /// Call any 7-param 3-return Lua function in a single line: + /** Call any 7-param 3-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, @@ -732,7 +734,7 @@ public: return true; } - /// Call any 8-param 3-return Lua function in a single line: + /** Call any 8-param 3-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename ArgT8, @@ -764,7 +766,7 @@ public: return true; } - /// Call any 9-param 5-return Lua function in a single line: + /** Call any 9-param 5-return Lua function in a single line: */ template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9, @@ -800,46 +802,71 @@ public: } - /// Returns true if the specified parameters on the stack are of the specified usertable type; also logs warning if not. Used for static functions + /** Returns true if the specified parameters on the stack are of the specified usertable type; also logs warning if not. Used for static functions */ bool CheckParamUserTable(int a_StartParam, const char * a_UserTable, int a_EndParam = -1); - /// Returns true if the specified parameters on the stack are of the specified usertype; also logs warning if not. Used for regular functions + /** Returns true if the specified parameters on the stack are of the specified usertype; also logs warning if not. Used for regular functions */ bool CheckParamUserType(int a_StartParam, const char * a_UserType, int a_EndParam = -1); - /// Returns true if the specified parameters on the stack are tables; also logs warning if not + /** Returns true if the specified parameters on the stack are tables; also logs warning if not */ bool CheckParamTable(int a_StartParam, int a_EndParam = -1); - /// Returns true if the specified parameters on the stack are numbers; also logs warning if not + /** Returns true if the specified parameters on the stack are numbers; also logs warning if not */ bool CheckParamNumber(int a_StartParam, int a_EndParam = -1); - /// Returns true if the specified parameters on the stack are strings; also logs warning if not + /** Returns true if the specified parameters on the stack are strings; also logs warning if not */ bool CheckParamString(int a_StartParam, int a_EndParam = -1); - /// Returns true if the specified parameters on the stack are functions; also logs warning if not + /** Returns true if the specified parameters on the stack are functions; also logs warning if not */ bool CheckParamFunction(int a_StartParam, int a_EndParam = -1); - /// Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) + /** Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) */ bool CheckParamEnd(int a_Param); - /// If the status is nonzero, prints the text on the top of Lua stack and returns true + /** If the status is nonzero, prints the text on the top of Lua stack and returns true */ bool ReportErrors(int status); - /// If the status is nonzero, prints the text on the top of Lua stack and returns true + /** If the status is nonzero, prints the text on the top of Lua stack and returns true */ static bool ReportErrors(lua_State * a_LuaState, int status); - /// Logs all items in the current stack trace to the server console + /** Logs all items in the current stack trace to the server console */ void LogStackTrace(void); - /// Logs all items in the current stack trace to the server console + /** Logs all items in the current stack trace to the server console */ static void LogStackTrace(lua_State * a_LuaState); - /// Returns the type of the item on the specified position in the stack + /** Returns the type of the item on the specified position in the stack */ AString GetTypeText(int a_StackPos); + /** Calls the function specified by its name, with arguments copied off the foreign state. + If successful, keeps the return values on the stack and returns their number. + If unsuccessful, returns a negative number and keeps the stack position unchanged. */ + int CallFunctionWithForeignParams( + const AString & a_FunctionName, + cLuaState & a_SrcLuaState, + int a_SrcParamStart, + int a_SrcParamEnd + ); + + /** Copies objects on the stack from the specified state. + Only numbers, bools, strings and userdatas are copied. + If successful, returns the number of objects copied. + If failed, returns a negative number and rewinds the stack position. */ + int CopyStackFrom(cLuaState & a_SrcLuaState, int a_SrcStart, int a_SrcEnd); + + /** Reads the value at the specified stack position as a string and sets it to a_String. */ + void ToString(int a_StackPos, AString & a_String); + + /** Logs all the elements' types on the API stack, with an optional header for the listing. */ + void LogStack(const char * a_Header); + + /** Logs all the elements' types on the API stack, with an optional header for the listing. */ + static void LogStack(lua_State * a_LuaState, const char * a_Header = NULL); + protected: lua_State * m_LuaState; - /// If true, the state is owned by this object and will be auto-Closed. False => attached state + /** If true, the state is owned by this object and will be auto-Closed. False => attached state */ bool m_IsOwned; /** The subsystem name is used for reporting errors to the console, it is either "plugin %s" or "LuaScript" @@ -847,10 +874,10 @@ protected: */ AString m_SubsystemName; - /// Name of the currently pushed function (for the Push / Call chain) + /** Name of the currently pushed function (for the Push / Call chain) */ AString m_CurrentFunctionName; - /// Number of arguments currently pushed (for the Push / Call chain) + /** Number of arguments currently pushed (for the Push / Call chain) */ int m_NumCurrentFunctionArgs; @@ -869,19 +896,19 @@ protected: */ bool PushFunction(const cTableRef & a_TableRef); - /// Pushes a usertype of the specified class type onto the stack + /** Pushes a usertype of the specified class type onto the stack */ void PushUserType(void * a_Object, const char * a_Type); - /// Retrieve value returned at a_StackPos, if it is a valid bool. If not, a_ReturnedVal is unchanged + /** Retrieve value returned at a_StackPos, if it is a valid bool. If not, a_ReturnedVal is unchanged */ void GetReturn(int a_StackPos, bool & a_ReturnedVal); - /// Retrieve value returned at a_StackPos, if it is a valid string. If not, a_ReturnedVal is unchanged + /** Retrieve value returned at a_StackPos, if it is a valid string. If not, a_ReturnedVal is unchanged */ void GetReturn(int a_StackPos, AString & a_ReturnedVal); - /// Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged + /** Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged */ void GetReturn(int a_StackPos, int & a_ReturnedVal); - /// Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged + /** Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged */ void GetReturn(int a_StackPos, double & a_ReturnedVal); /** diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 2206dd371..f1160f941 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1540,6 +1540,85 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L) +static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S) +{ + /* + Function signature: + cPluginManager:CallPlugin("PluginName", "FunctionName", args...) + */ + + // Check the parameters: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserTable(1, "cPluginManager") || + !L.CheckParamString(2, 3)) + { + return 0; + } + + // Retrieve the plugin name and function name + AString PluginName, FunctionName; + L.ToString(2, PluginName); + L.ToString(3, FunctionName); + if (PluginName.empty() || FunctionName.empty()) + { + LOGWARNING("cPluginManager:CallPlugin(): Invalid plugin name or function name"); + L.LogStackTrace(); + return 0; + } + + // If requesting calling the current plugin, refuse: + cPluginLua * ThisPlugin = GetLuaPlugin(L); + if (ThisPlugin == NULL) + { + return 0; + } + if (ThisPlugin->GetName() == PluginName) + { + LOGWARNING("cPluginManager::CallPlugin(): Calling self is not implemented (why would it?)"); + L.LogStackTrace(); + return 0; + } + + // Call the destination plugin using a plugin callback: + class cCallback : + public cPluginManager::cPluginCallback + { + public: + int m_NumReturns; + + cCallback(const AString & a_FunctionName, cLuaState & a_SrcLuaState) : + m_FunctionName(a_FunctionName), + m_SrcLuaState(a_SrcLuaState), + m_NumReturns(0) + { + } + protected: + const AString & m_FunctionName; + cLuaState & m_SrcLuaState; + + virtual bool Item(cPlugin * a_Plugin) override + { + m_NumReturns = ((cPluginLua *)a_Plugin)->CallFunctionFromForeignState( + m_FunctionName, m_SrcLuaState, 4, lua_gettop(m_SrcLuaState) + ); + return true; + } + } Callback(FunctionName, L); + if (!cPluginManager::Get()->DoWithPlugin(PluginName, Callback)) + { + // TODO 2014_01_20 _X: This might be too much logging, plugins cannot know if other plugins are loaded (async) + LOGWARNING("cPluginManager::CallPlugin: No such plugin name (\"%s\")", PluginName.c_str()); + L.LogStackTrace(); + return 0; + } + return Callback.m_NumReturns; +} + + + + + static int tolua_cPlayer_GetGroups(lua_State* tolua_S) { cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); @@ -1734,112 +1813,28 @@ static int tolua_cPluginLua_AddTab(lua_State* tolua_S) -// Perhaps use this as well for copying tables https://github.com/keplerproject/rings/pull/1 -static int copy_lua_values(lua_State * a_Source, lua_State * a_Destination, int i, int top) -{ - for(; i <= top; ++i ) - { - int t = lua_type(a_Source, i); - switch (t) { - case LUA_TSTRING: /* strings */ - { - const char * s = lua_tostring(a_Source, i); - LOGD("%i push string: %s", i, s); - tolua_pushstring(a_Destination, s); - } - break; - case LUA_TBOOLEAN: /* booleans */ - { - int b = tolua_toboolean(a_Source, i, false); - LOGD("%i push bool: %i", i, b); - tolua_pushboolean(a_Destination, b ); - } - break; - case LUA_TNUMBER: /* numbers */ - { - lua_Number d = tolua_tonumber(a_Source, i, 0); - LOGD("%i push number: %0.2f", i, d); - tolua_pushnumber(a_Destination, d ); - } - break; - case LUA_TUSERDATA: - { - const char * type = 0; - if (lua_getmetatable(a_Source,i)) - { - lua_rawget(a_Source, LUA_REGISTRYINDEX); - type = lua_tostring(a_Source, -1); - lua_pop(a_Source, 1); // Pop.. something?! I don't knooow~~ T_T - } - - // don't need tolua_tousertype we already have the type - void * ud = tolua_touserdata(a_Source, i, 0); - LOGD("%i push usertype: %p of type '%s'", i, ud, type); - if( type == 0 ) - { - LOGERROR("Call(): Something went wrong when trying to get usertype name!"); - return 0; - } - tolua_pushusertype(a_Destination, ud, type); - } - break; - default: /* other values */ - LOGERROR("Call(): Unsupported value: '%s'. Can only use numbers and strings!", lua_typename(a_Source, t)); - return 0; - } - } - return 1; -} - - - - -static int tolua_cPlugin_Call(lua_State* tolua_S) +static int tolua_cPlugin_Call(lua_State * tolua_S) { - cPluginLua * self = (cPluginLua *) tolua_tousertype(tolua_S, 1, 0); - lua_State* targetState = self->GetLuaState(); - int targetTop = lua_gettop(targetState); - - int top = lua_gettop(tolua_S); - LOGD("total in stack: %i", top ); - - std::string funcName = tolua_tostring(tolua_S, 2, ""); - LOGD("Func name: %s", funcName.c_str() ); - - lua_getglobal(targetState, funcName.c_str()); - if(!lua_isfunction(targetState,-1)) - { - LOGWARN("Error could not find function '%s' in plugin '%s'", funcName.c_str(), self->GetName().c_str() ); - lua_pop(targetState,1); - return 0; - } - - if( copy_lua_values(tolua_S, targetState, 3, top) == 0 ) // Start at 3 because 1 and 2 are the plugin and function name respectively - { - // something went wrong, exit - return 0; - } + cLuaState L(tolua_S); - int s = lua_pcall(targetState, top - 2, LUA_MULTRET, 0); - if (cLuaState::ReportErrors(targetState, s)) - { - LOGWARN("Error while calling function '%s' in plugin '%s'", funcName.c_str(), self->GetName().c_str() ); - return 0; - } - - int nresults = lua_gettop(targetState) - targetTop; - LOGD("num results: %i", nresults); - int ttop = lua_gettop(targetState); - if( copy_lua_values(targetState, tolua_S, targetTop+1, ttop) == 0 ) // Start at targetTop+1 and I have no idea why xD + // Log the obsoletion warning: + LOGWARNING("cPlugin:Call() is obsolete and unsafe, use cPluginManager:CallPlugin() instead."); + L.LogStackTrace(); + + // Retrieve the params: plugin and the function name to call + cPluginLua * TargetPlugin = (cPluginLua *) tolua_tousertype(tolua_S, 1, 0); + AString FunctionName = tolua_tostring(tolua_S, 2, ""); + + // Call the function: + int NumReturns = TargetPlugin->CallFunctionFromForeignState(FunctionName, L, 3, lua_gettop(L)); + if (NumReturns < 0) { - // something went wrong, exit + LOGWARNING("cPlugin::Call() failed to call destination function"); + L.LogStackTrace(); return 0; } - - lua_pop(targetState, nresults); // I have no idea what I'm doing, but it works - - return nresults; + return NumReturns; } @@ -2305,6 +2300,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "AddHook", tolua_cPluginManager_AddHook); tolua_function(tolua_S, "BindCommand", tolua_cPluginManager_BindCommand); tolua_function(tolua_S, "BindConsoleCommand", tolua_cPluginManager_BindConsoleCommand); + tolua_function(tolua_S, "CallPlugin", tolua_cPluginManager_CallPlugin); tolua_function(tolua_S, "ForEachCommand", tolua_cPluginManager_ForEachCommand); tolua_function(tolua_S, "ForEachConsoleCommand", tolua_cPluginManager_ForEachConsoleCommand); tolua_function(tolua_S, "GetAllPlugins", tolua_cPluginManager_GetAllPlugins); diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 4c4664815..1d8c4c6ed 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -1469,6 +1469,40 @@ bool cPluginLua::AddHookRef(int a_HookType, int a_FnRefIdx) +int cPluginLua::CallFunctionFromForeignState( + const AString & a_FunctionName, + cLuaState & a_ForeignState, + int a_ParamStart, + int a_ParamEnd +) +{ + cCSLock Lock(m_CriticalSection); + + // Call the function: + int NumReturns = m_LuaState.CallFunctionWithForeignParams(a_FunctionName, a_ForeignState, a_ParamStart, a_ParamEnd); + if (NumReturns < 0) + { + // The call has failed, an error has already been output to the log, so just silently bail out with the same error + return NumReturns; + } + + // Copy all the return values: + int Top = lua_gettop(m_LuaState); + int res = a_ForeignState.CopyStackFrom(m_LuaState, Top - NumReturns + 1, Top); + + // Remove the return values off this stack: + if (NumReturns > 0) + { + lua_pop(m_LuaState, NumReturns); + } + + return res; +} + + + + + AString cPluginLua::HandleWebRequest(const HTTPRequest * a_Request ) { cCSLock Lock(m_CriticalSection); diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index c01f5ca89..c13f31424 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -105,7 +105,7 @@ public: virtual void ClearConsoleCommands(void) override; - /// Returns true if the plugin contains the function for the specified hook type, using the old-style registration (#121) + /** Returns true if the plugin contains the function for the specified hook type, using the old-style registration (#121) */ bool CanAddOldStyleHook(int a_HookType); // cWebPlugin override @@ -115,26 +115,26 @@ public: virtual AString HandleWebRequest(const HTTPRequest * a_Request ) override; bool AddWebTab(const AString & a_Title, lua_State * a_LuaState, int a_FunctionReference); // >> EXPORTED IN MANUALBINDINGS << - /// Binds the command to call the function specified by a Lua function reference. Simply adds to CommandMap. + /** Binds the command to call the function specified by a Lua function reference. Simply adds to CommandMap. */ void BindCommand(const AString & a_Command, int a_FnRef); - /// Binds the console command to call the function specified by a Lua function reference. Simply adds to CommandMap. + /** Binds the console command to call the function specified by a Lua function reference. Simply adds to CommandMap. */ void BindConsoleCommand(const AString & a_Command, int a_FnRef); cLuaState & GetLuaState(void) { return m_LuaState; } cCriticalSection & GetCriticalSection(void) { return m_CriticalSection; } - /// Removes a previously referenced object (luaL_unref()) + /** Removes a previously referenced object (luaL_unref()) */ void Unreference(int a_LuaRef); - /// Calls the plugin-specified "cLuaWindow closing" callback. Returns true only if the callback returned true + /** Calls the plugin-specified "cLuaWindow closing" callback. Returns true only if the callback returned true */ bool CallbackWindowClosing(int a_FnRef, cWindow & a_Window, cPlayer & a_Player, bool a_CanRefuse); - /// Calls the plugin-specified "cLuaWindow slot changed" callback. + /** Calls the plugin-specified "cLuaWindow slot changed" callback. */ void CallbackWindowSlotChanged(int a_FnRef, cWindow & a_Window, int a_SlotNum); - /// Returns the name of Lua function that should handle the specified hook type in the older (#121) API + /** Returns the name of Lua function that should handle the specified hook type in the older (#121) API */ static const char * GetHookFnName(int a_HookType); /** Adds a Lua function to be called for the specified hook. @@ -143,37 +143,47 @@ public: */ bool AddHookRef(int a_HookType, int a_FnRefIdx); + /** Calls a function in this plugin's LuaState with parameters copied over from a_ForeignState. + The values that the function returns are placed onto a_ForeignState. + Returns the number of values returned, if successful, or negative number on failure. */ + int CallFunctionFromForeignState( + const AString & a_FunctionName, + cLuaState & a_ForeignState, + int a_ParamStart, + int a_ParamEnd + ); + // The following templates allow calls to arbitrary Lua functions residing in the plugin: - /// Call a Lua function with 0 args + /** Call a Lua function with 0 args */ template bool Call(FnT a_Fn) { cCSLock Lock(m_CriticalSection); return m_LuaState.Call(a_Fn); } - /// Call a Lua function with 1 arg + /** Call a Lua function with 1 arg */ template bool Call(FnT a_Fn, ArgT0 a_Arg0) { cCSLock Lock(m_CriticalSection); return m_LuaState.Call(a_Fn, a_Arg0); } - /// Call a Lua function with 2 args + /** Call a Lua function with 2 args */ template bool Call(FnT a_Fn, ArgT0 a_Arg0, ArgT1 a_Arg1) { cCSLock Lock(m_CriticalSection); return m_LuaState.Call(a_Fn, a_Arg0, a_Arg1); } - /// Call a Lua function with 3 args + /** Call a Lua function with 3 args */ template bool Call(FnT a_Fn, ArgT0 a_Arg0, ArgT1 a_Arg1, ArgT2 a_Arg2) { cCSLock Lock(m_CriticalSection); return m_LuaState.Call(a_Fn, a_Arg0, a_Arg1, a_Arg2); } - /// Call a Lua function with 4 args + /** Call a Lua function with 4 args */ template bool Call(FnT a_Fn, ArgT0 a_Arg0, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3) { cCSLock Lock(m_CriticalSection); @@ -181,13 +191,13 @@ public: } protected: - /// Maps command name into Lua function reference + /** Maps command name into Lua function reference */ typedef std::map CommandMap; - /// Provides an array of Lua function references + /** Provides an array of Lua function references */ typedef std::vector cLuaRefs; - /// Maps hook types into arrays of Lua function references to call for each hook type + /** Maps hook types into arrays of Lua function references to call for each hook type */ typedef std::map cHookMap; cCriticalSection m_CriticalSection; @@ -198,7 +208,7 @@ protected: cHookMap m_HookMap; - /// Releases all Lua references and closes the LuaState + /** Releases all Lua references and closes the LuaState */ void Close(void); } ; // tolua_export diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 24bb914d1..92c06487c 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -1736,6 +1736,21 @@ bool cPluginManager::IsValidHookType(int a_HookType) +bool cPluginManager::DoWithPlugin(const AString & a_PluginName, cPluginCallback & a_Callback) +{ + // TODO: Implement locking for plugins + PluginMap::iterator itr = m_Plugins.find(a_PluginName); + if (itr == m_Plugins.end()) + { + return false; + } + return a_Callback.Item(itr->second); +} + + + + + bool cPluginManager::AddPlugin(cPlugin * a_Plugin) { m_Plugins[a_Plugin->GetDirectory()] = a_Plugin; diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 9936f5a35..d8b838d80 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -122,7 +122,7 @@ public: // tolua_export } ; // tolua_end - /// Used as a callback for enumerating bound commands + /** Used as a callback for enumerating bound commands */ class cCommandEnumCallback { public: @@ -132,7 +132,11 @@ public: // tolua_export virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) = 0; } ; - /// Returns the instance of the Plugin Manager (there is only ever one) + /** The interface used for enumerating and extern-calling plugins */ + typedef cItemCallback cPluginCallback; + + + /** Returns the instance of the Plugin Manager (there is only ever one) */ static cPluginManager * Get(void); // tolua_export typedef std::map< AString, cPlugin * > PluginMap; @@ -143,7 +147,7 @@ public: // tolua_export void FindPlugins(); // tolua_export void ReloadPlugins(); // tolua_export - /// Adds the plugin to the list of plugins called for the specified hook type. Handles multiple adds as a single add + /** Adds the plugin to the list of plugins called for the specified hook type. Handles multiple adds as a single add */ void AddHook(cPlugin * a_Plugin, int a_HookType); unsigned int GetNumPlugins() const; // tolua_export @@ -206,46 +210,46 @@ public: // tolua_export bool DisablePlugin(const AString & a_PluginName); // tolua_export bool LoadPlugin (const AString & a_PluginName); // tolua_export - /// Removes all hooks the specified plugin has registered + /** Removes all hooks the specified plugin has registered */ void RemoveHooks(cPlugin * a_Plugin); - /// Removes the plugin from the internal structures and deletes its object. + /** Removes the plugin from the internal structures and deletes its object. */ void RemovePlugin(cPlugin * a_Plugin); - /// Removes all command bindings that the specified plugin has made + /** Removes all command bindings that the specified plugin has made */ void RemovePluginCommands(cPlugin * a_Plugin); - /// Binds a command to the specified plugin. Returns true if successful, false if command already bound. + /** Binds a command to the specified plugin. Returns true if successful, false if command already bound. */ bool BindCommand(const AString & a_Command, cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString); // Exported in ManualBindings.cpp, without the a_Plugin param - /// Calls a_Callback for each bound command, returns true if all commands were enumerated + /** Calls a_Callback for each bound command, returns true if all commands were enumerated */ bool ForEachCommand(cCommandEnumCallback & a_Callback); // Exported in ManualBindings.cpp - /// Returns true if the command is in the command map + /** Returns true if the command is in the command map */ bool IsCommandBound(const AString & a_Command); // tolua_export - /// Returns the permission needed for the specified command; empty string if command not found + /** Returns the permission needed for the specified command; empty string if command not found */ AString GetCommandPermission(const AString & a_Command); // tolua_export - /// Executes the command, as if it was requested by a_Player. Checks permissions first. Returns true if executed. + /** Executes the command, as if it was requested by a_Player. Checks permissions first. Returns true if executed. */ bool ExecuteCommand(cPlayer * a_Player, const AString & a_Command); // tolua_export - /// Executes the command, as if it was requested by a_Player. Permisssions are not checked. Returns true if executed (false if not found) + /** Executes the command, as if it was requested by a_Player. Permisssions are not checked. Returns true if executed (false if not found) */ bool ForceExecuteCommand(cPlayer * a_Player, const AString & a_Command); // tolua_export - /// Removes all console command bindings that the specified plugin has made + /** Removes all console command bindings that the specified plugin has made */ void RemovePluginConsoleCommands(cPlugin * a_Plugin); - /// Binds a console command to the specified plugin. Returns true if successful, false if command already bound. + /** Binds a console command to the specified plugin. Returns true if successful, false if command already bound. */ bool BindConsoleCommand(const AString & a_Command, cPlugin * a_Plugin, const AString & a_HelpString); // Exported in ManualBindings.cpp, without the a_Plugin param - /// Calls a_Callback for each bound console command, returns true if all commands were enumerated + /** Calls a_Callback for each bound console command, returns true if all commands were enumerated */ bool ForEachConsoleCommand(cCommandEnumCallback & a_Callback); // Exported in ManualBindings.cpp - /// Returns true if the console command is in the command map + /** Returns true if the console command is in the command map */ bool IsConsoleCommandBound(const AString & a_Command); // tolua_export - /// Executes the command split into a_Split, as if it was given on the console. Returns true if executed. Output is sent to the a_Output callback + /** Executes the command split into a_Split, as if it was given on the console. Returns true if executed. Output is sent to the a_Output callback */ bool ExecuteConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output); /** Appends all commands beginning with a_Text (case-insensitive) into a_Results. @@ -253,9 +257,13 @@ public: // tolua_export */ void TabCompleteCommand(const AString & a_Text, AStringVector & a_Results, cPlayer * a_Player); - /// Returns true if the specified hook type is within the allowed range + /** Returns true if the specified hook type is within the allowed range */ static bool IsValidHookType(int a_HookType); + /** Calls the specified callback with the plugin object of the specified plugin. + Returns false if plugin not found, and the value that the callback has returned otherwise. */ + bool DoWithPlugin(const AString & a_PluginName, cPluginCallback & a_Callback); + private: friend class cRoot; @@ -281,22 +289,22 @@ private: cPluginManager(); virtual ~cPluginManager(); - /// Reloads all plugins, defaulting to settings.ini for settings location + /** Reloads all plugins, defaulting to settings.ini for settings location */ void ReloadPluginsNow(void); - /// Reloads all plugins with a cIniFile object expected to be initialised to settings.ini + /** Reloads all plugins with a cIniFile object expected to be initialised to settings.ini */ void ReloadPluginsNow(cIniFile & a_SettingsIni); - /// Unloads all plugins + /** Unloads all plugins */ void UnloadPluginsNow(void); - /// Handles writing default plugins if 'Plugins' key not found using a cIniFile object expected to be intialised to settings.ini + /** Handles writing default plugins if 'Plugins' key not found using a cIniFile object expected to be intialised to settings.ini */ void InsertDefaultPlugins(cIniFile & a_SettingsIni); - /// Adds the plugin into the internal list of plugins and initializes it. If initialization fails, the plugin is removed again. + /** Adds the plugin into the internal list of plugins and initializes it. If initialization fails, the plugin is removed again. */ bool AddPlugin(cPlugin * a_Plugin); - /// Tries to match a_Command to the internal table of commands, if a match is found, the corresponding plugin is called. Returns true if the command is handled. + /** Tries to match a_Command to the internal table of commands, if a match is found, the corresponding plugin is called. Returns true if the command is handled. */ bool HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions, bool & a_WasCommandForbidden); bool HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions) { -- cgit v1.2.3 From f58d11fc1aa673bad1463718ff518ee518c78252 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 22 Jan 2014 10:18:58 +0100 Subject: InfoDump: Dump all referenced permissions. --- MCServer/Plugins/InfoDump.lua | 116 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 4 deletions(-) diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index df47d566b..c272f7818 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -17,22 +17,23 @@ if (_VERSION ~= "Lua 5.1") then return; end --- Try to load lfs, do not abort if not found +-- Try to load lfs, do not abort if not found ... local lfs, err = pcall( function() return require("lfs") end ); --- Rather, print a nice message with instructions: +-- ... rather, print a nice message with instructions: if not(lfs) then print([[ Cannot load LuaFileSystem Install it through luarocks by executing the following command: - sudo luarocks install luafilesystem + luarocks install luafilesystem (Windows) + sudo luarocks install luafilesystem (*nix) If you don't have luarocks installed, you need to install them using your OS's package manager, usually: - sudo apt-get install luarocks + sudo apt-get install luarocks (Ubuntu / Debian) On windows, a binary distribution can be downloaded from the LuaRocks homepage, http://luarocks.org/en/Download ]]); @@ -161,6 +162,21 @@ end +--- Returns a string specifying the command. +-- If a_Command is a simple string, returns a_Command colorized to blue +-- If a_Command is a table, expects members Name (full command name) and Params (command parameters), +-- colorizes command name blue and params green +local function GetCommandRefForum(a_Command) + if (type(a_Command) == "string") then + return "[color=blue]" .. a_Command .. "[/color]"; + end + return "[color=blue]" .. a_Command.Name .. "[/color] [color=green]" .. a_Command.Params .. "[/color]"; +end + + + + + --- Writes the specified command detailed help array to the output file, in the forum dump format local function WriteCommandParameterCombinationsForum(a_CmdString, a_ParameterCombinations, f) assert(type(a_CmdString) == "string"); @@ -270,6 +286,97 @@ end +--- Collects all permissions mentioned in the info, returns them as a sorted array +-- Each array item is {Name = "PermissionName", Info = { PermissionInfo }} +local function BuildPermissions(a_PluginInfo) + -- Collect all used permissions from Commands, reference the commands that use the permission: + local Permissions = a_PluginInfo.Permissions or {}; + local function CollectPermissions(a_CmdPrefix, a_Commands) + for cmd, info in pairs(a_Commands) do + CommandString = a_CmdPrefix .. cmd; + if ((info.Permission ~= nil) and (info.Permission ~= "")) then + -- Add the permission to the list of permissions: + local Permission = Permissions[info.Permission] or {}; + Permissions[info.Permission] = Permission; + -- Add the command to the list of commands using this permission: + Permission.CommandsAffected = Permission.CommandsAffected or {}; + table.insert(Permission.CommandsAffected, CommandString); + end + + -- Process the command param combinations for permissions: + local ParamCombinations = info.ParameterCombinations or {}; + for idx, comb in ipairs(ParamCombinations) do + if ((comb.Permission ~= nil) and (comb.Permission ~= "")) then + -- Add the permission to the list of permissions: + local Permission = Permissions[comb.Permission] or {}; + Permissions[info.Permission] = Permission; + -- Add the command to the list of commands using this permission: + Permission.CommandsAffected = Permission.CommandsAffected or {}; + table.insert(Permission.CommandsAffected, {Name = CommandString, Params = comb.Params}); + end + end + + -- Process subcommands: + if (info.Subcommands ~= nil) then + CollectPermissions(CommandString .. " ", info.Subcommands); + end + end + end + CollectPermissions("", a_PluginInfo.Commands); + + -- Copy the list of permissions to an array: + local PermArray = {}; + for name, perm in pairs(Permissions) do + table.insert(PermArray, {Name = name, Info = perm}); + end + + -- Sort the permissions array: + table.sort(PermArray, + function(p1, p2) + return (p1.Name < p2.Name); + end + ); + return PermArray; +end + + + + + +local function DumpPermissionsForum(a_PluginInfo, f) + -- Get the processed sorted array of permissions: + local Permissions = BuildPermissions(a_PluginInfo); + if ((Permissions == nil) or (#Permissions <= 0)) then + return; + end + + -- Dump the permissions: + f:write("\n[size=X-Large]Permissions[/size]\n[list]\n"); + for idx, perm in ipairs(Permissions) do + f:write(" - [color=red]", perm.Name, "[/color] - "); + f:write(perm.Info.Description or ""); + local CommandsAffected = perm.Info.CommandsAffected or {}; + if (#CommandsAffected > 0) then + f:write("\n[list] Commands affected:\n- "); + local Affects = {}; + for idx2, cmd in ipairs(CommandsAffected) do + table.insert(Affects, GetCommandRefForum(cmd)); + end + f:write(table.concat(Affects, "\n - ")); + f:write("\n[/list]"); + end + if (perm.Info.RecommendedGroups ~= nil) then + f:write("\n[list] Recommended groups: ", perm.Info.RecommendedGroups, "[/list]"); + end + f:write("\n"); + end + f:write("[/list]"); +end + + + + + local function DumpPluginInfoForum(a_PluginFolder, a_PluginInfo) -- Open the output file: local f, msg = io.open(a_PluginInfo.Name .. "_forum.txt", "w"); @@ -282,6 +389,7 @@ local function DumpPluginInfoForum(a_PluginFolder, a_PluginInfo) f:write(ForumizeString(a_PluginInfo.Description), "\n"); DumpAdditionalInfoForum(a_PluginInfo, f); DumpCommandsForum(a_PluginInfo, f); + DumpPermissionsForum(a_PluginInfo, f); f:close(); end -- cgit v1.2.3 From a6661e899a486badd8215bbc2fb04adc5542795c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 22 Jan 2014 12:41:19 +0100 Subject: InfoDump: Can dump a single plugin without LFS. --- MCServer/Plugins/InfoDump.lua | 112 ++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 47 deletions(-) diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index c272f7818..6b1da7a77 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -2,10 +2,17 @@ -- InfoDump.lua --- Goes through all subfolders, loads Info.lua and dumps its g_PluginInfo into various text formats --- This is used for generating plugin documentation for the forum and for GitHub's INFO.md files +--[[ +Loads plugins' Info.lua and dumps its g_PluginInfo into various text formats +This is used for generating plugin documentation for the forum and for GitHub's INFO.md files --- This script requires LuaRocks with LFS installed, instructions are printed when this is not present. +This script can be used in two ways: +Executing "lua InfoDump.lua" will go through all subfolders and dump each Info.lua file it can find + Note that this mode of operation requires LuaRocks with LFS installed; instructions are printed + when the prerequisites are not met. +Executing "lua InfoDump.lua PluginName" will load the Info.lua file from PluginName's folder and dump +only that one plugin's documentation. This mode of operation doesn't require LuaRocks +--]] @@ -17,34 +24,6 @@ if (_VERSION ~= "Lua 5.1") then return; end --- Try to load lfs, do not abort if not found ... -local lfs, err = pcall( - function() - return require("lfs") - end -); - --- ... rather, print a nice message with instructions: -if not(lfs) then - print([[ -Cannot load LuaFileSystem -Install it through luarocks by executing the following command: - luarocks install luafilesystem (Windows) - sudo luarocks install luafilesystem (*nix) - -If you don't have luarocks installed, you need to install them using your OS's package manager, usually: - sudo apt-get install luarocks (Ubuntu / Debian) -On windows, a binary distribution can be downloaded from the LuaRocks homepage, http://luarocks.org/en/Download -]]); - - print("Original error text: ", err); - return; -end - --- We now know that LFS is present, get it normally: -lfs = require("lfs"); - - @@ -409,12 +388,6 @@ end --- Tries to load the g_PluginInfo from the plugin's Info.lua file -- Returns the g_PluginInfo table on success, or nil and error message on failure local function LoadPluginInfo(a_FolderName) - -- Check if the Info file is present at all: - local Attribs = lfs.attributes(a_FolderName .. "/Info.lua"); - if ((Attribs == nil) or (Attribs.mode ~= "file")) then - return nil; - end - -- Load and compile the Info file: local cfg, err = loadfile(a_FolderName .. "/Info.lua"); if (cfg == nil) then @@ -440,7 +413,7 @@ local function ProcessPluginFolder(a_FolderName) local PluginInfo, Msg = LoadPluginInfo(a_FolderName); if (PluginInfo == nil) then if (Msg ~= nil) then - print("\tCannot load Info.lua: " .. Msg); + print("\t" .. Msg); end return; end @@ -451,19 +424,64 @@ end -print("Processing plugin subfolders:"); -for fnam in lfs.dir(".") do - if ((fnam ~= ".") and (fnam ~= "..")) then - local Attributes = lfs.attributes(fnam); - if (Attributes ~= nil) then - if (Attributes.mode == "directory") then - print(fnam); - ProcessPluginFolder(fnam); - end +--- Tries to load LFS through LuaRocks, returns the LFS instance, or nil on error +local function LoadLFS() + -- Try to load lfs, do not abort if not found ... + local lfs, err = pcall( + function() + return require("lfs") end + ); + + -- ... rather, print a nice message with instructions: + if not(lfs) then + print([[ + Cannot load LuaFileSystem + Install it through luarocks by executing the following command: + luarocks install luafilesystem (Windows) + sudo luarocks install luafilesystem (*nix) + + If you don't have luarocks installed, you need to install them using your OS's package manager, usually: + sudo apt-get install luarocks (Ubuntu / Debian) + On windows, a binary distribution can be downloaded from the LuaRocks homepage, http://luarocks.org/en/Download + ]]); + + print("Original error text: ", err); + return nil; end + + -- We now know that LFS is present, get it normally: + return require("lfs"); end + +local Arg1 = ...; +if ((Arg1 ~= nil) and (Arg1 ~= "")) then + -- Called with a plugin folder name, export only that one + ProcessPluginFolder(Arg1) +else + -- Called without any arguments, process all subfolders: + local lfs = LoadLFS(); + if (lfs == nil) then + -- LFS not loaded, error has already been printed, just bail out + return; + end + print("Processing plugin subfolders:"); + for fnam in lfs.dir(".") do + if ((fnam ~= ".") and (fnam ~= "..")) then + local Attributes = lfs.attributes(fnam); + if (Attributes ~= nil) then + if (Attributes.mode == "directory") then + print(fnam); + ProcessPluginFolder(fnam); + end + end + end + end +end +print("Done."); + + -- cgit v1.2.3 From dd04f5a73ccc125be80a3ba3a3ab508ac300b99a Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 22 Jan 2014 15:49:21 +0200 Subject: cWorld now saves/loads the scoreboard --- src/Scoreboard.cpp | 3 +++ src/Scoreboard.h | 32 +++++++++++++++++++++---------- src/World.cpp | 9 +++++++++ src/WorldStorage/ScoreboardSerializer.cpp | 15 ++++++++++----- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index e6812d3d7..b2edd613b 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -238,6 +238,8 @@ bool cTeam::HasPlayer(const AString & a_Name) const void cTeam::Reset(void) { + // TODO 2014-01-22 xdot: Inform online players + m_Players.clear(); } @@ -505,3 +507,4 @@ unsigned int cScoreboard::GetNumTeams(void) const + diff --git a/src/Scoreboard.h b/src/Scoreboard.h index 11b456739..f64ba2bce 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -27,8 +27,6 @@ class cObjective { public: - // tolua_end - typedef int Score; enum eType @@ -52,6 +50,8 @@ public: E_TYPE_STAT_ENTITY_KILLED_BY }; + // tolua_end + static AString TypeToString(eType a_Type); static eType StringToType(const AString & a_Name); @@ -60,6 +60,8 @@ public: cObjective(const AString & a_Name, const AString & a_DisplayName, eType a_Type, cWorld * a_World); + // tolua_begin + eType GetType(void) const { return m_Type; } const AString & GetName(void) const { return m_Name; } @@ -85,6 +87,8 @@ public: void SetDisplayName(const AString & a_Name); + // tolua_end + /// Send this objective to the specified client void SendTo(cClientHandle & a_Client); @@ -135,6 +139,8 @@ public: /// Removes all registered players void Reset(void); + // tolua_begin + /// Returns the number of registered players unsigned int GetNumPlayers(void) const; @@ -147,13 +153,15 @@ public: const AString & GetPrefix(void) const { return m_Prefix; } const AString & GetSuffix(void) const { return m_Suffix; } - void SetFriendlyFire(bool a_Flag) { m_AllowsFriendlyFire = a_Flag; } + void SetFriendlyFire(bool a_Flag) { m_AllowsFriendlyFire = a_Flag; } void SetCanSeeFriendlyInvisible(bool a_Flag) { m_CanSeeFriendlyInvisible = a_Flag; } void SetDisplayName(const AString & a_Name); - void SetPrefix(const AString & a_Prefix); - void SetSuffix(const AString & a_Suffix); + void SetPrefix(const AString & a_Prefix) { m_Prefix = a_Prefix; } + void SetSuffix(const AString & a_Suffix) { m_Suffix = a_Suffix; } + + // tolua_end private: @@ -183,8 +191,6 @@ class cScoreboard { public: - // tolua_end - enum eDisplaySlot { E_DISPLAY_SLOT_LIST = 0, @@ -194,11 +200,15 @@ public: E_DISPLAY_SLOT_COUNT }; + // tolua_end + public: cScoreboard(cWorld * a_World); + // tolua_begin + /// Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision cObjective * RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type); @@ -228,13 +238,15 @@ public: /// Execute callback for each objective with the specified type void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback); - /// Send this scoreboard to the specified client - void SendTo(cClientHandle & a_Client); - unsigned int GetNumObjectives(void) const; unsigned int GetNumTeams(void) const; + // tolua_end + + /// Send this scoreboard to the specified client + void SendTo(cClientHandle & a_Client); + private: diff --git a/src/World.cpp b/src/World.cpp index f83de0342..49d42f08e 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -12,6 +12,7 @@ #include "ChunkMap.h" #include "Generating/ChunkDesc.h" #include "OSSupport/Timer.h" +#include "WorldStorage/ScoreboardSerializer.h" // Entities (except mobs): #include "Entities/ExpOrb.h" @@ -248,6 +249,10 @@ cWorld::cWorld(const AString & a_WorldName) : LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str()); cFile::CreateFolder(FILE_IO_PREFIX + m_WorldName); + + // Load the scoreboard + cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard); + Serializer.Load(); } @@ -267,6 +272,10 @@ cWorld::~cWorld() m_Storage.WaitForFinish(); + // Unload the scoreboard + cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard); + Serializer.Save(); + delete m_ChunkMap; } diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp index bcac50bb6..dabc5e2e1 100644 --- a/src/WorldStorage/ScoreboardSerializer.cpp +++ b/src/WorldStorage/ScoreboardSerializer.cpp @@ -22,7 +22,12 @@ cScoreboardSerializer::cScoreboardSerializer(const AString & a_WorldName, cScoreboard* a_ScoreBoard) : m_ScoreBoard(a_ScoreBoard) { - Printf(m_Path, "%s/data/scoreboard.dat", a_WorldName.c_str()); + AString DataPath; + Printf(DataPath, "%s/data", a_WorldName.c_str()); + + m_Path = DataPath + "/scoreboard.dat"; + + cFile::CreateFolder(FILE_IO_PREFIX + DataPath); } @@ -33,7 +38,7 @@ bool cScoreboardSerializer::Load(void) { cFile File; - if (!File.Open(m_Path, cFile::fmReadWrite)) + if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmReadWrite)) { return false; } @@ -60,7 +65,7 @@ bool cScoreboardSerializer::Load(void) { return false; } - + // Parse the NBT data: cParsedNBT NBT(Uncompressed, strm.total_out); if (!NBT.IsValid()) @@ -81,7 +86,7 @@ bool cScoreboardSerializer::Save(void) cFastNBTWriter Writer; Writer.BeginCompound(""); - + m_ScoreBoard->RegisterObjective("test","test",cObjective::E_TYPE_DUMMY)->AddScore("dot", 2); SaveScoreboardToNBT(Writer); Writer.EndCompound(); @@ -91,7 +96,7 @@ bool cScoreboardSerializer::Save(void) cParsedNBT TestParse(Writer.GetResult().data(), Writer.GetResult().size()); ASSERT(TestParse.IsValid()); #endif // _DEBUG - + gzFile gz = gzopen((FILE_IO_PREFIX + m_Path).c_str(), "wb"); if (gz != NULL) { -- cgit v1.2.3 From d59a0156ce88e1d70169ccf42e7c3c4de7181020 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Wed, 22 Jan 2014 16:58:25 +0100 Subject: Fixed compilation on VC2008 --- src/Entities/Player.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c6b24a465..e5def0156 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -862,6 +862,7 @@ void cPlayer::KilledBy(cEntity * a_Killer) virtual bool Item(cObjective * a_Objective) override { a_Objective->AddScore(m_Name, 1); + return true; } } IncrementCounter (GetName()); -- cgit v1.2.3 From 1c320fa18c65ddb546ec5ff396f5554db306bd8b Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 22 Jan 2014 10:13:41 -0800 Subject: formatting changes --- src/WorldStorage/SchematicFileSerilizer.cpp | 16 +++++++++++++--- src/WorldStorage/SchematicFileSerilizer.h | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/WorldStorage/SchematicFileSerilizer.cpp b/src/WorldStorage/SchematicFileSerilizer.cpp index df68f3436..4e2ecb752 100644 --- a/src/WorldStorage/SchematicFileSerilizer.cpp +++ b/src/WorldStorage/SchematicFileSerilizer.cpp @@ -6,7 +6,7 @@ #include "SchematicFileSerilizer.h" -bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName) +bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName) { // Un-GZip the contents: AString Contents; @@ -35,7 +35,12 @@ bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea& a_BlockArea, co return LoadFromSchematicNBT(a_BlockArea, NBT); } -bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName) + + + + + +bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName) { cFastNBTWriter Writer("Schematic"); Writer.AddShort("Width", a_BlockArea.m_SizeX); @@ -82,7 +87,12 @@ bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea& a_BlockArea, cons return true; } -bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea& a_BlockArea, cParsedNBT & a_NBT) + + + + + +bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT) { int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials"); if ((TMaterials > 0) && (a_NBT.GetType(TMaterials) == TAG_String)) diff --git a/src/WorldStorage/SchematicFileSerilizer.h b/src/WorldStorage/SchematicFileSerilizer.h index e4dcf3eb9..cb30e55d8 100644 --- a/src/WorldStorage/SchematicFileSerilizer.h +++ b/src/WorldStorage/SchematicFileSerilizer.h @@ -1,20 +1,30 @@ +#pragma once + #include "../BlockArea.h" + + + + // fwd: FastNBT.h class cParsedNBT; + + + + class cSchematicFileSerializer { public: /// Loads an area from a .schematic file. Returns true if successful - static bool LoadFromSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName); + static bool LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName); /// Saves the area into a .schematic file. Returns true if successful - static bool SaveToSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName); + static bool SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName); private: /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful. - static bool LoadFromSchematicNBT(cBlockArea& a_BlockArea, cParsedNBT & a_NBT); + static bool LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT); }; -- cgit v1.2.3 From 571200019d7f0a948145b6cf8c2594d3e75cb375 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 22 Jan 2014 10:35:36 -0800 Subject: Added manual bindings for moved functions --- src/Bindings/AllToLua.pkg | 1 + src/Bindings/ManualBindings.cpp | 66 +++++++++++++++++++++++++++++++ src/WorldStorage/SchematicFileSerilizer.h | 6 ++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index f65aed9bb..9ad45d1bd 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -70,6 +70,7 @@ $cfile "../Generating/ChunkDesc.h" $cfile "../CraftingRecipes.h" $cfile "../UI/Window.h" $cfile "../Mobs/Monster.h" +$cfile "../WorldStorage/SchematicFileSerilizer.h" diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index f1160f941..1b7651acd 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -13,6 +13,7 @@ #include "../Entities/Player.h" #include "../WebAdmin.h" #include "../ClientHandle.h" +#include "../BlockArea.h" #include "../BlockEntities/ChestEntity.h" #include "../BlockEntities/CommandBlockEntity.h" #include "../BlockEntities/DispenserEntity.h" @@ -22,6 +23,7 @@ #include "../BlockEntities/NoteEntity.h" #include "md5/md5.h" #include "../LineBlockTracer.h" +#include "../WorldStorage/SchematicFileSerilizer.h" @@ -2234,6 +2236,65 @@ static int tolua_cHopperEntity_GetOutputBlockPos(lua_State * tolua_S) + +static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) +{ + // function cBlockArea::LoadFromSchematicFile + // Exported manually because function has been moved to SchematicFileSerilizer.cpp + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cBlockArea") || + !L.CheckParamString (2) || + !L.CheckParamEnd (3) + ) + { + return 0; + } + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, 0); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::LoadFromSchematicFile'", NULL); + return 0; + } + + AString Filename = tolua_tostring(tolua_S, 2, 0); + LOGWARNING("cBlockArea::LoadFromSchematic file is depreciated. Please use cSchematicFileSerilizer::LoadFromSchematicFile."); + bool res = cSchematicFileSerializer::LoadFromSchematicFile(*self,Filename); + tolua_pushboolean(tolua_S, res); + return 1; +} + + + + +static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) +{ + // function cBlockArea::SaveToSchematicFile + // Exported manually because function has been moved to SchematicFileSerilizer.cpp + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cBlockArea") || + !L.CheckParamString (2) || + !L.CheckParamEnd (3) + ) + { + return 0; + } + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, 0); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::SaveToSchematicFile'", NULL); + return 0; + } + AString Filename = tolua_tostring(tolua_S, 2, 0); + LOGWARNING("cBlockArea::SaveToSchematic file is depreciated. Please use cSchematicFileSerializer::SaveToSchematicFile."); + bool res = cSchematicFileSerializer::SaveToSchematicFile(*self,Filename); + tolua_pushboolean(tolua_S, res); + return 1; +} + + + void ManualBindings::Bind(lua_State * tolua_S) { tolua_beginmodule(tolua_S, NULL); @@ -2250,6 +2311,11 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cHopperEntity"); + tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile); + tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); + tolua_endmodule(tolua_S); + + tolua_beginmodule(tolua_S, "cBlockArea"); tolua_function(tolua_S, "GetOutputBlockPos", tolua_cHopperEntity_GetOutputBlockPos); tolua_endmodule(tolua_S); diff --git a/src/WorldStorage/SchematicFileSerilizer.h b/src/WorldStorage/SchematicFileSerilizer.h index cb30e55d8..31b36695c 100644 --- a/src/WorldStorage/SchematicFileSerilizer.h +++ b/src/WorldStorage/SchematicFileSerilizer.h @@ -13,7 +13,7 @@ class cParsedNBT; - +// tolua_begin class cSchematicFileSerializer { public: @@ -24,7 +24,9 @@ public: /// Saves the area into a .schematic file. Returns true if successful static bool SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName); + // tolua_end + private: /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful. static bool LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT); -}; +}; // tolua_export -- cgit v1.2.3 From 5ef0a00a6c11c183070b97d2121009de27830713 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 22 Jan 2014 10:39:09 -0800 Subject: Fixed spelling error --- src/Bindings/AllToLua.pkg | 2 +- src/Bindings/ManualBindings.cpp | 2 +- src/WorldStorage/SchematicFileSerializer.cpp | 172 +++++++++++++++++++++++++++ src/WorldStorage/SchematicFileSerializer.h | 32 +++++ src/WorldStorage/SchematicFileSerilizer.cpp | 172 --------------------------- src/WorldStorage/SchematicFileSerilizer.h | 32 ----- 6 files changed, 206 insertions(+), 206 deletions(-) create mode 100644 src/WorldStorage/SchematicFileSerializer.cpp create mode 100644 src/WorldStorage/SchematicFileSerializer.h delete mode 100644 src/WorldStorage/SchematicFileSerilizer.cpp delete mode 100644 src/WorldStorage/SchematicFileSerilizer.h diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 9ad45d1bd..8b2a78d05 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -70,7 +70,7 @@ $cfile "../Generating/ChunkDesc.h" $cfile "../CraftingRecipes.h" $cfile "../UI/Window.h" $cfile "../Mobs/Monster.h" -$cfile "../WorldStorage/SchematicFileSerilizer.h" +$cfile "../WorldStorage/SchematicFileSerializer.h" diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 1b7651acd..299dfd9ee 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -23,7 +23,7 @@ #include "../BlockEntities/NoteEntity.h" #include "md5/md5.h" #include "../LineBlockTracer.h" -#include "../WorldStorage/SchematicFileSerilizer.h" +#include "../WorldStorage/SchematicFileSerializer.h" diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp new file mode 100644 index 000000000..45fd967bd --- /dev/null +++ b/src/WorldStorage/SchematicFileSerializer.cpp @@ -0,0 +1,172 @@ + +#include "Globals.h" + +#include "OSSupport/GZipFile.h" +#include "FastNBT.h" + +#include "SchematicFileSerializer.h" + +bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName) +{ + // Un-GZip the contents: + AString Contents; + cGZipFile File; + if (!File.Open(a_FileName, cGZipFile::fmRead)) + { + LOG("Cannot open the schematic file \"%s\".", a_FileName.c_str()); + return false; + } + int NumBytesRead = File.ReadRestOfFile(Contents); + if (NumBytesRead < 0) + { + LOG("Cannot read GZipped data in the schematic file \"%s\", error %d", a_FileName.c_str(), NumBytesRead); + return false; + } + File.Close(); + + // Parse the NBT: + cParsedNBT NBT(Contents.data(), Contents.size()); + if (!NBT.IsValid()) + { + LOG("Cannot parse the NBT in the schematic file \"%s\".", a_FileName.c_str()); + return false; + } + + return LoadFromSchematicNBT(a_BlockArea, NBT); +} + + + + + + +bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName) +{ + cFastNBTWriter Writer("Schematic"); + Writer.AddShort("Width", a_BlockArea.m_SizeX); + Writer.AddShort("Height", a_BlockArea.m_SizeY); + Writer.AddShort("Length", a_BlockArea.m_SizeZ); + Writer.AddString("Materials", "Alpha"); + if (a_BlockArea.HasBlockTypes()) + { + Writer.AddByteArray("Blocks", (const char *)a_BlockArea.m_BlockTypes, a_BlockArea.GetBlockCount()); + } + else + { + AString Dummy(a_BlockArea.GetBlockCount(), 0); + Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size()); + } + if (a_BlockArea.HasBlockMetas()) + { + Writer.AddByteArray("Data", (const char *)a_BlockArea.m_BlockMetas, a_BlockArea.GetBlockCount()); + } + else + { + AString Dummy(a_BlockArea.GetBlockCount(), 0); + Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); + } + // TODO: Save entities and block entities + Writer.BeginList("Entities", TAG_Compound); + Writer.EndList(); + Writer.BeginList("TileEntities", TAG_Compound); + Writer.EndList(); + Writer.Finish(); + + // Save to file + cGZipFile File; + if (!File.Open(a_FileName, cGZipFile::fmWrite)) + { + LOG("Cannot open file \"%s\" for writing.", a_FileName.c_str()); + return false; + } + if (!File.Write(Writer.GetResult())) + { + LOG("Cannot write data to file \"%s\".", a_FileName.c_str()); + return false; + } + return true; +} + + + + + + +bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT) +{ + int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials"); + if ((TMaterials > 0) && (a_NBT.GetType(TMaterials) == TAG_String)) + { + AString Materials = a_NBT.GetString(TMaterials); + if (Materials.compare("Alpha") != 0) + { + LOG("Materials tag is present and \"%s\" instead of \"Alpha\". Possibly a wrong-format schematic file.", Materials.c_str()); + return false; + } + } + int TSizeX = a_NBT.FindChildByName(a_NBT.GetRoot(), "Width"); + int TSizeY = a_NBT.FindChildByName(a_NBT.GetRoot(), "Height"); + int TSizeZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "Length"); + if ( + (TSizeX < 0) || (TSizeY < 0) || (TSizeZ < 0) || + (a_NBT.GetType(TSizeX) != TAG_Short) || + (a_NBT.GetType(TSizeY) != TAG_Short) || + (a_NBT.GetType(TSizeZ) != TAG_Short) + ) + { + LOG("Dimensions are missing from the schematic file (%d, %d, %d), (%d, %d, %d)", + TSizeX, TSizeY, TSizeZ, + a_NBT.GetType(TSizeX), a_NBT.GetType(TSizeY), a_NBT.GetType(TSizeZ) + ); + return false; + } + + int SizeX = a_NBT.GetShort(TSizeX); + int SizeY = a_NBT.GetShort(TSizeY); + int SizeZ = a_NBT.GetShort(TSizeZ); + if ((SizeX < 1) || (SizeY < 1) || (SizeZ < 1)) + { + LOG("Dimensions are invalid in the schematic file: %d, %d, %d", SizeX, SizeY, SizeZ); + return false; + } + + int TBlockTypes = a_NBT.FindChildByName(a_NBT.GetRoot(), "Blocks"); + int TBlockMetas = a_NBT.FindChildByName(a_NBT.GetRoot(), "Data"); + if ((TBlockTypes < 0) || (a_NBT.GetType(TBlockTypes) != TAG_ByteArray)) + { + LOG("BlockTypes are invalid in the schematic file: %d", TBlockTypes); + return false; + } + bool AreMetasPresent = (TBlockMetas > 0) && (a_NBT.GetType(TBlockMetas) == TAG_ByteArray); + + a_BlockArea.Clear(); + a_BlockArea.SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes); + + // Copy the block types and metas: + int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ; + if (a_NBT.GetDataLength(TBlockTypes) < NumBytes) + { + LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.", + NumBytes, a_NBT.GetDataLength(TBlockTypes) + ); + NumBytes = a_NBT.GetDataLength(TBlockTypes); + } + memcpy(a_BlockArea.m_BlockTypes, a_NBT.GetData(TBlockTypes), NumBytes); + + if (AreMetasPresent) + { + int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ; + if (a_NBT.GetDataLength(TBlockMetas) < NumBytes) + { + LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.", + NumBytes, a_NBT.GetDataLength(TBlockMetas) + ); + NumBytes = a_NBT.GetDataLength(TBlockMetas); + } + memcpy(a_BlockArea.m_BlockMetas, a_NBT.GetData(TBlockMetas), NumBytes); + } + + return true; +} + + diff --git a/src/WorldStorage/SchematicFileSerializer.h b/src/WorldStorage/SchematicFileSerializer.h new file mode 100644 index 000000000..31b36695c --- /dev/null +++ b/src/WorldStorage/SchematicFileSerializer.h @@ -0,0 +1,32 @@ + +#pragma once + +#include "../BlockArea.h" + + + + + +// fwd: FastNBT.h +class cParsedNBT; + + + + +// tolua_begin +class cSchematicFileSerializer +{ +public: + + /// Loads an area from a .schematic file. Returns true if successful + static bool LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName); + + /// Saves the area into a .schematic file. Returns true if successful + static bool SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName); + + // tolua_end + +private: + /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful. + static bool LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT); +}; // tolua_export diff --git a/src/WorldStorage/SchematicFileSerilizer.cpp b/src/WorldStorage/SchematicFileSerilizer.cpp deleted file mode 100644 index 4e2ecb752..000000000 --- a/src/WorldStorage/SchematicFileSerilizer.cpp +++ /dev/null @@ -1,172 +0,0 @@ - -#include "Globals.h" - -#include "OSSupport/GZipFile.h" -#include "FastNBT.h" - -#include "SchematicFileSerilizer.h" - -bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName) -{ - // Un-GZip the contents: - AString Contents; - cGZipFile File; - if (!File.Open(a_FileName, cGZipFile::fmRead)) - { - LOG("Cannot open the schematic file \"%s\".", a_FileName.c_str()); - return false; - } - int NumBytesRead = File.ReadRestOfFile(Contents); - if (NumBytesRead < 0) - { - LOG("Cannot read GZipped data in the schematic file \"%s\", error %d", a_FileName.c_str(), NumBytesRead); - return false; - } - File.Close(); - - // Parse the NBT: - cParsedNBT NBT(Contents.data(), Contents.size()); - if (!NBT.IsValid()) - { - LOG("Cannot parse the NBT in the schematic file \"%s\".", a_FileName.c_str()); - return false; - } - - return LoadFromSchematicNBT(a_BlockArea, NBT); -} - - - - - - -bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName) -{ - cFastNBTWriter Writer("Schematic"); - Writer.AddShort("Width", a_BlockArea.m_SizeX); - Writer.AddShort("Height", a_BlockArea.m_SizeY); - Writer.AddShort("Length", a_BlockArea.m_SizeZ); - Writer.AddString("Materials", "Alpha"); - if (a_BlockArea.HasBlockTypes()) - { - Writer.AddByteArray("Blocks", (const char *)a_BlockArea.m_BlockTypes, a_BlockArea.GetBlockCount()); - } - else - { - AString Dummy(a_BlockArea.GetBlockCount(), 0); - Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size()); - } - if (a_BlockArea.HasBlockMetas()) - { - Writer.AddByteArray("Data", (const char *)a_BlockArea.m_BlockMetas, a_BlockArea.GetBlockCount()); - } - else - { - AString Dummy(a_BlockArea.GetBlockCount(), 0); - Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); - } - // TODO: Save entities and block entities - Writer.BeginList("Entities", TAG_Compound); - Writer.EndList(); - Writer.BeginList("TileEntities", TAG_Compound); - Writer.EndList(); - Writer.Finish(); - - // Save to file - cGZipFile File; - if (!File.Open(a_FileName, cGZipFile::fmWrite)) - { - LOG("Cannot open file \"%s\" for writing.", a_FileName.c_str()); - return false; - } - if (!File.Write(Writer.GetResult())) - { - LOG("Cannot write data to file \"%s\".", a_FileName.c_str()); - return false; - } - return true; -} - - - - - - -bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT) -{ - int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials"); - if ((TMaterials > 0) && (a_NBT.GetType(TMaterials) == TAG_String)) - { - AString Materials = a_NBT.GetString(TMaterials); - if (Materials.compare("Alpha") != 0) - { - LOG("Materials tag is present and \"%s\" instead of \"Alpha\". Possibly a wrong-format schematic file.", Materials.c_str()); - return false; - } - } - int TSizeX = a_NBT.FindChildByName(a_NBT.GetRoot(), "Width"); - int TSizeY = a_NBT.FindChildByName(a_NBT.GetRoot(), "Height"); - int TSizeZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "Length"); - if ( - (TSizeX < 0) || (TSizeY < 0) || (TSizeZ < 0) || - (a_NBT.GetType(TSizeX) != TAG_Short) || - (a_NBT.GetType(TSizeY) != TAG_Short) || - (a_NBT.GetType(TSizeZ) != TAG_Short) - ) - { - LOG("Dimensions are missing from the schematic file (%d, %d, %d), (%d, %d, %d)", - TSizeX, TSizeY, TSizeZ, - a_NBT.GetType(TSizeX), a_NBT.GetType(TSizeY), a_NBT.GetType(TSizeZ) - ); - return false; - } - - int SizeX = a_NBT.GetShort(TSizeX); - int SizeY = a_NBT.GetShort(TSizeY); - int SizeZ = a_NBT.GetShort(TSizeZ); - if ((SizeX < 1) || (SizeY < 1) || (SizeZ < 1)) - { - LOG("Dimensions are invalid in the schematic file: %d, %d, %d", SizeX, SizeY, SizeZ); - return false; - } - - int TBlockTypes = a_NBT.FindChildByName(a_NBT.GetRoot(), "Blocks"); - int TBlockMetas = a_NBT.FindChildByName(a_NBT.GetRoot(), "Data"); - if ((TBlockTypes < 0) || (a_NBT.GetType(TBlockTypes) != TAG_ByteArray)) - { - LOG("BlockTypes are invalid in the schematic file: %d", TBlockTypes); - return false; - } - bool AreMetasPresent = (TBlockMetas > 0) && (a_NBT.GetType(TBlockMetas) == TAG_ByteArray); - - a_BlockArea.Clear(); - a_BlockArea.SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes); - - // Copy the block types and metas: - int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ; - if (a_NBT.GetDataLength(TBlockTypes) < NumBytes) - { - LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.", - NumBytes, a_NBT.GetDataLength(TBlockTypes) - ); - NumBytes = a_NBT.GetDataLength(TBlockTypes); - } - memcpy(a_BlockArea.m_BlockTypes, a_NBT.GetData(TBlockTypes), NumBytes); - - if (AreMetasPresent) - { - int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ; - if (a_NBT.GetDataLength(TBlockMetas) < NumBytes) - { - LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.", - NumBytes, a_NBT.GetDataLength(TBlockMetas) - ); - NumBytes = a_NBT.GetDataLength(TBlockMetas); - } - memcpy(a_BlockArea.m_BlockMetas, a_NBT.GetData(TBlockMetas), NumBytes); - } - - return true; -} - - diff --git a/src/WorldStorage/SchematicFileSerilizer.h b/src/WorldStorage/SchematicFileSerilizer.h deleted file mode 100644 index 31b36695c..000000000 --- a/src/WorldStorage/SchematicFileSerilizer.h +++ /dev/null @@ -1,32 +0,0 @@ - -#pragma once - -#include "../BlockArea.h" - - - - - -// fwd: FastNBT.h -class cParsedNBT; - - - - -// tolua_begin -class cSchematicFileSerializer -{ -public: - - /// Loads an area from a .schematic file. Returns true if successful - static bool LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName); - - /// Saves the area into a .schematic file. Returns true if successful - static bool SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName); - - // tolua_end - -private: - /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful. - static bool LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT); -}; // tolua_export -- cgit v1.2.3 From 3b96fc1e547b4ed37a14c3b7fb264a1dbf142862 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 22 Jan 2014 19:29:18 +0100 Subject: Authenticator: Reduced logging levels. --- src/Authenticator.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Authenticator.cpp b/src/Authenticator.cpp index 4cbe3beed..bd6db1c11 100644 --- a/src/Authenticator.cpp +++ b/src/Authenticator.cpp @@ -43,7 +43,6 @@ cAuthenticator::~cAuthenticator() -/// Read custom values from INI void cAuthenticator::ReadINI(cIniFile & IniFile) { m_Server = IniFile.GetValueSet("Authentication", "Server", DEFAULT_AUTH_SERVER); @@ -55,7 +54,6 @@ void cAuthenticator::ReadINI(cIniFile & IniFile) -/// Queues a request for authenticating a user. If the auth fails, the user is kicked void cAuthenticator::Authenticate(int a_ClientID, const AString & a_UserName, const AString & a_ServerHash) { if (!m_ShouldAuthenticate) @@ -141,7 +139,9 @@ bool cAuthenticator::AuthFromAddress(const AString & a_Server, const AString & a cBlockingTCPLink Link; if (!Link.Connect(a_Server.c_str(), 80)) { - LOGERROR("cAuthenticator: cannot connect to auth server \"%s\", kicking user \"%s\"", a_Server.c_str(), a_Server.c_str()); + LOGWARNING("%s: cannot connect to auth server \"%s\", kicking user \"%s\"", + __FUNCTION__, a_Server.c_str(), a_UserName.c_str() + ); return false; } @@ -170,7 +170,7 @@ bool cAuthenticator::AuthFromAddress(const AString & a_Server, const AString & a if (code == 302) { // redirect blabla - LOGINFO("Need to redirect!"); + LOGD("%s: Need to redirect, current level %d!", __FUNCTION__, a_Level); if (a_Level > MAX_REDIRECTS) { LOGERROR("cAuthenticator: received too many levels of redirection from auth server \"%s\" for user \"%s\", bailing out and kicking the user", a_Server.c_str(), a_UserName.c_str()); -- cgit v1.2.3 From 37e820d16e150b918f9d4111bc07dfb7d57feec9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 22 Jan 2014 22:17:20 +0100 Subject: Added PolarSSL as a submodule. --- .gitmodules | 3 +++ lib/polarssl | 1 + 2 files changed, 4 insertions(+) create mode 160000 lib/polarssl diff --git a/.gitmodules b/.gitmodules index 2b5596589..2c7ec209b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "MCServer/Plugins/TransAPI"] path = MCServer/Plugins/TransAPI url = https://github.com/bearbin/transapi.git +[submodule "lib/polarssl"] + path = lib/polarssl + url = https://github.com/polarssl/polarssl diff --git a/lib/polarssl b/lib/polarssl new file mode 160000 index 000000000..c78c8422c --- /dev/null +++ b/lib/polarssl @@ -0,0 +1 @@ +Subproject commit c78c8422c25b9dc38f09eded3200d565375522e2 -- cgit v1.2.3 From eb9bebf7558e56aab10307afc59824c728b6206f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 22 Jan 2014 22:19:33 +0100 Subject: Replacing CryptoPP with PolarSSL. This is only the CMake modification to build with PolarSSL, the actual MCS code doesn't compile at all yet. --- CMakeLists.txt | 7 ++++++- src/CMakeLists.txt | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ddd34db3..a10db7d49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,7 +183,6 @@ project (MCServer) # Include all the libraries: add_subdirectory(lib/inifile/) add_subdirectory(lib/jsoncpp/) -add_subdirectory(lib/cryptopp/) add_subdirectory(lib/zlib/) add_subdirectory(lib/lua/) add_subdirectory(lib/tolua++/) @@ -192,6 +191,12 @@ add_subdirectory(lib/expat/) add_subdirectory(lib/luaexpat/) add_subdirectory(lib/md5/) + +# We use EXCLUDE_FROM_ALL so that only the explicit dependencies are used +# (PolarSSL also has test and example programs in their CMakeLists.txt, we don't want those) +add_subdirectory(lib/polarssl/ EXCLUDE_FROM_ALL) + + # Remove disabling the maximum warning level: # clang does not like a command line that reads -Wall -Wextra -w -Wall -Wextra and does not output any warnings # We do not do that for MSVC since MSVC produces an awful lot of warnings for its own STL headers; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 275099540..ba642f7e6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -120,4 +120,4 @@ endif () if (WIN32) target_link_libraries(${EXECUTABLE} expat tolualib ws2_32.lib Psapi.lib) endif() -target_link_libraries(${EXECUTABLE} md5 luaexpat iniFile jsoncpp cryptopp zlib lua sqlite) +target_link_libraries(${EXECUTABLE} md5 luaexpat iniFile jsoncpp polarssl zlib lua sqlite) -- cgit v1.2.3 From 34f13d589a2ebbcae9230732c7a763b3cdd88b41 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 22 Jan 2014 22:26:40 +0100 Subject: Removed CryptoPP files. --- lib/cryptopp/CMakeLists.txt | 14 - lib/cryptopp/Doxyfile | 1634 ----------------- lib/cryptopp/License.txt | 51 - lib/cryptopp/Readme.txt | 452 ----- lib/cryptopp/adler32.cpp | 77 - lib/cryptopp/adler32.h | 28 - lib/cryptopp/aes.h | 16 - lib/cryptopp/algebra.cpp | 340 ---- lib/cryptopp/algebra.h | 285 --- lib/cryptopp/algparam.cpp | 75 - lib/cryptopp/algparam.h | 398 ---- lib/cryptopp/argnames.h | 81 - lib/cryptopp/asn.cpp | 597 ------ lib/cryptopp/asn.h | 369 ---- lib/cryptopp/authenc.cpp | 180 -- lib/cryptopp/authenc.h | 49 - lib/cryptopp/base32.cpp | 39 - lib/cryptopp/base32.h | 38 - lib/cryptopp/base64.cpp | 42 - lib/cryptopp/base64.h | 36 - lib/cryptopp/basecode.cpp | 238 --- lib/cryptopp/basecode.h | 86 - lib/cryptopp/cbcmac.cpp | 62 - lib/cryptopp/cbcmac.h | 50 - lib/cryptopp/ccm.cpp | 140 -- lib/cryptopp/ccm.h | 101 -- lib/cryptopp/channels.cpp | 309 ---- lib/cryptopp/channels.h | 123 -- lib/cryptopp/cmac.cpp | 122 -- lib/cryptopp/cmac.h | 52 - lib/cryptopp/config.h | 462 ----- lib/cryptopp/cpu.cpp | 199 -- lib/cryptopp/cpu.h | 345 ---- lib/cryptopp/crc.cpp | 160 -- lib/cryptopp/crc.h | 42 - lib/cryptopp/cryptlib.cpp | 828 --------- lib/cryptopp/cryptlib.h | 1655 ----------------- lib/cryptopp/default.cpp | 258 --- lib/cryptopp/default.h | 104 -- lib/cryptopp/des.cpp | 449 ----- lib/cryptopp/des.h | 144 -- lib/cryptopp/dessp.cpp | 95 - lib/cryptopp/dh.cpp | 19 - lib/cryptopp/dh.h | 99 - lib/cryptopp/dh2.cpp | 22 - lib/cryptopp/dh2.h | 58 - lib/cryptopp/dll.cpp | 146 -- lib/cryptopp/dll.h | 70 - lib/cryptopp/dmac.h | 93 - lib/cryptopp/dsa.cpp | 63 - lib/cryptopp/dsa.h | 35 - lib/cryptopp/eax.cpp | 59 - lib/cryptopp/eax.h | 91 - lib/cryptopp/ec2n.cpp | 292 --- lib/cryptopp/ec2n.h | 113 -- lib/cryptopp/eccrypto.cpp | 694 ------- lib/cryptopp/eccrypto.h | 280 --- lib/cryptopp/ecp.cpp | 473 ----- lib/cryptopp/ecp.h | 126 -- lib/cryptopp/elgamal.cpp | 17 - lib/cryptopp/elgamal.h | 121 -- lib/cryptopp/emsa2.cpp | 34 - lib/cryptopp/emsa2.h | 86 - lib/cryptopp/eprecomp.cpp | 112 -- lib/cryptopp/eprecomp.h | 75 - lib/cryptopp/esign.cpp | 210 --- lib/cryptopp/esign.h | 128 -- lib/cryptopp/factory.h | 136 -- lib/cryptopp/files.cpp | 259 --- lib/cryptopp/files.h | 112 -- lib/cryptopp/filters.cpp | 1120 ------------ lib/cryptopp/filters.h | 810 --------- lib/cryptopp/fips140.cpp | 84 - lib/cryptopp/fips140.h | 59 - lib/cryptopp/fltrimpl.h | 67 - lib/cryptopp/gcm.cpp | 828 --------- lib/cryptopp/gcm.h | 106 -- lib/cryptopp/gf256.cpp | 34 - lib/cryptopp/gf256.h | 66 - lib/cryptopp/gf2_32.cpp | 99 - lib/cryptopp/gf2_32.h | 66 - lib/cryptopp/gf2n.cpp | 882 --------- lib/cryptopp/gf2n.h | 369 ---- lib/cryptopp/gfpcrypt.cpp | 273 --- lib/cryptopp/gfpcrypt.h | 528 ------ lib/cryptopp/gzip.h | 65 - lib/cryptopp/hex.cpp | 44 - lib/cryptopp/hex.h | 36 - lib/cryptopp/hmac.cpp | 86 - lib/cryptopp/hmac.h | 61 - lib/cryptopp/hrtimer.cpp | 138 -- lib/cryptopp/hrtimer.h | 61 - lib/cryptopp/integer.cpp | 4235 ------------------------------------------- lib/cryptopp/integer.h | 420 ----- lib/cryptopp/iterhash.cpp | 160 -- lib/cryptopp/iterhash.h | 106 -- lib/cryptopp/lubyrack.h | 141 -- lib/cryptopp/luc.cpp | 210 --- lib/cryptopp/luc.h | 236 --- lib/cryptopp/md2.cpp | 120 -- lib/cryptopp/md2.h | 46 - lib/cryptopp/md4.cpp | 110 -- lib/cryptopp/md4.h | 35 - lib/cryptopp/md5.cpp | 118 -- lib/cryptopp/md5.h | 33 - lib/cryptopp/mdc.h | 72 - lib/cryptopp/misc.cpp | 189 -- lib/cryptopp/misc.h | 1282 ------------- lib/cryptopp/modarith.h | 158 -- lib/cryptopp/modes.cpp | 245 --- lib/cryptopp/modes.h | 422 ----- lib/cryptopp/modexppc.h | 34 - lib/cryptopp/mqueue.cpp | 174 -- lib/cryptopp/mqueue.h | 100 - lib/cryptopp/mqv.cpp | 13 - lib/cryptopp/mqv.h | 141 -- lib/cryptopp/nbtheory.cpp | 1123 ------------ lib/cryptopp/nbtheory.h | 131 -- lib/cryptopp/network.cpp | 550 ------ lib/cryptopp/network.h | 235 --- lib/cryptopp/nr.h | 6 - lib/cryptopp/oaep.cpp | 97 - lib/cryptopp/oaep.h | 42 - lib/cryptopp/oids.h | 123 -- lib/cryptopp/osrng.cpp | 192 -- lib/cryptopp/osrng.h | 156 -- lib/cryptopp/pch.cpp | 1 - lib/cryptopp/pch.h | 21 - lib/cryptopp/pkcspad.cpp | 124 -- lib/cryptopp/pkcspad.h | 94 - lib/cryptopp/polynomi.cpp | 577 ------ lib/cryptopp/polynomi.h | 459 ----- lib/cryptopp/pssr.cpp | 145 -- lib/cryptopp/pssr.h | 66 - lib/cryptopp/pubkey.cpp | 165 -- lib/cryptopp/pubkey.h | 1678 ----------------- lib/cryptopp/pwdbased.h | 214 --- lib/cryptopp/queue.cpp | 565 ------ lib/cryptopp/queue.h | 144 -- lib/cryptopp/rabin.cpp | 221 --- lib/cryptopp/rabin.h | 107 -- lib/cryptopp/randpool.cpp | 63 - lib/cryptopp/randpool.h | 33 - lib/cryptopp/rdtables.cpp | 172 -- lib/cryptopp/resource.h | 15 - lib/cryptopp/rijndael.cpp | 1261 ------------- lib/cryptopp/rijndael.h | 68 - lib/cryptopp/rng.cpp | 155 -- lib/cryptopp/rng.h | 77 - lib/cryptopp/rsa.cpp | 304 ---- lib/cryptopp/rsa.h | 174 -- lib/cryptopp/rw.cpp | 196 -- lib/cryptopp/rw.h | 102 -- lib/cryptopp/safer.cpp | 153 -- lib/cryptopp/safer.h | 86 - lib/cryptopp/seal.cpp | 213 --- lib/cryptopp/seal.h | 44 - lib/cryptopp/secblock.h | 467 ----- lib/cryptopp/seckey.h | 221 --- lib/cryptopp/seed.cpp | 104 -- lib/cryptopp/seed.h | 38 - lib/cryptopp/sha.cpp | 900 --------- lib/cryptopp/sha.h | 63 - lib/cryptopp/shacal2.cpp | 140 -- lib/cryptopp/shacal2.h | 54 - lib/cryptopp/simple.cpp | 14 - lib/cryptopp/simple.h | 209 --- lib/cryptopp/smartptr.h | 223 --- lib/cryptopp/socketft.cpp | 531 ------ lib/cryptopp/socketft.h | 224 --- lib/cryptopp/square.cpp | 177 -- lib/cryptopp/square.h | 58 - lib/cryptopp/squaretb.cpp | 582 ------ lib/cryptopp/stdcpp.h | 41 - lib/cryptopp/strciphr.cpp | 252 --- lib/cryptopp/strciphr.h | 306 ---- lib/cryptopp/tea.cpp | 159 -- lib/cryptopp/tea.h | 132 -- lib/cryptopp/tiger.cpp | 265 --- lib/cryptopp/tiger.h | 24 - lib/cryptopp/tigertab.cpp | 525 ------ lib/cryptopp/trdlocal.cpp | 73 - lib/cryptopp/trdlocal.h | 44 - lib/cryptopp/trunhash.h | 48 - lib/cryptopp/ttmac.cpp | 338 ---- lib/cryptopp/ttmac.h | 38 - lib/cryptopp/validate.h | 81 - lib/cryptopp/vmac.cpp | 832 --------- lib/cryptopp/vmac.h | 68 - lib/cryptopp/wait.cpp | 397 ---- lib/cryptopp/wait.h | 208 --- lib/cryptopp/winpipes.cpp | 205 --- lib/cryptopp/winpipes.h | 142 -- lib/cryptopp/words.h | 103 -- 194 files changed, 48168 deletions(-) delete mode 100644 lib/cryptopp/CMakeLists.txt delete mode 100644 lib/cryptopp/Doxyfile delete mode 100644 lib/cryptopp/License.txt delete mode 100644 lib/cryptopp/Readme.txt delete mode 100644 lib/cryptopp/adler32.cpp delete mode 100644 lib/cryptopp/adler32.h delete mode 100644 lib/cryptopp/aes.h delete mode 100644 lib/cryptopp/algebra.cpp delete mode 100644 lib/cryptopp/algebra.h delete mode 100644 lib/cryptopp/algparam.cpp delete mode 100644 lib/cryptopp/algparam.h delete mode 100644 lib/cryptopp/argnames.h delete mode 100644 lib/cryptopp/asn.cpp delete mode 100644 lib/cryptopp/asn.h delete mode 100644 lib/cryptopp/authenc.cpp delete mode 100644 lib/cryptopp/authenc.h delete mode 100644 lib/cryptopp/base32.cpp delete mode 100644 lib/cryptopp/base32.h delete mode 100644 lib/cryptopp/base64.cpp delete mode 100644 lib/cryptopp/base64.h delete mode 100644 lib/cryptopp/basecode.cpp delete mode 100644 lib/cryptopp/basecode.h delete mode 100644 lib/cryptopp/cbcmac.cpp delete mode 100644 lib/cryptopp/cbcmac.h delete mode 100644 lib/cryptopp/ccm.cpp delete mode 100644 lib/cryptopp/ccm.h delete mode 100644 lib/cryptopp/channels.cpp delete mode 100644 lib/cryptopp/channels.h delete mode 100644 lib/cryptopp/cmac.cpp delete mode 100644 lib/cryptopp/cmac.h delete mode 100644 lib/cryptopp/config.h delete mode 100644 lib/cryptopp/cpu.cpp delete mode 100644 lib/cryptopp/cpu.h delete mode 100644 lib/cryptopp/crc.cpp delete mode 100644 lib/cryptopp/crc.h delete mode 100644 lib/cryptopp/cryptlib.cpp delete mode 100644 lib/cryptopp/cryptlib.h delete mode 100644 lib/cryptopp/default.cpp delete mode 100644 lib/cryptopp/default.h delete mode 100644 lib/cryptopp/des.cpp delete mode 100644 lib/cryptopp/des.h delete mode 100644 lib/cryptopp/dessp.cpp delete mode 100644 lib/cryptopp/dh.cpp delete mode 100644 lib/cryptopp/dh.h delete mode 100644 lib/cryptopp/dh2.cpp delete mode 100644 lib/cryptopp/dh2.h delete mode 100644 lib/cryptopp/dll.cpp delete mode 100644 lib/cryptopp/dll.h delete mode 100644 lib/cryptopp/dmac.h delete mode 100644 lib/cryptopp/dsa.cpp delete mode 100644 lib/cryptopp/dsa.h delete mode 100644 lib/cryptopp/eax.cpp delete mode 100644 lib/cryptopp/eax.h delete mode 100644 lib/cryptopp/ec2n.cpp delete mode 100644 lib/cryptopp/ec2n.h delete mode 100644 lib/cryptopp/eccrypto.cpp delete mode 100644 lib/cryptopp/eccrypto.h delete mode 100644 lib/cryptopp/ecp.cpp delete mode 100644 lib/cryptopp/ecp.h delete mode 100644 lib/cryptopp/elgamal.cpp delete mode 100644 lib/cryptopp/elgamal.h delete mode 100644 lib/cryptopp/emsa2.cpp delete mode 100644 lib/cryptopp/emsa2.h delete mode 100644 lib/cryptopp/eprecomp.cpp delete mode 100644 lib/cryptopp/eprecomp.h delete mode 100644 lib/cryptopp/esign.cpp delete mode 100644 lib/cryptopp/esign.h delete mode 100644 lib/cryptopp/factory.h delete mode 100644 lib/cryptopp/files.cpp delete mode 100644 lib/cryptopp/files.h delete mode 100644 lib/cryptopp/filters.cpp delete mode 100644 lib/cryptopp/filters.h delete mode 100644 lib/cryptopp/fips140.cpp delete mode 100644 lib/cryptopp/fips140.h delete mode 100644 lib/cryptopp/fltrimpl.h delete mode 100644 lib/cryptopp/gcm.cpp delete mode 100644 lib/cryptopp/gcm.h delete mode 100644 lib/cryptopp/gf256.cpp delete mode 100644 lib/cryptopp/gf256.h delete mode 100644 lib/cryptopp/gf2_32.cpp delete mode 100644 lib/cryptopp/gf2_32.h delete mode 100644 lib/cryptopp/gf2n.cpp delete mode 100644 lib/cryptopp/gf2n.h delete mode 100644 lib/cryptopp/gfpcrypt.cpp delete mode 100644 lib/cryptopp/gfpcrypt.h delete mode 100644 lib/cryptopp/gzip.h delete mode 100644 lib/cryptopp/hex.cpp delete mode 100644 lib/cryptopp/hex.h delete mode 100644 lib/cryptopp/hmac.cpp delete mode 100644 lib/cryptopp/hmac.h delete mode 100644 lib/cryptopp/hrtimer.cpp delete mode 100644 lib/cryptopp/hrtimer.h delete mode 100644 lib/cryptopp/integer.cpp delete mode 100644 lib/cryptopp/integer.h delete mode 100644 lib/cryptopp/iterhash.cpp delete mode 100644 lib/cryptopp/iterhash.h delete mode 100644 lib/cryptopp/lubyrack.h delete mode 100644 lib/cryptopp/luc.cpp delete mode 100644 lib/cryptopp/luc.h delete mode 100644 lib/cryptopp/md2.cpp delete mode 100644 lib/cryptopp/md2.h delete mode 100644 lib/cryptopp/md4.cpp delete mode 100644 lib/cryptopp/md4.h delete mode 100644 lib/cryptopp/md5.cpp delete mode 100644 lib/cryptopp/md5.h delete mode 100644 lib/cryptopp/mdc.h delete mode 100644 lib/cryptopp/misc.cpp delete mode 100644 lib/cryptopp/misc.h delete mode 100644 lib/cryptopp/modarith.h delete mode 100644 lib/cryptopp/modes.cpp delete mode 100644 lib/cryptopp/modes.h delete mode 100644 lib/cryptopp/modexppc.h delete mode 100644 lib/cryptopp/mqueue.cpp delete mode 100644 lib/cryptopp/mqueue.h delete mode 100644 lib/cryptopp/mqv.cpp delete mode 100644 lib/cryptopp/mqv.h delete mode 100644 lib/cryptopp/nbtheory.cpp delete mode 100644 lib/cryptopp/nbtheory.h delete mode 100644 lib/cryptopp/network.cpp delete mode 100644 lib/cryptopp/network.h delete mode 100644 lib/cryptopp/nr.h delete mode 100644 lib/cryptopp/oaep.cpp delete mode 100644 lib/cryptopp/oaep.h delete mode 100644 lib/cryptopp/oids.h delete mode 100644 lib/cryptopp/osrng.cpp delete mode 100644 lib/cryptopp/osrng.h delete mode 100644 lib/cryptopp/pch.cpp delete mode 100644 lib/cryptopp/pch.h delete mode 100644 lib/cryptopp/pkcspad.cpp delete mode 100644 lib/cryptopp/pkcspad.h delete mode 100644 lib/cryptopp/polynomi.cpp delete mode 100644 lib/cryptopp/polynomi.h delete mode 100644 lib/cryptopp/pssr.cpp delete mode 100644 lib/cryptopp/pssr.h delete mode 100644 lib/cryptopp/pubkey.cpp delete mode 100644 lib/cryptopp/pubkey.h delete mode 100644 lib/cryptopp/pwdbased.h delete mode 100644 lib/cryptopp/queue.cpp delete mode 100644 lib/cryptopp/queue.h delete mode 100644 lib/cryptopp/rabin.cpp delete mode 100644 lib/cryptopp/rabin.h delete mode 100644 lib/cryptopp/randpool.cpp delete mode 100644 lib/cryptopp/randpool.h delete mode 100644 lib/cryptopp/rdtables.cpp delete mode 100644 lib/cryptopp/resource.h delete mode 100644 lib/cryptopp/rijndael.cpp delete mode 100644 lib/cryptopp/rijndael.h delete mode 100644 lib/cryptopp/rng.cpp delete mode 100644 lib/cryptopp/rng.h delete mode 100644 lib/cryptopp/rsa.cpp delete mode 100644 lib/cryptopp/rsa.h delete mode 100644 lib/cryptopp/rw.cpp delete mode 100644 lib/cryptopp/rw.h delete mode 100644 lib/cryptopp/safer.cpp delete mode 100644 lib/cryptopp/safer.h delete mode 100644 lib/cryptopp/seal.cpp delete mode 100644 lib/cryptopp/seal.h delete mode 100644 lib/cryptopp/secblock.h delete mode 100644 lib/cryptopp/seckey.h delete mode 100644 lib/cryptopp/seed.cpp delete mode 100644 lib/cryptopp/seed.h delete mode 100644 lib/cryptopp/sha.cpp delete mode 100644 lib/cryptopp/sha.h delete mode 100644 lib/cryptopp/shacal2.cpp delete mode 100644 lib/cryptopp/shacal2.h delete mode 100644 lib/cryptopp/simple.cpp delete mode 100644 lib/cryptopp/simple.h delete mode 100644 lib/cryptopp/smartptr.h delete mode 100644 lib/cryptopp/socketft.cpp delete mode 100644 lib/cryptopp/socketft.h delete mode 100644 lib/cryptopp/square.cpp delete mode 100644 lib/cryptopp/square.h delete mode 100644 lib/cryptopp/squaretb.cpp delete mode 100644 lib/cryptopp/stdcpp.h delete mode 100644 lib/cryptopp/strciphr.cpp delete mode 100644 lib/cryptopp/strciphr.h delete mode 100644 lib/cryptopp/tea.cpp delete mode 100644 lib/cryptopp/tea.h delete mode 100644 lib/cryptopp/tiger.cpp delete mode 100644 lib/cryptopp/tiger.h delete mode 100644 lib/cryptopp/tigertab.cpp delete mode 100644 lib/cryptopp/trdlocal.cpp delete mode 100644 lib/cryptopp/trdlocal.h delete mode 100644 lib/cryptopp/trunhash.h delete mode 100644 lib/cryptopp/ttmac.cpp delete mode 100644 lib/cryptopp/ttmac.h delete mode 100644 lib/cryptopp/validate.h delete mode 100644 lib/cryptopp/vmac.cpp delete mode 100644 lib/cryptopp/vmac.h delete mode 100644 lib/cryptopp/wait.cpp delete mode 100644 lib/cryptopp/wait.h delete mode 100644 lib/cryptopp/winpipes.cpp delete mode 100644 lib/cryptopp/winpipes.h delete mode 100644 lib/cryptopp/words.h diff --git a/lib/cryptopp/CMakeLists.txt b/lib/cryptopp/CMakeLists.txt deleted file mode 100644 index 3497b3346..000000000 --- a/lib/cryptopp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ - -cmake_minimum_required (VERSION 2.6) -project (cryptopp) - -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCRYPTOPP_DISABLE_ASM") -endif() -include_directories ("${PROJECT_SOURCE_DIR}/../../src/") - -file(GLOB cryptopp_SRC - "*.cpp" -) - -add_library(cryptopp ${cryptopp_SRC}) diff --git a/lib/cryptopp/Doxyfile b/lib/cryptopp/Doxyfile deleted file mode 100644 index c221fdf56..000000000 --- a/lib/cryptopp/Doxyfile +++ /dev/null @@ -1,1634 +0,0 @@ -# Doxyfile 1.7.1 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project -# -# All text after a hash (#) is considered a comment and will be ignored -# The format is: -# TAG = value [value, ...] -# For lists items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (" ") - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all -# text before the first occurrence of this tag. Doxygen uses libiconv (or the -# iconv built into libc) for the transcoding. See -# http://www.gnu.org/software/libiconv for the list of possible encodings. - -DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded -# by quotes) that should identify the project. - -PROJECT_NAME = Crypto++ - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. -# This could be handy for archiving the generated documentation or -# if some version control system is used. - -PROJECT_NUMBER = - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) -# base path where the generated documentation will be put. -# If a relative path is entered, it will be relative to the location -# where doxygen was started. If left blank the current directory will be used. - -OUTPUT_DIRECTORY = doc - -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create -# 4096 sub-directories (in 2 levels) under the output directory of each output -# format and will distribute the generated files over these directories. -# Enabling this option can be useful when feeding doxygen a huge amount of -# source files, where putting all generated files in the same directory would -# otherwise cause performance problems for the file system. - -CREATE_SUBDIRS = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# The default language is English, other supported languages are: -# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, -# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, -# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English -# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, -# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, -# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. - -OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will -# include brief member descriptions after the members that are listed in -# the file and class documentation (similar to JavaDoc). -# Set to NO to disable this. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend -# the brief description of a member or function before the detailed description. -# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator -# that is used to form the text in various listings. Each string -# in this list, if found as the leading text of the brief description, will be -# stripped from the text and the result after processing the whole list, is -# used as the annotated text. Otherwise, the brief description is used as-is. -# If left blank, the following values are used ("$name" is automatically -# replaced with the name of the entity): "The $name class" "The $name widget" -# "The $name file" "is" "provides" "specifies" "contains" -# "represents" "a" "an" "the" - -ABBREVIATE_BRIEF = - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# Doxygen will generate a detailed section even if there is only a brief -# description. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. - -INLINE_INHERITED_MEMB = YES - -# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full -# path before files name in the file list and in the header files. If set -# to NO the shortest path that makes the file name unique will be used. - -FULL_PATH_NAMES = NO - -# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag -# can be used to strip a user-defined part of the path. Stripping is -# only done if one of the specified strings matches the left-hand part of -# the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the -# path to strip. - -STRIP_FROM_PATH = - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of -# the path mentioned in the documentation of a class, which tells -# the reader which header file to include in order to use a class. -# If left blank only the name of the header file containing the class -# definition is used. Otherwise one should specify the include paths that -# are normally passed to the compiler using the -I flag. - -STRIP_FROM_INC_PATH = - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter -# (but less readable) file names. This can be useful is your file systems -# doesn't support long names like on DOS, Mac, or CD-ROM. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen -# will interpret the first line (until the first dot) of a JavaDoc-style -# comment as the brief description. If set to NO, the JavaDoc -# comments will behave just like regular Qt-style comments -# (thus requiring an explicit @brief command for a brief description.) - -JAVADOC_AUTOBRIEF = YES - -# If the QT_AUTOBRIEF tag is set to YES then Doxygen will -# interpret the first line (until the first dot) of a Qt-style -# comment as the brief description. If set to NO, the comments -# will behave just like regular Qt-style comments (thus requiring -# an explicit \brief command for a brief description.) - -QT_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen -# treat a multi-line C++ special comment block (i.e. a block of //! or /// -# comments) as a brief description. This used to be the default behaviour. -# The new default is to treat a multi-line C++ comment block as a detailed -# description. Set this tag to YES if you prefer the old behaviour instead. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented -# member inherits the documentation from any documented member that it -# re-implements. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce -# a new page for each member. If set to NO, the documentation of a member will -# be part of the file/class/namespace that contains it. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. -# Doxygen uses this value to replace tabs by spaces in code fragments. - -TAB_SIZE = 8 - -# This tag can be used to specify a number of aliases that acts -# as commands in the documentation. An alias has the form "name=value". -# For example adding "sideeffect=\par Side Effects:\n" will allow you to -# put the command \sideeffect (or @sideeffect) in the documentation, which -# will result in a user-defined paragraph with heading "Side Effects:". -# You can put \n's in the value part of an alias to insert newlines. - -ALIASES = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C -# sources only. Doxygen will then generate output that is more tailored for C. -# For instance, some of the names that are used will be different. The list -# of all members will be omitted, etc. - -OPTIMIZE_OUTPUT_FOR_C = NO - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java -# sources only. Doxygen will then generate output that is more tailored for -# Java. For instance, namespaces will be presented as packages, qualified -# scopes will look different, etc. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources only. Doxygen will then generate output that is more tailored for -# Fortran. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for -# VHDL. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given extension. -# Doxygen has a built-in mapping, but you can override or extend it using this -# tag. The format is ext=language, where ext is a file extension, and language -# is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C, -# C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make -# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C -# (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions -# you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. - -EXTENSION_MAPPING = - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should -# set this tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. -# func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. - -BUILTIN_STL_SUPPORT = NO - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. -# Doxygen will parse them like normal C++ but will assume all classes use public -# instead of private inheritance when no explicit protection keyword is present. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate getter -# and setter methods for a property. Setting this option to YES (the default) -# will make doxygen to replace the get and set methods by a property in the -# documentation. This will only work if the methods are indeed getting or -# setting a simple type. If this is not the case, or you want to show the -# methods anyway, you should set this option to NO. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. - -DISTRIBUTE_GROUP_DOC = NO - -# Set the SUBGROUPING tag to YES (the default) to allow class member groups of -# the same type (for instance a group of public functions) to be put as a -# subgroup of that type (e.g. under the Public Functions section). Set it to -# NO to prevent subgrouping. Alternatively, this can be done per class using -# the \nosubgrouping command. - -SUBGROUPING = YES - -# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum -# is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically -# be useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. - -TYPEDEF_HIDES_STRUCT = NO - -# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to -# determine which symbols to keep in memory and which to flush to disk. -# When the cache is full, less often used symbols will be written to disk. -# For small to medium size projects (<1000 input files) the default value is -# probably good enough. For larger projects a too small cache size can cause -# doxygen to be busy swapping symbols to and from disk most of the time -# causing a significant performance penality. -# If the system has enough physical memory increasing the cache will improve the -# performance by keeping more symbols in memory. Note that the value works on -# a logarithmic scale so increasing the size by one will rougly double the -# memory usage. The cache size is given by this formula: -# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, -# corresponding to a cache size of 2^16 = 65536 symbols - -SYMBOL_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless -# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES - -EXTRACT_ALL = NO - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. - -EXTRACT_PRIVATE = NO - -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. - -EXTRACT_STATIC = NO - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. -# If set to NO only classes defined in header files are included. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. -# If set to NO (the default) only methods in the interface are included. - -EXTRACT_LOCAL_METHODS = NO - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base -# name of the file that contains the anonymous namespace. By default -# anonymous namespace are hidden. - -EXTRACT_ANON_NSPACES = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. -# This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these classes will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the -# documentation. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any -# documentation blocks found inside the body of a function. -# If set to NO (the default) these blocks will be appended to the -# function's detailed documentation block. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation -# that is typed after a \internal command is included. If the tag is set -# to NO (the default) then the documentation will be excluded. -# Set it to YES to include the internal documentation. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate -# file names in lower-case letters. If set to YES upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. - -CASE_SENSE_NAMES = NO - -# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen -# will show members with their full class and namespace scopes in the -# documentation. If set to YES the scope will be hidden. - -HIDE_SCOPE_NAMES = NO - -# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen -# will put a list of the files that are included by a file in the documentation -# of that file. - -SHOW_INCLUDE_FILES = YES - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen -# will list include files with double quotes in the documentation -# rather than with sharp brackets. - -FORCE_LOCAL_INCLUDES = NO - -# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] -# is inserted in the documentation for inline members. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen -# will sort the (detailed) documentation of file and class members -# alphabetically by member name. If set to NO the members will appear in -# declaration order. - -SORT_MEMBER_DOCS = NO - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the -# brief documentation of file, namespace and class members alphabetically -# by member name. If set to NO (the default) the members will appear in -# declaration order. - -SORT_BRIEF_DOCS = NO - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen -# will sort the (brief and detailed) documentation of class members so that -# constructors and destructors are listed first. If set to NO (the default) -# the constructors will appear in the respective orders defined by -# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. -# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO -# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. - -SORT_MEMBERS_CTORS_1ST = NO - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the -# hierarchy of group names into alphabetical order. If set to NO (the default) -# the group names will appear in their defined order. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be -# sorted by fully-qualified names, including namespaces. If set to -# NO (the default), the class list will be sorted only by class name, -# not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the -# alphabetical list. - -SORT_BY_SCOPE_NAME = NO - -# The GENERATE_TODOLIST tag can be used to enable (YES) or -# disable (NO) the todo list. This list is created by putting \todo -# commands in the documentation. - -GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable (YES) or -# disable (NO) the test list. This list is created by putting \test -# commands in the documentation. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable (YES) or -# disable (NO) the bug list. This list is created by putting \bug -# commands in the documentation. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or -# disable (NO) the deprecated list. This list is created by putting -# \deprecated commands in the documentation. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional -# documentation sections, marked by \if sectionname ... \endif. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines -# the initial value of a variable or define consists of for it to appear in -# the documentation. If the initializer consists of more lines than specified -# here it will be hidden. Use a value of 0 to hide initializers completely. -# The appearance of the initializer of individual variables and defines in the -# documentation can be controlled using \showinitializer or \hideinitializer -# command in the documentation regardless of this setting. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated -# at the bottom of the documentation of classes and structs. If set to YES the -# list will mention the files that were used to generate the documentation. - -SHOW_USED_FILES = YES - -# If the sources in your project are distributed over multiple directories -# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy -# in the documentation. The default is NO. - -SHOW_DIRECTORIES = NO - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. -# This will remove the Files entry from the Quick Index and from the -# Folder Tree View (if specified). The default is YES. - -SHOW_FILES = YES - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the -# Namespaces page. -# This will remove the Namespaces entry from the Quick Index -# and from the Folder Tree View (if specified). The default is YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command , where is the value of -# the FILE_VERSION_FILTER tag, and is the name of an input file -# provided by doxygen. Whatever the program writes to standard output -# is used as the file version. See the manual for examples. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed -# by doxygen. The layout file controls the global structure of the generated -# output files in an output format independent way. The create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. -# You can optionally specify a file name after the option, if omitted -# DoxygenLayout.xml will be used as the name of the layout file. - -LAYOUT_FILE = - -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated -# by doxygen. Possible values are YES and NO. If left blank NO is used. - -QUIET = NO - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated by doxygen. Possible values are YES and NO. If left blank -# NO is used. - -WARNINGS = NO - -# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings -# for undocumented members. If EXTRACT_ALL is set to YES then this flag will -# automatically be disabled. - -WARN_IF_UNDOCUMENTED = NO - -# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some -# parameters in a documented function, or documenting parameters that -# don't exist or using markup commands wrongly. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be abled to get warnings for -# functions that are documented, but have no documentation for their parameters -# or return value. If set to NO (the default) doxygen will only warn about -# wrong or incomplete parameter documentation, but not about the absence of -# documentation. - -WARN_NO_PARAMDOC = NO - -# The WARN_FORMAT tag determines the format of the warning messages that -# doxygen can produce. The string should contain the $file, $line, and $text -# tags, which will be replaced by the file and line number from which the -# warning originated and the warning text. Optionally the format may contain -# $version, which will be replaced by the version of the file (if it could -# be obtained via FILE_VERSION_FILTER) - -WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning -# and error messages should be written. If left blank the output is written -# to stderr. - -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag can be used to specify the files and/or directories that contain -# documented source files. You may enter file names like "myfile.cpp" or -# directories like "/usr/src/myproject". Separate the files or directories -# with spaces. - -INPUT = . - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is -# also the default input encoding. Doxygen uses libiconv (or the iconv built -# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for -# the list of possible encodings. - -INPUT_ENCODING = UTF-8 - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank the following patterns are tested: -# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx -# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 - -FILE_PATTERNS = *.h \ - *.cpp - -# The RECURSIVE tag can be used to turn specify whether or not subdirectories -# should be searched for input files as well. Possible values are YES and NO. -# If left blank NO is used. - -RECURSIVE = NO - -# The EXCLUDE tag can be used to specify files and/or directories that should -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. - -EXCLUDE = adhoc.cpp - -# The EXCLUDE_SYMLINKS tag can be used select whether or not files or -# directories that are symbolic links (a Unix filesystem feature) are excluded -# from the input. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. Note that the wildcards are matched -# against the file with absolute path, so to exclude all test directories -# for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or -# directories that contain example code fragments that are included (see -# the \include command). - -EXAMPLE_PATH = . - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank all files are included. - -EXAMPLE_PATTERNS = - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude -# commands irrespective of the value of the RECURSIVE tag. -# Possible values are YES and NO. If left blank NO is used. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or -# directories that contain image that are included in the documentation (see -# the \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command , where -# is the value of the INPUT_FILTER tag, and is the name of an -# input file. Doxygen will then use the output that the filter program writes -# to standard output. -# If FILTER_PATTERNS is specified, this tag will be -# ignored. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. -# Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. -# The filters are a list of the form: -# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further -# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER -# is applied to all files. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will be used to filter the input files when producing source -# files to browse (i.e. when SOURCE_BROWSER is set to YES). - -FILTER_SOURCE_FILES = NO - -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will -# be generated. Documented entities will be cross-referenced with these sources. -# Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. - -SOURCE_BROWSER = YES - -# Setting the INLINE_SOURCES tag to YES will include the body -# of functions and classes directly in the documentation. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct -# doxygen to hide any special comment blocks from generated source code -# fragments. Normal C and C++ comments will always remain visible. - -STRIP_CODE_COMMENTS = NO - -# If the REFERENCED_BY_RELATION tag is set to YES -# then for each documented function all documented -# functions referencing it will be listed. - -REFERENCED_BY_RELATION = YES - -# If the REFERENCES_RELATION tag is set to YES -# then for each documented function all documented entities -# called/used by that function will be listed. - -REFERENCES_RELATION = YES - -# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) -# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from -# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will -# link to the source code. -# Otherwise they will link to the documentation. - -REFERENCES_LINK_SOURCE = YES - -# If the USE_HTAGS tag is set to YES then the references to source code -# will point to the HTML generated by the htags(1) tool instead of doxygen -# built-in source browser. The htags tool is part of GNU's global source -# tagging system (see http://www.gnu.org/software/global/global.html). You -# will need version 4.8.6 or higher. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen -# will generate a verbatim copy of the header file for each class for -# which an include is specified. Set to NO to disable this. - -VERBATIM_HEADERS = YES - -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index -# of all compounds will be generated. Enable this if the project -# contains a lot of classes, structs, unions or interfaces. - -ALPHABETICAL_INDEX = YES - -# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then -# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns -# in which this list will be split (can be a number in the range [1..20]) - -COLS_IN_ALPHA_INDEX = 3 - -# In case all classes in a project start with a common prefix, all -# classes will be put under the same header in the alphabetical index. -# The IGNORE_PREFIX tag can be used to specify one or more prefixes that -# should be ignored while generating the index headers. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES (the default) Doxygen will -# generate HTML output. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `html' will be used as the default path. - -HTML_OUTPUT = - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for -# each generated HTML page (for example: .htm,.php,.asp). If it is left blank -# doxygen will generate files with .html extension. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a personal HTML header for -# each generated HTML page. If it is left blank doxygen will generate a -# standard header. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a personal HTML footer for -# each generated HTML page. If it is left blank doxygen will generate a -# standard footer. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading -# style sheet that is used by each HTML page. It can be used to -# fine-tune the look of the HTML output. If the tag is left blank doxygen -# will generate a default style sheet. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own -# stylesheet in the HTML output directory as well, or it will be erased! - -HTML_STYLESHEET = - -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. -# Doxygen will adjust the colors in the stylesheet and background images -# according to this color. Hue is specified as an angle on a colorwheel, -# see http://en.wikipedia.org/wiki/Hue for more information. -# For instance the value 0 represents red, 60 is yellow, 120 is green, -# 180 is cyan, 240 is blue, 300 purple, and 360 is red again. -# The allowed range is 0 to 359. - -HTML_COLORSTYLE_HUE = 220 - -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of -# the colors in the HTML output. For a value of 0 the output will use -# grayscales only. A value of 255 will produce the most vivid colors. - -HTML_COLORSTYLE_SAT = 100 - -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to -# the luminance component of the colors in the HTML output. Values below -# 100 gradually make the output lighter, whereas values above 100 make -# the output darker. The value divided by 100 is the actual gamma applied, -# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, -# and 100 does not change the gamma. - -HTML_COLORSTYLE_GAMMA = 80 - -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting -# this to NO can help when comparing the output of multiple runs. - -HTML_TIMESTAMP = YES - -# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, -# files or namespaces will be aligned in HTML using tables. If set to -# NO a bullet list will be used. - -HTML_ALIGN_MEMBERS = YES - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. For this to work a browser that supports -# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox -# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). - -HTML_DYNAMIC_SECTIONS = NO - -# If the GENERATE_DOCSET tag is set to YES, additional index files -# will be generated that can be used as input for Apple's Xcode 3 -# integrated development environment, introduced with OSX 10.5 (Leopard). -# To create a documentation set, doxygen will generate a Makefile in the -# HTML output directory. Running make will produce the docset in that -# directory and running "make install" will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find -# it at startup. -# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. - -GENERATE_DOCSET = NO - -# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the -# feed. A documentation feed provides an umbrella under which multiple -# documentation sets from a single provider (such as a company or product suite) -# can be grouped. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that -# should uniquely identify the documentation set bundle. This should be a -# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen -# will append .docset to the name. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify -# the documentation publisher. This should be a reverse domain-name style -# string, e.g. com.mycompany.MyDocSet.documentation. - -DOCSET_PUBLISHER_ID = org.doxygen.Publisher - -# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. - -DOCSET_PUBLISHER_NAME = Publisher - -# If the GENERATE_HTMLHELP tag is set to YES, additional index files -# will be generated that can be used as input for tools like the -# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) -# of the generated HTML documentation. - -GENERATE_HTMLHELP = YES - -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can -# be used to specify the file name of the resulting .chm file. You -# can add a path in front of the file if the result should not be -# written to the html output directory. - -CHM_FILE = - -# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can -# be used to specify the location (absolute path including file name) of -# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run -# the HTML help compiler on the generated index.hhp. - -HHC_LOCATION = - -# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag -# controls if a separate .chi index file is generated (YES) or that -# it should be included in the master .chm file (NO). - -GENERATE_CHI = NO - -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING -# is used to encode HtmlHelp index (hhk), content (hhc) and project file -# content. - -CHM_INDEX_ENCODING = - -# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag -# controls whether a binary table of contents is generated (YES) or a -# normal table of contents (NO) in the .chm file. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members -# to the contents of the HTML help documentation and to the tree view. - -TOC_EXPAND = NO - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated -# that can be used as input for Qt's qhelpgenerator to generate a -# Qt Compressed Help (.qch) of the generated HTML documentation. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can -# be used to specify the file name of the resulting .qch file. -# The path specified is relative to the HTML output folder. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#namespace - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#virtual-folders - -QHP_VIRTUAL_FOLDER = doc - -# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to -# add. For more information please see -# http://doc.trolltech.com/qthelpproject.html#custom-filters - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see -# -# Qt Help Project / Custom Filters. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's -# filter section matches. -# -# Qt Help Project / Filter Attributes. - -QHP_SECT_FILTER_ATTRS = - -# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can -# be used to specify the location of Qt's qhelpgenerator. -# If non-empty doxygen will try to run qhelpgenerator on the generated -# .qhp file. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files -# will be generated, which together with the HTML files, form an Eclipse help -# plugin. To install this plugin and make it available under the help contents -# menu in Eclipse, the contents of the directory containing the HTML and XML -# files needs to be copied into the plugins directory of eclipse. The name of -# the directory within the plugins directory should be the same as -# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before -# the help appears. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have -# this name. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# The DISABLE_INDEX tag can be used to turn on/off the condensed index at -# top of each HTML page. The value NO (the default) enables the index and -# the value YES disables it. - -DISABLE_INDEX = NO - -# This tag can be used to set the number of enum values (range [1..20]) -# that doxygen will group on one line in the generated HTML documentation. - -ENUM_VALUES_PER_LINE = 4 - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. -# If the tag value is set to YES, a side panel will be generated -# containing a tree-like index structure (just like the one that -# is generated for HTML Help). For this to work a browser that supports -# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). -# Windows users are probably better off using the HTML help feature. - -GENERATE_TREEVIEW = NO - -# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, -# and Class Hierarchy pages using a tree view instead of an ordered list. - -USE_INLINE_TREES = NO - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be -# used to set the initial width (in pixels) of the frame in which the tree -# is shown. - -TREEVIEW_WIDTH = 250 - -# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open -# links to external symbols imported via tag files in a separate window. - -EXT_LINKS_IN_WINDOW = NO - -# Use this tag to change the font size of Latex formulas included -# as images in the HTML documentation. The default is 10. Note that -# when you change the font size after a successful doxygen run you need -# to manually remove any form_*.png images from the HTML output directory -# to force them to be regenerated. - -FORMULA_FONTSIZE = 10 - -# Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are -# not supported properly for IE 6.0, but are supported on all modern browsers. -# Note that when changing this option you need to delete any form_*.png files -# in the HTML output before the changes have effect. - -FORMULA_TRANSPARENT = YES - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box -# for the HTML output. The underlying search engine uses javascript -# and DHTML and should work on any modern browser. Note that when using -# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets -# (GENERATE_DOCSET) there is already a search function so this one should -# typically be disabled. For large projects the javascript based search engine -# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. - -SEARCHENGINE = NO - -# When the SERVER_BASED_SEARCH tag is enabled the search engine will be -# implemented using a PHP enabled web server instead of at the web client -# using Javascript. Doxygen will generate the search PHP script and index -# file to put on the web server. The advantage of the server -# based approach is that it scales better to large projects and allows -# full text search. The disadvances is that it is more difficult to setup -# and does not have live searching capabilities. - -SERVER_BASED_SEARCH = NO - -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- - -# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will -# generate Latex output. - -GENERATE_LATEX = NO - -# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `latex' will be used as the default path. - -LATEX_OUTPUT = - -# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be -# invoked. If left blank `latex' will be used as the default command name. -# Note that when enabling USE_PDFLATEX this option is only used for -# generating bitmaps for formulas in the HTML output, but not in the -# Makefile that is written to the output directory. - -LATEX_CMD_NAME = latex - -# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to -# generate index for LaTeX. If left blank `makeindex' will be used as the -# default command name. - -MAKEINDEX_CMD_NAME = makeindex - -# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact -# LaTeX documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_LATEX = NO - -# The PAPER_TYPE tag can be used to set the paper type that is used -# by the printer. Possible values are: a4, a4wide, letter, legal and -# executive. If left blank a4wide will be used. - -PAPER_TYPE = a4 - -# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX -# packages that should be included in the LaTeX output. - -EXTRA_PACKAGES = - -# The LATEX_HEADER tag can be used to specify a personal LaTeX header for -# the generated latex document. The header should contain everything until -# the first chapter. If it is left blank doxygen will generate a -# standard header. Notice: only use this tag if you know what you are doing! - -LATEX_HEADER = - -# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated -# is prepared for conversion to pdf (using ps2pdf). The pdf file will -# contain links (just like the HTML output) instead of page references -# This makes the output suitable for online browsing using a pdf viewer. - -PDF_HYPERLINKS = NO - -# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of -# plain latex in the generated Makefile. Set this option to YES to get a -# higher quality PDF documentation. - -USE_PDFLATEX = NO - -# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. -# command to the generated LaTeX files. This will instruct LaTeX to keep -# running if errors occur, instead of asking the user for help. -# This option is also used when generating formulas in HTML. - -LATEX_BATCHMODE = NO - -# If LATEX_HIDE_INDICES is set to YES then doxygen will not -# include the index chapters (such as File Index, Compound Index, etc.) -# in the output. - -LATEX_HIDE_INDICES = NO - -# If LATEX_SOURCE_CODE is set to YES then doxygen will include -# source code with syntax highlighting in the LaTeX output. -# Note that which sources are shown also depends on other settings -# such as SOURCE_BROWSER. - -LATEX_SOURCE_CODE = NO - -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- - -# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output -# The RTF output is optimized for Word 97 and may not look very pretty with -# other RTF readers or editors. - -GENERATE_RTF = NO - -# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `rtf' will be used as the default path. - -RTF_OUTPUT = rtf - -# If the COMPACT_RTF tag is set to YES Doxygen generates more compact -# RTF documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_RTF = NO - -# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated -# will contain hyperlink fields. The RTF file will -# contain links (just like the HTML output) instead of page references. -# This makes the output suitable for online browsing using WORD or other -# programs which support those fields. -# Note: wordpad (write) and others do not support links. - -RTF_HYPERLINKS = NO - -# Load stylesheet definitions from file. Syntax is similar to doxygen's -# config file, i.e. a series of assignments. You only have to provide -# replacements, missing definitions are set to their default value. - -RTF_STYLESHEET_FILE = - -# Set optional variables used in the generation of an rtf document. -# Syntax is similar to doxygen's config file. - -RTF_EXTENSIONS_FILE = - -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- - -# If the GENERATE_MAN tag is set to YES (the default) Doxygen will -# generate man pages - -GENERATE_MAN = NO - -# The MAN_OUTPUT tag is used to specify where the man pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `man' will be used as the default path. - -MAN_OUTPUT = - -# The MAN_EXTENSION tag determines the extension that is added to -# the generated man pages (default is the subroutine's section .3) - -MAN_EXTENSION = .3 - -# If the MAN_LINKS tag is set to YES and Doxygen generates man output, -# then it will generate one additional man file for each entity -# documented in the real man page(s). These additional files -# only source the real man page, but without them the man command -# would be unable to find the correct page. The default is NO. - -MAN_LINKS = NO - -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- - -# If the GENERATE_XML tag is set to YES Doxygen will -# generate an XML file that captures the structure of -# the code including all documentation. - -GENERATE_XML = NO - -# The XML_OUTPUT tag is used to specify where the XML pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `xml' will be used as the default path. - -XML_OUTPUT = xml - -# The XML_SCHEMA tag can be used to specify an XML schema, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_SCHEMA = - -# The XML_DTD tag can be used to specify an XML DTD, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_DTD = - -# If the XML_PROGRAMLISTING tag is set to YES Doxygen will -# dump the program listings (including syntax highlighting -# and cross-referencing information) to the XML output. Note that -# enabling this will significantly increase the size of the XML output. - -XML_PROGRAMLISTING = YES - -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- - -# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will -# generate an AutoGen Definitions (see autogen.sf.net) file -# that captures the structure of the code including all -# documentation. Note that this feature is still experimental -# and incomplete at the moment. - -GENERATE_AUTOGEN_DEF = NO - -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- - -# If the GENERATE_PERLMOD tag is set to YES Doxygen will -# generate a Perl module file that captures the structure of -# the code including all documentation. Note that this -# feature is still experimental and incomplete at the -# moment. - -GENERATE_PERLMOD = NO - -# If the PERLMOD_LATEX tag is set to YES Doxygen will generate -# the necessary Makefile rules, Perl scripts and LaTeX code to be able -# to generate PDF and DVI output from the Perl module output. - -PERLMOD_LATEX = NO - -# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be -# nicely formatted so it can be parsed by a human reader. -# This is useful -# if you want to understand what is going on. -# On the other hand, if this -# tag is set to NO the size of the Perl module output will be much smaller -# and Perl will parse it just the same. - -PERLMOD_PRETTY = YES - -# The names of the make variables in the generated doxyrules.make file -# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. -# This is useful so different doxyrules.make files included by the same -# Makefile don't overwrite each other's variables. - -PERLMOD_MAKEVAR_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- - -# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will -# evaluate all C-preprocessor directives found in the sources and include -# files. - -ENABLE_PREPROCESSING = YES - -# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro -# names in the source code. If set to NO (the default) only conditional -# compilation will be performed. Macro expansion can be done in a controlled -# way by setting EXPAND_ONLY_PREDEF to YES. - -MACRO_EXPANSION = YES - -# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES -# then the macro expansion is limited to the macros specified with the -# PREDEFINED and EXPAND_AS_DEFINED tags. - -EXPAND_ONLY_PREDEF = NO - -# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files -# in the INCLUDE_PATH (see below) will be search if a #include is found. - -SEARCH_INCLUDES = YES - -# The INCLUDE_PATH tag can be used to specify one or more directories that -# contain include files that are not input files but should be processed by -# the preprocessor. - -INCLUDE_PATH = . - -# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard -# patterns (like *.h and *.hpp) to filter out the header-files in the -# directories. If left blank, the patterns specified with FILE_PATTERNS will -# be used. - -INCLUDE_FILE_PATTERNS = - -# The PREDEFINED tag can be used to specify one or more macro names that -# are defined before the preprocessor is started (similar to the -D option of -# gcc). The argument of the tag is a list of macros of the form: name -# or name=definition (no spaces). If the definition and the = are -# omitted =1 is assumed. To prevent a macro definition from being -# undefined via #undef or recursively expanded use the := operator -# instead of the = operator. - -PREDEFINED = _WIN32 \ - _WINDOWS \ - __FreeBSD__ \ - CRYPTOPP_DOXYGEN_PROCESSING - -# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then -# this tag can be used to specify a list of macro names that should be expanded. -# The macro definition that is found in the sources will be used. -# Use the PREDEFINED tag if you want to use a different macro definition. - -EXPAND_AS_DEFINED = - -# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then -# doxygen's preprocessor will remove all function-like macros that are alone -# on a line, have an all uppercase name, and do not end with a semicolon. Such -# function macros are typically used for boiler-plate code, and will confuse -# the parser if not removed. - -SKIP_FUNCTION_MACROS = YES - -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- - -# The TAGFILES option can be used to specify one or more tagfiles. -# Optionally an initial location of the external documentation -# can be added for each tagfile. The format of a tag file without -# this location is as follows: -# -# TAGFILES = file1 file2 ... -# Adding location for the tag files is done as follows: -# -# TAGFILES = file1=loc1 "file2 = loc2" ... -# where "loc1" and "loc2" can be relative or absolute paths or -# URLs. If a location is present for each tag, the installdox tool -# does not have to be run to correct the links. -# Note that each tag file must have a unique name -# (where the name does NOT include the path) -# If a tag file is not located in the directory in which doxygen -# is run, you must also specify the path to the tagfile here. - -TAGFILES = - -# When a file name is specified after GENERATE_TAGFILE, doxygen will create -# a tag file that is based on the input files it reads. - -GENERATE_TAGFILE = - -# If the ALLEXTERNALS tag is set to YES all external classes will be listed -# in the class index. If set to NO only the inherited external classes -# will be listed. - -ALLEXTERNALS = NO - -# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed -# in the modules index. If set to NO, only the current project's groups will -# be listed. - -EXTERNAL_GROUPS = YES - -# The PERL_PATH should be the absolute path and name of the perl script -# interpreter (i.e. the result of `which perl'). - -PERL_PATH = /usr/bin/perl - -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- - -# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will -# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base -# or super classes. Setting the tag to NO turns the diagrams off. Note that -# this option is superseded by the HAVE_DOT option below. This is only a -# fallback. It is recommended to install and use dot, since it yields more -# powerful graphs. - -CLASS_DIAGRAMS = YES - -# You can define message sequence charts within doxygen comments using the \msc -# command. Doxygen will then run the mscgen tool (see -# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the -# documentation. The MSCGEN_PATH tag allows you to specify the directory where -# the mscgen tool resides. If left empty the tool is assumed to be found in the -# default search path. - -MSCGEN_PATH = - -# If set to YES, the inheritance and collaboration graphs will hide -# inheritance and usage relations if the target is undocumented -# or is not a class. - -HIDE_UNDOC_RELATIONS = YES - -# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is -# available from the path. This tool is part of Graphviz, a graph visualization -# toolkit from AT&T and Lucent Bell Labs. The other options in this section -# have no effect if this option is set to NO (the default) - -HAVE_DOT = NO - -# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is -# allowed to run in parallel. When set to 0 (the default) doxygen will -# base this on the number of processors available in the system. You can set it -# explicitly to a value larger than 0 to get control over the balance -# between CPU load and processing speed. - -DOT_NUM_THREADS = 0 - -# By default doxygen will write a font called FreeSans.ttf to the output -# directory and reference it in all dot files that doxygen generates. This -# font does not include all possible unicode characters however, so when you need -# these (or just want a differently looking font) you can specify the font name -# using DOT_FONTNAME. You need need to make sure dot is able to find the font, -# which can be done by putting it in a standard location or by setting the -# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory -# containing the font. - -DOT_FONTNAME = FreeSans.ttf - -# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. -# The default size is 10pt. - -DOT_FONTSIZE = 10 - -# By default doxygen will tell dot to use the output directory to look for the -# FreeSans.ttf font (which doxygen will put there itself). If you specify a -# different font using DOT_FONTNAME you can set the path where dot -# can find it using this tag. - -DOT_FONTPATH = - -# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect inheritance relations. Setting this tag to YES will force the -# the CLASS_DIAGRAMS tag to NO. - -CLASS_GRAPH = YES - -# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect implementation dependencies (inheritance, containment, and -# class references variables) of the class with other documented classes. - -COLLABORATION_GRAPH = YES - -# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for groups, showing the direct groups dependencies - -GROUP_GRAPHS = YES - -# If the UML_LOOK tag is set to YES doxygen will generate inheritance and -# collaboration diagrams in a style similar to the OMG's Unified Modeling -# Language. - -UML_LOOK = NO - -# If set to YES, the inheritance and collaboration graphs will show the -# relations between templates and their instances. - -TEMPLATE_RELATIONS = YES - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT -# tags are set to YES then doxygen will generate a graph for each documented -# file showing the direct and indirect include dependencies of the file with -# other documented files. - -INCLUDE_GRAPH = YES - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and -# HAVE_DOT tags are set to YES then doxygen will generate a graph for each -# documented header file showing the documented files that directly or -# indirectly include this file. - -INCLUDED_BY_GRAPH = YES - -# If the CALL_GRAPH and HAVE_DOT options are set to YES then -# doxygen will generate a call dependency graph for every global function -# or class method. Note that enabling this option will significantly increase -# the time of a run. So in most cases it will be better to enable call graphs -# for selected functions only using the \callgraph command. - -CALL_GRAPH = NO - -# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then -# doxygen will generate a caller dependency graph for every global function -# or class method. Note that enabling this option will significantly increase -# the time of a run. So in most cases it will be better to enable caller -# graphs for selected functions only using the \callergraph command. - -CALLER_GRAPH = NO - -# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen -# will graphical hierarchy of all classes instead of a textual one. - -GRAPHICAL_HIERARCHY = YES - -# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES -# then doxygen will show the dependencies a directory has on other directories -# in a graphical way. The dependency relations are determined by the #include -# relations between the files in the directories. - -DIRECTORY_GRAPH = YES - -# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. Possible values are png, jpg, or gif -# If left blank png will be used. - -DOT_IMAGE_FORMAT = png - -# The tag DOT_PATH can be used to specify the path where the dot tool can be -# found. If left blank, it is assumed the dot tool can be found in the path. - -DOT_PATH = - -# The DOTFILE_DIRS tag can be used to specify one or more directories that -# contain dot files that are included in the documentation (see the -# \dotfile command). - -DOTFILE_DIRS = - -# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of -# nodes that will be shown in the graph. If the number of nodes in a graph -# becomes larger than this value, doxygen will truncate the graph, which is -# visualized by representing a node as a red box. Note that doxygen if the -# number of direct children of the root node in a graph is already larger than -# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note -# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. - -DOT_GRAPH_MAX_NODES = 50 - -# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the -# graphs generated by dot. A depth value of 3 means that only nodes reachable -# from the root by following a path via at most 3 edges will be shown. Nodes -# that lay further from the root node will be omitted. Note that setting this -# option to 1 or 2 may greatly reduce the computation time needed for large -# code bases. Also note that the size of a graph can be further restricted by -# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. - -MAX_DOT_GRAPH_DEPTH = 0 - -# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, because dot on Windows does not -# seem to support this out of the box. Warning: Depending on the platform used, -# enabling this option may lead to badly anti-aliased labels on the edges of -# a graph (i.e. they become hard to read). - -DOT_TRANSPARENT = NO - -# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output -# files in one run (i.e. multiple -o and -T options on the command line). This -# makes dot run faster, but since only newer versions of dot (>1.8.10) -# support this, this feature is disabled by default. - -DOT_MULTI_TARGETS = NO - -# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will -# generate a legend page explaining the meaning of the various boxes and -# arrows in the dot generated graphs. - -GENERATE_LEGEND = YES - -# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will -# remove the intermediate dot files that are used to generate -# the various graphs. - -DOT_CLEANUP = YES diff --git a/lib/cryptopp/License.txt b/lib/cryptopp/License.txt deleted file mode 100644 index c5d3f34b1..000000000 --- a/lib/cryptopp/License.txt +++ /dev/null @@ -1,51 +0,0 @@ -Compilation Copyright (c) 1995-2013 by Wei Dai. All rights reserved. -This copyright applies only to this software distribution package -as a compilation, and does not imply a copyright on any particular -file in the package. - -All individual files in this compilation are placed in the public domain by -Wei Dai and other contributors. - -I would like to thank the following authors for placing their works into -the public domain: - -Joan Daemen - 3way.cpp -Leonard Janke - cast.cpp, seal.cpp -Steve Reid - cast.cpp -Phil Karn - des.cpp -Andrew M. Kuchling - md2.cpp, md4.cpp -Colin Plumb - md5.cpp -Seal Woods - rc6.cpp -Chris Morgan - rijndael.cpp -Paulo Baretto - rijndael.cpp, skipjack.cpp, square.cpp -Richard De Moliner - safer.cpp -Matthew Skala - twofish.cpp -Kevin Springle - camellia.cpp, shacal2.cpp, ttmac.cpp, whrlpool.cpp, ripemd.cpp -Ronny Van Keer - sha3.cpp - -The Crypto++ Library (as a compilation) is currently licensed under the Boost -Software License 1.0 (http://www.boost.org/users/license.html). - -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/lib/cryptopp/Readme.txt b/lib/cryptopp/Readme.txt deleted file mode 100644 index 5f3b4525d..000000000 --- a/lib/cryptopp/Readme.txt +++ /dev/null @@ -1,452 +0,0 @@ -Crypto++: a C++ Class Library of Cryptographic Schemes -Version 5.6.2 - 2/20/2013 - -Crypto++ Library is a free C++ class library of cryptographic schemes. -Currently the library contains the following algorithms: - - algorithm type name - - authenticated encryption schemes GCM, CCM, EAX - - high speed stream ciphers Panama, Sosemanuk, Salsa20, XSalsa20 - - AES and AES candidates AES (Rijndael), RC6, MARS, Twofish, Serpent, - CAST-256 - - IDEA, Triple-DES (DES-EDE2 and DES-EDE3), - other block ciphers Camellia, SEED, RC5, Blowfish, TEA, XTEA, - Skipjack, SHACAL-2 - - block cipher modes of operation ECB, CBC, CBC ciphertext stealing (CTS), - CFB, OFB, counter mode (CTR) - - message authentication codes VMAC, HMAC, GMAC, CMAC, CBC-MAC, DMAC, - Two-Track-MAC - - SHA-1, SHA-2 (SHA-224, SHA-256, SHA-384, and - hash functions SHA-512), SHA-3, Tiger, WHIRLPOOL, RIPEMD-128, - RIPEMD-256, RIPEMD-160, RIPEMD-320 - - RSA, DSA, ElGamal, Nyberg-Rueppel (NR), - public-key cryptography Rabin-Williams (RW), LUC, LUCELG, - DLIES (variants of DHAES), ESIGN - - padding schemes for public-key PKCS#1 v2.0, OAEP, PSS, PSSR, IEEE P1363 - systems EMSA2 and EMSA5 - - Diffie-Hellman (DH), Unified Diffie-Hellman - key agreement schemes (DH2), Menezes-Qu-Vanstone (MQV), LUCDIF, - XTR-DH - - elliptic curve cryptography ECDSA, ECNR, ECIES, ECDH, ECMQV - - insecure or obsolescent MD2, MD4, MD5, Panama Hash, DES, ARC4, SEAL -algorithms retained for backwards 3.0, WAKE-OFB, DESX (DES-XEX3), RC2, - compatibility and historical SAFER, 3-WAY, GOST, SHARK, CAST-128, Square - value - -Other features include: - - * pseudo random number generators (PRNG): ANSI X9.17 appendix C, RandomPool - * password based key derivation functions: PBKDF1 and PBKDF2 from PKCS #5, - PBKDF from PKCS #12 appendix B - * Shamir's secret sharing scheme and Rabin's information dispersal algorithm - (IDA) - * fast multi-precision integer (bignum) and polynomial operations - * finite field arithmetics, including GF(p) and GF(2^n) - * prime number generation and verification - * useful non-cryptographic algorithms - + DEFLATE (RFC 1951) compression/decompression with gzip (RFC 1952) and - zlib (RFC 1950) format support - + hex, base-32, and base-64 coding/decoding - + 32-bit CRC and Adler32 checksum - * class wrappers for these operating system features (optional): - + high resolution timers on Windows, Unix, and Mac OS - + Berkeley and Windows style sockets - + Windows named pipes - + /dev/random, /dev/urandom, /dev/srandom - + Microsoft's CryptGenRandom on Windows - * A high level interface for most of the above, using a filter/pipeline - metaphor - * benchmarks and validation testing - * x86, x86-64 (x64), MMX, and SSE2 assembly code for the most commonly used - algorithms, with run-time CPU feature detection and code selection - * some versions are available in FIPS 140-2 validated form - -You are welcome to use it for any purpose without paying me, but see -License.txt for the fine print. - -The following compilers are supported for this release. Please visit -http://www.cryptopp.com the most up to date build instructions and porting notes. - - * MSVC 6.0 - 2010 - * GCC 3.3 - 4.5 - * C++Builder 2010 - * Intel C++ Compiler 9 - 11.1 - * Sun Studio 12u1, Express 11/08, Express 06/10 - -*** Important Usage Notes *** - -1. If a constructor for A takes a pointer to an object B (except primitive -types such as int and char), then A owns B and will delete B at A's -destruction. If a constructor for A takes a reference to an object B, -then the caller retains ownership of B and should not destroy it until -A no longer needs it. - -2. Crypto++ is thread safe at the class level. This means you can use -Crypto++ safely in a multithreaded application, but you must provide -synchronization when multiple threads access a common Crypto++ object. - -*** MSVC-Specific Information *** - -On Windows, Crypto++ can be compiled into 3 forms: a static library -including all algorithms, a DLL with only FIPS Approved algorithms, and -a static library with only algorithms not in the DLL. -(FIPS Approved means Approved according to the FIPS 140-2 standard.) -The DLL may be used by itself, or it may be used together with the second -form of the static library. MSVC project files are included to build -all three forms, and sample applications using each of the three forms -are also included. - -To compile Crypto++ with MSVC, open the "cryptest.dsw" (for MSVC 6 and MSVC .NET -2003) or "cryptest.sln" (for MSVC 2005 - 2010) workspace file and build one or -more of the following projects: - -cryptopp - This builds the DLL. Please note that if you wish to use Crypto++ - as a FIPS validated module, you must use a pre-built DLL that has undergone - the FIPS validation process instead of building your own. -dlltest - This builds a sample application that only uses the DLL. -cryptest Non-DLL-Import Configuration - This builds the full static library - along with a full test driver. -cryptest DLL-Import Configuration - This builds a static library containing - only algorithms not in the DLL, along with a full test driver that uses - both the DLL and the static library. - -To use the Crypto++ DLL in your application, #include "dll.h" before including -any other Crypto++ header files, and place the DLL in the same directory as -your .exe file. dll.h includes the line #pragma comment(lib, "cryptopp") -so you don't have to explicitly list the import library in your project -settings. To use a static library form of Crypto++, make the "cryptlib" -project a dependency of your application project, or specify it as -an additional library to link with in your project settings. -In either case you should check the compiler options to -make sure that the library and your application are using the same C++ -run-time libraries and calling conventions. - -*** DLL Memory Management *** - -Because it's possible for the Crypto++ DLL to delete objects allocated -by the calling application, they must use the same C++ memory heap. Three -methods are provided to achieve this. -1. The calling application can tell Crypto++ what heap to use. This method - is required when the calling application uses a non-standard heap. -2. Crypto++ can tell the calling application what heap to use. This method - is required when the calling application uses a statically linked C++ Run - Time Library. (Method 1 does not work in this case because the Crypto++ DLL - is initialized before the calling application's heap is initialized.) -3. Crypto++ can automatically use the heap provided by the calling application's - dynamically linked C++ Run Time Library. The calling application must - make sure that the dynamically linked C++ Run Time Library is initialized - before Crypto++ is loaded. (At this time it is not clear if it is possible - to control the order in which DLLs are initialized on Windows 9x machines, - so it might be best to avoid using this method.) - -When Crypto++ attaches to a new process, it searches all modules loaded -into the process space for exported functions "GetNewAndDeleteForCryptoPP" -and "SetNewAndDeleteFromCryptoPP". If one of these functions is found, -Crypto++ uses methods 1 or 2, respectively, by calling the function. -Otherwise, method 3 is used. - -*** GCC-Specific Information *** - -A makefile is included for you to compile Crypto++ with GCC. Make sure -you are using GNU Make and GNU ld. The make process will produce two files, -libcryptopp.a and cryptest.exe. Run "cryptest.exe v" for the validation -suite. - -*** Documentation and Support *** - -Crypto++ is documented through inline comments in header files, which are -processed through Doxygen to produce an HTML reference manual. You can find -a link to the manual from http://www.cryptopp.com. Also at that site is -the Crypto++ FAQ, which you should browse through before attempting to -use this library, because it will likely answer many of questions that -may come up. - -If you run into any problems, please try the Crypto++ mailing list. -The subscription information and the list archive are available on -http://www.cryptopp.com. You can also email me directly by visiting -http://www.weidai.com, but you will probably get a faster response through -the mailing list. - -*** History *** - -1.0 - First public release. Withdrawn at the request of RSA DSI. - - included Blowfish, BBS, DES, DH, Diamond, DSA, ElGamal, IDEA, - MD5, RC4, RC5, RSA, SHA, WAKE, secret sharing, DEFLATE compression - - had a serious bug in the RSA key generation code. - -1.1 - Removed RSA, RC4, RC5 - - Disabled calls to RSAREF's non-public functions - - Minor bugs fixed - -2.0 - a completely new, faster multiprecision integer class - - added MD5-MAC, HAVAL, 3-WAY, TEA, SAFER, LUC, Rabin, BlumGoldwasser, - elliptic curve algorithms - - added the Lucas strong probable primality test - - ElGamal encryption and signature schemes modified to avoid weaknesses - - Diamond changed to Diamond2 because of key schedule weakness - - fixed bug in WAKE key setup - - SHS class renamed to SHA - - lots of miscellaneous optimizations - -2.1 - added Tiger, HMAC, GOST, RIPE-MD160, LUCELG, LUCDIF, XOR-MAC, - OAEP, PSSR, SHARK - - added precomputation to DH, ElGamal, DSA, and elliptic curve algorithms - - added back RC5 and a new RSA - - optimizations in elliptic curves over GF(p) - - changed Rabin to use OAEP and PSSR - - changed many classes to allow copy constructors to work correctly - - improved exception generation and handling - -2.2 - added SEAL, CAST-128, Square - - fixed bug in HAVAL (padding problem) - - fixed bug in triple-DES (decryption order was reversed) - - fixed bug in RC5 (couldn't handle key length not a multiple of 4) - - changed HMAC to conform to RFC-2104 (which is not compatible - with the original HMAC) - - changed secret sharing and information dispersal to use GF(2^32) - instead of GF(65521) - - removed zero knowledge prover/verifier for graph isomorphism - - removed several utility classes in favor of the C++ standard library - -2.3 - ported to EGCS - - fixed incomplete workaround of min/max conflict in MSVC - -3.0 - placed all names into the "CryptoPP" namespace - - added MD2, RC2, RC6, MARS, RW, DH2, MQV, ECDHC, CBC-CTS - - added abstract base classes PK_SimpleKeyAgreementDomain and - PK_AuthenticatedKeyAgreementDomain - - changed DH and LUCDIF to implement the PK_SimpleKeyAgreementDomain - interface and to perform domain parameter and key validation - - changed interfaces of PK_Signer and PK_Verifier to sign and verify - messages instead of message digests - - changed OAEP to conform to PKCS#1 v2.0 - - changed benchmark code to produce HTML tables as output - - changed PSSR to track IEEE P1363a - - renamed ElGamalSignature to NR and changed it to track IEEE P1363 - - renamed ECKEP to ECMQVC and changed it to track IEEE P1363 - - renamed several other classes for clarity - - removed support for calling RSAREF - - removed option to compile old SHA (SHA-0) - - removed option not to throw exceptions - -3.1 - added ARC4, Rijndael, Twofish, Serpent, CBC-MAC, DMAC - - added interface for querying supported key lengths of symmetric ciphers - and MACs - - added sample code for RSA signature and verification - - changed CBC-CTS to be compatible with RFC 2040 - - updated SEAL to version 3.0 of the cipher specification - - optimized multiprecision squaring and elliptic curves over GF(p) - - fixed bug in MARS key setup - - fixed bug with attaching objects to Deflator - -3.2 - added DES-XEX3, ECDSA, DefaultEncryptorWithMAC - - renamed DES-EDE to DES-EDE2 and TripleDES to DES-EDE3 - - optimized ARC4 - - generalized DSA to allow keys longer than 1024 bits - - fixed bugs in GF2N and ModularArithmetic that can cause calculation errors - - fixed crashing bug in Inflator when given invalid inputs - - fixed endian bug in Serpent - - fixed padding bug in Tiger - -4.0 - added Skipjack, CAST-256, Panama, SHA-2 (SHA-256, SHA-384, and SHA-512), - and XTR-DH - - added a faster variant of Rabin's Information Dispersal Algorithm (IDA) - - added class wrappers for these operating system features: - - high resolution timers on Windows, Unix, and MacOS - - Berkeley and Windows style sockets - - Windows named pipes - - /dev/random and /dev/urandom on Linux and FreeBSD - - Microsoft's CryptGenRandom on Windows - - added support for SEC 1 elliptic curve key format and compressed points - - added support for X.509 public key format (subjectPublicKeyInfo) for - RSA, DSA, and elliptic curve schemes - - added support for DER and OpenPGP signature format for DSA - - added support for ZLIB compressed data format (RFC 1950) - - changed elliptic curve encryption to use ECIES (as defined in SEC 1) - - changed MARS key schedule to reflect the latest specification - - changed BufferedTransformation interface to support multiple channels - and messages - - changed CAST and SHA-1 implementations to use public domain source code - - fixed bug in StringSource - - optmized multi-precision integer code for better performance - -4.1 - added more support for the recommended elliptic curve parameters in SEC 2 - - added Panama MAC, MARC4 - - added IV stealing feature to CTS mode - - added support for PKCS #8 private key format for RSA, DSA, and elliptic - curve schemes - - changed Deflate, MD5, Rijndael, and Twofish to use public domain code - - fixed a bug with flushing compressed streams - - fixed a bug with decompressing stored blocks - - fixed a bug with EC point decompression using non-trinomial basis - - fixed a bug in NetworkSource::GeneralPump() - - fixed a performance issue with EC over GF(p) decryption - - fixed syntax to allow GCC to compile without -fpermissive - - relaxed some restrictions in the license - -4.2 - added support for longer HMAC keys - - added MD4 (which is not secure so use for compatibility purposes only) - - added compatibility fixes/workarounds for STLport 4.5, GCC 3.0.2, - and MSVC 7.0 - - changed MD2 to use public domain code - - fixed a bug with decompressing multiple messages with the same object - - fixed a bug in CBC-MAC with MACing multiple messages with the same object - - fixed a bug in RC5 and RC6 with zero-length keys - - fixed a bug in Adler32 where incorrect checksum may be generated - -5.0 - added ESIGN, DLIES, WAKE-OFB, PBKDF1 and PBKDF2 from PKCS #5 - - added key validation for encryption and signature public/private keys - - renamed StreamCipher interface to SymmetricCipher, which is now implemented - by both stream ciphers and block cipher modes including ECB and CBC - - added keying interfaces to support resetting of keys and IVs without - having to destroy and recreate objects - - changed filter interface to support non-blocking input/output - - changed SocketSource and SocketSink to use overlapped I/O on Microsoft Windows - - grouped related classes inside structs to help templates, for example - AESEncryption and AESDecryption are now AES::Encryption and AES::Decryption - - where possible, typedefs have been added to improve backwards - compatibility when the CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY macro is defined - - changed Serpent, HAVAL and IDEA to use public domain code - - implemented SSE2 optimizations for Integer operations - - fixed a bug in HMAC::TruncatedFinal() - - fixed SKIPJACK byte ordering following NIST clarification dated 5/9/02 - -5.01 - added known answer test for X9.17 RNG in FIPS 140 power-up self test - - submitted to NIST/CSE, but not publicly released - -5.02 - changed EDC test to MAC integrity check using HMAC/SHA1 - - improved performance of integrity check - - added blinding to defend against RSA timing attack - -5.03 - created DLL version of Crypto++ for FIPS 140-2 validation - - fixed vulnerabilities in GetNextIV for CTR and OFB modes - -5.0.4 - Removed DES, SHA-256, SHA-384, SHA-512 from DLL - -5.1 - added PSS padding and changed PSSR to track IEEE P1363a draft standard - - added blinding for RSA and Rabin to defend against timing attacks - on decryption operations - - changed signing and decryption APIs to support the above - - changed WaitObjectContainer to allow waiting for more than 64 - objects at a time on Win32 platforms - - fixed a bug in CBC and ECB modes with processing non-aligned data - - fixed standard conformance bugs in DLIES (DHAES mode) and RW/EMSA2 - signature scheme (these fixes are not backwards compatible) - - fixed a number of compiler warnings, minor bugs, and portability problems - - removed Sapphire - -5.2 - merged in changes for 5.01 - 5.0.4 - - added support for using encoding parameters and key derivation parameters - with public key encryption (implemented by OAEP and DL/ECIES) - - added Camellia, SHACAL-2, Two-Track-MAC, Whirlpool, RIPEMD-320, - RIPEMD-128, RIPEMD-256, Base-32 coding, FIPS variant of CFB mode - - added ThreadUserTimer for timing thread CPU usage - - added option for password-based key derivation functions - to iterate until a mimimum elapsed thread CPU time is reached - - added option (on by default) for DEFLATE compression to detect - uncompressible files and process them more quickly - - improved compatibility and performance on 64-bit platforms, - including Alpha, IA-64, x86-64, PPC64, Sparc64, and MIPS64 - - fixed ONE_AND_ZEROS_PADDING to use 0x80 instead 0x01 as padding. - - fixed encoding/decoding of PKCS #8 privateKeyInfo to properly - handle optional attributes - -5.2.1 - fixed bug in the "dlltest" DLL testing program - - fixed compiling with STLport using VC .NET - - fixed compiling with -fPIC using GCC - - fixed compiling with -msse2 on systems without memalign() - - fixed inability to instantiate PanamaMAC - - fixed problems with inline documentation - -5.2.2 - added SHA-224 - - put SHA-256, SHA-384, SHA-512, RSASSA-PSS into DLL - -5.2.3 - fixed issues with FIPS algorithm test vectors - - put RSASSA-ISO into DLL - -5.3 - ported to MSVC 2005 with support for x86-64 - - added defense against AES timing attacks, and more AES test vectors - - changed StaticAlgorithmName() of Rijndael to "AES", CTR to "CTR" - -5.4 - added Salsa20 - - updated Whirlpool to version 3.0 - - ported to GCC 4.1, Sun C++ 5.8, and Borland C++Builder 2006 - -5.5 - added VMAC and Sosemanuk (with x86-64 and SSE2 assembly) - - improved speed of integer arithmetic, AES, SHA-512, Tiger, Salsa20, - Whirlpool, and PANAMA cipher using assembly (x86-64, MMX, SSE2) - - optimized Camellia and added defense against timing attacks - - updated benchmarks code to show cycles per byte and to time key/IV setup - - started using OpenMP for increased multi-core speed - - enabled GCC optimization flags by default in GNUmakefile - - added blinding and computational error checking for RW signing - - changed RandomPool, X917RNG, GetNextIV, DSA/NR/ECDSA/ECNR to reduce - the risk of reusing random numbers and IVs after virtual machine state - rollback - - changed default FIPS mode RNG from AutoSeededX917RNG to - AutoSeededX917RNG - - fixed PANAMA cipher interface to accept 256-bit key and 256-bit IV - - moved MD2, MD4, MD5, PanamaHash, ARC4, WAKE_CFB into the namespace "Weak" - - removed HAVAL, MD5-MAC, XMAC - -5.5.1 - fixed VMAC validation failure on 32-bit big-endian machines - -5.5.2 - ported x64 assembly language code for AES, Salsa20, Sosemanuk, and Panama - to MSVC 2005 (using MASM since MSVC doesn't support inline assembly on x64) - - fixed Salsa20 initialization crash on non-SSE2 machines - - fixed Whirlpool crash on Pentium 2 machines - - fixed possible branch prediction analysis (BPA) vulnerability in - MontgomeryReduce(), which may affect security of RSA, RW, LUC - - fixed link error with MSVC 2003 when using "debug DLL" form of runtime library - - fixed crash in SSE2_Add on P4 machines when compiled with - MSVC 6.0 SP5 with Processor Pack - - ported to MSVC 2008, GCC 4.2, Sun CC 5.9, Intel C++ Compiler 10.0, - and Borland C++Builder 2007 - -5.6.0 - added AuthenticatedSymmetricCipher interface class and Filter wrappers - - added CCM, GCM (with SSE2 assembly), EAX, CMAC, XSalsa20, and SEED - - added support for variable length IVs - - added OIDs for Brainpool elliptic curve parameters - - improved AES and SHA-256 speed on x86 and x64 - - changed BlockTransformation interface to no longer assume data alignment - - fixed incorrect VMAC computation on message lengths - that are >64 mod 128 (x86 assembly version is not affected) - - fixed compiler error in vmac.cpp on x86 with GCC -fPIC - - fixed run-time validation error on x86-64 with GCC 4.3.2 -O2 - - fixed HashFilter bug when putMessage=true - - fixed AES-CTR data alignment bug that causes incorrect encryption on ARM - - removed WORD64_AVAILABLE; compiler support for 64-bit int is now required - - ported to GCC 4.3, C++Builder 2009, Sun CC 5.10, Intel C++ Compiler 11 - -5.6.1 - added support for AES-NI and CLMUL instruction sets in AES and GMAC/GCM - - removed WAKE-CFB - - fixed several bugs in the SHA-256 x86/x64 assembly code: - * incorrect hash on non-SSE2 x86 machines on non-aligned input - * incorrect hash on x86 machines when input crosses 0x80000000 - * incorrect hash on x64 when compiled with GCC with optimizations enabled - - fixed bugs in AES x86 and x64 assembly causing crashes in some MSVC build configurations - - switched to a public domain implementation of MARS - - ported to MSVC 2010, GCC 4.5.1, Sun Studio 12u1, C++Builder 2010, Intel C++ Compiler 11.1 - - renamed the MSVC DLL project to "cryptopp" for compatibility with MSVC 2010 - -5.6.2 - changed license to Boost Software License 1.0 - - added SHA-3 (Keccak) - - updated DSA to FIPS 186-3 (see DSA2 class) - - fixed Blowfish minimum keylength to be 4 bytes (32 bits) - - fixed Salsa validation failure when compiling with GCC 4.6 - - fixed infinite recursion when on x64, assembly disabled, and no AESNI - - ported to MSVC 2012, GCC 4.7, Clang 3.2, Solaris Studio 12.3, Intel C++ Compiler 13.0 - -Written by Wei Dai diff --git a/lib/cryptopp/adler32.cpp b/lib/cryptopp/adler32.cpp deleted file mode 100644 index 0d52c0838..000000000 --- a/lib/cryptopp/adler32.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// adler32.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "adler32.h" - -NAMESPACE_BEGIN(CryptoPP) - -void Adler32::Update(const byte *input, size_t length) -{ - const unsigned long BASE = 65521; - - unsigned long s1 = m_s1; - unsigned long s2 = m_s2; - - if (length % 8 != 0) - { - do - { - s1 += *input++; - s2 += s1; - length--; - } while (length % 8 != 0); - - if (s1 >= BASE) - s1 -= BASE; - s2 %= BASE; - } - - while (length > 0) - { - s1 += input[0]; s2 += s1; - s1 += input[1]; s2 += s1; - s1 += input[2]; s2 += s1; - s1 += input[3]; s2 += s1; - s1 += input[4]; s2 += s1; - s1 += input[5]; s2 += s1; - s1 += input[6]; s2 += s1; - s1 += input[7]; s2 += s1; - - length -= 8; - input += 8; - - if (s1 >= BASE) - s1 -= BASE; - if (length % 0x8000 == 0) - s2 %= BASE; - } - - assert(s1 < BASE); - assert(s2 < BASE); - - m_s1 = (word16)s1; - m_s2 = (word16)s2; -} - -void Adler32::TruncatedFinal(byte *hash, size_t size) -{ - ThrowIfInvalidTruncatedSize(size); - - switch (size) - { - default: - hash[3] = byte(m_s1); - case 3: - hash[2] = byte(m_s1 >> 8); - case 2: - hash[1] = byte(m_s2); - case 1: - hash[0] = byte(m_s2 >> 8); - case 0: - ; - } - - Reset(); -} - -NAMESPACE_END diff --git a/lib/cryptopp/adler32.h b/lib/cryptopp/adler32.h deleted file mode 100644 index 0ed803da9..000000000 --- a/lib/cryptopp/adler32.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef CRYPTOPP_ADLER32_H -#define CRYPTOPP_ADLER32_H - -#include "cryptlib.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! ADLER-32 checksum calculations -class Adler32 : public HashTransformation -{ -public: - CRYPTOPP_CONSTANT(DIGESTSIZE = 4) - Adler32() {Reset();} - void Update(const byte *input, size_t length); - void TruncatedFinal(byte *hash, size_t size); - unsigned int DigestSize() const {return DIGESTSIZE;} - static const char * StaticAlgorithmName() {return "Adler32";} - std::string AlgorithmName() const {return StaticAlgorithmName();} - -private: - void Reset() {m_s1 = 1; m_s2 = 0;} - - word16 m_s1, m_s2; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/aes.h b/lib/cryptopp/aes.h deleted file mode 100644 index 008754256..000000000 --- a/lib/cryptopp/aes.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef CRYPTOPP_AES_H -#define CRYPTOPP_AES_H - -#include "rijndael.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! AES winner, announced on 10/2/2000 -DOCUMENTED_TYPEDEF(Rijndael, AES); - -typedef RijndaelEncryption AESEncryption; -typedef RijndaelDecryption AESDecryption; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/algebra.cpp b/lib/cryptopp/algebra.cpp deleted file mode 100644 index 958e63701..000000000 --- a/lib/cryptopp/algebra.cpp +++ /dev/null @@ -1,340 +0,0 @@ -// algebra.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_ALGEBRA_CPP // SunCC workaround: compiler could cause this file to be included twice -#define CRYPTOPP_ALGEBRA_CPP - -#include "algebra.h" -#include "integer.h" - -#include - -NAMESPACE_BEGIN(CryptoPP) - -template const T& AbstractGroup::Double(const Element &a) const -{ - return this->Add(a, a); -} - -template const T& AbstractGroup::Subtract(const Element &a, const Element &b) const -{ - // make copy of a in case Inverse() overwrites it - Element a1(a); - return this->Add(a1, Inverse(b)); -} - -template T& AbstractGroup::Accumulate(Element &a, const Element &b) const -{ - return a = this->Add(a, b); -} - -template T& AbstractGroup::Reduce(Element &a, const Element &b) const -{ - return a = this->Subtract(a, b); -} - -template const T& AbstractRing::Square(const Element &a) const -{ - return this->Multiply(a, a); -} - -template const T& AbstractRing::Divide(const Element &a, const Element &b) const -{ - // make copy of a in case MultiplicativeInverse() overwrites it - Element a1(a); - return this->Multiply(a1, this->MultiplicativeInverse(b)); -} - -template const T& AbstractEuclideanDomain::Mod(const Element &a, const Element &b) const -{ - Element q; - this->DivisionAlgorithm(result, q, a, b); - return result; -} - -template const T& AbstractEuclideanDomain::Gcd(const Element &a, const Element &b) const -{ - Element g[3]={b, a}; - unsigned int i0=0, i1=1, i2=2; - - while (!this->Equal(g[i1], this->Identity())) - { - g[i2] = this->Mod(g[i0], g[i1]); - unsigned int t = i0; i0 = i1; i1 = i2; i2 = t; - } - - return result = g[i0]; -} - -template const typename QuotientRing::Element& QuotientRing::MultiplicativeInverse(const Element &a) const -{ - Element g[3]={m_modulus, a}; - Element v[3]={m_domain.Identity(), m_domain.MultiplicativeIdentity()}; - Element y; - unsigned int i0=0, i1=1, i2=2; - - while (!this->Equal(g[i1], this->Identity())) - { - // y = g[i0] / g[i1]; - // g[i2] = g[i0] % g[i1]; - m_domain.DivisionAlgorithm(g[i2], y, g[i0], g[i1]); - // v[i2] = v[i0] - (v[i1] * y); - v[i2] = m_domain.Subtract(v[i0], m_domain.Multiply(v[i1], y)); - unsigned int t = i0; i0 = i1; i1 = i2; i2 = t; - } - - return m_domain.IsUnit(g[i0]) ? m_domain.Divide(v[i0], g[i0]) : m_domain.Identity(); -} - -template T AbstractGroup::ScalarMultiply(const Element &base, const Integer &exponent) const -{ - Element result; - this->SimultaneousMultiply(&result, base, &exponent, 1); - return result; -} - -template T AbstractGroup::CascadeScalarMultiply(const Element &x, const Integer &e1, const Element &y, const Integer &e2) const -{ - const unsigned expLen = STDMAX(e1.BitCount(), e2.BitCount()); - if (expLen==0) - return this->Identity(); - - const unsigned w = (expLen <= 46 ? 1 : (expLen <= 260 ? 2 : 3)); - const unsigned tableSize = 1< powerTable(tableSize << w); - - powerTable[1] = x; - powerTable[tableSize] = y; - if (w==1) - powerTable[3] = this->Add(x,y); - else - { - powerTable[2] = this->Double(x); - powerTable[2*tableSize] = this->Double(y); - - unsigned i, j; - - for (i=3; i=0; i--) - { - power1 = 2*power1 + e1.GetBit(i); - power2 = 2*power2 + e2.GetBit(i); - - if (i==0 || 2*power1 >= tableSize || 2*power2 >= tableSize) - { - unsigned squaresBefore = prevPosition-i; - unsigned squaresAfter = 0; - prevPosition = i; - while ((power1 || power2) && power1%2 == 0 && power2%2==0) - { - power1 /= 2; - power2 /= 2; - squaresBefore--; - squaresAfter++; - } - if (firstTime) - { - result = powerTable[(power2<Double(result); - if (power1 || power2) - Accumulate(result, powerTable[(power2<Double(result); - power1 = power2 = 0; - } - } - return result; -} - -template Element GeneralCascadeMultiplication(const AbstractGroup &group, Iterator begin, Iterator end) -{ - if (end-begin == 1) - return group.ScalarMultiply(begin->base, begin->exponent); - else if (end-begin == 2) - return group.CascadeScalarMultiply(begin->base, begin->exponent, (begin+1)->base, (begin+1)->exponent); - else - { - Integer q, t; - Iterator last = end; - --last; - - std::make_heap(begin, end); - std::pop_heap(begin, end); - - while (!!begin->exponent) - { - // last->exponent is largest exponent, begin->exponent is next largest - t = last->exponent; - Integer::Divide(last->exponent, q, t, begin->exponent); - - if (q == Integer::One()) - group.Accumulate(begin->base, last->base); // avoid overhead of ScalarMultiply() - else - group.Accumulate(begin->base, group.ScalarMultiply(last->base, q)); - - std::push_heap(begin, end); - std::pop_heap(begin, end); - } - - return group.ScalarMultiply(last->base, last->exponent); - } -} - -struct WindowSlider -{ - WindowSlider(const Integer &expIn, bool fastNegate, unsigned int windowSizeIn=0) - : exp(expIn), windowModulus(Integer::One()), windowSize(windowSizeIn), windowBegin(0), fastNegate(fastNegate), firstTime(true), finished(false) - { - if (windowSize == 0) - { - unsigned int expLen = exp.BitCount(); - windowSize = expLen <= 17 ? 1 : (expLen <= 24 ? 2 : (expLen <= 70 ? 3 : (expLen <= 197 ? 4 : (expLen <= 539 ? 5 : (expLen <= 1434 ? 6 : 7))))); - } - windowModulus <<= windowSize; - } - - void FindNextWindow() - { - unsigned int expLen = exp.WordCount() * WORD_BITS; - unsigned int skipCount = firstTime ? 0 : windowSize; - firstTime = false; - while (!exp.GetBit(skipCount)) - { - if (skipCount >= expLen) - { - finished = true; - return; - } - skipCount++; - } - - exp >>= skipCount; - windowBegin += skipCount; - expWindow = word32(exp % (word(1) << windowSize)); - - if (fastNegate && exp.GetBit(windowSize)) - { - negateNext = true; - expWindow = (word32(1) << windowSize) - expWindow; - exp += windowModulus; - } - else - negateNext = false; - } - - Integer exp, windowModulus; - unsigned int windowSize, windowBegin; - word32 expWindow; - bool fastNegate, negateNext, firstTime, finished; -}; - -template -void AbstractGroup::SimultaneousMultiply(T *results, const T &base, const Integer *expBegin, unsigned int expCount) const -{ - std::vector > buckets(expCount); - std::vector exponents; - exponents.reserve(expCount); - unsigned int i; - - for (i=0; iNotNegative()); - exponents.push_back(WindowSlider(*expBegin++, InversionIsFast(), 0)); - exponents[i].FindNextWindow(); - buckets[i].resize(1<<(exponents[i].windowSize-1), Identity()); - } - - unsigned int expBitPosition = 0; - Element g = base; - bool notDone = true; - - while (notDone) - { - notDone = false; - for (i=0; i 1) - { - for (int j = (int)buckets[i].size()-2; j >= 1; j--) - { - Accumulate(buckets[i][j], buckets[i][j+1]); - Accumulate(r, buckets[i][j]); - } - Accumulate(buckets[i][0], buckets[i][1]); - r = Add(Double(r), buckets[i][0]); - } - } -} - -template T AbstractRing::Exponentiate(const Element &base, const Integer &exponent) const -{ - Element result; - SimultaneousExponentiate(&result, base, &exponent, 1); - return result; -} - -template T AbstractRing::CascadeExponentiate(const Element &x, const Integer &e1, const Element &y, const Integer &e2) const -{ - return MultiplicativeGroup().AbstractGroup::CascadeScalarMultiply(x, e1, y, e2); -} - -template Element GeneralCascadeExponentiation(const AbstractRing &ring, Iterator begin, Iterator end) -{ - return GeneralCascadeMultiplication(ring.MultiplicativeGroup(), begin, end); -} - -template -void AbstractRing::SimultaneousExponentiate(T *results, const T &base, const Integer *exponents, unsigned int expCount) const -{ - MultiplicativeGroup().AbstractGroup::SimultaneousMultiply(results, base, exponents, expCount); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/algebra.h b/lib/cryptopp/algebra.h deleted file mode 100644 index 13038bd80..000000000 --- a/lib/cryptopp/algebra.h +++ /dev/null @@ -1,285 +0,0 @@ -#ifndef CRYPTOPP_ALGEBRA_H -#define CRYPTOPP_ALGEBRA_H - -#include "config.h" - -NAMESPACE_BEGIN(CryptoPP) - -class Integer; - -// "const Element&" returned by member functions are references -// to internal data members. Since each object may have only -// one such data member for holding results, the following code -// will produce incorrect results: -// abcd = group.Add(group.Add(a,b), group.Add(c,d)); -// But this should be fine: -// abcd = group.Add(a, group.Add(b, group.Add(c,d)); - -//! Abstract Group -template class CRYPTOPP_NO_VTABLE AbstractGroup -{ -public: - typedef T Element; - - virtual ~AbstractGroup() {} - - virtual bool Equal(const Element &a, const Element &b) const =0; - virtual const Element& Identity() const =0; - virtual const Element& Add(const Element &a, const Element &b) const =0; - virtual const Element& Inverse(const Element &a) const =0; - virtual bool InversionIsFast() const {return false;} - - virtual const Element& Double(const Element &a) const; - virtual const Element& Subtract(const Element &a, const Element &b) const; - virtual Element& Accumulate(Element &a, const Element &b) const; - virtual Element& Reduce(Element &a, const Element &b) const; - - virtual Element ScalarMultiply(const Element &a, const Integer &e) const; - virtual Element CascadeScalarMultiply(const Element &x, const Integer &e1, const Element &y, const Integer &e2) const; - - virtual void SimultaneousMultiply(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const; -}; - -//! Abstract Ring -template class CRYPTOPP_NO_VTABLE AbstractRing : public AbstractGroup -{ -public: - typedef T Element; - - AbstractRing() {m_mg.m_pRing = this;} - AbstractRing(const AbstractRing &source) {m_mg.m_pRing = this;} - AbstractRing& operator=(const AbstractRing &source) {return *this;} - - virtual bool IsUnit(const Element &a) const =0; - virtual const Element& MultiplicativeIdentity() const =0; - virtual const Element& Multiply(const Element &a, const Element &b) const =0; - virtual const Element& MultiplicativeInverse(const Element &a) const =0; - - virtual const Element& Square(const Element &a) const; - virtual const Element& Divide(const Element &a, const Element &b) const; - - virtual Element Exponentiate(const Element &a, const Integer &e) const; - virtual Element CascadeExponentiate(const Element &x, const Integer &e1, const Element &y, const Integer &e2) const; - - virtual void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const; - - virtual const AbstractGroup& MultiplicativeGroup() const - {return m_mg;} - -private: - class MultiplicativeGroupT : public AbstractGroup - { - public: - const AbstractRing& GetRing() const - {return *m_pRing;} - - bool Equal(const Element &a, const Element &b) const - {return GetRing().Equal(a, b);} - - const Element& Identity() const - {return GetRing().MultiplicativeIdentity();} - - const Element& Add(const Element &a, const Element &b) const - {return GetRing().Multiply(a, b);} - - Element& Accumulate(Element &a, const Element &b) const - {return a = GetRing().Multiply(a, b);} - - const Element& Inverse(const Element &a) const - {return GetRing().MultiplicativeInverse(a);} - - const Element& Subtract(const Element &a, const Element &b) const - {return GetRing().Divide(a, b);} - - Element& Reduce(Element &a, const Element &b) const - {return a = GetRing().Divide(a, b);} - - const Element& Double(const Element &a) const - {return GetRing().Square(a);} - - Element ScalarMultiply(const Element &a, const Integer &e) const - {return GetRing().Exponentiate(a, e);} - - Element CascadeScalarMultiply(const Element &x, const Integer &e1, const Element &y, const Integer &e2) const - {return GetRing().CascadeExponentiate(x, e1, y, e2);} - - void SimultaneousMultiply(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const - {GetRing().SimultaneousExponentiate(results, base, exponents, exponentsCount);} - - const AbstractRing *m_pRing; - }; - - MultiplicativeGroupT m_mg; -}; - -// ******************************************************** - -//! Base and Exponent -template -struct BaseAndExponent -{ -public: - BaseAndExponent() {} - BaseAndExponent(const T &base, const E &exponent) : base(base), exponent(exponent) {} - bool operator<(const BaseAndExponent &rhs) const {return exponent < rhs.exponent;} - T base; - E exponent; -}; - -// VC60 workaround: incomplete member template support -template - Element GeneralCascadeMultiplication(const AbstractGroup &group, Iterator begin, Iterator end); -template - Element GeneralCascadeExponentiation(const AbstractRing &ring, Iterator begin, Iterator end); - -// ******************************************************** - -//! Abstract Euclidean Domain -template class CRYPTOPP_NO_VTABLE AbstractEuclideanDomain : public AbstractRing -{ -public: - typedef T Element; - - virtual void DivisionAlgorithm(Element &r, Element &q, const Element &a, const Element &d) const =0; - - virtual const Element& Mod(const Element &a, const Element &b) const =0; - virtual const Element& Gcd(const Element &a, const Element &b) const; - -protected: - mutable Element result; -}; - -// ******************************************************** - -//! EuclideanDomainOf -template class EuclideanDomainOf : public AbstractEuclideanDomain -{ -public: - typedef T Element; - - EuclideanDomainOf() {} - - bool Equal(const Element &a, const Element &b) const - {return a==b;} - - const Element& Identity() const - {return Element::Zero();} - - const Element& Add(const Element &a, const Element &b) const - {return result = a+b;} - - Element& Accumulate(Element &a, const Element &b) const - {return a+=b;} - - const Element& Inverse(const Element &a) const - {return result = -a;} - - const Element& Subtract(const Element &a, const Element &b) const - {return result = a-b;} - - Element& Reduce(Element &a, const Element &b) const - {return a-=b;} - - const Element& Double(const Element &a) const - {return result = a.Doubled();} - - const Element& MultiplicativeIdentity() const - {return Element::One();} - - const Element& Multiply(const Element &a, const Element &b) const - {return result = a*b;} - - const Element& Square(const Element &a) const - {return result = a.Squared();} - - bool IsUnit(const Element &a) const - {return a.IsUnit();} - - const Element& MultiplicativeInverse(const Element &a) const - {return result = a.MultiplicativeInverse();} - - const Element& Divide(const Element &a, const Element &b) const - {return result = a/b;} - - const Element& Mod(const Element &a, const Element &b) const - {return result = a%b;} - - void DivisionAlgorithm(Element &r, Element &q, const Element &a, const Element &d) const - {Element::Divide(r, q, a, d);} - - bool operator==(const EuclideanDomainOf &rhs) const - {return true;} - -private: - mutable Element result; -}; - -//! Quotient Ring -template class QuotientRing : public AbstractRing -{ -public: - typedef T EuclideanDomain; - typedef typename T::Element Element; - - QuotientRing(const EuclideanDomain &domain, const Element &modulus) - : m_domain(domain), m_modulus(modulus) {} - - const EuclideanDomain & GetDomain() const - {return m_domain;} - - const Element& GetModulus() const - {return m_modulus;} - - bool Equal(const Element &a, const Element &b) const - {return m_domain.Equal(m_domain.Mod(m_domain.Subtract(a, b), m_modulus), m_domain.Identity());} - - const Element& Identity() const - {return m_domain.Identity();} - - const Element& Add(const Element &a, const Element &b) const - {return m_domain.Add(a, b);} - - Element& Accumulate(Element &a, const Element &b) const - {return m_domain.Accumulate(a, b);} - - const Element& Inverse(const Element &a) const - {return m_domain.Inverse(a);} - - const Element& Subtract(const Element &a, const Element &b) const - {return m_domain.Subtract(a, b);} - - Element& Reduce(Element &a, const Element &b) const - {return m_domain.Reduce(a, b);} - - const Element& Double(const Element &a) const - {return m_domain.Double(a);} - - bool IsUnit(const Element &a) const - {return m_domain.IsUnit(m_domain.Gcd(a, m_modulus));} - - const Element& MultiplicativeIdentity() const - {return m_domain.MultiplicativeIdentity();} - - const Element& Multiply(const Element &a, const Element &b) const - {return m_domain.Mod(m_domain.Multiply(a, b), m_modulus);} - - const Element& Square(const Element &a) const - {return m_domain.Mod(m_domain.Square(a), m_modulus);} - - const Element& MultiplicativeInverse(const Element &a) const; - - bool operator==(const QuotientRing &rhs) const - {return m_domain == rhs.m_domain && m_modulus == rhs.m_modulus;} - -protected: - EuclideanDomain m_domain; - Element m_modulus; -}; - -NAMESPACE_END - -#ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES -#include "algebra.cpp" -#endif - -#endif diff --git a/lib/cryptopp/algparam.cpp b/lib/cryptopp/algparam.cpp deleted file mode 100644 index a70d5dd95..000000000 --- a/lib/cryptopp/algparam.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// algparam.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "algparam.h" - -NAMESPACE_BEGIN(CryptoPP) - -PAssignIntToInteger g_pAssignIntToInteger = NULL; - -bool CombinedNameValuePairs::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - if (strcmp(name, "ValueNames") == 0) - return m_pairs1.GetVoidValue(name, valueType, pValue) && m_pairs2.GetVoidValue(name, valueType, pValue); - else - return m_pairs1.GetVoidValue(name, valueType, pValue) || m_pairs2.GetVoidValue(name, valueType, pValue); -} - -void AlgorithmParametersBase::operator=(const AlgorithmParametersBase& rhs) -{ - assert(false); -} - -bool AlgorithmParametersBase::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - if (strcmp(name, "ValueNames") == 0) - { - NameValuePairs::ThrowIfTypeMismatch(name, typeid(std::string), valueType); - if (m_next.get()) - m_next->GetVoidValue(name, valueType, pValue); - (*reinterpret_cast(pValue) += m_name) += ";"; - return true; - } - else if (strcmp(name, m_name) == 0) - { - AssignValue(name, valueType, pValue); - m_used = true; - return true; - } - else if (m_next.get()) - return m_next->GetVoidValue(name, valueType, pValue); - else - return false; -} - -AlgorithmParameters::AlgorithmParameters() - : m_defaultThrowIfNotUsed(true) -{ -} - -AlgorithmParameters::AlgorithmParameters(const AlgorithmParameters &x) - : m_defaultThrowIfNotUsed(x.m_defaultThrowIfNotUsed) -{ - m_next.reset(const_cast(x).m_next.release()); -} - -AlgorithmParameters & AlgorithmParameters::operator=(const AlgorithmParameters &x) -{ - m_next.reset(const_cast(x).m_next.release()); - return *this; -} - -bool AlgorithmParameters::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - if (m_next.get()) - return m_next->GetVoidValue(name, valueType, pValue); - else - return false; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/algparam.h b/lib/cryptopp/algparam.h deleted file mode 100644 index ea5129c22..000000000 --- a/lib/cryptopp/algparam.h +++ /dev/null @@ -1,398 +0,0 @@ -#ifndef CRYPTOPP_ALGPARAM_H -#define CRYPTOPP_ALGPARAM_H - -#include "cryptlib.h" -#include "smartptr.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! used to pass byte array input as part of a NameValuePairs object -/*! the deepCopy option is used when the NameValuePairs object can't - keep a copy of the data available */ -class ConstByteArrayParameter -{ -public: - ConstByteArrayParameter(const char *data = NULL, bool deepCopy = false) - { - Assign((const byte *)data, data ? strlen(data) : 0, deepCopy); - } - ConstByteArrayParameter(const byte *data, size_t size, bool deepCopy = false) - { - Assign(data, size, deepCopy); - } - template ConstByteArrayParameter(const T &string, bool deepCopy = false) - { - CRYPTOPP_COMPILE_ASSERT(sizeof(CPP_TYPENAME T::value_type) == 1); - Assign((const byte *)string.data(), string.size(), deepCopy); - } - - void Assign(const byte *data, size_t size, bool deepCopy) - { - if (deepCopy) - m_block.Assign(data, size); - else - { - m_data = data; - m_size = size; - } - m_deepCopy = deepCopy; - } - - const byte *begin() const {return m_deepCopy ? m_block.begin() : m_data;} - const byte *end() const {return m_deepCopy ? m_block.end() : m_data + m_size;} - size_t size() const {return m_deepCopy ? m_block.size() : m_size;} - -private: - bool m_deepCopy; - const byte *m_data; - size_t m_size; - SecByteBlock m_block; -}; - -class ByteArrayParameter -{ -public: - ByteArrayParameter(byte *data = NULL, unsigned int size = 0) - : m_data(data), m_size(size) {} - ByteArrayParameter(SecByteBlock &block) - : m_data(block.begin()), m_size(block.size()) {} - - byte *begin() const {return m_data;} - byte *end() const {return m_data + m_size;} - size_t size() const {return m_size;} - -private: - byte *m_data; - size_t m_size; -}; - -class CRYPTOPP_DLL CombinedNameValuePairs : public NameValuePairs -{ -public: - CombinedNameValuePairs(const NameValuePairs &pairs1, const NameValuePairs &pairs2) - : m_pairs1(pairs1), m_pairs2(pairs2) {} - - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - -private: - const NameValuePairs &m_pairs1, &m_pairs2; -}; - -template -class GetValueHelperClass -{ -public: - GetValueHelperClass(const T *pObject, const char *name, const std::type_info &valueType, void *pValue, const NameValuePairs *searchFirst) - : m_pObject(pObject), m_name(name), m_valueType(&valueType), m_pValue(pValue), m_found(false), m_getValueNames(false) - { - if (strcmp(m_name, "ValueNames") == 0) - { - m_found = m_getValueNames = true; - NameValuePairs::ThrowIfTypeMismatch(m_name, typeid(std::string), *m_valueType); - if (searchFirst) - searchFirst->GetVoidValue(m_name, valueType, pValue); - if (typeid(T) != typeid(BASE)) - pObject->BASE::GetVoidValue(m_name, valueType, pValue); - ((*reinterpret_cast(m_pValue) += "ThisPointer:") += typeid(T).name()) += ';'; - } - - if (!m_found && strncmp(m_name, "ThisPointer:", 12) == 0 && strcmp(m_name+12, typeid(T).name()) == 0) - { - NameValuePairs::ThrowIfTypeMismatch(m_name, typeid(T *), *m_valueType); - *reinterpret_cast(pValue) = pObject; - m_found = true; - return; - } - - if (!m_found && searchFirst) - m_found = searchFirst->GetVoidValue(m_name, valueType, pValue); - - if (!m_found && typeid(T) != typeid(BASE)) - m_found = pObject->BASE::GetVoidValue(m_name, valueType, pValue); - } - - operator bool() const {return m_found;} - - template - GetValueHelperClass & operator()(const char *name, const R & (T::*pm)() const) - { - if (m_getValueNames) - (*reinterpret_cast(m_pValue) += name) += ";"; - if (!m_found && strcmp(name, m_name) == 0) - { - NameValuePairs::ThrowIfTypeMismatch(name, typeid(R), *m_valueType); - *reinterpret_cast(m_pValue) = (m_pObject->*pm)(); - m_found = true; - } - return *this; - } - - GetValueHelperClass &Assignable() - { -#ifndef __INTEL_COMPILER // ICL 9.1 workaround: Intel compiler copies the vTable pointer for some reason - if (m_getValueNames) - ((*reinterpret_cast(m_pValue) += "ThisObject:") += typeid(T).name()) += ';'; - if (!m_found && strncmp(m_name, "ThisObject:", 11) == 0 && strcmp(m_name+11, typeid(T).name()) == 0) - { - NameValuePairs::ThrowIfTypeMismatch(m_name, typeid(T), *m_valueType); - *reinterpret_cast(m_pValue) = *m_pObject; - m_found = true; - } -#endif - return *this; - } - -private: - const T *m_pObject; - const char *m_name; - const std::type_info *m_valueType; - void *m_pValue; - bool m_found, m_getValueNames; -}; - -template -GetValueHelperClass GetValueHelper(const T *pObject, const char *name, const std::type_info &valueType, void *pValue, const NameValuePairs *searchFirst=NULL, BASE *dummy=NULL) -{ - return GetValueHelperClass(pObject, name, valueType, pValue, searchFirst); -} - -template -GetValueHelperClass GetValueHelper(const T *pObject, const char *name, const std::type_info &valueType, void *pValue, const NameValuePairs *searchFirst=NULL) -{ - return GetValueHelperClass(pObject, name, valueType, pValue, searchFirst); -} - -// ******************************************************** - -template -R Hack_DefaultValueFromConstReferenceType(const R &) -{ - return R(); -} - -template -bool Hack_GetValueIntoConstReference(const NameValuePairs &source, const char *name, const R &value) -{ - return source.GetValue(name, const_cast(value)); -} - -template -class AssignFromHelperClass -{ -public: - AssignFromHelperClass(T *pObject, const NameValuePairs &source) - : m_pObject(pObject), m_source(source), m_done(false) - { - if (source.GetThisObject(*pObject)) - m_done = true; - else if (typeid(BASE) != typeid(T)) - pObject->BASE::AssignFrom(source); - } - - template - AssignFromHelperClass & operator()(const char *name, void (T::*pm)(R)) // VC60 workaround: "const R &" here causes compiler error - { - if (!m_done) - { - R value = Hack_DefaultValueFromConstReferenceType(reinterpret_cast(*(int *)NULL)); - if (!Hack_GetValueIntoConstReference(m_source, name, value)) - throw InvalidArgument(std::string(typeid(T).name()) + ": Missing required parameter '" + name + "'"); - (m_pObject->*pm)(value); - } - return *this; - } - - template - AssignFromHelperClass & operator()(const char *name1, const char *name2, void (T::*pm)(R, S)) // VC60 workaround: "const R &" here causes compiler error - { - if (!m_done) - { - R value1 = Hack_DefaultValueFromConstReferenceType(reinterpret_cast(*(int *)NULL)); - if (!Hack_GetValueIntoConstReference(m_source, name1, value1)) - throw InvalidArgument(std::string(typeid(T).name()) + ": Missing required parameter '" + name1 + "'"); - S value2 = Hack_DefaultValueFromConstReferenceType(reinterpret_cast(*(int *)NULL)); - if (!Hack_GetValueIntoConstReference(m_source, name2, value2)) - throw InvalidArgument(std::string(typeid(T).name()) + ": Missing required parameter '" + name2 + "'"); - (m_pObject->*pm)(value1, value2); - } - return *this; - } - -private: - T *m_pObject; - const NameValuePairs &m_source; - bool m_done; -}; - -template -AssignFromHelperClass AssignFromHelper(T *pObject, const NameValuePairs &source, BASE *dummy=NULL) -{ - return AssignFromHelperClass(pObject, source); -} - -template -AssignFromHelperClass AssignFromHelper(T *pObject, const NameValuePairs &source) -{ - return AssignFromHelperClass(pObject, source); -} - -// ******************************************************** - -// to allow the linker to discard Integer code if not needed. -typedef bool (CRYPTOPP_API * PAssignIntToInteger)(const std::type_info &valueType, void *pInteger, const void *pInt); -CRYPTOPP_DLL extern PAssignIntToInteger g_pAssignIntToInteger; - -CRYPTOPP_DLL const std::type_info & CRYPTOPP_API IntegerTypeId(); - -class CRYPTOPP_DLL AlgorithmParametersBase -{ -public: - class ParameterNotUsed : public Exception - { - public: - ParameterNotUsed(const char *name) : Exception(OTHER_ERROR, std::string("AlgorithmParametersBase: parameter \"") + name + "\" not used") {} - }; - - // this is actually a move, not a copy - AlgorithmParametersBase(const AlgorithmParametersBase &x) - : m_name(x.m_name), m_throwIfNotUsed(x.m_throwIfNotUsed), m_used(x.m_used) - { - m_next.reset(const_cast(x).m_next.release()); - x.m_used = true; - } - - AlgorithmParametersBase(const char *name, bool throwIfNotUsed) - : m_name(name), m_throwIfNotUsed(throwIfNotUsed), m_used(false) {} - - virtual ~AlgorithmParametersBase() - { -#ifdef CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE - if (!std::uncaught_exception()) -#else - try -#endif - { - if (m_throwIfNotUsed && !m_used) - throw ParameterNotUsed(m_name); - } -#ifndef CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE - catch(...) - { - } -#endif - } - - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - -protected: - friend class AlgorithmParameters; - void operator=(const AlgorithmParametersBase& rhs); // assignment not allowed, declare this for VC60 - - virtual void AssignValue(const char *name, const std::type_info &valueType, void *pValue) const =0; - virtual void MoveInto(void *p) const =0; // not really const - - const char *m_name; - bool m_throwIfNotUsed; - mutable bool m_used; - member_ptr m_next; -}; - -template -class AlgorithmParametersTemplate : public AlgorithmParametersBase -{ -public: - AlgorithmParametersTemplate(const char *name, const T &value, bool throwIfNotUsed) - : AlgorithmParametersBase(name, throwIfNotUsed), m_value(value) - { - } - - void AssignValue(const char *name, const std::type_info &valueType, void *pValue) const - { - // special case for retrieving an Integer parameter when an int was passed in - if (!(g_pAssignIntToInteger != NULL && typeid(T) == typeid(int) && g_pAssignIntToInteger(valueType, pValue, &m_value))) - { - NameValuePairs::ThrowIfTypeMismatch(name, typeid(T), valueType); - *reinterpret_cast(pValue) = m_value; - } - } - - void MoveInto(void *buffer) const - { - AlgorithmParametersTemplate* p = new(buffer) AlgorithmParametersTemplate(*this); - } - -protected: - T m_value; -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate; -CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate; -CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate; - -class CRYPTOPP_DLL AlgorithmParameters : public NameValuePairs -{ -public: - AlgorithmParameters(); - -#ifdef __BORLANDC__ - template - AlgorithmParameters(const char *name, const T &value, bool throwIfNotUsed=true) - : m_next(new AlgorithmParametersTemplate(name, value, throwIfNotUsed)) - , m_defaultThrowIfNotUsed(throwIfNotUsed) - { - } -#endif - - AlgorithmParameters(const AlgorithmParameters &x); - - AlgorithmParameters & operator=(const AlgorithmParameters &x); - - template - AlgorithmParameters & operator()(const char *name, const T &value, bool throwIfNotUsed) - { - member_ptr p(new AlgorithmParametersTemplate(name, value, throwIfNotUsed)); - p->m_next.reset(m_next.release()); - m_next.reset(p.release()); - m_defaultThrowIfNotUsed = throwIfNotUsed; - return *this; - } - - template - AlgorithmParameters & operator()(const char *name, const T &value) - { - return operator()(name, value, m_defaultThrowIfNotUsed); - } - - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - -protected: - member_ptr m_next; - bool m_defaultThrowIfNotUsed; -}; - -//! Create an object that implements NameValuePairs for passing parameters -/*! \param throwIfNotUsed if true, the object will throw an exception if the value is not accessed - \note throwIfNotUsed is ignored if using a compiler that does not support std::uncaught_exception(), - such as MSVC 7.0 and earlier. - \note A NameValuePairs object containing an arbitrary number of name value pairs may be constructed by - repeatedly using operator() on the object returned by MakeParameters, for example: - AlgorithmParameters parameters = MakeParameters(name1, value1)(name2, value2)(name3, value3); -*/ -#ifdef __BORLANDC__ -typedef AlgorithmParameters MakeParameters; -#else -template -AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed = true) -{ - return AlgorithmParameters()(name, value, throwIfNotUsed); -} -#endif - -#define CRYPTOPP_GET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Get##name) -#define CRYPTOPP_SET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Set##name) -#define CRYPTOPP_SET_FUNCTION_ENTRY2(name1, name2) (Name::name1(), Name::name2(), &ThisClass::Set##name1##And##name2) - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/argnames.h b/lib/cryptopp/argnames.h deleted file mode 100644 index e96172521..000000000 --- a/lib/cryptopp/argnames.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef CRYPTOPP_ARGNAMES_H -#define CRYPTOPP_ARGNAMES_H - -#include "cryptlib.h" - -NAMESPACE_BEGIN(CryptoPP) - -DOCUMENTED_NAMESPACE_BEGIN(Name) - -#define CRYPTOPP_DEFINE_NAME_STRING(name) inline const char *name() {return #name;} - -CRYPTOPP_DEFINE_NAME_STRING(ValueNames) //!< string, a list of value names with a semicolon (';') after each name -CRYPTOPP_DEFINE_NAME_STRING(Version) //!< int -CRYPTOPP_DEFINE_NAME_STRING(Seed) //!< ConstByteArrayParameter -CRYPTOPP_DEFINE_NAME_STRING(Key) //!< ConstByteArrayParameter -CRYPTOPP_DEFINE_NAME_STRING(IV) //!< ConstByteArrayParameter, also accepts const byte * for backwards compatibility -CRYPTOPP_DEFINE_NAME_STRING(StolenIV) //!< byte * -CRYPTOPP_DEFINE_NAME_STRING(Rounds) //!< int -CRYPTOPP_DEFINE_NAME_STRING(FeedbackSize) //!< int -CRYPTOPP_DEFINE_NAME_STRING(WordSize) //!< int, in bytes -CRYPTOPP_DEFINE_NAME_STRING(BlockSize) //!< int, in bytes -CRYPTOPP_DEFINE_NAME_STRING(EffectiveKeyLength) //!< int, in bits -CRYPTOPP_DEFINE_NAME_STRING(KeySize) //!< int, in bits -CRYPTOPP_DEFINE_NAME_STRING(ModulusSize) //!< int, in bits -CRYPTOPP_DEFINE_NAME_STRING(SubgroupOrderSize) //!< int, in bits -CRYPTOPP_DEFINE_NAME_STRING(PrivateExponentSize)//!< int, in bits -CRYPTOPP_DEFINE_NAME_STRING(Modulus) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(PublicExponent) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(PrivateExponent) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(PublicElement) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(SubgroupOrder) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(Cofactor) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(SubgroupGenerator) //!< Integer, ECP::Point, or EC2N::Point -CRYPTOPP_DEFINE_NAME_STRING(Curve) //!< ECP or EC2N -CRYPTOPP_DEFINE_NAME_STRING(GroupOID) //!< OID -CRYPTOPP_DEFINE_NAME_STRING(PointerToPrimeSelector) //!< const PrimeSelector * -CRYPTOPP_DEFINE_NAME_STRING(Prime1) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(Prime2) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(ModPrime1PrivateExponent) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(ModPrime2PrivateExponent) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(MultiplicativeInverseOfPrime2ModPrime1) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(QuadraticResidueModPrime1) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(QuadraticResidueModPrime2) //!< Integer -CRYPTOPP_DEFINE_NAME_STRING(PutMessage) //!< bool -CRYPTOPP_DEFINE_NAME_STRING(TruncatedDigestSize) //!< int -CRYPTOPP_DEFINE_NAME_STRING(BlockPaddingScheme) //!< StreamTransformationFilter::BlockPaddingScheme -CRYPTOPP_DEFINE_NAME_STRING(HashVerificationFilterFlags) //!< word32 -CRYPTOPP_DEFINE_NAME_STRING(AuthenticatedDecryptionFilterFlags) //!< word32 -CRYPTOPP_DEFINE_NAME_STRING(SignatureVerificationFilterFlags) //!< word32 -CRYPTOPP_DEFINE_NAME_STRING(InputBuffer) //!< ConstByteArrayParameter -CRYPTOPP_DEFINE_NAME_STRING(OutputBuffer) //!< ByteArrayParameter -CRYPTOPP_DEFINE_NAME_STRING(InputFileName) //!< const char * -CRYPTOPP_DEFINE_NAME_STRING(InputFileNameWide) //!< const wchar_t * -CRYPTOPP_DEFINE_NAME_STRING(InputStreamPointer) //!< std::istream * -CRYPTOPP_DEFINE_NAME_STRING(InputBinaryMode) //!< bool -CRYPTOPP_DEFINE_NAME_STRING(OutputFileName) //!< const char * -CRYPTOPP_DEFINE_NAME_STRING(OutputFileNameWide) //!< const wchar_t * -CRYPTOPP_DEFINE_NAME_STRING(OutputStreamPointer) //!< std::ostream * -CRYPTOPP_DEFINE_NAME_STRING(OutputBinaryMode) //!< bool -CRYPTOPP_DEFINE_NAME_STRING(EncodingParameters) //!< ConstByteArrayParameter -CRYPTOPP_DEFINE_NAME_STRING(KeyDerivationParameters) //!< ConstByteArrayParameter -CRYPTOPP_DEFINE_NAME_STRING(Separator) //< ConstByteArrayParameter -CRYPTOPP_DEFINE_NAME_STRING(Terminator) //< ConstByteArrayParameter -CRYPTOPP_DEFINE_NAME_STRING(Uppercase) //< bool -CRYPTOPP_DEFINE_NAME_STRING(GroupSize) //< int -CRYPTOPP_DEFINE_NAME_STRING(Pad) //< bool -CRYPTOPP_DEFINE_NAME_STRING(PaddingByte) //< byte -CRYPTOPP_DEFINE_NAME_STRING(Log2Base) //< int -CRYPTOPP_DEFINE_NAME_STRING(EncodingLookupArray) //< const byte * -CRYPTOPP_DEFINE_NAME_STRING(DecodingLookupArray) //< const byte * -CRYPTOPP_DEFINE_NAME_STRING(InsertLineBreaks) //< bool -CRYPTOPP_DEFINE_NAME_STRING(MaxLineLength) //< int -CRYPTOPP_DEFINE_NAME_STRING(DigestSize) //!< int, in bytes -CRYPTOPP_DEFINE_NAME_STRING(L1KeyLength) //!< int, in bytes -CRYPTOPP_DEFINE_NAME_STRING(TableSize) //!< int, in bytes - -DOCUMENTED_NAMESPACE_END - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/asn.cpp b/lib/cryptopp/asn.cpp deleted file mode 100644 index 8ae1ad65a..000000000 --- a/lib/cryptopp/asn.cpp +++ /dev/null @@ -1,597 +0,0 @@ -// asn.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "asn.h" - -#include -#include - -NAMESPACE_BEGIN(CryptoPP) -USING_NAMESPACE(std) - -/// DER Length -size_t DERLengthEncode(BufferedTransformation &bt, lword length) -{ - size_t i=0; - if (length <= 0x7f) - { - bt.Put(byte(length)); - i++; - } - else - { - bt.Put(byte(BytePrecision(length) | 0x80)); - i++; - for (int j=BytePrecision(length); j; --j) - { - bt.Put(byte(length >> (j-1)*8)); - i++; - } - } - return i; -} - -bool BERLengthDecode(BufferedTransformation &bt, lword &length, bool &definiteLength) -{ - byte b; - - if (!bt.Get(b)) - return false; - - if (!(b & 0x80)) - { - definiteLength = true; - length = b; - } - else - { - unsigned int lengthBytes = b & 0x7f; - - if (lengthBytes == 0) - { - definiteLength = false; - return true; - } - - definiteLength = true; - length = 0; - while (lengthBytes--) - { - if (length >> (8*(sizeof(length)-1))) - BERDecodeError(); // length about to overflow - - if (!bt.Get(b)) - return false; - - length = (length << 8) | b; - } - } - return true; -} - -bool BERLengthDecode(BufferedTransformation &bt, size_t &length) -{ - lword lw; - bool definiteLength; - if (!BERLengthDecode(bt, lw, definiteLength)) - BERDecodeError(); - if (!SafeConvert(lw, length)) - BERDecodeError(); - return definiteLength; -} - -void DEREncodeNull(BufferedTransformation &out) -{ - out.Put(TAG_NULL); - out.Put(0); -} - -void BERDecodeNull(BufferedTransformation &in) -{ - byte b; - if (!in.Get(b) || b != TAG_NULL) - BERDecodeError(); - size_t length; - if (!BERLengthDecode(in, length) || length != 0) - BERDecodeError(); -} - -/// ASN Strings -size_t DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen) -{ - bt.Put(OCTET_STRING); - size_t lengthBytes = DERLengthEncode(bt, strLen); - bt.Put(str, strLen); - return 1+lengthBytes+strLen; -} - -size_t DEREncodeOctetString(BufferedTransformation &bt, const SecByteBlock &str) -{ - return DEREncodeOctetString(bt, str.begin(), str.size()); -} - -size_t BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str) -{ - byte b; - if (!bt.Get(b) || b != OCTET_STRING) - BERDecodeError(); - - size_t bc; - if (!BERLengthDecode(bt, bc)) - BERDecodeError(); - - str.resize(bc); - if (bc != bt.Get(str, bc)) - BERDecodeError(); - return bc; -} - -size_t BERDecodeOctetString(BufferedTransformation &bt, BufferedTransformation &str) -{ - byte b; - if (!bt.Get(b) || b != OCTET_STRING) - BERDecodeError(); - - size_t bc; - if (!BERLengthDecode(bt, bc)) - BERDecodeError(); - - bt.TransferTo(str, bc); - return bc; -} - -size_t DEREncodeTextString(BufferedTransformation &bt, const std::string &str, byte asnTag) -{ - bt.Put(asnTag); - size_t lengthBytes = DERLengthEncode(bt, str.size()); - bt.Put((const byte *)str.data(), str.size()); - return 1+lengthBytes+str.size(); -} - -size_t BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte asnTag) -{ - byte b; - if (!bt.Get(b) || b != asnTag) - BERDecodeError(); - - size_t bc; - if (!BERLengthDecode(bt, bc)) - BERDecodeError(); - - SecByteBlock temp(bc); - if (bc != bt.Get(temp, bc)) - BERDecodeError(); - str.assign((char *)temp.begin(), bc); - return bc; -} - -/// ASN BitString -size_t DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits) -{ - bt.Put(BIT_STRING); - size_t lengthBytes = DERLengthEncode(bt, strLen+1); - bt.Put((byte)unusedBits); - bt.Put(str, strLen); - return 2+lengthBytes+strLen; -} - -size_t BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits) -{ - byte b; - if (!bt.Get(b) || b != BIT_STRING) - BERDecodeError(); - - size_t bc; - if (!BERLengthDecode(bt, bc)) - BERDecodeError(); - - byte unused; - if (!bt.Get(unused)) - BERDecodeError(); - unusedBits = unused; - str.resize(bc-1); - if ((bc-1) != bt.Get(str, bc-1)) - BERDecodeError(); - return bc-1; -} - -void DERReencode(BufferedTransformation &source, BufferedTransformation &dest) -{ - byte tag; - source.Peek(tag); - BERGeneralDecoder decoder(source, tag); - DERGeneralEncoder encoder(dest, tag); - if (decoder.IsDefiniteLength()) - decoder.TransferTo(encoder, decoder.RemainingLength()); - else - { - while (!decoder.EndReached()) - DERReencode(decoder, encoder); - } - decoder.MessageEnd(); - encoder.MessageEnd(); -} - -void OID::EncodeValue(BufferedTransformation &bt, word32 v) -{ - for (unsigned int i=RoundUpToMultipleOf(STDMAX(7U,BitPrecision(v)), 7U)-7; i != 0; i-=7) - bt.Put((byte)(0x80 | ((v >> i) & 0x7f))); - bt.Put((byte)(v & 0x7f)); -} - -size_t OID::DecodeValue(BufferedTransformation &bt, word32 &v) -{ - byte b; - size_t i=0; - v = 0; - while (true) - { - if (!bt.Get(b)) - BERDecodeError(); - i++; - if (v >> (8*sizeof(v)-7)) // v about to overflow - BERDecodeError(); - v <<= 7; - v += b & 0x7f; - if (!(b & 0x80)) - return i; - } -} - -void OID::DEREncode(BufferedTransformation &bt) const -{ - assert(m_values.size() >= 2); - ByteQueue temp; - temp.Put(byte(m_values[0] * 40 + m_values[1])); - for (size_t i=2; i 0) - { - word32 v; - size_t valueLen = DecodeValue(bt, v); - if (valueLen > length) - BERDecodeError(); - m_values.push_back(v); - length -= valueLen; - } -} - -void OID::BERDecodeAndCheck(BufferedTransformation &bt) const -{ - OID oid(bt); - if (*this != oid) - BERDecodeError(); -} - -inline BufferedTransformation & EncodedObjectFilter::CurrentTarget() -{ - if (m_flags & PUT_OBJECTS) - return *AttachedTransformation(); - else - return TheBitBucket(); -} - -void EncodedObjectFilter::Put(const byte *inString, size_t length) -{ - if (m_nCurrentObject == m_nObjects) - { - AttachedTransformation()->Put(inString, length); - return; - } - - LazyPutter lazyPutter(m_queue, inString, length); - - while (m_queue.AnyRetrievable()) - { - switch (m_state) - { - case IDENTIFIER: - if (!m_queue.Get(m_id)) - return; - m_queue.TransferTo(CurrentTarget(), 1); - m_state = LENGTH; // fall through - case LENGTH: - { - byte b; - if (m_level > 0 && m_id == 0 && m_queue.Peek(b) && b == 0) - { - m_queue.TransferTo(CurrentTarget(), 1); - m_level--; - m_state = IDENTIFIER; - break; - } - ByteQueue::Walker walker(m_queue); - bool definiteLength; - if (!BERLengthDecode(walker, m_lengthRemaining, definiteLength)) - return; - m_queue.TransferTo(CurrentTarget(), walker.GetCurrentPosition()); - if (!((m_id & CONSTRUCTED) || definiteLength)) - BERDecodeError(); - if (!definiteLength) - { - if (!(m_id & CONSTRUCTED)) - BERDecodeError(); - m_level++; - m_state = IDENTIFIER; - break; - } - m_state = BODY; // fall through - } - case BODY: - m_lengthRemaining -= m_queue.TransferTo(CurrentTarget(), m_lengthRemaining); - - if (m_lengthRemaining == 0) - m_state = IDENTIFIER; - } - - if (m_state == IDENTIFIER && m_level == 0) - { - // just finished processing a level 0 object - ++m_nCurrentObject; - - if (m_flags & PUT_MESSANGE_END_AFTER_EACH_OBJECT) - AttachedTransformation()->MessageEnd(); - - if (m_nCurrentObject == m_nObjects) - { - if (m_flags & PUT_MESSANGE_END_AFTER_ALL_OBJECTS) - AttachedTransformation()->MessageEnd(); - - if (m_flags & PUT_MESSANGE_SERIES_END_AFTER_ALL_OBJECTS) - AttachedTransformation()->MessageSeriesEnd(); - - m_queue.TransferAllTo(*AttachedTransformation()); - return; - } - } - } -} - -BERGeneralDecoder::BERGeneralDecoder(BufferedTransformation &inQueue, byte asnTag) - : m_inQueue(inQueue), m_finished(false) -{ - Init(asnTag); -} - -BERGeneralDecoder::BERGeneralDecoder(BERGeneralDecoder &inQueue, byte asnTag) - : m_inQueue(inQueue), m_finished(false) -{ - Init(asnTag); -} - -void BERGeneralDecoder::Init(byte asnTag) -{ - byte b; - if (!m_inQueue.Get(b) || b != asnTag) - BERDecodeError(); - - if (!BERLengthDecode(m_inQueue, m_length, m_definiteLength)) - BERDecodeError(); - - if (!m_definiteLength && !(asnTag & CONSTRUCTED)) - BERDecodeError(); // cannot be primitive and have indefinite length -} - -BERGeneralDecoder::~BERGeneralDecoder() -{ - try // avoid throwing in constructor - { - if (!m_finished) - MessageEnd(); - } - catch (...) - { - } -} - -bool BERGeneralDecoder::EndReached() const -{ - if (m_definiteLength) - return m_length == 0; - else - { // check end-of-content octets - word16 i; - return (m_inQueue.PeekWord16(i)==2 && i==0); - } -} - -byte BERGeneralDecoder::PeekByte() const -{ - byte b; - if (!Peek(b)) - BERDecodeError(); - return b; -} - -void BERGeneralDecoder::CheckByte(byte check) -{ - byte b; - if (!Get(b) || b != check) - BERDecodeError(); -} - -void BERGeneralDecoder::MessageEnd() -{ - m_finished = true; - if (m_definiteLength) - { - if (m_length != 0) - BERDecodeError(); - } - else - { // remove end-of-content octets - word16 i; - if (m_inQueue.GetWord16(i) != 2 || i != 0) - BERDecodeError(); - } -} - -size_t BERGeneralDecoder::TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel, bool blocking) -{ - if (m_definiteLength && transferBytes > m_length) - transferBytes = m_length; - size_t blockedBytes = m_inQueue.TransferTo2(target, transferBytes, channel, blocking); - ReduceLength(transferBytes); - return blockedBytes; -} - -size_t BERGeneralDecoder::CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end, const std::string &channel, bool blocking) const -{ - if (m_definiteLength) - end = STDMIN(m_length, end); - return m_inQueue.CopyRangeTo2(target, begin, end, channel, blocking); -} - -lword BERGeneralDecoder::ReduceLength(lword delta) -{ - if (m_definiteLength) - { - if (m_length < delta) - BERDecodeError(); - m_length -= delta; - } - return delta; -} - -DERGeneralEncoder::DERGeneralEncoder(BufferedTransformation &outQueue, byte asnTag) - : m_outQueue(outQueue), m_finished(false), m_asnTag(asnTag) -{ -} - -DERGeneralEncoder::DERGeneralEncoder(DERGeneralEncoder &outQueue, byte asnTag) - : m_outQueue(outQueue), m_finished(false), m_asnTag(asnTag) -{ -} - -DERGeneralEncoder::~DERGeneralEncoder() -{ - try // avoid throwing in constructor - { - if (!m_finished) - MessageEnd(); - } - catch (...) - { - } -} - -void DERGeneralEncoder::MessageEnd() -{ - m_finished = true; - lword length = CurrentSize(); - m_outQueue.Put(m_asnTag); - DERLengthEncode(m_outQueue, length); - TransferTo(m_outQueue); -} - -// ************************************************************* - -void X509PublicKey::BERDecode(BufferedTransformation &bt) -{ - BERSequenceDecoder subjectPublicKeyInfo(bt); - BERSequenceDecoder algorithm(subjectPublicKeyInfo); - GetAlgorithmID().BERDecodeAndCheck(algorithm); - bool parametersPresent = algorithm.EndReached() ? false : BERDecodeAlgorithmParameters(algorithm); - algorithm.MessageEnd(); - - BERGeneralDecoder subjectPublicKey(subjectPublicKeyInfo, BIT_STRING); - subjectPublicKey.CheckByte(0); // unused bits - BERDecodePublicKey(subjectPublicKey, parametersPresent, (size_t)subjectPublicKey.RemainingLength()); - subjectPublicKey.MessageEnd(); - subjectPublicKeyInfo.MessageEnd(); -} - -void X509PublicKey::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder subjectPublicKeyInfo(bt); - - DERSequenceEncoder algorithm(subjectPublicKeyInfo); - GetAlgorithmID().DEREncode(algorithm); - DEREncodeAlgorithmParameters(algorithm); - algorithm.MessageEnd(); - - DERGeneralEncoder subjectPublicKey(subjectPublicKeyInfo, BIT_STRING); - subjectPublicKey.Put(0); // unused bits - DEREncodePublicKey(subjectPublicKey); - subjectPublicKey.MessageEnd(); - - subjectPublicKeyInfo.MessageEnd(); -} - -void PKCS8PrivateKey::BERDecode(BufferedTransformation &bt) -{ - BERSequenceDecoder privateKeyInfo(bt); - word32 version; - BERDecodeUnsigned(privateKeyInfo, version, INTEGER, 0, 0); // check version - - BERSequenceDecoder algorithm(privateKeyInfo); - GetAlgorithmID().BERDecodeAndCheck(algorithm); - bool parametersPresent = algorithm.EndReached() ? false : BERDecodeAlgorithmParameters(algorithm); - algorithm.MessageEnd(); - - BERGeneralDecoder octetString(privateKeyInfo, OCTET_STRING); - BERDecodePrivateKey(octetString, parametersPresent, (size_t)privateKeyInfo.RemainingLength()); - octetString.MessageEnd(); - - if (!privateKeyInfo.EndReached()) - BERDecodeOptionalAttributes(privateKeyInfo); - privateKeyInfo.MessageEnd(); -} - -void PKCS8PrivateKey::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder privateKeyInfo(bt); - DEREncodeUnsigned(privateKeyInfo, 0); // version - - DERSequenceEncoder algorithm(privateKeyInfo); - GetAlgorithmID().DEREncode(algorithm); - DEREncodeAlgorithmParameters(algorithm); - algorithm.MessageEnd(); - - DERGeneralEncoder octetString(privateKeyInfo, OCTET_STRING); - DEREncodePrivateKey(octetString); - octetString.MessageEnd(); - - DEREncodeOptionalAttributes(privateKeyInfo); - privateKeyInfo.MessageEnd(); -} - -void PKCS8PrivateKey::BERDecodeOptionalAttributes(BufferedTransformation &bt) -{ - DERReencode(bt, m_optionalAttributes); -} - -void PKCS8PrivateKey::DEREncodeOptionalAttributes(BufferedTransformation &bt) const -{ - m_optionalAttributes.CopyTo(bt); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/asn.h b/lib/cryptopp/asn.h deleted file mode 100644 index c35126bc3..000000000 --- a/lib/cryptopp/asn.h +++ /dev/null @@ -1,369 +0,0 @@ -#ifndef CRYPTOPP_ASN_H -#define CRYPTOPP_ASN_H - -#include "filters.h" -#include "queue.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -// these tags and flags are not complete -enum ASNTag -{ - BOOLEAN = 0x01, - INTEGER = 0x02, - BIT_STRING = 0x03, - OCTET_STRING = 0x04, - TAG_NULL = 0x05, - OBJECT_IDENTIFIER = 0x06, - OBJECT_DESCRIPTOR = 0x07, - EXTERNAL = 0x08, - REAL = 0x09, - ENUMERATED = 0x0a, - UTF8_STRING = 0x0c, - SEQUENCE = 0x10, - SET = 0x11, - NUMERIC_STRING = 0x12, - PRINTABLE_STRING = 0x13, - T61_STRING = 0x14, - VIDEOTEXT_STRING = 0x15, - IA5_STRING = 0x16, - UTC_TIME = 0x17, - GENERALIZED_TIME = 0x18, - GRAPHIC_STRING = 0x19, - VISIBLE_STRING = 0x1a, - GENERAL_STRING = 0x1b -}; - -enum ASNIdFlag -{ - UNIVERSAL = 0x00, -// DATA = 0x01, -// HEADER = 0x02, - CONSTRUCTED = 0x20, - APPLICATION = 0x40, - CONTEXT_SPECIFIC = 0x80, - PRIVATE = 0xc0 -}; - -inline void BERDecodeError() {throw BERDecodeErr();} - -class CRYPTOPP_DLL UnknownOID : public BERDecodeErr -{ -public: - UnknownOID() : BERDecodeErr("BER decode error: unknown object identifier") {} - UnknownOID(const char *err) : BERDecodeErr(err) {} -}; - -// unsigned int DERLengthEncode(unsigned int length, byte *output=0); -CRYPTOPP_DLL size_t CRYPTOPP_API DERLengthEncode(BufferedTransformation &out, lword length); -// returns false if indefinite length -CRYPTOPP_DLL bool CRYPTOPP_API BERLengthDecode(BufferedTransformation &in, size_t &length); - -CRYPTOPP_DLL void CRYPTOPP_API DEREncodeNull(BufferedTransformation &out); -CRYPTOPP_DLL void CRYPTOPP_API BERDecodeNull(BufferedTransformation &in); - -CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &out, const byte *str, size_t strLen); -CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &out, const SecByteBlock &str); -CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &in, SecByteBlock &str); -CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &in, BufferedTransformation &str); - -// for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING -CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &out, const std::string &str, byte asnTag); -CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeTextString(BufferedTransformation &in, std::string &str, byte asnTag); - -CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeBitString(BufferedTransformation &out, const byte *str, size_t strLen, unsigned int unusedBits=0); -CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeBitString(BufferedTransformation &in, SecByteBlock &str, unsigned int &unusedBits); - -// BER decode from source and DER reencode into dest -CRYPTOPP_DLL void CRYPTOPP_API DERReencode(BufferedTransformation &source, BufferedTransformation &dest); - -//! Object Identifier -class CRYPTOPP_DLL OID -{ -public: - OID() {} - OID(word32 v) : m_values(1, v) {} - OID(BufferedTransformation &bt) {BERDecode(bt);} - - inline OID & operator+=(word32 rhs) {m_values.push_back(rhs); return *this;} - - void DEREncode(BufferedTransformation &bt) const; - void BERDecode(BufferedTransformation &bt); - - // throw BERDecodeErr() if decoded value doesn't equal this OID - void BERDecodeAndCheck(BufferedTransformation &bt) const; - - std::vector m_values; - -private: - static void EncodeValue(BufferedTransformation &bt, word32 v); - static size_t DecodeValue(BufferedTransformation &bt, word32 &v); -}; - -class EncodedObjectFilter : public Filter -{ -public: - enum Flag {PUT_OBJECTS=1, PUT_MESSANGE_END_AFTER_EACH_OBJECT=2, PUT_MESSANGE_END_AFTER_ALL_OBJECTS=4, PUT_MESSANGE_SERIES_END_AFTER_ALL_OBJECTS=8}; - EncodedObjectFilter(BufferedTransformation *attachment = NULL, unsigned int nObjects = 1, word32 flags = 0); - - void Put(const byte *inString, size_t length); - - unsigned int GetNumberOfCompletedObjects() const {return m_nCurrentObject;} - unsigned long GetPositionOfObject(unsigned int i) const {return m_positions[i];} - -private: - BufferedTransformation & CurrentTarget(); - - word32 m_flags; - unsigned int m_nObjects, m_nCurrentObject, m_level; - std::vector m_positions; - ByteQueue m_queue; - enum State {IDENTIFIER, LENGTH, BODY, TAIL, ALL_DONE} m_state; - byte m_id; - lword m_lengthRemaining; -}; - -//! BER General Decoder -class CRYPTOPP_DLL BERGeneralDecoder : public Store -{ -public: - explicit BERGeneralDecoder(BufferedTransformation &inQueue, byte asnTag); - explicit BERGeneralDecoder(BERGeneralDecoder &inQueue, byte asnTag); - ~BERGeneralDecoder(); - - bool IsDefiniteLength() const {return m_definiteLength;} - lword RemainingLength() const {assert(m_definiteLength); return m_length;} - bool EndReached() const; - byte PeekByte() const; - void CheckByte(byte b); - - size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const; - - // call this to denote end of sequence - void MessageEnd(); - -protected: - BufferedTransformation &m_inQueue; - bool m_finished, m_definiteLength; - lword m_length; - -private: - void Init(byte asnTag); - void StoreInitialize(const NameValuePairs ¶meters) {assert(false);} - lword ReduceLength(lword delta); -}; - -//! DER General Encoder -class CRYPTOPP_DLL DERGeneralEncoder : public ByteQueue -{ -public: - explicit DERGeneralEncoder(BufferedTransformation &outQueue, byte asnTag = SEQUENCE | CONSTRUCTED); - explicit DERGeneralEncoder(DERGeneralEncoder &outQueue, byte asnTag = SEQUENCE | CONSTRUCTED); - ~DERGeneralEncoder(); - - // call this to denote end of sequence - void MessageEnd(); - -private: - BufferedTransformation &m_outQueue; - bool m_finished; - - byte m_asnTag; -}; - -//! BER Sequence Decoder -class CRYPTOPP_DLL BERSequenceDecoder : public BERGeneralDecoder -{ -public: - explicit BERSequenceDecoder(BufferedTransformation &inQueue, byte asnTag = SEQUENCE | CONSTRUCTED) - : BERGeneralDecoder(inQueue, asnTag) {} - explicit BERSequenceDecoder(BERSequenceDecoder &inQueue, byte asnTag = SEQUENCE | CONSTRUCTED) - : BERGeneralDecoder(inQueue, asnTag) {} -}; - -//! DER Sequence Encoder -class CRYPTOPP_DLL DERSequenceEncoder : public DERGeneralEncoder -{ -public: - explicit DERSequenceEncoder(BufferedTransformation &outQueue, byte asnTag = SEQUENCE | CONSTRUCTED) - : DERGeneralEncoder(outQueue, asnTag) {} - explicit DERSequenceEncoder(DERSequenceEncoder &outQueue, byte asnTag = SEQUENCE | CONSTRUCTED) - : DERGeneralEncoder(outQueue, asnTag) {} -}; - -//! BER Set Decoder -class CRYPTOPP_DLL BERSetDecoder : public BERGeneralDecoder -{ -public: - explicit BERSetDecoder(BufferedTransformation &inQueue, byte asnTag = SET | CONSTRUCTED) - : BERGeneralDecoder(inQueue, asnTag) {} - explicit BERSetDecoder(BERSetDecoder &inQueue, byte asnTag = SET | CONSTRUCTED) - : BERGeneralDecoder(inQueue, asnTag) {} -}; - -//! DER Set Encoder -class CRYPTOPP_DLL DERSetEncoder : public DERGeneralEncoder -{ -public: - explicit DERSetEncoder(BufferedTransformation &outQueue, byte asnTag = SET | CONSTRUCTED) - : DERGeneralEncoder(outQueue, asnTag) {} - explicit DERSetEncoder(DERSetEncoder &outQueue, byte asnTag = SET | CONSTRUCTED) - : DERGeneralEncoder(outQueue, asnTag) {} -}; - -template -class ASNOptional : public member_ptr -{ -public: - void BERDecode(BERSequenceDecoder &seqDecoder, byte tag, byte mask = ~CONSTRUCTED) - { - byte b; - if (seqDecoder.Peek(b) && (b & mask) == tag) - reset(new T(seqDecoder)); - } - void DEREncode(BufferedTransformation &out) - { - if (this->get() != NULL) - this->get()->DEREncode(out); - } -}; - -//! _ -template -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ASN1CryptoMaterial : public ASN1Object, public BASE -{ -public: - void Save(BufferedTransformation &bt) const - {BEREncode(bt);} - void Load(BufferedTransformation &bt) - {BERDecode(bt);} -}; - -//! encodes/decodes subjectPublicKeyInfo -class CRYPTOPP_DLL X509PublicKey : public ASN1CryptoMaterial -{ -public: - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - virtual OID GetAlgorithmID() const =0; - virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt) - {BERDecodeNull(bt); return false;} - virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const - {DEREncodeNull(bt); return false;} // see RFC 2459, section 7.3.1 - - //! decode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header - virtual void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0; - //! encode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header - virtual void DEREncodePublicKey(BufferedTransformation &bt) const =0; -}; - -//! encodes/decodes privateKeyInfo -class CRYPTOPP_DLL PKCS8PrivateKey : public ASN1CryptoMaterial -{ -public: - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - virtual OID GetAlgorithmID() const =0; - virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt) - {BERDecodeNull(bt); return false;} - virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const - {DEREncodeNull(bt); return false;} // see RFC 2459, section 7.3.1 - - //! decode privateKey part of privateKeyInfo, without the OCTET STRING header - virtual void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0; - //! encode privateKey part of privateKeyInfo, without the OCTET STRING header - virtual void DEREncodePrivateKey(BufferedTransformation &bt) const =0; - - //! decode optional attributes including context-specific tag - /*! /note default implementation stores attributes to be output in DEREncodeOptionalAttributes */ - virtual void BERDecodeOptionalAttributes(BufferedTransformation &bt); - //! encode optional attributes including context-specific tag - virtual void DEREncodeOptionalAttributes(BufferedTransformation &bt) const; - -protected: - ByteQueue m_optionalAttributes; -}; - -// ******************************************************** - -//! DER Encode Unsigned -/*! for INTEGER, BOOLEAN, and ENUM */ -template -size_t DEREncodeUnsigned(BufferedTransformation &out, T w, byte asnTag = INTEGER) -{ - byte buf[sizeof(w)+1]; - unsigned int bc; - if (asnTag == BOOLEAN) - { - buf[sizeof(w)] = w ? 0xff : 0; - bc = 1; - } - else - { - buf[0] = 0; - for (unsigned int i=0; i> (sizeof(w)-1-i)*8); - bc = sizeof(w); - while (bc > 1 && buf[sizeof(w)+1-bc] == 0) - --bc; - if (buf[sizeof(w)+1-bc] & 0x80) - ++bc; - } - out.Put(asnTag); - size_t lengthBytes = DERLengthEncode(out, bc); - out.Put(buf+sizeof(w)+1-bc, bc); - return 1+lengthBytes+bc; -} - -//! BER Decode Unsigned -// VC60 workaround: std::numeric_limits::max conflicts with MFC max macro -// CW41 workaround: std::numeric_limits::max causes a template error -template -void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag = INTEGER, - T minValue = 0, T maxValue = 0xffffffff) -{ - byte b; - if (!in.Get(b) || b != asnTag) - BERDecodeError(); - - size_t bc; - BERLengthDecode(in, bc); - - SecByteBlock buf(bc); - - if (bc != in.Get(buf, bc)) - BERDecodeError(); - - const byte *ptr = buf; - while (bc > sizeof(w) && *ptr == 0) - { - bc--; - ptr++; - } - if (bc > sizeof(w)) - BERDecodeError(); - - w = 0; - for (unsigned int i=0; i maxValue) - BERDecodeError(); -} - -inline bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs) - {return lhs.m_values == rhs.m_values;} -inline bool operator!=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs) - {return lhs.m_values != rhs.m_values;} -inline bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs) - {return std::lexicographical_compare(lhs.m_values.begin(), lhs.m_values.end(), rhs.m_values.begin(), rhs.m_values.end());} -inline ::CryptoPP::OID operator+(const ::CryptoPP::OID &lhs, unsigned long rhs) - {return ::CryptoPP::OID(lhs)+=rhs;} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/authenc.cpp b/lib/cryptopp/authenc.cpp deleted file mode 100644 index f93662efb..000000000 --- a/lib/cryptopp/authenc.cpp +++ /dev/null @@ -1,180 +0,0 @@ -// authenc.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "authenc.h" - -NAMESPACE_BEGIN(CryptoPP) - -void AuthenticatedSymmetricCipherBase::AuthenticateData(const byte *input, size_t len) -{ - unsigned int blockSize = AuthenticationBlockSize(); - unsigned int &num = m_bufferedDataLength; - byte* data = m_buffer.begin(); - - if (num != 0) // process left over data - { - if (num+len >= blockSize) - { - memcpy(data+num, input, blockSize-num); - AuthenticateBlocks(data, blockSize); - input += (blockSize-num); - len -= (blockSize-num); - num = 0; - // drop through and do the rest - } - else - { - memcpy(data+num, input, len); - num += (unsigned int)len; - return; - } - } - - // now process the input data in blocks of blockSize bytes and save the leftovers to m_data - if (len >= blockSize) - { - size_t leftOver = AuthenticateBlocks(input, len); - input += (len - leftOver); - len = leftOver; - } - - memcpy(data, input, len); - num = (unsigned int)len; -} - -void AuthenticatedSymmetricCipherBase::SetKey(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) -{ - m_bufferedDataLength = 0; - m_state = State_Start; - - SetKeyWithoutResync(userKey, keylength, params); - m_state = State_KeySet; - - size_t length; - const byte *iv = GetIVAndThrowIfInvalid(params, length); - if (iv) - Resynchronize(iv, (int)length); -} - -void AuthenticatedSymmetricCipherBase::Resynchronize(const byte *iv, int length) -{ - if (m_state < State_KeySet) - throw BadState(AlgorithmName(), "Resynchronize", "key is set"); - - m_bufferedDataLength = 0; - m_totalHeaderLength = m_totalMessageLength = m_totalFooterLength = 0; - m_state = State_KeySet; - - Resync(iv, this->ThrowIfInvalidIVLength(length)); - m_state = State_IVSet; -} - -void AuthenticatedSymmetricCipherBase::Update(const byte *input, size_t length) -{ - if (length == 0) - return; - - switch (m_state) - { - case State_Start: - case State_KeySet: - throw BadState(AlgorithmName(), "Update", "setting key and IV"); - case State_IVSet: - AuthenticateData(input, length); - m_totalHeaderLength += length; - break; - case State_AuthUntransformed: - case State_AuthTransformed: - AuthenticateLastConfidentialBlock(); - m_bufferedDataLength = 0; - m_state = State_AuthFooter; - // fall through - case State_AuthFooter: - AuthenticateData(input, length); - m_totalFooterLength += length; - break; - default: - assert(false); - } -} - -void AuthenticatedSymmetricCipherBase::ProcessData(byte *outString, const byte *inString, size_t length) -{ - m_totalMessageLength += length; - if (m_state >= State_IVSet && m_totalMessageLength > MaxMessageLength()) - throw InvalidArgument(AlgorithmName() + ": message length exceeds maximum"); - -reswitch: - switch (m_state) - { - case State_Start: - case State_KeySet: - throw BadState(AlgorithmName(), "ProcessData", "setting key and IV"); - case State_AuthFooter: - throw BadState(AlgorithmName(), "ProcessData was called after footer input has started"); - case State_IVSet: - AuthenticateLastHeaderBlock(); - m_bufferedDataLength = 0; - m_state = AuthenticationIsOnPlaintext()==IsForwardTransformation() ? State_AuthUntransformed : State_AuthTransformed; - goto reswitch; - case State_AuthUntransformed: - AuthenticateData(inString, length); - AccessSymmetricCipher().ProcessData(outString, inString, length); - break; - case State_AuthTransformed: - AccessSymmetricCipher().ProcessData(outString, inString, length); - AuthenticateData(outString, length); - break; - default: - assert(false); - } -} - -void AuthenticatedSymmetricCipherBase::TruncatedFinal(byte *mac, size_t macSize) -{ - if (m_totalHeaderLength > MaxHeaderLength()) - throw InvalidArgument(AlgorithmName() + ": header length of " + IntToString(m_totalHeaderLength) + " exceeds the maximum of " + IntToString(MaxHeaderLength())); - - if (m_totalFooterLength > MaxFooterLength()) - { - if (MaxFooterLength() == 0) - throw InvalidArgument(AlgorithmName() + ": additional authenticated data (AAD) cannot be input after data to be encrypted or decrypted"); - else - throw InvalidArgument(AlgorithmName() + ": footer length of " + IntToString(m_totalFooterLength) + " exceeds the maximum of " + IntToString(MaxFooterLength())); - } - - switch (m_state) - { - case State_Start: - case State_KeySet: - throw BadState(AlgorithmName(), "TruncatedFinal", "setting key and IV"); - - case State_IVSet: - AuthenticateLastHeaderBlock(); - m_bufferedDataLength = 0; - // fall through - - case State_AuthUntransformed: - case State_AuthTransformed: - AuthenticateLastConfidentialBlock(); - m_bufferedDataLength = 0; - // fall through - - case State_AuthFooter: - AuthenticateLastFooterBlock(mac, macSize); - m_bufferedDataLength = 0; - break; - - default: - assert(false); - } - - m_state = State_KeySet; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/authenc.h b/lib/cryptopp/authenc.h deleted file mode 100644 index 5bb2a51c8..000000000 --- a/lib/cryptopp/authenc.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef CRYPTOPP_AUTHENC_H -#define CRYPTOPP_AUTHENC_H - -#include "cryptlib.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! . -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipherBase : public AuthenticatedSymmetricCipher -{ -public: - AuthenticatedSymmetricCipherBase() : m_state(State_Start) {} - - bool IsRandomAccess() const {return false;} - bool IsSelfInverting() const {return true;} - void UncheckedSetKey(const byte *,unsigned int,const CryptoPP::NameValuePairs &) {assert(false);} - - void SetKey(const byte *userKey, size_t keylength, const NameValuePairs ¶ms); - void Restart() {if (m_state > State_KeySet) m_state = State_KeySet;} - void Resynchronize(const byte *iv, int length=-1); - void Update(const byte *input, size_t length); - void ProcessData(byte *outString, const byte *inString, size_t length); - void TruncatedFinal(byte *mac, size_t macSize); - -protected: - void AuthenticateData(const byte *data, size_t len); - const SymmetricCipher & GetSymmetricCipher() const {return const_cast(this)->AccessSymmetricCipher();}; - - virtual SymmetricCipher & AccessSymmetricCipher() =0; - virtual bool AuthenticationIsOnPlaintext() const =0; - virtual unsigned int AuthenticationBlockSize() const =0; - virtual void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) =0; - virtual void Resync(const byte *iv, size_t len) =0; - virtual size_t AuthenticateBlocks(const byte *data, size_t len) =0; - virtual void AuthenticateLastHeaderBlock() =0; - virtual void AuthenticateLastConfidentialBlock() {} - virtual void AuthenticateLastFooterBlock(byte *mac, size_t macSize) =0; - - enum State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter}; - State m_state; - unsigned int m_bufferedDataLength; - lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength; - AlignedSecByteBlock m_buffer; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/base32.cpp b/lib/cryptopp/base32.cpp deleted file mode 100644 index 0568f0729..000000000 --- a/lib/cryptopp/base32.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// base32.cpp - written and placed in the public domain by Frank Palazzolo, based on hex.cpp by Wei Dai - -#include "pch.h" -#include "base32.h" - -NAMESPACE_BEGIN(CryptoPP) - -static const byte s_vecUpper[] = "ABCDEFGHIJKMNPQRSTUVWXYZ23456789"; -static const byte s_vecLower[] = "abcdefghijkmnpqrstuvwxyz23456789"; - -void Base32Encoder::IsolatedInitialize(const NameValuePairs ¶meters) -{ - bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true); - m_filter->Initialize(CombinedNameValuePairs( - parameters, - MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_vecUpper[0] : &s_vecLower[0], false)(Name::Log2Base(), 5, true))); -} - -void Base32Decoder::IsolatedInitialize(const NameValuePairs ¶meters) -{ - BaseN_Decoder::Initialize(CombinedNameValuePairs( - parameters, - MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 5, true))); -} - -const int *Base32Decoder::GetDefaultDecodingLookupArray() -{ - static volatile bool s_initialized = false; - static int s_array[256]; - - if (!s_initialized) - { - InitializeDecodingLookupArray(s_array, s_vecUpper, 32, true); - s_initialized = true; - } - return s_array; -} - -NAMESPACE_END diff --git a/lib/cryptopp/base32.h b/lib/cryptopp/base32.h deleted file mode 100644 index cb1e1af8d..000000000 --- a/lib/cryptopp/base32.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef CRYPTOPP_BASE32_H -#define CRYPTOPP_BASE32_H - -#include "basecode.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! Converts given data to base 32, the default code is based on draft-ietf-idn-dude-02.txt -/*! To specify alternative code, call Initialize() with EncodingLookupArray parameter. */ -class Base32Encoder : public SimpleProxyFilter -{ -public: - Base32Encoder(BufferedTransformation *attachment = NULL, bool uppercase = true, int outputGroupSize = 0, const std::string &separator = ":", const std::string &terminator = "") - : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment) - { - IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), outputGroupSize)(Name::Separator(), ConstByteArrayParameter(separator))); - } - - void IsolatedInitialize(const NameValuePairs ¶meters); -}; - -//! Decode base 32 data back to bytes, the default code is based on draft-ietf-idn-dude-02.txt -/*! To specify alternative code, call Initialize() with DecodingLookupArray parameter. */ -class Base32Decoder : public BaseN_Decoder -{ -public: - Base32Decoder(BufferedTransformation *attachment = NULL) - : BaseN_Decoder(GetDefaultDecodingLookupArray(), 5, attachment) {} - - void IsolatedInitialize(const NameValuePairs ¶meters); - -private: - static const int * CRYPTOPP_API GetDefaultDecodingLookupArray(); -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/base64.cpp b/lib/cryptopp/base64.cpp deleted file mode 100644 index 7571f2b8c..000000000 --- a/lib/cryptopp/base64.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// base64.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "base64.h" - -NAMESPACE_BEGIN(CryptoPP) - -static const byte s_vec[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static const byte s_padding = '='; - -void Base64Encoder::IsolatedInitialize(const NameValuePairs ¶meters) -{ - bool insertLineBreaks = parameters.GetValueWithDefault(Name::InsertLineBreaks(), true); - int maxLineLength = parameters.GetIntValueWithDefault(Name::MaxLineLength(), 72); - - const char *lineBreak = insertLineBreaks ? "\n" : ""; - - m_filter->Initialize(CombinedNameValuePairs( - parameters, - MakeParameters(Name::EncodingLookupArray(), &s_vec[0], false) - (Name::PaddingByte(), s_padding) - (Name::GroupSize(), insertLineBreaks ? maxLineLength : 0) - (Name::Separator(), ConstByteArrayParameter(lineBreak)) - (Name::Terminator(), ConstByteArrayParameter(lineBreak)) - (Name::Log2Base(), 6, true))); -} - -const int *Base64Decoder::GetDecodingLookupArray() -{ - static volatile bool s_initialized = false; - static int s_array[256]; - - if (!s_initialized) - { - InitializeDecodingLookupArray(s_array, s_vec, 64, false); - s_initialized = true; - } - return s_array; -} - -NAMESPACE_END diff --git a/lib/cryptopp/base64.h b/lib/cryptopp/base64.h deleted file mode 100644 index 5a9e184b2..000000000 --- a/lib/cryptopp/base64.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef CRYPTOPP_BASE64_H -#define CRYPTOPP_BASE64_H - -#include "basecode.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! Base64 Encoder Class -class Base64Encoder : public SimpleProxyFilter -{ -public: - Base64Encoder(BufferedTransformation *attachment = NULL, bool insertLineBreaks = true, int maxLineLength = 72) - : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment) - { - IsolatedInitialize(MakeParameters(Name::InsertLineBreaks(), insertLineBreaks)(Name::MaxLineLength(), maxLineLength)); - } - - void IsolatedInitialize(const NameValuePairs ¶meters); -}; - -//! Base64 Decoder Class -class Base64Decoder : public BaseN_Decoder -{ -public: - Base64Decoder(BufferedTransformation *attachment = NULL) - : BaseN_Decoder(GetDecodingLookupArray(), 6, attachment) {} - - void IsolatedInitialize(const NameValuePairs ¶meters) {} - -private: - static const int * CRYPTOPP_API GetDecodingLookupArray(); -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/basecode.cpp b/lib/cryptopp/basecode.cpp deleted file mode 100644 index 0c98b2271..000000000 --- a/lib/cryptopp/basecode.cpp +++ /dev/null @@ -1,238 +0,0 @@ -// basecode.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "basecode.h" -#include "fltrimpl.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -void BaseN_Encoder::IsolatedInitialize(const NameValuePairs ¶meters) -{ - parameters.GetRequiredParameter("BaseN_Encoder", Name::EncodingLookupArray(), m_alphabet); - - parameters.GetRequiredIntParameter("BaseN_Encoder", Name::Log2Base(), m_bitsPerChar); - if (m_bitsPerChar <= 0 || m_bitsPerChar >= 8) - throw InvalidArgument("BaseN_Encoder: Log2Base must be between 1 and 7 inclusive"); - - byte padding; - bool pad; - if (parameters.GetValue(Name::PaddingByte(), padding)) - pad = parameters.GetValueWithDefault(Name::Pad(), true); - else - pad = false; - m_padding = pad ? padding : -1; - - m_bytePos = m_bitPos = 0; - - int i = 8; - while (i%m_bitsPerChar != 0) - i += 8; - m_outputBlockSize = i/m_bitsPerChar; - - m_outBuf.New(m_outputBlockSize); -} - -size_t BaseN_Encoder::Put2(const byte *begin, size_t length, int messageEnd, bool blocking) -{ - FILTER_BEGIN; - while (m_inputPosition < length) - { - if (m_bytePos == 0) - memset(m_outBuf, 0, m_outputBlockSize); - - { - unsigned int b = begin[m_inputPosition++], bitsLeftInSource = 8; - while (true) - { - assert(m_bitPos < m_bitsPerChar); - unsigned int bitsLeftInTarget = m_bitsPerChar-m_bitPos; - m_outBuf[m_bytePos] |= b >> (8-bitsLeftInTarget); - if (bitsLeftInSource >= bitsLeftInTarget) - { - m_bitPos = 0; - ++m_bytePos; - bitsLeftInSource -= bitsLeftInTarget; - if (bitsLeftInSource == 0) - break; - b <<= bitsLeftInTarget; - b &= 0xff; - } - else - { - m_bitPos += bitsLeftInSource; - break; - } - } - } - - assert(m_bytePos <= m_outputBlockSize); - if (m_bytePos == m_outputBlockSize) - { - int i; - for (i=0; i 0) - ++m_bytePos; - - int i; - for (i=0; i 0) - { - memset(m_outBuf+m_bytePos, m_padding, m_outputBlockSize-m_bytePos); - m_bytePos = m_outputBlockSize; - } - FILTER_OUTPUT(2, m_outBuf, m_bytePos, messageEnd); - m_bytePos = m_bitPos = 0; - } - FILTER_END_NO_MESSAGE_END; -} - -void BaseN_Decoder::IsolatedInitialize(const NameValuePairs ¶meters) -{ - parameters.GetRequiredParameter("BaseN_Decoder", Name::DecodingLookupArray(), m_lookup); - - parameters.GetRequiredIntParameter("BaseN_Decoder", Name::Log2Base(), m_bitsPerChar); - if (m_bitsPerChar <= 0 || m_bitsPerChar >= 8) - throw InvalidArgument("BaseN_Decoder: Log2Base must be between 1 and 7 inclusive"); - - m_bytePos = m_bitPos = 0; - - int i = m_bitsPerChar; - while (i%8 != 0) - i += m_bitsPerChar; - m_outputBlockSize = i/8; - - m_outBuf.New(m_outputBlockSize); -} - -size_t BaseN_Decoder::Put2(const byte *begin, size_t length, int messageEnd, bool blocking) -{ - FILTER_BEGIN; - while (m_inputPosition < length) - { - unsigned int value; - value = m_lookup[begin[m_inputPosition++]]; - if (value >= 256) - continue; - - if (m_bytePos == 0 && m_bitPos == 0) - memset(m_outBuf, 0, m_outputBlockSize); - - { - int newBitPos = m_bitPos + m_bitsPerChar; - if (newBitPos <= 8) - m_outBuf[m_bytePos] |= value << (8-newBitPos); - else - { - m_outBuf[m_bytePos] |= value >> (newBitPos-8); - m_outBuf[m_bytePos+1] |= value << (16-newBitPos); - } - - m_bitPos = newBitPos; - while (m_bitPos >= 8) - { - m_bitPos -= 8; - ++m_bytePos; - } - } - - if (m_bytePos == m_outputBlockSize) - { - FILTER_OUTPUT(1, m_outBuf, m_outputBlockSize, 0); - m_bytePos = m_bitPos = 0; - } - } - if (messageEnd) - { - FILTER_OUTPUT(2, m_outBuf, m_bytePos, messageEnd); - m_bytePos = m_bitPos = 0; - } - FILTER_END_NO_MESSAGE_END; -} - -void BaseN_Decoder::InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive) -{ - std::fill(lookup, lookup+256, -1); - - for (unsigned int i=0; i -{ -public: - BaseN_Encoder(BufferedTransformation *attachment=NULL) - {Detach(attachment);} - - BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULL, int padding=-1) - { - Detach(attachment); - IsolatedInitialize(MakeParameters(Name::EncodingLookupArray(), alphabet) - (Name::Log2Base(), log2base) - (Name::Pad(), padding != -1) - (Name::PaddingByte(), byte(padding))); - } - - void IsolatedInitialize(const NameValuePairs ¶meters); - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking); - -private: - const byte *m_alphabet; - int m_padding, m_bitsPerChar, m_outputBlockSize; - int m_bytePos, m_bitPos; - SecByteBlock m_outBuf; -}; - -//! base n decoder, where n is a power of 2 -class CRYPTOPP_DLL BaseN_Decoder : public Unflushable -{ -public: - BaseN_Decoder(BufferedTransformation *attachment=NULL) - {Detach(attachment);} - - BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULL) - { - Detach(attachment); - IsolatedInitialize(MakeParameters(Name::DecodingLookupArray(), lookup)(Name::Log2Base(), log2base)); - } - - void IsolatedInitialize(const NameValuePairs ¶meters); - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking); - - static void CRYPTOPP_API InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive); - -private: - const int *m_lookup; - int m_padding, m_bitsPerChar, m_outputBlockSize; - int m_bytePos, m_bitPos; - SecByteBlock m_outBuf; -}; - -//! filter that breaks input stream into groups of fixed size -class CRYPTOPP_DLL Grouper : public Bufferless -{ -public: - Grouper(BufferedTransformation *attachment=NULL) - {Detach(attachment);} - - Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULL) - { - Detach(attachment); - IsolatedInitialize(MakeParameters(Name::GroupSize(), groupSize) - (Name::Separator(), ConstByteArrayParameter(separator)) - (Name::Terminator(), ConstByteArrayParameter(terminator))); - } - - void IsolatedInitialize(const NameValuePairs ¶meters); - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking); - -private: - SecByteBlock m_separator, m_terminator; - size_t m_groupSize, m_counter; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/cbcmac.cpp b/lib/cryptopp/cbcmac.cpp deleted file mode 100644 index 6b0e8858e..000000000 --- a/lib/cryptopp/cbcmac.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "cbcmac.h" - -NAMESPACE_BEGIN(CryptoPP) - -void CBC_MAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) -{ - AccessCipher().SetKey(key, length, params); - m_reg.CleanNew(AccessCipher().BlockSize()); - m_counter = 0; -} - -void CBC_MAC_Base::Update(const byte *input, size_t length) -{ - unsigned int blockSize = AccessCipher().BlockSize(); - - while (m_counter && length) - { - m_reg[m_counter++] ^= *input++; - if (m_counter == blockSize) - ProcessBuf(); - length--; - } - - if (length >= blockSize) - { - size_t leftOver = AccessCipher().AdvancedProcessBlocks(m_reg, input, m_reg, length, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput); - input += (length - leftOver); - length = leftOver; - } - - while (length--) - { - m_reg[m_counter++] ^= *input++; - if (m_counter == blockSize) - ProcessBuf(); - } -} - -void CBC_MAC_Base::TruncatedFinal(byte *mac, size_t size) -{ - ThrowIfInvalidTruncatedSize(size); - - if (m_counter) - ProcessBuf(); - - memcpy(mac, m_reg, size); - memset(m_reg, 0, AccessCipher().BlockSize()); -} - -void CBC_MAC_Base::ProcessBuf() -{ - AccessCipher().ProcessBlock(m_reg); - m_counter = 0; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/cbcmac.h b/lib/cryptopp/cbcmac.h deleted file mode 100644 index 4675dcb3d..000000000 --- a/lib/cryptopp/cbcmac.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef CRYPTOPP_CBCMAC_H -#define CRYPTOPP_CBCMAC_H - -#include "seckey.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticationCode -{ -public: - CBC_MAC_Base() {} - - void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); - void Update(const byte *input, size_t length); - void TruncatedFinal(byte *mac, size_t size); - unsigned int DigestSize() const {return const_cast(this)->AccessCipher().BlockSize();} - -protected: - virtual BlockCipher & AccessCipher() =0; - -private: - void ProcessBuf(); - SecByteBlock m_reg; - unsigned int m_counter; -}; - -//! CBC-MAC -/*! Compatible with FIPS 113. T should be a class derived from BlockCipherDocumentation. - Secure only for fixed length messages. For variable length messages use CMAC or DMAC. -*/ -template -class CBC_MAC : public MessageAuthenticationCodeImpl >, public SameKeyLengthAs -{ -public: - CBC_MAC() {} - CBC_MAC(const byte *key, size_t length=SameKeyLengthAs::DEFAULT_KEYLENGTH) - {this->SetKey(key, length);} - - static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";} - -private: - BlockCipher & AccessCipher() {return m_cipher;} - typename T::Encryption m_cipher; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/ccm.cpp b/lib/cryptopp/ccm.cpp deleted file mode 100644 index 030828ad8..000000000 --- a/lib/cryptopp/ccm.cpp +++ /dev/null @@ -1,140 +0,0 @@ -// ccm.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "ccm.h" - -NAMESPACE_BEGIN(CryptoPP) - -void CCM_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) -{ - BlockCipher &blockCipher = AccessBlockCipher(); - - blockCipher.SetKey(userKey, keylength, params); - - if (blockCipher.BlockSize() != REQUIRED_BLOCKSIZE) - throw InvalidArgument(AlgorithmName() + ": block size of underlying block cipher is not 16"); - - m_digestSize = params.GetIntValueWithDefault(Name::DigestSize(), DefaultDigestSize()); - if (m_digestSize % 2 > 0 || m_digestSize < 4 || m_digestSize > 16) - throw InvalidArgument(AlgorithmName() + ": DigestSize must be 4, 6, 8, 10, 12, 14, or 16"); - - m_buffer.Grow(2*REQUIRED_BLOCKSIZE); - m_L = 8; -} - -void CCM_Base::Resync(const byte *iv, size_t len) -{ - BlockCipher &cipher = AccessBlockCipher(); - - m_L = REQUIRED_BLOCKSIZE-1-(int)len; - assert(m_L >= 2); - if (m_L > 8) - m_L = 8; - - m_buffer[0] = byte(m_L-1); // flag - memcpy(m_buffer+1, iv, len); - memset(m_buffer+1+len, 0, REQUIRED_BLOCKSIZE-1-len); - - if (m_state >= State_IVSet) - m_ctr.Resynchronize(m_buffer, REQUIRED_BLOCKSIZE); - else - m_ctr.SetCipherWithIV(cipher, m_buffer); - - m_ctr.Seek(REQUIRED_BLOCKSIZE); - m_aadLength = 0; - m_messageLength = 0; -} - -void CCM_Base::UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength) -{ - if (m_state != State_IVSet) - throw BadState(AlgorithmName(), "SpecifyDataLengths", "or after State_IVSet"); - - m_aadLength = headerLength; - m_messageLength = messageLength; - - byte *cbcBuffer = CBC_Buffer(); - const BlockCipher &cipher = GetBlockCipher(); - - cbcBuffer[0] = byte(64*(headerLength>0) + 8*((m_digestSize-2)/2) + (m_L-1)); // flag - PutWord(true, BIG_ENDIAN_ORDER, cbcBuffer+REQUIRED_BLOCKSIZE-8, m_messageLength); - memcpy(cbcBuffer+1, m_buffer+1, REQUIRED_BLOCKSIZE-1-m_L); - cipher.ProcessBlock(cbcBuffer); - - if (headerLength>0) - { - assert(m_bufferedDataLength == 0); - - if (headerLength < ((1<<16) - (1<<8))) - { - PutWord(true, BIG_ENDIAN_ORDER, m_buffer, (word16)headerLength); - m_bufferedDataLength = 2; - } - else if (headerLength < (W64LIT(1)<<32)) - { - m_buffer[0] = 0xff; - m_buffer[1] = 0xfe; - PutWord(false, BIG_ENDIAN_ORDER, m_buffer+2, (word32)headerLength); - m_bufferedDataLength = 6; - } - else - { - m_buffer[0] = 0xff; - m_buffer[1] = 0xff; - PutWord(false, BIG_ENDIAN_ORDER, m_buffer+2, headerLength); - m_bufferedDataLength = 10; - } - } -} - -size_t CCM_Base::AuthenticateBlocks(const byte *data, size_t len) -{ - byte *cbcBuffer = CBC_Buffer(); - const BlockCipher &cipher = GetBlockCipher(); - return cipher.AdvancedProcessBlocks(cbcBuffer, data, cbcBuffer, len, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput); -} - -void CCM_Base::AuthenticateLastHeaderBlock() -{ - byte *cbcBuffer = CBC_Buffer(); - const BlockCipher &cipher = GetBlockCipher(); - - if (m_aadLength != m_totalHeaderLength) - throw InvalidArgument(AlgorithmName() + ": header length doesn't match that given in SpecifyDataLengths"); - - if (m_bufferedDataLength > 0) - { - xorbuf(cbcBuffer, m_buffer, m_bufferedDataLength); - cipher.ProcessBlock(cbcBuffer); - m_bufferedDataLength = 0; - } -} - -void CCM_Base::AuthenticateLastConfidentialBlock() -{ - byte *cbcBuffer = CBC_Buffer(); - const BlockCipher &cipher = GetBlockCipher(); - - if (m_messageLength != m_totalMessageLength) - throw InvalidArgument(AlgorithmName() + ": message length doesn't match that given in SpecifyDataLengths"); - - if (m_bufferedDataLength > 0) - { - xorbuf(cbcBuffer, m_buffer, m_bufferedDataLength); - cipher.ProcessBlock(cbcBuffer); - m_bufferedDataLength = 0; - } -} - -void CCM_Base::AuthenticateLastFooterBlock(byte *mac, size_t macSize) -{ - m_ctr.Seek(0); - m_ctr.ProcessData(mac, CBC_Buffer(), macSize); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/ccm.h b/lib/cryptopp/ccm.h deleted file mode 100644 index b1e5f00b9..000000000 --- a/lib/cryptopp/ccm.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef CRYPTOPP_CCM_H -#define CRYPTOPP_CCM_H - -#include "authenc.h" -#include "modes.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! . -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CCM_Base : public AuthenticatedSymmetricCipherBase -{ -public: - CCM_Base() - : m_digestSize(0), m_L(0) {} - - // AuthenticatedSymmetricCipher - std::string AlgorithmName() const - {return GetBlockCipher().AlgorithmName() + std::string("/CCM");} - size_t MinKeyLength() const - {return GetBlockCipher().MinKeyLength();} - size_t MaxKeyLength() const - {return GetBlockCipher().MaxKeyLength();} - size_t DefaultKeyLength() const - {return GetBlockCipher().DefaultKeyLength();} - size_t GetValidKeyLength(size_t n) const - {return GetBlockCipher().GetValidKeyLength(n);} - bool IsValidKeyLength(size_t n) const - {return GetBlockCipher().IsValidKeyLength(n);} - unsigned int OptimalDataAlignment() const - {return GetBlockCipher().OptimalDataAlignment();} - IV_Requirement IVRequirement() const - {return UNIQUE_IV;} - unsigned int IVSize() const - {return 8;} - unsigned int MinIVLength() const - {return 7;} - unsigned int MaxIVLength() const - {return 13;} - unsigned int DigestSize() const - {return m_digestSize;} - lword MaxHeaderLength() const - {return W64LIT(0)-1;} - lword MaxMessageLength() const - {return m_L<8 ? (W64LIT(1)<<(8*m_L))-1 : W64LIT(0)-1;} - bool NeedsPrespecifiedDataLengths() const - {return true;} - void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength); - -protected: - // AuthenticatedSymmetricCipherBase - bool AuthenticationIsOnPlaintext() const - {return true;} - unsigned int AuthenticationBlockSize() const - {return GetBlockCipher().BlockSize();} - void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms); - void Resync(const byte *iv, size_t len); - size_t AuthenticateBlocks(const byte *data, size_t len); - void AuthenticateLastHeaderBlock(); - void AuthenticateLastConfidentialBlock(); - void AuthenticateLastFooterBlock(byte *mac, size_t macSize); - SymmetricCipher & AccessSymmetricCipher() {return m_ctr;} - - virtual BlockCipher & AccessBlockCipher() =0; - virtual int DefaultDigestSize() const =0; - - const BlockCipher & GetBlockCipher() const {return const_cast(this)->AccessBlockCipher();}; - byte *CBC_Buffer() {return m_buffer+REQUIRED_BLOCKSIZE;} - - enum {REQUIRED_BLOCKSIZE = 16}; - int m_digestSize, m_L; - word64 m_messageLength, m_aadLength; - CTR_Mode_ExternalCipher::Encryption m_ctr; -}; - -//! . -template -class CCM_Final : public CCM_Base -{ -public: - static std::string StaticAlgorithmName() - {return T_BlockCipher::StaticAlgorithmName() + std::string("/CCM");} - bool IsForwardTransformation() const - {return T_IsEncryption;} - -private: - BlockCipher & AccessBlockCipher() {return m_cipher;} - int DefaultDigestSize() const {return T_DefaultDigestSize;} - typename T_BlockCipher::Encryption m_cipher; -}; - -/// CCM -template -struct CCM : public AuthenticatedSymmetricCipherDocumentation -{ - typedef CCM_Final Encryption; - typedef CCM_Final Decryption; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/channels.cpp b/lib/cryptopp/channels.cpp deleted file mode 100644 index 7359f54f7..000000000 --- a/lib/cryptopp/channels.cpp +++ /dev/null @@ -1,309 +0,0 @@ -// channels.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "channels.h" - -NAMESPACE_BEGIN(CryptoPP) -USING_NAMESPACE(std) - -#if 0 -void MessageSwitch::AddDefaultRoute(BufferedTransformation &destination, const std::string &channel) -{ - m_defaultRoutes.push_back(Route(&destination, channel)); -} - -void MessageSwitch::AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel) -{ - RangeRoute route(begin, end, Route(&destination, channel)); - RouteList::iterator it = upper_bound(m_routes.begin(), m_routes.end(), route); - m_routes.insert(it, route); -} - -/* -class MessageRouteIterator -{ -public: - typedef MessageSwitch::RouteList::const_iterator RouteIterator; - typedef MessageSwitch::DefaultRouteList::const_iterator DefaultIterator; - - bool m_useDefault; - RouteIterator m_itRouteCurrent, m_itRouteEnd; - DefaultIterator m_itDefaultCurrent, m_itDefaultEnd; - - MessageRouteIterator(MessageSwitch &ms, const std::string &channel) - : m_channel(channel) - { - pair range = cs.m_routeMap.equal_range(channel); - if (range.first == range.second) - { - m_useDefault = true; - m_itListCurrent = cs.m_defaultRoutes.begin(); - m_itListEnd = cs.m_defaultRoutes.end(); - } - else - { - m_useDefault = false; - m_itMapCurrent = range.first; - m_itMapEnd = range.second; - } - } - - bool End() const - { - return m_useDefault ? m_itListCurrent == m_itListEnd : m_itMapCurrent == m_itMapEnd; - } - - void Next() - { - if (m_useDefault) - ++m_itListCurrent; - else - ++m_itMapCurrent; - } - - BufferedTransformation & Destination() - { - return m_useDefault ? *m_itListCurrent->first : *m_itMapCurrent->second.first; - } - - const std::string & Message() - { - if (m_useDefault) - return m_itListCurrent->second.get() ? *m_itListCurrent->second.get() : m_channel; - else - return m_itMapCurrent->second.second; - } -}; - -void MessageSwitch::Put(byte inByte); -void MessageSwitch::Put(const byte *inString, unsigned int length); - -void MessageSwitch::Flush(bool completeFlush, int propagation=-1); -void MessageSwitch::MessageEnd(int propagation=-1); -void MessageSwitch::PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1); -void MessageSwitch::MessageSeriesEnd(int propagation=-1); -*/ -#endif - - -// -// ChannelRouteIterator -////////////////////////// - -void ChannelRouteIterator::Reset(const std::string &channel) -{ - m_channel = channel; - pair range = m_cs.m_routeMap.equal_range(channel); - if (range.first == range.second) - { - m_useDefault = true; - m_itListCurrent = m_cs.m_defaultRoutes.begin(); - m_itListEnd = m_cs.m_defaultRoutes.end(); - } - else - { - m_useDefault = false; - m_itMapCurrent = range.first; - m_itMapEnd = range.second; - } -} - -bool ChannelRouteIterator::End() const -{ - return m_useDefault ? m_itListCurrent == m_itListEnd : m_itMapCurrent == m_itMapEnd; -} - -void ChannelRouteIterator::Next() -{ - if (m_useDefault) - ++m_itListCurrent; - else - ++m_itMapCurrent; -} - -BufferedTransformation & ChannelRouteIterator::Destination() -{ - return m_useDefault ? *m_itListCurrent->first : *m_itMapCurrent->second.first; -} - -const std::string & ChannelRouteIterator::Channel() -{ - if (m_useDefault) - return m_itListCurrent->second.get() ? *m_itListCurrent->second.get() : m_channel; - else - return m_itMapCurrent->second.second; -} - - -// -// ChannelSwitch -/////////////////// - -size_t ChannelSwitch::ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking) -{ - if (m_blocked) - { - m_blocked = false; - goto WasBlocked; - } - - m_it.Reset(channel); - - while (!m_it.End()) - { -WasBlocked: - if (m_it.Destination().ChannelPut2(m_it.Channel(), begin, length, messageEnd, blocking)) - { - m_blocked = true; - return 1; - } - - m_it.Next(); - } - - return 0; -} - -void ChannelSwitch::IsolatedInitialize(const NameValuePairs ¶meters/* =g_nullNameValuePairs */) -{ - m_routeMap.clear(); - m_defaultRoutes.clear(); - m_blocked = false; -} - -bool ChannelSwitch::ChannelFlush(const std::string &channel, bool completeFlush, int propagation, bool blocking) -{ - if (m_blocked) - { - m_blocked = false; - goto WasBlocked; - } - - m_it.Reset(channel); - - while (!m_it.End()) - { - WasBlocked: - if (m_it.Destination().ChannelFlush(m_it.Channel(), completeFlush, propagation, blocking)) - { - m_blocked = true; - return true; - } - - m_it.Next(); - } - - return false; -} - -bool ChannelSwitch::ChannelMessageSeriesEnd(const std::string &channel, int propagation, bool blocking) -{ - if (m_blocked) - { - m_blocked = false; - goto WasBlocked; - } - - m_it.Reset(channel); - - while (!m_it.End()) - { - WasBlocked: - if (m_it.Destination().ChannelMessageSeriesEnd(m_it.Channel(), propagation)) - { - m_blocked = true; - return true; - } - - m_it.Next(); - } - - return false; -} - -byte * ChannelSwitch::ChannelCreatePutSpace(const std::string &channel, size_t &size) -{ - m_it.Reset(channel); - if (!m_it.End()) - { - BufferedTransformation &target = m_it.Destination(); - const std::string &channel = m_it.Channel(); - m_it.Next(); - if (m_it.End()) // there is only one target channel - return target.ChannelCreatePutSpace(channel, size); - } - size = 0; - return NULL; -} - -size_t ChannelSwitch::ChannelPutModifiable2(const std::string &channel, byte *inString, size_t length, int messageEnd, bool blocking) -{ - ChannelRouteIterator it(*this); - it.Reset(channel); - - if (!it.End()) - { - BufferedTransformation &target = it.Destination(); - const std::string &targetChannel = it.Channel(); - it.Next(); - if (it.End()) // there is only one target channel - return target.ChannelPutModifiable2(targetChannel, inString, length, messageEnd, blocking); - } - - return ChannelPut2(channel, inString, length, messageEnd, blocking); -} - -void ChannelSwitch::AddDefaultRoute(BufferedTransformation &destination) -{ - m_defaultRoutes.push_back(DefaultRoute(&destination, value_ptr(NULL))); -} - -void ChannelSwitch::RemoveDefaultRoute(BufferedTransformation &destination) -{ - for (DefaultRouteList::iterator it = m_defaultRoutes.begin(); it != m_defaultRoutes.end(); ++it) - if (it->first == &destination && !it->second.get()) - { - m_defaultRoutes.erase(it); - break; - } -} - -void ChannelSwitch::AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel) -{ - m_defaultRoutes.push_back(DefaultRoute(&destination, outChannel)); -} - -void ChannelSwitch::RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel) -{ - for (DefaultRouteList::iterator it = m_defaultRoutes.begin(); it != m_defaultRoutes.end(); ++it) - if (it->first == &destination && (it->second.get() && *it->second == outChannel)) - { - m_defaultRoutes.erase(it); - break; - } -} - -void ChannelSwitch::AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel) -{ - m_routeMap.insert(RouteMap::value_type(inChannel, Route(&destination, outChannel))); -} - -void ChannelSwitch::RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel) -{ - typedef ChannelSwitch::RouteMap::iterator MapIterator; - pair range = m_routeMap.equal_range(inChannel); - - for (MapIterator it = range.first; it != range.second; ++it) - if (it->second.first == &destination && it->second.second == outChannel) - { - m_routeMap.erase(it); - break; - } -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/channels.h b/lib/cryptopp/channels.h deleted file mode 100644 index 837415615..000000000 --- a/lib/cryptopp/channels.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef CRYPTOPP_CHANNELS_H -#define CRYPTOPP_CHANNELS_H - -#include "simple.h" -#include "smartptr.h" -#include -#include - -NAMESPACE_BEGIN(CryptoPP) - -#if 0 -//! Route input on default channel to different and/or multiple channels based on message sequence number -class MessageSwitch : public Sink -{ -public: - void AddDefaultRoute(BufferedTransformation &destination, const std::string &channel); - void AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel); - - void Put(byte inByte); - void Put(const byte *inString, unsigned int length); - - void Flush(bool completeFlush, int propagation=-1); - void MessageEnd(int propagation=-1); - void PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1); - void MessageSeriesEnd(int propagation=-1); - -private: - typedef std::pair Route; - struct RangeRoute - { - RangeRoute(unsigned int begin, unsigned int end, const Route &route) - : begin(begin), end(end), route(route) {} - bool operator<(const RangeRoute &rhs) const {return begin < rhs.begin;} - unsigned int begin, end; - Route route; - }; - - typedef std::list RouteList; - typedef std::list DefaultRouteList; - - RouteList m_routes; - DefaultRouteList m_defaultRoutes; - unsigned int m_nCurrentMessage; -}; -#endif - -class ChannelSwitchTypedefs -{ -public: - typedef std::pair Route; - typedef std::multimap RouteMap; - - typedef std::pair > DefaultRoute; - typedef std::list DefaultRouteList; - - // SunCC workaround: can't use const_iterator here - typedef RouteMap::iterator MapIterator; - typedef DefaultRouteList::iterator ListIterator; -}; - -class ChannelSwitch; - -class ChannelRouteIterator : public ChannelSwitchTypedefs -{ -public: - ChannelSwitch& m_cs; - std::string m_channel; - bool m_useDefault; - MapIterator m_itMapCurrent, m_itMapEnd; - ListIterator m_itListCurrent, m_itListEnd; - - ChannelRouteIterator(ChannelSwitch &cs) : m_cs(cs) {} - void Reset(const std::string &channel); - bool End() const; - void Next(); - BufferedTransformation & Destination(); - const std::string & Channel(); -}; - -//! Route input to different and/or multiple channels based on channel ID -class CRYPTOPP_DLL ChannelSwitch : public Multichannel, public ChannelSwitchTypedefs -{ -public: - ChannelSwitch() : m_it(*this), m_blocked(false) {} - ChannelSwitch(BufferedTransformation &destination) : m_it(*this), m_blocked(false) - { - AddDefaultRoute(destination); - } - ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel) : m_it(*this), m_blocked(false) - { - AddDefaultRoute(destination, outChannel); - } - - void IsolatedInitialize(const NameValuePairs ¶meters=g_nullNameValuePairs); - - size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking); - size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking); - - bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true); - bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true); - - byte * ChannelCreatePutSpace(const std::string &channel, size_t &size); - - void AddDefaultRoute(BufferedTransformation &destination); - void RemoveDefaultRoute(BufferedTransformation &destination); - void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel); - void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel); - void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel); - void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel); - -private: - RouteMap m_routeMap; - DefaultRouteList m_defaultRoutes; - - ChannelRouteIterator m_it; - bool m_blocked; - - friend class ChannelRouteIterator; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/cmac.cpp b/lib/cryptopp/cmac.cpp deleted file mode 100644 index a31d5f8b0..000000000 --- a/lib/cryptopp/cmac.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// cmac.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "cmac.h" - -NAMESPACE_BEGIN(CryptoPP) - -static void MulU(byte *k, unsigned int length) -{ - byte carry = 0; - - for (int i=length-1; i>=1; i-=2) - { - byte carry2 = k[i] >> 7; - k[i] += k[i] + carry; - carry = k[i-1] >> 7; - k[i-1] += k[i-1] + carry2; - } - - if (carry) - { - switch (length) - { - case 8: - k[7] ^= 0x1b; - break; - case 16: - k[15] ^= 0x87; - break; - case 32: - k[30] ^= 4; - k[31] ^= 0x23; - break; - default: - throw InvalidArgument("CMAC: " + IntToString(length) + " is not a supported cipher block size"); - } - } -} - -void CMAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) -{ - BlockCipher &cipher = AccessCipher(); - unsigned int blockSize = cipher.BlockSize(); - - cipher.SetKey(key, length, params); - m_reg.CleanNew(3*blockSize); - m_counter = 0; - - cipher.ProcessBlock(m_reg, m_reg+blockSize); - MulU(m_reg+blockSize, blockSize); - memcpy(m_reg+2*blockSize, m_reg+blockSize, blockSize); - MulU(m_reg+2*blockSize, blockSize); -} - -void CMAC_Base::Update(const byte *input, size_t length) -{ - if (!length) - return; - - BlockCipher &cipher = AccessCipher(); - unsigned int blockSize = cipher.BlockSize(); - - if (m_counter > 0) - { - unsigned int len = UnsignedMin(blockSize - m_counter, length); - xorbuf(m_reg+m_counter, input, len); - length -= len; - input += len; - m_counter += len; - - if (m_counter == blockSize && length > 0) - { - cipher.ProcessBlock(m_reg); - m_counter = 0; - } - } - - if (length > blockSize) - { - assert(m_counter == 0); - size_t leftOver = 1 + cipher.AdvancedProcessBlocks(m_reg, input, m_reg, length-1, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput); - input += (length - leftOver); - length = leftOver; - } - - if (length > 0) - { - assert(m_counter + length <= blockSize); - xorbuf(m_reg+m_counter, input, length); - m_counter += (unsigned int)length; - } - - assert(m_counter > 0); -} - -void CMAC_Base::TruncatedFinal(byte *mac, size_t size) -{ - ThrowIfInvalidTruncatedSize(size); - - BlockCipher &cipher = AccessCipher(); - unsigned int blockSize = cipher.BlockSize(); - - if (m_counter < blockSize) - { - m_reg[m_counter] ^= 0x80; - cipher.AdvancedProcessBlocks(m_reg, m_reg+2*blockSize, m_reg, blockSize, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput); - } - else - cipher.AdvancedProcessBlocks(m_reg, m_reg+blockSize, m_reg, blockSize, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput); - - memcpy(mac, m_reg, size); - - m_counter = 0; - memset(m_reg, 0, blockSize); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/cmac.h b/lib/cryptopp/cmac.h deleted file mode 100644 index d8a1b391d..000000000 --- a/lib/cryptopp/cmac.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef CRYPTOPP_CMAC_H -#define CRYPTOPP_CMAC_H - -#include "seckey.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode -{ -public: - CMAC_Base() {} - - void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); - void Update(const byte *input, size_t length); - void TruncatedFinal(byte *mac, size_t size); - unsigned int DigestSize() const {return GetCipher().BlockSize();} - unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();} - unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();} - -protected: - friend class EAX_Base; - - const BlockCipher & GetCipher() const {return const_cast(this)->AccessCipher();} - virtual BlockCipher & AccessCipher() =0; - - void ProcessBuf(); - SecByteBlock m_reg; - unsigned int m_counter; -}; - -/// CMAC -/*! Template parameter T should be a class derived from BlockCipherDocumentation, for example AES, with a block size of 8, 16, or 32 */ -template -class CMAC : public MessageAuthenticationCodeImpl >, public SameKeyLengthAs -{ -public: - CMAC() {} - CMAC(const byte *key, size_t length=SameKeyLengthAs::DEFAULT_KEYLENGTH) - {this->SetKey(key, length);} - - static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";} - -private: - BlockCipher & AccessCipher() {return m_cipher;} - typename T::Encryption m_cipher; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/config.h b/lib/cryptopp/config.h deleted file mode 100644 index edbfd00ef..000000000 --- a/lib/cryptopp/config.h +++ /dev/null @@ -1,462 +0,0 @@ -#ifndef CRYPTOPP_CONFIG_H -#define CRYPTOPP_CONFIG_H - -// ***************** Important Settings ******************** - -// define this if running on a big-endian CPU -#if !defined(IS_LITTLE_ENDIAN) && (defined(__BIG_ENDIAN__) || defined(__sparc) || defined(__sparc__) || defined(__hppa__) || defined(__MIPSEB__) || defined(__ARMEB__) || (defined(__MWERKS__) && !defined(__INTEL__))) -# define IS_BIG_ENDIAN -#endif - -// define this if running on a little-endian CPU -// big endian will be assumed if IS_LITTLE_ENDIAN is not defined -#ifndef IS_BIG_ENDIAN -# define IS_LITTLE_ENDIAN -#endif - -// define this if you want to disable all OS-dependent features, -// such as sockets and OS-provided random number generators -#define NO_OS_DEPENDENCE - -// Define this to use features provided by Microsoft's CryptoAPI. -// Currently the only feature used is random number generation. -// This macro will be ignored if NO_OS_DEPENDENCE is defined. -// #define USE_MS_CRYPTOAPI - -// Define this to 1 to enforce the requirement in FIPS 186-2 Change Notice 1 that only 1024 bit moduli be used -#ifndef DSA_1024_BIT_MODULUS_ONLY -# define DSA_1024_BIT_MODULUS_ONLY 1 -#endif - -// ***************** Less Important Settings *************** - -// define this to retain (as much as possible) old deprecated function and class names -// #define CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - -#define GZIP_OS_CODE 0 - -// Try this if your CPU has 256K internal cache or a slow multiply instruction -// and you want a (possibly) faster IDEA implementation using log tables -// #define IDEA_LARGECACHE - -// Define this if, for the linear congruential RNG, you want to use -// the original constants as specified in S.K. Park and K.W. Miller's -// CACM paper. -// #define LCRNG_ORIGINAL_NUMBERS - -// choose which style of sockets to wrap (mostly useful for cygwin which has both) -#define PREFER_BERKELEY_STYLE_SOCKETS -// #define PREFER_WINDOWS_STYLE_SOCKETS - -// set the name of Rijndael cipher, was "Rijndael" before version 5.3 -#define CRYPTOPP_RIJNDAEL_NAME "AES" - -// ***************** Important Settings Again ******************** -// But the defaults should be ok. - -// namespace support is now required -#ifdef NO_NAMESPACE -# error namespace support is now required -#endif - -// Define this to workaround a Microsoft CryptoAPI bug where -// each call to CryptAcquireContext causes a 100 KB memory leak. -// Defining this will cause Crypto++ to make only one call to CryptAcquireContext. -#define WORKAROUND_MS_BUG_Q258000 - -#ifdef CRYPTOPP_DOXYGEN_PROCESSING -// Avoid putting "CryptoPP::" in front of everything in Doxygen output -# define CryptoPP -# define NAMESPACE_BEGIN(x) -# define NAMESPACE_END -// Get Doxygen to generate better documentation for these typedefs -# define DOCUMENTED_TYPEDEF(x, y) class y : public x {}; -#else -# define NAMESPACE_BEGIN(x) namespace x { -# define NAMESPACE_END } -# define DOCUMENTED_TYPEDEF(x, y) typedef x y; -#endif -#define ANONYMOUS_NAMESPACE_BEGIN namespace { -#define USING_NAMESPACE(x) using namespace x; -#define DOCUMENTED_NAMESPACE_BEGIN(x) namespace x { -#define DOCUMENTED_NAMESPACE_END } - -// What is the type of the third parameter to bind? -// For Unix, the new standard is ::socklen_t (typically unsigned int), and the old standard is int. -// Unfortunately there is no way to tell whether or not socklen_t is defined. -// To work around this, TYPE_OF_SOCKLEN_T is a macro so that you can change it from the makefile. -#ifndef TYPE_OF_SOCKLEN_T -# if defined(_WIN32) || defined(__CYGWIN__) -# define TYPE_OF_SOCKLEN_T int -# else -# define TYPE_OF_SOCKLEN_T ::socklen_t -# endif -#endif - -#if defined(__CYGWIN__) && defined(PREFER_WINDOWS_STYLE_SOCKETS) -# define __USE_W32_SOCKETS -#endif - -typedef unsigned char byte; // put in global namespace to avoid ambiguity with other byte typedefs - -NAMESPACE_BEGIN(CryptoPP) - -typedef unsigned short word16; -typedef unsigned int word32; - -#if defined(_MSC_VER) || defined(__BORLANDC__) - typedef unsigned __int64 word64; - #define W64LIT(x) x##ui64 -#else - typedef unsigned long long word64; - #define W64LIT(x) x##ULL -#endif - -// define large word type, used for file offsets and such -typedef word64 lword; -const lword LWORD_MAX = W64LIT(0xffffffffffffffff); - -#ifdef __GNUC__ - #define CRYPTOPP_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -#endif - -// define hword, word, and dword. these are used for multiprecision integer arithmetic -// Intel compiler won't have _umul128 until version 10.0. See http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx -#if (defined(_MSC_VER) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1000) && (defined(_M_X64) || defined(_M_IA64))) || (defined(__DECCXX) && defined(__alpha__)) || (defined(__INTEL_COMPILER) && defined(__x86_64__)) || (defined(__SUNPRO_CC) && defined(__x86_64__)) - typedef word32 hword; - typedef word64 word; -#else - #define CRYPTOPP_NATIVE_DWORD_AVAILABLE - #if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || defined(__x86_64__) || defined(__mips64) || defined(__sparc64__) - #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !(CRYPTOPP_GCC_VERSION == 40001 && defined(__APPLE__)) && CRYPTOPP_GCC_VERSION >= 30400 - // GCC 4.0.1 on MacOS X is missing __umodti3 and __udivti3 - // mode(TI) division broken on amd64 with GCC earlier than GCC 3.4 - typedef word32 hword; - typedef word64 word; - typedef __uint128_t dword; - typedef __uint128_t word128; - #define CRYPTOPP_WORD128_AVAILABLE - #else - // if we're here, it means we're on a 64-bit CPU but we don't have a way to obtain 128-bit multiplication results - typedef word16 hword; - typedef word32 word; - typedef word64 dword; - #endif - #else - // being here means the native register size is probably 32 bits or less - #define CRYPTOPP_BOOL_SLOW_WORD64 1 - typedef word16 hword; - typedef word32 word; - typedef word64 dword; - #endif -#endif -#ifndef CRYPTOPP_BOOL_SLOW_WORD64 - #define CRYPTOPP_BOOL_SLOW_WORD64 0 -#endif - -const unsigned int WORD_SIZE = sizeof(word); -const unsigned int WORD_BITS = WORD_SIZE * 8; - -NAMESPACE_END - -#ifndef CRYPTOPP_L1_CACHE_LINE_SIZE - // This should be a lower bound on the L1 cache line size. It's used for defense against timing attacks. - #if defined(_M_X64) || defined(__x86_64__) - #define CRYPTOPP_L1_CACHE_LINE_SIZE 64 - #else - // L1 cache line size is 32 on Pentium III and earlier - #define CRYPTOPP_L1_CACHE_LINE_SIZE 32 - #endif -#endif - -#if defined(_MSC_VER) - #if _MSC_VER == 1200 - #include - #endif - #if _MSC_VER > 1200 || defined(_mm_free) - #define CRYPTOPP_MSVC6PP_OR_LATER // VC 6 processor pack or later - #else - #define CRYPTOPP_MSVC6_NO_PP // VC 6 without processor pack - #endif -#endif - -#ifndef CRYPTOPP_ALIGN_DATA - #if defined(CRYPTOPP_MSVC6PP_OR_LATER) - #define CRYPTOPP_ALIGN_DATA(x) __declspec(align(x)) - #elif defined(__GNUC__) - #define CRYPTOPP_ALIGN_DATA(x) __attribute__((aligned(x))) - #else - #define CRYPTOPP_ALIGN_DATA(x) - #endif -#endif - -#ifndef CRYPTOPP_SECTION_ALIGN16 - #if defined(__GNUC__) && !defined(__APPLE__) - // the alignment attribute doesn't seem to work without this section attribute when -fdata-sections is turned on - #define CRYPTOPP_SECTION_ALIGN16 __attribute__((section ("CryptoPP_Align16"))) - #else - #define CRYPTOPP_SECTION_ALIGN16 - #endif -#endif - -#if defined(_MSC_VER) || defined(__fastcall) - #define CRYPTOPP_FASTCALL __fastcall -#else - #define CRYPTOPP_FASTCALL -#endif - -// VC60 workaround: it doesn't allow typename in some places -#if defined(_MSC_VER) && (_MSC_VER < 1300) -#define CPP_TYPENAME -#else -#define CPP_TYPENAME typename -#endif - -// VC60 workaround: can't cast unsigned __int64 to float or double -#if defined(_MSC_VER) && !defined(CRYPTOPP_MSVC6PP_OR_LATER) -#define CRYPTOPP_VC6_INT64 (__int64) -#else -#define CRYPTOPP_VC6_INT64 -#endif - -#ifdef _MSC_VER -#define CRYPTOPP_NO_VTABLE __declspec(novtable) -#else -#define CRYPTOPP_NO_VTABLE -#endif - -#ifdef _MSC_VER - // 4231: nonstandard extension used : 'extern' before template explicit instantiation - // 4250: dominance - // 4251: member needs to have dll-interface - // 4275: base needs to have dll-interface - // 4660: explicitly instantiating a class that's already implicitly instantiated - // 4661: no suitable definition provided for explicit template instantiation request - // 4786: identifer was truncated in debug information - // 4355: 'this' : used in base member initializer list - // 4910: '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation -# pragma warning(disable: 4231 4250 4251 4275 4660 4661 4786 4355 4910) -#endif - -#ifdef __BORLANDC__ -// 8037: non-const function called for const object. needed to work around BCB2006 bug -# pragma warn -8037 -#endif - -#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__MWERKS__) || defined(_STLPORT_VERSION) || defined(ANDROID_NDK) -#define CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION -#endif - -#ifndef CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION -#define CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE -#endif - -#ifdef CRYPTOPP_DISABLE_X86ASM // for backwards compatibility: this macro had both meanings -#define CRYPTOPP_DISABLE_ASM -#define CRYPTOPP_DISABLE_SSE2 -#endif - -#if !defined(CRYPTOPP_DISABLE_ASM) && ((defined(_MSC_VER) && defined(_M_IX86)) || (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)))) - // C++Builder 2010 does not allow "call label" where label is defined within inline assembly - #define CRYPTOPP_X86_ASM_AVAILABLE - - #if !defined(CRYPTOPP_DISABLE_SSE2) && (defined(CRYPTOPP_MSVC6PP_OR_LATER) || CRYPTOPP_GCC_VERSION >= 30300) - #define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 1 - #else - #define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 0 - #endif - - // SSSE3 was actually introduced in GNU as 2.17, which was released 6/23/2006, but we can't tell what version of binutils is installed. - // GCC 4.1.2 was released on 2/13/2007, so we'll use that as a proxy for the binutils version. - #if !defined(CRYPTOPP_DISABLE_SSSE3) && (_MSC_VER >= 1400 || CRYPTOPP_GCC_VERSION >= 40102) - #define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 1 - #else - #define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 0 - #endif -#endif - -#if !defined(CRYPTOPP_DISABLE_ASM) && defined(_MSC_VER) && defined(_M_X64) - #define CRYPTOPP_X64_MASM_AVAILABLE -#endif - -#if !defined(CRYPTOPP_DISABLE_ASM) && defined(__GNUC__) && defined(__x86_64__) - #define CRYPTOPP_X64_ASM_AVAILABLE -#endif - -#if !defined(CRYPTOPP_DISABLE_SSE2) && (defined(CRYPTOPP_MSVC6PP_OR_LATER) || defined(__SSE2__)) - #define CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE 1 -#else - #define CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE 0 -#endif - -#if !defined(CRYPTOPP_DISABLE_SSSE3) && !defined(CRYPTOPP_DISABLE_AESNI) && CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE && (CRYPTOPP_GCC_VERSION >= 40400 || _MSC_FULL_VER >= 150030729 || __INTEL_COMPILER >= 1110) - #define CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 1 -#else - #define CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 0 -#endif - -#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE || CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) - #define CRYPTOPP_BOOL_ALIGN16_ENABLED 1 -#else - #define CRYPTOPP_BOOL_ALIGN16_ENABLED 0 -#endif - -// how to allocate 16-byte aligned memory (for SSE2) -#if defined(CRYPTOPP_MSVC6PP_OR_LATER) - #define CRYPTOPP_MM_MALLOC_AVAILABLE -#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) - #define CRYPTOPP_MALLOC_ALIGNMENT_IS_16 -#elif defined(__linux__) || defined(__sun__) || defined(__CYGWIN__) - #define CRYPTOPP_MEMALIGN_AVAILABLE -#else - #define CRYPTOPP_NO_ALIGNED_ALLOC -#endif - -// how to disable inlining -#if defined(_MSC_VER) && _MSC_VER >= 1300 -# define CRYPTOPP_NOINLINE_DOTDOTDOT -# define CRYPTOPP_NOINLINE __declspec(noinline) -#elif defined(__GNUC__) -# define CRYPTOPP_NOINLINE_DOTDOTDOT -# define CRYPTOPP_NOINLINE __attribute__((noinline)) -#else -# define CRYPTOPP_NOINLINE_DOTDOTDOT ... -# define CRYPTOPP_NOINLINE -#endif - -// how to declare class constants -#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) -# define CRYPTOPP_CONSTANT(x) enum {x}; -#else -# define CRYPTOPP_CONSTANT(x) static const int x; -#endif - -#if defined(_M_X64) || defined(__x86_64__) - #define CRYPTOPP_BOOL_X64 1 -#else - #define CRYPTOPP_BOOL_X64 0 -#endif - -// see http://predef.sourceforge.net/prearch.html -#if defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) - #define CRYPTOPP_BOOL_X86 1 -#else - #define CRYPTOPP_BOOL_X86 0 -#endif - -#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86 || defined(__powerpc__) - #define CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS -#endif - -#define CRYPTOPP_VERSION 562 - -// ***************** determine availability of OS features ******************** - -#ifndef NO_OS_DEPENDENCE - -#if defined(_WIN32) || defined(__CYGWIN__) -#define CRYPTOPP_WIN32_AVAILABLE -#endif - -#if defined(__unix__) || defined(__MACH__) || defined(__NetBSD__) || defined(__sun) -#define CRYPTOPP_UNIX_AVAILABLE -#endif - -#if defined(CRYPTOPP_WIN32_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE) -# define HIGHRES_TIMER_AVAILABLE -#endif - -#ifdef CRYPTOPP_UNIX_AVAILABLE -# define HAS_BERKELEY_STYLE_SOCKETS -#endif - -#ifdef CRYPTOPP_WIN32_AVAILABLE -# define HAS_WINDOWS_STYLE_SOCKETS -#endif - -#if defined(HIGHRES_TIMER_AVAILABLE) && (defined(HAS_BERKELEY_STYLE_SOCKETS) || defined(HAS_WINDOWS_STYLE_SOCKETS)) -# define SOCKETS_AVAILABLE -#endif - -#if defined(HAS_WINDOWS_STYLE_SOCKETS) && (!defined(HAS_BERKELEY_STYLE_SOCKETS) || defined(PREFER_WINDOWS_STYLE_SOCKETS)) -# define USE_WINDOWS_STYLE_SOCKETS -#else -# define USE_BERKELEY_STYLE_SOCKETS -#endif - -#if defined(HIGHRES_TIMER_AVAILABLE) && defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(USE_BERKELEY_STYLE_SOCKETS) -# define WINDOWS_PIPES_AVAILABLE -#endif - -#if defined(CRYPTOPP_WIN32_AVAILABLE) && defined(USE_MS_CRYPTOAPI) -# define NONBLOCKING_RNG_AVAILABLE -# define OS_RNG_AVAILABLE -#endif - -#if defined(CRYPTOPP_UNIX_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING) -# define NONBLOCKING_RNG_AVAILABLE -# define BLOCKING_RNG_AVAILABLE -# define OS_RNG_AVAILABLE -# define HAS_PTHREADS -# define THREADS_AVAILABLE -#endif - -#ifdef CRYPTOPP_WIN32_AVAILABLE -# define HAS_WINTHREADS -# define THREADS_AVAILABLE -#endif - -#endif // NO_OS_DEPENDENCE - -// ***************** DLL related ******************** - -#if defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) - -#ifdef CRYPTOPP_EXPORTS -#define CRYPTOPP_IS_DLL -#define CRYPTOPP_DLL __declspec(dllexport) -#elif defined(CRYPTOPP_IMPORTS) -#define CRYPTOPP_IS_DLL -#define CRYPTOPP_DLL __declspec(dllimport) -#else -#define CRYPTOPP_DLL -#endif - -#define CRYPTOPP_API __cdecl - -#else // CRYPTOPP_WIN32_AVAILABLE - -#define CRYPTOPP_DLL -#define CRYPTOPP_API - -#endif // CRYPTOPP_WIN32_AVAILABLE - -#if defined(__MWERKS__) -#define CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS extern class CRYPTOPP_DLL -#elif defined(__BORLANDC__) || defined(__SUNPRO_CC) -#define CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS template class CRYPTOPP_DLL -#else -#define CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS extern template class CRYPTOPP_DLL -#endif - -#if defined(CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES) && !defined(CRYPTOPP_IMPORTS) -#define CRYPTOPP_DLL_TEMPLATE_CLASS template class CRYPTOPP_DLL -#else -#define CRYPTOPP_DLL_TEMPLATE_CLASS CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS -#endif - -#if defined(__MWERKS__) -#define CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS extern class -#elif defined(__BORLANDC__) || defined(__SUNPRO_CC) -#define CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS template class -#else -#define CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS extern template class -#endif - -#if defined(CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES) && !defined(CRYPTOPP_EXPORTS) -#define CRYPTOPP_STATIC_TEMPLATE_CLASS template class -#else -#define CRYPTOPP_STATIC_TEMPLATE_CLASS CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS -#endif - -#endif diff --git a/lib/cryptopp/cpu.cpp b/lib/cryptopp/cpu.cpp deleted file mode 100644 index 3610a7c8e..000000000 --- a/lib/cryptopp/cpu.cpp +++ /dev/null @@ -1,199 +0,0 @@ -// cpu.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "cpu.h" -#include "misc.h" -#include - -#ifndef CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY -#include -#include -#endif - -#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE -#include -#endif - -NAMESPACE_BEGIN(CryptoPP) - -#ifdef CRYPTOPP_CPUID_AVAILABLE - -#if _MSC_VER >= 1400 && CRYPTOPP_BOOL_X64 - -bool CpuId(word32 input, word32 *output) -{ - __cpuid((int *)output, input); - return true; -} - -#else - -#ifndef CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY -extern "C" { -typedef void (*SigHandler)(int); - -static jmp_buf s_jmpNoCPUID; -static void SigIllHandlerCPUID(int) -{ - longjmp(s_jmpNoCPUID, 1); -} - -static jmp_buf s_jmpNoSSE2; -static void SigIllHandlerSSE2(int) -{ - longjmp(s_jmpNoSSE2, 1); -} -} -#endif - -bool CpuId(word32 input, word32 *output) -{ -#ifdef CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY - __try - { - __asm - { - mov eax, input - cpuid - mov edi, output - mov [edi], eax - mov [edi+4], ebx - mov [edi+8], ecx - mov [edi+12], edx - } - } - __except (1) - { - return false; - } - return true; -#else - SigHandler oldHandler = signal(SIGILL, SigIllHandlerCPUID); - if (oldHandler == SIG_ERR) - return false; - - bool result = true; - if (setjmp(s_jmpNoCPUID)) - result = false; - else - { - asm - ( - // save ebx in case -fPIC is being used -#if CRYPTOPP_BOOL_X86 - "push %%ebx; cpuid; mov %%ebx, %%edi; pop %%ebx" -#else - "pushq %%rbx; cpuid; mov %%ebx, %%edi; popq %%rbx" -#endif - : "=a" (output[0]), "=D" (output[1]), "=c" (output[2]), "=d" (output[3]) - : "a" (input) - ); - } - - signal(SIGILL, oldHandler); - return result; -#endif -} - -#endif - -static bool TrySSE2() -{ -#if CRYPTOPP_BOOL_X64 - return true; -#elif defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY) - __try - { -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE - AS2(por xmm0, xmm0) // executing SSE2 instruction -#elif CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE - __m128i x = _mm_setzero_si128(); - return _mm_cvtsi128_si32(x) == 0; -#endif - } - __except (1) - { - return false; - } - return true; -#else - SigHandler oldHandler = signal(SIGILL, SigIllHandlerSSE2); - if (oldHandler == SIG_ERR) - return false; - - bool result = true; - if (setjmp(s_jmpNoSSE2)) - result = false; - else - { -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE - __asm __volatile ("por %xmm0, %xmm0"); -#elif CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE - __m128i x = _mm_setzero_si128(); - result = _mm_cvtsi128_si32(x) == 0; -#endif - } - - signal(SIGILL, oldHandler); - return result; -#endif -} - -bool g_x86DetectionDone = false; -bool g_hasISSE = false, g_hasSSE2 = false, g_hasSSSE3 = false, g_hasMMX = false, g_hasAESNI = false, g_hasCLMUL = false, g_isP4 = false; -word32 g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE; - -void DetectX86Features() -{ - word32 cpuid[4], cpuid1[4]; - if (!CpuId(0, cpuid)) - return; - if (!CpuId(1, cpuid1)) - return; - - g_hasMMX = (cpuid1[3] & (1 << 23)) != 0; - if ((cpuid1[3] & (1 << 26)) != 0) - g_hasSSE2 = TrySSE2(); - g_hasSSSE3 = g_hasSSE2 && (cpuid1[2] & (1<<9)); - g_hasAESNI = g_hasSSE2 && (cpuid1[2] & (1<<25)); - g_hasCLMUL = g_hasSSE2 && (cpuid1[2] & (1<<1)); - - if ((cpuid1[3] & (1 << 25)) != 0) - g_hasISSE = true; - else - { - word32 cpuid2[4]; - CpuId(0x080000000, cpuid2); - if (cpuid2[0] >= 0x080000001) - { - CpuId(0x080000001, cpuid2); - g_hasISSE = (cpuid2[3] & (1 << 22)) != 0; - } - } - - std::swap(cpuid[2], cpuid[3]); - if (memcmp(cpuid+1, "GenuineIntel", 12) == 0) - { - g_isP4 = ((cpuid1[0] >> 8) & 0xf) == 0xf; - g_cacheLineSize = 8 * GETBYTE(cpuid1[1], 1); - } - else if (memcmp(cpuid+1, "AuthenticAMD", 12) == 0) - { - CpuId(0x80000005, cpuid); - g_cacheLineSize = GETBYTE(cpuid[2], 0); - } - - if (!g_cacheLineSize) - g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE; - - g_x86DetectionDone = true; -} - -#endif - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/cpu.h b/lib/cryptopp/cpu.h deleted file mode 100644 index 65029d338..000000000 --- a/lib/cryptopp/cpu.h +++ /dev/null @@ -1,345 +0,0 @@ -#ifndef CRYPTOPP_CPU_H -#define CRYPTOPP_CPU_H - -#ifdef CRYPTOPP_GENERATE_X64_MASM - -#define CRYPTOPP_X86_ASM_AVAILABLE -#define CRYPTOPP_BOOL_X64 1 -#define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 1 -#define NAMESPACE_END - -#else - -#include "config.h" - -#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE -#include -#endif - -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE -#if !defined(__GNUC__) || defined(__SSSE3__) || defined(__INTEL_COMPILER) -#include -#else -__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) -_mm_shuffle_epi8 (__m128i a, __m128i b) -{ - asm ("pshufb %1, %0" : "+x"(a) : "xm"(b)); - return a; -} -#endif -#if !defined(__GNUC__) || defined(__SSE4_1__) || defined(__INTEL_COMPILER) -#include -#else -__inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) -_mm_extract_epi32 (__m128i a, const int i) -{ - int r; - asm ("pextrd %2, %1, %0" : "=rm"(r) : "x"(a), "i"(i)); - return r; -} -__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) -_mm_insert_epi32 (__m128i a, int b, const int i) -{ - asm ("pinsrd %2, %1, %0" : "+x"(a) : "rm"(b), "i"(i)); - return a; -} -#endif -#if !defined(__GNUC__) || (defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER) -#include -#else -__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) -_mm_clmulepi64_si128 (__m128i a, __m128i b, const int i) -{ - asm ("pclmulqdq %2, %1, %0" : "+x"(a) : "xm"(b), "i"(i)); - return a; -} -__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) -_mm_aeskeygenassist_si128 (__m128i a, const int i) -{ - __m128i r; - asm ("aeskeygenassist %2, %1, %0" : "=x"(r) : "xm"(a), "i"(i)); - return r; -} -__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) -_mm_aesimc_si128 (__m128i a) -{ - __m128i r; - asm ("aesimc %1, %0" : "=x"(r) : "xm"(a)); - return r; -} -__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) -_mm_aesenc_si128 (__m128i a, __m128i b) -{ - asm ("aesenc %1, %0" : "+x"(a) : "xm"(b)); - return a; -} -__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) -_mm_aesenclast_si128 (__m128i a, __m128i b) -{ - asm ("aesenclast %1, %0" : "+x"(a) : "xm"(b)); - return a; -} -__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) -_mm_aesdec_si128 (__m128i a, __m128i b) -{ - asm ("aesdec %1, %0" : "+x"(a) : "xm"(b)); - return a; -} -__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) -_mm_aesdeclast_si128 (__m128i a, __m128i b) -{ - asm ("aesdeclast %1, %0" : "+x"(a) : "xm"(b)); - return a; -} -#endif -#endif - -NAMESPACE_BEGIN(CryptoPP) - -#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X64 - -#define CRYPTOPP_CPUID_AVAILABLE - -// these should not be used directly -extern CRYPTOPP_DLL bool g_x86DetectionDone; -extern CRYPTOPP_DLL bool g_hasSSSE3; -extern CRYPTOPP_DLL bool g_hasAESNI; -extern CRYPTOPP_DLL bool g_hasCLMUL; -extern CRYPTOPP_DLL bool g_isP4; -extern CRYPTOPP_DLL word32 g_cacheLineSize; -CRYPTOPP_DLL void CRYPTOPP_API DetectX86Features(); -CRYPTOPP_DLL bool CRYPTOPP_API CpuId(word32 input, word32 *output); - -#if CRYPTOPP_BOOL_X64 -inline bool HasSSE2() {return true;} -inline bool HasISSE() {return true;} -inline bool HasMMX() {return true;} -#else - -extern CRYPTOPP_DLL bool g_hasSSE2; -extern CRYPTOPP_DLL bool g_hasISSE; -extern CRYPTOPP_DLL bool g_hasMMX; - -inline bool HasSSE2() -{ - if (!g_x86DetectionDone) - DetectX86Features(); - return g_hasSSE2; -} - -inline bool HasISSE() -{ - if (!g_x86DetectionDone) - DetectX86Features(); - return g_hasISSE; -} - -inline bool HasMMX() -{ - if (!g_x86DetectionDone) - DetectX86Features(); - return g_hasMMX; -} - -#endif - -inline bool HasSSSE3() -{ - if (!g_x86DetectionDone) - DetectX86Features(); - return g_hasSSSE3; -} - -inline bool HasAESNI() -{ - if (!g_x86DetectionDone) - DetectX86Features(); - return g_hasAESNI; -} - -inline bool HasCLMUL() -{ - if (!g_x86DetectionDone) - DetectX86Features(); - return g_hasCLMUL; -} - -inline bool IsP4() -{ - if (!g_x86DetectionDone) - DetectX86Features(); - return g_isP4; -} - -inline int GetCacheLineSize() -{ - if (!g_x86DetectionDone) - DetectX86Features(); - return g_cacheLineSize; -} - -#else - -inline int GetCacheLineSize() -{ - return CRYPTOPP_L1_CACHE_LINE_SIZE; -} - -#endif - -#endif - -#ifdef CRYPTOPP_GENERATE_X64_MASM - #define AS1(x) x*newline* - #define AS2(x, y) x, y*newline* - #define AS3(x, y, z) x, y, z*newline* - #define ASS(x, y, a, b, c, d) x, y, a*64+b*16+c*4+d*newline* - #define ASL(x) label##x:*newline* - #define ASJ(x, y, z) x label##y*newline* - #define ASC(x, y) x label##y*newline* - #define AS_HEX(y) 0##y##h -#elif defined(_MSC_VER) || defined(__BORLANDC__) - #define CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY - #define AS1(x) __asm {x} - #define AS2(x, y) __asm {x, y} - #define AS3(x, y, z) __asm {x, y, z} - #define ASS(x, y, a, b, c, d) __asm {x, y, (a)*64+(b)*16+(c)*4+(d)} - #define ASL(x) __asm {label##x:} - #define ASJ(x, y, z) __asm {x label##y} - #define ASC(x, y) __asm {x label##y} - #define CRYPTOPP_NAKED __declspec(naked) - #define AS_HEX(y) 0x##y -#else - #define CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY - // define these in two steps to allow arguments to be expanded - #define GNU_AS1(x) #x ";" - #define GNU_AS2(x, y) #x ", " #y ";" - #define GNU_AS3(x, y, z) #x ", " #y ", " #z ";" - #define GNU_ASL(x) "\n" #x ":" - #define GNU_ASJ(x, y, z) #x " " #y #z ";" - #define AS1(x) GNU_AS1(x) - #define AS2(x, y) GNU_AS2(x, y) - #define AS3(x, y, z) GNU_AS3(x, y, z) - #define ASS(x, y, a, b, c, d) #x ", " #y ", " #a "*64+" #b "*16+" #c "*4+" #d ";" - #define ASL(x) GNU_ASL(x) - #define ASJ(x, y, z) GNU_ASJ(x, y, z) - #define ASC(x, y) #x " " #y ";" - #define CRYPTOPP_NAKED - #define AS_HEX(y) 0x##y -#endif - -#define IF0(y) -#define IF1(y) y - -#ifdef CRYPTOPP_GENERATE_X64_MASM -#define ASM_MOD(x, y) ((x) MOD (y)) -#define XMMWORD_PTR XMMWORD PTR -#else -// GNU assembler doesn't seem to have mod operator -#define ASM_MOD(x, y) ((x)-((x)/(y))*(y)) -// GAS 2.15 doesn't support XMMWORD PTR. it seems necessary only for MASM -#define XMMWORD_PTR -#endif - -#if CRYPTOPP_BOOL_X86 - #define AS_REG_1 ecx - #define AS_REG_2 edx - #define AS_REG_3 esi - #define AS_REG_4 edi - #define AS_REG_5 eax - #define AS_REG_6 ebx - #define AS_REG_7 ebp - #define AS_REG_1d ecx - #define AS_REG_2d edx - #define AS_REG_3d esi - #define AS_REG_4d edi - #define AS_REG_5d eax - #define AS_REG_6d ebx - #define AS_REG_7d ebp - #define WORD_SZ 4 - #define WORD_REG(x) e##x - #define WORD_PTR DWORD PTR - #define AS_PUSH_IF86(x) AS1(push e##x) - #define AS_POP_IF86(x) AS1(pop e##x) - #define AS_JCXZ jecxz -#elif CRYPTOPP_BOOL_X64 - #ifdef CRYPTOPP_GENERATE_X64_MASM - #define AS_REG_1 rcx - #define AS_REG_2 rdx - #define AS_REG_3 r8 - #define AS_REG_4 r9 - #define AS_REG_5 rax - #define AS_REG_6 r10 - #define AS_REG_7 r11 - #define AS_REG_1d ecx - #define AS_REG_2d edx - #define AS_REG_3d r8d - #define AS_REG_4d r9d - #define AS_REG_5d eax - #define AS_REG_6d r10d - #define AS_REG_7d r11d - #else - #define AS_REG_1 rdi - #define AS_REG_2 rsi - #define AS_REG_3 rdx - #define AS_REG_4 rcx - #define AS_REG_5 r8 - #define AS_REG_6 r9 - #define AS_REG_7 r10 - #define AS_REG_1d edi - #define AS_REG_2d esi - #define AS_REG_3d edx - #define AS_REG_4d ecx - #define AS_REG_5d r8d - #define AS_REG_6d r9d - #define AS_REG_7d r10d - #endif - #define WORD_SZ 8 - #define WORD_REG(x) r##x - #define WORD_PTR QWORD PTR - #define AS_PUSH_IF86(x) - #define AS_POP_IF86(x) - #define AS_JCXZ jrcxz -#endif - -// helper macro for stream cipher output -#define AS_XMM_OUTPUT4(labelPrefix, inputPtr, outputPtr, x0, x1, x2, x3, t, p0, p1, p2, p3, increment)\ - AS2( test inputPtr, inputPtr)\ - ASC( jz, labelPrefix##3)\ - AS2( test inputPtr, 15)\ - ASC( jnz, labelPrefix##7)\ - AS2( pxor xmm##x0, [inputPtr+p0*16])\ - AS2( pxor xmm##x1, [inputPtr+p1*16])\ - AS2( pxor xmm##x2, [inputPtr+p2*16])\ - AS2( pxor xmm##x3, [inputPtr+p3*16])\ - AS2( add inputPtr, increment*16)\ - ASC( jmp, labelPrefix##3)\ - ASL(labelPrefix##7)\ - AS2( movdqu xmm##t, [inputPtr+p0*16])\ - AS2( pxor xmm##x0, xmm##t)\ - AS2( movdqu xmm##t, [inputPtr+p1*16])\ - AS2( pxor xmm##x1, xmm##t)\ - AS2( movdqu xmm##t, [inputPtr+p2*16])\ - AS2( pxor xmm##x2, xmm##t)\ - AS2( movdqu xmm##t, [inputPtr+p3*16])\ - AS2( pxor xmm##x3, xmm##t)\ - AS2( add inputPtr, increment*16)\ - ASL(labelPrefix##3)\ - AS2( test outputPtr, 15)\ - ASC( jnz, labelPrefix##8)\ - AS2( movdqa [outputPtr+p0*16], xmm##x0)\ - AS2( movdqa [outputPtr+p1*16], xmm##x1)\ - AS2( movdqa [outputPtr+p2*16], xmm##x2)\ - AS2( movdqa [outputPtr+p3*16], xmm##x3)\ - ASC( jmp, labelPrefix##9)\ - ASL(labelPrefix##8)\ - AS2( movdqu [outputPtr+p0*16], xmm##x0)\ - AS2( movdqu [outputPtr+p1*16], xmm##x1)\ - AS2( movdqu [outputPtr+p2*16], xmm##x2)\ - AS2( movdqu [outputPtr+p3*16], xmm##x3)\ - ASL(labelPrefix##9)\ - AS2( add outputPtr, increment*16) - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/crc.cpp b/lib/cryptopp/crc.cpp deleted file mode 100644 index 10c25c257..000000000 --- a/lib/cryptopp/crc.cpp +++ /dev/null @@ -1,160 +0,0 @@ -// crc.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "crc.h" -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) - -/* Table of CRC-32's of all single byte values (made by makecrc.c) */ -const word32 CRC32::m_tab[] = { -#ifdef IS_LITTLE_ENDIAN - 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, - 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, - 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, - 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, - 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, - 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, - 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, - 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, - 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, - 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, - 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, - 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, - 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, - 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, - 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, - 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, - 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, - 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, - 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, - 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, - 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, - 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, - 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, - 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, - 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, - 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, - 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, - 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, - 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, - 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, - 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, - 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, - 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, - 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, - 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, - 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, - 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, - 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, - 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, - 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, - 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, - 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, - 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, - 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, - 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, - 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, - 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, - 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, - 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, - 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, - 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, - 0x2d02ef8dL -#else - 0x00000000L, 0x96300777L, 0x2c610eeeL, 0xba510999L, 0x19c46d07L, - 0x8ff46a70L, 0x35a563e9L, 0xa395649eL, 0x3288db0eL, 0xa4b8dc79L, - 0x1ee9d5e0L, 0x88d9d297L, 0x2b4cb609L, 0xbd7cb17eL, 0x072db8e7L, - 0x911dbf90L, 0x6410b71dL, 0xf220b06aL, 0x4871b9f3L, 0xde41be84L, - 0x7dd4da1aL, 0xebe4dd6dL, 0x51b5d4f4L, 0xc785d383L, 0x56986c13L, - 0xc0a86b64L, 0x7af962fdL, 0xecc9658aL, 0x4f5c0114L, 0xd96c0663L, - 0x633d0ffaL, 0xf50d088dL, 0xc8206e3bL, 0x5e10694cL, 0xe44160d5L, - 0x727167a2L, 0xd1e4033cL, 0x47d4044bL, 0xfd850dd2L, 0x6bb50aa5L, - 0xfaa8b535L, 0x6c98b242L, 0xd6c9bbdbL, 0x40f9bcacL, 0xe36cd832L, - 0x755cdf45L, 0xcf0dd6dcL, 0x593dd1abL, 0xac30d926L, 0x3a00de51L, - 0x8051d7c8L, 0x1661d0bfL, 0xb5f4b421L, 0x23c4b356L, 0x9995bacfL, - 0x0fa5bdb8L, 0x9eb80228L, 0x0888055fL, 0xb2d90cc6L, 0x24e90bb1L, - 0x877c6f2fL, 0x114c6858L, 0xab1d61c1L, 0x3d2d66b6L, 0x9041dc76L, - 0x0671db01L, 0xbc20d298L, 0x2a10d5efL, 0x8985b171L, 0x1fb5b606L, - 0xa5e4bf9fL, 0x33d4b8e8L, 0xa2c90778L, 0x34f9000fL, 0x8ea80996L, - 0x18980ee1L, 0xbb0d6a7fL, 0x2d3d6d08L, 0x976c6491L, 0x015c63e6L, - 0xf4516b6bL, 0x62616c1cL, 0xd8306585L, 0x4e0062f2L, 0xed95066cL, - 0x7ba5011bL, 0xc1f40882L, 0x57c40ff5L, 0xc6d9b065L, 0x50e9b712L, - 0xeab8be8bL, 0x7c88b9fcL, 0xdf1ddd62L, 0x492dda15L, 0xf37cd38cL, - 0x654cd4fbL, 0x5861b24dL, 0xce51b53aL, 0x7400bca3L, 0xe230bbd4L, - 0x41a5df4aL, 0xd795d83dL, 0x6dc4d1a4L, 0xfbf4d6d3L, 0x6ae96943L, - 0xfcd96e34L, 0x468867adL, 0xd0b860daL, 0x732d0444L, 0xe51d0333L, - 0x5f4c0aaaL, 0xc97c0dddL, 0x3c710550L, 0xaa410227L, 0x10100bbeL, - 0x86200cc9L, 0x25b56857L, 0xb3856f20L, 0x09d466b9L, 0x9fe461ceL, - 0x0ef9de5eL, 0x98c9d929L, 0x2298d0b0L, 0xb4a8d7c7L, 0x173db359L, - 0x810db42eL, 0x3b5cbdb7L, 0xad6cbac0L, 0x2083b8edL, 0xb6b3bf9aL, - 0x0ce2b603L, 0x9ad2b174L, 0x3947d5eaL, 0xaf77d29dL, 0x1526db04L, - 0x8316dc73L, 0x120b63e3L, 0x843b6494L, 0x3e6a6d0dL, 0xa85a6a7aL, - 0x0bcf0ee4L, 0x9dff0993L, 0x27ae000aL, 0xb19e077dL, 0x44930ff0L, - 0xd2a30887L, 0x68f2011eL, 0xfec20669L, 0x5d5762f7L, 0xcb676580L, - 0x71366c19L, 0xe7066b6eL, 0x761bd4feL, 0xe02bd389L, 0x5a7ada10L, - 0xcc4add67L, 0x6fdfb9f9L, 0xf9efbe8eL, 0x43beb717L, 0xd58eb060L, - 0xe8a3d6d6L, 0x7e93d1a1L, 0xc4c2d838L, 0x52f2df4fL, 0xf167bbd1L, - 0x6757bca6L, 0xdd06b53fL, 0x4b36b248L, 0xda2b0dd8L, 0x4c1b0aafL, - 0xf64a0336L, 0x607a0441L, 0xc3ef60dfL, 0x55df67a8L, 0xef8e6e31L, - 0x79be6946L, 0x8cb361cbL, 0x1a8366bcL, 0xa0d26f25L, 0x36e26852L, - 0x95770cccL, 0x03470bbbL, 0xb9160222L, 0x2f260555L, 0xbe3bbac5L, - 0x280bbdb2L, 0x925ab42bL, 0x046ab35cL, 0xa7ffd7c2L, 0x31cfd0b5L, - 0x8b9ed92cL, 0x1daede5bL, 0xb0c2649bL, 0x26f263ecL, 0x9ca36a75L, - 0x0a936d02L, 0xa906099cL, 0x3f360eebL, 0x85670772L, 0x13570005L, - 0x824abf95L, 0x147ab8e2L, 0xae2bb17bL, 0x381bb60cL, 0x9b8ed292L, - 0x0dbed5e5L, 0xb7efdc7cL, 0x21dfdb0bL, 0xd4d2d386L, 0x42e2d4f1L, - 0xf8b3dd68L, 0x6e83da1fL, 0xcd16be81L, 0x5b26b9f6L, 0xe177b06fL, - 0x7747b718L, 0xe65a0888L, 0x706a0fffL, 0xca3b0666L, 0x5c0b0111L, - 0xff9e658fL, 0x69ae62f8L, 0xd3ff6b61L, 0x45cf6c16L, 0x78e20aa0L, - 0xeed20dd7L, 0x5483044eL, 0xc2b30339L, 0x612667a7L, 0xf71660d0L, - 0x4d476949L, 0xdb776e3eL, 0x4a6ad1aeL, 0xdc5ad6d9L, 0x660bdf40L, - 0xf03bd837L, 0x53aebca9L, 0xc59ebbdeL, 0x7fcfb247L, 0xe9ffb530L, - 0x1cf2bdbdL, 0x8ac2bacaL, 0x3093b353L, 0xa6a3b424L, 0x0536d0baL, - 0x9306d7cdL, 0x2957de54L, 0xbf67d923L, 0x2e7a66b3L, 0xb84a61c4L, - 0x021b685dL, 0x942b6f2aL, 0x37be0bb4L, 0xa18e0cc3L, 0x1bdf055aL, - 0x8def022dL -#endif -}; - -CRC32::CRC32() -{ - Reset(); -} - -void CRC32::Update(const byte *s, size_t n) -{ - word32 crc = m_crc; - - for(; !IsAligned(s) && n > 0; n--) - crc = m_tab[CRC32_INDEX(crc) ^ *s++] ^ CRC32_SHIFTED(crc); - - while (n >= 4) - { - crc ^= *(const word32 *)s; - crc = m_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc); - crc = m_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc); - crc = m_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc); - crc = m_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc); - n -= 4; - s += 4; - } - - while (n--) - crc = m_tab[CRC32_INDEX(crc) ^ *s++] ^ CRC32_SHIFTED(crc); - - m_crc = crc; -} - -void CRC32::TruncatedFinal(byte *hash, size_t size) -{ - ThrowIfInvalidTruncatedSize(size); - - m_crc ^= CRC32_NEGL; - for (size_t i=0; i> 8) -#else -#define CRC32_INDEX(c) (c >> 24) -#define CRC32_SHIFTED(c) (c << 8) -#endif - -//! CRC Checksum Calculation -class CRC32 : public HashTransformation -{ -public: - CRYPTOPP_CONSTANT(DIGESTSIZE = 4) - CRC32(); - void Update(const byte *input, size_t length); - void TruncatedFinal(byte *hash, size_t size); - unsigned int DigestSize() const {return DIGESTSIZE;} - static const char * StaticAlgorithmName() {return "CRC32";} - std::string AlgorithmName() const {return StaticAlgorithmName();} - - void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} - byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];} - -private: - void Reset() {m_crc = CRC32_NEGL;} - - static const word32 m_tab[256]; - word32 m_crc; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/cryptlib.cpp b/lib/cryptopp/cryptlib.cpp deleted file mode 100644 index df138ddb0..000000000 --- a/lib/cryptopp/cryptlib.cpp +++ /dev/null @@ -1,828 +0,0 @@ -// cryptlib.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "cryptlib.h" -#include "misc.h" -#include "filters.h" -#include "algparam.h" -#include "fips140.h" -#include "argnames.h" -#include "fltrimpl.h" -#include "trdlocal.h" -#include "osrng.h" - -#include - -NAMESPACE_BEGIN(CryptoPP) - -CRYPTOPP_COMPILE_ASSERT(sizeof(byte) == 1); -CRYPTOPP_COMPILE_ASSERT(sizeof(word16) == 2); -CRYPTOPP_COMPILE_ASSERT(sizeof(word32) == 4); -CRYPTOPP_COMPILE_ASSERT(sizeof(word64) == 8); -#ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE -CRYPTOPP_COMPILE_ASSERT(sizeof(dword) == 2*sizeof(word)); -#endif - -const std::string DEFAULT_CHANNEL; -const std::string AAD_CHANNEL = "AAD"; -const std::string &BufferedTransformation::NULL_CHANNEL = DEFAULT_CHANNEL; - -class NullNameValuePairs : public NameValuePairs -{ -public: - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const {return false;} -}; - -simple_ptr s_pNullNameValuePairs(new NullNameValuePairs); -const NameValuePairs &g_nullNameValuePairs = *s_pNullNameValuePairs.m_p; - -BufferedTransformation & TheBitBucket() -{ - static BitBucket bitBucket; - return bitBucket; -} - -Algorithm::Algorithm(bool checkSelfTestStatus) -{ - if (checkSelfTestStatus && FIPS_140_2_ComplianceEnabled()) - { - if (GetPowerUpSelfTestStatus() == POWER_UP_SELF_TEST_NOT_DONE && !PowerUpSelfTestInProgressOnThisThread()) - throw SelfTestFailure("Cryptographic algorithms are disabled before the power-up self tests are performed."); - - if (GetPowerUpSelfTestStatus() == POWER_UP_SELF_TEST_FAILED) - throw SelfTestFailure("Cryptographic algorithms are disabled after a power-up self test failed."); - } -} - -void SimpleKeyingInterface::SetKey(const byte *key, size_t length, const NameValuePairs ¶ms) -{ - this->ThrowIfInvalidKeyLength(length); - this->UncheckedSetKey(key, (unsigned int)length, params); -} - -void SimpleKeyingInterface::SetKeyWithRounds(const byte *key, size_t length, int rounds) -{ - SetKey(key, length, MakeParameters(Name::Rounds(), rounds)); -} - -void SimpleKeyingInterface::SetKeyWithIV(const byte *key, size_t length, const byte *iv, size_t ivLength) -{ - SetKey(key, length, MakeParameters(Name::IV(), ConstByteArrayParameter(iv, ivLength))); -} - -void SimpleKeyingInterface::ThrowIfInvalidKeyLength(size_t length) -{ - if (!IsValidKeyLength(length)) - throw InvalidKeyLength(GetAlgorithm().AlgorithmName(), length); -} - -void SimpleKeyingInterface::ThrowIfResynchronizable() -{ - if (IsResynchronizable()) - throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": this object requires an IV"); -} - -void SimpleKeyingInterface::ThrowIfInvalidIV(const byte *iv) -{ - if (!iv && IVRequirement() == UNPREDICTABLE_RANDOM_IV) - throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": this object cannot use a null IV"); -} - -size_t SimpleKeyingInterface::ThrowIfInvalidIVLength(int size) -{ - if (size < 0) - return IVSize(); - else if ((size_t)size < MinIVLength()) - throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": IV length " + IntToString(size) + " is less than the minimum of " + IntToString(MinIVLength())); - else if ((size_t)size > MaxIVLength()) - throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": IV length " + IntToString(size) + " exceeds the maximum of " + IntToString(MaxIVLength())); - else - return size; -} - -const byte * SimpleKeyingInterface::GetIVAndThrowIfInvalid(const NameValuePairs ¶ms, size_t &size) -{ - ConstByteArrayParameter ivWithLength; - const byte *iv; - bool found = false; - - try {found = params.GetValue(Name::IV(), ivWithLength);} - catch (const NameValuePairs::ValueTypeMismatch &) {} - - if (found) - { - iv = ivWithLength.begin(); - ThrowIfInvalidIV(iv); - size = ThrowIfInvalidIVLength((int)ivWithLength.size()); - return iv; - } - else if (params.GetValue(Name::IV(), iv)) - { - ThrowIfInvalidIV(iv); - size = IVSize(); - return iv; - } - else - { - ThrowIfResynchronizable(); - size = 0; - return NULL; - } -} - -void SimpleKeyingInterface::GetNextIV(RandomNumberGenerator &rng, byte *IV) -{ - rng.GenerateBlock(IV, IVSize()); -} - -size_t BlockTransformation::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const -{ - size_t blockSize = BlockSize(); - size_t inIncrement = (flags & (BT_InBlockIsCounter|BT_DontIncrementInOutPointers)) ? 0 : blockSize; - size_t xorIncrement = xorBlocks ? blockSize : 0; - size_t outIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : blockSize; - - if (flags & BT_ReverseDirection) - { - assert(length % blockSize == 0); - inBlocks += length - blockSize; - xorBlocks += length - blockSize; - outBlocks += length - blockSize; - inIncrement = 0-inIncrement; - xorIncrement = 0-xorIncrement; - outIncrement = 0-outIncrement; - } - - while (length >= blockSize) - { - if (flags & BT_XorInput) - { - xorbuf(outBlocks, xorBlocks, inBlocks, blockSize); - ProcessBlock(outBlocks); - } - else - ProcessAndXorBlock(inBlocks, xorBlocks, outBlocks); - if (flags & BT_InBlockIsCounter) - const_cast(inBlocks)[blockSize-1]++; - inBlocks += inIncrement; - outBlocks += outIncrement; - xorBlocks += xorIncrement; - length -= blockSize; - } - - return length; -} - -unsigned int BlockTransformation::OptimalDataAlignment() const -{ - return GetAlignmentOf(); -} - -unsigned int StreamTransformation::OptimalDataAlignment() const -{ - return GetAlignmentOf(); -} - -unsigned int HashTransformation::OptimalDataAlignment() const -{ - return GetAlignmentOf(); -} - -void StreamTransformation::ProcessLastBlock(byte *outString, const byte *inString, size_t length) -{ - assert(MinLastBlockSize() == 0); // this function should be overriden otherwise - - if (length == MandatoryBlockSize()) - ProcessData(outString, inString, length); - else if (length != 0) - throw NotImplemented(AlgorithmName() + ": this object does't support a special last block"); -} - -void AuthenticatedSymmetricCipher::SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength) -{ - if (headerLength > MaxHeaderLength()) - throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": header length " + IntToString(headerLength) + " exceeds the maximum of " + IntToString(MaxHeaderLength())); - - if (messageLength > MaxMessageLength()) - throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": message length " + IntToString(messageLength) + " exceeds the maximum of " + IntToString(MaxMessageLength())); - - if (footerLength > MaxFooterLength()) - throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": footer length " + IntToString(footerLength) + " exceeds the maximum of " + IntToString(MaxFooterLength())); - - UncheckedSpecifyDataLengths(headerLength, messageLength, footerLength); -} - -void AuthenticatedSymmetricCipher::EncryptAndAuthenticate(byte *ciphertext, byte *mac, size_t macSize, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *message, size_t messageLength) -{ - Resynchronize(iv, ivLength); - SpecifyDataLengths(headerLength, messageLength); - Update(header, headerLength); - ProcessString(ciphertext, message, messageLength); - TruncatedFinal(mac, macSize); -} - -bool AuthenticatedSymmetricCipher::DecryptAndVerify(byte *message, const byte *mac, size_t macLength, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *ciphertext, size_t ciphertextLength) -{ - Resynchronize(iv, ivLength); - SpecifyDataLengths(headerLength, ciphertextLength); - Update(header, headerLength); - ProcessString(message, ciphertext, ciphertextLength); - return TruncatedVerify(mac, macLength); -} - -unsigned int RandomNumberGenerator::GenerateBit() -{ - return GenerateByte() & 1; -} - -byte RandomNumberGenerator::GenerateByte() -{ - byte b; - GenerateBlock(&b, 1); - return b; -} - -word32 RandomNumberGenerator::GenerateWord32(word32 min, word32 max) -{ - word32 range = max-min; - const int maxBits = BitPrecision(range); - - word32 value; - - do - { - GenerateBlock((byte *)&value, sizeof(value)); - value = Crop(value, maxBits); - } while (value > range); - - return value+min; -} - -void RandomNumberGenerator::GenerateBlock(byte *output, size_t size) -{ - ArraySink s(output, size); - GenerateIntoBufferedTransformation(s, DEFAULT_CHANNEL, size); -} - -void RandomNumberGenerator::DiscardBytes(size_t n) -{ - GenerateIntoBufferedTransformation(TheBitBucket(), DEFAULT_CHANNEL, n); -} - -void RandomNumberGenerator::GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length) -{ - FixedSizeSecBlock buffer; - while (length) - { - size_t len = UnsignedMin(buffer.size(), length); - GenerateBlock(buffer, len); - target.ChannelPut(channel, buffer, len); - length -= len; - } -} - -//! see NullRNG() -class ClassNullRNG : public RandomNumberGenerator -{ -public: - std::string AlgorithmName() const {return "NullRNG";} - void GenerateBlock(byte *output, size_t size) {throw NotImplemented("NullRNG: NullRNG should only be passed to functions that don't need to generate random bytes");} -}; - -RandomNumberGenerator & NullRNG() -{ - static ClassNullRNG s_nullRNG; - return s_nullRNG; -} - -bool HashTransformation::TruncatedVerify(const byte *digestIn, size_t digestLength) -{ - ThrowIfInvalidTruncatedSize(digestLength); - SecByteBlock digest(digestLength); - TruncatedFinal(digest, digestLength); - return VerifyBufsEqual(digest, digestIn, digestLength); -} - -void HashTransformation::ThrowIfInvalidTruncatedSize(size_t size) const -{ - if (size > DigestSize()) - throw InvalidArgument("HashTransformation: can't truncate a " + IntToString(DigestSize()) + " byte digest to " + IntToString(size) + " bytes"); -} - -unsigned int BufferedTransformation::GetMaxWaitObjectCount() const -{ - const BufferedTransformation *t = AttachedTransformation(); - return t ? t->GetMaxWaitObjectCount() : 0; -} - -void BufferedTransformation::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) -{ - BufferedTransformation *t = AttachedTransformation(); - if (t) - t->GetWaitObjects(container, callStack); // reduce clutter by not adding to stack here -} - -void BufferedTransformation::Initialize(const NameValuePairs ¶meters, int propagation) -{ - assert(!AttachedTransformation()); - IsolatedInitialize(parameters); -} - -bool BufferedTransformation::Flush(bool hardFlush, int propagation, bool blocking) -{ - assert(!AttachedTransformation()); - return IsolatedFlush(hardFlush, blocking); -} - -bool BufferedTransformation::MessageSeriesEnd(int propagation, bool blocking) -{ - assert(!AttachedTransformation()); - return IsolatedMessageSeriesEnd(blocking); -} - -byte * BufferedTransformation::ChannelCreatePutSpace(const std::string &channel, size_t &size) -{ - if (channel.empty()) - return CreatePutSpace(size); - else - throw NoChannelSupport(AlgorithmName()); -} - -size_t BufferedTransformation::ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking) -{ - if (channel.empty()) - return Put2(begin, length, messageEnd, blocking); - else - throw NoChannelSupport(AlgorithmName()); -} - -size_t BufferedTransformation::ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking) -{ - if (channel.empty()) - return PutModifiable2(begin, length, messageEnd, blocking); - else - return ChannelPut2(channel, begin, length, messageEnd, blocking); -} - -bool BufferedTransformation::ChannelFlush(const std::string &channel, bool completeFlush, int propagation, bool blocking) -{ - if (channel.empty()) - return Flush(completeFlush, propagation, blocking); - else - throw NoChannelSupport(AlgorithmName()); -} - -bool BufferedTransformation::ChannelMessageSeriesEnd(const std::string &channel, int propagation, bool blocking) -{ - if (channel.empty()) - return MessageSeriesEnd(propagation, blocking); - else - throw NoChannelSupport(AlgorithmName()); -} - -lword BufferedTransformation::MaxRetrievable() const -{ - if (AttachedTransformation()) - return AttachedTransformation()->MaxRetrievable(); - else - return CopyTo(TheBitBucket()); -} - -bool BufferedTransformation::AnyRetrievable() const -{ - if (AttachedTransformation()) - return AttachedTransformation()->AnyRetrievable(); - else - { - byte b; - return Peek(b) != 0; - } -} - -size_t BufferedTransformation::Get(byte &outByte) -{ - if (AttachedTransformation()) - return AttachedTransformation()->Get(outByte); - else - return Get(&outByte, 1); -} - -size_t BufferedTransformation::Get(byte *outString, size_t getMax) -{ - if (AttachedTransformation()) - return AttachedTransformation()->Get(outString, getMax); - else - { - ArraySink arraySink(outString, getMax); - return (size_t)TransferTo(arraySink, getMax); - } -} - -size_t BufferedTransformation::Peek(byte &outByte) const -{ - if (AttachedTransformation()) - return AttachedTransformation()->Peek(outByte); - else - return Peek(&outByte, 1); -} - -size_t BufferedTransformation::Peek(byte *outString, size_t peekMax) const -{ - if (AttachedTransformation()) - return AttachedTransformation()->Peek(outString, peekMax); - else - { - ArraySink arraySink(outString, peekMax); - return (size_t)CopyTo(arraySink, peekMax); - } -} - -lword BufferedTransformation::Skip(lword skipMax) -{ - if (AttachedTransformation()) - return AttachedTransformation()->Skip(skipMax); - else - return TransferTo(TheBitBucket(), skipMax); -} - -lword BufferedTransformation::TotalBytesRetrievable() const -{ - if (AttachedTransformation()) - return AttachedTransformation()->TotalBytesRetrievable(); - else - return MaxRetrievable(); -} - -unsigned int BufferedTransformation::NumberOfMessages() const -{ - if (AttachedTransformation()) - return AttachedTransformation()->NumberOfMessages(); - else - return CopyMessagesTo(TheBitBucket()); -} - -bool BufferedTransformation::AnyMessages() const -{ - if (AttachedTransformation()) - return AttachedTransformation()->AnyMessages(); - else - return NumberOfMessages() != 0; -} - -bool BufferedTransformation::GetNextMessage() -{ - if (AttachedTransformation()) - return AttachedTransformation()->GetNextMessage(); - else - { - assert(!AnyMessages()); - return false; - } -} - -unsigned int BufferedTransformation::SkipMessages(unsigned int count) -{ - if (AttachedTransformation()) - return AttachedTransformation()->SkipMessages(count); - else - return TransferMessagesTo(TheBitBucket(), count); -} - -size_t BufferedTransformation::TransferMessagesTo2(BufferedTransformation &target, unsigned int &messageCount, const std::string &channel, bool blocking) -{ - if (AttachedTransformation()) - return AttachedTransformation()->TransferMessagesTo2(target, messageCount, channel, blocking); - else - { - unsigned int maxMessages = messageCount; - for (messageCount=0; messageCount < maxMessages && AnyMessages(); messageCount++) - { - size_t blockedBytes; - lword transferredBytes; - - while (AnyRetrievable()) - { - transferredBytes = LWORD_MAX; - blockedBytes = TransferTo2(target, transferredBytes, channel, blocking); - if (blockedBytes > 0) - return blockedBytes; - } - - if (target.ChannelMessageEnd(channel, GetAutoSignalPropagation(), blocking)) - return 1; - - bool result = GetNextMessage(); - assert(result); - } - return 0; - } -} - -unsigned int BufferedTransformation::CopyMessagesTo(BufferedTransformation &target, unsigned int count, const std::string &channel) const -{ - if (AttachedTransformation()) - return AttachedTransformation()->CopyMessagesTo(target, count, channel); - else - return 0; -} - -void BufferedTransformation::SkipAll() -{ - if (AttachedTransformation()) - AttachedTransformation()->SkipAll(); - else - { - while (SkipMessages()) {} - while (Skip()) {} - } -} - -size_t BufferedTransformation::TransferAllTo2(BufferedTransformation &target, const std::string &channel, bool blocking) -{ - if (AttachedTransformation()) - return AttachedTransformation()->TransferAllTo2(target, channel, blocking); - else - { - assert(!NumberOfMessageSeries()); - - unsigned int messageCount; - do - { - messageCount = UINT_MAX; - size_t blockedBytes = TransferMessagesTo2(target, messageCount, channel, blocking); - if (blockedBytes) - return blockedBytes; - } - while (messageCount != 0); - - lword byteCount; - do - { - byteCount = ULONG_MAX; - size_t blockedBytes = TransferTo2(target, byteCount, channel, blocking); - if (blockedBytes) - return blockedBytes; - } - while (byteCount != 0); - - return 0; - } -} - -void BufferedTransformation::CopyAllTo(BufferedTransformation &target, const std::string &channel) const -{ - if (AttachedTransformation()) - AttachedTransformation()->CopyAllTo(target, channel); - else - { - assert(!NumberOfMessageSeries()); - while (CopyMessagesTo(target, UINT_MAX, channel)) {} - } -} - -void BufferedTransformation::SetRetrievalChannel(const std::string &channel) -{ - if (AttachedTransformation()) - AttachedTransformation()->SetRetrievalChannel(channel); -} - -size_t BufferedTransformation::ChannelPutWord16(const std::string &channel, word16 value, ByteOrder order, bool blocking) -{ - PutWord(false, order, m_buf, value); - return ChannelPut(channel, m_buf, 2, blocking); -} - -size_t BufferedTransformation::ChannelPutWord32(const std::string &channel, word32 value, ByteOrder order, bool blocking) -{ - PutWord(false, order, m_buf, value); - return ChannelPut(channel, m_buf, 4, blocking); -} - -size_t BufferedTransformation::PutWord16(word16 value, ByteOrder order, bool blocking) -{ - return ChannelPutWord16(DEFAULT_CHANNEL, value, order, blocking); -} - -size_t BufferedTransformation::PutWord32(word32 value, ByteOrder order, bool blocking) -{ - return ChannelPutWord32(DEFAULT_CHANNEL, value, order, blocking); -} - -size_t BufferedTransformation::PeekWord16(word16 &value, ByteOrder order) const -{ - byte buf[2] = {0, 0}; - size_t len = Peek(buf, 2); - - if (order) - value = (buf[0] << 8) | buf[1]; - else - value = (buf[1] << 8) | buf[0]; - - return len; -} - -size_t BufferedTransformation::PeekWord32(word32 &value, ByteOrder order) const -{ - byte buf[4] = {0, 0, 0, 0}; - size_t len = Peek(buf, 4); - - if (order) - value = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf [3]; - else - value = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf [0]; - - return len; -} - -size_t BufferedTransformation::GetWord16(word16 &value, ByteOrder order) -{ - return (size_t)Skip(PeekWord16(value, order)); -} - -size_t BufferedTransformation::GetWord32(word32 &value, ByteOrder order) -{ - return (size_t)Skip(PeekWord32(value, order)); -} - -void BufferedTransformation::Attach(BufferedTransformation *newOut) -{ - if (AttachedTransformation() && AttachedTransformation()->Attachable()) - AttachedTransformation()->Attach(newOut); - else - Detach(newOut); -} - -void GeneratableCryptoMaterial::GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize) -{ - GenerateRandom(rng, MakeParameters("KeySize", (int)keySize)); -} - -class PK_DefaultEncryptionFilter : public Unflushable -{ -public: - PK_DefaultEncryptionFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment, const NameValuePairs ¶meters) - : m_rng(rng), m_encryptor(encryptor), m_parameters(parameters) - { - Detach(attachment); - } - - size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking) - { - FILTER_BEGIN; - m_plaintextQueue.Put(inString, length); - - if (messageEnd) - { - { - size_t plaintextLength; - if (!SafeConvert(m_plaintextQueue.CurrentSize(), plaintextLength)) - throw InvalidArgument("PK_DefaultEncryptionFilter: plaintext too long"); - size_t ciphertextLength = m_encryptor.CiphertextLength(plaintextLength); - - SecByteBlock plaintext(plaintextLength); - m_plaintextQueue.Get(plaintext, plaintextLength); - m_ciphertext.resize(ciphertextLength); - m_encryptor.Encrypt(m_rng, plaintext, plaintextLength, m_ciphertext, m_parameters); - } - - FILTER_OUTPUT(1, m_ciphertext, m_ciphertext.size(), messageEnd); - } - FILTER_END_NO_MESSAGE_END; - } - - RandomNumberGenerator &m_rng; - const PK_Encryptor &m_encryptor; - const NameValuePairs &m_parameters; - ByteQueue m_plaintextQueue; - SecByteBlock m_ciphertext; -}; - -BufferedTransformation * PK_Encryptor::CreateEncryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment, const NameValuePairs ¶meters) const -{ - return new PK_DefaultEncryptionFilter(rng, *this, attachment, parameters); -} - -class PK_DefaultDecryptionFilter : public Unflushable -{ -public: - PK_DefaultDecryptionFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment, const NameValuePairs ¶meters) - : m_rng(rng), m_decryptor(decryptor), m_parameters(parameters) - { - Detach(attachment); - } - - size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking) - { - FILTER_BEGIN; - m_ciphertextQueue.Put(inString, length); - - if (messageEnd) - { - { - size_t ciphertextLength; - if (!SafeConvert(m_ciphertextQueue.CurrentSize(), ciphertextLength)) - throw InvalidArgument("PK_DefaultDecryptionFilter: ciphertext too long"); - size_t maxPlaintextLength = m_decryptor.MaxPlaintextLength(ciphertextLength); - - SecByteBlock ciphertext(ciphertextLength); - m_ciphertextQueue.Get(ciphertext, ciphertextLength); - m_plaintext.resize(maxPlaintextLength); - m_result = m_decryptor.Decrypt(m_rng, ciphertext, ciphertextLength, m_plaintext, m_parameters); - if (!m_result.isValidCoding) - throw InvalidCiphertext(m_decryptor.AlgorithmName() + ": invalid ciphertext"); - } - - FILTER_OUTPUT(1, m_plaintext, m_result.messageLength, messageEnd); - } - FILTER_END_NO_MESSAGE_END; - } - - RandomNumberGenerator &m_rng; - const PK_Decryptor &m_decryptor; - const NameValuePairs &m_parameters; - ByteQueue m_ciphertextQueue; - SecByteBlock m_plaintext; - DecodingResult m_result; -}; - -BufferedTransformation * PK_Decryptor::CreateDecryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment, const NameValuePairs ¶meters) const -{ - return new PK_DefaultDecryptionFilter(rng, *this, attachment, parameters); -} - -size_t PK_Signer::Sign(RandomNumberGenerator &rng, PK_MessageAccumulator *messageAccumulator, byte *signature) const -{ - std::auto_ptr m(messageAccumulator); - return SignAndRestart(rng, *m, signature, false); -} - -size_t PK_Signer::SignMessage(RandomNumberGenerator &rng, const byte *message, size_t messageLen, byte *signature) const -{ - std::auto_ptr m(NewSignatureAccumulator(rng)); - m->Update(message, messageLen); - return SignAndRestart(rng, *m, signature, false); -} - -size_t PK_Signer::SignMessageWithRecovery(RandomNumberGenerator &rng, const byte *recoverableMessage, size_t recoverableMessageLength, - const byte *nonrecoverableMessage, size_t nonrecoverableMessageLength, byte *signature) const -{ - std::auto_ptr m(NewSignatureAccumulator(rng)); - InputRecoverableMessage(*m, recoverableMessage, recoverableMessageLength); - m->Update(nonrecoverableMessage, nonrecoverableMessageLength); - return SignAndRestart(rng, *m, signature, false); -} - -bool PK_Verifier::Verify(PK_MessageAccumulator *messageAccumulator) const -{ - std::auto_ptr m(messageAccumulator); - return VerifyAndRestart(*m); -} - -bool PK_Verifier::VerifyMessage(const byte *message, size_t messageLen, const byte *signature, size_t signatureLength) const -{ - std::auto_ptr m(NewVerificationAccumulator()); - InputSignature(*m, signature, signatureLength); - m->Update(message, messageLen); - return VerifyAndRestart(*m); -} - -DecodingResult PK_Verifier::Recover(byte *recoveredMessage, PK_MessageAccumulator *messageAccumulator) const -{ - std::auto_ptr m(messageAccumulator); - return RecoverAndRestart(recoveredMessage, *m); -} - -DecodingResult PK_Verifier::RecoverMessage(byte *recoveredMessage, - const byte *nonrecoverableMessage, size_t nonrecoverableMessageLength, - const byte *signature, size_t signatureLength) const -{ - std::auto_ptr m(NewVerificationAccumulator()); - InputSignature(*m, signature, signatureLength); - m->Update(nonrecoverableMessage, nonrecoverableMessageLength); - return RecoverAndRestart(recoveredMessage, *m); -} - -void SimpleKeyAgreementDomain::GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const -{ - GeneratePrivateKey(rng, privateKey); - GeneratePublicKey(rng, privateKey, publicKey); -} - -void AuthenticatedKeyAgreementDomain::GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const -{ - GenerateStaticPrivateKey(rng, privateKey); - GenerateStaticPublicKey(rng, privateKey, publicKey); -} - -void AuthenticatedKeyAgreementDomain::GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const -{ - GenerateEphemeralPrivateKey(rng, privateKey); - GenerateEphemeralPublicKey(rng, privateKey, publicKey); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/cryptlib.h b/lib/cryptopp/cryptlib.h deleted file mode 100644 index 406872232..000000000 --- a/lib/cryptopp/cryptlib.h +++ /dev/null @@ -1,1655 +0,0 @@ -// cryptlib.h - written and placed in the public domain by Wei Dai -/*! \file - This file contains the declarations for the abstract base - classes that provide a uniform interface to this library. -*/ - -/*! \mainpage Crypto++ Library 5.6.2 API Reference -
-
Abstract Base Classes
- cryptlib.h -
Authenticated Encryption
- AuthenticatedSymmetricCipherDocumentation -
Symmetric Ciphers
- SymmetricCipherDocumentation -
Hash Functions
- SHA1, SHA224, SHA256, SHA384, SHA512, Tiger, Whirlpool, RIPEMD160, RIPEMD320, RIPEMD128, RIPEMD256, Weak1::MD2, Weak1::MD4, Weak1::MD5 -
Non-Cryptographic Checksums
- CRC32, Adler32 -
Message Authentication Codes
- VMAC, HMAC, CBC_MAC, CMAC, DMAC, TTMAC, GCM (GMAC) -
Random Number Generators
- NullRNG(), LC_RNG, RandomPool, BlockingRng, NonblockingRng, AutoSeededRandomPool, AutoSeededX917RNG, #DefaultAutoSeededRNG -
Password-based Cryptography
- PasswordBasedKeyDerivationFunction -
Public Key Cryptosystems
- DLIES, ECIES, LUCES, RSAES, RabinES, LUC_IES -
Public Key Signature Schemes
- DSA2, GDSA, ECDSA, NR, ECNR, LUCSS, RSASS, RSASS_ISO, RabinSS, RWSS, ESIGN -
Key Agreement
- #DH, DH2, #MQV, ECDH, ECMQV, XTR_DH -
Algebraic Structures
- Integer, PolynomialMod2, PolynomialOver, RingOfPolynomialsOver, - ModularArithmetic, MontgomeryRepresentation, GFP2_ONB, - GF2NP, GF256, GF2_32, EC2N, ECP -
Secret Sharing and Information Dispersal
- SecretSharing, SecretRecovery, InformationDispersal, InformationRecovery -
Compression
- Deflator, Inflator, Gzip, Gunzip, ZlibCompressor, ZlibDecompressor -
Input Source Classes
- StringSource, #ArraySource, FileSource, SocketSource, WindowsPipeSource, RandomNumberSource -
Output Sink Classes
- StringSinkTemplate, ArraySink, FileSink, SocketSink, WindowsPipeSink, RandomNumberSink -
Filter Wrappers
- StreamTransformationFilter, HashFilter, HashVerificationFilter, SignerFilter, SignatureVerificationFilter -
Binary to Text Encoders and Decoders
- HexEncoder, HexDecoder, Base64Encoder, Base64Decoder, Base32Encoder, Base32Decoder -
Wrappers for OS features
- Timer, Socket, WindowsHandle, ThreadLocalStorage, ThreadUserTimer -
FIPS 140 related
- fips140.h -
- -In the DLL version of Crypto++, only the following implementation class are available. -
-
Block Ciphers
- AES, DES_EDE2, DES_EDE3, SKIPJACK -
Cipher Modes (replace template parameter BC with one of the block ciphers above)
- ECB_Mode\, CTR_Mode\, CBC_Mode\, CFB_FIPS_Mode\, OFB_Mode\, GCM\ -
Hash Functions
- SHA1, SHA224, SHA256, SHA384, SHA512 -
Public Key Signature Schemes (replace template parameter H with one of the hash functions above)
- RSASS\, RSASS\, RSASS_ISO\, RWSS\, DSA, ECDSA\, ECDSA\ -
Message Authentication Codes (replace template parameter H with one of the hash functions above)
- HMAC\, CBC_MAC\, CBC_MAC\, GCM\ -
Random Number Generators
- #DefaultAutoSeededRNG (AutoSeededX917RNG\) -
Key Agreement
- #DH -
Public Key Cryptosystems
- RSAES\ \> -
- -

This reference manual is a work in progress. Some classes are still lacking detailed descriptions. -

Click here to download a zip archive containing this manual. -

Thanks to Ryan Phillips for providing the Doxygen configuration file -and getting me started with this manual. -*/ - -#ifndef CRYPTOPP_CRYPTLIB_H -#define CRYPTOPP_CRYPTLIB_H - -#include "config.h" -#include "stdcpp.h" - -NAMESPACE_BEGIN(CryptoPP) - -// forward declarations -class Integer; -class RandomNumberGenerator; -class BufferedTransformation; - -//! used to specify a direction for a cipher to operate in (encrypt or decrypt) -enum CipherDir {ENCRYPTION, DECRYPTION}; - -//! used to represent infinite time -const unsigned long INFINITE_TIME = ULONG_MAX; - -// VC60 workaround: using enums as template parameters causes problems -template -struct EnumToType -{ - static ENUM_TYPE ToEnum() {return (ENUM_TYPE)VALUE;} -}; - -enum ByteOrder {LITTLE_ENDIAN_ORDER = 0, BIG_ENDIAN_ORDER = 1}; -typedef EnumToType LittleEndian; -typedef EnumToType BigEndian; - -//! base class for all exceptions thrown by Crypto++ -class CRYPTOPP_DLL Exception : public std::exception -{ -public: - //! error types - enum ErrorType { - //! a method is not implemented - NOT_IMPLEMENTED, - //! invalid function argument - INVALID_ARGUMENT, - //! BufferedTransformation received a Flush(true) signal but can't flush buffers - CANNOT_FLUSH, - //! data integerity check (such as CRC or MAC) failed - DATA_INTEGRITY_CHECK_FAILED, - //! received input data that doesn't conform to expected format - INVALID_DATA_FORMAT, - //! error reading from input device or writing to output device - IO_ERROR, - //! some error not belong to any of the above categories - OTHER_ERROR - }; - - explicit Exception(ErrorType errorType, const std::string &s) : m_errorType(errorType), m_what(s) {} - virtual ~Exception() throw() {} - const char *what() const throw() {return (m_what.c_str());} - const std::string &GetWhat() const {return m_what;} - void SetWhat(const std::string &s) {m_what = s;} - ErrorType GetErrorType() const {return m_errorType;} - void SetErrorType(ErrorType errorType) {m_errorType = errorType;} - -private: - ErrorType m_errorType; - std::string m_what; -}; - -//! exception thrown when an invalid argument is detected -class CRYPTOPP_DLL InvalidArgument : public Exception -{ -public: - explicit InvalidArgument(const std::string &s) : Exception(INVALID_ARGUMENT, s) {} -}; - -//! exception thrown when input data is received that doesn't conform to expected format -class CRYPTOPP_DLL InvalidDataFormat : public Exception -{ -public: - explicit InvalidDataFormat(const std::string &s) : Exception(INVALID_DATA_FORMAT, s) {} -}; - -//! exception thrown by decryption filters when trying to decrypt an invalid ciphertext -class CRYPTOPP_DLL InvalidCiphertext : public InvalidDataFormat -{ -public: - explicit InvalidCiphertext(const std::string &s) : InvalidDataFormat(s) {} -}; - -//! exception thrown by a class if a non-implemented method is called -class CRYPTOPP_DLL NotImplemented : public Exception -{ -public: - explicit NotImplemented(const std::string &s) : Exception(NOT_IMPLEMENTED, s) {} -}; - -//! exception thrown by a class when Flush(true) is called but it can't completely flush its buffers -class CRYPTOPP_DLL CannotFlush : public Exception -{ -public: - explicit CannotFlush(const std::string &s) : Exception(CANNOT_FLUSH, s) {} -}; - -//! error reported by the operating system -class CRYPTOPP_DLL OS_Error : public Exception -{ -public: - OS_Error(ErrorType errorType, const std::string &s, const std::string& operation, int errorCode) - : Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {} - ~OS_Error() throw() {} - - // the operating system API that reported the error - const std::string & GetOperation() const {return m_operation;} - // the error code return by the operating system - int GetErrorCode() const {return m_errorCode;} - -protected: - std::string m_operation; - int m_errorCode; -}; - -//! used to return decoding results -struct CRYPTOPP_DLL DecodingResult -{ - explicit DecodingResult() : isValidCoding(false), messageLength(0) {} - explicit DecodingResult(size_t len) : isValidCoding(true), messageLength(len) {} - - bool operator==(const DecodingResult &rhs) const {return isValidCoding == rhs.isValidCoding && messageLength == rhs.messageLength;} - bool operator!=(const DecodingResult &rhs) const {return !operator==(rhs);} - - bool isValidCoding; - size_t messageLength; - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - operator size_t() const {return isValidCoding ? messageLength : 0;} -#endif -}; - -//! interface for retrieving values given their names -/*! \note This class is used to safely pass a variable number of arbitrarily typed arguments to functions - and to read values from keys and crypto parameters. - \note To obtain an object that implements NameValuePairs for the purpose of parameter - passing, use the MakeParameters() function. - \note To get a value from NameValuePairs, you need to know the name and the type of the value. - Call GetValueNames() on a NameValuePairs object to obtain a list of value names that it supports. - Then look at the Name namespace documentation to see what the type of each value is, or - alternatively, call GetIntValue() with the value name, and if the type is not int, a - ValueTypeMismatch exception will be thrown and you can get the actual type from the exception object. -*/ -class CRYPTOPP_NO_VTABLE NameValuePairs -{ -public: - virtual ~NameValuePairs() {} - - //! exception thrown when trying to retrieve a value using a different type than expected - class CRYPTOPP_DLL ValueTypeMismatch : public InvalidArgument - { - public: - ValueTypeMismatch(const std::string &name, const std::type_info &stored, const std::type_info &retrieving) - : InvalidArgument("NameValuePairs: type mismatch for '" + name + "', stored '" + stored.name() + "', trying to retrieve '" + retrieving.name() + "'") - , m_stored(stored), m_retrieving(retrieving) {} - - const std::type_info & GetStoredTypeInfo() const {return m_stored;} - const std::type_info & GetRetrievingTypeInfo() const {return m_retrieving;} - - private: - const std::type_info &m_stored; - const std::type_info &m_retrieving; - }; - - //! get a copy of this object or a subobject of it - template - bool GetThisObject(T &object) const - { - return GetValue((std::string("ThisObject:")+typeid(T).name()).c_str(), object); - } - - //! get a pointer to this object, as a pointer to T - template - bool GetThisPointer(T *&p) const - { - return GetValue((std::string("ThisPointer:")+typeid(T).name()).c_str(), p); - } - - //! get a named value, returns true if the name exists - template - bool GetValue(const char *name, T &value) const - { - return GetVoidValue(name, typeid(T), &value); - } - - //! get a named value, returns the default if the name doesn't exist - template - T GetValueWithDefault(const char *name, T defaultValue) const - { - GetValue(name, defaultValue); - return defaultValue; - } - - //! get a list of value names that can be retrieved - CRYPTOPP_DLL std::string GetValueNames() const - {std::string result; GetValue("ValueNames", result); return result;} - - //! get a named value with type int - /*! used to ensure we don't accidentally try to get an unsigned int - or some other type when we mean int (which is the most common case) */ - CRYPTOPP_DLL bool GetIntValue(const char *name, int &value) const - {return GetValue(name, value);} - - //! get a named value with type int, with default - CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const - {return GetValueWithDefault(name, defaultValue);} - - //! used by derived classes to check for type mismatch - CRYPTOPP_DLL static void CRYPTOPP_API ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving) - {if (stored != retrieving) throw ValueTypeMismatch(name, stored, retrieving);} - - template - void GetRequiredParameter(const char *className, const char *name, T &value) const - { - if (!GetValue(name, value)) - throw InvalidArgument(std::string(className) + ": missing required parameter '" + name + "'"); - } - - CRYPTOPP_DLL void GetRequiredIntParameter(const char *className, const char *name, int &value) const - { - if (!GetIntValue(name, value)) - throw InvalidArgument(std::string(className) + ": missing required parameter '" + name + "'"); - } - - //! to be implemented by derived classes, users should use one of the above functions instead - CRYPTOPP_DLL virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0; -}; - -//! namespace containing value name definitions -/*! value names, types and semantics: - - ThisObject:ClassName (ClassName, copy of this object or a subobject) - ThisPointer:ClassName (const ClassName *, pointer to this object or a subobject) -*/ -DOCUMENTED_NAMESPACE_BEGIN(Name) -// more names defined in argnames.h -DOCUMENTED_NAMESPACE_END - -//! empty set of name-value pairs -extern CRYPTOPP_DLL const NameValuePairs &g_nullNameValuePairs; - -// ******************************************************** - -//! interface for cloning objects, this is not implemented by most classes yet -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Clonable -{ -public: - virtual ~Clonable() {} - //! this is not implemented by most classes yet - virtual Clonable* Clone() const {throw NotImplemented("Clone() is not implemented yet.");} // TODO: make this =0 -}; - -//! interface for all crypto algorithms - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Algorithm : public Clonable -{ -public: - /*! When FIPS 140-2 compliance is enabled and checkSelfTestStatus == true, - this constructor throws SelfTestFailure if the self test hasn't been run or fails. */ - Algorithm(bool checkSelfTestStatus = true); - //! returns name of this algorithm, not universally implemented yet - virtual std::string AlgorithmName() const {return "unknown";} -}; - -//! keying interface for crypto algorithms that take byte strings as keys -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyingInterface -{ -public: - virtual ~SimpleKeyingInterface() {} - - //! returns smallest valid key length in bytes */ - virtual size_t MinKeyLength() const =0; - //! returns largest valid key length in bytes */ - virtual size_t MaxKeyLength() const =0; - //! returns default (recommended) key length in bytes */ - virtual size_t DefaultKeyLength() const =0; - - //! returns the smallest valid key length in bytes that is >= min(n, GetMaxKeyLength()) - virtual size_t GetValidKeyLength(size_t n) const =0; - - //! returns whether n is a valid key length - virtual bool IsValidKeyLength(size_t n) const - {return n == GetValidKeyLength(n);} - - //! set or reset the key of this object - /*! \param params is used to specify Rounds, BlockSize, etc. */ - virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms = g_nullNameValuePairs); - - //! calls SetKey() with an NameValuePairs object that just specifies "Rounds" - void SetKeyWithRounds(const byte *key, size_t length, int rounds); - - //! calls SetKey() with an NameValuePairs object that just specifies "IV" - void SetKeyWithIV(const byte *key, size_t length, const byte *iv, size_t ivLength); - - //! calls SetKey() with an NameValuePairs object that just specifies "IV" - void SetKeyWithIV(const byte *key, size_t length, const byte *iv) - {SetKeyWithIV(key, length, iv, IVSize());} - - enum IV_Requirement {UNIQUE_IV = 0, RANDOM_IV, UNPREDICTABLE_RANDOM_IV, INTERNALLY_GENERATED_IV, NOT_RESYNCHRONIZABLE}; - //! returns the minimal requirement for secure IVs - virtual IV_Requirement IVRequirement() const =0; - - //! returns whether this object can be resynchronized (i.e. supports initialization vectors) - /*! If this function returns true, and no IV is passed to SetKey() and CanUseStructuredIVs()==true, an IV of all 0's will be assumed. */ - bool IsResynchronizable() const {return IVRequirement() < NOT_RESYNCHRONIZABLE;} - //! returns whether this object can use random IVs (in addition to ones returned by GetNextIV) - bool CanUseRandomIVs() const {return IVRequirement() <= UNPREDICTABLE_RANDOM_IV;} - //! returns whether this object can use random but possibly predictable IVs (in addition to ones returned by GetNextIV) - bool CanUsePredictableIVs() const {return IVRequirement() <= RANDOM_IV;} - //! returns whether this object can use structured IVs, for example a counter (in addition to ones returned by GetNextIV) - bool CanUseStructuredIVs() const {return IVRequirement() <= UNIQUE_IV;} - - virtual unsigned int IVSize() const {throw NotImplemented(GetAlgorithm().AlgorithmName() + ": this object doesn't support resynchronization");} - //! returns default length of IVs accepted by this object - unsigned int DefaultIVLength() const {return IVSize();} - //! returns minimal length of IVs accepted by this object - virtual unsigned int MinIVLength() const {return IVSize();} - //! returns maximal length of IVs accepted by this object - virtual unsigned int MaxIVLength() const {return IVSize();} - //! resynchronize with an IV. ivLength=-1 means use IVSize() - virtual void Resynchronize(const byte *iv, int ivLength=-1) {throw NotImplemented(GetAlgorithm().AlgorithmName() + ": this object doesn't support resynchronization");} - //! get a secure IV for the next message - /*! This method should be called after you finish encrypting one message and are ready to start the next one. - After calling it, you must call SetKey() or Resynchronize() before using this object again. - This method is not implemented on decryption objects. */ - virtual void GetNextIV(RandomNumberGenerator &rng, byte *IV); - -protected: - virtual const Algorithm & GetAlgorithm() const =0; - virtual void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) =0; - - void ThrowIfInvalidKeyLength(size_t length); - void ThrowIfResynchronizable(); // to be called when no IV is passed - void ThrowIfInvalidIV(const byte *iv); // check for NULL IV if it can't be used - size_t ThrowIfInvalidIVLength(int size); - const byte * GetIVAndThrowIfInvalid(const NameValuePairs ¶ms, size_t &size); - inline void AssertValidKeyLength(size_t length) const - {assert(IsValidKeyLength(length));} -}; - -//! interface for the data processing part of block ciphers - -/*! Classes derived from BlockTransformation are block ciphers - in ECB mode (for example the DES::Encryption class), which are stateless. - These classes should not be used directly, but only in combination with - a mode class (see CipherModeDocumentation in modes.h). -*/ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockTransformation : public Algorithm -{ -public: - //! encrypt or decrypt inBlock, xor with xorBlock, and write to outBlock - virtual void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const =0; - - //! encrypt or decrypt one block - /*! \pre size of inBlock and outBlock == BlockSize() */ - void ProcessBlock(const byte *inBlock, byte *outBlock) const - {ProcessAndXorBlock(inBlock, NULL, outBlock);} - - //! encrypt or decrypt one block in place - void ProcessBlock(byte *inoutBlock) const - {ProcessAndXorBlock(inoutBlock, NULL, inoutBlock);} - - //! block size of the cipher in bytes - virtual unsigned int BlockSize() const =0; - - //! returns how inputs and outputs should be aligned for optimal performance - virtual unsigned int OptimalDataAlignment() const; - - //! returns true if this is a permutation (i.e. there is an inverse transformation) - virtual bool IsPermutation() const {return true;} - - //! returns true if this is an encryption object - virtual bool IsForwardTransformation() const =0; - - //! return number of blocks that can be processed in parallel, for bit-slicing implementations - virtual unsigned int OptimalNumberOfParallelBlocks() const {return 1;} - - enum {BT_InBlockIsCounter=1, BT_DontIncrementInOutPointers=2, BT_XorInput=4, BT_ReverseDirection=8, BT_AllowParallel=16} FlagsForAdvancedProcessBlocks; - - //! encrypt and xor blocks according to flags (see FlagsForAdvancedProcessBlocks) - /*! /note If BT_InBlockIsCounter is set, last byte of inBlocks may be modified. */ - virtual size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const; - - inline CipherDir GetCipherDirection() const {return IsForwardTransformation() ? ENCRYPTION : DECRYPTION;} -}; - -//! interface for the data processing part of stream ciphers - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE StreamTransformation : public Algorithm -{ -public: - //! return a reference to this object, useful for passing a temporary object to a function that takes a non-const reference - StreamTransformation& Ref() {return *this;} - - //! returns block size, if input must be processed in blocks, otherwise 1 - virtual unsigned int MandatoryBlockSize() const {return 1;} - - //! returns the input block size that is most efficient for this cipher - /*! \note optimal input length is n * OptimalBlockSize() - GetOptimalBlockSizeUsed() for any n > 0 */ - virtual unsigned int OptimalBlockSize() const {return MandatoryBlockSize();} - //! returns how much of the current block is used up - virtual unsigned int GetOptimalBlockSizeUsed() const {return 0;} - - //! returns how input should be aligned for optimal performance - virtual unsigned int OptimalDataAlignment() const; - - //! encrypt or decrypt an array of bytes of specified length - /*! \note either inString == outString, or they don't overlap */ - virtual void ProcessData(byte *outString, const byte *inString, size_t length) =0; - - //! for ciphers where the last block of data is special, encrypt or decrypt the last block of data - /*! For now the only use of this function is for CBC-CTS mode. */ - virtual void ProcessLastBlock(byte *outString, const byte *inString, size_t length); - //! returns the minimum size of the last block, 0 indicating the last block is not special - virtual unsigned int MinLastBlockSize() const {return 0;} - - //! same as ProcessData(inoutString, inoutString, length) - inline void ProcessString(byte *inoutString, size_t length) - {ProcessData(inoutString, inoutString, length);} - //! same as ProcessData(outString, inString, length) - inline void ProcessString(byte *outString, const byte *inString, size_t length) - {ProcessData(outString, inString, length);} - //! implemented as {ProcessData(&input, &input, 1); return input;} - inline byte ProcessByte(byte input) - {ProcessData(&input, &input, 1); return input;} - - //! returns whether this cipher supports random access - virtual bool IsRandomAccess() const =0; - //! for random access ciphers, seek to an absolute position - virtual void Seek(lword n) - { - assert(!IsRandomAccess()); - throw NotImplemented("StreamTransformation: this object doesn't support random access"); - } - - //! returns whether this transformation is self-inverting (e.g. xor with a keystream) - virtual bool IsSelfInverting() const =0; - //! returns whether this is an encryption object - virtual bool IsForwardTransformation() const =0; -}; - -//! interface for hash functions and data processing part of MACs - -/*! HashTransformation objects are stateful. They are created in an initial state, - change state as Update() is called, and return to the initial - state when Final() is called. This interface allows a large message to - be hashed in pieces by calling Update() on each piece followed by - calling Final(). -*/ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE HashTransformation : public Algorithm -{ -public: - //! return a reference to this object, useful for passing a temporary object to a function that takes a non-const reference - HashTransformation& Ref() {return *this;} - - //! process more input - virtual void Update(const byte *input, size_t length) =0; - - //! request space to write input into - virtual byte * CreateUpdateSpace(size_t &size) {size=0; return NULL;} - - //! compute hash for current message, then restart for a new message - /*! \pre size of digest == DigestSize(). */ - virtual void Final(byte *digest) - {TruncatedFinal(digest, DigestSize());} - - //! discard the current state, and restart with a new message - virtual void Restart() - {TruncatedFinal(NULL, 0);} - - //! size of the hash/digest/MAC returned by Final() - virtual unsigned int DigestSize() const =0; - - //! same as DigestSize() - unsigned int TagSize() const {return DigestSize();} - - - //! block size of underlying compression function, or 0 if not block based - virtual unsigned int BlockSize() const {return 0;} - - //! input to Update() should have length a multiple of this for optimal speed - virtual unsigned int OptimalBlockSize() const {return 1;} - - //! returns how input should be aligned for optimal performance - virtual unsigned int OptimalDataAlignment() const; - - //! use this if your input is in one piece and you don't want to call Update() and Final() separately - virtual void CalculateDigest(byte *digest, const byte *input, size_t length) - {Update(input, length); Final(digest);} - - //! verify that digest is a valid digest for the current message, then reinitialize the object - /*! Default implementation is to call Final() and do a bitwise comparison - between its output and digest. */ - virtual bool Verify(const byte *digest) - {return TruncatedVerify(digest, DigestSize());} - - //! use this if your input is in one piece and you don't want to call Update() and Verify() separately - virtual bool VerifyDigest(const byte *digest, const byte *input, size_t length) - {Update(input, length); return Verify(digest);} - - //! truncated version of Final() - virtual void TruncatedFinal(byte *digest, size_t digestSize) =0; - - //! truncated version of CalculateDigest() - virtual void CalculateTruncatedDigest(byte *digest, size_t digestSize, const byte *input, size_t length) - {Update(input, length); TruncatedFinal(digest, digestSize);} - - //! truncated version of Verify() - virtual bool TruncatedVerify(const byte *digest, size_t digestLength); - - //! truncated version of VerifyDigest() - virtual bool VerifyTruncatedDigest(const byte *digest, size_t digestLength, const byte *input, size_t length) - {Update(input, length); return TruncatedVerify(digest, digestLength);} - -protected: - void ThrowIfInvalidTruncatedSize(size_t size) const; -}; - -typedef HashTransformation HashFunction; - -//! interface for one direction (encryption or decryption) of a block cipher -/*! \note These objects usually should not be used directly. See BlockTransformation for more details. */ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockCipher : public SimpleKeyingInterface, public BlockTransformation -{ -protected: - const Algorithm & GetAlgorithm() const {return *this;} -}; - -//! interface for one direction (encryption or decryption) of a stream cipher or cipher mode -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SymmetricCipher : public SimpleKeyingInterface, public StreamTransformation -{ -protected: - const Algorithm & GetAlgorithm() const {return *this;} -}; - -//! interface for message authentication codes -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE MessageAuthenticationCode : public SimpleKeyingInterface, public HashTransformation -{ -protected: - const Algorithm & GetAlgorithm() const {return *this;} -}; - -//! interface for for one direction (encryption or decryption) of a stream cipher or block cipher mode with authentication -/*! The StreamTransformation part of this interface is used to encrypt/decrypt the data, and the MessageAuthenticationCode part of this - interface is used to input additional authenticated data (AAD, which is MAC'ed but not encrypted), and to generate/verify the MAC. */ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipher : public MessageAuthenticationCode, public StreamTransformation -{ -public: - //! this indicates that a member function was called in the wrong state, for example trying to encrypt a message before having set the key or IV - class BadState : public Exception - { - public: - explicit BadState(const std::string &name, const char *message) : Exception(OTHER_ERROR, name + ": " + message) {} - explicit BadState(const std::string &name, const char *function, const char *state) : Exception(OTHER_ERROR, name + ": " + function + " was called before " + state) {} - }; - - //! the maximum length of AAD that can be input before the encrypted data - virtual lword MaxHeaderLength() const =0; - //! the maximum length of encrypted data - virtual lword MaxMessageLength() const =0; - //! the maximum length of AAD that can be input after the encrypted data - virtual lword MaxFooterLength() const {return 0;} - //! if this function returns true, SpecifyDataLengths() must be called before attempting to input data - /*! This is the case for some schemes, such as CCM. */ - virtual bool NeedsPrespecifiedDataLengths() const {return false;} - //! this function only needs to be called if NeedsPrespecifiedDataLengths() returns true - void SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength=0); - //! encrypt and generate MAC in one call. will truncate MAC if macSize < TagSize() - virtual void EncryptAndAuthenticate(byte *ciphertext, byte *mac, size_t macSize, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *message, size_t messageLength); - //! decrypt and verify MAC in one call, returning true iff MAC is valid. will assume MAC is truncated if macLength < TagSize() - virtual bool DecryptAndVerify(byte *message, const byte *mac, size_t macLength, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *ciphertext, size_t ciphertextLength); - - // redeclare this to avoid compiler ambiguity errors - virtual std::string AlgorithmName() const =0; - -protected: - const Algorithm & GetAlgorithm() const {return *static_cast(this);} - virtual void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength) {} -}; - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY -typedef SymmetricCipher StreamCipher; -#endif - -//! interface for random number generators -/*! All return values are uniformly distributed over the range specified. -*/ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE RandomNumberGenerator : public Algorithm -{ -public: - //! update RNG state with additional unpredictable values - virtual void IncorporateEntropy(const byte *input, size_t length) {throw NotImplemented("RandomNumberGenerator: IncorporateEntropy not implemented");} - - //! returns true if IncorporateEntropy is implemented - virtual bool CanIncorporateEntropy() const {return false;} - - //! generate new random byte and return it - virtual byte GenerateByte(); - - //! generate new random bit and return it - /*! Default implementation is to call GenerateByte() and return its lowest bit. */ - virtual unsigned int GenerateBit(); - - //! generate a random 32 bit word in the range min to max, inclusive - virtual word32 GenerateWord32(word32 a=0, word32 b=0xffffffffL); - - //! generate random array of bytes - virtual void GenerateBlock(byte *output, size_t size); - - //! generate and discard n bytes - virtual void DiscardBytes(size_t n); - - //! generate random bytes as input to a BufferedTransformation - virtual void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length); - - //! randomly shuffle the specified array, resulting permutation is uniformly distributed - template void Shuffle(IT begin, IT end) - { - for (; begin != end; ++begin) - std::iter_swap(begin, begin + GenerateWord32(0, end-begin-1)); - } - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - byte GetByte() {return GenerateByte();} - unsigned int GetBit() {return GenerateBit();} - word32 GetLong(word32 a=0, word32 b=0xffffffffL) {return GenerateWord32(a, b);} - word16 GetShort(word16 a=0, word16 b=0xffff) {return (word16)GenerateWord32(a, b);} - void GetBlock(byte *output, size_t size) {GenerateBlock(output, size);} -#endif -}; - -//! returns a reference that can be passed to functions that ask for a RNG but doesn't actually use it -CRYPTOPP_DLL RandomNumberGenerator & CRYPTOPP_API NullRNG(); - -class WaitObjectContainer; -class CallStack; - -//! interface for objects that you can wait for - -class CRYPTOPP_NO_VTABLE Waitable -{ -public: - virtual ~Waitable() {} - - //! maximum number of wait objects that this object can return - virtual unsigned int GetMaxWaitObjectCount() const =0; - //! put wait objects into container - /*! \param callStack is used for tracing no wait loops, example: - something.GetWaitObjects(c, CallStack("my func after X", 0)); - - or in an outer GetWaitObjects() method that itself takes a callStack parameter: - innerThing.GetWaitObjects(c, CallStack("MyClass::GetWaitObjects at X", &callStack)); */ - virtual void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) =0; - //! wait on this object - /*! same as creating an empty container, calling GetWaitObjects(), and calling Wait() on the container */ - bool Wait(unsigned long milliseconds, CallStack const& callStack); -}; - -//! the default channel for BufferedTransformation, equal to the empty string -extern CRYPTOPP_DLL const std::string DEFAULT_CHANNEL; - -//! channel for additional authenticated data, equal to "AAD" -extern CRYPTOPP_DLL const std::string AAD_CHANNEL; - -//! interface for buffered transformations - -/*! BufferedTransformation is a generalization of BlockTransformation, - StreamTransformation, and HashTransformation. - - A buffered transformation is an object that takes a stream of bytes - as input (this may be done in stages), does some computation on them, and - then places the result into an internal buffer for later retrieval. Any - partial result already in the output buffer is not modified by further - input. - - If a method takes a "blocking" parameter, and you - pass "false" for it, the method will return before all input has been processed if - the input cannot be processed without waiting (for network buffers to become available, for example). - In this case the method will return true - or a non-zero integer value. When this happens you must continue to call the method with the same - parameters until it returns false or zero, before calling any other method on it or - attached BufferedTransformation. The integer return value in this case is approximately - the number of bytes left to be processed, and can be used to implement a progress bar. - - For functions that take a "propagation" parameter, propagation != 0 means pass on the signal to attached - BufferedTransformation objects, with propagation decremented at each step until it reaches 0. - -1 means unlimited propagation. - - \nosubgrouping -*/ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BufferedTransformation : public Algorithm, public Waitable -{ -public: - // placed up here for CW8 - static const std::string &NULL_CHANNEL; // same as DEFAULT_CHANNEL, for backwards compatibility - - BufferedTransformation() : Algorithm(false) {} - - //! return a reference to this object, useful for passing a temporary object to a function that takes a non-const reference - BufferedTransformation& Ref() {return *this;} - - //! \name INPUT - //@{ - //! input a byte for processing - size_t Put(byte inByte, bool blocking=true) - {return Put(&inByte, 1, blocking);} - //! input multiple bytes - size_t Put(const byte *inString, size_t length, bool blocking=true) - {return Put2(inString, length, 0, blocking);} - - //! input a 16-bit word - size_t PutWord16(word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true); - //! input a 32-bit word - size_t PutWord32(word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true); - - //! request space which can be written into by the caller, and then used as input to Put() - /*! \param size is requested size (as a hint) for input, and size of the returned space for output */ - /*! \note The purpose of this method is to help avoid doing extra memory allocations. */ - virtual byte * CreatePutSpace(size_t &size) {size=0; return NULL;} - - virtual bool CanModifyInput() const {return false;} - - //! input multiple bytes that may be modified by callee - size_t PutModifiable(byte *inString, size_t length, bool blocking=true) - {return PutModifiable2(inString, length, 0, blocking);} - - bool MessageEnd(int propagation=-1, bool blocking=true) - {return !!Put2(NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);} - size_t PutMessageEnd(const byte *inString, size_t length, int propagation=-1, bool blocking=true) - {return Put2(inString, length, propagation < 0 ? -1 : propagation+1, blocking);} - - //! input multiple bytes for blocking or non-blocking processing - /*! \param messageEnd means how many filters to signal MessageEnd to, including this one */ - virtual size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking) =0; - //! input multiple bytes that may be modified by callee for blocking or non-blocking processing - /*! \param messageEnd means how many filters to signal MessageEnd to, including this one */ - virtual size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking) - {return Put2(inString, length, messageEnd, blocking);} - - //! thrown by objects that have not implemented nonblocking input processing - struct BlockingInputOnly : public NotImplemented - {BlockingInputOnly(const std::string &s) : NotImplemented(s + ": Nonblocking input is not implemented by this object.") {}}; - //@} - - //! \name WAITING - //@{ - unsigned int GetMaxWaitObjectCount() const; - void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack); - //@} - - //! \name SIGNALS - //@{ - virtual void IsolatedInitialize(const NameValuePairs ¶meters) {throw NotImplemented("BufferedTransformation: this object can't be reinitialized");} - virtual bool IsolatedFlush(bool hardFlush, bool blocking) =0; - virtual bool IsolatedMessageSeriesEnd(bool blocking) {return false;} - - //! initialize or reinitialize this object - virtual void Initialize(const NameValuePairs ¶meters=g_nullNameValuePairs, int propagation=-1); - //! flush buffered input and/or output - /*! \param hardFlush is used to indicate whether all data should be flushed - \note Hard flushes must be used with care. It means try to process and output everything, even if - there may not be enough data to complete the action. For example, hard flushing a HexDecoder would - cause an error if you do it after inputing an odd number of hex encoded characters. - For some types of filters, for example ZlibDecompressor, hard flushes can only - be done at "synchronization points". These synchronization points are positions in the data - stream that are created by hard flushes on the corresponding reverse filters, in this - example ZlibCompressor. This is useful when zlib compressed data is moved across a - network in packets and compression state is preserved across packets, as in the ssh2 protocol. - */ - virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true); - //! mark end of a series of messages - /*! There should be a MessageEnd immediately before MessageSeriesEnd. */ - virtual bool MessageSeriesEnd(int propagation=-1, bool blocking=true); - - //! set propagation of automatically generated and transferred signals - /*! propagation == 0 means do not automaticly generate signals */ - virtual void SetAutoSignalPropagation(int propagation) {} - - //! - virtual int GetAutoSignalPropagation() const {return 0;} -public: - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - void Close() {MessageEnd();} -#endif - //@} - - //! \name RETRIEVAL OF ONE MESSAGE - //@{ - //! returns number of bytes that is currently ready for retrieval - /*! All retrieval functions return the actual number of bytes - retrieved, which is the lesser of the request number and - MaxRetrievable(). */ - virtual lword MaxRetrievable() const; - - //! returns whether any bytes are currently ready for retrieval - virtual bool AnyRetrievable() const; - - //! try to retrieve a single byte - virtual size_t Get(byte &outByte); - //! try to retrieve multiple bytes - virtual size_t Get(byte *outString, size_t getMax); - - //! peek at the next byte without removing it from the output buffer - virtual size_t Peek(byte &outByte) const; - //! peek at multiple bytes without removing them from the output buffer - virtual size_t Peek(byte *outString, size_t peekMax) const; - - //! try to retrieve a 16-bit word - size_t GetWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER); - //! try to retrieve a 32-bit word - size_t GetWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER); - - //! try to peek at a 16-bit word - size_t PeekWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER) const; - //! try to peek at a 32-bit word - size_t PeekWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER) const; - - //! move transferMax bytes of the buffered output to target as input - lword TransferTo(BufferedTransformation &target, lword transferMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) - {TransferTo2(target, transferMax, channel); return transferMax;} - - //! discard skipMax bytes from the output buffer - virtual lword Skip(lword skipMax=LWORD_MAX); - - //! copy copyMax bytes of the buffered output to target as input - lword CopyTo(BufferedTransformation &target, lword copyMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) const - {return CopyRangeTo(target, 0, copyMax, channel);} - - //! copy copyMax bytes of the buffered output, starting at position (relative to current position), to target as input - lword CopyRangeTo(BufferedTransformation &target, lword position, lword copyMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) const - {lword i = position; CopyRangeTo2(target, i, i+copyMax, channel); return i-position;} - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - unsigned long MaxRetrieveable() const {return MaxRetrievable();} -#endif - //@} - - //! \name RETRIEVAL OF MULTIPLE MESSAGES - //@{ - //! - virtual lword TotalBytesRetrievable() const; - //! number of times MessageEnd() has been received minus messages retrieved or skipped - virtual unsigned int NumberOfMessages() const; - //! returns true if NumberOfMessages() > 0 - virtual bool AnyMessages() const; - //! start retrieving the next message - /*! - Returns false if no more messages exist or this message - is not completely retrieved. - */ - virtual bool GetNextMessage(); - //! skip count number of messages - virtual unsigned int SkipMessages(unsigned int count=UINT_MAX); - //! - unsigned int TransferMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) - {TransferMessagesTo2(target, count, channel); return count;} - //! - unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const; - - //! - virtual void SkipAll(); - //! - void TransferAllTo(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL) - {TransferAllTo2(target, channel);} - //! - void CopyAllTo(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL) const; - - virtual bool GetNextMessageSeries() {return false;} - virtual unsigned int NumberOfMessagesInThisSeries() const {return NumberOfMessages();} - virtual unsigned int NumberOfMessageSeries() const {return 0;} - //@} - - //! \name NON-BLOCKING TRANSFER OF OUTPUT - //@{ - //! upon return, byteCount contains number of bytes that have finished being transfered, and returns the number of bytes left in the current transfer block - virtual size_t TransferTo2(BufferedTransformation &target, lword &byteCount, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) =0; - //! upon return, begin contains the start position of data yet to be finished copying, and returns the number of bytes left in the current transfer block - virtual size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const =0; - //! upon return, messageCount contains number of messages that have finished being transfered, and returns the number of bytes left in the current transfer block - size_t TransferMessagesTo2(BufferedTransformation &target, unsigned int &messageCount, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - //! returns the number of bytes left in the current transfer block - size_t TransferAllTo2(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - //@} - - //! \name CHANNELS - //@{ - struct NoChannelSupport : public NotImplemented - {NoChannelSupport(const std::string &name) : NotImplemented(name + ": this object doesn't support multiple channels") {}}; - struct InvalidChannelName : public InvalidArgument - {InvalidChannelName(const std::string &name, const std::string &channel) : InvalidArgument(name + ": unexpected channel name \"" + channel + "\"") {}}; - - size_t ChannelPut(const std::string &channel, byte inByte, bool blocking=true) - {return ChannelPut(channel, &inByte, 1, blocking);} - size_t ChannelPut(const std::string &channel, const byte *inString, size_t length, bool blocking=true) - {return ChannelPut2(channel, inString, length, 0, blocking);} - - size_t ChannelPutModifiable(const std::string &channel, byte *inString, size_t length, bool blocking=true) - {return ChannelPutModifiable2(channel, inString, length, 0, blocking);} - - size_t ChannelPutWord16(const std::string &channel, word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true); - size_t ChannelPutWord32(const std::string &channel, word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true); - - bool ChannelMessageEnd(const std::string &channel, int propagation=-1, bool blocking=true) - {return !!ChannelPut2(channel, NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);} - size_t ChannelPutMessageEnd(const std::string &channel, const byte *inString, size_t length, int propagation=-1, bool blocking=true) - {return ChannelPut2(channel, inString, length, propagation < 0 ? -1 : propagation+1, blocking);} - - virtual byte * ChannelCreatePutSpace(const std::string &channel, size_t &size); - - virtual size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking); - virtual size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking); - - virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true); - virtual bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true); - - virtual void SetRetrievalChannel(const std::string &channel); - //@} - - //! \name ATTACHMENT - /*! Some BufferedTransformation objects (e.g. Filter objects) - allow other BufferedTransformation objects to be attached. When - this is done, the first object instead of buffering its output, - sents that output to the attached object as input. The entire - attachment chain is deleted when the anchor object is destructed. - */ - //@{ - //! returns whether this object allows attachment - virtual bool Attachable() {return false;} - //! returns the object immediately attached to this object or NULL for no attachment - virtual BufferedTransformation *AttachedTransformation() {assert(!Attachable()); return 0;} - //! - virtual const BufferedTransformation *AttachedTransformation() const - {return const_cast(this)->AttachedTransformation();} - //! delete the current attachment chain and replace it with newAttachment - virtual void Detach(BufferedTransformation *newAttachment = 0) - {assert(!Attachable()); throw NotImplemented("BufferedTransformation: this object is not attachable");} - //! add newAttachment to the end of attachment chain - virtual void Attach(BufferedTransformation *newAttachment); - //@} - -protected: - static int DecrementPropagation(int propagation) - {return propagation != 0 ? propagation - 1 : 0;} - -private: - byte m_buf[4]; // for ChannelPutWord16 and ChannelPutWord32, to ensure buffer isn't deallocated before non-blocking operation completes -}; - -//! returns a reference to a BufferedTransformation object that discards all input -BufferedTransformation & TheBitBucket(); - -//! interface for crypto material, such as public and private keys, and crypto parameters - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CryptoMaterial : public NameValuePairs -{ -public: - //! exception thrown when invalid crypto material is detected - class CRYPTOPP_DLL InvalidMaterial : public InvalidDataFormat - { - public: - explicit InvalidMaterial(const std::string &s) : InvalidDataFormat(s) {} - }; - - //! assign values from source to this object - /*! \note This function can be used to create a public key from a private key. */ - virtual void AssignFrom(const NameValuePairs &source) =0; - - //! check this object for errors - /*! \param level denotes the level of thoroughness: - 0 - using this object won't cause a crash or exception (rng is ignored) - 1 - this object will probably function (encrypt, sign, etc.) correctly (but may not check for weak keys and such) - 2 - make sure this object will function correctly, and do reasonable security checks - 3 - do checks that may take a long time - \return true if the tests pass */ - virtual bool Validate(RandomNumberGenerator &rng, unsigned int level) const =0; - - //! throws InvalidMaterial if this object fails Validate() test - virtual void ThrowIfInvalid(RandomNumberGenerator &rng, unsigned int level) const - {if (!Validate(rng, level)) throw InvalidMaterial("CryptoMaterial: this object contains invalid values");} - -// virtual std::vector GetSupportedFormats(bool includeSaveOnly=false, bool includeLoadOnly=false); - - //! save key into a BufferedTransformation - virtual void Save(BufferedTransformation &bt) const - {throw NotImplemented("CryptoMaterial: this object does not support saving");} - - //! load key from a BufferedTransformation - /*! \throws KeyingErr if decode fails - \note Generally does not check that the key is valid. - Call ValidateKey() or ThrowIfInvalidKey() to check that. */ - virtual void Load(BufferedTransformation &bt) - {throw NotImplemented("CryptoMaterial: this object does not support loading");} - - //! \return whether this object supports precomputation - virtual bool SupportsPrecomputation() const {return false;} - //! do precomputation - /*! The exact semantics of Precompute() is varies, but - typically it means calculate a table of n objects - that can be used later to speed up computation. */ - virtual void Precompute(unsigned int n) - {assert(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");} - //! retrieve previously saved precomputation - virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation) - {assert(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");} - //! save precomputation for later use - virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const - {assert(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");} - - // for internal library use - void DoQuickSanityCheck() const {ThrowIfInvalid(NullRNG(), 0);} - -#if (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) - // Sun Studio 11/CC 5.8 workaround: it generates incorrect code when casting to an empty virtual base class - char m_sunCCworkaround; -#endif -}; - -//! interface for generatable crypto material, such as private keys and crypto parameters - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE GeneratableCryptoMaterial : virtual public CryptoMaterial -{ -public: - //! generate a random key or crypto parameters - /*! \throws KeyingErr if algorithm parameters are invalid, or if a key can't be generated - (e.g., if this is a public key object) */ - virtual void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms = g_nullNameValuePairs) - {throw NotImplemented("GeneratableCryptoMaterial: this object does not support key/parameter generation");} - - //! calls the above function with a NameValuePairs object that just specifies "KeySize" - void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize); -}; - -//! interface for public keys - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PublicKey : virtual public CryptoMaterial -{ -}; - -//! interface for private keys - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PrivateKey : public GeneratableCryptoMaterial -{ -}; - -//! interface for crypto prameters - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CryptoParameters : public GeneratableCryptoMaterial -{ -}; - -//! interface for asymmetric algorithms - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AsymmetricAlgorithm : public Algorithm -{ -public: - //! returns a reference to the crypto material used by this object - virtual CryptoMaterial & AccessMaterial() =0; - //! returns a const reference to the crypto material used by this object - virtual const CryptoMaterial & GetMaterial() const =0; - - //! for backwards compatibility, calls AccessMaterial().Load(bt) - void BERDecode(BufferedTransformation &bt) - {AccessMaterial().Load(bt);} - //! for backwards compatibility, calls GetMaterial().Save(bt) - void DEREncode(BufferedTransformation &bt) const - {GetMaterial().Save(bt);} -}; - -//! interface for asymmetric algorithms using public keys - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PublicKeyAlgorithm : public AsymmetricAlgorithm -{ -public: - // VC60 workaround: no co-variant return type - CryptoMaterial & AccessMaterial() {return AccessPublicKey();} - const CryptoMaterial & GetMaterial() const {return GetPublicKey();} - - virtual PublicKey & AccessPublicKey() =0; - virtual const PublicKey & GetPublicKey() const {return const_cast(this)->AccessPublicKey();} -}; - -//! interface for asymmetric algorithms using private keys - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PrivateKeyAlgorithm : public AsymmetricAlgorithm -{ -public: - CryptoMaterial & AccessMaterial() {return AccessPrivateKey();} - const CryptoMaterial & GetMaterial() const {return GetPrivateKey();} - - virtual PrivateKey & AccessPrivateKey() =0; - virtual const PrivateKey & GetPrivateKey() const {return const_cast(this)->AccessPrivateKey();} -}; - -//! interface for key agreement algorithms - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE KeyAgreementAlgorithm : public AsymmetricAlgorithm -{ -public: - CryptoMaterial & AccessMaterial() {return AccessCryptoParameters();} - const CryptoMaterial & GetMaterial() const {return GetCryptoParameters();} - - virtual CryptoParameters & AccessCryptoParameters() =0; - virtual const CryptoParameters & GetCryptoParameters() const {return const_cast(this)->AccessCryptoParameters();} -}; - -//! interface for public-key encryptors and decryptors - -/*! This class provides an interface common to encryptors and decryptors - for querying their plaintext and ciphertext lengths. -*/ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_CryptoSystem -{ -public: - virtual ~PK_CryptoSystem() {} - - //! maximum length of plaintext for a given ciphertext length - /*! \note This function returns 0 if ciphertextLength is not valid (too long or too short). */ - virtual size_t MaxPlaintextLength(size_t ciphertextLength) const =0; - - //! calculate length of ciphertext given length of plaintext - /*! \note This function returns 0 if plaintextLength is not valid (too long). */ - virtual size_t CiphertextLength(size_t plaintextLength) const =0; - - //! this object supports the use of the parameter with the given name - /*! some possible parameter names: EncodingParameters, KeyDerivationParameters */ - virtual bool ParameterSupported(const char *name) const =0; - - //! return fixed ciphertext length, if one exists, otherwise return 0 - /*! \note "Fixed" here means length of ciphertext does not depend on length of plaintext. - It usually does depend on the key length. */ - virtual size_t FixedCiphertextLength() const {return 0;} - - //! return maximum plaintext length given the fixed ciphertext length, if one exists, otherwise return 0 - virtual size_t FixedMaxPlaintextLength() const {return 0;} - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - size_t MaxPlainTextLength(size_t cipherTextLength) const {return MaxPlaintextLength(cipherTextLength);} - size_t CipherTextLength(size_t plainTextLength) const {return CiphertextLength(plainTextLength);} -#endif -}; - -//! interface for public-key encryptors -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_Encryptor : public PK_CryptoSystem, public PublicKeyAlgorithm -{ -public: - //! exception thrown when trying to encrypt plaintext of invalid length - class CRYPTOPP_DLL InvalidPlaintextLength : public Exception - { - public: - InvalidPlaintextLength() : Exception(OTHER_ERROR, "PK_Encryptor: invalid plaintext length") {} - }; - - //! encrypt a byte string - /*! \pre CiphertextLength(plaintextLength) != 0 (i.e., plaintext isn't too long) - \pre size of ciphertext == CiphertextLength(plaintextLength) - */ - virtual void Encrypt(RandomNumberGenerator &rng, - const byte *plaintext, size_t plaintextLength, - byte *ciphertext, const NameValuePairs ¶meters = g_nullNameValuePairs) const =0; - - //! create a new encryption filter - /*! \note The caller is responsible for deleting the returned pointer. - \note Encoding parameters should be passed in the "EP" channel. - */ - virtual BufferedTransformation * CreateEncryptionFilter(RandomNumberGenerator &rng, - BufferedTransformation *attachment=NULL, const NameValuePairs ¶meters = g_nullNameValuePairs) const; -}; - -//! interface for public-key decryptors - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_Decryptor : public PK_CryptoSystem, public PrivateKeyAlgorithm -{ -public: - //! decrypt a byte string, and return the length of plaintext - /*! \pre size of plaintext == MaxPlaintextLength(ciphertextLength) bytes. - \return the actual length of the plaintext, indication that decryption failed. - */ - virtual DecodingResult Decrypt(RandomNumberGenerator &rng, - const byte *ciphertext, size_t ciphertextLength, - byte *plaintext, const NameValuePairs ¶meters = g_nullNameValuePairs) const =0; - - //! create a new decryption filter - /*! \note caller is responsible for deleting the returned pointer - */ - virtual BufferedTransformation * CreateDecryptionFilter(RandomNumberGenerator &rng, - BufferedTransformation *attachment=NULL, const NameValuePairs ¶meters = g_nullNameValuePairs) const; - - //! decrypt a fixed size ciphertext - DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *ciphertext, byte *plaintext, const NameValuePairs ¶meters = g_nullNameValuePairs) const - {return Decrypt(rng, ciphertext, FixedCiphertextLength(), plaintext, parameters);} -}; - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY -typedef PK_CryptoSystem PK_FixedLengthCryptoSystem; -typedef PK_Encryptor PK_FixedLengthEncryptor; -typedef PK_Decryptor PK_FixedLengthDecryptor; -#endif - -//! interface for public-key signers and verifiers - -/*! This class provides an interface common to signers and verifiers - for querying scheme properties. -*/ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_SignatureScheme -{ -public: - //! invalid key exception, may be thrown by any function in this class if the private or public key has a length that can't be used - class CRYPTOPP_DLL InvalidKeyLength : public Exception - { - public: - InvalidKeyLength(const std::string &message) : Exception(OTHER_ERROR, message) {} - }; - - //! key too short exception, may be thrown by any function in this class if the private or public key is too short to sign or verify anything - class CRYPTOPP_DLL KeyTooShort : public InvalidKeyLength - { - public: - KeyTooShort() : InvalidKeyLength("PK_Signer: key too short for this signature scheme") {} - }; - - virtual ~PK_SignatureScheme() {} - - //! signature length if it only depends on the key, otherwise 0 - virtual size_t SignatureLength() const =0; - - //! maximum signature length produced for a given length of recoverable message part - virtual size_t MaxSignatureLength(size_t recoverablePartLength = 0) const {return SignatureLength();} - - //! length of longest message that can be recovered, or 0 if this signature scheme does not support message recovery - virtual size_t MaxRecoverableLength() const =0; - - //! length of longest message that can be recovered from a signature of given length, or 0 if this signature scheme does not support message recovery - virtual size_t MaxRecoverableLengthFromSignatureLength(size_t signatureLength) const =0; - - //! requires a random number generator to sign - /*! if this returns false, NullRNG() can be passed to functions that take RandomNumberGenerator & */ - virtual bool IsProbabilistic() const =0; - - //! whether or not a non-recoverable message part can be signed - virtual bool AllowNonrecoverablePart() const =0; - - //! if this function returns true, during verification you must input the signature before the message, otherwise you can input it at anytime */ - virtual bool SignatureUpfront() const {return false;} - - //! whether you must input the recoverable part before the non-recoverable part during signing - virtual bool RecoverablePartFirst() const =0; -}; - -//! interface for accumulating messages to be signed or verified -/*! Only Update() should be called - on this class. No other functions inherited from HashTransformation should be called. -*/ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_MessageAccumulator : public HashTransformation -{ -public: - //! should not be called on PK_MessageAccumulator - unsigned int DigestSize() const - {throw NotImplemented("PK_MessageAccumulator: DigestSize() should not be called");} - //! should not be called on PK_MessageAccumulator - void TruncatedFinal(byte *digest, size_t digestSize) - {throw NotImplemented("PK_MessageAccumulator: TruncatedFinal() should not be called");} -}; - -//! interface for public-key signers - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_Signer : public PK_SignatureScheme, public PrivateKeyAlgorithm -{ -public: - //! create a new HashTransformation to accumulate the message to be signed - virtual PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng) const =0; - - virtual void InputRecoverableMessage(PK_MessageAccumulator &messageAccumulator, const byte *recoverableMessage, size_t recoverableMessageLength) const =0; - - //! sign and delete messageAccumulator (even in case of exception thrown) - /*! \pre size of signature == MaxSignatureLength() - \return actual signature length - */ - virtual size_t Sign(RandomNumberGenerator &rng, PK_MessageAccumulator *messageAccumulator, byte *signature) const; - - //! sign and restart messageAccumulator - /*! \pre size of signature == MaxSignatureLength() - \return actual signature length - */ - virtual size_t SignAndRestart(RandomNumberGenerator &rng, PK_MessageAccumulator &messageAccumulator, byte *signature, bool restart=true) const =0; - - //! sign a message - /*! \pre size of signature == MaxSignatureLength() - \return actual signature length - */ - virtual size_t SignMessage(RandomNumberGenerator &rng, const byte *message, size_t messageLen, byte *signature) const; - - //! sign a recoverable message - /*! \pre size of signature == MaxSignatureLength(recoverableMessageLength) - \return actual signature length - */ - virtual size_t SignMessageWithRecovery(RandomNumberGenerator &rng, const byte *recoverableMessage, size_t recoverableMessageLength, - const byte *nonrecoverableMessage, size_t nonrecoverableMessageLength, byte *signature) const; -}; - -//! interface for public-key signature verifiers -/*! The Recover* functions throw NotImplemented if the signature scheme does not support - message recovery. - The Verify* functions throw InvalidDataFormat if the scheme does support message - recovery and the signature contains a non-empty recoverable message part. The - Recovery* functions should be used in that case. -*/ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_Verifier : public PK_SignatureScheme, public PublicKeyAlgorithm -{ -public: - //! create a new HashTransformation to accumulate the message to be verified - virtual PK_MessageAccumulator * NewVerificationAccumulator() const =0; - - //! input signature into a message accumulator - virtual void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, size_t signatureLength) const =0; - - //! check whether messageAccumulator contains a valid signature and message, and delete messageAccumulator (even in case of exception thrown) - virtual bool Verify(PK_MessageAccumulator *messageAccumulator) const; - - //! check whether messageAccumulator contains a valid signature and message, and restart messageAccumulator - virtual bool VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const =0; - - //! check whether input signature is a valid signature for input message - virtual bool VerifyMessage(const byte *message, size_t messageLen, - const byte *signature, size_t signatureLength) const; - - //! recover a message from its signature - /*! \pre size of recoveredMessage == MaxRecoverableLengthFromSignatureLength(signatureLength) - */ - virtual DecodingResult Recover(byte *recoveredMessage, PK_MessageAccumulator *messageAccumulator) const; - - //! recover a message from its signature - /*! \pre size of recoveredMessage == MaxRecoverableLengthFromSignatureLength(signatureLength) - */ - virtual DecodingResult RecoverAndRestart(byte *recoveredMessage, PK_MessageAccumulator &messageAccumulator) const =0; - - //! recover a message from its signature - /*! \pre size of recoveredMessage == MaxRecoverableLengthFromSignatureLength(signatureLength) - */ - virtual DecodingResult RecoverMessage(byte *recoveredMessage, - const byte *nonrecoverableMessage, size_t nonrecoverableMessageLength, - const byte *signature, size_t signatureLength) const; -}; - -//! interface for domains of simple key agreement protocols - -/*! A key agreement domain is a set of parameters that must be shared - by two parties in a key agreement protocol, along with the algorithms - for generating key pairs and deriving agreed values. -*/ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyAgreementDomain : public KeyAgreementAlgorithm -{ -public: - //! return length of agreed value produced - virtual unsigned int AgreedValueLength() const =0; - //! return length of private keys in this domain - virtual unsigned int PrivateKeyLength() const =0; - //! return length of public keys in this domain - virtual unsigned int PublicKeyLength() const =0; - //! generate private key - /*! \pre size of privateKey == PrivateKeyLength() */ - virtual void GeneratePrivateKey(RandomNumberGenerator &rng, byte *privateKey) const =0; - //! generate public key - /*! \pre size of publicKey == PublicKeyLength() */ - virtual void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0; - //! generate private/public key pair - /*! \note equivalent to calling GeneratePrivateKey() and then GeneratePublicKey() */ - virtual void GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const; - //! derive agreed value from your private key and couterparty's public key, return false in case of failure - /*! \note If you have previously validated the public key, use validateOtherPublicKey=false to save time. - \pre size of agreedValue == AgreedValueLength() - \pre length of privateKey == PrivateKeyLength() - \pre length of otherPublicKey == PublicKeyLength() - */ - virtual bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const =0; - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - bool ValidateDomainParameters(RandomNumberGenerator &rng) const - {return GetCryptoParameters().Validate(rng, 2);} -#endif -}; - -//! interface for domains of authenticated key agreement protocols - -/*! In an authenticated key agreement protocol, each party has two - key pairs. The long-lived key pair is called the static key pair, - and the short-lived key pair is called the ephemeral key pair. -*/ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedKeyAgreementDomain : public KeyAgreementAlgorithm -{ -public: - //! return length of agreed value produced - virtual unsigned int AgreedValueLength() const =0; - - //! return length of static private keys in this domain - virtual unsigned int StaticPrivateKeyLength() const =0; - //! return length of static public keys in this domain - virtual unsigned int StaticPublicKeyLength() const =0; - //! generate static private key - /*! \pre size of privateKey == PrivateStaticKeyLength() */ - virtual void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const =0; - //! generate static public key - /*! \pre size of publicKey == PublicStaticKeyLength() */ - virtual void GenerateStaticPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0; - //! generate private/public key pair - /*! \note equivalent to calling GenerateStaticPrivateKey() and then GenerateStaticPublicKey() */ - virtual void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const; - - //! return length of ephemeral private keys in this domain - virtual unsigned int EphemeralPrivateKeyLength() const =0; - //! return length of ephemeral public keys in this domain - virtual unsigned int EphemeralPublicKeyLength() const =0; - //! generate ephemeral private key - /*! \pre size of privateKey == PrivateEphemeralKeyLength() */ - virtual void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const =0; - //! generate ephemeral public key - /*! \pre size of publicKey == PublicEphemeralKeyLength() */ - virtual void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0; - //! generate private/public key pair - /*! \note equivalent to calling GenerateEphemeralPrivateKey() and then GenerateEphemeralPublicKey() */ - virtual void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const; - - //! derive agreed value from your private keys and couterparty's public keys, return false in case of failure - /*! \note The ephemeral public key will always be validated. - If you have previously validated the static public key, use validateStaticOtherPublicKey=false to save time. - \pre size of agreedValue == AgreedValueLength() - \pre length of staticPrivateKey == StaticPrivateKeyLength() - \pre length of ephemeralPrivateKey == EphemeralPrivateKeyLength() - \pre length of staticOtherPublicKey == StaticPublicKeyLength() - \pre length of ephemeralOtherPublicKey == EphemeralPublicKeyLength() - */ - virtual bool Agree(byte *agreedValue, - const byte *staticPrivateKey, const byte *ephemeralPrivateKey, - const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, - bool validateStaticOtherPublicKey=true) const =0; - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - bool ValidateDomainParameters(RandomNumberGenerator &rng) const - {return GetCryptoParameters().Validate(rng, 2);} -#endif -}; - -// interface for password authenticated key agreement protocols, not implemented yet -#if 0 -//! interface for protocol sessions -/*! The methods should be called in the following order: - - InitializeSession(rng, parameters); // or call initialize method in derived class - while (true) - { - if (OutgoingMessageAvailable()) - { - length = GetOutgoingMessageLength(); - GetOutgoingMessage(message); - ; // send outgoing message - } - - if (LastMessageProcessed()) - break; - - ; // receive incoming message - ProcessIncomingMessage(message); - } - ; // call methods in derived class to obtain result of protocol session -*/ -class ProtocolSession -{ -public: - //! exception thrown when an invalid protocol message is processed - class ProtocolError : public Exception - { - public: - ProtocolError(ErrorType errorType, const std::string &s) : Exception(errorType, s) {} - }; - - //! exception thrown when a function is called unexpectedly - /*! for example calling ProcessIncomingMessage() when ProcessedLastMessage() == true */ - class UnexpectedMethodCall : public Exception - { - public: - UnexpectedMethodCall(const std::string &s) : Exception(OTHER_ERROR, s) {} - }; - - ProtocolSession() : m_rng(NULL), m_throwOnProtocolError(true), m_validState(false) {} - virtual ~ProtocolSession() {} - - virtual void InitializeSession(RandomNumberGenerator &rng, const NameValuePairs ¶meters) =0; - - bool GetThrowOnProtocolError() const {return m_throwOnProtocolError;} - void SetThrowOnProtocolError(bool throwOnProtocolError) {m_throwOnProtocolError = throwOnProtocolError;} - - bool HasValidState() const {return m_validState;} - - virtual bool OutgoingMessageAvailable() const =0; - virtual unsigned int GetOutgoingMessageLength() const =0; - virtual void GetOutgoingMessage(byte *message) =0; - - virtual bool LastMessageProcessed() const =0; - virtual void ProcessIncomingMessage(const byte *message, unsigned int messageLength) =0; - -protected: - void HandleProtocolError(Exception::ErrorType errorType, const std::string &s) const; - void CheckAndHandleInvalidState() const; - void SetValidState(bool valid) {m_validState = valid;} - - RandomNumberGenerator *m_rng; - -private: - bool m_throwOnProtocolError, m_validState; -}; - -class KeyAgreementSession : public ProtocolSession -{ -public: - virtual unsigned int GetAgreedValueLength() const =0; - virtual void GetAgreedValue(byte *agreedValue) const =0; -}; - -class PasswordAuthenticatedKeyAgreementSession : public KeyAgreementSession -{ -public: - void InitializePasswordAuthenticatedKeyAgreementSession(RandomNumberGenerator &rng, - const byte *myId, unsigned int myIdLength, - const byte *counterPartyId, unsigned int counterPartyIdLength, - const byte *passwordOrVerifier, unsigned int passwordOrVerifierLength); -}; - -class PasswordAuthenticatedKeyAgreementDomain : public KeyAgreementAlgorithm -{ -public: - //! return whether the domain parameters stored in this object are valid - virtual bool ValidateDomainParameters(RandomNumberGenerator &rng) const - {return GetCryptoParameters().Validate(rng, 2);} - - virtual unsigned int GetPasswordVerifierLength(const byte *password, unsigned int passwordLength) const =0; - virtual void GeneratePasswordVerifier(RandomNumberGenerator &rng, const byte *userId, unsigned int userIdLength, const byte *password, unsigned int passwordLength, byte *verifier) const =0; - - enum RoleFlags {CLIENT=1, SERVER=2, INITIATOR=4, RESPONDER=8}; - - virtual bool IsValidRole(unsigned int role) =0; - virtual PasswordAuthenticatedKeyAgreementSession * CreateProtocolSession(unsigned int role) const =0; -}; -#endif - -//! BER Decode Exception Class, may be thrown during an ASN1 BER decode operation -class CRYPTOPP_DLL BERDecodeErr : public InvalidArgument -{ -public: - BERDecodeErr() : InvalidArgument("BER decode error") {} - BERDecodeErr(const std::string &s) : InvalidArgument(s) {} -}; - -//! interface for encoding and decoding ASN1 objects -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ASN1Object -{ -public: - virtual ~ASN1Object() {} - //! decode this object from a BufferedTransformation, using BER (Basic Encoding Rules) - virtual void BERDecode(BufferedTransformation &bt) =0; - //! encode this object into a BufferedTransformation, using DER (Distinguished Encoding Rules) - virtual void DEREncode(BufferedTransformation &bt) const =0; - //! encode this object into a BufferedTransformation, using BER - /*! this may be useful if DEREncode() would be too inefficient */ - virtual void BEREncode(BufferedTransformation &bt) const {DEREncode(bt);} -}; - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY -typedef PK_SignatureScheme PK_SignatureSystem; -typedef SimpleKeyAgreementDomain PK_SimpleKeyAgreementDomain; -typedef AuthenticatedKeyAgreementDomain PK_AuthenticatedKeyAgreementDomain; -#endif - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/default.cpp b/lib/cryptopp/default.cpp deleted file mode 100644 index 72940784d..000000000 --- a/lib/cryptopp/default.cpp +++ /dev/null @@ -1,258 +0,0 @@ -// default.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "default.h" -#include "queue.h" -#include -#include - -NAMESPACE_BEGIN(CryptoPP) - -static const unsigned int MASH_ITERATIONS = 200; -static const unsigned int SALTLENGTH = 8; -static const unsigned int BLOCKSIZE = Default_BlockCipher::Encryption::BLOCKSIZE; -static const unsigned int KEYLENGTH = Default_BlockCipher::Encryption::DEFAULT_KEYLENGTH; - -// The purpose of this function Mash() is to take an arbitrary length input -// string and *deterministicly* produce an arbitrary length output string such -// that (1) it looks random, (2) no information about the input is -// deducible from it, and (3) it contains as much entropy as it can hold, or -// the amount of entropy in the input string, whichever is smaller. - -static void Mash(const byte *in, size_t inLen, byte *out, size_t outLen, int iterations) -{ - if (BytePrecision(outLen) > 2) - throw InvalidArgument("Mash: output legnth too large"); - - size_t bufSize = RoundUpToMultipleOf(outLen, (size_t)DefaultHashModule::DIGESTSIZE); - byte b[2]; - SecByteBlock buf(bufSize); - SecByteBlock outBuf(bufSize); - DefaultHashModule hash; - - unsigned int i; - for(i=0; i> 8); - b[1] = (byte) i; - hash.Update(b, 2); - hash.Update(in, inLen); - hash.Final(outBuf+i); - } - - while (iterations-- > 1) - { - memcpy(buf, outBuf, bufSize); - for (i=0; i> 8); - b[1] = (byte) i; - hash.Update(b, 2); - hash.Update(buf, bufSize); - hash.Final(outBuf+i); - } - } - - memcpy(out, outBuf, outLen); -} - -static void GenerateKeyIV(const byte *passphrase, size_t passphraseLength, const byte *salt, size_t saltLength, byte *key, byte *IV) -{ - SecByteBlock temp(passphraseLength+saltLength); - memcpy(temp, passphrase, passphraseLength); - memcpy(temp+passphraseLength, salt, saltLength); - SecByteBlock keyIV(KEYLENGTH+BLOCKSIZE); - Mash(temp, passphraseLength + saltLength, keyIV, KEYLENGTH+BLOCKSIZE, MASH_ITERATIONS); - memcpy(key, keyIV, KEYLENGTH); - memcpy(IV, keyIV+KEYLENGTH, BLOCKSIZE); -} - -// ******************************************************** - -DefaultEncryptor::DefaultEncryptor(const char *passphrase, BufferedTransformation *attachment) - : ProxyFilter(NULL, 0, 0, attachment), m_passphrase((const byte *)passphrase, strlen(passphrase)) -{ -} - -DefaultEncryptor::DefaultEncryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment) - : ProxyFilter(NULL, 0, 0, attachment), m_passphrase(passphrase, passphraseLength) -{ -} - - -void DefaultEncryptor::FirstPut(const byte *) -{ - // VC60 workaround: __LINE__ expansion bug - CRYPTOPP_COMPILE_ASSERT_INSTANCE(SALTLENGTH <= DefaultHashModule::DIGESTSIZE, 1); - CRYPTOPP_COMPILE_ASSERT_INSTANCE(BLOCKSIZE <= DefaultHashModule::DIGESTSIZE, 2); - - SecByteBlock salt(DefaultHashModule::DIGESTSIZE), keyCheck(DefaultHashModule::DIGESTSIZE); - DefaultHashModule hash; - - // use hash(passphrase | time | clock) as salt - hash.Update(m_passphrase, m_passphrase.size()); - time_t t=time(0); - hash.Update((byte *)&t, sizeof(t)); - clock_t c=clock(); - hash.Update((byte *)&c, sizeof(c)); - hash.Final(salt); - - // use hash(passphrase | salt) as key check - hash.Update(m_passphrase, m_passphrase.size()); - hash.Update(salt, SALTLENGTH); - hash.Final(keyCheck); - - AttachedTransformation()->Put(salt, SALTLENGTH); - - // mash passphrase and salt together into key and IV - SecByteBlock key(KEYLENGTH); - SecByteBlock IV(BLOCKSIZE); - GenerateKeyIV(m_passphrase, m_passphrase.size(), salt, SALTLENGTH, key, IV); - - m_cipher.SetKeyWithIV(key, key.size(), IV); - SetFilter(new StreamTransformationFilter(m_cipher)); - - m_filter->Put(keyCheck, BLOCKSIZE); -} - -void DefaultEncryptor::LastPut(const byte *inString, size_t length) -{ - m_filter->MessageEnd(); -} - -// ******************************************************** - -DefaultDecryptor::DefaultDecryptor(const char *p, BufferedTransformation *attachment, bool throwException) - : ProxyFilter(NULL, SALTLENGTH+BLOCKSIZE, 0, attachment) - , m_state(WAITING_FOR_KEYCHECK) - , m_passphrase((const byte *)p, strlen(p)) - , m_throwException(throwException) -{ -} - -DefaultDecryptor::DefaultDecryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment, bool throwException) - : ProxyFilter(NULL, SALTLENGTH+BLOCKSIZE, 0, attachment) - , m_state(WAITING_FOR_KEYCHECK) - , m_passphrase(passphrase, passphraseLength) - , m_throwException(throwException) -{ -} - -void DefaultDecryptor::FirstPut(const byte *inString) -{ - CheckKey(inString, inString+SALTLENGTH); -} - -void DefaultDecryptor::LastPut(const byte *inString, size_t length) -{ - if (m_filter.get() == NULL) - { - m_state = KEY_BAD; - if (m_throwException) - throw KeyBadErr(); - } - else - { - m_filter->MessageEnd(); - m_state = WAITING_FOR_KEYCHECK; - } -} - -void DefaultDecryptor::CheckKey(const byte *salt, const byte *keyCheck) -{ - SecByteBlock check(STDMAX((unsigned int)2*BLOCKSIZE, (unsigned int)DefaultHashModule::DIGESTSIZE)); - - DefaultHashModule hash; - hash.Update(m_passphrase, m_passphrase.size()); - hash.Update(salt, SALTLENGTH); - hash.Final(check); - - SecByteBlock key(KEYLENGTH); - SecByteBlock IV(BLOCKSIZE); - GenerateKeyIV(m_passphrase, m_passphrase.size(), salt, SALTLENGTH, key, IV); - - m_cipher.SetKeyWithIV(key, key.size(), IV); - std::auto_ptr decryptor(new StreamTransformationFilter(m_cipher)); - - decryptor->Put(keyCheck, BLOCKSIZE); - decryptor->ForceNextPut(); - decryptor->Get(check+BLOCKSIZE, BLOCKSIZE); - - SetFilter(decryptor.release()); - - if (!VerifyBufsEqual(check, check+BLOCKSIZE, BLOCKSIZE)) - { - m_state = KEY_BAD; - if (m_throwException) - throw KeyBadErr(); - } - else - m_state = KEY_GOOD; -} - -// ******************************************************** - -static DefaultMAC * NewDefaultEncryptorMAC(const byte *passphrase, size_t passphraseLength) -{ - size_t macKeyLength = DefaultMAC::StaticGetValidKeyLength(16); - SecByteBlock macKey(macKeyLength); - // since the MAC is encrypted there is no reason to mash the passphrase for many iterations - Mash(passphrase, passphraseLength, macKey, macKeyLength, 1); - return new DefaultMAC(macKey, macKeyLength); -} - -DefaultEncryptorWithMAC::DefaultEncryptorWithMAC(const char *passphrase, BufferedTransformation *attachment) - : ProxyFilter(NULL, 0, 0, attachment) - , m_mac(NewDefaultEncryptorMAC((const byte *)passphrase, strlen(passphrase))) -{ - SetFilter(new HashFilter(*m_mac, new DefaultEncryptor(passphrase), true)); -} - -DefaultEncryptorWithMAC::DefaultEncryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment) - : ProxyFilter(NULL, 0, 0, attachment) - , m_mac(NewDefaultEncryptorMAC(passphrase, passphraseLength)) -{ - SetFilter(new HashFilter(*m_mac, new DefaultEncryptor(passphrase, passphraseLength), true)); -} - -void DefaultEncryptorWithMAC::LastPut(const byte *inString, size_t length) -{ - m_filter->MessageEnd(); -} - -// ******************************************************** - -DefaultDecryptorWithMAC::DefaultDecryptorWithMAC(const char *passphrase, BufferedTransformation *attachment, bool throwException) - : ProxyFilter(NULL, 0, 0, attachment) - , m_mac(NewDefaultEncryptorMAC((const byte *)passphrase, strlen(passphrase))) - , m_throwException(throwException) -{ - SetFilter(new DefaultDecryptor(passphrase, m_hashVerifier=new HashVerifier(*m_mac, NULL, HashVerifier::PUT_MESSAGE), throwException)); -} - -DefaultDecryptorWithMAC::DefaultDecryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment, bool throwException) - : ProxyFilter(NULL, 0, 0, attachment) - , m_mac(NewDefaultEncryptorMAC(passphrase, passphraseLength)) - , m_throwException(throwException) -{ - SetFilter(new DefaultDecryptor(passphrase, passphraseLength, m_hashVerifier=new HashVerifier(*m_mac, NULL, HashVerifier::PUT_MESSAGE), throwException)); -} - -DefaultDecryptor::State DefaultDecryptorWithMAC::CurrentState() const -{ - return static_cast(m_filter.get())->CurrentState(); -} - -bool DefaultDecryptorWithMAC::CheckLastMAC() const -{ - return m_hashVerifier->GetLastResult(); -} - -void DefaultDecryptorWithMAC::LastPut(const byte *inString, size_t length) -{ - m_filter->MessageEnd(); - if (m_throwException && !CheckLastMAC()) - throw MACBadErr(); -} - -NAMESPACE_END diff --git a/lib/cryptopp/default.h b/lib/cryptopp/default.h deleted file mode 100644 index fb5364152..000000000 --- a/lib/cryptopp/default.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef CRYPTOPP_DEFAULT_H -#define CRYPTOPP_DEFAULT_H - -#include "sha.h" -#include "hmac.h" -#include "des.h" -#include "filters.h" -#include "modes.h" - -NAMESPACE_BEGIN(CryptoPP) - -typedef DES_EDE2 Default_BlockCipher; -typedef SHA DefaultHashModule; -typedef HMAC DefaultMAC; - -//! Password-Based Encryptor using DES-EDE2 -class DefaultEncryptor : public ProxyFilter -{ -public: - DefaultEncryptor(const char *passphrase, BufferedTransformation *attachment = NULL); - DefaultEncryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL); - -protected: - void FirstPut(const byte *); - void LastPut(const byte *inString, size_t length); - -private: - SecByteBlock m_passphrase; - CBC_Mode::Encryption m_cipher; -}; - -//! Password-Based Decryptor using DES-EDE2 -class DefaultDecryptor : public ProxyFilter -{ -public: - DefaultDecryptor(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true); - DefaultDecryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true); - - class Err : public Exception - { - public: - Err(const std::string &s) - : Exception(DATA_INTEGRITY_CHECK_FAILED, s) {} - }; - class KeyBadErr : public Err {public: KeyBadErr() : Err("DefaultDecryptor: cannot decrypt message with this passphrase") {}}; - - enum State {WAITING_FOR_KEYCHECK, KEY_GOOD, KEY_BAD}; - State CurrentState() const {return m_state;} - -protected: - void FirstPut(const byte *inString); - void LastPut(const byte *inString, size_t length); - - State m_state; - -private: - void CheckKey(const byte *salt, const byte *keyCheck); - - SecByteBlock m_passphrase; - CBC_Mode::Decryption m_cipher; - member_ptr m_decryptor; - bool m_throwException; -}; - -//! Password-Based Encryptor using DES-EDE2 and HMAC/SHA-1 -class DefaultEncryptorWithMAC : public ProxyFilter -{ -public: - DefaultEncryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL); - DefaultEncryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL); - -protected: - void FirstPut(const byte *inString) {} - void LastPut(const byte *inString, size_t length); - -private: - member_ptr m_mac; -}; - -//! Password-Based Decryptor using DES-EDE2 and HMAC/SHA-1 -class DefaultDecryptorWithMAC : public ProxyFilter -{ -public: - class MACBadErr : public DefaultDecryptor::Err {public: MACBadErr() : DefaultDecryptor::Err("DefaultDecryptorWithMAC: MAC check failed") {}}; - - DefaultDecryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true); - DefaultDecryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true); - - DefaultDecryptor::State CurrentState() const; - bool CheckLastMAC() const; - -protected: - void FirstPut(const byte *inString) {} - void LastPut(const byte *inString, size_t length); - -private: - member_ptr m_mac; - HashVerifier *m_hashVerifier; - bool m_throwException; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/des.cpp b/lib/cryptopp/des.cpp deleted file mode 100644 index a6e0c514d..000000000 --- a/lib/cryptopp/des.cpp +++ /dev/null @@ -1,449 +0,0 @@ -// des.cpp - modified by Wei Dai from Phil Karn's des.c -// The original code and all modifications are in the public domain. - -/* - * This is a major rewrite of my old public domain DES code written - * circa 1987, which in turn borrowed heavily from Jim Gillogly's 1977 - * public domain code. I pretty much kept my key scheduling code, but - * the actual encrypt/decrypt routines are taken from from Richard - * Outerbridge's DES code as printed in Schneier's "Applied Cryptography." - * - * This code is in the public domain. I would appreciate bug reports and - * enhancements. - * - * Phil Karn KA9Q, karn@unix.ka9q.ampr.org, August 1994. - */ - -#include "pch.h" -#include "misc.h" -#include "des.h" - -NAMESPACE_BEGIN(CryptoPP) - -typedef BlockGetAndPut Block; - -// Richard Outerbridge's initial permutation algorithm -/* -inline void IPERM(word32 &left, word32 &right) -{ - word32 work; - - work = ((left >> 4) ^ right) & 0x0f0f0f0f; - right ^= work; - left ^= work << 4; - work = ((left >> 16) ^ right) & 0xffff; - right ^= work; - left ^= work << 16; - work = ((right >> 2) ^ left) & 0x33333333; - left ^= work; - right ^= (work << 2); - work = ((right >> 8) ^ left) & 0xff00ff; - left ^= work; - right ^= (work << 8); - right = rotl(right, 1); - work = (left ^ right) & 0xaaaaaaaa; - left ^= work; - right ^= work; - left = rotl(left, 1); -} -inline void FPERM(word32 &left, word32 &right) -{ - word32 work; - - right = rotr(right, 1); - work = (left ^ right) & 0xaaaaaaaa; - left ^= work; - right ^= work; - left = rotr(left, 1); - work = ((left >> 8) ^ right) & 0xff00ff; - right ^= work; - left ^= work << 8; - work = ((left >> 2) ^ right) & 0x33333333; - right ^= work; - left ^= work << 2; - work = ((right >> 16) ^ left) & 0xffff; - left ^= work; - right ^= work << 16; - work = ((right >> 4) ^ left) & 0x0f0f0f0f; - left ^= work; - right ^= work << 4; -} -*/ - -// Wei Dai's modification to Richard Outerbridge's initial permutation -// algorithm, this one is faster if you have access to rotate instructions -// (like in MSVC) -static inline void IPERM(word32 &left, word32 &right) -{ - word32 work; - - right = rotlFixed(right, 4U); - work = (left ^ right) & 0xf0f0f0f0; - left ^= work; - right = rotrFixed(right^work, 20U); - work = (left ^ right) & 0xffff0000; - left ^= work; - right = rotrFixed(right^work, 18U); - work = (left ^ right) & 0x33333333; - left ^= work; - right = rotrFixed(right^work, 6U); - work = (left ^ right) & 0x00ff00ff; - left ^= work; - right = rotlFixed(right^work, 9U); - work = (left ^ right) & 0xaaaaaaaa; - left = rotlFixed(left^work, 1U); - right ^= work; -} - -static inline void FPERM(word32 &left, word32 &right) -{ - word32 work; - - right = rotrFixed(right, 1U); - work = (left ^ right) & 0xaaaaaaaa; - right ^= work; - left = rotrFixed(left^work, 9U); - work = (left ^ right) & 0x00ff00ff; - right ^= work; - left = rotlFixed(left^work, 6U); - work = (left ^ right) & 0x33333333; - right ^= work; - left = rotlFixed(left^work, 18U); - work = (left ^ right) & 0xffff0000; - right ^= work; - left = rotlFixed(left^work, 20U); - work = (left ^ right) & 0xf0f0f0f0; - right ^= work; - left = rotrFixed(left^work, 4U); -} - -void DES::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &) -{ - AssertValidKeyLength(length); - - RawSetKey(GetCipherDirection(), userKey); -} - -#ifndef CRYPTOPP_IMPORTS - -/* Tables defined in the Data Encryption Standard documents - * Three of these tables, the initial permutation, the final - * permutation and the expansion operator, are regular enough that - * for speed, we hard-code them. They're here for reference only. - * Also, the S and P boxes are used by a separate program, gensp.c, - * to build the combined SP box, Spbox[]. They're also here just - * for reference. - */ -#ifdef notdef -/* initial permutation IP */ -static byte ip[] = { - 58, 50, 42, 34, 26, 18, 10, 2, - 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, - 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, - 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, - 63, 55, 47, 39, 31, 23, 15, 7 -}; - -/* final permutation IP^-1 */ -static byte fp[] = { - 40, 8, 48, 16, 56, 24, 64, 32, - 39, 7, 47, 15, 55, 23, 63, 31, - 38, 6, 46, 14, 54, 22, 62, 30, - 37, 5, 45, 13, 53, 21, 61, 29, - 36, 4, 44, 12, 52, 20, 60, 28, - 35, 3, 43, 11, 51, 19, 59, 27, - 34, 2, 42, 10, 50, 18, 58, 26, - 33, 1, 41, 9, 49, 17, 57, 25 -}; -/* expansion operation matrix */ -static byte ei[] = { - 32, 1, 2, 3, 4, 5, - 4, 5, 6, 7, 8, 9, - 8, 9, 10, 11, 12, 13, - 12, 13, 14, 15, 16, 17, - 16, 17, 18, 19, 20, 21, - 20, 21, 22, 23, 24, 25, - 24, 25, 26, 27, 28, 29, - 28, 29, 30, 31, 32, 1 -}; -/* The (in)famous S-boxes */ -static byte sbox[8][64] = { - /* S1 */ - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13, - - /* S2 */ - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9, - - /* S3 */ - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12, - - /* S4 */ - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14, - - /* S5 */ - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3, - - /* S6 */ - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13, - - /* S7 */ - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12, - - /* S8 */ - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 -}; - -/* 32-bit permutation function P used on the output of the S-boxes */ -static byte p32i[] = { - 16, 7, 20, 21, - 29, 12, 28, 17, - 1, 15, 23, 26, - 5, 18, 31, 10, - 2, 8, 24, 14, - 32, 27, 3, 9, - 19, 13, 30, 6, - 22, 11, 4, 25 -}; -#endif - -/* permuted choice table (key) */ -static const byte pc1[] = { - 57, 49, 41, 33, 25, 17, 9, - 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, - 19, 11, 3, 60, 52, 44, 36, - - 63, 55, 47, 39, 31, 23, 15, - 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, - 21, 13, 5, 28, 20, 12, 4 -}; - -/* number left rotations of pc1 */ -static const byte totrot[] = { - 1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28 -}; - -/* permuted choice key (table) */ -static const byte pc2[] = { - 14, 17, 11, 24, 1, 5, - 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, - 16, 7, 27, 20, 13, 2, - 41, 52, 31, 37, 47, 55, - 30, 40, 51, 45, 33, 48, - 44, 49, 39, 56, 34, 53, - 46, 42, 50, 36, 29, 32 -}; - -/* End of DES-defined tables */ - -/* bit 0 is left-most in byte */ -static const int bytebit[] = { - 0200,0100,040,020,010,04,02,01 -}; - -/* Set key (initialize key schedule array) */ -void RawDES::RawSetKey(CipherDir dir, const byte *key) -{ - SecByteBlock buffer(56+56+8); - byte *const pc1m=buffer; /* place to modify pc1 into */ - byte *const pcr=pc1m+56; /* place to rotate pc1 into */ - byte *const ks=pcr+56; - register int i,j,l; - int m; - - for (j=0; j<56; j++) { /* convert pc1 to bits of key */ - l=pc1[j]-1; /* integer bit location */ - m = l & 07; /* find bit */ - pc1m[j]=(key[l>>3] & /* find which key byte l is in */ - bytebit[m]) /* and which bit of that byte */ - ? 1 : 0; /* and store 1-bit result */ - } - for (i=0; i<16; i++) { /* key chunk for each iteration */ - memset(ks,0,8); /* Clear key schedule */ - for (j=0; j<56; j++) /* rotate pc1 the right amount */ - pcr[j] = pc1m[(l=j+totrot[i])<(j<28? 28 : 56) ? l: l-28]; - /* rotate left and right halves independently */ - for (j=0; j<48; j++){ /* select bits individually */ - /* check bit that goes to ks[j] */ - if (pcr[pc2[j]-1]){ - /* mask it in if it's there */ - l= j % 6; - ks[j/6] |= bytebit[l] >> 2; - } - } - /* Now convert to odd/even interleaved form for use in F */ - k[2*i] = ((word32)ks[0] << 24) - | ((word32)ks[2] << 16) - | ((word32)ks[4] << 8) - | ((word32)ks[6]); - k[2*i+1] = ((word32)ks[1] << 24) - | ((word32)ks[3] << 16) - | ((word32)ks[5] << 8) - | ((word32)ks[7]); - } - - if (dir==DECRYPTION) // reverse key schedule order - for (i=0; i<16; i+=2) - { - std::swap(k[i], k[32-2-i]); - std::swap(k[i+1], k[32-1-i]); - } -} - -void RawDES::RawProcessBlock(word32 &l_, word32 &r_) const -{ - word32 l = l_, r = r_; - const word32 *kptr=k; - - for (unsigned i=0; i<8; i++) - { - word32 work = rotrFixed(r, 4U) ^ kptr[4*i+0]; - l ^= Spbox[6][(work) & 0x3f] - ^ Spbox[4][(work >> 8) & 0x3f] - ^ Spbox[2][(work >> 16) & 0x3f] - ^ Spbox[0][(work >> 24) & 0x3f]; - work = r ^ kptr[4*i+1]; - l ^= Spbox[7][(work) & 0x3f] - ^ Spbox[5][(work >> 8) & 0x3f] - ^ Spbox[3][(work >> 16) & 0x3f] - ^ Spbox[1][(work >> 24) & 0x3f]; - - work = rotrFixed(l, 4U) ^ kptr[4*i+2]; - r ^= Spbox[6][(work) & 0x3f] - ^ Spbox[4][(work >> 8) & 0x3f] - ^ Spbox[2][(work >> 16) & 0x3f] - ^ Spbox[0][(work >> 24) & 0x3f]; - work = l ^ kptr[4*i+3]; - r ^= Spbox[7][(work) & 0x3f] - ^ Spbox[5][(work >> 8) & 0x3f] - ^ Spbox[3][(work >> 16) & 0x3f] - ^ Spbox[1][(work >> 24) & 0x3f]; - } - - l_ = l; r_ = r; -} - -void DES_EDE2::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &) -{ - AssertValidKeyLength(length); - - m_des1.RawSetKey(GetCipherDirection(), userKey); - m_des2.RawSetKey(ReverseCipherDir(GetCipherDirection()), userKey+8); -} - -void DES_EDE2::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - word32 l,r; - Block::Get(inBlock)(l)(r); - IPERM(l,r); - m_des1.RawProcessBlock(l, r); - m_des2.RawProcessBlock(r, l); - m_des1.RawProcessBlock(l, r); - FPERM(l,r); - Block::Put(xorBlock, outBlock)(r)(l); -} - -void DES_EDE3::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &) -{ - AssertValidKeyLength(length); - - m_des1.RawSetKey(GetCipherDirection(), userKey + (IsForwardTransformation() ? 0 : 16)); - m_des2.RawSetKey(ReverseCipherDir(GetCipherDirection()), userKey + 8); - m_des3.RawSetKey(GetCipherDirection(), userKey + (IsForwardTransformation() ? 16 : 0)); -} - -void DES_EDE3::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - word32 l,r; - Block::Get(inBlock)(l)(r); - IPERM(l,r); - m_des1.RawProcessBlock(l, r); - m_des2.RawProcessBlock(r, l); - m_des3.RawProcessBlock(l, r); - FPERM(l,r); - Block::Put(xorBlock, outBlock)(r)(l); -} - -#endif // #ifndef CRYPTOPP_IMPORTS - -static inline bool CheckParity(byte b) -{ - unsigned int a = b ^ (b >> 4); - return ((a ^ (a>>1) ^ (a>>2) ^ (a>>3)) & 1) == 1; -} - -bool DES::CheckKeyParityBits(const byte *key) -{ - for (unsigned int i=0; i<8; i++) - if (!CheckParity(key[i])) - return false; - return true; -} - -void DES::CorrectKeyParityBits(byte *key) -{ - for (unsigned int i=0; i<8; i++) - if (!CheckParity(key[i])) - key[i] ^= 1; -} - -// Encrypt or decrypt a block of data in ECB mode -void DES::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - word32 l,r; - Block::Get(inBlock)(l)(r); - IPERM(l,r); - RawProcessBlock(l, r); - FPERM(l,r); - Block::Put(xorBlock, outBlock)(r)(l); -} - -void DES_XEX3::Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &) -{ - AssertValidKeyLength(length); - - if (!m_des.get()) - m_des.reset(new DES::Encryption); - - memcpy(m_x1, key + (IsForwardTransformation() ? 0 : 16), BLOCKSIZE); - m_des->RawSetKey(GetCipherDirection(), key + 8); - memcpy(m_x3, key + (IsForwardTransformation() ? 16 : 0), BLOCKSIZE); -} - -void DES_XEX3::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - xorbuf(outBlock, inBlock, m_x1, BLOCKSIZE); - m_des->ProcessAndXorBlock(outBlock, xorBlock, outBlock); - xorbuf(outBlock, m_x3, BLOCKSIZE); -} - -NAMESPACE_END diff --git a/lib/cryptopp/des.h b/lib/cryptopp/des.h deleted file mode 100644 index 62f628824..000000000 --- a/lib/cryptopp/des.h +++ /dev/null @@ -1,144 +0,0 @@ -#ifndef CRYPTOPP_DES_H -#define CRYPTOPP_DES_H - -/** \file -*/ - -#include "seckey.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -class CRYPTOPP_DLL RawDES -{ -public: - void RawSetKey(CipherDir direction, const byte *userKey); - void RawProcessBlock(word32 &l, word32 &r) const; - -protected: - static const word32 Spbox[8][64]; - - FixedSizeSecBlock k; -}; - -//! _ -struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8> -{ - // disable DES in DLL version by not exporting this function - static const char * StaticAlgorithmName() {return "DES";} -}; - -/// DES -/*! The DES implementation in Crypto++ ignores the parity bits - (the least significant bits of each byte) in the key. However - you can use CheckKeyParityBits() and CorrectKeyParityBits() to - check or correct the parity bits if you wish. */ -class DES : public DES_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl, public RawDES - { - public: - void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - }; - -public: - //! check DES key parity bits - static bool CheckKeyParityBits(const byte *key); - //! correct DES key parity bits - static void CorrectKeyParityBits(byte *key); - - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -//! _ -struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16> -{ - CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE2";} -}; - -/// DES-EDE2 -class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl - { - public: - void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - - protected: - RawDES m_des1, m_des2; - }; - -public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -//! _ -struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24> -{ - CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE3";} -}; - -/// DES-EDE3 -class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl - { - public: - void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - - protected: - RawDES m_des1, m_des2, m_des3; - }; - -public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -//! _ -struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24> -{ - static const char *StaticAlgorithmName() {return "DES-XEX3";} -}; - -/// DES-XEX3, AKA DESX -class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl - { - public: - void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - - protected: - FixedSizeSecBlock m_x1, m_x3; - // VS2005 workaround: calling modules compiled with /clr gets unresolved external symbol DES::Base::ProcessAndXorBlock - // if we use DES::Encryption here directly without value_ptr. - value_ptr m_des; - }; - -public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -typedef DES::Encryption DESEncryption; -typedef DES::Decryption DESDecryption; - -typedef DES_EDE2::Encryption DES_EDE2_Encryption; -typedef DES_EDE2::Decryption DES_EDE2_Decryption; - -typedef DES_EDE3::Encryption DES_EDE3_Encryption; -typedef DES_EDE3::Decryption DES_EDE3_Decryption; - -typedef DES_XEX3::Encryption DES_XEX3_Encryption; -typedef DES_XEX3::Decryption DES_XEX3_Decryption; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/dessp.cpp b/lib/cryptopp/dessp.cpp deleted file mode 100644 index 49ed1d26d..000000000 --- a/lib/cryptopp/dessp.cpp +++ /dev/null @@ -1,95 +0,0 @@ -// This file is mostly generated by Phil Karn's gensp.c - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "des.h" - -NAMESPACE_BEGIN(CryptoPP) - -// VC60 workaround: gives a C4786 warning without this function -// when runtime lib is set to multithread debug DLL -// even though warning 4786 is disabled! -void DES_VC60Workaround() -{ -} - -const word32 RawDES::Spbox[8][64] = { -{ -0x01010400,0x00000000,0x00010000,0x01010404, 0x01010004,0x00010404,0x00000004,0x00010000, -0x00000400,0x01010400,0x01010404,0x00000400, 0x01000404,0x01010004,0x01000000,0x00000004, -0x00000404,0x01000400,0x01000400,0x00010400, 0x00010400,0x01010000,0x01010000,0x01000404, -0x00010004,0x01000004,0x01000004,0x00010004, 0x00000000,0x00000404,0x00010404,0x01000000, -0x00010000,0x01010404,0x00000004,0x01010000, 0x01010400,0x01000000,0x01000000,0x00000400, -0x01010004,0x00010000,0x00010400,0x01000004, 0x00000400,0x00000004,0x01000404,0x00010404, -0x01010404,0x00010004,0x01010000,0x01000404, 0x01000004,0x00000404,0x00010404,0x01010400, -0x00000404,0x01000400,0x01000400,0x00000000, 0x00010004,0x00010400,0x00000000,0x01010004}, -{ -0x80108020,0x80008000,0x00008000,0x00108020, 0x00100000,0x00000020,0x80100020,0x80008020, -0x80000020,0x80108020,0x80108000,0x80000000, 0x80008000,0x00100000,0x00000020,0x80100020, -0x00108000,0x00100020,0x80008020,0x00000000, 0x80000000,0x00008000,0x00108020,0x80100000, -0x00100020,0x80000020,0x00000000,0x00108000, 0x00008020,0x80108000,0x80100000,0x00008020, -0x00000000,0x00108020,0x80100020,0x00100000, 0x80008020,0x80100000,0x80108000,0x00008000, -0x80100000,0x80008000,0x00000020,0x80108020, 0x00108020,0x00000020,0x00008000,0x80000000, -0x00008020,0x80108000,0x00100000,0x80000020, 0x00100020,0x80008020,0x80000020,0x00100020, -0x00108000,0x00000000,0x80008000,0x00008020, 0x80000000,0x80100020,0x80108020,0x00108000}, -{ -0x00000208,0x08020200,0x00000000,0x08020008, 0x08000200,0x00000000,0x00020208,0x08000200, -0x00020008,0x08000008,0x08000008,0x00020000, 0x08020208,0x00020008,0x08020000,0x00000208, -0x08000000,0x00000008,0x08020200,0x00000200, 0x00020200,0x08020000,0x08020008,0x00020208, -0x08000208,0x00020200,0x00020000,0x08000208, 0x00000008,0x08020208,0x00000200,0x08000000, -0x08020200,0x08000000,0x00020008,0x00000208, 0x00020000,0x08020200,0x08000200,0x00000000, -0x00000200,0x00020008,0x08020208,0x08000200, 0x08000008,0x00000200,0x00000000,0x08020008, -0x08000208,0x00020000,0x08000000,0x08020208, 0x00000008,0x00020208,0x00020200,0x08000008, -0x08020000,0x08000208,0x00000208,0x08020000, 0x00020208,0x00000008,0x08020008,0x00020200}, -{ -0x00802001,0x00002081,0x00002081,0x00000080, 0x00802080,0x00800081,0x00800001,0x00002001, -0x00000000,0x00802000,0x00802000,0x00802081, 0x00000081,0x00000000,0x00800080,0x00800001, -0x00000001,0x00002000,0x00800000,0x00802001, 0x00000080,0x00800000,0x00002001,0x00002080, -0x00800081,0x00000001,0x00002080,0x00800080, 0x00002000,0x00802080,0x00802081,0x00000081, -0x00800080,0x00800001,0x00802000,0x00802081, 0x00000081,0x00000000,0x00000000,0x00802000, -0x00002080,0x00800080,0x00800081,0x00000001, 0x00802001,0x00002081,0x00002081,0x00000080, -0x00802081,0x00000081,0x00000001,0x00002000, 0x00800001,0x00002001,0x00802080,0x00800081, -0x00002001,0x00002080,0x00800000,0x00802001, 0x00000080,0x00800000,0x00002000,0x00802080}, -{ -0x00000100,0x02080100,0x02080000,0x42000100, 0x00080000,0x00000100,0x40000000,0x02080000, -0x40080100,0x00080000,0x02000100,0x40080100, 0x42000100,0x42080000,0x00080100,0x40000000, -0x02000000,0x40080000,0x40080000,0x00000000, 0x40000100,0x42080100,0x42080100,0x02000100, -0x42080000,0x40000100,0x00000000,0x42000000, 0x02080100,0x02000000,0x42000000,0x00080100, -0x00080000,0x42000100,0x00000100,0x02000000, 0x40000000,0x02080000,0x42000100,0x40080100, -0x02000100,0x40000000,0x42080000,0x02080100, 0x40080100,0x00000100,0x02000000,0x42080000, -0x42080100,0x00080100,0x42000000,0x42080100, 0x02080000,0x00000000,0x40080000,0x42000000, -0x00080100,0x02000100,0x40000100,0x00080000, 0x00000000,0x40080000,0x02080100,0x40000100}, -{ -0x20000010,0x20400000,0x00004000,0x20404010, 0x20400000,0x00000010,0x20404010,0x00400000, -0x20004000,0x00404010,0x00400000,0x20000010, 0x00400010,0x20004000,0x20000000,0x00004010, -0x00000000,0x00400010,0x20004010,0x00004000, 0x00404000,0x20004010,0x00000010,0x20400010, -0x20400010,0x00000000,0x00404010,0x20404000, 0x00004010,0x00404000,0x20404000,0x20000000, -0x20004000,0x00000010,0x20400010,0x00404000, 0x20404010,0x00400000,0x00004010,0x20000010, -0x00400000,0x20004000,0x20000000,0x00004010, 0x20000010,0x20404010,0x00404000,0x20400000, -0x00404010,0x20404000,0x00000000,0x20400010, 0x00000010,0x00004000,0x20400000,0x00404010, -0x00004000,0x00400010,0x20004010,0x00000000, 0x20404000,0x20000000,0x00400010,0x20004010}, -{ -0x00200000,0x04200002,0x04000802,0x00000000, 0x00000800,0x04000802,0x00200802,0x04200800, -0x04200802,0x00200000,0x00000000,0x04000002, 0x00000002,0x04000000,0x04200002,0x00000802, -0x04000800,0x00200802,0x00200002,0x04000800, 0x04000002,0x04200000,0x04200800,0x00200002, -0x04200000,0x00000800,0x00000802,0x04200802, 0x00200800,0x00000002,0x04000000,0x00200800, -0x04000000,0x00200800,0x00200000,0x04000802, 0x04000802,0x04200002,0x04200002,0x00000002, -0x00200002,0x04000000,0x04000800,0x00200000, 0x04200800,0x00000802,0x00200802,0x04200800, -0x00000802,0x04000002,0x04200802,0x04200000, 0x00200800,0x00000000,0x00000002,0x04200802, -0x00000000,0x00200802,0x04200000,0x00000800, 0x04000002,0x04000800,0x00000800,0x00200002}, -{ -0x10001040,0x00001000,0x00040000,0x10041040, 0x10000000,0x10001040,0x00000040,0x10000000, -0x00040040,0x10040000,0x10041040,0x00041000, 0x10041000,0x00041040,0x00001000,0x00000040, -0x10040000,0x10000040,0x10001000,0x00001040, 0x00041000,0x00040040,0x10040040,0x10041000, -0x00001040,0x00000000,0x00000000,0x10040040, 0x10000040,0x10001000,0x00041040,0x00040000, -0x00041040,0x00040000,0x10041000,0x00001000, 0x00000040,0x10040040,0x00001000,0x00041040, -0x10001000,0x00000040,0x10000040,0x10040000, 0x10040040,0x10000000,0x00040000,0x10001040, -0x00000000,0x10041040,0x00040040,0x10000040, 0x10040000,0x10001000,0x10001040,0x00000000, -0x10041040,0x00041000,0x00041000,0x00001040, 0x00001040,0x00040040,0x10000000,0x10041000} -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/dh.cpp b/lib/cryptopp/dh.cpp deleted file mode 100644 index 22097a051..000000000 --- a/lib/cryptopp/dh.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// dh.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "dh.h" - -NAMESPACE_BEGIN(CryptoPP) - -void DH_TestInstantiations() -{ - DH dh1; - DH dh2(NullRNG(), 10); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/dh.h b/lib/cryptopp/dh.h deleted file mode 100644 index 10e8d142e..000000000 --- a/lib/cryptopp/dh.h +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef CRYPTOPP_DH_H -#define CRYPTOPP_DH_H - -/** \file -*/ - -#include "gfpcrypt.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! , -template -class DH_Domain : public DL_SimpleKeyAgreementDomainBase -{ - typedef DL_SimpleKeyAgreementDomainBase Base; - -public: - typedef GROUP_PARAMETERS GroupParameters; - typedef typename GroupParameters::Element Element; - typedef DL_KeyAgreementAlgorithm_DH DH_Algorithm; - typedef DH_Domain Domain; - - DH_Domain() {} - - DH_Domain(const GroupParameters ¶ms) - : m_groupParameters(params) {} - - DH_Domain(BufferedTransformation &bt) - {m_groupParameters.BERDecode(bt);} - - template - DH_Domain(RandomNumberGenerator &v1, const T2 &v2) - {m_groupParameters.Initialize(v1, v2);} - - template - DH_Domain(RandomNumberGenerator &v1, const T2 &v2, const T3 &v3) - {m_groupParameters.Initialize(v1, v2, v3);} - - template - DH_Domain(RandomNumberGenerator &v1, const T2 &v2, const T3 &v3, const T4 &v4) - {m_groupParameters.Initialize(v1, v2, v3, v4);} - - template - DH_Domain(const T1 &v1, const T2 &v2) - {m_groupParameters.Initialize(v1, v2);} - - template - DH_Domain(const T1 &v1, const T2 &v2, const T3 &v3) - {m_groupParameters.Initialize(v1, v2, v3);} - - template - DH_Domain(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4) - {m_groupParameters.Initialize(v1, v2, v3, v4);} - - const GroupParameters & GetGroupParameters() const {return m_groupParameters;} - GroupParameters & AccessGroupParameters() {return m_groupParameters;} - - void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const - { - Base::GeneratePublicKey(rng, privateKey, publicKey); - - if (FIPS_140_2_ComplianceEnabled()) - { - SecByteBlock privateKey2(this->PrivateKeyLength()); - this->GeneratePrivateKey(rng, privateKey2); - - SecByteBlock publicKey2(this->PublicKeyLength()); - Base::GeneratePublicKey(rng, privateKey2, publicKey2); - - SecByteBlock agreedValue(this->AgreedValueLength()), agreedValue2(this->AgreedValueLength()); - bool agreed1 = this->Agree(agreedValue, privateKey, publicKey2); - bool agreed2 = this->Agree(agreedValue2, privateKey2, publicKey); - - if (!agreed1 || !agreed2 || agreedValue != agreedValue2) - throw SelfTestFailure(this->AlgorithmName() + ": pairwise consistency test failed"); - } - } - - static std::string CRYPTOPP_API StaticAlgorithmName() - {return GroupParameters::StaticAlgorithmNamePrefix() + DH_Algorithm::StaticAlgorithmName();} - std::string AlgorithmName() const {return StaticAlgorithmName();} - -private: - const DL_KeyAgreementAlgorithm & GetKeyAgreementAlgorithm() const - {return Singleton().Ref();} - DL_GroupParameters & AccessAbstractGroupParameters() - {return m_groupParameters;} - - GroupParameters m_groupParameters; -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS DH_Domain; - -//! Diffie-Hellman in GF(p) with key validation -typedef DH_Domain DH; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/dh2.cpp b/lib/cryptopp/dh2.cpp deleted file mode 100644 index 98175ee28..000000000 --- a/lib/cryptopp/dh2.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// dh2.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "dh2.h" - -NAMESPACE_BEGIN(CryptoPP) - -void DH2_TestInstantiations() -{ - DH2 dh(*(SimpleKeyAgreementDomain*)NULL); -} - -bool DH2::Agree(byte *agreedValue, - const byte *staticSecretKey, const byte *ephemeralSecretKey, - const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, - bool validateStaticOtherPublicKey) const -{ - return d1.Agree(agreedValue, staticSecretKey, staticOtherPublicKey, validateStaticOtherPublicKey) - && d2.Agree(agreedValue+d1.AgreedValueLength(), ephemeralSecretKey, ephemeralOtherPublicKey, true); -} - -NAMESPACE_END diff --git a/lib/cryptopp/dh2.h b/lib/cryptopp/dh2.h deleted file mode 100644 index af9d342d6..000000000 --- a/lib/cryptopp/dh2.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef CRYPTOPP_DH2_H -#define CRYPTOPP_DH2_H - -/** \file -*/ - -#include "cryptlib.h" - -NAMESPACE_BEGIN(CryptoPP) - -/// Unified Diffie-Hellman -class DH2 : public AuthenticatedKeyAgreementDomain -{ -public: - DH2(SimpleKeyAgreementDomain &domain) - : d1(domain), d2(domain) {} - DH2(SimpleKeyAgreementDomain &staticDomain, SimpleKeyAgreementDomain &ephemeralDomain) - : d1(staticDomain), d2(ephemeralDomain) {} - - CryptoParameters & AccessCryptoParameters() {return d1.AccessCryptoParameters();} - - unsigned int AgreedValueLength() const - {return d1.AgreedValueLength() + d2.AgreedValueLength();} - - unsigned int StaticPrivateKeyLength() const - {return d1.PrivateKeyLength();} - unsigned int StaticPublicKeyLength() const - {return d1.PublicKeyLength();} - void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const - {d1.GeneratePrivateKey(rng, privateKey);} - void GenerateStaticPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const - {d1.GeneratePublicKey(rng, privateKey, publicKey);} - void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const - {d1.GenerateKeyPair(rng, privateKey, publicKey);} - - unsigned int EphemeralPrivateKeyLength() const - {return d2.PrivateKeyLength();} - unsigned int EphemeralPublicKeyLength() const - {return d2.PublicKeyLength();} - void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const - {d2.GeneratePrivateKey(rng, privateKey);} - void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const - {d2.GeneratePublicKey(rng, privateKey, publicKey);} - void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const - {d2.GenerateKeyPair(rng, privateKey, publicKey);} - - bool Agree(byte *agreedValue, - const byte *staticPrivateKey, const byte *ephemeralPrivateKey, - const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, - bool validateStaticOtherPublicKey=true) const; - -protected: - SimpleKeyAgreementDomain &d1, &d2; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/dll.cpp b/lib/cryptopp/dll.cpp deleted file mode 100644 index 2b4ef7ade..000000000 --- a/lib/cryptopp/dll.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// dll.cpp - written and placed in the public domain by Wei Dai - -#define CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES -#define CRYPTOPP_DEFAULT_NO_DLL - -#include "dll.h" -#pragma warning(default: 4660) - -#if defined(CRYPTOPP_EXPORTS) && defined(CRYPTOPP_WIN32_AVAILABLE) -#include -#endif - -#ifndef CRYPTOPP_IMPORTS - -NAMESPACE_BEGIN(CryptoPP) - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x2d,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x04,0x05,0x00,0x04,0x1c}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x31,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01,0x05,0x00,0x04,0x20}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x41,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x02,0x05,0x00,0x04,0x30}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x51,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x03,0x05,0x00,0x04,0x40}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte EMSA2HashId::id = 0x33; -template<> const byte EMSA2HashId::id = 0x38; -template<> const byte EMSA2HashId::id = 0x34; -template<> const byte EMSA2HashId::id = 0x36; -template<> const byte EMSA2HashId::id = 0x35; - -NAMESPACE_END - -#endif - -#ifdef CRYPTOPP_EXPORTS - -USING_NAMESPACE(CryptoPP) - -#if !(defined(_MSC_VER) && (_MSC_VER < 1300)) -using std::set_new_handler; -#endif - -static PNew s_pNew = NULL; -static PDelete s_pDelete = NULL; - -static void * New (size_t size) -{ - void *p; - while (!(p = malloc(size))) - CallNewHandler(); - - return p; -} - -static void SetNewAndDeleteFunctionPointers() -{ - void *p = NULL; - HMODULE hModule = NULL; - MEMORY_BASIC_INFORMATION mbi; - - while (true) - { - VirtualQuery(p, &mbi, sizeof(mbi)); - - if (p >= (char *)mbi.BaseAddress + mbi.RegionSize) - break; - - p = (char *)mbi.BaseAddress + mbi.RegionSize; - - if (!mbi.AllocationBase || mbi.AllocationBase == hModule) - continue; - - hModule = HMODULE(mbi.AllocationBase); - - PGetNewAndDelete pGetNewAndDelete = (PGetNewAndDelete)GetProcAddress(hModule, "GetNewAndDeleteForCryptoPP"); - if (pGetNewAndDelete) - { - pGetNewAndDelete(s_pNew, s_pDelete); - return; - } - - PSetNewAndDelete pSetNewAndDelete = (PSetNewAndDelete)GetProcAddress(hModule, "SetNewAndDeleteFromCryptoPP"); - if (pSetNewAndDelete) - { - s_pNew = &New; - s_pDelete = &free; - pSetNewAndDelete(s_pNew, s_pDelete, &set_new_handler); - return; - } - } - - // try getting these directly using mangled names of new and delete operators - - hModule = GetModuleHandle("msvcrtd"); - if (!hModule) - hModule = GetModuleHandle("msvcrt"); - if (hModule) - { - // 32-bit versions - s_pNew = (PNew)GetProcAddress(hModule, "??2@YAPAXI@Z"); - s_pDelete = (PDelete)GetProcAddress(hModule, "??3@YAXPAX@Z"); - if (s_pNew && s_pDelete) - return; - - // 64-bit versions - s_pNew = (PNew)GetProcAddress(hModule, "??2@YAPEAX_K@Z"); - s_pDelete = (PDelete)GetProcAddress(hModule, "??3@YAXPEAX@Z"); - if (s_pNew && s_pDelete) - return; - } - - OutputDebugString("Crypto++ was not able to obtain new and delete function pointers.\n"); - throw 0; -} - -void * operator new (size_t size) -{ - if (!s_pNew) - SetNewAndDeleteFunctionPointers(); - - return s_pNew(size); -} - -void operator delete (void * p) -{ - s_pDelete(p); -} - -void * operator new [] (size_t size) -{ - return operator new (size); -} - -void operator delete [] (void * p) -{ - operator delete (p); -} - -#endif // #ifdef CRYPTOPP_EXPORTS diff --git a/lib/cryptopp/dll.h b/lib/cryptopp/dll.h deleted file mode 100644 index 50775e98b..000000000 --- a/lib/cryptopp/dll.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef CRYPTOPP_DLL_H -#define CRYPTOPP_DLL_H - -#if !defined(CRYPTOPP_IMPORTS) && !defined(CRYPTOPP_EXPORTS) && !defined(CRYPTOPP_DEFAULT_NO_DLL) -#ifdef CRYPTOPP_CONFIG_H -#error To use the DLL version of Crypto++, this file must be included before any other Crypto++ header files. -#endif -#define CRYPTOPP_IMPORTS -#endif - -#include "aes.h" -#include "cbcmac.h" -#include "ccm.h" -#include "cmac.h" -#include "channels.h" -#include "des.h" -#include "dh.h" -#include "dsa.h" -#include "ec2n.h" -#include "eccrypto.h" -#include "ecp.h" -#include "files.h" -#include "fips140.h" -#include "gcm.h" -#include "hex.h" -#include "hmac.h" -#include "modes.h" -#include "mqueue.h" -#include "nbtheory.h" -#include "osrng.h" -#include "pkcspad.h" -#include "pssr.h" -#include "randpool.h" -#include "rsa.h" -#include "rw.h" -#include "sha.h" -#include "trdlocal.h" - -#ifdef CRYPTOPP_IMPORTS - -#ifdef _DLL -// cause CRT DLL to be initialized before Crypto++ so that we can use malloc and free during DllMain() -#ifdef NDEBUG -#pragma comment(lib, "msvcrt") -#else -#pragma comment(lib, "msvcrtd") -#endif -#endif - -#pragma comment(lib, "cryptopp") - -#endif // #ifdef CRYPTOPP_IMPORTS - -#include // for new_handler - -NAMESPACE_BEGIN(CryptoPP) - -#if !(defined(_MSC_VER) && (_MSC_VER < 1300)) -using std::new_handler; -#endif - -typedef void * (CRYPTOPP_API * PNew)(size_t); -typedef void (CRYPTOPP_API * PDelete)(void *); -typedef void (CRYPTOPP_API * PGetNewAndDelete)(PNew &, PDelete &); -typedef new_handler (CRYPTOPP_API * PSetNewHandler)(new_handler); -typedef void (CRYPTOPP_API * PSetNewAndDelete)(PNew, PDelete, PSetNewHandler); - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/dmac.h b/lib/cryptopp/dmac.h deleted file mode 100644 index 80b54ac2f..000000000 --- a/lib/cryptopp/dmac.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef CRYPTOPP_DMAC_H -#define CRYPTOPP_DMAC_H - -#include "cbcmac.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -template -class CRYPTOPP_NO_VTABLE DMAC_Base : public SameKeyLengthAs, public MessageAuthenticationCode -{ -public: - static std::string StaticAlgorithmName() {return std::string("DMAC(") + T::StaticAlgorithmName() + ")";} - - CRYPTOPP_CONSTANT(DIGESTSIZE=T::BLOCKSIZE) - - DMAC_Base() {} - - void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); - void Update(const byte *input, size_t length); - void TruncatedFinal(byte *mac, size_t size); - unsigned int DigestSize() const {return DIGESTSIZE;} - -private: - byte *GenerateSubKeys(const byte *key, size_t keylength); - - size_t m_subkeylength; - SecByteBlock m_subkeys; - CBC_MAC m_mac1; - typename T::Encryption m_f2; - unsigned int m_counter; -}; - -//! DMAC -/*! Based on "CBC MAC for Real-Time Data Sources" by Erez Petrank - and Charles Rackoff. T should be a class derived from BlockCipherDocumentation. -*/ -template -class DMAC : public MessageAuthenticationCodeFinal > -{ -public: - DMAC() {} - DMAC(const byte *key, size_t length=DMAC_Base::DEFAULT_KEYLENGTH) - {this->SetKey(key, length);} -}; - -template -void DMAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) -{ - m_subkeylength = T::StaticGetValidKeyLength(T::BLOCKSIZE); - m_subkeys.resize(2*UnsignedMin((unsigned int)T::BLOCKSIZE, m_subkeylength)); - m_mac1.SetKey(GenerateSubKeys(key, length), m_subkeylength, params); - m_f2.SetKey(m_subkeys+m_subkeys.size()/2, m_subkeylength, params); - m_counter = 0; - m_subkeys.resize(0); -} - -template -void DMAC_Base::Update(const byte *input, size_t length) -{ - m_mac1.Update(input, length); - m_counter = (unsigned int)((m_counter + length) % T::BLOCKSIZE); -} - -template -void DMAC_Base::TruncatedFinal(byte *mac, size_t size) -{ - ThrowIfInvalidTruncatedSize(size); - - byte pad[T::BLOCKSIZE]; - byte padByte = byte(T::BLOCKSIZE-m_counter); - memset(pad, padByte, padByte); - m_mac1.Update(pad, padByte); - m_mac1.TruncatedFinal(mac, size); - m_f2.ProcessBlock(mac); - - m_counter = 0; // reset for next message -} - -template -byte *DMAC_Base::GenerateSubKeys(const byte *key, size_t keylength) -{ - typename T::Encryption cipher(key, keylength); - memset(m_subkeys, 0, m_subkeys.size()); - cipher.ProcessBlock(m_subkeys); - m_subkeys[m_subkeys.size()/2 + T::BLOCKSIZE - 1] = 1; - cipher.ProcessBlock(m_subkeys+m_subkeys.size()/2); - return m_subkeys; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/dsa.cpp b/lib/cryptopp/dsa.cpp deleted file mode 100644 index 5aace4857..000000000 --- a/lib/cryptopp/dsa.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// dsa.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "dsa.h" -#include "nbtheory.h" - -NAMESPACE_BEGIN(CryptoPP) - -size_t DSAConvertSignatureFormat(byte *buffer, size_t bufferSize, DSASignatureFormat toFormat, const byte *signature, size_t signatureLen, DSASignatureFormat fromFormat) -{ - Integer r, s; - StringStore store(signature, signatureLen); - ArraySink sink(buffer, bufferSize); - - switch (fromFormat) - { - case DSA_P1363: - r.Decode(store, signatureLen/2); - s.Decode(store, signatureLen/2); - break; - case DSA_DER: - { - BERSequenceDecoder seq(store); - r.BERDecode(seq); - s.BERDecode(seq); - seq.MessageEnd(); - break; - } - case DSA_OPENPGP: - r.OpenPGPDecode(store); - s.OpenPGPDecode(store); - break; - } - - switch (toFormat) - { - case DSA_P1363: - r.Encode(sink, bufferSize/2); - s.Encode(sink, bufferSize/2); - break; - case DSA_DER: - { - DERSequenceEncoder seq(sink); - r.DEREncode(seq); - s.DEREncode(seq); - seq.MessageEnd(); - break; - } - case DSA_OPENPGP: - r.OpenPGPEncode(sink); - s.OpenPGPEncode(sink); - break; - } - - return (size_t)sink.TotalPutLength(); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/dsa.h b/lib/cryptopp/dsa.h deleted file mode 100644 index 6ae03877c..000000000 --- a/lib/cryptopp/dsa.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef CRYPTOPP_DSA_H -#define CRYPTOPP_DSA_H - -/** \file -*/ - -#include "gfpcrypt.h" - -NAMESPACE_BEGIN(CryptoPP) - -/*! The DSA signature format used by Crypto++ is as defined by IEEE P1363. - Java uses the DER format, and OpenPGP uses the OpenPGP format. */ -enum DSASignatureFormat {DSA_P1363, DSA_DER, DSA_OPENPGP}; -/** This function converts between these formats, and returns length of signature in the target format. - If toFormat == DSA_P1363, bufferSize must equal publicKey.SignatureLength() */ -size_t DSAConvertSignatureFormat(byte *buffer, size_t bufferSize, DSASignatureFormat toFormat, - const byte *signature, size_t signatureLen, DSASignatureFormat fromFormat); - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - -typedef DSA::Signer DSAPrivateKey; -typedef DSA::Verifier DSAPublicKey; - -const int MIN_DSA_PRIME_LENGTH = DSA::MIN_PRIME_LENGTH; -const int MAX_DSA_PRIME_LENGTH = DSA::MAX_PRIME_LENGTH; -const int DSA_PRIME_LENGTH_MULTIPLE = DSA::PRIME_LENGTH_MULTIPLE; - -inline bool GenerateDSAPrimes(const byte *seed, size_t seedLength, int &counter, Integer &p, unsigned int primeLength, Integer &q) - {return DSA::GeneratePrimes(seed, seedLength, counter, p, primeLength, q);} - -#endif - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/eax.cpp b/lib/cryptopp/eax.cpp deleted file mode 100644 index 2728c9bcd..000000000 --- a/lib/cryptopp/eax.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// eax.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "eax.h" - -NAMESPACE_BEGIN(CryptoPP) - -void EAX_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) -{ - AccessMAC().SetKey(userKey, keylength, params); - m_buffer.New(2*AccessMAC().TagSize()); -} - -void EAX_Base::Resync(const byte *iv, size_t len) -{ - MessageAuthenticationCode &mac = AccessMAC(); - unsigned int blockSize = mac.TagSize(); - - memset(m_buffer, 0, blockSize); - mac.Update(m_buffer, blockSize); - mac.CalculateDigest(m_buffer+blockSize, iv, len); - - m_buffer[blockSize-1] = 1; - mac.Update(m_buffer, blockSize); - - m_ctr.SetCipherWithIV(AccessMAC().AccessCipher(), m_buffer+blockSize, blockSize); -} - -size_t EAX_Base::AuthenticateBlocks(const byte *data, size_t len) -{ - AccessMAC().Update(data, len); - return 0; -} - -void EAX_Base::AuthenticateLastHeaderBlock() -{ - assert(m_bufferedDataLength == 0); - MessageAuthenticationCode &mac = AccessMAC(); - unsigned int blockSize = mac.TagSize(); - - mac.Final(m_buffer); - xorbuf(m_buffer+blockSize, m_buffer, blockSize); - - memset(m_buffer, 0, blockSize); - m_buffer[blockSize-1] = 2; - mac.Update(m_buffer, blockSize); -} - -void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize) -{ - assert(m_bufferedDataLength == 0); - MessageAuthenticationCode &mac = AccessMAC(); - unsigned int blockSize = mac.TagSize(); - - mac.TruncatedFinal(m_buffer, macSize); - xorbuf(tag, m_buffer, m_buffer+blockSize, macSize); -} - -NAMESPACE_END diff --git a/lib/cryptopp/eax.h b/lib/cryptopp/eax.h deleted file mode 100644 index e48ee92b5..000000000 --- a/lib/cryptopp/eax.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef CRYPTOPP_EAX_H -#define CRYPTOPP_EAX_H - -#include "authenc.h" -#include "modes.h" -#include "cmac.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! . -class CRYPTOPP_NO_VTABLE EAX_Base : public AuthenticatedSymmetricCipherBase -{ -public: - // AuthenticatedSymmetricCipher - std::string AlgorithmName() const - {return GetMAC().GetCipher().AlgorithmName() + std::string("/EAX");} - size_t MinKeyLength() const - {return GetMAC().MinKeyLength();} - size_t MaxKeyLength() const - {return GetMAC().MaxKeyLength();} - size_t DefaultKeyLength() const - {return GetMAC().DefaultKeyLength();} - size_t GetValidKeyLength(size_t n) const - {return GetMAC().GetValidKeyLength(n);} - bool IsValidKeyLength(size_t n) const - {return GetMAC().IsValidKeyLength(n);} - unsigned int OptimalDataAlignment() const - {return GetMAC().OptimalDataAlignment();} - IV_Requirement IVRequirement() const - {return UNIQUE_IV;} - unsigned int IVSize() const - {return GetMAC().TagSize();} - unsigned int MinIVLength() const - {return 0;} - unsigned int MaxIVLength() const - {return UINT_MAX;} - unsigned int DigestSize() const - {return GetMAC().TagSize();} - lword MaxHeaderLength() const - {return LWORD_MAX;} - lword MaxMessageLength() const - {return LWORD_MAX;} - -protected: - // AuthenticatedSymmetricCipherBase - bool AuthenticationIsOnPlaintext() const - {return false;} - unsigned int AuthenticationBlockSize() const - {return 1;} - void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms); - void Resync(const byte *iv, size_t len); - size_t AuthenticateBlocks(const byte *data, size_t len); - void AuthenticateLastHeaderBlock(); - void AuthenticateLastFooterBlock(byte *mac, size_t macSize); - SymmetricCipher & AccessSymmetricCipher() {return m_ctr;} - const CMAC_Base & GetMAC() const {return const_cast(this)->AccessMAC();} - virtual CMAC_Base & AccessMAC() =0; - - CTR_Mode_ExternalCipher::Encryption m_ctr; -}; - -//! . -template -class EAX_Final : public EAX_Base -{ -public: - static std::string StaticAlgorithmName() - {return T_BlockCipher::StaticAlgorithmName() + std::string("/EAX");} - bool IsForwardTransformation() const - {return T_IsEncryption;} - -private: - CMAC_Base & AccessMAC() {return m_cmac;} - CMAC m_cmac; -}; - -#ifdef EAX // EAX is defined to 11 on GCC 3.4.3, OpenSolaris 8.11 -#undef EAX -#endif - -/// EAX -template -struct EAX : public AuthenticatedSymmetricCipherDocumentation -{ - typedef EAX_Final Encryption; - typedef EAX_Final Decryption; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/ec2n.cpp b/lib/cryptopp/ec2n.cpp deleted file mode 100644 index b513b2cb8..000000000 --- a/lib/cryptopp/ec2n.cpp +++ /dev/null @@ -1,292 +0,0 @@ -// ec2n.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "ec2n.h" -#include "asn.h" - -#include "algebra.cpp" -#include "eprecomp.cpp" - -NAMESPACE_BEGIN(CryptoPP) - -EC2N::EC2N(BufferedTransformation &bt) - : m_field(BERDecodeGF2NP(bt)) -{ - BERSequenceDecoder seq(bt); - m_field->BERDecodeElement(seq, m_a); - m_field->BERDecodeElement(seq, m_b); - // skip optional seed - if (!seq.EndReached()) - { - SecByteBlock seed; - unsigned int unused; - BERDecodeBitString(seq, seed, unused); - } - seq.MessageEnd(); -} - -void EC2N::DEREncode(BufferedTransformation &bt) const -{ - m_field->DEREncode(bt); - DERSequenceEncoder seq(bt); - m_field->DEREncodeElement(seq, m_a); - m_field->DEREncodeElement(seq, m_b); - seq.MessageEnd(); -} - -bool EC2N::DecodePoint(EC2N::Point &P, const byte *encodedPoint, size_t encodedPointLen) const -{ - StringStore store(encodedPoint, encodedPointLen); - return DecodePoint(P, store, encodedPointLen); -} - -bool EC2N::DecodePoint(EC2N::Point &P, BufferedTransformation &bt, size_t encodedPointLen) const -{ - byte type; - if (encodedPointLen < 1 || !bt.Get(type)) - return false; - - switch (type) - { - case 0: - P.identity = true; - return true; - case 2: - case 3: - { - if (encodedPointLen != EncodedPointSize(true)) - return false; - - P.identity = false; - P.x.Decode(bt, m_field->MaxElementByteLength()); - - if (P.x.IsZero()) - { - P.y = m_field->SquareRoot(m_b); - return true; - } - - FieldElement z = m_field->Square(P.x); - assert(P.x == m_field->SquareRoot(z)); - P.y = m_field->Divide(m_field->Add(m_field->Multiply(z, m_field->Add(P.x, m_a)), m_b), z); - assert(P.x == m_field->Subtract(m_field->Divide(m_field->Subtract(m_field->Multiply(P.y, z), m_b), z), m_a)); - z = m_field->SolveQuadraticEquation(P.y); - assert(m_field->Add(m_field->Square(z), z) == P.y); - z.SetCoefficient(0, type & 1); - - P.y = m_field->Multiply(z, P.x); - return true; - } - case 4: - { - if (encodedPointLen != EncodedPointSize(false)) - return false; - - unsigned int len = m_field->MaxElementByteLength(); - P.identity = false; - P.x.Decode(bt, len); - P.y.Decode(bt, len); - return true; - } - default: - return false; - } -} - -void EC2N::EncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const -{ - if (P.identity) - NullStore().TransferTo(bt, EncodedPointSize(compressed)); - else if (compressed) - { - bt.Put(2 + (!P.x ? 0 : m_field->Divide(P.y, P.x).GetBit(0))); - P.x.Encode(bt, m_field->MaxElementByteLength()); - } - else - { - unsigned int len = m_field->MaxElementByteLength(); - bt.Put(4); // uncompressed - P.x.Encode(bt, len); - P.y.Encode(bt, len); - } -} - -void EC2N::EncodePoint(byte *encodedPoint, const Point &P, bool compressed) const -{ - ArraySink sink(encodedPoint, EncodedPointSize(compressed)); - EncodePoint(sink, P, compressed); - assert(sink.TotalPutLength() == EncodedPointSize(compressed)); -} - -EC2N::Point EC2N::BERDecodePoint(BufferedTransformation &bt) const -{ - SecByteBlock str; - BERDecodeOctetString(bt, str); - Point P; - if (!DecodePoint(P, str, str.size())) - BERDecodeError(); - return P; -} - -void EC2N::DEREncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const -{ - SecByteBlock str(EncodedPointSize(compressed)); - EncodePoint(str, P, compressed); - DEREncodeOctetString(bt, str); -} - -bool EC2N::ValidateParameters(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = !!m_b; - pass = pass && m_a.CoefficientCount() <= m_field->MaxElementBitLength(); - pass = pass && m_b.CoefficientCount() <= m_field->MaxElementBitLength(); - - if (level >= 1) - pass = pass && m_field->GetModulus().IsIrreducible(); - - return pass; -} - -bool EC2N::VerifyPoint(const Point &P) const -{ - const FieldElement &x = P.x, &y = P.y; - return P.identity || - (x.CoefficientCount() <= m_field->MaxElementBitLength() - && y.CoefficientCount() <= m_field->MaxElementBitLength() - && !(((x+m_a)*x*x+m_b-(x+y)*y)%m_field->GetModulus())); -} - -bool EC2N::Equal(const Point &P, const Point &Q) const -{ - if (P.identity && Q.identity) - return true; - - if (P.identity && !Q.identity) - return false; - - if (!P.identity && Q.identity) - return false; - - return (m_field->Equal(P.x,Q.x) && m_field->Equal(P.y,Q.y)); -} - -const EC2N::Point& EC2N::Identity() const -{ - return Singleton().Ref(); -} - -const EC2N::Point& EC2N::Inverse(const Point &P) const -{ - if (P.identity) - return P; - else - { - m_R.identity = false; - m_R.y = m_field->Add(P.x, P.y); - m_R.x = P.x; - return m_R; - } -} - -const EC2N::Point& EC2N::Add(const Point &P, const Point &Q) const -{ - if (P.identity) return Q; - if (Q.identity) return P; - if (Equal(P, Q)) return Double(P); - if (m_field->Equal(P.x, Q.x) && m_field->Equal(P.y, m_field->Add(Q.x, Q.y))) return Identity(); - - FieldElement t = m_field->Add(P.y, Q.y); - t = m_field->Divide(t, m_field->Add(P.x, Q.x)); - FieldElement x = m_field->Square(t); - m_field->Accumulate(x, t); - m_field->Accumulate(x, Q.x); - m_field->Accumulate(x, m_a); - m_R.y = m_field->Add(P.y, m_field->Multiply(t, x)); - m_field->Accumulate(x, P.x); - m_field->Accumulate(m_R.y, x); - - m_R.x.swap(x); - m_R.identity = false; - return m_R; -} - -const EC2N::Point& EC2N::Double(const Point &P) const -{ - if (P.identity) return P; - if (!m_field->IsUnit(P.x)) return Identity(); - - FieldElement t = m_field->Divide(P.y, P.x); - m_field->Accumulate(t, P.x); - m_R.y = m_field->Square(P.x); - m_R.x = m_field->Square(t); - m_field->Accumulate(m_R.x, t); - m_field->Accumulate(m_R.x, m_a); - m_field->Accumulate(m_R.y, m_field->Multiply(t, m_R.x)); - m_field->Accumulate(m_R.y, m_R.x); - - m_R.identity = false; - return m_R; -} - -// ******************************************************** - -/* -EcPrecomputation& EcPrecomputation::operator=(const EcPrecomputation &rhs) -{ - m_ec = rhs.m_ec; - m_ep = rhs.m_ep; - m_ep.m_group = m_ec.get(); - return *this; -} - -void EcPrecomputation::SetCurveAndBase(const EC2N &ec, const EC2N::Point &base) -{ - m_ec.reset(new EC2N(ec)); - m_ep.SetGroupAndBase(*m_ec, base); -} - -void EcPrecomputation::Precompute(unsigned int maxExpBits, unsigned int storage) -{ - m_ep.Precompute(maxExpBits, storage); -} - -void EcPrecomputation::Load(BufferedTransformation &bt) -{ - BERSequenceDecoder seq(bt); - word32 version; - BERDecodeUnsigned(seq, version, INTEGER, 1, 1); - m_ep.m_exponentBase.BERDecode(seq); - m_ep.m_windowSize = m_ep.m_exponentBase.BitCount() - 1; - m_ep.m_bases.clear(); - while (!seq.EndReached()) - m_ep.m_bases.push_back(m_ec->BERDecodePoint(seq)); - seq.MessageEnd(); -} - -void EcPrecomputation::Save(BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - DEREncodeUnsigned(seq, 1); // version - m_ep.m_exponentBase.DEREncode(seq); - for (unsigned i=0; iDEREncodePoint(seq, m_ep.m_bases[i]); - seq.MessageEnd(); -} - -EC2N::Point EcPrecomputation::Exponentiate(const Integer &exponent) const -{ - return m_ep.Exponentiate(exponent); -} - -EC2N::Point EcPrecomputation::CascadeExponentiate(const Integer &exponent, const DL_FixedBasePrecomputation &pc2, const Integer &exponent2) const -{ - return m_ep.CascadeExponentiate(exponent, static_cast &>(pc2).m_ep, exponent2); -} -*/ - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/ec2n.h b/lib/cryptopp/ec2n.h deleted file mode 100644 index ae4007cd6..000000000 --- a/lib/cryptopp/ec2n.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef CRYPTOPP_EC2N_H -#define CRYPTOPP_EC2N_H - -#include "gf2n.h" -#include "eprecomp.h" -#include "smartptr.h" -#include "pubkey.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! Elliptic Curve Point -struct CRYPTOPP_DLL EC2NPoint -{ - EC2NPoint() : identity(true) {} - EC2NPoint(const PolynomialMod2 &x, const PolynomialMod2 &y) - : identity(false), x(x), y(y) {} - - bool operator==(const EC2NPoint &t) const - {return (identity && t.identity) || (!identity && !t.identity && x==t.x && y==t.y);} - bool operator< (const EC2NPoint &t) const - {return identity ? !t.identity : (!t.identity && (x; - -//! Elliptic Curve over GF(2^n) -class CRYPTOPP_DLL EC2N : public AbstractGroup -{ -public: - typedef GF2NP Field; - typedef Field::Element FieldElement; - typedef EC2NPoint Point; - - EC2N() {} - EC2N(const Field &field, const Field::Element &a, const Field::Element &b) - : m_field(field), m_a(a), m_b(b) {} - // construct from BER encoded parameters - // this constructor will decode and extract the the fields fieldID and curve of the sequence ECParameters - EC2N(BufferedTransformation &bt); - - // encode the fields fieldID and curve of the sequence ECParameters - void DEREncode(BufferedTransformation &bt) const; - - bool Equal(const Point &P, const Point &Q) const; - const Point& Identity() const; - const Point& Inverse(const Point &P) const; - bool InversionIsFast() const {return true;} - const Point& Add(const Point &P, const Point &Q) const; - const Point& Double(const Point &P) const; - - Point Multiply(const Integer &k, const Point &P) const - {return ScalarMultiply(P, k);} - Point CascadeMultiply(const Integer &k1, const Point &P, const Integer &k2, const Point &Q) const - {return CascadeScalarMultiply(P, k1, Q, k2);} - - bool ValidateParameters(RandomNumberGenerator &rng, unsigned int level=3) const; - bool VerifyPoint(const Point &P) const; - - unsigned int EncodedPointSize(bool compressed = false) const - {return 1 + (compressed?1:2)*m_field->MaxElementByteLength();} - // returns false if point is compressed and not valid (doesn't check if uncompressed) - bool DecodePoint(Point &P, BufferedTransformation &bt, size_t len) const; - bool DecodePoint(Point &P, const byte *encodedPoint, size_t len) const; - void EncodePoint(byte *encodedPoint, const Point &P, bool compressed) const; - void EncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const; - - Point BERDecodePoint(BufferedTransformation &bt) const; - void DEREncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const; - - Integer FieldSize() const {return Integer::Power2(m_field->MaxElementBitLength());} - const Field & GetField() const {return *m_field;} - const FieldElement & GetA() const {return m_a;} - const FieldElement & GetB() const {return m_b;} - - bool operator==(const EC2N &rhs) const - {return GetField() == rhs.GetField() && m_a == rhs.m_a && m_b == rhs.m_b;} - -private: - clonable_ptr m_field; - FieldElement m_a, m_b; - mutable Point m_R; -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS DL_FixedBasePrecomputationImpl; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupPrecomputation; - -template class EcPrecomputation; - -//! EC2N precomputation -template<> class EcPrecomputation : public DL_GroupPrecomputation -{ -public: - typedef EC2N EllipticCurve; - - // DL_GroupPrecomputation - const AbstractGroup & GetGroup() const {return m_ec;} - Element BERDecodeElement(BufferedTransformation &bt) const {return m_ec.BERDecodePoint(bt);} - void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {m_ec.DEREncodePoint(bt, v, false);} - - // non-inherited - void SetCurve(const EC2N &ec) {m_ec = ec;} - const EC2N & GetCurve() const {return m_ec;} - -private: - EC2N m_ec; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/eccrypto.cpp b/lib/cryptopp/eccrypto.cpp deleted file mode 100644 index 922104c4d..000000000 --- a/lib/cryptopp/eccrypto.cpp +++ /dev/null @@ -1,694 +0,0 @@ -// eccrypto.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "eccrypto.h" -#include "nbtheory.h" -#include "oids.h" -#include "hex.h" -#include "argnames.h" -#include "ec2n.h" - -NAMESPACE_BEGIN(CryptoPP) - -#if 0 -static void ECDSA_TestInstantiations() -{ - ECDSA::Signer t1; - ECDSA::Verifier t2(t1); - ECNR::Signer t3; - ECNR::Verifier t4(t3); - ECIES::Encryptor t5; - ECIES::Decryptor t6; - ECDH::Domain t7; - ECMQV::Domain t8; -} -#endif - -// VC60 workaround: complains when these functions are put into an anonymous namespace -static Integer ConvertToInteger(const PolynomialMod2 &x) -{ - unsigned int l = x.ByteCount(); - SecByteBlock temp(l); - x.Encode(temp, l); - return Integer(temp, l); -} - -static inline Integer ConvertToInteger(const Integer &x) -{ - return x; -} - -static bool CheckMOVCondition(const Integer &q, const Integer &r) -{ - // see "Updated standards for validating elliptic curves", http://eprint.iacr.org/2007/343 - Integer t = 1; - unsigned int n = q.IsEven() ? 1 : q.BitCount(), m = r.BitCount(); - - for (unsigned int i=n; DiscreteLogWorkFactor(i) struct EcRecommendedParameters; - -template<> struct EcRecommendedParameters -{ - EcRecommendedParameters(const OID &oid, unsigned int t2, unsigned int t3, unsigned int t4, const char *a, const char *b, const char *g, const char *n, unsigned int h) - : oid(oid), t0(0), t1(0), t2(t2), t3(t3), t4(t4), a(a), b(b), g(g), n(n), h(h) {} - EcRecommendedParameters(const OID &oid, unsigned int t0, unsigned int t1, unsigned int t2, unsigned int t3, unsigned int t4, const char *a, const char *b, const char *g, const char *n, unsigned int h) - : oid(oid), t0(t0), t1(t1), t2(t2), t3(t3), t4(t4), a(a), b(b), g(g), n(n), h(h) {} - EC2N *NewEC() const - { - StringSource ssA(a, true, new HexDecoder); - StringSource ssB(b, true, new HexDecoder); - if (t0 == 0) - return new EC2N(GF2NT(t2, t3, t4), EC2N::FieldElement(ssA, (size_t)ssA.MaxRetrievable()), EC2N::FieldElement(ssB, (size_t)ssB.MaxRetrievable())); - else - return new EC2N(GF2NPP(t0, t1, t2, t3, t4), EC2N::FieldElement(ssA, (size_t)ssA.MaxRetrievable()), EC2N::FieldElement(ssB, (size_t)ssB.MaxRetrievable())); - }; - - OID oid; - unsigned int t0, t1, t2, t3, t4; - const char *a, *b, *g, *n; - unsigned int h; -}; - -template<> struct EcRecommendedParameters -{ - EcRecommendedParameters(const OID &oid, const char *p, const char *a, const char *b, const char *g, const char *n, unsigned int h) - : oid(oid), p(p), a(a), b(b), g(g), n(n), h(h) {} - ECP *NewEC() const - { - StringSource ssP(p, true, new HexDecoder); - StringSource ssA(a, true, new HexDecoder); - StringSource ssB(b, true, new HexDecoder); - return new ECP(Integer(ssP, (size_t)ssP.MaxRetrievable()), ECP::FieldElement(ssA, (size_t)ssA.MaxRetrievable()), ECP::FieldElement(ssB, (size_t)ssB.MaxRetrievable())); - }; - - OID oid; - const char *p; - const char *a, *b, *g, *n; - unsigned int h; -}; - -struct OIDLessThan -{ - template - inline bool operator()(const EcRecommendedParameters& a, const OID& b) {return a.oid < b;} - template - inline bool operator()(const OID& a, const EcRecommendedParameters& b) {return a < b.oid;} - template - inline bool operator()(const EcRecommendedParameters& a, const EcRecommendedParameters& b) {return a.oid < b.oid;} -}; - -static void GetRecommendedParameters(const EcRecommendedParameters *&begin, const EcRecommendedParameters *&end) -{ - // this array must be sorted by OID - static const EcRecommendedParameters rec[] = { - EcRecommendedParameters(ASN1::sect163k1(), - 163, 7, 6, 3, 0, - "000000000000000000000000000000000000000001", - "000000000000000000000000000000000000000001", - "0402FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE80289070FB05D38FF58321F2E800536D538CCDAA3D9", - "04000000000000000000020108A2E0CC0D99F8A5EF", - 2), - EcRecommendedParameters(ASN1::sect163r1(), - 163, 7, 6, 3, 0, - "07B6882CAAEFA84F9554FF8428BD88E246D2782AE2", - "0713612DCDDCB40AAB946BDA29CA91F73AF958AFD9", - "040369979697AB43897789566789567F787A7876A65400435EDB42EFAFB2989D51FEFCE3C80988F41FF883", - "03FFFFFFFFFFFFFFFFFFFF48AAB689C29CA710279B", - 2), - EcRecommendedParameters(ASN1::sect239k1(), - 239, 158, 0, - "000000000000000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000000000000001", - "0429A0B6A887A983E9730988A68727A8B2D126C44CC2CC7B2A6555193035DC76310804F12E549BDB011C103089E73510ACB275FC312A5DC6B76553F0CA", - "2000000000000000000000000000005A79FEC67CB6E91F1C1DA800E478A5", - 4), - EcRecommendedParameters(ASN1::sect113r1(), - 113, 9, 0, - "003088250CA6E7C7FE649CE85820F7", - "00E8BEE4D3E2260744188BE0E9C723", - "04009D73616F35F4AB1407D73562C10F00A52830277958EE84D1315ED31886", - "0100000000000000D9CCEC8A39E56F", - 2), - EcRecommendedParameters(ASN1::sect113r2(), - 113, 9, 0, - "00689918DBEC7E5A0DD6DFC0AA55C7", - "0095E9A9EC9B297BD4BF36E059184F", - "0401A57A6A7B26CA5EF52FCDB816479700B3ADC94ED1FE674C06E695BABA1D", - "010000000000000108789B2496AF93", - 2), - EcRecommendedParameters(ASN1::sect163r2(), - 163, 7, 6, 3, 0, - "000000000000000000000000000000000000000001", - "020A601907B8C953CA1481EB10512F78744A3205FD", - "0403F0EBA16286A2D57EA0991168D4994637E8343E3600D51FBC6C71A0094FA2CDD545B11C5C0C797324F1", - "040000000000000000000292FE77E70C12A4234C33", - 2), - EcRecommendedParameters(ASN1::sect283k1(), - 283, 12, 7, 5, 0, - "000000000000000000000000000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000000000000000000000000001", - "040503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC245849283601CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259", - "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61", - 4), - EcRecommendedParameters(ASN1::sect283r1(), - 283, 12, 7, 5, 0, - "000000000000000000000000000000000000000000000000000000000000000000000001", - "027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5", - "0405F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B1205303676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4", - "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307", - 2), - EcRecommendedParameters(ASN1::sect131r1(), - 131, 8, 3, 2, 0, - "07A11B09A76B562144418FF3FF8C2570B8", - "0217C05610884B63B9C6C7291678F9D341", - "040081BAF91FDF9833C40F9C181343638399078C6E7EA38C001F73C8134B1B4EF9E150", - "0400000000000000023123953A9464B54D", - 2), - EcRecommendedParameters(ASN1::sect131r2(), - 131, 8, 3, 2, 0, - "03E5A88919D7CAFCBF415F07C2176573B2", - "04B8266A46C55657AC734CE38F018F2192", - "040356DCD8F2F95031AD652D23951BB366A80648F06D867940A5366D9E265DE9EB240F", - "0400000000000000016954A233049BA98F", - 2), - EcRecommendedParameters(ASN1::sect193r1(), - 193, 15, 0, - "0017858FEB7A98975169E171F77B4087DE098AC8A911DF7B01", - "00FDFB49BFE6C3A89FACADAA7A1E5BBC7CC1C2E5D831478814", - "0401F481BC5F0FF84A74AD6CDF6FDEF4BF6179625372D8C0C5E10025E399F2903712CCF3EA9E3A1AD17FB0B3201B6AF7CE1B05", - "01000000000000000000000000C7F34A778F443ACC920EBA49", - 2), - EcRecommendedParameters(ASN1::sect193r2(), - 193, 15, 0, - "0163F35A5137C2CE3EA6ED8667190B0BC43ECD69977702709B", - "00C9BB9E8927D4D64C377E2AB2856A5B16E3EFB7F61D4316AE", - "0400D9B67D192E0367C803F39E1A7E82CA14A651350AAE617E8F01CE94335607C304AC29E7DEFBD9CA01F596F927224CDECF6C", - "010000000000000000000000015AAB561B005413CCD4EE99D5", - 2), - EcRecommendedParameters(ASN1::sect233k1(), - 233, 74, 0, - "000000000000000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000000000000001", - "04017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD612601DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3", - "8000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF", - 4), - EcRecommendedParameters(ASN1::sect233r1(), - 233, 74, 0, - "000000000000000000000000000000000000000000000000000000000001", - "0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD", - "0400FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052", - "01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7", - 2), - EcRecommendedParameters(ASN1::sect409k1(), - 409, 87, 0, - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "040060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE902374601E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B", - "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF", - 4), - EcRecommendedParameters(ASN1::sect409r1(), - 409, 87, 0, - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F", - "04015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A70061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706", - "010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173", - 2), - EcRecommendedParameters(ASN1::sect571k1(), - 571, 10, 5, 2, 0, - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "04026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C89720349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3", - "020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001", - 4), - EcRecommendedParameters(ASN1::sect571r1(), - 571, 10, 5, 2, 0, - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A", - "040303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B", - "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47", - 2), - }; - begin = rec; - end = rec + sizeof(rec)/sizeof(rec[0]); -} - -static void GetRecommendedParameters(const EcRecommendedParameters *&begin, const EcRecommendedParameters *&end) -{ - // this array must be sorted by OID - static const EcRecommendedParameters rec[] = { - EcRecommendedParameters(ASN1::secp192r1(), - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", - "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1", - "04188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF101207192B95FFC8DA78631011ED6B24CDD573F977A11E794811", - "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831", - 1), - EcRecommendedParameters(ASN1::secp256r1(), - "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", - "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", - "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B", - "046B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C2964FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", - "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", - 1), - EcRecommendedParameters(ASN1::brainpoolP160r1(), - "E95E4A5F737059DC60DFC7AD95B3D8139515620F", - "340E7BE2A280EB74E2BE61BADA745D97E8F7C300", - "1E589A8595423412134FAA2DBDEC95C8D8675E58", - "04BED5AF16EA3F6A4F62938C4631EB5AF7BDBCDBC31667CB477A1A8EC338F94741669C976316DA6321", - "E95E4A5F737059DC60DF5991D45029409E60FC09", - 1), - EcRecommendedParameters(ASN1::brainpoolP192r1(), - "C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297", - "6A91174076B1E0E19C39C031FE8685C1CAE040E5C69A28EF", - "469A28EF7C28CCA3DC721D044F4496BCCA7EF4146FBF25C9", - "04C0A0647EAAB6A48753B033C56CB0F0900A2F5C4853375FD614B690866ABD5BB88B5F4828C1490002E6773FA2FA299B8F", - "C302F41D932A36CDA7A3462F9E9E916B5BE8F1029AC4ACC1", - 1), - EcRecommendedParameters(ASN1::brainpoolP224r1(), - "D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF", - "68A5E62CA9CE6C1C299803A6C1530B514E182AD8B0042A59CAD29F43", - "2580F63CCFE44138870713B1A92369E33E2135D266DBB372386C400B", - "040D9029AD2C7E5CF4340823B2A87DC68C9E4CE3174C1E6EFDEE12C07D58AA56F772C0726F24C6B89E4ECDAC24354B9E99CAA3F6D3761402CD", - "D7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A7939F", - 1), - EcRecommendedParameters(ASN1::brainpoolP256r1(), - "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", - "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", - "26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", - "048BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", - "A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", - 1), - EcRecommendedParameters(ASN1::brainpoolP320r1(), - "D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28FCD412B1F1B32E27", - "3EE30B568FBAB0F883CCEBD46D3F3BB8A2A73513F5EB79DA66190EB085FFA9F492F375A97D860EB4", - "520883949DFDBC42D3AD198640688A6FE13F41349554B49ACC31DCCD884539816F5EB4AC8FB1F1A6", - "0443BD7E9AFB53D8B85289BCC48EE5BFE6F20137D10A087EB6E7871E2A10A599C710AF8D0D39E2061114FDD05545EC1CC8AB4093247F77275E0743FFED117182EAA9C77877AAAC6AC7D35245D1692E8EE1", - "D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D482EC7EE8658E98691555B44C59311", - 1), - EcRecommendedParameters(ASN1::brainpoolP384r1(), - "8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A71874700133107EC53", - "7BC382C63D8C150C3C72080ACE05AFA0C2BEA28E4FB22787139165EFBA91F90F8AA5814A503AD4EB04A8C7DD22CE2826", - "04A8C7DD22CE28268B39B55416F0447C2FB77DE107DCD2A62E880EA53EEB62D57CB4390295DBC9943AB78696FA504C11", - "041D1C64F068CF45FFA2A63A81B7C13F6B8847A3E77EF14FE3DB7FCAFE0CBD10E8E826E03436D646AAEF87B2E247D4AF1E8ABE1D7520F9C2A45CB1EB8E95CFD55262B70B29FEEC5864E19C054FF99129280E4646217791811142820341263C5315", - "8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC3103B883202E9046565", - 1), - EcRecommendedParameters(ASN1::brainpoolP512r1(), - "AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3", - "7830A3318B603B89E2327145AC234CC594CBDD8D3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA", - "3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723", - "0481AEE4BDD82ED9645A21322E9C4C6A9385ED9F70B5D916C1B43B62EEF4D0098EFF3B1F78E2D0D48D50D1687B93B97D5F7C6D5047406A5E688B352209BCB9F8227DDE385D566332ECC0EABFA9CF7822FDF209F70024A57B1AA000C55B881F8111B2DCDE494A5F485E5BCA4BD88A2763AED1CA2B2FA8F0540678CD1E0F3AD80892", - "AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA92619418661197FAC10471DB1D381085DDADDB58796829CA90069", - 1), - EcRecommendedParameters(ASN1::secp112r1(), - "DB7C2ABF62E35E668076BEAD208B", - "DB7C2ABF62E35E668076BEAD2088", - "659EF8BA043916EEDE8911702B22", - "0409487239995A5EE76B55F9C2F098A89CE5AF8724C0A23E0E0FF77500", - "DB7C2ABF62E35E7628DFAC6561C5", - 1), - EcRecommendedParameters(ASN1::secp112r2(), - "DB7C2ABF62E35E668076BEAD208B", - "6127C24C05F38A0AAAF65C0EF02C", - "51DEF1815DB5ED74FCC34C85D709", - "044BA30AB5E892B4E1649DD0928643ADCD46F5882E3747DEF36E956E97", - "36DF0AAFD8B8D7597CA10520D04B", - 4), - EcRecommendedParameters(ASN1::secp160r1(), - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC", - "1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45", - "044A96B5688EF573284664698968C38BB913CBFC8223A628553168947D59DCC912042351377AC5FB32", - "0100000000000000000001F4C8F927AED3CA752257", - 1), - EcRecommendedParameters(ASN1::secp160k1(), - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", - "0000000000000000000000000000000000000000", - "0000000000000000000000000000000000000007", - "043B4C382CE37AA192A4019E763036F4F5DD4D7EBB938CF935318FDCED6BC28286531733C3F03C4FEE", - "0100000000000000000001B8FA16DFAB9ACA16B6B3", - 1), - EcRecommendedParameters(ASN1::secp256k1(), - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", - "0000000000000000000000000000000000000000000000000000000000000000", - "0000000000000000000000000000000000000000000000000000000000000007", - "0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", - 1), - EcRecommendedParameters(ASN1::secp128r1(), - "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF", - "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC", - "E87579C11079F43DD824993C2CEE5ED3", - "04161FF7528B899B2D0C28607CA52C5B86CF5AC8395BAFEB13C02DA292DDED7A83", - "FFFFFFFE0000000075A30D1B9038A115", - 1), - EcRecommendedParameters(ASN1::secp128r2(), - "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF", - "D6031998D1B3BBFEBF59CC9BBFF9AEE1", - "5EEEFCA380D02919DC2C6558BB6D8A5D", - "047B6AA5D85E572983E6FB32A7CDEBC14027B6916A894D3AEE7106FE805FC34B44", - "3FFFFFFF7FFFFFFFBE0024720613B5A3", - 4), - EcRecommendedParameters(ASN1::secp160r2(), - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC70", - "B4E134D3FB59EB8BAB57274904664D5AF50388BA", - "0452DCB034293A117E1F4FF11B30F7199D3144CE6DFEAFFEF2E331F296E071FA0DF9982CFEA7D43F2E", - "0100000000000000000000351EE786A818F3A1A16B", - 1), - EcRecommendedParameters(ASN1::secp192k1(), - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37", - "000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000003", - "04DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D", - "FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D", - 1), - EcRecommendedParameters(ASN1::secp224k1(), - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFE56D", - "00000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000005", - "04A1455B334DF099DF30FC28A169A467E9E47075A90F7E650EB6B7A45C7E089FED7FBA344282CAFBD6F7E319F7C0B0BD59E2CA4BDB556D61A5", - "010000000000000000000000000001DCE8D2EC6184CAF0A971769FB1F7", - 1), - EcRecommendedParameters(ASN1::secp224r1(), - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE", - "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4", - "04B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D", - 1), - EcRecommendedParameters(ASN1::secp384r1(), - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC", - "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF", - "04AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB73617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", - 1), - EcRecommendedParameters(ASN1::secp521r1(), - "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", - "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", - "0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", - "0400C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650", - "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", - 1), - }; - begin = rec; - end = rec + sizeof(rec)/sizeof(rec[0]); -} - -template OID DL_GroupParameters_EC::GetNextRecommendedParametersOID(const OID &oid) -{ - const EcRecommendedParameters *begin, *end; - GetRecommendedParameters(begin, end); - const EcRecommendedParameters *it = std::upper_bound(begin, end, oid, OIDLessThan()); - return (it == end ? OID() : it->oid); -} - -template void DL_GroupParameters_EC::Initialize(const OID &oid) -{ - const EcRecommendedParameters *begin, *end; - GetRecommendedParameters(begin, end); - const EcRecommendedParameters *it = std::lower_bound(begin, end, oid, OIDLessThan()); - if (it == end || it->oid != oid) - throw UnknownOID(); - - const EcRecommendedParameters ¶m = *it; - m_oid = oid; - std::auto_ptr ec(param.NewEC()); - this->m_groupPrecomputation.SetCurve(*ec); - - StringSource ssG(param.g, true, new HexDecoder); - Element G; - bool result = GetCurve().DecodePoint(G, ssG, (size_t)ssG.MaxRetrievable()); - this->SetSubgroupGenerator(G); - assert(result); - - StringSource ssN(param.n, true, new HexDecoder); - m_n.Decode(ssN, (size_t)ssN.MaxRetrievable()); - m_k = param.h; -} - -template -bool DL_GroupParameters_EC::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - if (strcmp(name, Name::GroupOID()) == 0) - { - if (m_oid.m_values.empty()) - return false; - - this->ThrowIfTypeMismatch(name, typeid(OID), valueType); - *reinterpret_cast(pValue) = m_oid; - return true; - } - else - return GetValueHelper >(this, name, valueType, pValue).Assignable() - CRYPTOPP_GET_FUNCTION_ENTRY(Curve); -} - -template -void DL_GroupParameters_EC::AssignFrom(const NameValuePairs &source) -{ - OID oid; - if (source.GetValue(Name::GroupOID(), oid)) - Initialize(oid); - else - { - EllipticCurve ec; - Point G; - Integer n; - - source.GetRequiredParameter("DL_GroupParameters_EC", Name::Curve(), ec); - source.GetRequiredParameter("DL_GroupParameters_EC", Name::SubgroupGenerator(), G); - source.GetRequiredParameter("DL_GroupParameters_EC", Name::SubgroupOrder(), n); - Integer k = source.GetValueWithDefault(Name::Cofactor(), Integer::Zero()); - - Initialize(ec, G, n, k); - } -} - -template -void DL_GroupParameters_EC::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg) -{ - try - { - AssignFrom(alg); - } - catch (InvalidArgument &) - { - throw NotImplemented("DL_GroupParameters_EC: curve generation is not implemented yet"); - } -} - -template -void DL_GroupParameters_EC::BERDecode(BufferedTransformation &bt) -{ - byte b; - if (!bt.Peek(b)) - BERDecodeError(); - if (b == OBJECT_IDENTIFIER) - Initialize(OID(bt)); - else - { - BERSequenceDecoder seq(bt); - word32 version; - BERDecodeUnsigned(seq, version, INTEGER, 1, 1); // check version - EllipticCurve ec(seq); - Point G = ec.BERDecodePoint(seq); - Integer n(seq); - Integer k; - bool cofactorPresent = !seq.EndReached(); - if (cofactorPresent) - k.BERDecode(seq); - else - k = Integer::Zero(); - seq.MessageEnd(); - - Initialize(ec, G, n, k); - } -} - -template -void DL_GroupParameters_EC::DEREncode(BufferedTransformation &bt) const -{ - if (m_encodeAsOID && !m_oid.m_values.empty()) - m_oid.DEREncode(bt); - else - { - DERSequenceEncoder seq(bt); - DEREncodeUnsigned(seq, 1); // version - GetCurve().DEREncode(seq); - GetCurve().DEREncodePoint(seq, this->GetSubgroupGenerator(), m_compress); - m_n.DEREncode(seq); - if (m_k.NotZero()) - m_k.DEREncode(seq); - seq.MessageEnd(); - } -} - -template -Integer DL_GroupParameters_EC::GetCofactor() const -{ - if (!m_k) - { - Integer q = GetCurve().FieldSize(); - Integer qSqrt = q.SquareRoot(); - m_k = (q+2*qSqrt+1)/m_n; - } - - return m_k; -} - -template -Integer DL_GroupParameters_EC::ConvertElementToInteger(const Element &element) const -{ - return ConvertToInteger(element.x); -}; - -template -bool DL_GroupParameters_EC::ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = GetCurve().ValidateParameters(rng, level); - - Integer q = GetCurve().FieldSize(); - pass = pass && m_n!=q; - - if (level >= 2) - { - Integer qSqrt = q.SquareRoot(); - pass = pass && m_n>4*qSqrt; - pass = pass && VerifyPrime(rng, m_n, level-2); - pass = pass && (m_k.IsZero() || m_k == (q+2*qSqrt+1)/m_n); - pass = pass && CheckMOVCondition(q, m_n); - } - - return pass; -} - -template -bool DL_GroupParameters_EC::ValidateElement(unsigned int level, const Element &g, const DL_FixedBasePrecomputation *gpc) const -{ - bool pass = !IsIdentity(g) && GetCurve().VerifyPoint(g); - if (level >= 1) - { - if (gpc) - pass = pass && gpc->Exponentiate(this->GetGroupPrecomputation(), Integer::One()) == g; - } - if (level >= 2 && pass) - { - const Integer &q = GetSubgroupOrder(); - Element gq = gpc ? gpc->Exponentiate(this->GetGroupPrecomputation(), q) : this->ExponentiateElement(g, q); - pass = pass && IsIdentity(gq); - } - return pass; -} - -template -void DL_GroupParameters_EC::SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const -{ - GetCurve().SimultaneousMultiply(results, base, exponents, exponentsCount); -} - -template -CPP_TYPENAME DL_GroupParameters_EC::Element DL_GroupParameters_EC::MultiplyElements(const Element &a, const Element &b) const -{ - return GetCurve().Add(a, b); -} - -template -CPP_TYPENAME DL_GroupParameters_EC::Element DL_GroupParameters_EC::CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const -{ - return GetCurve().CascadeMultiply(exponent1, element1, exponent2, element2); -} - -template -OID DL_GroupParameters_EC::GetAlgorithmID() const -{ - return ASN1::id_ecPublicKey(); -} - -// ****************************************************************** - -template -void DL_PublicKey_EC::BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size) -{ - typename EC::Point P; - if (!this->GetGroupParameters().GetCurve().DecodePoint(P, bt, size)) - BERDecodeError(); - this->SetPublicElement(P); -} - -template -void DL_PublicKey_EC::DEREncodePublicKey(BufferedTransformation &bt) const -{ - this->GetGroupParameters().GetCurve().EncodePoint(bt, this->GetPublicElement(), this->GetGroupParameters().GetPointCompression()); -} - -// ****************************************************************** - -template -void DL_PrivateKey_EC::BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size) -{ - BERSequenceDecoder seq(bt); - word32 version; - BERDecodeUnsigned(seq, version, INTEGER, 1, 1); // check version - - BERGeneralDecoder dec(seq, OCTET_STRING); - if (!dec.IsDefiniteLength()) - BERDecodeError(); - Integer x; - x.Decode(dec, (size_t)dec.RemainingLength()); - dec.MessageEnd(); - if (!parametersPresent && seq.PeekByte() != (CONTEXT_SPECIFIC | CONSTRUCTED | 0)) - BERDecodeError(); - if (!seq.EndReached() && seq.PeekByte() == (CONTEXT_SPECIFIC | CONSTRUCTED | 0)) - { - BERGeneralDecoder parameters(seq, CONTEXT_SPECIFIC | CONSTRUCTED | 0); - this->AccessGroupParameters().BERDecode(parameters); - parameters.MessageEnd(); - } - if (!seq.EndReached()) - { - // skip over the public element - SecByteBlock subjectPublicKey; - unsigned int unusedBits; - BERGeneralDecoder publicKey(seq, CONTEXT_SPECIFIC | CONSTRUCTED | 1); - BERDecodeBitString(publicKey, subjectPublicKey, unusedBits); - publicKey.MessageEnd(); - Element Q; - if (!(unusedBits == 0 && this->GetGroupParameters().GetCurve().DecodePoint(Q, subjectPublicKey, subjectPublicKey.size()))) - BERDecodeError(); - } - seq.MessageEnd(); - - this->SetPrivateExponent(x); -} - -template -void DL_PrivateKey_EC::DEREncodePrivateKey(BufferedTransformation &bt) const -{ - DERSequenceEncoder privateKey(bt); - DEREncodeUnsigned(privateKey, 1); // version - // SEC 1 ver 1.0 says privateKey (m_d) has the same length as order of the curve - // this will be changed to order of base point in a future version - this->GetPrivateExponent().DEREncodeAsOctetString(privateKey, this->GetGroupParameters().GetSubgroupOrder().ByteCount()); - privateKey.MessageEnd(); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/eccrypto.h b/lib/cryptopp/eccrypto.h deleted file mode 100644 index 3530455a3..000000000 --- a/lib/cryptopp/eccrypto.h +++ /dev/null @@ -1,280 +0,0 @@ -#ifndef CRYPTOPP_ECCRYPTO_H -#define CRYPTOPP_ECCRYPTO_H - -/*! \file -*/ - -#include "pubkey.h" -#include "integer.h" -#include "asn.h" -#include "hmac.h" -#include "sha.h" -#include "gfpcrypt.h" -#include "dh.h" -#include "mqv.h" -#include "ecp.h" -#include "ec2n.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! Elliptic Curve Parameters -/*! This class corresponds to the ASN.1 sequence of the same name - in ANSI X9.62 (also SEC 1). -*/ -template -class DL_GroupParameters_EC : public DL_GroupParametersImpl > -{ - typedef DL_GroupParameters_EC ThisClass; - -public: - typedef EC EllipticCurve; - typedef typename EllipticCurve::Point Point; - typedef Point Element; - typedef IncompatibleCofactorMultiplication DefaultCofactorOption; - - DL_GroupParameters_EC() : m_compress(false), m_encodeAsOID(false) {} - DL_GroupParameters_EC(const OID &oid) - : m_compress(false), m_encodeAsOID(false) {Initialize(oid);} - DL_GroupParameters_EC(const EllipticCurve &ec, const Point &G, const Integer &n, const Integer &k = Integer::Zero()) - : m_compress(false), m_encodeAsOID(false) {Initialize(ec, G, n, k);} - DL_GroupParameters_EC(BufferedTransformation &bt) - : m_compress(false), m_encodeAsOID(false) {BERDecode(bt);} - - void Initialize(const EllipticCurve &ec, const Point &G, const Integer &n, const Integer &k = Integer::Zero()) - { - this->m_groupPrecomputation.SetCurve(ec); - this->SetSubgroupGenerator(G); - m_n = n; - m_k = k; - } - void Initialize(const OID &oid); - - // NameValuePairs - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - - // GeneratibleCryptoMaterial interface - //! this implementation doesn't actually generate a curve, it just initializes the parameters with existing values - /*! parameters: (Curve, SubgroupGenerator, SubgroupOrder, Cofactor (optional)), or (GroupOID) */ - void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); - - // DL_GroupParameters - const DL_FixedBasePrecomputation & GetBasePrecomputation() const {return this->m_gpc;} - DL_FixedBasePrecomputation & AccessBasePrecomputation() {return this->m_gpc;} - const Integer & GetSubgroupOrder() const {return m_n;} - Integer GetCofactor() const; - bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const; - bool ValidateElement(unsigned int level, const Element &element, const DL_FixedBasePrecomputation *precomp) const; - bool FastSubgroupCheckAvailable() const {return false;} - void EncodeElement(bool reversible, const Element &element, byte *encoded) const - { - if (reversible) - GetCurve().EncodePoint(encoded, element, m_compress); - else - element.x.Encode(encoded, GetEncodedElementSize(false)); - } - unsigned int GetEncodedElementSize(bool reversible) const - { - if (reversible) - return GetCurve().EncodedPointSize(m_compress); - else - return GetCurve().GetField().MaxElementByteLength(); - } - Element DecodeElement(const byte *encoded, bool checkForGroupMembership) const - { - Point result; - if (!GetCurve().DecodePoint(result, encoded, GetEncodedElementSize(true))) - throw DL_BadElement(); - if (checkForGroupMembership && !ValidateElement(1, result, NULL)) - throw DL_BadElement(); - return result; - } - Integer ConvertElementToInteger(const Element &element) const; - Integer GetMaxExponent() const {return GetSubgroupOrder()-1;} - bool IsIdentity(const Element &element) const {return element.identity;} - void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const; - static std::string CRYPTOPP_API StaticAlgorithmNamePrefix() {return "EC";} - - // ASN1Key - OID GetAlgorithmID() const; - - // used by MQV - Element MultiplyElements(const Element &a, const Element &b) const; - Element CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const; - - // non-inherited - - // enumerate OIDs for recommended parameters, use OID() to get first one - static OID CRYPTOPP_API GetNextRecommendedParametersOID(const OID &oid); - - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - void SetPointCompression(bool compress) {m_compress = compress;} - bool GetPointCompression() const {return m_compress;} - - void SetEncodeAsOID(bool encodeAsOID) {m_encodeAsOID = encodeAsOID;} - bool GetEncodeAsOID() const {return m_encodeAsOID;} - - const EllipticCurve& GetCurve() const {return this->m_groupPrecomputation.GetCurve();} - - bool operator==(const ThisClass &rhs) const - {return this->m_groupPrecomputation.GetCurve() == rhs.m_groupPrecomputation.GetCurve() && this->m_gpc.GetBase(this->m_groupPrecomputation) == rhs.m_gpc.GetBase(rhs.m_groupPrecomputation);} - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - const Point& GetBasePoint() const {return GetSubgroupGenerator();} - const Integer& GetBasePointOrder() const {return GetSubgroupOrder();} - void LoadRecommendedParameters(const OID &oid) {Initialize(oid);} -#endif - -protected: - unsigned int FieldElementLength() const {return GetCurve().GetField().MaxElementByteLength();} - unsigned int ExponentLength() const {return m_n.ByteCount();} - - OID m_oid; // set if parameters loaded from a recommended curve - Integer m_n; // order of base point - bool m_compress, m_encodeAsOID; - mutable Integer m_k; // cofactor -}; - -//! EC public key -template -class DL_PublicKey_EC : public DL_PublicKeyImpl > -{ -public: - typedef typename EC::Point Element; - - void Initialize(const DL_GroupParameters_EC ¶ms, const Element &Q) - {this->AccessGroupParameters() = params; this->SetPublicElement(Q);} - void Initialize(const EC &ec, const Element &G, const Integer &n, const Element &Q) - {this->AccessGroupParameters().Initialize(ec, G, n); this->SetPublicElement(Q);} - - // X509PublicKey - void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size); - void DEREncodePublicKey(BufferedTransformation &bt) const; -}; - -//! EC private key -template -class DL_PrivateKey_EC : public DL_PrivateKeyImpl > -{ -public: - typedef typename EC::Point Element; - - void Initialize(const DL_GroupParameters_EC ¶ms, const Integer &x) - {this->AccessGroupParameters() = params; this->SetPrivateExponent(x);} - void Initialize(const EC &ec, const Element &G, const Integer &n, const Integer &x) - {this->AccessGroupParameters().Initialize(ec, G, n); this->SetPrivateExponent(x);} - void Initialize(RandomNumberGenerator &rng, const DL_GroupParameters_EC ¶ms) - {this->GenerateRandom(rng, params);} - void Initialize(RandomNumberGenerator &rng, const EC &ec, const Element &G, const Integer &n) - {this->GenerateRandom(rng, DL_GroupParameters_EC(ec, G, n));} - - // PKCS8PrivateKey - void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size); - void DEREncodePrivateKey(BufferedTransformation &bt) const; -}; - -//! Elliptic Curve Diffie-Hellman, AKA ECDH -template ::DefaultCofactorOption> -struct ECDH -{ - typedef DH_Domain, COFACTOR_OPTION> Domain; -}; - -/// Elliptic Curve Menezes-Qu-Vanstone, AKA ECMQV -template ::DefaultCofactorOption> -struct ECMQV -{ - typedef MQV_Domain, COFACTOR_OPTION> Domain; -}; - -//! EC keys -template -struct DL_Keys_EC -{ - typedef DL_PublicKey_EC PublicKey; - typedef DL_PrivateKey_EC PrivateKey; -}; - -template -struct ECDSA; - -//! ECDSA keys -template -struct DL_Keys_ECDSA -{ - typedef DL_PublicKey_EC PublicKey; - typedef DL_PrivateKey_WithSignaturePairwiseConsistencyTest, ECDSA > PrivateKey; -}; - -//! ECDSA algorithm -template -class DL_Algorithm_ECDSA : public DL_Algorithm_GDSA -{ -public: - static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECDSA";} -}; - -//! ECNR algorithm -template -class DL_Algorithm_ECNR : public DL_Algorithm_NR -{ -public: - static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECNR";} -}; - -//! ECDSA -template -struct ECDSA : public DL_SS, DL_Algorithm_ECDSA, DL_SignatureMessageEncodingMethod_DSA, H> -{ -}; - -//! ECNR -template -struct ECNR : public DL_SS, DL_Algorithm_ECNR, DL_SignatureMessageEncodingMethod_NR, H> -{ -}; - -//! Elliptic Curve Integrated Encryption Scheme, AKA ECIES -/*! Default to (NoCofactorMultiplication and DHAES_MODE = false) for compatibilty with SEC1 and Crypto++ 4.2. - The combination of (IncompatibleCofactorMultiplication and DHAES_MODE = true) is recommended for best - efficiency and security. */ -template -struct ECIES - : public DL_ES< - DL_Keys_EC, - DL_KeyAgreementAlgorithm_DH, - DL_KeyDerivationAlgorithm_P1363 >, - DL_EncryptionAlgorithm_Xor, DHAES_MODE>, - ECIES > -{ - static std::string CRYPTOPP_API StaticAlgorithmName() {return "ECIES";} // TODO: fix this after name is standardized -}; - -NAMESPACE_END - -#ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES -#include "eccrypto.cpp" -#endif - -NAMESPACE_BEGIN(CryptoPP) - -CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl >; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl >; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl >; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl >; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, ECDSA >; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, ECDSA >; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/ecp.cpp b/lib/cryptopp/ecp.cpp deleted file mode 100644 index 55a7cc15b..000000000 --- a/lib/cryptopp/ecp.cpp +++ /dev/null @@ -1,473 +0,0 @@ -// ecp.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "ecp.h" -#include "asn.h" -#include "nbtheory.h" - -#include "algebra.cpp" - -NAMESPACE_BEGIN(CryptoPP) - -ANONYMOUS_NAMESPACE_BEGIN -static inline ECP::Point ToMontgomery(const ModularArithmetic &mr, const ECP::Point &P) -{ - return P.identity ? P : ECP::Point(mr.ConvertIn(P.x), mr.ConvertIn(P.y)); -} - -static inline ECP::Point FromMontgomery(const ModularArithmetic &mr, const ECP::Point &P) -{ - return P.identity ? P : ECP::Point(mr.ConvertOut(P.x), mr.ConvertOut(P.y)); -} -NAMESPACE_END - -ECP::ECP(const ECP &ecp, bool convertToMontgomeryRepresentation) -{ - if (convertToMontgomeryRepresentation && !ecp.GetField().IsMontgomeryRepresentation()) - { - m_fieldPtr.reset(new MontgomeryRepresentation(ecp.GetField().GetModulus())); - m_a = GetField().ConvertIn(ecp.m_a); - m_b = GetField().ConvertIn(ecp.m_b); - } - else - operator=(ecp); -} - -ECP::ECP(BufferedTransformation &bt) - : m_fieldPtr(new Field(bt)) -{ - BERSequenceDecoder seq(bt); - GetField().BERDecodeElement(seq, m_a); - GetField().BERDecodeElement(seq, m_b); - // skip optional seed - if (!seq.EndReached()) - { - SecByteBlock seed; - unsigned int unused; - BERDecodeBitString(seq, seed, unused); - } - seq.MessageEnd(); -} - -void ECP::DEREncode(BufferedTransformation &bt) const -{ - GetField().DEREncode(bt); - DERSequenceEncoder seq(bt); - GetField().DEREncodeElement(seq, m_a); - GetField().DEREncodeElement(seq, m_b); - seq.MessageEnd(); -} - -bool ECP::DecodePoint(ECP::Point &P, const byte *encodedPoint, size_t encodedPointLen) const -{ - StringStore store(encodedPoint, encodedPointLen); - return DecodePoint(P, store, encodedPointLen); -} - -bool ECP::DecodePoint(ECP::Point &P, BufferedTransformation &bt, size_t encodedPointLen) const -{ - byte type; - if (encodedPointLen < 1 || !bt.Get(type)) - return false; - - switch (type) - { - case 0: - P.identity = true; - return true; - case 2: - case 3: - { - if (encodedPointLen != EncodedPointSize(true)) - return false; - - Integer p = FieldSize(); - - P.identity = false; - P.x.Decode(bt, GetField().MaxElementByteLength()); - P.y = ((P.x*P.x+m_a)*P.x+m_b) % p; - - if (Jacobi(P.y, p) !=1) - return false; - - P.y = ModularSquareRoot(P.y, p); - - if ((type & 1) != P.y.GetBit(0)) - P.y = p-P.y; - - return true; - } - case 4: - { - if (encodedPointLen != EncodedPointSize(false)) - return false; - - unsigned int len = GetField().MaxElementByteLength(); - P.identity = false; - P.x.Decode(bt, len); - P.y.Decode(bt, len); - return true; - } - default: - return false; - } -} - -void ECP::EncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const -{ - if (P.identity) - NullStore().TransferTo(bt, EncodedPointSize(compressed)); - else if (compressed) - { - bt.Put(2 + P.y.GetBit(0)); - P.x.Encode(bt, GetField().MaxElementByteLength()); - } - else - { - unsigned int len = GetField().MaxElementByteLength(); - bt.Put(4); // uncompressed - P.x.Encode(bt, len); - P.y.Encode(bt, len); - } -} - -void ECP::EncodePoint(byte *encodedPoint, const Point &P, bool compressed) const -{ - ArraySink sink(encodedPoint, EncodedPointSize(compressed)); - EncodePoint(sink, P, compressed); - assert(sink.TotalPutLength() == EncodedPointSize(compressed)); -} - -ECP::Point ECP::BERDecodePoint(BufferedTransformation &bt) const -{ - SecByteBlock str; - BERDecodeOctetString(bt, str); - Point P; - if (!DecodePoint(P, str, str.size())) - BERDecodeError(); - return P; -} - -void ECP::DEREncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const -{ - SecByteBlock str(EncodedPointSize(compressed)); - EncodePoint(str, P, compressed); - DEREncodeOctetString(bt, str); -} - -bool ECP::ValidateParameters(RandomNumberGenerator &rng, unsigned int level) const -{ - Integer p = FieldSize(); - - bool pass = p.IsOdd(); - pass = pass && !m_a.IsNegative() && m_a

= 1) - pass = pass && ((4*m_a*m_a*m_a+27*m_b*m_b)%p).IsPositive(); - - if (level >= 2) - pass = pass && VerifyPrime(rng, p); - - return pass; -} - -bool ECP::VerifyPoint(const Point &P) const -{ - const FieldElement &x = P.x, &y = P.y; - Integer p = FieldSize(); - return P.identity || - (!x.IsNegative() && x

().Ref(); -} - -const ECP::Point& ECP::Inverse(const Point &P) const -{ - if (P.identity) - return P; - else - { - m_R.identity = false; - m_R.x = P.x; - m_R.y = GetField().Inverse(P.y); - return m_R; - } -} - -const ECP::Point& ECP::Add(const Point &P, const Point &Q) const -{ - if (P.identity) return Q; - if (Q.identity) return P; - if (GetField().Equal(P.x, Q.x)) - return GetField().Equal(P.y, Q.y) ? Double(P) : Identity(); - - FieldElement t = GetField().Subtract(Q.y, P.y); - t = GetField().Divide(t, GetField().Subtract(Q.x, P.x)); - FieldElement x = GetField().Subtract(GetField().Subtract(GetField().Square(t), P.x), Q.x); - m_R.y = GetField().Subtract(GetField().Multiply(t, GetField().Subtract(P.x, x)), P.y); - - m_R.x.swap(x); - m_R.identity = false; - return m_R; -} - -const ECP::Point& ECP::Double(const Point &P) const -{ - if (P.identity || P.y==GetField().Identity()) return Identity(); - - FieldElement t = GetField().Square(P.x); - t = GetField().Add(GetField().Add(GetField().Double(t), t), m_a); - t = GetField().Divide(t, GetField().Double(P.y)); - FieldElement x = GetField().Subtract(GetField().Subtract(GetField().Square(t), P.x), P.x); - m_R.y = GetField().Subtract(GetField().Multiply(t, GetField().Subtract(P.x, x)), P.y); - - m_R.x.swap(x); - m_R.identity = false; - return m_R; -} - -template void ParallelInvert(const AbstractRing &ring, Iterator begin, Iterator end) -{ - size_t n = end-begin; - if (n == 1) - *begin = ring.MultiplicativeInverse(*begin); - else if (n > 1) - { - std::vector vec((n+1)/2); - unsigned int i; - Iterator it; - - for (i=0, it=begin; i::iterator it) : it(it) {} - Integer& operator*() {return it->z;} - int operator-(ZIterator it2) {return int(it-it2.it);} - ZIterator operator+(int i) {return ZIterator(it+i);} - ZIterator& operator+=(int i) {it+=i; return *this;} - std::vector::iterator it; -}; - -ECP::Point ECP::ScalarMultiply(const Point &P, const Integer &k) const -{ - Element result; - if (k.BitCount() <= 5) - AbstractGroup::SimultaneousMultiply(&result, P, &k, 1); - else - ECP::SimultaneousMultiply(&result, P, &k, 1); - return result; -} - -void ECP::SimultaneousMultiply(ECP::Point *results, const ECP::Point &P, const Integer *expBegin, unsigned int expCount) const -{ - if (!GetField().IsMontgomeryRepresentation()) - { - ECP ecpmr(*this, true); - const ModularArithmetic &mr = ecpmr.GetField(); - ecpmr.SimultaneousMultiply(results, ToMontgomery(mr, P), expBegin, expCount); - for (unsigned int i=0; i bases; - std::vector exponents; - exponents.reserve(expCount); - std::vector > baseIndices(expCount); - std::vector > negateBase(expCount); - std::vector > exponentWindows(expCount); - unsigned int i; - - for (i=0; iNotNegative()); - exponents.push_back(WindowSlider(*expBegin++, InversionIsFast(), 5)); - exponents[i].FindNextWindow(); - } - - unsigned int expBitPosition = 0; - bool notDone = true; - - while (notDone) - { - notDone = false; - bool baseAdded = false; - for (i=0; i > finalCascade; - for (i=0; i::CascadeScalarMultiply(P, k1, Q, k2); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/ecp.h b/lib/cryptopp/ecp.h deleted file mode 100644 index d946be63a..000000000 --- a/lib/cryptopp/ecp.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef CRYPTOPP_ECP_H -#define CRYPTOPP_ECP_H - -#include "modarith.h" -#include "eprecomp.h" -#include "smartptr.h" -#include "pubkey.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! Elliptical Curve Point -struct CRYPTOPP_DLL ECPPoint -{ - ECPPoint() : identity(true) {} - ECPPoint(const Integer &x, const Integer &y) - : identity(false), x(x), y(y) {} - - bool operator==(const ECPPoint &t) const - {return (identity && t.identity) || (!identity && !t.identity && x==t.x && y==t.y);} - bool operator< (const ECPPoint &t) const - {return identity ? !t.identity : (!t.identity && (x; - -//! Elliptic Curve over GF(p), where p is prime -class CRYPTOPP_DLL ECP : public AbstractGroup -{ -public: - typedef ModularArithmetic Field; - typedef Integer FieldElement; - typedef ECPPoint Point; - - ECP() {} - ECP(const ECP &ecp, bool convertToMontgomeryRepresentation = false); - ECP(const Integer &modulus, const FieldElement &a, const FieldElement &b) - : m_fieldPtr(new Field(modulus)), m_a(a.IsNegative() ? modulus+a : a), m_b(b) {} - // construct from BER encoded parameters - // this constructor will decode and extract the the fields fieldID and curve of the sequence ECParameters - ECP(BufferedTransformation &bt); - - // encode the fields fieldID and curve of the sequence ECParameters - void DEREncode(BufferedTransformation &bt) const; - - bool Equal(const Point &P, const Point &Q) const; - const Point& Identity() const; - const Point& Inverse(const Point &P) const; - bool InversionIsFast() const {return true;} - const Point& Add(const Point &P, const Point &Q) const; - const Point& Double(const Point &P) const; - Point ScalarMultiply(const Point &P, const Integer &k) const; - Point CascadeScalarMultiply(const Point &P, const Integer &k1, const Point &Q, const Integer &k2) const; - void SimultaneousMultiply(Point *results, const Point &base, const Integer *exponents, unsigned int exponentsCount) const; - - Point Multiply(const Integer &k, const Point &P) const - {return ScalarMultiply(P, k);} - Point CascadeMultiply(const Integer &k1, const Point &P, const Integer &k2, const Point &Q) const - {return CascadeScalarMultiply(P, k1, Q, k2);} - - bool ValidateParameters(RandomNumberGenerator &rng, unsigned int level=3) const; - bool VerifyPoint(const Point &P) const; - - unsigned int EncodedPointSize(bool compressed = false) const - {return 1 + (compressed?1:2)*GetField().MaxElementByteLength();} - // returns false if point is compressed and not valid (doesn't check if uncompressed) - bool DecodePoint(Point &P, BufferedTransformation &bt, size_t len) const; - bool DecodePoint(Point &P, const byte *encodedPoint, size_t len) const; - void EncodePoint(byte *encodedPoint, const Point &P, bool compressed) const; - void EncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const; - - Point BERDecodePoint(BufferedTransformation &bt) const; - void DEREncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const; - - Integer FieldSize() const {return GetField().GetModulus();} - const Field & GetField() const {return *m_fieldPtr;} - const FieldElement & GetA() const {return m_a;} - const FieldElement & GetB() const {return m_b;} - - bool operator==(const ECP &rhs) const - {return GetField() == rhs.GetField() && m_a == rhs.m_a && m_b == rhs.m_b;} - -private: - clonable_ptr m_fieldPtr; - FieldElement m_a, m_b; - mutable Point m_R; -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS DL_FixedBasePrecomputationImpl; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupPrecomputation; - -template class EcPrecomputation; - -//! ECP precomputation -template<> class EcPrecomputation : public DL_GroupPrecomputation -{ -public: - typedef ECP EllipticCurve; - - // DL_GroupPrecomputation - bool NeedConversions() const {return true;} - Element ConvertIn(const Element &P) const - {return P.identity ? P : ECP::Point(m_ec->GetField().ConvertIn(P.x), m_ec->GetField().ConvertIn(P.y));}; - Element ConvertOut(const Element &P) const - {return P.identity ? P : ECP::Point(m_ec->GetField().ConvertOut(P.x), m_ec->GetField().ConvertOut(P.y));} - const AbstractGroup & GetGroup() const {return *m_ec;} - Element BERDecodeElement(BufferedTransformation &bt) const {return m_ec->BERDecodePoint(bt);} - void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {m_ec->DEREncodePoint(bt, v, false);} - - // non-inherited - void SetCurve(const ECP &ec) - { - m_ec.reset(new ECP(ec, true)); - m_ecOriginal = ec; - } - const ECP & GetCurve() const {return *m_ecOriginal;} - -private: - value_ptr m_ec, m_ecOriginal; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/elgamal.cpp b/lib/cryptopp/elgamal.cpp deleted file mode 100644 index b58fe7c06..000000000 --- a/lib/cryptopp/elgamal.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// elgamal.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "elgamal.h" -#include "asn.h" -#include "nbtheory.h" - -NAMESPACE_BEGIN(CryptoPP) - -void ElGamal_TestInstantiations() -{ - ElGamalEncryptor test1(1, 1, 1); - ElGamalDecryptor test2(NullRNG(), 123); - ElGamalEncryptor test3(test2); -} - -NAMESPACE_END diff --git a/lib/cryptopp/elgamal.h b/lib/cryptopp/elgamal.h deleted file mode 100644 index 9afc30eee..000000000 --- a/lib/cryptopp/elgamal.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef CRYPTOPP_ELGAMAL_H -#define CRYPTOPP_ELGAMAL_H - -#include "modexppc.h" -#include "dsa.h" - -NAMESPACE_BEGIN(CryptoPP) - -class CRYPTOPP_NO_VTABLE ElGamalBase : public DL_KeyAgreementAlgorithm_DH, - public DL_KeyDerivationAlgorithm, - public DL_SymmetricEncryptionAlgorithm -{ -public: - void Derive(const DL_GroupParameters &groupParams, byte *derivedKey, size_t derivedLength, const Integer &agreedElement, const Integer &ephemeralPublicKey, const NameValuePairs &derivationParams) const - { - agreedElement.Encode(derivedKey, derivedLength); - } - - size_t GetSymmetricKeyLength(size_t plainTextLength) const - { - return GetGroupParameters().GetModulus().ByteCount(); - } - - size_t GetSymmetricCiphertextLength(size_t plainTextLength) const - { - unsigned int len = GetGroupParameters().GetModulus().ByteCount(); - if (plainTextLength <= GetMaxSymmetricPlaintextLength(len)) - return len; - else - return 0; - } - - size_t GetMaxSymmetricPlaintextLength(size_t cipherTextLength) const - { - unsigned int len = GetGroupParameters().GetModulus().ByteCount(); - if (cipherTextLength == len) - return STDMIN(255U, len-3); - else - return 0; - } - - void SymmetricEncrypt(RandomNumberGenerator &rng, const byte *key, const byte *plainText, size_t plainTextLength, byte *cipherText, const NameValuePairs ¶meters) const - { - const Integer &p = GetGroupParameters().GetModulus(); - unsigned int modulusLen = p.ByteCount(); - - SecByteBlock block(modulusLen-1); - rng.GenerateBlock(block, modulusLen-2-plainTextLength); - memcpy(block+modulusLen-2-plainTextLength, plainText, plainTextLength); - block[modulusLen-2] = (byte)plainTextLength; - - a_times_b_mod_c(Integer(key, modulusLen), Integer(block, modulusLen-1), p).Encode(cipherText, modulusLen); - } - - DecodingResult SymmetricDecrypt(const byte *key, const byte *cipherText, size_t cipherTextLength, byte *plainText, const NameValuePairs ¶meters) const - { - const Integer &p = GetGroupParameters().GetModulus(); - unsigned int modulusLen = p.ByteCount(); - - if (cipherTextLength != modulusLen) - return DecodingResult(); - - Integer m = a_times_b_mod_c(Integer(cipherText, modulusLen), Integer(key, modulusLen).InverseMod(p), p); - - m.Encode(plainText, 1); - unsigned int plainTextLength = plainText[0]; - if (plainTextLength > GetMaxSymmetricPlaintextLength(modulusLen)) - return DecodingResult(); - m >>= 8; - m.Encode(plainText, plainTextLength); - return DecodingResult(plainTextLength); - } - - virtual const DL_GroupParameters_GFP & GetGroupParameters() const =0; -}; - -template -class ElGamalObjectImpl : public DL_ObjectImplBase, public ElGamalBase -{ -public: - size_t FixedMaxPlaintextLength() const {return this->MaxPlaintextLength(FixedCiphertextLength());} - size_t FixedCiphertextLength() const {return this->CiphertextLength(0);} - - const DL_GroupParameters_GFP & GetGroupParameters() const {return this->GetKey().GetGroupParameters();} - - DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *cipherText, byte *plainText) const - {return Decrypt(rng, cipherText, FixedCiphertextLength(), plainText);} - -protected: - const DL_KeyAgreementAlgorithm & GetKeyAgreementAlgorithm() const {return *this;} - const DL_KeyDerivationAlgorithm & GetKeyDerivationAlgorithm() const {return *this;} - const DL_SymmetricEncryptionAlgorithm & GetSymmetricEncryptionAlgorithm() const {return *this;} -}; - -struct ElGamalKeys -{ - typedef DL_CryptoKeys_GFP::GroupParameters GroupParameters; - typedef DL_PrivateKey_GFP_OldFormat PrivateKey; - typedef DL_PublicKey_GFP_OldFormat PublicKey; -}; - -//! ElGamal encryption scheme with non-standard padding -struct ElGamal -{ - typedef DL_CryptoSchemeOptions SchemeOptions; - - static const char * StaticAlgorithmName() {return "ElgamalEnc/Crypto++Padding";} - - typedef SchemeOptions::GroupParameters GroupParameters; - //! implements PK_Encryptor interface - typedef PK_FinalTemplate, SchemeOptions, SchemeOptions::PublicKey> > Encryptor; - //! implements PK_Decryptor interface - typedef PK_FinalTemplate, SchemeOptions, SchemeOptions::PrivateKey> > Decryptor; -}; - -typedef ElGamal::Encryptor ElGamalEncryptor; -typedef ElGamal::Decryptor ElGamalDecryptor; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/emsa2.cpp b/lib/cryptopp/emsa2.cpp deleted file mode 100644 index 3dbb7e8c0..000000000 --- a/lib/cryptopp/emsa2.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// emsa2.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "emsa2.h" - -#ifndef CRYPTOPP_IMPORTS - -NAMESPACE_BEGIN(CryptoPP) - -void EMSA2Pad::ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const -{ - assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize())); - - if (representativeBitLength % 8 != 7) - throw PK_SignatureScheme::InvalidKeyLength("EMSA2: EMSA2 requires a key length that is a multiple of 8"); - - size_t digestSize = hash.DigestSize(); - size_t representativeByteLength = BitsToBytes(representativeBitLength); - - representative[0] = messageEmpty ? 0x4b : 0x6b; - memset(representative+1, 0xbb, representativeByteLength-digestSize-4); // pad with 0xbb - byte *afterP2 = representative+representativeByteLength-digestSize-3; - afterP2[0] = 0xba; - hash.Final(afterP2+1); - representative[representativeByteLength-2] = *hashIdentifier.first; - representative[representativeByteLength-1] = 0xcc; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/emsa2.h b/lib/cryptopp/emsa2.h deleted file mode 100644 index 49109e6db..000000000 --- a/lib/cryptopp/emsa2.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef CRYPTOPP_EMSA2_H -#define CRYPTOPP_EMSA2_H - -/** \file - This file contains various padding schemes for public key algorithms. -*/ - -#include "cryptlib.h" -#include "pubkey.h" - -#ifdef CRYPTOPP_IS_DLL -#include "sha.h" -#endif - -NAMESPACE_BEGIN(CryptoPP) - -template class EMSA2HashId -{ -public: - static const byte id; -}; - -template -class EMSA2HashIdLookup : public BASE -{ -public: - struct HashIdentifierLookup - { - template struct HashIdentifierLookup2 - { - static HashIdentifier Lookup() - { - return HashIdentifier(&EMSA2HashId::id, 1); - } - }; - }; -}; - -// EMSA2HashId can be instantiated with the following classes. -class SHA1; -class RIPEMD160; -class RIPEMD128; -class SHA256; -class SHA384; -class SHA512; -class Whirlpool; -class SHA224; -// end of list - -#ifdef CRYPTOPP_IS_DLL -CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; -CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; -CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; -CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; -CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; -#endif - -//! _ -class CRYPTOPP_DLL EMSA2Pad : public EMSA2HashIdLookup -{ -public: - static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA2";} - - size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const - {return 8*digestLength + 31;} - - void ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const; -}; - -//! EMSA2, for use with RWSS and RSA_ISO -/*! Only the following hash functions are supported by this signature standard: - \dontinclude emsa2.h - \skip EMSA2HashId can be instantiated - \until end of list -*/ -struct P1363_EMSA2 : public SignatureStandard -{ - typedef EMSA2Pad SignatureMessageEncodingMethod; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/eprecomp.cpp b/lib/cryptopp/eprecomp.cpp deleted file mode 100644 index a061cf6cd..000000000 --- a/lib/cryptopp/eprecomp.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// eprecomp.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "eprecomp.h" -#include "asn.h" - -NAMESPACE_BEGIN(CryptoPP) - -template void DL_FixedBasePrecomputationImpl::SetBase(const DL_GroupPrecomputation &group, const Element &i_base) -{ - m_base = group.NeedConversions() ? group.ConvertIn(i_base) : i_base; - - if (m_bases.empty() || !(m_base == m_bases[0])) - { - m_bases.resize(1); - m_bases[0] = m_base; - } - - if (group.NeedConversions()) - m_base = i_base; -} - -template void DL_FixedBasePrecomputationImpl::Precompute(const DL_GroupPrecomputation &group, unsigned int maxExpBits, unsigned int storage) -{ - assert(m_bases.size() > 0); - assert(storage <= maxExpBits); - - if (storage > 1) - { - m_windowSize = (maxExpBits+storage-1)/storage; - m_exponentBase = Integer::Power2(m_windowSize); - } - - m_bases.resize(storage); - for (unsigned i=1; i void DL_FixedBasePrecomputationImpl::Load(const DL_GroupPrecomputation &group, BufferedTransformation &bt) -{ - BERSequenceDecoder seq(bt); - word32 version; - BERDecodeUnsigned(seq, version, INTEGER, 1, 1); - m_exponentBase.BERDecode(seq); - m_windowSize = m_exponentBase.BitCount() - 1; - m_bases.clear(); - while (!seq.EndReached()) - m_bases.push_back(group.BERDecodeElement(seq)); - if (!m_bases.empty() && group.NeedConversions()) - m_base = group.ConvertOut(m_bases[0]); - seq.MessageEnd(); -} - -template void DL_FixedBasePrecomputationImpl::Save(const DL_GroupPrecomputation &group, BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - DEREncodeUnsigned(seq, 1); // version - m_exponentBase.DEREncode(seq); - for (unsigned i=0; i void DL_FixedBasePrecomputationImpl::PrepareCascade(const DL_GroupPrecomputation &i_group, std::vector > &eb, const Integer &exponent) const -{ - const AbstractGroup &group = i_group.GetGroup(); - - Integer r, q, e = exponent; - bool fastNegate = group.InversionIsFast() && m_windowSize > 1; - unsigned int i; - - for (i=0; i+1(group.Inverse(m_bases[i]), m_exponentBase - r)); - } - else - eb.push_back(BaseAndExponent(m_bases[i], r)); - } - eb.push_back(BaseAndExponent(m_bases[i], e)); -} - -template T DL_FixedBasePrecomputationImpl::Exponentiate(const DL_GroupPrecomputation &group, const Integer &exponent) const -{ - std::vector > eb; // array of segments of the exponent and precalculated bases - eb.reserve(m_bases.size()); - PrepareCascade(group, eb, exponent); - return group.ConvertOut(GeneralCascadeMultiplication(group.GetGroup(), eb.begin(), eb.end())); -} - -template T - DL_FixedBasePrecomputationImpl::CascadeExponentiate(const DL_GroupPrecomputation &group, const Integer &exponent, - const DL_FixedBasePrecomputation &i_pc2, const Integer &exponent2) const -{ - std::vector > eb; // array of segments of the exponent and precalculated bases - const DL_FixedBasePrecomputationImpl &pc2 = static_cast &>(i_pc2); - eb.reserve(m_bases.size() + pc2.m_bases.size()); - PrepareCascade(group, eb, exponent); - pc2.PrepareCascade(group, eb, exponent2); - return group.ConvertOut(GeneralCascadeMultiplication(group.GetGroup(), eb.begin(), eb.end())); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/eprecomp.h b/lib/cryptopp/eprecomp.h deleted file mode 100644 index 1f3256766..000000000 --- a/lib/cryptopp/eprecomp.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef CRYPTOPP_EPRECOMP_H -#define CRYPTOPP_EPRECOMP_H - -#include "integer.h" -#include "algebra.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -template -class DL_GroupPrecomputation -{ -public: - typedef T Element; - - virtual bool NeedConversions() const {return false;} - virtual Element ConvertIn(const Element &v) const {return v;} - virtual Element ConvertOut(const Element &v) const {return v;} - virtual const AbstractGroup & GetGroup() const =0; - virtual Element BERDecodeElement(BufferedTransformation &bt) const =0; - virtual void DEREncodeElement(BufferedTransformation &bt, const Element &P) const =0; -}; - -template -class DL_FixedBasePrecomputation -{ -public: - typedef T Element; - - virtual bool IsInitialized() const =0; - virtual void SetBase(const DL_GroupPrecomputation &group, const Element &base) =0; - virtual const Element & GetBase(const DL_GroupPrecomputation &group) const =0; - virtual void Precompute(const DL_GroupPrecomputation &group, unsigned int maxExpBits, unsigned int storage) =0; - virtual void Load(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation) =0; - virtual void Save(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation) const =0; - virtual Element Exponentiate(const DL_GroupPrecomputation &group, const Integer &exponent) const =0; - virtual Element CascadeExponentiate(const DL_GroupPrecomputation &group, const Integer &exponent, const DL_FixedBasePrecomputation &pc2, const Integer &exponent2) const =0; -}; - -template -class DL_FixedBasePrecomputationImpl : public DL_FixedBasePrecomputation -{ -public: - typedef T Element; - - DL_FixedBasePrecomputationImpl() : m_windowSize(0) {} - - // DL_FixedBasePrecomputation - bool IsInitialized() const - {return !m_bases.empty();} - void SetBase(const DL_GroupPrecomputation &group, const Element &base); - const Element & GetBase(const DL_GroupPrecomputation &group) const - {return group.NeedConversions() ? m_base : m_bases[0];} - void Precompute(const DL_GroupPrecomputation &group, unsigned int maxExpBits, unsigned int storage); - void Load(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation); - void Save(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation) const; - Element Exponentiate(const DL_GroupPrecomputation &group, const Integer &exponent) const; - Element CascadeExponentiate(const DL_GroupPrecomputation &group, const Integer &exponent, const DL_FixedBasePrecomputation &pc2, const Integer &exponent2) const; - -private: - void PrepareCascade(const DL_GroupPrecomputation &group, std::vector > &eb, const Integer &exponent) const; - - Element m_base; - unsigned int m_windowSize; - Integer m_exponentBase; // what base to represent the exponent in - std::vector m_bases; // precalculated bases -}; - -NAMESPACE_END - -#ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES -#include "eprecomp.cpp" -#endif - -#endif diff --git a/lib/cryptopp/esign.cpp b/lib/cryptopp/esign.cpp deleted file mode 100644 index 8b42c1fa4..000000000 --- a/lib/cryptopp/esign.cpp +++ /dev/null @@ -1,210 +0,0 @@ -// esign.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "esign.h" -#include "asn.h" -#include "modarith.h" -#include "nbtheory.h" -#include "sha.h" -#include "algparam.h" - -NAMESPACE_BEGIN(CryptoPP) - -void ESIGN_TestInstantiations() -{ - ESIGN::Verifier x1(1, 1); - ESIGN::Signer x2(NullRNG(), 1); - ESIGN::Verifier x3(x2); - ESIGN::Verifier x4(x2.GetKey()); - ESIGN::Verifier x5(x3); - ESIGN::Signer x6 = x2; - - x6 = x2; - x3 = ESIGN::Verifier(x2); - x4 = x2.GetKey(); -} - -void ESIGNFunction::BERDecode(BufferedTransformation &bt) -{ - BERSequenceDecoder seq(bt); - m_n.BERDecode(seq); - m_e.BERDecode(seq); - seq.MessageEnd(); -} - -void ESIGNFunction::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - m_n.DEREncode(seq); - m_e.DEREncode(seq); - seq.MessageEnd(); -} - -Integer ESIGNFunction::ApplyFunction(const Integer &x) const -{ - DoQuickSanityCheck(); - return STDMIN(a_exp_b_mod_c(x, m_e, m_n) >> (2*GetK()+2), MaxImage()); -} - -bool ESIGNFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = true; - pass = pass && m_n > Integer::One() && m_n.IsOdd(); - pass = pass && m_e >= 8 && m_e < m_n; - return pass; -} - -bool ESIGNFunction::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - return GetValueHelper(this, name, valueType, pValue).Assignable() - CRYPTOPP_GET_FUNCTION_ENTRY(Modulus) - CRYPTOPP_GET_FUNCTION_ENTRY(PublicExponent) - ; -} - -void ESIGNFunction::AssignFrom(const NameValuePairs &source) -{ - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(Modulus) - CRYPTOPP_SET_FUNCTION_ENTRY(PublicExponent) - ; -} - -// ***************************************************************************** - -void InvertibleESIGNFunction::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶m) -{ - int modulusSize = 1023*2; - param.GetIntValue("ModulusSize", modulusSize) || param.GetIntValue("KeySize", modulusSize); - - if (modulusSize < 24) - throw InvalidArgument("InvertibleESIGNFunction: specified modulus size is too small"); - - if (modulusSize % 3 != 0) - throw InvalidArgument("InvertibleESIGNFunction: modulus size must be divisible by 3"); - - m_e = param.GetValueWithDefault("PublicExponent", Integer(32)); - - if (m_e < 8) - throw InvalidArgument("InvertibleESIGNFunction: public exponents less than 8 may not be secure"); - - // VC70 workaround: putting these after primeParam causes overlapped stack allocation - ConstByteArrayParameter seedParam; - SecByteBlock seed; - - const Integer minP = Integer(204) << (modulusSize/3-8); - const Integer maxP = Integer::Power2(modulusSize/3)-1; - AlgorithmParameters primeParam = MakeParameters("Min", minP)("Max", maxP)("RandomNumberType", Integer::PRIME); - - if (param.GetValue("Seed", seedParam)) - { - seed.resize(seedParam.size() + 4); - memcpy(seed + 4, seedParam.begin(), seedParam.size()); - - PutWord(false, BIG_ENDIAN_ORDER, seed, (word32)0); - m_p.GenerateRandom(rng, CombinedNameValuePairs(primeParam, MakeParameters("Seed", ConstByteArrayParameter(seed)))); - PutWord(false, BIG_ENDIAN_ORDER, seed, (word32)1); - m_q.GenerateRandom(rng, CombinedNameValuePairs(primeParam, MakeParameters("Seed", ConstByteArrayParameter(seed)))); - } - else - { - m_p.GenerateRandom(rng, primeParam); - m_q.GenerateRandom(rng, primeParam); - } - - m_n = m_p * m_p * m_q; - - assert(m_n.BitCount() == modulusSize); -} - -void InvertibleESIGNFunction::BERDecode(BufferedTransformation &bt) -{ - BERSequenceDecoder privateKey(bt); - m_n.BERDecode(privateKey); - m_e.BERDecode(privateKey); - m_p.BERDecode(privateKey); - m_q.BERDecode(privateKey); - privateKey.MessageEnd(); -} - -void InvertibleESIGNFunction::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder privateKey(bt); - m_n.DEREncode(privateKey); - m_e.DEREncode(privateKey); - m_p.DEREncode(privateKey); - m_q.DEREncode(privateKey); - privateKey.MessageEnd(); -} - -Integer InvertibleESIGNFunction::CalculateRandomizedInverse(RandomNumberGenerator &rng, const Integer &x) const -{ - DoQuickSanityCheck(); - - Integer pq = m_p * m_q; - Integer p2 = m_p * m_p; - Integer r, z, re, a, w0, w1; - - do - { - r.Randomize(rng, Integer::Zero(), pq); - z = x << (2*GetK()+2); - re = a_exp_b_mod_c(r, m_e, m_n); - a = (z - re) % m_n; - Integer::Divide(w1, w0, a, pq); - if (w1.NotZero()) - { - ++w0; - w1 = pq - w1; - } - } - while ((w1 >> 2*GetK()+1).IsPositive()); - - ModularArithmetic modp(m_p); - Integer t = modp.Divide(w0 * r % m_p, m_e * re % m_p); - Integer s = r + t*pq; - assert(s < m_n); -/* - using namespace std; - cout << "f = " << x << endl; - cout << "r = " << r << endl; - cout << "z = " << z << endl; - cout << "a = " << a << endl; - cout << "w0 = " << w0 << endl; - cout << "w1 = " << w1 << endl; - cout << "t = " << t << endl; - cout << "s = " << s << endl; -*/ - return s; -} - -bool InvertibleESIGNFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = ESIGNFunction::Validate(rng, level); - pass = pass && m_p > Integer::One() && m_p.IsOdd() && m_p < m_n; - pass = pass && m_q > Integer::One() && m_q.IsOdd() && m_q < m_n; - pass = pass && m_p.BitCount() == m_q.BitCount(); - if (level >= 1) - pass = pass && m_p * m_p * m_q == m_n; - if (level >= 2) - pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2); - return pass; -} - -bool InvertibleESIGNFunction::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - return GetValueHelper(this, name, valueType, pValue).Assignable() - CRYPTOPP_GET_FUNCTION_ENTRY(Prime1) - CRYPTOPP_GET_FUNCTION_ENTRY(Prime2) - ; -} - -void InvertibleESIGNFunction::AssignFrom(const NameValuePairs &source) -{ - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(Prime1) - CRYPTOPP_SET_FUNCTION_ENTRY(Prime2) - ; -} - -NAMESPACE_END diff --git a/lib/cryptopp/esign.h b/lib/cryptopp/esign.h deleted file mode 100644 index 8eecbc5a1..000000000 --- a/lib/cryptopp/esign.h +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef CRYPTOPP_ESIGN_H -#define CRYPTOPP_ESIGN_H - -/** \file - This file contains classes that implement the - ESIGN signature schemes as defined in IEEE P1363a. -*/ - -#include "pubkey.h" -#include "integer.h" -#include "asn.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -class ESIGNFunction : public TrapdoorFunction, public ASN1CryptoMaterial -{ - typedef ESIGNFunction ThisClass; - -public: - void Initialize(const Integer &n, const Integer &e) - {m_n = n; m_e = e;} - - // PublicKey - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - // CryptoMaterial - bool Validate(RandomNumberGenerator &rng, unsigned int level) const; - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - - // TrapdoorFunction - Integer ApplyFunction(const Integer &x) const; - Integer PreimageBound() const {return m_n;} - Integer ImageBound() const {return Integer::Power2(GetK());} - - // non-derived - const Integer & GetModulus() const {return m_n;} - const Integer & GetPublicExponent() const {return m_e;} - - void SetModulus(const Integer &n) {m_n = n;} - void SetPublicExponent(const Integer &e) {m_e = e;} - -protected: - unsigned int GetK() const {return m_n.BitCount()/3-1;} - - Integer m_n, m_e; -}; - -//! _ -class InvertibleESIGNFunction : public ESIGNFunction, public RandomizedTrapdoorFunctionInverse, public PrivateKey -{ - typedef InvertibleESIGNFunction ThisClass; - -public: - void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q) - {m_n = n; m_e = e; m_p = p; m_q = q;} - // generate a random private key - void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits) - {GenerateRandomWithKeySize(rng, modulusBits);} - - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - Integer CalculateRandomizedInverse(RandomNumberGenerator &rng, const Integer &x) const; - - // GeneratibleCryptoMaterial - bool Validate(RandomNumberGenerator &rng, unsigned int level) const; - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - /*! parameters: (ModulusSize) */ - void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); - - const Integer& GetPrime1() const {return m_p;} - const Integer& GetPrime2() const {return m_q;} - - void SetPrime1(const Integer &p) {m_p = p;} - void SetPrime2(const Integer &q) {m_q = q;} - -protected: - Integer m_p, m_q; -}; - -//! _ -template -class EMSA5Pad : public PK_DeterministicSignatureMessageEncodingMethod -{ -public: - static const char *StaticAlgorithmName() {return "EMSA5";} - - void ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const - { - SecByteBlock digest(hash.DigestSize()); - hash.Final(digest); - size_t representativeByteLength = BitsToBytes(representativeBitLength); - T mgf; - mgf.GenerateAndMask(hash, representative, representativeByteLength, digest, digest.size(), false); - if (representativeBitLength % 8 != 0) - representative[0] = (byte)Crop(representative[0], representativeBitLength % 8); - } -}; - -//! EMSA5, for use with ESIGN -struct P1363_EMSA5 : public SignatureStandard -{ - typedef EMSA5Pad SignatureMessageEncodingMethod; -}; - -struct ESIGN_Keys -{ - static std::string StaticAlgorithmName() {return "ESIGN";} - typedef ESIGNFunction PublicKey; - typedef InvertibleESIGNFunction PrivateKey; -}; - -//! ESIGN, as defined in IEEE P1363a -template -struct ESIGN : public TF_SS -{ -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/factory.h b/lib/cryptopp/factory.h deleted file mode 100644 index 5b65db3da..000000000 --- a/lib/cryptopp/factory.h +++ /dev/null @@ -1,136 +0,0 @@ -#ifndef CRYPTOPP_OBJFACT_H -#define CRYPTOPP_OBJFACT_H - -#include "cryptlib.h" -#include -#include - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -template -class ObjectFactory -{ -public: - virtual ~ObjectFactory () {} - virtual AbstractClass * CreateObject() const =0; -}; - -//! _ -template -class DefaultObjectFactory : public ObjectFactory -{ -public: - AbstractClass * CreateObject() const - { - return new ConcreteClass; - } - -}; - -//! _ -template -class ObjectFactoryRegistry -{ -public: - class FactoryNotFound : public Exception - { - public: - FactoryNotFound(const char *name) : Exception(OTHER_ERROR, std::string("ObjectFactoryRegistry: could not find factory for algorithm ") + name) {} - }; - - ~ObjectFactoryRegistry() - { - for (CPP_TYPENAME Map::iterator i = m_map.begin(); i != m_map.end(); ++i) - { - delete (ObjectFactory *)i->second; - i->second = NULL; - } - } - - void RegisterFactory(const std::string &name, ObjectFactory *factory) - { - m_map[name] = factory; - } - - const ObjectFactory * GetFactory(const char *name) const - { - CPP_TYPENAME Map::const_iterator i = m_map.find(name); - return i == m_map.end() ? NULL : (ObjectFactory *)i->second; - } - - AbstractClass *CreateObject(const char *name) const - { - const ObjectFactory *factory = GetFactory(name); - if (!factory) - throw FactoryNotFound(name); - return factory->CreateObject(); - } - - // Return a vector containing the factory names. This is easier than returning an iterator. - // from Andrew Pitonyak - std::vector GetFactoryNames() const - { - std::vector names; - CPP_TYPENAME Map::const_iterator iter; - for (iter = m_map.begin(); iter != m_map.end(); ++iter) - names.push_back(iter->first); - return names; - } - - CRYPTOPP_NOINLINE static ObjectFactoryRegistry & Registry(CRYPTOPP_NOINLINE_DOTDOTDOT); - -private: - // use void * instead of ObjectFactory * to save code size - typedef std::map Map; - Map m_map; -}; - -template -ObjectFactoryRegistry & ObjectFactoryRegistry::Registry(CRYPTOPP_NOINLINE_DOTDOTDOT) -{ - static ObjectFactoryRegistry s_registry; - return s_registry; -} - -template -struct RegisterDefaultFactoryFor { -RegisterDefaultFactoryFor(const char *name=NULL) -{ - // BCB2006 workaround - std::string n = name ? std::string(name) : std::string(ConcreteClass::StaticAlgorithmName()); - ObjectFactoryRegistry::Registry(). - RegisterFactory(n, new DefaultObjectFactory); -}}; - -template -void RegisterAsymmetricCipherDefaultFactories(const char *name=NULL, SchemeClass *dummy=NULL) -{ - RegisterDefaultFactoryFor((const char *)name); - RegisterDefaultFactoryFor((const char *)name); -} - -template -void RegisterSignatureSchemeDefaultFactories(const char *name=NULL, SchemeClass *dummy=NULL) -{ - RegisterDefaultFactoryFor((const char *)name); - RegisterDefaultFactoryFor((const char *)name); -} - -template -void RegisterSymmetricCipherDefaultFactories(const char *name=NULL, SchemeClass *dummy=NULL) -{ - RegisterDefaultFactoryFor((const char *)name); - RegisterDefaultFactoryFor((const char *)name); -} - -template -void RegisterAuthenticatedSymmetricCipherDefaultFactories(const char *name=NULL, SchemeClass *dummy=NULL) -{ - RegisterDefaultFactoryFor((const char *)name); - RegisterDefaultFactoryFor((const char *)name); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/files.cpp b/lib/cryptopp/files.cpp deleted file mode 100644 index 453b56248..000000000 --- a/lib/cryptopp/files.cpp +++ /dev/null @@ -1,259 +0,0 @@ -// files.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "files.h" - -#include - -NAMESPACE_BEGIN(CryptoPP) - -using namespace std; - -#ifndef NDEBUG -void Files_TestInstantiations() -{ - FileStore f0; - FileSource f1; - FileSink f2; -} -#endif - -void FileStore::StoreInitialize(const NameValuePairs ¶meters) -{ - m_waiting = false; - m_stream = NULL; - m_file.release(); - - const char *fileName = NULL; -#if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400 - const wchar_t *fileNameWide = NULL; - if (!parameters.GetValue(Name::InputFileNameWide(), fileNameWide)) -#endif - if (!parameters.GetValue(Name::InputFileName(), fileName)) - { - parameters.GetValue(Name::InputStreamPointer(), m_stream); - return; - } - - ios::openmode binary = parameters.GetValueWithDefault(Name::InputBinaryMode(), true) ? ios::binary : ios::openmode(0); - m_file.reset(new std::ifstream); -#ifdef CRYPTOPP_UNIX_AVAILABLE - std::string narrowed; - if (fileNameWide) - fileName = (narrowed = StringNarrow(fileNameWide)).c_str(); -#endif -#if _MSC_VER >= 1400 - if (fileNameWide) - { - m_file->open(fileNameWide, ios::in | binary); - if (!*m_file) - throw OpenErr(StringNarrow(fileNameWide, false)); - } -#endif - if (fileName) - { - m_file->open(fileName, ios::in | binary); - if (!*m_file) - throw OpenErr(fileName); - } - m_stream = m_file.get(); -} - -lword FileStore::MaxRetrievable() const -{ - if (!m_stream) - return 0; - - streampos current = m_stream->tellg(); - streampos end = m_stream->seekg(0, ios::end).tellg(); - m_stream->seekg(current); - return end-current; -} - -size_t FileStore::TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel, bool blocking) -{ - if (!m_stream) - { - transferBytes = 0; - return 0; - } - - lword size=transferBytes; - transferBytes = 0; - - if (m_waiting) - goto output; - - while (size && m_stream->good()) - { - { - size_t spaceSize = 1024; - m_space = HelpCreatePutSpace(target, channel, 1, UnsignedMin(size_t(0)-1, size), spaceSize); - - m_stream->read((char *)m_space, (unsigned int)STDMIN(size, (lword)spaceSize)); - } - m_len = (size_t)m_stream->gcount(); - size_t blockedBytes; -output: - blockedBytes = target.ChannelPutModifiable2(channel, m_space, m_len, 0, blocking); - m_waiting = blockedBytes > 0; - if (m_waiting) - return blockedBytes; - size -= m_len; - transferBytes += m_len; - } - - if (!m_stream->good() && !m_stream->eof()) - throw ReadErr(); - - return 0; -} - -size_t FileStore::CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end, const std::string &channel, bool blocking) const -{ - if (!m_stream) - return 0; - - if (begin == 0 && end == 1) - { - int result = m_stream->peek(); - if (result == char_traits::eof()) - return 0; - else - { - size_t blockedBytes = target.ChannelPut(channel, byte(result), blocking); - begin += 1-blockedBytes; - return blockedBytes; - } - } - - // TODO: figure out what happens on cin - streampos current = m_stream->tellg(); - streampos endPosition = m_stream->seekg(0, ios::end).tellg(); - streampos newPosition = current + (streamoff)begin; - - if (newPosition >= endPosition) - { - m_stream->seekg(current); - return 0; // don't try to seek beyond the end of file - } - m_stream->seekg(newPosition); - try - { - assert(!m_waiting); - lword copyMax = end-begin; - size_t blockedBytes = const_cast(this)->TransferTo2(target, copyMax, channel, blocking); - begin += copyMax; - if (blockedBytes) - { - const_cast(this)->m_waiting = false; - return blockedBytes; - } - } - catch(...) - { - m_stream->clear(); - m_stream->seekg(current); - throw; - } - m_stream->clear(); - m_stream->seekg(current); - - return 0; -} - -lword FileStore::Skip(lword skipMax) -{ - if (!m_stream) - return 0; - - lword oldPos = m_stream->tellg(); - std::istream::off_type offset; - if (!SafeConvert(skipMax, offset)) - throw InvalidArgument("FileStore: maximum seek offset exceeded"); - m_stream->seekg(offset, ios::cur); - return (lword)m_stream->tellg() - oldPos; -} - -void FileSink::IsolatedInitialize(const NameValuePairs ¶meters) -{ - m_stream = NULL; - m_file.release(); - - const char *fileName = NULL; -#if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400 - const wchar_t *fileNameWide = NULL; - if (!parameters.GetValue(Name::OutputFileNameWide(), fileNameWide)) -#endif - if (!parameters.GetValue(Name::OutputFileName(), fileName)) - { - parameters.GetValue(Name::OutputStreamPointer(), m_stream); - return; - } - - ios::openmode binary = parameters.GetValueWithDefault(Name::OutputBinaryMode(), true) ? ios::binary : ios::openmode(0); - m_file.reset(new std::ofstream); -#ifdef CRYPTOPP_UNIX_AVAILABLE - std::string narrowed; - if (fileNameWide) - fileName = (narrowed = StringNarrow(fileNameWide)).c_str(); -#endif -#if _MSC_VER >= 1400 - if (fileNameWide) - { - m_file->open(fileNameWide, ios::out | ios::trunc | binary); - if (!*m_file) - throw OpenErr(StringNarrow(fileNameWide, false)); - } -#endif - if (fileName) - { - m_file->open(fileName, ios::out | ios::trunc | binary); - if (!*m_file) - throw OpenErr(fileName); - } - m_stream = m_file.get(); -} - -bool FileSink::IsolatedFlush(bool hardFlush, bool blocking) -{ - if (!m_stream) - throw Err("FileSink: output stream not opened"); - - m_stream->flush(); - if (!m_stream->good()) - throw WriteErr(); - - return false; -} - -size_t FileSink::Put2(const byte *inString, size_t length, int messageEnd, bool blocking) -{ - if (!m_stream) - throw Err("FileSink: output stream not opened"); - - while (length > 0) - { - std::streamsize size; - if (!SafeConvert(length, size)) - size = numeric_limits::max(); - m_stream->write((const char *)inString, size); - inString += size; - length -= (size_t)size; - } - - if (messageEnd) - m_stream->flush(); - - if (!m_stream->good()) - throw WriteErr(); - - return 0; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/files.h b/lib/cryptopp/files.h deleted file mode 100644 index a47e856bf..000000000 --- a/lib/cryptopp/files.h +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef CRYPTOPP_FILES_H -#define CRYPTOPP_FILES_H - -#include "cryptlib.h" -#include "filters.h" -#include "argnames.h" - -#include -#include - -NAMESPACE_BEGIN(CryptoPP) - -//! file-based implementation of Store interface -class CRYPTOPP_DLL FileStore : public Store, private FilterPutSpaceHelper, public NotCopyable -{ -public: - class Err : public Exception - { - public: - Err(const std::string &s) : Exception(IO_ERROR, s) {} - }; - class OpenErr : public Err {public: OpenErr(const std::string &filename) : Err("FileStore: error opening file for reading: " + filename) {}}; - class ReadErr : public Err {public: ReadErr() : Err("FileStore: error reading file") {}}; - - FileStore() : m_stream(NULL) {} - FileStore(std::istream &in) - {StoreInitialize(MakeParameters(Name::InputStreamPointer(), &in));} - FileStore(const char *filename) - {StoreInitialize(MakeParameters(Name::InputFileName(), filename));} -#if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400 - //! specify file with Unicode name. On non-Windows OS, this function assumes that setlocale() has been called. - FileStore(const wchar_t *filename) - {StoreInitialize(MakeParameters(Name::InputFileNameWide(), filename));} -#endif - - std::istream* GetStream() {return m_stream;} - - lword MaxRetrievable() const; - size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const; - lword Skip(lword skipMax=ULONG_MAX); - -private: - void StoreInitialize(const NameValuePairs ¶meters); - - member_ptr m_file; - std::istream *m_stream; - byte *m_space; - size_t m_len; - bool m_waiting; -}; - -//! file-based implementation of Source interface -class CRYPTOPP_DLL FileSource : public SourceTemplate -{ -public: - typedef FileStore::Err Err; - typedef FileStore::OpenErr OpenErr; - typedef FileStore::ReadErr ReadErr; - - FileSource(BufferedTransformation *attachment = NULL) - : SourceTemplate(attachment) {} - FileSource(std::istream &in, bool pumpAll, BufferedTransformation *attachment = NULL) - : SourceTemplate(attachment) {SourceInitialize(pumpAll, MakeParameters(Name::InputStreamPointer(), &in));} - FileSource(const char *filename, bool pumpAll, BufferedTransformation *attachment = NULL, bool binary=true) - : SourceTemplate(attachment) {SourceInitialize(pumpAll, MakeParameters(Name::InputFileName(), filename)(Name::InputBinaryMode(), binary));} -#if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400 - //! specify file with Unicode name. On non-Windows OS, this function assumes that setlocale() has been called. - FileSource(const wchar_t *filename, bool pumpAll, BufferedTransformation *attachment = NULL, bool binary=true) - : SourceTemplate(attachment) {SourceInitialize(pumpAll, MakeParameters(Name::InputFileNameWide(), filename)(Name::InputBinaryMode(), binary));} -#endif - - std::istream* GetStream() {return m_store.GetStream();} -}; - -//! file-based implementation of Sink interface -class CRYPTOPP_DLL FileSink : public Sink, public NotCopyable -{ -public: - class Err : public Exception - { - public: - Err(const std::string &s) : Exception(IO_ERROR, s) {} - }; - class OpenErr : public Err {public: OpenErr(const std::string &filename) : Err("FileSink: error opening file for writing: " + filename) {}}; - class WriteErr : public Err {public: WriteErr() : Err("FileSink: error writing file") {}}; - - FileSink() : m_stream(NULL) {} - FileSink(std::ostream &out) - {IsolatedInitialize(MakeParameters(Name::OutputStreamPointer(), &out));} - FileSink(const char *filename, bool binary=true) - {IsolatedInitialize(MakeParameters(Name::OutputFileName(), filename)(Name::OutputBinaryMode(), binary));} -#if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400 - //! specify file with Unicode name. On non-Windows OS, this function assumes that setlocale() has been called. - FileSink(const wchar_t *filename, bool binary=true) - {IsolatedInitialize(MakeParameters(Name::OutputFileNameWide(), filename)(Name::OutputBinaryMode(), binary));} -#endif - - std::ostream* GetStream() {return m_stream;} - - void IsolatedInitialize(const NameValuePairs ¶meters); - size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking); - bool IsolatedFlush(bool hardFlush, bool blocking); - -private: - member_ptr m_file; - std::ostream *m_stream; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/filters.cpp b/lib/cryptopp/filters.cpp deleted file mode 100644 index 083dfd361..000000000 --- a/lib/cryptopp/filters.cpp +++ /dev/null @@ -1,1120 +0,0 @@ -// filters.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "filters.h" -#include "mqueue.h" -#include "fltrimpl.h" -#include "argnames.h" -#include -#include - -NAMESPACE_BEGIN(CryptoPP) - -Filter::Filter(BufferedTransformation *attachment) - : m_attachment(attachment), m_continueAt(0) -{ -} - -BufferedTransformation * Filter::NewDefaultAttachment() const -{ - return new MessageQueue; -} - -BufferedTransformation * Filter::AttachedTransformation() -{ - if (m_attachment.get() == NULL) - m_attachment.reset(NewDefaultAttachment()); - return m_attachment.get(); -} - -const BufferedTransformation *Filter::AttachedTransformation() const -{ - if (m_attachment.get() == NULL) - const_cast(this)->m_attachment.reset(NewDefaultAttachment()); - return m_attachment.get(); -} - -void Filter::Detach(BufferedTransformation *newOut) -{ - m_attachment.reset(newOut); -} - -void Filter::Insert(Filter *filter) -{ - filter->m_attachment.reset(m_attachment.release()); - m_attachment.reset(filter); -} - -size_t Filter::CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end, const std::string &channel, bool blocking) const -{ - return AttachedTransformation()->CopyRangeTo2(target, begin, end, channel, blocking); -} - -size_t Filter::TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel, bool blocking) -{ - return AttachedTransformation()->TransferTo2(target, transferBytes, channel, blocking); -} - -void Filter::Initialize(const NameValuePairs ¶meters, int propagation) -{ - m_continueAt = 0; - IsolatedInitialize(parameters); - PropagateInitialize(parameters, propagation); -} - -bool Filter::Flush(bool hardFlush, int propagation, bool blocking) -{ - switch (m_continueAt) - { - case 0: - if (IsolatedFlush(hardFlush, blocking)) - return true; - case 1: - if (OutputFlush(1, hardFlush, propagation, blocking)) - return true; - } - return false; -} - -bool Filter::MessageSeriesEnd(int propagation, bool blocking) -{ - switch (m_continueAt) - { - case 0: - if (IsolatedMessageSeriesEnd(blocking)) - return true; - case 1: - if (ShouldPropagateMessageSeriesEnd() && OutputMessageSeriesEnd(1, propagation, blocking)) - return true; - } - return false; -} - -void Filter::PropagateInitialize(const NameValuePairs ¶meters, int propagation) -{ - if (propagation) - AttachedTransformation()->Initialize(parameters, propagation-1); -} - -size_t Filter::OutputModifiable(int outputSite, byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel) -{ - if (messageEnd) - messageEnd--; - size_t result = AttachedTransformation()->ChannelPutModifiable2(channel, inString, length, messageEnd, blocking); - m_continueAt = result ? outputSite : 0; - return result; -} - -size_t Filter::Output(int outputSite, const byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel) -{ - if (messageEnd) - messageEnd--; - size_t result = AttachedTransformation()->ChannelPut2(channel, inString, length, messageEnd, blocking); - m_continueAt = result ? outputSite : 0; - return result; -} - -bool Filter::OutputFlush(int outputSite, bool hardFlush, int propagation, bool blocking, const std::string &channel) -{ - if (propagation && AttachedTransformation()->ChannelFlush(channel, hardFlush, propagation-1, blocking)) - { - m_continueAt = outputSite; - return true; - } - m_continueAt = 0; - return false; -} - -bool Filter::OutputMessageSeriesEnd(int outputSite, int propagation, bool blocking, const std::string &channel) -{ - if (propagation && AttachedTransformation()->ChannelMessageSeriesEnd(channel, propagation-1, blocking)) - { - m_continueAt = outputSite; - return true; - } - m_continueAt = 0; - return false; -} - -// ************************************************************* - -void MeterFilter::ResetMeter() -{ - m_currentMessageBytes = m_totalBytes = m_currentSeriesMessages = m_totalMessages = m_totalMessageSeries = 0; - m_rangesToSkip.clear(); -} - -void MeterFilter::AddRangeToSkip(unsigned int message, lword position, lword size, bool sortNow) -{ - MessageRange r = {message, position, size}; - m_rangesToSkip.push_back(r); - if (sortNow) - std::sort(m_rangesToSkip.begin(), m_rangesToSkip.end()); -} - -size_t MeterFilter::PutMaybeModifiable(byte *begin, size_t length, int messageEnd, bool blocking, bool modifiable) -{ - if (!m_transparent) - return 0; - - size_t t; - FILTER_BEGIN; - - m_begin = begin; - m_length = length; - - while (m_length > 0 || messageEnd) - { - if (m_length > 0 && !m_rangesToSkip.empty() && m_rangesToSkip.front().message == m_totalMessages && m_currentMessageBytes + m_length > m_rangesToSkip.front().position) - { - FILTER_OUTPUT_MAYBE_MODIFIABLE(1, m_begin, t = (size_t)SaturatingSubtract(m_rangesToSkip.front().position, m_currentMessageBytes), false, modifiable); - - assert(t < m_length); - m_begin += t; - m_length -= t; - m_currentMessageBytes += t; - m_totalBytes += t; - - if (m_currentMessageBytes + m_length < m_rangesToSkip.front().position + m_rangesToSkip.front().size) - t = m_length; - else - { - t = (size_t)SaturatingSubtract(m_rangesToSkip.front().position + m_rangesToSkip.front().size, m_currentMessageBytes); - assert(t <= m_length); - m_rangesToSkip.pop_front(); - } - - m_begin += t; - m_length -= t; - m_currentMessageBytes += t; - m_totalBytes += t; - } - else - { - FILTER_OUTPUT_MAYBE_MODIFIABLE(2, m_begin, m_length, messageEnd, modifiable); - - m_currentMessageBytes += m_length; - m_totalBytes += m_length; - m_length = 0; - - if (messageEnd) - { - m_currentMessageBytes = 0; - m_currentSeriesMessages++; - m_totalMessages++; - messageEnd = false; - } - } - } - - FILTER_END_NO_MESSAGE_END; -} - -size_t MeterFilter::Put2(const byte *begin, size_t length, int messageEnd, bool blocking) -{ - return PutMaybeModifiable(const_cast(begin), length, messageEnd, blocking, false); -} - -size_t MeterFilter::PutModifiable2(byte *begin, size_t length, int messageEnd, bool blocking) -{ - return PutMaybeModifiable(begin, length, messageEnd, blocking, true); -} - -bool MeterFilter::IsolatedMessageSeriesEnd(bool blocking) -{ - m_currentMessageBytes = 0; - m_currentSeriesMessages = 0; - m_totalMessageSeries++; - return false; -} - -// ************************************************************* - -void FilterWithBufferedInput::BlockQueue::ResetQueue(size_t blockSize, size_t maxBlocks) -{ - m_buffer.New(blockSize * maxBlocks); - m_blockSize = blockSize; - m_maxBlocks = maxBlocks; - m_size = 0; - m_begin = m_buffer; -} - -byte *FilterWithBufferedInput::BlockQueue::GetBlock() -{ - if (m_size >= m_blockSize) - { - byte *ptr = m_begin; - if ((m_begin+=m_blockSize) == m_buffer.end()) - m_begin = m_buffer; - m_size -= m_blockSize; - return ptr; - } - else - return NULL; -} - -byte *FilterWithBufferedInput::BlockQueue::GetContigousBlocks(size_t &numberOfBytes) -{ - numberOfBytes = STDMIN(numberOfBytes, STDMIN(size_t(m_buffer.end()-m_begin), m_size)); - byte *ptr = m_begin; - m_begin += numberOfBytes; - m_size -= numberOfBytes; - if (m_size == 0 || m_begin == m_buffer.end()) - m_begin = m_buffer; - return ptr; -} - -size_t FilterWithBufferedInput::BlockQueue::GetAll(byte *outString) -{ - size_t size = m_size; - size_t numberOfBytes = m_maxBlocks*m_blockSize; - const byte *ptr = GetContigousBlocks(numberOfBytes); - memcpy(outString, ptr, numberOfBytes); - memcpy(outString+numberOfBytes, m_begin, m_size); - m_size = 0; - return size; -} - -void FilterWithBufferedInput::BlockQueue::Put(const byte *inString, size_t length) -{ - assert(m_size + length <= m_buffer.size()); - byte *end = (m_size < size_t(m_buffer.end()-m_begin)) ? m_begin + m_size : m_begin + m_size - m_buffer.size(); - size_t len = STDMIN(length, size_t(m_buffer.end()-end)); - memcpy(end, inString, len); - if (len < length) - memcpy(m_buffer, inString+len, length-len); - m_size += length; -} - -FilterWithBufferedInput::FilterWithBufferedInput(BufferedTransformation *attachment) - : Filter(attachment) -{ -} - -FilterWithBufferedInput::FilterWithBufferedInput(size_t firstSize, size_t blockSize, size_t lastSize, BufferedTransformation *attachment) - : Filter(attachment), m_firstSize(firstSize), m_blockSize(blockSize), m_lastSize(lastSize) - , m_firstInputDone(false) -{ - if (m_firstSize < 0 || m_blockSize < 1 || m_lastSize < 0) - throw InvalidArgument("FilterWithBufferedInput: invalid buffer size"); - - m_queue.ResetQueue(1, m_firstSize); -} - -void FilterWithBufferedInput::IsolatedInitialize(const NameValuePairs ¶meters) -{ - InitializeDerivedAndReturnNewSizes(parameters, m_firstSize, m_blockSize, m_lastSize); - if (m_firstSize < 0 || m_blockSize < 1 || m_lastSize < 0) - throw InvalidArgument("FilterWithBufferedInput: invalid buffer size"); - m_queue.ResetQueue(1, m_firstSize); - m_firstInputDone = false; -} - -bool FilterWithBufferedInput::IsolatedFlush(bool hardFlush, bool blocking) -{ - if (!blocking) - throw BlockingInputOnly("FilterWithBufferedInput"); - - if (hardFlush) - ForceNextPut(); - FlushDerived(); - - return false; -} - -size_t FilterWithBufferedInput::PutMaybeModifiable(byte *inString, size_t length, int messageEnd, bool blocking, bool modifiable) -{ - if (!blocking) - throw BlockingInputOnly("FilterWithBufferedInput"); - - if (length != 0) - { - size_t newLength = m_queue.CurrentSize() + length; - - if (!m_firstInputDone && newLength >= m_firstSize) - { - size_t len = m_firstSize - m_queue.CurrentSize(); - m_queue.Put(inString, len); - FirstPut(m_queue.GetContigousBlocks(m_firstSize)); - assert(m_queue.CurrentSize() == 0); - m_queue.ResetQueue(m_blockSize, (2*m_blockSize+m_lastSize-2)/m_blockSize); - - inString += len; - newLength -= m_firstSize; - m_firstInputDone = true; - } - - if (m_firstInputDone) - { - if (m_blockSize == 1) - { - while (newLength > m_lastSize && m_queue.CurrentSize() > 0) - { - size_t len = newLength - m_lastSize; - byte *ptr = m_queue.GetContigousBlocks(len); - NextPutModifiable(ptr, len); - newLength -= len; - } - - if (newLength > m_lastSize) - { - size_t len = newLength - m_lastSize; - NextPutMaybeModifiable(inString, len, modifiable); - inString += len; - newLength -= len; - } - } - else - { - while (newLength >= m_blockSize + m_lastSize && m_queue.CurrentSize() >= m_blockSize) - { - NextPutModifiable(m_queue.GetBlock(), m_blockSize); - newLength -= m_blockSize; - } - - if (newLength >= m_blockSize + m_lastSize && m_queue.CurrentSize() > 0) - { - assert(m_queue.CurrentSize() < m_blockSize); - size_t len = m_blockSize - m_queue.CurrentSize(); - m_queue.Put(inString, len); - inString += len; - NextPutModifiable(m_queue.GetBlock(), m_blockSize); - newLength -= m_blockSize; - } - - if (newLength >= m_blockSize + m_lastSize) - { - size_t len = RoundDownToMultipleOf(newLength - m_lastSize, m_blockSize); - NextPutMaybeModifiable(inString, len, modifiable); - inString += len; - newLength -= len; - } - } - } - - m_queue.Put(inString, newLength - m_queue.CurrentSize()); - } - - if (messageEnd) - { - if (!m_firstInputDone && m_firstSize==0) - FirstPut(NULL); - - SecByteBlock temp(m_queue.CurrentSize()); - m_queue.GetAll(temp); - LastPut(temp, temp.size()); - - m_firstInputDone = false; - m_queue.ResetQueue(1, m_firstSize); - - Output(1, NULL, 0, messageEnd, blocking); - } - return 0; -} - -void FilterWithBufferedInput::ForceNextPut() -{ - if (!m_firstInputDone) - return; - - if (m_blockSize > 1) - { - while (m_queue.CurrentSize() >= m_blockSize) - NextPutModifiable(m_queue.GetBlock(), m_blockSize); - } - else - { - size_t len; - while ((len = m_queue.CurrentSize()) > 0) - NextPutModifiable(m_queue.GetContigousBlocks(len), len); - } -} - -void FilterWithBufferedInput::NextPutMultiple(const byte *inString, size_t length) -{ - assert(m_blockSize > 1); // m_blockSize = 1 should always override this function - while (length > 0) - { - assert(length >= m_blockSize); - NextPutSingle(inString); - inString += m_blockSize; - length -= m_blockSize; - } -} - -// ************************************************************* - -void Redirector::Initialize(const NameValuePairs ¶meters, int propagation) -{ - m_target = parameters.GetValueWithDefault("RedirectionTargetPointer", (BufferedTransformation*)NULL); - m_behavior = parameters.GetIntValueWithDefault("RedirectionBehavior", PASS_EVERYTHING); - - if (m_target && GetPassSignals()) - m_target->Initialize(parameters, propagation); -} - -// ************************************************************* - -ProxyFilter::ProxyFilter(BufferedTransformation *filter, size_t firstSize, size_t lastSize, BufferedTransformation *attachment) - : FilterWithBufferedInput(firstSize, 1, lastSize, attachment), m_filter(filter) -{ - if (m_filter.get()) - m_filter->Attach(new OutputProxy(*this, false)); -} - -bool ProxyFilter::IsolatedFlush(bool hardFlush, bool blocking) -{ - return m_filter.get() ? m_filter->Flush(hardFlush, -1, blocking) : false; -} - -void ProxyFilter::SetFilter(Filter *filter) -{ - m_filter.reset(filter); - if (filter) - { - OutputProxy *proxy; - std::auto_ptr temp(proxy = new OutputProxy(*this, false)); - m_filter->TransferAllTo(*proxy); - m_filter->Attach(temp.release()); - } -} - -void ProxyFilter::NextPutMultiple(const byte *s, size_t len) -{ - if (m_filter.get()) - m_filter->Put(s, len); -} - -void ProxyFilter::NextPutModifiable(byte *s, size_t len) -{ - if (m_filter.get()) - m_filter->PutModifiable(s, len); -} - -// ************************************************************* - -void RandomNumberSink::IsolatedInitialize(const NameValuePairs ¶meters) -{ - parameters.GetRequiredParameter("RandomNumberSink", "RandomNumberGeneratorPointer", m_rng); -} - -size_t RandomNumberSink::Put2(const byte *begin, size_t length, int messageEnd, bool blocking) -{ - m_rng->IncorporateEntropy(begin, length); - return 0; -} - -size_t ArraySink::Put2(const byte *begin, size_t length, int messageEnd, bool blocking) -{ - if (m_buf+m_total != begin) - memcpy(m_buf+m_total, begin, STDMIN(length, SaturatingSubtract(m_size, m_total))); - m_total += length; - return 0; -} - -byte * ArraySink::CreatePutSpace(size_t &size) -{ - size = SaturatingSubtract(m_size, m_total); - return m_buf + m_total; -} - -void ArraySink::IsolatedInitialize(const NameValuePairs ¶meters) -{ - ByteArrayParameter array; - if (!parameters.GetValue(Name::OutputBuffer(), array)) - throw InvalidArgument("ArraySink: missing OutputBuffer argument"); - m_buf = array.begin(); - m_size = array.size(); - m_total = 0; -} - -size_t ArrayXorSink::Put2(const byte *begin, size_t length, int messageEnd, bool blocking) -{ - xorbuf(m_buf+m_total, begin, STDMIN(length, SaturatingSubtract(m_size, m_total))); - m_total += length; - return 0; -} - -// ************************************************************* - -StreamTransformationFilter::StreamTransformationFilter(StreamTransformation &c, BufferedTransformation *attachment, BlockPaddingScheme padding, bool allowAuthenticatedSymmetricCipher) - : FilterWithBufferedInput(attachment) - , m_cipher(c) -{ - assert(c.MinLastBlockSize() == 0 || c.MinLastBlockSize() > c.MandatoryBlockSize()); - - if (!allowAuthenticatedSymmetricCipher && dynamic_cast(&c) != 0) - throw InvalidArgument("StreamTransformationFilter: please use AuthenticatedEncryptionFilter and AuthenticatedDecryptionFilter for AuthenticatedSymmetricCipher"); - - IsolatedInitialize(MakeParameters(Name::BlockPaddingScheme(), padding)); -} - -size_t StreamTransformationFilter::LastBlockSize(StreamTransformation &c, BlockPaddingScheme padding) -{ - if (c.MinLastBlockSize() > 0) - return c.MinLastBlockSize(); - else if (c.MandatoryBlockSize() > 1 && !c.IsForwardTransformation() && padding != NO_PADDING && padding != ZEROS_PADDING) - return c.MandatoryBlockSize(); - else - return 0; -} - -void StreamTransformationFilter::InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize) -{ - BlockPaddingScheme padding = parameters.GetValueWithDefault(Name::BlockPaddingScheme(), DEFAULT_PADDING); - bool isBlockCipher = (m_cipher.MandatoryBlockSize() > 1 && m_cipher.MinLastBlockSize() == 0); - - if (padding == DEFAULT_PADDING) - m_padding = isBlockCipher ? PKCS_PADDING : NO_PADDING; - else - m_padding = padding; - - if (!isBlockCipher && (m_padding == PKCS_PADDING || m_padding == ONE_AND_ZEROS_PADDING)) - throw InvalidArgument("StreamTransformationFilter: PKCS_PADDING and ONE_AND_ZEROS_PADDING cannot be used with " + m_cipher.AlgorithmName()); - - firstSize = 0; - blockSize = m_cipher.MandatoryBlockSize(); - lastSize = LastBlockSize(m_cipher, m_padding); -} - -void StreamTransformationFilter::FirstPut(const byte *inString) -{ - m_optimalBufferSize = m_cipher.OptimalBlockSize(); - m_optimalBufferSize = (unsigned int)STDMAX(m_optimalBufferSize, RoundDownToMultipleOf(4096U, m_optimalBufferSize)); -} - -void StreamTransformationFilter::NextPutMultiple(const byte *inString, size_t length) -{ - if (!length) - return; - - size_t s = m_cipher.MandatoryBlockSize(); - - do - { - size_t len = m_optimalBufferSize; - byte *space = HelpCreatePutSpace(*AttachedTransformation(), DEFAULT_CHANNEL, s, length, len); - if (len < length) - { - if (len == m_optimalBufferSize) - len -= m_cipher.GetOptimalBlockSizeUsed(); - len = RoundDownToMultipleOf(len, s); - } - else - len = length; - m_cipher.ProcessString(space, inString, len); - AttachedTransformation()->PutModifiable(space, len); - inString += len; - length -= len; - } - while (length > 0); -} - -void StreamTransformationFilter::NextPutModifiable(byte *inString, size_t length) -{ - m_cipher.ProcessString(inString, length); - AttachedTransformation()->PutModifiable(inString, length); -} - -void StreamTransformationFilter::LastPut(const byte *inString, size_t length) -{ - byte *space = NULL; - - switch (m_padding) - { - case NO_PADDING: - case ZEROS_PADDING: - if (length > 0) - { - size_t minLastBlockSize = m_cipher.MinLastBlockSize(); - bool isForwardTransformation = m_cipher.IsForwardTransformation(); - - if (isForwardTransformation && m_padding == ZEROS_PADDING && (minLastBlockSize == 0 || length < minLastBlockSize)) - { - // do padding - size_t blockSize = STDMAX(minLastBlockSize, (size_t)m_cipher.MandatoryBlockSize()); - space = HelpCreatePutSpace(*AttachedTransformation(), DEFAULT_CHANNEL, blockSize); - memcpy(space, inString, length); - memset(space + length, 0, blockSize - length); - m_cipher.ProcessLastBlock(space, space, blockSize); - AttachedTransformation()->Put(space, blockSize); - } - else - { - if (minLastBlockSize == 0) - { - if (isForwardTransformation) - throw InvalidDataFormat("StreamTransformationFilter: plaintext length is not a multiple of block size and NO_PADDING is specified"); - else - throw InvalidCiphertext("StreamTransformationFilter: ciphertext length is not a multiple of block size"); - } - - space = HelpCreatePutSpace(*AttachedTransformation(), DEFAULT_CHANNEL, length, m_optimalBufferSize); - m_cipher.ProcessLastBlock(space, inString, length); - AttachedTransformation()->Put(space, length); - } - } - break; - - case PKCS_PADDING: - case ONE_AND_ZEROS_PADDING: - unsigned int s; - s = m_cipher.MandatoryBlockSize(); - assert(s > 1); - space = HelpCreatePutSpace(*AttachedTransformation(), DEFAULT_CHANNEL, s, m_optimalBufferSize); - if (m_cipher.IsForwardTransformation()) - { - assert(length < s); - memcpy(space, inString, length); - if (m_padding == PKCS_PADDING) - { - assert(s < 256); - byte pad = byte(s-length); - memset(space+length, pad, s-length); - } - else - { - space[length] = 0x80; - memset(space+length+1, 0, s-length-1); - } - m_cipher.ProcessData(space, space, s); - AttachedTransformation()->Put(space, s); - } - else - { - if (length != s) - throw InvalidCiphertext("StreamTransformationFilter: ciphertext length is not a multiple of block size"); - m_cipher.ProcessData(space, inString, s); - if (m_padding == PKCS_PADDING) - { - byte pad = space[s-1]; - if (pad < 1 || pad > s || std::find_if(space+s-pad, space+s, std::bind2nd(std::not_equal_to(), pad)) != space+s) - throw InvalidCiphertext("StreamTransformationFilter: invalid PKCS #7 block padding found"); - length = s-pad; - } - else - { - while (length > 1 && space[length-1] == 0) - --length; - if (space[--length] != 0x80) - throw InvalidCiphertext("StreamTransformationFilter: invalid ones-and-zeros padding found"); - } - AttachedTransformation()->Put(space, length); - } - break; - - default: - assert(false); - } -} - -// ************************************************************* - -HashFilter::HashFilter(HashTransformation &hm, BufferedTransformation *attachment, bool putMessage, int truncatedDigestSize, const std::string &messagePutChannel, const std::string &hashPutChannel) - : m_hashModule(hm), m_putMessage(putMessage), m_messagePutChannel(messagePutChannel), m_hashPutChannel(hashPutChannel) -{ - m_digestSize = truncatedDigestSize < 0 ? m_hashModule.DigestSize() : truncatedDigestSize; - Detach(attachment); -} - -void HashFilter::IsolatedInitialize(const NameValuePairs ¶meters) -{ - m_putMessage = parameters.GetValueWithDefault(Name::PutMessage(), false); - int s = parameters.GetIntValueWithDefault(Name::TruncatedDigestSize(), -1); - m_digestSize = s < 0 ? m_hashModule.DigestSize() : s; -} - -size_t HashFilter::Put2(const byte *inString, size_t length, int messageEnd, bool blocking) -{ - FILTER_BEGIN; - if (m_putMessage) - FILTER_OUTPUT3(1, 0, inString, length, 0, m_messagePutChannel); - m_hashModule.Update(inString, length); - if (messageEnd) - { - { - size_t size; - m_space = HelpCreatePutSpace(*AttachedTransformation(), m_hashPutChannel, m_digestSize, m_digestSize, size = m_digestSize); - m_hashModule.TruncatedFinal(m_space, m_digestSize); - } - FILTER_OUTPUT3(2, 0, m_space, m_digestSize, messageEnd, m_hashPutChannel); - } - FILTER_END_NO_MESSAGE_END; -} - -// ************************************************************* - -HashVerificationFilter::HashVerificationFilter(HashTransformation &hm, BufferedTransformation *attachment, word32 flags, int truncatedDigestSize) - : FilterWithBufferedInput(attachment) - , m_hashModule(hm) -{ - IsolatedInitialize(MakeParameters(Name::HashVerificationFilterFlags(), flags)(Name::TruncatedDigestSize(), truncatedDigestSize)); -} - -void HashVerificationFilter::InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize) -{ - m_flags = parameters.GetValueWithDefault(Name::HashVerificationFilterFlags(), (word32)DEFAULT_FLAGS); - int s = parameters.GetIntValueWithDefault(Name::TruncatedDigestSize(), -1); - m_digestSize = s < 0 ? m_hashModule.DigestSize() : s; - m_verified = false; - firstSize = m_flags & HASH_AT_BEGIN ? m_digestSize : 0; - blockSize = 1; - lastSize = m_flags & HASH_AT_BEGIN ? 0 : m_digestSize; -} - -void HashVerificationFilter::FirstPut(const byte *inString) -{ - if (m_flags & HASH_AT_BEGIN) - { - m_expectedHash.New(m_digestSize); - memcpy(m_expectedHash, inString, m_expectedHash.size()); - if (m_flags & PUT_HASH) - AttachedTransformation()->Put(inString, m_expectedHash.size()); - } -} - -void HashVerificationFilter::NextPutMultiple(const byte *inString, size_t length) -{ - m_hashModule.Update(inString, length); - if (m_flags & PUT_MESSAGE) - AttachedTransformation()->Put(inString, length); -} - -void HashVerificationFilter::LastPut(const byte *inString, size_t length) -{ - if (m_flags & HASH_AT_BEGIN) - { - assert(length == 0); - m_verified = m_hashModule.TruncatedVerify(m_expectedHash, m_digestSize); - } - else - { - m_verified = (length==m_digestSize && m_hashModule.TruncatedVerify(inString, length)); - if (m_flags & PUT_HASH) - AttachedTransformation()->Put(inString, length); - } - - if (m_flags & PUT_RESULT) - AttachedTransformation()->Put(m_verified); - - if ((m_flags & THROW_EXCEPTION) && !m_verified) - throw HashVerificationFailed(); -} - -// ************************************************************* - -AuthenticatedEncryptionFilter::AuthenticatedEncryptionFilter(AuthenticatedSymmetricCipher &c, BufferedTransformation *attachment, - bool putAAD, int truncatedDigestSize, const std::string &macChannel, BlockPaddingScheme padding) - : StreamTransformationFilter(c, attachment, padding, true) - , m_hf(c, new OutputProxy(*this, false), putAAD, truncatedDigestSize, AAD_CHANNEL, macChannel) -{ - assert(c.IsForwardTransformation()); -} - -void AuthenticatedEncryptionFilter::IsolatedInitialize(const NameValuePairs ¶meters) -{ - m_hf.IsolatedInitialize(parameters); - StreamTransformationFilter::IsolatedInitialize(parameters); -} - -byte * AuthenticatedEncryptionFilter::ChannelCreatePutSpace(const std::string &channel, size_t &size) -{ - if (channel.empty()) - return StreamTransformationFilter::CreatePutSpace(size); - - if (channel == AAD_CHANNEL) - return m_hf.CreatePutSpace(size); - - throw InvalidChannelName("AuthenticatedEncryptionFilter", channel); -} - -size_t AuthenticatedEncryptionFilter::ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking) -{ - if (channel.empty()) - return StreamTransformationFilter::Put2(begin, length, messageEnd, blocking); - - if (channel == AAD_CHANNEL) - return m_hf.Put2(begin, length, 0, blocking); - - throw InvalidChannelName("AuthenticatedEncryptionFilter", channel); -} - -void AuthenticatedEncryptionFilter::LastPut(const byte *inString, size_t length) -{ - StreamTransformationFilter::LastPut(inString, length); - m_hf.MessageEnd(); -} - -// ************************************************************* - -AuthenticatedDecryptionFilter::AuthenticatedDecryptionFilter(AuthenticatedSymmetricCipher &c, BufferedTransformation *attachment, word32 flags, int truncatedDigestSize, BlockPaddingScheme padding) - : FilterWithBufferedInput(attachment) - , m_hashVerifier(c, new OutputProxy(*this, false)) - , m_streamFilter(c, new OutputProxy(*this, false), padding, true) -{ - assert(!c.IsForwardTransformation() || c.IsSelfInverting()); - IsolatedInitialize(MakeParameters(Name::BlockPaddingScheme(), padding)(Name::AuthenticatedDecryptionFilterFlags(), flags)(Name::TruncatedDigestSize(), truncatedDigestSize)); -} - -void AuthenticatedDecryptionFilter::InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize) -{ - word32 flags = parameters.GetValueWithDefault(Name::AuthenticatedDecryptionFilterFlags(), (word32)DEFAULT_FLAGS); - - m_hashVerifier.Initialize(CombinedNameValuePairs(parameters, MakeParameters(Name::HashVerificationFilterFlags(), flags))); - m_streamFilter.Initialize(parameters); - - firstSize = m_hashVerifier.m_firstSize; - blockSize = 1; - lastSize = m_hashVerifier.m_lastSize; -} - -byte * AuthenticatedDecryptionFilter::ChannelCreatePutSpace(const std::string &channel, size_t &size) -{ - if (channel.empty()) - return m_streamFilter.CreatePutSpace(size); - - if (channel == AAD_CHANNEL) - return m_hashVerifier.CreatePutSpace(size); - - throw InvalidChannelName("AuthenticatedDecryptionFilter", channel); -} - -size_t AuthenticatedDecryptionFilter::ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking) -{ - if (channel.empty()) - { - if (m_lastSize > 0) - m_hashVerifier.ForceNextPut(); - return FilterWithBufferedInput::Put2(begin, length, messageEnd, blocking); - } - - if (channel == AAD_CHANNEL) - return m_hashVerifier.Put2(begin, length, 0, blocking); - - throw InvalidChannelName("AuthenticatedDecryptionFilter", channel); -} - -void AuthenticatedDecryptionFilter::FirstPut(const byte *inString) -{ - m_hashVerifier.Put(inString, m_firstSize); -} - -void AuthenticatedDecryptionFilter::NextPutMultiple(const byte *inString, size_t length) -{ - m_streamFilter.Put(inString, length); -} - -void AuthenticatedDecryptionFilter::LastPut(const byte *inString, size_t length) -{ - m_streamFilter.MessageEnd(); - m_hashVerifier.PutMessageEnd(inString, length); -} - -// ************************************************************* - -void SignerFilter::IsolatedInitialize(const NameValuePairs ¶meters) -{ - m_putMessage = parameters.GetValueWithDefault(Name::PutMessage(), false); - m_messageAccumulator.reset(m_signer.NewSignatureAccumulator(m_rng)); -} - -size_t SignerFilter::Put2(const byte *inString, size_t length, int messageEnd, bool blocking) -{ - FILTER_BEGIN; - m_messageAccumulator->Update(inString, length); - if (m_putMessage) - FILTER_OUTPUT(1, inString, length, 0); - if (messageEnd) - { - m_buf.New(m_signer.SignatureLength()); - m_signer.Sign(m_rng, m_messageAccumulator.release(), m_buf); - FILTER_OUTPUT(2, m_buf, m_buf.size(), messageEnd); - m_messageAccumulator.reset(m_signer.NewSignatureAccumulator(m_rng)); - } - FILTER_END_NO_MESSAGE_END; -} - -SignatureVerificationFilter::SignatureVerificationFilter(const PK_Verifier &verifier, BufferedTransformation *attachment, word32 flags) - : FilterWithBufferedInput(attachment) - , m_verifier(verifier) -{ - IsolatedInitialize(MakeParameters(Name::SignatureVerificationFilterFlags(), flags)); -} - -void SignatureVerificationFilter::InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize) -{ - m_flags = parameters.GetValueWithDefault(Name::SignatureVerificationFilterFlags(), (word32)DEFAULT_FLAGS); - m_messageAccumulator.reset(m_verifier.NewVerificationAccumulator()); - size_t size = m_verifier.SignatureLength(); - assert(size != 0); // TODO: handle recoverable signature scheme - m_verified = false; - firstSize = m_flags & SIGNATURE_AT_BEGIN ? size : 0; - blockSize = 1; - lastSize = m_flags & SIGNATURE_AT_BEGIN ? 0 : size; -} - -void SignatureVerificationFilter::FirstPut(const byte *inString) -{ - if (m_flags & SIGNATURE_AT_BEGIN) - { - if (m_verifier.SignatureUpfront()) - m_verifier.InputSignature(*m_messageAccumulator, inString, m_verifier.SignatureLength()); - else - { - m_signature.New(m_verifier.SignatureLength()); - memcpy(m_signature, inString, m_signature.size()); - } - - if (m_flags & PUT_SIGNATURE) - AttachedTransformation()->Put(inString, m_signature.size()); - } - else - { - assert(!m_verifier.SignatureUpfront()); - } -} - -void SignatureVerificationFilter::NextPutMultiple(const byte *inString, size_t length) -{ - m_messageAccumulator->Update(inString, length); - if (m_flags & PUT_MESSAGE) - AttachedTransformation()->Put(inString, length); -} - -void SignatureVerificationFilter::LastPut(const byte *inString, size_t length) -{ - if (m_flags & SIGNATURE_AT_BEGIN) - { - assert(length == 0); - m_verifier.InputSignature(*m_messageAccumulator, m_signature, m_signature.size()); - m_verified = m_verifier.VerifyAndRestart(*m_messageAccumulator); - } - else - { - m_verifier.InputSignature(*m_messageAccumulator, inString, length); - m_verified = m_verifier.VerifyAndRestart(*m_messageAccumulator); - if (m_flags & PUT_SIGNATURE) - AttachedTransformation()->Put(inString, length); - } - - if (m_flags & PUT_RESULT) - AttachedTransformation()->Put(m_verified); - - if ((m_flags & THROW_EXCEPTION) && !m_verified) - throw SignatureVerificationFailed(); -} - -// ************************************************************* - -size_t Source::PumpAll2(bool blocking) -{ - unsigned int messageCount = UINT_MAX; - do { - RETURN_IF_NONZERO(PumpMessages2(messageCount, blocking)); - } while(messageCount == UINT_MAX); - - return 0; -} - -bool Store::GetNextMessage() -{ - if (!m_messageEnd && !AnyRetrievable()) - { - m_messageEnd=true; - return true; - } - else - return false; -} - -unsigned int Store::CopyMessagesTo(BufferedTransformation &target, unsigned int count, const std::string &channel) const -{ - if (m_messageEnd || count == 0) - return 0; - else - { - CopyTo(target, ULONG_MAX, channel); - if (GetAutoSignalPropagation()) - target.ChannelMessageEnd(channel, GetAutoSignalPropagation()-1); - return 1; - } -} - -void StringStore::StoreInitialize(const NameValuePairs ¶meters) -{ - ConstByteArrayParameter array; - if (!parameters.GetValue(Name::InputBuffer(), array)) - throw InvalidArgument("StringStore: missing InputBuffer argument"); - m_store = array.begin(); - m_length = array.size(); - m_count = 0; -} - -size_t StringStore::TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel, bool blocking) -{ - lword position = 0; - size_t blockedBytes = CopyRangeTo2(target, position, transferBytes, channel, blocking); - m_count += (size_t)position; - transferBytes = position; - return blockedBytes; -} - -size_t StringStore::CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end, const std::string &channel, bool blocking) const -{ - size_t i = UnsignedMin(m_length, m_count+begin); - size_t len = UnsignedMin(m_length-i, end-begin); - size_t blockedBytes = target.ChannelPut2(channel, m_store+i, len, 0, blocking); - if (!blockedBytes) - begin += len; - return blockedBytes; -} - -void RandomNumberStore::StoreInitialize(const NameValuePairs ¶meters) -{ - parameters.GetRequiredParameter("RandomNumberStore", "RandomNumberGeneratorPointer", m_rng); - int length; - parameters.GetRequiredIntParameter("RandomNumberStore", "RandomNumberStoreSize", length); - m_length = length; -} - -size_t RandomNumberStore::TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel, bool blocking) -{ - if (!blocking) - throw NotImplemented("RandomNumberStore: nonblocking transfer is not implemented by this object"); - - transferBytes = UnsignedMin(transferBytes, m_length - m_count); - m_rng->GenerateIntoBufferedTransformation(target, channel, transferBytes); - m_count += transferBytes; - - return 0; -} - -size_t NullStore::CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end, const std::string &channel, bool blocking) const -{ - static const byte nullBytes[128] = {0}; - while (begin < end) - { - size_t len = (size_t)STDMIN(end-begin, lword(128)); - size_t blockedBytes = target.ChannelPut2(channel, nullBytes, len, 0, blocking); - if (blockedBytes) - return blockedBytes; - begin += len; - } - return 0; -} - -size_t NullStore::TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel, bool blocking) -{ - lword begin = 0; - size_t blockedBytes = NullStore::CopyRangeTo2(target, begin, transferBytes, channel, blocking); - transferBytes = begin; - m_size -= begin; - return blockedBytes; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/filters.h b/lib/cryptopp/filters.h deleted file mode 100644 index c72a4ece3..000000000 --- a/lib/cryptopp/filters.h +++ /dev/null @@ -1,810 +0,0 @@ -#ifndef CRYPTOPP_FILTERS_H -#define CRYPTOPP_FILTERS_H - -//! \file - -#include "simple.h" -#include "secblock.h" -#include "misc.h" -#include "smartptr.h" -#include "queue.h" -#include "algparam.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -/// provides an implementation of BufferedTransformation's attachment interface -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Filter : public BufferedTransformation, public NotCopyable -{ -public: - Filter(BufferedTransformation *attachment = NULL); - - bool Attachable() {return true;} - BufferedTransformation *AttachedTransformation(); - const BufferedTransformation *AttachedTransformation() const; - void Detach(BufferedTransformation *newAttachment = NULL); - - size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const; - - void Initialize(const NameValuePairs ¶meters=g_nullNameValuePairs, int propagation=-1); - bool Flush(bool hardFlush, int propagation=-1, bool blocking=true); - bool MessageSeriesEnd(int propagation=-1, bool blocking=true); - -protected: - virtual BufferedTransformation * NewDefaultAttachment() const; - void Insert(Filter *nextFilter); // insert filter after this one - - virtual bool ShouldPropagateMessageEnd() const {return true;} - virtual bool ShouldPropagateMessageSeriesEnd() const {return true;} - - void PropagateInitialize(const NameValuePairs ¶meters, int propagation); - - size_t Output(int outputSite, const byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel=DEFAULT_CHANNEL); - size_t OutputModifiable(int outputSite, byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel=DEFAULT_CHANNEL); - bool OutputMessageEnd(int outputSite, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL); - bool OutputFlush(int outputSite, bool hardFlush, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL); - bool OutputMessageSeriesEnd(int outputSite, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL); - -private: - member_ptr m_attachment; - -protected: - size_t m_inputPosition; - int m_continueAt; -}; - -struct CRYPTOPP_DLL FilterPutSpaceHelper -{ - // desiredSize is how much to ask target, bufferSize is how much to allocate in m_tempSpace - byte *HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t desiredSize, size_t &bufferSize) - { - assert(desiredSize >= minSize && bufferSize >= minSize); - if (m_tempSpace.size() < minSize) - { - byte *result = target.ChannelCreatePutSpace(channel, desiredSize); - if (desiredSize >= minSize) - { - bufferSize = desiredSize; - return result; - } - m_tempSpace.New(bufferSize); - } - - bufferSize = m_tempSpace.size(); - return m_tempSpace.begin(); - } - byte *HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize) - {return HelpCreatePutSpace(target, channel, minSize, minSize, minSize);} - byte *HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t bufferSize) - {return HelpCreatePutSpace(target, channel, minSize, minSize, bufferSize);} - SecByteBlock m_tempSpace; -}; - -//! measure how many byte and messages pass through, also serves as valve -class CRYPTOPP_DLL MeterFilter : public Bufferless -{ -public: - MeterFilter(BufferedTransformation *attachment=NULL, bool transparent=true) - : m_transparent(transparent) {Detach(attachment); ResetMeter();} - - void SetTransparent(bool transparent) {m_transparent = transparent;} - void AddRangeToSkip(unsigned int message, lword position, lword size, bool sortNow = true); - void ResetMeter(); - void IsolatedInitialize(const NameValuePairs ¶meters) {ResetMeter();} - - lword GetCurrentMessageBytes() const {return m_currentMessageBytes;} - lword GetTotalBytes() {return m_totalBytes;} - unsigned int GetCurrentSeriesMessages() {return m_currentSeriesMessages;} - unsigned int GetTotalMessages() {return m_totalMessages;} - unsigned int GetTotalMessageSeries() {return m_totalMessageSeries;} - - byte * CreatePutSpace(size_t &size) - {return AttachedTransformation()->CreatePutSpace(size);} - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking); - size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking); - bool IsolatedMessageSeriesEnd(bool blocking); - -private: - size_t PutMaybeModifiable(byte *inString, size_t length, int messageEnd, bool blocking, bool modifiable); - bool ShouldPropagateMessageEnd() const {return m_transparent;} - bool ShouldPropagateMessageSeriesEnd() const {return m_transparent;} - - struct MessageRange - { - inline bool operator<(const MessageRange &b) const // BCB2006 workaround: this has to be a member function - {return message < b.message || (message == b.message && position < b.position);} - unsigned int message; lword position; lword size; - }; - - bool m_transparent; - lword m_currentMessageBytes, m_totalBytes; - unsigned int m_currentSeriesMessages, m_totalMessages, m_totalMessageSeries; - std::deque m_rangesToSkip; - byte *m_begin; - size_t m_length; -}; - -//! _ -class CRYPTOPP_DLL TransparentFilter : public MeterFilter -{ -public: - TransparentFilter(BufferedTransformation *attachment=NULL) : MeterFilter(attachment, true) {} -}; - -//! _ -class CRYPTOPP_DLL OpaqueFilter : public MeterFilter -{ -public: - OpaqueFilter(BufferedTransformation *attachment=NULL) : MeterFilter(attachment, false) {} -}; - -/*! FilterWithBufferedInput divides up the input stream into - a first block, a number of middle blocks, and a last block. - First and last blocks are optional, and middle blocks may - be a stream instead (i.e. blockSize == 1). -*/ -class CRYPTOPP_DLL FilterWithBufferedInput : public Filter -{ -public: - FilterWithBufferedInput(BufferedTransformation *attachment); - //! firstSize and lastSize may be 0, blockSize must be at least 1 - FilterWithBufferedInput(size_t firstSize, size_t blockSize, size_t lastSize, BufferedTransformation *attachment); - - void IsolatedInitialize(const NameValuePairs ¶meters); - size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking) - { - return PutMaybeModifiable(const_cast(inString), length, messageEnd, blocking, false); - } - size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking) - { - return PutMaybeModifiable(inString, length, messageEnd, blocking, true); - } - /*! calls ForceNextPut() if hardFlush is true */ - bool IsolatedFlush(bool hardFlush, bool blocking); - - /*! The input buffer may contain more than blockSize bytes if lastSize != 0. - ForceNextPut() forces a call to NextPut() if this is the case. - */ - void ForceNextPut(); - -protected: - bool DidFirstPut() {return m_firstInputDone;} - - virtual void InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize) - {InitializeDerived(parameters);} - virtual void InitializeDerived(const NameValuePairs ¶meters) {} - // FirstPut() is called if (firstSize != 0 and totalLength >= firstSize) - // or (firstSize == 0 and (totalLength > 0 or a MessageEnd() is received)) - virtual void FirstPut(const byte *inString) =0; - // NextPut() is called if totalLength >= firstSize+blockSize+lastSize - virtual void NextPutSingle(const byte *inString) {assert(false);} - // Same as NextPut() except length can be a multiple of blockSize - // Either NextPut() or NextPutMultiple() must be overriden - virtual void NextPutMultiple(const byte *inString, size_t length); - // Same as NextPutMultiple(), but inString can be modified - virtual void NextPutModifiable(byte *inString, size_t length) - {NextPutMultiple(inString, length);} - // LastPut() is always called - // if totalLength < firstSize then length == totalLength - // else if totalLength <= firstSize+lastSize then length == totalLength-firstSize - // else lastSize <= length < lastSize+blockSize - virtual void LastPut(const byte *inString, size_t length) =0; - virtual void FlushDerived() {} - -protected: - size_t PutMaybeModifiable(byte *begin, size_t length, int messageEnd, bool blocking, bool modifiable); - void NextPutMaybeModifiable(byte *inString, size_t length, bool modifiable) - { - if (modifiable) NextPutModifiable(inString, length); - else NextPutMultiple(inString, length); - } - - // This function should no longer be used, put this here to cause a compiler error - // if someone tries to override NextPut(). - virtual int NextPut(const byte *inString, size_t length) {assert(false); return 0;} - - class BlockQueue - { - public: - void ResetQueue(size_t blockSize, size_t maxBlocks); - byte *GetBlock(); - byte *GetContigousBlocks(size_t &numberOfBytes); - size_t GetAll(byte *outString); - void Put(const byte *inString, size_t length); - size_t CurrentSize() const {return m_size;} - size_t MaxSize() const {return m_buffer.size();} - - private: - SecByteBlock m_buffer; - size_t m_blockSize, m_maxBlocks, m_size; - byte *m_begin; - }; - - size_t m_firstSize, m_blockSize, m_lastSize; - bool m_firstInputDone; - BlockQueue m_queue; -}; - -//! _ -class CRYPTOPP_DLL FilterWithInputQueue : public Filter -{ -public: - FilterWithInputQueue(BufferedTransformation *attachment=NULL) : Filter(attachment) {} - - size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking) - { - if (!blocking) - throw BlockingInputOnly("FilterWithInputQueue"); - - m_inQueue.Put(inString, length); - if (messageEnd) - { - IsolatedMessageEnd(blocking); - Output(0, NULL, 0, messageEnd, blocking); - } - return 0; - } - -protected: - virtual bool IsolatedMessageEnd(bool blocking) =0; - void IsolatedInitialize(const NameValuePairs ¶meters) {m_inQueue.Clear();} - - ByteQueue m_inQueue; -}; - -struct BlockPaddingSchemeDef -{ - enum BlockPaddingScheme {NO_PADDING, ZEROS_PADDING, PKCS_PADDING, ONE_AND_ZEROS_PADDING, DEFAULT_PADDING}; -}; - -//! Filter Wrapper for StreamTransformation, optionally handling padding/unpadding when needed -class CRYPTOPP_DLL StreamTransformationFilter : public FilterWithBufferedInput, public BlockPaddingSchemeDef, private FilterPutSpaceHelper -{ -public: - /*! DEFAULT_PADDING means PKCS_PADDING if c.MandatoryBlockSize() > 1 && c.MinLastBlockSize() == 0 (e.g. ECB or CBC mode), - otherwise NO_PADDING (OFB, CFB, CTR, CBC-CTS modes). - See http://www.weidai.com/scan-mirror/csp.html for details of the padding schemes. */ - StreamTransformationFilter(StreamTransformation &c, BufferedTransformation *attachment = NULL, BlockPaddingScheme padding = DEFAULT_PADDING, bool allowAuthenticatedSymmetricCipher = false); - - std::string AlgorithmName() const {return m_cipher.AlgorithmName();} - -protected: - void InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize); - void FirstPut(const byte *inString); - void NextPutMultiple(const byte *inString, size_t length); - void NextPutModifiable(byte *inString, size_t length); - void LastPut(const byte *inString, size_t length); - - static size_t LastBlockSize(StreamTransformation &c, BlockPaddingScheme padding); - - StreamTransformation &m_cipher; - BlockPaddingScheme m_padding; - unsigned int m_optimalBufferSize; -}; - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY -typedef StreamTransformationFilter StreamCipherFilter; -#endif - -//! Filter Wrapper for HashTransformation -class CRYPTOPP_DLL HashFilter : public Bufferless, private FilterPutSpaceHelper -{ -public: - HashFilter(HashTransformation &hm, BufferedTransformation *attachment = NULL, bool putMessage=false, int truncatedDigestSize=-1, const std::string &messagePutChannel=DEFAULT_CHANNEL, const std::string &hashPutChannel=DEFAULT_CHANNEL); - - std::string AlgorithmName() const {return m_hashModule.AlgorithmName();} - void IsolatedInitialize(const NameValuePairs ¶meters); - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking); - byte * CreatePutSpace(size_t &size) {return m_hashModule.CreateUpdateSpace(size);} - -private: - HashTransformation &m_hashModule; - bool m_putMessage; - unsigned int m_digestSize; - byte *m_space; - std::string m_messagePutChannel, m_hashPutChannel; -}; - -//! Filter Wrapper for HashTransformation -class CRYPTOPP_DLL HashVerificationFilter : public FilterWithBufferedInput -{ -public: - class HashVerificationFailed : public Exception - { - public: - HashVerificationFailed() - : Exception(DATA_INTEGRITY_CHECK_FAILED, "HashVerificationFilter: message hash or MAC not valid") {} - }; - - enum Flags {HASH_AT_END=0, HASH_AT_BEGIN=1, PUT_MESSAGE=2, PUT_HASH=4, PUT_RESULT=8, THROW_EXCEPTION=16, DEFAULT_FLAGS = HASH_AT_BEGIN | PUT_RESULT}; - HashVerificationFilter(HashTransformation &hm, BufferedTransformation *attachment = NULL, word32 flags = DEFAULT_FLAGS, int truncatedDigestSize=-1); - - std::string AlgorithmName() const {return m_hashModule.AlgorithmName();} - bool GetLastResult() const {return m_verified;} - -protected: - void InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize); - void FirstPut(const byte *inString); - void NextPutMultiple(const byte *inString, size_t length); - void LastPut(const byte *inString, size_t length); - -private: - friend class AuthenticatedDecryptionFilter; - - HashTransformation &m_hashModule; - word32 m_flags; - unsigned int m_digestSize; - bool m_verified; - SecByteBlock m_expectedHash; -}; - -typedef HashVerificationFilter HashVerifier; // for backwards compatibility - -//! Filter wrapper for encrypting with AuthenticatedSymmetricCipher, optionally handling padding/unpadding when needed -/*! Additional authenticated data should be given in channel "AAD". If putAAD is true, AAD will be Put() to the attached BufferedTransformation in channel "AAD". */ -class CRYPTOPP_DLL AuthenticatedEncryptionFilter : public StreamTransformationFilter -{ -public: - /*! See StreamTransformationFilter for documentation on BlockPaddingScheme */ - AuthenticatedEncryptionFilter(AuthenticatedSymmetricCipher &c, BufferedTransformation *attachment = NULL, bool putAAD=false, int truncatedDigestSize=-1, const std::string &macChannel=DEFAULT_CHANNEL, BlockPaddingScheme padding = DEFAULT_PADDING); - - void IsolatedInitialize(const NameValuePairs ¶meters); - byte * ChannelCreatePutSpace(const std::string &channel, size_t &size); - size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking); - void LastPut(const byte *inString, size_t length); - -protected: - HashFilter m_hf; -}; - -//! Filter wrapper for decrypting with AuthenticatedSymmetricCipher, optionally handling padding/unpadding when needed -/*! Additional authenticated data should be given in channel "AAD". */ -class CRYPTOPP_DLL AuthenticatedDecryptionFilter : public FilterWithBufferedInput, public BlockPaddingSchemeDef -{ -public: - enum Flags {MAC_AT_END=0, MAC_AT_BEGIN=1, THROW_EXCEPTION=16, DEFAULT_FLAGS = THROW_EXCEPTION}; - - /*! See StreamTransformationFilter for documentation on BlockPaddingScheme */ - AuthenticatedDecryptionFilter(AuthenticatedSymmetricCipher &c, BufferedTransformation *attachment = NULL, word32 flags = DEFAULT_FLAGS, int truncatedDigestSize=-1, BlockPaddingScheme padding = DEFAULT_PADDING); - - std::string AlgorithmName() const {return m_hashVerifier.AlgorithmName();} - byte * ChannelCreatePutSpace(const std::string &channel, size_t &size); - size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking); - bool GetLastResult() const {return m_hashVerifier.GetLastResult();} - -protected: - void InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize); - void FirstPut(const byte *inString); - void NextPutMultiple(const byte *inString, size_t length); - void LastPut(const byte *inString, size_t length); - - HashVerificationFilter m_hashVerifier; - StreamTransformationFilter m_streamFilter; -}; - -//! Filter Wrapper for PK_Signer -class CRYPTOPP_DLL SignerFilter : public Unflushable -{ -public: - SignerFilter(RandomNumberGenerator &rng, const PK_Signer &signer, BufferedTransformation *attachment = NULL, bool putMessage=false) - : m_rng(rng), m_signer(signer), m_messageAccumulator(signer.NewSignatureAccumulator(rng)), m_putMessage(putMessage) {Detach(attachment);} - - std::string AlgorithmName() const {return m_signer.AlgorithmName();} - - void IsolatedInitialize(const NameValuePairs ¶meters); - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking); - -private: - RandomNumberGenerator &m_rng; - const PK_Signer &m_signer; - member_ptr m_messageAccumulator; - bool m_putMessage; - SecByteBlock m_buf; -}; - -//! Filter Wrapper for PK_Verifier -class CRYPTOPP_DLL SignatureVerificationFilter : public FilterWithBufferedInput -{ -public: - class SignatureVerificationFailed : public Exception - { - public: - SignatureVerificationFailed() - : Exception(DATA_INTEGRITY_CHECK_FAILED, "VerifierFilter: digital signature not valid") {} - }; - - enum Flags {SIGNATURE_AT_END=0, SIGNATURE_AT_BEGIN=1, PUT_MESSAGE=2, PUT_SIGNATURE=4, PUT_RESULT=8, THROW_EXCEPTION=16, DEFAULT_FLAGS = SIGNATURE_AT_BEGIN | PUT_RESULT}; - SignatureVerificationFilter(const PK_Verifier &verifier, BufferedTransformation *attachment = NULL, word32 flags = DEFAULT_FLAGS); - - std::string AlgorithmName() const {return m_verifier.AlgorithmName();} - - bool GetLastResult() const {return m_verified;} - -protected: - void InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize); - void FirstPut(const byte *inString); - void NextPutMultiple(const byte *inString, size_t length); - void LastPut(const byte *inString, size_t length); - -private: - const PK_Verifier &m_verifier; - member_ptr m_messageAccumulator; - word32 m_flags; - SecByteBlock m_signature; - bool m_verified; -}; - -typedef SignatureVerificationFilter VerifierFilter; // for backwards compatibility - -//! Redirect input to another BufferedTransformation without owning it -class CRYPTOPP_DLL Redirector : public CustomSignalPropagation -{ -public: - enum Behavior - { - DATA_ONLY = 0x00, - PASS_SIGNALS = 0x01, - PASS_WAIT_OBJECTS = 0x02, - PASS_EVERYTHING = PASS_SIGNALS | PASS_WAIT_OBJECTS - }; - - Redirector() : m_target(NULL), m_behavior(PASS_EVERYTHING) {} - Redirector(BufferedTransformation &target, Behavior behavior=PASS_EVERYTHING) - : m_target(&target), m_behavior(behavior) {} - - void Redirect(BufferedTransformation &target) {m_target = ⌖} - void StopRedirection() {m_target = NULL;} - - Behavior GetBehavior() {return (Behavior) m_behavior;} - void SetBehavior(Behavior behavior) {m_behavior=behavior;} - bool GetPassSignals() const {return (m_behavior & PASS_SIGNALS) != 0;} - void SetPassSignals(bool pass) { if (pass) m_behavior |= PASS_SIGNALS; else m_behavior &= ~(word32) PASS_SIGNALS; } - bool GetPassWaitObjects() const {return (m_behavior & PASS_WAIT_OBJECTS) != 0;} - void SetPassWaitObjects(bool pass) { if (pass) m_behavior |= PASS_WAIT_OBJECTS; else m_behavior &= ~(word32) PASS_WAIT_OBJECTS; } - - bool CanModifyInput() const - {return m_target ? m_target->CanModifyInput() : false;} - - void Initialize(const NameValuePairs ¶meters, int propagation); - byte * CreatePutSpace(size_t &size) - {return m_target ? m_target->CreatePutSpace(size) : (byte *)(size=0, NULL);} - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking) - {return m_target ? m_target->Put2(begin, length, GetPassSignals() ? messageEnd : 0, blocking) : 0;} - bool Flush(bool hardFlush, int propagation=-1, bool blocking=true) - {return m_target && GetPassSignals() ? m_target->Flush(hardFlush, propagation, blocking) : false;} - bool MessageSeriesEnd(int propagation=-1, bool blocking=true) - {return m_target && GetPassSignals() ? m_target->MessageSeriesEnd(propagation, blocking) : false;} - - byte * ChannelCreatePutSpace(const std::string &channel, size_t &size) - {return m_target ? m_target->ChannelCreatePutSpace(channel, size) : (byte *)(size=0, NULL);} - size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking) - {return m_target ? m_target->ChannelPut2(channel, begin, length, GetPassSignals() ? messageEnd : 0, blocking) : 0;} - size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking) - {return m_target ? m_target->ChannelPutModifiable2(channel, begin, length, GetPassSignals() ? messageEnd : 0, blocking) : 0;} - bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true) - {return m_target && GetPassSignals() ? m_target->ChannelFlush(channel, completeFlush, propagation, blocking) : false;} - bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true) - {return m_target && GetPassSignals() ? m_target->ChannelMessageSeriesEnd(channel, propagation, blocking) : false;} - - unsigned int GetMaxWaitObjectCount() const - { return m_target && GetPassWaitObjects() ? m_target->GetMaxWaitObjectCount() : 0; } - void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) - { if (m_target && GetPassWaitObjects()) m_target->GetWaitObjects(container, callStack); } - -private: - BufferedTransformation *m_target; - word32 m_behavior; -}; - -// Used By ProxyFilter -class CRYPTOPP_DLL OutputProxy : public CustomSignalPropagation -{ -public: - OutputProxy(BufferedTransformation &owner, bool passSignal) : m_owner(owner), m_passSignal(passSignal) {} - - bool GetPassSignal() const {return m_passSignal;} - void SetPassSignal(bool passSignal) {m_passSignal = passSignal;} - - byte * CreatePutSpace(size_t &size) - {return m_owner.AttachedTransformation()->CreatePutSpace(size);} - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking) - {return m_owner.AttachedTransformation()->Put2(begin, length, m_passSignal ? messageEnd : 0, blocking);} - size_t PutModifiable2(byte *begin, size_t length, int messageEnd, bool blocking) - {return m_owner.AttachedTransformation()->PutModifiable2(begin, length, m_passSignal ? messageEnd : 0, blocking);} - void Initialize(const NameValuePairs ¶meters=g_nullNameValuePairs, int propagation=-1) - {if (m_passSignal) m_owner.AttachedTransformation()->Initialize(parameters, propagation);} - bool Flush(bool hardFlush, int propagation=-1, bool blocking=true) - {return m_passSignal ? m_owner.AttachedTransformation()->Flush(hardFlush, propagation, blocking) : false;} - bool MessageSeriesEnd(int propagation=-1, bool blocking=true) - {return m_passSignal ? m_owner.AttachedTransformation()->MessageSeriesEnd(propagation, blocking) : false;} - - byte * ChannelCreatePutSpace(const std::string &channel, size_t &size) - {return m_owner.AttachedTransformation()->ChannelCreatePutSpace(channel, size);} - size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking) - {return m_owner.AttachedTransformation()->ChannelPut2(channel, begin, length, m_passSignal ? messageEnd : 0, blocking);} - size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking) - {return m_owner.AttachedTransformation()->ChannelPutModifiable2(channel, begin, length, m_passSignal ? messageEnd : 0, blocking);} - bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true) - {return m_passSignal ? m_owner.AttachedTransformation()->ChannelFlush(channel, completeFlush, propagation, blocking) : false;} - bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true) - {return m_passSignal ? m_owner.AttachedTransformation()->ChannelMessageSeriesEnd(channel, propagation, blocking) : false;} - -private: - BufferedTransformation &m_owner; - bool m_passSignal; -}; - -//! Base class for Filter classes that are proxies for a chain of other filters. -class CRYPTOPP_DLL ProxyFilter : public FilterWithBufferedInput -{ -public: - ProxyFilter(BufferedTransformation *filter, size_t firstSize, size_t lastSize, BufferedTransformation *attachment); - - bool IsolatedFlush(bool hardFlush, bool blocking); - - void SetFilter(Filter *filter); - void NextPutMultiple(const byte *s, size_t len); - void NextPutModifiable(byte *inString, size_t length); - -protected: - member_ptr m_filter; -}; - -//! simple proxy filter that doesn't modify the underlying filter's input or output -class CRYPTOPP_DLL SimpleProxyFilter : public ProxyFilter -{ -public: - SimpleProxyFilter(BufferedTransformation *filter, BufferedTransformation *attachment) - : ProxyFilter(filter, 0, 0, attachment) {} - - void FirstPut(const byte *) {} - void LastPut(const byte *, size_t) {m_filter->MessageEnd();} -}; - -//! proxy for the filter created by PK_Encryptor::CreateEncryptionFilter -/*! This class is here just to provide symmetry with VerifierFilter. */ -class CRYPTOPP_DLL PK_EncryptorFilter : public SimpleProxyFilter -{ -public: - PK_EncryptorFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment = NULL) - : SimpleProxyFilter(encryptor.CreateEncryptionFilter(rng), attachment) {} -}; - -//! proxy for the filter created by PK_Decryptor::CreateDecryptionFilter -/*! This class is here just to provide symmetry with SignerFilter. */ -class CRYPTOPP_DLL PK_DecryptorFilter : public SimpleProxyFilter -{ -public: - PK_DecryptorFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment = NULL) - : SimpleProxyFilter(decryptor.CreateDecryptionFilter(rng), attachment) {} -}; - -//! Append input to a string object -template -class StringSinkTemplate : public Bufferless -{ -public: - // VC60 workaround: no T::char_type - typedef typename T::traits_type::char_type char_type; - - StringSinkTemplate(T &output) - : m_output(&output) {assert(sizeof(output[0])==1);} - - void IsolatedInitialize(const NameValuePairs ¶meters) - {if (!parameters.GetValue("OutputStringPointer", m_output)) throw InvalidArgument("StringSink: OutputStringPointer not specified");} - - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking) - { - if (length > 0) - { - typename T::size_type size = m_output->size(); - if (length < size && size + length > m_output->capacity()) - m_output->reserve(2*size); - m_output->append((const char_type *)begin, (const char_type *)begin+length); - } - return 0; - } - -private: - T *m_output; -}; - -//! Append input to an std::string -CRYPTOPP_DLL_TEMPLATE_CLASS StringSinkTemplate; -typedef StringSinkTemplate StringSink; - -//! incorporates input into RNG as additional entropy -class RandomNumberSink : public Bufferless -{ -public: - RandomNumberSink() - : m_rng(NULL) {} - - RandomNumberSink(RandomNumberGenerator &rng) - : m_rng(&rng) {} - - void IsolatedInitialize(const NameValuePairs ¶meters); - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking); - -private: - RandomNumberGenerator *m_rng; -}; - -//! Copy input to a memory buffer -class CRYPTOPP_DLL ArraySink : public Bufferless -{ -public: - ArraySink(const NameValuePairs ¶meters = g_nullNameValuePairs) {IsolatedInitialize(parameters);} - ArraySink(byte *buf, size_t size) : m_buf(buf), m_size(size), m_total(0) {} - - size_t AvailableSize() {return SaturatingSubtract(m_size, m_total);} - lword TotalPutLength() {return m_total;} - - void IsolatedInitialize(const NameValuePairs ¶meters); - byte * CreatePutSpace(size_t &size); - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking); - -protected: - byte *m_buf; - size_t m_size; - lword m_total; -}; - -//! Xor input to a memory buffer -class CRYPTOPP_DLL ArrayXorSink : public ArraySink -{ -public: - ArrayXorSink(byte *buf, size_t size) - : ArraySink(buf, size) {} - - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking); - byte * CreatePutSpace(size_t &size) {return BufferedTransformation::CreatePutSpace(size);} -}; - -//! string-based implementation of Store interface -class StringStore : public Store -{ -public: - StringStore(const char *string = NULL) - {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string)));} - StringStore(const byte *string, size_t length) - {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string, length)));} - template StringStore(const T &string) - {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string)));} - - CRYPTOPP_DLL size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - CRYPTOPP_DLL size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const; - -private: - CRYPTOPP_DLL void StoreInitialize(const NameValuePairs ¶meters); - - const byte *m_store; - size_t m_length, m_count; -}; - -//! RNG-based implementation of Source interface -class CRYPTOPP_DLL RandomNumberStore : public Store -{ -public: - RandomNumberStore() - : m_rng(NULL), m_length(0), m_count(0) {} - - RandomNumberStore(RandomNumberGenerator &rng, lword length) - : m_rng(&rng), m_length(length), m_count(0) {} - - bool AnyRetrievable() const {return MaxRetrievable() != 0;} - lword MaxRetrievable() const {return m_length-m_count;} - - size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const - { - throw NotImplemented("RandomNumberStore: CopyRangeTo2() is not supported by this store"); - } - -private: - void StoreInitialize(const NameValuePairs ¶meters); - - RandomNumberGenerator *m_rng; - lword m_length, m_count; -}; - -//! empty store -class CRYPTOPP_DLL NullStore : public Store -{ -public: - NullStore(lword size = ULONG_MAX) : m_size(size) {} - void StoreInitialize(const NameValuePairs ¶meters) {} - lword MaxRetrievable() const {return m_size;} - size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const; - -private: - lword m_size; -}; - -//! A Filter that pumps data into its attachment as input -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Source : public InputRejecting -{ -public: - Source(BufferedTransformation *attachment = NULL) - {Source::Detach(attachment);} - - lword Pump(lword pumpMax=size_t(0)-1) - {Pump2(pumpMax); return pumpMax;} - unsigned int PumpMessages(unsigned int count=UINT_MAX) - {PumpMessages2(count); return count;} - void PumpAll() - {PumpAll2();} - virtual size_t Pump2(lword &byteCount, bool blocking=true) =0; - virtual size_t PumpMessages2(unsigned int &messageCount, bool blocking=true) =0; - virtual size_t PumpAll2(bool blocking=true); - virtual bool SourceExhausted() const =0; - -protected: - void SourceInitialize(bool pumpAll, const NameValuePairs ¶meters) - { - IsolatedInitialize(parameters); - if (pumpAll) - PumpAll(); - } -}; - -//! Turn a Store into a Source -template -class SourceTemplate : public Source -{ -public: - SourceTemplate(BufferedTransformation *attachment) - : Source(attachment) {} - void IsolatedInitialize(const NameValuePairs ¶meters) - {m_store.IsolatedInitialize(parameters);} - size_t Pump2(lword &byteCount, bool blocking=true) - {return m_store.TransferTo2(*AttachedTransformation(), byteCount, DEFAULT_CHANNEL, blocking);} - size_t PumpMessages2(unsigned int &messageCount, bool blocking=true) - {return m_store.TransferMessagesTo2(*AttachedTransformation(), messageCount, DEFAULT_CHANNEL, blocking);} - size_t PumpAll2(bool blocking=true) - {return m_store.TransferAllTo2(*AttachedTransformation(), DEFAULT_CHANNEL, blocking);} - bool SourceExhausted() const - {return !m_store.AnyRetrievable() && !m_store.AnyMessages();} - void SetAutoSignalPropagation(int propagation) - {m_store.SetAutoSignalPropagation(propagation);} - int GetAutoSignalPropagation() const - {return m_store.GetAutoSignalPropagation();} - -protected: - T m_store; -}; - -//! string-based implementation of Source interface -class CRYPTOPP_DLL StringSource : public SourceTemplate -{ -public: - StringSource(BufferedTransformation *attachment = NULL) - : SourceTemplate(attachment) {} - //! zero terminated string as source - StringSource(const char *string, bool pumpAll, BufferedTransformation *attachment = NULL) - : SourceTemplate(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string)));} - //! binary byte array as source - StringSource(const byte *string, size_t length, bool pumpAll, BufferedTransformation *attachment = NULL) - : SourceTemplate(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string, length)));} - //! std::string as source - StringSource(const std::string &string, bool pumpAll, BufferedTransformation *attachment = NULL) - : SourceTemplate(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string)));} -}; - -//! use the third constructor for an array source -typedef StringSource ArraySource; - -//! RNG-based implementation of Source interface -class CRYPTOPP_DLL RandomNumberSource : public SourceTemplate -{ -public: - RandomNumberSource(RandomNumberGenerator &rng, int length, bool pumpAll, BufferedTransformation *attachment = NULL) - : SourceTemplate(attachment) - {SourceInitialize(pumpAll, MakeParameters("RandomNumberGeneratorPointer", &rng)("RandomNumberStoreSize", length));} -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/fips140.cpp b/lib/cryptopp/fips140.cpp deleted file mode 100644 index 1fcf59014..000000000 --- a/lib/cryptopp/fips140.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// fips140.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "fips140.h" -#include "trdlocal.h" // needs to be included last for cygwin - -NAMESPACE_BEGIN(CryptoPP) - -// Define this to 1 to turn on FIPS 140-2 compliance features, including additional tests during -// startup, random number generation, and key generation. These tests may affect performance. -#ifndef CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 -#define CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 0 -#endif - -#if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(THREADS_AVAILABLE)) -#error FIPS 140-2 compliance requires the availability of thread local storage. -#endif - -#if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(OS_RNG_AVAILABLE)) -#error FIPS 140-2 compliance requires the availability of OS provided RNG. -#endif - -PowerUpSelfTestStatus g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_NOT_DONE; - -bool FIPS_140_2_ComplianceEnabled() -{ - return CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2; -} - -void SimulatePowerUpSelfTestFailure() -{ - g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_FAILED; -} - -PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus() -{ - return g_powerUpSelfTestStatus; -} - -#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 -ThreadLocalStorage & AccessPowerUpSelfTestInProgress() -{ - static ThreadLocalStorage selfTestInProgress; - return selfTestInProgress; -} -#endif - -bool PowerUpSelfTestInProgressOnThisThread() -{ -#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 - return AccessPowerUpSelfTestInProgress().GetValue() != NULL; -#else - assert(false); // should not be called - return false; -#endif -} - -void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress) -{ -#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 - AccessPowerUpSelfTestInProgress().SetValue((void *)inProgress); -#endif -} - -void EncryptionPairwiseConsistencyTest_FIPS_140_Only(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor) -{ -#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 - EncryptionPairwiseConsistencyTest(encryptor, decryptor); -#endif -} - -void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, const PK_Verifier &verifier) -{ -#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 - SignaturePairwiseConsistencyTest(signer, verifier); -#endif -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/fips140.h b/lib/cryptopp/fips140.h deleted file mode 100644 index a3e538613..000000000 --- a/lib/cryptopp/fips140.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef CRYPTOPP_FIPS140_H -#define CRYPTOPP_FIPS140_H - -/*! \file - FIPS 140 related functions and classes. -*/ - -#include "cryptlib.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! exception thrown when a crypto algorithm is used after a self test fails -class CRYPTOPP_DLL SelfTestFailure : public Exception -{ -public: - explicit SelfTestFailure(const std::string &s) : Exception(OTHER_ERROR, s) {} -}; - -//! returns whether FIPS 140-2 compliance features were enabled at compile time -CRYPTOPP_DLL bool CRYPTOPP_API FIPS_140_2_ComplianceEnabled(); - -//! enum values representing status of the power-up self test -enum PowerUpSelfTestStatus {POWER_UP_SELF_TEST_NOT_DONE, POWER_UP_SELF_TEST_FAILED, POWER_UP_SELF_TEST_PASSED}; - -//! perform the power-up self test, and set the self test status -CRYPTOPP_DLL void CRYPTOPP_API DoPowerUpSelfTest(const char *moduleFilename, const byte *expectedModuleMac); - -//! perform the power-up self test using the filename of this DLL and the embedded module MAC -CRYPTOPP_DLL void CRYPTOPP_API DoDllPowerUpSelfTest(); - -//! set the power-up self test status to POWER_UP_SELF_TEST_FAILED -CRYPTOPP_DLL void CRYPTOPP_API SimulatePowerUpSelfTestFailure(); - -//! return the current power-up self test status -CRYPTOPP_DLL PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus(); - -typedef PowerUpSelfTestStatus (CRYPTOPP_API * PGetPowerUpSelfTestStatus)(); - -CRYPTOPP_DLL MessageAuthenticationCode * CRYPTOPP_API NewIntegrityCheckingMAC(); - -CRYPTOPP_DLL bool CRYPTOPP_API IntegrityCheckModule(const char *moduleFilename, const byte *expectedModuleMac, SecByteBlock *pActualMac = NULL, unsigned long *pMacFileLocation = NULL); - -// this is used by Algorithm constructor to allow Algorithm objects to be constructed for the self test -bool PowerUpSelfTestInProgressOnThisThread(); - -void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress); - -void SignaturePairwiseConsistencyTest(const PK_Signer &signer, const PK_Verifier &verifier); -void EncryptionPairwiseConsistencyTest(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor); - -void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, const PK_Verifier &verifier); -void EncryptionPairwiseConsistencyTest_FIPS_140_Only(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor); - -#define CRYPTOPP_DUMMY_DLL_MAC "MAC_51f34b8db820ae8" - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/fltrimpl.h b/lib/cryptopp/fltrimpl.h deleted file mode 100644 index 4087d7d9f..000000000 --- a/lib/cryptopp/fltrimpl.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef CRYPTOPP_FLTRIMPL_H -#define CRYPTOPP_FLTRIMPL_H - -#define FILTER_BEGIN \ - switch (m_continueAt) \ - { \ - case 0: \ - m_inputPosition = 0; - -#define FILTER_END_NO_MESSAGE_END_NO_RETURN \ - break; \ - default: \ - assert(false); \ - } - -#define FILTER_END_NO_MESSAGE_END \ - FILTER_END_NO_MESSAGE_END_NO_RETURN \ - return 0; - -/* -#define FILTER_END \ - case -1: \ - if (messageEnd && Output(-1, NULL, 0, messageEnd, blocking)) \ - return 1; \ - FILTER_END_NO_MESSAGE_END -*/ - -#define FILTER_OUTPUT3(site, statement, output, length, messageEnd, channel) \ - {\ - case site: \ - statement; \ - if (Output(site, output, length, messageEnd, blocking, channel)) \ - return STDMAX(size_t(1), length-m_inputPosition);\ - } - -#define FILTER_OUTPUT2(site, statement, output, length, messageEnd) \ - FILTER_OUTPUT3(site, statement, output, length, messageEnd, DEFAULT_CHANNEL) - -#define FILTER_OUTPUT(site, output, length, messageEnd) \ - FILTER_OUTPUT2(site, 0, output, length, messageEnd) - -#define FILTER_OUTPUT_BYTE(site, output) \ - FILTER_OUTPUT(site, &(const byte &)(byte)output, 1, 0) - -#define FILTER_OUTPUT2_MODIFIABLE(site, statement, output, length, messageEnd) \ - {\ - case site: \ - statement; \ - if (OutputModifiable(site, output, length, messageEnd, blocking)) \ - return STDMAX(size_t(1), length-m_inputPosition);\ - } - -#define FILTER_OUTPUT_MODIFIABLE(site, output, length, messageEnd) \ - FILTER_OUTPUT2_MODIFIABLE(site, 0, output, length, messageEnd) - -#define FILTER_OUTPUT2_MAYBE_MODIFIABLE(site, statement, output, length, messageEnd, modifiable) \ - {\ - case site: \ - statement; \ - if (modifiable ? OutputModifiable(site, output, length, messageEnd, blocking) : Output(site, output, length, messageEnd, blocking)) \ - return STDMAX(size_t(1), length-m_inputPosition);\ - } - -#define FILTER_OUTPUT_MAYBE_MODIFIABLE(site, output, length, messageEnd, modifiable) \ - FILTER_OUTPUT2_MAYBE_MODIFIABLE(site, 0, output, length, messageEnd, modifiable) - -#endif diff --git a/lib/cryptopp/gcm.cpp b/lib/cryptopp/gcm.cpp deleted file mode 100644 index 2304f96d8..000000000 --- a/lib/cryptopp/gcm.cpp +++ /dev/null @@ -1,828 +0,0 @@ -// gcm.cpp - written and placed in the public domain by Wei Dai - -// use "cl /EP /P /DCRYPTOPP_GENERATE_X64_MASM gcm.cpp" to generate MASM code - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS -#ifndef CRYPTOPP_GENERATE_X64_MASM - -#include "gcm.h" -#include "cpu.h" - -NAMESPACE_BEGIN(CryptoPP) - -word16 GCM_Base::s_reductionTable[256]; -volatile bool GCM_Base::s_reductionTableInitialized = false; - -void GCM_Base::GCTR::IncrementCounterBy256() -{ - IncrementCounterByOne(m_counterArray+BlockSize()-4, 3); -} - -#if 0 -// preserved for testing -void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *c) -{ - word64 Z0=0, Z1=0, V0, V1; - - typedef BlockGetAndPut Block; - Block::Get(a)(V0)(V1); - - for (int i=0; i<16; i++) - { - for (int j=0x80; j!=0; j>>=1) - { - int x = b[i] & j; - Z0 ^= x ? V0 : 0; - Z1 ^= x ? V1 : 0; - x = (int)V1 & 1; - V1 = (V1>>1) | (V0<<63); - V0 = (V0>>1) ^ (x ? W64LIT(0xe1) << 56 : 0); - } - } - Block::Put(NULL, c)(Z0)(Z1); -} - -__m128i _mm_clmulepi64_si128(const __m128i &a, const __m128i &b, int i) -{ - word64 A[1] = {ByteReverse(((word64*)&a)[i&1])}; - word64 B[1] = {ByteReverse(((word64*)&b)[i>>4])}; - - PolynomialMod2 pa((byte *)A, 8); - PolynomialMod2 pb((byte *)B, 8); - PolynomialMod2 c = pa*pb; - - __m128i output; - for (int i=0; i<16; i++) - ((byte *)&output)[i] = c.GetByte(i); - return output; -} -#endif - -#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE || CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE -inline static void SSE2_Xor16(byte *a, const byte *b, const byte *c) -{ -#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE - *(__m128i *)a = _mm_xor_si128(*(__m128i *)b, *(__m128i *)c); -#else - asm ("movdqa %1, %%xmm0; pxor %2, %%xmm0; movdqa %%xmm0, %0;" : "=m" (a[0]) : "m"(b[0]), "m"(c[0])); -#endif -} -#endif - -inline static void Xor16(byte *a, const byte *b, const byte *c) -{ - ((word64 *)a)[0] = ((word64 *)b)[0] ^ ((word64 *)c)[0]; - ((word64 *)a)[1] = ((word64 *)b)[1] ^ ((word64 *)c)[1]; -} - -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE -static CRYPTOPP_ALIGN_DATA(16) const word64 s_clmulConstants64[] = { - W64LIT(0xe100000000000000), W64LIT(0xc200000000000000), - W64LIT(0x08090a0b0c0d0e0f), W64LIT(0x0001020304050607), - W64LIT(0x0001020304050607), W64LIT(0x08090a0b0c0d0e0f)}; -static const __m128i *s_clmulConstants = (const __m128i *)s_clmulConstants64; -static const unsigned int s_clmulTableSizeInBlocks = 8; - -inline __m128i CLMUL_Reduce(__m128i c0, __m128i c1, __m128i c2, const __m128i &r) -{ - /* - The polynomial to be reduced is c0 * x^128 + c1 * x^64 + c2. c0t below refers to the most - significant half of c0 as a polynomial, which, due to GCM's bit reflection, are in the - rightmost bit positions, and the lowest byte addresses. - - c1 ^= c0t * 0xc200000000000000 - c2t ^= c0t - t = shift (c1t ^ c0b) left 1 bit - c2 ^= t * 0xe100000000000000 - c2t ^= c1b - shift c2 left 1 bit and xor in lowest bit of c1t - */ -#if 0 // MSVC 2010 workaround: see http://connect.microsoft.com/VisualStudio/feedback/details/575301 - c2 = _mm_xor_si128(c2, _mm_move_epi64(c0)); -#else - c1 = _mm_xor_si128(c1, _mm_slli_si128(c0, 8)); -#endif - c1 = _mm_xor_si128(c1, _mm_clmulepi64_si128(c0, r, 0x10)); - c0 = _mm_srli_si128(c0, 8); - c0 = _mm_xor_si128(c0, c1); - c0 = _mm_slli_epi64(c0, 1); - c0 = _mm_clmulepi64_si128(c0, r, 0); - c2 = _mm_xor_si128(c2, c0); - c2 = _mm_xor_si128(c2, _mm_srli_si128(c1, 8)); - c1 = _mm_unpacklo_epi64(c1, c2); - c1 = _mm_srli_epi64(c1, 63); - c2 = _mm_slli_epi64(c2, 1); - return _mm_xor_si128(c2, c1); -} - -inline __m128i CLMUL_GF_Mul(const __m128i &x, const __m128i &h, const __m128i &r) -{ - __m128i c0 = _mm_clmulepi64_si128(x,h,0); - __m128i c1 = _mm_xor_si128(_mm_clmulepi64_si128(x,h,1), _mm_clmulepi64_si128(x,h,0x10)); - __m128i c2 = _mm_clmulepi64_si128(x,h,0x11); - - return CLMUL_Reduce(c0, c1, c2, r); -} -#endif - -void GCM_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) -{ - BlockCipher &blockCipher = AccessBlockCipher(); - blockCipher.SetKey(userKey, keylength, params); - - if (blockCipher.BlockSize() != REQUIRED_BLOCKSIZE) - throw InvalidArgument(AlgorithmName() + ": block size of underlying block cipher is not 16"); - - int tableSize, i, j, k; - -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE - if (HasCLMUL()) - { - params.GetIntValue(Name::TableSize(), tableSize); // avoid "parameter not used" error - tableSize = s_clmulTableSizeInBlocks * REQUIRED_BLOCKSIZE; - } - else -#endif - { - if (params.GetIntValue(Name::TableSize(), tableSize)) - tableSize = (tableSize >= 64*1024) ? 64*1024 : 2*1024; - else - tableSize = (GetTablesOption() == GCM_64K_Tables) ? 64*1024 : 2*1024; - -#if defined(_MSC_VER) && (_MSC_VER >= 1300 && _MSC_VER < 1400) - // VC 2003 workaround: compiler generates bad code for 64K tables - tableSize = 2*1024; -#endif - } - - m_buffer.resize(3*REQUIRED_BLOCKSIZE + tableSize); - byte *table = MulTable(); - byte *hashKey = HashKey(); - memset(hashKey, 0, REQUIRED_BLOCKSIZE); - blockCipher.ProcessBlock(hashKey); - -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE - if (HasCLMUL()) - { - const __m128i r = s_clmulConstants[0]; - __m128i h0 = _mm_shuffle_epi8(_mm_load_si128((__m128i *)hashKey), s_clmulConstants[1]); - __m128i h = h0; - - for (i=0; i Block; - Block::Get(hashKey)(V0)(V1); - - if (tableSize == 64*1024) - { - for (i=0; i<128; i++) - { - k = i%8; - Block::Put(NULL, table+(i/8)*256*16+(size_t(1)<<(11-k)))(V0)(V1); - - int x = (int)V1 & 1; - V1 = (V1>>1) | (V0<<63); - V0 = (V0>>1) ^ (x ? W64LIT(0xe1) << 56 : 0); - } - - for (i=0; i<16; i++) - { - memset(table+i*256*16, 0, 16); -#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE || CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE - if (HasSSE2()) - for (j=2; j<=0x80; j*=2) - for (k=1; k>1) | (V0<<63); - V0 = (V0>>1) ^ (x ? W64LIT(0xe1) << 56 : 0); - } - - for (i=0; i<4; i++) - { - memset(table+i*256, 0, 16); - memset(table+1024+i*256, 0, 16); -#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE || CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE - if (HasSSE2()) - for (j=2; j<=8; j*=2) - for (k=1; k= HASH_BLOCKSIZE) - { - len = GCM_Base::AuthenticateBlocks(iv, len); - iv += (origLen - len); - } - - if (len > 0) - { - memcpy(m_buffer, iv, len); - memset(m_buffer+len, 0, HASH_BLOCKSIZE-len); - GCM_Base::AuthenticateBlocks(m_buffer, HASH_BLOCKSIZE); - } - - PutBlock(NULL, m_buffer)(0)(origLen*8); - GCM_Base::AuthenticateBlocks(m_buffer, HASH_BLOCKSIZE); - - ReverseHashBufferIfNeeded(); - } - - if (m_state >= State_IVSet) - m_ctr.Resynchronize(hashBuffer, REQUIRED_BLOCKSIZE); - else - m_ctr.SetCipherWithIV(cipher, hashBuffer); - - m_ctr.Seek(HASH_BLOCKSIZE); - - memset(hashBuffer, 0, HASH_BLOCKSIZE); -} - -unsigned int GCM_Base::OptimalDataAlignment() const -{ - return -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) - HasSSE2() ? 16 : -#endif - GetBlockCipher().OptimalDataAlignment(); -} - -#pragma warning(disable: 4731) // frame pointer register 'ebp' modified by inline assembly code - -#endif // #ifndef CRYPTOPP_GENERATE_X64_MASM - -#ifdef CRYPTOPP_X64_MASM_AVAILABLE -extern "C" { -void GCM_AuthenticateBlocks_2K(const byte *data, size_t blocks, word64 *hashBuffer, const word16 *reductionTable); -void GCM_AuthenticateBlocks_64K(const byte *data, size_t blocks, word64 *hashBuffer); -} -#endif - -#ifndef CRYPTOPP_GENERATE_X64_MASM - -size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len) -{ -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE - if (HasCLMUL()) - { - const __m128i *table = (const __m128i *)MulTable(); - __m128i x = _mm_load_si128((__m128i *)HashBuffer()); - const __m128i r = s_clmulConstants[0], bswapMask = s_clmulConstants[1], bswapMask2 = s_clmulConstants[2]; - - while (len >= 16) - { - size_t s = UnsignedMin(len/16, s_clmulTableSizeInBlocks), i=0; - __m128i d, d2 = _mm_shuffle_epi8(_mm_loadu_si128((const __m128i *)(data+(s-1)*16)), bswapMask2);; - __m128i c0 = _mm_setzero_si128(); - __m128i c1 = _mm_setzero_si128(); - __m128i c2 = _mm_setzero_si128(); - - while (true) - { - __m128i h0 = _mm_load_si128(table+i); - __m128i h1 = _mm_load_si128(table+i+1); - __m128i h01 = _mm_xor_si128(h0, h1); - - if (++i == s) - { - d = _mm_shuffle_epi8(_mm_loadu_si128((const __m128i *)data), bswapMask); - d = _mm_xor_si128(d, x); - c0 = _mm_xor_si128(c0, _mm_clmulepi64_si128(d, h0, 0)); - c2 = _mm_xor_si128(c2, _mm_clmulepi64_si128(d, h1, 1)); - d = _mm_xor_si128(d, _mm_shuffle_epi32(d, _MM_SHUFFLE(1, 0, 3, 2))); - c1 = _mm_xor_si128(c1, _mm_clmulepi64_si128(d, h01, 0)); - break; - } - - d = _mm_shuffle_epi8(_mm_loadu_si128((const __m128i *)(data+(s-i)*16-8)), bswapMask2); - c0 = _mm_xor_si128(c0, _mm_clmulepi64_si128(d2, h0, 1)); - c2 = _mm_xor_si128(c2, _mm_clmulepi64_si128(d, h1, 1)); - d2 = _mm_xor_si128(d2, d); - c1 = _mm_xor_si128(c1, _mm_clmulepi64_si128(d2, h01, 1)); - - if (++i == s) - { - d = _mm_shuffle_epi8(_mm_loadu_si128((const __m128i *)data), bswapMask); - d = _mm_xor_si128(d, x); - c0 = _mm_xor_si128(c0, _mm_clmulepi64_si128(d, h0, 0x10)); - c2 = _mm_xor_si128(c2, _mm_clmulepi64_si128(d, h1, 0x11)); - d = _mm_xor_si128(d, _mm_shuffle_epi32(d, _MM_SHUFFLE(1, 0, 3, 2))); - c1 = _mm_xor_si128(c1, _mm_clmulepi64_si128(d, h01, 0x10)); - break; - } - - d2 = _mm_shuffle_epi8(_mm_loadu_si128((const __m128i *)(data+(s-i)*16-8)), bswapMask); - c0 = _mm_xor_si128(c0, _mm_clmulepi64_si128(d, h0, 0x10)); - c2 = _mm_xor_si128(c2, _mm_clmulepi64_si128(d2, h1, 0x10)); - d = _mm_xor_si128(d, d2); - c1 = _mm_xor_si128(c1, _mm_clmulepi64_si128(d, h01, 0x10)); - } - data += s*16; - len -= s*16; - - c1 = _mm_xor_si128(_mm_xor_si128(c1, c0), c2); - x = CLMUL_Reduce(c0, c1, c2, r); - } - - _mm_store_si128((__m128i *)HashBuffer(), x); - return len; - } -#endif - - typedef BlockGetAndPut Block; - word64 *hashBuffer = (word64 *)HashBuffer(); - - switch (2*(m_buffer.size()>=64*1024) -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) - + HasSSE2() -#endif - ) - { - case 0: // non-SSE2 and 2K tables - { - byte *table = MulTable(); - word64 x0 = hashBuffer[0], x1 = hashBuffer[1]; - - do - { - word64 y0, y1, a0, a1, b0, b1, c0, c1, d0, d1; - Block::Get(data)(y0)(y1); - x0 ^= y0; - x1 ^= y1; - - data += HASH_BLOCKSIZE; - len -= HASH_BLOCKSIZE; - - #define READ_TABLE_WORD64_COMMON(a, b, c, d) *(word64 *)(table+(a*1024)+(b*256)+c+d*8) - - #ifdef IS_LITTLE_ENDIAN - #if CRYPTOPP_BOOL_SLOW_WORD64 - word32 z0 = (word32)x0; - word32 z1 = (word32)(x0>>32); - word32 z2 = (word32)x1; - word32 z3 = (word32)(x1>>32); - #define READ_TABLE_WORD64(a, b, c, d, e) READ_TABLE_WORD64_COMMON((d%2), c, (d?(z##c>>((d?d-1:0)*4))&0xf0:(z##c&0xf)<<4), e) - #else - #define READ_TABLE_WORD64(a, b, c, d, e) READ_TABLE_WORD64_COMMON((d%2), c, ((d+8*b)?(x##a>>(((d+8*b)?(d+8*b)-1:1)*4))&0xf0:(x##a&0xf)<<4), e) - #endif - #define GF_MOST_SIG_8BITS(a) (a##1 >> 7*8) - #define GF_SHIFT_8(a) a##1 = (a##1 << 8) ^ (a##0 >> 7*8); a##0 <<= 8; - #else - #define READ_TABLE_WORD64(a, b, c, d, e) READ_TABLE_WORD64_COMMON((1-d%2), c, ((15-d-8*b)?(x##a>>(((15-d-8*b)?(15-d-8*b)-1:0)*4))&0xf0:(x##a&0xf)<<4), e) - #define GF_MOST_SIG_8BITS(a) (a##1 & 0xff) - #define GF_SHIFT_8(a) a##1 = (a##1 >> 8) ^ (a##0 << 7*8); a##0 >>= 8; - #endif - - #define GF_MUL_32BY128(op, a, b, c) \ - a0 op READ_TABLE_WORD64(a, b, c, 0, 0) ^ READ_TABLE_WORD64(a, b, c, 1, 0);\ - a1 op READ_TABLE_WORD64(a, b, c, 0, 1) ^ READ_TABLE_WORD64(a, b, c, 1, 1);\ - b0 op READ_TABLE_WORD64(a, b, c, 2, 0) ^ READ_TABLE_WORD64(a, b, c, 3, 0);\ - b1 op READ_TABLE_WORD64(a, b, c, 2, 1) ^ READ_TABLE_WORD64(a, b, c, 3, 1);\ - c0 op READ_TABLE_WORD64(a, b, c, 4, 0) ^ READ_TABLE_WORD64(a, b, c, 5, 0);\ - c1 op READ_TABLE_WORD64(a, b, c, 4, 1) ^ READ_TABLE_WORD64(a, b, c, 5, 1);\ - d0 op READ_TABLE_WORD64(a, b, c, 6, 0) ^ READ_TABLE_WORD64(a, b, c, 7, 0);\ - d1 op READ_TABLE_WORD64(a, b, c, 6, 1) ^ READ_TABLE_WORD64(a, b, c, 7, 1);\ - - GF_MUL_32BY128(=, 0, 0, 0) - GF_MUL_32BY128(^=, 0, 1, 1) - GF_MUL_32BY128(^=, 1, 0, 2) - GF_MUL_32BY128(^=, 1, 1, 3) - - word32 r = (word32)s_reductionTable[GF_MOST_SIG_8BITS(d)] << 16; - GF_SHIFT_8(d) - c0 ^= d0; c1 ^= d1; - r ^= (word32)s_reductionTable[GF_MOST_SIG_8BITS(c)] << 8; - GF_SHIFT_8(c) - b0 ^= c0; b1 ^= c1; - r ^= s_reductionTable[GF_MOST_SIG_8BITS(b)]; - GF_SHIFT_8(b) - a0 ^= b0; a1 ^= b1; - a0 ^= ConditionalByteReverse(LITTLE_ENDIAN_ORDER, r); - x0 = a0; x1 = a1; - } - while (len >= HASH_BLOCKSIZE); - - hashBuffer[0] = x0; hashBuffer[1] = x1; - return len; - } - - case 2: // non-SSE2 and 64K tables - { - byte *table = MulTable(); - word64 x0 = hashBuffer[0], x1 = hashBuffer[1]; - - do - { - word64 y0, y1, a0, a1; - Block::Get(data)(y0)(y1); - x0 ^= y0; - x1 ^= y1; - - data += HASH_BLOCKSIZE; - len -= HASH_BLOCKSIZE; - - #undef READ_TABLE_WORD64_COMMON - #undef READ_TABLE_WORD64 - - #define READ_TABLE_WORD64_COMMON(a, c, d) *(word64 *)(table+(a)*256*16+(c)+(d)*8) - - #ifdef IS_LITTLE_ENDIAN - #if CRYPTOPP_BOOL_SLOW_WORD64 - word32 z0 = (word32)x0; - word32 z1 = (word32)(x0>>32); - word32 z2 = (word32)x1; - word32 z3 = (word32)(x1>>32); - #define READ_TABLE_WORD64(b, c, d, e) READ_TABLE_WORD64_COMMON(c*4+d, (d?(z##c>>((d?d:1)*8-4))&0xff0:(z##c&0xff)<<4), e) - #else - #define READ_TABLE_WORD64(b, c, d, e) READ_TABLE_WORD64_COMMON(c*4+d, ((d+4*(c%2))?(x##b>>(((d+4*(c%2))?(d+4*(c%2)):1)*8-4))&0xff0:(x##b&0xff)<<4), e) - #endif - #else - #define READ_TABLE_WORD64(b, c, d, e) READ_TABLE_WORD64_COMMON(c*4+d, ((7-d-4*(c%2))?(x##b>>(((7-d-4*(c%2))?(7-d-4*(c%2)):1)*8-4))&0xff0:(x##b&0xff)<<4), e) - #endif - - #define GF_MUL_8BY128(op, b, c, d) \ - a0 op READ_TABLE_WORD64(b, c, d, 0);\ - a1 op READ_TABLE_WORD64(b, c, d, 1);\ - - GF_MUL_8BY128(=, 0, 0, 0) - GF_MUL_8BY128(^=, 0, 0, 1) - GF_MUL_8BY128(^=, 0, 0, 2) - GF_MUL_8BY128(^=, 0, 0, 3) - GF_MUL_8BY128(^=, 0, 1, 0) - GF_MUL_8BY128(^=, 0, 1, 1) - GF_MUL_8BY128(^=, 0, 1, 2) - GF_MUL_8BY128(^=, 0, 1, 3) - GF_MUL_8BY128(^=, 1, 2, 0) - GF_MUL_8BY128(^=, 1, 2, 1) - GF_MUL_8BY128(^=, 1, 2, 2) - GF_MUL_8BY128(^=, 1, 2, 3) - GF_MUL_8BY128(^=, 1, 3, 0) - GF_MUL_8BY128(^=, 1, 3, 1) - GF_MUL_8BY128(^=, 1, 3, 2) - GF_MUL_8BY128(^=, 1, 3, 3) - - x0 = a0; x1 = a1; - } - while (len >= HASH_BLOCKSIZE); - - hashBuffer[0] = x0; hashBuffer[1] = x1; - return len; - } -#endif // #ifndef CRYPTOPP_GENERATE_X64_MASM - -#ifdef CRYPTOPP_X64_MASM_AVAILABLE - case 1: // SSE2 and 2K tables - GCM_AuthenticateBlocks_2K(data, len/16, hashBuffer, s_reductionTable); - return len % 16; - case 3: // SSE2 and 64K tables - GCM_AuthenticateBlocks_64K(data, len/16, hashBuffer); - return len % 16; -#endif - -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE - case 1: // SSE2 and 2K tables - { - #ifdef __GNUC__ - __asm__ __volatile__ - ( - ".intel_syntax noprefix;" - #elif defined(CRYPTOPP_GENERATE_X64_MASM) - ALIGN 8 - GCM_AuthenticateBlocks_2K PROC FRAME - rex_push_reg rsi - push_reg rdi - push_reg rbx - .endprolog - mov rsi, r8 - mov r11, r9 - #else - AS2( mov WORD_REG(cx), data ) - AS2( mov WORD_REG(dx), len ) - AS2( mov WORD_REG(si), hashBuffer ) - AS2( shr WORD_REG(dx), 4 ) - #endif - - AS_PUSH_IF86( bx) - AS_PUSH_IF86( bp) - - #ifdef __GNUC__ - AS2( mov AS_REG_7, WORD_REG(di)) - #elif CRYPTOPP_BOOL_X86 - AS2( lea AS_REG_7, s_reductionTable) - #endif - - AS2( movdqa xmm0, [WORD_REG(si)] ) - - #define MUL_TABLE_0 WORD_REG(si) + 32 - #define MUL_TABLE_1 WORD_REG(si) + 32 + 1024 - #define RED_TABLE AS_REG_7 - - ASL(0) - AS2( movdqu xmm4, [WORD_REG(cx)] ) - AS2( pxor xmm0, xmm4 ) - - AS2( movd ebx, xmm0 ) - AS2( mov eax, AS_HEX(f0f0f0f0) ) - AS2( and eax, ebx ) - AS2( shl ebx, 4 ) - AS2( and ebx, AS_HEX(f0f0f0f0) ) - AS2( movzx edi, ah ) - AS2( movdqa xmm5, XMMWORD_PTR [MUL_TABLE_1 + WORD_REG(di)] ) - AS2( movzx edi, al ) - AS2( movdqa xmm4, XMMWORD_PTR [MUL_TABLE_1 + WORD_REG(di)] ) - AS2( shr eax, 16 ) - AS2( movzx edi, ah ) - AS2( movdqa xmm3, XMMWORD_PTR [MUL_TABLE_1 + WORD_REG(di)] ) - AS2( movzx edi, al ) - AS2( movdqa xmm2, XMMWORD_PTR [MUL_TABLE_1 + WORD_REG(di)] ) - - #define SSE2_MUL_32BITS(i) \ - AS2( psrldq xmm0, 4 )\ - AS2( movd eax, xmm0 )\ - AS2( and eax, AS_HEX(f0f0f0f0) )\ - AS2( movzx edi, bh )\ - AS2( pxor xmm5, XMMWORD_PTR [MUL_TABLE_0 + (i-1)*256 + WORD_REG(di)] )\ - AS2( movzx edi, bl )\ - AS2( pxor xmm4, XMMWORD_PTR [MUL_TABLE_0 + (i-1)*256 + WORD_REG(di)] )\ - AS2( shr ebx, 16 )\ - AS2( movzx edi, bh )\ - AS2( pxor xmm3, XMMWORD_PTR [MUL_TABLE_0 + (i-1)*256 + WORD_REG(di)] )\ - AS2( movzx edi, bl )\ - AS2( pxor xmm2, XMMWORD_PTR [MUL_TABLE_0 + (i-1)*256 + WORD_REG(di)] )\ - AS2( movd ebx, xmm0 )\ - AS2( shl ebx, 4 )\ - AS2( and ebx, AS_HEX(f0f0f0f0) )\ - AS2( movzx edi, ah )\ - AS2( pxor xmm5, XMMWORD_PTR [MUL_TABLE_1 + i*256 + WORD_REG(di)] )\ - AS2( movzx edi, al )\ - AS2( pxor xmm4, XMMWORD_PTR [MUL_TABLE_1 + i*256 + WORD_REG(di)] )\ - AS2( shr eax, 16 )\ - AS2( movzx edi, ah )\ - AS2( pxor xmm3, XMMWORD_PTR [MUL_TABLE_1 + i*256 + WORD_REG(di)] )\ - AS2( movzx edi, al )\ - AS2( pxor xmm2, XMMWORD_PTR [MUL_TABLE_1 + i*256 + WORD_REG(di)] )\ - - SSE2_MUL_32BITS(1) - SSE2_MUL_32BITS(2) - SSE2_MUL_32BITS(3) - - AS2( movzx edi, bh ) - AS2( pxor xmm5, XMMWORD_PTR [MUL_TABLE_0 + 3*256 + WORD_REG(di)] ) - AS2( movzx edi, bl ) - AS2( pxor xmm4, XMMWORD_PTR [MUL_TABLE_0 + 3*256 + WORD_REG(di)] ) - AS2( shr ebx, 16 ) - AS2( movzx edi, bh ) - AS2( pxor xmm3, XMMWORD_PTR [MUL_TABLE_0 + 3*256 + WORD_REG(di)] ) - AS2( movzx edi, bl ) - AS2( pxor xmm2, XMMWORD_PTR [MUL_TABLE_0 + 3*256 + WORD_REG(di)] ) - - AS2( movdqa xmm0, xmm3 ) - AS2( pslldq xmm3, 1 ) - AS2( pxor xmm2, xmm3 ) - AS2( movdqa xmm1, xmm2 ) - AS2( pslldq xmm2, 1 ) - AS2( pxor xmm5, xmm2 ) - - AS2( psrldq xmm0, 15 ) - AS2( movd WORD_REG(di), xmm0 ) - AS2( movzx eax, WORD PTR [RED_TABLE + WORD_REG(di)*2] ) - AS2( shl eax, 8 ) - - AS2( movdqa xmm0, xmm5 ) - AS2( pslldq xmm5, 1 ) - AS2( pxor xmm4, xmm5 ) - - AS2( psrldq xmm1, 15 ) - AS2( movd WORD_REG(di), xmm1 ) - AS2( xor ax, WORD PTR [RED_TABLE + WORD_REG(di)*2] ) - AS2( shl eax, 8 ) - - AS2( psrldq xmm0, 15 ) - AS2( movd WORD_REG(di), xmm0 ) - AS2( xor ax, WORD PTR [RED_TABLE + WORD_REG(di)*2] ) - - AS2( movd xmm0, eax ) - AS2( pxor xmm0, xmm4 ) - - AS2( add WORD_REG(cx), 16 ) - AS2( sub WORD_REG(dx), 1 ) - ASJ( jnz, 0, b ) - AS2( movdqa [WORD_REG(si)], xmm0 ) - - AS_POP_IF86( bp) - AS_POP_IF86( bx) - - #ifdef __GNUC__ - ".att_syntax prefix;" - : - : "c" (data), "d" (len/16), "S" (hashBuffer), "D" (s_reductionTable) - : "memory", "cc", "%eax" - #if CRYPTOPP_BOOL_X64 - , "%ebx", "%r11" - #endif - ); - #elif defined(CRYPTOPP_GENERATE_X64_MASM) - pop rbx - pop rdi - pop rsi - ret - GCM_AuthenticateBlocks_2K ENDP - #endif - - return len%16; - } - case 3: // SSE2 and 64K tables - { - #ifdef __GNUC__ - __asm__ __volatile__ - ( - ".intel_syntax noprefix;" - #elif defined(CRYPTOPP_GENERATE_X64_MASM) - ALIGN 8 - GCM_AuthenticateBlocks_64K PROC FRAME - rex_push_reg rsi - push_reg rdi - .endprolog - mov rsi, r8 - #else - AS2( mov WORD_REG(cx), data ) - AS2( mov WORD_REG(dx), len ) - AS2( mov WORD_REG(si), hashBuffer ) - AS2( shr WORD_REG(dx), 4 ) - #endif - - AS2( movdqa xmm0, [WORD_REG(si)] ) - - #undef MUL_TABLE - #define MUL_TABLE(i,j) WORD_REG(si) + 32 + (i*4+j)*256*16 - - ASL(1) - AS2( movdqu xmm1, [WORD_REG(cx)] ) - AS2( pxor xmm1, xmm0 ) - AS2( pxor xmm0, xmm0 ) - - #undef SSE2_MUL_32BITS - #define SSE2_MUL_32BITS(i) \ - AS2( movd eax, xmm1 )\ - AS2( psrldq xmm1, 4 )\ - AS2( movzx edi, al )\ - AS2( add WORD_REG(di), WORD_REG(di) )\ - AS2( pxor xmm0, [MUL_TABLE(i,0) + WORD_REG(di)*8] )\ - AS2( movzx edi, ah )\ - AS2( add WORD_REG(di), WORD_REG(di) )\ - AS2( pxor xmm0, [MUL_TABLE(i,1) + WORD_REG(di)*8] )\ - AS2( shr eax, 16 )\ - AS2( movzx edi, al )\ - AS2( add WORD_REG(di), WORD_REG(di) )\ - AS2( pxor xmm0, [MUL_TABLE(i,2) + WORD_REG(di)*8] )\ - AS2( movzx edi, ah )\ - AS2( add WORD_REG(di), WORD_REG(di) )\ - AS2( pxor xmm0, [MUL_TABLE(i,3) + WORD_REG(di)*8] )\ - - SSE2_MUL_32BITS(0) - SSE2_MUL_32BITS(1) - SSE2_MUL_32BITS(2) - SSE2_MUL_32BITS(3) - - AS2( add WORD_REG(cx), 16 ) - AS2( sub WORD_REG(dx), 1 ) - ASJ( jnz, 1, b ) - AS2( movdqa [WORD_REG(si)], xmm0 ) - - #ifdef __GNUC__ - ".att_syntax prefix;" - : - : "c" (data), "d" (len/16), "S" (hashBuffer) - : "memory", "cc", "%edi", "%eax" - ); - #elif defined(CRYPTOPP_GENERATE_X64_MASM) - pop rdi - pop rsi - ret - GCM_AuthenticateBlocks_64K ENDP - #endif - - return len%16; - } -#endif -#ifndef CRYPTOPP_GENERATE_X64_MASM - } - - return len%16; -} - -void GCM_Base::AuthenticateLastHeaderBlock() -{ - if (m_bufferedDataLength > 0) - { - memset(m_buffer+m_bufferedDataLength, 0, HASH_BLOCKSIZE-m_bufferedDataLength); - m_bufferedDataLength = 0; - GCM_Base::AuthenticateBlocks(m_buffer, HASH_BLOCKSIZE); - } -} - -void GCM_Base::AuthenticateLastConfidentialBlock() -{ - GCM_Base::AuthenticateLastHeaderBlock(); - PutBlock(NULL, m_buffer)(m_totalHeaderLength*8)(m_totalMessageLength*8); - GCM_Base::AuthenticateBlocks(m_buffer, HASH_BLOCKSIZE); -} - -void GCM_Base::AuthenticateLastFooterBlock(byte *mac, size_t macSize) -{ - m_ctr.Seek(0); - ReverseHashBufferIfNeeded(); - m_ctr.ProcessData(mac, HashBuffer(), macSize); -} - -NAMESPACE_END - -#endif // #ifndef CRYPTOPP_GENERATE_X64_MASM -#endif diff --git a/lib/cryptopp/gcm.h b/lib/cryptopp/gcm.h deleted file mode 100644 index 272a51c9c..000000000 --- a/lib/cryptopp/gcm.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef CRYPTOPP_GCM_H -#define CRYPTOPP_GCM_H - -#include "authenc.h" -#include "modes.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! . -enum GCM_TablesOption {GCM_2K_Tables, GCM_64K_Tables}; - -//! . -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE GCM_Base : public AuthenticatedSymmetricCipherBase -{ -public: - // AuthenticatedSymmetricCipher - std::string AlgorithmName() const - {return GetBlockCipher().AlgorithmName() + std::string("/GCM");} - size_t MinKeyLength() const - {return GetBlockCipher().MinKeyLength();} - size_t MaxKeyLength() const - {return GetBlockCipher().MaxKeyLength();} - size_t DefaultKeyLength() const - {return GetBlockCipher().DefaultKeyLength();} - size_t GetValidKeyLength(size_t n) const - {return GetBlockCipher().GetValidKeyLength(n);} - bool IsValidKeyLength(size_t n) const - {return GetBlockCipher().IsValidKeyLength(n);} - unsigned int OptimalDataAlignment() const; - IV_Requirement IVRequirement() const - {return UNIQUE_IV;} - unsigned int IVSize() const - {return 12;} - unsigned int MinIVLength() const - {return 1;} - unsigned int MaxIVLength() const - {return UINT_MAX;} // (W64LIT(1)<<61)-1 in the standard - unsigned int DigestSize() const - {return 16;} - lword MaxHeaderLength() const - {return (W64LIT(1)<<61)-1;} - lword MaxMessageLength() const - {return ((W64LIT(1)<<39)-256)/8;} - -protected: - // AuthenticatedSymmetricCipherBase - bool AuthenticationIsOnPlaintext() const - {return false;} - unsigned int AuthenticationBlockSize() const - {return HASH_BLOCKSIZE;} - void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms); - void Resync(const byte *iv, size_t len); - size_t AuthenticateBlocks(const byte *data, size_t len); - void AuthenticateLastHeaderBlock(); - void AuthenticateLastConfidentialBlock(); - void AuthenticateLastFooterBlock(byte *mac, size_t macSize); - SymmetricCipher & AccessSymmetricCipher() {return m_ctr;} - - virtual BlockCipher & AccessBlockCipher() =0; - virtual GCM_TablesOption GetTablesOption() const =0; - - const BlockCipher & GetBlockCipher() const {return const_cast(this)->AccessBlockCipher();}; - byte *HashBuffer() {return m_buffer+REQUIRED_BLOCKSIZE;} - byte *HashKey() {return m_buffer+2*REQUIRED_BLOCKSIZE;} - byte *MulTable() {return m_buffer+3*REQUIRED_BLOCKSIZE;} - inline void ReverseHashBufferIfNeeded(); - - class CRYPTOPP_DLL GCTR : public CTR_Mode_ExternalCipher::Encryption - { - protected: - void IncrementCounterBy256(); - }; - - GCTR m_ctr; - static word16 s_reductionTable[256]; - static volatile bool s_reductionTableInitialized; - enum {REQUIRED_BLOCKSIZE = 16, HASH_BLOCKSIZE = 16}; -}; - -//! . -template -class GCM_Final : public GCM_Base -{ -public: - static std::string StaticAlgorithmName() - {return T_BlockCipher::StaticAlgorithmName() + std::string("/GCM");} - bool IsForwardTransformation() const - {return T_IsEncryption;} - -private: - GCM_TablesOption GetTablesOption() const {return T_TablesOption;} - BlockCipher & AccessBlockCipher() {return m_cipher;} - typename T_BlockCipher::Encryption m_cipher; -}; - -//! GCM -template -struct GCM : public AuthenticatedSymmetricCipherDocumentation -{ - typedef GCM_Final Encryption; - typedef GCM_Final Decryption; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/gf256.cpp b/lib/cryptopp/gf256.cpp deleted file mode 100644 index 72026d1e1..000000000 --- a/lib/cryptopp/gf256.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// gf256.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "gf256.h" - -NAMESPACE_BEGIN(CryptoPP) - -GF256::Element GF256::Multiply(Element a, Element b) const -{ - word result = 0, t = b; - - for (unsigned int i=0; i<8; i++) - { - result <<= 1; - if (result & 0x100) - result ^= m_modulus; - - t <<= 1; - if (t & 0x100) - result ^= a; - } - - return (GF256::Element) result; -} - -GF256::Element GF256::MultiplicativeInverse(Element a) const -{ - Element result = a; - for (int i=1; i<7; i++) - result = Multiply(Square(result), a); - return Square(result); -} - -NAMESPACE_END diff --git a/lib/cryptopp/gf256.h b/lib/cryptopp/gf256.h deleted file mode 100644 index e0ea74826..000000000 --- a/lib/cryptopp/gf256.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef CRYPTOPP_GF256_H -#define CRYPTOPP_GF256_H - -#include "cryptlib.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! GF(256) with polynomial basis -class GF256 -{ -public: - typedef byte Element; - typedef int RandomizationParameter; - - GF256(byte modulus) : m_modulus(modulus) {} - - Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const - {return rng.GenerateByte();} - - bool Equal(Element a, Element b) const - {return a==b;} - - Element Zero() const - {return 0;} - - Element Add(Element a, Element b) const - {return a^b;} - - Element& Accumulate(Element &a, Element b) const - {return a^=b;} - - Element Inverse(Element a) const - {return a;} - - Element Subtract(Element a, Element b) const - {return a^b;} - - Element& Reduce(Element &a, Element b) const - {return a^=b;} - - Element Double(Element a) const - {return 0;} - - Element One() const - {return 1;} - - Element Multiply(Element a, Element b) const; - - Element Square(Element a) const - {return Multiply(a, a);} - - bool IsUnit(Element a) const - {return a != 0;} - - Element MultiplicativeInverse(Element a) const; - - Element Divide(Element a, Element b) const - {return Multiply(a, MultiplicativeInverse(b));} - -private: - word m_modulus; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/gf2_32.cpp b/lib/cryptopp/gf2_32.cpp deleted file mode 100644 index ae4874a40..000000000 --- a/lib/cryptopp/gf2_32.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// gf2_32.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "misc.h" -#include "gf2_32.h" - -NAMESPACE_BEGIN(CryptoPP) - -GF2_32::Element GF2_32::Multiply(Element a, Element b) const -{ - word32 table[4]; - table[0] = 0; - table[1] = m_modulus; - if (a & 0x80000000) - { - table[2] = m_modulus ^ (a<<1); - table[3] = a<<1; - } - else - { - table[2] = a<<1; - table[3] = m_modulus ^ (a<<1); - } - -#if CRYPTOPP_FAST_ROTATE(32) - b = rotrFixed(b, 30U); - word32 result = table[b&2]; - - for (int i=29; i>=0; --i) - { - b = rotlFixed(b, 1U); - result = (result<<1) ^ table[(b&2) + (result>>31)]; - } - - return (b&1) ? result ^ a : result; -#else - word32 result = table[(b>>30) & 2]; - - for (int i=29; i>=0; --i) - result = (result<<1) ^ table[((b>>i)&2) + (result>>31)]; - - return (b&1) ? result ^ a : result; -#endif -} - -GF2_32::Element GF2_32::MultiplicativeInverse(Element a) const -{ - if (a <= 1) // 1 is a special case - return a; - - // warning - don't try to adapt this algorithm for another situation - word32 g0=m_modulus, g1=a, g2=a; - word32 v0=0, v1=1, v2=1; - - assert(g1); - - while (!(g2 & 0x80000000)) - { - g2 <<= 1; - v2 <<= 1; - } - - g2 <<= 1; - v2 <<= 1; - - g0 ^= g2; - v0 ^= v2; - - while (g0 != 1) - { - if (g1 < g0 || ((g0^g1) < g0 && (g0^g1) < g1)) - { - assert(BitPrecision(g1) <= BitPrecision(g0)); - g2 = g1; - v2 = v1; - } - else - { - assert(BitPrecision(g1) > BitPrecision(g0)); - g2 = g0; g0 = g1; g1 = g2; - v2 = v0; v0 = v1; v1 = v2; - } - - while ((g0^g2) >= g2) - { - assert(BitPrecision(g0) > BitPrecision(g2)); - g2 <<= 1; - v2 <<= 1; - } - - assert(BitPrecision(g0) == BitPrecision(g2)); - g0 ^= g2; - v0 ^= v2; - } - - return v0; -} - -NAMESPACE_END diff --git a/lib/cryptopp/gf2_32.h b/lib/cryptopp/gf2_32.h deleted file mode 100644 index 31713f4c0..000000000 --- a/lib/cryptopp/gf2_32.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef CRYPTOPP_GF2_32_H -#define CRYPTOPP_GF2_32_H - -#include "cryptlib.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! GF(2^32) with polynomial basis -class GF2_32 -{ -public: - typedef word32 Element; - typedef int RandomizationParameter; - - GF2_32(word32 modulus=0x0000008D) : m_modulus(modulus) {} - - Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const - {return rng.GenerateWord32();} - - bool Equal(Element a, Element b) const - {return a==b;} - - Element Identity() const - {return 0;} - - Element Add(Element a, Element b) const - {return a^b;} - - Element& Accumulate(Element &a, Element b) const - {return a^=b;} - - Element Inverse(Element a) const - {return a;} - - Element Subtract(Element a, Element b) const - {return a^b;} - - Element& Reduce(Element &a, Element b) const - {return a^=b;} - - Element Double(Element a) const - {return 0;} - - Element MultiplicativeIdentity() const - {return 1;} - - Element Multiply(Element a, Element b) const; - - Element Square(Element a) const - {return Multiply(a, a);} - - bool IsUnit(Element a) const - {return a != 0;} - - Element MultiplicativeInverse(Element a) const; - - Element Divide(Element a, Element b) const - {return Multiply(a, MultiplicativeInverse(b));} - -private: - word32 m_modulus; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/gf2n.cpp b/lib/cryptopp/gf2n.cpp deleted file mode 100644 index bcc56071a..000000000 --- a/lib/cryptopp/gf2n.cpp +++ /dev/null @@ -1,882 +0,0 @@ -// gf2n.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "gf2n.h" -#include "algebra.h" -#include "words.h" -#include "randpool.h" -#include "asn.h" -#include "oids.h" - -#include - -NAMESPACE_BEGIN(CryptoPP) - -PolynomialMod2::PolynomialMod2() -{ -} - -PolynomialMod2::PolynomialMod2(word value, size_t bitLength) - : reg(BitsToWords(bitLength)) -{ - assert(value==0 || reg.size()>0); - - if (reg.size() > 0) - { - reg[0] = value; - SetWords(reg+1, 0, reg.size()-1); - } -} - -PolynomialMod2::PolynomialMod2(const PolynomialMod2& t) - : reg(t.reg.size()) -{ - CopyWords(reg, t.reg, reg.size()); -} - -void PolynomialMod2::Randomize(RandomNumberGenerator &rng, size_t nbits) -{ - const size_t nbytes = nbits/8 + 1; - SecByteBlock buf(nbytes); - rng.GenerateBlock(buf, nbytes); - buf[0] = (byte)Crop(buf[0], nbits % 8); - Decode(buf, nbytes); -} - -PolynomialMod2 PolynomialMod2::AllOnes(size_t bitLength) -{ - PolynomialMod2 result((word)0, bitLength); - SetWords(result.reg, ~(word)0, result.reg.size()); - if (bitLength%WORD_BITS) - result.reg[result.reg.size()-1] = (word)Crop(result.reg[result.reg.size()-1], bitLength%WORD_BITS); - return result; -} - -void PolynomialMod2::SetBit(size_t n, int value) -{ - if (value) - { - reg.CleanGrow(n/WORD_BITS + 1); - reg[n/WORD_BITS] |= (word(1) << (n%WORD_BITS)); - } - else - { - if (n/WORD_BITS < reg.size()) - reg[n/WORD_BITS] &= ~(word(1) << (n%WORD_BITS)); - } -} - -byte PolynomialMod2::GetByte(size_t n) const -{ - if (n/WORD_SIZE >= reg.size()) - return 0; - else - return byte(reg[n/WORD_SIZE] >> ((n%WORD_SIZE)*8)); -} - -void PolynomialMod2::SetByte(size_t n, byte value) -{ - reg.CleanGrow(BytesToWords(n+1)); - reg[n/WORD_SIZE] &= ~(word(0xff) << 8*(n%WORD_SIZE)); - reg[n/WORD_SIZE] |= (word(value) << 8*(n%WORD_SIZE)); -} - -PolynomialMod2 PolynomialMod2::Monomial(size_t i) -{ - PolynomialMod2 r((word)0, i+1); - r.SetBit(i); - return r; -} - -PolynomialMod2 PolynomialMod2::Trinomial(size_t t0, size_t t1, size_t t2) -{ - PolynomialMod2 r((word)0, t0+1); - r.SetBit(t0); - r.SetBit(t1); - r.SetBit(t2); - return r; -} - -PolynomialMod2 PolynomialMod2::Pentanomial(size_t t0, size_t t1, size_t t2, size_t t3, size_t t4) -{ - PolynomialMod2 r((word)0, t0+1); - r.SetBit(t0); - r.SetBit(t1); - r.SetBit(t2); - r.SetBit(t3); - r.SetBit(t4); - return r; -} - -template -struct NewPolynomialMod2 -{ - PolynomialMod2 * operator()() const - { - return new PolynomialMod2(i); - } -}; - -const PolynomialMod2 &PolynomialMod2::Zero() -{ - return Singleton().Ref(); -} - -const PolynomialMod2 &PolynomialMod2::One() -{ - return Singleton >().Ref(); -} - -void PolynomialMod2::Decode(const byte *input, size_t inputLen) -{ - StringStore store(input, inputLen); - Decode(store, inputLen); -} - -void PolynomialMod2::Encode(byte *output, size_t outputLen) const -{ - ArraySink sink(output, outputLen); - Encode(sink, outputLen); -} - -void PolynomialMod2::Decode(BufferedTransformation &bt, size_t inputLen) -{ - reg.CleanNew(BytesToWords(inputLen)); - - for (size_t i=inputLen; i > 0; i--) - { - byte b; - bt.Get(b); - reg[(i-1)/WORD_SIZE] |= word(b) << ((i-1)%WORD_SIZE)*8; - } -} - -void PolynomialMod2::Encode(BufferedTransformation &bt, size_t outputLen) const -{ - for (size_t i=outputLen; i > 0; i--) - bt.Put(GetByte(i-1)); -} - -void PolynomialMod2::DEREncodeAsOctetString(BufferedTransformation &bt, size_t length) const -{ - DERGeneralEncoder enc(bt, OCTET_STRING); - Encode(enc, length); - enc.MessageEnd(); -} - -void PolynomialMod2::BERDecodeAsOctetString(BufferedTransformation &bt, size_t length) -{ - BERGeneralDecoder dec(bt, OCTET_STRING); - if (!dec.IsDefiniteLength() || dec.RemainingLength() != length) - BERDecodeError(); - Decode(dec, length); - dec.MessageEnd(); -} - -unsigned int PolynomialMod2::WordCount() const -{ - return (unsigned int)CountWords(reg, reg.size()); -} - -unsigned int PolynomialMod2::ByteCount() const -{ - unsigned wordCount = WordCount(); - if (wordCount) - return (wordCount-1)*WORD_SIZE + BytePrecision(reg[wordCount-1]); - else - return 0; -} - -unsigned int PolynomialMod2::BitCount() const -{ - unsigned wordCount = WordCount(); - if (wordCount) - return (wordCount-1)*WORD_BITS + BitPrecision(reg[wordCount-1]); - else - return 0; -} - -unsigned int PolynomialMod2::Parity() const -{ - unsigned i; - word temp=0; - for (i=0; i= reg.size()) - { - PolynomialMod2 result((word)0, b.reg.size()*WORD_BITS); - XorWords(result.reg, reg, b.reg, reg.size()); - CopyWords(result.reg+reg.size(), b.reg+reg.size(), b.reg.size()-reg.size()); - return result; - } - else - { - PolynomialMod2 result((word)0, reg.size()*WORD_BITS); - XorWords(result.reg, reg, b.reg, b.reg.size()); - CopyWords(result.reg+b.reg.size(), reg+b.reg.size(), reg.size()-b.reg.size()); - return result; - } -} - -PolynomialMod2 PolynomialMod2::And(const PolynomialMod2 &b) const -{ - PolynomialMod2 result((word)0, WORD_BITS*STDMIN(reg.size(), b.reg.size())); - AndWords(result.reg, reg, b.reg, result.reg.size()); - return result; -} - -PolynomialMod2 PolynomialMod2::Times(const PolynomialMod2 &b) const -{ - PolynomialMod2 result((word)0, BitCount() + b.BitCount()); - - for (int i=b.Degree(); i>=0; i--) - { - result <<= 1; - if (b[i]) - XorWords(result.reg, reg, reg.size()); - } - return result; -} - -PolynomialMod2 PolynomialMod2::Squared() const -{ - static const word map[16] = {0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84, 85}; - - PolynomialMod2 result((word)0, 2*reg.size()*WORD_BITS); - - for (unsigned i=0; i> (j/2)) % 16] << j; - - for (j=0; j> (j/2 + WORD_BITS/2)) % 16] << j; - } - - return result; -} - -void PolynomialMod2::Divide(PolynomialMod2 &remainder, PolynomialMod2 "ient, - const PolynomialMod2 ÷nd, const PolynomialMod2 &divisor) -{ - if (!divisor) - throw PolynomialMod2::DivideByZero(); - - int degree = divisor.Degree(); - remainder.reg.CleanNew(BitsToWords(degree+1)); - if (dividend.BitCount() >= divisor.BitCount()) - quotient.reg.CleanNew(BitsToWords(dividend.BitCount() - divisor.BitCount() + 1)); - else - quotient.reg.CleanNew(0); - - for (int i=dividend.Degree(); i>=0; i--) - { - remainder <<= 1; - remainder.reg[0] |= dividend[i]; - if (remainder[degree]) - { - remainder -= divisor; - quotient.SetBit(i); - } - } -} - -PolynomialMod2 PolynomialMod2::DividedBy(const PolynomialMod2 &b) const -{ - PolynomialMod2 remainder, quotient; - PolynomialMod2::Divide(remainder, quotient, *this, b); - return quotient; -} - -PolynomialMod2 PolynomialMod2::Modulo(const PolynomialMod2 &b) const -{ - PolynomialMod2 remainder, quotient; - PolynomialMod2::Divide(remainder, quotient, *this, b); - return remainder; -} - -PolynomialMod2& PolynomialMod2::operator<<=(unsigned int n) -{ - if (!reg.size()) - return *this; - - int i; - word u; - word carry=0; - word *r=reg; - - if (n==1) // special case code for most frequent case - { - i = (int)reg.size(); - while (i--) - { - u = *r; - *r = (u << 1) | carry; - carry = u >> (WORD_BITS-1); - r++; - } - - if (carry) - { - reg.Grow(reg.size()+1); - reg[reg.size()-1] = carry; - } - - return *this; - } - - int shiftWords = n / WORD_BITS; - int shiftBits = n % WORD_BITS; - - if (shiftBits) - { - i = (int)reg.size(); - while (i--) - { - u = *r; - *r = (u << shiftBits) | carry; - carry = u >> (WORD_BITS-shiftBits); - r++; - } - } - - if (carry) - { - reg.Grow(reg.size()+shiftWords+1); - reg[reg.size()-1] = carry; - } - else - reg.Grow(reg.size()+shiftWords); - - if (shiftWords) - { - for (i = (int)reg.size()-1; i>=shiftWords; i--) - reg[i] = reg[i-shiftWords]; - for (; i>=0; i--) - reg[i] = 0; - } - - return *this; -} - -PolynomialMod2& PolynomialMod2::operator>>=(unsigned int n) -{ - if (!reg.size()) - return *this; - - int shiftWords = n / WORD_BITS; - int shiftBits = n % WORD_BITS; - - size_t i; - word u; - word carry=0; - word *r=reg+reg.size()-1; - - if (shiftBits) - { - i = reg.size(); - while (i--) - { - u = *r; - *r = (u >> shiftBits) | carry; - carry = u << (WORD_BITS-shiftBits); - r--; - } - } - - if (shiftWords) - { - for (i=0; i>(unsigned int n) const -{ - PolynomialMod2 result(*this); - return result>>=n; -} - -bool PolynomialMod2::operator!() const -{ - for (unsigned i=0; i s(a.BitCount()/bits+1); - unsigned i; - - static const char upper[]="0123456789ABCDEF"; - static const char lower[]="0123456789abcdef"; - const char* vec = (out.flags() & std::ios::uppercase) ? upper : lower; - - for (i=0; i*bits < a.BitCount(); i++) - { - int digit=0; - for (int j=0; j().Gcd(a, b); -} - -PolynomialMod2 PolynomialMod2::InverseMod(const PolynomialMod2 &modulus) const -{ - typedef EuclideanDomainOf Domain; - return QuotientRing(Domain(), modulus).MultiplicativeInverse(*this); -} - -bool PolynomialMod2::IsIrreducible() const -{ - signed int d = Degree(); - if (d <= 0) - return false; - - PolynomialMod2 t(2), u(t); - for (int i=1; i<=d/2; i++) - { - u = u.Squared()%(*this); - if (!Gcd(u+t, *this).IsUnit()) - return false; - } - return true; -} - -// ******************************************************** - -GF2NP::GF2NP(const PolynomialMod2 &modulus) - : QuotientRing >(EuclideanDomainOf(), modulus), m(modulus.Degree()) -{ -} - -GF2NP::Element GF2NP::SquareRoot(const Element &a) const -{ - Element r = a; - for (unsigned int i=1; i t1 && t1 > t2 && t2==0); -} - -const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const -{ - if (t0-t1 < WORD_BITS) - return GF2NP::MultiplicativeInverse(a); - - SecWordBlock T(m_modulus.reg.size() * 4); - word *b = T; - word *c = T+m_modulus.reg.size(); - word *f = T+2*m_modulus.reg.size(); - word *g = T+3*m_modulus.reg.size(); - size_t bcLen=1, fgLen=m_modulus.reg.size(); - unsigned int k=0; - - SetWords(T, 0, 3*m_modulus.reg.size()); - b[0]=1; - assert(a.reg.size() <= m_modulus.reg.size()); - CopyWords(f, a.reg, a.reg.size()); - CopyWords(g, m_modulus.reg, m_modulus.reg.size()); - - while (1) - { - word t=f[0]; - while (!t) - { - ShiftWordsRightByWords(f, fgLen, 1); - if (c[bcLen-1]) - bcLen++; - assert(bcLen <= m_modulus.reg.size()); - ShiftWordsLeftByWords(c, bcLen, 1); - k+=WORD_BITS; - t=f[0]; - } - - unsigned int i=0; - while (t%2 == 0) - { - t>>=1; - i++; - } - k+=i; - - if (t==1 && CountWords(f, fgLen)==1) - break; - - if (i==1) - { - ShiftWordsRightByBits(f, fgLen, 1); - t=ShiftWordsLeftByBits(c, bcLen, 1); - } - else - { - ShiftWordsRightByBits(f, fgLen, i); - t=ShiftWordsLeftByBits(c, bcLen, i); - } - if (t) - { - c[bcLen] = t; - bcLen++; - assert(bcLen <= m_modulus.reg.size()); - } - - if (f[fgLen-1]==0 && g[fgLen-1]==0) - fgLen--; - - if (f[fgLen-1] < g[fgLen-1]) - { - std::swap(f, g); - std::swap(b, c); - } - - XorWords(f, g, fgLen); - XorWords(b, c, bcLen); - } - - while (k >= WORD_BITS) - { - word temp = b[0]; - // right shift b - for (unsigned i=0; i+1> j) & 1) << (t1 + j); - else - b[t1/WORD_BITS-1] ^= temp << t1%WORD_BITS; - - if (t1 % WORD_BITS) - b[t1/WORD_BITS] ^= temp >> (WORD_BITS - t1%WORD_BITS); - - if (t0%WORD_BITS) - { - b[t0/WORD_BITS-1] ^= temp << t0%WORD_BITS; - b[t0/WORD_BITS] ^= temp >> (WORD_BITS - t0%WORD_BITS); - } - else - b[t0/WORD_BITS-1] ^= temp; - - k -= WORD_BITS; - } - - if (k) - { - word temp = b[0] << (WORD_BITS - k); - ShiftWordsRightByBits(b, BitsToWords(m), k); - - if (t1 < WORD_BITS) - for (unsigned int j=0; j> j) & 1) << (t1 + j); - else - b[t1/WORD_BITS-1] ^= temp << t1%WORD_BITS; - - if (t1 % WORD_BITS) - b[t1/WORD_BITS] ^= temp >> (WORD_BITS - t1%WORD_BITS); - - if (t0%WORD_BITS) - { - b[t0/WORD_BITS-1] ^= temp << t0%WORD_BITS; - b[t0/WORD_BITS] ^= temp >> (WORD_BITS - t0%WORD_BITS); - } - else - b[t0/WORD_BITS-1] ^= temp; - } - - CopyWords(result.reg.begin(), b, result.reg.size()); - return result; -} - -const GF2NT::Element& GF2NT::Multiply(const Element &a, const Element &b) const -{ - size_t aSize = STDMIN(a.reg.size(), result.reg.size()); - Element r((word)0, m); - - for (int i=m-1; i>=0; i--) - { - if (r[m-1]) - { - ShiftWordsLeftByBits(r.reg.begin(), r.reg.size(), 1); - XorWords(r.reg.begin(), m_modulus.reg, r.reg.size()); - } - else - ShiftWordsLeftByBits(r.reg.begin(), r.reg.size(), 1); - - if (b[i]) - XorWords(r.reg.begin(), a.reg, aSize); - } - - if (m%WORD_BITS) - r.reg.begin()[r.reg.size()-1] = (word)Crop(r.reg[r.reg.size()-1], m%WORD_BITS); - - CopyWords(result.reg.begin(), r.reg.begin(), result.reg.size()); - return result; -} - -const GF2NT::Element& GF2NT::Reduced(const Element &a) const -{ - if (t0-t1 < WORD_BITS) - return m_domain.Mod(a, m_modulus); - - SecWordBlock b(a.reg); - - size_t i; - for (i=b.size()-1; i>=BitsToWords(t0); i--) - { - word temp = b[i]; - - if (t0%WORD_BITS) - { - b[i-t0/WORD_BITS] ^= temp >> t0%WORD_BITS; - b[i-t0/WORD_BITS-1] ^= temp << (WORD_BITS - t0%WORD_BITS); - } - else - b[i-t0/WORD_BITS] ^= temp; - - if ((t0-t1)%WORD_BITS) - { - b[i-(t0-t1)/WORD_BITS] ^= temp >> (t0-t1)%WORD_BITS; - b[i-(t0-t1)/WORD_BITS-1] ^= temp << (WORD_BITS - (t0-t1)%WORD_BITS); - } - else - b[i-(t0-t1)/WORD_BITS] ^= temp; - } - - if (i==BitsToWords(t0)-1 && t0%WORD_BITS) - { - word mask = ((word)1<<(t0%WORD_BITS))-1; - word temp = b[i] & ~mask; - b[i] &= mask; - - b[i-t0/WORD_BITS] ^= temp >> t0%WORD_BITS; - - if ((t0-t1)%WORD_BITS) - { - b[i-(t0-t1)/WORD_BITS] ^= temp >> (t0-t1)%WORD_BITS; - if ((t0-t1)%WORD_BITS > t0%WORD_BITS) - b[i-(t0-t1)/WORD_BITS-1] ^= temp << (WORD_BITS - (t0-t1)%WORD_BITS); - else - assert(temp << (WORD_BITS - (t0-t1)%WORD_BITS) == 0); - } - else - b[i-(t0-t1)/WORD_BITS] ^= temp; - } - - SetWords(result.reg.begin(), 0, result.reg.size()); - CopyWords(result.reg.begin(), b, STDMIN(b.size(), result.reg.size())); - return result; -} - -void GF2NP::DEREncodeElement(BufferedTransformation &out, const Element &a) const -{ - a.DEREncodeAsOctetString(out, MaxElementByteLength()); -} - -void GF2NP::BERDecodeElement(BufferedTransformation &in, Element &a) const -{ - a.BERDecodeAsOctetString(in, MaxElementByteLength()); -} - -void GF2NT::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - ASN1::characteristic_two_field().DEREncode(seq); - DERSequenceEncoder parameters(seq); - DEREncodeUnsigned(parameters, m); - ASN1::tpBasis().DEREncode(parameters); - DEREncodeUnsigned(parameters, t1); - parameters.MessageEnd(); - seq.MessageEnd(); -} - -void GF2NPP::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - ASN1::characteristic_two_field().DEREncode(seq); - DERSequenceEncoder parameters(seq); - DEREncodeUnsigned(parameters, m); - ASN1::ppBasis().DEREncode(parameters); - DERSequenceEncoder pentanomial(parameters); - DEREncodeUnsigned(pentanomial, t3); - DEREncodeUnsigned(pentanomial, t2); - DEREncodeUnsigned(pentanomial, t1); - pentanomial.MessageEnd(); - parameters.MessageEnd(); - seq.MessageEnd(); -} - -GF2NP * BERDecodeGF2NP(BufferedTransformation &bt) -{ - // VC60 workaround: auto_ptr lacks reset() - member_ptr result; - - BERSequenceDecoder seq(bt); - if (OID(seq) != ASN1::characteristic_two_field()) - BERDecodeError(); - BERSequenceDecoder parameters(seq); - unsigned int m; - BERDecodeUnsigned(parameters, m); - OID oid(parameters); - if (oid == ASN1::tpBasis()) - { - unsigned int t1; - BERDecodeUnsigned(parameters, t1); - result.reset(new GF2NT(m, t1, 0)); - } - else if (oid == ASN1::ppBasis()) - { - unsigned int t1, t2, t3; - BERSequenceDecoder pentanomial(parameters); - BERDecodeUnsigned(pentanomial, t3); - BERDecodeUnsigned(pentanomial, t2); - BERDecodeUnsigned(pentanomial, t1); - pentanomial.MessageEnd(); - result.reset(new GF2NPP(m, t3, t2, t1, 0)); - } - else - { - BERDecodeError(); - return NULL; - } - parameters.MessageEnd(); - seq.MessageEnd(); - - return result.release(); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/gf2n.h b/lib/cryptopp/gf2n.h deleted file mode 100644 index 67ade641e..000000000 --- a/lib/cryptopp/gf2n.h +++ /dev/null @@ -1,369 +0,0 @@ -#ifndef CRYPTOPP_GF2N_H -#define CRYPTOPP_GF2N_H - -/*! \file */ - -#include "cryptlib.h" -#include "secblock.h" -#include "misc.h" -#include "algebra.h" - -#include - -NAMESPACE_BEGIN(CryptoPP) - -//! Polynomial with Coefficients in GF(2) -/*! \nosubgrouping */ -class CRYPTOPP_DLL PolynomialMod2 -{ -public: - //! \name ENUMS, EXCEPTIONS, and TYPEDEFS - //@{ - //! divide by zero exception - class DivideByZero : public Exception - { - public: - DivideByZero() : Exception(OTHER_ERROR, "PolynomialMod2: division by zero") {} - }; - - typedef unsigned int RandomizationParameter; - //@} - - //! \name CREATORS - //@{ - //! creates the zero polynomial - PolynomialMod2(); - //! copy constructor - PolynomialMod2(const PolynomialMod2& t); - - //! convert from word - /*! value should be encoded with the least significant bit as coefficient to x^0 - and most significant bit as coefficient to x^(WORD_BITS-1) - bitLength denotes how much memory to allocate initially - */ - PolynomialMod2(word value, size_t bitLength=WORD_BITS); - - //! convert from big-endian byte array - PolynomialMod2(const byte *encodedPoly, size_t byteCount) - {Decode(encodedPoly, byteCount);} - - //! convert from big-endian form stored in a BufferedTransformation - PolynomialMod2(BufferedTransformation &encodedPoly, size_t byteCount) - {Decode(encodedPoly, byteCount);} - - //! create a random polynomial uniformly distributed over all polynomials with degree less than bitcount - PolynomialMod2(RandomNumberGenerator &rng, size_t bitcount) - {Randomize(rng, bitcount);} - - //! return x^i - static PolynomialMod2 CRYPTOPP_API Monomial(size_t i); - //! return x^t0 + x^t1 + x^t2 - static PolynomialMod2 CRYPTOPP_API Trinomial(size_t t0, size_t t1, size_t t2); - //! return x^t0 + x^t1 + x^t2 + x^t3 + x^t4 - static PolynomialMod2 CRYPTOPP_API Pentanomial(size_t t0, size_t t1, size_t t2, size_t t3, size_t t4); - //! return x^(n-1) + ... + x + 1 - static PolynomialMod2 CRYPTOPP_API AllOnes(size_t n); - - //! - static const PolynomialMod2 & CRYPTOPP_API Zero(); - //! - static const PolynomialMod2 & CRYPTOPP_API One(); - //@} - - //! \name ENCODE/DECODE - //@{ - //! minimum number of bytes to encode this polynomial - /*! MinEncodedSize of 0 is 1 */ - unsigned int MinEncodedSize() const {return STDMAX(1U, ByteCount());} - - //! encode in big-endian format - /*! if outputLen < MinEncodedSize, the most significant bytes will be dropped - if outputLen > MinEncodedSize, the most significant bytes will be padded - */ - void Encode(byte *output, size_t outputLen) const; - //! - void Encode(BufferedTransformation &bt, size_t outputLen) const; - - //! - void Decode(const byte *input, size_t inputLen); - //! - //* Precondition: bt.MaxRetrievable() >= inputLen - void Decode(BufferedTransformation &bt, size_t inputLen); - - //! encode value as big-endian octet string - void DEREncodeAsOctetString(BufferedTransformation &bt, size_t length) const; - //! decode value as big-endian octet string - void BERDecodeAsOctetString(BufferedTransformation &bt, size_t length); - //@} - - //! \name ACCESSORS - //@{ - //! number of significant bits = Degree() + 1 - unsigned int BitCount() const; - //! number of significant bytes = ceiling(BitCount()/8) - unsigned int ByteCount() const; - //! number of significant words = ceiling(ByteCount()/sizeof(word)) - unsigned int WordCount() const; - - //! return the n-th bit, n=0 being the least significant bit - bool GetBit(size_t n) const {return GetCoefficient(n)!=0;} - //! return the n-th byte - byte GetByte(size_t n) const; - - //! the zero polynomial will return a degree of -1 - signed int Degree() const {return BitCount()-1;} - //! degree + 1 - unsigned int CoefficientCount() const {return BitCount();} - //! return coefficient for x^i - int GetCoefficient(size_t i) const - {return (i/WORD_BITS < reg.size()) ? int(reg[i/WORD_BITS] >> (i % WORD_BITS)) & 1 : 0;} - //! return coefficient for x^i - int operator[](unsigned int i) const {return GetCoefficient(i);} - - //! - bool IsZero() const {return !*this;} - //! - bool Equals(const PolynomialMod2 &rhs) const; - //@} - - //! \name MANIPULATORS - //@{ - //! - PolynomialMod2& operator=(const PolynomialMod2& t); - //! - PolynomialMod2& operator&=(const PolynomialMod2& t); - //! - PolynomialMod2& operator^=(const PolynomialMod2& t); - //! - PolynomialMod2& operator+=(const PolynomialMod2& t) {return *this ^= t;} - //! - PolynomialMod2& operator-=(const PolynomialMod2& t) {return *this ^= t;} - //! - PolynomialMod2& operator*=(const PolynomialMod2& t); - //! - PolynomialMod2& operator/=(const PolynomialMod2& t); - //! - PolynomialMod2& operator%=(const PolynomialMod2& t); - //! - PolynomialMod2& operator<<=(unsigned int); - //! - PolynomialMod2& operator>>=(unsigned int); - - //! - void Randomize(RandomNumberGenerator &rng, size_t bitcount); - - //! - void SetBit(size_t i, int value = 1); - //! set the n-th byte to value - void SetByte(size_t n, byte value); - - //! - void SetCoefficient(size_t i, int value) {SetBit(i, value);} - - //! - void swap(PolynomialMod2 &a) {reg.swap(a.reg);} - //@} - - //! \name UNARY OPERATORS - //@{ - //! - bool operator!() const; - //! - PolynomialMod2 operator+() const {return *this;} - //! - PolynomialMod2 operator-() const {return *this;} - //@} - - //! \name BINARY OPERATORS - //@{ - //! - PolynomialMod2 And(const PolynomialMod2 &b) const; - //! - PolynomialMod2 Xor(const PolynomialMod2 &b) const; - //! - PolynomialMod2 Plus(const PolynomialMod2 &b) const {return Xor(b);} - //! - PolynomialMod2 Minus(const PolynomialMod2 &b) const {return Xor(b);} - //! - PolynomialMod2 Times(const PolynomialMod2 &b) const; - //! - PolynomialMod2 DividedBy(const PolynomialMod2 &b) const; - //! - PolynomialMod2 Modulo(const PolynomialMod2 &b) const; - - //! - PolynomialMod2 operator>>(unsigned int n) const; - //! - PolynomialMod2 operator<<(unsigned int n) const; - //@} - - //! \name OTHER ARITHMETIC FUNCTIONS - //@{ - //! sum modulo 2 of all coefficients - unsigned int Parity() const; - - //! check for irreducibility - bool IsIrreducible() const; - - //! is always zero since we're working modulo 2 - PolynomialMod2 Doubled() const {return Zero();} - //! - PolynomialMod2 Squared() const; - - //! only 1 is a unit - bool IsUnit() const {return Equals(One());} - //! return inverse if *this is a unit, otherwise return 0 - PolynomialMod2 MultiplicativeInverse() const {return IsUnit() ? One() : Zero();} - - //! greatest common divisor - static PolynomialMod2 CRYPTOPP_API Gcd(const PolynomialMod2 &a, const PolynomialMod2 &n); - //! calculate multiplicative inverse of *this mod n - PolynomialMod2 InverseMod(const PolynomialMod2 &) const; - - //! calculate r and q such that (a == d*q + r) && (deg(r) < deg(d)) - static void CRYPTOPP_API Divide(PolynomialMod2 &r, PolynomialMod2 &q, const PolynomialMod2 &a, const PolynomialMod2 &d); - //@} - - //! \name INPUT/OUTPUT - //@{ - //! - friend std::ostream& operator<<(std::ostream& out, const PolynomialMod2 &a); - //@} - -private: - friend class GF2NT; - - SecWordBlock reg; -}; - -//! -inline bool operator==(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) -{return a.Equals(b);} -//! -inline bool operator!=(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) -{return !(a==b);} -//! compares degree -inline bool operator> (const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) -{return a.Degree() > b.Degree();} -//! compares degree -inline bool operator>=(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) -{return a.Degree() >= b.Degree();} -//! compares degree -inline bool operator< (const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) -{return a.Degree() < b.Degree();} -//! compares degree -inline bool operator<=(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) -{return a.Degree() <= b.Degree();} -//! -inline CryptoPP::PolynomialMod2 operator&(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.And(b);} -//! -inline CryptoPP::PolynomialMod2 operator^(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.Xor(b);} -//! -inline CryptoPP::PolynomialMod2 operator+(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.Plus(b);} -//! -inline CryptoPP::PolynomialMod2 operator-(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.Minus(b);} -//! -inline CryptoPP::PolynomialMod2 operator*(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.Times(b);} -//! -inline CryptoPP::PolynomialMod2 operator/(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.DividedBy(b);} -//! -inline CryptoPP::PolynomialMod2 operator%(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.Modulo(b);} - -// CodeWarrior 8 workaround: put these template instantiations after overloaded operator declarations, -// but before the use of QuotientRing > for VC .NET 2003 -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractGroup; -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractRing; -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractEuclideanDomain; -CRYPTOPP_DLL_TEMPLATE_CLASS EuclideanDomainOf; -CRYPTOPP_DLL_TEMPLATE_CLASS QuotientRing >; - -//! GF(2^n) with Polynomial Basis -class CRYPTOPP_DLL GF2NP : public QuotientRing > -{ -public: - GF2NP(const PolynomialMod2 &modulus); - - virtual GF2NP * Clone() const {return new GF2NP(*this);} - virtual void DEREncode(BufferedTransformation &bt) const - {assert(false);} // no ASN.1 syntax yet for general polynomial basis - - void DEREncodeElement(BufferedTransformation &out, const Element &a) const; - void BERDecodeElement(BufferedTransformation &in, Element &a) const; - - bool Equal(const Element &a, const Element &b) const - {assert(a.Degree() < m_modulus.Degree() && b.Degree() < m_modulus.Degree()); return a.Equals(b);} - - bool IsUnit(const Element &a) const - {assert(a.Degree() < m_modulus.Degree()); return !!a;} - - unsigned int MaxElementBitLength() const - {return m;} - - unsigned int MaxElementByteLength() const - {return (unsigned int)BitsToBytes(MaxElementBitLength());} - - Element SquareRoot(const Element &a) const; - - Element HalfTrace(const Element &a) const; - - // returns z such that z^2 + z == a - Element SolveQuadraticEquation(const Element &a) const; - -protected: - unsigned int m; -}; - -//! GF(2^n) with Trinomial Basis -class CRYPTOPP_DLL GF2NT : public GF2NP -{ -public: - // polynomial modulus = x^t0 + x^t1 + x^t2, t0 > t1 > t2 - GF2NT(unsigned int t0, unsigned int t1, unsigned int t2); - - GF2NP * Clone() const {return new GF2NT(*this);} - void DEREncode(BufferedTransformation &bt) const; - - const Element& Multiply(const Element &a, const Element &b) const; - - const Element& Square(const Element &a) const - {return Reduced(a.Squared());} - - const Element& MultiplicativeInverse(const Element &a) const; - -private: - const Element& Reduced(const Element &a) const; - - unsigned int t0, t1; - mutable PolynomialMod2 result; -}; - -//! GF(2^n) with Pentanomial Basis -class CRYPTOPP_DLL GF2NPP : public GF2NP -{ -public: - // polynomial modulus = x^t0 + x^t1 + x^t2 + x^t3 + x^t4, t0 > t1 > t2 > t3 > t4 - GF2NPP(unsigned int t0, unsigned int t1, unsigned int t2, unsigned int t3, unsigned int t4) - : GF2NP(PolynomialMod2::Pentanomial(t0, t1, t2, t3, t4)), t0(t0), t1(t1), t2(t2), t3(t3) {} - - GF2NP * Clone() const {return new GF2NPP(*this);} - void DEREncode(BufferedTransformation &bt) const; - -private: - unsigned int t0, t1, t2, t3; -}; - -// construct new GF2NP from the ASN.1 sequence Characteristic-two -CRYPTOPP_DLL GF2NP * CRYPTOPP_API BERDecodeGF2NP(BufferedTransformation &bt); - -NAMESPACE_END - -#ifndef __BORLANDC__ -NAMESPACE_BEGIN(std) -template<> inline void swap(CryptoPP::PolynomialMod2 &a, CryptoPP::PolynomialMod2 &b) -{ - a.swap(b); -} -NAMESPACE_END -#endif - -#endif diff --git a/lib/cryptopp/gfpcrypt.cpp b/lib/cryptopp/gfpcrypt.cpp deleted file mode 100644 index e293fc598..000000000 --- a/lib/cryptopp/gfpcrypt.cpp +++ /dev/null @@ -1,273 +0,0 @@ -// dsa.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "gfpcrypt.h" -#include "asn.h" -#include "oids.h" -#include "nbtheory.h" - -NAMESPACE_BEGIN(CryptoPP) - -void TestInstantiations_gfpcrypt() -{ - GDSA::Signer test; - GDSA::Verifier test1; - DSA::Signer test5(NullRNG(), 100); - DSA::Signer test2(test5); - NR::Signer test3; - NR::Verifier test4; - DLIES<>::Encryptor test6; - DLIES<>::Decryptor test7; -} - -void DL_GroupParameters_DSA::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg) -{ - Integer p, q, g; - - if (alg.GetValue("Modulus", p) && alg.GetValue("SubgroupGenerator", g)) - { - q = alg.GetValueWithDefault("SubgroupOrder", ComputeGroupOrder(p)/2); - Initialize(p, q, g); - } - else - { - int modulusSize = 1024, defaultSubgroupOrderSize; - alg.GetIntValue("ModulusSize", modulusSize) || alg.GetIntValue("KeySize", modulusSize); - - switch (modulusSize) - { - case 1024: - defaultSubgroupOrderSize = 160; - break; - case 2048: - defaultSubgroupOrderSize = 224; - break; - case 3072: - defaultSubgroupOrderSize = 256; - break; - default: - throw InvalidArgument("DSA: not a valid prime length"); - } - - DL_GroupParameters_GFP::GenerateRandom(rng, CombinedNameValuePairs(alg, MakeParameters(Name::SubgroupOrderSize(), defaultSubgroupOrderSize, false))); - } -} - -bool DL_GroupParameters_DSA::ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = DL_GroupParameters_GFP::ValidateGroup(rng, level); - int pSize = GetModulus().BitCount(), qSize = GetSubgroupOrder().BitCount(); - pass = pass && ((pSize==1024 && qSize==160) || (pSize==2048 && qSize==224) || (pSize==2048 && qSize==256) || (pSize==3072 && qSize==256)); - return pass; -} - -void DL_SignatureMessageEncodingMethod_DSA::ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const -{ - assert(recoverableMessageLength == 0); - assert(hashIdentifier.second == 0); - const size_t representativeByteLength = BitsToBytes(representativeBitLength); - const size_t digestSize = hash.DigestSize(); - const size_t paddingLength = SaturatingSubtract(representativeByteLength, digestSize); - - memset(representative, 0, paddingLength); - hash.TruncatedFinal(representative+paddingLength, STDMIN(representativeByteLength, digestSize)); - - if (digestSize*8 > representativeBitLength) - { - Integer h(representative, representativeByteLength); - h >>= representativeByteLength*8 - representativeBitLength; - h.Encode(representative, representativeByteLength); - } -} - -void DL_SignatureMessageEncodingMethod_NR::ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const -{ - assert(recoverableMessageLength == 0); - assert(hashIdentifier.second == 0); - const size_t representativeByteLength = BitsToBytes(representativeBitLength); - const size_t digestSize = hash.DigestSize(); - const size_t paddingLength = SaturatingSubtract(representativeByteLength, digestSize); - - memset(representative, 0, paddingLength); - hash.TruncatedFinal(representative+paddingLength, STDMIN(representativeByteLength, digestSize)); - - if (digestSize*8 >= representativeBitLength) - { - Integer h(representative, representativeByteLength); - h >>= representativeByteLength*8 - representativeBitLength + 1; - h.Encode(representative, representativeByteLength); - } -} - -bool DL_GroupParameters_IntegerBased::ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const -{ - const Integer &p = GetModulus(), &q = GetSubgroupOrder(); - - bool pass = true; - pass = pass && p > Integer::One() && p.IsOdd(); - pass = pass && q > Integer::One() && q.IsOdd(); - - if (level >= 1) - pass = pass && GetCofactor() > Integer::One() && GetGroupOrder() % q == Integer::Zero(); - if (level >= 2) - pass = pass && VerifyPrime(rng, q, level-2) && VerifyPrime(rng, p, level-2); - - return pass; -} - -bool DL_GroupParameters_IntegerBased::ValidateElement(unsigned int level, const Integer &g, const DL_FixedBasePrecomputation *gpc) const -{ - const Integer &p = GetModulus(), &q = GetSubgroupOrder(); - - bool pass = true; - pass = pass && GetFieldType() == 1 ? g.IsPositive() : g.NotNegative(); - pass = pass && g < p && !IsIdentity(g); - - if (level >= 1) - { - if (gpc) - pass = pass && gpc->Exponentiate(GetGroupPrecomputation(), Integer::One()) == g; - } - if (level >= 2) - { - if (GetFieldType() == 2) - pass = pass && Jacobi(g*g-4, p)==-1; - - // verifying that Lucas((p+1)/2, w, p)==2 is omitted because it's too costly - // and at most 1 bit is leaked if it's false - bool fullValidate = (GetFieldType() == 2 && level >= 3) || !FastSubgroupCheckAvailable(); - - if (fullValidate && pass) - { - Integer gp = gpc ? gpc->Exponentiate(GetGroupPrecomputation(), q) : ExponentiateElement(g, q); - pass = pass && IsIdentity(gp); - } - else if (GetFieldType() == 1) - pass = pass && Jacobi(g, p) == 1; - } - - return pass; -} - -void DL_GroupParameters_IntegerBased::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg) -{ - Integer p, q, g; - - if (alg.GetValue("Modulus", p) && alg.GetValue("SubgroupGenerator", g)) - { - q = alg.GetValueWithDefault("SubgroupOrder", ComputeGroupOrder(p)/2); - } - else - { - int modulusSize, subgroupOrderSize; - - if (!alg.GetIntValue("ModulusSize", modulusSize)) - modulusSize = alg.GetIntValueWithDefault("KeySize", 2048); - - if (!alg.GetIntValue("SubgroupOrderSize", subgroupOrderSize)) - subgroupOrderSize = GetDefaultSubgroupOrderSize(modulusSize); - - PrimeAndGenerator pg; - pg.Generate(GetFieldType() == 1 ? 1 : -1, rng, modulusSize, subgroupOrderSize); - p = pg.Prime(); - q = pg.SubPrime(); - g = pg.Generator(); - } - - Initialize(p, q, g); -} - -Integer DL_GroupParameters_IntegerBased::DecodeElement(const byte *encoded, bool checkForGroupMembership) const -{ - Integer g(encoded, GetModulus().ByteCount()); - if (!ValidateElement(1, g, NULL)) - throw DL_BadElement(); - return g; -} - -void DL_GroupParameters_IntegerBased::BERDecode(BufferedTransformation &bt) -{ - BERSequenceDecoder parameters(bt); - Integer p(parameters); - Integer q(parameters); - Integer g; - if (parameters.EndReached()) - { - g = q; - q = ComputeGroupOrder(p) / 2; - } - else - g.BERDecode(parameters); - parameters.MessageEnd(); - - SetModulusAndSubgroupGenerator(p, g); - SetSubgroupOrder(q); -} - -void DL_GroupParameters_IntegerBased::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder parameters(bt); - GetModulus().DEREncode(parameters); - m_q.DEREncode(parameters); - GetSubgroupGenerator().DEREncode(parameters); - parameters.MessageEnd(); -} - -bool DL_GroupParameters_IntegerBased::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - return GetValueHelper >(this, name, valueType, pValue) - CRYPTOPP_GET_FUNCTION_ENTRY(Modulus); -} - -void DL_GroupParameters_IntegerBased::AssignFrom(const NameValuePairs &source) -{ - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY2(Modulus, SubgroupGenerator) - CRYPTOPP_SET_FUNCTION_ENTRY(SubgroupOrder) - ; -} - -OID DL_GroupParameters_IntegerBased::GetAlgorithmID() const -{ - return ASN1::id_dsa(); -} - -void DL_GroupParameters_GFP::SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const -{ - ModularArithmetic ma(GetModulus()); - ma.SimultaneousExponentiate(results, base, exponents, exponentsCount); -} - -DL_GroupParameters_GFP::Element DL_GroupParameters_GFP::MultiplyElements(const Element &a, const Element &b) const -{ - return a_times_b_mod_c(a, b, GetModulus()); -} - -DL_GroupParameters_GFP::Element DL_GroupParameters_GFP::CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const -{ - ModularArithmetic ma(GetModulus()); - return ma.CascadeExponentiate(element1, exponent1, element2, exponent2); -} - -Integer DL_GroupParameters_IntegerBased::GetMaxExponent() const -{ - return STDMIN(GetSubgroupOrder()-1, Integer::Power2(2*DiscreteLogWorkFactor(GetFieldType()*GetModulus().BitCount()))); -} - -unsigned int DL_GroupParameters_IntegerBased::GetDefaultSubgroupOrderSize(unsigned int modulusSize) const -{ - return 2*DiscreteLogWorkFactor(GetFieldType()*modulusSize); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/gfpcrypt.h b/lib/cryptopp/gfpcrypt.h deleted file mode 100644 index 7af993fb3..000000000 --- a/lib/cryptopp/gfpcrypt.h +++ /dev/null @@ -1,528 +0,0 @@ -#ifndef CRYPTOPP_GFPCRYPT_H -#define CRYPTOPP_GFPCRYPT_H - -/** \file - Implementation of schemes based on DL over GF(p) -*/ - -#include "pubkey.h" -#include "modexppc.h" -#include "sha.h" -#include "algparam.h" -#include "asn.h" -#include "smartptr.h" -#include "hmac.h" - -#include - -NAMESPACE_BEGIN(CryptoPP) - -CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters; - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE DL_GroupParameters_IntegerBased : public ASN1CryptoMaterial > -{ - typedef DL_GroupParameters_IntegerBased ThisClass; - -public: - void Initialize(const DL_GroupParameters_IntegerBased ¶ms) - {Initialize(params.GetModulus(), params.GetSubgroupOrder(), params.GetSubgroupGenerator());} - void Initialize(RandomNumberGenerator &rng, unsigned int pbits) - {GenerateRandom(rng, MakeParameters("ModulusSize", (int)pbits));} - void Initialize(const Integer &p, const Integer &g) - {SetModulusAndSubgroupGenerator(p, g); SetSubgroupOrder(ComputeGroupOrder(p)/2);} - void Initialize(const Integer &p, const Integer &q, const Integer &g) - {SetModulusAndSubgroupGenerator(p, g); SetSubgroupOrder(q);} - - // ASN1Object interface - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - // GeneratibleCryptoMaterial interface - /*! parameters: (ModulusSize, SubgroupOrderSize (optional)) */ - void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - - // DL_GroupParameters - const Integer & GetSubgroupOrder() const {return m_q;} - Integer GetGroupOrder() const {return GetFieldType() == 1 ? GetModulus()-Integer::One() : GetModulus()+Integer::One();} - bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const; - bool ValidateElement(unsigned int level, const Integer &element, const DL_FixedBasePrecomputation *precomp) const; - bool FastSubgroupCheckAvailable() const {return GetCofactor() == 2;} - void EncodeElement(bool reversible, const Element &element, byte *encoded) const - {element.Encode(encoded, GetModulus().ByteCount());} - unsigned int GetEncodedElementSize(bool reversible) const {return GetModulus().ByteCount();} - Integer DecodeElement(const byte *encoded, bool checkForGroupMembership) const; - Integer ConvertElementToInteger(const Element &element) const - {return element;} - Integer GetMaxExponent() const; - static std::string CRYPTOPP_API StaticAlgorithmNamePrefix() {return "";} - - OID GetAlgorithmID() const; - - virtual const Integer & GetModulus() const =0; - virtual void SetModulusAndSubgroupGenerator(const Integer &p, const Integer &g) =0; - - void SetSubgroupOrder(const Integer &q) - {m_q = q; ParametersChanged();} - -protected: - Integer ComputeGroupOrder(const Integer &modulus) const - {return modulus-(GetFieldType() == 1 ? 1 : -1);} - - // GF(p) = 1, GF(p^2) = 2 - virtual int GetFieldType() const =0; - virtual unsigned int GetDefaultSubgroupOrderSize(unsigned int modulusSize) const; - -private: - Integer m_q; -}; - -//! _ -template > -class CRYPTOPP_NO_VTABLE DL_GroupParameters_IntegerBasedImpl : public DL_GroupParametersImpl -{ - typedef DL_GroupParameters_IntegerBasedImpl ThisClass; - -public: - typedef typename GROUP_PRECOMP::Element Element; - - // GeneratibleCryptoMaterial interface - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const - {return GetValueHelper(this, name, valueType, pValue).Assignable();} - - void AssignFrom(const NameValuePairs &source) - {AssignFromHelper(this, source);} - - // DL_GroupParameters - const DL_FixedBasePrecomputation & GetBasePrecomputation() const {return this->m_gpc;} - DL_FixedBasePrecomputation & AccessBasePrecomputation() {return this->m_gpc;} - - // IntegerGroupParameters - const Integer & GetModulus() const {return this->m_groupPrecomputation.GetModulus();} - const Integer & GetGenerator() const {return this->m_gpc.GetBase(this->GetGroupPrecomputation());} - - void SetModulusAndSubgroupGenerator(const Integer &p, const Integer &g) // these have to be set together - {this->m_groupPrecomputation.SetModulus(p); this->m_gpc.SetBase(this->GetGroupPrecomputation(), g); this->ParametersChanged();} - - // non-inherited - bool operator==(const DL_GroupParameters_IntegerBasedImpl &rhs) const - {return GetModulus() == rhs.GetModulus() && GetGenerator() == rhs.GetGenerator() && this->GetSubgroupOrder() == rhs.GetSubgroupOrder();} - bool operator!=(const DL_GroupParameters_IntegerBasedImpl &rhs) const - {return !operator==(rhs);} -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_IntegerBasedImpl; - -//! GF(p) group parameters -class CRYPTOPP_DLL DL_GroupParameters_GFP : public DL_GroupParameters_IntegerBasedImpl -{ -public: - // DL_GroupParameters - bool IsIdentity(const Integer &element) const {return element == Integer::One();} - void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const; - - // NameValuePairs interface - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const - { - return GetValueHelper(this, name, valueType, pValue).Assignable(); - } - - // used by MQV - Element MultiplyElements(const Element &a, const Element &b) const; - Element CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const; - -protected: - int GetFieldType() const {return 1;} -}; - -//! GF(p) group parameters that default to same primes -class CRYPTOPP_DLL DL_GroupParameters_GFP_DefaultSafePrime : public DL_GroupParameters_GFP -{ -public: - typedef NoCofactorMultiplication DefaultCofactorOption; - -protected: - unsigned int GetDefaultSubgroupOrderSize(unsigned int modulusSize) const {return modulusSize-1;} -}; - -//! GDSA algorithm -template -class DL_Algorithm_GDSA : public DL_ElgamalLikeSignatureAlgorithm -{ -public: - static const char * CRYPTOPP_API StaticAlgorithmName() {return "DSA-1363";} - - void Sign(const DL_GroupParameters ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const - { - const Integer &q = params.GetSubgroupOrder(); - r %= q; - Integer kInv = k.InverseMod(q); - s = (kInv * (x*r + e)) % q; - assert(!!r && !!s); - } - - bool Verify(const DL_GroupParameters ¶ms, const DL_PublicKey &publicKey, const Integer &e, const Integer &r, const Integer &s) const - { - const Integer &q = params.GetSubgroupOrder(); - if (r>=q || r<1 || s>=q || s<1) - return false; - - Integer w = s.InverseMod(q); - Integer u1 = (e * w) % q; - Integer u2 = (r * w) % q; - // verify r == (g^u1 * y^u2 mod p) mod q - return r == params.ConvertElementToInteger(publicKey.CascadeExponentiateBaseAndPublicElement(u1, u2)) % q; - } -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA; - -//! NR algorithm -template -class DL_Algorithm_NR : public DL_ElgamalLikeSignatureAlgorithm -{ -public: - static const char * CRYPTOPP_API StaticAlgorithmName() {return "NR";} - - void Sign(const DL_GroupParameters ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const - { - const Integer &q = params.GetSubgroupOrder(); - r = (r + e) % q; - s = (k - x*r) % q; - assert(!!r); - } - - bool Verify(const DL_GroupParameters ¶ms, const DL_PublicKey &publicKey, const Integer &e, const Integer &r, const Integer &s) const - { - const Integer &q = params.GetSubgroupOrder(); - if (r>=q || r<1 || s>=q) - return false; - - // check r == (m_g^s * m_y^r + m) mod m_q - return r == (params.ConvertElementToInteger(publicKey.CascadeExponentiateBaseAndPublicElement(s, r)) + e) % q; - } -}; - -/*! DSA public key format is defined in 7.3.3 of RFC 2459. The - private key format is defined in 12.9 of PKCS #11 v2.10. */ -template -class DL_PublicKey_GFP : public DL_PublicKeyImpl -{ -public: - void Initialize(const DL_GroupParameters_IntegerBased ¶ms, const Integer &y) - {this->AccessGroupParameters().Initialize(params); this->SetPublicElement(y);} - void Initialize(const Integer &p, const Integer &g, const Integer &y) - {this->AccessGroupParameters().Initialize(p, g); this->SetPublicElement(y);} - void Initialize(const Integer &p, const Integer &q, const Integer &g, const Integer &y) - {this->AccessGroupParameters().Initialize(p, q, g); this->SetPublicElement(y);} - - // X509PublicKey - void BERDecodePublicKey(BufferedTransformation &bt, bool, size_t) - {this->SetPublicElement(Integer(bt));} - void DEREncodePublicKey(BufferedTransformation &bt) const - {this->GetPublicElement().DEREncode(bt);} -}; - -//! DL private key (in GF(p) groups) -template -class DL_PrivateKey_GFP : public DL_PrivateKeyImpl -{ -public: - void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits) - {this->GenerateRandomWithKeySize(rng, modulusBits);} - void Initialize(RandomNumberGenerator &rng, const Integer &p, const Integer &g) - {this->GenerateRandom(rng, MakeParameters("Modulus", p)("SubgroupGenerator", g));} - void Initialize(RandomNumberGenerator &rng, const Integer &p, const Integer &q, const Integer &g) - {this->GenerateRandom(rng, MakeParameters("Modulus", p)("SubgroupOrder", q)("SubgroupGenerator", g));} - void Initialize(const DL_GroupParameters_IntegerBased ¶ms, const Integer &x) - {this->AccessGroupParameters().Initialize(params); this->SetPrivateExponent(x);} - void Initialize(const Integer &p, const Integer &g, const Integer &x) - {this->AccessGroupParameters().Initialize(p, g); this->SetPrivateExponent(x);} - void Initialize(const Integer &p, const Integer &q, const Integer &g, const Integer &x) - {this->AccessGroupParameters().Initialize(p, q, g); this->SetPrivateExponent(x);} -}; - -//! DL signing/verification keys (in GF(p) groups) -struct DL_SignatureKeys_GFP -{ - typedef DL_GroupParameters_GFP GroupParameters; - typedef DL_PublicKey_GFP PublicKey; - typedef DL_PrivateKey_GFP PrivateKey; -}; - -//! DL encryption/decryption keys (in GF(p) groups) -struct DL_CryptoKeys_GFP -{ - typedef DL_GroupParameters_GFP_DefaultSafePrime GroupParameters; - typedef DL_PublicKey_GFP PublicKey; - typedef DL_PrivateKey_GFP PrivateKey; -}; - -//! provided for backwards compatibility, this class uses the old non-standard Crypto++ key format -template -class DL_PublicKey_GFP_OldFormat : public BASE -{ -public: - void BERDecode(BufferedTransformation &bt) - { - BERSequenceDecoder seq(bt); - Integer v1(seq); - Integer v2(seq); - Integer v3(seq); - - if (seq.EndReached()) - { - this->AccessGroupParameters().Initialize(v1, v1/2, v2); - this->SetPublicElement(v3); - } - else - { - Integer v4(seq); - this->AccessGroupParameters().Initialize(v1, v2, v3); - this->SetPublicElement(v4); - } - - seq.MessageEnd(); - } - - void DEREncode(BufferedTransformation &bt) const - { - DERSequenceEncoder seq(bt); - this->GetGroupParameters().GetModulus().DEREncode(seq); - if (this->GetGroupParameters().GetCofactor() != 2) - this->GetGroupParameters().GetSubgroupOrder().DEREncode(seq); - this->GetGroupParameters().GetGenerator().DEREncode(seq); - this->GetPublicElement().DEREncode(seq); - seq.MessageEnd(); - } -}; - -//! provided for backwards compatibility, this class uses the old non-standard Crypto++ key format -template -class DL_PrivateKey_GFP_OldFormat : public BASE -{ -public: - void BERDecode(BufferedTransformation &bt) - { - BERSequenceDecoder seq(bt); - Integer v1(seq); - Integer v2(seq); - Integer v3(seq); - Integer v4(seq); - - if (seq.EndReached()) - { - this->AccessGroupParameters().Initialize(v1, v1/2, v2); - this->SetPrivateExponent(v4 % (v1/2)); // some old keys may have x >= q - } - else - { - Integer v5(seq); - this->AccessGroupParameters().Initialize(v1, v2, v3); - this->SetPrivateExponent(v5); - } - - seq.MessageEnd(); - } - - void DEREncode(BufferedTransformation &bt) const - { - DERSequenceEncoder seq(bt); - this->GetGroupParameters().GetModulus().DEREncode(seq); - if (this->GetGroupParameters().GetCofactor() != 2) - this->GetGroupParameters().GetSubgroupOrder().DEREncode(seq); - this->GetGroupParameters().GetGenerator().DEREncode(seq); - this->GetGroupParameters().ExponentiateBase(this->GetPrivateExponent()).DEREncode(seq); - this->GetPrivateExponent().DEREncode(seq); - seq.MessageEnd(); - } -}; - -//! DSA-1363 -template -struct GDSA : public DL_SS< - DL_SignatureKeys_GFP, - DL_Algorithm_GDSA, - DL_SignatureMessageEncodingMethod_DSA, - H> -{ -}; - -//! NR -template -struct NR : public DL_SS< - DL_SignatureKeys_GFP, - DL_Algorithm_NR, - DL_SignatureMessageEncodingMethod_NR, - H> -{ -}; - -//! DSA group parameters, these are GF(p) group parameters that are allowed by the DSA standard -class CRYPTOPP_DLL DL_GroupParameters_DSA : public DL_GroupParameters_GFP -{ -public: - /*! also checks that the lengths of p and q are allowed by the DSA standard */ - bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const; - /*! parameters: (ModulusSize), or (Modulus, SubgroupOrder, SubgroupGenerator) */ - /*! ModulusSize must be between DSA::MIN_PRIME_LENGTH and DSA::MAX_PRIME_LENGTH, and divisible by DSA::PRIME_LENGTH_MULTIPLE */ - void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); - - static bool CRYPTOPP_API IsValidPrimeLength(unsigned int pbits) - {return pbits >= MIN_PRIME_LENGTH && pbits <= MAX_PRIME_LENGTH && pbits % PRIME_LENGTH_MULTIPLE == 0;} - - enum {MIN_PRIME_LENGTH = 1024, MAX_PRIME_LENGTH = 3072, PRIME_LENGTH_MULTIPLE = 1024}; -}; - -template -class DSA2; - -//! DSA keys -struct DL_Keys_DSA -{ - typedef DL_PublicKey_GFP PublicKey; - typedef DL_PrivateKey_WithSignaturePairwiseConsistencyTest, DSA2 > PrivateKey; -}; - -//! DSA, as specified in FIPS 186-3 -// class named DSA2 instead of DSA for backwards compatibility (DSA was a non-template class) -template -class DSA2 : public DL_SS< - DL_Keys_DSA, - DL_Algorithm_GDSA, - DL_SignatureMessageEncodingMethod_DSA, - H, - DSA2 > -{ -public: - static std::string CRYPTOPP_API StaticAlgorithmName() {return "DSA/" + (std::string)H::StaticAlgorithmName();} -}; - -//! DSA with SHA-1, typedef'd for backwards compatibility -typedef DSA2 DSA; - -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_GFP; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_GFP; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, DSA2 >; - -//! the XOR encryption method, for use with DL-based cryptosystems -template -class DL_EncryptionAlgorithm_Xor : public DL_SymmetricEncryptionAlgorithm -{ -public: - bool ParameterSupported(const char *name) const {return strcmp(name, Name::EncodingParameters()) == 0;} - size_t GetSymmetricKeyLength(size_t plaintextLength) const - {return plaintextLength + MAC::DEFAULT_KEYLENGTH;} - size_t GetSymmetricCiphertextLength(size_t plaintextLength) const - {return plaintextLength + MAC::DIGESTSIZE;} - size_t GetMaxSymmetricPlaintextLength(size_t ciphertextLength) const - {return (unsigned int)SaturatingSubtract(ciphertextLength, (unsigned int)MAC::DIGESTSIZE);} - void SymmetricEncrypt(RandomNumberGenerator &rng, const byte *key, const byte *plaintext, size_t plaintextLength, byte *ciphertext, const NameValuePairs ¶meters) const - { - const byte *cipherKey, *macKey; - if (DHAES_MODE) - { - macKey = key; - cipherKey = key + MAC::DEFAULT_KEYLENGTH; - } - else - { - cipherKey = key; - macKey = key + plaintextLength; - } - - ConstByteArrayParameter encodingParameters; - parameters.GetValue(Name::EncodingParameters(), encodingParameters); - - xorbuf(ciphertext, plaintext, cipherKey, plaintextLength); - MAC mac(macKey); - mac.Update(ciphertext, plaintextLength); - mac.Update(encodingParameters.begin(), encodingParameters.size()); - if (DHAES_MODE) - { - byte L[8] = {0,0,0,0}; - PutWord(false, BIG_ENDIAN_ORDER, L+4, word32(encodingParameters.size())); - mac.Update(L, 8); - } - mac.Final(ciphertext + plaintextLength); - } - DecodingResult SymmetricDecrypt(const byte *key, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters) const - { - size_t plaintextLength = GetMaxSymmetricPlaintextLength(ciphertextLength); - const byte *cipherKey, *macKey; - if (DHAES_MODE) - { - macKey = key; - cipherKey = key + MAC::DEFAULT_KEYLENGTH; - } - else - { - cipherKey = key; - macKey = key + plaintextLength; - } - - ConstByteArrayParameter encodingParameters; - parameters.GetValue(Name::EncodingParameters(), encodingParameters); - - MAC mac(macKey); - mac.Update(ciphertext, plaintextLength); - mac.Update(encodingParameters.begin(), encodingParameters.size()); - if (DHAES_MODE) - { - byte L[8] = {0,0,0,0}; - PutWord(false, BIG_ENDIAN_ORDER, L+4, word32(encodingParameters.size())); - mac.Update(L, 8); - } - if (!mac.Verify(ciphertext + plaintextLength)) - return DecodingResult(); - - xorbuf(plaintext, ciphertext, cipherKey, plaintextLength); - return DecodingResult(plaintextLength); - } -}; - -//! _ -template -class DL_KeyDerivationAlgorithm_P1363 : public DL_KeyDerivationAlgorithm -{ -public: - bool ParameterSupported(const char *name) const {return strcmp(name, Name::KeyDerivationParameters()) == 0;} - void Derive(const DL_GroupParameters ¶ms, byte *derivedKey, size_t derivedLength, const T &agreedElement, const T &ephemeralPublicKey, const NameValuePairs ¶meters) const - { - SecByteBlock agreedSecret; - if (DHAES_MODE) - { - agreedSecret.New(params.GetEncodedElementSize(true) + params.GetEncodedElementSize(false)); - params.EncodeElement(true, ephemeralPublicKey, agreedSecret); - params.EncodeElement(false, agreedElement, agreedSecret + params.GetEncodedElementSize(true)); - } - else - { - agreedSecret.New(params.GetEncodedElementSize(false)); - params.EncodeElement(false, agreedElement, agreedSecret); - } - - ConstByteArrayParameter derivationParameters; - parameters.GetValue(Name::KeyDerivationParameters(), derivationParameters); - KDF::DeriveKey(derivedKey, derivedLength, agreedSecret, agreedSecret.size(), derivationParameters.begin(), derivationParameters.size()); - } -}; - -//! Discrete Log Integrated Encryption Scheme, AKA DLIES -template -struct DLIES - : public DL_ES< - DL_CryptoKeys_GFP, - DL_KeyAgreementAlgorithm_DH, - DL_KeyDerivationAlgorithm_P1363 >, - DL_EncryptionAlgorithm_Xor, DHAES_MODE>, - DLIES<> > -{ - static std::string CRYPTOPP_API StaticAlgorithmName() {return "DLIES";} // TODO: fix this after name is standardized -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/gzip.h b/lib/cryptopp/gzip.h deleted file mode 100644 index f3148ad71..000000000 --- a/lib/cryptopp/gzip.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef CRYPTOPP_GZIP_H -#define CRYPTOPP_GZIP_H - -#include "zdeflate.h" -#include "zinflate.h" -#include "crc.h" - -NAMESPACE_BEGIN(CryptoPP) - -/// GZIP Compression (RFC 1952) -class Gzip : public Deflator -{ -public: - Gzip(BufferedTransformation *attachment=NULL, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true) - : Deflator(attachment, deflateLevel, log2WindowSize, detectUncompressible) {} - Gzip(const NameValuePairs ¶meters, BufferedTransformation *attachment=NULL) - : Deflator(parameters, attachment) {} - -protected: - enum {MAGIC1=0x1f, MAGIC2=0x8b, // flags for the header - DEFLATED=8, FAST=4, SLOW=2}; - - void WritePrestreamHeader(); - void ProcessUncompressedData(const byte *string, size_t length); - void WritePoststreamTail(); - - word32 m_totalLen; - CRC32 m_crc; -}; - -/// GZIP Decompression (RFC 1952) -class Gunzip : public Inflator -{ -public: - typedef Inflator::Err Err; - class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "Gunzip: header decoding error") {}}; - class TailErr : public Err {public: TailErr() : Err(INVALID_DATA_FORMAT, "Gunzip: tail too short") {}}; - class CrcErr : public Err {public: CrcErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: CRC check error") {}}; - class LengthErr : public Err {public: LengthErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: length check error") {}}; - - /*! \param repeat decompress multiple compressed streams in series - \param autoSignalPropagation 0 to turn off MessageEnd signal - */ - Gunzip(BufferedTransformation *attachment = NULL, bool repeat = false, int autoSignalPropagation = -1); - -protected: - enum {MAGIC1=0x1f, MAGIC2=0x8b, // flags for the header - DEFLATED=8}; - - enum FLAG_MASKS { - CONTINUED=2, EXTRA_FIELDS=4, FILENAME=8, COMMENTS=16, ENCRYPTED=32}; - - unsigned int MaxPrestreamHeaderSize() const {return 1024;} - void ProcessPrestreamHeader(); - void ProcessDecompressedData(const byte *string, size_t length); - unsigned int MaxPoststreamTailSize() const {return 8;} - void ProcessPoststreamTail(); - - word32 m_length; - CRC32 m_crc; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/hex.cpp b/lib/cryptopp/hex.cpp deleted file mode 100644 index 5731df550..000000000 --- a/lib/cryptopp/hex.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// hex.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "hex.h" - -NAMESPACE_BEGIN(CryptoPP) - -static const byte s_vecUpper[] = "0123456789ABCDEF"; -static const byte s_vecLower[] = "0123456789abcdef"; - -void HexEncoder::IsolatedInitialize(const NameValuePairs ¶meters) -{ - bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true); - m_filter->Initialize(CombinedNameValuePairs( - parameters, - MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_vecUpper[0] : &s_vecLower[0], false)(Name::Log2Base(), 4, true))); -} - -void HexDecoder::IsolatedInitialize(const NameValuePairs ¶meters) -{ - BaseN_Decoder::IsolatedInitialize(CombinedNameValuePairs( - parameters, - MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 4, true))); -} - -const int *HexDecoder::GetDefaultDecodingLookupArray() -{ - static volatile bool s_initialized = false; - static int s_array[256]; - - if (!s_initialized) - { - InitializeDecodingLookupArray(s_array, s_vecUpper, 16, true); - s_initialized = true; - } - return s_array; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/hex.h b/lib/cryptopp/hex.h deleted file mode 100644 index 006914c5a..000000000 --- a/lib/cryptopp/hex.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef CRYPTOPP_HEX_H -#define CRYPTOPP_HEX_H - -#include "basecode.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! Converts given data to base 16 -class CRYPTOPP_DLL HexEncoder : public SimpleProxyFilter -{ -public: - HexEncoder(BufferedTransformation *attachment = NULL, bool uppercase = true, int outputGroupSize = 0, const std::string &separator = ":", const std::string &terminator = "") - : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment) - { - IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), outputGroupSize)(Name::Separator(), ConstByteArrayParameter(separator))(Name::Terminator(), ConstByteArrayParameter(terminator))); - } - - void IsolatedInitialize(const NameValuePairs ¶meters); -}; - -//! Decode base 16 data back to bytes -class CRYPTOPP_DLL HexDecoder : public BaseN_Decoder -{ -public: - HexDecoder(BufferedTransformation *attachment = NULL) - : BaseN_Decoder(GetDefaultDecodingLookupArray(), 4, attachment) {} - - void IsolatedInitialize(const NameValuePairs ¶meters); - -private: - static const int * CRYPTOPP_API GetDefaultDecodingLookupArray(); -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/hmac.cpp b/lib/cryptopp/hmac.cpp deleted file mode 100644 index d4a649c08..000000000 --- a/lib/cryptopp/hmac.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// hmac.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "hmac.h" - -NAMESPACE_BEGIN(CryptoPP) - -void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &) -{ - AssertValidKeyLength(keylength); - - Restart(); - - HashTransformation &hash = AccessHash(); - unsigned int blockSize = hash.BlockSize(); - - if (!blockSize) - throw InvalidArgument("HMAC: can only be used with a block-based hash function"); - - m_buf.resize(2*AccessHash().BlockSize() + AccessHash().DigestSize()); - - if (keylength <= blockSize) - memcpy(AccessIpad(), userKey, keylength); - else - { - AccessHash().CalculateDigest(AccessIpad(), userKey, keylength); - keylength = hash.DigestSize(); - } - - assert(keylength <= blockSize); - memset(AccessIpad()+keylength, 0, blockSize-keylength); - - for (unsigned int i=0; i, public MessageAuthenticationCode -{ -public: - HMAC_Base() : m_innerHashKeyed(false) {} - void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms); - - void Restart(); - void Update(const byte *input, size_t length); - void TruncatedFinal(byte *mac, size_t size); - unsigned int OptimalBlockSize() const {return const_cast(this)->AccessHash().OptimalBlockSize();} - unsigned int DigestSize() const {return const_cast(this)->AccessHash().DigestSize();} - -protected: - virtual HashTransformation & AccessHash() =0; - byte * AccessIpad() {return m_buf;} - byte * AccessOpad() {return m_buf + AccessHash().BlockSize();} - byte * AccessInnerHash() {return m_buf + 2*AccessHash().BlockSize();} - -private: - void KeyInnerHash(); - - SecByteBlock m_buf; - bool m_innerHashKeyed; -}; - -//! HMAC -/*! HMAC(K, text) = H(K XOR opad, H(K XOR ipad, text)) */ -template -class HMAC : public MessageAuthenticationCodeImpl > -{ -public: - CRYPTOPP_CONSTANT(DIGESTSIZE=T::DIGESTSIZE) - CRYPTOPP_CONSTANT(BLOCKSIZE=T::BLOCKSIZE) - - HMAC() {} - HMAC(const byte *key, size_t length=HMAC_Base::DEFAULT_KEYLENGTH) - {this->SetKey(key, length);} - - static std::string StaticAlgorithmName() {return std::string("HMAC(") + T::StaticAlgorithmName() + ")";} - std::string AlgorithmName() const {return std::string("HMAC(") + m_hash.AlgorithmName() + ")";} - -private: - HashTransformation & AccessHash() {return m_hash;} - - T m_hash; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/hrtimer.cpp b/lib/cryptopp/hrtimer.cpp deleted file mode 100644 index 6871a15dc..000000000 --- a/lib/cryptopp/hrtimer.cpp +++ /dev/null @@ -1,138 +0,0 @@ -// hrtimer.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "hrtimer.h" -#include "misc.h" -#include // for NULL -#include - -#if defined(CRYPTOPP_WIN32_AVAILABLE) -#include -#elif defined(CRYPTOPP_UNIX_AVAILABLE) -#include -#include -#include -#endif - -#include - -NAMESPACE_BEGIN(CryptoPP) - -#ifndef CRYPTOPP_IMPORTS - -double TimerBase::ConvertTo(TimerWord t, Unit unit) -{ - static unsigned long unitsPerSecondTable[] = {1, 1000, 1000*1000, 1000*1000*1000}; - - assert(unit < sizeof(unitsPerSecondTable) / sizeof(unitsPerSecondTable[0])); - return (double)CRYPTOPP_VC6_INT64 t * unitsPerSecondTable[unit] / CRYPTOPP_VC6_INT64 TicksPerSecond(); -} - -void TimerBase::StartTimer() -{ - m_last = m_start = GetCurrentTimerValue(); - m_started = true; -} - -double TimerBase::ElapsedTimeAsDouble() -{ - if (m_stuckAtZero) - return 0; - - if (m_started) - { - TimerWord now = GetCurrentTimerValue(); - if (m_last < now) // protect against OS bugs where time goes backwards - m_last = now; - return ConvertTo(m_last - m_start, m_timerUnit); - } - - StartTimer(); - return 0; -} - -unsigned long TimerBase::ElapsedTime() -{ - double elapsed = ElapsedTimeAsDouble(); - assert(elapsed <= ULONG_MAX); - return (unsigned long)elapsed; -} - -TimerWord Timer::GetCurrentTimerValue() -{ -#if defined(CRYPTOPP_WIN32_AVAILABLE) - LARGE_INTEGER now; - if (!QueryPerformanceCounter(&now)) - throw Exception(Exception::OTHER_ERROR, "Timer: QueryPerformanceCounter failed with error " + IntToString(GetLastError())); - return now.QuadPart; -#elif defined(CRYPTOPP_UNIX_AVAILABLE) - timeval now; - gettimeofday(&now, NULL); - return (TimerWord)now.tv_sec * 1000000 + now.tv_usec; -#else - return clock(); -#endif -} - -TimerWord Timer::TicksPerSecond() -{ -#if defined(CRYPTOPP_WIN32_AVAILABLE) - static LARGE_INTEGER freq = {0}; - if (freq.QuadPart == 0) - { - if (!QueryPerformanceFrequency(&freq)) - throw Exception(Exception::OTHER_ERROR, "Timer: QueryPerformanceFrequency failed with error " + IntToString(GetLastError())); - } - return freq.QuadPart; -#elif defined(CRYPTOPP_UNIX_AVAILABLE) - return 1000000; -#else - return CLOCKS_PER_SEC; -#endif -} - -#endif // #ifndef CRYPTOPP_IMPORTS - -TimerWord ThreadUserTimer::GetCurrentTimerValue() -{ -#if defined(CRYPTOPP_WIN32_AVAILABLE) - static bool getCurrentThreadImplemented = true; - if (getCurrentThreadImplemented) - { - FILETIME now, ignored; - if (!GetThreadTimes(GetCurrentThread(), &ignored, &ignored, &ignored, &now)) - { - DWORD lastError = GetLastError(); - if (lastError == ERROR_CALL_NOT_IMPLEMENTED) - { - getCurrentThreadImplemented = false; - goto GetCurrentThreadNotImplemented; - } - throw Exception(Exception::OTHER_ERROR, "ThreadUserTimer: GetThreadTimes failed with error " + IntToString(lastError)); - } - return now.dwLowDateTime + ((TimerWord)now.dwHighDateTime << 32); - } -GetCurrentThreadNotImplemented: - return (TimerWord)clock() * (10*1000*1000 / CLOCKS_PER_SEC); -#elif defined(CRYPTOPP_UNIX_AVAILABLE) - tms now; - times(&now); - return now.tms_utime; -#else - return clock(); -#endif -} - -TimerWord ThreadUserTimer::TicksPerSecond() -{ -#if defined(CRYPTOPP_WIN32_AVAILABLE) - return 10*1000*1000; -#elif defined(CRYPTOPP_UNIX_AVAILABLE) - static const long ticksPerSecond = sysconf(_SC_CLK_TCK); - return ticksPerSecond; -#else - return CLOCKS_PER_SEC; -#endif -} - -NAMESPACE_END diff --git a/lib/cryptopp/hrtimer.h b/lib/cryptopp/hrtimer.h deleted file mode 100644 index 858dbd226..000000000 --- a/lib/cryptopp/hrtimer.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef CRYPTOPP_HRTIMER_H -#define CRYPTOPP_HRTIMER_H - -#include "config.h" -#ifndef HIGHRES_TIMER_AVAILABLE -#include -#endif - -NAMESPACE_BEGIN(CryptoPP) - -#ifdef HIGHRES_TIMER_AVAILABLE - typedef word64 TimerWord; -#else - typedef clock_t TimerWord; -#endif - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TimerBase -{ -public: - enum Unit {SECONDS = 0, MILLISECONDS, MICROSECONDS, NANOSECONDS}; - TimerBase(Unit unit, bool stuckAtZero) : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false) {} - - virtual TimerWord GetCurrentTimerValue() =0; // GetCurrentTime is a macro in MSVC 6.0 - virtual TimerWord TicksPerSecond() =0; // this is not the resolution, just a conversion factor into seconds - - void StartTimer(); - double ElapsedTimeAsDouble(); - unsigned long ElapsedTime(); - -private: - double ConvertTo(TimerWord t, Unit unit); - - Unit m_timerUnit; // HPUX workaround: m_unit is a system macro on HPUX - bool m_stuckAtZero, m_started; - TimerWord m_start, m_last; -}; - -//! measure CPU time spent executing instructions of this thread (if supported by OS) -/*! /note This only works correctly on Windows NT or later. On Unix it reports process time, and others wall clock time. -*/ -class ThreadUserTimer : public TimerBase -{ -public: - ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {} - TimerWord GetCurrentTimerValue(); - TimerWord TicksPerSecond(); -}; - -//! high resolution timer -class CRYPTOPP_DLL Timer : public TimerBase -{ -public: - Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {} - TimerWord GetCurrentTimerValue(); - TimerWord TicksPerSecond(); -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/integer.cpp b/lib/cryptopp/integer.cpp deleted file mode 100644 index f07cce873..000000000 --- a/lib/cryptopp/integer.cpp +++ /dev/null @@ -1,4235 +0,0 @@ -// integer.cpp - written and placed in the public domain by Wei Dai -// contains public domain code contributed by Alister Lee and Leonard Janke - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "integer.h" -#include "modarith.h" -#include "nbtheory.h" -#include "asn.h" -#include "oids.h" -#include "words.h" -#include "algparam.h" -#include "pubkey.h" // for P1363_KDF2 -#include "sha.h" -#include "cpu.h" - -#include - -#if _MSC_VER >= 1400 - #include -#endif - -#ifdef __DECCXX - #include -#endif - -#ifdef CRYPTOPP_MSVC6_NO_PP - #pragma message("You do not seem to have the Visual C++ Processor Pack installed, so use of SSE2 instructions will be disabled.") -#endif - -#define CRYPTOPP_INTEGER_SSE2 (CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && CRYPTOPP_BOOL_X86) - -NAMESPACE_BEGIN(CryptoPP) - -bool AssignIntToInteger(const std::type_info &valueType, void *pInteger, const void *pInt) -{ - if (valueType != typeid(Integer)) - return false; - *reinterpret_cast(pInteger) = *reinterpret_cast(pInt); - return true; -} - -inline static int Compare(const word *A, const word *B, size_t N) -{ - while (N--) - if (A[N] > B[N]) - return 1; - else if (A[N] < B[N]) - return -1; - - return 0; -} - -inline static int Increment(word *A, size_t N, word B=1) -{ - assert(N); - word t = A[0]; - A[0] = t+B; - if (A[0] >= t) - return 0; - for (unsigned i=1; i>(WORD_BITS-1)); d##0 = 2*d##0 + (c>>(WORD_BITS-1)); c *= 2; - #endif - #ifndef Acc2WordsBy2 - #define Acc2WordsBy2(a, b) a##0 += b##0; a##1 += a##0 < b##0; a##1 += b##1; - #endif - #define AddWithCarry(u, a, b) {word t = a+b; u##0 = t + u##1; u##1 = (ta) + (u##0>t);} - #define GetCarry(u) u##1 - #define GetBorrow(u) u##1 -#else - #define Declare2Words(x) dword x; - #if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER) - #define MultiplyWords(p, a, b) p = __emulu(a, b); - #else - #define MultiplyWords(p, a, b) p = (dword)a*b; - #endif - #define AssignWord(a, b) a = b; - #define Add2WordsBy1(a, b, c) a = b + c; - #define Acc2WordsBy2(a, b) a += b; - #define LowWord(a) word(a) - #define HighWord(a) word(a>>WORD_BITS) - #define Double3Words(c, d) d = 2*d + (c>>(WORD_BITS-1)); c *= 2; - #define AddWithCarry(u, a, b) u = dword(a) + b + GetCarry(u); - #define SubtractWithBorrow(u, a, b) u = dword(a) - b - GetBorrow(u); - #define GetCarry(u) HighWord(u) - #define GetBorrow(u) word(u>>(WORD_BITS*2-1)) -#endif -#ifndef MulAcc - #define MulAcc(c, d, a, b) MultiplyWords(p, a, b); Acc2WordsBy1(p, c); c = LowWord(p); Acc2WordsBy1(d, HighWord(p)); -#endif -#ifndef Acc2WordsBy1 - #define Acc2WordsBy1(a, b) Add2WordsBy1(a, a, b) -#endif -#ifndef Acc3WordsBy2 - #define Acc3WordsBy2(c, d, e) Acc2WordsBy1(e, c); c = LowWord(e); Add2WordsBy1(e, d, HighWord(e)); -#endif - -class DWord -{ -public: - DWord() {} - -#ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE - explicit DWord(word low) - { - m_whole = low; - } -#else - explicit DWord(word low) - { - m_halfs.low = low; - m_halfs.high = 0; - } -#endif - - DWord(word low, word high) - { - m_halfs.low = low; - m_halfs.high = high; - } - - static DWord Multiply(word a, word b) - { - DWord r; - #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE - r.m_whole = (dword)a * b; - #elif defined(MultiplyWordsLoHi) - MultiplyWordsLoHi(r.m_halfs.low, r.m_halfs.high, a, b); - #endif - return r; - } - - static DWord MultiplyAndAdd(word a, word b, word c) - { - DWord r = Multiply(a, b); - return r += c; - } - - DWord & operator+=(word a) - { - #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE - m_whole = m_whole + a; - #else - m_halfs.low += a; - m_halfs.high += (m_halfs.low < a); - #endif - return *this; - } - - DWord operator+(word a) - { - DWord r; - #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE - r.m_whole = m_whole + a; - #else - r.m_halfs.low = m_halfs.low + a; - r.m_halfs.high = m_halfs.high + (r.m_halfs.low < a); - #endif - return r; - } - - DWord operator-(DWord a) - { - DWord r; - #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE - r.m_whole = m_whole - a.m_whole; - #else - r.m_halfs.low = m_halfs.low - a.m_halfs.low; - r.m_halfs.high = m_halfs.high - a.m_halfs.high - (r.m_halfs.low > m_halfs.low); - #endif - return r; - } - - DWord operator-(word a) - { - DWord r; - #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE - r.m_whole = m_whole - a; - #else - r.m_halfs.low = m_halfs.low - a; - r.m_halfs.high = m_halfs.high - (r.m_halfs.low > m_halfs.low); - #endif - return r; - } - - // returns quotient, which must fit in a word - word operator/(word divisor); - - word operator%(word a); - - bool operator!() const - { - #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE - return !m_whole; - #else - return !m_halfs.high && !m_halfs.low; - #endif - } - - word GetLowHalf() const {return m_halfs.low;} - word GetHighHalf() const {return m_halfs.high;} - word GetHighHalfAsBorrow() const {return 0-m_halfs.high;} - -private: - union - { - #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE - dword m_whole; - #endif - struct - { - #ifdef IS_LITTLE_ENDIAN - word low; - word high; - #else - word high; - word low; - #endif - } m_halfs; - }; -}; - -class Word -{ -public: - Word() {} - - Word(word value) - { - m_whole = value; - } - - Word(hword low, hword high) - { - m_whole = low | (word(high) << (WORD_BITS/2)); - } - - static Word Multiply(hword a, hword b) - { - Word r; - r.m_whole = (word)a * b; - return r; - } - - Word operator-(Word a) - { - Word r; - r.m_whole = m_whole - a.m_whole; - return r; - } - - Word operator-(hword a) - { - Word r; - r.m_whole = m_whole - a; - return r; - } - - // returns quotient, which must fit in a word - hword operator/(hword divisor) - { - return hword(m_whole / divisor); - } - - bool operator!() const - { - return !m_whole; - } - - word GetWhole() const {return m_whole;} - hword GetLowHalf() const {return hword(m_whole);} - hword GetHighHalf() const {return hword(m_whole>>(WORD_BITS/2));} - hword GetHighHalfAsBorrow() const {return 0-hword(m_whole>>(WORD_BITS/2));} - -private: - word m_whole; -}; - -// do a 3 word by 2 word divide, returns quotient and leaves remainder in A -template -S DivideThreeWordsByTwo(S *A, S B0, S B1, D *dummy=NULL) -{ - // assert {A[2],A[1]} < {B1,B0}, so quotient can fit in a S - assert(A[2] < B1 || (A[2]==B1 && A[1] < B0)); - - // estimate the quotient: do a 2 S by 1 S divide - S Q; - if (S(B1+1) == 0) - Q = A[2]; - else if (B1 > 0) - Q = D(A[1], A[2]) / S(B1+1); - else - Q = D(A[0], A[1]) / B0; - - // now subtract Q*B from A - D p = D::Multiply(B0, Q); - D u = (D) A[0] - p.GetLowHalf(); - A[0] = u.GetLowHalf(); - u = (D) A[1] - p.GetHighHalf() - u.GetHighHalfAsBorrow() - D::Multiply(B1, Q); - A[1] = u.GetLowHalf(); - A[2] += u.GetHighHalf(); - - // Q <= actual quotient, so fix it - while (A[2] || A[1] > B1 || (A[1]==B1 && A[0]>=B0)) - { - u = (D) A[0] - B0; - A[0] = u.GetLowHalf(); - u = (D) A[1] - B1 - u.GetHighHalfAsBorrow(); - A[1] = u.GetLowHalf(); - A[2] += u.GetHighHalf(); - Q++; - assert(Q); // shouldn't overflow - } - - return Q; -} - -// do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1 -template -inline D DivideFourWordsByTwo(S *T, const D &Al, const D &Ah, const D &B) -{ - if (!B) // if divisor is 0, we assume divisor==2**(2*WORD_BITS) - return D(Ah.GetLowHalf(), Ah.GetHighHalf()); - else - { - S Q[2]; - T[0] = Al.GetLowHalf(); - T[1] = Al.GetHighHalf(); - T[2] = Ah.GetLowHalf(); - T[3] = Ah.GetHighHalf(); - Q[1] = DivideThreeWordsByTwo(T+1, B.GetLowHalf(), B.GetHighHalf()); - Q[0] = DivideThreeWordsByTwo(T, B.GetLowHalf(), B.GetHighHalf()); - return D(Q[0], Q[1]); - } -} - -// returns quotient, which must fit in a word -inline word DWord::operator/(word a) -{ - #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE - return word(m_whole / a); - #else - hword r[4]; - return DivideFourWordsByTwo(r, m_halfs.low, m_halfs.high, a).GetWhole(); - #endif -} - -inline word DWord::operator%(word a) -{ - #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE - return word(m_whole % a); - #else - if (a < (word(1) << (WORD_BITS/2))) - { - hword h = hword(a); - word r = m_halfs.high % h; - r = ((m_halfs.low >> (WORD_BITS/2)) + (r << (WORD_BITS/2))) % h; - return hword((hword(m_halfs.low) + (r << (WORD_BITS/2))) % h); - } - else - { - hword r[4]; - DivideFourWordsByTwo(r, m_halfs.low, m_halfs.high, a); - return Word(r[0], r[1]).GetWhole(); - } - #endif -} - -// ******************************************************** - -// use some tricks to share assembly code between MSVC and GCC -#if defined(__GNUC__) - #define AddPrologue \ - int result; \ - __asm__ __volatile__ \ - ( \ - ".intel_syntax noprefix;" - #define AddEpilogue \ - ".att_syntax prefix;" \ - : "=a" (result)\ - : "d" (C), "a" (A), "D" (B), "c" (N) \ - : "%esi", "memory", "cc" \ - );\ - return result; - #define MulPrologue \ - __asm__ __volatile__ \ - ( \ - ".intel_syntax noprefix;" \ - AS1( push ebx) \ - AS2( mov ebx, edx) - #define MulEpilogue \ - AS1( pop ebx) \ - ".att_syntax prefix;" \ - : \ - : "d" (s_maskLow16), "c" (C), "a" (A), "D" (B) \ - : "%esi", "memory", "cc" \ - ); - #define SquPrologue MulPrologue - #define SquEpilogue \ - AS1( pop ebx) \ - ".att_syntax prefix;" \ - : \ - : "d" (s_maskLow16), "c" (C), "a" (A) \ - : "%esi", "%edi", "memory", "cc" \ - ); - #define TopPrologue MulPrologue - #define TopEpilogue \ - AS1( pop ebx) \ - ".att_syntax prefix;" \ - : \ - : "d" (s_maskLow16), "c" (C), "a" (A), "D" (B), "S" (L) \ - : "memory", "cc" \ - ); -#else - #define AddPrologue \ - __asm push edi \ - __asm push esi \ - __asm mov eax, [esp+12] \ - __asm mov edi, [esp+16] - #define AddEpilogue \ - __asm pop esi \ - __asm pop edi \ - __asm ret 8 -#if _MSC_VER < 1300 - #define SaveEBX __asm push ebx - #define RestoreEBX __asm pop ebx -#else - #define SaveEBX - #define RestoreEBX -#endif - #define SquPrologue \ - AS2( mov eax, A) \ - AS2( mov ecx, C) \ - SaveEBX \ - AS2( lea ebx, s_maskLow16) - #define MulPrologue \ - AS2( mov eax, A) \ - AS2( mov edi, B) \ - AS2( mov ecx, C) \ - SaveEBX \ - AS2( lea ebx, s_maskLow16) - #define TopPrologue \ - AS2( mov eax, A) \ - AS2( mov edi, B) \ - AS2( mov ecx, C) \ - AS2( mov esi, L) \ - SaveEBX \ - AS2( lea ebx, s_maskLow16) - #define SquEpilogue RestoreEBX - #define MulEpilogue RestoreEBX - #define TopEpilogue RestoreEBX -#endif - -#ifdef CRYPTOPP_X64_MASM_AVAILABLE -extern "C" { -int Baseline_Add(size_t N, word *C, const word *A, const word *B); -int Baseline_Sub(size_t N, word *C, const word *A, const word *B); -} -#elif defined(CRYPTOPP_X64_ASM_AVAILABLE) && defined(__GNUC__) && defined(CRYPTOPP_WORD128_AVAILABLE) -int Baseline_Add(size_t N, word *C, const word *A, const word *B) -{ - word result; - __asm__ __volatile__ - ( - ".intel_syntax;" - AS1( neg %1) - ASJ( jz, 1, f) - AS2( mov %0,[%3+8*%1]) - AS2( add %0,[%4+8*%1]) - AS2( mov [%2+8*%1],%0) - ASL(0) - AS2( mov %0,[%3+8*%1+8]) - AS2( adc %0,[%4+8*%1+8]) - AS2( mov [%2+8*%1+8],%0) - AS2( lea %1,[%1+2]) - ASJ( jrcxz, 1, f) - AS2( mov %0,[%3+8*%1]) - AS2( adc %0,[%4+8*%1]) - AS2( mov [%2+8*%1],%0) - ASJ( jmp, 0, b) - ASL(1) - AS2( mov %0, 0) - AS2( adc %0, %0) - ".att_syntax;" - : "=&r" (result), "+c" (N) - : "r" (C+N), "r" (A+N), "r" (B+N) - : "memory", "cc" - ); - return (int)result; -} - -int Baseline_Sub(size_t N, word *C, const word *A, const word *B) -{ - word result; - __asm__ __volatile__ - ( - ".intel_syntax;" - AS1( neg %1) - ASJ( jz, 1, f) - AS2( mov %0,[%3+8*%1]) - AS2( sub %0,[%4+8*%1]) - AS2( mov [%2+8*%1],%0) - ASL(0) - AS2( mov %0,[%3+8*%1+8]) - AS2( sbb %0,[%4+8*%1+8]) - AS2( mov [%2+8*%1+8],%0) - AS2( lea %1,[%1+2]) - ASJ( jrcxz, 1, f) - AS2( mov %0,[%3+8*%1]) - AS2( sbb %0,[%4+8*%1]) - AS2( mov [%2+8*%1],%0) - ASJ( jmp, 0, b) - ASL(1) - AS2( mov %0, 0) - AS2( adc %0, %0) - ".att_syntax;" - : "=&r" (result), "+c" (N) - : "r" (C+N), "r" (A+N), "r" (B+N) - : "memory", "cc" - ); - return (int)result; -} -#elif defined(CRYPTOPP_X86_ASM_AVAILABLE) && CRYPTOPP_BOOL_X86 -CRYPTOPP_NAKED int CRYPTOPP_FASTCALL Baseline_Add(size_t N, word *C, const word *A, const word *B) -{ - AddPrologue - - // now: eax = A, edi = B, edx = C, ecx = N - AS2( lea eax, [eax+4*ecx]) - AS2( lea edi, [edi+4*ecx]) - AS2( lea edx, [edx+4*ecx]) - - AS1( neg ecx) // ecx is negative index - AS2( test ecx, 2) // this clears carry flag - ASJ( jz, 0, f) - AS2( sub ecx, 2) - ASJ( jmp, 1, f) - - ASL(0) - ASJ( jecxz, 2, f) // loop until ecx overflows and becomes zero - AS2( mov esi,[eax+4*ecx]) - AS2( adc esi,[edi+4*ecx]) - AS2( mov [edx+4*ecx],esi) - AS2( mov esi,[eax+4*ecx+4]) - AS2( adc esi,[edi+4*ecx+4]) - AS2( mov [edx+4*ecx+4],esi) - ASL(1) - AS2( mov esi,[eax+4*ecx+8]) - AS2( adc esi,[edi+4*ecx+8]) - AS2( mov [edx+4*ecx+8],esi) - AS2( mov esi,[eax+4*ecx+12]) - AS2( adc esi,[edi+4*ecx+12]) - AS2( mov [edx+4*ecx+12],esi) - - AS2( lea ecx,[ecx+4]) // advance index, avoid inc which causes slowdown on Intel Core 2 - ASJ( jmp, 0, b) - - ASL(2) - AS2( mov eax, 0) - AS1( setc al) // store carry into eax (return result register) - - AddEpilogue -} - -CRYPTOPP_NAKED int CRYPTOPP_FASTCALL Baseline_Sub(size_t N, word *C, const word *A, const word *B) -{ - AddPrologue - - // now: eax = A, edi = B, edx = C, ecx = N - AS2( lea eax, [eax+4*ecx]) - AS2( lea edi, [edi+4*ecx]) - AS2( lea edx, [edx+4*ecx]) - - AS1( neg ecx) // ecx is negative index - AS2( test ecx, 2) // this clears carry flag - ASJ( jz, 0, f) - AS2( sub ecx, 2) - ASJ( jmp, 1, f) - - ASL(0) - ASJ( jecxz, 2, f) // loop until ecx overflows and becomes zero - AS2( mov esi,[eax+4*ecx]) - AS2( sbb esi,[edi+4*ecx]) - AS2( mov [edx+4*ecx],esi) - AS2( mov esi,[eax+4*ecx+4]) - AS2( sbb esi,[edi+4*ecx+4]) - AS2( mov [edx+4*ecx+4],esi) - ASL(1) - AS2( mov esi,[eax+4*ecx+8]) - AS2( sbb esi,[edi+4*ecx+8]) - AS2( mov [edx+4*ecx+8],esi) - AS2( mov esi,[eax+4*ecx+12]) - AS2( sbb esi,[edi+4*ecx+12]) - AS2( mov [edx+4*ecx+12],esi) - - AS2( lea ecx,[ecx+4]) // advance index, avoid inc which causes slowdown on Intel Core 2 - ASJ( jmp, 0, b) - - ASL(2) - AS2( mov eax, 0) - AS1( setc al) // store carry into eax (return result register) - - AddEpilogue -} - -#if CRYPTOPP_INTEGER_SSE2 -CRYPTOPP_NAKED int CRYPTOPP_FASTCALL SSE2_Add(size_t N, word *C, const word *A, const word *B) -{ - AddPrologue - - // now: eax = A, edi = B, edx = C, ecx = N - AS2( lea eax, [eax+4*ecx]) - AS2( lea edi, [edi+4*ecx]) - AS2( lea edx, [edx+4*ecx]) - - AS1( neg ecx) // ecx is negative index - AS2( pxor mm2, mm2) - ASJ( jz, 2, f) - AS2( test ecx, 2) // this clears carry flag - ASJ( jz, 0, f) - AS2( sub ecx, 2) - ASJ( jmp, 1, f) - - ASL(0) - AS2( movd mm0, DWORD PTR [eax+4*ecx]) - AS2( movd mm1, DWORD PTR [edi+4*ecx]) - AS2( paddq mm0, mm1) - AS2( paddq mm2, mm0) - AS2( movd DWORD PTR [edx+4*ecx], mm2) - AS2( psrlq mm2, 32) - - AS2( movd mm0, DWORD PTR [eax+4*ecx+4]) - AS2( movd mm1, DWORD PTR [edi+4*ecx+4]) - AS2( paddq mm0, mm1) - AS2( paddq mm2, mm0) - AS2( movd DWORD PTR [edx+4*ecx+4], mm2) - AS2( psrlq mm2, 32) - - ASL(1) - AS2( movd mm0, DWORD PTR [eax+4*ecx+8]) - AS2( movd mm1, DWORD PTR [edi+4*ecx+8]) - AS2( paddq mm0, mm1) - AS2( paddq mm2, mm0) - AS2( movd DWORD PTR [edx+4*ecx+8], mm2) - AS2( psrlq mm2, 32) - - AS2( movd mm0, DWORD PTR [eax+4*ecx+12]) - AS2( movd mm1, DWORD PTR [edi+4*ecx+12]) - AS2( paddq mm0, mm1) - AS2( paddq mm2, mm0) - AS2( movd DWORD PTR [edx+4*ecx+12], mm2) - AS2( psrlq mm2, 32) - - AS2( add ecx, 4) - ASJ( jnz, 0, b) - - ASL(2) - AS2( movd eax, mm2) - AS1( emms) - - AddEpilogue -} -CRYPTOPP_NAKED int CRYPTOPP_FASTCALL SSE2_Sub(size_t N, word *C, const word *A, const word *B) -{ - AddPrologue - - // now: eax = A, edi = B, edx = C, ecx = N - AS2( lea eax, [eax+4*ecx]) - AS2( lea edi, [edi+4*ecx]) - AS2( lea edx, [edx+4*ecx]) - - AS1( neg ecx) // ecx is negative index - AS2( pxor mm2, mm2) - ASJ( jz, 2, f) - AS2( test ecx, 2) // this clears carry flag - ASJ( jz, 0, f) - AS2( sub ecx, 2) - ASJ( jmp, 1, f) - - ASL(0) - AS2( movd mm0, DWORD PTR [eax+4*ecx]) - AS2( movd mm1, DWORD PTR [edi+4*ecx]) - AS2( psubq mm0, mm1) - AS2( psubq mm0, mm2) - AS2( movd DWORD PTR [edx+4*ecx], mm0) - AS2( psrlq mm0, 63) - - AS2( movd mm2, DWORD PTR [eax+4*ecx+4]) - AS2( movd mm1, DWORD PTR [edi+4*ecx+4]) - AS2( psubq mm2, mm1) - AS2( psubq mm2, mm0) - AS2( movd DWORD PTR [edx+4*ecx+4], mm2) - AS2( psrlq mm2, 63) - - ASL(1) - AS2( movd mm0, DWORD PTR [eax+4*ecx+8]) - AS2( movd mm1, DWORD PTR [edi+4*ecx+8]) - AS2( psubq mm0, mm1) - AS2( psubq mm0, mm2) - AS2( movd DWORD PTR [edx+4*ecx+8], mm0) - AS2( psrlq mm0, 63) - - AS2( movd mm2, DWORD PTR [eax+4*ecx+12]) - AS2( movd mm1, DWORD PTR [edi+4*ecx+12]) - AS2( psubq mm2, mm1) - AS2( psubq mm2, mm0) - AS2( movd DWORD PTR [edx+4*ecx+12], mm2) - AS2( psrlq mm2, 63) - - AS2( add ecx, 4) - ASJ( jnz, 0, b) - - ASL(2) - AS2( movd eax, mm2) - AS1( emms) - - AddEpilogue -} -#endif // #if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE -#else -int CRYPTOPP_FASTCALL Baseline_Add(size_t N, word *C, const word *A, const word *B) -{ - assert (N%2 == 0); - - Declare2Words(u); - AssignWord(u, 0); - for (size_t i=0; i=2 && N%2==0); - - if (N <= s_recursionLimit) - s_pMul[N/4](R, A, B); - else - { - const size_t N2 = N/2; - - size_t AN2 = Compare(A0, A1, N2) > 0 ? 0 : N2; - Subtract(R0, A + AN2, A + (N2 ^ AN2), N2); - - size_t BN2 = Compare(B0, B1, N2) > 0 ? 0 : N2; - Subtract(R1, B + BN2, B + (N2 ^ BN2), N2); - - RecursiveMultiply(R2, T2, A1, B1, N2); - RecursiveMultiply(T0, T2, R0, R1, N2); - RecursiveMultiply(R0, T2, A0, B0, N2); - - // now T[01] holds (A1-A0)*(B0-B1), R[01] holds A0*B0, R[23] holds A1*B1 - - int c2 = Add(R2, R2, R1, N2); - int c3 = c2; - c2 += Add(R1, R2, R0, N2); - c3 += Add(R2, R2, R3, N2); - - if (AN2 == BN2) - c3 -= Subtract(R1, R1, T0, N); - else - c3 += Add(R1, R1, T0, N); - - c3 += Increment(R2, N2, c2); - assert (c3 >= 0 && c3 <= 2); - Increment(R3, N2, c3); - } -} - -// R[2*N] - result = A*A -// T[2*N] - temporary work space -// A[N] --- number to be squared - -void RecursiveSquare(word *R, word *T, const word *A, size_t N) -{ - assert(N && N%2==0); - - if (N <= s_recursionLimit) - s_pSqu[N/4](R, A); - else - { - const size_t N2 = N/2; - - RecursiveSquare(R0, T2, A0, N2); - RecursiveSquare(R2, T2, A1, N2); - RecursiveMultiply(T0, T2, A0, A1, N2); - - int carry = Add(R1, R1, T0, N); - carry += Add(R1, R1, T0, N); - Increment(R3, N2, carry); - } -} - -// R[N] - bottom half of A*B -// T[3*N/2] - temporary work space -// A[N] - multiplier -// B[N] - multiplicant - -void RecursiveMultiplyBottom(word *R, word *T, const word *A, const word *B, size_t N) -{ - assert(N>=2 && N%2==0); - - if (N <= s_recursionLimit) - s_pBot[N/4](R, A, B); - else - { - const size_t N2 = N/2; - - RecursiveMultiply(R, T, A0, B0, N2); - RecursiveMultiplyBottom(T0, T1, A1, B0, N2); - Add(R1, R1, T0, N2); - RecursiveMultiplyBottom(T0, T1, A0, B1, N2); - Add(R1, R1, T0, N2); - } -} - -// R[N] --- upper half of A*B -// T[2*N] - temporary work space -// L[N] --- lower half of A*B -// A[N] --- multiplier -// B[N] --- multiplicant - -void MultiplyTop(word *R, word *T, const word *L, const word *A, const word *B, size_t N) -{ - assert(N>=2 && N%2==0); - - if (N <= s_recursionLimit) - s_pTop[N/4](R, A, B, L[N-1]); - else - { - const size_t N2 = N/2; - - size_t AN2 = Compare(A0, A1, N2) > 0 ? 0 : N2; - Subtract(R0, A + AN2, A + (N2 ^ AN2), N2); - - size_t BN2 = Compare(B0, B1, N2) > 0 ? 0 : N2; - Subtract(R1, B + BN2, B + (N2 ^ BN2), N2); - - RecursiveMultiply(T0, T2, R0, R1, N2); - RecursiveMultiply(R0, T2, A1, B1, N2); - - // now T[01] holds (A1-A0)*(B0-B1) = A1*B0+A0*B1-A1*B1-A0*B0, R[01] holds A1*B1 - - int t, c3; - int c2 = Subtract(T2, L+N2, L, N2); - - if (AN2 == BN2) - { - c2 -= Add(T2, T2, T0, N2); - t = (Compare(T2, R0, N2) == -1); - c3 = t - Subtract(T2, T2, T1, N2); - } - else - { - c2 += Subtract(T2, T2, T0, N2); - t = (Compare(T2, R0, N2) == -1); - c3 = t + Add(T2, T2, T1, N2); - } - - c2 += t; - if (c2 >= 0) - c3 += Increment(T2, N2, c2); - else - c3 -= Decrement(T2, N2, -c2); - c3 += Add(R0, T2, R1, N2); - - assert (c3 >= 0 && c3 <= 2); - Increment(R1, N2, c3); - } -} - -inline void Multiply(word *R, word *T, const word *A, const word *B, size_t N) -{ - RecursiveMultiply(R, T, A, B, N); -} - -inline void Square(word *R, word *T, const word *A, size_t N) -{ - RecursiveSquare(R, T, A, N); -} - -inline void MultiplyBottom(word *R, word *T, const word *A, const word *B, size_t N) -{ - RecursiveMultiplyBottom(R, T, A, B, N); -} - -// R[NA+NB] - result = A*B -// T[NA+NB] - temporary work space -// A[NA] ---- multiplier -// B[NB] ---- multiplicant - -void AsymmetricMultiply(word *R, word *T, const word *A, size_t NA, const word *B, size_t NB) -{ - if (NA == NB) - { - if (A == B) - Square(R, T, A, NA); - else - Multiply(R, T, A, B, NA); - - return; - } - - if (NA > NB) - { - std::swap(A, B); - std::swap(NA, NB); - } - - assert(NB % NA == 0); - - if (NA==2 && !A[1]) - { - switch (A[0]) - { - case 0: - SetWords(R, 0, NB+2); - return; - case 1: - CopyWords(R, B, NB); - R[NB] = R[NB+1] = 0; - return; - default: - R[NB] = LinearMultiply(R, B, A[0], NB); - R[NB+1] = 0; - return; - } - } - - size_t i; - if ((NB/NA)%2 == 0) - { - Multiply(R, T, A, B, NA); - CopyWords(T+2*NA, R+NA, NA); - - for (i=2*NA; i=4); - -#define M0 M -#define M1 (M+N2) -#define V0 V -#define V1 (V+N2) - -#define X0 X -#define X1 (X+N2) -#define X2 (X+N) -#define X3 (X+N+N2) - - const size_t N2 = N/2; - Multiply(T0, T2, V0, X3, N2); - int c2 = Add(T0, T0, X0, N); - MultiplyBottom(T3, T2, T0, U, N2); - MultiplyTop(T2, R, T0, T3, M0, N2); - c2 -= Subtract(T2, T1, T2, N2); - Multiply(T0, R, T3, M1, N2); - c2 -= Subtract(T0, T2, T0, N2); - int c3 = -(int)Subtract(T1, X2, T1, N2); - Multiply(R0, T2, V1, X3, N2); - c3 += Add(R, R, T, N); - - if (c2>0) - c3 += Increment(R1, N2); - else if (c2<0) - c3 -= Decrement(R1, N2, -c2); - - assert(c3>=-1 && c3<=1); - if (c3>0) - Subtract(R, R, M, N); - else if (c3<0) - Add(R, R, M, N); - -#undef M0 -#undef M1 -#undef V0 -#undef V1 - -#undef X0 -#undef X1 -#undef X2 -#undef X3 -} - -#undef A0 -#undef A1 -#undef B0 -#undef B1 - -#undef T0 -#undef T1 -#undef T2 -#undef T3 - -#undef R0 -#undef R1 -#undef R2 -#undef R3 - -/* -// do a 3 word by 2 word divide, returns quotient and leaves remainder in A -static word SubatomicDivide(word *A, word B0, word B1) -{ - // assert {A[2],A[1]} < {B1,B0}, so quotient can fit in a word - assert(A[2] < B1 || (A[2]==B1 && A[1] < B0)); - - // estimate the quotient: do a 2 word by 1 word divide - word Q; - if (B1+1 == 0) - Q = A[2]; - else - Q = DWord(A[1], A[2]).DividedBy(B1+1); - - // now subtract Q*B from A - DWord p = DWord::Multiply(B0, Q); - DWord u = (DWord) A[0] - p.GetLowHalf(); - A[0] = u.GetLowHalf(); - u = (DWord) A[1] - p.GetHighHalf() - u.GetHighHalfAsBorrow() - DWord::Multiply(B1, Q); - A[1] = u.GetLowHalf(); - A[2] += u.GetHighHalf(); - - // Q <= actual quotient, so fix it - while (A[2] || A[1] > B1 || (A[1]==B1 && A[0]>=B0)) - { - u = (DWord) A[0] - B0; - A[0] = u.GetLowHalf(); - u = (DWord) A[1] - B1 - u.GetHighHalfAsBorrow(); - A[1] = u.GetLowHalf(); - A[2] += u.GetHighHalf(); - Q++; - assert(Q); // shouldn't overflow - } - - return Q; -} - -// do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1 -static inline void AtomicDivide(word *Q, const word *A, const word *B) -{ - if (!B[0] && !B[1]) // if divisor is 0, we assume divisor==2**(2*WORD_BITS) - { - Q[0] = A[2]; - Q[1] = A[3]; - } - else - { - word T[4]; - T[0] = A[0]; T[1] = A[1]; T[2] = A[2]; T[3] = A[3]; - Q[1] = SubatomicDivide(T+1, B[0], B[1]); - Q[0] = SubatomicDivide(T, B[0], B[1]); - -#ifndef NDEBUG - // multiply quotient and divisor and add remainder, make sure it equals dividend - assert(!T[2] && !T[3] && (T[1] < B[1] || (T[1]==B[1] && T[0](T, DWord(A[0], A[1]), DWord(A[2], A[3]), DWord(B[0], B[1])); - Q[0] = q.GetLowHalf(); - Q[1] = q.GetHighHalf(); - -#ifndef NDEBUG - if (B[0] || B[1]) - { - // multiply quotient and divisor and add remainder, make sure it equals dividend - assert(!T[2] && !T[3] && (T[1] < B[1] || (T[1]==B[1] && T[0]= 0) - { - R[N] -= Subtract(R, R, B, N); - Q[1] += (++Q[0]==0); - assert(Q[0] || Q[1]); // no overflow - } -} - -// R[NB] -------- remainder = A%B -// Q[NA-NB+2] --- quotient = A/B -// T[NA+3*(NB+2)] - temp work space -// A[NA] -------- dividend -// B[NB] -------- divisor - -void Divide(word *R, word *Q, word *T, const word *A, size_t NA, const word *B, size_t NB) -{ - assert(NA && NB && NA%2==0 && NB%2==0); - assert(B[NB-1] || B[NB-2]); - assert(NB <= NA); - - // set up temporary work space - word *const TA=T; - word *const TB=T+NA+2; - word *const TP=T+NA+2+NB; - - // copy B into TB and normalize it so that TB has highest bit set to 1 - unsigned shiftWords = (B[NB-1]==0); - TB[0] = TB[NB-1] = 0; - CopyWords(TB+shiftWords, B, NB-shiftWords); - unsigned shiftBits = WORD_BITS - BitPrecision(TB[NB-1]); - assert(shiftBits < WORD_BITS); - ShiftWordsLeftByBits(TB, NB, shiftBits); - - // copy A into TA and normalize it - TA[0] = TA[NA] = TA[NA+1] = 0; - CopyWords(TA+shiftWords, A, NA); - ShiftWordsLeftByBits(TA, NA+2, shiftBits); - - if (TA[NA+1]==0 && TA[NA] <= 1) - { - Q[NA-NB+1] = Q[NA-NB] = 0; - while (TA[NA] || Compare(TA+NA-NB, TB, NB) >= 0) - { - TA[NA] -= Subtract(TA+NA-NB, TA+NA-NB, TB, NB); - ++Q[NA-NB]; - } - } - else - { - NA+=2; - assert(Compare(TA+NA-NB, TB, NB) < 0); - } - - word BT[2]; - BT[0] = TB[NB-2] + 1; - BT[1] = TB[NB-1] + (BT[0]==0); - - // start reducing TA mod TB, 2 words at a time - for (size_t i=NA-2; i>=NB; i-=2) - { - AtomicDivide(Q+i-NB, TA+i-2, BT); - CorrectQuotientEstimate(TA+i-NB, TP, Q+i-NB, TB, NB); - } - - // copy TA into R, and denormalize it - CopyWords(R, TA+shiftWords, NB); - ShiftWordsRightByBits(R, NB, shiftBits); -} - -static inline size_t EvenWordCount(const word *X, size_t N) -{ - while (N && X[N-2]==0 && X[N-1]==0) - N-=2; - return N; -} - -// return k -// R[N] --- result = A^(-1) * 2^k mod M -// T[4*N] - temporary work space -// A[NA] -- number to take inverse of -// M[N] --- modulus - -unsigned int AlmostInverse(word *R, word *T, const word *A, size_t NA, const word *M, size_t N) -{ - assert(NA<=N && N && N%2==0); - - word *b = T; - word *c = T+N; - word *f = T+2*N; - word *g = T+3*N; - size_t bcLen=2, fgLen=EvenWordCount(M, N); - unsigned int k=0; - bool s=false; - - SetWords(T, 0, 3*N); - b[0]=1; - CopyWords(f, A, NA); - CopyWords(g, M, N); - - while (1) - { - word t=f[0]; - while (!t) - { - if (EvenWordCount(f, fgLen)==0) - { - SetWords(R, 0, N); - return 0; - } - - ShiftWordsRightByWords(f, fgLen, 1); - bcLen += 2 * (c[bcLen-1] != 0); - assert(bcLen <= N); - ShiftWordsLeftByWords(c, bcLen, 1); - k+=WORD_BITS; - t=f[0]; - } - - unsigned int i = TrailingZeros(t); - t >>= i; - k += i; - - if (t==1 && f[1]==0 && EvenWordCount(f+2, fgLen-2)==0) - { - if (s) - Subtract(R, M, b, N); - else - CopyWords(R, b, N); - return k; - } - - ShiftWordsRightByBits(f, fgLen, i); - t = ShiftWordsLeftByBits(c, bcLen, i); - c[bcLen] += t; - bcLen += 2 * (t!=0); - assert(bcLen <= N); - - bool swap = Compare(f, g, fgLen)==-1; - ConditionalSwapPointers(swap, f, g); - ConditionalSwapPointers(swap, b, c); - s ^= swap; - - fgLen -= 2 * !(f[fgLen-2] | f[fgLen-1]); - - Subtract(f, f, g, fgLen); - t = Add(b, b, c, bcLen); - b[bcLen] += t; - bcLen += 2*t; - assert(bcLen <= N); - } -} - -// R[N] - result = A/(2^k) mod M -// A[N] - input -// M[N] - modulus - -void DivideByPower2Mod(word *R, const word *A, size_t k, const word *M, size_t N) -{ - CopyWords(R, A, N); - - while (k--) - { - if (R[0]%2==0) - ShiftWordsRightByBits(R, N, 1); - else - { - word carry = Add(R, R, M, N); - ShiftWordsRightByBits(R, N, 1); - R[N-1] += carry<<(WORD_BITS-1); - } - } -} - -// R[N] - result = A*(2^k) mod M -// A[N] - input -// M[N] - modulus - -void MultiplyByPower2Mod(word *R, const word *A, size_t k, const word *M, size_t N) -{ - CopyWords(R, A, N); - - while (k--) - if (ShiftWordsLeftByBits(R, N, 1) || Compare(R, M, N)>=0) - Subtract(R, R, M, N); -} - -// ****************************************************************** - -InitializeInteger::InitializeInteger() -{ - if (!g_pAssignIntToInteger) - { - SetFunctionPointers(); - g_pAssignIntToInteger = AssignIntToInteger; - } -} - -static const unsigned int RoundupSizeTable[] = {2, 2, 2, 4, 4, 8, 8, 8, 8}; - -static inline size_t RoundupSize(size_t n) -{ - if (n<=8) - return RoundupSizeTable[n]; - else if (n<=16) - return 16; - else if (n<=32) - return 32; - else if (n<=64) - return 64; - else return size_t(1) << BitPrecision(n-1); -} - -Integer::Integer() - : reg(2), sign(POSITIVE) -{ - reg[0] = reg[1] = 0; -} - -Integer::Integer(const Integer& t) - : reg(RoundupSize(t.WordCount())), sign(t.sign) -{ - CopyWords(reg, t.reg, reg.size()); -} - -Integer::Integer(Sign s, lword value) - : reg(2), sign(s) -{ - reg[0] = word(value); - reg[1] = word(SafeRightShift(value)); -} - -Integer::Integer(signed long value) - : reg(2) -{ - if (value >= 0) - sign = POSITIVE; - else - { - sign = NEGATIVE; - value = -value; - } - reg[0] = word(value); - reg[1] = word(SafeRightShift((unsigned long)value)); -} - -Integer::Integer(Sign s, word high, word low) - : reg(2), sign(s) -{ - reg[0] = low; - reg[1] = high; -} - -bool Integer::IsConvertableToLong() const -{ - if (ByteCount() > sizeof(long)) - return false; - - unsigned long value = (unsigned long)reg[0]; - value += SafeLeftShift((unsigned long)reg[1]); - - if (sign==POSITIVE) - return (signed long)value >= 0; - else - return -(signed long)value < 0; -} - -signed long Integer::ConvertToLong() const -{ - assert(IsConvertableToLong()); - - unsigned long value = (unsigned long)reg[0]; - value += SafeLeftShift((unsigned long)reg[1]); - return sign==POSITIVE ? value : -(signed long)value; -} - -Integer::Integer(BufferedTransformation &encodedInteger, size_t byteCount, Signedness s) -{ - Decode(encodedInteger, byteCount, s); -} - -Integer::Integer(const byte *encodedInteger, size_t byteCount, Signedness s) -{ - Decode(encodedInteger, byteCount, s); -} - -Integer::Integer(BufferedTransformation &bt) -{ - BERDecode(bt); -} - -Integer::Integer(RandomNumberGenerator &rng, size_t bitcount) -{ - Randomize(rng, bitcount); -} - -Integer::Integer(RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType, const Integer &equiv, const Integer &mod) -{ - if (!Randomize(rng, min, max, rnType, equiv, mod)) - throw Integer::RandomNumberNotFound(); -} - -Integer Integer::Power2(size_t e) -{ - Integer r((word)0, BitsToWords(e+1)); - r.SetBit(e); - return r; -} - -template -struct NewInteger -{ - Integer * operator()() const - { - return new Integer(i); - } -}; - -const Integer &Integer::Zero() -{ - return Singleton().Ref(); -} - -const Integer &Integer::One() -{ - return Singleton >().Ref(); -} - -const Integer &Integer::Two() -{ - return Singleton >().Ref(); -} - -bool Integer::operator!() const -{ - return IsNegative() ? false : (reg[0]==0 && WordCount()==0); -} - -Integer& Integer::operator=(const Integer& t) -{ - if (this != &t) - { - if (reg.size() != t.reg.size() || t.reg[t.reg.size()/2] == 0) - reg.New(RoundupSize(t.WordCount())); - CopyWords(reg, t.reg, reg.size()); - sign = t.sign; - } - return *this; -} - -bool Integer::GetBit(size_t n) const -{ - if (n/WORD_BITS >= reg.size()) - return 0; - else - return bool((reg[n/WORD_BITS] >> (n % WORD_BITS)) & 1); -} - -void Integer::SetBit(size_t n, bool value) -{ - if (value) - { - reg.CleanGrow(RoundupSize(BitsToWords(n+1))); - reg[n/WORD_BITS] |= (word(1) << (n%WORD_BITS)); - } - else - { - if (n/WORD_BITS < reg.size()) - reg[n/WORD_BITS] &= ~(word(1) << (n%WORD_BITS)); - } -} - -byte Integer::GetByte(size_t n) const -{ - if (n/WORD_SIZE >= reg.size()) - return 0; - else - return byte(reg[n/WORD_SIZE] >> ((n%WORD_SIZE)*8)); -} - -void Integer::SetByte(size_t n, byte value) -{ - reg.CleanGrow(RoundupSize(BytesToWords(n+1))); - reg[n/WORD_SIZE] &= ~(word(0xff) << 8*(n%WORD_SIZE)); - reg[n/WORD_SIZE] |= (word(value) << 8*(n%WORD_SIZE)); -} - -lword Integer::GetBits(size_t i, size_t n) const -{ - lword v = 0; - assert(n <= sizeof(v)*8); - for (unsigned int j=0; j -static Integer StringToInteger(const T *str) -{ - int radix; - // GCC workaround - // std::char_traits::length() not defined in GCC 3.2 and STLport 4.5.3 - unsigned int length; - for (length = 0; str[length] != 0; length++) {} - - Integer v; - - if (length == 0) - return v; - - switch (str[length-1]) - { - case 'h': - case 'H': - radix=16; - break; - case 'o': - case 'O': - radix=8; - break; - case 'b': - case 'B': - radix=2; - break; - default: - radix=10; - } - - if (length > 2 && str[0] == '0' && str[1] == 'x') - radix = 16; - - for (unsigned i=0; i= '0' && str[i] <= '9') - digit = str[i] - '0'; - else if (str[i] >= 'A' && str[i] <= 'F') - digit = str[i] - 'A' + 10; - else if (str[i] >= 'a' && str[i] <= 'f') - digit = str[i] - 'a' + 10; - else - digit = radix; - - if (digit < radix) - { - v *= radix; - v += digit; - } - } - - if (str[0] == '-') - v.Negate(); - - return v; -} - -Integer::Integer(const char *str) - : reg(2), sign(POSITIVE) -{ - *this = StringToInteger(str); -} - -Integer::Integer(const wchar_t *str) - : reg(2), sign(POSITIVE) -{ - *this = StringToInteger(str); -} - -unsigned int Integer::WordCount() const -{ - return (unsigned int)CountWords(reg, reg.size()); -} - -unsigned int Integer::ByteCount() const -{ - unsigned wordCount = WordCount(); - if (wordCount) - return (wordCount-1)*WORD_SIZE + BytePrecision(reg[wordCount-1]); - else - return 0; -} - -unsigned int Integer::BitCount() const -{ - unsigned wordCount = WordCount(); - if (wordCount) - return (wordCount-1)*WORD_BITS + BitPrecision(reg[wordCount-1]); - else - return 0; -} - -void Integer::Decode(const byte *input, size_t inputLen, Signedness s) -{ - StringStore store(input, inputLen); - Decode(store, inputLen, s); -} - -void Integer::Decode(BufferedTransformation &bt, size_t inputLen, Signedness s) -{ - assert(bt.MaxRetrievable() >= inputLen); - - byte b; - bt.Peek(b); - sign = ((s==SIGNED) && (b & 0x80)) ? NEGATIVE : POSITIVE; - - while (inputLen>0 && (sign==POSITIVE ? b==0 : b==0xff)) - { - bt.Skip(1); - inputLen--; - bt.Peek(b); - } - - reg.CleanNew(RoundupSize(BytesToWords(inputLen))); - - for (size_t i=inputLen; i > 0; i--) - { - bt.Get(b); - reg[(i-1)/WORD_SIZE] |= word(b) << ((i-1)%WORD_SIZE)*8; - } - - if (sign == NEGATIVE) - { - for (size_t i=inputLen; i 0; i--) - bt.Put(GetByte(i-1)); - } - else - { - // take two's complement of *this - Integer temp = Integer::Power2(8*STDMAX((size_t)ByteCount(), outputLen)) + *this; - temp.Encode(bt, outputLen, UNSIGNED); - } -} - -void Integer::DEREncode(BufferedTransformation &bt) const -{ - DERGeneralEncoder enc(bt, INTEGER); - Encode(enc, MinEncodedSize(SIGNED), SIGNED); - enc.MessageEnd(); -} - -void Integer::BERDecode(const byte *input, size_t len) -{ - StringStore store(input, len); - BERDecode(store); -} - -void Integer::BERDecode(BufferedTransformation &bt) -{ - BERGeneralDecoder dec(bt, INTEGER); - if (!dec.IsDefiniteLength() || dec.MaxRetrievable() < dec.RemainingLength()) - BERDecodeError(); - Decode(dec, (size_t)dec.RemainingLength(), SIGNED); - dec.MessageEnd(); -} - -void Integer::DEREncodeAsOctetString(BufferedTransformation &bt, size_t length) const -{ - DERGeneralEncoder enc(bt, OCTET_STRING); - Encode(enc, length); - enc.MessageEnd(); -} - -void Integer::BERDecodeAsOctetString(BufferedTransformation &bt, size_t length) -{ - BERGeneralDecoder dec(bt, OCTET_STRING); - if (!dec.IsDefiniteLength() || dec.RemainingLength() != length) - BERDecodeError(); - Decode(dec, length); - dec.MessageEnd(); -} - -size_t Integer::OpenPGPEncode(byte *output, size_t len) const -{ - ArraySink sink(output, len); - return OpenPGPEncode(sink); -} - -size_t Integer::OpenPGPEncode(BufferedTransformation &bt) const -{ - word16 bitCount = BitCount(); - bt.PutWord16(bitCount); - size_t byteCount = BitsToBytes(bitCount); - Encode(bt, byteCount); - return 2 + byteCount; -} - -void Integer::OpenPGPDecode(const byte *input, size_t len) -{ - StringStore store(input, len); - OpenPGPDecode(store); -} - -void Integer::OpenPGPDecode(BufferedTransformation &bt) -{ - word16 bitCount; - if (bt.GetWord16(bitCount) != 2 || bt.MaxRetrievable() < BitsToBytes(bitCount)) - throw OpenPGPDecodeErr(); - Decode(bt, BitsToBytes(bitCount)); -} - -void Integer::Randomize(RandomNumberGenerator &rng, size_t nbits) -{ - const size_t nbytes = nbits/8 + 1; - SecByteBlock buf(nbytes); - rng.GenerateBlock(buf, nbytes); - if (nbytes) - buf[0] = (byte)Crop(buf[0], nbits % 8); - Decode(buf, nbytes, UNSIGNED); -} - -void Integer::Randomize(RandomNumberGenerator &rng, const Integer &min, const Integer &max) -{ - if (min > max) - throw InvalidArgument("Integer: Min must be no greater than Max"); - - Integer range = max - min; - const unsigned int nbits = range.BitCount(); - - do - { - Randomize(rng, nbits); - } - while (*this > range); - - *this += min; -} - -bool Integer::Randomize(RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType, const Integer &equiv, const Integer &mod) -{ - return GenerateRandomNoThrow(rng, MakeParameters("Min", min)("Max", max)("RandomNumberType", rnType)("EquivalentTo", equiv)("Mod", mod)); -} - -class KDF2_RNG : public RandomNumberGenerator -{ -public: - KDF2_RNG(const byte *seed, size_t seedSize) - : m_counter(0), m_counterAndSeed(seedSize + 4) - { - memcpy(m_counterAndSeed + 4, seed, seedSize); - } - - void GenerateBlock(byte *output, size_t size) - { - PutWord(false, BIG_ENDIAN_ORDER, m_counterAndSeed, m_counter); - ++m_counter; - P1363_KDF2::DeriveKey(output, size, m_counterAndSeed, m_counterAndSeed.size(), NULL, 0); - } - -private: - word32 m_counter; - SecByteBlock m_counterAndSeed; -}; - -bool Integer::GenerateRandomNoThrow(RandomNumberGenerator &i_rng, const NameValuePairs ¶ms) -{ - Integer min = params.GetValueWithDefault("Min", Integer::Zero()); - Integer max; - if (!params.GetValue("Max", max)) - { - int bitLength; - if (params.GetIntValue("BitLength", bitLength)) - max = Integer::Power2(bitLength); - else - throw InvalidArgument("Integer: missing Max argument"); - } - if (min > max) - throw InvalidArgument("Integer: Min must be no greater than Max"); - - Integer equiv = params.GetValueWithDefault("EquivalentTo", Integer::Zero()); - Integer mod = params.GetValueWithDefault("Mod", Integer::One()); - - if (equiv.IsNegative() || equiv >= mod) - throw InvalidArgument("Integer: invalid EquivalentTo and/or Mod argument"); - - Integer::RandomNumberType rnType = params.GetValueWithDefault("RandomNumberType", Integer::ANY); - - member_ptr kdf2Rng; - ConstByteArrayParameter seed; - if (params.GetValue(Name::Seed(), seed)) - { - ByteQueue bq; - DERSequenceEncoder seq(bq); - min.DEREncode(seq); - max.DEREncode(seq); - equiv.DEREncode(seq); - mod.DEREncode(seq); - DEREncodeUnsigned(seq, rnType); - DEREncodeOctetString(seq, seed.begin(), seed.size()); - seq.MessageEnd(); - - SecByteBlock finalSeed((size_t)bq.MaxRetrievable()); - bq.Get(finalSeed, finalSeed.size()); - kdf2Rng.reset(new KDF2_RNG(finalSeed.begin(), finalSeed.size())); - } - RandomNumberGenerator &rng = kdf2Rng.get() ? (RandomNumberGenerator &)*kdf2Rng : i_rng; - - switch (rnType) - { - case ANY: - if (mod == One()) - Randomize(rng, min, max); - else - { - Integer min1 = min + (equiv-min)%mod; - if (max < min1) - return false; - Randomize(rng, Zero(), (max - min1) / mod); - *this *= mod; - *this += min1; - } - return true; - - case PRIME: - { - const PrimeSelector *pSelector = params.GetValueWithDefault(Name::PointerToPrimeSelector(), (const PrimeSelector *)NULL); - - int i; - i = 0; - while (1) - { - if (++i==16) - { - // check if there are any suitable primes in [min, max] - Integer first = min; - if (FirstPrime(first, max, equiv, mod, pSelector)) - { - // if there is only one suitable prime, we're done - *this = first; - if (!FirstPrime(first, max, equiv, mod, pSelector)) - return true; - } - else - return false; - } - - Randomize(rng, min, max); - if (FirstPrime(*this, STDMIN(*this+mod*PrimeSearchInterval(max), max), equiv, mod, pSelector)) - return true; - } - } - - default: - throw InvalidArgument("Integer: invalid RandomNumberType argument"); - } -} - -std::istream& operator>>(std::istream& in, Integer &a) -{ - char c; - unsigned int length = 0; - SecBlock str(length + 16); - - std::ws(in); - - do - { - in.read(&c, 1); - str[length++] = c; - if (length >= str.size()) - str.Grow(length + 16); - } - while (in && (c=='-' || c=='x' || (c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F') || c=='h' || c=='H' || c=='o' || c=='O' || c==',' || c=='.')); - - if (in.gcount()) - in.putback(c); - str[length-1] = '\0'; - a = Integer(str); - - return in; -} - -std::ostream& operator<<(std::ostream& out, const Integer &a) -{ - // Get relevant conversion specifications from ostream. - long f = out.flags() & std::ios::basefield; // Get base digits. - int base, block; - char suffix; - switch(f) - { - case std::ios::oct : - base = 8; - block = 8; - suffix = 'o'; - break; - case std::ios::hex : - base = 16; - block = 4; - suffix = 'h'; - break; - default : - base = 10; - block = 3; - suffix = '.'; - } - - Integer temp1=a, temp2; - - if (a.IsNegative()) - { - out << '-'; - temp1.Negate(); - } - - if (!a) - out << '0'; - - static const char upper[]="0123456789ABCDEF"; - static const char lower[]="0123456789abcdef"; - - const char* vec = (out.flags() & std::ios::uppercase) ? upper : lower; - unsigned i=0; - SecBlock s(a.BitCount() / (BitPrecision(base)-1) + 1); - - while (!!temp1) - { - word digit; - Integer::Divide(digit, temp2, temp1, base); - s[i++]=vec[digit]; - temp1.swap(temp2); - } - - while (i--) - { - out << s[i]; -// if (i && !(i%block)) -// out << ","; - } - return out << suffix; -} - -Integer& Integer::operator++() -{ - if (NotNegative()) - { - if (Increment(reg, reg.size())) - { - reg.CleanGrow(2*reg.size()); - reg[reg.size()/2]=1; - } - } - else - { - word borrow = Decrement(reg, reg.size()); - assert(!borrow); - if (WordCount()==0) - *this = Zero(); - } - return *this; -} - -Integer& Integer::operator--() -{ - if (IsNegative()) - { - if (Increment(reg, reg.size())) - { - reg.CleanGrow(2*reg.size()); - reg[reg.size()/2]=1; - } - } - else - { - if (Decrement(reg, reg.size())) - *this = -One(); - } - return *this; -} - -void PositiveAdd(Integer &sum, const Integer &a, const Integer& b) -{ - int carry; - if (a.reg.size() == b.reg.size()) - carry = Add(sum.reg, a.reg, b.reg, a.reg.size()); - else if (a.reg.size() > b.reg.size()) - { - carry = Add(sum.reg, a.reg, b.reg, b.reg.size()); - CopyWords(sum.reg+b.reg.size(), a.reg+b.reg.size(), a.reg.size()-b.reg.size()); - carry = Increment(sum.reg+b.reg.size(), a.reg.size()-b.reg.size(), carry); - } - else - { - carry = Add(sum.reg, a.reg, b.reg, a.reg.size()); - CopyWords(sum.reg+a.reg.size(), b.reg+a.reg.size(), b.reg.size()-a.reg.size()); - carry = Increment(sum.reg+a.reg.size(), b.reg.size()-a.reg.size(), carry); - } - - if (carry) - { - sum.reg.CleanGrow(2*sum.reg.size()); - sum.reg[sum.reg.size()/2] = 1; - } - sum.sign = Integer::POSITIVE; -} - -void PositiveSubtract(Integer &diff, const Integer &a, const Integer& b) -{ - unsigned aSize = a.WordCount(); - aSize += aSize%2; - unsigned bSize = b.WordCount(); - bSize += bSize%2; - - if (aSize == bSize) - { - if (Compare(a.reg, b.reg, aSize) >= 0) - { - Subtract(diff.reg, a.reg, b.reg, aSize); - diff.sign = Integer::POSITIVE; - } - else - { - Subtract(diff.reg, b.reg, a.reg, aSize); - diff.sign = Integer::NEGATIVE; - } - } - else if (aSize > bSize) - { - word borrow = Subtract(diff.reg, a.reg, b.reg, bSize); - CopyWords(diff.reg+bSize, a.reg+bSize, aSize-bSize); - borrow = Decrement(diff.reg+bSize, aSize-bSize, borrow); - assert(!borrow); - diff.sign = Integer::POSITIVE; - } - else - { - word borrow = Subtract(diff.reg, b.reg, a.reg, aSize); - CopyWords(diff.reg+aSize, b.reg+aSize, bSize-aSize); - borrow = Decrement(diff.reg+aSize, bSize-aSize, borrow); - assert(!borrow); - diff.sign = Integer::NEGATIVE; - } -} - -// MSVC .NET 2003 workaround -template inline const T& STDMAX2(const T& a, const T& b) -{ - return a < b ? b : a; -} - -Integer Integer::Plus(const Integer& b) const -{ - Integer sum((word)0, STDMAX2(reg.size(), b.reg.size())); - if (NotNegative()) - { - if (b.NotNegative()) - PositiveAdd(sum, *this, b); - else - PositiveSubtract(sum, *this, b); - } - else - { - if (b.NotNegative()) - PositiveSubtract(sum, b, *this); - else - { - PositiveAdd(sum, *this, b); - sum.sign = Integer::NEGATIVE; - } - } - return sum; -} - -Integer& Integer::operator+=(const Integer& t) -{ - reg.CleanGrow(t.reg.size()); - if (NotNegative()) - { - if (t.NotNegative()) - PositiveAdd(*this, *this, t); - else - PositiveSubtract(*this, *this, t); - } - else - { - if (t.NotNegative()) - PositiveSubtract(*this, t, *this); - else - { - PositiveAdd(*this, *this, t); - sign = Integer::NEGATIVE; - } - } - return *this; -} - -Integer Integer::Minus(const Integer& b) const -{ - Integer diff((word)0, STDMAX2(reg.size(), b.reg.size())); - if (NotNegative()) - { - if (b.NotNegative()) - PositiveSubtract(diff, *this, b); - else - PositiveAdd(diff, *this, b); - } - else - { - if (b.NotNegative()) - { - PositiveAdd(diff, *this, b); - diff.sign = Integer::NEGATIVE; - } - else - PositiveSubtract(diff, b, *this); - } - return diff; -} - -Integer& Integer::operator-=(const Integer& t) -{ - reg.CleanGrow(t.reg.size()); - if (NotNegative()) - { - if (t.NotNegative()) - PositiveSubtract(*this, *this, t); - else - PositiveAdd(*this, *this, t); - } - else - { - if (t.NotNegative()) - { - PositiveAdd(*this, *this, t); - sign = Integer::NEGATIVE; - } - else - PositiveSubtract(*this, t, *this); - } - return *this; -} - -Integer& Integer::operator<<=(size_t n) -{ - const size_t wordCount = WordCount(); - const size_t shiftWords = n / WORD_BITS; - const unsigned int shiftBits = (unsigned int)(n % WORD_BITS); - - reg.CleanGrow(RoundupSize(wordCount+BitsToWords(n))); - ShiftWordsLeftByWords(reg, wordCount + shiftWords, shiftWords); - ShiftWordsLeftByBits(reg+shiftWords, wordCount+BitsToWords(shiftBits), shiftBits); - return *this; -} - -Integer& Integer::operator>>=(size_t n) -{ - const size_t wordCount = WordCount(); - const size_t shiftWords = n / WORD_BITS; - const unsigned int shiftBits = (unsigned int)(n % WORD_BITS); - - ShiftWordsRightByWords(reg, wordCount, shiftWords); - if (wordCount > shiftWords) - ShiftWordsRightByBits(reg, wordCount-shiftWords, shiftBits); - if (IsNegative() && WordCount()==0) // avoid -0 - *this = Zero(); - return *this; -} - -void PositiveMultiply(Integer &product, const Integer &a, const Integer &b) -{ - size_t aSize = RoundupSize(a.WordCount()); - size_t bSize = RoundupSize(b.WordCount()); - - product.reg.CleanNew(RoundupSize(aSize+bSize)); - product.sign = Integer::POSITIVE; - - IntegerSecBlock workspace(aSize + bSize); - AsymmetricMultiply(product.reg, workspace, a.reg, aSize, b.reg, bSize); -} - -void Multiply(Integer &product, const Integer &a, const Integer &b) -{ - PositiveMultiply(product, a, b); - - if (a.NotNegative() != b.NotNegative()) - product.Negate(); -} - -Integer Integer::Times(const Integer &b) const -{ - Integer product; - Multiply(product, *this, b); - return product; -} - -/* -void PositiveDivide(Integer &remainder, Integer "ient, - const Integer ÷nd, const Integer &divisor) -{ - remainder.reg.CleanNew(divisor.reg.size()); - remainder.sign = Integer::POSITIVE; - quotient.reg.New(0); - quotient.sign = Integer::POSITIVE; - unsigned i=dividend.BitCount(); - while (i--) - { - word overflow = ShiftWordsLeftByBits(remainder.reg, remainder.reg.size(), 1); - remainder.reg[0] |= dividend[i]; - if (overflow || remainder >= divisor) - { - Subtract(remainder.reg, remainder.reg, divisor.reg, remainder.reg.size()); - quotient.SetBit(i); - } - } -} -*/ - -void PositiveDivide(Integer &remainder, Integer "ient, - const Integer &a, const Integer &b) -{ - unsigned aSize = a.WordCount(); - unsigned bSize = b.WordCount(); - - if (!bSize) - throw Integer::DivideByZero(); - - if (aSize < bSize) - { - remainder = a; - remainder.sign = Integer::POSITIVE; - quotient = Integer::Zero(); - return; - } - - aSize += aSize%2; // round up to next even number - bSize += bSize%2; - - remainder.reg.CleanNew(RoundupSize(bSize)); - remainder.sign = Integer::POSITIVE; - quotient.reg.CleanNew(RoundupSize(aSize-bSize+2)); - quotient.sign = Integer::POSITIVE; - - IntegerSecBlock T(aSize+3*(bSize+2)); - Divide(remainder.reg, quotient.reg, T, a.reg, aSize, b.reg, bSize); -} - -void Integer::Divide(Integer &remainder, Integer "ient, const Integer ÷nd, const Integer &divisor) -{ - PositiveDivide(remainder, quotient, dividend, divisor); - - if (dividend.IsNegative()) - { - quotient.Negate(); - if (remainder.NotZero()) - { - --quotient; - remainder = divisor.AbsoluteValue() - remainder; - } - } - - if (divisor.IsNegative()) - quotient.Negate(); -} - -void Integer::DivideByPowerOf2(Integer &r, Integer &q, const Integer &a, unsigned int n) -{ - q = a; - q >>= n; - - const size_t wordCount = BitsToWords(n); - if (wordCount <= a.WordCount()) - { - r.reg.resize(RoundupSize(wordCount)); - CopyWords(r.reg, a.reg, wordCount); - SetWords(r.reg+wordCount, 0, r.reg.size()-wordCount); - if (n % WORD_BITS != 0) - r.reg[wordCount-1] %= (word(1) << (n % WORD_BITS)); - } - else - { - r.reg.resize(RoundupSize(a.WordCount())); - CopyWords(r.reg, a.reg, r.reg.size()); - } - r.sign = POSITIVE; - - if (a.IsNegative() && r.NotZero()) - { - --q; - r = Power2(n) - r; - } -} - -Integer Integer::DividedBy(const Integer &b) const -{ - Integer remainder, quotient; - Integer::Divide(remainder, quotient, *this, b); - return quotient; -} - -Integer Integer::Modulo(const Integer &b) const -{ - Integer remainder, quotient; - Integer::Divide(remainder, quotient, *this, b); - return remainder; -} - -void Integer::Divide(word &remainder, Integer "ient, const Integer ÷nd, word divisor) -{ - if (!divisor) - throw Integer::DivideByZero(); - - assert(divisor); - - if ((divisor & (divisor-1)) == 0) // divisor is a power of 2 - { - quotient = dividend >> (BitPrecision(divisor)-1); - remainder = dividend.reg[0] & (divisor-1); - return; - } - - unsigned int i = dividend.WordCount(); - quotient.reg.CleanNew(RoundupSize(i)); - remainder = 0; - while (i--) - { - quotient.reg[i] = DWord(dividend.reg[i], remainder) / divisor; - remainder = DWord(dividend.reg[i], remainder) % divisor; - } - - if (dividend.NotNegative()) - quotient.sign = POSITIVE; - else - { - quotient.sign = NEGATIVE; - if (remainder) - { - --quotient; - remainder = divisor - remainder; - } - } -} - -Integer Integer::DividedBy(word b) const -{ - word remainder; - Integer quotient; - Integer::Divide(remainder, quotient, *this, b); - return quotient; -} - -word Integer::Modulo(word divisor) const -{ - if (!divisor) - throw Integer::DivideByZero(); - - assert(divisor); - - word remainder; - - if ((divisor & (divisor-1)) == 0) // divisor is a power of 2 - remainder = reg[0] & (divisor-1); - else - { - unsigned int i = WordCount(); - - if (divisor <= 5) - { - DWord sum(0, 0); - while (i--) - sum += reg[i]; - remainder = sum % divisor; - } - else - { - remainder = 0; - while (i--) - remainder = DWord(reg[i], remainder) % divisor; - } - } - - if (IsNegative() && remainder) - remainder = divisor - remainder; - - return remainder; -} - -void Integer::Negate() -{ - if (!!(*this)) // don't flip sign if *this==0 - sign = Sign(1-sign); -} - -int Integer::PositiveCompare(const Integer& t) const -{ - unsigned size = WordCount(), tSize = t.WordCount(); - - if (size == tSize) - return CryptoPP::Compare(reg, t.reg, size); - else - return size > tSize ? 1 : -1; -} - -int Integer::Compare(const Integer& t) const -{ - if (NotNegative()) - { - if (t.NotNegative()) - return PositiveCompare(t); - else - return 1; - } - else - { - if (t.NotNegative()) - return -1; - else - return -PositiveCompare(t); - } -} - -Integer Integer::SquareRoot() const -{ - if (!IsPositive()) - return Zero(); - - // overestimate square root - Integer x, y = Power2((BitCount()+1)/2); - assert(y*y >= *this); - - do - { - x = y; - y = (x + *this/x) >> 1; - } while (y().Gcd(a, b); -} - -Integer Integer::InverseMod(const Integer &m) const -{ - assert(m.NotNegative()); - - if (IsNegative()) - return Modulo(m).InverseMod(m); - - if (m.IsEven()) - { - if (!m || IsEven()) - return Zero(); // no inverse - if (*this == One()) - return One(); - - Integer u = m.Modulo(*this).InverseMod(*this); - return !u ? Zero() : (m*(*this-u)+1)/(*this); - } - - SecBlock T(m.reg.size() * 4); - Integer r((word)0, m.reg.size()); - unsigned k = AlmostInverse(r.reg, T, reg, reg.size(), m.reg, m.reg.size()); - DivideByPower2Mod(r.reg, r.reg, k, m.reg, m.reg.size()); - return r; -} - -word Integer::InverseMod(word mod) const -{ - word g0 = mod, g1 = *this % mod; - word v0 = 0, v1 = 1; - word y; - - while (g1) - { - if (g1 == 1) - return v1; - y = g0 / g1; - g0 = g0 % g1; - v0 += y * v1; - - if (!g0) - break; - if (g0 == 1) - return mod-v0; - y = g1 / g0; - g1 = g1 % g0; - v1 += y * v0; - } - return 0; -} - -// ******************************************************** - -ModularArithmetic::ModularArithmetic(BufferedTransformation &bt) -{ - BERSequenceDecoder seq(bt); - OID oid(seq); - if (oid != ASN1::prime_field()) - BERDecodeError(); - m_modulus.BERDecode(seq); - seq.MessageEnd(); - m_result.reg.resize(m_modulus.reg.size()); -} - -void ModularArithmetic::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - ASN1::prime_field().DEREncode(seq); - m_modulus.DEREncode(seq); - seq.MessageEnd(); -} - -void ModularArithmetic::DEREncodeElement(BufferedTransformation &out, const Element &a) const -{ - a.DEREncodeAsOctetString(out, MaxElementByteLength()); -} - -void ModularArithmetic::BERDecodeElement(BufferedTransformation &in, Element &a) const -{ - a.BERDecodeAsOctetString(in, MaxElementByteLength()); -} - -const Integer& ModularArithmetic::Half(const Integer &a) const -{ - if (a.reg.size()==m_modulus.reg.size()) - { - CryptoPP::DivideByPower2Mod(m_result.reg.begin(), a.reg, 1, m_modulus.reg, a.reg.size()); - return m_result; - } - else - return m_result1 = (a.IsEven() ? (a >> 1) : ((a+m_modulus) >> 1)); -} - -const Integer& ModularArithmetic::Add(const Integer &a, const Integer &b) const -{ - if (a.reg.size()==m_modulus.reg.size() && b.reg.size()==m_modulus.reg.size()) - { - if (CryptoPP::Add(m_result.reg.begin(), a.reg, b.reg, a.reg.size()) - || Compare(m_result.reg, m_modulus.reg, a.reg.size()) >= 0) - { - CryptoPP::Subtract(m_result.reg.begin(), m_result.reg, m_modulus.reg, a.reg.size()); - } - return m_result; - } - else - { - m_result1 = a+b; - if (m_result1 >= m_modulus) - m_result1 -= m_modulus; - return m_result1; - } -} - -Integer& ModularArithmetic::Accumulate(Integer &a, const Integer &b) const -{ - if (a.reg.size()==m_modulus.reg.size() && b.reg.size()==m_modulus.reg.size()) - { - if (CryptoPP::Add(a.reg, a.reg, b.reg, a.reg.size()) - || Compare(a.reg, m_modulus.reg, a.reg.size()) >= 0) - { - CryptoPP::Subtract(a.reg, a.reg, m_modulus.reg, a.reg.size()); - } - } - else - { - a+=b; - if (a>=m_modulus) - a-=m_modulus; - } - - return a; -} - -const Integer& ModularArithmetic::Subtract(const Integer &a, const Integer &b) const -{ - if (a.reg.size()==m_modulus.reg.size() && b.reg.size()==m_modulus.reg.size()) - { - if (CryptoPP::Subtract(m_result.reg.begin(), a.reg, b.reg, a.reg.size())) - CryptoPP::Add(m_result.reg.begin(), m_result.reg, m_modulus.reg, a.reg.size()); - return m_result; - } - else - { - m_result1 = a-b; - if (m_result1.IsNegative()) - m_result1 += m_modulus; - return m_result1; - } -} - -Integer& ModularArithmetic::Reduce(Integer &a, const Integer &b) const -{ - if (a.reg.size()==m_modulus.reg.size() && b.reg.size()==m_modulus.reg.size()) - { - if (CryptoPP::Subtract(a.reg, a.reg, b.reg, a.reg.size())) - CryptoPP::Add(a.reg, a.reg, m_modulus.reg, a.reg.size()); - } - else - { - a-=b; - if (a.IsNegative()) - a+=m_modulus; - } - - return a; -} - -const Integer& ModularArithmetic::Inverse(const Integer &a) const -{ - if (!a) - return a; - - CopyWords(m_result.reg.begin(), m_modulus.reg, m_modulus.reg.size()); - if (CryptoPP::Subtract(m_result.reg.begin(), m_result.reg, a.reg, a.reg.size())) - Decrement(m_result.reg.begin()+a.reg.size(), m_modulus.reg.size()-a.reg.size()); - - return m_result; -} - -Integer ModularArithmetic::CascadeExponentiate(const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const -{ - if (m_modulus.IsOdd()) - { - MontgomeryRepresentation dr(m_modulus); - return dr.ConvertOut(dr.CascadeExponentiate(dr.ConvertIn(x), e1, dr.ConvertIn(y), e2)); - } - else - return AbstractRing::CascadeExponentiate(x, e1, y, e2); -} - -void ModularArithmetic::SimultaneousExponentiate(Integer *results, const Integer &base, const Integer *exponents, unsigned int exponentsCount) const -{ - if (m_modulus.IsOdd()) - { - MontgomeryRepresentation dr(m_modulus); - dr.SimultaneousExponentiate(results, dr.ConvertIn(base), exponents, exponentsCount); - for (unsigned int i=0; i::SimultaneousExponentiate(results, base, exponents, exponentsCount); -} - -MontgomeryRepresentation::MontgomeryRepresentation(const Integer &m) // modulus must be odd - : ModularArithmetic(m), - m_u((word)0, m_modulus.reg.size()), - m_workspace(5*m_modulus.reg.size()) -{ - if (!m_modulus.IsOdd()) - throw InvalidArgument("MontgomeryRepresentation: Montgomery representation requires an odd modulus"); - - RecursiveInverseModPower2(m_u.reg, m_workspace, m_modulus.reg, m_modulus.reg.size()); -} - -const Integer& MontgomeryRepresentation::Multiply(const Integer &a, const Integer &b) const -{ - word *const T = m_workspace.begin(); - word *const R = m_result.reg.begin(); - const size_t N = m_modulus.reg.size(); - assert(a.reg.size()<=N && b.reg.size()<=N); - - AsymmetricMultiply(T, T+2*N, a.reg, a.reg.size(), b.reg, b.reg.size()); - SetWords(T+a.reg.size()+b.reg.size(), 0, 2*N-a.reg.size()-b.reg.size()); - MontgomeryReduce(R, T+2*N, T, m_modulus.reg, m_u.reg, N); - return m_result; -} - -const Integer& MontgomeryRepresentation::Square(const Integer &a) const -{ - word *const T = m_workspace.begin(); - word *const R = m_result.reg.begin(); - const size_t N = m_modulus.reg.size(); - assert(a.reg.size()<=N); - - CryptoPP::Square(T, T+2*N, a.reg, a.reg.size()); - SetWords(T+2*a.reg.size(), 0, 2*N-2*a.reg.size()); - MontgomeryReduce(R, T+2*N, T, m_modulus.reg, m_u.reg, N); - return m_result; -} - -Integer MontgomeryRepresentation::ConvertOut(const Integer &a) const -{ - word *const T = m_workspace.begin(); - word *const R = m_result.reg.begin(); - const size_t N = m_modulus.reg.size(); - assert(a.reg.size()<=N); - - CopyWords(T, a.reg, a.reg.size()); - SetWords(T+a.reg.size(), 0, 2*N-a.reg.size()); - MontgomeryReduce(R, T+2*N, T, m_modulus.reg, m_u.reg, N); - return m_result; -} - -const Integer& MontgomeryRepresentation::MultiplicativeInverse(const Integer &a) const -{ -// return (EuclideanMultiplicativeInverse(a, modulus)<<(2*WORD_BITS*modulus.reg.size()))%modulus; - word *const T = m_workspace.begin(); - word *const R = m_result.reg.begin(); - const size_t N = m_modulus.reg.size(); - assert(a.reg.size()<=N); - - CopyWords(T, a.reg, a.reg.size()); - SetWords(T+a.reg.size(), 0, 2*N-a.reg.size()); - MontgomeryReduce(R, T+2*N, T, m_modulus.reg, m_u.reg, N); - unsigned k = AlmostInverse(R, T, R, N, m_modulus.reg, N); - -// cout << "k=" << k << " N*32=" << 32*N << endl; - - if (k>N*WORD_BITS) - DivideByPower2Mod(R, R, k-N*WORD_BITS, m_modulus.reg, N); - else - MultiplyByPower2Mod(R, R, N*WORD_BITS-k, m_modulus.reg, N); - - return m_result; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/integer.h b/lib/cryptopp/integer.h deleted file mode 100644 index 6d844fa57..000000000 --- a/lib/cryptopp/integer.h +++ /dev/null @@ -1,420 +0,0 @@ -#ifndef CRYPTOPP_INTEGER_H -#define CRYPTOPP_INTEGER_H - -/** \file */ - -#include "cryptlib.h" -#include "secblock.h" - -#include -#include - -NAMESPACE_BEGIN(CryptoPP) - -struct InitializeInteger // used to initialize static variables -{ - InitializeInteger(); -}; - -typedef SecBlock > IntegerSecBlock; - -//! multiple precision integer and basic arithmetics -/*! This class can represent positive and negative integers - with absolute value less than (256**sizeof(word)) ** (256**sizeof(int)). - \nosubgrouping -*/ -class CRYPTOPP_DLL Integer : private InitializeInteger, public ASN1Object -{ -public: - //! \name ENUMS, EXCEPTIONS, and TYPEDEFS - //@{ - //! division by zero exception - class DivideByZero : public Exception - { - public: - DivideByZero() : Exception(OTHER_ERROR, "Integer: division by zero") {} - }; - - //! - class RandomNumberNotFound : public Exception - { - public: - RandomNumberNotFound() : Exception(OTHER_ERROR, "Integer: no integer satisfies the given parameters") {} - }; - - //! - enum Sign {POSITIVE=0, NEGATIVE=1}; - - //! - enum Signedness { - //! - UNSIGNED, - //! - SIGNED}; - - //! - enum RandomNumberType { - //! - ANY, - //! - PRIME}; - //@} - - //! \name CREATORS - //@{ - //! creates the zero integer - Integer(); - - //! copy constructor - Integer(const Integer& t); - - //! convert from signed long - Integer(signed long value); - - //! convert from lword - Integer(Sign s, lword value); - - //! convert from two words - Integer(Sign s, word highWord, word lowWord); - - //! convert from string - /*! str can be in base 2, 8, 10, or 16. Base is determined by a - case insensitive suffix of 'h', 'o', or 'b'. No suffix means base 10. - */ - explicit Integer(const char *str); - explicit Integer(const wchar_t *str); - - //! convert from big-endian byte array - Integer(const byte *encodedInteger, size_t byteCount, Signedness s=UNSIGNED); - - //! convert from big-endian form stored in a BufferedTransformation - Integer(BufferedTransformation &bt, size_t byteCount, Signedness s=UNSIGNED); - - //! convert from BER encoded byte array stored in a BufferedTransformation object - explicit Integer(BufferedTransformation &bt); - - //! create a random integer - /*! The random integer created is uniformly distributed over [0, 2**bitcount). */ - Integer(RandomNumberGenerator &rng, size_t bitcount); - - //! avoid calling constructors for these frequently used integers - static const Integer & CRYPTOPP_API Zero(); - //! avoid calling constructors for these frequently used integers - static const Integer & CRYPTOPP_API One(); - //! avoid calling constructors for these frequently used integers - static const Integer & CRYPTOPP_API Two(); - - //! create a random integer of special type - /*! Ideally, the random integer created should be uniformly distributed - over {x | min <= x <= max and x is of rnType and x % mod == equiv}. - However the actual distribution may not be uniform because sequential - search is used to find an appropriate number from a random starting - point. - May return (with very small probability) a pseudoprime when a prime - is requested and max > lastSmallPrime*lastSmallPrime (lastSmallPrime - is declared in nbtheory.h). - \throw RandomNumberNotFound if the set is empty. - */ - Integer(RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType=ANY, const Integer &equiv=Zero(), const Integer &mod=One()); - - //! return the integer 2**e - static Integer CRYPTOPP_API Power2(size_t e); - //@} - - //! \name ENCODE/DECODE - //@{ - //! minimum number of bytes to encode this integer - /*! MinEncodedSize of 0 is 1 */ - size_t MinEncodedSize(Signedness=UNSIGNED) const; - //! encode in big-endian format - /*! unsigned means encode absolute value, signed means encode two's complement if negative. - if outputLen < MinEncodedSize, the most significant bytes will be dropped - if outputLen > MinEncodedSize, the most significant bytes will be padded - */ - void Encode(byte *output, size_t outputLen, Signedness=UNSIGNED) const; - //! - void Encode(BufferedTransformation &bt, size_t outputLen, Signedness=UNSIGNED) const; - - //! encode using Distinguished Encoding Rules, put result into a BufferedTransformation object - void DEREncode(BufferedTransformation &bt) const; - - //! encode absolute value as big-endian octet string - void DEREncodeAsOctetString(BufferedTransformation &bt, size_t length) const; - - //! encode absolute value in OpenPGP format, return length of output - size_t OpenPGPEncode(byte *output, size_t bufferSize) const; - //! encode absolute value in OpenPGP format, put result into a BufferedTransformation object - size_t OpenPGPEncode(BufferedTransformation &bt) const; - - //! - void Decode(const byte *input, size_t inputLen, Signedness=UNSIGNED); - //! - //* Precondition: bt.MaxRetrievable() >= inputLen - void Decode(BufferedTransformation &bt, size_t inputLen, Signedness=UNSIGNED); - - //! - void BERDecode(const byte *input, size_t inputLen); - //! - void BERDecode(BufferedTransformation &bt); - - //! decode nonnegative value as big-endian octet string - void BERDecodeAsOctetString(BufferedTransformation &bt, size_t length); - - class OpenPGPDecodeErr : public Exception - { - public: - OpenPGPDecodeErr() : Exception(INVALID_DATA_FORMAT, "OpenPGP decode error") {} - }; - - //! - void OpenPGPDecode(const byte *input, size_t inputLen); - //! - void OpenPGPDecode(BufferedTransformation &bt); - //@} - - //! \name ACCESSORS - //@{ - //! return true if *this can be represented as a signed long - bool IsConvertableToLong() const; - //! return equivalent signed long if possible, otherwise undefined - signed long ConvertToLong() const; - - //! number of significant bits = floor(log2(abs(*this))) + 1 - unsigned int BitCount() const; - //! number of significant bytes = ceiling(BitCount()/8) - unsigned int ByteCount() const; - //! number of significant words = ceiling(ByteCount()/sizeof(word)) - unsigned int WordCount() const; - - //! return the i-th bit, i=0 being the least significant bit - bool GetBit(size_t i) const; - //! return the i-th byte - byte GetByte(size_t i) const; - //! return n lowest bits of *this >> i - lword GetBits(size_t i, size_t n) const; - - //! - bool IsZero() const {return !*this;} - //! - bool NotZero() const {return !IsZero();} - //! - bool IsNegative() const {return sign == NEGATIVE;} - //! - bool NotNegative() const {return !IsNegative();} - //! - bool IsPositive() const {return NotNegative() && NotZero();} - //! - bool NotPositive() const {return !IsPositive();} - //! - bool IsEven() const {return GetBit(0) == 0;} - //! - bool IsOdd() const {return GetBit(0) == 1;} - //@} - - //! \name MANIPULATORS - //@{ - //! - Integer& operator=(const Integer& t); - - //! - Integer& operator+=(const Integer& t); - //! - Integer& operator-=(const Integer& t); - //! - Integer& operator*=(const Integer& t) {return *this = Times(t);} - //! - Integer& operator/=(const Integer& t) {return *this = DividedBy(t);} - //! - Integer& operator%=(const Integer& t) {return *this = Modulo(t);} - //! - Integer& operator/=(word t) {return *this = DividedBy(t);} - //! - Integer& operator%=(word t) {return *this = Integer(POSITIVE, 0, Modulo(t));} - - //! - Integer& operator<<=(size_t); - //! - Integer& operator>>=(size_t); - - //! - void Randomize(RandomNumberGenerator &rng, size_t bitcount); - //! - void Randomize(RandomNumberGenerator &rng, const Integer &min, const Integer &max); - //! set this Integer to a random element of {x | min <= x <= max and x is of rnType and x % mod == equiv} - /*! returns false if the set is empty */ - bool Randomize(RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType, const Integer &equiv=Zero(), const Integer &mod=One()); - - bool GenerateRandomNoThrow(RandomNumberGenerator &rng, const NameValuePairs ¶ms = g_nullNameValuePairs); - void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms = g_nullNameValuePairs) - { - if (!GenerateRandomNoThrow(rng, params)) - throw RandomNumberNotFound(); - } - - //! set the n-th bit to value - void SetBit(size_t n, bool value=1); - //! set the n-th byte to value - void SetByte(size_t n, byte value); - - //! - void Negate(); - //! - void SetPositive() {sign = POSITIVE;} - //! - void SetNegative() {if (!!(*this)) sign = NEGATIVE;} - - //! - void swap(Integer &a); - //@} - - //! \name UNARY OPERATORS - //@{ - //! - bool operator!() const; - //! - Integer operator+() const {return *this;} - //! - Integer operator-() const; - //! - Integer& operator++(); - //! - Integer& operator--(); - //! - Integer operator++(int) {Integer temp = *this; ++*this; return temp;} - //! - Integer operator--(int) {Integer temp = *this; --*this; return temp;} - //@} - - //! \name BINARY OPERATORS - //@{ - //! signed comparison - /*! \retval -1 if *this < a - \retval 0 if *this = a - \retval 1 if *this > a - */ - int Compare(const Integer& a) const; - - //! - Integer Plus(const Integer &b) const; - //! - Integer Minus(const Integer &b) const; - //! - Integer Times(const Integer &b) const; - //! - Integer DividedBy(const Integer &b) const; - //! - Integer Modulo(const Integer &b) const; - //! - Integer DividedBy(word b) const; - //! - word Modulo(word b) const; - - //! - Integer operator>>(size_t n) const {return Integer(*this)>>=n;} - //! - Integer operator<<(size_t n) const {return Integer(*this)<<=n;} - //@} - - //! \name OTHER ARITHMETIC FUNCTIONS - //@{ - //! - Integer AbsoluteValue() const; - //! - Integer Doubled() const {return Plus(*this);} - //! - Integer Squared() const {return Times(*this);} - //! extract square root, if negative return 0, else return floor of square root - Integer SquareRoot() const; - //! return whether this integer is a perfect square - bool IsSquare() const; - - //! is 1 or -1 - bool IsUnit() const; - //! return inverse if 1 or -1, otherwise return 0 - Integer MultiplicativeInverse() const; - - //! modular multiplication - CRYPTOPP_DLL friend Integer CRYPTOPP_API a_times_b_mod_c(const Integer &x, const Integer& y, const Integer& m); - //! modular exponentiation - CRYPTOPP_DLL friend Integer CRYPTOPP_API a_exp_b_mod_c(const Integer &x, const Integer& e, const Integer& m); - - //! calculate r and q such that (a == d*q + r) && (0 <= r < abs(d)) - static void CRYPTOPP_API Divide(Integer &r, Integer &q, const Integer &a, const Integer &d); - //! use a faster division algorithm when divisor is short - static void CRYPTOPP_API Divide(word &r, Integer &q, const Integer &a, word d); - - //! returns same result as Divide(r, q, a, Power2(n)), but faster - static void CRYPTOPP_API DivideByPowerOf2(Integer &r, Integer &q, const Integer &a, unsigned int n); - - //! greatest common divisor - static Integer CRYPTOPP_API Gcd(const Integer &a, const Integer &n); - //! calculate multiplicative inverse of *this mod n - Integer InverseMod(const Integer &n) const; - //! - word InverseMod(word n) const; - //@} - - //! \name INPUT/OUTPUT - //@{ - //! - friend CRYPTOPP_DLL std::istream& CRYPTOPP_API operator>>(std::istream& in, Integer &a); - //! - friend CRYPTOPP_DLL std::ostream& CRYPTOPP_API operator<<(std::ostream& out, const Integer &a); - //@} - -private: - friend class ModularArithmetic; - friend class MontgomeryRepresentation; - friend class HalfMontgomeryRepresentation; - - Integer(word value, size_t length); - - int PositiveCompare(const Integer &t) const; - friend void PositiveAdd(Integer &sum, const Integer &a, const Integer &b); - friend void PositiveSubtract(Integer &diff, const Integer &a, const Integer &b); - friend void PositiveMultiply(Integer &product, const Integer &a, const Integer &b); - friend void PositiveDivide(Integer &remainder, Integer "ient, const Integer ÷nd, const Integer &divisor); - - IntegerSecBlock reg; - Sign sign; -}; - -//! -inline bool operator==(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)==0;} -//! -inline bool operator!=(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)!=0;} -//! -inline bool operator> (const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)> 0;} -//! -inline bool operator>=(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)>=0;} -//! -inline bool operator< (const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)< 0;} -//! -inline bool operator<=(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)<=0;} -//! -inline CryptoPP::Integer operator+(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Plus(b);} -//! -inline CryptoPP::Integer operator-(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Minus(b);} -//! -inline CryptoPP::Integer operator*(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Times(b);} -//! -inline CryptoPP::Integer operator/(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.DividedBy(b);} -//! -inline CryptoPP::Integer operator%(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Modulo(b);} -//! -inline CryptoPP::Integer operator/(const CryptoPP::Integer &a, CryptoPP::word b) {return a.DividedBy(b);} -//! -inline CryptoPP::word operator%(const CryptoPP::Integer &a, CryptoPP::word b) {return a.Modulo(b);} - -NAMESPACE_END - -#ifndef __BORLANDC__ -NAMESPACE_BEGIN(std) -inline void swap(CryptoPP::Integer &a, CryptoPP::Integer &b) -{ - a.swap(b); -} -NAMESPACE_END -#endif - -#endif diff --git a/lib/cryptopp/iterhash.cpp b/lib/cryptopp/iterhash.cpp deleted file mode 100644 index 1e31e9fb3..000000000 --- a/lib/cryptopp/iterhash.cpp +++ /dev/null @@ -1,160 +0,0 @@ -// iterhash.cpp - written and placed in the public domain by Wei Dai - -#ifndef __GNUC__ -#define CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES -#endif - -#include "iterhash.h" -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) - -template void IteratedHashBase::Update(const byte *input, size_t len) -{ - HashWordType oldCountLo = m_countLo, oldCountHi = m_countHi; - if ((m_countLo = oldCountLo + HashWordType(len)) < oldCountLo) - m_countHi++; // carry from low to high - m_countHi += (HashWordType)SafeRightShift<8*sizeof(HashWordType)>(len); - if (m_countHi < oldCountHi || SafeRightShift<2*8*sizeof(HashWordType)>(len) != 0) - throw HashInputTooLong(this->AlgorithmName()); - - unsigned int blockSize = this->BlockSize(); - unsigned int num = ModPowerOf2(oldCountLo, blockSize); - T* dataBuf = this->DataBuf(); - byte* data = (byte *)dataBuf; - - if (num != 0) // process left over data - { - if (num+len >= blockSize) - { - memcpy(data+num, input, blockSize-num); - HashBlock(dataBuf); - input += (blockSize-num); - len -= (blockSize-num); - num = 0; - // drop through and do the rest - } - else - { - memcpy(data+num, input, len); - return; - } - } - - // now process the input data in blocks of blockSize bytes and save the leftovers to m_data - if (len >= blockSize) - { - if (input == data) - { - assert(len == blockSize); - HashBlock(dataBuf); - return; - } - else if (IsAligned(input)) - { - size_t leftOver = HashMultipleBlocks((T *)input, len); - input += (len - leftOver); - len = leftOver; - } - else - do - { // copy input first if it's not aligned correctly - memcpy(data, input, blockSize); - HashBlock(dataBuf); - input+=blockSize; - len-=blockSize; - } while (len >= blockSize); - } - - if (len && data != input) - memcpy(data, input, len); -} - -template byte * IteratedHashBase::CreateUpdateSpace(size_t &size) -{ - unsigned int blockSize = this->BlockSize(); - unsigned int num = ModPowerOf2(m_countLo, blockSize); - size = blockSize - num; - return (byte *)DataBuf() + num; -} - -template size_t IteratedHashBase::HashMultipleBlocks(const T *input, size_t length) -{ - unsigned int blockSize = this->BlockSize(); - bool noReverse = NativeByteOrderIs(this->GetByteOrder()); - T* dataBuf = this->DataBuf(); - do - { - if (noReverse) - this->HashEndianCorrectedBlock(input); - else - { - ByteReverse(dataBuf, input, this->BlockSize()); - this->HashEndianCorrectedBlock(dataBuf); - } - - input += blockSize/sizeof(T); - length -= blockSize; - } - while (length >= blockSize); - return length; -} - -template void IteratedHashBase::PadLastBlock(unsigned int lastBlockSize, byte padFirst) -{ - unsigned int blockSize = this->BlockSize(); - unsigned int num = ModPowerOf2(m_countLo, blockSize); - T* dataBuf = this->DataBuf(); - byte* data = (byte *)dataBuf; - data[num++] = padFirst; - if (num <= lastBlockSize) - memset(data+num, 0, lastBlockSize-num); - else - { - memset(data+num, 0, blockSize-num); - HashBlock(dataBuf); - memset(data, 0, lastBlockSize); - } -} - -template void IteratedHashBase::Restart() -{ - m_countLo = m_countHi = 0; - Init(); -} - -template void IteratedHashBase::TruncatedFinal(byte *digest, size_t size) -{ - this->ThrowIfInvalidTruncatedSize(size); - - T* dataBuf = this->DataBuf(); - T* stateBuf = this->StateBuf(); - unsigned int blockSize = this->BlockSize(); - ByteOrder order = this->GetByteOrder(); - - PadLastBlock(blockSize - 2*sizeof(HashWordType)); - dataBuf[blockSize/sizeof(T)-2+order] = ConditionalByteReverse(order, this->GetBitCountLo()); - dataBuf[blockSize/sizeof(T)-1-order] = ConditionalByteReverse(order, this->GetBitCountHi()); - - HashBlock(dataBuf); - - if (IsAligned(digest) && size%sizeof(HashWordType)==0) - ConditionalByteReverse(order, (HashWordType *)digest, stateBuf, size); - else - { - ConditionalByteReverse(order, stateBuf, stateBuf, this->DigestSize()); - memcpy(digest, stateBuf, size); - } - - this->Restart(); // reinit for next use -} - -#ifdef __GNUC__ - template class IteratedHashBase; - template class IteratedHashBase; - - template class IteratedHashBase; - template class IteratedHashBase; -#endif - -NAMESPACE_END diff --git a/lib/cryptopp/iterhash.h b/lib/cryptopp/iterhash.h deleted file mode 100644 index cce9e8211..000000000 --- a/lib/cryptopp/iterhash.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef CRYPTOPP_ITERHASH_H -#define CRYPTOPP_ITERHASH_H - -#include "cryptlib.h" -#include "secblock.h" -#include "misc.h" -#include "simple.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! exception thrown when trying to hash more data than is allowed by a hash function -class CRYPTOPP_DLL HashInputTooLong : public InvalidDataFormat -{ -public: - explicit HashInputTooLong(const std::string &alg) - : InvalidDataFormat("IteratedHashBase: input data exceeds maximum allowed by hash function " + alg) {} -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE IteratedHashBase : public BASE -{ -public: - typedef T HashWordType; - - IteratedHashBase() : m_countLo(0), m_countHi(0) {} - unsigned int OptimalBlockSize() const {return this->BlockSize();} - unsigned int OptimalDataAlignment() const {return GetAlignmentOf();} - void Update(const byte *input, size_t length); - byte * CreateUpdateSpace(size_t &size); - void Restart(); - void TruncatedFinal(byte *digest, size_t size); - -protected: - inline T GetBitCountHi() const {return (m_countLo >> (8*sizeof(T)-3)) + (m_countHi << 3);} - inline T GetBitCountLo() const {return m_countLo << 3;} - - void PadLastBlock(unsigned int lastBlockSize, byte padFirst=0x80); - virtual void Init() =0; - - virtual ByteOrder GetByteOrder() const =0; - virtual void HashEndianCorrectedBlock(const HashWordType *data) =0; - virtual size_t HashMultipleBlocks(const T *input, size_t length); - void HashBlock(const HashWordType *input) {HashMultipleBlocks(input, this->BlockSize());} - - virtual T* DataBuf() =0; - virtual T* StateBuf() =0; - -private: - T m_countLo, m_countHi; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE IteratedHash : public IteratedHashBase -{ -public: - typedef T_Endianness ByteOrderClass; - typedef T_HashWordType HashWordType; - - CRYPTOPP_CONSTANT(BLOCKSIZE = T_BlockSize) - // BCB2006 workaround: can't use BLOCKSIZE here - CRYPTOPP_COMPILE_ASSERT((T_BlockSize & (T_BlockSize - 1)) == 0); // blockSize is a power of 2 - unsigned int BlockSize() const {return T_BlockSize;} - - ByteOrder GetByteOrder() const {return T_Endianness::ToEnum();} - - inline static void CorrectEndianess(HashWordType *out, const HashWordType *in, size_t byteCount) - { - ConditionalByteReverse(T_Endianness::ToEnum(), out, in, byteCount); - } - -protected: - T_HashWordType* DataBuf() {return this->m_data;} - FixedSizeSecBlock m_data; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE IteratedHashWithStaticTransform - : public ClonableImpl, T_Transform> > -{ -public: - CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize ? T_DigestSize : T_StateSize) - unsigned int DigestSize() const {return DIGESTSIZE;}; - -protected: - IteratedHashWithStaticTransform() {this->Init();} - void HashEndianCorrectedBlock(const T_HashWordType *data) {T_Transform::Transform(this->m_state, data);} - void Init() {T_Transform::InitState(this->m_state);} - - T_HashWordType* StateBuf() {return this->m_state;} - FixedSizeAlignedSecBlock m_state; -}; - -#ifndef __GNUC__ - CRYPTOPP_DLL_TEMPLATE_CLASS IteratedHashBase; - CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase; - - CRYPTOPP_DLL_TEMPLATE_CLASS IteratedHashBase; - CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase; -#endif - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/lubyrack.h b/lib/cryptopp/lubyrack.h deleted file mode 100644 index e8fd2f748..000000000 --- a/lib/cryptopp/lubyrack.h +++ /dev/null @@ -1,141 +0,0 @@ -// lubyrack.h - written and placed in the public domain by Wei Dai - -#ifndef CRYPTOPP_LUBYRACK_H -#define CRYPTOPP_LUBYRACK_H - -/** \file */ - -#include "simple.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -template struct DigestSizeDoubleWorkaround // VC60 workaround -{ - CRYPTOPP_CONSTANT(RESULT = 2*T::DIGESTSIZE) -}; - -//! algorithm info -template -struct LR_Info : public VariableKeyLength<16, 0, 2*(INT_MAX/2), 2>, public FixedBlockSize::RESULT> -{ - static std::string StaticAlgorithmName() {return std::string("LR/")+T::StaticAlgorithmName();} -}; - -//! Luby-Rackoff -template -class LR : public LR_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl > - { - public: - // VC60 workaround: have to define these functions within class definition - void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms) - { - this->AssertValidKeyLength(length); - - L = length/2; - buffer.New(2*S); - digest.New(S); - key.Assign(userKey, 2*L); - } - - protected: - CRYPTOPP_CONSTANT(S=T::DIGESTSIZE) - unsigned int L; // key length / 2 - SecByteBlock key; - - mutable T hm; - mutable SecByteBlock buffer, digest; - }; - - class CRYPTOPP_NO_VTABLE Enc : public Base - { - public: - -#define KL this->key -#define KR this->key+this->L -#define BL this->buffer -#define BR this->buffer+this->S -#define IL inBlock -#define IR inBlock+this->S -#define OL outBlock -#define OR outBlock+this->S - - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const - { - this->hm.Update(KL, this->L); - this->hm.Update(IL, this->S); - this->hm.Final(BR); - xorbuf(BR, IR, this->S); - - this->hm.Update(KR, this->L); - this->hm.Update(BR, this->S); - this->hm.Final(BL); - xorbuf(BL, IL, this->S); - - this->hm.Update(KL, this->L); - this->hm.Update(BL, this->S); - this->hm.Final(this->digest); - xorbuf(BR, this->digest, this->S); - - this->hm.Update(KR, this->L); - this->hm.Update(OR, this->S); - this->hm.Final(this->digest); - xorbuf(BL, this->digest, this->S); - - if (xorBlock) - xorbuf(outBlock, xorBlock, this->buffer, 2*this->S); - else - memcpy_s(outBlock, 2*this->S, this->buffer, 2*this->S); - } - }; - - class CRYPTOPP_NO_VTABLE Dec : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const - { - this->hm.Update(KR, this->L); - this->hm.Update(IR, this->S); - this->hm.Final(BL); - xorbuf(BL, IL, this->S); - - this->hm.Update(KL, this->L); - this->hm.Update(BL, this->S); - this->hm.Final(BR); - xorbuf(BR, IR, this->S); - - this->hm.Update(KR, this->L); - this->hm.Update(BR, this->S); - this->hm.Final(this->digest); - xorbuf(BL, this->digest, this->S); - - this->hm.Update(KL, this->L); - this->hm.Update(OL, this->S); - this->hm.Final(this->digest); - xorbuf(BR, this->digest, this->S); - - if (xorBlock) - xorbuf(outBlock, xorBlock, this->buffer, 2*this->S); - else - memcpy(outBlock, this->buffer, 2*this->S); - } -#undef KL -#undef KR -#undef BL -#undef BR -#undef IL -#undef IR -#undef OL -#undef OR - }; - -public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/luc.cpp b/lib/cryptopp/luc.cpp deleted file mode 100644 index 43cd2ed21..000000000 --- a/lib/cryptopp/luc.cpp +++ /dev/null @@ -1,210 +0,0 @@ -// luc.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "luc.h" -#include "asn.h" -#include "nbtheory.h" -#include "sha.h" -#include "algparam.h" - -NAMESPACE_BEGIN(CryptoPP) - -void LUC_TestInstantiations() -{ - LUC_HMP::Signer t1; - LUCFunction t2; - InvertibleLUCFunction t3; -} - -void DL_Algorithm_LUC_HMP::Sign(const DL_GroupParameters ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const -{ - const Integer &q = params.GetSubgroupOrder(); - r = params.ExponentiateBase(k); - s = (k + x*(r+e)) % q; -} - -bool DL_Algorithm_LUC_HMP::Verify(const DL_GroupParameters ¶ms, const DL_PublicKey &publicKey, const Integer &e, const Integer &r, const Integer &s) const -{ - Integer p = params.GetGroupOrder()-1; - const Integer &q = params.GetSubgroupOrder(); - - Integer Vsg = params.ExponentiateBase(s); - Integer Vry = publicKey.ExponentiatePublicElement((r+e)%q); - return (Vsg*Vsg + Vry*Vry + r*r) % p == (Vsg * Vry * r + 4) % p; -} - -Integer DL_BasePrecomputation_LUC::Exponentiate(const DL_GroupPrecomputation &group, const Integer &exponent) const -{ - return Lucas(exponent, m_g, static_cast(group).GetModulus()); -} - -void DL_GroupParameters_LUC::SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const -{ - for (unsigned int i=0; i Integer::One() && m_n.IsOdd(); - pass = pass && m_e > Integer::One() && m_e.IsOdd() && m_e < m_n; - return pass; -} - -bool LUCFunction::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - return GetValueHelper(this, name, valueType, pValue).Assignable() - CRYPTOPP_GET_FUNCTION_ENTRY(Modulus) - CRYPTOPP_GET_FUNCTION_ENTRY(PublicExponent) - ; -} - -void LUCFunction::AssignFrom(const NameValuePairs &source) -{ - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(Modulus) - CRYPTOPP_SET_FUNCTION_ENTRY(PublicExponent) - ; -} - -// ***************************************************************************** -// private key operations: - -class LUCPrimeSelector : public PrimeSelector -{ -public: - LUCPrimeSelector(const Integer &e) : m_e(e) {} - bool IsAcceptable(const Integer &candidate) const - { - return RelativelyPrime(m_e, candidate+1) && RelativelyPrime(m_e, candidate-1); - } - Integer m_e; -}; - -void InvertibleLUCFunction::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg) -{ - int modulusSize = 2048; - alg.GetIntValue("ModulusSize", modulusSize) || alg.GetIntValue("KeySize", modulusSize); - - if (modulusSize < 16) - throw InvalidArgument("InvertibleLUCFunction: specified modulus size is too small"); - - m_e = alg.GetValueWithDefault("PublicExponent", Integer(17)); - - if (m_e < 5 || m_e.IsEven()) - throw InvalidArgument("InvertibleLUCFunction: invalid public exponent"); - - LUCPrimeSelector selector(m_e); - AlgorithmParameters primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize) - ("PointerToPrimeSelector", selector.GetSelectorPointer()); - m_p.GenerateRandom(rng, primeParam); - m_q.GenerateRandom(rng, primeParam); - - m_n = m_p * m_q; - m_u = m_q.InverseMod(m_p); -} - -void InvertibleLUCFunction::Initialize(RandomNumberGenerator &rng, unsigned int keybits, const Integer &e) -{ - GenerateRandom(rng, MakeParameters("ModulusSize", (int)keybits)("PublicExponent", e)); -} - -void InvertibleLUCFunction::BERDecode(BufferedTransformation &bt) -{ - BERSequenceDecoder seq(bt); - - Integer version(seq); - if (!!version) // make sure version is 0 - BERDecodeError(); - - m_n.BERDecode(seq); - m_e.BERDecode(seq); - m_p.BERDecode(seq); - m_q.BERDecode(seq); - m_u.BERDecode(seq); - seq.MessageEnd(); -} - -void InvertibleLUCFunction::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - - const byte version[] = {INTEGER, 1, 0}; - seq.Put(version, sizeof(version)); - m_n.DEREncode(seq); - m_e.DEREncode(seq); - m_p.DEREncode(seq); - m_q.DEREncode(seq); - m_u.DEREncode(seq); - seq.MessageEnd(); -} - -Integer InvertibleLUCFunction::CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const -{ - // not clear how to do blinding with LUC - DoQuickSanityCheck(); - return InverseLucas(m_e, x, m_q, m_p, m_u); -} - -bool InvertibleLUCFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = LUCFunction::Validate(rng, level); - pass = pass && m_p > Integer::One() && m_p.IsOdd() && m_p < m_n; - pass = pass && m_q > Integer::One() && m_q.IsOdd() && m_q < m_n; - pass = pass && m_u.IsPositive() && m_u < m_p; - if (level >= 1) - { - pass = pass && m_p * m_q == m_n; - pass = pass && RelativelyPrime(m_e, m_p+1); - pass = pass && RelativelyPrime(m_e, m_p-1); - pass = pass && RelativelyPrime(m_e, m_q+1); - pass = pass && RelativelyPrime(m_e, m_q-1); - pass = pass && m_u * m_q % m_p == 1; - } - if (level >= 2) - pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2); - return pass; -} - -bool InvertibleLUCFunction::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - return GetValueHelper(this, name, valueType, pValue).Assignable() - CRYPTOPP_GET_FUNCTION_ENTRY(Prime1) - CRYPTOPP_GET_FUNCTION_ENTRY(Prime2) - CRYPTOPP_GET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1) - ; -} - -void InvertibleLUCFunction::AssignFrom(const NameValuePairs &source) -{ - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(Prime1) - CRYPTOPP_SET_FUNCTION_ENTRY(Prime2) - CRYPTOPP_SET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1) - ; -} - -NAMESPACE_END diff --git a/lib/cryptopp/luc.h b/lib/cryptopp/luc.h deleted file mode 100644 index 730776d57..000000000 --- a/lib/cryptopp/luc.h +++ /dev/null @@ -1,236 +0,0 @@ -#ifndef CRYPTOPP_LUC_H -#define CRYPTOPP_LUC_H - -/** \file -*/ - -#include "pkcspad.h" -#include "oaep.h" -#include "integer.h" -#include "dh.h" - -#include - -NAMESPACE_BEGIN(CryptoPP) - -//! The LUC function. -/*! This class is here for historical and pedagogical interest. It has no - practical advantages over other trapdoor functions and probably shouldn't - be used in production software. The discrete log based LUC schemes - defined later in this .h file may be of more practical interest. -*/ -class LUCFunction : public TrapdoorFunction, public PublicKey -{ - typedef LUCFunction ThisClass; - -public: - void Initialize(const Integer &n, const Integer &e) - {m_n = n; m_e = e;} - - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - Integer ApplyFunction(const Integer &x) const; - Integer PreimageBound() const {return m_n;} - Integer ImageBound() const {return m_n;} - - bool Validate(RandomNumberGenerator &rng, unsigned int level) const; - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - - // non-derived interface - const Integer & GetModulus() const {return m_n;} - const Integer & GetPublicExponent() const {return m_e;} - - void SetModulus(const Integer &n) {m_n = n;} - void SetPublicExponent(const Integer &e) {m_e = e;} - -protected: - Integer m_n, m_e; -}; - -//! _ -class InvertibleLUCFunction : public LUCFunction, public TrapdoorFunctionInverse, public PrivateKey -{ - typedef InvertibleLUCFunction ThisClass; - -public: - void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &eStart=17); - void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q, const Integer &u) - {m_n = n; m_e = e; m_p = p; m_q = q; m_u = u;} - - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const; - - bool Validate(RandomNumberGenerator &rng, unsigned int level) const; - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - /*! parameters: (ModulusSize, PublicExponent (default 17)) */ - void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); - - // non-derived interface - const Integer& GetPrime1() const {return m_p;} - const Integer& GetPrime2() const {return m_q;} - const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;} - - void SetPrime1(const Integer &p) {m_p = p;} - void SetPrime2(const Integer &q) {m_q = q;} - void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;} - -protected: - Integer m_p, m_q, m_u; -}; - -struct LUC -{ - static std::string StaticAlgorithmName() {return "LUC";} - typedef LUCFunction PublicKey; - typedef InvertibleLUCFunction PrivateKey; -}; - -//! LUC cryptosystem -template -struct LUCES : public TF_ES -{ -}; - -//! LUC signature scheme with appendix -template -struct LUCSS : public TF_SS -{ -}; - -// analagous to the RSA schemes defined in PKCS #1 v2.0 -typedef LUCES >::Decryptor LUCES_OAEP_SHA_Decryptor; -typedef LUCES >::Encryptor LUCES_OAEP_SHA_Encryptor; - -typedef LUCSS::Signer LUCSSA_PKCS1v15_SHA_Signer; -typedef LUCSS::Verifier LUCSSA_PKCS1v15_SHA_Verifier; - -// ******************************************************** - -// no actual precomputation -class DL_GroupPrecomputation_LUC : public DL_GroupPrecomputation -{ -public: - const AbstractGroup & GetGroup() const {assert(false); throw 0;} - Element BERDecodeElement(BufferedTransformation &bt) const {return Integer(bt);} - void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {v.DEREncode(bt);} - - // non-inherited - void SetModulus(const Integer &v) {m_p = v;} - const Integer & GetModulus() const {return m_p;} - -private: - Integer m_p; -}; - -//! _ -class DL_BasePrecomputation_LUC : public DL_FixedBasePrecomputation -{ -public: - // DL_FixedBasePrecomputation - bool IsInitialized() const {return m_g.NotZero();} - void SetBase(const DL_GroupPrecomputation &group, const Integer &base) {m_g = base;} - const Integer & GetBase(const DL_GroupPrecomputation &group) const {return m_g;} - void Precompute(const DL_GroupPrecomputation &group, unsigned int maxExpBits, unsigned int storage) {} - void Load(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation) {} - void Save(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation) const {} - Integer Exponentiate(const DL_GroupPrecomputation &group, const Integer &exponent) const; - Integer CascadeExponentiate(const DL_GroupPrecomputation &group, const Integer &exponent, const DL_FixedBasePrecomputation &pc2, const Integer &exponent2) const - {throw NotImplemented("DL_BasePrecomputation_LUC: CascadeExponentiate not implemented");} // shouldn't be called - -private: - Integer m_g; -}; - -//! _ -class DL_GroupParameters_LUC : public DL_GroupParameters_IntegerBasedImpl -{ -public: - // DL_GroupParameters - bool IsIdentity(const Integer &element) const {return element == Integer::Two();} - void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const; - Element MultiplyElements(const Element &a, const Element &b) const - {throw NotImplemented("LUC_GroupParameters: MultiplyElements can not be implemented");} - Element CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const - {throw NotImplemented("LUC_GroupParameters: MultiplyElements can not be implemented");} - - // NameValuePairs interface - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const - { - return GetValueHelper(this, name, valueType, pValue).Assignable(); - } - -private: - int GetFieldType() const {return 2;} -}; - -//! _ -class DL_GroupParameters_LUC_DefaultSafePrime : public DL_GroupParameters_LUC -{ -public: - typedef NoCofactorMultiplication DefaultCofactorOption; - -protected: - unsigned int GetDefaultSubgroupOrderSize(unsigned int modulusSize) const {return modulusSize-1;} -}; - -//! _ -class DL_Algorithm_LUC_HMP : public DL_ElgamalLikeSignatureAlgorithm -{ -public: - static const char * StaticAlgorithmName() {return "LUC-HMP";} - - void Sign(const DL_GroupParameters ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const; - bool Verify(const DL_GroupParameters ¶ms, const DL_PublicKey &publicKey, const Integer &e, const Integer &r, const Integer &s) const; - - size_t RLen(const DL_GroupParameters ¶ms) const - {return params.GetGroupOrder().ByteCount();} -}; - -//! _ -struct DL_SignatureKeys_LUC -{ - typedef DL_GroupParameters_LUC GroupParameters; - typedef DL_PublicKey_GFP PublicKey; - typedef DL_PrivateKey_GFP PrivateKey; -}; - -//! LUC-HMP, based on "Digital signature schemes based on Lucas functions" by Patrick Horster, Markus Michels, Holger Petersen -template -struct LUC_HMP : public DL_SS -{ -}; - -//! _ -struct DL_CryptoKeys_LUC -{ - typedef DL_GroupParameters_LUC_DefaultSafePrime GroupParameters; - typedef DL_PublicKey_GFP PublicKey; - typedef DL_PrivateKey_GFP PrivateKey; -}; - -//! LUC-IES -template -struct LUC_IES - : public DL_ES< - DL_CryptoKeys_LUC, - DL_KeyAgreementAlgorithm_DH, - DL_KeyDerivationAlgorithm_P1363 >, - DL_EncryptionAlgorithm_Xor, DHAES_MODE>, - LUC_IES<> > -{ - static std::string StaticAlgorithmName() {return "LUC-IES";} // non-standard name -}; - -// ******************************************************** - -//! LUC-DH -typedef DH_Domain LUC_DH; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/md2.cpp b/lib/cryptopp/md2.cpp deleted file mode 100644 index 41f714b59..000000000 --- a/lib/cryptopp/md2.cpp +++ /dev/null @@ -1,120 +0,0 @@ -// md2.cpp - modified by Wei Dai from Andrew M. Kuchling's md2.c -// The original code and all modifications are in the public domain. - -// This is the original introductory comment: - -/* - * md2.c : MD2 hash algorithm. - * - * Part of the Python Cryptography Toolkit, version 1.1 - * - * Distribute and use freely; there are no restrictions on further - * dissemination and usage except those imposed by the laws of your - * country of residence. - * - */ - -#include "pch.h" -#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 -#include "md2.h" - -NAMESPACE_BEGIN(CryptoPP) -namespace Weak1 { - -MD2::MD2() - : m_X(48), m_C(16), m_buf(16) -{ - Init(); -} - -void MD2::Init() -{ - memset(m_X, 0, 48); - memset(m_C, 0, 16); - memset(m_buf, 0, 16); - m_count = 0; -} - -void MD2::Update(const byte *buf, size_t len) -{ - static const byte S[256] = { - 41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6, - 19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188, - 76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24, - 138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251, - 245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63, - 148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50, - 39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165, - 181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210, - 150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157, - 112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27, - 96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15, - 85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197, - 234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65, - 129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123, - 8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233, - 203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228, - 166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237, - 31, 26, 219, 153, 141, 51, 159, 17, 131, 20 - }; - - while (len) - { - unsigned int L = UnsignedMin(16U-m_count, len); - memcpy(m_buf+m_count, buf, L); - m_count+=L; - buf+=L; - len-=L; - if (m_count==16) - { - byte t; - int i,j; - - m_count=0; - memcpy(m_X+16, m_buf, 16); - t=m_C[15]; - for(i=0; i<16; i++) - { - m_X[32+i]=m_X[16+i]^m_X[i]; - t=m_C[i]^=S[m_buf[i]^t]; - } - - t=0; - for(i=0; i<18; i++) - { - for(j=0; j<48; j+=8) - { - t=m_X[j+0]^=S[t]; - t=m_X[j+1]^=S[t]; - t=m_X[j+2]^=S[t]; - t=m_X[j+3]^=S[t]; - t=m_X[j+4]^=S[t]; - t=m_X[j+5]^=S[t]; - t=m_X[j+6]^=S[t]; - t=m_X[j+7]^=S[t]; - } - t=(t+i) & 0xFF; - } - } - } -} - -void MD2::TruncatedFinal(byte *hash, size_t size) -{ - ThrowIfInvalidTruncatedSize(size); - - byte padding[16]; - word32 padlen; - unsigned int i; - - padlen= 16-m_count; - for(i=0; iMD2 -class MD2 : public HashTransformation -{ -public: - MD2(); - void Update(const byte *input, size_t length); - void TruncatedFinal(byte *hash, size_t size); - unsigned int DigestSize() const {return DIGESTSIZE;} - unsigned int BlockSize() const {return BLOCKSIZE;} - static const char * StaticAlgorithmName() {return "MD2";} - - CRYPTOPP_CONSTANT(DIGESTSIZE = 16) - CRYPTOPP_CONSTANT(BLOCKSIZE = 16) - -private: - void Transform(); - void Init(); - SecByteBlock m_X, m_C, m_buf; - unsigned int m_count; -}; - -} -#if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1 -namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak -#else -using namespace Weak1; // import Weak1 into CryptoPP with warning -#ifdef __GNUC__ -#warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning." -#else -#pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning.") -#endif -#endif - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/md4.cpp b/lib/cryptopp/md4.cpp deleted file mode 100644 index 9ed639cb9..000000000 --- a/lib/cryptopp/md4.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// md4.cpp - modified by Wei Dai from Andrew M. Kuchling's md4.c -// The original code and all modifications are in the public domain. - -// This is the original introductory comment: - -/* - * md4.c : MD4 hash algorithm. - * - * Part of the Python Cryptography Toolkit, version 1.1 - * - * Distribute and use freely; there are no restrictions on further - * dissemination and usage except those imposed by the laws of your - * country of residence. - * - */ - -#include "pch.h" -#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 -#include "md4.h" -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) -namespace Weak1 { - -void MD4::InitState(HashWordType *state) -{ - state[0] = 0x67452301L; - state[1] = 0xefcdab89L; - state[2] = 0x98badcfeL; - state[3] = 0x10325476L; -} - -void MD4::Transform (word32 *digest, const word32 *in) -{ -// #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) -#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) -#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) -#define H(x, y, z) ((x) ^ (y) ^ (z)) - - word32 A, B, C, D; - - A=digest[0]; - B=digest[1]; - C=digest[2]; - D=digest[3]; - -#define function(a,b,c,d,k,s) a=rotlFixed(a+F(b,c,d)+in[k],s); - function(A,B,C,D, 0, 3); - function(D,A,B,C, 1, 7); - function(C,D,A,B, 2,11); - function(B,C,D,A, 3,19); - function(A,B,C,D, 4, 3); - function(D,A,B,C, 5, 7); - function(C,D,A,B, 6,11); - function(B,C,D,A, 7,19); - function(A,B,C,D, 8, 3); - function(D,A,B,C, 9, 7); - function(C,D,A,B,10,11); - function(B,C,D,A,11,19); - function(A,B,C,D,12, 3); - function(D,A,B,C,13, 7); - function(C,D,A,B,14,11); - function(B,C,D,A,15,19); - -#undef function -#define function(a,b,c,d,k,s) a=rotlFixed(a+G(b,c,d)+in[k]+0x5a827999,s); - function(A,B,C,D, 0, 3); - function(D,A,B,C, 4, 5); - function(C,D,A,B, 8, 9); - function(B,C,D,A,12,13); - function(A,B,C,D, 1, 3); - function(D,A,B,C, 5, 5); - function(C,D,A,B, 9, 9); - function(B,C,D,A,13,13); - function(A,B,C,D, 2, 3); - function(D,A,B,C, 6, 5); - function(C,D,A,B,10, 9); - function(B,C,D,A,14,13); - function(A,B,C,D, 3, 3); - function(D,A,B,C, 7, 5); - function(C,D,A,B,11, 9); - function(B,C,D,A,15,13); - -#undef function -#define function(a,b,c,d,k,s) a=rotlFixed(a+H(b,c,d)+in[k]+0x6ed9eba1,s); - function(A,B,C,D, 0, 3); - function(D,A,B,C, 8, 9); - function(C,D,A,B, 4,11); - function(B,C,D,A,12,15); - function(A,B,C,D, 2, 3); - function(D,A,B,C,10, 9); - function(C,D,A,B, 6,11); - function(B,C,D,A,14,15); - function(A,B,C,D, 1, 3); - function(D,A,B,C, 9, 9); - function(C,D,A,B, 5,11); - function(B,C,D,A,13,15); - function(A,B,C,D, 3, 3); - function(D,A,B,C,11, 9); - function(C,D,A,B, 7,11); - function(B,C,D,A,15,15); - - digest[0]+=A; - digest[1]+=B; - digest[2]+=C; - digest[3]+=D; -} - -} -NAMESPACE_END diff --git a/lib/cryptopp/md4.h b/lib/cryptopp/md4.h deleted file mode 100644 index 53387003c..000000000 --- a/lib/cryptopp/md4.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef CRYPTOPP_MD4_H -#define CRYPTOPP_MD4_H - -#include "iterhash.h" - -NAMESPACE_BEGIN(CryptoPP) - -namespace Weak1 { - -//! MD4 -/*! \warning MD4 is considered insecure, and should not be used - unless you absolutely need it for compatibility. */ -class MD4 : public IteratedHashWithStaticTransform -{ -public: - static void InitState(HashWordType *state); - static void Transform(word32 *digest, const word32 *data); - static const char *StaticAlgorithmName() {return "MD4";} -}; - -} -#if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1 -namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak -#else -using namespace Weak1; // import Weak1 into CryptoPP with warning -#ifdef __GNUC__ -#warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning." -#else -#pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning.") -#endif -#endif - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/md5.cpp b/lib/cryptopp/md5.cpp deleted file mode 100644 index a52297816..000000000 --- a/lib/cryptopp/md5.cpp +++ /dev/null @@ -1,118 +0,0 @@ -// md5.cpp - modified by Wei Dai from Colin Plumb's public domain md5.c -// any modifications are placed in the public domain - -#include "pch.h" -#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 -#include "md5.h" -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) -namespace Weak1 { - -void MD5_TestInstantiations() -{ - MD5 x; -} - -void MD5::InitState(HashWordType *state) -{ - state[0] = 0x67452301L; - state[1] = 0xefcdab89L; - state[2] = 0x98badcfeL; - state[3] = 0x10325476L; -} - -void MD5::Transform (word32 *digest, const word32 *in) -{ -// #define F1(x, y, z) (x & y | ~x & z) -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -#define MD5STEP(f, w, x, y, z, data, s) \ - w = rotlFixed(w + f(x, y, z) + data, s) + x - - word32 a, b, c, d; - - a=digest[0]; - b=digest[1]; - c=digest[2]; - d=digest[3]; - - MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); - MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); - MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); - MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); - MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); - MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); - MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); - MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); - MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); - MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); - MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); - MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); - MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); - MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); - MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); - MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); - MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); - MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); - MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); - MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); - MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); - MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); - MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); - MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); - MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); - MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); - MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); - MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); - MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); - MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); - - MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); - MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); - MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); - MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); - MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); - MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); - MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); - MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); - MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); - MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); - - digest[0]+=a; - digest[1]+=b; - digest[2]+=c; - digest[3]+=d; -} - -} -NAMESPACE_END diff --git a/lib/cryptopp/md5.h b/lib/cryptopp/md5.h deleted file mode 100644 index 73ec5326c..000000000 --- a/lib/cryptopp/md5.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef CRYPTOPP_MD5_H -#define CRYPTOPP_MD5_H - -#include "iterhash.h" - -NAMESPACE_BEGIN(CryptoPP) - -namespace Weak1 { - -//! MD5 -class MD5 : public IteratedHashWithStaticTransform -{ -public: - static void InitState(HashWordType *state); - static void Transform(word32 *digest, const word32 *data); - static const char * StaticAlgorithmName() {return "MD5";} -}; - -} -#if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1 -namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak -#else -using namespace Weak1; // import Weak1 into CryptoPP with warning -#ifdef __GNUC__ -#warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning." -#else -#pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning.") -#endif -#endif - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/mdc.h b/lib/cryptopp/mdc.h deleted file mode 100644 index cc90cdc45..000000000 --- a/lib/cryptopp/mdc.h +++ /dev/null @@ -1,72 +0,0 @@ - // mdc.h - written and placed in the public domain by Wei Dai - -#ifndef CRYPTOPP_MDC_H -#define CRYPTOPP_MDC_H - -/** \file -*/ - -#include "seckey.h" -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -template -struct MDC_Info : public FixedBlockSize, public FixedKeyLength -{ - static std::string StaticAlgorithmName() {return std::string("MDC/")+T::StaticAlgorithmName();} -}; - -//! MDC -/*! a construction by Peter Gutmann to turn an iterated hash function into a PRF */ -template -class MDC : public MDC_Info -{ - class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl > - { - typedef typename T::HashWordType HashWordType; - - public: - void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms) - { - this->AssertValidKeyLength(length); - memcpy_s(m_key, m_key.size(), userKey, this->KEYLENGTH); - T::CorrectEndianess(Key(), Key(), this->KEYLENGTH); - } - - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const - { - T::CorrectEndianess(Buffer(), (HashWordType *)inBlock, this->BLOCKSIZE); - T::Transform(Buffer(), Key()); - if (xorBlock) - { - T::CorrectEndianess(Buffer(), Buffer(), this->BLOCKSIZE); - xorbuf(outBlock, xorBlock, m_buffer, this->BLOCKSIZE); - } - else - T::CorrectEndianess((HashWordType *)outBlock, Buffer(), this->BLOCKSIZE); - } - - bool IsPermutation() const {return false;} - - unsigned int OptimalDataAlignment() const {return sizeof(HashWordType);} - - private: - HashWordType *Key() {return (HashWordType *)m_key.data();} - const HashWordType *Key() const {return (const HashWordType *)m_key.data();} - HashWordType *Buffer() const {return (HashWordType *)m_buffer.data();} - - // VC60 workaround: bug triggered if using FixedSizeAllocatorWithCleanup - FixedSizeSecBlock::KEYLENGTH, AllocatorWithCleanup > m_key; - mutable FixedSizeSecBlock::BLOCKSIZE, AllocatorWithCleanup > m_buffer; - }; - -public: - //! use BlockCipher interface - typedef BlockCipherFinal Encryption; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/misc.cpp b/lib/cryptopp/misc.cpp deleted file mode 100644 index 93760e3a3..000000000 --- a/lib/cryptopp/misc.cpp +++ /dev/null @@ -1,189 +0,0 @@ -// misc.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "misc.h" -#include "words.h" -#include - -#if defined(CRYPTOPP_MEMALIGN_AVAILABLE) || defined(CRYPTOPP_MM_MALLOC_AVAILABLE) || defined(QNX) -#include -#endif - -NAMESPACE_BEGIN(CryptoPP) - -void xorbuf(byte *buf, const byte *mask, size_t count) -{ - size_t i; - - if (IsAligned(buf) && IsAligned(mask)) - { - if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned(buf) && IsAligned(mask)) - { - for (i=0; i(output) && IsAligned(input) && IsAligned(mask)) - { - if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned(output) && IsAligned(input) && IsAligned(mask)) - { - for (i=0; i(buf) && IsAligned(mask)) - { - word32 acc32 = 0; - if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned(buf) && IsAligned(mask)) - { - word64 acc64 = 0; - for (i=0; i>32); - } - - for (i=0; i>8) | byte(acc32>>16) | byte(acc32>>24); - } - - for (i=0; i // for memcpy and memmove - -#ifdef _MSC_VER - #if _MSC_VER >= 1400 - // VC2005 workaround: disable declarations that conflict with winnt.h - #define _interlockedbittestandset CRYPTOPP_DISABLED_INTRINSIC_1 - #define _interlockedbittestandreset CRYPTOPP_DISABLED_INTRINSIC_2 - #define _interlockedbittestandset64 CRYPTOPP_DISABLED_INTRINSIC_3 - #define _interlockedbittestandreset64 CRYPTOPP_DISABLED_INTRINSIC_4 - #include - #undef _interlockedbittestandset - #undef _interlockedbittestandreset - #undef _interlockedbittestandset64 - #undef _interlockedbittestandreset64 - #define CRYPTOPP_FAST_ROTATE(x) 1 - #elif _MSC_VER >= 1300 - #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32 | (x) == 64) - #else - #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32) - #endif -#elif (defined(__MWERKS__) && TARGET_CPU_PPC) || \ - (defined(__GNUC__) && (defined(_ARCH_PWR2) || defined(_ARCH_PWR) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || defined(_ARCH_COM))) - #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32) -#elif defined(__GNUC__) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86) // depend on GCC's peephole optimization to generate rotate instructions - #define CRYPTOPP_FAST_ROTATE(x) 1 -#else - #define CRYPTOPP_FAST_ROTATE(x) 0 -#endif - -#ifdef __BORLANDC__ -#include -#endif - -#if defined(__GNUC__) && defined(__linux__) -#define CRYPTOPP_BYTESWAP_AVAILABLE -#include -#endif - -NAMESPACE_BEGIN(CryptoPP) - -// ************** compile-time assertion *************** - -template -struct CompileAssert -{ - static char dummy[2*b-1]; -}; - -#define CRYPTOPP_COMPILE_ASSERT(assertion) CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, __LINE__) -#if defined(CRYPTOPP_EXPORTS) || defined(CRYPTOPP_IMPORTS) -#define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) -#else -#define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) static CompileAssert<(assertion)> CRYPTOPP_ASSERT_JOIN(cryptopp_assert_, instance) -#endif -#define CRYPTOPP_ASSERT_JOIN(X, Y) CRYPTOPP_DO_ASSERT_JOIN(X, Y) -#define CRYPTOPP_DO_ASSERT_JOIN(X, Y) X##Y - -// ************** misc classes *************** - -class CRYPTOPP_DLL Empty -{ -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE TwoBases : public BASE1, public BASE2 -{ -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE ThreeBases : public BASE1, public BASE2, public BASE3 -{ -}; - -template -class ObjectHolder -{ -protected: - T m_object; -}; - -class NotCopyable -{ -public: - NotCopyable() {} -private: - NotCopyable(const NotCopyable &); - void operator=(const NotCopyable &); -}; - -template -struct NewObject -{ - T* operator()() const {return new T;} -}; - -/*! This function safely initializes a static object in a multithreaded environment without using locks (for portability). - Note that if two threads call Ref() at the same time, they may get back different references, and one object - may end up being memory leaked. This is by design. -*/ -template , int instance=0> -class Singleton -{ -public: - Singleton(F objectFactory = F()) : m_objectFactory(objectFactory) {} - - // prevent this function from being inlined - CRYPTOPP_NOINLINE const T & Ref(CRYPTOPP_NOINLINE_DOTDOTDOT) const; - -private: - F m_objectFactory; -}; - -template -const T & Singleton::Ref(CRYPTOPP_NOINLINE_DOTDOTDOT) const -{ - static volatile simple_ptr s_pObject; - T *p = s_pObject.m_p; - - if (p) - return *p; - - T *newObject = m_objectFactory(); - p = s_pObject.m_p; - - if (p) - { - delete newObject; - return *p; - } - - s_pObject.m_p = newObject; - return *newObject; -} - -// ************** misc functions *************** - -#if (!__STDC_WANT_SECURE_LIB__ && !defined(_MEMORY_S_DEFINED)) -inline void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count) -{ - if (count > sizeInBytes) - throw InvalidArgument("memcpy_s: buffer overflow"); - memcpy(dest, src, count); -} - -inline void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t count) -{ - if (count > sizeInBytes) - throw InvalidArgument("memmove_s: buffer overflow"); - memmove(dest, src, count); -} - -#if __BORLANDC__ >= 0x620 -// C++Builder 2010 workaround: can't use std::memcpy_s because it doesn't allow 0 lengths -#define memcpy_s CryptoPP::memcpy_s -#define memmove_s CryptoPP::memmove_s -#endif -#endif - -inline void * memset_z(void *ptr, int value, size_t num) -{ -// avoid extranous warning on GCC 4.3.2 Ubuntu 8.10 -#if CRYPTOPP_GCC_VERSION >= 30001 - if (__builtin_constant_p(num) && num==0) - return ptr; -#endif - return memset(ptr, value, num); -} - -// can't use std::min or std::max in MSVC60 or Cygwin 1.1.0 -template inline const T& STDMIN(const T& a, const T& b) -{ - return b < a ? b : a; -} - -template inline const T1 UnsignedMin(const T1& a, const T2& b) -{ - CRYPTOPP_COMPILE_ASSERT((sizeof(T1)<=sizeof(T2) && T2(-1)>0) || (sizeof(T1)>sizeof(T2) && T1(-1)>0)); - assert(a==0 || a>0); // GCC workaround: get rid of the warning "comparison is always true due to limited range of data type" - assert(b>=0); - - if (sizeof(T1)<=sizeof(T2)) - return b < (T2)a ? (T1)b : a; - else - return (T1)b < a ? (T1)b : a; -} - -template inline const T& STDMAX(const T& a, const T& b) -{ - return a < b ? b : a; -} - -#define RETURN_IF_NONZERO(x) size_t returnedValue = x; if (returnedValue) return returnedValue - -// this version of the macro is fastest on Pentium 3 and Pentium 4 with MSVC 6 SP5 w/ Processor Pack -#define GETBYTE(x, y) (unsigned int)byte((x)>>(8*(y))) -// these may be faster on other CPUs/compilers -// #define GETBYTE(x, y) (unsigned int)(((x)>>(8*(y)))&255) -// #define GETBYTE(x, y) (((byte *)&(x))[y]) - -#define CRYPTOPP_GET_BYTE_AS_BYTE(x, y) byte((x)>>(8*(y))) - -template -unsigned int Parity(T value) -{ - for (unsigned int i=8*sizeof(value)/2; i>0; i/=2) - value ^= value >> i; - return (unsigned int)value&1; -} - -template -unsigned int BytePrecision(const T &value) -{ - if (!value) - return 0; - - unsigned int l=0, h=8*sizeof(value); - - while (h-l > 8) - { - unsigned int t = (l+h)/2; - if (value >> t) - l = t; - else - h = t; - } - - return h/8; -} - -template -unsigned int BitPrecision(const T &value) -{ - if (!value) - return 0; - - unsigned int l=0, h=8*sizeof(value); - - while (h-l > 1) - { - unsigned int t = (l+h)/2; - if (value >> t) - l = t; - else - h = t; - } - - return h; -} - -inline unsigned int TrailingZeros(word32 v) -{ -#if defined(__GNUC__) && CRYPTOPP_GCC_VERSION >= 30400 - return __builtin_ctz(v); -#elif defined(_MSC_VER) && _MSC_VER >= 1400 - unsigned long result; - _BitScanForward(&result, v); - return result; -#else - // from http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup - static const int MultiplyDeBruijnBitPosition[32] = - { - 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, - 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 - }; - return MultiplyDeBruijnBitPosition[((word32)((v & -v) * 0x077CB531U)) >> 27]; -#endif -} - -inline unsigned int TrailingZeros(word64 v) -{ -#if defined(__GNUC__) && CRYPTOPP_GCC_VERSION >= 30400 - return __builtin_ctzll(v); -#elif defined(_MSC_VER) && _MSC_VER >= 1400 && (defined(_M_X64) || defined(_M_IA64)) - unsigned long result; - _BitScanForward64(&result, v); - return result; -#else - return word32(v) ? TrailingZeros(word32(v)) : 32 + TrailingZeros(word32(v>>32)); -#endif -} - -template -inline T Crop(T value, size_t size) -{ - if (size < 8*sizeof(value)) - return T(value & ((T(1) << size) - 1)); - else - return value; -} - -template -inline bool SafeConvert(T1 from, T2 &to) -{ - to = (T2)from; - if (from != to || (from > 0) != (to > 0)) - return false; - return true; -} - -inline size_t BitsToBytes(size_t bitCount) -{ - return ((bitCount+7)/(8)); -} - -inline size_t BytesToWords(size_t byteCount) -{ - return ((byteCount+WORD_SIZE-1)/WORD_SIZE); -} - -inline size_t BitsToWords(size_t bitCount) -{ - return ((bitCount+WORD_BITS-1)/(WORD_BITS)); -} - -inline size_t BitsToDwords(size_t bitCount) -{ - return ((bitCount+2*WORD_BITS-1)/(2*WORD_BITS)); -} - -CRYPTOPP_DLL void CRYPTOPP_API xorbuf(byte *buf, const byte *mask, size_t count); -CRYPTOPP_DLL void CRYPTOPP_API xorbuf(byte *output, const byte *input, const byte *mask, size_t count); - -CRYPTOPP_DLL bool CRYPTOPP_API VerifyBufsEqual(const byte *buf1, const byte *buf2, size_t count); - -template -inline bool IsPowerOf2(const T &n) -{ - return n > 0 && (n & (n-1)) == 0; -} - -template -inline T2 ModPowerOf2(const T1 &a, const T2 &b) -{ - assert(IsPowerOf2(b)); - return T2(a) & (b-1); -} - -template -inline T1 RoundDownToMultipleOf(const T1 &n, const T2 &m) -{ - if (IsPowerOf2(m)) - return n - ModPowerOf2(n, m); - else - return n - n%m; -} - -template -inline T1 RoundUpToMultipleOf(const T1 &n, const T2 &m) -{ - if (n+m-1 < n) - throw InvalidArgument("RoundUpToMultipleOf: integer overflow"); - return RoundDownToMultipleOf(n+m-1, m); -} - -template -inline unsigned int GetAlignmentOf(T *dummy=NULL) // VC60 workaround -{ -#ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - if (sizeof(T) < 16) - return 1; -#endif - -#if (_MSC_VER >= 1300) - return __alignof(T); -#elif defined(__GNUC__) - return __alignof__(T); -#elif CRYPTOPP_BOOL_SLOW_WORD64 - return UnsignedMin(4U, sizeof(T)); -#else - return sizeof(T); -#endif -} - -inline bool IsAlignedOn(const void *p, unsigned int alignment) -{ - return alignment==1 || (IsPowerOf2(alignment) ? ModPowerOf2((size_t)p, alignment) == 0 : (size_t)p % alignment == 0); -} - -template -inline bool IsAligned(const void *p, T *dummy=NULL) // VC60 workaround -{ - return IsAlignedOn(p, GetAlignmentOf()); -} - -#ifdef IS_LITTLE_ENDIAN - typedef LittleEndian NativeByteOrder; -#else - typedef BigEndian NativeByteOrder; -#endif - -inline ByteOrder GetNativeByteOrder() -{ - return NativeByteOrder::ToEnum(); -} - -inline bool NativeByteOrderIs(ByteOrder order) -{ - return order == GetNativeByteOrder(); -} - -template -std::string IntToString(T a, unsigned int base = 10) -{ - if (a == 0) - return "0"; - bool negate = false; - if (a < 0) - { - negate = true; - a = 0-a; // VC .NET does not like -a - } - std::string result; - while (a > 0) - { - T digit = a % base; - result = char((digit < 10 ? '0' : ('a' - 10)) + digit) + result; - a /= base; - } - if (negate) - result = "-" + result; - return result; -} - -template -inline T1 SaturatingSubtract(const T1 &a, const T2 &b) -{ - return T1((a > b) ? (a - b) : 0); -} - -template -inline CipherDir GetCipherDir(const T &obj) -{ - return obj.IsForwardTransformation() ? ENCRYPTION : DECRYPTION; -} - -CRYPTOPP_DLL void CRYPTOPP_API CallNewHandler(); - -inline void IncrementCounterByOne(byte *inout, unsigned int s) -{ - for (int i=s-1, carry=1; i>=0 && carry; i--) - carry = !++inout[i]; -} - -inline void IncrementCounterByOne(byte *output, const byte *input, unsigned int s) -{ - int i, carry; - for (i=s-1, carry=1; i>=0 && carry; i--) - carry = ((output[i] = input[i]+1) == 0); - memcpy_s(output, s, input, i+1); -} - -template -inline void ConditionalSwap(bool c, T &a, T &b) -{ - T t = c * (a ^ b); - a ^= t; - b ^= t; -} - -template -inline void ConditionalSwapPointers(bool c, T &a, T &b) -{ - ptrdiff_t t = c * (a - b); - a -= t; - b += t; -} - -// see http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/protect-secrets.html -// and https://www.securecoding.cert.org/confluence/display/cplusplus/MSC06-CPP.+Be+aware+of+compiler+optimization+when+dealing+with+sensitive+data -template -void SecureWipeBuffer(T *buf, size_t n) -{ - // GCC 4.3.2 on Cygwin optimizes away the first store if this loop is done in the forward direction - volatile T *p = buf+n; - while (n--) - *(--p) = 0; -} - -#if (_MSC_VER >= 1400 || defined(__GNUC__)) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86) - -template<> inline void SecureWipeBuffer(byte *buf, size_t n) -{ - volatile byte *p = buf; -#ifdef __GNUC__ - asm volatile("rep stosb" : "+c"(n), "+D"(p) : "a"(0) : "memory"); -#else - __stosb((byte *)(size_t)p, 0, n); -#endif -} - -template<> inline void SecureWipeBuffer(word16 *buf, size_t n) -{ - volatile word16 *p = buf; -#ifdef __GNUC__ - asm volatile("rep stosw" : "+c"(n), "+D"(p) : "a"(0) : "memory"); -#else - __stosw((word16 *)(size_t)p, 0, n); -#endif -} - -template<> inline void SecureWipeBuffer(word32 *buf, size_t n) -{ - volatile word32 *p = buf; -#ifdef __GNUC__ - asm volatile("rep stosl" : "+c"(n), "+D"(p) : "a"(0) : "memory"); -#else - __stosd((unsigned long *)(size_t)p, 0, n); -#endif -} - -template<> inline void SecureWipeBuffer(word64 *buf, size_t n) -{ -#if CRYPTOPP_BOOL_X64 - volatile word64 *p = buf; -#ifdef __GNUC__ - asm volatile("rep stosq" : "+c"(n), "+D"(p) : "a"(0) : "memory"); -#else - __stosq((word64 *)(size_t)p, 0, n); -#endif -#else - SecureWipeBuffer((word32 *)buf, 2*n); -#endif -} - -#endif // #if (_MSC_VER >= 1400 || defined(__GNUC__)) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86) - -template -inline void SecureWipeArray(T *buf, size_t n) -{ - if (sizeof(T) % 8 == 0 && GetAlignmentOf() % GetAlignmentOf() == 0) - SecureWipeBuffer((word64 *)buf, n * (sizeof(T)/8)); - else if (sizeof(T) % 4 == 0 && GetAlignmentOf() % GetAlignmentOf() == 0) - SecureWipeBuffer((word32 *)buf, n * (sizeof(T)/4)); - else if (sizeof(T) % 2 == 0 && GetAlignmentOf() % GetAlignmentOf() == 0) - SecureWipeBuffer((word16 *)buf, n * (sizeof(T)/2)); - else - SecureWipeBuffer((byte *)buf, n * sizeof(T)); -} - -// this function uses wcstombs(), which assumes that setlocale() has been called -inline std::string StringNarrow(const wchar_t *str, bool throwOnError = true) -{ -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4996) // 'wcstombs': This function or variable may be unsafe. -#endif - size_t size = wcstombs(NULL, str, 0); - if (size == size_t(0)-1) - { - if (throwOnError) - throw InvalidArgument("StringNarrow: wcstombs() call failed"); - else - return std::string(); - } - std::string result(size, 0); - wcstombs(&result[0], str, size); - return result; -#ifdef _MSC_VER -#pragma warning(pop) -#endif -} - -#if CRYPTOPP_BOOL_ALIGN16_ENABLED -CRYPTOPP_DLL void * CRYPTOPP_API AlignedAllocate(size_t size); -CRYPTOPP_DLL void CRYPTOPP_API AlignedDeallocate(void *p); -#endif - -CRYPTOPP_DLL void * CRYPTOPP_API UnalignedAllocate(size_t size); -CRYPTOPP_DLL void CRYPTOPP_API UnalignedDeallocate(void *p); - -// ************** rotate functions *************** - -template inline T rotlFixed(T x, unsigned int y) -{ - assert(y < sizeof(T)*8); - return y ? T((x<>(sizeof(T)*8-y))) : x; -} - -template inline T rotrFixed(T x, unsigned int y) -{ - assert(y < sizeof(T)*8); - return y ? T((x>>y) | (x<<(sizeof(T)*8-y))) : x; -} - -template inline T rotlVariable(T x, unsigned int y) -{ - assert(y < sizeof(T)*8); - return T((x<>(sizeof(T)*8-y))); -} - -template inline T rotrVariable(T x, unsigned int y) -{ - assert(y < sizeof(T)*8); - return T((x>>y) | (x<<(sizeof(T)*8-y))); -} - -template inline T rotlMod(T x, unsigned int y) -{ - y %= sizeof(T)*8; - return T((x<>(sizeof(T)*8-y))); -} - -template inline T rotrMod(T x, unsigned int y) -{ - y %= sizeof(T)*8; - return T((x>>y) | (x<<(sizeof(T)*8-y))); -} - -#ifdef _MSC_VER - -template<> inline word32 rotlFixed(word32 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return y ? _lrotl(x, y) : x; -} - -template<> inline word32 rotrFixed(word32 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return y ? _lrotr(x, y) : x; -} - -template<> inline word32 rotlVariable(word32 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return _lrotl(x, y); -} - -template<> inline word32 rotrVariable(word32 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return _lrotr(x, y); -} - -template<> inline word32 rotlMod(word32 x, unsigned int y) -{ - return _lrotl(x, y); -} - -template<> inline word32 rotrMod(word32 x, unsigned int y) -{ - return _lrotr(x, y); -} - -#endif // #ifdef _MSC_VER - -#if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER) -// Intel C++ Compiler 10.0 calls a function instead of using the rotate instruction when using these instructions - -template<> inline word64 rotlFixed(word64 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return y ? _rotl64(x, y) : x; -} - -template<> inline word64 rotrFixed(word64 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return y ? _rotr64(x, y) : x; -} - -template<> inline word64 rotlVariable(word64 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return _rotl64(x, y); -} - -template<> inline word64 rotrVariable(word64 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return _rotr64(x, y); -} - -template<> inline word64 rotlMod(word64 x, unsigned int y) -{ - return _rotl64(x, y); -} - -template<> inline word64 rotrMod(word64 x, unsigned int y) -{ - return _rotr64(x, y); -} - -#endif // #if _MSC_VER >= 1310 - -#if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER) -// Intel C++ Compiler 10.0 gives undefined externals with these - -template<> inline word16 rotlFixed(word16 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return y ? _rotl16(x, y) : x; -} - -template<> inline word16 rotrFixed(word16 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return y ? _rotr16(x, y) : x; -} - -template<> inline word16 rotlVariable(word16 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return _rotl16(x, y); -} - -template<> inline word16 rotrVariable(word16 x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return _rotr16(x, y); -} - -template<> inline word16 rotlMod(word16 x, unsigned int y) -{ - return _rotl16(x, y); -} - -template<> inline word16 rotrMod(word16 x, unsigned int y) -{ - return _rotr16(x, y); -} - -template<> inline byte rotlFixed(byte x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return y ? _rotl8(x, y) : x; -} - -template<> inline byte rotrFixed(byte x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return y ? _rotr8(x, y) : x; -} - -template<> inline byte rotlVariable(byte x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return _rotl8(x, y); -} - -template<> inline byte rotrVariable(byte x, unsigned int y) -{ - assert(y < 8*sizeof(x)); - return _rotr8(x, y); -} - -template<> inline byte rotlMod(byte x, unsigned int y) -{ - return _rotl8(x, y); -} - -template<> inline byte rotrMod(byte x, unsigned int y) -{ - return _rotr8(x, y); -} - -#endif // #if _MSC_VER >= 1400 - -#if (defined(__MWERKS__) && TARGET_CPU_PPC) - -template<> inline word32 rotlFixed(word32 x, unsigned int y) -{ - assert(y < 32); - return y ? __rlwinm(x,y,0,31) : x; -} - -template<> inline word32 rotrFixed(word32 x, unsigned int y) -{ - assert(y < 32); - return y ? __rlwinm(x,32-y,0,31) : x; -} - -template<> inline word32 rotlVariable(word32 x, unsigned int y) -{ - assert(y < 32); - return (__rlwnm(x,y,0,31)); -} - -template<> inline word32 rotrVariable(word32 x, unsigned int y) -{ - assert(y < 32); - return (__rlwnm(x,32-y,0,31)); -} - -template<> inline word32 rotlMod(word32 x, unsigned int y) -{ - return (__rlwnm(x,y,0,31)); -} - -template<> inline word32 rotrMod(word32 x, unsigned int y) -{ - return (__rlwnm(x,32-y,0,31)); -} - -#endif // #if (defined(__MWERKS__) && TARGET_CPU_PPC) - -// ************** endian reversal *************** - -template -inline unsigned int GetByte(ByteOrder order, T value, unsigned int index) -{ - if (order == LITTLE_ENDIAN_ORDER) - return GETBYTE(value, index); - else - return GETBYTE(value, sizeof(T)-index-1); -} - -inline byte ByteReverse(byte value) -{ - return value; -} - -inline word16 ByteReverse(word16 value) -{ -#ifdef CRYPTOPP_BYTESWAP_AVAILABLE - return bswap_16(value); -#elif defined(_MSC_VER) && _MSC_VER >= 1300 - return _byteswap_ushort(value); -#else - return rotlFixed(value, 8U); -#endif -} - -inline word32 ByteReverse(word32 value) -{ -#if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) - __asm__ ("bswap %0" : "=r" (value) : "0" (value)); - return value; -#elif defined(CRYPTOPP_BYTESWAP_AVAILABLE) - return bswap_32(value); -#elif defined(__MWERKS__) && TARGET_CPU_PPC - return (word32)__lwbrx(&value,0); -#elif _MSC_VER >= 1400 || (_MSC_VER >= 1300 && !defined(_DLL)) - return _byteswap_ulong(value); -#elif CRYPTOPP_FAST_ROTATE(32) - // 5 instructions with rotate instruction, 9 without - return (rotrFixed(value, 8U) & 0xff00ff00) | (rotlFixed(value, 8U) & 0x00ff00ff); -#else - // 6 instructions with rotate instruction, 8 without - value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8); - return rotlFixed(value, 16U); -#endif -} - -inline word64 ByteReverse(word64 value) -{ -#if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__) - __asm__ ("bswap %0" : "=r" (value) : "0" (value)); - return value; -#elif defined(CRYPTOPP_BYTESWAP_AVAILABLE) - return bswap_64(value); -#elif defined(_MSC_VER) && _MSC_VER >= 1300 - return _byteswap_uint64(value); -#elif CRYPTOPP_BOOL_SLOW_WORD64 - return (word64(ByteReverse(word32(value))) << 32) | ByteReverse(word32(value>>32)); -#else - value = ((value & W64LIT(0xFF00FF00FF00FF00)) >> 8) | ((value & W64LIT(0x00FF00FF00FF00FF)) << 8); - value = ((value & W64LIT(0xFFFF0000FFFF0000)) >> 16) | ((value & W64LIT(0x0000FFFF0000FFFF)) << 16); - return rotlFixed(value, 32U); -#endif -} - -inline byte BitReverse(byte value) -{ - value = ((value & 0xAA) >> 1) | ((value & 0x55) << 1); - value = ((value & 0xCC) >> 2) | ((value & 0x33) << 2); - return rotlFixed(value, 4U); -} - -inline word16 BitReverse(word16 value) -{ - value = ((value & 0xAAAA) >> 1) | ((value & 0x5555) << 1); - value = ((value & 0xCCCC) >> 2) | ((value & 0x3333) << 2); - value = ((value & 0xF0F0) >> 4) | ((value & 0x0F0F) << 4); - return ByteReverse(value); -} - -inline word32 BitReverse(word32 value) -{ - value = ((value & 0xAAAAAAAA) >> 1) | ((value & 0x55555555) << 1); - value = ((value & 0xCCCCCCCC) >> 2) | ((value & 0x33333333) << 2); - value = ((value & 0xF0F0F0F0) >> 4) | ((value & 0x0F0F0F0F) << 4); - return ByteReverse(value); -} - -inline word64 BitReverse(word64 value) -{ -#if CRYPTOPP_BOOL_SLOW_WORD64 - return (word64(BitReverse(word32(value))) << 32) | BitReverse(word32(value>>32)); -#else - value = ((value & W64LIT(0xAAAAAAAAAAAAAAAA)) >> 1) | ((value & W64LIT(0x5555555555555555)) << 1); - value = ((value & W64LIT(0xCCCCCCCCCCCCCCCC)) >> 2) | ((value & W64LIT(0x3333333333333333)) << 2); - value = ((value & W64LIT(0xF0F0F0F0F0F0F0F0)) >> 4) | ((value & W64LIT(0x0F0F0F0F0F0F0F0F)) << 4); - return ByteReverse(value); -#endif -} - -template -inline T BitReverse(T value) -{ - if (sizeof(T) == 1) - return (T)BitReverse((byte)value); - else if (sizeof(T) == 2) - return (T)BitReverse((word16)value); - else if (sizeof(T) == 4) - return (T)BitReverse((word32)value); - else - { - assert(sizeof(T) == 8); - return (T)BitReverse((word64)value); - } -} - -template -inline T ConditionalByteReverse(ByteOrder order, T value) -{ - return NativeByteOrderIs(order) ? value : ByteReverse(value); -} - -template -void ByteReverse(T *out, const T *in, size_t byteCount) -{ - assert(byteCount % sizeof(T) == 0); - size_t count = byteCount/sizeof(T); - for (size_t i=0; i -inline void ConditionalByteReverse(ByteOrder order, T *out, const T *in, size_t byteCount) -{ - if (!NativeByteOrderIs(order)) - ByteReverse(out, in, byteCount); - else if (in != out) - memcpy_s(out, byteCount, in, byteCount); -} - -template -inline void GetUserKey(ByteOrder order, T *out, size_t outlen, const byte *in, size_t inlen) -{ - const size_t U = sizeof(T); - assert(inlen <= outlen*U); - memcpy_s(out, outlen*U, in, inlen); - memset_z((byte *)out+inlen, 0, outlen*U-inlen); - ConditionalByteReverse(order, out, out, RoundUpToMultipleOf(inlen, U)); -} - -#ifndef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS -inline byte UnalignedGetWordNonTemplate(ByteOrder order, const byte *block, const byte *) -{ - return block[0]; -} - -inline word16 UnalignedGetWordNonTemplate(ByteOrder order, const byte *block, const word16 *) -{ - return (order == BIG_ENDIAN_ORDER) - ? block[1] | (block[0] << 8) - : block[0] | (block[1] << 8); -} - -inline word32 UnalignedGetWordNonTemplate(ByteOrder order, const byte *block, const word32 *) -{ - return (order == BIG_ENDIAN_ORDER) - ? word32(block[3]) | (word32(block[2]) << 8) | (word32(block[1]) << 16) | (word32(block[0]) << 24) - : word32(block[0]) | (word32(block[1]) << 8) | (word32(block[2]) << 16) | (word32(block[3]) << 24); -} - -inline word64 UnalignedGetWordNonTemplate(ByteOrder order, const byte *block, const word64 *) -{ - return (order == BIG_ENDIAN_ORDER) - ? - (word64(block[7]) | - (word64(block[6]) << 8) | - (word64(block[5]) << 16) | - (word64(block[4]) << 24) | - (word64(block[3]) << 32) | - (word64(block[2]) << 40) | - (word64(block[1]) << 48) | - (word64(block[0]) << 56)) - : - (word64(block[0]) | - (word64(block[1]) << 8) | - (word64(block[2]) << 16) | - (word64(block[3]) << 24) | - (word64(block[4]) << 32) | - (word64(block[5]) << 40) | - (word64(block[6]) << 48) | - (word64(block[7]) << 56)); -} - -inline void UnalignedPutWordNonTemplate(ByteOrder order, byte *block, byte value, const byte *xorBlock) -{ - block[0] = xorBlock ? (value ^ xorBlock[0]) : value; -} - -inline void UnalignedPutWordNonTemplate(ByteOrder order, byte *block, word16 value, const byte *xorBlock) -{ - if (order == BIG_ENDIAN_ORDER) - { - if (xorBlock) - { - block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - } - else - { - block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - } - } - else - { - if (xorBlock) - { - block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - } - else - { - block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - } - } -} - -inline void UnalignedPutWordNonTemplate(ByteOrder order, byte *block, word32 value, const byte *xorBlock) -{ - if (order == BIG_ENDIAN_ORDER) - { - if (xorBlock) - { - block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3); - block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2); - block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - } - else - { - block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3); - block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2); - block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - } - } - else - { - if (xorBlock) - { - block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2); - block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3); - } - else - { - block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2); - block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3); - } - } -} - -inline void UnalignedPutWordNonTemplate(ByteOrder order, byte *block, word64 value, const byte *xorBlock) -{ - if (order == BIG_ENDIAN_ORDER) - { - if (xorBlock) - { - block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7); - block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6); - block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5); - block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4); - block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3); - block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2); - block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - } - else - { - block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7); - block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6); - block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5); - block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4); - block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3); - block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2); - block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - } - } - else - { - if (xorBlock) - { - block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2); - block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3); - block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4); - block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5); - block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6); - block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7); - } - else - { - block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0); - block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1); - block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2); - block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3); - block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4); - block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5); - block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6); - block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7); - } - } -} -#endif // #ifndef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - -template -inline T GetWord(bool assumeAligned, ByteOrder order, const byte *block) -{ -#ifndef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - if (!assumeAligned) - return UnalignedGetWordNonTemplate(order, block, (T*)NULL); - assert(IsAligned(block)); -#endif - return ConditionalByteReverse(order, *reinterpret_cast(block)); -} - -template -inline void GetWord(bool assumeAligned, ByteOrder order, T &result, const byte *block) -{ - result = GetWord(assumeAligned, order, block); -} - -template -inline void PutWord(bool assumeAligned, ByteOrder order, byte *block, T value, const byte *xorBlock = NULL) -{ -#ifndef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - if (!assumeAligned) - return UnalignedPutWordNonTemplate(order, block, value, xorBlock); - assert(IsAligned(block)); - assert(IsAligned(xorBlock)); -#endif - *reinterpret_cast(block) = ConditionalByteReverse(order, value) ^ (xorBlock ? *reinterpret_cast(xorBlock) : 0); -} - -template -class GetBlock -{ -public: - GetBlock(const void *block) - : m_block((const byte *)block) {} - - template - inline GetBlock & operator()(U &x) - { - CRYPTOPP_COMPILE_ASSERT(sizeof(U) >= sizeof(T)); - x = GetWord(A, B::ToEnum(), m_block); - m_block += sizeof(T); - return *this; - } - -private: - const byte *m_block; -}; - -template -class PutBlock -{ -public: - PutBlock(const void *xorBlock, void *block) - : m_xorBlock((const byte *)xorBlock), m_block((byte *)block) {} - - template - inline PutBlock & operator()(U x) - { - PutWord(A, B::ToEnum(), m_block, (T)x, m_xorBlock); - m_block += sizeof(T); - if (m_xorBlock) - m_xorBlock += sizeof(T); - return *this; - } - -private: - const byte *m_xorBlock; - byte *m_block; -}; - -template -struct BlockGetAndPut -{ - // function needed because of C++ grammatical ambiguity between expression-statements and declarations - static inline GetBlock Get(const void *block) {return GetBlock(block);} - typedef PutBlock Put; -}; - -template -std::string WordToString(T value, ByteOrder order = BIG_ENDIAN_ORDER) -{ - if (!NativeByteOrderIs(order)) - value = ByteReverse(value); - - return std::string((char *)&value, sizeof(value)); -} - -template -T StringToWord(const std::string &str, ByteOrder order = BIG_ENDIAN_ORDER) -{ - T value = 0; - memcpy_s(&value, sizeof(value), str.data(), UnsignedMin(str.size(), sizeof(value))); - return NativeByteOrderIs(order) ? value : ByteReverse(value); -} - -// ************** help remove warning on g++ *************** - -template struct SafeShifter; - -template<> struct SafeShifter -{ - template - static inline T RightShift(T value, unsigned int bits) - { - return 0; - } - - template - static inline T LeftShift(T value, unsigned int bits) - { - return 0; - } -}; - -template<> struct SafeShifter -{ - template - static inline T RightShift(T value, unsigned int bits) - { - return value >> bits; - } - - template - static inline T LeftShift(T value, unsigned int bits) - { - return value << bits; - } -}; - -template -inline T SafeRightShift(T value) -{ - return SafeShifter<(bits>=(8*sizeof(T)))>::RightShift(value, bits); -} - -template -inline T SafeLeftShift(T value) -{ - return SafeShifter<(bits>=(8*sizeof(T)))>::LeftShift(value, bits); -} - -// ************** use one buffer for multiple data members *************** - -#define CRYPTOPP_BLOCK_1(n, t, s) t* m_##n() {return (t *)(m_aggregate+0);} size_t SS1() {return sizeof(t)*(s);} size_t m_##n##Size() {return (s);} -#define CRYPTOPP_BLOCK_2(n, t, s) t* m_##n() {return (t *)(m_aggregate+SS1());} size_t SS2() {return SS1()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);} -#define CRYPTOPP_BLOCK_3(n, t, s) t* m_##n() {return (t *)(m_aggregate+SS2());} size_t SS3() {return SS2()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);} -#define CRYPTOPP_BLOCK_4(n, t, s) t* m_##n() {return (t *)(m_aggregate+SS3());} size_t SS4() {return SS3()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);} -#define CRYPTOPP_BLOCK_5(n, t, s) t* m_##n() {return (t *)(m_aggregate+SS4());} size_t SS5() {return SS4()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);} -#define CRYPTOPP_BLOCK_6(n, t, s) t* m_##n() {return (t *)(m_aggregate+SS5());} size_t SS6() {return SS5()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);} -#define CRYPTOPP_BLOCK_7(n, t, s) t* m_##n() {return (t *)(m_aggregate+SS6());} size_t SS7() {return SS6()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);} -#define CRYPTOPP_BLOCK_8(n, t, s) t* m_##n() {return (t *)(m_aggregate+SS7());} size_t SS8() {return SS7()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);} -#define CRYPTOPP_BLOCKS_END(i) size_t SST() {return SS##i();} void AllocateBlocks() {m_aggregate.New(SST());} AlignedSecByteBlock m_aggregate; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/modarith.h b/lib/cryptopp/modarith.h deleted file mode 100644 index c0368e3fb..000000000 --- a/lib/cryptopp/modarith.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef CRYPTOPP_MODARITH_H -#define CRYPTOPP_MODARITH_H - -// implementations are in integer.cpp - -#include "cryptlib.h" -#include "misc.h" -#include "integer.h" -#include "algebra.h" - -NAMESPACE_BEGIN(CryptoPP) - -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractGroup; -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractRing; -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractEuclideanDomain; - -//! ring of congruence classes modulo n -/*! \note this implementation represents each congruence class as the smallest non-negative integer in that class */ -class CRYPTOPP_DLL ModularArithmetic : public AbstractRing -{ -public: - - typedef int RandomizationParameter; - typedef Integer Element; - - ModularArithmetic(const Integer &modulus = Integer::One()) - : m_modulus(modulus), m_result((word)0, modulus.reg.size()) {} - - ModularArithmetic(const ModularArithmetic &ma) - : m_modulus(ma.m_modulus), m_result((word)0, m_modulus.reg.size()) {} - - ModularArithmetic(BufferedTransformation &bt); // construct from BER encoded parameters - - virtual ModularArithmetic * Clone() const {return new ModularArithmetic(*this);} - - void DEREncode(BufferedTransformation &bt) const; - - void DEREncodeElement(BufferedTransformation &out, const Element &a) const; - void BERDecodeElement(BufferedTransformation &in, Element &a) const; - - const Integer& GetModulus() const {return m_modulus;} - void SetModulus(const Integer &newModulus) {m_modulus = newModulus; m_result.reg.resize(m_modulus.reg.size());} - - virtual bool IsMontgomeryRepresentation() const {return false;} - - virtual Integer ConvertIn(const Integer &a) const - {return a%m_modulus;} - - virtual Integer ConvertOut(const Integer &a) const - {return a;} - - const Integer& Half(const Integer &a) const; - - bool Equal(const Integer &a, const Integer &b) const - {return a==b;} - - const Integer& Identity() const - {return Integer::Zero();} - - const Integer& Add(const Integer &a, const Integer &b) const; - - Integer& Accumulate(Integer &a, const Integer &b) const; - - const Integer& Inverse(const Integer &a) const; - - const Integer& Subtract(const Integer &a, const Integer &b) const; - - Integer& Reduce(Integer &a, const Integer &b) const; - - const Integer& Double(const Integer &a) const - {return Add(a, a);} - - const Integer& MultiplicativeIdentity() const - {return Integer::One();} - - const Integer& Multiply(const Integer &a, const Integer &b) const - {return m_result1 = a*b%m_modulus;} - - const Integer& Square(const Integer &a) const - {return m_result1 = a.Squared()%m_modulus;} - - bool IsUnit(const Integer &a) const - {return Integer::Gcd(a, m_modulus).IsUnit();} - - const Integer& MultiplicativeInverse(const Integer &a) const - {return m_result1 = a.InverseMod(m_modulus);} - - const Integer& Divide(const Integer &a, const Integer &b) const - {return Multiply(a, MultiplicativeInverse(b));} - - Integer CascadeExponentiate(const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const; - - void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const; - - unsigned int MaxElementBitLength() const - {return (m_modulus-1).BitCount();} - - unsigned int MaxElementByteLength() const - {return (m_modulus-1).ByteCount();} - - Element RandomElement( RandomNumberGenerator &rng , const RandomizationParameter &ignore_for_now = 0 ) const - // left RandomizationParameter arg as ref in case RandomizationParameter becomes a more complicated struct - { - return Element( rng , Integer( (long) 0) , m_modulus - Integer( (long) 1 ) ) ; - } - - bool operator==(const ModularArithmetic &rhs) const - {return m_modulus == rhs.m_modulus;} - - static const RandomizationParameter DefaultRandomizationParameter ; - -protected: - Integer m_modulus; - mutable Integer m_result, m_result1; - -}; - -// const ModularArithmetic::RandomizationParameter ModularArithmetic::DefaultRandomizationParameter = 0 ; - -//! do modular arithmetics in Montgomery representation for increased speed -/*! \note the Montgomery representation represents each congruence class [a] as a*r%n, where r is a convenient power of 2 */ -class CRYPTOPP_DLL MontgomeryRepresentation : public ModularArithmetic -{ -public: - MontgomeryRepresentation(const Integer &modulus); // modulus must be odd - - virtual ModularArithmetic * Clone() const {return new MontgomeryRepresentation(*this);} - - bool IsMontgomeryRepresentation() const {return true;} - - Integer ConvertIn(const Integer &a) const - {return (a<<(WORD_BITS*m_modulus.reg.size()))%m_modulus;} - - Integer ConvertOut(const Integer &a) const; - - const Integer& MultiplicativeIdentity() const - {return m_result1 = Integer::Power2(WORD_BITS*m_modulus.reg.size())%m_modulus;} - - const Integer& Multiply(const Integer &a, const Integer &b) const; - - const Integer& Square(const Integer &a) const; - - const Integer& MultiplicativeInverse(const Integer &a) const; - - Integer CascadeExponentiate(const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const - {return AbstractRing::CascadeExponentiate(x, e1, y, e2);} - - void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const - {AbstractRing::SimultaneousExponentiate(results, base, exponents, exponentsCount);} - -private: - Integer m_u; - mutable IntegerSecBlock m_workspace; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/modes.cpp b/lib/cryptopp/modes.cpp deleted file mode 100644 index 46332284b..000000000 --- a/lib/cryptopp/modes.cpp +++ /dev/null @@ -1,245 +0,0 @@ -// modes.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "modes.h" - -#ifndef NDEBUG -#include "des.h" -#endif - -NAMESPACE_BEGIN(CryptoPP) - -#ifndef NDEBUG -void Modes_TestInstantiations() -{ - CFB_Mode::Encryption m0; - CFB_Mode::Decryption m1; - OFB_Mode::Encryption m2; - CTR_Mode::Encryption m3; - ECB_Mode::Encryption m4; - CBC_Mode::Encryption m5; -} -#endif - -void CFB_ModePolicy::Iterate(byte *output, const byte *input, CipherDir dir, size_t iterationCount) -{ - assert(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt - assert(m_feedbackSize == BlockSize()); - - unsigned int s = BlockSize(); - if (dir == ENCRYPTION) - { - m_cipher->ProcessAndXorBlock(m_register, input, output); - m_cipher->AdvancedProcessBlocks(output, input+s, output+s, (iterationCount-1)*s, 0); - memcpy(m_register, output+(iterationCount-1)*s, s); - } - else - { - memcpy(m_temp, input+(iterationCount-1)*s, s); // make copy first in case of in-place decryption - m_cipher->AdvancedProcessBlocks(input, input+s, output+s, (iterationCount-1)*s, BlockTransformation::BT_ReverseDirection); - m_cipher->ProcessAndXorBlock(m_register, input, output); - memcpy(m_register, m_temp, s); - } -} - -void CFB_ModePolicy::TransformRegister() -{ - assert(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt - m_cipher->ProcessBlock(m_register, m_temp); - unsigned int updateSize = BlockSize()-m_feedbackSize; - memmove_s(m_register, m_register.size(), m_register+m_feedbackSize, updateSize); - memcpy_s(m_register+updateSize, m_register.size()-updateSize, m_temp, m_feedbackSize); -} - -void CFB_ModePolicy::CipherResynchronize(const byte *iv, size_t length) -{ - assert(length == BlockSize()); - CopyOrZero(m_register, iv, length); - TransformRegister(); -} - -void CFB_ModePolicy::SetFeedbackSize(unsigned int feedbackSize) -{ - if (feedbackSize > BlockSize()) - throw InvalidArgument("CFB_Mode: invalid feedback size"); - m_feedbackSize = feedbackSize ? feedbackSize : BlockSize(); -} - -void CFB_ModePolicy::ResizeBuffers() -{ - CipherModeBase::ResizeBuffers(); - m_temp.New(BlockSize()); -} - -void OFB_ModePolicy::WriteKeystream(byte *keystreamBuffer, size_t iterationCount) -{ - assert(m_cipher->IsForwardTransformation()); // OFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt - unsigned int s = BlockSize(); - m_cipher->ProcessBlock(m_register, keystreamBuffer); - if (iterationCount > 1) - m_cipher->AdvancedProcessBlocks(keystreamBuffer, NULL, keystreamBuffer+s, s*(iterationCount-1), 0); - memcpy(m_register, keystreamBuffer+s*(iterationCount-1), s); -} - -void OFB_ModePolicy::CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length) -{ - assert(length == BlockSize()); - CopyOrZero(m_register, iv, length); -} - -void CTR_ModePolicy::SeekToIteration(lword iterationCount) -{ - int carry=0; - for (int i=BlockSize()-1; i>=0; i--) - { - unsigned int sum = m_register[i] + byte(iterationCount) + carry; - m_counterArray[i] = (byte) sum; - carry = sum >> 8; - iterationCount >>= 8; - } -} - -void CTR_ModePolicy::IncrementCounterBy256() -{ - IncrementCounterByOne(m_counterArray, BlockSize()-1); -} - -void CTR_ModePolicy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount) -{ - assert(m_cipher->IsForwardTransformation()); // CTR mode needs the "encrypt" direction of the underlying block cipher, even to decrypt - unsigned int s = BlockSize(); - unsigned int inputIncrement = input ? s : 0; - - while (iterationCount) - { - byte lsb = m_counterArray[s-1]; - size_t blocks = UnsignedMin(iterationCount, 256U-lsb); - m_cipher->AdvancedProcessBlocks(m_counterArray, input, output, blocks*s, BlockTransformation::BT_InBlockIsCounter|BlockTransformation::BT_AllowParallel); - if ((m_counterArray[s-1] = lsb + (byte)blocks) == 0) - IncrementCounterBy256(); - - output += blocks*s; - input += blocks*inputIncrement; - iterationCount -= blocks; - } -} - -void CTR_ModePolicy::CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length) -{ - assert(length == BlockSize()); - CopyOrZero(m_register, iv, length); - m_counterArray = m_register; -} - -void BlockOrientedCipherModeBase::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) -{ - m_cipher->SetKey(key, length, params); - ResizeBuffers(); - if (IsResynchronizable()) - { - size_t ivLength; - const byte *iv = GetIVAndThrowIfInvalid(params, ivLength); - Resynchronize(iv, (int)ivLength); - } -} - -void ECB_OneWay::ProcessData(byte *outString, const byte *inString, size_t length) -{ - assert(length%BlockSize()==0); - m_cipher->AdvancedProcessBlocks(inString, NULL, outString, length, BlockTransformation::BT_AllowParallel); -} - -void CBC_Encryption::ProcessData(byte *outString, const byte *inString, size_t length) -{ - if (!length) - return; - assert(length%BlockSize()==0); - - unsigned int blockSize = BlockSize(); - m_cipher->AdvancedProcessBlocks(inString, m_register, outString, blockSize, BlockTransformation::BT_XorInput); - if (length > blockSize) - m_cipher->AdvancedProcessBlocks(inString+blockSize, outString, outString+blockSize, length-blockSize, BlockTransformation::BT_XorInput); - memcpy(m_register, outString + length - blockSize, blockSize); -} - -void CBC_CTS_Encryption::ProcessLastBlock(byte *outString, const byte *inString, size_t length) -{ - if (length <= BlockSize()) - { - if (!m_stolenIV) - throw InvalidArgument("CBC_Encryption: message is too short for ciphertext stealing"); - - // steal from IV - memcpy(outString, m_register, length); - outString = m_stolenIV; - } - else - { - // steal from next to last block - xorbuf(m_register, inString, BlockSize()); - m_cipher->ProcessBlock(m_register); - inString += BlockSize(); - length -= BlockSize(); - memcpy(outString+BlockSize(), m_register, length); - } - - // output last full ciphertext block - xorbuf(m_register, inString, length); - m_cipher->ProcessBlock(m_register); - memcpy(outString, m_register, BlockSize()); -} - -void CBC_Decryption::ProcessData(byte *outString, const byte *inString, size_t length) -{ - if (!length) - return; - assert(length%BlockSize()==0); - - unsigned int blockSize = BlockSize(); - memcpy(m_temp, inString+length-blockSize, blockSize); // save copy now in case of in-place decryption - if (length > blockSize) - m_cipher->AdvancedProcessBlocks(inString+blockSize, inString, outString+blockSize, length-blockSize, BlockTransformation::BT_ReverseDirection|BlockTransformation::BT_AllowParallel); - m_cipher->ProcessAndXorBlock(inString, m_register, outString); - m_register.swap(m_temp); -} - -void CBC_CTS_Decryption::ProcessLastBlock(byte *outString, const byte *inString, size_t length) -{ - const byte *pn, *pn1; - bool stealIV = length <= BlockSize(); - - if (stealIV) - { - pn = inString; - pn1 = m_register; - } - else - { - pn = inString + BlockSize(); - pn1 = inString; - length -= BlockSize(); - } - - // decrypt last partial plaintext block - memcpy(m_temp, pn1, BlockSize()); - m_cipher->ProcessBlock(m_temp); - xorbuf(m_temp, pn, length); - - if (stealIV) - memcpy(outString, m_temp, length); - else - { - memcpy(outString+BlockSize(), m_temp, length); - // decrypt next to last plaintext block - memcpy(m_temp, pn, length); - m_cipher->ProcessBlock(m_temp); - xorbuf(outString, m_temp, m_register, BlockSize()); - } -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/modes.h b/lib/cryptopp/modes.h deleted file mode 100644 index c0c30c476..000000000 --- a/lib/cryptopp/modes.h +++ /dev/null @@ -1,422 +0,0 @@ -#ifndef CRYPTOPP_MODES_H -#define CRYPTOPP_MODES_H - -/*! \file -*/ - -#include "cryptlib.h" -#include "secblock.h" -#include "misc.h" -#include "strciphr.h" -#include "argnames.h" -#include "algparam.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! Cipher modes documentation. See NIST SP 800-38A for definitions of these modes. See AuthenticatedSymmetricCipherDocumentation for authenticated encryption modes. - -/*! Each class derived from this one defines two types, Encryption and Decryption, - both of which implement the SymmetricCipher interface. - For each mode there are two classes, one of which is a template class, - and the other one has a name that ends in "_ExternalCipher". - The "external cipher" mode objects hold a reference to the underlying block cipher, - instead of holding an instance of it. The reference must be passed in to the constructor. - For the "cipher holder" classes, the CIPHER template parameter should be a class - derived from BlockCipherDocumentation, for example DES or AES. -*/ -struct CipherModeDocumentation : public SymmetricCipherDocumentation -{ -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher -{ -public: - size_t MinKeyLength() const {return m_cipher->MinKeyLength();} - size_t MaxKeyLength() const {return m_cipher->MaxKeyLength();} - size_t DefaultKeyLength() const {return m_cipher->DefaultKeyLength();} - size_t GetValidKeyLength(size_t n) const {return m_cipher->GetValidKeyLength(n);} - bool IsValidKeyLength(size_t n) const {return m_cipher->IsValidKeyLength(n);} - - unsigned int OptimalDataAlignment() const {return m_cipher->OptimalDataAlignment();} - - unsigned int IVSize() const {return BlockSize();} - virtual IV_Requirement IVRequirement() const =0; - - void SetCipher(BlockCipher &cipher) - { - this->ThrowIfResynchronizable(); - this->m_cipher = &cipher; - this->ResizeBuffers(); - } - - void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize = 0) - { - this->ThrowIfInvalidIV(iv); - this->m_cipher = &cipher; - this->ResizeBuffers(); - this->SetFeedbackSize(feedbackSize); - if (this->IsResynchronizable()) - this->Resynchronize(iv); - } - -protected: - CipherModeBase() : m_cipher(NULL) {} - inline unsigned int BlockSize() const {assert(m_register.size() > 0); return (unsigned int)m_register.size();} - virtual void SetFeedbackSize(unsigned int feedbackSize) - { - if (!(feedbackSize == 0 || feedbackSize == BlockSize())) - throw InvalidArgument("CipherModeBase: feedback size cannot be specified for this cipher mode"); - } - virtual void ResizeBuffers() - { - m_register.New(m_cipher->BlockSize()); - } - - BlockCipher *m_cipher; - AlignedSecByteBlock m_register; -}; - -template -class CRYPTOPP_NO_VTABLE ModePolicyCommonTemplate : public CipherModeBase, public POLICY_INTERFACE -{ - unsigned int GetAlignment() const {return m_cipher->OptimalDataAlignment();} - void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); -}; - -template -void ModePolicyCommonTemplate::CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length) -{ - m_cipher->SetKey(key, length, params); - ResizeBuffers(); - int feedbackSize = params.GetIntValueWithDefault(Name::FeedbackSize(), 0); - SetFeedbackSize(feedbackSize); -} - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_ModePolicy : public ModePolicyCommonTemplate -{ -public: - IV_Requirement IVRequirement() const {return RANDOM_IV;} - static const char * CRYPTOPP_API StaticAlgorithmName() {return "CFB";} - -protected: - unsigned int GetBytesPerIteration() const {return m_feedbackSize;} - byte * GetRegisterBegin() {return m_register + BlockSize() - m_feedbackSize;} - bool CanIterate() const {return m_feedbackSize == BlockSize();} - void Iterate(byte *output, const byte *input, CipherDir dir, size_t iterationCount); - void TransformRegister(); - void CipherResynchronize(const byte *iv, size_t length); - void SetFeedbackSize(unsigned int feedbackSize); - void ResizeBuffers(); - - SecByteBlock m_temp; - unsigned int m_feedbackSize; -}; - -inline void CopyOrZero(void *dest, const void *src, size_t s) -{ - if (src) - memcpy_s(dest, s, src, s); - else - memset(dest, 0, s); -} - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTemplate -{ -public: - bool CipherIsRandomAccess() const {return false;} - IV_Requirement IVRequirement() const {return UNIQUE_IV;} - static const char * CRYPTOPP_API StaticAlgorithmName() {return "OFB";} - -private: - unsigned int GetBytesPerIteration() const {return BlockSize();} - unsigned int GetIterationsToBuffer() const {return m_cipher->OptimalNumberOfParallelBlocks();} - void WriteKeystream(byte *keystreamBuffer, size_t iterationCount); - void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length); -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTemplate -{ -public: - bool CipherIsRandomAccess() const {return true;} - IV_Requirement IVRequirement() const {return RANDOM_IV;} - static const char * CRYPTOPP_API StaticAlgorithmName() {return "CTR";} - -protected: - virtual void IncrementCounterBy256(); - - unsigned int GetAlignment() const {return m_cipher->OptimalDataAlignment();} - unsigned int GetBytesPerIteration() const {return BlockSize();} - unsigned int GetIterationsToBuffer() const {return m_cipher->OptimalNumberOfParallelBlocks();} - void WriteKeystream(byte *buffer, size_t iterationCount) - {OperateKeystream(WRITE_KEYSTREAM, buffer, NULL, iterationCount);} - bool CanOperateKeystream() const {return true;} - void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); - void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length); - void SeekToIteration(lword iterationCount); - - AlignedSecByteBlock m_counterArray; -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase -{ -public: - void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); - unsigned int MandatoryBlockSize() const {return BlockSize();} - bool IsRandomAccess() const {return false;} - bool IsSelfInverting() const {return false;} - bool IsForwardTransformation() const {return m_cipher->IsForwardTransformation();} - void Resynchronize(const byte *iv, int length=-1) {memcpy_s(m_register, m_register.size(), iv, ThrowIfInvalidIVLength(length));} - -protected: - bool RequireAlignedInput() const {return true;} - void ResizeBuffers() - { - CipherModeBase::ResizeBuffers(); - m_buffer.New(BlockSize()); - } - - SecByteBlock m_buffer; -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherModeBase -{ -public: - void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms = g_nullNameValuePairs) - {m_cipher->SetKey(key, length, params); BlockOrientedCipherModeBase::ResizeBuffers();} - IV_Requirement IVRequirement() const {return NOT_RESYNCHRONIZABLE;} - unsigned int OptimalBlockSize() const {return BlockSize() * m_cipher->OptimalNumberOfParallelBlocks();} - void ProcessData(byte *outString, const byte *inString, size_t length); - static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECB";} -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_ModeBase : public BlockOrientedCipherModeBase -{ -public: - IV_Requirement IVRequirement() const {return UNPREDICTABLE_RANDOM_IV;} - bool RequireAlignedInput() const {return false;} - unsigned int MinLastBlockSize() const {return 0;} - static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC";} -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Encryption : public CBC_ModeBase -{ -public: - void ProcessData(byte *outString, const byte *inString, size_t length); -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption -{ -public: - void SetStolenIV(byte *iv) {m_stolenIV = iv;} - unsigned int MinLastBlockSize() const {return BlockSize()+1;} - void ProcessLastBlock(byte *outString, const byte *inString, size_t length); - static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";} - -protected: - void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) - { - CBC_Encryption::UncheckedSetKey(key, length, params); - m_stolenIV = params.GetValueWithDefault(Name::StolenIV(), (byte *)NULL); - } - - byte *m_stolenIV; -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Decryption : public CBC_ModeBase -{ -public: - void ProcessData(byte *outString, const byte *inString, size_t length); - -protected: - void ResizeBuffers() - { - BlockOrientedCipherModeBase::ResizeBuffers(); - m_temp.New(BlockSize()); - } - AlignedSecByteBlock m_temp; -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Decryption : public CBC_Decryption -{ -public: - unsigned int MinLastBlockSize() const {return BlockSize()+1;} - void ProcessLastBlock(byte *outString, const byte *inString, size_t length); -}; - -//! _ -template -class CipherModeFinalTemplate_CipherHolder : protected ObjectHolder, public AlgorithmImpl > -{ -public: - CipherModeFinalTemplate_CipherHolder() - { - this->m_cipher = &this->m_object; - this->ResizeBuffers(); - } - CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length) - { - this->m_cipher = &this->m_object; - this->SetKey(key, length); - } - CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length, const byte *iv) - { - this->m_cipher = &this->m_object; - this->SetKey(key, length, MakeParameters(Name::IV(), ConstByteArrayParameter(iv, this->m_cipher->BlockSize()))); - } - CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length, const byte *iv, int feedbackSize) - { - this->m_cipher = &this->m_object; - this->SetKey(key, length, MakeParameters(Name::IV(), ConstByteArrayParameter(iv, this->m_cipher->BlockSize()))(Name::FeedbackSize(), feedbackSize)); - } - - static std::string CRYPTOPP_API StaticAlgorithmName() - {return CIPHER::StaticAlgorithmName() + "/" + BASE::StaticAlgorithmName();} -}; - -//! _ -template -class CipherModeFinalTemplate_ExternalCipher : public BASE -{ -public: - CipherModeFinalTemplate_ExternalCipher() {} - CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher) - {this->SetCipher(cipher);} - CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv, int feedbackSize = 0) - {this->SetCipherWithIV(cipher, iv, feedbackSize);} - - std::string AlgorithmName() const - {return (this->m_cipher ? this->m_cipher->AlgorithmName() + "/" : std::string("")) + BASE::StaticAlgorithmName();} -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS CFB_CipherTemplate >; -CRYPTOPP_DLL_TEMPLATE_CLASS CFB_EncryptionTemplate >; -CRYPTOPP_DLL_TEMPLATE_CLASS CFB_DecryptionTemplate >; - -//! CFB mode -template -struct CFB_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder > > > Encryption; - typedef CipherModeFinalTemplate_CipherHolder > > > Decryption; -}; - -//! CFB mode, external cipher -struct CFB_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher > > > Encryption; - typedef CipherModeFinalTemplate_ExternalCipher > > > Decryption; -}; - -//! CFB mode FIPS variant, requiring full block plaintext according to FIPS 800-38A -template -struct CFB_FIPS_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder > > > > Encryption; - typedef CipherModeFinalTemplate_CipherHolder > > > > Decryption; -}; - -//! CFB mode FIPS variant, requiring full block plaintext according to FIPS 800-38A, external cipher -struct CFB_FIPS_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher > > > > Encryption; - typedef CipherModeFinalTemplate_ExternalCipher > > > > Decryption; -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate >; - -//! OFB mode -template -struct OFB_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder > > > Encryption; - typedef Encryption Decryption; -}; - -//! OFB mode, external cipher -struct OFB_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher > > > Encryption; - typedef Encryption Decryption; -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate >; -CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher > > >; - -//! CTR mode -template -struct CTR_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder > > > Encryption; - typedef Encryption Decryption; -}; - -//! CTR mode, external cipher -struct CTR_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher > > > Encryption; - typedef Encryption Decryption; -}; - -//! ECB mode -template -struct ECB_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder Encryption; - typedef CipherModeFinalTemplate_CipherHolder Decryption; -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher; - -//! ECB mode, external cipher -struct ECB_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher Encryption; - typedef Encryption Decryption; -}; - -//! CBC mode -template -struct CBC_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder Encryption; - typedef CipherModeFinalTemplate_CipherHolder Decryption; -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher; -CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher; - -//! CBC mode, external cipher -struct CBC_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher Encryption; - typedef CipherModeFinalTemplate_ExternalCipher Decryption; -}; - -//! CBC mode with ciphertext stealing -template -struct CBC_CTS_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder Encryption; - typedef CipherModeFinalTemplate_CipherHolder Decryption; -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher; -CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher; - -//! CBC mode with ciphertext stealing, external cipher -struct CBC_CTS_Mode_ExternalCipher : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_ExternalCipher Encryption; - typedef CipherModeFinalTemplate_ExternalCipher Decryption; -}; - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY -typedef CFB_Mode_ExternalCipher::Encryption CFBEncryption; -typedef CFB_Mode_ExternalCipher::Decryption CFBDecryption; -typedef OFB_Mode_ExternalCipher::Encryption OFB; -typedef CTR_Mode_ExternalCipher::Encryption CounterMode; -#endif - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/modexppc.h b/lib/cryptopp/modexppc.h deleted file mode 100644 index fbe701279..000000000 --- a/lib/cryptopp/modexppc.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CRYPTOPP_MODEXPPC_H -#define CRYPTOPP_MODEXPPC_H - -#include "modarith.h" -#include "eprecomp.h" -#include "smartptr.h" -#include "pubkey.h" - -NAMESPACE_BEGIN(CryptoPP) - -CRYPTOPP_DLL_TEMPLATE_CLASS DL_FixedBasePrecomputationImpl; - -class ModExpPrecomputation : public DL_GroupPrecomputation -{ -public: - // DL_GroupPrecomputation - bool NeedConversions() const {return true;} - Element ConvertIn(const Element &v) const {return m_mr->ConvertIn(v);} - virtual Element ConvertOut(const Element &v) const {return m_mr->ConvertOut(v);} - const AbstractGroup & GetGroup() const {return m_mr->MultiplicativeGroup();} - Element BERDecodeElement(BufferedTransformation &bt) const {return Integer(bt);} - void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {v.DEREncode(bt);} - - // non-inherited - void SetModulus(const Integer &v) {m_mr.reset(new MontgomeryRepresentation(v));} - const Integer & GetModulus() const {return m_mr->GetModulus();} - -private: - value_ptr m_mr; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/mqueue.cpp b/lib/cryptopp/mqueue.cpp deleted file mode 100644 index 1d645d83d..000000000 --- a/lib/cryptopp/mqueue.cpp +++ /dev/null @@ -1,174 +0,0 @@ -// mqueue.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "mqueue.h" - -NAMESPACE_BEGIN(CryptoPP) - -MessageQueue::MessageQueue(unsigned int nodeSize) - : m_queue(nodeSize), m_lengths(1, 0U), m_messageCounts(1, 0U) -{ -} - -size_t MessageQueue::CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end, const std::string &channel, bool blocking) const -{ - if (begin >= MaxRetrievable()) - return 0; - - return m_queue.CopyRangeTo2(target, begin, STDMIN(MaxRetrievable(), end), channel, blocking); -} - -size_t MessageQueue::TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel, bool blocking) -{ - transferBytes = STDMIN(MaxRetrievable(), transferBytes); - size_t blockedBytes = m_queue.TransferTo2(target, transferBytes, channel, blocking); - m_lengths.front() -= transferBytes; - return blockedBytes; -} - -bool MessageQueue::GetNextMessage() -{ - if (NumberOfMessages() > 0 && !AnyRetrievable()) - { - m_lengths.pop_front(); - if (m_messageCounts[0] == 0 && m_messageCounts.size() > 1) - m_messageCounts.pop_front(); - return true; - } - else - return false; -} - -unsigned int MessageQueue::CopyMessagesTo(BufferedTransformation &target, unsigned int count, const std::string &channel) const -{ - ByteQueue::Walker walker(m_queue); - std::deque::const_iterator it = m_lengths.begin(); - unsigned int i; - for (i=0; i 0 && q2.AnyRetrievable()) - { - size_t len = length; - const byte *data = q2.Spy(len); - len = STDMIN(len, length); - if (memcmp(inString, data, len) != 0) - goto mismatch; - inString += len; - length -= len; - q2.Skip(len); - } - - q1.Put(inString, length); - - if (messageEnd) - { - if (q2.AnyRetrievable()) - goto mismatch; - else if (q2.AnyMessages()) - q2.GetNextMessage(); - else if (q2.NumberOfMessageSeries() > 0) - goto mismatch; - else - q1.MessageEnd(); - } - - return 0; - -mismatch: - return HandleMismatchDetected(blocking); - } -} - -bool EqualityComparisonFilter::ChannelMessageSeriesEnd(const std::string &channel, int propagation, bool blocking) -{ - unsigned int i = MapChannel(channel); - - if (i == 2) - { - OutputMessageSeriesEnd(4, propagation, blocking, channel); - return false; - } - else if (m_mismatchDetected) - return false; - else - { - MessageQueue &q1 = m_q[i], &q2 = m_q[1-i]; - - if (q2.AnyRetrievable() || q2.AnyMessages()) - goto mismatch; - else if (q2.NumberOfMessageSeries() > 0) - return Output(2, (const byte *)"\1", 1, 0, blocking) != 0; - else - q1.MessageSeriesEnd(); - - return false; - -mismatch: - return HandleMismatchDetected(blocking); - } -} - -bool EqualityComparisonFilter::HandleMismatchDetected(bool blocking) -{ - m_mismatchDetected = true; - if (m_throwIfNotEqual) - throw MismatchDetected(); - return Output(1, (const byte *)"\0", 1, 0, blocking) != 0; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/mqueue.h b/lib/cryptopp/mqueue.h deleted file mode 100644 index efa57a7cf..000000000 --- a/lib/cryptopp/mqueue.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef CRYPTOPP_MQUEUE_H -#define CRYPTOPP_MQUEUE_H - -#include "queue.h" -#include "filters.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -//! Message Queue -class CRYPTOPP_DLL MessageQueue : public AutoSignaling -{ -public: - MessageQueue(unsigned int nodeSize=256); - - void IsolatedInitialize(const NameValuePairs ¶meters) - {m_queue.IsolatedInitialize(parameters); m_lengths.assign(1, 0U); m_messageCounts.assign(1, 0U);} - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking) - { - m_queue.Put(begin, length); - m_lengths.back() += length; - if (messageEnd) - { - m_lengths.push_back(0); - m_messageCounts.back()++; - } - return 0; - } - bool IsolatedFlush(bool hardFlush, bool blocking) {return false;} - bool IsolatedMessageSeriesEnd(bool blocking) - {m_messageCounts.push_back(0); return false;} - - lword MaxRetrievable() const - {return m_lengths.front();} - bool AnyRetrievable() const - {return m_lengths.front() > 0;} - - size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const; - - lword TotalBytesRetrievable() const - {return m_queue.MaxRetrievable();} - unsigned int NumberOfMessages() const - {return (unsigned int)m_lengths.size()-1;} - bool GetNextMessage(); - - unsigned int NumberOfMessagesInThisSeries() const - {return m_messageCounts[0];} - unsigned int NumberOfMessageSeries() const - {return (unsigned int)m_messageCounts.size()-1;} - - unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const; - - const byte * Spy(size_t &contiguousSize) const; - - void swap(MessageQueue &rhs); - -private: - ByteQueue m_queue; - std::deque m_lengths; - std::deque m_messageCounts; -}; - - -//! A filter that checks messages on two channels for equality -class CRYPTOPP_DLL EqualityComparisonFilter : public Unflushable > -{ -public: - struct MismatchDetected : public Exception {MismatchDetected() : Exception(DATA_INTEGRITY_CHECK_FAILED, "EqualityComparisonFilter: did not receive the same data on two channels") {}}; - - /*! if throwIfNotEqual is false, this filter will output a '\\0' byte when it detects a mismatch, '\\1' otherwise */ - EqualityComparisonFilter(BufferedTransformation *attachment=NULL, bool throwIfNotEqual=true, const std::string &firstChannel="0", const std::string &secondChannel="1") - : m_throwIfNotEqual(throwIfNotEqual), m_mismatchDetected(false) - , m_firstChannel(firstChannel), m_secondChannel(secondChannel) - {Detach(attachment);} - - size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking); - bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true); - -private: - unsigned int MapChannel(const std::string &channel) const; - bool HandleMismatchDetected(bool blocking); - - bool m_throwIfNotEqual, m_mismatchDetected; - std::string m_firstChannel, m_secondChannel; - MessageQueue m_q[2]; -}; - -NAMESPACE_END - -#ifndef __BORLANDC__ -NAMESPACE_BEGIN(std) -template<> inline void swap(CryptoPP::MessageQueue &a, CryptoPP::MessageQueue &b) -{ - a.swap(b); -} -NAMESPACE_END -#endif - -#endif diff --git a/lib/cryptopp/mqv.cpp b/lib/cryptopp/mqv.cpp deleted file mode 100644 index c427561b2..000000000 --- a/lib/cryptopp/mqv.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// mqv.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "mqv.h" - -NAMESPACE_BEGIN(CryptoPP) - -void TestInstantiations_MQV() -{ - MQV mqv; -} - -NAMESPACE_END diff --git a/lib/cryptopp/mqv.h b/lib/cryptopp/mqv.h deleted file mode 100644 index 2683817b0..000000000 --- a/lib/cryptopp/mqv.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef CRYPTOPP_MQV_H -#define CRYPTOPP_MQV_H - -/** \file -*/ - -#include "gfpcrypt.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -template -class MQV_Domain : public AuthenticatedKeyAgreementDomain -{ -public: - typedef GROUP_PARAMETERS GroupParameters; - typedef typename GroupParameters::Element Element; - typedef MQV_Domain Domain; - - MQV_Domain() {} - - MQV_Domain(const GroupParameters ¶ms) - : m_groupParameters(params) {} - - MQV_Domain(BufferedTransformation &bt) - {m_groupParameters.BERDecode(bt);} - - template - MQV_Domain(T1 v1, T2 v2) - {m_groupParameters.Initialize(v1, v2);} - - template - MQV_Domain(T1 v1, T2 v2, T3 v3) - {m_groupParameters.Initialize(v1, v2, v3);} - - template - MQV_Domain(T1 v1, T2 v2, T3 v3, T4 v4) - {m_groupParameters.Initialize(v1, v2, v3, v4);} - - const GroupParameters & GetGroupParameters() const {return m_groupParameters;} - GroupParameters & AccessGroupParameters() {return m_groupParameters;} - - CryptoParameters & AccessCryptoParameters() {return AccessAbstractGroupParameters();} - - unsigned int AgreedValueLength() const {return GetAbstractGroupParameters().GetEncodedElementSize(false);} - unsigned int StaticPrivateKeyLength() const {return GetAbstractGroupParameters().GetSubgroupOrder().ByteCount();} - unsigned int StaticPublicKeyLength() const {return GetAbstractGroupParameters().GetEncodedElementSize(true);} - - void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const - { - Integer x(rng, Integer::One(), GetAbstractGroupParameters().GetMaxExponent()); - x.Encode(privateKey, StaticPrivateKeyLength()); - } - - void GenerateStaticPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const - { - const DL_GroupParameters ¶ms = GetAbstractGroupParameters(); - Integer x(privateKey, StaticPrivateKeyLength()); - Element y = params.ExponentiateBase(x); - params.EncodeElement(true, y, publicKey); - } - - unsigned int EphemeralPrivateKeyLength() const {return StaticPrivateKeyLength() + StaticPublicKeyLength();} - unsigned int EphemeralPublicKeyLength() const {return StaticPublicKeyLength();} - - void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const - { - const DL_GroupParameters ¶ms = GetAbstractGroupParameters(); - Integer x(rng, Integer::One(), params.GetMaxExponent()); - x.Encode(privateKey, StaticPrivateKeyLength()); - Element y = params.ExponentiateBase(x); - params.EncodeElement(true, y, privateKey+StaticPrivateKeyLength()); - } - - void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const - { - memcpy(publicKey, privateKey+StaticPrivateKeyLength(), EphemeralPublicKeyLength()); - } - - bool Agree(byte *agreedValue, - const byte *staticPrivateKey, const byte *ephemeralPrivateKey, - const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, - bool validateStaticOtherPublicKey=true) const - { - try - { - const DL_GroupParameters ¶ms = GetAbstractGroupParameters(); - Element WW = params.DecodeElement(staticOtherPublicKey, validateStaticOtherPublicKey); - Element VV = params.DecodeElement(ephemeralOtherPublicKey, true); - - Integer s(staticPrivateKey, StaticPrivateKeyLength()); - Integer u(ephemeralPrivateKey, StaticPrivateKeyLength()); - Element V = params.DecodeElement(ephemeralPrivateKey+StaticPrivateKeyLength(), false); - - const Integer &r = params.GetSubgroupOrder(); - Integer h2 = Integer::Power2((r.BitCount()+1)/2); - Integer e = ((h2+params.ConvertElementToInteger(V)%h2)*s+u) % r; - Integer tt = h2 + params.ConvertElementToInteger(VV) % h2; - - if (COFACTOR_OPTION::ToEnum() == NO_COFACTOR_MULTIPLICTION) - { - Element P = params.ExponentiateElement(WW, tt); - P = m_groupParameters.MultiplyElements(P, VV); - Element R[2]; - const Integer e2[2] = {r, e}; - params.SimultaneousExponentiate(R, P, e2, 2); - if (!params.IsIdentity(R[0]) || params.IsIdentity(R[1])) - return false; - params.EncodeElement(false, R[1], agreedValue); - } - else - { - const Integer &k = params.GetCofactor(); - if (COFACTOR_OPTION::ToEnum() == COMPATIBLE_COFACTOR_MULTIPLICTION) - e = ModularArithmetic(r).Divide(e, k); - Element P = m_groupParameters.CascadeExponentiate(VV, k*e, WW, k*(e*tt%r)); - if (params.IsIdentity(P)) - return false; - params.EncodeElement(false, P, agreedValue); - } - } - catch (DL_BadElement &) - { - return false; - } - return true; - } - -private: - DL_GroupParameters & AccessAbstractGroupParameters() {return m_groupParameters;} - const DL_GroupParameters & GetAbstractGroupParameters() const {return m_groupParameters;} - - GroupParameters m_groupParameters; -}; - -//! Menezes-Qu-Vanstone in GF(p) with key validation, AKA MQV -typedef MQV_Domain MQV; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/nbtheory.cpp b/lib/cryptopp/nbtheory.cpp deleted file mode 100644 index 3fdea4e69..000000000 --- a/lib/cryptopp/nbtheory.cpp +++ /dev/null @@ -1,1123 +0,0 @@ -// nbtheory.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "nbtheory.h" -#include "modarith.h" -#include "algparam.h" - -#include -#include - -#ifdef _OPENMP -// needed in MSVC 2005 to generate correct manifest -#include -#endif - -NAMESPACE_BEGIN(CryptoPP) - -const word s_lastSmallPrime = 32719; - -struct NewPrimeTable -{ - std::vector * operator()() const - { - const unsigned int maxPrimeTableSize = 3511; - - std::auto_ptr > pPrimeTable(new std::vector); - std::vector &primeTable = *pPrimeTable; - primeTable.reserve(maxPrimeTableSize); - - primeTable.push_back(2); - unsigned int testEntriesEnd = 1; - - for (unsigned int p=3; p<=s_lastSmallPrime; p+=2) - { - unsigned int j; - for (j=1; j &primeTable = Singleton, NewPrimeTable>().Ref(); - size = (unsigned int)primeTable.size(); - return &primeTable[0]; -} - -bool IsSmallPrime(const Integer &p) -{ - unsigned int primeTableSize; - const word16 * primeTable = GetPrimeTable(primeTableSize); - - if (p.IsPositive() && p <= primeTable[primeTableSize-1]) - return std::binary_search(primeTable, primeTable+primeTableSize, (word16)p.ConvertToLong()); - else - return false; -} - -bool TrialDivision(const Integer &p, unsigned bound) -{ - unsigned int primeTableSize; - const word16 * primeTable = GetPrimeTable(primeTableSize); - - assert(primeTable[primeTableSize-1] >= bound); - - unsigned int i; - for (i = 0; primeTable[i]3 && b>1 && b3 && b>1 && b>a; - - Integer z = a_exp_b_mod_c(b, m, n); - if (z==1 || z==nminus1) - return true; - for (unsigned j=1; j3); - - Integer b; - for (unsigned int i=0; i2); - - Integer b=3; - unsigned int i=0; - int j; - - while ((j=Jacobi(b.Squared()-4, n)) == 1) - { - if (++i==64 && n.IsSquare()) // avoid infinite loop if n is a square - return false; - ++b; ++b; - } - - if (j==0) - return false; - else - return Lucas(n+1, b, n)==2; -} - -bool IsStrongLucasProbablePrime(const Integer &n) -{ - if (n <= 1) - return false; - - if (n.IsEven()) - return n==2; - - assert(n>2); - - Integer b=3; - unsigned int i=0; - int j; - - while ((j=Jacobi(b.Squared()-4, n)) == 1) - { - if (++i==64 && n.IsSquare()) // avoid infinite loop if n is a square - return false; - ++b; ++b; - } - - if (j==0) - return false; - - Integer n1 = n+1; - unsigned int a; - - // calculate a = largest power of 2 that divides n1 - for (a=0; ; a++) - if (n1.GetBit(a)) - break; - Integer m = n1>>a; - - Integer z = Lucas(m, b, n); - if (z==2 || z==n-2) - return true; - for (i=1; i().Ref()) - return SmallDivisorsTest(p); - else - return SmallDivisorsTest(p) && IsStrongProbablePrime(p, 3) && IsStrongLucasProbablePrime(p); -} - -bool VerifyPrime(RandomNumberGenerator &rng, const Integer &p, unsigned int level) -{ - bool pass = IsPrime(p) && RabinMillerTest(rng, p, 1); - if (level >= 1) - pass = pass && RabinMillerTest(rng, p, 10); - return pass; -} - -unsigned int PrimeSearchInterval(const Integer &max) -{ - return max.BitCount(); -} - -static inline bool FastProbablePrimeTest(const Integer &n) -{ - return IsStrongProbablePrime(n,2); -} - -AlgorithmParameters MakeParametersForTwoPrimesOfEqualSize(unsigned int productBitLength) -{ - if (productBitLength < 16) - throw InvalidArgument("invalid bit length"); - - Integer minP, maxP; - - if (productBitLength%2==0) - { - minP = Integer(182) << (productBitLength/2-8); - maxP = Integer::Power2(productBitLength/2)-1; - } - else - { - minP = Integer::Power2((productBitLength-1)/2); - maxP = Integer(181) << ((productBitLength+1)/2-8); - } - - return MakeParameters("RandomNumberType", Integer::PRIME)("Min", minP)("Max", maxP); -} - -class PrimeSieve -{ -public: - // delta == 1 or -1 means double sieve with p = 2*q + delta - PrimeSieve(const Integer &first, const Integer &last, const Integer &step, signed int delta=0); - bool NextCandidate(Integer &c); - - void DoSieve(); - static void SieveSingle(std::vector &sieve, word16 p, const Integer &first, const Integer &step, word16 stepInv); - - Integer m_first, m_last, m_step; - signed int m_delta; - word m_next; - std::vector m_sieve; -}; - -PrimeSieve::PrimeSieve(const Integer &first, const Integer &last, const Integer &step, signed int delta) - : m_first(first), m_last(last), m_step(step), m_delta(delta), m_next(0) -{ - DoSieve(); -} - -bool PrimeSieve::NextCandidate(Integer &c) -{ - bool safe = SafeConvert(std::find(m_sieve.begin()+m_next, m_sieve.end(), false) - m_sieve.begin(), m_next); - assert(safe); - if (m_next == m_sieve.size()) - { - m_first += long(m_sieve.size())*m_step; - if (m_first > m_last) - return false; - else - { - m_next = 0; - DoSieve(); - return NextCandidate(c); - } - } - else - { - c = m_first + long(m_next)*m_step; - ++m_next; - return true; - } -} - -void PrimeSieve::SieveSingle(std::vector &sieve, word16 p, const Integer &first, const Integer &step, word16 stepInv) -{ - if (stepInv) - { - size_t sieveSize = sieve.size(); - size_t j = (word32(p-(first%p))*stepInv) % p; - // if the first multiple of p is p, skip it - if (first.WordCount() <= 1 && first + step*long(j) == p) - j += p; - for (; j < sieveSize; j += p) - sieve[j] = true; - } -} - -void PrimeSieve::DoSieve() -{ - unsigned int primeTableSize; - const word16 * primeTable = GetPrimeTable(primeTableSize); - - const unsigned int maxSieveSize = 32768; - unsigned int sieveSize = STDMIN(Integer(maxSieveSize), (m_last-m_first)/m_step+1).ConvertToLong(); - - m_sieve.clear(); - m_sieve.resize(sieveSize, false); - - if (m_delta == 0) - { - for (unsigned int i = 0; i < primeTableSize; ++i) - SieveSingle(m_sieve, primeTable[i], m_first, m_step, (word16)m_step.InverseMod(primeTable[i])); - } - else - { - assert(m_step%2==0); - Integer qFirst = (m_first-m_delta) >> 1; - Integer halfStep = m_step >> 1; - for (unsigned int i = 0; i < primeTableSize; ++i) - { - word16 p = primeTable[i]; - word16 stepInv = (word16)m_step.InverseMod(p); - SieveSingle(m_sieve, p, m_first, m_step, stepInv); - - word16 halfStepInv = 2*stepInv < p ? 2*stepInv : 2*stepInv-p; - SieveSingle(m_sieve, p, qFirst, halfStep, halfStepInv); - } - } -} - -bool FirstPrime(Integer &p, const Integer &max, const Integer &equiv, const Integer &mod, const PrimeSelector *pSelector) -{ - assert(!equiv.IsNegative() && equiv < mod); - - Integer gcd = GCD(equiv, mod); - if (gcd != Integer::One()) - { - // the only possible prime p such that p%mod==equiv where GCD(mod,equiv)!=1 is GCD(mod,equiv) - if (p <= gcd && gcd <= max && IsPrime(gcd) && (!pSelector || pSelector->IsAcceptable(gcd))) - { - p = gcd; - return true; - } - else - return false; - } - - unsigned int primeTableSize; - const word16 * primeTable = GetPrimeTable(primeTableSize); - - if (p <= primeTable[primeTableSize-1]) - { - const word16 *pItr; - - --p; - if (p.IsPositive()) - pItr = std::upper_bound(primeTable, primeTable+primeTableSize, (word)p.ConvertToLong()); - else - pItr = primeTable; - - while (pItr < primeTable+primeTableSize && !(*pItr%mod == equiv && (!pSelector || pSelector->IsAcceptable(*pItr)))) - ++pItr; - - if (pItr < primeTable+primeTableSize) - { - p = *pItr; - return p <= max; - } - - p = primeTable[primeTableSize-1]+1; - } - - assert(p > primeTable[primeTableSize-1]); - - if (mod.IsOdd()) - return FirstPrime(p, max, CRT(equiv, mod, 1, 2, 1), mod<<1, pSelector); - - p += (equiv-p)%mod; - - if (p>max) - return false; - - PrimeSieve sieve(p, max, mod); - - while (sieve.NextCandidate(p)) - { - if ((!pSelector || pSelector->IsAcceptable(p)) && FastProbablePrimeTest(p) && IsPrime(p)) - return true; - } - - return false; -} - -// the following two functions are based on code and comments provided by Preda Mihailescu -static bool ProvePrime(const Integer &p, const Integer &q) -{ - assert(p < q*q*q); - assert(p % q == 1); - -// this is the Quisquater test. Numbers p having passed the Lucas - Lehmer test -// for q and verifying p < q^3 can only be built up of two factors, both = 1 mod q, -// or be prime. The next two lines build the discriminant of a quadratic equation -// which holds iff p is built up of two factors (excercise ... ) - - Integer r = (p-1)/q; - if (((r%q).Squared()-4*(r/q)).IsSquare()) - return false; - - unsigned int primeTableSize; - const word16 * primeTable = GetPrimeTable(primeTableSize); - - assert(primeTableSize >= 50); - for (int i=0; i<50; i++) - { - Integer b = a_exp_b_mod_c(primeTable[i], r, p); - if (b != 1) - return a_exp_b_mod_c(b, q, p) == 1; - } - return false; -} - -Integer MihailescuProvablePrime(RandomNumberGenerator &rng, unsigned int pbits) -{ - Integer p; - Integer minP = Integer::Power2(pbits-1); - Integer maxP = Integer::Power2(pbits) - 1; - - if (maxP <= Integer(s_lastSmallPrime).Squared()) - { - // Randomize() will generate a prime provable by trial division - p.Randomize(rng, minP, maxP, Integer::PRIME); - return p; - } - - unsigned int qbits = (pbits+2)/3 + 1 + rng.GenerateWord32(0, pbits/36); - Integer q = MihailescuProvablePrime(rng, qbits); - Integer q2 = q<<1; - - while (true) - { - // this initializes the sieve to search in the arithmetic - // progression p = p_0 + \lambda * q2 = p_0 + 2 * \lambda * q, - // with q the recursively generated prime above. We will be able - // to use Lucas tets for proving primality. A trick of Quisquater - // allows taking q > cubic_root(p) rather then square_root: this - // decreases the recursion. - - p.Randomize(rng, minP, maxP, Integer::ANY, 1, q2); - PrimeSieve sieve(p, STDMIN(p+PrimeSearchInterval(maxP)*q2, maxP), q2); - - while (sieve.NextCandidate(p)) - { - if (FastProbablePrimeTest(p) && ProvePrime(p, q)) - return p; - } - } - - // not reached - return p; -} - -Integer MaurerProvablePrime(RandomNumberGenerator &rng, unsigned int bits) -{ - const unsigned smallPrimeBound = 29, c_opt=10; - Integer p; - - unsigned int primeTableSize; - const word16 * primeTable = GetPrimeTable(primeTableSize); - - if (bits < smallPrimeBound) - { - do - p.Randomize(rng, Integer::Power2(bits-1), Integer::Power2(bits)-1, Integer::ANY, 1, 2); - while (TrialDivision(p, 1 << ((bits+1)/2))); - } - else - { - const unsigned margin = bits > 50 ? 20 : (bits-10)/2; - double relativeSize; - do - relativeSize = pow(2.0, double(rng.GenerateWord32())/0xffffffff - 1); - while (bits * relativeSize >= bits - margin); - - Integer a,b; - Integer q = MaurerProvablePrime(rng, unsigned(bits*relativeSize)); - Integer I = Integer::Power2(bits-2)/q; - Integer I2 = I << 1; - unsigned int trialDivisorBound = (unsigned int)STDMIN((unsigned long)primeTable[primeTableSize-1], (unsigned long)bits*bits/c_opt); - bool success = false; - while (!success) - { - p.Randomize(rng, I, I2, Integer::ANY); - p *= q; p <<= 1; ++p; - if (!TrialDivision(p, trialDivisorBound)) - { - a.Randomize(rng, 2, p-1, Integer::ANY); - b = a_exp_b_mod_c(a, (p-1)/q, p); - success = (GCD(b-1, p) == 1) && (a_exp_b_mod_c(b, q, p) == 1); - } - } - } - return p; -} - -Integer CRT(const Integer &xp, const Integer &p, const Integer &xq, const Integer &q, const Integer &u) -{ - // isn't operator overloading great? - return p * (u * (xq-xp) % q) + xp; -/* - Integer t1 = xq-xp; - cout << hex << t1 << endl; - Integer t2 = u * t1; - cout << hex << t2 << endl; - Integer t3 = t2 % q; - cout << hex << t3 << endl; - Integer t4 = p * t3; - cout << hex << t4 << endl; - Integer t5 = t4 + xp; - cout << hex << t5 << endl; - return t5; -*/ -} - -Integer ModularSquareRoot(const Integer &a, const Integer &p) -{ - if (p%4 == 3) - return a_exp_b_mod_c(a, (p+1)/4, p); - - Integer q=p-1; - unsigned int r=0; - while (q.IsEven()) - { - r++; - q >>= 1; - } - - Integer n=2; - while (Jacobi(n, p) != -1) - ++n; - - Integer y = a_exp_b_mod_c(n, q, p); - Integer x = a_exp_b_mod_c(a, (q-1)/2, p); - Integer b = (x.Squared()%p)*a%p; - x = a*x%p; - Integer tempb, t; - - while (b != 1) - { - unsigned m=0; - tempb = b; - do - { - m++; - b = b.Squared()%p; - if (m==r) - return Integer::Zero(); - } - while (b != 1); - - t = y; - for (unsigned i=0; i>= 1; - b >>= 1; - k++; - } - - while (a[0]==0) - a >>= 1; - - while (b[0]==0) - b >>= 1; - - while (1) - { - switch (a.Compare(b)) - { - case -1: - b -= a; - while (b[0]==0) - b >>= 1; - break; - - case 0: - return (a <<= k); - - case 1: - a -= b; - while (a[0]==0) - a >>= 1; - break; - - default: - assert(false); - } - } -} - -Integer EuclideanMultiplicativeInverse(const Integer &a, const Integer &b) -{ - assert(b.Positive()); - - if (a.Negative()) - return EuclideanMultiplicativeInverse(a%b, b); - - if (b[0]==0) - { - if (!b || a[0]==0) - return Integer::Zero(); // no inverse - if (a==1) - return 1; - Integer u = EuclideanMultiplicativeInverse(b, a); - if (!u) - return Integer::Zero(); // no inverse - else - return (b*(a-u)+1)/a; - } - - Integer u=1, d=a, v1=b, v3=b, t1, t3, b2=(b+1)>>1; - - if (a[0]) - { - t1 = Integer::Zero(); - t3 = -b; - } - else - { - t1 = b2; - t3 = a>>1; - } - - while (!!t3) - { - while (t3[0]==0) - { - t3 >>= 1; - if (t1[0]==0) - t1 >>= 1; - else - { - t1 >>= 1; - t1 += b2; - } - } - if (t3.Positive()) - { - u = t1; - d = t3; - } - else - { - v1 = b-t1; - v3 = -t3; - } - t1 = u-v1; - t3 = d-v3; - if (t1.Negative()) - t1 += b; - } - if (d==1) - return u; - else - return Integer::Zero(); // no inverse -} -*/ - -int Jacobi(const Integer &aIn, const Integer &bIn) -{ - assert(bIn.IsOdd()); - - Integer b = bIn, a = aIn%bIn; - int result = 1; - - while (!!a) - { - unsigned i=0; - while (a.GetBit(i)==0) - i++; - a>>=i; - - if (i%2==1 && (b%8==3 || b%8==5)) - result = -result; - - if (a%4==3 && b%4==3) - result = -result; - - std::swap(a, b); - a %= b; - } - - return (b==1) ? result : 0; -} - -Integer Lucas(const Integer &e, const Integer &pIn, const Integer &n) -{ - unsigned i = e.BitCount(); - if (i==0) - return Integer::Two(); - - MontgomeryRepresentation m(n); - Integer p=m.ConvertIn(pIn%n), two=m.ConvertIn(Integer::Two()); - Integer v=p, v1=m.Subtract(m.Square(p), two); - - i--; - while (i--) - { - if (e.GetBit(i)) - { - // v = (v*v1 - p) % m; - v = m.Subtract(m.Multiply(v,v1), p); - // v1 = (v1*v1 - 2) % m; - v1 = m.Subtract(m.Square(v1), two); - } - else - { - // v1 = (v*v1 - p) % m; - v1 = m.Subtract(m.Multiply(v,v1), p); - // v = (v*v - 2) % m; - v = m.Subtract(m.Square(v), two); - } - } - return m.ConvertOut(v); -} - -// This is Peter Montgomery's unpublished Lucas sequence evalutation algorithm. -// The total number of multiplies and squares used is less than the binary -// algorithm (see above). Unfortunately I can't get it to run as fast as -// the binary algorithm because of the extra overhead. -/* -Integer Lucas(const Integer &n, const Integer &P, const Integer &modulus) -{ - if (!n) - return 2; - -#define f(A, B, C) m.Subtract(m.Multiply(A, B), C) -#define X2(A) m.Subtract(m.Square(A), two) -#define X3(A) m.Multiply(A, m.Subtract(m.Square(A), three)) - - MontgomeryRepresentation m(modulus); - Integer two=m.ConvertIn(2), three=m.ConvertIn(3); - Integer A=m.ConvertIn(P), B, C, p, d=n, e, r, t, T, U; - - while (d!=1) - { - p = d; - unsigned int b = WORD_BITS * p.WordCount(); - Integer alpha = (Integer(5)<<(2*b-2)).SquareRoot() - Integer::Power2(b-1); - r = (p*alpha)>>b; - e = d-r; - B = A; - C = two; - d = r; - - while (d!=e) - { - if (d>2)) - if ((dm3+em3==0 || dm3+em3==3) && (t = e, t >>= 2, t += e, d <= t)) - { - // #1 -// t = (d+d-e)/3; -// t = d; t += d; t -= e; t /= 3; -// e = (e+e-d)/3; -// e += e; e -= d; e /= 3; -// d = t; - -// t = (d+e)/3 - t = d; t += e; t /= 3; - e -= t; - d -= t; - - T = f(A, B, C); - U = f(T, A, B); - B = f(T, B, A); - A = U; - continue; - } - -// if (dm6 == em6 && d <= e + (e>>2)) - if (dm3 == em3 && dm2 == em2 && (t = e, t >>= 2, t += e, d <= t)) - { - // #2 -// d = (d-e)>>1; - d -= e; d >>= 1; - B = f(A, B, C); - A = X2(A); - continue; - } - -// if (d <= (e<<2)) - if (d <= (t = e, t <<= 2)) - { - // #3 - d -= e; - C = f(A, B, C); - swap(B, C); - continue; - } - - if (dm2 == em2) - { - // #4 -// d = (d-e)>>1; - d -= e; d >>= 1; - B = f(A, B, C); - A = X2(A); - continue; - } - - if (dm2 == 0) - { - // #5 - d >>= 1; - C = f(A, C, B); - A = X2(A); - continue; - } - - if (dm3 == 0) - { - // #6 -// d = d/3 - e; - d /= 3; d -= e; - T = X2(A); - C = f(T, f(A, B, C), C); - swap(B, C); - A = f(T, A, A); - continue; - } - - if (dm3+em3==0 || dm3+em3==3) - { - // #7 -// d = (d-e-e)/3; - d -= e; d -= e; d /= 3; - T = f(A, B, C); - B = f(T, A, B); - A = X3(A); - continue; - } - - if (dm3 == em3) - { - // #8 -// d = (d-e)/3; - d -= e; d /= 3; - T = f(A, B, C); - C = f(A, C, B); - B = T; - A = X3(A); - continue; - } - - assert(em2 == 0); - // #9 - e >>= 1; - C = f(C, B, A); - B = X2(B); - } - - A = f(A, B, C); - } - -#undef f -#undef X2 -#undef X3 - - return m.ConvertOut(A); -} -*/ - -Integer InverseLucas(const Integer &e, const Integer &m, const Integer &p, const Integer &q, const Integer &u) -{ - Integer d = (m*m-4); - Integer p2, q2; - #pragma omp parallel - #pragma omp sections - { - #pragma omp section - { - p2 = p-Jacobi(d,p); - p2 = Lucas(EuclideanMultiplicativeInverse(e,p2), m, p); - } - #pragma omp section - { - q2 = q-Jacobi(d,q); - q2 = Lucas(EuclideanMultiplicativeInverse(e,q2), m, q); - } - } - return CRT(p2, p, q2, q, u); -} - -unsigned int FactoringWorkFactor(unsigned int n) -{ - // extrapolated from the table in Odlyzko's "The Future of Integer Factorization" - // updated to reflect the factoring of RSA-130 - if (n<5) return 0; - else return (unsigned int)(2.4 * pow((double)n, 1.0/3.0) * pow(log(double(n)), 2.0/3.0) - 5); -} - -unsigned int DiscreteLogWorkFactor(unsigned int n) -{ - // assuming discrete log takes about the same time as factoring - if (n<5) return 0; - else return (unsigned int)(2.4 * pow((double)n, 1.0/3.0) * pow(log(double(n)), 2.0/3.0) - 5); -} - -// ******************************************************** - -void PrimeAndGenerator::Generate(signed int delta, RandomNumberGenerator &rng, unsigned int pbits, unsigned int qbits) -{ - // no prime exists for delta = -1, qbits = 4, and pbits = 5 - assert(qbits > 4); - assert(pbits > qbits); - - if (qbits+1 == pbits) - { - Integer minP = Integer::Power2(pbits-1); - Integer maxP = Integer::Power2(pbits) - 1; - bool success = false; - - while (!success) - { - p.Randomize(rng, minP, maxP, Integer::ANY, 6+5*delta, 12); - PrimeSieve sieve(p, STDMIN(p+PrimeSearchInterval(maxP)*12, maxP), 12, delta); - - while (sieve.NextCandidate(p)) - { - assert(IsSmallPrime(p) || SmallDivisorsTest(p)); - q = (p-delta) >> 1; - assert(IsSmallPrime(q) || SmallDivisorsTest(q)); - if (FastProbablePrimeTest(q) && FastProbablePrimeTest(p) && IsPrime(q) && IsPrime(p)) - { - success = true; - break; - } - } - } - - if (delta == 1) - { - // find g such that g is a quadratic residue mod p, then g has order q - // g=4 always works, but this way we get the smallest quadratic residue (other than 1) - for (g=2; Jacobi(g, p) != 1; ++g) {} - // contributed by Walt Tuvell: g should be the following according to the Law of Quadratic Reciprocity - assert((p%8==1 || p%8==7) ? g==2 : (p%12==1 || p%12==11) ? g==3 : g==4); - } - else - { - assert(delta == -1); - // find g such that g*g-4 is a quadratic non-residue, - // and such that g has order q - for (g=3; ; ++g) - if (Jacobi(g*g-4, p)==-1 && Lucas(q, g, p)==2) - break; - } - } - else - { - Integer minQ = Integer::Power2(qbits-1); - Integer maxQ = Integer::Power2(qbits) - 1; - Integer minP = Integer::Power2(pbits-1); - Integer maxP = Integer::Power2(pbits) - 1; - - do - { - q.Randomize(rng, minQ, maxQ, Integer::PRIME); - } while (!p.Randomize(rng, minP, maxP, Integer::PRIME, delta%q, q)); - - // find a random g of order q - if (delta==1) - { - do - { - Integer h(rng, 2, p-2, Integer::ANY); - g = a_exp_b_mod_c(h, (p-1)/q, p); - } while (g <= 1); - assert(a_exp_b_mod_c(g, q, p)==1); - } - else - { - assert(delta==-1); - do - { - Integer h(rng, 3, p-1, Integer::ANY); - if (Jacobi(h*h-4, p)==1) - continue; - g = Lucas((p+1)/q, h, p); - } while (g <= 2); - assert(Lucas(q, g, p) == 2); - } - } -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/nbtheory.h b/lib/cryptopp/nbtheory.h deleted file mode 100644 index 636479269..000000000 --- a/lib/cryptopp/nbtheory.h +++ /dev/null @@ -1,131 +0,0 @@ -// nbtheory.h - written and placed in the public domain by Wei Dai - -#ifndef CRYPTOPP_NBTHEORY_H -#define CRYPTOPP_NBTHEORY_H - -#include "integer.h" -#include "algparam.h" - -NAMESPACE_BEGIN(CryptoPP) - -// obtain pointer to small prime table and get its size -CRYPTOPP_DLL const word16 * CRYPTOPP_API GetPrimeTable(unsigned int &size); - -// ************ primality testing **************** - -// generate a provable prime -CRYPTOPP_DLL Integer CRYPTOPP_API MaurerProvablePrime(RandomNumberGenerator &rng, unsigned int bits); -CRYPTOPP_DLL Integer CRYPTOPP_API MihailescuProvablePrime(RandomNumberGenerator &rng, unsigned int bits); - -CRYPTOPP_DLL bool CRYPTOPP_API IsSmallPrime(const Integer &p); - -// returns true if p is divisible by some prime less than bound -// bound not be greater than the largest entry in the prime table -CRYPTOPP_DLL bool CRYPTOPP_API TrialDivision(const Integer &p, unsigned bound); - -// returns true if p is NOT divisible by small primes -CRYPTOPP_DLL bool CRYPTOPP_API SmallDivisorsTest(const Integer &p); - -// These is no reason to use these two, use the ones below instead -CRYPTOPP_DLL bool CRYPTOPP_API IsFermatProbablePrime(const Integer &n, const Integer &b); -CRYPTOPP_DLL bool CRYPTOPP_API IsLucasProbablePrime(const Integer &n); - -CRYPTOPP_DLL bool CRYPTOPP_API IsStrongProbablePrime(const Integer &n, const Integer &b); -CRYPTOPP_DLL bool CRYPTOPP_API IsStrongLucasProbablePrime(const Integer &n); - -// Rabin-Miller primality test, i.e. repeating the strong probable prime test -// for several rounds with random bases -CRYPTOPP_DLL bool CRYPTOPP_API RabinMillerTest(RandomNumberGenerator &rng, const Integer &w, unsigned int rounds); - -// primality test, used to generate primes -CRYPTOPP_DLL bool CRYPTOPP_API IsPrime(const Integer &p); - -// more reliable than IsPrime(), used to verify primes generated by others -CRYPTOPP_DLL bool CRYPTOPP_API VerifyPrime(RandomNumberGenerator &rng, const Integer &p, unsigned int level = 1); - -class CRYPTOPP_DLL PrimeSelector -{ -public: - const PrimeSelector *GetSelectorPointer() const {return this;} - virtual bool IsAcceptable(const Integer &candidate) const =0; -}; - -// use a fast sieve to find the first probable prime in {x | p<=x<=max and x%mod==equiv} -// returns true iff successful, value of p is undefined if no such prime exists -CRYPTOPP_DLL bool CRYPTOPP_API FirstPrime(Integer &p, const Integer &max, const Integer &equiv, const Integer &mod, const PrimeSelector *pSelector); - -CRYPTOPP_DLL unsigned int CRYPTOPP_API PrimeSearchInterval(const Integer &max); - -CRYPTOPP_DLL AlgorithmParameters CRYPTOPP_API MakeParametersForTwoPrimesOfEqualSize(unsigned int productBitLength); - -// ********** other number theoretic functions ************ - -inline Integer GCD(const Integer &a, const Integer &b) - {return Integer::Gcd(a,b);} -inline bool RelativelyPrime(const Integer &a, const Integer &b) - {return Integer::Gcd(a,b) == Integer::One();} -inline Integer LCM(const Integer &a, const Integer &b) - {return a/Integer::Gcd(a,b)*b;} -inline Integer EuclideanMultiplicativeInverse(const Integer &a, const Integer &b) - {return a.InverseMod(b);} - -// use Chinese Remainder Theorem to calculate x given x mod p and x mod q, and u = inverse of p mod q -CRYPTOPP_DLL Integer CRYPTOPP_API CRT(const Integer &xp, const Integer &p, const Integer &xq, const Integer &q, const Integer &u); - -// if b is prime, then Jacobi(a, b) returns 0 if a%b==0, 1 if a is quadratic residue mod b, -1 otherwise -// check a number theory book for what Jacobi symbol means when b is not prime -CRYPTOPP_DLL int CRYPTOPP_API Jacobi(const Integer &a, const Integer &b); - -// calculates the Lucas function V_e(p, 1) mod n -CRYPTOPP_DLL Integer CRYPTOPP_API Lucas(const Integer &e, const Integer &p, const Integer &n); -// calculates x such that m==Lucas(e, x, p*q), p q primes, u=inverse of p mod q -CRYPTOPP_DLL Integer CRYPTOPP_API InverseLucas(const Integer &e, const Integer &m, const Integer &p, const Integer &q, const Integer &u); - -inline Integer ModularExponentiation(const Integer &a, const Integer &e, const Integer &m) - {return a_exp_b_mod_c(a, e, m);} -// returns x such that x*x%p == a, p prime -CRYPTOPP_DLL Integer CRYPTOPP_API ModularSquareRoot(const Integer &a, const Integer &p); -// returns x such that a==ModularExponentiation(x, e, p*q), p q primes, -// and e relatively prime to (p-1)*(q-1) -// dp=d%(p-1), dq=d%(q-1), (d is inverse of e mod (p-1)*(q-1)) -// and u=inverse of p mod q -CRYPTOPP_DLL Integer CRYPTOPP_API ModularRoot(const Integer &a, const Integer &dp, const Integer &dq, const Integer &p, const Integer &q, const Integer &u); - -// find r1 and r2 such that ax^2 + bx + c == 0 (mod p) for x in {r1, r2}, p prime -// returns true if solutions exist -CRYPTOPP_DLL bool CRYPTOPP_API SolveModularQuadraticEquation(Integer &r1, Integer &r2, const Integer &a, const Integer &b, const Integer &c, const Integer &p); - -// returns log base 2 of estimated number of operations to calculate discrete log or factor a number -CRYPTOPP_DLL unsigned int CRYPTOPP_API DiscreteLogWorkFactor(unsigned int bitlength); -CRYPTOPP_DLL unsigned int CRYPTOPP_API FactoringWorkFactor(unsigned int bitlength); - -// ******************************************************** - -//! generator of prime numbers of special forms -class CRYPTOPP_DLL PrimeAndGenerator -{ -public: - PrimeAndGenerator() {} - // generate a random prime p of the form 2*q+delta, where delta is 1 or -1 and q is also prime - // Precondition: pbits > 5 - // warning: this is slow, because primes of this form are harder to find - PrimeAndGenerator(signed int delta, RandomNumberGenerator &rng, unsigned int pbits) - {Generate(delta, rng, pbits, pbits-1);} - // generate a random prime p of the form 2*r*q+delta, where q is also prime - // Precondition: qbits > 4 && pbits > qbits - PrimeAndGenerator(signed int delta, RandomNumberGenerator &rng, unsigned int pbits, unsigned qbits) - {Generate(delta, rng, pbits, qbits);} - - void Generate(signed int delta, RandomNumberGenerator &rng, unsigned int pbits, unsigned qbits); - - const Integer& Prime() const {return p;} - const Integer& SubPrime() const {return q;} - const Integer& Generator() const {return g;} - -private: - Integer p, q, g; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/network.cpp b/lib/cryptopp/network.cpp deleted file mode 100644 index 9b7198d16..000000000 --- a/lib/cryptopp/network.cpp +++ /dev/null @@ -1,550 +0,0 @@ -// network.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "network.h" -#include "wait.h" - -#define CRYPTOPP_TRACE_NETWORK 0 - -NAMESPACE_BEGIN(CryptoPP) - -#ifdef HIGHRES_TIMER_AVAILABLE - -lword LimitedBandwidth::ComputeCurrentTransceiveLimit() -{ - if (!m_maxBytesPerSecond) - return ULONG_MAX; - - double curTime = GetCurTimeAndCleanUp(); - lword total = 0; - for (OpQueue::size_type i=0; i!=m_ops.size(); ++i) - total += m_ops[i].second; - return SaturatingSubtract(m_maxBytesPerSecond, total); -} - -double LimitedBandwidth::TimeToNextTransceive() -{ - if (!m_maxBytesPerSecond) - return 0; - - if (!m_nextTransceiveTime) - ComputeNextTransceiveTime(); - - return SaturatingSubtract(m_nextTransceiveTime, m_timer.ElapsedTimeAsDouble()); -} - -void LimitedBandwidth::NoteTransceive(lword size) -{ - if (m_maxBytesPerSecond) - { - double curTime = GetCurTimeAndCleanUp(); - m_ops.push_back(std::make_pair(curTime, size)); - m_nextTransceiveTime = 0; - } -} - -void LimitedBandwidth::ComputeNextTransceiveTime() -{ - double curTime = GetCurTimeAndCleanUp(); - lword total = 0; - for (unsigned int i=0; i!=m_ops.size(); ++i) - total += m_ops[i].second; - m_nextTransceiveTime = - (total < m_maxBytesPerSecond) ? curTime : m_ops.front().first + 1000; -} - -double LimitedBandwidth::GetCurTimeAndCleanUp() -{ - if (!m_maxBytesPerSecond) - return 0; - - double curTime = m_timer.ElapsedTimeAsDouble(); - while (m_ops.size() && (m_ops.front().first + 1000 < curTime)) - m_ops.pop_front(); - return curTime; -} - -void LimitedBandwidth::GetWaitObjects(WaitObjectContainer &container, const CallStack &callStack) -{ - double nextTransceiveTime = TimeToNextTransceive(); - if (nextTransceiveTime) - container.ScheduleEvent(nextTransceiveTime, CallStack("LimitedBandwidth::GetWaitObjects()", &callStack)); -} - -// ************************************************************* - -size_t NonblockingSource::GeneralPump2( - lword& byteCount, bool blockingOutput, - unsigned long maxTime, bool checkDelimiter, byte delimiter) -{ - m_blockedBySpeedLimit = false; - - if (!GetMaxBytesPerSecond()) - { - size_t ret = DoPump(byteCount, blockingOutput, maxTime, checkDelimiter, delimiter); - m_doPumpBlocked = (ret != 0); - return ret; - } - - bool forever = (maxTime == INFINITE_TIME); - unsigned long timeToGo = maxTime; - Timer timer(Timer::MILLISECONDS, forever); - lword maxSize = byteCount; - byteCount = 0; - - timer.StartTimer(); - - while (true) - { - lword curMaxSize = UnsignedMin(ComputeCurrentTransceiveLimit(), maxSize - byteCount); - - if (curMaxSize || m_doPumpBlocked) - { - if (!forever) timeToGo = SaturatingSubtract(maxTime, timer.ElapsedTime()); - size_t ret = DoPump(curMaxSize, blockingOutput, timeToGo, checkDelimiter, delimiter); - m_doPumpBlocked = (ret != 0); - if (curMaxSize) - { - NoteTransceive(curMaxSize); - byteCount += curMaxSize; - } - if (ret) - return ret; - } - - if (maxSize != ULONG_MAX && byteCount >= maxSize) - break; - - if (!forever) - { - timeToGo = SaturatingSubtract(maxTime, timer.ElapsedTime()); - if (!timeToGo) - break; - } - - double waitTime = TimeToNextTransceive(); - if (!forever && waitTime > timeToGo) - { - m_blockedBySpeedLimit = true; - break; - } - - WaitObjectContainer container; - LimitedBandwidth::GetWaitObjects(container, CallStack("NonblockingSource::GeneralPump2() - speed limit", 0)); - container.Wait((unsigned long)waitTime); - } - - return 0; -} - -size_t NonblockingSource::PumpMessages2(unsigned int &messageCount, bool blocking) -{ - if (messageCount == 0) - return 0; - - messageCount = 0; - - lword byteCount; - do { - byteCount = LWORD_MAX; - RETURN_IF_NONZERO(Pump2(byteCount, blocking)); - } while(byteCount == LWORD_MAX); - - if (!m_messageEndSent && SourceExhausted()) - { - RETURN_IF_NONZERO(AttachedTransformation()->Put2(NULL, 0, GetAutoSignalPropagation(), true)); - m_messageEndSent = true; - messageCount = 1; - } - return 0; -} - -lword NonblockingSink::TimedFlush(unsigned long maxTime, size_t targetSize) -{ - m_blockedBySpeedLimit = false; - - size_t curBufSize = GetCurrentBufferSize(); - if (curBufSize <= targetSize && (targetSize || !EofPending())) - return 0; - - if (!GetMaxBytesPerSecond()) - return DoFlush(maxTime, targetSize); - - bool forever = (maxTime == INFINITE_TIME); - unsigned long timeToGo = maxTime; - Timer timer(Timer::MILLISECONDS, forever); - lword totalFlushed = 0; - - timer.StartTimer(); - - while (true) - { - size_t flushSize = UnsignedMin(curBufSize - targetSize, ComputeCurrentTransceiveLimit()); - if (flushSize || EofPending()) - { - if (!forever) timeToGo = SaturatingSubtract(maxTime, timer.ElapsedTime()); - size_t ret = (size_t)DoFlush(timeToGo, curBufSize - flushSize); - if (ret) - { - NoteTransceive(ret); - curBufSize -= ret; - totalFlushed += ret; - } - } - - if (curBufSize <= targetSize && (targetSize || !EofPending())) - break; - - if (!forever) - { - timeToGo = SaturatingSubtract(maxTime, timer.ElapsedTime()); - if (!timeToGo) - break; - } - - double waitTime = TimeToNextTransceive(); - if (!forever && waitTime > timeToGo) - { - m_blockedBySpeedLimit = true; - break; - } - - WaitObjectContainer container; - LimitedBandwidth::GetWaitObjects(container, CallStack("NonblockingSink::TimedFlush() - speed limit", 0)); - container.Wait((unsigned long)waitTime); - } - - return totalFlushed; -} - -bool NonblockingSink::IsolatedFlush(bool hardFlush, bool blocking) -{ - TimedFlush(blocking ? INFINITE_TIME : 0); - return hardFlush && (!!GetCurrentBufferSize() || EofPending()); -} - -// ************************************************************* - -NetworkSource::NetworkSource(BufferedTransformation *attachment) - : NonblockingSource(attachment), m_buf(1024*16) - , m_waitingForResult(false), m_outputBlocked(false) - , m_dataBegin(0), m_dataEnd(0) -{ -} - -unsigned int NetworkSource::GetMaxWaitObjectCount() const -{ - return LimitedBandwidth::GetMaxWaitObjectCount() - + GetReceiver().GetMaxWaitObjectCount() - + AttachedTransformation()->GetMaxWaitObjectCount(); -} - -void NetworkSource::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) -{ - if (BlockedBySpeedLimit()) - LimitedBandwidth::GetWaitObjects(container, CallStack("NetworkSource::GetWaitObjects() - speed limit", &callStack)); - else if (!m_outputBlocked) - { - if (m_dataBegin == m_dataEnd) - AccessReceiver().GetWaitObjects(container, CallStack("NetworkSource::GetWaitObjects() - no data", &callStack)); - else - container.SetNoWait(CallStack("NetworkSource::GetWaitObjects() - have data", &callStack)); - } - - AttachedTransformation()->GetWaitObjects(container, CallStack("NetworkSource::GetWaitObjects() - attachment", &callStack)); -} - -size_t NetworkSource::DoPump(lword &byteCount, bool blockingOutput, unsigned long maxTime, bool checkDelimiter, byte delimiter) -{ - NetworkReceiver &receiver = AccessReceiver(); - - lword maxSize = byteCount; - byteCount = 0; - bool forever = maxTime == INFINITE_TIME; - Timer timer(Timer::MILLISECONDS, forever); - BufferedTransformation *t = AttachedTransformation(); - - if (m_outputBlocked) - goto DoOutput; - - while (true) - { - if (m_dataBegin == m_dataEnd) - { - if (receiver.EofReceived()) - break; - - if (m_waitingForResult) - { - if (receiver.MustWaitForResult() && - !receiver.Wait(SaturatingSubtract(maxTime, timer.ElapsedTime()), - CallStack("NetworkSource::DoPump() - wait receive result", 0))) - break; - - unsigned int recvResult = receiver.GetReceiveResult(); -#if CRYPTOPP_TRACE_NETWORK - OutputDebugString((IntToString((unsigned int)this) + ": Received " + IntToString(recvResult) + " bytes\n").c_str()); -#endif - m_dataEnd += recvResult; - m_waitingForResult = false; - - if (!receiver.MustWaitToReceive() && !receiver.EofReceived() && m_dataEnd != m_buf.size()) - goto ReceiveNoWait; - } - else - { - m_dataEnd = m_dataBegin = 0; - - if (receiver.MustWaitToReceive()) - { - if (!receiver.Wait(SaturatingSubtract(maxTime, timer.ElapsedTime()), - CallStack("NetworkSource::DoPump() - wait receive", 0))) - break; - - receiver.Receive(m_buf+m_dataEnd, m_buf.size()-m_dataEnd); - m_waitingForResult = true; - } - else - { -ReceiveNoWait: - m_waitingForResult = true; - // call Receive repeatedly as long as data is immediately available, - // because some receivers tend to return data in small pieces -#if CRYPTOPP_TRACE_NETWORK - OutputDebugString((IntToString((unsigned int)this) + ": Receiving " + IntToString(m_buf.size()-m_dataEnd) + " bytes\n").c_str()); -#endif - while (receiver.Receive(m_buf+m_dataEnd, m_buf.size()-m_dataEnd)) - { - unsigned int recvResult = receiver.GetReceiveResult(); -#if CRYPTOPP_TRACE_NETWORK - OutputDebugString((IntToString((unsigned int)this) + ": Received " + IntToString(recvResult) + " bytes\n").c_str()); -#endif - m_dataEnd += recvResult; - if (receiver.EofReceived() || m_dataEnd > m_buf.size() /2) - { - m_waitingForResult = false; - break; - } - } - } - } - } - else - { - m_putSize = UnsignedMin(m_dataEnd - m_dataBegin, maxSize - byteCount); - - if (checkDelimiter) - m_putSize = std::find(m_buf+m_dataBegin, m_buf+m_dataBegin+m_putSize, delimiter) - (m_buf+m_dataBegin); - -DoOutput: - size_t result = t->PutModifiable2(m_buf+m_dataBegin, m_putSize, 0, forever || blockingOutput); - if (result) - { - if (t->Wait(SaturatingSubtract(maxTime, timer.ElapsedTime()), - CallStack("NetworkSource::DoPump() - wait attachment", 0))) - goto DoOutput; - else - { - m_outputBlocked = true; - return result; - } - } - m_outputBlocked = false; - - byteCount += m_putSize; - m_dataBegin += m_putSize; - if (checkDelimiter && m_dataBegin < m_dataEnd && m_buf[m_dataBegin] == delimiter) - break; - if (maxSize != ULONG_MAX && byteCount == maxSize) - break; - // once time limit is reached, return even if there is more data waiting - // but make 0 a special case so caller can request a large amount of data to be - // pumped as long as it is immediately available - if (maxTime > 0 && timer.ElapsedTime() > maxTime) - break; - } - } - - return 0; -} - -// ************************************************************* - -NetworkSink::NetworkSink(unsigned int maxBufferSize, unsigned int autoFlushBound) - : m_maxBufferSize(maxBufferSize), m_autoFlushBound(autoFlushBound) - , m_needSendResult(false), m_wasBlocked(false), m_eofState(EOF_NONE) - , m_buffer(STDMIN(16U*1024U+256, maxBufferSize)), m_skipBytes(0) - , m_speedTimer(Timer::MILLISECONDS), m_byteCountSinceLastTimerReset(0) - , m_currentSpeed(0), m_maxObservedSpeed(0) -{ -} - -float NetworkSink::ComputeCurrentSpeed() -{ - if (m_speedTimer.ElapsedTime() > 1000) - { - m_currentSpeed = m_byteCountSinceLastTimerReset * 1000 / m_speedTimer.ElapsedTime(); - m_maxObservedSpeed = STDMAX(m_currentSpeed, m_maxObservedSpeed * 0.98f); - m_byteCountSinceLastTimerReset = 0; - m_speedTimer.StartTimer(); -// OutputDebugString(("max speed: " + IntToString((int)m_maxObservedSpeed) + " current speed: " + IntToString((int)m_currentSpeed) + "\n").c_str()); - } - return m_currentSpeed; -} - -float NetworkSink::GetMaxObservedSpeed() const -{ - lword m = GetMaxBytesPerSecond(); - return m ? STDMIN(m_maxObservedSpeed, float(CRYPTOPP_VC6_INT64 m)) : m_maxObservedSpeed; -} - -unsigned int NetworkSink::GetMaxWaitObjectCount() const -{ - return LimitedBandwidth::GetMaxWaitObjectCount() + GetSender().GetMaxWaitObjectCount(); -} - -void NetworkSink::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) -{ - if (BlockedBySpeedLimit()) - LimitedBandwidth::GetWaitObjects(container, CallStack("NetworkSink::GetWaitObjects() - speed limit", &callStack)); - else if (m_wasBlocked) - AccessSender().GetWaitObjects(container, CallStack("NetworkSink::GetWaitObjects() - was blocked", &callStack)); - else if (!m_buffer.IsEmpty()) - AccessSender().GetWaitObjects(container, CallStack("NetworkSink::GetWaitObjects() - buffer not empty", &callStack)); - else if (EofPending()) - AccessSender().GetWaitObjects(container, CallStack("NetworkSink::GetWaitObjects() - EOF pending", &callStack)); -} - -size_t NetworkSink::Put2(const byte *inString, size_t length, int messageEnd, bool blocking) -{ - if (m_eofState == EOF_DONE) - { - if (length || messageEnd) - throw Exception(Exception::OTHER_ERROR, "NetworkSink::Put2() being called after EOF had been sent"); - - return 0; - } - - if (m_eofState > EOF_NONE) - goto EofSite; - - { - if (m_skipBytes) - { - assert(length >= m_skipBytes); - inString += m_skipBytes; - length -= m_skipBytes; - } - - m_buffer.Put(inString, length); - - if (!blocking || m_buffer.CurrentSize() > m_autoFlushBound) - TimedFlush(0, 0); - - size_t targetSize = messageEnd ? 0 : m_maxBufferSize; - if (blocking) - TimedFlush(INFINITE_TIME, targetSize); - - if (m_buffer.CurrentSize() > targetSize) - { - assert(!blocking); - m_wasBlocked = true; - m_skipBytes += length; - size_t blockedBytes = UnsignedMin(length, m_buffer.CurrentSize() - targetSize); - return STDMAX(blockedBytes, 1); - } - - m_wasBlocked = false; - m_skipBytes = 0; - } - - if (messageEnd) - { - m_eofState = EOF_PENDING_SEND; - - EofSite: - TimedFlush(blocking ? INFINITE_TIME : 0, 0); - if (m_eofState != EOF_DONE) - return 1; - } - - return 0; -} - -lword NetworkSink::DoFlush(unsigned long maxTime, size_t targetSize) -{ - NetworkSender &sender = AccessSender(); - - bool forever = maxTime == INFINITE_TIME; - Timer timer(Timer::MILLISECONDS, forever); - unsigned int totalFlushSize = 0; - - while (true) - { - if (m_buffer.CurrentSize() <= targetSize) - break; - - if (m_needSendResult) - { - if (sender.MustWaitForResult() && - !sender.Wait(SaturatingSubtract(maxTime, timer.ElapsedTime()), - CallStack("NetworkSink::DoFlush() - wait send result", 0))) - break; - - unsigned int sendResult = sender.GetSendResult(); -#if CRYPTOPP_TRACE_NETWORK - OutputDebugString((IntToString((unsigned int)this) + ": Sent " + IntToString(sendResult) + " bytes\n").c_str()); -#endif - m_buffer.Skip(sendResult); - totalFlushSize += sendResult; - m_needSendResult = false; - - if (!m_buffer.AnyRetrievable()) - break; - } - - unsigned long timeOut = maxTime ? SaturatingSubtract(maxTime, timer.ElapsedTime()) : 0; - if (sender.MustWaitToSend() && !sender.Wait(timeOut, CallStack("NetworkSink::DoFlush() - wait send", 0))) - break; - - size_t contiguousSize = 0; - const byte *block = m_buffer.Spy(contiguousSize); - -#if CRYPTOPP_TRACE_NETWORK - OutputDebugString((IntToString((unsigned int)this) + ": Sending " + IntToString(contiguousSize) + " bytes\n").c_str()); -#endif - sender.Send(block, contiguousSize); - m_needSendResult = true; - - if (maxTime > 0 && timeOut == 0) - break; // once time limit is reached, return even if there is more data waiting - } - - m_byteCountSinceLastTimerReset += totalFlushSize; - ComputeCurrentSpeed(); - - if (m_buffer.IsEmpty() && !m_needSendResult) - { - if (m_eofState == EOF_PENDING_SEND) - { - sender.SendEof(); - m_eofState = sender.MustWaitForEof() ? EOF_PENDING_DELIVERY : EOF_DONE; - } - - while (m_eofState == EOF_PENDING_DELIVERY) - { - unsigned long timeOut = maxTime ? SaturatingSubtract(maxTime, timer.ElapsedTime()) : 0; - if (!sender.Wait(timeOut, CallStack("NetworkSink::DoFlush() - wait EOF", 0))) - break; - - if (sender.EofSent()) - m_eofState = EOF_DONE; - } - } - - return totalFlushSize; -} - -#endif // #ifdef HIGHRES_TIMER_AVAILABLE - -NAMESPACE_END diff --git a/lib/cryptopp/network.h b/lib/cryptopp/network.h deleted file mode 100644 index 96cd4567e..000000000 --- a/lib/cryptopp/network.h +++ /dev/null @@ -1,235 +0,0 @@ -#ifndef CRYPTOPP_NETWORK_H -#define CRYPTOPP_NETWORK_H - -#include "config.h" - -#ifdef HIGHRES_TIMER_AVAILABLE - -#include "filters.h" -#include "hrtimer.h" - -#include - -NAMESPACE_BEGIN(CryptoPP) - -class LimitedBandwidth -{ -public: - LimitedBandwidth(lword maxBytesPerSecond = 0) - : m_maxBytesPerSecond(maxBytesPerSecond), m_timer(Timer::MILLISECONDS) - , m_nextTransceiveTime(0) - { m_timer.StartTimer(); } - - lword GetMaxBytesPerSecond() const - { return m_maxBytesPerSecond; } - - void SetMaxBytesPerSecond(lword v) - { m_maxBytesPerSecond = v; } - - lword ComputeCurrentTransceiveLimit(); - - double TimeToNextTransceive(); - - void NoteTransceive(lword size); - -public: - /*! GetWaitObjects() must be called despite the 0 return from GetMaxWaitObjectCount(); - the 0 is because the ScheduleEvent() method is used instead of adding a wait object */ - unsigned int GetMaxWaitObjectCount() const { return 0; } - void GetWaitObjects(WaitObjectContainer &container, const CallStack &callStack); - -private: - lword m_maxBytesPerSecond; - - typedef std::deque > OpQueue; - OpQueue m_ops; - - Timer m_timer; - double m_nextTransceiveTime; - - void ComputeNextTransceiveTime(); - double GetCurTimeAndCleanUp(); -}; - -//! a Source class that can pump from a device for a specified amount of time. -class CRYPTOPP_NO_VTABLE NonblockingSource : public AutoSignaling, public LimitedBandwidth -{ -public: - NonblockingSource(BufferedTransformation *attachment) - : m_messageEndSent(false) , m_doPumpBlocked(false), m_blockedBySpeedLimit(false) {Detach(attachment);} - - //! \name NONBLOCKING SOURCE - //@{ - - //! pump up to maxSize bytes using at most maxTime milliseconds - /*! If checkDelimiter is true, pump up to delimiter, which itself is not extracted or pumped. */ - size_t GeneralPump2(lword &byteCount, bool blockingOutput=true, unsigned long maxTime=INFINITE_TIME, bool checkDelimiter=false, byte delimiter='\n'); - - lword GeneralPump(lword maxSize=LWORD_MAX, unsigned long maxTime=INFINITE_TIME, bool checkDelimiter=false, byte delimiter='\n') - { - GeneralPump2(maxSize, true, maxTime, checkDelimiter, delimiter); - return maxSize; - } - lword TimedPump(unsigned long maxTime) - {return GeneralPump(LWORD_MAX, maxTime);} - lword PumpLine(byte delimiter='\n', lword maxSize=1024) - {return GeneralPump(maxSize, INFINITE_TIME, true, delimiter);} - - size_t Pump2(lword &byteCount, bool blocking=true) - {return GeneralPump2(byteCount, blocking, blocking ? INFINITE_TIME : 0);} - size_t PumpMessages2(unsigned int &messageCount, bool blocking=true); - //@} - -protected: - virtual size_t DoPump(lword &byteCount, bool blockingOutput, - unsigned long maxTime, bool checkDelimiter, byte delimiter) =0; - - bool BlockedBySpeedLimit() const { return m_blockedBySpeedLimit; } - -private: - bool m_messageEndSent, m_doPumpBlocked, m_blockedBySpeedLimit; -}; - -//! Network Receiver -class CRYPTOPP_NO_VTABLE NetworkReceiver : public Waitable -{ -public: - virtual bool MustWaitToReceive() {return false;} - virtual bool MustWaitForResult() {return false;} - //! receive data from network source, returns whether result is immediately available - virtual bool Receive(byte* buf, size_t bufLen) =0; - virtual unsigned int GetReceiveResult() =0; - virtual bool EofReceived() const =0; -}; - -class CRYPTOPP_NO_VTABLE NonblockingSinkInfo -{ -public: - virtual ~NonblockingSinkInfo() {} - virtual size_t GetMaxBufferSize() const =0; - virtual size_t GetCurrentBufferSize() const =0; - virtual bool EofPending() const =0; - //! compute the current speed of this sink in bytes per second - virtual float ComputeCurrentSpeed() =0; - //! get the maximum observed speed of this sink in bytes per second - virtual float GetMaxObservedSpeed() const =0; -}; - -//! a Sink class that queues input and can flush to a device for a specified amount of time. -class CRYPTOPP_NO_VTABLE NonblockingSink : public Sink, public NonblockingSinkInfo, public LimitedBandwidth -{ -public: - NonblockingSink() : m_blockedBySpeedLimit(false) {} - - bool IsolatedFlush(bool hardFlush, bool blocking); - - //! flush to device for no more than maxTime milliseconds - /*! This function will repeatedly attempt to flush data to some device, until - the queue is empty, or a total of maxTime milliseconds have elapsed. - If maxTime == 0, at least one attempt will be made to flush some data, but - it is likely that not all queued data will be flushed, even if the device - is ready to receive more data without waiting. If you want to flush as much data - as possible without waiting for the device, call this function in a loop. - For example: while (sink.TimedFlush(0) > 0) {} - \return number of bytes flushed - */ - lword TimedFlush(unsigned long maxTime, size_t targetSize = 0); - - virtual void SetMaxBufferSize(size_t maxBufferSize) =0; - //! set a bound which will cause sink to flush if exceeded by GetCurrentBufferSize() - virtual void SetAutoFlushBound(size_t bound) =0; - -protected: - virtual lword DoFlush(unsigned long maxTime, size_t targetSize) = 0; - - bool BlockedBySpeedLimit() const { return m_blockedBySpeedLimit; } - -private: - bool m_blockedBySpeedLimit; -}; - -//! Network Sender -class CRYPTOPP_NO_VTABLE NetworkSender : public Waitable -{ -public: - virtual bool MustWaitToSend() {return false;} - virtual bool MustWaitForResult() {return false;} - virtual void Send(const byte* buf, size_t bufLen) =0; - virtual unsigned int GetSendResult() =0; - virtual bool MustWaitForEof() {return false;} - virtual void SendEof() =0; - virtual bool EofSent() {return false;} // implement if MustWaitForEof() == true -}; - -//! Network Source -class CRYPTOPP_NO_VTABLE NetworkSource : public NonblockingSource -{ -public: - NetworkSource(BufferedTransformation *attachment); - - unsigned int GetMaxWaitObjectCount() const; - void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack); - - bool SourceExhausted() const {return m_dataBegin == m_dataEnd && GetReceiver().EofReceived();} - -protected: - size_t DoPump(lword &byteCount, bool blockingOutput, unsigned long maxTime, bool checkDelimiter, byte delimiter); - - virtual NetworkReceiver & AccessReceiver() =0; - const NetworkReceiver & GetReceiver() const {return const_cast(this)->AccessReceiver();} - -private: - SecByteBlock m_buf; - size_t m_putSize, m_dataBegin, m_dataEnd; - bool m_waitingForResult, m_outputBlocked; -}; - -//! Network Sink -class CRYPTOPP_NO_VTABLE NetworkSink : public NonblockingSink -{ -public: - NetworkSink(unsigned int maxBufferSize, unsigned int autoFlushBound); - - unsigned int GetMaxWaitObjectCount() const; - void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack); - - size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking); - - void SetMaxBufferSize(size_t maxBufferSize) {m_maxBufferSize = maxBufferSize; m_buffer.SetNodeSize(UnsignedMin(maxBufferSize, 16U*1024U+256U));} - void SetAutoFlushBound(size_t bound) {m_autoFlushBound = bound;} - - size_t GetMaxBufferSize() const {return m_maxBufferSize;} - size_t GetCurrentBufferSize() const {return (size_t)m_buffer.CurrentSize();} - - void ClearBuffer() { m_buffer.Clear(); } - - bool EofPending() const { return m_eofState > EOF_NONE && m_eofState < EOF_DONE; } - - //! compute the current speed of this sink in bytes per second - float ComputeCurrentSpeed(); - //! get the maximum observed speed of this sink in bytes per second - float GetMaxObservedSpeed() const; - -protected: - lword DoFlush(unsigned long maxTime, size_t targetSize); - - virtual NetworkSender & AccessSender() =0; - const NetworkSender & GetSender() const {return const_cast(this)->AccessSender();} - -private: - enum EofState { EOF_NONE, EOF_PENDING_SEND, EOF_PENDING_DELIVERY, EOF_DONE }; - - size_t m_maxBufferSize, m_autoFlushBound; - bool m_needSendResult, m_wasBlocked; - EofState m_eofState; - ByteQueue m_buffer; - size_t m_skipBytes; - Timer m_speedTimer; - float m_byteCountSinceLastTimerReset, m_currentSpeed, m_maxObservedSpeed; -}; - -NAMESPACE_END - -#endif // #ifdef HIGHRES_TIMER_AVAILABLE - -#endif diff --git a/lib/cryptopp/nr.h b/lib/cryptopp/nr.h deleted file mode 100644 index c398e3550..000000000 --- a/lib/cryptopp/nr.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef CRYPTOPP_NR_H -#define CRYPTOPP_NR_H - -#include "gfpcrypt.h" - -#endif diff --git a/lib/cryptopp/oaep.cpp b/lib/cryptopp/oaep.cpp deleted file mode 100644 index 1d474be52..000000000 --- a/lib/cryptopp/oaep.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// oaep.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "oaep.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -// ******************************************************** - -size_t OAEP_Base::MaxUnpaddedLength(size_t paddedLength) const -{ - return SaturatingSubtract(paddedLength/8, 1+2*DigestSize()); -} - -void OAEP_Base::Pad(RandomNumberGenerator &rng, const byte *input, size_t inputLength, byte *oaepBlock, size_t oaepBlockLen, const NameValuePairs ¶meters) const -{ - assert (inputLength <= MaxUnpaddedLength(oaepBlockLen)); - - // convert from bit length to byte length - if (oaepBlockLen % 8 != 0) - { - oaepBlock[0] = 0; - oaepBlock++; - } - oaepBlockLen /= 8; - - std::auto_ptr pHash(NewHash()); - const size_t hLen = pHash->DigestSize(); - const size_t seedLen = hLen, dbLen = oaepBlockLen-seedLen; - byte *const maskedSeed = oaepBlock; - byte *const maskedDB = oaepBlock+seedLen; - - ConstByteArrayParameter encodingParameters; - parameters.GetValue(Name::EncodingParameters(), encodingParameters); - - // DB = pHash || 00 ... || 01 || M - pHash->CalculateDigest(maskedDB, encodingParameters.begin(), encodingParameters.size()); - memset(maskedDB+hLen, 0, dbLen-hLen-inputLength-1); - maskedDB[dbLen-inputLength-1] = 0x01; - memcpy(maskedDB+dbLen-inputLength, input, inputLength); - - rng.GenerateBlock(maskedSeed, seedLen); - std::auto_ptr pMGF(NewMGF()); - pMGF->GenerateAndMask(*pHash, maskedDB, dbLen, maskedSeed, seedLen); - pMGF->GenerateAndMask(*pHash, maskedSeed, seedLen, maskedDB, dbLen); -} - -DecodingResult OAEP_Base::Unpad(const byte *oaepBlock, size_t oaepBlockLen, byte *output, const NameValuePairs ¶meters) const -{ - bool invalid = false; - - // convert from bit length to byte length - if (oaepBlockLen % 8 != 0) - { - invalid = (oaepBlock[0] != 0) || invalid; - oaepBlock++; - } - oaepBlockLen /= 8; - - std::auto_ptr pHash(NewHash()); - const size_t hLen = pHash->DigestSize(); - const size_t seedLen = hLen, dbLen = oaepBlockLen-seedLen; - - invalid = (oaepBlockLen < 2*hLen+1) || invalid; - - SecByteBlock t(oaepBlock, oaepBlockLen); - byte *const maskedSeed = t; - byte *const maskedDB = t+seedLen; - - std::auto_ptr pMGF(NewMGF()); - pMGF->GenerateAndMask(*pHash, maskedSeed, seedLen, maskedDB, dbLen); - pMGF->GenerateAndMask(*pHash, maskedDB, dbLen, maskedSeed, seedLen); - - ConstByteArrayParameter encodingParameters; - parameters.GetValue(Name::EncodingParameters(), encodingParameters); - - // DB = pHash' || 00 ... || 01 || M - byte *M = std::find(maskedDB+hLen, maskedDB+dbLen, 0x01); - invalid = (M == maskedDB+dbLen) || invalid; - invalid = (std::find_if(maskedDB+hLen, M, std::bind2nd(std::not_equal_to(), 0)) != M) || invalid; - invalid = !pHash->VerifyDigest(maskedDB, encodingParameters.begin(), encodingParameters.size()) || invalid; - - if (invalid) - return DecodingResult(); - - M++; - memcpy(output, M, maskedDB+dbLen-M); - return DecodingResult(maskedDB+dbLen-M); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/oaep.h b/lib/cryptopp/oaep.h deleted file mode 100644 index 4bf6b0d83..000000000 --- a/lib/cryptopp/oaep.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef CRYPTOPP_OAEP_H -#define CRYPTOPP_OAEP_H - -#include "pubkey.h" -#include "sha.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -class CRYPTOPP_DLL OAEP_Base : public PK_EncryptionMessageEncodingMethod -{ -public: - bool ParameterSupported(const char *name) const {return strcmp(name, Name::EncodingParameters()) == 0;} - size_t MaxUnpaddedLength(size_t paddedLength) const; - void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs ¶meters) const; - DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs ¶meters) const; - -protected: - virtual unsigned int DigestSize() const =0; - virtual HashTransformation * NewHash() const =0; - virtual MaskGeneratingFunction * NewMGF() const =0; -}; - -//! EME-OAEP, for use with classes derived from TF_ES -template -class OAEP : public OAEP_Base, public EncryptionStandard -{ -public: - static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string("OAEP-") + MGF::StaticAlgorithmName() + "(" + H::StaticAlgorithmName() + ")";} - typedef OAEP EncryptionMessageEncodingMethod; - -protected: - unsigned int DigestSize() const {return H::DIGESTSIZE;} - HashTransformation * NewHash() const {return new H;} - MaskGeneratingFunction * NewMGF() const {return new MGF;} -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS OAEP; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/oids.h b/lib/cryptopp/oids.h deleted file mode 100644 index 8b1030150..000000000 --- a/lib/cryptopp/oids.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef CRYPTOPP_OIDS_H -#define CRYPTOPP_OIDS_H - -// crypto-related ASN.1 object identifiers - -#include "asn.h" - -NAMESPACE_BEGIN(CryptoPP) - -NAMESPACE_BEGIN(ASN1) - -#define DEFINE_OID(value, name) inline OID name() {return value;} - -DEFINE_OID(1, iso) - DEFINE_OID(iso()+2, member_body) - DEFINE_OID(member_body()+840, iso_us) - DEFINE_OID(iso_us()+10040, ansi_x9_57) - DEFINE_OID(ansi_x9_57()+4+1, id_dsa) - DEFINE_OID(iso_us()+10045, ansi_x9_62) - DEFINE_OID(ansi_x9_62()+1, id_fieldType) - DEFINE_OID(id_fieldType()+1, prime_field) - DEFINE_OID(id_fieldType()+2, characteristic_two_field) - DEFINE_OID(characteristic_two_field()+3, id_characteristic_two_basis) - DEFINE_OID(id_characteristic_two_basis()+1, gnBasis) - DEFINE_OID(id_characteristic_two_basis()+2, tpBasis) - DEFINE_OID(id_characteristic_two_basis()+3, ppBasis) - DEFINE_OID(ansi_x9_62()+2, id_publicKeyType) - DEFINE_OID(id_publicKeyType()+1, id_ecPublicKey) - DEFINE_OID(ansi_x9_62()+3, ansi_x9_62_curves) - DEFINE_OID(ansi_x9_62_curves()+1, ansi_x9_62_curves_prime) - DEFINE_OID(ansi_x9_62_curves_prime()+1, secp192r1) - DEFINE_OID(ansi_x9_62_curves_prime()+7, secp256r1) - DEFINE_OID(iso_us()+113549, rsadsi) - DEFINE_OID(rsadsi()+1, pkcs) - DEFINE_OID(pkcs()+1, pkcs_1) - DEFINE_OID(pkcs_1()+1, rsaEncryption); - DEFINE_OID(rsadsi()+2, rsadsi_digestAlgorithm) - DEFINE_OID(rsadsi_digestAlgorithm()+2, id_md2) - DEFINE_OID(rsadsi_digestAlgorithm()+5, id_md5) - DEFINE_OID(iso()+3, identified_organization); - DEFINE_OID(identified_organization()+14, oiw); - DEFINE_OID(oiw()+3, oiw_secsig); - DEFINE_OID(oiw_secsig()+2, oiw_secsig_algorithms); - DEFINE_OID(oiw_secsig_algorithms()+26, id_sha1); - - DEFINE_OID(identified_organization()+36, teletrust); - DEFINE_OID(teletrust()+3, teletrust_algorithm) - DEFINE_OID(teletrust_algorithm()+2+1, id_ripemd160) - DEFINE_OID(teletrust_algorithm()+3+2+8+1, teletrust_ellipticCurve) - DEFINE_OID(teletrust_ellipticCurve()+1+1, brainpoolP160r1) - DEFINE_OID(teletrust_ellipticCurve()+1+3, brainpoolP192r1) - DEFINE_OID(teletrust_ellipticCurve()+1+5, brainpoolP224r1) - DEFINE_OID(teletrust_ellipticCurve()+1+7, brainpoolP256r1) - DEFINE_OID(teletrust_ellipticCurve()+1+9, brainpoolP320r1) - DEFINE_OID(teletrust_ellipticCurve()+1+11, brainpoolP384r1) - DEFINE_OID(teletrust_ellipticCurve()+1+13, brainpoolP512r1) - - DEFINE_OID(identified_organization()+132, certicom); - DEFINE_OID(certicom()+0, certicom_ellipticCurve); - // these are sorted by curve type and then by OID - // first curves based on GF(p) - DEFINE_OID(certicom_ellipticCurve()+6, secp112r1); - DEFINE_OID(certicom_ellipticCurve()+7, secp112r2); - DEFINE_OID(certicom_ellipticCurve()+8, secp160r1); - DEFINE_OID(certicom_ellipticCurve()+9, secp160k1); - DEFINE_OID(certicom_ellipticCurve()+10, secp256k1); - DEFINE_OID(certicom_ellipticCurve()+28, secp128r1); - DEFINE_OID(certicom_ellipticCurve()+29, secp128r2); - DEFINE_OID(certicom_ellipticCurve()+30, secp160r2); - DEFINE_OID(certicom_ellipticCurve()+31, secp192k1); - DEFINE_OID(certicom_ellipticCurve()+32, secp224k1); - DEFINE_OID(certicom_ellipticCurve()+33, secp224r1); - DEFINE_OID(certicom_ellipticCurve()+34, secp384r1); - DEFINE_OID(certicom_ellipticCurve()+35, secp521r1); - // then curves based on GF(2^n) - DEFINE_OID(certicom_ellipticCurve()+1, sect163k1); - DEFINE_OID(certicom_ellipticCurve()+2, sect163r1); - DEFINE_OID(certicom_ellipticCurve()+3, sect239k1); - DEFINE_OID(certicom_ellipticCurve()+4, sect113r1); - DEFINE_OID(certicom_ellipticCurve()+5, sect113r2); - DEFINE_OID(certicom_ellipticCurve()+15, sect163r2); - DEFINE_OID(certicom_ellipticCurve()+16, sect283k1); - DEFINE_OID(certicom_ellipticCurve()+17, sect283r1); - DEFINE_OID(certicom_ellipticCurve()+22, sect131r1); - DEFINE_OID(certicom_ellipticCurve()+23, sect131r2); - DEFINE_OID(certicom_ellipticCurve()+24, sect193r1); - DEFINE_OID(certicom_ellipticCurve()+25, sect193r2); - DEFINE_OID(certicom_ellipticCurve()+26, sect233k1); - DEFINE_OID(certicom_ellipticCurve()+27, sect233r1); - DEFINE_OID(certicom_ellipticCurve()+36, sect409k1); - DEFINE_OID(certicom_ellipticCurve()+37, sect409r1); - DEFINE_OID(certicom_ellipticCurve()+38, sect571k1); - DEFINE_OID(certicom_ellipticCurve()+39, sect571r1); -DEFINE_OID(2, joint_iso_ccitt) - DEFINE_OID(joint_iso_ccitt()+16, country) - DEFINE_OID(country()+840, joint_iso_ccitt_us) - DEFINE_OID(joint_iso_ccitt_us()+1, us_organization) - DEFINE_OID(us_organization()+101, us_gov) - DEFINE_OID(us_gov()+3, csor) - DEFINE_OID(csor()+4, nistalgorithms) - DEFINE_OID(nistalgorithms()+1, aes) - DEFINE_OID(aes()+1, id_aes128_ECB) - DEFINE_OID(aes()+2, id_aes128_cbc) - DEFINE_OID(aes()+3, id_aes128_ofb) - DEFINE_OID(aes()+4, id_aes128_cfb) - DEFINE_OID(aes()+21, id_aes192_ECB) - DEFINE_OID(aes()+22, id_aes192_cbc) - DEFINE_OID(aes()+23, id_aes192_ofb) - DEFINE_OID(aes()+24, id_aes192_cfb) - DEFINE_OID(aes()+41, id_aes256_ECB) - DEFINE_OID(aes()+42, id_aes256_cbc) - DEFINE_OID(aes()+43, id_aes256_ofb) - DEFINE_OID(aes()+44, id_aes256_cfb) - DEFINE_OID(nistalgorithms()+2, nist_hashalgs) - DEFINE_OID(nist_hashalgs()+1, id_sha256) - DEFINE_OID(nist_hashalgs()+2, id_sha384) - DEFINE_OID(nist_hashalgs()+3, id_sha512) - -NAMESPACE_END - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/osrng.cpp b/lib/cryptopp/osrng.cpp deleted file mode 100644 index 76e486b4e..000000000 --- a/lib/cryptopp/osrng.cpp +++ /dev/null @@ -1,192 +0,0 @@ -// osrng.cpp - written and placed in the public domain by Wei Dai - -// Thanks to Leonard Janke for the suggestion for AutoSeededRandomPool. - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "osrng.h" - -#ifdef OS_RNG_AVAILABLE - -#include "rng.h" - -#ifdef CRYPTOPP_WIN32_AVAILABLE -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0400 -#endif -#include -#include -#endif - -#ifdef CRYPTOPP_UNIX_AVAILABLE -#include -#include -#include -#endif - -NAMESPACE_BEGIN(CryptoPP) - -#if defined(NONBLOCKING_RNG_AVAILABLE) || defined(BLOCKING_RNG_AVAILABLE) -OS_RNG_Err::OS_RNG_Err(const std::string &operation) - : Exception(OTHER_ERROR, "OS_Rng: " + operation + " operation failed with error " + -#ifdef CRYPTOPP_WIN32_AVAILABLE - "0x" + IntToString(GetLastError(), 16) -#else - IntToString(errno) -#endif - ) -{ -} -#endif - -#ifdef NONBLOCKING_RNG_AVAILABLE - -#ifdef CRYPTOPP_WIN32_AVAILABLE - -MicrosoftCryptoProvider::MicrosoftCryptoProvider() -{ - if(!CryptAcquireContext(&m_hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) - throw OS_RNG_Err("CryptAcquireContext"); -} - -MicrosoftCryptoProvider::~MicrosoftCryptoProvider() -{ - CryptReleaseContext(m_hProvider, 0); -} - -#endif - -NonblockingRng::NonblockingRng() -{ -#ifndef CRYPTOPP_WIN32_AVAILABLE - m_fd = open("/dev/urandom",O_RDONLY); - if (m_fd == -1) - throw OS_RNG_Err("open /dev/urandom"); -#endif -} - -NonblockingRng::~NonblockingRng() -{ -#ifndef CRYPTOPP_WIN32_AVAILABLE - close(m_fd); -#endif -} - -void NonblockingRng::GenerateBlock(byte *output, size_t size) -{ -#ifdef CRYPTOPP_WIN32_AVAILABLE -# ifdef WORKAROUND_MS_BUG_Q258000 - const MicrosoftCryptoProvider &m_Provider = Singleton().Ref(); -# endif - if (!CryptGenRandom(m_Provider.GetProviderHandle(), (DWORD)size, output)) - throw OS_RNG_Err("CryptGenRandom"); -#else - while (size) - { - ssize_t len = read(m_fd, output, size); - - if (len < 0) - { - // /dev/urandom reads CAN give EAGAIN errors! (maybe EINTR as well) - if (errno != EINTR && errno != EAGAIN) - throw OS_RNG_Err("read /dev/urandom"); - - continue; - } - - output += len; - size -= len; - } -#endif -} - -#endif - -// ************************************************************* - -#ifdef BLOCKING_RNG_AVAILABLE - -#ifndef CRYPTOPP_BLOCKING_RNG_FILENAME -#ifdef __OpenBSD__ -#define CRYPTOPP_BLOCKING_RNG_FILENAME "/dev/srandom" -#else -#define CRYPTOPP_BLOCKING_RNG_FILENAME "/dev/random" -#endif -#endif - -BlockingRng::BlockingRng() -{ - m_fd = open(CRYPTOPP_BLOCKING_RNG_FILENAME,O_RDONLY); - if (m_fd == -1) - throw OS_RNG_Err("open " CRYPTOPP_BLOCKING_RNG_FILENAME); -} - -BlockingRng::~BlockingRng() -{ - close(m_fd); -} - -void BlockingRng::GenerateBlock(byte *output, size_t size) -{ - while (size) - { - // on some systems /dev/random will block until all bytes - // are available, on others it returns immediately - ssize_t len = read(m_fd, output, size); - if (len < 0) - { - // /dev/random reads CAN give EAGAIN errors! (maybe EINTR as well) - if (errno != EINTR && errno != EAGAIN) - throw OS_RNG_Err("read " CRYPTOPP_BLOCKING_RNG_FILENAME); - - continue; - } - - size -= len; - output += len; - if (size) - sleep(1); - } -} - -#endif - -// ************************************************************* - -void OS_GenerateRandomBlock(bool blocking, byte *output, size_t size) -{ -#ifdef NONBLOCKING_RNG_AVAILABLE - if (blocking) -#endif - { -#ifdef BLOCKING_RNG_AVAILABLE - BlockingRng rng; - rng.GenerateBlock(output, size); -#endif - } - -#ifdef BLOCKING_RNG_AVAILABLE - if (!blocking) -#endif - { -#ifdef NONBLOCKING_RNG_AVAILABLE - NonblockingRng rng; - rng.GenerateBlock(output, size); -#endif - } -} - -void AutoSeededRandomPool::Reseed(bool blocking, unsigned int seedSize) -{ - SecByteBlock seed(seedSize); - OS_GenerateRandomBlock(blocking, seed, seedSize); - IncorporateEntropy(seed, seedSize); -} - -NAMESPACE_END - -#endif - -#endif diff --git a/lib/cryptopp/osrng.h b/lib/cryptopp/osrng.h deleted file mode 100644 index ae07d057b..000000000 --- a/lib/cryptopp/osrng.h +++ /dev/null @@ -1,156 +0,0 @@ -#ifndef CRYPTOPP_OSRNG_H -#define CRYPTOPP_OSRNG_H - -//! \file - -#include "config.h" - -#ifdef OS_RNG_AVAILABLE - -#include "randpool.h" -#include "rng.h" -#include "aes.h" -#include "sha.h" -#include "fips140.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! Exception class for Operating-System Random Number Generator. -class CRYPTOPP_DLL OS_RNG_Err : public Exception -{ -public: - OS_RNG_Err(const std::string &operation); -}; - -#ifdef NONBLOCKING_RNG_AVAILABLE - -#ifdef CRYPTOPP_WIN32_AVAILABLE -class CRYPTOPP_DLL MicrosoftCryptoProvider -{ -public: - MicrosoftCryptoProvider(); - ~MicrosoftCryptoProvider(); -#if defined(_WIN64) - typedef unsigned __int64 ProviderHandle; // type HCRYPTPROV, avoid #include -#else - typedef unsigned long ProviderHandle; -#endif - ProviderHandle GetProviderHandle() const {return m_hProvider;} -private: - ProviderHandle m_hProvider; -}; - -#pragma comment(lib, "advapi32.lib") -#endif - -//! encapsulate CryptoAPI's CryptGenRandom or /dev/urandom -class CRYPTOPP_DLL NonblockingRng : public RandomNumberGenerator -{ -public: - NonblockingRng(); - ~NonblockingRng(); - void GenerateBlock(byte *output, size_t size); - -protected: -#ifdef CRYPTOPP_WIN32_AVAILABLE -# ifndef WORKAROUND_MS_BUG_Q258000 - MicrosoftCryptoProvider m_Provider; -# endif -#else - int m_fd; -#endif -}; - -#endif - -#ifdef BLOCKING_RNG_AVAILABLE - -//! encapsulate /dev/random, or /dev/srandom on OpenBSD -class CRYPTOPP_DLL BlockingRng : public RandomNumberGenerator -{ -public: - BlockingRng(); - ~BlockingRng(); - void GenerateBlock(byte *output, size_t size); - -protected: - int m_fd; -}; - -#endif - -CRYPTOPP_DLL void CRYPTOPP_API OS_GenerateRandomBlock(bool blocking, byte *output, size_t size); - -//! Automaticly Seeded Randomness Pool -/*! This class seeds itself using an operating system provided RNG. */ -class CRYPTOPP_DLL AutoSeededRandomPool : public RandomPool -{ -public: - //! use blocking to choose seeding with BlockingRng or NonblockingRng. the parameter is ignored if only one of these is available - explicit AutoSeededRandomPool(bool blocking = false, unsigned int seedSize = 32) - {Reseed(blocking, seedSize);} - void Reseed(bool blocking = false, unsigned int seedSize = 32); -}; - -//! RNG from ANSI X9.17 Appendix C, seeded using an OS provided RNG -template -class AutoSeededX917RNG : public RandomNumberGenerator, public NotCopyable -{ -public: - //! use blocking to choose seeding with BlockingRng or NonblockingRng. the parameter is ignored if only one of these is available - explicit AutoSeededX917RNG(bool blocking = false, bool autoSeed = true) - {if (autoSeed) Reseed(blocking);} - void Reseed(bool blocking = false, const byte *additionalEntropy = NULL, size_t length = 0); - // exposed for testing - void Reseed(const byte *key, size_t keylength, const byte *seed, const byte *timeVector); - - bool CanIncorporateEntropy() const {return true;} - void IncorporateEntropy(const byte *input, size_t length) {Reseed(false, input, length);} - void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length) {m_rng->GenerateIntoBufferedTransformation(target, channel, length);} - -private: - member_ptr m_rng; -}; - -template -void AutoSeededX917RNG::Reseed(const byte *key, size_t keylength, const byte *seed, const byte *timeVector) -{ - m_rng.reset(new X917RNG(new typename BLOCK_CIPHER::Encryption(key, keylength), seed, timeVector)); -} - -template -void AutoSeededX917RNG::Reseed(bool blocking, const byte *input, size_t length) -{ - SecByteBlock seed(BLOCK_CIPHER::BLOCKSIZE + BLOCK_CIPHER::DEFAULT_KEYLENGTH); - const byte *key; - do - { - OS_GenerateRandomBlock(blocking, seed, seed.size()); - if (length > 0) - { - SHA256 hash; - hash.Update(seed, seed.size()); - hash.Update(input, length); - hash.TruncatedFinal(seed, UnsignedMin(hash.DigestSize(), seed.size())); - } - key = seed + BLOCK_CIPHER::BLOCKSIZE; - } // check that seed and key don't have same value - while (memcmp(key, seed, STDMIN((unsigned int)BLOCK_CIPHER::BLOCKSIZE, (unsigned int)BLOCK_CIPHER::DEFAULT_KEYLENGTH)) == 0); - - Reseed(key, BLOCK_CIPHER::DEFAULT_KEYLENGTH, seed, NULL); -} - -CRYPTOPP_DLL_TEMPLATE_CLASS AutoSeededX917RNG; - -//! this is AutoSeededX917RNG\ in FIPS mode, otherwise it's AutoSeededRandomPool -#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 -typedef AutoSeededX917RNG DefaultAutoSeededRNG; -#else -typedef AutoSeededRandomPool DefaultAutoSeededRNG; -#endif - -NAMESPACE_END - -#endif - -#endif diff --git a/lib/cryptopp/pch.cpp b/lib/cryptopp/pch.cpp deleted file mode 100644 index 1d9f38c57..000000000 --- a/lib/cryptopp/pch.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "pch.h" diff --git a/lib/cryptopp/pch.h b/lib/cryptopp/pch.h deleted file mode 100644 index 418c39076..000000000 --- a/lib/cryptopp/pch.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef CRYPTOPP_PCH_H -#define CRYPTOPP_PCH_H - -#ifdef CRYPTOPP_GENERATE_X64_MASM - - #include "cpu.h" - -#else - - #include "config.h" - - #ifdef USE_PRECOMPILED_HEADERS - #include "simple.h" - #include "secblock.h" - #include "misc.h" - #include "smartptr.h" - #endif - -#endif - -#endif diff --git a/lib/cryptopp/pkcspad.cpp b/lib/cryptopp/pkcspad.cpp deleted file mode 100644 index e1f1d1e23..000000000 --- a/lib/cryptopp/pkcspad.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// pkcspad.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_PKCSPAD_CPP // SunCC workaround: compiler could cause this file to be included twice -#define CRYPTOPP_PKCSPAD_CPP - -#include "pkcspad.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -// more in dll.cpp -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x02,0x05,0x00,0x04,0x10}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x04,0x10}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2b,0x24,0x03,0x02,0x01,0x05,0x00,0x04,0x14}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x29,0x30,0x0D,0x06,0x09,0x2B,0x06,0x01,0x04,0x01,0xDA,0x47,0x0C,0x02,0x05,0x00,0x04,0x18}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -size_t PKCS_EncryptionPaddingScheme::MaxUnpaddedLength(size_t paddedLength) const -{ - return SaturatingSubtract(paddedLength/8, 10U); -} - -void PKCS_EncryptionPaddingScheme::Pad(RandomNumberGenerator &rng, const byte *input, size_t inputLen, byte *pkcsBlock, size_t pkcsBlockLen, const NameValuePairs ¶meters) const -{ - assert (inputLen <= MaxUnpaddedLength(pkcsBlockLen)); // this should be checked by caller - - // convert from bit length to byte length - if (pkcsBlockLen % 8 != 0) - { - pkcsBlock[0] = 0; - pkcsBlock++; - } - pkcsBlockLen /= 8; - - pkcsBlock[0] = 2; // block type 2 - - // pad with non-zero random bytes - for (unsigned i = 1; i < pkcsBlockLen-inputLen-1; i++) - pkcsBlock[i] = (byte)rng.GenerateWord32(1, 0xff); - - pkcsBlock[pkcsBlockLen-inputLen-1] = 0; // separator - memcpy(pkcsBlock+pkcsBlockLen-inputLen, input, inputLen); -} - -DecodingResult PKCS_EncryptionPaddingScheme::Unpad(const byte *pkcsBlock, size_t pkcsBlockLen, byte *output, const NameValuePairs ¶meters) const -{ - bool invalid = false; - size_t maxOutputLen = MaxUnpaddedLength(pkcsBlockLen); - - // convert from bit length to byte length - if (pkcsBlockLen % 8 != 0) - { - invalid = (pkcsBlock[0] != 0) || invalid; - pkcsBlock++; - } - pkcsBlockLen /= 8; - - // Require block type 2. - invalid = (pkcsBlock[0] != 2) || invalid; - - // skip past the padding until we find the separator - size_t i=1; - while (i maxOutputLen) || invalid; - - if (invalid) - return DecodingResult(); - - memcpy (output, pkcsBlock+i, outputLen); - return DecodingResult(outputLen); -} - -// ******************************************************** - -#ifndef CRYPTOPP_IMPORTS - -void PKCS1v15_SignatureMessageEncodingMethod::ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const -{ - assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize())); - - size_t pkcsBlockLen = representativeBitLength; - // convert from bit length to byte length - if (pkcsBlockLen % 8 != 0) - { - representative[0] = 0; - representative++; - } - pkcsBlockLen /= 8; - - representative[0] = 1; // block type 1 - - unsigned int digestSize = hash.DigestSize(); - byte *pPadding = representative + 1; - byte *pDigest = representative + pkcsBlockLen - digestSize; - byte *pHashId = pDigest - hashIdentifier.second; - byte *pSeparator = pHashId - 1; - - // pad with 0xff - memset(pPadding, 0xff, pSeparator-pPadding); - *pSeparator = 0; - memcpy(pHashId, hashIdentifier.first, hashIdentifier.second); - hash.Final(pDigest); -} - -#endif - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/pkcspad.h b/lib/cryptopp/pkcspad.h deleted file mode 100644 index 6371c7698..000000000 --- a/lib/cryptopp/pkcspad.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef CRYPTOPP_PKCSPAD_H -#define CRYPTOPP_PKCSPAD_H - -#include "cryptlib.h" -#include "pubkey.h" - -#ifdef CRYPTOPP_IS_DLL -#include "sha.h" -#endif - -NAMESPACE_BEGIN(CryptoPP) - -//! EME-PKCS1-v1_5 -class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod -{ -public: - static const char * StaticAlgorithmName() {return "EME-PKCS1-v1_5";} - - size_t MaxUnpaddedLength(size_t paddedLength) const; - void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs ¶meters) const; - DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs ¶meters) const; -}; - -template class PKCS_DigestDecoration -{ -public: - static const byte decoration[]; - static const unsigned int length; -}; - -// PKCS_DigestDecoration can be instantiated with the following -// classes as specified in PKCS#1 v2.0 and P1363a -class SHA1; -class RIPEMD160; -class Tiger; -class SHA224; -class SHA256; -class SHA384; -class SHA512; -namespace Weak1 { -class MD2; -class MD5; -} -// end of list - -#ifdef CRYPTOPP_IS_DLL -CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; -CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; -CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; -CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; -CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; -#endif - -//! EMSA-PKCS1-v1_5 -class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod -{ -public: - static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";} - - size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const - {return 8 * (digestSize + hashIdentifierSize + 10);} - - void ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const; - - struct HashIdentifierLookup - { - template struct HashIdentifierLookup2 - { - static HashIdentifier Lookup() - { - return HashIdentifier(PKCS_DigestDecoration::decoration, PKCS_DigestDecoration::length); - } - }; - }; -}; - -//! PKCS #1 version 1.5, for use with RSAES and RSASS -/*! Only the following hash functions are supported by this signature standard: - \dontinclude pkcspad.h - \skip can be instantiated - \until end of list -*/ -struct PKCS1v15 : public SignatureStandard, public EncryptionStandard -{ - typedef PKCS_EncryptionPaddingScheme EncryptionMessageEncodingMethod; - typedef PKCS1v15_SignatureMessageEncodingMethod SignatureMessageEncodingMethod; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/polynomi.cpp b/lib/cryptopp/polynomi.cpp deleted file mode 100644 index 734cae926..000000000 --- a/lib/cryptopp/polynomi.cpp +++ /dev/null @@ -1,577 +0,0 @@ -// polynomi.cpp - written and placed in the public domain by Wei Dai - -// Part of the code for polynomial evaluation and interpolation -// originally came from Hal Finney's public domain secsplit.c. - -#include "pch.h" -#include "polynomi.h" -#include "secblock.h" - -#include -#include - -NAMESPACE_BEGIN(CryptoPP) - -template -void PolynomialOver::Randomize(RandomNumberGenerator &rng, const RandomizationParameter ¶meter, const Ring &ring) -{ - m_coefficients.resize(parameter.m_coefficientCount); - for (unsigned int i=0; i -void PolynomialOver::FromStr(const char *str, const Ring &ring) -{ - std::istringstream in((char *)str); - bool positive = true; - CoefficientType coef; - unsigned int power; - - while (in) - { - std::ws(in); - if (in.peek() == 'x') - coef = ring.MultiplicativeIdentity(); - else - in >> coef; - - std::ws(in); - if (in.peek() == 'x') - { - in.get(); - std::ws(in); - if (in.peek() == '^') - { - in.get(); - in >> power; - } - else - power = 1; - } - else - power = 0; - - if (!positive) - coef = ring.Inverse(coef); - - SetCoefficient(power, coef, ring); - - std::ws(in); - switch (in.get()) - { - case '+': - positive = true; - break; - case '-': - positive = false; - break; - default: - return; // something's wrong with the input string - } - } -} - -template -unsigned int PolynomialOver::CoefficientCount(const Ring &ring) const -{ - unsigned count = m_coefficients.size(); - while (count && ring.Equal(m_coefficients[count-1], ring.Identity())) - count--; - const_cast &>(m_coefficients).resize(count); - return count; -} - -template -typename PolynomialOver::CoefficientType PolynomialOver::GetCoefficient(unsigned int i, const Ring &ring) const -{ - return (i < m_coefficients.size()) ? m_coefficients[i] : ring.Identity(); -} - -template -PolynomialOver& PolynomialOver::operator=(const PolynomialOver& t) -{ - if (this != &t) - { - m_coefficients.resize(t.m_coefficients.size()); - for (unsigned int i=0; i -PolynomialOver& PolynomialOver::Accumulate(const PolynomialOver& t, const Ring &ring) -{ - unsigned int count = t.CoefficientCount(ring); - - if (count > CoefficientCount(ring)) - m_coefficients.resize(count, ring.Identity()); - - for (unsigned int i=0; i -PolynomialOver& PolynomialOver::Reduce(const PolynomialOver& t, const Ring &ring) -{ - unsigned int count = t.CoefficientCount(ring); - - if (count > CoefficientCount(ring)) - m_coefficients.resize(count, ring.Identity()); - - for (unsigned int i=0; i -typename PolynomialOver::CoefficientType PolynomialOver::EvaluateAt(const CoefficientType &x, const Ring &ring) const -{ - int degree = Degree(ring); - - if (degree < 0) - return ring.Identity(); - - CoefficientType result = m_coefficients[degree]; - for (int j=degree-1; j>=0; j--) - { - result = ring.Multiply(result, x); - ring.Accumulate(result, m_coefficients[j]); - } - return result; -} - -template -PolynomialOver& PolynomialOver::ShiftLeft(unsigned int n, const Ring &ring) -{ - unsigned int i = CoefficientCount(ring) + n; - m_coefficients.resize(i, ring.Identity()); - while (i > n) - { - i--; - m_coefficients[i] = m_coefficients[i-n]; - } - while (i) - { - i--; - m_coefficients[i] = ring.Identity(); - } - return *this; -} - -template -PolynomialOver& PolynomialOver::ShiftRight(unsigned int n, const Ring &ring) -{ - unsigned int count = CoefficientCount(ring); - if (count > n) - { - for (unsigned int i=0; i -void PolynomialOver::SetCoefficient(unsigned int i, const CoefficientType &value, const Ring &ring) -{ - if (i >= m_coefficients.size()) - m_coefficients.resize(i+1, ring.Identity()); - m_coefficients[i] = value; -} - -template -void PolynomialOver::Negate(const Ring &ring) -{ - unsigned int count = CoefficientCount(ring); - for (unsigned int i=0; i -void PolynomialOver::swap(PolynomialOver &t) -{ - m_coefficients.swap(t.m_coefficients); -} - -template -bool PolynomialOver::Equals(const PolynomialOver& t, const Ring &ring) const -{ - unsigned int count = CoefficientCount(ring); - - if (count != t.CoefficientCount(ring)) - return false; - - for (unsigned int i=0; i -PolynomialOver PolynomialOver::Plus(const PolynomialOver& t, const Ring &ring) const -{ - unsigned int i; - unsigned int count = CoefficientCount(ring); - unsigned int tCount = t.CoefficientCount(ring); - - if (count > tCount) - { - PolynomialOver result(ring, count); - - for (i=0; i result(ring, tCount); - - for (i=0; i -PolynomialOver PolynomialOver::Minus(const PolynomialOver& t, const Ring &ring) const -{ - unsigned int i; - unsigned int count = CoefficientCount(ring); - unsigned int tCount = t.CoefficientCount(ring); - - if (count > tCount) - { - PolynomialOver result(ring, count); - - for (i=0; i result(ring, tCount); - - for (i=0; i -PolynomialOver PolynomialOver::Inverse(const Ring &ring) const -{ - unsigned int count = CoefficientCount(ring); - PolynomialOver result(ring, count); - - for (unsigned int i=0; i -PolynomialOver PolynomialOver::Times(const PolynomialOver& t, const Ring &ring) const -{ - if (IsZero(ring) || t.IsZero(ring)) - return PolynomialOver(); - - unsigned int count1 = CoefficientCount(ring), count2 = t.CoefficientCount(ring); - PolynomialOver result(ring, count1 + count2 - 1); - - for (unsigned int i=0; i -PolynomialOver PolynomialOver::DividedBy(const PolynomialOver& t, const Ring &ring) const -{ - PolynomialOver remainder, quotient; - Divide(remainder, quotient, *this, t, ring); - return quotient; -} - -template -PolynomialOver PolynomialOver::Modulo(const PolynomialOver& t, const Ring &ring) const -{ - PolynomialOver remainder, quotient; - Divide(remainder, quotient, *this, t, ring); - return remainder; -} - -template -PolynomialOver PolynomialOver::MultiplicativeInverse(const Ring &ring) const -{ - return Degree(ring)==0 ? ring.MultiplicativeInverse(m_coefficients[0]) : ring.Identity(); -} - -template -bool PolynomialOver::IsUnit(const Ring &ring) const -{ - return Degree(ring)==0 && ring.IsUnit(m_coefficients[0]); -} - -template -std::istream& PolynomialOver::Input(std::istream &in, const Ring &ring) -{ - char c; - unsigned int length = 0; - SecBlock str(length + 16); - bool paren = false; - - std::ws(in); - - if (in.peek() == '(') - { - paren = true; - in.get(); - } - - do - { - in.read(&c, 1); - str[length++] = c; - if (length >= str.size()) - str.Grow(length + 16); - } - // if we started with a left paren, then read until we find a right paren, - // otherwise read until the end of the line - while (in && ((paren && c != ')') || (!paren && c != '\n'))); - - str[length-1] = '\0'; - *this = PolynomialOver(str, ring); - - return in; -} - -template -std::ostream& PolynomialOver::Output(std::ostream &out, const Ring &ring) const -{ - unsigned int i = CoefficientCount(ring); - if (i) - { - bool firstTerm = true; - - while (i--) - { - if (m_coefficients[i] != ring.Identity()) - { - if (firstTerm) - { - firstTerm = false; - if (!i || !ring.Equal(m_coefficients[i], ring.MultiplicativeIdentity())) - out << m_coefficients[i]; - } - else - { - CoefficientType inverse = ring.Inverse(m_coefficients[i]); - std::ostringstream pstr, nstr; - - pstr << m_coefficients[i]; - nstr << inverse; - - if (pstr.str().size() <= nstr.str().size()) - { - out << " + "; - if (!i || !ring.Equal(m_coefficients[i], ring.MultiplicativeIdentity())) - out << m_coefficients[i]; - } - else - { - out << " - "; - if (!i || !ring.Equal(inverse, ring.MultiplicativeIdentity())) - out << inverse; - } - } - - switch (i) - { - case 0: - break; - case 1: - out << "x"; - break; - default: - out << "x^" << i; - } - } - } - } - else - { - out << ring.Identity(); - } - return out; -} - -template -void PolynomialOver::Divide(PolynomialOver &r, PolynomialOver &q, const PolynomialOver &a, const PolynomialOver &d, const Ring &ring) -{ - unsigned int i = a.CoefficientCount(ring); - const int dDegree = d.Degree(ring); - - if (dDegree < 0) - throw DivideByZero(); - - r = a; - q.m_coefficients.resize(STDMAX(0, int(i - dDegree))); - - while (i > (unsigned int)dDegree) - { - --i; - q.m_coefficients[i-dDegree] = ring.Divide(r.m_coefficients[i], d.m_coefficients[dDegree]); - for (int j=0; j<=dDegree; j++) - ring.Reduce(r.m_coefficients[i-dDegree+j], ring.Multiply(q.m_coefficients[i-dDegree], d.m_coefficients[j])); - } - - r.CoefficientCount(ring); // resize r.m_coefficients -} - -// ******************************************************** - -// helper function for Interpolate() and InterpolateAt() -template -void RingOfPolynomialsOver::CalculateAlpha(std::vector &alpha, const CoefficientType x[], const CoefficientType y[], unsigned int n) const -{ - for (unsigned int j=0; j=k; --j) - { - m_ring.Reduce(alpha[j], alpha[j-1]); - - CoefficientType d = m_ring.Subtract(x[j], x[j-k]); - if (!m_ring.IsUnit(d)) - throw InterpolationFailed(); - alpha[j] = m_ring.Divide(alpha[j], d); - } - } -} - -template -typename RingOfPolynomialsOver::Element RingOfPolynomialsOver::Interpolate(const CoefficientType x[], const CoefficientType y[], unsigned int n) const -{ - assert(n > 0); - - std::vector alpha(n); - CalculateAlpha(alpha, x, y, n); - - std::vector coefficients((size_t)n, m_ring.Identity()); - coefficients[0] = alpha[n-1]; - - for (int j=n-2; j>=0; --j) - { - for (unsigned int i=n-j-1; i>0; i--) - coefficients[i] = m_ring.Subtract(coefficients[i-1], m_ring.Multiply(coefficients[i], x[j])); - - coefficients[0] = m_ring.Subtract(alpha[j], m_ring.Multiply(coefficients[0], x[j])); - } - - return PolynomialOver(coefficients.begin(), coefficients.end()); -} - -template -typename RingOfPolynomialsOver::CoefficientType RingOfPolynomialsOver::InterpolateAt(const CoefficientType &position, const CoefficientType x[], const CoefficientType y[], unsigned int n) const -{ - assert(n > 0); - - std::vector alpha(n); - CalculateAlpha(alpha, x, y, n); - - CoefficientType result = alpha[n-1]; - for (int j=n-2; j>=0; --j) - { - result = m_ring.Multiply(result, m_ring.Subtract(position, x[j])); - m_ring.Accumulate(result, alpha[j]); - } - return result; -} - -template -void PrepareBulkPolynomialInterpolation(const Ring &ring, Element *w, const Element x[], unsigned int n) -{ - for (unsigned int i=0; i -void PrepareBulkPolynomialInterpolationAt(const Ring &ring, Element *v, const Element &position, const Element x[], const Element w[], unsigned int n) -{ - assert(n > 0); - - std::vector a(2*n-1); - unsigned int i; - - for (i=0; i1; i--) - a[i-1] = ring.Multiply(a[2*i], a[2*i-1]); - - a[0] = ring.MultiplicativeIdentity(); - - for (i=0; i -Element BulkPolynomialInterpolateAt(const Ring &ring, const Element y[], const Element v[], unsigned int n) -{ - Element result = ring.Identity(); - for (unsigned int i=0; i -const PolynomialOverFixedRing &PolynomialOverFixedRing::Zero() -{ - return Singleton().Ref(); -} - -template -const PolynomialOverFixedRing &PolynomialOverFixedRing::One() -{ - return Singleton().Ref(); -} - -NAMESPACE_END diff --git a/lib/cryptopp/polynomi.h b/lib/cryptopp/polynomi.h deleted file mode 100644 index cddadaeaf..000000000 --- a/lib/cryptopp/polynomi.h +++ /dev/null @@ -1,459 +0,0 @@ -#ifndef CRYPTOPP_POLYNOMI_H -#define CRYPTOPP_POLYNOMI_H - -/*! \file */ - -#include "cryptlib.h" -#include "misc.h" -#include "algebra.h" - -#include -#include - -NAMESPACE_BEGIN(CryptoPP) - -//! represents single-variable polynomials over arbitrary rings -/*! \nosubgrouping */ -template class PolynomialOver -{ -public: - //! \name ENUMS, EXCEPTIONS, and TYPEDEFS - //@{ - //! division by zero exception - class DivideByZero : public Exception - { - public: - DivideByZero() : Exception(OTHER_ERROR, "PolynomialOver: division by zero") {} - }; - - //! specify the distribution for randomization functions - class RandomizationParameter - { - public: - RandomizationParameter(unsigned int coefficientCount, const typename T::RandomizationParameter &coefficientParameter ) - : m_coefficientCount(coefficientCount), m_coefficientParameter(coefficientParameter) {} - - private: - unsigned int m_coefficientCount; - typename T::RandomizationParameter m_coefficientParameter; - friend class PolynomialOver; - }; - - typedef T Ring; - typedef typename T::Element CoefficientType; - //@} - - //! \name CREATORS - //@{ - //! creates the zero polynomial - PolynomialOver() {} - - //! - PolynomialOver(const Ring &ring, unsigned int count) - : m_coefficients((size_t)count, ring.Identity()) {} - - //! copy constructor - PolynomialOver(const PolynomialOver &t) - : m_coefficients(t.m_coefficients.size()) {*this = t;} - - //! construct constant polynomial - PolynomialOver(const CoefficientType &element) - : m_coefficients(1, element) {} - - //! construct polynomial with specified coefficients, starting from coefficient of x^0 - template PolynomialOver(Iterator begin, Iterator end) - : m_coefficients(begin, end) {} - - //! convert from string - PolynomialOver(const char *str, const Ring &ring) {FromStr(str, ring);} - - //! convert from big-endian byte array - PolynomialOver(const byte *encodedPolynomialOver, unsigned int byteCount); - - //! convert from Basic Encoding Rules encoded byte array - explicit PolynomialOver(const byte *BEREncodedPolynomialOver); - - //! convert from BER encoded byte array stored in a BufferedTransformation object - explicit PolynomialOver(BufferedTransformation &bt); - - //! create a random PolynomialOver - PolynomialOver(RandomNumberGenerator &rng, const RandomizationParameter ¶meter, const Ring &ring) - {Randomize(rng, parameter, ring);} - //@} - - //! \name ACCESSORS - //@{ - //! the zero polynomial will return a degree of -1 - int Degree(const Ring &ring) const {return int(CoefficientCount(ring))-1;} - //! - unsigned int CoefficientCount(const Ring &ring) const; - //! return coefficient for x^i - CoefficientType GetCoefficient(unsigned int i, const Ring &ring) const; - //@} - - //! \name MANIPULATORS - //@{ - //! - PolynomialOver& operator=(const PolynomialOver& t); - - //! - void Randomize(RandomNumberGenerator &rng, const RandomizationParameter ¶meter, const Ring &ring); - - //! set the coefficient for x^i to value - void SetCoefficient(unsigned int i, const CoefficientType &value, const Ring &ring); - - //! - void Negate(const Ring &ring); - - //! - void swap(PolynomialOver &t); - //@} - - - //! \name BASIC ARITHMETIC ON POLYNOMIALS - //@{ - bool Equals(const PolynomialOver &t, const Ring &ring) const; - bool IsZero(const Ring &ring) const {return CoefficientCount(ring)==0;} - - PolynomialOver Plus(const PolynomialOver& t, const Ring &ring) const; - PolynomialOver Minus(const PolynomialOver& t, const Ring &ring) const; - PolynomialOver Inverse(const Ring &ring) const; - - PolynomialOver Times(const PolynomialOver& t, const Ring &ring) const; - PolynomialOver DividedBy(const PolynomialOver& t, const Ring &ring) const; - PolynomialOver Modulo(const PolynomialOver& t, const Ring &ring) const; - PolynomialOver MultiplicativeInverse(const Ring &ring) const; - bool IsUnit(const Ring &ring) const; - - PolynomialOver& Accumulate(const PolynomialOver& t, const Ring &ring); - PolynomialOver& Reduce(const PolynomialOver& t, const Ring &ring); - - //! - PolynomialOver Doubled(const Ring &ring) const {return Plus(*this, ring);} - //! - PolynomialOver Squared(const Ring &ring) const {return Times(*this, ring);} - - CoefficientType EvaluateAt(const CoefficientType &x, const Ring &ring) const; - - PolynomialOver& ShiftLeft(unsigned int n, const Ring &ring); - PolynomialOver& ShiftRight(unsigned int n, const Ring &ring); - - //! calculate r and q such that (a == d*q + r) && (0 <= degree of r < degree of d) - static void Divide(PolynomialOver &r, PolynomialOver &q, const PolynomialOver &a, const PolynomialOver &d, const Ring &ring); - //@} - - //! \name INPUT/OUTPUT - //@{ - std::istream& Input(std::istream &in, const Ring &ring); - std::ostream& Output(std::ostream &out, const Ring &ring) const; - //@} - -private: - void FromStr(const char *str, const Ring &ring); - - std::vector m_coefficients; -}; - -//! Polynomials over a fixed ring -/*! Having a fixed ring allows overloaded operators */ -template class PolynomialOverFixedRing : private PolynomialOver -{ - typedef PolynomialOver B; - typedef PolynomialOverFixedRing ThisType; - -public: - typedef T Ring; - typedef typename T::Element CoefficientType; - typedef typename B::DivideByZero DivideByZero; - typedef typename B::RandomizationParameter RandomizationParameter; - - //! \name CREATORS - //@{ - //! creates the zero polynomial - PolynomialOverFixedRing(unsigned int count = 0) : B(ms_fixedRing, count) {} - - //! copy constructor - PolynomialOverFixedRing(const ThisType &t) : B(t) {} - - explicit PolynomialOverFixedRing(const B &t) : B(t) {} - - //! construct constant polynomial - PolynomialOverFixedRing(const CoefficientType &element) : B(element) {} - - //! construct polynomial with specified coefficients, starting from coefficient of x^0 - template PolynomialOverFixedRing(Iterator first, Iterator last) - : B(first, last) {} - - //! convert from string - explicit PolynomialOverFixedRing(const char *str) : B(str, ms_fixedRing) {} - - //! convert from big-endian byte array - PolynomialOverFixedRing(const byte *encodedPoly, unsigned int byteCount) : B(encodedPoly, byteCount) {} - - //! convert from Basic Encoding Rules encoded byte array - explicit PolynomialOverFixedRing(const byte *BEREncodedPoly) : B(BEREncodedPoly) {} - - //! convert from BER encoded byte array stored in a BufferedTransformation object - explicit PolynomialOverFixedRing(BufferedTransformation &bt) : B(bt) {} - - //! create a random PolynomialOverFixedRing - PolynomialOverFixedRing(RandomNumberGenerator &rng, const RandomizationParameter ¶meter) : B(rng, parameter, ms_fixedRing) {} - - static const ThisType &Zero(); - static const ThisType &One(); - //@} - - //! \name ACCESSORS - //@{ - //! the zero polynomial will return a degree of -1 - int Degree() const {return B::Degree(ms_fixedRing);} - //! degree + 1 - unsigned int CoefficientCount() const {return B::CoefficientCount(ms_fixedRing);} - //! return coefficient for x^i - CoefficientType GetCoefficient(unsigned int i) const {return B::GetCoefficient(i, ms_fixedRing);} - //! return coefficient for x^i - CoefficientType operator[](unsigned int i) const {return B::GetCoefficient(i, ms_fixedRing);} - //@} - - //! \name MANIPULATORS - //@{ - //! - ThisType& operator=(const ThisType& t) {B::operator=(t); return *this;} - //! - ThisType& operator+=(const ThisType& t) {Accumulate(t, ms_fixedRing); return *this;} - //! - ThisType& operator-=(const ThisType& t) {Reduce(t, ms_fixedRing); return *this;} - //! - ThisType& operator*=(const ThisType& t) {return *this = *this*t;} - //! - ThisType& operator/=(const ThisType& t) {return *this = *this/t;} - //! - ThisType& operator%=(const ThisType& t) {return *this = *this%t;} - - //! - ThisType& operator<<=(unsigned int n) {ShiftLeft(n, ms_fixedRing); return *this;} - //! - ThisType& operator>>=(unsigned int n) {ShiftRight(n, ms_fixedRing); return *this;} - - //! set the coefficient for x^i to value - void SetCoefficient(unsigned int i, const CoefficientType &value) {B::SetCoefficient(i, value, ms_fixedRing);} - - //! - void Randomize(RandomNumberGenerator &rng, const RandomizationParameter ¶meter) {B::Randomize(rng, parameter, ms_fixedRing);} - - //! - void Negate() {B::Negate(ms_fixedRing);} - - void swap(ThisType &t) {B::swap(t);} - //@} - - //! \name UNARY OPERATORS - //@{ - //! - bool operator!() const {return CoefficientCount()==0;} - //! - ThisType operator+() const {return *this;} - //! - ThisType operator-() const {return ThisType(Inverse(ms_fixedRing));} - //@} - - //! \name BINARY OPERATORS - //@{ - //! - friend ThisType operator>>(ThisType a, unsigned int n) {return ThisType(a>>=n);} - //! - friend ThisType operator<<(ThisType a, unsigned int n) {return ThisType(a<<=n);} - //@} - - //! \name OTHER ARITHMETIC FUNCTIONS - //@{ - //! - ThisType MultiplicativeInverse() const {return ThisType(B::MultiplicativeInverse(ms_fixedRing));} - //! - bool IsUnit() const {return B::IsUnit(ms_fixedRing);} - - //! - ThisType Doubled() const {return ThisType(B::Doubled(ms_fixedRing));} - //! - ThisType Squared() const {return ThisType(B::Squared(ms_fixedRing));} - - CoefficientType EvaluateAt(const CoefficientType &x) const {return B::EvaluateAt(x, ms_fixedRing);} - - //! calculate r and q such that (a == d*q + r) && (0 <= r < abs(d)) - static void Divide(ThisType &r, ThisType &q, const ThisType &a, const ThisType &d) - {B::Divide(r, q, a, d, ms_fixedRing);} - //@} - - //! \name INPUT/OUTPUT - //@{ - //! - friend std::istream& operator>>(std::istream& in, ThisType &a) - {return a.Input(in, ms_fixedRing);} - //! - friend std::ostream& operator<<(std::ostream& out, const ThisType &a) - {return a.Output(out, ms_fixedRing);} - //@} - -private: - struct NewOnePolynomial - { - ThisType * operator()() const - { - return new ThisType(ms_fixedRing.MultiplicativeIdentity()); - } - }; - - static const Ring ms_fixedRing; -}; - -//! Ring of polynomials over another ring -template class RingOfPolynomialsOver : public AbstractEuclideanDomain > -{ -public: - typedef T CoefficientRing; - typedef PolynomialOver Element; - typedef typename Element::CoefficientType CoefficientType; - typedef typename Element::RandomizationParameter RandomizationParameter; - - RingOfPolynomialsOver(const CoefficientRing &ring) : m_ring(ring) {} - - Element RandomElement(RandomNumberGenerator &rng, const RandomizationParameter ¶meter) - {return Element(rng, parameter, m_ring);} - - bool Equal(const Element &a, const Element &b) const - {return a.Equals(b, m_ring);} - - const Element& Identity() const - {return this->result = m_ring.Identity();} - - const Element& Add(const Element &a, const Element &b) const - {return this->result = a.Plus(b, m_ring);} - - Element& Accumulate(Element &a, const Element &b) const - {a.Accumulate(b, m_ring); return a;} - - const Element& Inverse(const Element &a) const - {return this->result = a.Inverse(m_ring);} - - const Element& Subtract(const Element &a, const Element &b) const - {return this->result = a.Minus(b, m_ring);} - - Element& Reduce(Element &a, const Element &b) const - {return a.Reduce(b, m_ring);} - - const Element& Double(const Element &a) const - {return this->result = a.Doubled(m_ring);} - - const Element& MultiplicativeIdentity() const - {return this->result = m_ring.MultiplicativeIdentity();} - - const Element& Multiply(const Element &a, const Element &b) const - {return this->result = a.Times(b, m_ring);} - - const Element& Square(const Element &a) const - {return this->result = a.Squared(m_ring);} - - bool IsUnit(const Element &a) const - {return a.IsUnit(m_ring);} - - const Element& MultiplicativeInverse(const Element &a) const - {return this->result = a.MultiplicativeInverse(m_ring);} - - const Element& Divide(const Element &a, const Element &b) const - {return this->result = a.DividedBy(b, m_ring);} - - const Element& Mod(const Element &a, const Element &b) const - {return this->result = a.Modulo(b, m_ring);} - - void DivisionAlgorithm(Element &r, Element &q, const Element &a, const Element &d) const - {Element::Divide(r, q, a, d, m_ring);} - - class InterpolationFailed : public Exception - { - public: - InterpolationFailed() : Exception(OTHER_ERROR, "RingOfPolynomialsOver: interpolation failed") {} - }; - - Element Interpolate(const CoefficientType x[], const CoefficientType y[], unsigned int n) const; - - // a faster version of Interpolate(x, y, n).EvaluateAt(position) - CoefficientType InterpolateAt(const CoefficientType &position, const CoefficientType x[], const CoefficientType y[], unsigned int n) const; -/* - void PrepareBulkInterpolation(CoefficientType *w, const CoefficientType x[], unsigned int n) const; - void PrepareBulkInterpolationAt(CoefficientType *v, const CoefficientType &position, const CoefficientType x[], const CoefficientType w[], unsigned int n) const; - CoefficientType BulkInterpolateAt(const CoefficientType y[], const CoefficientType v[], unsigned int n) const; -*/ -protected: - void CalculateAlpha(std::vector &alpha, const CoefficientType x[], const CoefficientType y[], unsigned int n) const; - - CoefficientRing m_ring; -}; - -template -void PrepareBulkPolynomialInterpolation(const Ring &ring, Element *w, const Element x[], unsigned int n); -template -void PrepareBulkPolynomialInterpolationAt(const Ring &ring, Element *v, const Element &position, const Element x[], const Element w[], unsigned int n); -template -Element BulkPolynomialInterpolateAt(const Ring &ring, const Element y[], const Element v[], unsigned int n); - -//! -template -inline bool operator==(const CryptoPP::PolynomialOverFixedRing &a, const CryptoPP::PolynomialOverFixedRing &b) - {return a.Equals(b, a.ms_fixedRing);} -//! -template -inline bool operator!=(const CryptoPP::PolynomialOverFixedRing &a, const CryptoPP::PolynomialOverFixedRing &b) - {return !(a==b);} - -//! -template -inline bool operator> (const CryptoPP::PolynomialOverFixedRing &a, const CryptoPP::PolynomialOverFixedRing &b) - {return a.Degree() > b.Degree();} -//! -template -inline bool operator>=(const CryptoPP::PolynomialOverFixedRing &a, const CryptoPP::PolynomialOverFixedRing &b) - {return a.Degree() >= b.Degree();} -//! -template -inline bool operator< (const CryptoPP::PolynomialOverFixedRing &a, const CryptoPP::PolynomialOverFixedRing &b) - {return a.Degree() < b.Degree();} -//! -template -inline bool operator<=(const CryptoPP::PolynomialOverFixedRing &a, const CryptoPP::PolynomialOverFixedRing &b) - {return a.Degree() <= b.Degree();} - -//! -template -inline CryptoPP::PolynomialOverFixedRing operator+(const CryptoPP::PolynomialOverFixedRing &a, const CryptoPP::PolynomialOverFixedRing &b) - {return CryptoPP::PolynomialOverFixedRing(a.Plus(b, a.ms_fixedRing));} -//! -template -inline CryptoPP::PolynomialOverFixedRing operator-(const CryptoPP::PolynomialOverFixedRing &a, const CryptoPP::PolynomialOverFixedRing &b) - {return CryptoPP::PolynomialOverFixedRing(a.Minus(b, a.ms_fixedRing));} -//! -template -inline CryptoPP::PolynomialOverFixedRing operator*(const CryptoPP::PolynomialOverFixedRing &a, const CryptoPP::PolynomialOverFixedRing &b) - {return CryptoPP::PolynomialOverFixedRing(a.Times(b, a.ms_fixedRing));} -//! -template -inline CryptoPP::PolynomialOverFixedRing operator/(const CryptoPP::PolynomialOverFixedRing &a, const CryptoPP::PolynomialOverFixedRing &b) - {return CryptoPP::PolynomialOverFixedRing(a.DividedBy(b, a.ms_fixedRing));} -//! -template -inline CryptoPP::PolynomialOverFixedRing operator%(const CryptoPP::PolynomialOverFixedRing &a, const CryptoPP::PolynomialOverFixedRing &b) - {return CryptoPP::PolynomialOverFixedRing(a.Modulo(b, a.ms_fixedRing));} - -NAMESPACE_END - -NAMESPACE_BEGIN(std) -template inline void swap(CryptoPP::PolynomialOver &a, CryptoPP::PolynomialOver &b) -{ - a.swap(b); -} -template inline void swap(CryptoPP::PolynomialOverFixedRing &a, CryptoPP::PolynomialOverFixedRing &b) -{ - a.swap(b); -} -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/pssr.cpp b/lib/cryptopp/pssr.cpp deleted file mode 100644 index ccbe4ee27..000000000 --- a/lib/cryptopp/pssr.cpp +++ /dev/null @@ -1,145 +0,0 @@ -// pssr.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "pssr.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -// more in dll.cpp -template<> const byte EMSA2HashId::id = 0x31; -template<> const byte EMSA2HashId::id = 0x32; -template<> const byte EMSA2HashId::id = 0x37; - -#ifndef CRYPTOPP_IMPORTS - -size_t PSSR_MEM_Base::MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const -{ - size_t saltLen = SaltLen(digestLength); - size_t minPadLen = MinPadLen(digestLength); - return 9 + 8*(minPadLen + saltLen + digestLength + hashIdentifierLength); -} - -size_t PSSR_MEM_Base::MaxRecoverableLength(size_t representativeBitLength, size_t hashIdentifierLength, size_t digestLength) const -{ - if (AllowRecovery()) - return SaturatingSubtract(representativeBitLength, MinRepresentativeBitLength(hashIdentifierLength, digestLength)) / 8; - return 0; -} - -bool PSSR_MEM_Base::IsProbabilistic() const -{ - return SaltLen(1) > 0; -} - -bool PSSR_MEM_Base::AllowNonrecoverablePart() const -{ - return true; -} - -bool PSSR_MEM_Base::RecoverablePartFirst() const -{ - return false; -} - -void PSSR_MEM_Base::ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const -{ - assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize())); - - const size_t u = hashIdentifier.second + 1; - const size_t representativeByteLength = BitsToBytes(representativeBitLength); - const size_t digestSize = hash.DigestSize(); - const size_t saltSize = SaltLen(digestSize); - byte *const h = representative + representativeByteLength - u - digestSize; - - SecByteBlock digest(digestSize), salt(saltSize); - hash.Final(digest); - rng.GenerateBlock(salt, saltSize); - - // compute H = hash of M' - byte c[8]; - PutWord(false, BIG_ENDIAN_ORDER, c, (word32)SafeRightShift<29>(recoverableMessageLength)); - PutWord(false, BIG_ENDIAN_ORDER, c+4, word32(recoverableMessageLength << 3)); - hash.Update(c, 8); - hash.Update(recoverableMessage, recoverableMessageLength); - hash.Update(digest, digestSize); - hash.Update(salt, saltSize); - hash.Final(h); - - // compute representative - GetMGF().GenerateAndMask(hash, representative, representativeByteLength - u - digestSize, h, digestSize, false); - byte *xorStart = representative + representativeByteLength - u - digestSize - salt.size() - recoverableMessageLength - 1; - xorStart[0] ^= 1; - xorbuf(xorStart + 1, recoverableMessage, recoverableMessageLength); - xorbuf(xorStart + 1 + recoverableMessageLength, salt, salt.size()); - memcpy(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second); - representative[representativeByteLength - 1] = hashIdentifier.second ? 0xcc : 0xbc; - if (representativeBitLength % 8 != 0) - representative[0] = (byte)Crop(representative[0], representativeBitLength % 8); -} - -DecodingResult PSSR_MEM_Base::RecoverMessageFromRepresentative( - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength, - byte *recoverableMessage) const -{ - assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize())); - - const size_t u = hashIdentifier.second + 1; - const size_t representativeByteLength = BitsToBytes(representativeBitLength); - const size_t digestSize = hash.DigestSize(); - const size_t saltSize = SaltLen(digestSize); - const byte *const h = representative + representativeByteLength - u - digestSize; - - SecByteBlock digest(digestSize); - hash.Final(digest); - - DecodingResult result(0); - bool &valid = result.isValidCoding; - size_t &recoverableMessageLength = result.messageLength; - - valid = (representative[representativeByteLength - 1] == (hashIdentifier.second ? 0xcc : 0xbc)) && valid; - valid = VerifyBufsEqual(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second) && valid; - - GetMGF().GenerateAndMask(hash, representative, representativeByteLength - u - digestSize, h, digestSize); - if (representativeBitLength % 8 != 0) - representative[0] = (byte)Crop(representative[0], representativeBitLength % 8); - - // extract salt and recoverableMessage from DB = 00 ... || 01 || M || salt - byte *salt = representative + representativeByteLength - u - digestSize - saltSize; - byte *M = std::find_if(representative, salt-1, std::bind2nd(std::not_equal_to(), 0)); - recoverableMessageLength = salt-M-1; - if (*M == 0x01 - && (size_t)(M - representative - (representativeBitLength % 8 != 0)) >= MinPadLen(digestSize) - && recoverableMessageLength <= MaxRecoverableLength(representativeBitLength, hashIdentifier.second, digestSize)) - { - memcpy(recoverableMessage, M+1, recoverableMessageLength); - } - else - { - recoverableMessageLength = 0; - valid = false; - } - - // verify H = hash of M' - byte c[8]; - PutWord(false, BIG_ENDIAN_ORDER, c, (word32)SafeRightShift<29>(recoverableMessageLength)); - PutWord(false, BIG_ENDIAN_ORDER, c+4, word32(recoverableMessageLength << 3)); - hash.Update(c, 8); - hash.Update(recoverableMessage, recoverableMessageLength); - hash.Update(digest, digestSize); - hash.Update(salt, saltSize); - valid = hash.Verify(h) && valid; - - if (!AllowRecovery() && valid && recoverableMessageLength != 0) - {throw NotImplemented("PSSR_MEM: message recovery disabled");} - - return result; -} - -#endif - -NAMESPACE_END diff --git a/lib/cryptopp/pssr.h b/lib/cryptopp/pssr.h deleted file mode 100644 index 6ec6936e5..000000000 --- a/lib/cryptopp/pssr.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef CRYPTOPP_PSSR_H -#define CRYPTOPP_PSSR_H - -#include "pubkey.h" -#include "emsa2.h" - -#ifdef CRYPTOPP_IS_DLL -#include "sha.h" -#endif - -NAMESPACE_BEGIN(CryptoPP) - -class CRYPTOPP_DLL PSSR_MEM_Base : public PK_RecoverableSignatureMessageEncodingMethod -{ - virtual bool AllowRecovery() const =0; - virtual size_t SaltLen(size_t hashLen) const =0; - virtual size_t MinPadLen(size_t hashLen) const =0; - virtual const MaskGeneratingFunction & GetMGF() const =0; - -public: - size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const; - size_t MaxRecoverableLength(size_t representativeBitLength, size_t hashIdentifierLength, size_t digestLength) const; - bool IsProbabilistic() const; - bool AllowNonrecoverablePart() const; - bool RecoverablePartFirst() const; - void ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const; - DecodingResult RecoverMessageFromRepresentative( - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength, - byte *recoverableMessage) const; -}; - -template class PSSR_MEM_BaseWithHashId; -template<> class PSSR_MEM_BaseWithHashId : public EMSA2HashIdLookup {}; -template<> class PSSR_MEM_BaseWithHashId : public PSSR_MEM_Base {}; - -template -class PSSR_MEM : public PSSR_MEM_BaseWithHashId -{ - virtual bool AllowRecovery() const {return ALLOW_RECOVERY;} - virtual size_t SaltLen(size_t hashLen) const {return SALT_LEN < 0 ? hashLen : SALT_LEN;} - virtual size_t MinPadLen(size_t hashLen) const {return MIN_PAD_LEN < 0 ? hashLen : MIN_PAD_LEN;} - virtual const MaskGeneratingFunction & GetMGF() const {static MGF mgf; return mgf;} - -public: - static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string(ALLOW_RECOVERY ? "PSSR-" : "PSS-") + MGF::StaticAlgorithmName();} -}; - -//! PSSR-MGF1 -struct PSSR : public SignatureStandard -{ - typedef PSSR_MEM SignatureMessageEncodingMethod; -}; - -//! PSS-MGF1 -struct PSS : public SignatureStandard -{ - typedef PSSR_MEM SignatureMessageEncodingMethod; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/pubkey.cpp b/lib/cryptopp/pubkey.cpp deleted file mode 100644 index 1159e5343..000000000 --- a/lib/cryptopp/pubkey.cpp +++ /dev/null @@ -1,165 +0,0 @@ -// pubkey.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "pubkey.h" - -NAMESPACE_BEGIN(CryptoPP) - -void P1363_MGF1KDF2_Common(HashTransformation &hash, byte *output, size_t outputLength, const byte *input, size_t inputLength, const byte *derivationParams, size_t derivationParamsLength, bool mask, unsigned int counterStart) -{ - ArraySink *sink; - HashFilter filter(hash, sink = mask ? new ArrayXorSink(output, outputLength) : new ArraySink(output, outputLength)); - word32 counter = counterStart; - while (sink->AvailableSize() > 0) - { - filter.Put(input, inputLength); - filter.PutWord32(counter++); - filter.Put(derivationParams, derivationParamsLength); - filter.MessageEnd(); - } -} - -bool PK_DeterministicSignatureMessageEncodingMethod::VerifyMessageRepresentative( - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const -{ - SecByteBlock computedRepresentative(BitsToBytes(representativeBitLength)); - ComputeMessageRepresentative(NullRNG(), NULL, 0, hash, hashIdentifier, messageEmpty, computedRepresentative, representativeBitLength); - return VerifyBufsEqual(representative, computedRepresentative, computedRepresentative.size()); -} - -bool PK_RecoverableSignatureMessageEncodingMethod::VerifyMessageRepresentative( - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const -{ - SecByteBlock recoveredMessage(MaxRecoverableLength(representativeBitLength, hashIdentifier.second, hash.DigestSize())); - DecodingResult result = RecoverMessageFromRepresentative( - hash, hashIdentifier, messageEmpty, representative, representativeBitLength, recoveredMessage); - return result.isValidCoding && result.messageLength == 0; -} - -void TF_SignerBase::InputRecoverableMessage(PK_MessageAccumulator &messageAccumulator, const byte *recoverableMessage, size_t recoverableMessageLength) const -{ - PK_MessageAccumulatorBase &ma = static_cast(messageAccumulator); - HashIdentifier id = GetHashIdentifier(); - const MessageEncodingInterface &encoding = GetMessageEncodingInterface(); - - if (MessageRepresentativeBitLength() < encoding.MinRepresentativeBitLength(id.second, ma.AccessHash().DigestSize())) - throw PK_SignatureScheme::KeyTooShort(); - - size_t maxRecoverableLength = encoding.MaxRecoverableLength(MessageRepresentativeBitLength(), GetHashIdentifier().second, ma.AccessHash().DigestSize()); - - if (maxRecoverableLength == 0) - {throw NotImplemented("TF_SignerBase: this algorithm does not support messsage recovery or the key is too short");} - if (recoverableMessageLength > maxRecoverableLength) - throw InvalidArgument("TF_SignerBase: the recoverable message part is too long for the given key and algorithm"); - - ma.m_recoverableMessage.Assign(recoverableMessage, recoverableMessageLength); - encoding.ProcessRecoverableMessage( - ma.AccessHash(), - recoverableMessage, recoverableMessageLength, - NULL, 0, ma.m_semisignature); -} - -size_t TF_SignerBase::SignAndRestart(RandomNumberGenerator &rng, PK_MessageAccumulator &messageAccumulator, byte *signature, bool restart) const -{ - PK_MessageAccumulatorBase &ma = static_cast(messageAccumulator); - HashIdentifier id = GetHashIdentifier(); - const MessageEncodingInterface &encoding = GetMessageEncodingInterface(); - - if (MessageRepresentativeBitLength() < encoding.MinRepresentativeBitLength(id.second, ma.AccessHash().DigestSize())) - throw PK_SignatureScheme::KeyTooShort(); - - SecByteBlock representative(MessageRepresentativeLength()); - encoding.ComputeMessageRepresentative(rng, - ma.m_recoverableMessage, ma.m_recoverableMessage.size(), - ma.AccessHash(), id, ma.m_empty, - representative, MessageRepresentativeBitLength()); - ma.m_empty = true; - - Integer r(representative, representative.size()); - size_t signatureLength = SignatureLength(); - GetTrapdoorFunctionInterface().CalculateRandomizedInverse(rng, r).Encode(signature, signatureLength); - return signatureLength; -} - -void TF_VerifierBase::InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, size_t signatureLength) const -{ - PK_MessageAccumulatorBase &ma = static_cast(messageAccumulator); - HashIdentifier id = GetHashIdentifier(); - const MessageEncodingInterface &encoding = GetMessageEncodingInterface(); - - if (MessageRepresentativeBitLength() < encoding.MinRepresentativeBitLength(id.second, ma.AccessHash().DigestSize())) - throw PK_SignatureScheme::KeyTooShort(); - - ma.m_representative.New(MessageRepresentativeLength()); - Integer x = GetTrapdoorFunctionInterface().ApplyFunction(Integer(signature, signatureLength)); - if (x.BitCount() > MessageRepresentativeBitLength()) - x = Integer::Zero(); // don't return false here to prevent timing attack - x.Encode(ma.m_representative, ma.m_representative.size()); -} - -bool TF_VerifierBase::VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const -{ - PK_MessageAccumulatorBase &ma = static_cast(messageAccumulator); - HashIdentifier id = GetHashIdentifier(); - const MessageEncodingInterface &encoding = GetMessageEncodingInterface(); - - if (MessageRepresentativeBitLength() < encoding.MinRepresentativeBitLength(id.second, ma.AccessHash().DigestSize())) - throw PK_SignatureScheme::KeyTooShort(); - - bool result = encoding.VerifyMessageRepresentative( - ma.AccessHash(), id, ma.m_empty, ma.m_representative, MessageRepresentativeBitLength()); - ma.m_empty = true; - return result; -} - -DecodingResult TF_VerifierBase::RecoverAndRestart(byte *recoveredMessage, PK_MessageAccumulator &messageAccumulator) const -{ - PK_MessageAccumulatorBase &ma = static_cast(messageAccumulator); - HashIdentifier id = GetHashIdentifier(); - const MessageEncodingInterface &encoding = GetMessageEncodingInterface(); - - if (MessageRepresentativeBitLength() < encoding.MinRepresentativeBitLength(id.second, ma.AccessHash().DigestSize())) - throw PK_SignatureScheme::KeyTooShort(); - - DecodingResult result = encoding.RecoverMessageFromRepresentative( - ma.AccessHash(), id, ma.m_empty, ma.m_representative, MessageRepresentativeBitLength(), recoveredMessage); - ma.m_empty = true; - return result; -} - -DecodingResult TF_DecryptorBase::Decrypt(RandomNumberGenerator &rng, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters) const -{ - if (ciphertextLength != FixedCiphertextLength()) - throw InvalidArgument(AlgorithmName() + ": ciphertext length of " + IntToString(ciphertextLength) + " doesn't match the required length of " + IntToString(FixedCiphertextLength()) + " for this key"); - - SecByteBlock paddedBlock(PaddedBlockByteLength()); - Integer x = GetTrapdoorFunctionInterface().CalculateInverse(rng, Integer(ciphertext, ciphertextLength)); - if (x.ByteCount() > paddedBlock.size()) - x = Integer::Zero(); // don't return false here to prevent timing attack - x.Encode(paddedBlock, paddedBlock.size()); - return GetMessageEncodingInterface().Unpad(paddedBlock, PaddedBlockBitLength(), plaintext, parameters); -} - -void TF_EncryptorBase::Encrypt(RandomNumberGenerator &rng, const byte *plaintext, size_t plaintextLength, byte *ciphertext, const NameValuePairs ¶meters) const -{ - if (plaintextLength > FixedMaxPlaintextLength()) - { - if (FixedMaxPlaintextLength() < 1) - throw InvalidArgument(AlgorithmName() + ": this key is too short to encrypt any messages"); - else - throw InvalidArgument(AlgorithmName() + ": message length of " + IntToString(plaintextLength) + " exceeds the maximum of " + IntToString(FixedMaxPlaintextLength()) + " for this public key"); - } - - SecByteBlock paddedBlock(PaddedBlockByteLength()); - GetMessageEncodingInterface().Pad(rng, plaintext, plaintextLength, paddedBlock, PaddedBlockBitLength(), parameters); - GetTrapdoorFunctionInterface().ApplyRandomizedFunction(rng, Integer(paddedBlock, paddedBlock.size())).Encode(ciphertext, FixedCiphertextLength()); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/pubkey.h b/lib/cryptopp/pubkey.h deleted file mode 100644 index 3a3f3bcde..000000000 --- a/lib/cryptopp/pubkey.h +++ /dev/null @@ -1,1678 +0,0 @@ -// pubkey.h - written and placed in the public domain by Wei Dai - -#ifndef CRYPTOPP_PUBKEY_H -#define CRYPTOPP_PUBKEY_H - -/** \file - - This file contains helper classes/functions for implementing public key algorithms. - - The class hierachies in this .h file tend to look like this: -

-                  x1
-                 / \
-                y1  z1
-                 |  |
-            x2  x2
-                 |  |
-                y2  z2
-                 |  |
-            x3  x3
-                 |  |
-                y3  z3
-
- - x1, y1, z1 are abstract interface classes defined in cryptlib.h - - x2, y2, z2 are implementations of the interfaces using "abstract policies", which - are pure virtual functions that should return interfaces to interchangeable algorithms. - These classes have "Base" suffixes. - - x3, y3, z3 hold actual algorithms and implement those virtual functions. - These classes have "Impl" suffixes. - - The "TF_" prefix means an implementation using trapdoor functions on integers. - The "DL_" prefix means an implementation using group operations (in groups where discrete log is hard). -*/ - -#include "modarith.h" -#include "filters.h" -#include "eprecomp.h" -#include "fips140.h" -#include "argnames.h" -#include - -// VC60 workaround: this macro is defined in shlobj.h and conflicts with a template parameter used in this file -#undef INTERFACE - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TrapdoorFunctionBounds -{ -public: - virtual ~TrapdoorFunctionBounds() {} - - virtual Integer PreimageBound() const =0; - virtual Integer ImageBound() const =0; - virtual Integer MaxPreimage() const {return --PreimageBound();} - virtual Integer MaxImage() const {return --ImageBound();} -}; - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE RandomizedTrapdoorFunction : public TrapdoorFunctionBounds -{ -public: - virtual Integer ApplyRandomizedFunction(RandomNumberGenerator &rng, const Integer &x) const =0; - virtual bool IsRandomized() const {return true;} -}; - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TrapdoorFunction : public RandomizedTrapdoorFunction -{ -public: - Integer ApplyRandomizedFunction(RandomNumberGenerator &rng, const Integer &x) const - {return ApplyFunction(x);} - bool IsRandomized() const {return false;} - - virtual Integer ApplyFunction(const Integer &x) const =0; -}; - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE RandomizedTrapdoorFunctionInverse -{ -public: - virtual ~RandomizedTrapdoorFunctionInverse() {} - - virtual Integer CalculateRandomizedInverse(RandomNumberGenerator &rng, const Integer &x) const =0; - virtual bool IsRandomized() const {return true;} -}; - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TrapdoorFunctionInverse : public RandomizedTrapdoorFunctionInverse -{ -public: - virtual ~TrapdoorFunctionInverse() {} - - Integer CalculateRandomizedInverse(RandomNumberGenerator &rng, const Integer &x) const - {return CalculateInverse(rng, x);} - bool IsRandomized() const {return false;} - - virtual Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const =0; -}; - -// ******************************************************** - -//! message encoding method for public key encryption -class CRYPTOPP_NO_VTABLE PK_EncryptionMessageEncodingMethod -{ -public: - virtual ~PK_EncryptionMessageEncodingMethod() {} - - virtual bool ParameterSupported(const char *name) const {return false;} - - //! max size of unpadded message in bytes, given max size of padded message in bits (1 less than size of modulus) - virtual size_t MaxUnpaddedLength(size_t paddedLength) const =0; - - virtual void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedBitLength, const NameValuePairs ¶meters) const =0; - - virtual DecodingResult Unpad(const byte *padded, size_t paddedBitLength, byte *raw, const NameValuePairs ¶meters) const =0; -}; - -// ******************************************************** - -//! _ -template -class CRYPTOPP_NO_VTABLE TF_Base -{ -protected: - virtual const TrapdoorFunctionBounds & GetTrapdoorFunctionBounds() const =0; - - typedef TFI TrapdoorFunctionInterface; - virtual const TrapdoorFunctionInterface & GetTrapdoorFunctionInterface() const =0; - - typedef MEI MessageEncodingInterface; - virtual const MessageEncodingInterface & GetMessageEncodingInterface() const =0; -}; - -// ******************************************************** - -//! _ -template -class CRYPTOPP_NO_VTABLE PK_FixedLengthCryptoSystemImpl : public BASE -{ -public: - size_t MaxPlaintextLength(size_t ciphertextLength) const - {return ciphertextLength == FixedCiphertextLength() ? FixedMaxPlaintextLength() : 0;} - size_t CiphertextLength(size_t plaintextLength) const - {return plaintextLength <= FixedMaxPlaintextLength() ? FixedCiphertextLength() : 0;} - - virtual size_t FixedMaxPlaintextLength() const =0; - virtual size_t FixedCiphertextLength() const =0; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE TF_CryptoSystemBase : public PK_FixedLengthCryptoSystemImpl, protected BASE -{ -public: - bool ParameterSupported(const char *name) const {return this->GetMessageEncodingInterface().ParameterSupported(name);} - size_t FixedMaxPlaintextLength() const {return this->GetMessageEncodingInterface().MaxUnpaddedLength(PaddedBlockBitLength());} - size_t FixedCiphertextLength() const {return this->GetTrapdoorFunctionBounds().MaxImage().ByteCount();} - -protected: - size_t PaddedBlockByteLength() const {return BitsToBytes(PaddedBlockBitLength());} - size_t PaddedBlockBitLength() const {return this->GetTrapdoorFunctionBounds().PreimageBound().BitCount()-1;} -}; - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TF_DecryptorBase : public TF_CryptoSystemBase > -{ -public: - DecodingResult Decrypt(RandomNumberGenerator &rng, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters = g_nullNameValuePairs) const; -}; - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TF_EncryptorBase : public TF_CryptoSystemBase > -{ -public: - void Encrypt(RandomNumberGenerator &rng, const byte *plaintext, size_t plaintextLength, byte *ciphertext, const NameValuePairs ¶meters = g_nullNameValuePairs) const; -}; - -// ******************************************************** - -typedef std::pair HashIdentifier; - -//! interface for message encoding method for public key signature schemes -class CRYPTOPP_NO_VTABLE PK_SignatureMessageEncodingMethod -{ -public: - virtual ~PK_SignatureMessageEncodingMethod() {} - - virtual size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const - {return 0;} - virtual size_t MaxRecoverableLength(size_t representativeBitLength, size_t hashIdentifierLength, size_t digestLength) const - {return 0;} - - bool IsProbabilistic() const - {return true;} - bool AllowNonrecoverablePart() const - {throw NotImplemented("PK_MessageEncodingMethod: this signature scheme does not support message recovery");} - virtual bool RecoverablePartFirst() const - {throw NotImplemented("PK_MessageEncodingMethod: this signature scheme does not support message recovery");} - - // for verification, DL - virtual void ProcessSemisignature(HashTransformation &hash, const byte *semisignature, size_t semisignatureLength) const {} - - // for signature - virtual void ProcessRecoverableMessage(HashTransformation &hash, - const byte *recoverableMessage, size_t recoverableMessageLength, - const byte *presignature, size_t presignatureLength, - SecByteBlock &semisignature) const - { - if (RecoverablePartFirst()) - assert(!"ProcessRecoverableMessage() not implemented"); - } - - virtual void ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const =0; - - virtual bool VerifyMessageRepresentative( - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const =0; - - virtual DecodingResult RecoverMessageFromRepresentative( // for TF - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength, - byte *recoveredMessage) const - {throw NotImplemented("PK_MessageEncodingMethod: this signature scheme does not support message recovery");} - - virtual DecodingResult RecoverMessageFromSemisignature( // for DL - HashTransformation &hash, HashIdentifier hashIdentifier, - const byte *presignature, size_t presignatureLength, - const byte *semisignature, size_t semisignatureLength, - byte *recoveredMessage) const - {throw NotImplemented("PK_MessageEncodingMethod: this signature scheme does not support message recovery");} - - // VC60 workaround - struct HashIdentifierLookup - { - template struct HashIdentifierLookup2 - { - static HashIdentifier CRYPTOPP_API Lookup() - { - return HashIdentifier((const byte *)NULL, 0); - } - }; - }; -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_DeterministicSignatureMessageEncodingMethod : public PK_SignatureMessageEncodingMethod -{ -public: - bool VerifyMessageRepresentative( - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const; -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_RecoverableSignatureMessageEncodingMethod : public PK_SignatureMessageEncodingMethod -{ -public: - bool VerifyMessageRepresentative( - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const; -}; - -class CRYPTOPP_DLL DL_SignatureMessageEncodingMethod_DSA : public PK_DeterministicSignatureMessageEncodingMethod -{ -public: - void ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const; -}; - -class CRYPTOPP_DLL DL_SignatureMessageEncodingMethod_NR : public PK_DeterministicSignatureMessageEncodingMethod -{ -public: - void ComputeMessageRepresentative(RandomNumberGenerator &rng, - const byte *recoverableMessage, size_t recoverableMessageLength, - HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, - byte *representative, size_t representativeBitLength) const; -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_MessageAccumulatorBase : public PK_MessageAccumulator -{ -public: - PK_MessageAccumulatorBase() : m_empty(true) {} - - virtual HashTransformation & AccessHash() =0; - - void Update(const byte *input, size_t length) - { - AccessHash().Update(input, length); - m_empty = m_empty && length == 0; - } - - SecByteBlock m_recoverableMessage, m_representative, m_presignature, m_semisignature; - Integer m_k, m_s; - bool m_empty; -}; - -template -class PK_MessageAccumulatorImpl : public PK_MessageAccumulatorBase, protected ObjectHolder -{ -public: - HashTransformation & AccessHash() {return this->m_object;} -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE TF_SignatureSchemeBase : public INTERFACE, protected BASE -{ -public: - size_t SignatureLength() const - {return this->GetTrapdoorFunctionBounds().MaxPreimage().ByteCount();} - size_t MaxRecoverableLength() const - {return this->GetMessageEncodingInterface().MaxRecoverableLength(MessageRepresentativeBitLength(), GetHashIdentifier().second, GetDigestSize());} - size_t MaxRecoverableLengthFromSignatureLength(size_t signatureLength) const - {return this->MaxRecoverableLength();} - - bool IsProbabilistic() const - {return this->GetTrapdoorFunctionInterface().IsRandomized() || this->GetMessageEncodingInterface().IsProbabilistic();} - bool AllowNonrecoverablePart() const - {return this->GetMessageEncodingInterface().AllowNonrecoverablePart();} - bool RecoverablePartFirst() const - {return this->GetMessageEncodingInterface().RecoverablePartFirst();} - -protected: - size_t MessageRepresentativeLength() const {return BitsToBytes(MessageRepresentativeBitLength());} - size_t MessageRepresentativeBitLength() const {return this->GetTrapdoorFunctionBounds().ImageBound().BitCount()-1;} - virtual HashIdentifier GetHashIdentifier() const =0; - virtual size_t GetDigestSize() const =0; -}; - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TF_SignerBase : public TF_SignatureSchemeBase > -{ -public: - void InputRecoverableMessage(PK_MessageAccumulator &messageAccumulator, const byte *recoverableMessage, size_t recoverableMessageLength) const; - size_t SignAndRestart(RandomNumberGenerator &rng, PK_MessageAccumulator &messageAccumulator, byte *signature, bool restart=true) const; -}; - -//! _ -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TF_VerifierBase : public TF_SignatureSchemeBase > -{ -public: - void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, size_t signatureLength) const; - bool VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const; - DecodingResult RecoverAndRestart(byte *recoveredMessage, PK_MessageAccumulator &recoveryAccumulator) const; -}; - -// ******************************************************** - -//! _ -template -struct TF_CryptoSchemeOptions -{ - typedef T1 AlgorithmInfo; - typedef T2 Keys; - typedef typename Keys::PrivateKey PrivateKey; - typedef typename Keys::PublicKey PublicKey; - typedef T3 MessageEncodingMethod; -}; - -//! _ -template -struct TF_SignatureSchemeOptions : public TF_CryptoSchemeOptions -{ - typedef T4 HashFunction; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE TF_ObjectImplBase : public AlgorithmImpl -{ -public: - typedef SCHEME_OPTIONS SchemeOptions; - typedef KEY_CLASS KeyClass; - - PublicKey & AccessPublicKey() {return AccessKey();} - const PublicKey & GetPublicKey() const {return GetKey();} - - PrivateKey & AccessPrivateKey() {return AccessKey();} - const PrivateKey & GetPrivateKey() const {return GetKey();} - - virtual const KeyClass & GetKey() const =0; - virtual KeyClass & AccessKey() =0; - - const KeyClass & GetTrapdoorFunction() const {return GetKey();} - - PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng) const - { - return new PK_MessageAccumulatorImpl; - } - PK_MessageAccumulator * NewVerificationAccumulator() const - { - return new PK_MessageAccumulatorImpl; - } - -protected: - const typename BASE::MessageEncodingInterface & GetMessageEncodingInterface() const - {return Singleton().Ref();} - const TrapdoorFunctionBounds & GetTrapdoorFunctionBounds() const - {return GetKey();} - const typename BASE::TrapdoorFunctionInterface & GetTrapdoorFunctionInterface() const - {return GetKey();} - - // for signature scheme - HashIdentifier GetHashIdentifier() const - { - typedef CPP_TYPENAME SchemeOptions::MessageEncodingMethod::HashIdentifierLookup::template HashIdentifierLookup2 L; - return L::Lookup(); - } - size_t GetDigestSize() const - { - typedef CPP_TYPENAME SchemeOptions::HashFunction H; - return H::DIGESTSIZE; - } -}; - -//! _ -template -class TF_ObjectImplExtRef : public TF_ObjectImplBase -{ -public: - TF_ObjectImplExtRef(const KEY *pKey = NULL) : m_pKey(pKey) {} - void SetKeyPtr(const KEY *pKey) {m_pKey = pKey;} - - const KEY & GetKey() const {return *m_pKey;} - KEY & AccessKey() {throw NotImplemented("TF_ObjectImplExtRef: cannot modify refererenced key");} - -private: - const KEY * m_pKey; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE TF_ObjectImpl : public TF_ObjectImplBase -{ -public: - typedef KEY_CLASS KeyClass; - - const KeyClass & GetKey() const {return m_trapdoorFunction;} - KeyClass & AccessKey() {return m_trapdoorFunction;} - -private: - KeyClass m_trapdoorFunction; -}; - -//! _ -template -class TF_DecryptorImpl : public TF_ObjectImpl -{ -}; - -//! _ -template -class TF_EncryptorImpl : public TF_ObjectImpl -{ -}; - -//! _ -template -class TF_SignerImpl : public TF_ObjectImpl -{ -}; - -//! _ -template -class TF_VerifierImpl : public TF_ObjectImpl -{ -}; - -// ******************************************************** - -//! _ -class CRYPTOPP_NO_VTABLE MaskGeneratingFunction -{ -public: - virtual ~MaskGeneratingFunction() {} - virtual void GenerateAndMask(HashTransformation &hash, byte *output, size_t outputLength, const byte *input, size_t inputLength, bool mask = true) const =0; -}; - -CRYPTOPP_DLL void CRYPTOPP_API P1363_MGF1KDF2_Common(HashTransformation &hash, byte *output, size_t outputLength, const byte *input, size_t inputLength, const byte *derivationParams, size_t derivationParamsLength, bool mask, unsigned int counterStart); - -//! _ -class P1363_MGF1 : public MaskGeneratingFunction -{ -public: - static const char * CRYPTOPP_API StaticAlgorithmName() {return "MGF1";} - void GenerateAndMask(HashTransformation &hash, byte *output, size_t outputLength, const byte *input, size_t inputLength, bool mask = true) const - { - P1363_MGF1KDF2_Common(hash, output, outputLength, input, inputLength, NULL, 0, mask, 0); - } -}; - -// ******************************************************** - -//! _ -template -class P1363_KDF2 -{ -public: - static void CRYPTOPP_API DeriveKey(byte *output, size_t outputLength, const byte *input, size_t inputLength, const byte *derivationParams, size_t derivationParamsLength) - { - H h; - P1363_MGF1KDF2_Common(h, output, outputLength, input, inputLength, derivationParams, derivationParamsLength, false, 1); - } -}; - -// ******************************************************** - -//! to be thrown by DecodeElement and AgreeWithStaticPrivateKey -class DL_BadElement : public InvalidDataFormat -{ -public: - DL_BadElement() : InvalidDataFormat("CryptoPP: invalid group element") {} -}; - -//! interface for DL group parameters -template -class CRYPTOPP_NO_VTABLE DL_GroupParameters : public CryptoParameters -{ - typedef DL_GroupParameters ThisClass; - -public: - typedef T Element; - - DL_GroupParameters() : m_validationLevel(0) {} - - // CryptoMaterial - bool Validate(RandomNumberGenerator &rng, unsigned int level) const - { - if (!GetBasePrecomputation().IsInitialized()) - return false; - - if (m_validationLevel > level) - return true; - - bool pass = ValidateGroup(rng, level); - pass = pass && ValidateElement(level, GetSubgroupGenerator(), &GetBasePrecomputation()); - - m_validationLevel = pass ? level+1 : 0; - - return pass; - } - - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const - { - return GetValueHelper(this, name, valueType, pValue) - CRYPTOPP_GET_FUNCTION_ENTRY(SubgroupOrder) - CRYPTOPP_GET_FUNCTION_ENTRY(SubgroupGenerator) - ; - } - - bool SupportsPrecomputation() const {return true;} - - void Precompute(unsigned int precomputationStorage=16) - { - AccessBasePrecomputation().Precompute(GetGroupPrecomputation(), GetSubgroupOrder().BitCount(), precomputationStorage); - } - - void LoadPrecomputation(BufferedTransformation &storedPrecomputation) - { - AccessBasePrecomputation().Load(GetGroupPrecomputation(), storedPrecomputation); - m_validationLevel = 0; - } - - void SavePrecomputation(BufferedTransformation &storedPrecomputation) const - { - GetBasePrecomputation().Save(GetGroupPrecomputation(), storedPrecomputation); - } - - // non-inherited - virtual const Element & GetSubgroupGenerator() const {return GetBasePrecomputation().GetBase(GetGroupPrecomputation());} - virtual void SetSubgroupGenerator(const Element &base) {AccessBasePrecomputation().SetBase(GetGroupPrecomputation(), base);} - virtual Element ExponentiateBase(const Integer &exponent) const - { - return GetBasePrecomputation().Exponentiate(GetGroupPrecomputation(), exponent); - } - virtual Element ExponentiateElement(const Element &base, const Integer &exponent) const - { - Element result; - SimultaneousExponentiate(&result, base, &exponent, 1); - return result; - } - - virtual const DL_GroupPrecomputation & GetGroupPrecomputation() const =0; - virtual const DL_FixedBasePrecomputation & GetBasePrecomputation() const =0; - virtual DL_FixedBasePrecomputation & AccessBasePrecomputation() =0; - virtual const Integer & GetSubgroupOrder() const =0; // order of subgroup generated by base element - virtual Integer GetMaxExponent() const =0; - virtual Integer GetGroupOrder() const {return GetSubgroupOrder()*GetCofactor();} // one of these two needs to be overriden - virtual Integer GetCofactor() const {return GetGroupOrder()/GetSubgroupOrder();} - virtual unsigned int GetEncodedElementSize(bool reversible) const =0; - virtual void EncodeElement(bool reversible, const Element &element, byte *encoded) const =0; - virtual Element DecodeElement(const byte *encoded, bool checkForGroupMembership) const =0; - virtual Integer ConvertElementToInteger(const Element &element) const =0; - virtual bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const =0; - virtual bool ValidateElement(unsigned int level, const Element &element, const DL_FixedBasePrecomputation *precomp) const =0; - virtual bool FastSubgroupCheckAvailable() const =0; - virtual bool IsIdentity(const Element &element) const =0; - virtual void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const =0; - -protected: - void ParametersChanged() {m_validationLevel = 0;} - -private: - mutable unsigned int m_validationLevel; -}; - -//! _ -template , class BASE = DL_GroupParameters > -class DL_GroupParametersImpl : public BASE -{ -public: - typedef GROUP_PRECOMP GroupPrecomputation; - typedef typename GROUP_PRECOMP::Element Element; - typedef BASE_PRECOMP BasePrecomputation; - - const DL_GroupPrecomputation & GetGroupPrecomputation() const {return m_groupPrecomputation;} - const DL_FixedBasePrecomputation & GetBasePrecomputation() const {return m_gpc;} - DL_FixedBasePrecomputation & AccessBasePrecomputation() {return m_gpc;} - -protected: - GROUP_PRECOMP m_groupPrecomputation; - BASE_PRECOMP m_gpc; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE DL_Key -{ -public: - virtual const DL_GroupParameters & GetAbstractGroupParameters() const =0; - virtual DL_GroupParameters & AccessAbstractGroupParameters() =0; -}; - -//! interface for DL public keys -template -class CRYPTOPP_NO_VTABLE DL_PublicKey : public DL_Key -{ - typedef DL_PublicKey ThisClass; - -public: - typedef T Element; - - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const - { - return GetValueHelper(this, name, valueType, pValue, &this->GetAbstractGroupParameters()) - CRYPTOPP_GET_FUNCTION_ENTRY(PublicElement); - } - - void AssignFrom(const NameValuePairs &source); - - // non-inherited - virtual const Element & GetPublicElement() const {return GetPublicPrecomputation().GetBase(this->GetAbstractGroupParameters().GetGroupPrecomputation());} - virtual void SetPublicElement(const Element &y) {AccessPublicPrecomputation().SetBase(this->GetAbstractGroupParameters().GetGroupPrecomputation(), y);} - virtual Element ExponentiatePublicElement(const Integer &exponent) const - { - const DL_GroupParameters ¶ms = this->GetAbstractGroupParameters(); - return GetPublicPrecomputation().Exponentiate(params.GetGroupPrecomputation(), exponent); - } - virtual Element CascadeExponentiateBaseAndPublicElement(const Integer &baseExp, const Integer &publicExp) const - { - const DL_GroupParameters ¶ms = this->GetAbstractGroupParameters(); - return params.GetBasePrecomputation().CascadeExponentiate(params.GetGroupPrecomputation(), baseExp, GetPublicPrecomputation(), publicExp); - } - - virtual const DL_FixedBasePrecomputation & GetPublicPrecomputation() const =0; - virtual DL_FixedBasePrecomputation & AccessPublicPrecomputation() =0; -}; - -//! interface for DL private keys -template -class CRYPTOPP_NO_VTABLE DL_PrivateKey : public DL_Key -{ - typedef DL_PrivateKey ThisClass; - -public: - typedef T Element; - - void MakePublicKey(DL_PublicKey &pub) const - { - pub.AccessAbstractGroupParameters().AssignFrom(this->GetAbstractGroupParameters()); - pub.SetPublicElement(this->GetAbstractGroupParameters().ExponentiateBase(GetPrivateExponent())); - } - - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const - { - return GetValueHelper(this, name, valueType, pValue, &this->GetAbstractGroupParameters()) - CRYPTOPP_GET_FUNCTION_ENTRY(PrivateExponent); - } - - void AssignFrom(const NameValuePairs &source) - { - this->AccessAbstractGroupParameters().AssignFrom(source); - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(PrivateExponent); - } - - virtual const Integer & GetPrivateExponent() const =0; - virtual void SetPrivateExponent(const Integer &x) =0; -}; - -template -void DL_PublicKey::AssignFrom(const NameValuePairs &source) -{ - DL_PrivateKey *pPrivateKey = NULL; - if (source.GetThisPointer(pPrivateKey)) - pPrivateKey->MakePublicKey(*this); - else - { - this->AccessAbstractGroupParameters().AssignFrom(source); - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(PublicElement); - } -} - -class OID; - -//! _ -template -class DL_KeyImpl : public PK -{ -public: - typedef GP GroupParameters; - - O GetAlgorithmID() const {return GetGroupParameters().GetAlgorithmID();} -// void BERDecode(BufferedTransformation &bt) -// {PK::BERDecode(bt);} -// void DEREncode(BufferedTransformation &bt) const -// {PK::DEREncode(bt);} - bool BERDecodeAlgorithmParameters(BufferedTransformation &bt) - {AccessGroupParameters().BERDecode(bt); return true;} - bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const - {GetGroupParameters().DEREncode(bt); return true;} - - const GP & GetGroupParameters() const {return m_groupParameters;} - GP & AccessGroupParameters() {return m_groupParameters;} - -private: - GP m_groupParameters; -}; - -class X509PublicKey; -class PKCS8PrivateKey; - -//! _ -template -class DL_PrivateKeyImpl : public DL_PrivateKey, public DL_KeyImpl -{ -public: - typedef typename GP::Element Element; - - // GeneratableCryptoMaterial - bool Validate(RandomNumberGenerator &rng, unsigned int level) const - { - bool pass = GetAbstractGroupParameters().Validate(rng, level); - - const Integer &q = GetAbstractGroupParameters().GetSubgroupOrder(); - const Integer &x = GetPrivateExponent(); - - pass = pass && x.IsPositive() && x < q; - if (level >= 1) - pass = pass && Integer::Gcd(x, q) == Integer::One(); - return pass; - } - - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const - { - return GetValueHelper >(this, name, valueType, pValue).Assignable(); - } - - void AssignFrom(const NameValuePairs &source) - { - AssignFromHelper >(this, source); - } - - void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms) - { - if (!params.GetThisObject(this->AccessGroupParameters())) - this->AccessGroupParameters().GenerateRandom(rng, params); -// std::pair seed; - Integer x(rng, Integer::One(), GetAbstractGroupParameters().GetMaxExponent()); -// Integer::ANY, Integer::Zero(), Integer::One(), -// params.GetValue("DeterministicKeyGenerationSeed", seed) ? &seed : NULL); - SetPrivateExponent(x); - } - - bool SupportsPrecomputation() const {return true;} - - void Precompute(unsigned int precomputationStorage=16) - {AccessAbstractGroupParameters().Precompute(precomputationStorage);} - - void LoadPrecomputation(BufferedTransformation &storedPrecomputation) - {AccessAbstractGroupParameters().LoadPrecomputation(storedPrecomputation);} - - void SavePrecomputation(BufferedTransformation &storedPrecomputation) const - {GetAbstractGroupParameters().SavePrecomputation(storedPrecomputation);} - - // DL_Key - const DL_GroupParameters & GetAbstractGroupParameters() const {return this->GetGroupParameters();} - DL_GroupParameters & AccessAbstractGroupParameters() {return this->AccessGroupParameters();} - - // DL_PrivateKey - const Integer & GetPrivateExponent() const {return m_x;} - void SetPrivateExponent(const Integer &x) {m_x = x;} - - // PKCS8PrivateKey - void BERDecodePrivateKey(BufferedTransformation &bt, bool, size_t) - {m_x.BERDecode(bt);} - void DEREncodePrivateKey(BufferedTransformation &bt) const - {m_x.DEREncode(bt);} - -private: - Integer m_x; -}; - -//! _ -template -class DL_PrivateKey_WithSignaturePairwiseConsistencyTest : public BASE -{ -public: - void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms) - { - BASE::GenerateRandom(rng, params); - - if (FIPS_140_2_ComplianceEnabled()) - { - typename SIGNATURE_SCHEME::Signer signer(*this); - typename SIGNATURE_SCHEME::Verifier verifier(signer); - SignaturePairwiseConsistencyTest_FIPS_140_Only(signer, verifier); - } - } -}; - -//! _ -template -class DL_PublicKeyImpl : public DL_PublicKey, public DL_KeyImpl -{ -public: - typedef typename GP::Element Element; - - // CryptoMaterial - bool Validate(RandomNumberGenerator &rng, unsigned int level) const - { - bool pass = GetAbstractGroupParameters().Validate(rng, level); - pass = pass && GetAbstractGroupParameters().ValidateElement(level, this->GetPublicElement(), &GetPublicPrecomputation()); - return pass; - } - - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const - { - return GetValueHelper >(this, name, valueType, pValue).Assignable(); - } - - void AssignFrom(const NameValuePairs &source) - { - AssignFromHelper >(this, source); - } - - bool SupportsPrecomputation() const {return true;} - - void Precompute(unsigned int precomputationStorage=16) - { - AccessAbstractGroupParameters().Precompute(precomputationStorage); - AccessPublicPrecomputation().Precompute(GetAbstractGroupParameters().GetGroupPrecomputation(), GetAbstractGroupParameters().GetSubgroupOrder().BitCount(), precomputationStorage); - } - - void LoadPrecomputation(BufferedTransformation &storedPrecomputation) - { - AccessAbstractGroupParameters().LoadPrecomputation(storedPrecomputation); - AccessPublicPrecomputation().Load(GetAbstractGroupParameters().GetGroupPrecomputation(), storedPrecomputation); - } - - void SavePrecomputation(BufferedTransformation &storedPrecomputation) const - { - GetAbstractGroupParameters().SavePrecomputation(storedPrecomputation); - GetPublicPrecomputation().Save(GetAbstractGroupParameters().GetGroupPrecomputation(), storedPrecomputation); - } - - // DL_Key - const DL_GroupParameters & GetAbstractGroupParameters() const {return this->GetGroupParameters();} - DL_GroupParameters & AccessAbstractGroupParameters() {return this->AccessGroupParameters();} - - // DL_PublicKey - const DL_FixedBasePrecomputation & GetPublicPrecomputation() const {return m_ypc;} - DL_FixedBasePrecomputation & AccessPublicPrecomputation() {return m_ypc;} - - // non-inherited - bool operator==(const DL_PublicKeyImpl &rhs) const - {return this->GetGroupParameters() == rhs.GetGroupParameters() && this->GetPublicElement() == rhs.GetPublicElement();} - -private: - typename GP::BasePrecomputation m_ypc; -}; - -//! interface for Elgamal-like signature algorithms -template -class CRYPTOPP_NO_VTABLE DL_ElgamalLikeSignatureAlgorithm -{ -public: - virtual void Sign(const DL_GroupParameters ¶ms, const Integer &privateKey, const Integer &k, const Integer &e, Integer &r, Integer &s) const =0; - virtual bool Verify(const DL_GroupParameters ¶ms, const DL_PublicKey &publicKey, const Integer &e, const Integer &r, const Integer &s) const =0; - virtual Integer RecoverPresignature(const DL_GroupParameters ¶ms, const DL_PublicKey &publicKey, const Integer &r, const Integer &s) const - {throw NotImplemented("DL_ElgamalLikeSignatureAlgorithm: this signature scheme does not support message recovery");} - virtual size_t RLen(const DL_GroupParameters ¶ms) const - {return params.GetSubgroupOrder().ByteCount();} - virtual size_t SLen(const DL_GroupParameters ¶ms) const - {return params.GetSubgroupOrder().ByteCount();} -}; - -//! interface for DL key agreement algorithms -template -class CRYPTOPP_NO_VTABLE DL_KeyAgreementAlgorithm -{ -public: - typedef T Element; - - virtual Element AgreeWithEphemeralPrivateKey(const DL_GroupParameters ¶ms, const DL_FixedBasePrecomputation &publicPrecomputation, const Integer &privateExponent) const =0; - virtual Element AgreeWithStaticPrivateKey(const DL_GroupParameters ¶ms, const Element &publicElement, bool validateOtherPublicKey, const Integer &privateExponent) const =0; -}; - -//! interface for key derivation algorithms used in DL cryptosystems -template -class CRYPTOPP_NO_VTABLE DL_KeyDerivationAlgorithm -{ -public: - virtual bool ParameterSupported(const char *name) const {return false;} - virtual void Derive(const DL_GroupParameters &groupParams, byte *derivedKey, size_t derivedLength, const T &agreedElement, const T &ephemeralPublicKey, const NameValuePairs &derivationParams) const =0; -}; - -//! interface for symmetric encryption algorithms used in DL cryptosystems -class CRYPTOPP_NO_VTABLE DL_SymmetricEncryptionAlgorithm -{ -public: - virtual bool ParameterSupported(const char *name) const {return false;} - virtual size_t GetSymmetricKeyLength(size_t plaintextLength) const =0; - virtual size_t GetSymmetricCiphertextLength(size_t plaintextLength) const =0; - virtual size_t GetMaxSymmetricPlaintextLength(size_t ciphertextLength) const =0; - virtual void SymmetricEncrypt(RandomNumberGenerator &rng, const byte *key, const byte *plaintext, size_t plaintextLength, byte *ciphertext, const NameValuePairs ¶meters) const =0; - virtual DecodingResult SymmetricDecrypt(const byte *key, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters) const =0; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE DL_Base -{ -protected: - typedef KI KeyInterface; - typedef typename KI::Element Element; - - const DL_GroupParameters & GetAbstractGroupParameters() const {return GetKeyInterface().GetAbstractGroupParameters();} - DL_GroupParameters & AccessAbstractGroupParameters() {return AccessKeyInterface().AccessAbstractGroupParameters();} - - virtual KeyInterface & AccessKeyInterface() =0; - virtual const KeyInterface & GetKeyInterface() const =0; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE DL_SignatureSchemeBase : public INTERFACE, public DL_Base -{ -public: - size_t SignatureLength() const - { - return GetSignatureAlgorithm().RLen(this->GetAbstractGroupParameters()) - + GetSignatureAlgorithm().SLen(this->GetAbstractGroupParameters()); - } - size_t MaxRecoverableLength() const - {return GetMessageEncodingInterface().MaxRecoverableLength(0, GetHashIdentifier().second, GetDigestSize());} - size_t MaxRecoverableLengthFromSignatureLength(size_t signatureLength) const - {assert(false); return 0;} // TODO - - bool IsProbabilistic() const - {return true;} - bool AllowNonrecoverablePart() const - {return GetMessageEncodingInterface().AllowNonrecoverablePart();} - bool RecoverablePartFirst() const - {return GetMessageEncodingInterface().RecoverablePartFirst();} - -protected: - size_t MessageRepresentativeLength() const {return BitsToBytes(MessageRepresentativeBitLength());} - size_t MessageRepresentativeBitLength() const {return this->GetAbstractGroupParameters().GetSubgroupOrder().BitCount();} - - virtual const DL_ElgamalLikeSignatureAlgorithm & GetSignatureAlgorithm() const =0; - virtual const PK_SignatureMessageEncodingMethod & GetMessageEncodingInterface() const =0; - virtual HashIdentifier GetHashIdentifier() const =0; - virtual size_t GetDigestSize() const =0; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE DL_SignerBase : public DL_SignatureSchemeBase > -{ -public: - // for validation testing - void RawSign(const Integer &k, const Integer &e, Integer &r, Integer &s) const - { - const DL_ElgamalLikeSignatureAlgorithm &alg = this->GetSignatureAlgorithm(); - const DL_GroupParameters ¶ms = this->GetAbstractGroupParameters(); - const DL_PrivateKey &key = this->GetKeyInterface(); - - r = params.ConvertElementToInteger(params.ExponentiateBase(k)); - alg.Sign(params, key.GetPrivateExponent(), k, e, r, s); - } - - void InputRecoverableMessage(PK_MessageAccumulator &messageAccumulator, const byte *recoverableMessage, size_t recoverableMessageLength) const - { - PK_MessageAccumulatorBase &ma = static_cast(messageAccumulator); - ma.m_recoverableMessage.Assign(recoverableMessage, recoverableMessageLength); - this->GetMessageEncodingInterface().ProcessRecoverableMessage(ma.AccessHash(), - recoverableMessage, recoverableMessageLength, - ma.m_presignature, ma.m_presignature.size(), - ma.m_semisignature); - } - - size_t SignAndRestart(RandomNumberGenerator &rng, PK_MessageAccumulator &messageAccumulator, byte *signature, bool restart) const - { - this->GetMaterial().DoQuickSanityCheck(); - - PK_MessageAccumulatorBase &ma = static_cast(messageAccumulator); - const DL_ElgamalLikeSignatureAlgorithm &alg = this->GetSignatureAlgorithm(); - const DL_GroupParameters ¶ms = this->GetAbstractGroupParameters(); - const DL_PrivateKey &key = this->GetKeyInterface(); - - SecByteBlock representative(this->MessageRepresentativeLength()); - this->GetMessageEncodingInterface().ComputeMessageRepresentative( - rng, - ma.m_recoverableMessage, ma.m_recoverableMessage.size(), - ma.AccessHash(), this->GetHashIdentifier(), ma.m_empty, - representative, this->MessageRepresentativeBitLength()); - ma.m_empty = true; - Integer e(representative, representative.size()); - - // hash message digest into random number k to prevent reusing the same k on a different messages - // after virtual machine rollback - if (rng.CanIncorporateEntropy()) - rng.IncorporateEntropy(representative, representative.size()); - Integer k(rng, 1, params.GetSubgroupOrder()-1); - Integer r, s; - r = params.ConvertElementToInteger(params.ExponentiateBase(k)); - alg.Sign(params, key.GetPrivateExponent(), k, e, r, s); - - /* - Integer r, s; - if (this->MaxRecoverableLength() > 0) - r.Decode(ma.m_semisignature, ma.m_semisignature.size()); - else - r.Decode(ma.m_presignature, ma.m_presignature.size()); - alg.Sign(params, key.GetPrivateExponent(), ma.m_k, e, r, s); - */ - - size_t rLen = alg.RLen(params); - r.Encode(signature, rLen); - s.Encode(signature+rLen, alg.SLen(params)); - - if (restart) - RestartMessageAccumulator(rng, ma); - - return this->SignatureLength(); - } - -protected: - void RestartMessageAccumulator(RandomNumberGenerator &rng, PK_MessageAccumulatorBase &ma) const - { - // k needs to be generated before hashing for signature schemes with recovery - // but to defend against VM rollbacks we need to generate k after hashing. - // so this code is commented out, since no DL-based signature scheme with recovery - // has been implemented in Crypto++ anyway - /* - const DL_ElgamalLikeSignatureAlgorithm &alg = this->GetSignatureAlgorithm(); - const DL_GroupParameters ¶ms = this->GetAbstractGroupParameters(); - ma.m_k.Randomize(rng, 1, params.GetSubgroupOrder()-1); - ma.m_presignature.New(params.GetEncodedElementSize(false)); - params.ConvertElementToInteger(params.ExponentiateBase(ma.m_k)).Encode(ma.m_presignature, ma.m_presignature.size()); - */ - } -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE DL_VerifierBase : public DL_SignatureSchemeBase > -{ -public: - void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, size_t signatureLength) const - { - PK_MessageAccumulatorBase &ma = static_cast(messageAccumulator); - const DL_ElgamalLikeSignatureAlgorithm &alg = this->GetSignatureAlgorithm(); - const DL_GroupParameters ¶ms = this->GetAbstractGroupParameters(); - - size_t rLen = alg.RLen(params); - ma.m_semisignature.Assign(signature, rLen); - ma.m_s.Decode(signature+rLen, alg.SLen(params)); - - this->GetMessageEncodingInterface().ProcessSemisignature(ma.AccessHash(), ma.m_semisignature, ma.m_semisignature.size()); - } - - bool VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const - { - this->GetMaterial().DoQuickSanityCheck(); - - PK_MessageAccumulatorBase &ma = static_cast(messageAccumulator); - const DL_ElgamalLikeSignatureAlgorithm &alg = this->GetSignatureAlgorithm(); - const DL_GroupParameters ¶ms = this->GetAbstractGroupParameters(); - const DL_PublicKey &key = this->GetKeyInterface(); - - SecByteBlock representative(this->MessageRepresentativeLength()); - this->GetMessageEncodingInterface().ComputeMessageRepresentative(NullRNG(), ma.m_recoverableMessage, ma.m_recoverableMessage.size(), - ma.AccessHash(), this->GetHashIdentifier(), ma.m_empty, - representative, this->MessageRepresentativeBitLength()); - ma.m_empty = true; - Integer e(representative, representative.size()); - - Integer r(ma.m_semisignature, ma.m_semisignature.size()); - return alg.Verify(params, key, e, r, ma.m_s); - } - - DecodingResult RecoverAndRestart(byte *recoveredMessage, PK_MessageAccumulator &messageAccumulator) const - { - this->GetMaterial().DoQuickSanityCheck(); - - PK_MessageAccumulatorBase &ma = static_cast(messageAccumulator); - const DL_ElgamalLikeSignatureAlgorithm &alg = this->GetSignatureAlgorithm(); - const DL_GroupParameters ¶ms = this->GetAbstractGroupParameters(); - const DL_PublicKey &key = this->GetKeyInterface(); - - SecByteBlock representative(this->MessageRepresentativeLength()); - this->GetMessageEncodingInterface().ComputeMessageRepresentative( - NullRNG(), - ma.m_recoverableMessage, ma.m_recoverableMessage.size(), - ma.AccessHash(), this->GetHashIdentifier(), ma.m_empty, - representative, this->MessageRepresentativeBitLength()); - ma.m_empty = true; - Integer e(representative, representative.size()); - - ma.m_presignature.New(params.GetEncodedElementSize(false)); - Integer r(ma.m_semisignature, ma.m_semisignature.size()); - alg.RecoverPresignature(params, key, r, ma.m_s).Encode(ma.m_presignature, ma.m_presignature.size()); - - return this->GetMessageEncodingInterface().RecoverMessageFromSemisignature( - ma.AccessHash(), this->GetHashIdentifier(), - ma.m_presignature, ma.m_presignature.size(), - ma.m_semisignature, ma.m_semisignature.size(), - recoveredMessage); - } -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE DL_CryptoSystemBase : public PK, public DL_Base -{ -public: - typedef typename DL_Base::Element Element; - - size_t MaxPlaintextLength(size_t ciphertextLength) const - { - unsigned int minLen = this->GetAbstractGroupParameters().GetEncodedElementSize(true); - return ciphertextLength < minLen ? 0 : GetSymmetricEncryptionAlgorithm().GetMaxSymmetricPlaintextLength(ciphertextLength - minLen); - } - - size_t CiphertextLength(size_t plaintextLength) const - { - size_t len = GetSymmetricEncryptionAlgorithm().GetSymmetricCiphertextLength(plaintextLength); - return len == 0 ? 0 : this->GetAbstractGroupParameters().GetEncodedElementSize(true) + len; - } - - bool ParameterSupported(const char *name) const - {return GetKeyDerivationAlgorithm().ParameterSupported(name) || GetSymmetricEncryptionAlgorithm().ParameterSupported(name);} - -protected: - virtual const DL_KeyAgreementAlgorithm & GetKeyAgreementAlgorithm() const =0; - virtual const DL_KeyDerivationAlgorithm & GetKeyDerivationAlgorithm() const =0; - virtual const DL_SymmetricEncryptionAlgorithm & GetSymmetricEncryptionAlgorithm() const =0; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE DL_DecryptorBase : public DL_CryptoSystemBase > -{ -public: - typedef T Element; - - DecodingResult Decrypt(RandomNumberGenerator &rng, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters = g_nullNameValuePairs) const - { - try - { - const DL_KeyAgreementAlgorithm &agreeAlg = this->GetKeyAgreementAlgorithm(); - const DL_KeyDerivationAlgorithm &derivAlg = this->GetKeyDerivationAlgorithm(); - const DL_SymmetricEncryptionAlgorithm &encAlg = this->GetSymmetricEncryptionAlgorithm(); - const DL_GroupParameters ¶ms = this->GetAbstractGroupParameters(); - const DL_PrivateKey &key = this->GetKeyInterface(); - - Element q = params.DecodeElement(ciphertext, true); - size_t elementSize = params.GetEncodedElementSize(true); - ciphertext += elementSize; - ciphertextLength -= elementSize; - - Element z = agreeAlg.AgreeWithStaticPrivateKey(params, q, true, key.GetPrivateExponent()); - - SecByteBlock derivedKey(encAlg.GetSymmetricKeyLength(encAlg.GetMaxSymmetricPlaintextLength(ciphertextLength))); - derivAlg.Derive(params, derivedKey, derivedKey.size(), z, q, parameters); - - return encAlg.SymmetricDecrypt(derivedKey, ciphertext, ciphertextLength, plaintext, parameters); - } - catch (DL_BadElement &) - { - return DecodingResult(); - } - } -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE DL_EncryptorBase : public DL_CryptoSystemBase > -{ -public: - typedef T Element; - - void Encrypt(RandomNumberGenerator &rng, const byte *plaintext, size_t plaintextLength, byte *ciphertext, const NameValuePairs ¶meters = g_nullNameValuePairs) const - { - const DL_KeyAgreementAlgorithm &agreeAlg = this->GetKeyAgreementAlgorithm(); - const DL_KeyDerivationAlgorithm &derivAlg = this->GetKeyDerivationAlgorithm(); - const DL_SymmetricEncryptionAlgorithm &encAlg = this->GetSymmetricEncryptionAlgorithm(); - const DL_GroupParameters ¶ms = this->GetAbstractGroupParameters(); - const DL_PublicKey &key = this->GetKeyInterface(); - - Integer x(rng, Integer::One(), params.GetMaxExponent()); - Element q = params.ExponentiateBase(x); - params.EncodeElement(true, q, ciphertext); - unsigned int elementSize = params.GetEncodedElementSize(true); - ciphertext += elementSize; - - Element z = agreeAlg.AgreeWithEphemeralPrivateKey(params, key.GetPublicPrecomputation(), x); - - SecByteBlock derivedKey(encAlg.GetSymmetricKeyLength(plaintextLength)); - derivAlg.Derive(params, derivedKey, derivedKey.size(), z, q, parameters); - - encAlg.SymmetricEncrypt(rng, derivedKey, plaintext, plaintextLength, ciphertext, parameters); - } -}; - -//! _ -template -struct DL_SchemeOptionsBase -{ - typedef T1 AlgorithmInfo; - typedef T2 GroupParameters; - typedef typename GroupParameters::Element Element; -}; - -//! _ -template -struct DL_KeyedSchemeOptions : public DL_SchemeOptionsBase -{ - typedef T2 Keys; - typedef typename Keys::PrivateKey PrivateKey; - typedef typename Keys::PublicKey PublicKey; -}; - -//! _ -template -struct DL_SignatureSchemeOptions : public DL_KeyedSchemeOptions -{ - typedef T3 SignatureAlgorithm; - typedef T4 MessageEncodingMethod; - typedef T5 HashFunction; -}; - -//! _ -template -struct DL_CryptoSchemeOptions : public DL_KeyedSchemeOptions -{ - typedef T3 KeyAgreementAlgorithm; - typedef T4 KeyDerivationAlgorithm; - typedef T5 SymmetricEncryptionAlgorithm; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE DL_ObjectImplBase : public AlgorithmImpl -{ -public: - typedef SCHEME_OPTIONS SchemeOptions; - typedef typename KEY::Element Element; - - PrivateKey & AccessPrivateKey() {return m_key;} - PublicKey & AccessPublicKey() {return m_key;} - - // KeyAccessor - const KEY & GetKey() const {return m_key;} - KEY & AccessKey() {return m_key;} - -protected: - typename BASE::KeyInterface & AccessKeyInterface() {return m_key;} - const typename BASE::KeyInterface & GetKeyInterface() const {return m_key;} - - // for signature scheme - HashIdentifier GetHashIdentifier() const - { - typedef typename SchemeOptions::MessageEncodingMethod::HashIdentifierLookup HashLookup; - return HashLookup::template HashIdentifierLookup2::Lookup(); - } - size_t GetDigestSize() const - { - typedef CPP_TYPENAME SchemeOptions::HashFunction H; - return H::DIGESTSIZE; - } - -private: - KEY m_key; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE DL_ObjectImpl : public DL_ObjectImplBase -{ -public: - typedef typename KEY::Element Element; - -protected: - const DL_ElgamalLikeSignatureAlgorithm & GetSignatureAlgorithm() const - {return Singleton().Ref();} - const DL_KeyAgreementAlgorithm & GetKeyAgreementAlgorithm() const - {return Singleton().Ref();} - const DL_KeyDerivationAlgorithm & GetKeyDerivationAlgorithm() const - {return Singleton().Ref();} - const DL_SymmetricEncryptionAlgorithm & GetSymmetricEncryptionAlgorithm() const - {return Singleton().Ref();} - HashIdentifier GetHashIdentifier() const - {return HashIdentifier();} - const PK_SignatureMessageEncodingMethod & GetMessageEncodingInterface() const - {return Singleton().Ref();} -}; - -//! _ -template -class DL_SignerImpl : public DL_ObjectImpl, SCHEME_OPTIONS, typename SCHEME_OPTIONS::PrivateKey> -{ -public: - PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng) const - { - std::auto_ptr p(new PK_MessageAccumulatorImpl); - this->RestartMessageAccumulator(rng, *p); - return p.release(); - } -}; - -//! _ -template -class DL_VerifierImpl : public DL_ObjectImpl, SCHEME_OPTIONS, typename SCHEME_OPTIONS::PublicKey> -{ -public: - PK_MessageAccumulator * NewVerificationAccumulator() const - { - return new PK_MessageAccumulatorImpl; - } -}; - -//! _ -template -class DL_EncryptorImpl : public DL_ObjectImpl, SCHEME_OPTIONS, typename SCHEME_OPTIONS::PublicKey> -{ -}; - -//! _ -template -class DL_DecryptorImpl : public DL_ObjectImpl, SCHEME_OPTIONS, typename SCHEME_OPTIONS::PrivateKey> -{ -}; - -// ******************************************************** - -//! _ -template -class CRYPTOPP_NO_VTABLE DL_SimpleKeyAgreementDomainBase : public SimpleKeyAgreementDomain -{ -public: - typedef T Element; - - CryptoParameters & AccessCryptoParameters() {return AccessAbstractGroupParameters();} - unsigned int AgreedValueLength() const {return GetAbstractGroupParameters().GetEncodedElementSize(false);} - unsigned int PrivateKeyLength() const {return GetAbstractGroupParameters().GetSubgroupOrder().ByteCount();} - unsigned int PublicKeyLength() const {return GetAbstractGroupParameters().GetEncodedElementSize(true);} - - void GeneratePrivateKey(RandomNumberGenerator &rng, byte *privateKey) const - { - Integer x(rng, Integer::One(), GetAbstractGroupParameters().GetMaxExponent()); - x.Encode(privateKey, PrivateKeyLength()); - } - - void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const - { - const DL_GroupParameters ¶ms = GetAbstractGroupParameters(); - Integer x(privateKey, PrivateKeyLength()); - Element y = params.ExponentiateBase(x); - params.EncodeElement(true, y, publicKey); - } - - bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const - { - try - { - const DL_GroupParameters ¶ms = GetAbstractGroupParameters(); - Integer x(privateKey, PrivateKeyLength()); - Element w = params.DecodeElement(otherPublicKey, validateOtherPublicKey); - - Element z = GetKeyAgreementAlgorithm().AgreeWithStaticPrivateKey( - GetAbstractGroupParameters(), w, validateOtherPublicKey, x); - params.EncodeElement(false, z, agreedValue); - } - catch (DL_BadElement &) - { - return false; - } - return true; - } - - const Element &GetGenerator() const {return GetAbstractGroupParameters().GetSubgroupGenerator();} - -protected: - virtual const DL_KeyAgreementAlgorithm & GetKeyAgreementAlgorithm() const =0; - virtual DL_GroupParameters & AccessAbstractGroupParameters() =0; - const DL_GroupParameters & GetAbstractGroupParameters() const {return const_cast *>(this)->AccessAbstractGroupParameters();} -}; - -enum CofactorMultiplicationOption {NO_COFACTOR_MULTIPLICTION, COMPATIBLE_COFACTOR_MULTIPLICTION, INCOMPATIBLE_COFACTOR_MULTIPLICTION}; -typedef EnumToType NoCofactorMultiplication; -typedef EnumToType CompatibleCofactorMultiplication; -typedef EnumToType IncompatibleCofactorMultiplication; - -//! DH key agreement algorithm -template -class DL_KeyAgreementAlgorithm_DH : public DL_KeyAgreementAlgorithm -{ -public: - typedef ELEMENT Element; - - static const char * CRYPTOPP_API StaticAlgorithmName() - {return COFACTOR_OPTION::ToEnum() == INCOMPATIBLE_COFACTOR_MULTIPLICTION ? "DHC" : "DH";} - - Element AgreeWithEphemeralPrivateKey(const DL_GroupParameters ¶ms, const DL_FixedBasePrecomputation &publicPrecomputation, const Integer &privateExponent) const - { - return publicPrecomputation.Exponentiate(params.GetGroupPrecomputation(), - COFACTOR_OPTION::ToEnum() == INCOMPATIBLE_COFACTOR_MULTIPLICTION ? privateExponent*params.GetCofactor() : privateExponent); - } - - Element AgreeWithStaticPrivateKey(const DL_GroupParameters ¶ms, const Element &publicElement, bool validateOtherPublicKey, const Integer &privateExponent) const - { - if (COFACTOR_OPTION::ToEnum() == COMPATIBLE_COFACTOR_MULTIPLICTION) - { - const Integer &k = params.GetCofactor(); - return params.ExponentiateElement(publicElement, - ModularArithmetic(params.GetSubgroupOrder()).Divide(privateExponent, k)*k); - } - else if (COFACTOR_OPTION::ToEnum() == INCOMPATIBLE_COFACTOR_MULTIPLICTION) - return params.ExponentiateElement(publicElement, privateExponent*params.GetCofactor()); - else - { - assert(COFACTOR_OPTION::ToEnum() == NO_COFACTOR_MULTIPLICTION); - - if (!validateOtherPublicKey) - return params.ExponentiateElement(publicElement, privateExponent); - - if (params.FastSubgroupCheckAvailable()) - { - if (!params.ValidateElement(2, publicElement, NULL)) - throw DL_BadElement(); - return params.ExponentiateElement(publicElement, privateExponent); - } - else - { - const Integer e[2] = {params.GetSubgroupOrder(), privateExponent}; - Element r[2]; - params.SimultaneousExponentiate(r, publicElement, e, 2); - if (!params.IsIdentity(r[0])) - throw DL_BadElement(); - return r[1]; - } - } - } -}; - -// ******************************************************** - -//! A template implementing constructors for public key algorithm classes -template -class CRYPTOPP_NO_VTABLE PK_FinalTemplate : public BASE -{ -public: - PK_FinalTemplate() {} - - PK_FinalTemplate(const CryptoMaterial &key) - {this->AccessKey().AssignFrom(key);} - - PK_FinalTemplate(BufferedTransformation &bt) - {this->AccessKey().BERDecode(bt);} - - PK_FinalTemplate(const AsymmetricAlgorithm &algorithm) - {this->AccessKey().AssignFrom(algorithm.GetMaterial());} - - PK_FinalTemplate(const Integer &v1) - {this->AccessKey().Initialize(v1);} - -#if (defined(_MSC_VER) && _MSC_VER < 1300) - - template - PK_FinalTemplate(T1 &v1, T2 &v2) - {this->AccessKey().Initialize(v1, v2);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3) - {this->AccessKey().Initialize(v1, v2, v3);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4) - {this->AccessKey().Initialize(v1, v2, v3, v4);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6, T7 &v7) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6, T7 &v7, T8 &v8) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);} - -#else - - template - PK_FinalTemplate(const T1 &v1, const T2 &v2) - {this->AccessKey().Initialize(v1, v2);} - - template - PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3) - {this->AccessKey().Initialize(v1, v2, v3);} - - template - PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4) - {this->AccessKey().Initialize(v1, v2, v3, v4);} - - template - PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5);} - - template - PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6);} - - template - PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);} - - template - PK_FinalTemplate(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7, const T8 &v8) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);} - - template - PK_FinalTemplate(T1 &v1, const T2 &v2) - {this->AccessKey().Initialize(v1, v2);} - - template - PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3) - {this->AccessKey().Initialize(v1, v2, v3);} - - template - PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4) - {this->AccessKey().Initialize(v1, v2, v3, v4);} - - template - PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5);} - - template - PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6);} - - template - PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);} - - template - PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7, const T8 &v8) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);} - -#endif -}; - -//! Base class for public key encryption standard classes. These classes are used to select from variants of algorithms. Note that not all standards apply to all algorithms. -struct EncryptionStandard {}; - -//! Base class for public key signature standard classes. These classes are used to select from variants of algorithms. Note that not all standards apply to all algorithms. -struct SignatureStandard {}; - -template -class TF_ES; - -//! Trapdoor Function Based Encryption Scheme -template > -class TF_ES : public KEYS -{ - typedef typename STANDARD::EncryptionMessageEncodingMethod MessageEncodingMethod; - -public: - //! see EncryptionStandard for a list of standards - typedef STANDARD Standard; - typedef TF_CryptoSchemeOptions SchemeOptions; - - static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string(KEYS::StaticAlgorithmName()) + "/" + MessageEncodingMethod::StaticAlgorithmName();} - - //! implements PK_Decryptor interface - typedef PK_FinalTemplate > Decryptor; - //! implements PK_Encryptor interface - typedef PK_FinalTemplate > Encryptor; -}; - -template // VC60 workaround: doesn't work if KEYS is first parameter -class TF_SS; - -//! Trapdoor Function Based Signature Scheme -template > // VC60 workaround: doesn't work if KEYS is first parameter -class TF_SS : public KEYS -{ -public: - //! see SignatureStandard for a list of standards - typedef STANDARD Standard; - typedef typename Standard::SignatureMessageEncodingMethod MessageEncodingMethod; - typedef TF_SignatureSchemeOptions SchemeOptions; - - static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string(KEYS::StaticAlgorithmName()) + "/" + MessageEncodingMethod::StaticAlgorithmName() + "(" + H::StaticAlgorithmName() + ")";} - - //! implements PK_Signer interface - typedef PK_FinalTemplate > Signer; - //! implements PK_Verifier interface - typedef PK_FinalTemplate > Verifier; -}; - -template -class DL_SS; - -//! Discrete Log Based Signature Scheme -template > -class DL_SS : public KEYS -{ - typedef DL_SignatureSchemeOptions SchemeOptions; - -public: - static std::string StaticAlgorithmName() {return SA::StaticAlgorithmName() + std::string("/EMSA1(") + H::StaticAlgorithmName() + ")";} - - //! implements PK_Signer interface - typedef PK_FinalTemplate > Signer; - //! implements PK_Verifier interface - typedef PK_FinalTemplate > Verifier; -}; - -//! Discrete Log Based Encryption Scheme -template -class DL_ES : public KEYS -{ - typedef DL_CryptoSchemeOptions SchemeOptions; - -public: - //! implements PK_Decryptor interface - typedef PK_FinalTemplate > Decryptor; - //! implements PK_Encryptor interface - typedef PK_FinalTemplate > Encryptor; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/pwdbased.h b/lib/cryptopp/pwdbased.h deleted file mode 100644 index f755724b1..000000000 --- a/lib/cryptopp/pwdbased.h +++ /dev/null @@ -1,214 +0,0 @@ -// pwdbased.h - written and placed in the public domain by Wei Dai - -#ifndef CRYPTOPP_PWDBASED_H -#define CRYPTOPP_PWDBASED_H - -#include "cryptlib.h" -#include "hmac.h" -#include "hrtimer.h" -#include "integer.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! abstract base class for password based key derivation function -class PasswordBasedKeyDerivationFunction -{ -public: - virtual size_t MaxDerivedKeyLength() const =0; - virtual bool UsesPurposeByte() const =0; - //! derive key from password - /*! If timeInSeconds != 0, will iterate until time elapsed, as measured by ThreadUserTimer - Returns actual iteration count, which is equal to iterations if timeInSeconds == 0, and not less than iterations otherwise. */ - virtual unsigned int DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds=0) const =0; -}; - -//! PBKDF1 from PKCS #5, T should be a HashTransformation class -template -class PKCS5_PBKDF1 : public PasswordBasedKeyDerivationFunction -{ -public: - size_t MaxDerivedKeyLength() const {return T::DIGESTSIZE;} - bool UsesPurposeByte() const {return false;} - // PKCS #5 says PBKDF1 should only take 8-byte salts. This implementation allows salts of any length. - unsigned int DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds=0) const; -}; - -//! PBKDF2 from PKCS #5, T should be a HashTransformation class -template -class PKCS5_PBKDF2_HMAC : public PasswordBasedKeyDerivationFunction -{ -public: - size_t MaxDerivedKeyLength() const {return 0xffffffffU;} // should multiply by T::DIGESTSIZE, but gets overflow that way - bool UsesPurposeByte() const {return false;} - unsigned int DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds=0) const; -}; - -/* -class PBKDF2Params -{ -public: - SecByteBlock m_salt; - unsigned int m_interationCount; - ASNOptional > m_keyLength; -}; -*/ - -template -unsigned int PKCS5_PBKDF1::DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const -{ - assert(derivedLen <= MaxDerivedKeyLength()); - assert(iterations > 0 || timeInSeconds > 0); - - if (!iterations) - iterations = 1; - - T hash; - hash.Update(password, passwordLen); - hash.Update(salt, saltLen); - - SecByteBlock buffer(hash.DigestSize()); - hash.Final(buffer); - - unsigned int i; - ThreadUserTimer timer; - - if (timeInSeconds) - timer.StartTimer(); - - for (i=1; i -unsigned int PKCS5_PBKDF2_HMAC::DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const -{ - assert(derivedLen <= MaxDerivedKeyLength()); - assert(iterations > 0 || timeInSeconds > 0); - - if (!iterations) - iterations = 1; - - HMAC hmac(password, passwordLen); - SecByteBlock buffer(hmac.DigestSize()); - ThreadUserTimer timer; - - unsigned int i=1; - while (derivedLen > 0) - { - hmac.Update(salt, saltLen); - unsigned int j; - for (j=0; j<4; j++) - { - byte b = byte(i >> ((3-j)*8)); - hmac.Update(&b, 1); - } - hmac.Final(buffer); - - size_t segmentLen = STDMIN(derivedLen, buffer.size()); - memcpy(derived, buffer, segmentLen); - - if (timeInSeconds) - { - timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); - timer.StartTimer(); - } - - for (j=1; j -class PKCS12_PBKDF : public PasswordBasedKeyDerivationFunction -{ -public: - size_t MaxDerivedKeyLength() const {return size_t(0)-1;} - bool UsesPurposeByte() const {return true;} - unsigned int DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const; -}; - -template -unsigned int PKCS12_PBKDF::DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const -{ - assert(derivedLen <= MaxDerivedKeyLength()); - assert(iterations > 0 || timeInSeconds > 0); - - if (!iterations) - iterations = 1; - - const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 - const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); - const size_t PLen = RoundUpToMultipleOf(passwordLen, v), ILen = SLen + PLen; - SecByteBlock buffer(DLen + SLen + PLen); - byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; - - memset(D, purpose, DLen); - size_t i; - for (i=0; i 0) - { - hash.CalculateDigest(Ai, buffer, buffer.size()); - - if (timeInSeconds) - { - timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); - timer.StartTimer(); - } - - for (i=1; inext; current; current=current->next) - { - m_tail->next = new ByteQueueNode(*current); - m_tail = m_tail->next; - } - - m_tail->next = NULL; - - Put(copy.m_lazyString, copy.m_lazyLength); -} - -ByteQueue::~ByteQueue() -{ - Destroy(); -} - -void ByteQueue::Destroy() -{ - for (ByteQueueNode *next, *current=m_head; current; current=next) - { - next=current->next; - delete current; - } -} - -void ByteQueue::IsolatedInitialize(const NameValuePairs ¶meters) -{ - m_nodeSize = parameters.GetIntValueWithDefault("NodeSize", 256); - Clear(); -} - -lword ByteQueue::CurrentSize() const -{ - lword size=0; - - for (ByteQueueNode *current=m_head; current; current=current->next) - size += current->CurrentSize(); - - return size + m_lazyLength; -} - -bool ByteQueue::IsEmpty() const -{ - return m_head==m_tail && m_head->CurrentSize()==0 && m_lazyLength==0; -} - -void ByteQueue::Clear() -{ - for (ByteQueueNode *next, *current=m_head->next; current; current=next) - { - next=current->next; - delete current; - } - - m_tail = m_head; - m_head->Clear(); - m_head->next = NULL; - m_lazyLength = 0; -} - -size_t ByteQueue::Put2(const byte *inString, size_t length, int messageEnd, bool blocking) -{ - if (m_lazyLength > 0) - FinalizeLazyPut(); - - size_t len; - while ((len=m_tail->Put(inString, length)) < length) - { - inString += len; - length -= len; - if (m_autoNodeSize && m_nodeSize < s_maxAutoNodeSize) - do - { - m_nodeSize *= 2; - } - while (m_nodeSize < length && m_nodeSize < s_maxAutoNodeSize); - m_tail->next = new ByteQueueNode(STDMAX(m_nodeSize, length)); - m_tail = m_tail->next; - } - - return 0; -} - -void ByteQueue::CleanupUsedNodes() -{ - while (m_head != m_tail && m_head->UsedUp()) - { - ByteQueueNode *temp=m_head; - m_head=m_head->next; - delete temp; - } - - if (m_head->CurrentSize() == 0) - m_head->Clear(); -} - -void ByteQueue::LazyPut(const byte *inString, size_t size) -{ - if (m_lazyLength > 0) - FinalizeLazyPut(); - - if (inString == m_tail->buf+m_tail->m_tail) - Put(inString, size); - else - { - m_lazyString = const_cast(inString); - m_lazyLength = size; - m_lazyStringModifiable = false; - } -} - -void ByteQueue::LazyPutModifiable(byte *inString, size_t size) -{ - if (m_lazyLength > 0) - FinalizeLazyPut(); - m_lazyString = inString; - m_lazyLength = size; - m_lazyStringModifiable = true; -} - -void ByteQueue::UndoLazyPut(size_t size) -{ - if (m_lazyLength < size) - throw InvalidArgument("ByteQueue: size specified for UndoLazyPut is too large"); - - m_lazyLength -= size; -} - -void ByteQueue::FinalizeLazyPut() -{ - size_t len = m_lazyLength; - m_lazyLength = 0; - if (len) - Put(m_lazyString, len); -} - -size_t ByteQueue::Get(byte &outByte) -{ - if (m_head->Get(outByte)) - { - if (m_head->UsedUp()) - CleanupUsedNodes(); - return 1; - } - else if (m_lazyLength > 0) - { - outByte = *m_lazyString++; - m_lazyLength--; - return 1; - } - else - return 0; -} - -size_t ByteQueue::Get(byte *outString, size_t getMax) -{ - ArraySink sink(outString, getMax); - return (size_t)TransferTo(sink, getMax); -} - -size_t ByteQueue::Peek(byte &outByte) const -{ - if (m_head->Peek(outByte)) - return 1; - else if (m_lazyLength > 0) - { - outByte = *m_lazyString; - return 1; - } - else - return 0; -} - -size_t ByteQueue::Peek(byte *outString, size_t peekMax) const -{ - ArraySink sink(outString, peekMax); - return (size_t)CopyTo(sink, peekMax); -} - -size_t ByteQueue::TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel, bool blocking) -{ - if (blocking) - { - lword bytesLeft = transferBytes; - for (ByteQueueNode *current=m_head; bytesLeft && current; current=current->next) - bytesLeft -= current->TransferTo(target, bytesLeft, channel); - CleanupUsedNodes(); - - size_t len = (size_t)STDMIN(bytesLeft, (lword)m_lazyLength); - if (len) - { - if (m_lazyStringModifiable) - target.ChannelPutModifiable(channel, m_lazyString, len); - else - target.ChannelPut(channel, m_lazyString, len); - m_lazyString += len; - m_lazyLength -= len; - bytesLeft -= len; - } - transferBytes -= bytesLeft; - return 0; - } - else - { - Walker walker(*this); - size_t blockedBytes = walker.TransferTo2(target, transferBytes, channel, blocking); - Skip(transferBytes); - return blockedBytes; - } -} - -size_t ByteQueue::CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end, const std::string &channel, bool blocking) const -{ - Walker walker(*this); - walker.Skip(begin); - lword transferBytes = end-begin; - size_t blockedBytes = walker.TransferTo2(target, transferBytes, channel, blocking); - begin += transferBytes; - return blockedBytes; -} - -void ByteQueue::Unget(byte inByte) -{ - Unget(&inByte, 1); -} - -void ByteQueue::Unget(const byte *inString, size_t length) -{ - size_t len = STDMIN(length, m_head->m_head); - length -= len; - m_head->m_head -= len; - memcpy(m_head->buf + m_head->m_head, inString + length, len); - - if (length > 0) - { - ByteQueueNode *newHead = new ByteQueueNode(length); - newHead->next = m_head; - m_head = newHead; - m_head->Put(inString, length); - } -} - -const byte * ByteQueue::Spy(size_t &contiguousSize) const -{ - contiguousSize = m_head->m_tail - m_head->m_head; - if (contiguousSize == 0 && m_lazyLength > 0) - { - contiguousSize = m_lazyLength; - return m_lazyString; - } - else - return m_head->buf + m_head->m_head; -} - -byte * ByteQueue::CreatePutSpace(size_t &size) -{ - if (m_lazyLength > 0) - FinalizeLazyPut(); - - if (m_tail->m_tail == m_tail->MaxSize()) - { - m_tail->next = new ByteQueueNode(STDMAX(m_nodeSize, size)); - m_tail = m_tail->next; - } - - size = m_tail->MaxSize() - m_tail->m_tail; - return m_tail->buf + m_tail->m_tail; -} - -ByteQueue & ByteQueue::operator=(const ByteQueue &rhs) -{ - Destroy(); - CopyFrom(rhs); - return *this; -} - -bool ByteQueue::operator==(const ByteQueue &rhs) const -{ - const lword currentSize = CurrentSize(); - - if (currentSize != rhs.CurrentSize()) - return false; - - Walker walker1(*this), walker2(rhs); - byte b1, b2; - - while (walker1.Get(b1) && walker2.Get(b2)) - if (b1 != b2) - return false; - - return true; -} - -byte ByteQueue::operator[](lword i) const -{ - for (ByteQueueNode *current=m_head; current; current=current->next) - { - if (i < current->CurrentSize()) - return (*current)[(size_t)i]; - - i -= current->CurrentSize(); - } - - assert(i < m_lazyLength); - return m_lazyString[i]; -} - -void ByteQueue::swap(ByteQueue &rhs) -{ - std::swap(m_autoNodeSize, rhs.m_autoNodeSize); - std::swap(m_nodeSize, rhs.m_nodeSize); - std::swap(m_head, rhs.m_head); - std::swap(m_tail, rhs.m_tail); - std::swap(m_lazyString, rhs.m_lazyString); - std::swap(m_lazyLength, rhs.m_lazyLength); - std::swap(m_lazyStringModifiable, rhs.m_lazyStringModifiable); -} - -// ******************************************************** - -void ByteQueue::Walker::IsolatedInitialize(const NameValuePairs ¶meters) -{ - m_node = m_queue.m_head; - m_position = 0; - m_offset = 0; - m_lazyString = m_queue.m_lazyString; - m_lazyLength = m_queue.m_lazyLength; -} - -size_t ByteQueue::Walker::Get(byte &outByte) -{ - ArraySink sink(&outByte, 1); - return (size_t)TransferTo(sink, 1); -} - -size_t ByteQueue::Walker::Get(byte *outString, size_t getMax) -{ - ArraySink sink(outString, getMax); - return (size_t)TransferTo(sink, getMax); -} - -size_t ByteQueue::Walker::Peek(byte &outByte) const -{ - ArraySink sink(&outByte, 1); - return (size_t)CopyTo(sink, 1); -} - -size_t ByteQueue::Walker::Peek(byte *outString, size_t peekMax) const -{ - ArraySink sink(outString, peekMax); - return (size_t)CopyTo(sink, peekMax); -} - -size_t ByteQueue::Walker::TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel, bool blocking) -{ - lword bytesLeft = transferBytes; - size_t blockedBytes = 0; - - while (m_node) - { - size_t len = (size_t)STDMIN(bytesLeft, (lword)m_node->CurrentSize()-m_offset); - blockedBytes = target.ChannelPut2(channel, m_node->buf+m_node->m_head+m_offset, len, 0, blocking); - - if (blockedBytes) - goto done; - - m_position += len; - bytesLeft -= len; - - if (!bytesLeft) - { - m_offset += len; - goto done; - } - - m_node = m_node->next; - m_offset = 0; - } - - if (bytesLeft && m_lazyLength) - { - size_t len = (size_t)STDMIN(bytesLeft, (lword)m_lazyLength); - blockedBytes = target.ChannelPut2(channel, m_lazyString, len, 0, blocking); - if (blockedBytes) - goto done; - - m_lazyString += len; - m_lazyLength -= len; - bytesLeft -= len; - } - -done: - transferBytes -= bytesLeft; - return blockedBytes; -} - -size_t ByteQueue::Walker::CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end, const std::string &channel, bool blocking) const -{ - Walker walker(*this); - walker.Skip(begin); - lword transferBytes = end-begin; - size_t blockedBytes = walker.TransferTo2(target, transferBytes, channel, blocking); - begin += transferBytes; - return blockedBytes; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/queue.h b/lib/cryptopp/queue.h deleted file mode 100644 index ab89dbdf1..000000000 --- a/lib/cryptopp/queue.h +++ /dev/null @@ -1,144 +0,0 @@ -// specification file for an unlimited queue for storing bytes - -#ifndef CRYPTOPP_QUEUE_H -#define CRYPTOPP_QUEUE_H - -#include "simple.h" -//#include - -NAMESPACE_BEGIN(CryptoPP) - -/** The queue is implemented as a linked list of byte arrays, but you don't need to - know about that. So just ignore this next line. :) */ -class ByteQueueNode; - -//! Byte Queue -class CRYPTOPP_DLL ByteQueue : public Bufferless -{ -public: - ByteQueue(size_t nodeSize=0); - ByteQueue(const ByteQueue ©); - ~ByteQueue(); - - lword MaxRetrievable() const - {return CurrentSize();} - bool AnyRetrievable() const - {return !IsEmpty();} - - void IsolatedInitialize(const NameValuePairs ¶meters); - byte * CreatePutSpace(size_t &size); - size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking); - - size_t Get(byte &outByte); - size_t Get(byte *outString, size_t getMax); - - size_t Peek(byte &outByte) const; - size_t Peek(byte *outString, size_t peekMax) const; - - size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const; - - // these member functions are not inherited - void SetNodeSize(size_t nodeSize); - - lword CurrentSize() const; - bool IsEmpty() const; - - void Clear(); - - void Unget(byte inByte); - void Unget(const byte *inString, size_t length); - - const byte * Spy(size_t &contiguousSize) const; - - void LazyPut(const byte *inString, size_t size); - void LazyPutModifiable(byte *inString, size_t size); - void UndoLazyPut(size_t size); - void FinalizeLazyPut(); - - ByteQueue & operator=(const ByteQueue &rhs); - bool operator==(const ByteQueue &rhs) const; - bool operator!=(const ByteQueue &rhs) const {return !operator==(rhs);} - byte operator[](lword i) const; - void swap(ByteQueue &rhs); - - class Walker : public InputRejecting - { - public: - Walker(const ByteQueue &queue) - : m_queue(queue) {Initialize();} - - lword GetCurrentPosition() {return m_position;} - - lword MaxRetrievable() const - {return m_queue.CurrentSize() - m_position;} - - void IsolatedInitialize(const NameValuePairs ¶meters); - - size_t Get(byte &outByte); - size_t Get(byte *outString, size_t getMax); - - size_t Peek(byte &outByte) const; - size_t Peek(byte *outString, size_t peekMax) const; - - size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const; - - private: - const ByteQueue &m_queue; - const ByteQueueNode *m_node; - lword m_position; - size_t m_offset; - const byte *m_lazyString; - size_t m_lazyLength; - }; - - friend class Walker; - -private: - void CleanupUsedNodes(); - void CopyFrom(const ByteQueue ©); - void Destroy(); - - bool m_autoNodeSize; - size_t m_nodeSize; - ByteQueueNode *m_head, *m_tail; - byte *m_lazyString; - size_t m_lazyLength; - bool m_lazyStringModifiable; -}; - -//! use this to make sure LazyPut is finalized in event of exception -class CRYPTOPP_DLL LazyPutter -{ -public: - LazyPutter(ByteQueue &bq, const byte *inString, size_t size) - : m_bq(bq) {bq.LazyPut(inString, size);} - ~LazyPutter() - {try {m_bq.FinalizeLazyPut();} catch(...) {}} -protected: - LazyPutter(ByteQueue &bq) : m_bq(bq) {} -private: - ByteQueue &m_bq; -}; - -//! like LazyPutter, but does a LazyPutModifiable instead -class LazyPutterModifiable : public LazyPutter -{ -public: - LazyPutterModifiable(ByteQueue &bq, byte *inString, size_t size) - : LazyPutter(bq) {bq.LazyPutModifiable(inString, size);} -}; - -NAMESPACE_END - -#ifndef __BORLANDC__ -NAMESPACE_BEGIN(std) -template<> inline void swap(CryptoPP::ByteQueue &a, CryptoPP::ByteQueue &b) -{ - a.swap(b); -} -NAMESPACE_END -#endif - -#endif diff --git a/lib/cryptopp/rabin.cpp b/lib/cryptopp/rabin.cpp deleted file mode 100644 index d496333b5..000000000 --- a/lib/cryptopp/rabin.cpp +++ /dev/null @@ -1,221 +0,0 @@ -// rabin.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "rabin.h" -#include "nbtheory.h" -#include "asn.h" -#include "sha.h" -#include "modarith.h" - -NAMESPACE_BEGIN(CryptoPP) - -void RabinFunction::BERDecode(BufferedTransformation &bt) -{ - BERSequenceDecoder seq(bt); - m_n.BERDecode(seq); - m_r.BERDecode(seq); - m_s.BERDecode(seq); - seq.MessageEnd(); -} - -void RabinFunction::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - m_n.DEREncode(seq); - m_r.DEREncode(seq); - m_s.DEREncode(seq); - seq.MessageEnd(); -} - -Integer RabinFunction::ApplyFunction(const Integer &in) const -{ - DoQuickSanityCheck(); - - Integer out = in.Squared()%m_n; - if (in.IsOdd()) - out = out*m_r%m_n; - if (Jacobi(in, m_n)==-1) - out = out*m_s%m_n; - return out; -} - -bool RabinFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = true; - pass = pass && m_n > Integer::One() && m_n%4 == 1; - pass = pass && m_r > Integer::One() && m_r < m_n; - pass = pass && m_s > Integer::One() && m_s < m_n; - if (level >= 1) - pass = pass && Jacobi(m_r, m_n) == -1 && Jacobi(m_s, m_n) == -1; - return pass; -} - -bool RabinFunction::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - return GetValueHelper(this, name, valueType, pValue).Assignable() - CRYPTOPP_GET_FUNCTION_ENTRY(Modulus) - CRYPTOPP_GET_FUNCTION_ENTRY(QuadraticResidueModPrime1) - CRYPTOPP_GET_FUNCTION_ENTRY(QuadraticResidueModPrime2) - ; -} - -void RabinFunction::AssignFrom(const NameValuePairs &source) -{ - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(Modulus) - CRYPTOPP_SET_FUNCTION_ENTRY(QuadraticResidueModPrime1) - CRYPTOPP_SET_FUNCTION_ENTRY(QuadraticResidueModPrime2) - ; -} - -// ***************************************************************************** -// private key operations: - -// generate a random private key -void InvertibleRabinFunction::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg) -{ - int modulusSize = 2048; - alg.GetIntValue("ModulusSize", modulusSize) || alg.GetIntValue("KeySize", modulusSize); - - if (modulusSize < 16) - throw InvalidArgument("InvertibleRabinFunction: specified modulus size is too small"); - - // VC70 workaround: putting these after primeParam causes overlapped stack allocation - bool rFound=false, sFound=false; - Integer t=2; - - AlgorithmParameters primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize) - ("EquivalentTo", 3)("Mod", 4); - m_p.GenerateRandom(rng, primeParam); - m_q.GenerateRandom(rng, primeParam); - - while (!(rFound && sFound)) - { - int jp = Jacobi(t, m_p); - int jq = Jacobi(t, m_q); - - if (!rFound && jp==1 && jq==-1) - { - m_r = t; - rFound = true; - } - - if (!sFound && jp==-1 && jq==1) - { - m_s = t; - sFound = true; - } - - ++t; - } - - m_n = m_p * m_q; - m_u = m_q.InverseMod(m_p); -} - -void InvertibleRabinFunction::BERDecode(BufferedTransformation &bt) -{ - BERSequenceDecoder seq(bt); - m_n.BERDecode(seq); - m_r.BERDecode(seq); - m_s.BERDecode(seq); - m_p.BERDecode(seq); - m_q.BERDecode(seq); - m_u.BERDecode(seq); - seq.MessageEnd(); -} - -void InvertibleRabinFunction::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - m_n.DEREncode(seq); - m_r.DEREncode(seq); - m_s.DEREncode(seq); - m_p.DEREncode(seq); - m_q.DEREncode(seq); - m_u.DEREncode(seq); - seq.MessageEnd(); -} - -Integer InvertibleRabinFunction::CalculateInverse(RandomNumberGenerator &rng, const Integer &in) const -{ - DoQuickSanityCheck(); - - ModularArithmetic modn(m_n); - Integer r(rng, Integer::One(), m_n - Integer::One()); - r = modn.Square(r); - Integer r2 = modn.Square(r); - Integer c = modn.Multiply(in, r2); // blind - - Integer cp=c%m_p, cq=c%m_q; - - int jp = Jacobi(cp, m_p); - int jq = Jacobi(cq, m_q); - - if (jq==-1) - { - cp = cp*EuclideanMultiplicativeInverse(m_r, m_p)%m_p; - cq = cq*EuclideanMultiplicativeInverse(m_r, m_q)%m_q; - } - - if (jp==-1) - { - cp = cp*EuclideanMultiplicativeInverse(m_s, m_p)%m_p; - cq = cq*EuclideanMultiplicativeInverse(m_s, m_q)%m_q; - } - - cp = ModularSquareRoot(cp, m_p); - cq = ModularSquareRoot(cq, m_q); - - if (jp==-1) - cp = m_p-cp; - - Integer out = CRT(cq, m_q, cp, m_p, m_u); - - out = modn.Divide(out, r); // unblind - - if ((jq==-1 && out.IsEven()) || (jq==1 && out.IsOdd())) - out = m_n-out; - - return out; -} - -bool InvertibleRabinFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = RabinFunction::Validate(rng, level); - pass = pass && m_p > Integer::One() && m_p%4 == 3 && m_p < m_n; - pass = pass && m_q > Integer::One() && m_q%4 == 3 && m_q < m_n; - pass = pass && m_u.IsPositive() && m_u < m_p; - if (level >= 1) - { - pass = pass && m_p * m_q == m_n; - pass = pass && m_u * m_q % m_p == 1; - pass = pass && Jacobi(m_r, m_p) == 1; - pass = pass && Jacobi(m_r, m_q) == -1; - pass = pass && Jacobi(m_s, m_p) == -1; - pass = pass && Jacobi(m_s, m_q) == 1; - } - if (level >= 2) - pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2); - return pass; -} - -bool InvertibleRabinFunction::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - return GetValueHelper(this, name, valueType, pValue).Assignable() - CRYPTOPP_GET_FUNCTION_ENTRY(Prime1) - CRYPTOPP_GET_FUNCTION_ENTRY(Prime2) - CRYPTOPP_GET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1) - ; -} - -void InvertibleRabinFunction::AssignFrom(const NameValuePairs &source) -{ - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(Prime1) - CRYPTOPP_SET_FUNCTION_ENTRY(Prime2) - CRYPTOPP_SET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1) - ; -} - -NAMESPACE_END diff --git a/lib/cryptopp/rabin.h b/lib/cryptopp/rabin.h deleted file mode 100644 index 1c9bcbb49..000000000 --- a/lib/cryptopp/rabin.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef CRYPTOPP_RABIN_H -#define CRYPTOPP_RABIN_H - -/** \file -*/ - -#include "oaep.h" -#include "pssr.h" -#include "integer.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -class RabinFunction : public TrapdoorFunction, public PublicKey -{ - typedef RabinFunction ThisClass; - -public: - void Initialize(const Integer &n, const Integer &r, const Integer &s) - {m_n = n; m_r = r; m_s = s;} - - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - Integer ApplyFunction(const Integer &x) const; - Integer PreimageBound() const {return m_n;} - Integer ImageBound() const {return m_n;} - - bool Validate(RandomNumberGenerator &rng, unsigned int level) const; - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - - const Integer& GetModulus() const {return m_n;} - const Integer& GetQuadraticResidueModPrime1() const {return m_r;} - const Integer& GetQuadraticResidueModPrime2() const {return m_s;} - - void SetModulus(const Integer &n) {m_n = n;} - void SetQuadraticResidueModPrime1(const Integer &r) {m_r = r;} - void SetQuadraticResidueModPrime2(const Integer &s) {m_s = s;} - -protected: - Integer m_n, m_r, m_s; -}; - -//! _ -class InvertibleRabinFunction : public RabinFunction, public TrapdoorFunctionInverse, public PrivateKey -{ - typedef InvertibleRabinFunction ThisClass; - -public: - void Initialize(const Integer &n, const Integer &r, const Integer &s, - const Integer &p, const Integer &q, const Integer &u) - {m_n = n; m_r = r; m_s = s; m_p = p; m_q = q; m_u = u;} - void Initialize(RandomNumberGenerator &rng, unsigned int keybits) - {GenerateRandomWithKeySize(rng, keybits);} - - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const; - - bool Validate(RandomNumberGenerator &rng, unsigned int level) const; - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - /*! parameters: (ModulusSize) */ - void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); - - const Integer& GetPrime1() const {return m_p;} - const Integer& GetPrime2() const {return m_q;} - const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;} - - void SetPrime1(const Integer &p) {m_p = p;} - void SetPrime2(const Integer &q) {m_q = q;} - void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;} - -protected: - Integer m_p, m_q, m_u; -}; - -//! Rabin -struct Rabin -{ - static std::string StaticAlgorithmName() {return "Rabin-Crypto++Variant";} - typedef RabinFunction PublicKey; - typedef InvertibleRabinFunction PrivateKey; -}; - -//! Rabin encryption -template -struct RabinES : public TF_ES -{ -}; - -//! Rabin signature -template -struct RabinSS : public TF_SS -{ -}; - -// More typedefs for backwards compatibility -class SHA1; -typedef RabinES >::Decryptor RabinDecryptor; -typedef RabinES >::Encryptor RabinEncryptor; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/randpool.cpp b/lib/cryptopp/randpool.cpp deleted file mode 100644 index a063c8996..000000000 --- a/lib/cryptopp/randpool.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// randpool.cpp - written and placed in the public domain by Wei Dai -// RandomPool used to follow the design of randpool in PGP 2.6.x, -// but as of version 5.5 it has been redesigned to reduce the risk -// of reusing random numbers after state rollback (which may occur -// when running in a virtual machine like VMware). - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "randpool.h" -#include "aes.h" -#include "sha.h" -#include "hrtimer.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -RandomPool::RandomPool() - : m_pCipher(new AES::Encryption), m_keySet(false) -{ - memset(m_key, 0, m_key.SizeInBytes()); - memset(m_seed, 0, m_seed.SizeInBytes()); -} - -void RandomPool::IncorporateEntropy(const byte *input, size_t length) -{ - SHA256 hash; - hash.Update(m_key, 32); - hash.Update(input, length); - hash.Final(m_key); - m_keySet = false; -} - -void RandomPool::GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size) -{ - if (size > 0) - { - if (!m_keySet) - m_pCipher->SetKey(m_key, 32); - - Timer timer; - TimerWord tw = timer.GetCurrentTimerValue(); - CRYPTOPP_COMPILE_ASSERT(sizeof(tw) <= 16); - *(TimerWord *)m_seed.data() += tw; - - time_t t = time(NULL); - CRYPTOPP_COMPILE_ASSERT(sizeof(t) <= 8); - *(time_t *)(m_seed.data()+8) += t; - - do - { - m_pCipher->ProcessBlock(m_seed); - size_t len = UnsignedMin(16, size); - target.ChannelPut(channel, m_seed, len); - size -= len; - } while (size > 0); - } -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/randpool.h b/lib/cryptopp/randpool.h deleted file mode 100644 index c25bc9bb1..000000000 --- a/lib/cryptopp/randpool.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef CRYPTOPP_RANDPOOL_H -#define CRYPTOPP_RANDPOOL_H - -#include "cryptlib.h" -#include "filters.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! Randomness Pool -/*! This class can be used to generate cryptographic quality - pseudorandom bytes after seeding the pool with IncorporateEntropy() */ -class CRYPTOPP_DLL RandomPool : public RandomNumberGenerator, public NotCopyable -{ -public: - RandomPool(); - - bool CanIncorporateEntropy() const {return true;} - void IncorporateEntropy(const byte *input, size_t length); - void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size); - - // for backwards compatibility. use RandomNumberSource, RandomNumberStore, and RandomNumberSink for other BufferTransformation functionality - void Put(const byte *input, size_t length) {IncorporateEntropy(input, length);} - -private: - FixedSizeSecBlock m_key; - FixedSizeSecBlock m_seed; - member_ptr m_pCipher; - bool m_keySet; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/rdtables.cpp b/lib/cryptopp/rdtables.cpp deleted file mode 100644 index 493793252..000000000 --- a/lib/cryptopp/rdtables.cpp +++ /dev/null @@ -1,172 +0,0 @@ -// Rijndael tables - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "rijndael.h" - -// VC60 workaround: gives a C4786 warning without this function -// when runtime lib is set to multithread debug DLL -// even though warning 4786 is disabled! -void Rijndael_VC60Workaround() -{ -} - -NAMESPACE_BEGIN(CryptoPP) - -/* -Te0[x] = S [x].[02, 01, 01, 03]; -Te1[x] = S [x].[03, 02, 01, 01]; -Te2[x] = S [x].[01, 03, 02, 01]; -Te3[x] = S [x].[01, 01, 03, 02]; - -Td0[x] = Si[x].[0e, 09, 0d, 0b]; -Td1[x] = Si[x].[0b, 0e, 09, 0d]; -Td2[x] = Si[x].[0d, 0b, 0e, 09]; -Td3[x] = Si[x].[09, 0d, 0b, 0e]; -*/ - -const byte Rijndael::Base::Se[256] = { - 0x63, 0x7c, 0x77, 0x7b, - 0xf2, 0x6b, 0x6f, 0xc5, - 0x30, 0x01, 0x67, 0x2b, - 0xfe, 0xd7, 0xab, 0x76, - 0xca, 0x82, 0xc9, 0x7d, - 0xfa, 0x59, 0x47, 0xf0, - 0xad, 0xd4, 0xa2, 0xaf, - 0x9c, 0xa4, 0x72, 0xc0, - 0xb7, 0xfd, 0x93, 0x26, - 0x36, 0x3f, 0xf7, 0xcc, - 0x34, 0xa5, 0xe5, 0xf1, - 0x71, 0xd8, 0x31, 0x15, - 0x04, 0xc7, 0x23, 0xc3, - 0x18, 0x96, 0x05, 0x9a, - 0x07, 0x12, 0x80, 0xe2, - 0xeb, 0x27, 0xb2, 0x75, - 0x09, 0x83, 0x2c, 0x1a, - 0x1b, 0x6e, 0x5a, 0xa0, - 0x52, 0x3b, 0xd6, 0xb3, - 0x29, 0xe3, 0x2f, 0x84, - 0x53, 0xd1, 0x00, 0xed, - 0x20, 0xfc, 0xb1, 0x5b, - 0x6a, 0xcb, 0xbe, 0x39, - 0x4a, 0x4c, 0x58, 0xcf, - 0xd0, 0xef, 0xaa, 0xfb, - 0x43, 0x4d, 0x33, 0x85, - 0x45, 0xf9, 0x02, 0x7f, - 0x50, 0x3c, 0x9f, 0xa8, - 0x51, 0xa3, 0x40, 0x8f, - 0x92, 0x9d, 0x38, 0xf5, - 0xbc, 0xb6, 0xda, 0x21, - 0x10, 0xff, 0xf3, 0xd2, - 0xcd, 0x0c, 0x13, 0xec, - 0x5f, 0x97, 0x44, 0x17, - 0xc4, 0xa7, 0x7e, 0x3d, - 0x64, 0x5d, 0x19, 0x73, - 0x60, 0x81, 0x4f, 0xdc, - 0x22, 0x2a, 0x90, 0x88, - 0x46, 0xee, 0xb8, 0x14, - 0xde, 0x5e, 0x0b, 0xdb, - 0xe0, 0x32, 0x3a, 0x0a, - 0x49, 0x06, 0x24, 0x5c, - 0xc2, 0xd3, 0xac, 0x62, - 0x91, 0x95, 0xe4, 0x79, - 0xe7, 0xc8, 0x37, 0x6d, - 0x8d, 0xd5, 0x4e, 0xa9, - 0x6c, 0x56, 0xf4, 0xea, - 0x65, 0x7a, 0xae, 0x08, - 0xba, 0x78, 0x25, 0x2e, - 0x1c, 0xa6, 0xb4, 0xc6, - 0xe8, 0xdd, 0x74, 0x1f, - 0x4b, 0xbd, 0x8b, 0x8a, - 0x70, 0x3e, 0xb5, 0x66, - 0x48, 0x03, 0xf6, 0x0e, - 0x61, 0x35, 0x57, 0xb9, - 0x86, 0xc1, 0x1d, 0x9e, - 0xe1, 0xf8, 0x98, 0x11, - 0x69, 0xd9, 0x8e, 0x94, - 0x9b, 0x1e, 0x87, 0xe9, - 0xce, 0x55, 0x28, 0xdf, - 0x8c, 0xa1, 0x89, 0x0d, - 0xbf, 0xe6, 0x42, 0x68, - 0x41, 0x99, 0x2d, 0x0f, - 0xb0, 0x54, 0xbb, 0x16, -}; - -const byte Rijndael::Base::Sd[256] = { - 0x52, 0x09, 0x6a, 0xd5, - 0x30, 0x36, 0xa5, 0x38, - 0xbf, 0x40, 0xa3, 0x9e, - 0x81, 0xf3, 0xd7, 0xfb, - 0x7c, 0xe3, 0x39, 0x82, - 0x9b, 0x2f, 0xff, 0x87, - 0x34, 0x8e, 0x43, 0x44, - 0xc4, 0xde, 0xe9, 0xcb, - 0x54, 0x7b, 0x94, 0x32, - 0xa6, 0xc2, 0x23, 0x3d, - 0xee, 0x4c, 0x95, 0x0b, - 0x42, 0xfa, 0xc3, 0x4e, - 0x08, 0x2e, 0xa1, 0x66, - 0x28, 0xd9, 0x24, 0xb2, - 0x76, 0x5b, 0xa2, 0x49, - 0x6d, 0x8b, 0xd1, 0x25, - 0x72, 0xf8, 0xf6, 0x64, - 0x86, 0x68, 0x98, 0x16, - 0xd4, 0xa4, 0x5c, 0xcc, - 0x5d, 0x65, 0xb6, 0x92, - 0x6c, 0x70, 0x48, 0x50, - 0xfd, 0xed, 0xb9, 0xda, - 0x5e, 0x15, 0x46, 0x57, - 0xa7, 0x8d, 0x9d, 0x84, - 0x90, 0xd8, 0xab, 0x00, - 0x8c, 0xbc, 0xd3, 0x0a, - 0xf7, 0xe4, 0x58, 0x05, - 0xb8, 0xb3, 0x45, 0x06, - 0xd0, 0x2c, 0x1e, 0x8f, - 0xca, 0x3f, 0x0f, 0x02, - 0xc1, 0xaf, 0xbd, 0x03, - 0x01, 0x13, 0x8a, 0x6b, - 0x3a, 0x91, 0x11, 0x41, - 0x4f, 0x67, 0xdc, 0xea, - 0x97, 0xf2, 0xcf, 0xce, - 0xf0, 0xb4, 0xe6, 0x73, - 0x96, 0xac, 0x74, 0x22, - 0xe7, 0xad, 0x35, 0x85, - 0xe2, 0xf9, 0x37, 0xe8, - 0x1c, 0x75, 0xdf, 0x6e, - 0x47, 0xf1, 0x1a, 0x71, - 0x1d, 0x29, 0xc5, 0x89, - 0x6f, 0xb7, 0x62, 0x0e, - 0xaa, 0x18, 0xbe, 0x1b, - 0xfc, 0x56, 0x3e, 0x4b, - 0xc6, 0xd2, 0x79, 0x20, - 0x9a, 0xdb, 0xc0, 0xfe, - 0x78, 0xcd, 0x5a, 0xf4, - 0x1f, 0xdd, 0xa8, 0x33, - 0x88, 0x07, 0xc7, 0x31, - 0xb1, 0x12, 0x10, 0x59, - 0x27, 0x80, 0xec, 0x5f, - 0x60, 0x51, 0x7f, 0xa9, - 0x19, 0xb5, 0x4a, 0x0d, - 0x2d, 0xe5, 0x7a, 0x9f, - 0x93, 0xc9, 0x9c, 0xef, - 0xa0, 0xe0, 0x3b, 0x4d, - 0xae, 0x2a, 0xf5, 0xb0, - 0xc8, 0xeb, 0xbb, 0x3c, - 0x83, 0x53, 0x99, 0x61, - 0x17, 0x2b, 0x04, 0x7e, - 0xba, 0x77, 0xd6, 0x26, - 0xe1, 0x69, 0x14, 0x63, - 0x55, 0x21, 0x0c, 0x7d, -}; - -const word32 Rijndael::Base::rcon[] = { - 0x01000000, 0x02000000, 0x04000000, 0x08000000, - 0x10000000, 0x20000000, 0x40000000, 0x80000000, - 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/resource.h b/lib/cryptopp/resource.h deleted file mode 100644 index 861e22ba3..000000000 --- a/lib/cryptopp/resource.h +++ /dev/null @@ -1,15 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by cryptopp.rc -// - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/lib/cryptopp/rijndael.cpp b/lib/cryptopp/rijndael.cpp deleted file mode 100644 index c185032cf..000000000 --- a/lib/cryptopp/rijndael.cpp +++ /dev/null @@ -1,1261 +0,0 @@ -// rijndael.cpp - modified by Chris Morgan -// and Wei Dai from Paulo Baretto's Rijndael implementation -// The original code and all modifications are in the public domain. - -// use "cl /EP /P /DCRYPTOPP_GENERATE_X64_MASM rijndael.cpp" to generate MASM code - -/* -July 2010: Added support for AES-NI instructions via compiler intrinsics. -*/ - -/* -Feb 2009: The x86/x64 assembly code was rewritten in by Wei Dai to do counter mode -caching, which was invented by Hongjun Wu and popularized by Daniel J. Bernstein -and Peter Schwabe in their paper "New AES software speed records". The round -function was also modified to include a trick similar to one in Brian Gladman's -x86 assembly code, doing an 8-bit register move to minimize the number of -register spills. Also switched to compressed tables and copying round keys to -the stack. - -The C++ implementation now uses compressed tables if -CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS is defined. -*/ - -/* -July 2006: Defense against timing attacks was added in by Wei Dai. - -The code now uses smaller tables in the first and last rounds, -and preloads them into L1 cache before usage (by loading at least -one element in each cache line). - -We try to delay subsequent accesses to each table (used in the first -and last rounds) until all of the table has been preloaded. Hopefully -the compiler isn't smart enough to optimize that code away. - -After preloading the table, we also try not to access any memory location -other than the table and the stack, in order to prevent table entries from -being unloaded from L1 cache, until that round is finished. -(Some popular CPUs have 2-way associative caches.) -*/ - -// This is the original introductory comment: - -/** - * version 3.0 (December 2000) - * - * Optimised ANSI C code for the Rijndael cipher (now AES) - * - * author Vincent Rijmen - * author Antoon Bosselaers - * author Paulo Barreto - * - * This code is hereby placed in the public domain. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS -#ifndef CRYPTOPP_GENERATE_X64_MASM - -#include "rijndael.h" -#include "misc.h" -#include "cpu.h" - -NAMESPACE_BEGIN(CryptoPP) - -#ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) -namespace rdtable {CRYPTOPP_ALIGN_DATA(16) word64 Te[256+2];} -using namespace rdtable; -#else -static word64 Te[256]; -#endif -static word64 Td[256]; -#else -static word32 Te[256*4], Td[256*4]; -#endif -static volatile bool s_TeFilled = false, s_TdFilled = false; - -// ************************* Portable Code ************************************ - -#define QUARTER_ROUND(L, T, t, a, b, c, d) \ - a ^= L(T, 3, byte(t)); t >>= 8;\ - b ^= L(T, 2, byte(t)); t >>= 8;\ - c ^= L(T, 1, byte(t)); t >>= 8;\ - d ^= L(T, 0, t); - -#define QUARTER_ROUND_LE(t, a, b, c, d) \ - tempBlock[a] = ((byte *)(Te+byte(t)))[1]; t >>= 8;\ - tempBlock[b] = ((byte *)(Te+byte(t)))[1]; t >>= 8;\ - tempBlock[c] = ((byte *)(Te+byte(t)))[1]; t >>= 8;\ - tempBlock[d] = ((byte *)(Te+t))[1]; - -#ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - #define QUARTER_ROUND_LD(t, a, b, c, d) \ - tempBlock[a] = ((byte *)(Td+byte(t)))[GetNativeByteOrder()*7]; t >>= 8;\ - tempBlock[b] = ((byte *)(Td+byte(t)))[GetNativeByteOrder()*7]; t >>= 8;\ - tempBlock[c] = ((byte *)(Td+byte(t)))[GetNativeByteOrder()*7]; t >>= 8;\ - tempBlock[d] = ((byte *)(Td+t))[GetNativeByteOrder()*7]; -#else - #define QUARTER_ROUND_LD(t, a, b, c, d) \ - tempBlock[a] = Sd[byte(t)]; t >>= 8;\ - tempBlock[b] = Sd[byte(t)]; t >>= 8;\ - tempBlock[c] = Sd[byte(t)]; t >>= 8;\ - tempBlock[d] = Sd[t]; -#endif - -#define QUARTER_ROUND_E(t, a, b, c, d) QUARTER_ROUND(TL_M, Te, t, a, b, c, d) -#define QUARTER_ROUND_D(t, a, b, c, d) QUARTER_ROUND(TL_M, Td, t, a, b, c, d) - -#ifdef IS_LITTLE_ENDIAN - #define QUARTER_ROUND_FE(t, a, b, c, d) QUARTER_ROUND(TL_F, Te, t, d, c, b, a) - #define QUARTER_ROUND_FD(t, a, b, c, d) QUARTER_ROUND(TL_F, Td, t, d, c, b, a) - #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - #define TL_F(T, i, x) (*(word32 *)((byte *)T + x*8 + (6-i)%4+1)) - #define TL_M(T, i, x) (*(word32 *)((byte *)T + x*8 + (i+3)%4+1)) - #else - #define TL_F(T, i, x) rotrFixed(T[x], (3-i)*8) - #define TL_M(T, i, x) T[i*256 + x] - #endif -#else - #define QUARTER_ROUND_FE(t, a, b, c, d) QUARTER_ROUND(TL_F, Te, t, a, b, c, d) - #define QUARTER_ROUND_FD(t, a, b, c, d) QUARTER_ROUND(TL_F, Td, t, a, b, c, d) - #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - #define TL_F(T, i, x) (*(word32 *)((byte *)T + x*8 + (4-i)%4)) - #define TL_M TL_F - #else - #define TL_F(T, i, x) rotrFixed(T[x], i*8) - #define TL_M(T, i, x) T[i*256 + x] - #endif -#endif - - -#define f2(x) ((x<<1)^(((x>>7)&1)*0x11b)) -#define f4(x) ((x<<2)^(((x>>6)&1)*0x11b)^(((x>>6)&2)*0x11b)) -#define f8(x) ((x<<3)^(((x>>5)&1)*0x11b)^(((x>>5)&2)*0x11b)^(((x>>5)&4)*0x11b)) - -#define f3(x) (f2(x) ^ x) -#define f9(x) (f8(x) ^ x) -#define fb(x) (f8(x) ^ f2(x) ^ x) -#define fd(x) (f8(x) ^ f4(x) ^ x) -#define fe(x) (f8(x) ^ f4(x) ^ f2(x)) - -void Rijndael::Base::FillEncTable() -{ - for (int i=0; i<256; i++) - { - byte x = Se[i]; -#ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - word32 y = word32(x)<<8 | word32(x)<<16 | word32(f2(x))<<24; - Te[i] = word64(y | f3(x))<<32 | y; -#else - word32 y = f3(x) | word32(x)<<8 | word32(x)<<16 | word32(f2(x))<<24; - for (int j=0; j<4; j++) - { - Te[i+j*256] = y; - y = rotrFixed(y, 8); - } -#endif - } -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) - Te[256] = Te[257] = 0; -#endif - s_TeFilled = true; -} - -void Rijndael::Base::FillDecTable() -{ - for (int i=0; i<256; i++) - { - byte x = Sd[i]; -#ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - word32 y = word32(fd(x))<<8 | word32(f9(x))<<16 | word32(fe(x))<<24; - Td[i] = word64(y | fb(x))<<32 | y | x; -#else - word32 y = fb(x) | word32(fd(x))<<8 | word32(f9(x))<<16 | word32(fe(x))<<24;; - for (int j=0; j<4; j++) - { - Td[i+j*256] = y; - y = rotrFixed(y, 8); - } -#endif - } - s_TdFilled = true; -} - -void Rijndael::Base::UncheckedSetKey(const byte *userKey, unsigned int keylen, const NameValuePairs &) -{ - AssertValidKeyLength(keylen); - - m_rounds = keylen/4 + 6; - m_key.New(4*(m_rounds+1)); - - word32 *rk = m_key; - -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE && (!defined(_MSC_VER) || _MSC_VER >= 1600 || CRYPTOPP_BOOL_X86) - // MSVC 2008 SP1 generates bad code for _mm_extract_epi32() when compiling for X64 - if (HasAESNI()) - { - static const word32 rcLE[] = { - 0x01, 0x02, 0x04, 0x08, - 0x10, 0x20, 0x40, 0x80, - 0x1B, 0x36, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ - }; - const word32 *rc = rcLE; - - __m128i temp = _mm_loadu_si128((__m128i *)(userKey+keylen-16)); - memcpy(rk, userKey, keylen); - - while (true) - { - rk[keylen/4] = rk[0] ^ _mm_extract_epi32(_mm_aeskeygenassist_si128(temp, 0), 3) ^ *(rc++); - rk[keylen/4+1] = rk[1] ^ rk[keylen/4]; - rk[keylen/4+2] = rk[2] ^ rk[keylen/4+1]; - rk[keylen/4+3] = rk[3] ^ rk[keylen/4+2]; - - if (rk + keylen/4 + 4 == m_key.end()) - break; - - if (keylen == 24) - { - rk[10] = rk[ 4] ^ rk[ 9]; - rk[11] = rk[ 5] ^ rk[10]; - temp = _mm_insert_epi32(temp, rk[11], 3); - } - else if (keylen == 32) - { - temp = _mm_insert_epi32(temp, rk[11], 3); - rk[12] = rk[ 4] ^ _mm_extract_epi32(_mm_aeskeygenassist_si128(temp, 0), 2); - rk[13] = rk[ 5] ^ rk[12]; - rk[14] = rk[ 6] ^ rk[13]; - rk[15] = rk[ 7] ^ rk[14]; - temp = _mm_insert_epi32(temp, rk[15], 3); - } - else - temp = _mm_insert_epi32(temp, rk[7], 3); - - rk += keylen/4; - } - - if (!IsForwardTransformation()) - { - rk = m_key; - unsigned int i, j; - - std::swap(*(__m128i *)(rk), *(__m128i *)(rk+4*m_rounds)); - - for (i = 4, j = 4*m_rounds-4; i < j; i += 4, j -= 4) - { - temp = _mm_aesimc_si128(*(__m128i *)(rk+i)); - *(__m128i *)(rk+i) = _mm_aesimc_si128(*(__m128i *)(rk+j)); - *(__m128i *)(rk+j) = temp; - } - - *(__m128i *)(rk+i) = _mm_aesimc_si128(*(__m128i *)(rk+i)); - } - - return; - } -#endif - - GetUserKey(BIG_ENDIAN_ORDER, rk, keylen/4, userKey, keylen); - const word32 *rc = rcon; - word32 temp; - - while (true) - { - temp = rk[keylen/4-1]; - word32 x = (word32(Se[GETBYTE(temp, 2)]) << 24) ^ (word32(Se[GETBYTE(temp, 1)]) << 16) ^ (word32(Se[GETBYTE(temp, 0)]) << 8) ^ Se[GETBYTE(temp, 3)]; - rk[keylen/4] = rk[0] ^ x ^ *(rc++); - rk[keylen/4+1] = rk[1] ^ rk[keylen/4]; - rk[keylen/4+2] = rk[2] ^ rk[keylen/4+1]; - rk[keylen/4+3] = rk[3] ^ rk[keylen/4+2]; - - if (rk + keylen/4 + 4 == m_key.end()) - break; - - if (keylen == 24) - { - rk[10] = rk[ 4] ^ rk[ 9]; - rk[11] = rk[ 5] ^ rk[10]; - } - else if (keylen == 32) - { - temp = rk[11]; - rk[12] = rk[ 4] ^ (word32(Se[GETBYTE(temp, 3)]) << 24) ^ (word32(Se[GETBYTE(temp, 2)]) << 16) ^ (word32(Se[GETBYTE(temp, 1)]) << 8) ^ Se[GETBYTE(temp, 0)]; - rk[13] = rk[ 5] ^ rk[12]; - rk[14] = rk[ 6] ^ rk[13]; - rk[15] = rk[ 7] ^ rk[14]; - } - rk += keylen/4; - } - - rk = m_key; - - if (IsForwardTransformation()) - { - if (!s_TeFilled) - FillEncTable(); - - ConditionalByteReverse(BIG_ENDIAN_ORDER, rk, rk, 16); - ConditionalByteReverse(BIG_ENDIAN_ORDER, rk + m_rounds*4, rk + m_rounds*4, 16); - } - else - { - if (!s_TdFilled) - FillDecTable(); - - unsigned int i, j; - -#define InverseMixColumn(x) TL_M(Td, 0, Se[GETBYTE(x, 3)]) ^ TL_M(Td, 1, Se[GETBYTE(x, 2)]) ^ TL_M(Td, 2, Se[GETBYTE(x, 1)]) ^ TL_M(Td, 3, Se[GETBYTE(x, 0)]) - - for (i = 4, j = 4*m_rounds-4; i < j; i += 4, j -= 4) - { - temp = InverseMixColumn(rk[i ]); rk[i ] = InverseMixColumn(rk[j ]); rk[j ] = temp; - temp = InverseMixColumn(rk[i + 1]); rk[i + 1] = InverseMixColumn(rk[j + 1]); rk[j + 1] = temp; - temp = InverseMixColumn(rk[i + 2]); rk[i + 2] = InverseMixColumn(rk[j + 2]); rk[j + 2] = temp; - temp = InverseMixColumn(rk[i + 3]); rk[i + 3] = InverseMixColumn(rk[j + 3]); rk[j + 3] = temp; - } - - rk[i+0] = InverseMixColumn(rk[i+0]); - rk[i+1] = InverseMixColumn(rk[i+1]); - rk[i+2] = InverseMixColumn(rk[i+2]); - rk[i+3] = InverseMixColumn(rk[i+3]); - - temp = ConditionalByteReverse(BIG_ENDIAN_ORDER, rk[0]); rk[0] = ConditionalByteReverse(BIG_ENDIAN_ORDER, rk[4*m_rounds+0]); rk[4*m_rounds+0] = temp; - temp = ConditionalByteReverse(BIG_ENDIAN_ORDER, rk[1]); rk[1] = ConditionalByteReverse(BIG_ENDIAN_ORDER, rk[4*m_rounds+1]); rk[4*m_rounds+1] = temp; - temp = ConditionalByteReverse(BIG_ENDIAN_ORDER, rk[2]); rk[2] = ConditionalByteReverse(BIG_ENDIAN_ORDER, rk[4*m_rounds+2]); rk[4*m_rounds+2] = temp; - temp = ConditionalByteReverse(BIG_ENDIAN_ORDER, rk[3]); rk[3] = ConditionalByteReverse(BIG_ENDIAN_ORDER, rk[4*m_rounds+3]); rk[4*m_rounds+3] = temp; - } - -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE - if (HasAESNI()) - ConditionalByteReverse(BIG_ENDIAN_ORDER, rk+4, rk+4, (m_rounds-1)*16); -#endif -} - -void Rijndael::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) || CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) - if (HasSSE2()) -#else - if (HasAESNI()) -#endif - { - Rijndael::Enc::AdvancedProcessBlocks(inBlock, xorBlock, outBlock, 16, 0); - return; - } -#endif - - typedef BlockGetAndPut Block; - - word32 s0, s1, s2, s3, t0, t1, t2, t3; - Block::Get(inBlock)(s0)(s1)(s2)(s3); - - const word32 *rk = m_key; - s0 ^= rk[0]; - s1 ^= rk[1]; - s2 ^= rk[2]; - s3 ^= rk[3]; - t0 = rk[4]; - t1 = rk[5]; - t2 = rk[6]; - t3 = rk[7]; - rk += 8; - - // timing attack countermeasure. see comments at top for more details - const int cacheLineSize = GetCacheLineSize(); - unsigned int i; - word32 u = 0; -#ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - for (i=0; i<2048; i+=cacheLineSize) -#else - for (i=0; i<1024; i+=cacheLineSize) -#endif - u &= *(const word32 *)(((const byte *)Te)+i); - u &= Te[255]; - s0 |= u; s1 |= u; s2 |= u; s3 |= u; - - QUARTER_ROUND_FE(s3, t0, t1, t2, t3) - QUARTER_ROUND_FE(s2, t3, t0, t1, t2) - QUARTER_ROUND_FE(s1, t2, t3, t0, t1) - QUARTER_ROUND_FE(s0, t1, t2, t3, t0) - - // Nr - 2 full rounds: - unsigned int r = m_rounds/2 - 1; - do - { - s0 = rk[0]; s1 = rk[1]; s2 = rk[2]; s3 = rk[3]; - - QUARTER_ROUND_E(t3, s0, s1, s2, s3) - QUARTER_ROUND_E(t2, s3, s0, s1, s2) - QUARTER_ROUND_E(t1, s2, s3, s0, s1) - QUARTER_ROUND_E(t0, s1, s2, s3, s0) - - t0 = rk[4]; t1 = rk[5]; t2 = rk[6]; t3 = rk[7]; - - QUARTER_ROUND_E(s3, t0, t1, t2, t3) - QUARTER_ROUND_E(s2, t3, t0, t1, t2) - QUARTER_ROUND_E(s1, t2, t3, t0, t1) - QUARTER_ROUND_E(s0, t1, t2, t3, t0) - - rk += 8; - } while (--r); - - word32 tbw[4]; - byte *const tempBlock = (byte *)tbw; - - QUARTER_ROUND_LE(t2, 15, 2, 5, 8) - QUARTER_ROUND_LE(t1, 11, 14, 1, 4) - QUARTER_ROUND_LE(t0, 7, 10, 13, 0) - QUARTER_ROUND_LE(t3, 3, 6, 9, 12) - - Block::Put(xorBlock, outBlock)(tbw[0]^rk[0])(tbw[1]^rk[1])(tbw[2]^rk[2])(tbw[3]^rk[3]); -} - -void Rijndael::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE - if (HasAESNI()) - { - Rijndael::Dec::AdvancedProcessBlocks(inBlock, xorBlock, outBlock, 16, 0); - return; - } -#endif - - typedef BlockGetAndPut Block; - - word32 s0, s1, s2, s3, t0, t1, t2, t3; - Block::Get(inBlock)(s0)(s1)(s2)(s3); - - const word32 *rk = m_key; - s0 ^= rk[0]; - s1 ^= rk[1]; - s2 ^= rk[2]; - s3 ^= rk[3]; - t0 = rk[4]; - t1 = rk[5]; - t2 = rk[6]; - t3 = rk[7]; - rk += 8; - - // timing attack countermeasure. see comments at top for more details - const int cacheLineSize = GetCacheLineSize(); - unsigned int i; - word32 u = 0; -#ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - for (i=0; i<2048; i+=cacheLineSize) -#else - for (i=0; i<1024; i+=cacheLineSize) -#endif - u &= *(const word32 *)(((const byte *)Td)+i); - u &= Td[255]; - s0 |= u; s1 |= u; s2 |= u; s3 |= u; - - QUARTER_ROUND_FD(s3, t2, t1, t0, t3) - QUARTER_ROUND_FD(s2, t1, t0, t3, t2) - QUARTER_ROUND_FD(s1, t0, t3, t2, t1) - QUARTER_ROUND_FD(s0, t3, t2, t1, t0) - - // Nr - 2 full rounds: - unsigned int r = m_rounds/2 - 1; - do - { - s0 = rk[0]; s1 = rk[1]; s2 = rk[2]; s3 = rk[3]; - - QUARTER_ROUND_D(t3, s2, s1, s0, s3) - QUARTER_ROUND_D(t2, s1, s0, s3, s2) - QUARTER_ROUND_D(t1, s0, s3, s2, s1) - QUARTER_ROUND_D(t0, s3, s2, s1, s0) - - t0 = rk[4]; t1 = rk[5]; t2 = rk[6]; t3 = rk[7]; - - QUARTER_ROUND_D(s3, t2, t1, t0, t3) - QUARTER_ROUND_D(s2, t1, t0, t3, t2) - QUARTER_ROUND_D(s1, t0, t3, t2, t1) - QUARTER_ROUND_D(s0, t3, t2, t1, t0) - - rk += 8; - } while (--r); - -#ifndef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS - // timing attack countermeasure. see comments at top for more details - // If CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS is defined, - // QUARTER_ROUND_LD will use Td, which is already preloaded. - u = 0; - for (i=0; i<256; i+=cacheLineSize) - u &= *(const word32 *)(Sd+i); - u &= *(const word32 *)(Sd+252); - t0 |= u; t1 |= u; t2 |= u; t3 |= u; -#endif - - word32 tbw[4]; - byte *const tempBlock = (byte *)tbw; - - QUARTER_ROUND_LD(t2, 7, 2, 13, 8) - QUARTER_ROUND_LD(t1, 3, 14, 9, 4) - QUARTER_ROUND_LD(t0, 15, 10, 5, 0) - QUARTER_ROUND_LD(t3, 11, 6, 1, 12) - - Block::Put(xorBlock, outBlock)(tbw[0]^rk[0])(tbw[1]^rk[1])(tbw[2]^rk[2])(tbw[3]^rk[3]); -} - -// ************************* Assembly Code ************************************ - -#pragma warning(disable: 4731) // frame pointer register 'ebp' modified by inline assembly code - -#endif // #ifndef CRYPTOPP_GENERATE_X64_MASM - -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE - -CRYPTOPP_NAKED void CRYPTOPP_FASTCALL Rijndael_Enc_AdvancedProcessBlocks(void *locals, const word32 *k) -{ -#if CRYPTOPP_BOOL_X86 - -#define L_REG esp -#define L_INDEX(i) (L_REG+768+i) -#define L_INXORBLOCKS L_INBLOCKS+4 -#define L_OUTXORBLOCKS L_INBLOCKS+8 -#define L_OUTBLOCKS L_INBLOCKS+12 -#define L_INCREMENTS L_INDEX(16*15) -#define L_SP L_INDEX(16*16) -#define L_LENGTH L_INDEX(16*16+4) -#define L_KEYS_BEGIN L_INDEX(16*16+8) - -#define MOVD movd -#define MM(i) mm##i - -#define MXOR(a,b,c) \ - AS2( movzx esi, b)\ - AS2( movd mm7, DWORD PTR [AS_REG_7+8*WORD_REG(si)+MAP0TO4(c)])\ - AS2( pxor MM(a), mm7)\ - -#define MMOV(a,b,c) \ - AS2( movzx esi, b)\ - AS2( movd MM(a), DWORD PTR [AS_REG_7+8*WORD_REG(si)+MAP0TO4(c)])\ - -#else - -#define L_REG r8 -#define L_INDEX(i) (L_REG+i) -#define L_INXORBLOCKS L_INBLOCKS+8 -#define L_OUTXORBLOCKS L_INBLOCKS+16 -#define L_OUTBLOCKS L_INBLOCKS+24 -#define L_INCREMENTS L_INDEX(16*16) -#define L_LENGTH L_INDEX(16*18+8) -#define L_KEYS_BEGIN L_INDEX(16*19) - -#define MOVD mov -#define MM_0 r9d -#define MM_1 r12d -#ifdef __GNUC__ -#define MM_2 r11d -#else -#define MM_2 r10d -#endif -#define MM(i) MM_##i - -#define MXOR(a,b,c) \ - AS2( movzx esi, b)\ - AS2( xor MM(a), DWORD PTR [AS_REG_7+8*WORD_REG(si)+MAP0TO4(c)])\ - -#define MMOV(a,b,c) \ - AS2( movzx esi, b)\ - AS2( mov MM(a), DWORD PTR [AS_REG_7+8*WORD_REG(si)+MAP0TO4(c)])\ - -#endif - -#define L_SUBKEYS L_INDEX(0) -#define L_SAVED_X L_SUBKEYS -#define L_KEY12 L_INDEX(16*12) -#define L_LASTROUND L_INDEX(16*13) -#define L_INBLOCKS L_INDEX(16*14) -#define MAP0TO4(i) (ASM_MOD(i+3,4)+1) - -#define XOR(a,b,c) \ - AS2( movzx esi, b)\ - AS2( xor a, DWORD PTR [AS_REG_7+8*WORD_REG(si)+MAP0TO4(c)])\ - -#define MOV(a,b,c) \ - AS2( movzx esi, b)\ - AS2( mov a, DWORD PTR [AS_REG_7+8*WORD_REG(si)+MAP0TO4(c)])\ - -#ifdef CRYPTOPP_GENERATE_X64_MASM - ALIGN 8 - Rijndael_Enc_AdvancedProcessBlocks PROC FRAME - rex_push_reg rsi - push_reg rdi - push_reg rbx - push_reg r12 - .endprolog - mov L_REG, rcx - mov AS_REG_7, ?Te@rdtable@CryptoPP@@3PA_KA - mov edi, DWORD PTR [?g_cacheLineSize@CryptoPP@@3IA] -#elif defined(__GNUC__) - __asm__ __volatile__ - ( - ".intel_syntax noprefix;" - #if CRYPTOPP_BOOL_X64 - AS2( mov L_REG, rcx) - #endif - AS_PUSH_IF86(bx) - AS_PUSH_IF86(bp) - AS2( mov AS_REG_7, WORD_REG(si)) -#else - AS_PUSH_IF86(si) - AS_PUSH_IF86(di) - AS_PUSH_IF86(bx) - AS_PUSH_IF86(bp) - AS2( lea AS_REG_7, [Te]) - AS2( mov edi, [g_cacheLineSize]) -#endif - -#if CRYPTOPP_BOOL_X86 - AS2( mov [ecx+16*12+16*4], esp) // save esp to L_SP - AS2( lea esp, [ecx-768]) -#endif - - // copy subkeys to stack - AS2( mov WORD_REG(si), [L_KEYS_BEGIN]) - AS2( mov WORD_REG(ax), 16) - AS2( and WORD_REG(ax), WORD_REG(si)) - AS2( movdqa xmm3, XMMWORD_PTR [WORD_REG(dx)+16+WORD_REG(ax)]) // subkey 1 (non-counter) or 2 (counter) - AS2( movdqa [L_KEY12], xmm3) - AS2( lea WORD_REG(ax), [WORD_REG(dx)+WORD_REG(ax)+2*16]) - AS2( sub WORD_REG(ax), WORD_REG(si)) - ASL(0) - AS2( movdqa xmm0, [WORD_REG(ax)+WORD_REG(si)]) - AS2( movdqa XMMWORD_PTR [L_SUBKEYS+WORD_REG(si)], xmm0) - AS2( add WORD_REG(si), 16) - AS2( cmp WORD_REG(si), 16*12) - ASJ( jl, 0, b) - - // read subkeys 0, 1 and last - AS2( movdqa xmm4, [WORD_REG(ax)+WORD_REG(si)]) // last subkey - AS2( movdqa xmm1, [WORD_REG(dx)]) // subkey 0 - AS2( MOVD MM(1), [WORD_REG(dx)+4*4]) // 0,1,2,3 - AS2( mov ebx, [WORD_REG(dx)+5*4]) // 4,5,6,7 - AS2( mov ecx, [WORD_REG(dx)+6*4]) // 8,9,10,11 - AS2( mov edx, [WORD_REG(dx)+7*4]) // 12,13,14,15 - - // load table into cache - AS2( xor WORD_REG(ax), WORD_REG(ax)) - ASL(9) - AS2( mov esi, [AS_REG_7+WORD_REG(ax)]) - AS2( add WORD_REG(ax), WORD_REG(di)) - AS2( mov esi, [AS_REG_7+WORD_REG(ax)]) - AS2( add WORD_REG(ax), WORD_REG(di)) - AS2( mov esi, [AS_REG_7+WORD_REG(ax)]) - AS2( add WORD_REG(ax), WORD_REG(di)) - AS2( mov esi, [AS_REG_7+WORD_REG(ax)]) - AS2( add WORD_REG(ax), WORD_REG(di)) - AS2( cmp WORD_REG(ax), 2048) - ASJ( jl, 9, b) - AS1( lfence) - - AS2( test DWORD PTR [L_LENGTH], 1) - ASJ( jz, 8, f) - - // counter mode one-time setup - AS2( mov WORD_REG(si), [L_INBLOCKS]) - AS2( movdqu xmm2, [WORD_REG(si)]) // counter - AS2( pxor xmm2, xmm1) - AS2( psrldq xmm1, 14) - AS2( movd eax, xmm1) - AS2( mov al, BYTE PTR [WORD_REG(si)+15]) - AS2( MOVD MM(2), eax) -#if CRYPTOPP_BOOL_X86 - AS2( mov eax, 1) - AS2( movd mm3, eax) -#endif - - // partial first round, in: xmm2(15,14,13,12;11,10,9,8;7,6,5,4;3,2,1,0), out: mm1, ebx, ecx, edx - AS2( movd eax, xmm2) - AS2( psrldq xmm2, 4) - AS2( movd edi, xmm2) - AS2( psrldq xmm2, 4) - MXOR( 1, al, 0) // 0 - XOR( edx, ah, 1) // 1 - AS2( shr eax, 16) - XOR( ecx, al, 2) // 2 - XOR( ebx, ah, 3) // 3 - AS2( mov eax, edi) - AS2( movd edi, xmm2) - AS2( psrldq xmm2, 4) - XOR( ebx, al, 0) // 4 - MXOR( 1, ah, 1) // 5 - AS2( shr eax, 16) - XOR( edx, al, 2) // 6 - XOR( ecx, ah, 3) // 7 - AS2( mov eax, edi) - AS2( movd edi, xmm2) - XOR( ecx, al, 0) // 8 - XOR( ebx, ah, 1) // 9 - AS2( shr eax, 16) - MXOR( 1, al, 2) // 10 - XOR( edx, ah, 3) // 11 - AS2( mov eax, edi) - XOR( edx, al, 0) // 12 - XOR( ecx, ah, 1) // 13 - AS2( shr eax, 16) - XOR( ebx, al, 2) // 14 - AS2( psrldq xmm2, 3) - - // partial second round, in: ebx(4,5,6,7), ecx(8,9,10,11), edx(12,13,14,15), out: eax, ebx, edi, mm0 - AS2( mov eax, [L_KEY12+0*4]) - AS2( mov edi, [L_KEY12+2*4]) - AS2( MOVD MM(0), [L_KEY12+3*4]) - MXOR( 0, cl, 3) /* 11 */ - XOR( edi, bl, 3) /* 7 */ - MXOR( 0, bh, 2) /* 6 */ - AS2( shr ebx, 16) /* 4,5 */ - XOR( eax, bl, 1) /* 5 */ - MOV( ebx, bh, 0) /* 4 */ - AS2( xor ebx, [L_KEY12+1*4]) - XOR( eax, ch, 2) /* 10 */ - AS2( shr ecx, 16) /* 8,9 */ - XOR( eax, dl, 3) /* 15 */ - XOR( ebx, dh, 2) /* 14 */ - AS2( shr edx, 16) /* 12,13 */ - XOR( edi, ch, 0) /* 8 */ - XOR( ebx, cl, 1) /* 9 */ - XOR( edi, dl, 1) /* 13 */ - MXOR( 0, dh, 0) /* 12 */ - - AS2( movd ecx, xmm2) - AS2( MOVD edx, MM(1)) - AS2( MOVD [L_SAVED_X+3*4], MM(0)) - AS2( mov [L_SAVED_X+0*4], eax) - AS2( mov [L_SAVED_X+1*4], ebx) - AS2( mov [L_SAVED_X+2*4], edi) - ASJ( jmp, 5, f) - - ASL(3) - // non-counter mode per-block setup - AS2( MOVD MM(1), [L_KEY12+0*4]) // 0,1,2,3 - AS2( mov ebx, [L_KEY12+1*4]) // 4,5,6,7 - AS2( mov ecx, [L_KEY12+2*4]) // 8,9,10,11 - AS2( mov edx, [L_KEY12+3*4]) // 12,13,14,15 - ASL(8) - AS2( mov WORD_REG(ax), [L_INBLOCKS]) - AS2( movdqu xmm2, [WORD_REG(ax)]) - AS2( mov WORD_REG(si), [L_INXORBLOCKS]) - AS2( movdqu xmm5, [WORD_REG(si)]) - AS2( pxor xmm2, xmm1) - AS2( pxor xmm2, xmm5) - - // first round, in: xmm2(15,14,13,12;11,10,9,8;7,6,5,4;3,2,1,0), out: eax, ebx, ecx, edx - AS2( movd eax, xmm2) - AS2( psrldq xmm2, 4) - AS2( movd edi, xmm2) - AS2( psrldq xmm2, 4) - MXOR( 1, al, 0) // 0 - XOR( edx, ah, 1) // 1 - AS2( shr eax, 16) - XOR( ecx, al, 2) // 2 - XOR( ebx, ah, 3) // 3 - AS2( mov eax, edi) - AS2( movd edi, xmm2) - AS2( psrldq xmm2, 4) - XOR( ebx, al, 0) // 4 - MXOR( 1, ah, 1) // 5 - AS2( shr eax, 16) - XOR( edx, al, 2) // 6 - XOR( ecx, ah, 3) // 7 - AS2( mov eax, edi) - AS2( movd edi, xmm2) - XOR( ecx, al, 0) // 8 - XOR( ebx, ah, 1) // 9 - AS2( shr eax, 16) - MXOR( 1, al, 2) // 10 - XOR( edx, ah, 3) // 11 - AS2( mov eax, edi) - XOR( edx, al, 0) // 12 - XOR( ecx, ah, 1) // 13 - AS2( shr eax, 16) - XOR( ebx, al, 2) // 14 - MXOR( 1, ah, 3) // 15 - AS2( MOVD eax, MM(1)) - - AS2( add L_REG, [L_KEYS_BEGIN]) - AS2( add L_REG, 4*16) - ASJ( jmp, 2, f) - - ASL(1) - // counter-mode per-block setup - AS2( MOVD ecx, MM(2)) - AS2( MOVD edx, MM(1)) - AS2( mov eax, [L_SAVED_X+0*4]) - AS2( mov ebx, [L_SAVED_X+1*4]) - AS2( xor cl, ch) - AS2( and WORD_REG(cx), 255) - ASL(5) -#if CRYPTOPP_BOOL_X86 - AS2( paddb MM(2), mm3) -#else - AS2( add MM(2), 1) -#endif - // remaining part of second round, in: edx(previous round),esi(keyed counter byte) eax,ebx,[L_SAVED_X+2*4],[L_SAVED_X+3*4], out: eax,ebx,ecx,edx - AS2( xor edx, DWORD PTR [AS_REG_7+WORD_REG(cx)*8+3]) - XOR( ebx, dl, 3) - MOV( ecx, dh, 2) - AS2( shr edx, 16) - AS2( xor ecx, [L_SAVED_X+2*4]) - XOR( eax, dh, 0) - MOV( edx, dl, 1) - AS2( xor edx, [L_SAVED_X+3*4]) - - AS2( add L_REG, [L_KEYS_BEGIN]) - AS2( add L_REG, 3*16) - ASJ( jmp, 4, f) - -// in: eax(0,1,2,3), ebx(4,5,6,7), ecx(8,9,10,11), edx(12,13,14,15) -// out: eax, ebx, edi, mm0 -#define ROUND() \ - MXOR( 0, cl, 3) /* 11 */\ - AS2( mov cl, al) /* 8,9,10,3 */\ - XOR( edi, ah, 2) /* 2 */\ - AS2( shr eax, 16) /* 0,1 */\ - XOR( edi, bl, 3) /* 7 */\ - MXOR( 0, bh, 2) /* 6 */\ - AS2( shr ebx, 16) /* 4,5 */\ - MXOR( 0, al, 1) /* 1 */\ - MOV( eax, ah, 0) /* 0 */\ - XOR( eax, bl, 1) /* 5 */\ - MOV( ebx, bh, 0) /* 4 */\ - XOR( eax, ch, 2) /* 10 */\ - XOR( ebx, cl, 3) /* 3 */\ - AS2( shr ecx, 16) /* 8,9 */\ - XOR( eax, dl, 3) /* 15 */\ - XOR( ebx, dh, 2) /* 14 */\ - AS2( shr edx, 16) /* 12,13 */\ - XOR( edi, ch, 0) /* 8 */\ - XOR( ebx, cl, 1) /* 9 */\ - XOR( edi, dl, 1) /* 13 */\ - MXOR( 0, dh, 0) /* 12 */\ - - ASL(2) // 2-round loop - AS2( MOVD MM(0), [L_SUBKEYS-4*16+3*4]) - AS2( mov edi, [L_SUBKEYS-4*16+2*4]) - ROUND() - AS2( mov ecx, edi) - AS2( xor eax, [L_SUBKEYS-4*16+0*4]) - AS2( xor ebx, [L_SUBKEYS-4*16+1*4]) - AS2( MOVD edx, MM(0)) - - ASL(4) - AS2( MOVD MM(0), [L_SUBKEYS-4*16+7*4]) - AS2( mov edi, [L_SUBKEYS-4*16+6*4]) - ROUND() - AS2( mov ecx, edi) - AS2( xor eax, [L_SUBKEYS-4*16+4*4]) - AS2( xor ebx, [L_SUBKEYS-4*16+5*4]) - AS2( MOVD edx, MM(0)) - - AS2( add L_REG, 32) - AS2( test L_REG, 255) - ASJ( jnz, 2, b) - AS2( sub L_REG, 16*16) - -#define LAST(a, b, c) \ - AS2( movzx esi, a )\ - AS2( movzx edi, BYTE PTR [AS_REG_7+WORD_REG(si)*8+1] )\ - AS2( movzx esi, b )\ - AS2( xor edi, DWORD PTR [AS_REG_7+WORD_REG(si)*8+0] )\ - AS2( mov WORD PTR [L_LASTROUND+c], di )\ - - // last round - LAST(ch, dl, 2) - LAST(dh, al, 6) - AS2( shr edx, 16) - LAST(ah, bl, 10) - AS2( shr eax, 16) - LAST(bh, cl, 14) - AS2( shr ebx, 16) - LAST(dh, al, 12) - AS2( shr ecx, 16) - LAST(ah, bl, 0) - LAST(bh, cl, 4) - LAST(ch, dl, 8) - - AS2( mov WORD_REG(ax), [L_OUTXORBLOCKS]) - AS2( mov WORD_REG(bx), [L_OUTBLOCKS]) - - AS2( mov WORD_REG(cx), [L_LENGTH]) - AS2( sub WORD_REG(cx), 16) - - AS2( movdqu xmm2, [WORD_REG(ax)]) - AS2( pxor xmm2, xmm4) - -#if CRYPTOPP_BOOL_X86 - AS2( movdqa xmm0, [L_INCREMENTS]) - AS2( paddd xmm0, [L_INBLOCKS]) - AS2( movdqa [L_INBLOCKS], xmm0) -#else - AS2( movdqa xmm0, [L_INCREMENTS+16]) - AS2( paddq xmm0, [L_INBLOCKS+16]) - AS2( movdqa [L_INBLOCKS+16], xmm0) -#endif - - AS2( pxor xmm2, [L_LASTROUND]) - AS2( movdqu [WORD_REG(bx)], xmm2) - - ASJ( jle, 7, f) - AS2( mov [L_LENGTH], WORD_REG(cx)) - AS2( test WORD_REG(cx), 1) - ASJ( jnz, 1, b) -#if CRYPTOPP_BOOL_X64 - AS2( movdqa xmm0, [L_INCREMENTS]) - AS2( paddq xmm0, [L_INBLOCKS]) - AS2( movdqa [L_INBLOCKS], xmm0) -#endif - ASJ( jmp, 3, b) - - ASL(7) - // erase keys on stack - AS2( xorps xmm0, xmm0) - AS2( lea WORD_REG(ax), [L_SUBKEYS+7*16]) - AS2( movaps [WORD_REG(ax)-7*16], xmm0) - AS2( movaps [WORD_REG(ax)-6*16], xmm0) - AS2( movaps [WORD_REG(ax)-5*16], xmm0) - AS2( movaps [WORD_REG(ax)-4*16], xmm0) - AS2( movaps [WORD_REG(ax)-3*16], xmm0) - AS2( movaps [WORD_REG(ax)-2*16], xmm0) - AS2( movaps [WORD_REG(ax)-1*16], xmm0) - AS2( movaps [WORD_REG(ax)+0*16], xmm0) - AS2( movaps [WORD_REG(ax)+1*16], xmm0) - AS2( movaps [WORD_REG(ax)+2*16], xmm0) - AS2( movaps [WORD_REG(ax)+3*16], xmm0) - AS2( movaps [WORD_REG(ax)+4*16], xmm0) - AS2( movaps [WORD_REG(ax)+5*16], xmm0) - AS2( movaps [WORD_REG(ax)+6*16], xmm0) -#if CRYPTOPP_BOOL_X86 - AS2( mov esp, [L_SP]) - AS1( emms) -#endif - AS_POP_IF86(bp) - AS_POP_IF86(bx) -#if defined(_MSC_VER) && CRYPTOPP_BOOL_X86 - AS_POP_IF86(di) - AS_POP_IF86(si) - AS1(ret) -#endif -#ifdef CRYPTOPP_GENERATE_X64_MASM - pop r12 - pop rbx - pop rdi - pop rsi - ret - Rijndael_Enc_AdvancedProcessBlocks ENDP -#endif -#ifdef __GNUC__ - ".att_syntax prefix;" - : - : "c" (locals), "d" (k), "S" (Te), "D" (g_cacheLineSize) - : "memory", "cc", "%eax" - #if CRYPTOPP_BOOL_X64 - , "%rbx", "%r8", "%r9", "%r10", "%r11", "%r12" - #endif - ); -#endif -} - -#endif - -#ifndef CRYPTOPP_GENERATE_X64_MASM - -#ifdef CRYPTOPP_X64_MASM_AVAILABLE -extern "C" { -void Rijndael_Enc_AdvancedProcessBlocks(void *locals, const word32 *k); -} -#endif - -#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86 - -static inline bool AliasedWithTable(const byte *begin, const byte *end) -{ - size_t s0 = size_t(begin)%4096, s1 = size_t(end)%4096; - size_t t0 = size_t(Te)%4096, t1 = (size_t(Te)+sizeof(Te))%4096; - if (t1 > t0) - return (s0 >= t0 && s0 < t1) || (s1 > t0 && s1 <= t1); - else - return (s0 < t1 || s1 <= t1) || (s0 >= t0 || s1 > t0); -} - -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE - -inline void AESNI_Enc_Block(__m128i &block, const __m128i *subkeys, unsigned int rounds) -{ - block = _mm_xor_si128(block, subkeys[0]); - for (unsigned int i=1; i -inline size_t AESNI_AdvancedProcessBlocks(F1 func1, F4 func4, const __m128i *subkeys, unsigned int rounds, const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) -{ - size_t blockSize = 16; - size_t inIncrement = (flags & (BlockTransformation::BT_InBlockIsCounter|BlockTransformation::BT_DontIncrementInOutPointers)) ? 0 : blockSize; - size_t xorIncrement = xorBlocks ? blockSize : 0; - size_t outIncrement = (flags & BlockTransformation::BT_DontIncrementInOutPointers) ? 0 : blockSize; - - if (flags & BlockTransformation::BT_ReverseDirection) - { - assert(length % blockSize == 0); - inBlocks += length - blockSize; - xorBlocks += length - blockSize; - outBlocks += length - blockSize; - inIncrement = 0-inIncrement; - xorIncrement = 0-xorIncrement; - outIncrement = 0-outIncrement; - } - - if (flags & BlockTransformation::BT_AllowParallel) - { - while (length >= 4*blockSize) - { - __m128i block0 = _mm_loadu_si128((const __m128i *)inBlocks), block1, block2, block3; - if (flags & BlockTransformation::BT_InBlockIsCounter) - { - const __m128i be1 = *(const __m128i *)s_one; - block1 = _mm_add_epi32(block0, be1); - block2 = _mm_add_epi32(block1, be1); - block3 = _mm_add_epi32(block2, be1); - _mm_storeu_si128((__m128i *)inBlocks, _mm_add_epi32(block3, be1)); - } - else - { - inBlocks += inIncrement; - block1 = _mm_loadu_si128((const __m128i *)inBlocks); - inBlocks += inIncrement; - block2 = _mm_loadu_si128((const __m128i *)inBlocks); - inBlocks += inIncrement; - block3 = _mm_loadu_si128((const __m128i *)inBlocks); - inBlocks += inIncrement; - } - - if (flags & BlockTransformation::BT_XorInput) - { - block0 = _mm_xor_si128(block0, _mm_loadu_si128((const __m128i *)xorBlocks)); - xorBlocks += xorIncrement; - block1 = _mm_xor_si128(block1, _mm_loadu_si128((const __m128i *)xorBlocks)); - xorBlocks += xorIncrement; - block2 = _mm_xor_si128(block2, _mm_loadu_si128((const __m128i *)xorBlocks)); - xorBlocks += xorIncrement; - block3 = _mm_xor_si128(block3, _mm_loadu_si128((const __m128i *)xorBlocks)); - xorBlocks += xorIncrement; - } - - func4(block0, block1, block2, block3, subkeys, rounds); - - if (xorBlocks && !(flags & BlockTransformation::BT_XorInput)) - { - block0 = _mm_xor_si128(block0, _mm_loadu_si128((const __m128i *)xorBlocks)); - xorBlocks += xorIncrement; - block1 = _mm_xor_si128(block1, _mm_loadu_si128((const __m128i *)xorBlocks)); - xorBlocks += xorIncrement; - block2 = _mm_xor_si128(block2, _mm_loadu_si128((const __m128i *)xorBlocks)); - xorBlocks += xorIncrement; - block3 = _mm_xor_si128(block3, _mm_loadu_si128((const __m128i *)xorBlocks)); - xorBlocks += xorIncrement; - } - - _mm_storeu_si128((__m128i *)outBlocks, block0); - outBlocks += outIncrement; - _mm_storeu_si128((__m128i *)outBlocks, block1); - outBlocks += outIncrement; - _mm_storeu_si128((__m128i *)outBlocks, block2); - outBlocks += outIncrement; - _mm_storeu_si128((__m128i *)outBlocks, block3); - outBlocks += outIncrement; - - length -= 4*blockSize; - } - } - - while (length >= blockSize) - { - __m128i block = _mm_loadu_si128((const __m128i *)inBlocks); - - if (flags & BlockTransformation::BT_XorInput) - block = _mm_xor_si128(block, _mm_loadu_si128((const __m128i *)xorBlocks)); - - if (flags & BlockTransformation::BT_InBlockIsCounter) - const_cast(inBlocks)[15]++; - - func1(block, subkeys, rounds); - - if (xorBlocks && !(flags & BlockTransformation::BT_XorInput)) - block = _mm_xor_si128(block, _mm_loadu_si128((const __m128i *)xorBlocks)); - - _mm_storeu_si128((__m128i *)outBlocks, block); - - inBlocks += inIncrement; - outBlocks += outIncrement; - xorBlocks += xorIncrement; - length -= blockSize; - } - - return length; -} -#endif - -size_t Rijndael::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const -{ -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE - if (HasAESNI()) - return AESNI_AdvancedProcessBlocks(AESNI_Enc_Block, AESNI_Enc_4_Blocks, (const __m128i *)m_key.begin(), m_rounds, inBlocks, xorBlocks, outBlocks, length, flags); -#endif - -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) - if (HasSSE2()) - { - if (length < BLOCKSIZE) - return length; - - struct Locals - { - word32 subkeys[4*12], workspace[8]; - const byte *inBlocks, *inXorBlocks, *outXorBlocks; - byte *outBlocks; - size_t inIncrement, inXorIncrement, outXorIncrement, outIncrement; - size_t regSpill, lengthAndCounterFlag, keysBegin; - }; - - size_t increment = BLOCKSIZE; - const byte* zeros = (byte *)(Te+256); - byte *space; - - do { - space = (byte *)alloca(255+sizeof(Locals)); - space += (256-(size_t)space%256)%256; - } - while (AliasedWithTable(space, space+sizeof(Locals))); - - if (flags & BT_ReverseDirection) - { - assert(length % BLOCKSIZE == 0); - inBlocks += length - BLOCKSIZE; - xorBlocks += length - BLOCKSIZE; - outBlocks += length - BLOCKSIZE; - increment = 0-increment; - } - - Locals &locals = *(Locals *)space; - - locals.inBlocks = inBlocks; - locals.inXorBlocks = (flags & BT_XorInput) && xorBlocks ? xorBlocks : zeros; - locals.outXorBlocks = (flags & BT_XorInput) || !xorBlocks ? zeros : xorBlocks; - locals.outBlocks = outBlocks; - - locals.inIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : increment; - locals.inXorIncrement = (flags & BT_XorInput) && xorBlocks ? increment : 0; - locals.outXorIncrement = (flags & BT_XorInput) || !xorBlocks ? 0 : increment; - locals.outIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : increment; - - locals.lengthAndCounterFlag = length - (length%16) - bool(flags & BT_InBlockIsCounter); - int keysToCopy = m_rounds - (flags & BT_InBlockIsCounter ? 3 : 2); - locals.keysBegin = (12-keysToCopy)*16; - - Rijndael_Enc_AdvancedProcessBlocks(&locals, m_key); - return length % BLOCKSIZE; - } -#endif - - return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags); -} - -#endif - -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE - -size_t Rijndael::Dec::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const -{ - if (HasAESNI()) - return AESNI_AdvancedProcessBlocks(AESNI_Dec_Block, AESNI_Dec_4_Blocks, (const __m128i *)m_key.begin(), m_rounds, inBlocks, xorBlocks, outBlocks, length, flags); - - return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags); -} - -#endif // #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE - -NAMESPACE_END - -#endif -#endif diff --git a/lib/cryptopp/rijndael.h b/lib/cryptopp/rijndael.h deleted file mode 100644 index 64c784b07..000000000 --- a/lib/cryptopp/rijndael.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef CRYPTOPP_RIJNDAEL_H -#define CRYPTOPP_RIJNDAEL_H - -/** \file -*/ - -#include "seckey.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -struct Rijndael_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8> -{ - CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return CRYPTOPP_RIJNDAEL_NAME;} -}; - -/// Rijndael -class CRYPTOPP_DLL Rijndael : public Rijndael_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl - { - public: - void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); - - protected: - static void FillEncTable(); - static void FillDecTable(); - - // VS2005 workaround: have to put these on seperate lines, or error C2487 is triggered in DLL build - static const byte Se[256]; - static const byte Sd[256]; - - static const word32 rcon[]; - - unsigned int m_rounds; - FixedSizeAlignedSecBlock m_key; - }; - - class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Enc : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; -#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86 - size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const; -#endif - }; - - class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Dec : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE - size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const; -#endif - }; - -public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -typedef Rijndael::Encryption RijndaelEncryption; -typedef Rijndael::Decryption RijndaelDecryption; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/rng.cpp b/lib/cryptopp/rng.cpp deleted file mode 100644 index 9866cd831..000000000 --- a/lib/cryptopp/rng.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// rng.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#include "rng.h" -#include "fips140.h" - -#include -#include - -NAMESPACE_BEGIN(CryptoPP) - -// linear congruential generator -// originally by William S. England - -// do not use for cryptographic purposes - -/* -** Original_numbers are the original published m and q in the -** ACM article above. John Burton has furnished numbers for -** a reportedly better generator. The new numbers are now -** used in this program by default. -*/ - -#ifndef LCRNG_ORIGINAL_NUMBERS -const word32 LC_RNG::m=2147483647L; -const word32 LC_RNG::q=44488L; - -const word16 LC_RNG::a=(unsigned int)48271L; -const word16 LC_RNG::r=3399; -#else -const word32 LC_RNG::m=2147483647L; -const word32 LC_RNG::q=127773L; - -const word16 LC_RNG::a=16807; -const word16 LC_RNG::r=2836; -#endif - -void LC_RNG::GenerateBlock(byte *output, size_t size) -{ - while (size--) - { - word32 hi = seed/q; - word32 lo = seed%q; - - long test = a*lo - r*hi; - - if (test > 0) - seed = test; - else - seed = test+ m; - - *output++ = (GETBYTE(seed, 0) ^ GETBYTE(seed, 1) ^ GETBYTE(seed, 2) ^ GETBYTE(seed, 3)); - } -} - -// ******************************************************** - -#ifndef CRYPTOPP_IMPORTS - -X917RNG::X917RNG(BlockTransformation *c, const byte *seed, const byte *deterministicTimeVector) - : cipher(c), - S(cipher->BlockSize()), - dtbuf(S), - randseed(seed, S), - m_lastBlock(S), - m_deterministicTimeVector(deterministicTimeVector, deterministicTimeVector ? S : 0) -{ - if (!deterministicTimeVector) - { - time_t tstamp1 = time(0); - xorbuf(dtbuf, (byte *)&tstamp1, UnsignedMin(sizeof(tstamp1), S)); - cipher->ProcessBlock(dtbuf); - clock_t tstamp2 = clock(); - xorbuf(dtbuf, (byte *)&tstamp2, UnsignedMin(sizeof(tstamp2), S)); - cipher->ProcessBlock(dtbuf); - } - - // for FIPS 140-2 - GenerateBlock(m_lastBlock, S); -} - -void X917RNG::GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size) -{ - while (size > 0) - { - // calculate new enciphered timestamp - if (m_deterministicTimeVector.size()) - { - cipher->ProcessBlock(m_deterministicTimeVector, dtbuf); - IncrementCounterByOne(m_deterministicTimeVector, S); - } - else - { - clock_t c = clock(); - xorbuf(dtbuf, (byte *)&c, UnsignedMin(sizeof(c), S)); - time_t t = time(NULL); - xorbuf(dtbuf+S-UnsignedMin(sizeof(t), S), (byte *)&t, UnsignedMin(sizeof(t), S)); - cipher->ProcessBlock(dtbuf); - } - - // combine enciphered timestamp with seed - xorbuf(randseed, dtbuf, S); - - // generate a new block of random bytes - cipher->ProcessBlock(randseed); - if (memcmp(m_lastBlock, randseed, S) == 0) - throw SelfTestFailure("X917RNG: Continuous random number generator test failed."); - - // output random bytes - size_t len = UnsignedMin(S, size); - target.ChannelPut(channel, randseed, len); - size -= len; - - // compute new seed vector - memcpy(m_lastBlock, randseed, S); - xorbuf(randseed, dtbuf, S); - cipher->ProcessBlock(randseed); - } -} - -#endif - -MaurerRandomnessTest::MaurerRandomnessTest() - : sum(0.0), n(0) -{ - for (unsigned i=0; i= Q) - sum += log(double(n - tab[inByte])); - tab[inByte] = n; - n++; - } - return 0; -} - -double MaurerRandomnessTest::GetTestValue() const -{ - if (BytesNeeded() > 0) - throw Exception(Exception::OTHER_ERROR, "MaurerRandomnessTest: " + IntToString(BytesNeeded()) + " more bytes of input needed"); - - double fTu = (sum/(n-Q))/log(2.0); // this is the test value defined by Maurer - - double value = fTu * 0.1392; // arbitrarily normalize it to - return value > 1.0 ? 1.0 : value; // a number between 0 and 1 -} - -NAMESPACE_END diff --git a/lib/cryptopp/rng.h b/lib/cryptopp/rng.h deleted file mode 100644 index 2439dee69..000000000 --- a/lib/cryptopp/rng.h +++ /dev/null @@ -1,77 +0,0 @@ -// rng.h - misc RNG related classes, see also osrng.h, randpool.h - -#ifndef CRYPTOPP_RNG_H -#define CRYPTOPP_RNG_H - -#include "cryptlib.h" -#include "filters.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! linear congruential generator -/*! originally by William S. England, do not use for cryptographic purposes */ -class LC_RNG : public RandomNumberGenerator -{ -public: - LC_RNG(word32 init_seed) - : seed(init_seed) {} - - void GenerateBlock(byte *output, size_t size); - - word32 GetSeed() {return seed;} - -private: - word32 seed; - - static const word32 m; - static const word32 q; - static const word16 a; - static const word16 r; -}; - -//! RNG derived from ANSI X9.17 Appendix C - -class CRYPTOPP_DLL X917RNG : public RandomNumberGenerator, public NotCopyable -{ -public: - // cipher will be deleted by destructor, deterministicTimeVector = 0 means obtain time vector from system - X917RNG(BlockTransformation *cipher, const byte *seed, const byte *deterministicTimeVector = 0); - - void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size); - -private: - member_ptr cipher; - unsigned int S; // blocksize of cipher - SecByteBlock dtbuf; // buffer for enciphered timestamp - SecByteBlock randseed, m_lastBlock, m_deterministicTimeVector; -}; - -/** This class implements Maurer's Universal Statistical Test for Random Bit Generators - it is intended for measuring the randomness of *PHYSICAL* RNGs. - For more details see his paper in Journal of Cryptology, 1992. */ - -class MaurerRandomnessTest : public Bufferless -{ -public: - MaurerRandomnessTest(); - - size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking); - - // BytesNeeded() returns how many more bytes of input is needed by the test - // GetTestValue() should not be called before BytesNeeded()==0 - unsigned int BytesNeeded() const {return n >= (Q+K) ? 0 : Q+K-n;} - - // returns a number between 0.0 and 1.0, describing the quality of the - // random numbers entered - double GetTestValue() const; - -private: - enum {L=8, V=256, Q=2000, K=2000}; - double sum; - unsigned int n; - unsigned int tab[V]; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/rsa.cpp b/lib/cryptopp/rsa.cpp deleted file mode 100644 index 59449c40e..000000000 --- a/lib/cryptopp/rsa.cpp +++ /dev/null @@ -1,304 +0,0 @@ -// rsa.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "rsa.h" -#include "asn.h" -#include "oids.h" -#include "modarith.h" -#include "nbtheory.h" -#include "sha.h" -#include "algparam.h" -#include "fips140.h" - -#if !defined(NDEBUG) && !defined(CRYPTOPP_IS_DLL) -#include "pssr.h" -NAMESPACE_BEGIN(CryptoPP) -void RSA_TestInstantiations() -{ - RSASS::Verifier x1(1, 1); - RSASS::Signer x2(NullRNG(), 1); - RSASS::Verifier x3(x2); - RSASS::Verifier x4(x2.GetKey()); - RSASS::Verifier x5(x3); -#ifndef __MWERKS__ - RSASS::Signer x6 = x2; - x3 = x2; - x6 = x2; -#endif - RSAES::Encryptor x7(x2); -#ifndef __GNUC__ - RSAES::Encryptor x8(x3); -#endif - RSAES >::Encryptor x9(x2); - - x4 = x2.GetKey(); -} -NAMESPACE_END -#endif - -#ifndef CRYPTOPP_IMPORTS - -NAMESPACE_BEGIN(CryptoPP) - -OID RSAFunction::GetAlgorithmID() const -{ - return ASN1::rsaEncryption(); -} - -void RSAFunction::BERDecodePublicKey(BufferedTransformation &bt, bool, size_t) -{ - BERSequenceDecoder seq(bt); - m_n.BERDecode(seq); - m_e.BERDecode(seq); - seq.MessageEnd(); -} - -void RSAFunction::DEREncodePublicKey(BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - m_n.DEREncode(seq); - m_e.DEREncode(seq); - seq.MessageEnd(); -} - -Integer RSAFunction::ApplyFunction(const Integer &x) const -{ - DoQuickSanityCheck(); - return a_exp_b_mod_c(x, m_e, m_n); -} - -bool RSAFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = true; - pass = pass && m_n > Integer::One() && m_n.IsOdd(); - pass = pass && m_e > Integer::One() && m_e.IsOdd() && m_e < m_n; - return pass; -} - -bool RSAFunction::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - return GetValueHelper(this, name, valueType, pValue).Assignable() - CRYPTOPP_GET_FUNCTION_ENTRY(Modulus) - CRYPTOPP_GET_FUNCTION_ENTRY(PublicExponent) - ; -} - -void RSAFunction::AssignFrom(const NameValuePairs &source) -{ - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(Modulus) - CRYPTOPP_SET_FUNCTION_ENTRY(PublicExponent) - ; -} - -// ***************************************************************************** - -class RSAPrimeSelector : public PrimeSelector -{ -public: - RSAPrimeSelector(const Integer &e) : m_e(e) {} - bool IsAcceptable(const Integer &candidate) const {return RelativelyPrime(m_e, candidate-Integer::One());} - Integer m_e; -}; - -void InvertibleRSAFunction::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg) -{ - int modulusSize = 2048; - alg.GetIntValue(Name::ModulusSize(), modulusSize) || alg.GetIntValue(Name::KeySize(), modulusSize); - - if (modulusSize < 16) - throw InvalidArgument("InvertibleRSAFunction: specified modulus size is too small"); - - m_e = alg.GetValueWithDefault(Name::PublicExponent(), Integer(17)); - - if (m_e < 3 || m_e.IsEven()) - throw InvalidArgument("InvertibleRSAFunction: invalid public exponent"); - - RSAPrimeSelector selector(m_e); - AlgorithmParameters primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize) - (Name::PointerToPrimeSelector(), selector.GetSelectorPointer()); - m_p.GenerateRandom(rng, primeParam); - m_q.GenerateRandom(rng, primeParam); - - m_d = m_e.InverseMod(LCM(m_p-1, m_q-1)); - assert(m_d.IsPositive()); - - m_dp = m_d % (m_p-1); - m_dq = m_d % (m_q-1); - m_n = m_p * m_q; - m_u = m_q.InverseMod(m_p); - - if (FIPS_140_2_ComplianceEnabled()) - { - RSASS::Signer signer(*this); - RSASS::Verifier verifier(signer); - SignaturePairwiseConsistencyTest_FIPS_140_Only(signer, verifier); - - RSAES >::Decryptor decryptor(*this); - RSAES >::Encryptor encryptor(decryptor); - EncryptionPairwiseConsistencyTest_FIPS_140_Only(encryptor, decryptor); - } -} - -void InvertibleRSAFunction::Initialize(RandomNumberGenerator &rng, unsigned int keybits, const Integer &e) -{ - GenerateRandom(rng, MakeParameters(Name::ModulusSize(), (int)keybits)(Name::PublicExponent(), e+e.IsEven())); -} - -void InvertibleRSAFunction::Initialize(const Integer &n, const Integer &e, const Integer &d) -{ - if (n.IsEven() || e.IsEven() | d.IsEven()) - throw InvalidArgument("InvertibleRSAFunction: input is not a valid RSA private key"); - - m_n = n; - m_e = e; - m_d = d; - - Integer r = --(d*e); - unsigned int s = 0; - while (r.IsEven()) - { - r >>= 1; - s++; - } - - ModularArithmetic modn(n); - for (Integer i = 2; ; ++i) - { - Integer a = modn.Exponentiate(i, r); - if (a == 1) - continue; - Integer b; - unsigned int j = 0; - while (a != n-1) - { - b = modn.Square(a); - if (b == 1) - { - m_p = GCD(a-1, n); - m_q = n/m_p; - m_dp = m_d % (m_p-1); - m_dq = m_d % (m_q-1); - m_u = m_q.InverseMod(m_p); - return; - } - if (++j == s) - throw InvalidArgument("InvertibleRSAFunction: input is not a valid RSA private key"); - a = b; - } - } -} - -void InvertibleRSAFunction::BERDecodePrivateKey(BufferedTransformation &bt, bool, size_t) -{ - BERSequenceDecoder privateKey(bt); - word32 version; - BERDecodeUnsigned(privateKey, version, INTEGER, 0, 0); // check version - m_n.BERDecode(privateKey); - m_e.BERDecode(privateKey); - m_d.BERDecode(privateKey); - m_p.BERDecode(privateKey); - m_q.BERDecode(privateKey); - m_dp.BERDecode(privateKey); - m_dq.BERDecode(privateKey); - m_u.BERDecode(privateKey); - privateKey.MessageEnd(); -} - -void InvertibleRSAFunction::DEREncodePrivateKey(BufferedTransformation &bt) const -{ - DERSequenceEncoder privateKey(bt); - DEREncodeUnsigned(privateKey, 0); // version - m_n.DEREncode(privateKey); - m_e.DEREncode(privateKey); - m_d.DEREncode(privateKey); - m_p.DEREncode(privateKey); - m_q.DEREncode(privateKey); - m_dp.DEREncode(privateKey); - m_dq.DEREncode(privateKey); - m_u.DEREncode(privateKey); - privateKey.MessageEnd(); -} - -Integer InvertibleRSAFunction::CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const -{ - DoQuickSanityCheck(); - ModularArithmetic modn(m_n); - Integer r, rInv; - do { // do this in a loop for people using small numbers for testing - r.Randomize(rng, Integer::One(), m_n - Integer::One()); - rInv = modn.MultiplicativeInverse(r); - } while (rInv.IsZero()); - Integer re = modn.Exponentiate(r, m_e); - re = modn.Multiply(re, x); // blind - // here we follow the notation of PKCS #1 and let u=q inverse mod p - // but in ModRoot, u=p inverse mod q, so we reverse the order of p and q - Integer y = ModularRoot(re, m_dq, m_dp, m_q, m_p, m_u); - y = modn.Multiply(y, rInv); // unblind - if (modn.Exponentiate(y, m_e) != x) // check - throw Exception(Exception::OTHER_ERROR, "InvertibleRSAFunction: computational error during private key operation"); - return y; -} - -bool InvertibleRSAFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = RSAFunction::Validate(rng, level); - pass = pass && m_p > Integer::One() && m_p.IsOdd() && m_p < m_n; - pass = pass && m_q > Integer::One() && m_q.IsOdd() && m_q < m_n; - pass = pass && m_d > Integer::One() && m_d.IsOdd() && m_d < m_n; - pass = pass && m_dp > Integer::One() && m_dp.IsOdd() && m_dp < m_p; - pass = pass && m_dq > Integer::One() && m_dq.IsOdd() && m_dq < m_q; - pass = pass && m_u.IsPositive() && m_u < m_p; - if (level >= 1) - { - pass = pass && m_p * m_q == m_n; - pass = pass && m_e*m_d % LCM(m_p-1, m_q-1) == 1; - pass = pass && m_dp == m_d%(m_p-1) && m_dq == m_d%(m_q-1); - pass = pass && m_u * m_q % m_p == 1; - } - if (level >= 2) - pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2); - return pass; -} - -bool InvertibleRSAFunction::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - return GetValueHelper(this, name, valueType, pValue).Assignable() - CRYPTOPP_GET_FUNCTION_ENTRY(Prime1) - CRYPTOPP_GET_FUNCTION_ENTRY(Prime2) - CRYPTOPP_GET_FUNCTION_ENTRY(PrivateExponent) - CRYPTOPP_GET_FUNCTION_ENTRY(ModPrime1PrivateExponent) - CRYPTOPP_GET_FUNCTION_ENTRY(ModPrime2PrivateExponent) - CRYPTOPP_GET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1) - ; -} - -void InvertibleRSAFunction::AssignFrom(const NameValuePairs &source) -{ - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(Prime1) - CRYPTOPP_SET_FUNCTION_ENTRY(Prime2) - CRYPTOPP_SET_FUNCTION_ENTRY(PrivateExponent) - CRYPTOPP_SET_FUNCTION_ENTRY(ModPrime1PrivateExponent) - CRYPTOPP_SET_FUNCTION_ENTRY(ModPrime2PrivateExponent) - CRYPTOPP_SET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1) - ; -} - -// ***************************************************************************** - -Integer RSAFunction_ISO::ApplyFunction(const Integer &x) const -{ - Integer t = RSAFunction::ApplyFunction(x); - return t % 16 == 12 ? t : m_n - t; -} - -Integer InvertibleRSAFunction_ISO::CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const -{ - Integer t = InvertibleRSAFunction::CalculateInverse(rng, x); - return STDMIN(t, m_n-t); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/rsa.h b/lib/cryptopp/rsa.h deleted file mode 100644 index 6a8b18525..000000000 --- a/lib/cryptopp/rsa.h +++ /dev/null @@ -1,174 +0,0 @@ -#ifndef CRYPTOPP_RSA_H -#define CRYPTOPP_RSA_H - -/** \file - This file contains classes that implement the RSA - ciphers and signature schemes as defined in PKCS #1 v2.0. -*/ - -#include "pubkey.h" -#include "asn.h" -#include "pkcspad.h" -#include "oaep.h" -#include "emsa2.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -class CRYPTOPP_DLL RSAFunction : public TrapdoorFunction, public X509PublicKey -{ - typedef RSAFunction ThisClass; - -public: - void Initialize(const Integer &n, const Integer &e) - {m_n = n; m_e = e;} - - // X509PublicKey - OID GetAlgorithmID() const; - void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size); - void DEREncodePublicKey(BufferedTransformation &bt) const; - - // CryptoMaterial - bool Validate(RandomNumberGenerator &rng, unsigned int level) const; - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - - // TrapdoorFunction - Integer ApplyFunction(const Integer &x) const; - Integer PreimageBound() const {return m_n;} - Integer ImageBound() const {return m_n;} - - // non-derived - const Integer & GetModulus() const {return m_n;} - const Integer & GetPublicExponent() const {return m_e;} - - void SetModulus(const Integer &n) {m_n = n;} - void SetPublicExponent(const Integer &e) {m_e = e;} - -protected: - Integer m_n, m_e; -}; - -//! _ -class CRYPTOPP_DLL InvertibleRSAFunction : public RSAFunction, public TrapdoorFunctionInverse, public PKCS8PrivateKey -{ - typedef InvertibleRSAFunction ThisClass; - -public: - void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &e = 17); - void Initialize(const Integer &n, const Integer &e, const Integer &d, const Integer &p, const Integer &q, const Integer &dp, const Integer &dq, const Integer &u) - {m_n = n; m_e = e; m_d = d; m_p = p; m_q = q; m_dp = dp; m_dq = dq; m_u = u;} - //! factor n given private exponent - void Initialize(const Integer &n, const Integer &e, const Integer &d); - - // PKCS8PrivateKey - void BERDecode(BufferedTransformation &bt) - {PKCS8PrivateKey::BERDecode(bt);} - void DEREncode(BufferedTransformation &bt) const - {PKCS8PrivateKey::DEREncode(bt);} - void Load(BufferedTransformation &bt) - {PKCS8PrivateKey::BERDecode(bt);} - void Save(BufferedTransformation &bt) const - {PKCS8PrivateKey::DEREncode(bt);} - OID GetAlgorithmID() const {return RSAFunction::GetAlgorithmID();} - void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size); - void DEREncodePrivateKey(BufferedTransformation &bt) const; - - // TrapdoorFunctionInverse - Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const; - - // GeneratableCryptoMaterial - bool Validate(RandomNumberGenerator &rng, unsigned int level) const; - /*! parameters: (ModulusSize, PublicExponent (default 17)) */ - void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - - // non-derived interface - const Integer& GetPrime1() const {return m_p;} - const Integer& GetPrime2() const {return m_q;} - const Integer& GetPrivateExponent() const {return m_d;} - const Integer& GetModPrime1PrivateExponent() const {return m_dp;} - const Integer& GetModPrime2PrivateExponent() const {return m_dq;} - const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;} - - void SetPrime1(const Integer &p) {m_p = p;} - void SetPrime2(const Integer &q) {m_q = q;} - void SetPrivateExponent(const Integer &d) {m_d = d;} - void SetModPrime1PrivateExponent(const Integer &dp) {m_dp = dp;} - void SetModPrime2PrivateExponent(const Integer &dq) {m_dq = dq;} - void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;} - -protected: - Integer m_d, m_p, m_q, m_dp, m_dq, m_u; -}; - -class CRYPTOPP_DLL RSAFunction_ISO : public RSAFunction -{ -public: - Integer ApplyFunction(const Integer &x) const; - Integer PreimageBound() const {return ++(m_n>>1);} -}; - -class CRYPTOPP_DLL InvertibleRSAFunction_ISO : public InvertibleRSAFunction -{ -public: - Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const; - Integer PreimageBound() const {return ++(m_n>>1);} -}; - -//! RSA -struct CRYPTOPP_DLL RSA -{ - static const char * CRYPTOPP_API StaticAlgorithmName() {return "RSA";} - typedef RSAFunction PublicKey; - typedef InvertibleRSAFunction PrivateKey; -}; - -//! RSA cryptosystem -template -struct RSAES : public TF_ES -{ -}; - -//! RSA signature scheme with appendix -/*! See documentation of PKCS1v15 for a list of hash functions that can be used with it. */ -template -struct RSASS : public TF_SS -{ -}; - -struct CRYPTOPP_DLL RSA_ISO -{ - static const char * CRYPTOPP_API StaticAlgorithmName() {return "RSA-ISO";} - typedef RSAFunction_ISO PublicKey; - typedef InvertibleRSAFunction_ISO PrivateKey; -}; - -template -struct RSASS_ISO : public TF_SS -{ -}; - -// The two RSA encryption schemes defined in PKCS #1 v2.0 -typedef RSAES::Decryptor RSAES_PKCS1v15_Decryptor; -typedef RSAES::Encryptor RSAES_PKCS1v15_Encryptor; - -typedef RSAES >::Decryptor RSAES_OAEP_SHA_Decryptor; -typedef RSAES >::Encryptor RSAES_OAEP_SHA_Encryptor; - -// The three RSA signature schemes defined in PKCS #1 v2.0 -typedef RSASS::Signer RSASSA_PKCS1v15_SHA_Signer; -typedef RSASS::Verifier RSASSA_PKCS1v15_SHA_Verifier; - -namespace Weak { -typedef RSASS::Signer RSASSA_PKCS1v15_MD2_Signer; -typedef RSASS::Verifier RSASSA_PKCS1v15_MD2_Verifier; - -typedef RSASS::Signer RSASSA_PKCS1v15_MD5_Signer; -typedef RSASS::Verifier RSASSA_PKCS1v15_MD5_Verifier; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/rw.cpp b/lib/cryptopp/rw.cpp deleted file mode 100644 index cdd9f2d22..000000000 --- a/lib/cryptopp/rw.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// rw.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "rw.h" -#include "nbtheory.h" -#include "asn.h" - -#ifndef CRYPTOPP_IMPORTS - -NAMESPACE_BEGIN(CryptoPP) - -void RWFunction::BERDecode(BufferedTransformation &bt) -{ - BERSequenceDecoder seq(bt); - m_n.BERDecode(seq); - seq.MessageEnd(); -} - -void RWFunction::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - m_n.DEREncode(seq); - seq.MessageEnd(); -} - -Integer RWFunction::ApplyFunction(const Integer &in) const -{ - DoQuickSanityCheck(); - - Integer out = in.Squared()%m_n; - const word r = 12; - // this code was written to handle both r = 6 and r = 12, - // but now only r = 12 is used in P1363 - const word r2 = r/2; - const word r3a = (16 + 5 - r) % 16; // n%16 could be 5 or 13 - const word r3b = (16 + 13 - r) % 16; - const word r4 = (8 + 5 - r/2) % 8; // n%8 == 5 - switch (out % 16) - { - case r: - break; - case r2: - case r2+8: - out <<= 1; - break; - case r3a: - case r3b: - out.Negate(); - out += m_n; - break; - case r4: - case r4+8: - out.Negate(); - out += m_n; - out <<= 1; - break; - default: - out = Integer::Zero(); - } - return out; -} - -bool RWFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = true; - pass = pass && m_n > Integer::One() && m_n%8 == 5; - return pass; -} - -bool RWFunction::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - return GetValueHelper(this, name, valueType, pValue).Assignable() - CRYPTOPP_GET_FUNCTION_ENTRY(Modulus) - ; -} - -void RWFunction::AssignFrom(const NameValuePairs &source) -{ - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(Modulus) - ; -} - -// ***************************************************************************** -// private key operations: - -// generate a random private key -void InvertibleRWFunction::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg) -{ - int modulusSize = 2048; - alg.GetIntValue("ModulusSize", modulusSize) || alg.GetIntValue("KeySize", modulusSize); - - if (modulusSize < 16) - throw InvalidArgument("InvertibleRWFunction: specified modulus length is too small"); - - AlgorithmParameters primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize); - m_p.GenerateRandom(rng, CombinedNameValuePairs(primeParam, MakeParameters("EquivalentTo", 3)("Mod", 8))); - m_q.GenerateRandom(rng, CombinedNameValuePairs(primeParam, MakeParameters("EquivalentTo", 7)("Mod", 8))); - - m_n = m_p * m_q; - m_u = m_q.InverseMod(m_p); -} - -void InvertibleRWFunction::BERDecode(BufferedTransformation &bt) -{ - BERSequenceDecoder seq(bt); - m_n.BERDecode(seq); - m_p.BERDecode(seq); - m_q.BERDecode(seq); - m_u.BERDecode(seq); - seq.MessageEnd(); -} - -void InvertibleRWFunction::DEREncode(BufferedTransformation &bt) const -{ - DERSequenceEncoder seq(bt); - m_n.DEREncode(seq); - m_p.DEREncode(seq); - m_q.DEREncode(seq); - m_u.DEREncode(seq); - seq.MessageEnd(); -} - -Integer InvertibleRWFunction::CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const -{ - DoQuickSanityCheck(); - ModularArithmetic modn(m_n); - Integer r, rInv; - do { // do this in a loop for people using small numbers for testing - r.Randomize(rng, Integer::One(), m_n - Integer::One()); - rInv = modn.MultiplicativeInverse(r); - } while (rInv.IsZero()); - Integer re = modn.Square(r); - re = modn.Multiply(re, x); // blind - - Integer cp=re%m_p, cq=re%m_q; - if (Jacobi(cp, m_p) * Jacobi(cq, m_q) != 1) - { - cp = cp.IsOdd() ? (cp+m_p) >> 1 : cp >> 1; - cq = cq.IsOdd() ? (cq+m_q) >> 1 : cq >> 1; - } - - #pragma omp parallel - #pragma omp sections - { - #pragma omp section - cp = ModularSquareRoot(cp, m_p); - #pragma omp section - cq = ModularSquareRoot(cq, m_q); - } - - Integer y = CRT(cq, m_q, cp, m_p, m_u); - y = modn.Multiply(y, rInv); // unblind - y = STDMIN(y, m_n-y); - if (ApplyFunction(y) != x) // check - throw Exception(Exception::OTHER_ERROR, "InvertibleRWFunction: computational error during private key operation"); - return y; -} - -bool InvertibleRWFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const -{ - bool pass = RWFunction::Validate(rng, level); - pass = pass && m_p > Integer::One() && m_p%8 == 3 && m_p < m_n; - pass = pass && m_q > Integer::One() && m_q%8 == 7 && m_q < m_n; - pass = pass && m_u.IsPositive() && m_u < m_p; - if (level >= 1) - { - pass = pass && m_p * m_q == m_n; - pass = pass && m_u * m_q % m_p == 1; - } - if (level >= 2) - pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2); - return pass; -} - -bool InvertibleRWFunction::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const -{ - return GetValueHelper(this, name, valueType, pValue).Assignable() - CRYPTOPP_GET_FUNCTION_ENTRY(Prime1) - CRYPTOPP_GET_FUNCTION_ENTRY(Prime2) - CRYPTOPP_GET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1) - ; -} - -void InvertibleRWFunction::AssignFrom(const NameValuePairs &source) -{ - AssignFromHelper(this, source) - CRYPTOPP_SET_FUNCTION_ENTRY(Prime1) - CRYPTOPP_SET_FUNCTION_ENTRY(Prime2) - CRYPTOPP_SET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1) - ; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/rw.h b/lib/cryptopp/rw.h deleted file mode 100644 index 6820251e8..000000000 --- a/lib/cryptopp/rw.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef CRYPTOPP_RW_H -#define CRYPTOPP_RW_H - -/** \file - This file contains classes that implement the - Rabin-Williams signature schemes as defined in IEEE P1363. -*/ - -#include "pubkey.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -class CRYPTOPP_DLL RWFunction : public TrapdoorFunction, public PublicKey -{ - typedef RWFunction ThisClass; - -public: - void Initialize(const Integer &n) - {m_n = n;} - - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - void Save(BufferedTransformation &bt) const - {DEREncode(bt);} - void Load(BufferedTransformation &bt) - {BERDecode(bt);} - - Integer ApplyFunction(const Integer &x) const; - Integer PreimageBound() const {return ++(m_n>>1);} - Integer ImageBound() const {return m_n;} - - bool Validate(RandomNumberGenerator &rng, unsigned int level) const; - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - - const Integer& GetModulus() const {return m_n;} - void SetModulus(const Integer &n) {m_n = n;} - -protected: - Integer m_n; -}; - -//! _ -class CRYPTOPP_DLL InvertibleRWFunction : public RWFunction, public TrapdoorFunctionInverse, public PrivateKey -{ - typedef InvertibleRWFunction ThisClass; - -public: - void Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u) - {m_n = n; m_p = p; m_q = q; m_u = u;} - // generate a random private key - void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits) - {GenerateRandomWithKeySize(rng, modulusBits);} - - void BERDecode(BufferedTransformation &bt); - void DEREncode(BufferedTransformation &bt) const; - - void Save(BufferedTransformation &bt) const - {DEREncode(bt);} - void Load(BufferedTransformation &bt) - {BERDecode(bt);} - - Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const; - - // GeneratibleCryptoMaterial - bool Validate(RandomNumberGenerator &rng, unsigned int level) const; - bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; - void AssignFrom(const NameValuePairs &source); - /*! parameters: (ModulusSize) */ - void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); - - const Integer& GetPrime1() const {return m_p;} - const Integer& GetPrime2() const {return m_q;} - const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;} - - void SetPrime1(const Integer &p) {m_p = p;} - void SetPrime2(const Integer &q) {m_q = q;} - void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;} - -protected: - Integer m_p, m_q, m_u; -}; - -//! RW -struct RW -{ - static std::string StaticAlgorithmName() {return "RW";} - typedef RWFunction PublicKey; - typedef InvertibleRWFunction PrivateKey; -}; - -//! RWSS -template -struct RWSS : public TF_SS -{ -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/safer.cpp b/lib/cryptopp/safer.cpp deleted file mode 100644 index d46ca6417..000000000 --- a/lib/cryptopp/safer.cpp +++ /dev/null @@ -1,153 +0,0 @@ -// safer.cpp - modified by by Wei Dai from Richard De Moliner's safer.c - -#include "pch.h" -#include "safer.h" -#include "misc.h" -#include "argnames.h" - -NAMESPACE_BEGIN(CryptoPP) - -const byte SAFER::Base::exp_tab[256] = - {1, 45, 226, 147, 190, 69, 21, 174, 120, 3, 135, 164, 184, 56, 207, 63, - 8, 103, 9, 148, 235, 38, 168, 107, 189, 24, 52, 27, 187, 191, 114, 247, - 64, 53, 72, 156, 81, 47, 59, 85, 227, 192, 159, 216, 211, 243, 141, 177, - 255, 167, 62, 220, 134, 119, 215, 166, 17, 251, 244, 186, 146, 145, 100, 131, - 241, 51, 239, 218, 44, 181, 178, 43, 136, 209, 153, 203, 140, 132, 29, 20, - 129, 151, 113, 202, 95, 163, 139, 87, 60, 130, 196, 82, 92, 28, 232, 160, - 4, 180, 133, 74, 246, 19, 84, 182, 223, 12, 26, 142, 222, 224, 57, 252, - 32, 155, 36, 78, 169, 152, 158, 171, 242, 96, 208, 108, 234, 250, 199, 217, - 0, 212, 31, 110, 67, 188, 236, 83, 137, 254, 122, 93, 73, 201, 50, 194, - 249, 154, 248, 109, 22, 219, 89, 150, 68, 233, 205, 230, 70, 66, 143, 10, - 193, 204, 185, 101, 176, 210, 198, 172, 30, 65, 98, 41, 46, 14, 116, 80, - 2, 90, 195, 37, 123, 138, 42, 91, 240, 6, 13, 71, 111, 112, 157, 126, - 16, 206, 18, 39, 213, 76, 79, 214, 121, 48, 104, 54, 117, 125, 228, 237, - 128, 106, 144, 55, 162, 94, 118, 170, 197, 127, 61, 175, 165, 229, 25, 97, - 253, 77, 124, 183, 11, 238, 173, 75, 34, 245, 231, 115, 35, 33, 200, 5, - 225, 102, 221, 179, 88, 105, 99, 86, 15, 161, 49, 149, 23, 7, 58, 40}; - -const byte SAFER::Base::log_tab[256] = - {128, 0, 176, 9, 96, 239, 185, 253, 16, 18, 159, 228, 105, 186, 173, 248, - 192, 56, 194, 101, 79, 6, 148, 252, 25, 222, 106, 27, 93, 78, 168, 130, - 112, 237, 232, 236, 114, 179, 21, 195, 255, 171, 182, 71, 68, 1, 172, 37, - 201, 250, 142, 65, 26, 33, 203, 211, 13, 110, 254, 38, 88, 218, 50, 15, - 32, 169, 157, 132, 152, 5, 156, 187, 34, 140, 99, 231, 197, 225, 115, 198, - 175, 36, 91, 135, 102, 39, 247, 87, 244, 150, 177, 183, 92, 139, 213, 84, - 121, 223, 170, 246, 62, 163, 241, 17, 202, 245, 209, 23, 123, 147, 131, 188, - 189, 82, 30, 235, 174, 204, 214, 53, 8, 200, 138, 180, 226, 205, 191, 217, - 208, 80, 89, 63, 77, 98, 52, 10, 72, 136, 181, 86, 76, 46, 107, 158, - 210, 61, 60, 3, 19, 251, 151, 81, 117, 74, 145, 113, 35, 190, 118, 42, - 95, 249, 212, 85, 11, 220, 55, 49, 22, 116, 215, 119, 167, 230, 7, 219, - 164, 47, 70, 243, 97, 69, 103, 227, 12, 162, 59, 28, 133, 24, 4, 29, - 41, 160, 143, 178, 90, 216, 166, 126, 238, 141, 83, 75, 161, 154, 193, 14, - 122, 73, 165, 44, 129, 196, 199, 54, 43, 127, 67, 149, 51, 242, 108, 104, - 109, 240, 2, 40, 206, 221, 155, 234, 94, 153, 124, 20, 134, 207, 229, 66, - 184, 64, 120, 45, 58, 233, 100, 31, 146, 144, 125, 57, 111, 224, 137, 48}; - -#define EXP(x) exp_tab[(x)] -#define LOG(x) log_tab[(x)] -#define PHT(x, y) { y += x; x += y; } -#define IPHT(x, y) { x -= y; y -= x; } - -static const unsigned int BLOCKSIZE = 8; -static const unsigned int MAX_ROUNDS = 13; - -void SAFER::Base::UncheckedSetKey(const byte *userkey_1, unsigned int length, const NameValuePairs ¶ms) -{ - bool strengthened = Strengthened(); - unsigned int nof_rounds = params.GetIntValueWithDefault(Name::Rounds(), length == 8 ? (strengthened ? 8 : 6) : 10); - - const byte *userkey_2 = length == 8 ? userkey_1 : userkey_1 + 8; - keySchedule.New(1 + BLOCKSIZE * (1 + 2 * nof_rounds)); - - unsigned int i, j; - byte *key = keySchedule; - SecByteBlock ka(BLOCKSIZE + 1), kb(BLOCKSIZE + 1); - - if (MAX_ROUNDS < nof_rounds) - nof_rounds = MAX_ROUNDS; - *key++ = (unsigned char)nof_rounds; - ka[BLOCKSIZE] = 0; - kb[BLOCKSIZE] = 0; - for (j = 0; j < BLOCKSIZE; j++) - { - ka[BLOCKSIZE] ^= ka[j] = rotlFixed(userkey_1[j], 5U); - kb[BLOCKSIZE] ^= kb[j] = *key++ = userkey_2[j]; - } - - for (i = 1; i <= nof_rounds; i++) - { - for (j = 0; j < BLOCKSIZE + 1; j++) - { - ka[j] = rotlFixed(ka[j], 6U); - kb[j] = rotlFixed(kb[j], 6U); - } - for (j = 0; j < BLOCKSIZE; j++) - if (strengthened) - *key++ = (ka[(j + 2 * i - 1) % (BLOCKSIZE + 1)] - + exp_tab[exp_tab[18 * i + j + 1]]) & 0xFF; - else - *key++ = (ka[j] + exp_tab[exp_tab[18 * i + j + 1]]) & 0xFF; - for (j = 0; j < BLOCKSIZE; j++) - if (strengthened) - *key++ = (kb[(j + 2 * i) % (BLOCKSIZE + 1)] - + exp_tab[exp_tab[18 * i + j + 10]]) & 0xFF; - else - *key++ = (kb[j] + exp_tab[exp_tab[18 * i + j + 10]]) & 0xFF; - } -} - -typedef BlockGetAndPut Block; - -void SAFER::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - byte a, b, c, d, e, f, g, h, t; - const byte *key = keySchedule+1; - unsigned int round = keySchedule[0]; - - Block::Get(inBlock)(a)(b)(c)(d)(e)(f)(g)(h); - while(round--) - { - a ^= key[0]; b += key[1]; c += key[2]; d ^= key[3]; - e ^= key[4]; f += key[5]; g += key[6]; h ^= key[7]; - a = EXP(a) + key[ 8]; b = LOG(b) ^ key[ 9]; - c = LOG(c) ^ key[10]; d = EXP(d) + key[11]; - e = EXP(e) + key[12]; f = LOG(f) ^ key[13]; - g = LOG(g) ^ key[14]; h = EXP(h) + key[15]; - key += 16; - PHT(a, b); PHT(c, d); PHT(e, f); PHT(g, h); - PHT(a, c); PHT(e, g); PHT(b, d); PHT(f, h); - PHT(a, e); PHT(b, f); PHT(c, g); PHT(d, h); - t = b; b = e; e = c; c = t; t = d; d = f; f = g; g = t; - } - a ^= key[0]; b += key[1]; c += key[2]; d ^= key[3]; - e ^= key[4]; f += key[5]; g += key[6]; h ^= key[7]; - Block::Put(xorBlock, outBlock)(a)(b)(c)(d)(e)(f)(g)(h); -} - -void SAFER::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - byte a, b, c, d, e, f, g, h, t; - unsigned int round = keySchedule[0]; - const byte *key = keySchedule + BLOCKSIZE * (1 + 2 * round) - 7; - - Block::Get(inBlock)(a)(b)(c)(d)(e)(f)(g)(h); - h ^= key[7]; g -= key[6]; f -= key[5]; e ^= key[4]; - d ^= key[3]; c -= key[2]; b -= key[1]; a ^= key[0]; - while (round--) - { - key -= 16; - t = e; e = b; b = c; c = t; t = f; f = d; d = g; g = t; - IPHT(a, e); IPHT(b, f); IPHT(c, g); IPHT(d, h); - IPHT(a, c); IPHT(e, g); IPHT(b, d); IPHT(f, h); - IPHT(a, b); IPHT(c, d); IPHT(e, f); IPHT(g, h); - h -= key[15]; g ^= key[14]; f ^= key[13]; e -= key[12]; - d -= key[11]; c ^= key[10]; b ^= key[9]; a -= key[8]; - h = LOG(h) ^ key[7]; g = EXP(g) - key[6]; - f = EXP(f) - key[5]; e = LOG(e) ^ key[4]; - d = LOG(d) ^ key[3]; c = EXP(c) - key[2]; - b = EXP(b) - key[1]; a = LOG(a) ^ key[0]; - } - Block::Put(xorBlock, outBlock)(a)(b)(c)(d)(e)(f)(g)(h); -} - -NAMESPACE_END diff --git a/lib/cryptopp/safer.h b/lib/cryptopp/safer.h deleted file mode 100644 index f9a3c9e1f..000000000 --- a/lib/cryptopp/safer.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef CRYPTOPP_SAFER_H -#define CRYPTOPP_SAFER_H - -/** \file -*/ - -#include "seckey.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -/// base class, do not use directly -class SAFER -{ -public: - class CRYPTOPP_NO_VTABLE Base : public BlockCipher - { - public: - unsigned int OptimalDataAlignment() const {return 1;} - void UncheckedSetKey(const byte *userkey, unsigned int length, const NameValuePairs ¶ms); - - protected: - virtual bool Strengthened() const =0; - - SecByteBlock keySchedule; - static const byte exp_tab[256]; - static const byte log_tab[256]; - }; - - class CRYPTOPP_NO_VTABLE Enc : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - }; - - class CRYPTOPP_NO_VTABLE Dec : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - }; -}; - -template -class CRYPTOPP_NO_VTABLE SAFER_Impl : public BlockCipherImpl -{ -protected: - bool Strengthened() const {return STR;} -}; - -//! _ -struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13> -{ - static const char *StaticAlgorithmName() {return "SAFER-K";} -}; - -/// SAFER-K -class SAFER_K : public SAFER_K_Info, public SAFER, public BlockCipherDocumentation -{ -public: - typedef BlockCipherFinal > Encryption; - typedef BlockCipherFinal > Decryption; -}; - -//! _ -struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13> -{ - static const char *StaticAlgorithmName() {return "SAFER-SK";} -}; - -/// SAFER-SK -class SAFER_SK : public SAFER_SK_Info, public SAFER, public BlockCipherDocumentation -{ -public: - typedef BlockCipherFinal > Encryption; - typedef BlockCipherFinal > Decryption; -}; - -typedef SAFER_K::Encryption SAFER_K_Encryption; -typedef SAFER_K::Decryption SAFER_K_Decryption; - -typedef SAFER_SK::Encryption SAFER_SK_Encryption; -typedef SAFER_SK::Decryption SAFER_SK_Decryption; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/seal.cpp b/lib/cryptopp/seal.cpp deleted file mode 100644 index f49b52203..000000000 --- a/lib/cryptopp/seal.cpp +++ /dev/null @@ -1,213 +0,0 @@ -// seal.cpp - written and placed in the public domain by Wei Dai -// updated to SEAL 3.0 by Leonard Janke - -#include "pch.h" - -#include "seal.h" -#include "sha.h" -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) - -void SEAL_TestInstantiations() -{ - SEAL<>::Encryption x; -} - -struct SEAL_Gamma -{ - SEAL_Gamma(const byte *key) - : H(5), Z(5), D(16), lastIndex(0xffffffff) - { - GetUserKey(BIG_ENDIAN_ORDER, H.begin(), 5, key, 20); - memset(D, 0, 64); - } - - word32 Apply(word32 i); - - SecBlock H, Z, D; - word32 lastIndex; -}; - -word32 SEAL_Gamma::Apply(word32 i) -{ - word32 shaIndex = i/5; - if (shaIndex != lastIndex) - { - memcpy(Z, H, 20); - D[0] = shaIndex; - SHA::Transform(Z, D); - lastIndex = shaIndex; - } - return Z[i%5]; -} - -template -void SEAL_Policy::CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length) -{ - m_insideCounter = m_outsideCounter = m_startCount = 0; - - unsigned int L = params.GetIntValueWithDefault("NumberOfOutputBitsPerPositionIndex", 32*1024); - m_iterationsPerCount = L / 8192; - - SEAL_Gamma gamma(key); - unsigned int i; - - for (i=0; i<512; i++) - m_T[i] = gamma.Apply(i); - - for (i=0; i<256; i++) - m_S[i] = gamma.Apply(0x1000+i); - - m_R.New(4*(L/8192)); - - for (i=0; i -void SEAL_Policy::CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length) -{ - assert(length==4); - m_outsideCounter = IV ? GetWord(false, BIG_ENDIAN_ORDER, IV) : 0; - m_startCount = m_outsideCounter; - m_insideCounter = 0; -} - -template -void SEAL_Policy::SeekToIteration(lword iterationCount) -{ - m_outsideCounter = m_startCount + (unsigned int)(iterationCount / m_iterationsPerCount); - m_insideCounter = (unsigned int)(iterationCount % m_iterationsPerCount); -} - -template -void SEAL_Policy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount) -{ - word32 a, b, c, d, n1, n2, n3, n4; - unsigned int p, q; - - for (size_t iteration = 0; iteration < iterationCount; ++iteration) - { -#define Ttab(x) *(word32 *)((byte *)m_T.begin()+x) - - a = m_outsideCounter ^ m_R[4*m_insideCounter]; - b = rotrFixed(m_outsideCounter, 8U) ^ m_R[4*m_insideCounter+1]; - c = rotrFixed(m_outsideCounter, 16U) ^ m_R[4*m_insideCounter+2]; - d = rotrFixed(m_outsideCounter, 24U) ^ m_R[4*m_insideCounter+3]; - - for (unsigned int j=0; j<2; j++) - { - p = a & 0x7fc; - b += Ttab(p); - a = rotrFixed(a, 9U); - - p = b & 0x7fc; - c += Ttab(p); - b = rotrFixed(b, 9U); - - p = c & 0x7fc; - d += Ttab(p); - c = rotrFixed(c, 9U); - - p = d & 0x7fc; - a += Ttab(p); - d = rotrFixed(d, 9U); - } - - n1 = d, n2 = b, n3 = a, n4 = c; - - p = a & 0x7fc; - b += Ttab(p); - a = rotrFixed(a, 9U); - - p = b & 0x7fc; - c += Ttab(p); - b = rotrFixed(b, 9U); - - p = c & 0x7fc; - d += Ttab(p); - c = rotrFixed(c, 9U); - - p = d & 0x7fc; - a += Ttab(p); - d = rotrFixed(d, 9U); - - // generate 8192 bits - for (unsigned int i=0; i<64; i++) - { - p = a & 0x7fc; - a = rotrFixed(a, 9U); - b += Ttab(p); - b ^= a; - - q = b & 0x7fc; - b = rotrFixed(b, 9U); - c ^= Ttab(q); - c += b; - - p = (p+c) & 0x7fc; - c = rotrFixed(c, 9U); - d += Ttab(p); - d ^= c; - - q = (q+d) & 0x7fc; - d = rotrFixed(d, 9U); - a ^= Ttab(q); - a += d; - - p = (p+a) & 0x7fc; - b ^= Ttab(p); - a = rotrFixed(a, 9U); - - q = (q+b) & 0x7fc; - c += Ttab(q); - b = rotrFixed(b, 9U); - - p = (p+c) & 0x7fc; - d ^= Ttab(p); - c = rotrFixed(c, 9U); - - q = (q+d) & 0x7fc; - d = rotrFixed(d, 9U); - a += Ttab(q); - -#define SEAL_OUTPUT(x) \ - CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 0, b + m_S[4*i+0]);\ - CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 1, c ^ m_S[4*i+1]);\ - CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 2, d + m_S[4*i+2]);\ - CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 3, a ^ m_S[4*i+3]); - - CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(SEAL_OUTPUT, 4*4); - - if (i & 1) - { - a += n3; - b += n4; - c ^= n3; - d ^= n4; - } - else - { - a += n1; - b += n2; - c ^= n1; - d ^= n2; - } - } - - if (++m_insideCounter == m_iterationsPerCount) - { - ++m_outsideCounter; - m_insideCounter = 0; - } - } - - a = b = c = d = n1 = n2 = n3 = n4 = 0; - p = q = 0; -} - -template class SEAL_Policy; -template class SEAL_Policy; - -NAMESPACE_END diff --git a/lib/cryptopp/seal.h b/lib/cryptopp/seal.h deleted file mode 100644 index e14ae1caf..000000000 --- a/lib/cryptopp/seal.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef CRYPTOPP_SEAL_H -#define CRYPTOPP_SEAL_H - -#include "strciphr.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -template -struct SEAL_Info : public FixedKeyLength<20, SimpleKeyingInterface::INTERNALLY_GENERATED_IV, 4> -{ - static const char *StaticAlgorithmName() {return B::ToEnum() == LITTLE_ENDIAN_ORDER ? "SEAL-3.0-LE" : "SEAL-3.0-BE";} -}; - -template -class CRYPTOPP_NO_VTABLE SEAL_Policy : public AdditiveCipherConcretePolicy, public SEAL_Info -{ -protected: - void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); - void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); - void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length); - bool CipherIsRandomAccess() const {return true;} - void SeekToIteration(lword iterationCount); - -private: - FixedSizeSecBlock m_T; - FixedSizeSecBlock m_S; - SecBlock m_R; - - word32 m_startCount, m_iterationsPerCount; - word32 m_outsideCounter, m_insideCounter; -}; - -//! SEAL -template -struct SEAL : public SEAL_Info, public SymmetricCipherDocumentation -{ - typedef SymmetricCipherFinal, AdditiveCipherTemplate<> >, SEAL_Info > Encryption; - typedef Encryption Decryption; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/secblock.h b/lib/cryptopp/secblock.h deleted file mode 100644 index 40cce3341..000000000 --- a/lib/cryptopp/secblock.h +++ /dev/null @@ -1,467 +0,0 @@ -// secblock.h - written and placed in the public domain by Wei Dai - -#ifndef CRYPTOPP_SECBLOCK_H -#define CRYPTOPP_SECBLOCK_H - -#include "config.h" -#include "misc.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -// ************** secure memory allocation *************** - -template -class AllocatorBase -{ -public: - typedef T value_type; - typedef size_t size_type; -#ifdef CRYPTOPP_MSVCRT6 - typedef ptrdiff_t difference_type; -#else - typedef std::ptrdiff_t difference_type; -#endif - typedef T * pointer; - typedef const T * const_pointer; - typedef T & reference; - typedef const T & const_reference; - - pointer address(reference r) const {return (&r);} - const_pointer address(const_reference r) const {return (&r); } - void construct(pointer p, const T& val) {new (p) T(val);} - void destroy(pointer p) {p->~T();} - size_type max_size() const {return ~size_type(0)/sizeof(T);} // switch to std::numeric_limits::max later - -protected: - static void CheckSize(size_t n) - { - if (n > ~size_t(0) / sizeof(T)) - throw InvalidArgument("AllocatorBase: requested size would cause integer overflow"); - } -}; - -#define CRYPTOPP_INHERIT_ALLOCATOR_TYPES \ -typedef typename AllocatorBase::value_type value_type;\ -typedef typename AllocatorBase::size_type size_type;\ -typedef typename AllocatorBase::difference_type difference_type;\ -typedef typename AllocatorBase::pointer pointer;\ -typedef typename AllocatorBase::const_pointer const_pointer;\ -typedef typename AllocatorBase::reference reference;\ -typedef typename AllocatorBase::const_reference const_reference; - -#if defined(_MSC_VER) && (_MSC_VER < 1300) -// this pragma causes an internal compiler error if placed immediately before std::swap(a, b) -#pragma warning(push) -#pragma warning(disable: 4700) // VC60 workaround: don't know how to get rid of this warning -#endif - -template -typename A::pointer StandardReallocate(A& a, T *p, typename A::size_type oldSize, typename A::size_type newSize, bool preserve) -{ - if (oldSize == newSize) - return p; - - if (preserve) - { - typename A::pointer newPointer = a.allocate(newSize, NULL); - memcpy_s(newPointer, sizeof(T)*newSize, p, sizeof(T)*STDMIN(oldSize, newSize)); - a.deallocate(p, oldSize); - return newPointer; - } - else - { - a.deallocate(p, oldSize); - return a.allocate(newSize, NULL); - } -} - -#if defined(_MSC_VER) && (_MSC_VER < 1300) -#pragma warning(pop) -#endif - -template -class AllocatorWithCleanup : public AllocatorBase -{ -public: - CRYPTOPP_INHERIT_ALLOCATOR_TYPES - - pointer allocate(size_type n, const void * = NULL) - { - this->CheckSize(n); - if (n == 0) - return NULL; - -#if CRYPTOPP_BOOL_ALIGN16_ENABLED - if (T_Align16 && n*sizeof(T) >= 16) - return (pointer)AlignedAllocate(n*sizeof(T)); -#endif - - return (pointer)UnalignedAllocate(n*sizeof(T)); - } - - void deallocate(void *p, size_type n) - { - SecureWipeArray((pointer)p, n); - -#if CRYPTOPP_BOOL_ALIGN16_ENABLED - if (T_Align16 && n*sizeof(T) >= 16) - return AlignedDeallocate(p); -#endif - - UnalignedDeallocate(p); - } - - pointer reallocate(T *p, size_type oldSize, size_type newSize, bool preserve) - { - return StandardReallocate(*this, p, oldSize, newSize, preserve); - } - - // VS.NET STL enforces the policy of "All STL-compliant allocators have to provide a - // template class member called rebind". - template struct rebind { typedef AllocatorWithCleanup other; }; -#if _MSC_VER >= 1500 - AllocatorWithCleanup() {} - template AllocatorWithCleanup(const AllocatorWithCleanup &) {} -#endif -}; - -CRYPTOPP_DLL_TEMPLATE_CLASS AllocatorWithCleanup; -CRYPTOPP_DLL_TEMPLATE_CLASS AllocatorWithCleanup; -CRYPTOPP_DLL_TEMPLATE_CLASS AllocatorWithCleanup; -CRYPTOPP_DLL_TEMPLATE_CLASS AllocatorWithCleanup; -#if CRYPTOPP_BOOL_X86 -CRYPTOPP_DLL_TEMPLATE_CLASS AllocatorWithCleanup; // for Integer -#endif - -template -class NullAllocator : public AllocatorBase -{ -public: - CRYPTOPP_INHERIT_ALLOCATOR_TYPES - - pointer allocate(size_type n, const void * = NULL) - { - assert(false); - return NULL; - } - - void deallocate(void *p, size_type n) - { - assert(false); - } - - size_type max_size() const {return 0;} -}; - -// This allocator can't be used with standard collections because -// they require that all objects of the same allocator type are equivalent. -// So this is for use with SecBlock only. -template , bool T_Align16 = false> -class FixedSizeAllocatorWithCleanup : public AllocatorBase -{ -public: - CRYPTOPP_INHERIT_ALLOCATOR_TYPES - - FixedSizeAllocatorWithCleanup() : m_allocated(false) {} - - pointer allocate(size_type n) - { - assert(IsAlignedOn(m_array, 8)); - - if (n <= S && !m_allocated) - { - m_allocated = true; - return GetAlignedArray(); - } - else - return m_fallbackAllocator.allocate(n); - } - - pointer allocate(size_type n, const void *hint) - { - if (n <= S && !m_allocated) - { - m_allocated = true; - return GetAlignedArray(); - } - else - return m_fallbackAllocator.allocate(n, hint); - } - - void deallocate(void *p, size_type n) - { - if (p == GetAlignedArray()) - { - assert(n <= S); - assert(m_allocated); - m_allocated = false; - SecureWipeArray((pointer)p, n); - } - else - m_fallbackAllocator.deallocate(p, n); - } - - pointer reallocate(pointer p, size_type oldSize, size_type newSize, bool preserve) - { - if (p == GetAlignedArray() && newSize <= S) - { - assert(oldSize <= S); - if (oldSize > newSize) - SecureWipeArray(p+newSize, oldSize-newSize); - return p; - } - - pointer newPointer = allocate(newSize, NULL); - if (preserve) - memcpy(newPointer, p, sizeof(T)*STDMIN(oldSize, newSize)); - deallocate(p, oldSize); - return newPointer; - } - - size_type max_size() const {return STDMAX(m_fallbackAllocator.max_size(), S);} - -private: -#ifdef __BORLANDC__ - T* GetAlignedArray() {return m_array;} - T m_array[S]; -#else - T* GetAlignedArray() {return (CRYPTOPP_BOOL_ALIGN16_ENABLED && T_Align16) ? (T*)(((byte *)m_array) + (0-(size_t)m_array)%16) : m_array;} - CRYPTOPP_ALIGN_DATA(8) T m_array[(CRYPTOPP_BOOL_ALIGN16_ENABLED && T_Align16) ? S+8/sizeof(T) : S]; -#endif - A m_fallbackAllocator; - bool m_allocated; -}; - -//! a block of memory allocated using A -template > -class SecBlock -{ -public: - typedef typename A::value_type value_type; - typedef typename A::pointer iterator; - typedef typename A::const_pointer const_iterator; - typedef typename A::size_type size_type; - - explicit SecBlock(size_type size=0) - : m_size(size) {m_ptr = m_alloc.allocate(size, NULL);} - SecBlock(const SecBlock &t) - : m_size(t.m_size) {m_ptr = m_alloc.allocate(m_size, NULL); memcpy_s(m_ptr, m_size*sizeof(T), t.m_ptr, m_size*sizeof(T));} - SecBlock(const T *t, size_type len) - : m_size(len) - { - m_ptr = m_alloc.allocate(len, NULL); - if (t == NULL) - memset_z(m_ptr, 0, len*sizeof(T)); - else - memcpy(m_ptr, t, len*sizeof(T)); - } - - ~SecBlock() - {m_alloc.deallocate(m_ptr, m_size);} - -#ifdef __BORLANDC__ - operator T *() const - {return (T*)m_ptr;} -#else - operator const void *() const - {return m_ptr;} - operator void *() - {return m_ptr;} - - operator const T *() const - {return m_ptr;} - operator T *() - {return m_ptr;} -#endif - -// T *operator +(size_type offset) -// {return m_ptr+offset;} - -// const T *operator +(size_type offset) const -// {return m_ptr+offset;} - -// T& operator[](size_type index) -// {assert(index >= 0 && index < m_size); return m_ptr[index];} - -// const T& operator[](size_type index) const -// {assert(index >= 0 && index < m_size); return m_ptr[index];} - - iterator begin() - {return m_ptr;} - const_iterator begin() const - {return m_ptr;} - iterator end() - {return m_ptr+m_size;} - const_iterator end() const - {return m_ptr+m_size;} - - typename A::pointer data() {return m_ptr;} - typename A::const_pointer data() const {return m_ptr;} - - size_type size() const {return m_size;} - bool empty() const {return m_size == 0;} - - byte * BytePtr() {return (byte *)m_ptr;} - const byte * BytePtr() const {return (const byte *)m_ptr;} - size_type SizeInBytes() const {return m_size*sizeof(T);} - - //! set contents and size - void Assign(const T *t, size_type len) - { - New(len); - memcpy_s(m_ptr, m_size*sizeof(T), t, len*sizeof(T)); - } - - //! copy contents and size from another SecBlock - void Assign(const SecBlock &t) - { - if (this != &t) - { - New(t.m_size); - memcpy_s(m_ptr, m_size*sizeof(T), t.m_ptr, m_size*sizeof(T)); - } - } - - SecBlock& operator=(const SecBlock &t) - { - Assign(t); - return *this; - } - - // append to this object - SecBlock& operator+=(const SecBlock &t) - { - size_type oldSize = m_size; - Grow(m_size+t.m_size); - memcpy_s(m_ptr+oldSize, m_size*sizeof(T), t.m_ptr, t.m_size*sizeof(T)); - return *this; - } - - // append operator - SecBlock operator+(const SecBlock &t) - { - SecBlock result(m_size+t.m_size); - memcpy_s(result.m_ptr, result.m_size*sizeof(T), m_ptr, m_size*sizeof(T)); - memcpy_s(result.m_ptr+m_size, t.m_size*sizeof(T), t.m_ptr, t.m_size*sizeof(T)); - return result; - } - - bool operator==(const SecBlock &t) const - { - return m_size == t.m_size && VerifyBufsEqual(m_ptr, t.m_ptr, m_size*sizeof(T)); - } - - bool operator!=(const SecBlock &t) const - { - return !operator==(t); - } - - //! change size, without preserving contents - void New(size_type newSize) - { - m_ptr = m_alloc.reallocate(m_ptr, m_size, newSize, false); - m_size = newSize; - } - - //! change size and set contents to 0 - void CleanNew(size_type newSize) - { - New(newSize); - memset_z(m_ptr, 0, m_size*sizeof(T)); - } - - //! change size only if newSize > current size. contents are preserved - void Grow(size_type newSize) - { - if (newSize > m_size) - { - m_ptr = m_alloc.reallocate(m_ptr, m_size, newSize, true); - m_size = newSize; - } - } - - //! change size only if newSize > current size. contents are preserved and additional area is set to 0 - void CleanGrow(size_type newSize) - { - if (newSize > m_size) - { - m_ptr = m_alloc.reallocate(m_ptr, m_size, newSize, true); - memset(m_ptr+m_size, 0, (newSize-m_size)*sizeof(T)); - m_size = newSize; - } - } - - //! change size and preserve contents - void resize(size_type newSize) - { - m_ptr = m_alloc.reallocate(m_ptr, m_size, newSize, true); - m_size = newSize; - } - - //! swap contents and size with another SecBlock - void swap(SecBlock &b) - { - std::swap(m_alloc, b.m_alloc); - std::swap(m_size, b.m_size); - std::swap(m_ptr, b.m_ptr); - } - -//private: - A m_alloc; - size_type m_size; - T *m_ptr; -}; - -typedef SecBlock SecByteBlock; -typedef SecBlock > AlignedSecByteBlock; -typedef SecBlock SecWordBlock; - -//! a SecBlock with fixed size, allocated statically -template > -class FixedSizeSecBlock : public SecBlock -{ -public: - explicit FixedSizeSecBlock() : SecBlock(S) {} -}; - -template -class FixedSizeAlignedSecBlock : public FixedSizeSecBlock, T_Align16> > -{ -}; - -//! a SecBlock that preallocates size S statically, and uses the heap when this size is exceeded -template > > -class SecBlockWithHint : public SecBlock -{ -public: - explicit SecBlockWithHint(size_t size) : SecBlock(size) {} -}; - -template -inline bool operator==(const CryptoPP::AllocatorWithCleanup&, const CryptoPP::AllocatorWithCleanup&) {return (true);} -template -inline bool operator!=(const CryptoPP::AllocatorWithCleanup&, const CryptoPP::AllocatorWithCleanup&) {return (false);} - -NAMESPACE_END - -NAMESPACE_BEGIN(std) -template -inline void swap(CryptoPP::SecBlock &a, CryptoPP::SecBlock &b) -{ - a.swap(b); -} - -#if defined(_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE) || (defined(_STLPORT_VERSION) && !defined(_STLP_MEMBER_TEMPLATE_CLASSES)) -// working for STLport 5.1.3 and MSVC 6 SP5 -template -inline CryptoPP::AllocatorWithCleanup<_Tp2>& -__stl_alloc_rebind(CryptoPP::AllocatorWithCleanup<_Tp1>& __a, const _Tp2*) -{ - return (CryptoPP::AllocatorWithCleanup<_Tp2>&)(__a); -} -#endif - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/seckey.h b/lib/cryptopp/seckey.h deleted file mode 100644 index 35046a61b..000000000 --- a/lib/cryptopp/seckey.h +++ /dev/null @@ -1,221 +0,0 @@ -// seckey.h - written and placed in the public domain by Wei Dai - -// This file contains helper classes/functions for implementing secret key algorithms. - -#ifndef CRYPTOPP_SECKEY_H -#define CRYPTOPP_SECKEY_H - -#include "cryptlib.h" -#include "misc.h" -#include "simple.h" - -NAMESPACE_BEGIN(CryptoPP) - -inline CipherDir ReverseCipherDir(CipherDir dir) -{ - return (dir == ENCRYPTION) ? DECRYPTION : ENCRYPTION; -} - -//! to be inherited by block ciphers with fixed block size -template -class FixedBlockSize -{ -public: - CRYPTOPP_CONSTANT(BLOCKSIZE = N) -}; - -// ************** rounds *************** - -//! to be inherited by ciphers with fixed number of rounds -template -class FixedRounds -{ -public: - CRYPTOPP_CONSTANT(ROUNDS = R) -}; - -//! to be inherited by ciphers with variable number of rounds -template // use INT_MAX here because enums are treated as signed ints -class VariableRounds -{ -public: - CRYPTOPP_CONSTANT(DEFAULT_ROUNDS = D) - CRYPTOPP_CONSTANT(MIN_ROUNDS = N) - CRYPTOPP_CONSTANT(MAX_ROUNDS = M) - static unsigned int StaticGetDefaultRounds(size_t keylength) {return DEFAULT_ROUNDS;} - -protected: - inline void ThrowIfInvalidRounds(int rounds, const Algorithm *alg) - { - if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS) - throw InvalidRounds(alg->AlgorithmName(), rounds); - } - - inline unsigned int GetRoundsAndThrowIfInvalid(const NameValuePairs ¶m, const Algorithm *alg) - { - int rounds = param.GetIntValueWithDefault("Rounds", DEFAULT_ROUNDS); - ThrowIfInvalidRounds(rounds, alg); - return (unsigned int)rounds; - } -}; - -// ************** key length *************** - -//! to be inherited by keyed algorithms with fixed key length -template -class FixedKeyLength -{ -public: - CRYPTOPP_CONSTANT(KEYLENGTH=N) - CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N) - CRYPTOPP_CONSTANT(MAX_KEYLENGTH=N) - CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=N) - CRYPTOPP_CONSTANT(IV_REQUIREMENT = IV_REQ) - CRYPTOPP_CONSTANT(IV_LENGTH = IV_L) - static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t) {return KEYLENGTH;} -}; - -/// support query of variable key length, template parameters are default, min, max, multiple (default multiple 1) -template -class VariableKeyLength -{ - // make these private to avoid Doxygen documenting them in all derived classes - CRYPTOPP_COMPILE_ASSERT(Q > 0); - CRYPTOPP_COMPILE_ASSERT(N % Q == 0); - CRYPTOPP_COMPILE_ASSERT(M % Q == 0); - CRYPTOPP_COMPILE_ASSERT(N < M); - CRYPTOPP_COMPILE_ASSERT(D >= N); - CRYPTOPP_COMPILE_ASSERT(M >= D); - -public: - CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N) - CRYPTOPP_CONSTANT(MAX_KEYLENGTH=M) - CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=D) - CRYPTOPP_CONSTANT(KEYLENGTH_MULTIPLE=Q) - CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ) - CRYPTOPP_CONSTANT(IV_LENGTH=IV_L) - - static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t n) - { - if (n < (size_t)MIN_KEYLENGTH) - return MIN_KEYLENGTH; - else if (n > (size_t)MAX_KEYLENGTH) - return (size_t)MAX_KEYLENGTH; - else - { - n += KEYLENGTH_MULTIPLE-1; - return n - n%KEYLENGTH_MULTIPLE; - } - } -}; - -/// support query of key length that's the same as another class -template -class SameKeyLengthAs -{ -public: - CRYPTOPP_CONSTANT(MIN_KEYLENGTH=T::MIN_KEYLENGTH) - CRYPTOPP_CONSTANT(MAX_KEYLENGTH=T::MAX_KEYLENGTH) - CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=T::DEFAULT_KEYLENGTH) - CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ) - CRYPTOPP_CONSTANT(IV_LENGTH=IV_L) - - static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength) - {return T::StaticGetValidKeyLength(keylength);} -}; - -// ************** implementation helper for SimpleKeyed *************** - -//! _ -template -class CRYPTOPP_NO_VTABLE SimpleKeyingInterfaceImpl : public BASE -{ -public: - size_t MinKeyLength() const {return INFO::MIN_KEYLENGTH;} - size_t MaxKeyLength() const {return (size_t)INFO::MAX_KEYLENGTH;} - size_t DefaultKeyLength() const {return INFO::DEFAULT_KEYLENGTH;} - size_t GetValidKeyLength(size_t n) const {return INFO::StaticGetValidKeyLength(n);} - SimpleKeyingInterface::IV_Requirement IVRequirement() const {return (SimpleKeyingInterface::IV_Requirement)INFO::IV_REQUIREMENT;} - unsigned int IVSize() const {return INFO::IV_LENGTH;} -}; - -template -class CRYPTOPP_NO_VTABLE BlockCipherImpl : public AlgorithmImpl > > -{ -public: - unsigned int BlockSize() const {return this->BLOCKSIZE;} -}; - -//! _ -template -class BlockCipherFinal : public ClonableImpl, BASE> -{ -public: - BlockCipherFinal() {} - BlockCipherFinal(const byte *key) - {this->SetKey(key, this->DEFAULT_KEYLENGTH);} - BlockCipherFinal(const byte *key, size_t length) - {this->SetKey(key, length);} - BlockCipherFinal(const byte *key, size_t length, unsigned int rounds) - {this->SetKeyWithRounds(key, length, rounds);} - - bool IsForwardTransformation() const {return DIR == ENCRYPTION;} -}; - -//! _ -template -class MessageAuthenticationCodeImpl : public AlgorithmImpl, INFO> -{ -}; - -//! _ -template -class MessageAuthenticationCodeFinal : public ClonableImpl, MessageAuthenticationCodeImpl > -{ -public: - MessageAuthenticationCodeFinal() {} - MessageAuthenticationCodeFinal(const byte *key) - {this->SetKey(key, this->DEFAULT_KEYLENGTH);} - MessageAuthenticationCodeFinal(const byte *key, size_t length) - {this->SetKey(key, length);} -}; - -// ************** documentation *************** - -//! These objects usually should not be used directly. See CipherModeDocumentation instead. -/*! Each class derived from this one defines two types, Encryption and Decryption, - both of which implement the BlockCipher interface. */ -struct BlockCipherDocumentation -{ - //! implements the BlockCipher interface - typedef BlockCipher Encryption; - //! implements the BlockCipher interface - typedef BlockCipher Decryption; -}; - -/*! \brief Each class derived from this one defines two types, Encryption and Decryption, - both of which implement the SymmetricCipher interface. Two types of classes derive - from this class: stream ciphers and block cipher modes. Stream ciphers can be used - alone, cipher mode classes need to be used with a block cipher. See CipherModeDocumentation - for more for information about using cipher modes and block ciphers. */ -struct SymmetricCipherDocumentation -{ - //! implements the SymmetricCipher interface - typedef SymmetricCipher Encryption; - //! implements the SymmetricCipher interface - typedef SymmetricCipher Decryption; -}; - -/*! \brief Each class derived from this one defines two types, Encryption and Decryption, - both of which implement the AuthenticatedSymmetricCipher interface. */ -struct AuthenticatedSymmetricCipherDocumentation -{ - //! implements the AuthenticatedSymmetricCipher interface - typedef AuthenticatedSymmetricCipher Encryption; - //! implements the AuthenticatedSymmetricCipher interface - typedef AuthenticatedSymmetricCipher Decryption; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/seed.cpp b/lib/cryptopp/seed.cpp deleted file mode 100644 index 101902dce..000000000 --- a/lib/cryptopp/seed.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// seed.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "seed.h" -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) - -static const word32 s_kc[16] = { - 0x9e3779b9, 0x3c6ef373, 0x78dde6e6, 0xf1bbcdcc, 0xe3779b99, 0xc6ef3733, 0x8dde6e67, 0x1bbcdccf, - 0x3779b99e, 0x6ef3733c, 0xdde6e678, 0xbbcdccf1, 0x779b99e3, 0xef3733c6, 0xde6e678d, 0xbcdccf1b}; - -static const byte s_s0[256] = { - 0xA9, 0x85, 0xD6, 0xD3, 0x54, 0x1D, 0xAC, 0x25, 0x5D, 0x43, 0x18, 0x1E, 0x51, 0xFC, 0xCA, 0x63, 0x28, - 0x44, 0x20, 0x9D, 0xE0, 0xE2, 0xC8, 0x17, 0xA5, 0x8F, 0x03, 0x7B, 0xBB, 0x13, 0xD2, 0xEE, 0x70, 0x8C, - 0x3F, 0xA8, 0x32, 0xDD, 0xF6, 0x74, 0xEC, 0x95, 0x0B, 0x57, 0x5C, 0x5B, 0xBD, 0x01, 0x24, 0x1C, 0x73, - 0x98, 0x10, 0xCC, 0xF2, 0xD9, 0x2C, 0xE7, 0x72, 0x83, 0x9B, 0xD1, 0x86, 0xC9, 0x60, 0x50, 0xA3, 0xEB, - 0x0D, 0xB6, 0x9E, 0x4F, 0xB7, 0x5A, 0xC6, 0x78, 0xA6, 0x12, 0xAF, 0xD5, 0x61, 0xC3, 0xB4, 0x41, 0x52, - 0x7D, 0x8D, 0x08, 0x1F, 0x99, 0x00, 0x19, 0x04, 0x53, 0xF7, 0xE1, 0xFD, 0x76, 0x2F, 0x27, 0xB0, 0x8B, - 0x0E, 0xAB, 0xA2, 0x6E, 0x93, 0x4D, 0x69, 0x7C, 0x09, 0x0A, 0xBF, 0xEF, 0xF3, 0xC5, 0x87, 0x14, 0xFE, - 0x64, 0xDE, 0x2E, 0x4B, 0x1A, 0x06, 0x21, 0x6B, 0x66, 0x02, 0xF5, 0x92, 0x8A, 0x0C, 0xB3, 0x7E, 0xD0, - 0x7A, 0x47, 0x96, 0xE5, 0x26, 0x80, 0xAD, 0xDF, 0xA1, 0x30, 0x37, 0xAE, 0x36, 0x15, 0x22, 0x38, 0xF4, - 0xA7, 0x45, 0x4C, 0x81, 0xE9, 0x84, 0x97, 0x35, 0xCB, 0xCE, 0x3C, 0x71, 0x11, 0xC7, 0x89, 0x75, 0xFB, - 0xDA, 0xF8, 0x94, 0x59, 0x82, 0xC4, 0xFF, 0x49, 0x39, 0x67, 0xC0, 0xCF, 0xD7, 0xB8, 0x0F, 0x8E, 0x42, - 0x23, 0x91, 0x6C, 0xDB, 0xA4, 0x34, 0xF1, 0x48, 0xC2, 0x6F, 0x3D, 0x2D, 0x40, 0xBE, 0x3E, 0xBC, 0xC1, - 0xAA, 0xBA, 0x4E, 0x55, 0x3B, 0xDC, 0x68, 0x7F, 0x9C, 0xD8, 0x4A, 0x56, 0x77, 0xA0, 0xED, 0x46, 0xB5, - 0x2B, 0x65, 0xFA, 0xE3, 0xB9, 0xB1, 0x9F, 0x5E, 0xF9, 0xE6, 0xB2, 0x31, 0xEA, 0x6D, 0x5F, 0xE4, 0xF0, - 0xCD, 0x88, 0x16, 0x3A, 0x58, 0xD4, 0x62, 0x29, 0x07, 0x33, 0xE8, 0x1B, 0x05, 0x79, 0x90, 0x6A, 0x2A, - 0x9A}; - -static const byte s_s1[256] = { - 0x38, 0xE8, 0x2D, 0xA6, 0xCF, 0xDE, 0xB3, 0xB8, 0xAF, 0x60, 0x55, 0xC7, 0x44, 0x6F, 0x6B, 0x5B, 0xC3, - 0x62, 0x33, 0xB5, 0x29, 0xA0, 0xE2, 0xA7, 0xD3, 0x91, 0x11, 0x06, 0x1C, 0xBC, 0x36, 0x4B, 0xEF, 0x88, - 0x6C, 0xA8, 0x17, 0xC4, 0x16, 0xF4, 0xC2, 0x45, 0xE1, 0xD6, 0x3F, 0x3D, 0x8E, 0x98, 0x28, 0x4E, 0xF6, - 0x3E, 0xA5, 0xF9, 0x0D, 0xDF, 0xD8, 0x2B, 0x66, 0x7A, 0x27, 0x2F, 0xF1, 0x72, 0x42, 0xD4, 0x41, 0xC0, - 0x73, 0x67, 0xAC, 0x8B, 0xF7, 0xAD, 0x80, 0x1F, 0xCA, 0x2C, 0xAA, 0x34, 0xD2, 0x0B, 0xEE, 0xE9, 0x5D, - 0x94, 0x18, 0xF8, 0x57, 0xAE, 0x08, 0xC5, 0x13, 0xCD, 0x86, 0xB9, 0xFF, 0x7D, 0xC1, 0x31, 0xF5, 0x8A, - 0x6A, 0xB1, 0xD1, 0x20, 0xD7, 0x02, 0x22, 0x04, 0x68, 0x71, 0x07, 0xDB, 0x9D, 0x99, 0x61, 0xBE, 0xE6, - 0x59, 0xDD, 0x51, 0x90, 0xDC, 0x9A, 0xA3, 0xAB, 0xD0, 0x81, 0x0F, 0x47, 0x1A, 0xE3, 0xEC, 0x8D, 0xBF, - 0x96, 0x7B, 0x5C, 0xA2, 0xA1, 0x63, 0x23, 0x4D, 0xC8, 0x9E, 0x9C, 0x3A, 0x0C, 0x2E, 0xBA, 0x6E, 0x9F, - 0x5A, 0xF2, 0x92, 0xF3, 0x49, 0x78, 0xCC, 0x15, 0xFB, 0x70, 0x75, 0x7F, 0x35, 0x10, 0x03, 0x64, 0x6D, - 0xC6, 0x74, 0xD5, 0xB4, 0xEA, 0x09, 0x76, 0x19, 0xFE, 0x40, 0x12, 0xE0, 0xBD, 0x05, 0xFA, 0x01, 0xF0, - 0x2A, 0x5E, 0xA9, 0x56, 0x43, 0x85, 0x14, 0x89, 0x9B, 0xB0, 0xE5, 0x48, 0x79, 0x97, 0xFC, 0x1E, 0x82, - 0x21, 0x8C, 0x1B, 0x5F, 0x77, 0x54, 0xB2, 0x1D, 0x25, 0x4F, 0x00, 0x46, 0xED, 0x58, 0x52, 0xEB, 0x7E, - 0xDA, 0xC9, 0xFD, 0x30, 0x95, 0x65, 0x3C, 0xB6, 0xE4, 0xBB, 0x7C, 0x0E, 0x50, 0x39, 0x26, 0x32, 0x84, - 0x69, 0x93, 0x37, 0xE7, 0x24, 0xA4, 0xCB, 0x53, 0x0A, 0x87, 0xD9, 0x4C, 0x83, 0x8F, 0xCE, 0x3B, 0x4A, - 0xB7}; - -#define SS0(x) ((s_s0[x]*0x01010101UL) & 0x3FCFF3FC) -#define SS1(x) ((s_s1[x]*0x01010101UL) & 0xFC3FCFF3) -#define SS2(x) ((s_s0[x]*0x01010101UL) & 0xF3FC3FCF) -#define SS3(x) ((s_s1[x]*0x01010101UL) & 0xCFF3FC3F) -#define G(x) (SS0(GETBYTE(x, 0)) ^ SS1(GETBYTE(x, 1)) ^ SS2(GETBYTE(x, 2)) ^ SS3(GETBYTE(x, 3))) - -void SEED::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms) -{ - AssertValidKeyLength(length); - - word64 key01, key23; - GetBlock get(userKey); - get(key01)(key23); - word32 *k = m_k; - size_t kInc = 2; - if (!IsForwardTransformation()) - { - k = k+30; - kInc = 0-kInc; - } - - for (int i=0; i>32) + word32(key23>>32) - s_kc[i]; - word32 t1 = word32(key01) - word32(key23) + s_kc[i]; - k[0] = G(t0); - k[1] = G(t1); - k+=kInc; - if (i&1) - key23 = rotlFixed(key23, 8); - else - key01 = rotrFixed(key01, 8); - } -} - -void SEED::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - typedef BlockGetAndPut Block; - word32 a0, a1, b0, b1, t0, t1; - Block::Get(inBlock)(a0)(a1)(b0)(b1); - - for (int i=0; i, public FixedKeyLength<16>, public FixedRounds<16> -{ - static const char *StaticAlgorithmName() {return "SEED";} -}; - -/// SEED -class SEED : public SEED_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl - { - public: - void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - - protected: - FixedSizeSecBlock m_k; - }; - -public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/sha.cpp b/lib/cryptopp/sha.cpp deleted file mode 100644 index df947ad16..000000000 --- a/lib/cryptopp/sha.cpp +++ /dev/null @@ -1,900 +0,0 @@ -// sha.cpp - modified by Wei Dai from Steve Reid's public domain sha1.c - -// Steve Reid implemented SHA-1. Wei Dai implemented SHA-2. -// Both are in the public domain. - -// use "cl /EP /P /DCRYPTOPP_GENERATE_X64_MASM sha.cpp" to generate MASM code - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS -#ifndef CRYPTOPP_GENERATE_X64_MASM - -#include "sha.h" -#include "misc.h" -#include "cpu.h" - -NAMESPACE_BEGIN(CryptoPP) - -// start of Steve Reid's code - -#define blk0(i) (W[i] = data[i]) -#define blk1(i) (W[i&15] = rotlFixed(W[(i+13)&15]^W[(i+8)&15]^W[(i+2)&15]^W[i&15],1)) - -void SHA1::InitState(HashWordType *state) -{ - state[0] = 0x67452301L; - state[1] = 0xEFCDAB89L; - state[2] = 0x98BADCFEL; - state[3] = 0x10325476L; - state[4] = 0xC3D2E1F0L; -} - -#define f1(x,y,z) (z^(x&(y^z))) -#define f2(x,y,z) (x^y^z) -#define f3(x,y,z) ((x&y)|(z&(x|y))) -#define f4(x,y,z) (x^y^z) - -/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ -#define R0(v,w,x,y,z,i) z+=f1(w,x,y)+blk0(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30); -#define R1(v,w,x,y,z,i) z+=f1(w,x,y)+blk1(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30); -#define R2(v,w,x,y,z,i) z+=f2(w,x,y)+blk1(i)+0x6ED9EBA1+rotlFixed(v,5);w=rotlFixed(w,30); -#define R3(v,w,x,y,z,i) z+=f3(w,x,y)+blk1(i)+0x8F1BBCDC+rotlFixed(v,5);w=rotlFixed(w,30); -#define R4(v,w,x,y,z,i) z+=f4(w,x,y)+blk1(i)+0xCA62C1D6+rotlFixed(v,5);w=rotlFixed(w,30); - -void SHA1::Transform(word32 *state, const word32 *data) -{ - word32 W[16]; - /* Copy context->state[] to working vars */ - word32 a = state[0]; - word32 b = state[1]; - word32 c = state[2]; - word32 d = state[3]; - word32 e = state[4]; - /* 4 rounds of 20 operations each. Loop unrolled. */ - R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); - R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); - R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); - R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); - R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); - R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); - R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); - R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); - R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); - R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); - R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); - R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); - R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); - R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); - R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); - R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); - R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); - R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); - R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); - R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); - /* Add the working vars back into context.state[] */ - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - state[4] += e; -} - -// end of Steve Reid's code - -// ************************************************************* - -void SHA224::InitState(HashWordType *state) -{ - static const word32 s[8] = {0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4}; - memcpy(state, s, sizeof(s)); -} - -void SHA256::InitState(HashWordType *state) -{ - static const word32 s[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; - memcpy(state, s, sizeof(s)); -} - -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE -CRYPTOPP_ALIGN_DATA(16) extern const word32 SHA256_K[64] CRYPTOPP_SECTION_ALIGN16 = { -#else -extern const word32 SHA256_K[64] = { -#endif - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -}; - -#endif // #ifndef CRYPTOPP_GENERATE_X64_MASM - -#if defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_GENERATE_X64_MASM) - -#pragma warning(disable: 4731) // frame pointer register 'ebp' modified by inline assembly code - -static void CRYPTOPP_FASTCALL X86_SHA256_HashBlocks(word32 *state, const word32 *data, size_t len -#if defined(_MSC_VER) && (_MSC_VER == 1200) - , ... // VC60 workaround: prevent VC 6 from inlining this function -#endif - ) -{ -#if defined(_MSC_VER) && (_MSC_VER == 1200) - AS2(mov ecx, [state]) - AS2(mov edx, [data]) -#endif - - #define LOCALS_SIZE 8*4 + 16*4 + 4*WORD_SZ - #define H(i) [BASE+ASM_MOD(1024+7-(i),8)*4] - #define G(i) H(i+1) - #define F(i) H(i+2) - #define E(i) H(i+3) - #define D(i) H(i+4) - #define C(i) H(i+5) - #define B(i) H(i+6) - #define A(i) H(i+7) - #define Wt(i) BASE+8*4+ASM_MOD(1024+15-(i),16)*4 - #define Wt_2(i) Wt((i)-2) - #define Wt_15(i) Wt((i)-15) - #define Wt_7(i) Wt((i)-7) - #define K_END [BASE+8*4+16*4+0*WORD_SZ] - #define STATE_SAVE [BASE+8*4+16*4+1*WORD_SZ] - #define DATA_SAVE [BASE+8*4+16*4+2*WORD_SZ] - #define DATA_END [BASE+8*4+16*4+3*WORD_SZ] - #define Kt(i) WORD_REG(si)+(i)*4 -#if CRYPTOPP_BOOL_X86 - #define BASE esp+4 -#elif defined(__GNUC__) - #define BASE r8 -#else - #define BASE rsp -#endif - -#define RA0(i, edx, edi) \ - AS2( add edx, [Kt(i)] )\ - AS2( add edx, [Wt(i)] )\ - AS2( add edx, H(i) )\ - -#define RA1(i, edx, edi) - -#define RB0(i, edx, edi) - -#define RB1(i, edx, edi) \ - AS2( mov AS_REG_7d, [Wt_2(i)] )\ - AS2( mov edi, [Wt_15(i)])\ - AS2( mov ebx, AS_REG_7d )\ - AS2( shr AS_REG_7d, 10 )\ - AS2( ror ebx, 17 )\ - AS2( xor AS_REG_7d, ebx )\ - AS2( ror ebx, 2 )\ - AS2( xor ebx, AS_REG_7d )/* s1(W_t-2) */\ - AS2( add ebx, [Wt_7(i)])\ - AS2( mov AS_REG_7d, edi )\ - AS2( shr AS_REG_7d, 3 )\ - AS2( ror edi, 7 )\ - AS2( add ebx, [Wt(i)])/* s1(W_t-2) + W_t-7 + W_t-16 */\ - AS2( xor AS_REG_7d, edi )\ - AS2( add edx, [Kt(i)])\ - AS2( ror edi, 11 )\ - AS2( add edx, H(i) )\ - AS2( xor AS_REG_7d, edi )/* s0(W_t-15) */\ - AS2( add AS_REG_7d, ebx )/* W_t = s1(W_t-2) + W_t-7 + s0(W_t-15) W_t-16*/\ - AS2( mov [Wt(i)], AS_REG_7d)\ - AS2( add edx, AS_REG_7d )\ - -#define ROUND(i, r, eax, ecx, edi, edx)\ - /* in: edi = E */\ - /* unused: eax, ecx, temp: ebx, AS_REG_7d, out: edx = T1 */\ - AS2( mov edx, F(i) )\ - AS2( xor edx, G(i) )\ - AS2( and edx, edi )\ - AS2( xor edx, G(i) )/* Ch(E,F,G) = (G^(E&(F^G))) */\ - AS2( mov AS_REG_7d, edi )\ - AS2( ror edi, 6 )\ - AS2( ror AS_REG_7d, 25 )\ - RA##r(i, edx, edi )/* H + Wt + Kt + Ch(E,F,G) */\ - AS2( xor AS_REG_7d, edi )\ - AS2( ror edi, 5 )\ - AS2( xor AS_REG_7d, edi )/* S1(E) */\ - AS2( add edx, AS_REG_7d )/* T1 = S1(E) + Ch(E,F,G) + H + Wt + Kt */\ - RB##r(i, edx, edi )/* H + Wt + Kt + Ch(E,F,G) */\ - /* in: ecx = A, eax = B^C, edx = T1 */\ - /* unused: edx, temp: ebx, AS_REG_7d, out: eax = A, ecx = B^C, edx = E */\ - AS2( mov ebx, ecx )\ - AS2( xor ecx, B(i) )/* A^B */\ - AS2( and eax, ecx )\ - AS2( xor eax, B(i) )/* Maj(A,B,C) = B^((A^B)&(B^C) */\ - AS2( mov AS_REG_7d, ebx )\ - AS2( ror ebx, 2 )\ - AS2( add eax, edx )/* T1 + Maj(A,B,C) */\ - AS2( add edx, D(i) )\ - AS2( mov D(i), edx )\ - AS2( ror AS_REG_7d, 22 )\ - AS2( xor AS_REG_7d, ebx )\ - AS2( ror ebx, 11 )\ - AS2( xor AS_REG_7d, ebx )\ - AS2( add eax, AS_REG_7d )/* T1 + S0(A) + Maj(A,B,C) */\ - AS2( mov H(i), eax )\ - -#define SWAP_COPY(i) \ - AS2( mov WORD_REG(bx), [WORD_REG(dx)+i*WORD_SZ])\ - AS1( bswap WORD_REG(bx))\ - AS2( mov [Wt(i*(1+CRYPTOPP_BOOL_X64)+CRYPTOPP_BOOL_X64)], WORD_REG(bx)) - -#if defined(__GNUC__) - #if CRYPTOPP_BOOL_X64 - FixedSizeAlignedSecBlock workspace; - #endif - __asm__ __volatile__ - ( - #if CRYPTOPP_BOOL_X64 - "lea %4, %%r8;" - #endif - ".intel_syntax noprefix;" -#elif defined(CRYPTOPP_GENERATE_X64_MASM) - ALIGN 8 - X86_SHA256_HashBlocks PROC FRAME - rex_push_reg rsi - push_reg rdi - push_reg rbx - push_reg rbp - alloc_stack(LOCALS_SIZE+8) - .endprolog - mov rdi, r8 - lea rsi, [?SHA256_K@CryptoPP@@3QBIB + 48*4] -#endif - -#if CRYPTOPP_BOOL_X86 - #ifndef __GNUC__ - AS2( mov edi, [len]) - AS2( lea WORD_REG(si), [SHA256_K+48*4]) - #endif - #if !defined(_MSC_VER) || (_MSC_VER < 1400) - AS_PUSH_IF86(bx) - #endif - - AS_PUSH_IF86(bp) - AS2( mov ebx, esp) - AS2( and esp, -16) - AS2( sub WORD_REG(sp), LOCALS_SIZE) - AS_PUSH_IF86(bx) -#endif - AS2( mov STATE_SAVE, WORD_REG(cx)) - AS2( mov DATA_SAVE, WORD_REG(dx)) - AS2( lea WORD_REG(ax), [WORD_REG(di) + WORD_REG(dx)]) - AS2( mov DATA_END, WORD_REG(ax)) - AS2( mov K_END, WORD_REG(si)) - -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE -#if CRYPTOPP_BOOL_X86 - AS2( test edi, 1) - ASJ( jnz, 2, f) - AS1( dec DWORD PTR K_END) -#endif - AS2( movdqa xmm0, XMMWORD_PTR [WORD_REG(cx)+0*16]) - AS2( movdqa xmm1, XMMWORD_PTR [WORD_REG(cx)+1*16]) -#endif - -#if CRYPTOPP_BOOL_X86 -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE - ASJ( jmp, 0, f) -#endif - ASL(2) // non-SSE2 - AS2( mov esi, ecx) - AS2( lea edi, A(0)) - AS2( mov ecx, 8) - AS1( rep movsd) - AS2( mov esi, K_END) - ASJ( jmp, 3, f) -#endif - -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE - ASL(0) - AS2( movdqa E(0), xmm1) - AS2( movdqa A(0), xmm0) -#endif -#if CRYPTOPP_BOOL_X86 - ASL(3) -#endif - AS2( sub WORD_REG(si), 48*4) - SWAP_COPY(0) SWAP_COPY(1) SWAP_COPY(2) SWAP_COPY(3) - SWAP_COPY(4) SWAP_COPY(5) SWAP_COPY(6) SWAP_COPY(7) -#if CRYPTOPP_BOOL_X86 - SWAP_COPY(8) SWAP_COPY(9) SWAP_COPY(10) SWAP_COPY(11) - SWAP_COPY(12) SWAP_COPY(13) SWAP_COPY(14) SWAP_COPY(15) -#endif - AS2( mov edi, E(0)) // E - AS2( mov eax, B(0)) // B - AS2( xor eax, C(0)) // B^C - AS2( mov ecx, A(0)) // A - - ROUND(0, 0, eax, ecx, edi, edx) - ROUND(1, 0, ecx, eax, edx, edi) - ROUND(2, 0, eax, ecx, edi, edx) - ROUND(3, 0, ecx, eax, edx, edi) - ROUND(4, 0, eax, ecx, edi, edx) - ROUND(5, 0, ecx, eax, edx, edi) - ROUND(6, 0, eax, ecx, edi, edx) - ROUND(7, 0, ecx, eax, edx, edi) - ROUND(8, 0, eax, ecx, edi, edx) - ROUND(9, 0, ecx, eax, edx, edi) - ROUND(10, 0, eax, ecx, edi, edx) - ROUND(11, 0, ecx, eax, edx, edi) - ROUND(12, 0, eax, ecx, edi, edx) - ROUND(13, 0, ecx, eax, edx, edi) - ROUND(14, 0, eax, ecx, edi, edx) - ROUND(15, 0, ecx, eax, edx, edi) - - ASL(1) - AS2(add WORD_REG(si), 4*16) - ROUND(0, 1, eax, ecx, edi, edx) - ROUND(1, 1, ecx, eax, edx, edi) - ROUND(2, 1, eax, ecx, edi, edx) - ROUND(3, 1, ecx, eax, edx, edi) - ROUND(4, 1, eax, ecx, edi, edx) - ROUND(5, 1, ecx, eax, edx, edi) - ROUND(6, 1, eax, ecx, edi, edx) - ROUND(7, 1, ecx, eax, edx, edi) - ROUND(8, 1, eax, ecx, edi, edx) - ROUND(9, 1, ecx, eax, edx, edi) - ROUND(10, 1, eax, ecx, edi, edx) - ROUND(11, 1, ecx, eax, edx, edi) - ROUND(12, 1, eax, ecx, edi, edx) - ROUND(13, 1, ecx, eax, edx, edi) - ROUND(14, 1, eax, ecx, edi, edx) - ROUND(15, 1, ecx, eax, edx, edi) - AS2( cmp WORD_REG(si), K_END) - ASJ( jb, 1, b) - - AS2( mov WORD_REG(dx), DATA_SAVE) - AS2( add WORD_REG(dx), 64) - AS2( mov AS_REG_7, STATE_SAVE) - AS2( mov DATA_SAVE, WORD_REG(dx)) - -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE -#if CRYPTOPP_BOOL_X86 - AS2( test DWORD PTR K_END, 1) - ASJ( jz, 4, f) -#endif - AS2( movdqa xmm1, XMMWORD_PTR [AS_REG_7+1*16]) - AS2( movdqa xmm0, XMMWORD_PTR [AS_REG_7+0*16]) - AS2( paddd xmm1, E(0)) - AS2( paddd xmm0, A(0)) - AS2( movdqa [AS_REG_7+1*16], xmm1) - AS2( movdqa [AS_REG_7+0*16], xmm0) - AS2( cmp WORD_REG(dx), DATA_END) - ASJ( jb, 0, b) -#endif - -#if CRYPTOPP_BOOL_X86 -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE - ASJ( jmp, 5, f) - ASL(4) // non-SSE2 -#endif - AS2( add [AS_REG_7+0*4], ecx) // A - AS2( add [AS_REG_7+4*4], edi) // E - AS2( mov eax, B(0)) - AS2( mov ebx, C(0)) - AS2( mov ecx, D(0)) - AS2( add [AS_REG_7+1*4], eax) - AS2( add [AS_REG_7+2*4], ebx) - AS2( add [AS_REG_7+3*4], ecx) - AS2( mov eax, F(0)) - AS2( mov ebx, G(0)) - AS2( mov ecx, H(0)) - AS2( add [AS_REG_7+5*4], eax) - AS2( add [AS_REG_7+6*4], ebx) - AS2( add [AS_REG_7+7*4], ecx) - AS2( mov ecx, AS_REG_7d) - AS2( cmp WORD_REG(dx), DATA_END) - ASJ( jb, 2, b) -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE - ASL(5) -#endif -#endif - - AS_POP_IF86(sp) - AS_POP_IF86(bp) - #if !defined(_MSC_VER) || (_MSC_VER < 1400) - AS_POP_IF86(bx) - #endif - -#ifdef CRYPTOPP_GENERATE_X64_MASM - add rsp, LOCALS_SIZE+8 - pop rbp - pop rbx - pop rdi - pop rsi - ret - X86_SHA256_HashBlocks ENDP -#endif - -#ifdef __GNUC__ - ".att_syntax prefix;" - : - : "c" (state), "d" (data), "S" (SHA256_K+48), "D" (len) - #if CRYPTOPP_BOOL_X64 - , "m" (workspace[0]) - #endif - : "memory", "cc", "%eax" - #if CRYPTOPP_BOOL_X64 - , "%rbx", "%r8", "%r10" - #endif - ); -#endif -} - -#endif // #if defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_GENERATE_X64_MASM) - -#ifndef CRYPTOPP_GENERATE_X64_MASM - -#ifdef CRYPTOPP_X64_MASM_AVAILABLE -extern "C" { -void CRYPTOPP_FASTCALL X86_SHA256_HashBlocks(word32 *state, const word32 *data, size_t len); -} -#endif - -#if defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE) - -size_t SHA256::HashMultipleBlocks(const word32 *input, size_t length) -{ - X86_SHA256_HashBlocks(m_state, input, (length&(size_t(0)-BLOCKSIZE)) - !HasSSE2()); - return length % BLOCKSIZE; -} - -size_t SHA224::HashMultipleBlocks(const word32 *input, size_t length) -{ - X86_SHA256_HashBlocks(m_state, input, (length&(size_t(0)-BLOCKSIZE)) - !HasSSE2()); - return length % BLOCKSIZE; -} - -#endif - -#define blk2(i) (W[i&15]+=s1(W[(i-2)&15])+W[(i-7)&15]+s0(W[(i-15)&15])) - -#define Ch(x,y,z) (z^(x&(y^z))) -#define Maj(x,y,z) (y^((x^y)&(y^z))) - -#define a(i) T[(0-i)&7] -#define b(i) T[(1-i)&7] -#define c(i) T[(2-i)&7] -#define d(i) T[(3-i)&7] -#define e(i) T[(4-i)&7] -#define f(i) T[(5-i)&7] -#define g(i) T[(6-i)&7] -#define h(i) T[(7-i)&7] - -#define R(i) h(i)+=S1(e(i))+Ch(e(i),f(i),g(i))+SHA256_K[i+j]+(j?blk2(i):blk0(i));\ - d(i)+=h(i);h(i)+=S0(a(i))+Maj(a(i),b(i),c(i)) - -// for SHA256 -#define S0(x) (rotrFixed(x,2)^rotrFixed(x,13)^rotrFixed(x,22)) -#define S1(x) (rotrFixed(x,6)^rotrFixed(x,11)^rotrFixed(x,25)) -#define s0(x) (rotrFixed(x,7)^rotrFixed(x,18)^(x>>3)) -#define s1(x) (rotrFixed(x,17)^rotrFixed(x,19)^(x>>10)) - -void SHA256::Transform(word32 *state, const word32 *data) -{ - word32 W[16]; -#if defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE) - // this byte reverse is a waste of time, but this function is only called by MDC - ByteReverse(W, data, BLOCKSIZE); - X86_SHA256_HashBlocks(state, W, BLOCKSIZE - !HasSSE2()); -#else - word32 T[8]; - /* Copy context->state[] to working vars */ - memcpy(T, state, sizeof(T)); - /* 64 operations, partially loop unrolled */ - for (unsigned int j=0; j<64; j+=16) - { - R( 0); R( 1); R( 2); R( 3); - R( 4); R( 5); R( 6); R( 7); - R( 8); R( 9); R(10); R(11); - R(12); R(13); R(14); R(15); - } - /* Add the working vars back into context.state[] */ - state[0] += a(0); - state[1] += b(0); - state[2] += c(0); - state[3] += d(0); - state[4] += e(0); - state[5] += f(0); - state[6] += g(0); - state[7] += h(0); -#endif -} - -/* -// smaller but slower -void SHA256::Transform(word32 *state, const word32 *data) -{ - word32 T[20]; - word32 W[32]; - unsigned int i = 0, j = 0; - word32 *t = T+8; - - memcpy(t, state, 8*4); - word32 e = t[4], a = t[0]; - - do - { - word32 w = data[j]; - W[j] = w; - w += SHA256_K[j]; - w += t[7]; - w += S1(e); - w += Ch(e, t[5], t[6]); - e = t[3] + w; - t[3] = t[3+8] = e; - w += S0(t[0]); - a = w + Maj(a, t[1], t[2]); - t[-1] = t[7] = a; - --t; - ++j; - if (j%8 == 0) - t += 8; - } while (j<16); - - do - { - i = j&0xf; - word32 w = s1(W[i+16-2]) + s0(W[i+16-15]) + W[i] + W[i+16-7]; - W[i+16] = W[i] = w; - w += SHA256_K[j]; - w += t[7]; - w += S1(e); - w += Ch(e, t[5], t[6]); - e = t[3] + w; - t[3] = t[3+8] = e; - w += S0(t[0]); - a = w + Maj(a, t[1], t[2]); - t[-1] = t[7] = a; - - w = s1(W[(i+1)+16-2]) + s0(W[(i+1)+16-15]) + W[(i+1)] + W[(i+1)+16-7]; - W[(i+1)+16] = W[(i+1)] = w; - w += SHA256_K[j+1]; - w += (t-1)[7]; - w += S1(e); - w += Ch(e, (t-1)[5], (t-1)[6]); - e = (t-1)[3] + w; - (t-1)[3] = (t-1)[3+8] = e; - w += S0((t-1)[0]); - a = w + Maj(a, (t-1)[1], (t-1)[2]); - (t-1)[-1] = (t-1)[7] = a; - - t-=2; - j+=2; - if (j%8 == 0) - t += 8; - } while (j<64); - - state[0] += a; - state[1] += t[1]; - state[2] += t[2]; - state[3] += t[3]; - state[4] += e; - state[5] += t[5]; - state[6] += t[6]; - state[7] += t[7]; -} -*/ - -#undef S0 -#undef S1 -#undef s0 -#undef s1 -#undef R - -// ************************************************************* - -void SHA384::InitState(HashWordType *state) -{ - static const word64 s[8] = { - W64LIT(0xcbbb9d5dc1059ed8), W64LIT(0x629a292a367cd507), - W64LIT(0x9159015a3070dd17), W64LIT(0x152fecd8f70e5939), - W64LIT(0x67332667ffc00b31), W64LIT(0x8eb44a8768581511), - W64LIT(0xdb0c2e0d64f98fa7), W64LIT(0x47b5481dbefa4fa4)}; - memcpy(state, s, sizeof(s)); -} - -void SHA512::InitState(HashWordType *state) -{ - static const word64 s[8] = { - W64LIT(0x6a09e667f3bcc908), W64LIT(0xbb67ae8584caa73b), - W64LIT(0x3c6ef372fe94f82b), W64LIT(0xa54ff53a5f1d36f1), - W64LIT(0x510e527fade682d1), W64LIT(0x9b05688c2b3e6c1f), - W64LIT(0x1f83d9abfb41bd6b), W64LIT(0x5be0cd19137e2179)}; - memcpy(state, s, sizeof(s)); -} - -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && CRYPTOPP_BOOL_X86 -CRYPTOPP_ALIGN_DATA(16) static const word64 SHA512_K[80] CRYPTOPP_SECTION_ALIGN16 = { -#else -static const word64 SHA512_K[80] = { -#endif - W64LIT(0x428a2f98d728ae22), W64LIT(0x7137449123ef65cd), - W64LIT(0xb5c0fbcfec4d3b2f), W64LIT(0xe9b5dba58189dbbc), - W64LIT(0x3956c25bf348b538), W64LIT(0x59f111f1b605d019), - W64LIT(0x923f82a4af194f9b), W64LIT(0xab1c5ed5da6d8118), - W64LIT(0xd807aa98a3030242), W64LIT(0x12835b0145706fbe), - W64LIT(0x243185be4ee4b28c), W64LIT(0x550c7dc3d5ffb4e2), - W64LIT(0x72be5d74f27b896f), W64LIT(0x80deb1fe3b1696b1), - W64LIT(0x9bdc06a725c71235), W64LIT(0xc19bf174cf692694), - W64LIT(0xe49b69c19ef14ad2), W64LIT(0xefbe4786384f25e3), - W64LIT(0x0fc19dc68b8cd5b5), W64LIT(0x240ca1cc77ac9c65), - W64LIT(0x2de92c6f592b0275), W64LIT(0x4a7484aa6ea6e483), - W64LIT(0x5cb0a9dcbd41fbd4), W64LIT(0x76f988da831153b5), - W64LIT(0x983e5152ee66dfab), W64LIT(0xa831c66d2db43210), - W64LIT(0xb00327c898fb213f), W64LIT(0xbf597fc7beef0ee4), - W64LIT(0xc6e00bf33da88fc2), W64LIT(0xd5a79147930aa725), - W64LIT(0x06ca6351e003826f), W64LIT(0x142929670a0e6e70), - W64LIT(0x27b70a8546d22ffc), W64LIT(0x2e1b21385c26c926), - W64LIT(0x4d2c6dfc5ac42aed), W64LIT(0x53380d139d95b3df), - W64LIT(0x650a73548baf63de), W64LIT(0x766a0abb3c77b2a8), - W64LIT(0x81c2c92e47edaee6), W64LIT(0x92722c851482353b), - W64LIT(0xa2bfe8a14cf10364), W64LIT(0xa81a664bbc423001), - W64LIT(0xc24b8b70d0f89791), W64LIT(0xc76c51a30654be30), - W64LIT(0xd192e819d6ef5218), W64LIT(0xd69906245565a910), - W64LIT(0xf40e35855771202a), W64LIT(0x106aa07032bbd1b8), - W64LIT(0x19a4c116b8d2d0c8), W64LIT(0x1e376c085141ab53), - W64LIT(0x2748774cdf8eeb99), W64LIT(0x34b0bcb5e19b48a8), - W64LIT(0x391c0cb3c5c95a63), W64LIT(0x4ed8aa4ae3418acb), - W64LIT(0x5b9cca4f7763e373), W64LIT(0x682e6ff3d6b2b8a3), - W64LIT(0x748f82ee5defb2fc), W64LIT(0x78a5636f43172f60), - W64LIT(0x84c87814a1f0ab72), W64LIT(0x8cc702081a6439ec), - W64LIT(0x90befffa23631e28), W64LIT(0xa4506cebde82bde9), - W64LIT(0xbef9a3f7b2c67915), W64LIT(0xc67178f2e372532b), - W64LIT(0xca273eceea26619c), W64LIT(0xd186b8c721c0c207), - W64LIT(0xeada7dd6cde0eb1e), W64LIT(0xf57d4f7fee6ed178), - W64LIT(0x06f067aa72176fba), W64LIT(0x0a637dc5a2c898a6), - W64LIT(0x113f9804bef90dae), W64LIT(0x1b710b35131c471b), - W64LIT(0x28db77f523047d84), W64LIT(0x32caab7b40c72493), - W64LIT(0x3c9ebe0a15c9bebc), W64LIT(0x431d67c49c100d4c), - W64LIT(0x4cc5d4becb3e42b6), W64LIT(0x597f299cfc657e2a), - W64LIT(0x5fcb6fab3ad6faec), W64LIT(0x6c44198c4a475817) -}; - -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && CRYPTOPP_BOOL_X86 -// put assembly version in separate function, otherwise MSVC 2005 SP1 doesn't generate correct code for the non-assembly version -CRYPTOPP_NAKED static void CRYPTOPP_FASTCALL SHA512_SSE2_Transform(word64 *state, const word64 *data) -{ -#ifdef __GNUC__ - __asm__ __volatile__ - ( - ".intel_syntax noprefix;" - AS1( push ebx) - AS2( mov ebx, eax) -#else - AS1( push ebx) - AS1( push esi) - AS1( push edi) - AS2( lea ebx, SHA512_K) -#endif - - AS2( mov eax, esp) - AS2( and esp, 0xfffffff0) - AS2( sub esp, 27*16) // 17*16 for expanded data, 20*8 for state - AS1( push eax) - AS2( xor eax, eax) - AS2( lea edi, [esp+4+8*8]) // start at middle of state buffer. will decrement pointer each round to avoid copying - AS2( lea esi, [esp+4+20*8+8]) // 16-byte alignment, then add 8 - - AS2( movdqa xmm0, [ecx+0*16]) - AS2( movdq2q mm4, xmm0) - AS2( movdqa [edi+0*16], xmm0) - AS2( movdqa xmm0, [ecx+1*16]) - AS2( movdqa [edi+1*16], xmm0) - AS2( movdqa xmm0, [ecx+2*16]) - AS2( movdq2q mm5, xmm0) - AS2( movdqa [edi+2*16], xmm0) - AS2( movdqa xmm0, [ecx+3*16]) - AS2( movdqa [edi+3*16], xmm0) - ASJ( jmp, 0, f) - -#define SSE2_S0_S1(r, a, b, c) \ - AS2( movq mm6, r)\ - AS2( psrlq r, a)\ - AS2( movq mm7, r)\ - AS2( psllq mm6, 64-c)\ - AS2( pxor mm7, mm6)\ - AS2( psrlq r, b-a)\ - AS2( pxor mm7, r)\ - AS2( psllq mm6, c-b)\ - AS2( pxor mm7, mm6)\ - AS2( psrlq r, c-b)\ - AS2( pxor r, mm7)\ - AS2( psllq mm6, b-a)\ - AS2( pxor r, mm6) - -#define SSE2_s0(r, a, b, c) \ - AS2( movdqa xmm6, r)\ - AS2( psrlq r, a)\ - AS2( movdqa xmm7, r)\ - AS2( psllq xmm6, 64-c)\ - AS2( pxor xmm7, xmm6)\ - AS2( psrlq r, b-a)\ - AS2( pxor xmm7, r)\ - AS2( psrlq r, c-b)\ - AS2( pxor r, xmm7)\ - AS2( psllq xmm6, c-a)\ - AS2( pxor r, xmm6) - -#define SSE2_s1(r, a, b, c) \ - AS2( movdqa xmm6, r)\ - AS2( psrlq r, a)\ - AS2( movdqa xmm7, r)\ - AS2( psllq xmm6, 64-c)\ - AS2( pxor xmm7, xmm6)\ - AS2( psrlq r, b-a)\ - AS2( pxor xmm7, r)\ - AS2( psllq xmm6, c-b)\ - AS2( pxor xmm7, xmm6)\ - AS2( psrlq r, c-b)\ - AS2( pxor r, xmm7) - - ASL(SHA512_Round) - // k + w is in mm0, a is in mm4, e is in mm5 - AS2( paddq mm0, [edi+7*8]) // h - AS2( movq mm2, [edi+5*8]) // f - AS2( movq mm3, [edi+6*8]) // g - AS2( pxor mm2, mm3) - AS2( pand mm2, mm5) - SSE2_S0_S1(mm5,14,18,41) - AS2( pxor mm2, mm3) - AS2( paddq mm0, mm2) // h += Ch(e,f,g) - AS2( paddq mm5, mm0) // h += S1(e) - AS2( movq mm2, [edi+1*8]) // b - AS2( movq mm1, mm2) - AS2( por mm2, mm4) - AS2( pand mm2, [edi+2*8]) // c - AS2( pand mm1, mm4) - AS2( por mm1, mm2) - AS2( paddq mm1, mm5) // temp = h + Maj(a,b,c) - AS2( paddq mm5, [edi+3*8]) // e = d + h - AS2( movq [edi+3*8], mm5) - AS2( movq [edi+11*8], mm5) - SSE2_S0_S1(mm4,28,34,39) // S0(a) - AS2( paddq mm4, mm1) // a = temp + S0(a) - AS2( movq [edi-8], mm4) - AS2( movq [edi+7*8], mm4) - AS1( ret) - - // first 16 rounds - ASL(0) - AS2( movq mm0, [edx+eax*8]) - AS2( movq [esi+eax*8], mm0) - AS2( movq [esi+eax*8+16*8], mm0) - AS2( paddq mm0, [ebx+eax*8]) - ASC( call, SHA512_Round) - AS1( inc eax) - AS2( sub edi, 8) - AS2( test eax, 7) - ASJ( jnz, 0, b) - AS2( add edi, 8*8) - AS2( cmp eax, 16) - ASJ( jne, 0, b) - - // rest of the rounds - AS2( movdqu xmm0, [esi+(16-2)*8]) - ASL(1) - // data expansion, W[i-2] already in xmm0 - AS2( movdqu xmm3, [esi]) - AS2( paddq xmm3, [esi+(16-7)*8]) - AS2( movdqa xmm2, [esi+(16-15)*8]) - SSE2_s1(xmm0, 6, 19, 61) - AS2( paddq xmm0, xmm3) - SSE2_s0(xmm2, 1, 7, 8) - AS2( paddq xmm0, xmm2) - AS2( movdq2q mm0, xmm0) - AS2( movhlps xmm1, xmm0) - AS2( paddq mm0, [ebx+eax*8]) - AS2( movlps [esi], xmm0) - AS2( movlps [esi+8], xmm1) - AS2( movlps [esi+8*16], xmm0) - AS2( movlps [esi+8*17], xmm1) - // 2 rounds - ASC( call, SHA512_Round) - AS2( sub edi, 8) - AS2( movdq2q mm0, xmm1) - AS2( paddq mm0, [ebx+eax*8+8]) - ASC( call, SHA512_Round) - // update indices and loop - AS2( add esi, 16) - AS2( add eax, 2) - AS2( sub edi, 8) - AS2( test eax, 7) - ASJ( jnz, 1, b) - // do housekeeping every 8 rounds - AS2( mov esi, 0xf) - AS2( and esi, eax) - AS2( lea esi, [esp+4+20*8+8+esi*8]) - AS2( add edi, 8*8) - AS2( cmp eax, 80) - ASJ( jne, 1, b) - -#define SSE2_CombineState(i) \ - AS2( movdqa xmm0, [edi+i*16])\ - AS2( paddq xmm0, [ecx+i*16])\ - AS2( movdqa [ecx+i*16], xmm0) - - SSE2_CombineState(0) - SSE2_CombineState(1) - SSE2_CombineState(2) - SSE2_CombineState(3) - - AS1( pop esp) - AS1( emms) - -#if defined(__GNUC__) - AS1( pop ebx) - ".att_syntax prefix;" - : - : "a" (SHA512_K), "c" (state), "d" (data) - : "%esi", "%edi", "memory", "cc" - ); -#else - AS1( pop edi) - AS1( pop esi) - AS1( pop ebx) - AS1( ret) -#endif -} -#endif // #if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE - -void SHA512::Transform(word64 *state, const word64 *data) -{ -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && CRYPTOPP_BOOL_X86 - if (HasSSE2()) - { - SHA512_SSE2_Transform(state, data); - return; - } -#endif - -#define S0(x) (rotrFixed(x,28)^rotrFixed(x,34)^rotrFixed(x,39)) -#define S1(x) (rotrFixed(x,14)^rotrFixed(x,18)^rotrFixed(x,41)) -#define s0(x) (rotrFixed(x,1)^rotrFixed(x,8)^(x>>7)) -#define s1(x) (rotrFixed(x,19)^rotrFixed(x,61)^(x>>6)) - -#define R(i) h(i)+=S1(e(i))+Ch(e(i),f(i),g(i))+SHA512_K[i+j]+(j?blk2(i):blk0(i));\ - d(i)+=h(i);h(i)+=S0(a(i))+Maj(a(i),b(i),c(i)) - - word64 W[16]; - word64 T[8]; - /* Copy context->state[] to working vars */ - memcpy(T, state, sizeof(T)); - /* 80 operations, partially loop unrolled */ - for (unsigned int j=0; j<80; j+=16) - { - R( 0); R( 1); R( 2); R( 3); - R( 4); R( 5); R( 6); R( 7); - R( 8); R( 9); R(10); R(11); - R(12); R(13); R(14); R(15); - } - /* Add the working vars back into context.state[] */ - state[0] += a(0); - state[1] += b(0); - state[2] += c(0); - state[3] += d(0); - state[4] += e(0); - state[5] += f(0); - state[6] += g(0); - state[7] += h(0); -} - -NAMESPACE_END - -#endif // #ifndef CRYPTOPP_GENERATE_X64_MASM -#endif // #ifndef CRYPTOPP_IMPORTS diff --git a/lib/cryptopp/sha.h b/lib/cryptopp/sha.h deleted file mode 100644 index 679081e8f..000000000 --- a/lib/cryptopp/sha.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef CRYPTOPP_SHA_H -#define CRYPTOPP_SHA_H - -#include "iterhash.h" - -NAMESPACE_BEGIN(CryptoPP) - -/// SHA-1 -class CRYPTOPP_DLL SHA1 : public IteratedHashWithStaticTransform -{ -public: - static void CRYPTOPP_API InitState(HashWordType *state); - static void CRYPTOPP_API Transform(word32 *digest, const word32 *data); - static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";} -}; - -typedef SHA1 SHA; // for backwards compatibility - -//! implements the SHA-256 standard -class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform -{ -public: -#if defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE) - size_t HashMultipleBlocks(const word32 *input, size_t length); -#endif - static void CRYPTOPP_API InitState(HashWordType *state); - static void CRYPTOPP_API Transform(word32 *digest, const word32 *data); - static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";} -}; - -//! implements the SHA-224 standard -class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform -{ -public: -#if defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE) - size_t HashMultipleBlocks(const word32 *input, size_t length); -#endif - static void CRYPTOPP_API InitState(HashWordType *state); - static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);} - static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";} -}; - -//! implements the SHA-512 standard -class CRYPTOPP_DLL SHA512 : public IteratedHashWithStaticTransform -{ -public: - static void CRYPTOPP_API InitState(HashWordType *state); - static void CRYPTOPP_API Transform(word64 *digest, const word64 *data); - static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";} -}; - -//! implements the SHA-384 standard -class CRYPTOPP_DLL SHA384 : public IteratedHashWithStaticTransform -{ -public: - static void CRYPTOPP_API InitState(HashWordType *state); - static void CRYPTOPP_API Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);} - static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";} -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/shacal2.cpp b/lib/cryptopp/shacal2.cpp deleted file mode 100644 index b0360e404..000000000 --- a/lib/cryptopp/shacal2.cpp +++ /dev/null @@ -1,140 +0,0 @@ -// shacal2.cpp - by Kevin Springle, 2003 -// -// Portions of this code were derived from -// Wei Dai's implementation of SHA-2 -// -// The original code and all modifications are in the public domain. - -#include "pch.h" -#include "shacal2.h" -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) - -// SHACAL-2 function and round definitions - -#define S0(x) (rotrFixed(x,2)^rotrFixed(x,13)^rotrFixed(x,22)) -#define S1(x) (rotrFixed(x,6)^rotrFixed(x,11)^rotrFixed(x,25)) -#define s0(x) (rotrFixed(x,7)^rotrFixed(x,18)^(x>>3)) -#define s1(x) (rotrFixed(x,17)^rotrFixed(x,19)^(x>>10)) - -#define Ch(x,y,z) (z^(x&(y^z))) -#define Maj(x,y,z) ((x&y)|(z&(x|y))) - -/* R is the SHA-256 round function. */ -/* This macro increments the k argument as a side effect. */ -#define R(a,b,c,d,e,f,g,h,k) \ - h+=S1(e)+Ch(e,f,g)+*k++;d+=h;h+=S0(a)+Maj(a,b,c); - -/* P is the inverse of the SHA-256 round function. */ -/* This macro decrements the k argument as a side effect. */ -#define P(a,b,c,d,e,f,g,h,k) \ - h-=S0(a)+Maj(a,b,c);d-=h;h-=S1(e)+Ch(e,f,g)+*--k; - -void SHACAL2::Base::UncheckedSetKey(const byte *userKey, unsigned int keylen, const NameValuePairs &) -{ - AssertValidKeyLength(keylen); - - word32 *rk = m_key; - unsigned int i; - - GetUserKey(BIG_ENDIAN_ORDER, rk, m_key.size(), userKey, keylen); - for (i = 0; i < 48; i++, rk++) - { - rk[16] = rk[0] + s0(rk[1]) + rk[9] + s1(rk[14]); - rk[0] += K[i]; - } - for (i = 48; i < 64; i++, rk++) - { - rk[0] += K[i]; - } -} - -typedef BlockGetAndPut Block; - -void SHACAL2::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - word32 a, b, c, d, e, f, g, h; - const word32 *rk = m_key; - - /* - * map byte array block to cipher state: - */ - Block::Get(inBlock)(a)(b)(c)(d)(e)(f)(g)(h); - - // Perform SHA-256 transformation. - - /* 64 operations, partially loop unrolled */ - for (unsigned int j=0; j<64; j+=8) - { - R(a,b,c,d,e,f,g,h,rk); - R(h,a,b,c,d,e,f,g,rk); - R(g,h,a,b,c,d,e,f,rk); - R(f,g,h,a,b,c,d,e,rk); - R(e,f,g,h,a,b,c,d,rk); - R(d,e,f,g,h,a,b,c,rk); - R(c,d,e,f,g,h,a,b,rk); - R(b,c,d,e,f,g,h,a,rk); - } - - /* - * map cipher state to byte array block: - */ - - Block::Put(xorBlock, outBlock)(a)(b)(c)(d)(e)(f)(g)(h); -} - -void SHACAL2::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - word32 a, b, c, d, e, f, g, h; - const word32 *rk = m_key + 64; - - /* - * map byte array block to cipher state: - */ - Block::Get(inBlock)(a)(b)(c)(d)(e)(f)(g)(h); - - // Perform inverse SHA-256 transformation. - - /* 64 operations, partially loop unrolled */ - for (unsigned int j=0; j<64; j+=8) - { - P(b,c,d,e,f,g,h,a,rk); - P(c,d,e,f,g,h,a,b,rk); - P(d,e,f,g,h,a,b,c,rk); - P(e,f,g,h,a,b,c,d,rk); - P(f,g,h,a,b,c,d,e,rk); - P(g,h,a,b,c,d,e,f,rk); - P(h,a,b,c,d,e,f,g,rk); - P(a,b,c,d,e,f,g,h,rk); - } - - /* - * map cipher state to byte array block: - */ - - Block::Put(xorBlock, outBlock)(a)(b)(c)(d)(e)(f)(g)(h); -} - -// The SHACAL-2 round constants are identical to the SHA-256 round constants. -const word32 SHACAL2::Base::K[64] = -{ - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -}; - -NAMESPACE_END diff --git a/lib/cryptopp/shacal2.h b/lib/cryptopp/shacal2.h deleted file mode 100644 index 66c987fd7..000000000 --- a/lib/cryptopp/shacal2.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef CRYPTOPP_SHACAL2_H -#define CRYPTOPP_SHACAL2_H - -/** \file -*/ - -#include "seckey.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -struct SHACAL2_Info : public FixedBlockSize<32>, public VariableKeyLength<16, 16, 64> -{ - static const char *StaticAlgorithmName() {return "SHACAL-2";} -}; - -/// SHACAL-2 -class SHACAL2 : public SHACAL2_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl - { - public: - void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); - - protected: - FixedSizeSecBlock m_key; - - static const word32 K[64]; - }; - - class CRYPTOPP_NO_VTABLE Enc : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - }; - - class CRYPTOPP_NO_VTABLE Dec : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - }; - -public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -typedef SHACAL2::Encryption SHACAL2Encryption; -typedef SHACAL2::Decryption SHACAL2Decryption; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/simple.cpp b/lib/cryptopp/simple.cpp deleted file mode 100644 index 96f256b40..000000000 --- a/lib/cryptopp/simple.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// simple.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "simple.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/simple.h b/lib/cryptopp/simple.h deleted file mode 100644 index 35fd65ae4..000000000 --- a/lib/cryptopp/simple.h +++ /dev/null @@ -1,209 +0,0 @@ -// simple.h - written and placed in the public domain by Wei Dai -/*! \file - Simple non-interface classes derived from classes in cryptlib.h. -*/ - -#ifndef CRYPTOPP_SIMPLE_H -#define CRYPTOPP_SIMPLE_H - -#include "cryptlib.h" -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -template -class CRYPTOPP_NO_VTABLE ClonableImpl : public BASE -{ -public: - Clonable * Clone() const {return new DERIVED(*static_cast(this));} -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE AlgorithmImpl : public BASE -{ -public: - static std::string CRYPTOPP_API StaticAlgorithmName() {return ALGORITHM_INFO::StaticAlgorithmName();} - std::string AlgorithmName() const {return ALGORITHM_INFO::StaticAlgorithmName();} -}; - -//! _ -class CRYPTOPP_DLL InvalidKeyLength : public InvalidArgument -{ -public: - explicit InvalidKeyLength(const std::string &algorithm, size_t length) : InvalidArgument(algorithm + ": " + IntToString(length) + " is not a valid key length") {} -}; - -//! _ -class CRYPTOPP_DLL InvalidRounds : public InvalidArgument -{ -public: - explicit InvalidRounds(const std::string &algorithm, unsigned int rounds) : InvalidArgument(algorithm + ": " + IntToString(rounds) + " is not a valid number of rounds") {} -}; - -// ***************************** - -//! _ -template -class CRYPTOPP_NO_VTABLE Bufferless : public T -{ -public: - bool IsolatedFlush(bool hardFlush, bool blocking) {return false;} -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE Unflushable : public T -{ -public: - bool Flush(bool completeFlush, int propagation=-1, bool blocking=true) - {return ChannelFlush(DEFAULT_CHANNEL, completeFlush, propagation, blocking);} - bool IsolatedFlush(bool hardFlush, bool blocking) - {assert(false); return false;} - bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true) - { - if (hardFlush && !InputBufferIsEmpty()) - throw CannotFlush("Unflushable: this object has buffered input that cannot be flushed"); - else - { - BufferedTransformation *attached = this->AttachedTransformation(); - return attached && propagation ? attached->ChannelFlush(channel, hardFlush, propagation-1, blocking) : false; - } - } - -protected: - virtual bool InputBufferIsEmpty() const {return false;} -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE InputRejecting : public T -{ -public: - struct InputRejected : public NotImplemented - {InputRejected() : NotImplemented("BufferedTransformation: this object doesn't allow input") {}}; - - // shouldn't be calling these functions on this class - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking) - {throw InputRejected();} - bool IsolatedFlush(bool, bool) {return false;} - bool IsolatedMessageSeriesEnd(bool) {throw InputRejected();} - - size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking) - {throw InputRejected();} - bool ChannelMessageSeriesEnd(const std::string &, int, bool) {throw InputRejected();} -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE CustomFlushPropagation : public T -{ -public: - virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true) =0; - -private: - bool IsolatedFlush(bool hardFlush, bool blocking) {assert(false); return false;} -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE CustomSignalPropagation : public CustomFlushPropagation -{ -public: - virtual void Initialize(const NameValuePairs ¶meters=g_nullNameValuePairs, int propagation=-1) =0; - -private: - void IsolatedInitialize(const NameValuePairs ¶meters) {assert(false);} -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE Multichannel : public CustomFlushPropagation -{ -public: - bool Flush(bool hardFlush, int propagation=-1, bool blocking=true) - {return this->ChannelFlush(DEFAULT_CHANNEL, hardFlush, propagation, blocking);} - bool MessageSeriesEnd(int propagation=-1, bool blocking=true) - {return this->ChannelMessageSeriesEnd(DEFAULT_CHANNEL, propagation, blocking);} - byte * CreatePutSpace(size_t &size) - {return this->ChannelCreatePutSpace(DEFAULT_CHANNEL, size);} - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking) - {return this->ChannelPut2(DEFAULT_CHANNEL, begin, length, messageEnd, blocking);} - size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking) - {return this->ChannelPutModifiable2(DEFAULT_CHANNEL, inString, length, messageEnd, blocking);} - -// void ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1) -// {PropagateMessageSeriesEnd(propagation, channel);} - byte * ChannelCreatePutSpace(const std::string &channel, size_t &size) - {size = 0; return NULL;} - bool ChannelPutModifiable(const std::string &channel, byte *inString, size_t length) - {this->ChannelPut(channel, inString, length); return false;} - - virtual size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking) =0; - size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking) - {return ChannelPut2(channel, begin, length, messageEnd, blocking);} - - virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true) =0; -}; - -//! _ -template -class CRYPTOPP_NO_VTABLE AutoSignaling : public T -{ -public: - AutoSignaling(int propagation=-1) : m_autoSignalPropagation(propagation) {} - - void SetAutoSignalPropagation(int propagation) - {m_autoSignalPropagation = propagation;} - int GetAutoSignalPropagation() const - {return m_autoSignalPropagation;} - -private: - int m_autoSignalPropagation; -}; - -//! A BufferedTransformation that only contains pre-existing data as "output" -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Store : public AutoSignaling > -{ -public: - Store() : m_messageEnd(false) {} - - void IsolatedInitialize(const NameValuePairs ¶meters) - { - m_messageEnd = false; - StoreInitialize(parameters); - } - - unsigned int NumberOfMessages() const {return m_messageEnd ? 0 : 1;} - bool GetNextMessage(); - unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const; - -protected: - virtual void StoreInitialize(const NameValuePairs ¶meters) =0; - - bool m_messageEnd; -}; - -//! A BufferedTransformation that doesn't produce any retrievable output -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Sink : public BufferedTransformation -{ -public: - size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) - {transferBytes = 0; return 0;} - size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const - {return 0;} -}; - -class CRYPTOPP_DLL BitBucket : public Bufferless -{ -public: - std::string AlgorithmName() const {return "BitBucket";} - void IsolatedInitialize(const NameValuePairs ¶meters) {} - size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking) - {return 0;} -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/smartptr.h b/lib/cryptopp/smartptr.h deleted file mode 100644 index a0a727edc..000000000 --- a/lib/cryptopp/smartptr.h +++ /dev/null @@ -1,223 +0,0 @@ -#ifndef CRYPTOPP_SMARTPTR_H -#define CRYPTOPP_SMARTPTR_H - -#include "config.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -template class simple_ptr -{ -public: - simple_ptr(T *p = NULL) : m_p(p) {} - ~simple_ptr() {delete m_p; m_p = NULL;} // set m_p to NULL so double destruction (which might occur in Singleton) will be harmless - T *m_p; -}; - -template class member_ptr -{ -public: - explicit member_ptr(T *p = NULL) : m_p(p) {} - - ~member_ptr(); - - const T& operator*() const { return *m_p; } - T& operator*() { return *m_p; } - - const T* operator->() const { return m_p; } - T* operator->() { return m_p; } - - const T* get() const { return m_p; } - T* get() { return m_p; } - - T* release() - { - T *old_p = m_p; - m_p = 0; - return old_p; - } - - void reset(T *p = 0); - -protected: - member_ptr(const member_ptr& rhs); // copy not allowed - void operator=(const member_ptr& rhs); // assignment not allowed - - T *m_p; -}; - -template member_ptr::~member_ptr() {delete m_p;} -template void member_ptr::reset(T *p) {delete m_p; m_p = p;} - -// ******************************************************** - -template class value_ptr : public member_ptr -{ -public: - value_ptr(const T &obj) : member_ptr(new T(obj)) {} - value_ptr(T *p = NULL) : member_ptr(p) {} - value_ptr(const value_ptr& rhs) - : member_ptr(rhs.m_p ? new T(*rhs.m_p) : NULL) {} - - value_ptr& operator=(const value_ptr& rhs); - bool operator==(const value_ptr& rhs) - { - return (!this->m_p && !rhs.m_p) || (this->m_p && rhs.m_p && *this->m_p == *rhs.m_p); - } -}; - -template value_ptr& value_ptr::operator=(const value_ptr& rhs) -{ - T *old_p = this->m_p; - this->m_p = rhs.m_p ? new T(*rhs.m_p) : NULL; - delete old_p; - return *this; -} - -// ******************************************************** - -template class clonable_ptr : public member_ptr -{ -public: - clonable_ptr(const T &obj) : member_ptr(obj.Clone()) {} - clonable_ptr(T *p = NULL) : member_ptr(p) {} - clonable_ptr(const clonable_ptr& rhs) - : member_ptr(rhs.m_p ? rhs.m_p->Clone() : NULL) {} - - clonable_ptr& operator=(const clonable_ptr& rhs); -}; - -template clonable_ptr& clonable_ptr::operator=(const clonable_ptr& rhs) -{ - T *old_p = this->m_p; - this->m_p = rhs.m_p ? rhs.m_p->Clone() : NULL; - delete old_p; - return *this; -} - -// ******************************************************** - -template class counted_ptr -{ -public: - explicit counted_ptr(T *p = 0); - counted_ptr(const T &r) : m_p(0) {attach(r);} - counted_ptr(const counted_ptr& rhs); - - ~counted_ptr(); - - const T& operator*() const { return *m_p; } - T& operator*() { return *m_p; } - - const T* operator->() const { return m_p; } - T* operator->() { return get(); } - - const T* get() const { return m_p; } - T* get(); - - void attach(const T &p); - - counted_ptr & operator=(const counted_ptr& rhs); - -private: - T *m_p; -}; - -template counted_ptr::counted_ptr(T *p) - : m_p(p) -{ - if (m_p) - m_p->m_referenceCount = 1; -} - -template counted_ptr::counted_ptr(const counted_ptr& rhs) - : m_p(rhs.m_p) -{ - if (m_p) - m_p->m_referenceCount++; -} - -template counted_ptr::~counted_ptr() -{ - if (m_p && --m_p->m_referenceCount == 0) - delete m_p; -} - -template void counted_ptr::attach(const T &r) -{ - if (m_p && --m_p->m_referenceCount == 0) - delete m_p; - if (r.m_referenceCount == 0) - { - m_p = r.clone(); - m_p->m_referenceCount = 1; - } - else - { - m_p = const_cast(&r); - m_p->m_referenceCount++; - } -} - -template T* counted_ptr::get() -{ - if (m_p && m_p->m_referenceCount > 1) - { - T *temp = m_p->clone(); - m_p->m_referenceCount--; - m_p = temp; - m_p->m_referenceCount = 1; - } - return m_p; -} - -template counted_ptr & counted_ptr::operator=(const counted_ptr& rhs) -{ - if (m_p != rhs.m_p) - { - if (m_p && --m_p->m_referenceCount == 0) - delete m_p; - m_p = rhs.m_p; - if (m_p) - m_p->m_referenceCount++; - } - return *this; -} - -// ******************************************************** - -template class vector_member_ptrs -{ -public: - vector_member_ptrs(size_t size=0) - : m_size(size), m_ptr(new member_ptr[size]) {} - ~vector_member_ptrs() - {delete [] this->m_ptr;} - - member_ptr& operator[](size_t index) - {assert(indexm_size); return this->m_ptr[index];} - const member_ptr& operator[](size_t index) const - {assert(indexm_size); return this->m_ptr[index];} - - size_t size() const {return this->m_size;} - void resize(size_t newSize) - { - member_ptr *newPtr = new member_ptr[newSize]; - for (size_t i=0; im_size && im_ptr[i].release()); - delete [] this->m_ptr; - this->m_size = newSize; - this->m_ptr = newPtr; - } - -private: - vector_member_ptrs(const vector_member_ptrs &c); // copy not allowed - void operator=(const vector_member_ptrs &x); // assignment not allowed - - size_t m_size; - member_ptr *m_ptr; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/socketft.cpp b/lib/cryptopp/socketft.cpp deleted file mode 100644 index 6c5a8ff9d..000000000 --- a/lib/cryptopp/socketft.cpp +++ /dev/null @@ -1,531 +0,0 @@ -// socketft.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "socketft.h" - -#ifdef SOCKETS_AVAILABLE - -#include "wait.h" - -#ifdef USE_BERKELEY_STYLE_SOCKETS -#include -#include -#include -#include -#include -#include -#endif - -NAMESPACE_BEGIN(CryptoPP) - -#ifdef USE_WINDOWS_STYLE_SOCKETS -const int SOCKET_EINVAL = WSAEINVAL; -const int SOCKET_EWOULDBLOCK = WSAEWOULDBLOCK; -typedef int socklen_t; -#else -const int SOCKET_EINVAL = EINVAL; -const int SOCKET_EWOULDBLOCK = EWOULDBLOCK; -#endif - -Socket::Err::Err(socket_t s, const std::string& operation, int error) - : OS_Error(IO_ERROR, "Socket: " + operation + " operation failed with error " + IntToString(error), operation, error) - , m_s(s) -{ -} - -Socket::~Socket() -{ - if (m_own) - { - try - { - CloseSocket(); - } - catch (...) - { - } - } -} - -void Socket::AttachSocket(socket_t s, bool own) -{ - if (m_own) - CloseSocket(); - - m_s = s; - m_own = own; - SocketChanged(); -} - -socket_t Socket::DetachSocket() -{ - socket_t s = m_s; - m_s = INVALID_SOCKET; - SocketChanged(); - return s; -} - -void Socket::Create(int nType) -{ - assert(m_s == INVALID_SOCKET); - m_s = socket(AF_INET, nType, 0); - CheckAndHandleError("socket", m_s); - m_own = true; - SocketChanged(); -} - -void Socket::CloseSocket() -{ - if (m_s != INVALID_SOCKET) - { -#ifdef USE_WINDOWS_STYLE_SOCKETS - CancelIo((HANDLE) m_s); - CheckAndHandleError_int("closesocket", closesocket(m_s)); -#else - CheckAndHandleError_int("close", close(m_s)); -#endif - m_s = INVALID_SOCKET; - SocketChanged(); - } -} - -void Socket::Bind(unsigned int port, const char *addr) -{ - sockaddr_in sa; - memset(&sa, 0, sizeof(sa)); - sa.sin_family = AF_INET; - - if (addr == NULL) - sa.sin_addr.s_addr = htonl(INADDR_ANY); - else - { - unsigned long result = inet_addr(addr); - if (result == -1) // Solaris doesn't have INADDR_NONE - { - SetLastError(SOCKET_EINVAL); - CheckAndHandleError_int("inet_addr", SOCKET_ERROR); - } - sa.sin_addr.s_addr = result; - } - - sa.sin_port = htons((u_short)port); - - Bind((sockaddr *)&sa, sizeof(sa)); -} - -void Socket::Bind(const sockaddr *psa, socklen_t saLen) -{ - assert(m_s != INVALID_SOCKET); - // cygwin workaround: needs const_cast - CheckAndHandleError_int("bind", bind(m_s, const_cast(psa), saLen)); -} - -void Socket::Listen(int backlog) -{ - assert(m_s != INVALID_SOCKET); - CheckAndHandleError_int("listen", listen(m_s, backlog)); -} - -bool Socket::Connect(const char *addr, unsigned int port) -{ - assert(addr != NULL); - - sockaddr_in sa; - memset(&sa, 0, sizeof(sa)); - sa.sin_family = AF_INET; - sa.sin_addr.s_addr = inet_addr(addr); - - if (sa.sin_addr.s_addr == -1) // Solaris doesn't have INADDR_NONE - { - hostent *lphost = gethostbyname(addr); - if (lphost == NULL) - { - SetLastError(SOCKET_EINVAL); - CheckAndHandleError_int("gethostbyname", SOCKET_ERROR); - } - - sa.sin_addr.s_addr = ((in_addr *)lphost->h_addr)->s_addr; - } - - sa.sin_port = htons((u_short)port); - - return Connect((const sockaddr *)&sa, sizeof(sa)); -} - -bool Socket::Connect(const sockaddr* psa, socklen_t saLen) -{ - assert(m_s != INVALID_SOCKET); - int result = connect(m_s, const_cast(psa), saLen); - if (result == SOCKET_ERROR && GetLastError() == SOCKET_EWOULDBLOCK) - return false; - CheckAndHandleError_int("connect", result); - return true; -} - -bool Socket::Accept(Socket& target, sockaddr *psa, socklen_t *psaLen) -{ - assert(m_s != INVALID_SOCKET); - socket_t s = accept(m_s, psa, psaLen); - if (s == INVALID_SOCKET && GetLastError() == SOCKET_EWOULDBLOCK) - return false; - CheckAndHandleError("accept", s); - target.AttachSocket(s, true); - return true; -} - -void Socket::GetSockName(sockaddr *psa, socklen_t *psaLen) -{ - assert(m_s != INVALID_SOCKET); - CheckAndHandleError_int("getsockname", getsockname(m_s, psa, psaLen)); -} - -void Socket::GetPeerName(sockaddr *psa, socklen_t *psaLen) -{ - assert(m_s != INVALID_SOCKET); - CheckAndHandleError_int("getpeername", getpeername(m_s, psa, psaLen)); -} - -unsigned int Socket::Send(const byte* buf, size_t bufLen, int flags) -{ - assert(m_s != INVALID_SOCKET); - int result = send(m_s, (const char *)buf, UnsignedMin(INT_MAX, bufLen), flags); - CheckAndHandleError_int("send", result); - return result; -} - -unsigned int Socket::Receive(byte* buf, size_t bufLen, int flags) -{ - assert(m_s != INVALID_SOCKET); - int result = recv(m_s, (char *)buf, UnsignedMin(INT_MAX, bufLen), flags); - CheckAndHandleError_int("recv", result); - return result; -} - -void Socket::ShutDown(int how) -{ - assert(m_s != INVALID_SOCKET); - int result = shutdown(m_s, how); - CheckAndHandleError_int("shutdown", result); -} - -void Socket::IOCtl(long cmd, unsigned long *argp) -{ - assert(m_s != INVALID_SOCKET); -#ifdef USE_WINDOWS_STYLE_SOCKETS - CheckAndHandleError_int("ioctlsocket", ioctlsocket(m_s, cmd, argp)); -#else - CheckAndHandleError_int("ioctl", ioctl(m_s, cmd, argp)); -#endif -} - -bool Socket::SendReady(const timeval *timeout) -{ - fd_set fds; - FD_ZERO(&fds); - FD_SET(m_s, &fds); - int ready; - if (timeout == NULL) - ready = select((int)m_s+1, NULL, &fds, NULL, NULL); - else - { - timeval timeoutCopy = *timeout; // select() modified timeout on Linux - ready = select((int)m_s+1, NULL, &fds, NULL, &timeoutCopy); - } - CheckAndHandleError_int("select", ready); - return ready > 0; -} - -bool Socket::ReceiveReady(const timeval *timeout) -{ - fd_set fds; - FD_ZERO(&fds); - FD_SET(m_s, &fds); - int ready; - if (timeout == NULL) - ready = select((int)m_s+1, &fds, NULL, NULL, NULL); - else - { - timeval timeoutCopy = *timeout; // select() modified timeout on Linux - ready = select((int)m_s+1, &fds, NULL, NULL, &timeoutCopy); - } - CheckAndHandleError_int("select", ready); - return ready > 0; -} - -unsigned int Socket::PortNameToNumber(const char *name, const char *protocol) -{ - int port = atoi(name); - if (IntToString(port) == name) - return port; - - servent *se = getservbyname(name, protocol); - if (!se) - throw Err(INVALID_SOCKET, "getservbyname", SOCKET_EINVAL); - return ntohs(se->s_port); -} - -void Socket::StartSockets() -{ -#ifdef USE_WINDOWS_STYLE_SOCKETS - WSADATA wsd; - int result = WSAStartup(0x0202, &wsd); - if (result != 0) - throw Err(INVALID_SOCKET, "WSAStartup", result); -#endif -} - -void Socket::ShutdownSockets() -{ -#ifdef USE_WINDOWS_STYLE_SOCKETS - int result = WSACleanup(); - if (result != 0) - throw Err(INVALID_SOCKET, "WSACleanup", result); -#endif -} - -int Socket::GetLastError() -{ -#ifdef USE_WINDOWS_STYLE_SOCKETS - return WSAGetLastError(); -#else - return errno; -#endif -} - -void Socket::SetLastError(int errorCode) -{ -#ifdef USE_WINDOWS_STYLE_SOCKETS - WSASetLastError(errorCode); -#else - errno = errorCode; -#endif -} - -void Socket::HandleError(const char *operation) const -{ - int err = GetLastError(); - throw Err(m_s, operation, err); -} - -#ifdef USE_WINDOWS_STYLE_SOCKETS - -SocketReceiver::SocketReceiver(Socket &s) - : m_s(s), m_resultPending(false), m_eofReceived(false) -{ - m_event.AttachHandle(CreateEvent(NULL, true, false, NULL), true); - m_s.CheckAndHandleError("CreateEvent", m_event.HandleValid()); - memset(&m_overlapped, 0, sizeof(m_overlapped)); - m_overlapped.hEvent = m_event; -} - -SocketReceiver::~SocketReceiver() -{ -#ifdef USE_WINDOWS_STYLE_SOCKETS - CancelIo((HANDLE) m_s.GetSocket()); -#endif -} - -bool SocketReceiver::Receive(byte* buf, size_t bufLen) -{ - assert(!m_resultPending && !m_eofReceived); - - DWORD flags = 0; - // don't queue too much at once, or we might use up non-paged memory - WSABUF wsabuf = {UnsignedMin((u_long)128*1024, bufLen), (char *)buf}; - if (WSARecv(m_s, &wsabuf, 1, &m_lastResult, &flags, &m_overlapped, NULL) == 0) - { - if (m_lastResult == 0) - m_eofReceived = true; - } - else - { - switch (WSAGetLastError()) - { - default: - m_s.CheckAndHandleError_int("WSARecv", SOCKET_ERROR); - case WSAEDISCON: - m_lastResult = 0; - m_eofReceived = true; - break; - case WSA_IO_PENDING: - m_resultPending = true; - } - } - return !m_resultPending; -} - -void SocketReceiver::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) -{ - if (m_resultPending) - container.AddHandle(m_event, CallStack("SocketReceiver::GetWaitObjects() - result pending", &callStack)); - else if (!m_eofReceived) - container.SetNoWait(CallStack("SocketReceiver::GetWaitObjects() - result ready", &callStack)); -} - -unsigned int SocketReceiver::GetReceiveResult() -{ - if (m_resultPending) - { - DWORD flags = 0; - if (WSAGetOverlappedResult(m_s, &m_overlapped, &m_lastResult, false, &flags)) - { - if (m_lastResult == 0) - m_eofReceived = true; - } - else - { - switch (WSAGetLastError()) - { - default: - m_s.CheckAndHandleError("WSAGetOverlappedResult", FALSE); - case WSAEDISCON: - m_lastResult = 0; - m_eofReceived = true; - } - } - m_resultPending = false; - } - return m_lastResult; -} - -// ************************************************************* - -SocketSender::SocketSender(Socket &s) - : m_s(s), m_resultPending(false), m_lastResult(0) -{ - m_event.AttachHandle(CreateEvent(NULL, true, false, NULL), true); - m_s.CheckAndHandleError("CreateEvent", m_event.HandleValid()); - memset(&m_overlapped, 0, sizeof(m_overlapped)); - m_overlapped.hEvent = m_event; -} - - -SocketSender::~SocketSender() -{ -#ifdef USE_WINDOWS_STYLE_SOCKETS - CancelIo((HANDLE) m_s.GetSocket()); -#endif -} - -void SocketSender::Send(const byte* buf, size_t bufLen) -{ - assert(!m_resultPending); - DWORD written = 0; - // don't queue too much at once, or we might use up non-paged memory - WSABUF wsabuf = {UnsignedMin((u_long)128*1024, bufLen), (char *)buf}; - if (WSASend(m_s, &wsabuf, 1, &written, 0, &m_overlapped, NULL) == 0) - { - m_resultPending = false; - m_lastResult = written; - } - else - { - if (WSAGetLastError() != WSA_IO_PENDING) - m_s.CheckAndHandleError_int("WSASend", SOCKET_ERROR); - - m_resultPending = true; - } -} - -void SocketSender::SendEof() -{ - assert(!m_resultPending); - m_s.ShutDown(SD_SEND); - m_s.CheckAndHandleError("ResetEvent", ResetEvent(m_event)); - m_s.CheckAndHandleError_int("WSAEventSelect", WSAEventSelect(m_s, m_event, FD_CLOSE)); - m_resultPending = true; -} - -bool SocketSender::EofSent() -{ - if (m_resultPending) - { - WSANETWORKEVENTS events; - m_s.CheckAndHandleError_int("WSAEnumNetworkEvents", WSAEnumNetworkEvents(m_s, m_event, &events)); - if ((events.lNetworkEvents & FD_CLOSE) != FD_CLOSE) - throw Socket::Err(m_s, "WSAEnumNetworkEvents (FD_CLOSE not present)", E_FAIL); - if (events.iErrorCode[FD_CLOSE_BIT] != 0) - throw Socket::Err(m_s, "FD_CLOSE (via WSAEnumNetworkEvents)", events.iErrorCode[FD_CLOSE_BIT]); - m_resultPending = false; - } - return m_lastResult != 0; -} - -void SocketSender::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) -{ - if (m_resultPending) - container.AddHandle(m_event, CallStack("SocketSender::GetWaitObjects() - result pending", &callStack)); - else - container.SetNoWait(CallStack("SocketSender::GetWaitObjects() - result ready", &callStack)); -} - -unsigned int SocketSender::GetSendResult() -{ - if (m_resultPending) - { - DWORD flags = 0; - BOOL result = WSAGetOverlappedResult(m_s, &m_overlapped, &m_lastResult, false, &flags); - m_s.CheckAndHandleError("WSAGetOverlappedResult", result); - m_resultPending = false; - } - return m_lastResult; -} - -#endif - -#ifdef USE_BERKELEY_STYLE_SOCKETS - -SocketReceiver::SocketReceiver(Socket &s) - : m_s(s), m_lastResult(0), m_eofReceived(false) -{ -} - -void SocketReceiver::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) -{ - if (!m_eofReceived) - container.AddReadFd(m_s, CallStack("SocketReceiver::GetWaitObjects()", &callStack)); -} - -bool SocketReceiver::Receive(byte* buf, size_t bufLen) -{ - m_lastResult = m_s.Receive(buf, bufLen); - if (bufLen > 0 && m_lastResult == 0) - m_eofReceived = true; - return true; -} - -unsigned int SocketReceiver::GetReceiveResult() -{ - return m_lastResult; -} - -SocketSender::SocketSender(Socket &s) - : m_s(s), m_lastResult(0) -{ -} - -void SocketSender::Send(const byte* buf, size_t bufLen) -{ - m_lastResult = m_s.Send(buf, bufLen); -} - -void SocketSender::SendEof() -{ - m_s.ShutDown(SD_SEND); -} - -unsigned int SocketSender::GetSendResult() -{ - return m_lastResult; -} - -void SocketSender::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) -{ - container.AddWriteFd(m_s, CallStack("SocketSender::GetWaitObjects()", &callStack)); -} - -#endif - -NAMESPACE_END - -#endif // #ifdef SOCKETS_AVAILABLE diff --git a/lib/cryptopp/socketft.h b/lib/cryptopp/socketft.h deleted file mode 100644 index e414aa68f..000000000 --- a/lib/cryptopp/socketft.h +++ /dev/null @@ -1,224 +0,0 @@ -#ifndef CRYPTOPP_SOCKETFT_H -#define CRYPTOPP_SOCKETFT_H - -#include "config.h" - -#ifdef SOCKETS_AVAILABLE - -#include "network.h" -#include "queue.h" - -#ifdef USE_WINDOWS_STYLE_SOCKETS -# if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_) -# error Winsock 1 is not supported by this library. Please include this file or winsock2.h before windows.h. -# endif -#include -#include "winpipes.h" -#else -#include -#include -#include -#include -#endif - -NAMESPACE_BEGIN(CryptoPP) - -#ifdef USE_WINDOWS_STYLE_SOCKETS -typedef ::SOCKET socket_t; -#else -typedef int socket_t; -const socket_t INVALID_SOCKET = -1; -// cygwin 1.1.4 doesn't have SHUT_RD -const int SD_RECEIVE = 0; -const int SD_SEND = 1; -const int SD_BOTH = 2; -const int SOCKET_ERROR = -1; -#endif - -#ifndef socklen_t -typedef TYPE_OF_SOCKLEN_T socklen_t; // see config.h -#endif - -//! wrapper for Windows or Berkeley Sockets -class Socket -{ -public: - //! exception thrown by Socket class - class Err : public OS_Error - { - public: - Err(socket_t s, const std::string& operation, int error); - socket_t GetSocket() const {return m_s;} - - private: - socket_t m_s; - }; - - Socket(socket_t s = INVALID_SOCKET, bool own=false) : m_s(s), m_own(own) {} - Socket(const Socket &s) : m_s(s.m_s), m_own(false) {} - virtual ~Socket(); - - bool GetOwnership() const {return m_own;} - void SetOwnership(bool own) {m_own = own;} - - operator socket_t() {return m_s;} - socket_t GetSocket() const {return m_s;} - void AttachSocket(socket_t s, bool own=false); - socket_t DetachSocket(); - void CloseSocket(); - - void Create(int nType = SOCK_STREAM); - void Bind(unsigned int port, const char *addr=NULL); - void Bind(const sockaddr* psa, socklen_t saLen); - void Listen(int backlog=5); - // the next three functions return false if the socket is in nonblocking mode - // and the operation cannot be completed immediately - bool Connect(const char *addr, unsigned int port); - bool Connect(const sockaddr* psa, socklen_t saLen); - bool Accept(Socket& s, sockaddr *psa=NULL, socklen_t *psaLen=NULL); - void GetSockName(sockaddr *psa, socklen_t *psaLen); - void GetPeerName(sockaddr *psa, socklen_t *psaLen); - unsigned int Send(const byte* buf, size_t bufLen, int flags=0); - unsigned int Receive(byte* buf, size_t bufLen, int flags=0); - void ShutDown(int how = SD_SEND); - - void IOCtl(long cmd, unsigned long *argp); - bool SendReady(const timeval *timeout); - bool ReceiveReady(const timeval *timeout); - - virtual void HandleError(const char *operation) const; - void CheckAndHandleError_int(const char *operation, int result) const - {if (result == SOCKET_ERROR) HandleError(operation);} - void CheckAndHandleError(const char *operation, socket_t result) const - {if (result == SOCKET_ERROR) HandleError(operation);} -#ifdef USE_WINDOWS_STYLE_SOCKETS - void CheckAndHandleError(const char *operation, BOOL result) const - {assert(result==TRUE || result==FALSE); if (!result) HandleError(operation);} - void CheckAndHandleError(const char *operation, bool result) const - {if (!result) HandleError(operation);} -#endif - - //! look up the port number given its name, returns 0 if not found - static unsigned int PortNameToNumber(const char *name, const char *protocol="tcp"); - //! start Windows Sockets 2 - static void StartSockets(); - //! calls WSACleanup for Windows Sockets - static void ShutdownSockets(); - //! returns errno or WSAGetLastError - static int GetLastError(); - //! sets errno or calls WSASetLastError - static void SetLastError(int errorCode); - -protected: - virtual void SocketChanged() {} - - socket_t m_s; - bool m_own; -}; - -class SocketsInitializer -{ -public: - SocketsInitializer() {Socket::StartSockets();} - ~SocketsInitializer() {try {Socket::ShutdownSockets();} catch (...) {}} -}; - -class SocketReceiver : public NetworkReceiver -{ -public: - SocketReceiver(Socket &s); - -#ifdef USE_BERKELEY_STYLE_SOCKETS - bool MustWaitToReceive() {return true;} -#else - ~SocketReceiver(); - bool MustWaitForResult() {return true;} -#endif - bool Receive(byte* buf, size_t bufLen); - unsigned int GetReceiveResult(); - bool EofReceived() const {return m_eofReceived;} - - unsigned int GetMaxWaitObjectCount() const {return 1;} - void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack); - -private: - Socket &m_s; - bool m_eofReceived; - -#ifdef USE_WINDOWS_STYLE_SOCKETS - WindowsHandle m_event; - OVERLAPPED m_overlapped; - bool m_resultPending; - DWORD m_lastResult; -#else - unsigned int m_lastResult; -#endif -}; - -class SocketSender : public NetworkSender -{ -public: - SocketSender(Socket &s); - -#ifdef USE_BERKELEY_STYLE_SOCKETS - bool MustWaitToSend() {return true;} -#else - ~SocketSender(); - bool MustWaitForResult() {return true;} - bool MustWaitForEof() { return true; } - bool EofSent(); -#endif - void Send(const byte* buf, size_t bufLen); - unsigned int GetSendResult(); - void SendEof(); - - unsigned int GetMaxWaitObjectCount() const {return 1;} - void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack); - -private: - Socket &m_s; -#ifdef USE_WINDOWS_STYLE_SOCKETS - WindowsHandle m_event; - OVERLAPPED m_overlapped; - bool m_resultPending; - DWORD m_lastResult; -#else - unsigned int m_lastResult; -#endif -}; - -//! socket-based implementation of NetworkSource -class SocketSource : public NetworkSource, public Socket -{ -public: - SocketSource(socket_t s = INVALID_SOCKET, bool pumpAll = false, BufferedTransformation *attachment = NULL) - : NetworkSource(attachment), Socket(s), m_receiver(*this) - { - if (pumpAll) - PumpAll(); - } - -private: - NetworkReceiver & AccessReceiver() {return m_receiver;} - SocketReceiver m_receiver; -}; - -//! socket-based implementation of NetworkSink -class SocketSink : public NetworkSink, public Socket -{ -public: - SocketSink(socket_t s=INVALID_SOCKET, unsigned int maxBufferSize=0, unsigned int autoFlushBound=16*1024) - : NetworkSink(maxBufferSize, autoFlushBound), Socket(s), m_sender(*this) {} - - void SendEof() {ShutDown(SD_SEND);} - -private: - NetworkSender & AccessSender() {return m_sender;} - SocketSender m_sender; -}; - -NAMESPACE_END - -#endif // #ifdef SOCKETS_AVAILABLE - -#endif diff --git a/lib/cryptopp/square.cpp b/lib/cryptopp/square.cpp deleted file mode 100644 index 00e6bddbe..000000000 --- a/lib/cryptopp/square.cpp +++ /dev/null @@ -1,177 +0,0 @@ -// square.cpp - written and placed in the public domain by Wei Dai -// Based on Paulo S.L.M. Barreto's public domain implementation - -#include "pch.h" -#include "square.h" -#include "misc.h" -#include "gf256.h" - -NAMESPACE_BEGIN(CryptoPP) - -// apply theta to a roundkey -static void SquareTransform (word32 in[4], word32 out[4]) -{ - static const byte G[4][4] = - { - 0x02U, 0x01U, 0x01U, 0x03U, - 0x03U, 0x02U, 0x01U, 0x01U, - 0x01U, 0x03U, 0x02U, 0x01U, - 0x01U, 0x01U, 0x03U, 0x02U - }; - - GF256 gf256(0xf5); - - for (int i = 0; i < 4; i++) - { - word32 temp = 0; - for (int j = 0; j < 4; j++) - for (int k = 0; k < 4; k++) - temp ^= (word32)gf256.Multiply(GETBYTE(in[i], 3-k), G[k][j]) << ((3-j)*8); - out[i] = temp; - } -} - -#define roundkeys(i, j) m_roundkeys[(i)*4+(j)] -#define roundkeys4(i) (m_roundkeys+(i)*4) - -void Square::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &) -{ - AssertValidKeyLength(length); - - static const word32 offset[ROUNDS] = { - 0x01000000UL, 0x02000000UL, 0x04000000UL, 0x08000000UL, - 0x10000000UL, 0x20000000UL, 0x40000000UL, 0x80000000UL, - }; - - GetUserKey(BIG_ENDIAN_ORDER, m_roundkeys.data(), KEYLENGTH/4, userKey, KEYLENGTH); - - /* apply the key evolution function */ - for (int i = 1; i < ROUNDS+1; i++) - { - roundkeys(i, 0) = roundkeys(i-1, 0) ^ rotlFixed(roundkeys(i-1, 3), 8U) ^ offset[i-1]; - roundkeys(i, 1) = roundkeys(i-1, 1) ^ roundkeys(i, 0); - roundkeys(i, 2) = roundkeys(i-1, 2) ^ roundkeys(i, 1); - roundkeys(i, 3) = roundkeys(i-1, 3) ^ roundkeys(i, 2); - } - - /* produce the round keys */ - if (IsForwardTransformation()) - { - for (int i = 0; i < ROUNDS; i++) - SquareTransform (roundkeys4(i), roundkeys4(i)); - } - else - { - for (int i = 0; i < ROUNDS/2; i++) - for (int j = 0; j < 4; j++) - std::swap(roundkeys(i, j), roundkeys(ROUNDS-i, j)); - SquareTransform (roundkeys4(ROUNDS), roundkeys4(ROUNDS)); - } -} - -#define MSB(x) (((x) >> 24) & 0xffU) /* most significant byte */ -#define SSB(x) (((x) >> 16) & 0xffU) /* second in significance */ -#define TSB(x) (((x) >> 8) & 0xffU) /* third in significance */ -#define LSB(x) (((x) ) & 0xffU) /* least significant byte */ - -#define squareRound(text, temp, T0, T1, T2, T3, roundkey) \ -{ \ - temp[0] = T0[MSB (text[0])] \ - ^ T1[MSB (text[1])] \ - ^ T2[MSB (text[2])] \ - ^ T3[MSB (text[3])] \ - ^ roundkey[0]; \ - temp[1] = T0[SSB (text[0])] \ - ^ T1[SSB (text[1])] \ - ^ T2[SSB (text[2])] \ - ^ T3[SSB (text[3])] \ - ^ roundkey[1]; \ - temp[2] = T0[TSB (text[0])] \ - ^ T1[TSB (text[1])] \ - ^ T2[TSB (text[2])] \ - ^ T3[TSB (text[3])] \ - ^ roundkey[2]; \ - temp[3] = T0[LSB (text[0])] \ - ^ T1[LSB (text[1])] \ - ^ T2[LSB (text[2])] \ - ^ T3[LSB (text[3])] \ - ^ roundkey[3]; \ -} /* squareRound */ - -#define squareFinal(text, temp, S, roundkey) \ -{ \ - text[0] = ((word32) (S[MSB (temp[0])]) << 24) \ - ^ ((word32) (S[MSB (temp[1])]) << 16) \ - ^ ((word32) (S[MSB (temp[2])]) << 8) \ - ^ (word32) (S[MSB (temp[3])]) \ - ^ roundkey[0]; \ - text[1] = ((word32) (S[SSB (temp[0])]) << 24) \ - ^ ((word32) (S[SSB (temp[1])]) << 16) \ - ^ ((word32) (S[SSB (temp[2])]) << 8) \ - ^ (word32) (S[SSB (temp[3])]) \ - ^ roundkey[1]; \ - text[2] = ((word32) (S[TSB (temp[0])]) << 24) \ - ^ ((word32) (S[TSB (temp[1])]) << 16) \ - ^ ((word32) (S[TSB (temp[2])]) << 8) \ - ^ (word32) (S[TSB (temp[3])]) \ - ^ roundkey[2]; \ - text[3] = ((word32) (S[LSB (temp[0])]) << 24) \ - ^ ((word32) (S[LSB (temp[1])]) << 16) \ - ^ ((word32) (S[LSB (temp[2])]) << 8) \ - ^ (word32) (S[LSB (temp[3])]) \ - ^ roundkey[3]; \ -} /* squareFinal */ - -typedef BlockGetAndPut Block; - -void Square::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - word32 text[4], temp[4]; - Block::Get(inBlock)(text[0])(text[1])(text[2])(text[3]); - - /* initial key addition */ - text[0] ^= roundkeys(0, 0); - text[1] ^= roundkeys(0, 1); - text[2] ^= roundkeys(0, 2); - text[3] ^= roundkeys(0, 3); - - /* ROUNDS - 1 full rounds */ - for (int i=1; i+1, public FixedKeyLength<16>, FixedRounds<8> -{ - static const char *StaticAlgorithmName() {return "Square";} -}; - -/// Square -class Square : public Square_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl - { - public: - void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); - - protected: - FixedSizeSecBlock m_roundkeys; - }; - - class CRYPTOPP_NO_VTABLE Enc : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - private: - static const byte Se[256]; - static const word32 Te[4][256]; - }; - - class CRYPTOPP_NO_VTABLE Dec : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - private: - static const byte Sd[256]; - static const word32 Td[4][256]; - }; - -public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -typedef Square::Encryption SquareEncryption; -typedef Square::Decryption SquareDecryption; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/squaretb.cpp b/lib/cryptopp/squaretb.cpp deleted file mode 100644 index bc3bee7df..000000000 --- a/lib/cryptopp/squaretb.cpp +++ /dev/null @@ -1,582 +0,0 @@ -#include "pch.h" -#include "square.h" - -NAMESPACE_BEGIN(CryptoPP) - -const byte Square::Enc::Se[256] = { -177, 206, 195, 149, 90, 173, 231, 2, 77, 68, 251, 145, 12, 135, 161, 80, -203, 103, 84, 221, 70, 143, 225, 78, 240, 253, 252, 235, 249, 196, 26, 110, - 94, 245, 204, 141, 28, 86, 67, 254, 7, 97, 248, 117, 89, 255, 3, 34, -138, 209, 19, 238, 136, 0, 14, 52, 21, 128, 148, 227, 237, 181, 83, 35, - 75, 71, 23, 167, 144, 53, 171, 216, 184, 223, 79, 87, 154, 146, 219, 27, - 60, 200, 153, 4, 142, 224, 215, 125, 133, 187, 64, 44, 58, 69, 241, 66, -101, 32, 65, 24, 114, 37, 147, 112, 54, 5, 242, 11, 163, 121, 236, 8, - 39, 49, 50, 182, 124, 176, 10, 115, 91, 123, 183, 129, 210, 13, 106, 38, -158, 88, 156, 131, 116, 179, 172, 48, 122, 105, 119, 15, 174, 33, 222, 208, - 46, 151, 16, 164, 152, 168, 212, 104, 45, 98, 41, 109, 22, 73, 118, 199, -232, 193, 150, 55, 229, 202, 244, 233, 99, 18, 194, 166, 20, 188, 211, 40, -175, 47, 230, 36, 82, 198, 160, 9, 189, 140, 207, 93, 17, 95, 1, 197, -159, 61, 162, 155, 201, 59, 190, 81, 25, 31, 63, 92, 178, 239, 74, 205, -191, 186, 111, 100, 217, 243, 62, 180, 170, 220, 213, 6, 192, 126, 246, 102, -108, 132, 113, 56, 185, 29, 127, 157, 72, 139, 42, 218, 165, 51, 130, 57, -214, 120, 134, 250, 228, 43, 169, 30, 137, 96, 107, 234, 85, 76, 247, 226, -}; - -const byte Square::Dec::Sd[256] = { - 53, 190, 7, 46, 83, 105, 219, 40, 111, 183, 118, 107, 12, 125, 54, 139, -146, 188, 169, 50, 172, 56, 156, 66, 99, 200, 30, 79, 36, 229, 247, 201, - 97, 141, 47, 63, 179, 101, 127, 112, 175, 154, 234, 245, 91, 152, 144, 177, -135, 113, 114, 237, 55, 69, 104, 163, 227, 239, 92, 197, 80, 193, 214, 202, - 90, 98, 95, 38, 9, 93, 20, 65, 232, 157, 206, 64, 253, 8, 23, 74, - 15, 199, 180, 62, 18, 252, 37, 75, 129, 44, 4, 120, 203, 187, 32, 189, -249, 41, 153, 168, 211, 96, 223, 17, 151, 137, 126, 250, 224, 155, 31, 210, -103, 226, 100, 119, 132, 43, 158, 138, 241, 109, 136, 121, 116, 87, 221, 230, - 57, 123, 238, 131, 225, 88, 242, 13, 52, 248, 48, 233, 185, 35, 84, 21, - 68, 11, 77, 102, 58, 3, 162, 145, 148, 82, 76, 195, 130, 231, 128, 192, -182, 14, 194, 108, 147, 236, 171, 67, 149, 246, 216, 70, 134, 5, 140, 176, -117, 0, 204, 133, 215, 61, 115, 122, 72, 228, 209, 89, 173, 184, 198, 208, -220, 161, 170, 2, 29, 191, 181, 159, 81, 196, 165, 16, 34, 207, 1, 186, -143, 49, 124, 174, 150, 218, 240, 86, 71, 212, 235, 78, 217, 19, 142, 73, - 85, 22, 255, 59, 244, 164, 178, 6, 160, 167, 251, 27, 110, 60, 51, 205, - 24, 94, 106, 213, 166, 33, 222, 254, 42, 28, 243, 10, 26, 25, 39, 45, -}; - -const word32 Square::Enc::Te[4][256] = { -{ -0x97b1b126UL, 0x69cecea7UL, 0x73c3c3b0UL, 0xdf95954aUL, -0xb45a5aeeUL, 0xafadad02UL, 0x3be7e7dcUL, 0x04020206UL, -0x9a4d4dd7UL, 0x884444ccUL, 0x03fbfbf8UL, 0xd7919146UL, -0x180c0c14UL, 0xfb87877cUL, 0xb7a1a116UL, 0xa05050f0UL, -0x63cbcba8UL, 0xce6767a9UL, 0xa85454fcUL, 0x4fdddd92UL, -0x8c4646caUL, 0xeb8f8f64UL, 0x37e1e1d6UL, 0x9c4e4ed2UL, -0x15f0f0e5UL, 0x0ffdfdf2UL, 0x0dfcfcf1UL, 0x23ebebc8UL, -0x07f9f9feUL, 0x7dc4c4b9UL, 0x341a1a2eUL, 0xdc6e6eb2UL, -0xbc5e5ee2UL, 0x1ff5f5eaUL, 0x6dcccca1UL, 0xef8d8d62UL, -0x381c1c24UL, 0xac5656faUL, 0x864343c5UL, 0x09fefef7UL, -0x0e070709UL, 0xc26161a3UL, 0x05f8f8fdUL, 0xea75759fUL, -0xb25959ebUL, 0x0bfffff4UL, 0x06030305UL, 0x44222266UL, -0xe18a8a6bUL, 0x57d1d186UL, 0x26131335UL, 0x29eeeec7UL, -0xe588886dUL, 0x00000000UL, 0x1c0e0e12UL, 0x6834345cUL, -0x2a15153fUL, 0xf5808075UL, 0xdd949449UL, 0x33e3e3d0UL, -0x2fededc2UL, 0x9fb5b52aUL, 0xa65353f5UL, 0x46232365UL, -0x964b4bddUL, 0x8e4747c9UL, 0x2e171739UL, 0xbba7a71cUL, -0xd5909045UL, 0x6a35355fUL, 0xa3abab08UL, 0x45d8d89dUL, -0x85b8b83dUL, 0x4bdfdf94UL, 0x9e4f4fd1UL, 0xae5757f9UL, -0xc19a9a5bUL, 0xd1929243UL, 0x43dbdb98UL, 0x361b1b2dUL, -0x783c3c44UL, 0x65c8c8adUL, 0xc799995eUL, 0x0804040cUL, -0xe98e8e67UL, 0x35e0e0d5UL, 0x5bd7d78cUL, 0xfa7d7d87UL, -0xff85857aUL, 0x83bbbb38UL, 0x804040c0UL, 0x582c2c74UL, -0x743a3a4eUL, 0x8a4545cfUL, 0x17f1f1e6UL, 0x844242c6UL, -0xca6565afUL, 0x40202060UL, 0x824141c3UL, 0x30181828UL, -0xe4727296UL, 0x4a25256fUL, 0xd3939340UL, 0xe0707090UL, -0x6c36365aUL, 0x0a05050fUL, 0x11f2f2e3UL, 0x160b0b1dUL, -0xb3a3a310UL, 0xf279798bUL, 0x2dececc1UL, 0x10080818UL, -0x4e272769UL, 0x62313153UL, 0x64323256UL, 0x99b6b62fUL, -0xf87c7c84UL, 0x95b0b025UL, 0x140a0a1eUL, 0xe6737395UL, -0xb65b5bedUL, 0xf67b7b8dUL, 0x9bb7b72cUL, 0xf7818176UL, -0x51d2d283UL, 0x1a0d0d17UL, 0xd46a6abeUL, 0x4c26266aUL, -0xc99e9e57UL, 0xb05858e8UL, 0xcd9c9c51UL, 0xf3838370UL, -0xe874749cUL, 0x93b3b320UL, 0xadacac01UL, 0x60303050UL, -0xf47a7a8eUL, 0xd26969bbUL, 0xee777799UL, 0x1e0f0f11UL, -0xa9aeae07UL, 0x42212163UL, 0x49dede97UL, 0x55d0d085UL, -0x5c2e2e72UL, 0xdb97974cUL, 0x20101030UL, 0xbda4a419UL, -0xc598985dUL, 0xa5a8a80dUL, 0x5dd4d489UL, 0xd06868b8UL, -0x5a2d2d77UL, 0xc46262a6UL, 0x5229297bUL, 0xda6d6db7UL, -0x2c16163aUL, 0x924949dbUL, 0xec76769aUL, 0x7bc7c7bcUL, -0x25e8e8cdUL, 0x77c1c1b6UL, 0xd996964fUL, 0x6e373759UL, -0x3fe5e5daUL, 0x61cacaabUL, 0x1df4f4e9UL, 0x27e9e9ceUL, -0xc66363a5UL, 0x24121236UL, 0x71c2c2b3UL, 0xb9a6a61fUL, -0x2814143cUL, 0x8dbcbc31UL, 0x53d3d380UL, 0x50282878UL, -0xabafaf04UL, 0x5e2f2f71UL, 0x39e6e6dfUL, 0x4824246cUL, -0xa45252f6UL, 0x79c6c6bfUL, 0xb5a0a015UL, 0x1209091bUL, -0x8fbdbd32UL, 0xed8c8c61UL, 0x6bcfcfa4UL, 0xba5d5de7UL, -0x22111133UL, 0xbe5f5fe1UL, 0x02010103UL, 0x7fc5c5baUL, -0xcb9f9f54UL, 0x7a3d3d47UL, 0xb1a2a213UL, 0xc39b9b58UL, -0x67c9c9aeUL, 0x763b3b4dUL, 0x89bebe37UL, 0xa25151f3UL, -0x3219192bUL, 0x3e1f1f21UL, 0x7e3f3f41UL, 0xb85c5ce4UL, -0x91b2b223UL, 0x2befefc4UL, 0x944a4adeUL, 0x6fcdcda2UL, -0x8bbfbf34UL, 0x81baba3bUL, 0xde6f6fb1UL, 0xc86464acUL, -0x47d9d99eUL, 0x13f3f3e0UL, 0x7c3e3e42UL, 0x9db4b429UL, -0xa1aaaa0bUL, 0x4ddcdc91UL, 0x5fd5d58aUL, 0x0c06060aUL, -0x75c0c0b5UL, 0xfc7e7e82UL, 0x19f6f6efUL, 0xcc6666aaUL, -0xd86c6cb4UL, 0xfd848479UL, 0xe2717193UL, 0x70383848UL, -0x87b9b93eUL, 0x3a1d1d27UL, 0xfe7f7f81UL, 0xcf9d9d52UL, -0x904848d8UL, 0xe38b8b68UL, 0x542a2a7eUL, 0x41dada9bUL, -0xbfa5a51aUL, 0x66333355UL, 0xf1828273UL, 0x7239394bUL, -0x59d6d68fUL, 0xf0787888UL, 0xf986867fUL, 0x01fafafbUL, -0x3de4e4d9UL, 0x562b2b7dUL, 0xa7a9a90eUL, 0x3c1e1e22UL, -0xe789896eUL, 0xc06060a0UL, 0xd66b6bbdUL, 0x21eaeacbUL, -0xaa5555ffUL, 0x984c4cd4UL, 0x1bf7f7ecUL, 0x31e2e2d3UL, -}, - -{ -0x2697b1b1UL, 0xa769ceceUL, 0xb073c3c3UL, 0x4adf9595UL, -0xeeb45a5aUL, 0x02afadadUL, 0xdc3be7e7UL, 0x06040202UL, -0xd79a4d4dUL, 0xcc884444UL, 0xf803fbfbUL, 0x46d79191UL, -0x14180c0cUL, 0x7cfb8787UL, 0x16b7a1a1UL, 0xf0a05050UL, -0xa863cbcbUL, 0xa9ce6767UL, 0xfca85454UL, 0x924fddddUL, -0xca8c4646UL, 0x64eb8f8fUL, 0xd637e1e1UL, 0xd29c4e4eUL, -0xe515f0f0UL, 0xf20ffdfdUL, 0xf10dfcfcUL, 0xc823ebebUL, -0xfe07f9f9UL, 0xb97dc4c4UL, 0x2e341a1aUL, 0xb2dc6e6eUL, -0xe2bc5e5eUL, 0xea1ff5f5UL, 0xa16dccccUL, 0x62ef8d8dUL, -0x24381c1cUL, 0xfaac5656UL, 0xc5864343UL, 0xf709fefeUL, -0x090e0707UL, 0xa3c26161UL, 0xfd05f8f8UL, 0x9fea7575UL, -0xebb25959UL, 0xf40bffffUL, 0x05060303UL, 0x66442222UL, -0x6be18a8aUL, 0x8657d1d1UL, 0x35261313UL, 0xc729eeeeUL, -0x6de58888UL, 0x00000000UL, 0x121c0e0eUL, 0x5c683434UL, -0x3f2a1515UL, 0x75f58080UL, 0x49dd9494UL, 0xd033e3e3UL, -0xc22fededUL, 0x2a9fb5b5UL, 0xf5a65353UL, 0x65462323UL, -0xdd964b4bUL, 0xc98e4747UL, 0x392e1717UL, 0x1cbba7a7UL, -0x45d59090UL, 0x5f6a3535UL, 0x08a3ababUL, 0x9d45d8d8UL, -0x3d85b8b8UL, 0x944bdfdfUL, 0xd19e4f4fUL, 0xf9ae5757UL, -0x5bc19a9aUL, 0x43d19292UL, 0x9843dbdbUL, 0x2d361b1bUL, -0x44783c3cUL, 0xad65c8c8UL, 0x5ec79999UL, 0x0c080404UL, -0x67e98e8eUL, 0xd535e0e0UL, 0x8c5bd7d7UL, 0x87fa7d7dUL, -0x7aff8585UL, 0x3883bbbbUL, 0xc0804040UL, 0x74582c2cUL, -0x4e743a3aUL, 0xcf8a4545UL, 0xe617f1f1UL, 0xc6844242UL, -0xafca6565UL, 0x60402020UL, 0xc3824141UL, 0x28301818UL, -0x96e47272UL, 0x6f4a2525UL, 0x40d39393UL, 0x90e07070UL, -0x5a6c3636UL, 0x0f0a0505UL, 0xe311f2f2UL, 0x1d160b0bUL, -0x10b3a3a3UL, 0x8bf27979UL, 0xc12dececUL, 0x18100808UL, -0x694e2727UL, 0x53623131UL, 0x56643232UL, 0x2f99b6b6UL, -0x84f87c7cUL, 0x2595b0b0UL, 0x1e140a0aUL, 0x95e67373UL, -0xedb65b5bUL, 0x8df67b7bUL, 0x2c9bb7b7UL, 0x76f78181UL, -0x8351d2d2UL, 0x171a0d0dUL, 0xbed46a6aUL, 0x6a4c2626UL, -0x57c99e9eUL, 0xe8b05858UL, 0x51cd9c9cUL, 0x70f38383UL, -0x9ce87474UL, 0x2093b3b3UL, 0x01adacacUL, 0x50603030UL, -0x8ef47a7aUL, 0xbbd26969UL, 0x99ee7777UL, 0x111e0f0fUL, -0x07a9aeaeUL, 0x63422121UL, 0x9749dedeUL, 0x8555d0d0UL, -0x725c2e2eUL, 0x4cdb9797UL, 0x30201010UL, 0x19bda4a4UL, -0x5dc59898UL, 0x0da5a8a8UL, 0x895dd4d4UL, 0xb8d06868UL, -0x775a2d2dUL, 0xa6c46262UL, 0x7b522929UL, 0xb7da6d6dUL, -0x3a2c1616UL, 0xdb924949UL, 0x9aec7676UL, 0xbc7bc7c7UL, -0xcd25e8e8UL, 0xb677c1c1UL, 0x4fd99696UL, 0x596e3737UL, -0xda3fe5e5UL, 0xab61cacaUL, 0xe91df4f4UL, 0xce27e9e9UL, -0xa5c66363UL, 0x36241212UL, 0xb371c2c2UL, 0x1fb9a6a6UL, -0x3c281414UL, 0x318dbcbcUL, 0x8053d3d3UL, 0x78502828UL, -0x04abafafUL, 0x715e2f2fUL, 0xdf39e6e6UL, 0x6c482424UL, -0xf6a45252UL, 0xbf79c6c6UL, 0x15b5a0a0UL, 0x1b120909UL, -0x328fbdbdUL, 0x61ed8c8cUL, 0xa46bcfcfUL, 0xe7ba5d5dUL, -0x33221111UL, 0xe1be5f5fUL, 0x03020101UL, 0xba7fc5c5UL, -0x54cb9f9fUL, 0x477a3d3dUL, 0x13b1a2a2UL, 0x58c39b9bUL, -0xae67c9c9UL, 0x4d763b3bUL, 0x3789bebeUL, 0xf3a25151UL, -0x2b321919UL, 0x213e1f1fUL, 0x417e3f3fUL, 0xe4b85c5cUL, -0x2391b2b2UL, 0xc42befefUL, 0xde944a4aUL, 0xa26fcdcdUL, -0x348bbfbfUL, 0x3b81babaUL, 0xb1de6f6fUL, 0xacc86464UL, -0x9e47d9d9UL, 0xe013f3f3UL, 0x427c3e3eUL, 0x299db4b4UL, -0x0ba1aaaaUL, 0x914ddcdcUL, 0x8a5fd5d5UL, 0x0a0c0606UL, -0xb575c0c0UL, 0x82fc7e7eUL, 0xef19f6f6UL, 0xaacc6666UL, -0xb4d86c6cUL, 0x79fd8484UL, 0x93e27171UL, 0x48703838UL, -0x3e87b9b9UL, 0x273a1d1dUL, 0x81fe7f7fUL, 0x52cf9d9dUL, -0xd8904848UL, 0x68e38b8bUL, 0x7e542a2aUL, 0x9b41dadaUL, -0x1abfa5a5UL, 0x55663333UL, 0x73f18282UL, 0x4b723939UL, -0x8f59d6d6UL, 0x88f07878UL, 0x7ff98686UL, 0xfb01fafaUL, -0xd93de4e4UL, 0x7d562b2bUL, 0x0ea7a9a9UL, 0x223c1e1eUL, -0x6ee78989UL, 0xa0c06060UL, 0xbdd66b6bUL, 0xcb21eaeaUL, -0xffaa5555UL, 0xd4984c4cUL, 0xec1bf7f7UL, 0xd331e2e2UL, -}, - -{ -0xb12697b1UL, 0xcea769ceUL, 0xc3b073c3UL, 0x954adf95UL, -0x5aeeb45aUL, 0xad02afadUL, 0xe7dc3be7UL, 0x02060402UL, -0x4dd79a4dUL, 0x44cc8844UL, 0xfbf803fbUL, 0x9146d791UL, -0x0c14180cUL, 0x877cfb87UL, 0xa116b7a1UL, 0x50f0a050UL, -0xcba863cbUL, 0x67a9ce67UL, 0x54fca854UL, 0xdd924fddUL, -0x46ca8c46UL, 0x8f64eb8fUL, 0xe1d637e1UL, 0x4ed29c4eUL, -0xf0e515f0UL, 0xfdf20ffdUL, 0xfcf10dfcUL, 0xebc823ebUL, -0xf9fe07f9UL, 0xc4b97dc4UL, 0x1a2e341aUL, 0x6eb2dc6eUL, -0x5ee2bc5eUL, 0xf5ea1ff5UL, 0xcca16dccUL, 0x8d62ef8dUL, -0x1c24381cUL, 0x56faac56UL, 0x43c58643UL, 0xfef709feUL, -0x07090e07UL, 0x61a3c261UL, 0xf8fd05f8UL, 0x759fea75UL, -0x59ebb259UL, 0xfff40bffUL, 0x03050603UL, 0x22664422UL, -0x8a6be18aUL, 0xd18657d1UL, 0x13352613UL, 0xeec729eeUL, -0x886de588UL, 0x00000000UL, 0x0e121c0eUL, 0x345c6834UL, -0x153f2a15UL, 0x8075f580UL, 0x9449dd94UL, 0xe3d033e3UL, -0xedc22fedUL, 0xb52a9fb5UL, 0x53f5a653UL, 0x23654623UL, -0x4bdd964bUL, 0x47c98e47UL, 0x17392e17UL, 0xa71cbba7UL, -0x9045d590UL, 0x355f6a35UL, 0xab08a3abUL, 0xd89d45d8UL, -0xb83d85b8UL, 0xdf944bdfUL, 0x4fd19e4fUL, 0x57f9ae57UL, -0x9a5bc19aUL, 0x9243d192UL, 0xdb9843dbUL, 0x1b2d361bUL, -0x3c44783cUL, 0xc8ad65c8UL, 0x995ec799UL, 0x040c0804UL, -0x8e67e98eUL, 0xe0d535e0UL, 0xd78c5bd7UL, 0x7d87fa7dUL, -0x857aff85UL, 0xbb3883bbUL, 0x40c08040UL, 0x2c74582cUL, -0x3a4e743aUL, 0x45cf8a45UL, 0xf1e617f1UL, 0x42c68442UL, -0x65afca65UL, 0x20604020UL, 0x41c38241UL, 0x18283018UL, -0x7296e472UL, 0x256f4a25UL, 0x9340d393UL, 0x7090e070UL, -0x365a6c36UL, 0x050f0a05UL, 0xf2e311f2UL, 0x0b1d160bUL, -0xa310b3a3UL, 0x798bf279UL, 0xecc12decUL, 0x08181008UL, -0x27694e27UL, 0x31536231UL, 0x32566432UL, 0xb62f99b6UL, -0x7c84f87cUL, 0xb02595b0UL, 0x0a1e140aUL, 0x7395e673UL, -0x5bedb65bUL, 0x7b8df67bUL, 0xb72c9bb7UL, 0x8176f781UL, -0xd28351d2UL, 0x0d171a0dUL, 0x6abed46aUL, 0x266a4c26UL, -0x9e57c99eUL, 0x58e8b058UL, 0x9c51cd9cUL, 0x8370f383UL, -0x749ce874UL, 0xb32093b3UL, 0xac01adacUL, 0x30506030UL, -0x7a8ef47aUL, 0x69bbd269UL, 0x7799ee77UL, 0x0f111e0fUL, -0xae07a9aeUL, 0x21634221UL, 0xde9749deUL, 0xd08555d0UL, -0x2e725c2eUL, 0x974cdb97UL, 0x10302010UL, 0xa419bda4UL, -0x985dc598UL, 0xa80da5a8UL, 0xd4895dd4UL, 0x68b8d068UL, -0x2d775a2dUL, 0x62a6c462UL, 0x297b5229UL, 0x6db7da6dUL, -0x163a2c16UL, 0x49db9249UL, 0x769aec76UL, 0xc7bc7bc7UL, -0xe8cd25e8UL, 0xc1b677c1UL, 0x964fd996UL, 0x37596e37UL, -0xe5da3fe5UL, 0xcaab61caUL, 0xf4e91df4UL, 0xe9ce27e9UL, -0x63a5c663UL, 0x12362412UL, 0xc2b371c2UL, 0xa61fb9a6UL, -0x143c2814UL, 0xbc318dbcUL, 0xd38053d3UL, 0x28785028UL, -0xaf04abafUL, 0x2f715e2fUL, 0xe6df39e6UL, 0x246c4824UL, -0x52f6a452UL, 0xc6bf79c6UL, 0xa015b5a0UL, 0x091b1209UL, -0xbd328fbdUL, 0x8c61ed8cUL, 0xcfa46bcfUL, 0x5de7ba5dUL, -0x11332211UL, 0x5fe1be5fUL, 0x01030201UL, 0xc5ba7fc5UL, -0x9f54cb9fUL, 0x3d477a3dUL, 0xa213b1a2UL, 0x9b58c39bUL, -0xc9ae67c9UL, 0x3b4d763bUL, 0xbe3789beUL, 0x51f3a251UL, -0x192b3219UL, 0x1f213e1fUL, 0x3f417e3fUL, 0x5ce4b85cUL, -0xb22391b2UL, 0xefc42befUL, 0x4ade944aUL, 0xcda26fcdUL, -0xbf348bbfUL, 0xba3b81baUL, 0x6fb1de6fUL, 0x64acc864UL, -0xd99e47d9UL, 0xf3e013f3UL, 0x3e427c3eUL, 0xb4299db4UL, -0xaa0ba1aaUL, 0xdc914ddcUL, 0xd58a5fd5UL, 0x060a0c06UL, -0xc0b575c0UL, 0x7e82fc7eUL, 0xf6ef19f6UL, 0x66aacc66UL, -0x6cb4d86cUL, 0x8479fd84UL, 0x7193e271UL, 0x38487038UL, -0xb93e87b9UL, 0x1d273a1dUL, 0x7f81fe7fUL, 0x9d52cf9dUL, -0x48d89048UL, 0x8b68e38bUL, 0x2a7e542aUL, 0xda9b41daUL, -0xa51abfa5UL, 0x33556633UL, 0x8273f182UL, 0x394b7239UL, -0xd68f59d6UL, 0x7888f078UL, 0x867ff986UL, 0xfafb01faUL, -0xe4d93de4UL, 0x2b7d562bUL, 0xa90ea7a9UL, 0x1e223c1eUL, -0x896ee789UL, 0x60a0c060UL, 0x6bbdd66bUL, 0xeacb21eaUL, -0x55ffaa55UL, 0x4cd4984cUL, 0xf7ec1bf7UL, 0xe2d331e2UL, -}, - -{ -0xb1b12697UL, 0xcecea769UL, 0xc3c3b073UL, 0x95954adfUL, -0x5a5aeeb4UL, 0xadad02afUL, 0xe7e7dc3bUL, 0x02020604UL, -0x4d4dd79aUL, 0x4444cc88UL, 0xfbfbf803UL, 0x919146d7UL, -0x0c0c1418UL, 0x87877cfbUL, 0xa1a116b7UL, 0x5050f0a0UL, -0xcbcba863UL, 0x6767a9ceUL, 0x5454fca8UL, 0xdddd924fUL, -0x4646ca8cUL, 0x8f8f64ebUL, 0xe1e1d637UL, 0x4e4ed29cUL, -0xf0f0e515UL, 0xfdfdf20fUL, 0xfcfcf10dUL, 0xebebc823UL, -0xf9f9fe07UL, 0xc4c4b97dUL, 0x1a1a2e34UL, 0x6e6eb2dcUL, -0x5e5ee2bcUL, 0xf5f5ea1fUL, 0xcccca16dUL, 0x8d8d62efUL, -0x1c1c2438UL, 0x5656faacUL, 0x4343c586UL, 0xfefef709UL, -0x0707090eUL, 0x6161a3c2UL, 0xf8f8fd05UL, 0x75759feaUL, -0x5959ebb2UL, 0xfffff40bUL, 0x03030506UL, 0x22226644UL, -0x8a8a6be1UL, 0xd1d18657UL, 0x13133526UL, 0xeeeec729UL, -0x88886de5UL, 0x00000000UL, 0x0e0e121cUL, 0x34345c68UL, -0x15153f2aUL, 0x808075f5UL, 0x949449ddUL, 0xe3e3d033UL, -0xededc22fUL, 0xb5b52a9fUL, 0x5353f5a6UL, 0x23236546UL, -0x4b4bdd96UL, 0x4747c98eUL, 0x1717392eUL, 0xa7a71cbbUL, -0x909045d5UL, 0x35355f6aUL, 0xabab08a3UL, 0xd8d89d45UL, -0xb8b83d85UL, 0xdfdf944bUL, 0x4f4fd19eUL, 0x5757f9aeUL, -0x9a9a5bc1UL, 0x929243d1UL, 0xdbdb9843UL, 0x1b1b2d36UL, -0x3c3c4478UL, 0xc8c8ad65UL, 0x99995ec7UL, 0x04040c08UL, -0x8e8e67e9UL, 0xe0e0d535UL, 0xd7d78c5bUL, 0x7d7d87faUL, -0x85857affUL, 0xbbbb3883UL, 0x4040c080UL, 0x2c2c7458UL, -0x3a3a4e74UL, 0x4545cf8aUL, 0xf1f1e617UL, 0x4242c684UL, -0x6565afcaUL, 0x20206040UL, 0x4141c382UL, 0x18182830UL, -0x727296e4UL, 0x25256f4aUL, 0x939340d3UL, 0x707090e0UL, -0x36365a6cUL, 0x05050f0aUL, 0xf2f2e311UL, 0x0b0b1d16UL, -0xa3a310b3UL, 0x79798bf2UL, 0xececc12dUL, 0x08081810UL, -0x2727694eUL, 0x31315362UL, 0x32325664UL, 0xb6b62f99UL, -0x7c7c84f8UL, 0xb0b02595UL, 0x0a0a1e14UL, 0x737395e6UL, -0x5b5bedb6UL, 0x7b7b8df6UL, 0xb7b72c9bUL, 0x818176f7UL, -0xd2d28351UL, 0x0d0d171aUL, 0x6a6abed4UL, 0x26266a4cUL, -0x9e9e57c9UL, 0x5858e8b0UL, 0x9c9c51cdUL, 0x838370f3UL, -0x74749ce8UL, 0xb3b32093UL, 0xacac01adUL, 0x30305060UL, -0x7a7a8ef4UL, 0x6969bbd2UL, 0x777799eeUL, 0x0f0f111eUL, -0xaeae07a9UL, 0x21216342UL, 0xdede9749UL, 0xd0d08555UL, -0x2e2e725cUL, 0x97974cdbUL, 0x10103020UL, 0xa4a419bdUL, -0x98985dc5UL, 0xa8a80da5UL, 0xd4d4895dUL, 0x6868b8d0UL, -0x2d2d775aUL, 0x6262a6c4UL, 0x29297b52UL, 0x6d6db7daUL, -0x16163a2cUL, 0x4949db92UL, 0x76769aecUL, 0xc7c7bc7bUL, -0xe8e8cd25UL, 0xc1c1b677UL, 0x96964fd9UL, 0x3737596eUL, -0xe5e5da3fUL, 0xcacaab61UL, 0xf4f4e91dUL, 0xe9e9ce27UL, -0x6363a5c6UL, 0x12123624UL, 0xc2c2b371UL, 0xa6a61fb9UL, -0x14143c28UL, 0xbcbc318dUL, 0xd3d38053UL, 0x28287850UL, -0xafaf04abUL, 0x2f2f715eUL, 0xe6e6df39UL, 0x24246c48UL, -0x5252f6a4UL, 0xc6c6bf79UL, 0xa0a015b5UL, 0x09091b12UL, -0xbdbd328fUL, 0x8c8c61edUL, 0xcfcfa46bUL, 0x5d5de7baUL, -0x11113322UL, 0x5f5fe1beUL, 0x01010302UL, 0xc5c5ba7fUL, -0x9f9f54cbUL, 0x3d3d477aUL, 0xa2a213b1UL, 0x9b9b58c3UL, -0xc9c9ae67UL, 0x3b3b4d76UL, 0xbebe3789UL, 0x5151f3a2UL, -0x19192b32UL, 0x1f1f213eUL, 0x3f3f417eUL, 0x5c5ce4b8UL, -0xb2b22391UL, 0xefefc42bUL, 0x4a4ade94UL, 0xcdcda26fUL, -0xbfbf348bUL, 0xbaba3b81UL, 0x6f6fb1deUL, 0x6464acc8UL, -0xd9d99e47UL, 0xf3f3e013UL, 0x3e3e427cUL, 0xb4b4299dUL, -0xaaaa0ba1UL, 0xdcdc914dUL, 0xd5d58a5fUL, 0x06060a0cUL, -0xc0c0b575UL, 0x7e7e82fcUL, 0xf6f6ef19UL, 0x6666aaccUL, -0x6c6cb4d8UL, 0x848479fdUL, 0x717193e2UL, 0x38384870UL, -0xb9b93e87UL, 0x1d1d273aUL, 0x7f7f81feUL, 0x9d9d52cfUL, -0x4848d890UL, 0x8b8b68e3UL, 0x2a2a7e54UL, 0xdada9b41UL, -0xa5a51abfUL, 0x33335566UL, 0x828273f1UL, 0x39394b72UL, -0xd6d68f59UL, 0x787888f0UL, 0x86867ff9UL, 0xfafafb01UL, -0xe4e4d93dUL, 0x2b2b7d56UL, 0xa9a90ea7UL, 0x1e1e223cUL, -0x89896ee7UL, 0x6060a0c0UL, 0x6b6bbdd6UL, 0xeaeacb21UL, -0x5555ffaaUL, 0x4c4cd498UL, 0xf7f7ec1bUL, 0xe2e2d331UL, -}}; - -const word32 Square::Dec::Td[4][256] = { -{ -0xe368bc02UL, 0x5585620cUL, 0x2a3f2331UL, 0x61ab13f7UL, -0x98d46d72UL, 0x21cb9a19UL, 0x3c22a461UL, 0x459d3dcdUL, -0x05fdb423UL, 0x2bc4075fUL, 0x9b2c01c0UL, 0x3dd9800fUL, -0x486c5c74UL, 0xf97f7e85UL, 0xf173ab1fUL, 0xb6edde0eUL, -0x283c6bedUL, 0x4997781aUL, 0x9f2a918dUL, 0xc9579f33UL, -0xa907a8aaUL, 0xa50ded7dUL, 0x7c422d8fUL, 0x764db0c9UL, -0x4d91e857UL, 0xcea963ccUL, 0xb4ee96d2UL, 0x3028e1b6UL, -0x0df161b9UL, 0xbd196726UL, 0x419bad80UL, 0xc0a06ec7UL, -0x5183f241UL, 0x92dbf034UL, 0x6fa21efcUL, 0x8f32ce4cUL, -0x13e03373UL, 0x69a7c66dUL, 0xe56d6493UL, 0xbf1a2ffaUL, -0xbb1cbfb7UL, 0x587403b5UL, 0xe76e2c4fUL, 0x5d89b796UL, -0xe89c052aUL, 0x446619a3UL, 0x342e71fbUL, 0x0ff22965UL, -0xfe81827aUL, 0xb11322f1UL, 0xa30835ecUL, 0xcd510f7eUL, -0xff7aa614UL, 0x5c7293f8UL, 0x2fc29712UL, 0xf370e3c3UL, -0x992f491cUL, 0xd1431568UL, 0xc2a3261bUL, 0x88cc32b3UL, -0x8acf7a6fUL, 0xb0e8069fUL, 0x7a47f51eUL, 0xd2bb79daUL, -0xe6950821UL, 0x4398e55cUL, 0xd0b83106UL, 0x11e37bafUL, -0x7e416553UL, 0xccaa2b10UL, 0xd8b4e49cUL, 0x6456a7d4UL, -0xfb7c3659UL, 0x724b2084UL, 0xea9f4df6UL, 0x6a5faadfUL, -0x2dc1dfceUL, 0x70486858UL, 0xcaaff381UL, 0x0605d891UL, -0x5a774b69UL, 0x94de28a5UL, 0x39df1042UL, 0x813bc347UL, -0xfc82caa6UL, 0x23c8d2c5UL, 0x03f86cb2UL, 0x080cd59aUL, -0xdab7ac40UL, 0x7db909e1UL, 0x3824342cUL, 0xcf5247a2UL, -0xdcb274d1UL, 0x63a85b2bUL, 0x35d55595UL, 0x479e7511UL, -0x15e5ebe2UL, 0x4b9430c6UL, 0x4a6f14a8UL, 0x91239c86UL, -0x4c6acc39UL, 0x5f8aff4aUL, 0x0406904dUL, 0xee99ddbbUL, -0x1e1152caUL, 0xaaffc418UL, 0xeb646998UL, 0x07fefcffUL, -0x8b345e01UL, 0x567d0ebeUL, 0xbae79bd9UL, 0x4263c132UL, -0x75b5dc7bUL, 0x97264417UL, 0x67aecb66UL, 0x95250ccbUL, -0xec9a9567UL, 0x57862ad0UL, 0x60503799UL, 0xb8e4d305UL, -0x65ad83baUL, 0x19efae35UL, 0xa4f6c913UL, 0xc15b4aa9UL, -0x873e1bd6UL, 0xa0f0595eUL, 0x18148a5bUL, 0xaf02703bUL, -0xab04e076UL, 0xdd4950bfUL, 0xdf4a1863UL, 0xc6a5b656UL, -0x853d530aUL, 0xfa871237UL, 0x77b694a7UL, 0x4665517fUL, -0xed61b109UL, 0x1bece6e9UL, 0xd5458525UL, 0xf5753b52UL, -0x7fba413dUL, 0x27ce4288UL, 0xb2eb4e43UL, 0xd6bde997UL, -0x527b9ef3UL, 0x62537f45UL, 0x2c3afba0UL, 0x7bbcd170UL, -0xb91ff76bUL, 0x121b171dUL, 0xfd79eec8UL, 0x3a277cf0UL, -0x0c0a45d7UL, 0x96dd6079UL, 0x2233f6abUL, 0xacfa1c89UL, -0xc8acbb5dUL, 0xa10b7d30UL, 0xd4bea14bUL, 0xbee10b94UL, -0x25cd0a54UL, 0x547e4662UL, 0xa2f31182UL, 0x17e6a33eUL, -0x263566e6UL, 0xc3580275UL, 0x83388b9bUL, 0x7844bdc2UL, -0x020348dcUL, 0x4f92a08bUL, 0x2e39b37cUL, 0x4e6984e5UL, -0xf0888f71UL, 0x362d3927UL, 0x9cd2fd3fUL, 0x01fb246eUL, -0x893716ddUL, 0x00000000UL, 0xf68d57e0UL, 0xe293986cUL, -0x744ef815UL, 0x9320d45aUL, 0xad0138e7UL, 0xd3405db4UL, -0x1a17c287UL, 0xb3106a2dUL, 0x5078d62fUL, 0xf48e1f3cUL, -0xa70ea5a1UL, 0x71b34c36UL, 0x9ad725aeUL, 0x5e71db24UL, -0x161d8750UL, 0xef62f9d5UL, 0x8d318690UL, 0x1c121a16UL, -0xa6f581cfUL, 0x5b8c6f07UL, 0x37d61d49UL, 0x6e593a92UL, -0x84c67764UL, 0x86c53fb8UL, 0xd746cdf9UL, 0xe090d0b0UL, -0x29c74f83UL, 0xe49640fdUL, 0x0e090d0bUL, 0x6da15620UL, -0x8ec9ea22UL, 0xdb4c882eUL, 0xf776738eUL, 0xb515b2bcUL, -0x10185fc1UL, 0x322ba96aUL, 0x6ba48eb1UL, 0xaef95455UL, -0x406089eeUL, 0x6655ef08UL, 0xe9672144UL, 0x3e21ecbdUL, -0x2030be77UL, 0xf28bc7adUL, 0x80c0e729UL, 0x141ecf8cUL, -0xbce24348UL, 0xc4a6fe8aUL, 0x31d3c5d8UL, 0xb716fa60UL, -0x5380ba9dUL, 0xd94fc0f2UL, 0x1de93e78UL, 0x24362e3aUL, -0xe16bf4deUL, 0xcb54d7efUL, 0x09f7f1f4UL, 0x82c3aff5UL, -0x0bf4b928UL, 0x9d29d951UL, 0xc75e9238UL, 0xf8845aebUL, -0x90d8b8e8UL, 0xdeb13c0dUL, 0x33d08d04UL, 0x685ce203UL, -0xc55ddae4UL, 0x3bdc589eUL, 0x0a0f9d46UL, 0x3fdac8d3UL, -0x598f27dbUL, 0xa8fc8cc4UL, 0x79bf99acUL, 0x6c5a724eUL, -0x8ccaa2feUL, 0x9ed1b5e3UL, 0x1fea76a4UL, 0x73b004eaUL, -}, - -{ -0x02e368bcUL, 0x0c558562UL, 0x312a3f23UL, 0xf761ab13UL, -0x7298d46dUL, 0x1921cb9aUL, 0x613c22a4UL, 0xcd459d3dUL, -0x2305fdb4UL, 0x5f2bc407UL, 0xc09b2c01UL, 0x0f3dd980UL, -0x74486c5cUL, 0x85f97f7eUL, 0x1ff173abUL, 0x0eb6eddeUL, -0xed283c6bUL, 0x1a499778UL, 0x8d9f2a91UL, 0x33c9579fUL, -0xaaa907a8UL, 0x7da50dedUL, 0x8f7c422dUL, 0xc9764db0UL, -0x574d91e8UL, 0xcccea963UL, 0xd2b4ee96UL, 0xb63028e1UL, -0xb90df161UL, 0x26bd1967UL, 0x80419badUL, 0xc7c0a06eUL, -0x415183f2UL, 0x3492dbf0UL, 0xfc6fa21eUL, 0x4c8f32ceUL, -0x7313e033UL, 0x6d69a7c6UL, 0x93e56d64UL, 0xfabf1a2fUL, -0xb7bb1cbfUL, 0xb5587403UL, 0x4fe76e2cUL, 0x965d89b7UL, -0x2ae89c05UL, 0xa3446619UL, 0xfb342e71UL, 0x650ff229UL, -0x7afe8182UL, 0xf1b11322UL, 0xeca30835UL, 0x7ecd510fUL, -0x14ff7aa6UL, 0xf85c7293UL, 0x122fc297UL, 0xc3f370e3UL, -0x1c992f49UL, 0x68d14315UL, 0x1bc2a326UL, 0xb388cc32UL, -0x6f8acf7aUL, 0x9fb0e806UL, 0x1e7a47f5UL, 0xdad2bb79UL, -0x21e69508UL, 0x5c4398e5UL, 0x06d0b831UL, 0xaf11e37bUL, -0x537e4165UL, 0x10ccaa2bUL, 0x9cd8b4e4UL, 0xd46456a7UL, -0x59fb7c36UL, 0x84724b20UL, 0xf6ea9f4dUL, 0xdf6a5faaUL, -0xce2dc1dfUL, 0x58704868UL, 0x81caaff3UL, 0x910605d8UL, -0x695a774bUL, 0xa594de28UL, 0x4239df10UL, 0x47813bc3UL, -0xa6fc82caUL, 0xc523c8d2UL, 0xb203f86cUL, 0x9a080cd5UL, -0x40dab7acUL, 0xe17db909UL, 0x2c382434UL, 0xa2cf5247UL, -0xd1dcb274UL, 0x2b63a85bUL, 0x9535d555UL, 0x11479e75UL, -0xe215e5ebUL, 0xc64b9430UL, 0xa84a6f14UL, 0x8691239cUL, -0x394c6accUL, 0x4a5f8affUL, 0x4d040690UL, 0xbbee99ddUL, -0xca1e1152UL, 0x18aaffc4UL, 0x98eb6469UL, 0xff07fefcUL, -0x018b345eUL, 0xbe567d0eUL, 0xd9bae79bUL, 0x324263c1UL, -0x7b75b5dcUL, 0x17972644UL, 0x6667aecbUL, 0xcb95250cUL, -0x67ec9a95UL, 0xd057862aUL, 0x99605037UL, 0x05b8e4d3UL, -0xba65ad83UL, 0x3519efaeUL, 0x13a4f6c9UL, 0xa9c15b4aUL, -0xd6873e1bUL, 0x5ea0f059UL, 0x5b18148aUL, 0x3baf0270UL, -0x76ab04e0UL, 0xbfdd4950UL, 0x63df4a18UL, 0x56c6a5b6UL, -0x0a853d53UL, 0x37fa8712UL, 0xa777b694UL, 0x7f466551UL, -0x09ed61b1UL, 0xe91bece6UL, 0x25d54585UL, 0x52f5753bUL, -0x3d7fba41UL, 0x8827ce42UL, 0x43b2eb4eUL, 0x97d6bde9UL, -0xf3527b9eUL, 0x4562537fUL, 0xa02c3afbUL, 0x707bbcd1UL, -0x6bb91ff7UL, 0x1d121b17UL, 0xc8fd79eeUL, 0xf03a277cUL, -0xd70c0a45UL, 0x7996dd60UL, 0xab2233f6UL, 0x89acfa1cUL, -0x5dc8acbbUL, 0x30a10b7dUL, 0x4bd4bea1UL, 0x94bee10bUL, -0x5425cd0aUL, 0x62547e46UL, 0x82a2f311UL, 0x3e17e6a3UL, -0xe6263566UL, 0x75c35802UL, 0x9b83388bUL, 0xc27844bdUL, -0xdc020348UL, 0x8b4f92a0UL, 0x7c2e39b3UL, 0xe54e6984UL, -0x71f0888fUL, 0x27362d39UL, 0x3f9cd2fdUL, 0x6e01fb24UL, -0xdd893716UL, 0x00000000UL, 0xe0f68d57UL, 0x6ce29398UL, -0x15744ef8UL, 0x5a9320d4UL, 0xe7ad0138UL, 0xb4d3405dUL, -0x871a17c2UL, 0x2db3106aUL, 0x2f5078d6UL, 0x3cf48e1fUL, -0xa1a70ea5UL, 0x3671b34cUL, 0xae9ad725UL, 0x245e71dbUL, -0x50161d87UL, 0xd5ef62f9UL, 0x908d3186UL, 0x161c121aUL, -0xcfa6f581UL, 0x075b8c6fUL, 0x4937d61dUL, 0x926e593aUL, -0x6484c677UL, 0xb886c53fUL, 0xf9d746cdUL, 0xb0e090d0UL, -0x8329c74fUL, 0xfde49640UL, 0x0b0e090dUL, 0x206da156UL, -0x228ec9eaUL, 0x2edb4c88UL, 0x8ef77673UL, 0xbcb515b2UL, -0xc110185fUL, 0x6a322ba9UL, 0xb16ba48eUL, 0x55aef954UL, -0xee406089UL, 0x086655efUL, 0x44e96721UL, 0xbd3e21ecUL, -0x772030beUL, 0xadf28bc7UL, 0x2980c0e7UL, 0x8c141ecfUL, -0x48bce243UL, 0x8ac4a6feUL, 0xd831d3c5UL, 0x60b716faUL, -0x9d5380baUL, 0xf2d94fc0UL, 0x781de93eUL, 0x3a24362eUL, -0xdee16bf4UL, 0xefcb54d7UL, 0xf409f7f1UL, 0xf582c3afUL, -0x280bf4b9UL, 0x519d29d9UL, 0x38c75e92UL, 0xebf8845aUL, -0xe890d8b8UL, 0x0ddeb13cUL, 0x0433d08dUL, 0x03685ce2UL, -0xe4c55ddaUL, 0x9e3bdc58UL, 0x460a0f9dUL, 0xd33fdac8UL, -0xdb598f27UL, 0xc4a8fc8cUL, 0xac79bf99UL, 0x4e6c5a72UL, -0xfe8ccaa2UL, 0xe39ed1b5UL, 0xa41fea76UL, 0xea73b004UL, -}, - -{ -0xbc02e368UL, 0x620c5585UL, 0x23312a3fUL, 0x13f761abUL, -0x6d7298d4UL, 0x9a1921cbUL, 0xa4613c22UL, 0x3dcd459dUL, -0xb42305fdUL, 0x075f2bc4UL, 0x01c09b2cUL, 0x800f3dd9UL, -0x5c74486cUL, 0x7e85f97fUL, 0xab1ff173UL, 0xde0eb6edUL, -0x6bed283cUL, 0x781a4997UL, 0x918d9f2aUL, 0x9f33c957UL, -0xa8aaa907UL, 0xed7da50dUL, 0x2d8f7c42UL, 0xb0c9764dUL, -0xe8574d91UL, 0x63cccea9UL, 0x96d2b4eeUL, 0xe1b63028UL, -0x61b90df1UL, 0x6726bd19UL, 0xad80419bUL, 0x6ec7c0a0UL, -0xf2415183UL, 0xf03492dbUL, 0x1efc6fa2UL, 0xce4c8f32UL, -0x337313e0UL, 0xc66d69a7UL, 0x6493e56dUL, 0x2ffabf1aUL, -0xbfb7bb1cUL, 0x03b55874UL, 0x2c4fe76eUL, 0xb7965d89UL, -0x052ae89cUL, 0x19a34466UL, 0x71fb342eUL, 0x29650ff2UL, -0x827afe81UL, 0x22f1b113UL, 0x35eca308UL, 0x0f7ecd51UL, -0xa614ff7aUL, 0x93f85c72UL, 0x97122fc2UL, 0xe3c3f370UL, -0x491c992fUL, 0x1568d143UL, 0x261bc2a3UL, 0x32b388ccUL, -0x7a6f8acfUL, 0x069fb0e8UL, 0xf51e7a47UL, 0x79dad2bbUL, -0x0821e695UL, 0xe55c4398UL, 0x3106d0b8UL, 0x7baf11e3UL, -0x65537e41UL, 0x2b10ccaaUL, 0xe49cd8b4UL, 0xa7d46456UL, -0x3659fb7cUL, 0x2084724bUL, 0x4df6ea9fUL, 0xaadf6a5fUL, -0xdfce2dc1UL, 0x68587048UL, 0xf381caafUL, 0xd8910605UL, -0x4b695a77UL, 0x28a594deUL, 0x104239dfUL, 0xc347813bUL, -0xcaa6fc82UL, 0xd2c523c8UL, 0x6cb203f8UL, 0xd59a080cUL, -0xac40dab7UL, 0x09e17db9UL, 0x342c3824UL, 0x47a2cf52UL, -0x74d1dcb2UL, 0x5b2b63a8UL, 0x559535d5UL, 0x7511479eUL, -0xebe215e5UL, 0x30c64b94UL, 0x14a84a6fUL, 0x9c869123UL, -0xcc394c6aUL, 0xff4a5f8aUL, 0x904d0406UL, 0xddbbee99UL, -0x52ca1e11UL, 0xc418aaffUL, 0x6998eb64UL, 0xfcff07feUL, -0x5e018b34UL, 0x0ebe567dUL, 0x9bd9bae7UL, 0xc1324263UL, -0xdc7b75b5UL, 0x44179726UL, 0xcb6667aeUL, 0x0ccb9525UL, -0x9567ec9aUL, 0x2ad05786UL, 0x37996050UL, 0xd305b8e4UL, -0x83ba65adUL, 0xae3519efUL, 0xc913a4f6UL, 0x4aa9c15bUL, -0x1bd6873eUL, 0x595ea0f0UL, 0x8a5b1814UL, 0x703baf02UL, -0xe076ab04UL, 0x50bfdd49UL, 0x1863df4aUL, 0xb656c6a5UL, -0x530a853dUL, 0x1237fa87UL, 0x94a777b6UL, 0x517f4665UL, -0xb109ed61UL, 0xe6e91becUL, 0x8525d545UL, 0x3b52f575UL, -0x413d7fbaUL, 0x428827ceUL, 0x4e43b2ebUL, 0xe997d6bdUL, -0x9ef3527bUL, 0x7f456253UL, 0xfba02c3aUL, 0xd1707bbcUL, -0xf76bb91fUL, 0x171d121bUL, 0xeec8fd79UL, 0x7cf03a27UL, -0x45d70c0aUL, 0x607996ddUL, 0xf6ab2233UL, 0x1c89acfaUL, -0xbb5dc8acUL, 0x7d30a10bUL, 0xa14bd4beUL, 0x0b94bee1UL, -0x0a5425cdUL, 0x4662547eUL, 0x1182a2f3UL, 0xa33e17e6UL, -0x66e62635UL, 0x0275c358UL, 0x8b9b8338UL, 0xbdc27844UL, -0x48dc0203UL, 0xa08b4f92UL, 0xb37c2e39UL, 0x84e54e69UL, -0x8f71f088UL, 0x3927362dUL, 0xfd3f9cd2UL, 0x246e01fbUL, -0x16dd8937UL, 0x00000000UL, 0x57e0f68dUL, 0x986ce293UL, -0xf815744eUL, 0xd45a9320UL, 0x38e7ad01UL, 0x5db4d340UL, -0xc2871a17UL, 0x6a2db310UL, 0xd62f5078UL, 0x1f3cf48eUL, -0xa5a1a70eUL, 0x4c3671b3UL, 0x25ae9ad7UL, 0xdb245e71UL, -0x8750161dUL, 0xf9d5ef62UL, 0x86908d31UL, 0x1a161c12UL, -0x81cfa6f5UL, 0x6f075b8cUL, 0x1d4937d6UL, 0x3a926e59UL, -0x776484c6UL, 0x3fb886c5UL, 0xcdf9d746UL, 0xd0b0e090UL, -0x4f8329c7UL, 0x40fde496UL, 0x0d0b0e09UL, 0x56206da1UL, -0xea228ec9UL, 0x882edb4cUL, 0x738ef776UL, 0xb2bcb515UL, -0x5fc11018UL, 0xa96a322bUL, 0x8eb16ba4UL, 0x5455aef9UL, -0x89ee4060UL, 0xef086655UL, 0x2144e967UL, 0xecbd3e21UL, -0xbe772030UL, 0xc7adf28bUL, 0xe72980c0UL, 0xcf8c141eUL, -0x4348bce2UL, 0xfe8ac4a6UL, 0xc5d831d3UL, 0xfa60b716UL, -0xba9d5380UL, 0xc0f2d94fUL, 0x3e781de9UL, 0x2e3a2436UL, -0xf4dee16bUL, 0xd7efcb54UL, 0xf1f409f7UL, 0xaff582c3UL, -0xb9280bf4UL, 0xd9519d29UL, 0x9238c75eUL, 0x5aebf884UL, -0xb8e890d8UL, 0x3c0ddeb1UL, 0x8d0433d0UL, 0xe203685cUL, -0xdae4c55dUL, 0x589e3bdcUL, 0x9d460a0fUL, 0xc8d33fdaUL, -0x27db598fUL, 0x8cc4a8fcUL, 0x99ac79bfUL, 0x724e6c5aUL, -0xa2fe8ccaUL, 0xb5e39ed1UL, 0x76a41feaUL, 0x04ea73b0UL, -}, - -{ -0x68bc02e3UL, 0x85620c55UL, 0x3f23312aUL, 0xab13f761UL, -0xd46d7298UL, 0xcb9a1921UL, 0x22a4613cUL, 0x9d3dcd45UL, -0xfdb42305UL, 0xc4075f2bUL, 0x2c01c09bUL, 0xd9800f3dUL, -0x6c5c7448UL, 0x7f7e85f9UL, 0x73ab1ff1UL, 0xedde0eb6UL, -0x3c6bed28UL, 0x97781a49UL, 0x2a918d9fUL, 0x579f33c9UL, -0x07a8aaa9UL, 0x0ded7da5UL, 0x422d8f7cUL, 0x4db0c976UL, -0x91e8574dUL, 0xa963ccceUL, 0xee96d2b4UL, 0x28e1b630UL, -0xf161b90dUL, 0x196726bdUL, 0x9bad8041UL, 0xa06ec7c0UL, -0x83f24151UL, 0xdbf03492UL, 0xa21efc6fUL, 0x32ce4c8fUL, -0xe0337313UL, 0xa7c66d69UL, 0x6d6493e5UL, 0x1a2ffabfUL, -0x1cbfb7bbUL, 0x7403b558UL, 0x6e2c4fe7UL, 0x89b7965dUL, -0x9c052ae8UL, 0x6619a344UL, 0x2e71fb34UL, 0xf229650fUL, -0x81827afeUL, 0x1322f1b1UL, 0x0835eca3UL, 0x510f7ecdUL, -0x7aa614ffUL, 0x7293f85cUL, 0xc297122fUL, 0x70e3c3f3UL, -0x2f491c99UL, 0x431568d1UL, 0xa3261bc2UL, 0xcc32b388UL, -0xcf7a6f8aUL, 0xe8069fb0UL, 0x47f51e7aUL, 0xbb79dad2UL, -0x950821e6UL, 0x98e55c43UL, 0xb83106d0UL, 0xe37baf11UL, -0x4165537eUL, 0xaa2b10ccUL, 0xb4e49cd8UL, 0x56a7d464UL, -0x7c3659fbUL, 0x4b208472UL, 0x9f4df6eaUL, 0x5faadf6aUL, -0xc1dfce2dUL, 0x48685870UL, 0xaff381caUL, 0x05d89106UL, -0x774b695aUL, 0xde28a594UL, 0xdf104239UL, 0x3bc34781UL, -0x82caa6fcUL, 0xc8d2c523UL, 0xf86cb203UL, 0x0cd59a08UL, -0xb7ac40daUL, 0xb909e17dUL, 0x24342c38UL, 0x5247a2cfUL, -0xb274d1dcUL, 0xa85b2b63UL, 0xd5559535UL, 0x9e751147UL, -0xe5ebe215UL, 0x9430c64bUL, 0x6f14a84aUL, 0x239c8691UL, -0x6acc394cUL, 0x8aff4a5fUL, 0x06904d04UL, 0x99ddbbeeUL, -0x1152ca1eUL, 0xffc418aaUL, 0x646998ebUL, 0xfefcff07UL, -0x345e018bUL, 0x7d0ebe56UL, 0xe79bd9baUL, 0x63c13242UL, -0xb5dc7b75UL, 0x26441797UL, 0xaecb6667UL, 0x250ccb95UL, -0x9a9567ecUL, 0x862ad057UL, 0x50379960UL, 0xe4d305b8UL, -0xad83ba65UL, 0xefae3519UL, 0xf6c913a4UL, 0x5b4aa9c1UL, -0x3e1bd687UL, 0xf0595ea0UL, 0x148a5b18UL, 0x02703bafUL, -0x04e076abUL, 0x4950bfddUL, 0x4a1863dfUL, 0xa5b656c6UL, -0x3d530a85UL, 0x871237faUL, 0xb694a777UL, 0x65517f46UL, -0x61b109edUL, 0xece6e91bUL, 0x458525d5UL, 0x753b52f5UL, -0xba413d7fUL, 0xce428827UL, 0xeb4e43b2UL, 0xbde997d6UL, -0x7b9ef352UL, 0x537f4562UL, 0x3afba02cUL, 0xbcd1707bUL, -0x1ff76bb9UL, 0x1b171d12UL, 0x79eec8fdUL, 0x277cf03aUL, -0x0a45d70cUL, 0xdd607996UL, 0x33f6ab22UL, 0xfa1c89acUL, -0xacbb5dc8UL, 0x0b7d30a1UL, 0xbea14bd4UL, 0xe10b94beUL, -0xcd0a5425UL, 0x7e466254UL, 0xf31182a2UL, 0xe6a33e17UL, -0x3566e626UL, 0x580275c3UL, 0x388b9b83UL, 0x44bdc278UL, -0x0348dc02UL, 0x92a08b4fUL, 0x39b37c2eUL, 0x6984e54eUL, -0x888f71f0UL, 0x2d392736UL, 0xd2fd3f9cUL, 0xfb246e01UL, -0x3716dd89UL, 0x00000000UL, 0x8d57e0f6UL, 0x93986ce2UL, -0x4ef81574UL, 0x20d45a93UL, 0x0138e7adUL, 0x405db4d3UL, -0x17c2871aUL, 0x106a2db3UL, 0x78d62f50UL, 0x8e1f3cf4UL, -0x0ea5a1a7UL, 0xb34c3671UL, 0xd725ae9aUL, 0x71db245eUL, -0x1d875016UL, 0x62f9d5efUL, 0x3186908dUL, 0x121a161cUL, -0xf581cfa6UL, 0x8c6f075bUL, 0xd61d4937UL, 0x593a926eUL, -0xc6776484UL, 0xc53fb886UL, 0x46cdf9d7UL, 0x90d0b0e0UL, -0xc74f8329UL, 0x9640fde4UL, 0x090d0b0eUL, 0xa156206dUL, -0xc9ea228eUL, 0x4c882edbUL, 0x76738ef7UL, 0x15b2bcb5UL, -0x185fc110UL, 0x2ba96a32UL, 0xa48eb16bUL, 0xf95455aeUL, -0x6089ee40UL, 0x55ef0866UL, 0x672144e9UL, 0x21ecbd3eUL, -0x30be7720UL, 0x8bc7adf2UL, 0xc0e72980UL, 0x1ecf8c14UL, -0xe24348bcUL, 0xa6fe8ac4UL, 0xd3c5d831UL, 0x16fa60b7UL, -0x80ba9d53UL, 0x4fc0f2d9UL, 0xe93e781dUL, 0x362e3a24UL, -0x6bf4dee1UL, 0x54d7efcbUL, 0xf7f1f409UL, 0xc3aff582UL, -0xf4b9280bUL, 0x29d9519dUL, 0x5e9238c7UL, 0x845aebf8UL, -0xd8b8e890UL, 0xb13c0ddeUL, 0xd08d0433UL, 0x5ce20368UL, -0x5ddae4c5UL, 0xdc589e3bUL, 0x0f9d460aUL, 0xdac8d33fUL, -0x8f27db59UL, 0xfc8cc4a8UL, 0xbf99ac79UL, 0x5a724e6cUL, -0xcaa2fe8cUL, 0xd1b5e39eUL, 0xea76a41fUL, 0xb004ea73UL, -}}; - -NAMESPACE_END diff --git a/lib/cryptopp/stdcpp.h b/lib/cryptopp/stdcpp.h deleted file mode 100644 index 6511c4fa2..000000000 --- a/lib/cryptopp/stdcpp.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef CRYPTOPP_STDCPP_H -#define CRYPTOPP_STDCPP_H - -#if _MSC_VER >= 1500 -#define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef CRYPTOPP_INCLUDE_VECTOR_CC -// workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 -#include -#endif - -// for alloca -#ifdef __sun -#include -#elif defined(__MINGW32__) || defined(__BORLANDC__) -#include -#endif - -#ifdef _MSC_VER -#pragma warning(disable: 4231) // re-disable this -#ifdef _CRTAPI1 -#define CRYPTOPP_MSVCRT6 -#endif -#endif - -#endif diff --git a/lib/cryptopp/strciphr.cpp b/lib/cryptopp/strciphr.cpp deleted file mode 100644 index 53e007376..000000000 --- a/lib/cryptopp/strciphr.cpp +++ /dev/null @@ -1,252 +0,0 @@ -// strciphr.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS - -#include "strciphr.h" - -NAMESPACE_BEGIN(CryptoPP) - -template -void AdditiveCipherTemplate::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) -{ - PolicyInterface &policy = this->AccessPolicy(); - policy.CipherSetKey(params, key, length); - m_leftOver = 0; - unsigned int bufferByteSize = policy.CanOperateKeystream() ? GetBufferByteSize(policy) : RoundUpToMultipleOf(1024U, GetBufferByteSize(policy)); - m_buffer.New(bufferByteSize); - - if (this->IsResynchronizable()) - { - size_t ivLength; - const byte *iv = this->GetIVAndThrowIfInvalid(params, ivLength); - policy.CipherResynchronize(m_buffer, iv, ivLength); - } -} - -template -void AdditiveCipherTemplate::GenerateBlock(byte *outString, size_t length) -{ - if (m_leftOver > 0) - { - size_t len = STDMIN(m_leftOver, length); - memcpy(outString, KeystreamBufferEnd()-m_leftOver, len); - length -= len; - m_leftOver -= len; - outString += len; - - if (!length) - return; - } - assert(m_leftOver == 0); - - PolicyInterface &policy = this->AccessPolicy(); - unsigned int bytesPerIteration = policy.GetBytesPerIteration(); - - if (length >= bytesPerIteration) - { - size_t iterations = length / bytesPerIteration; - policy.WriteKeystream(outString, iterations); - outString += iterations * bytesPerIteration; - length -= iterations * bytesPerIteration; - } - - if (length > 0) - { - size_t bufferByteSize = RoundUpToMultipleOf(length, bytesPerIteration); - size_t bufferIterations = bufferByteSize / bytesPerIteration; - - policy.WriteKeystream(KeystreamBufferEnd()-bufferByteSize, bufferIterations); - memcpy(outString, KeystreamBufferEnd()-bufferByteSize, length); - m_leftOver = bufferByteSize - length; - } -} - -template -void AdditiveCipherTemplate::ProcessData(byte *outString, const byte *inString, size_t length) -{ - if (m_leftOver > 0) - { - size_t len = STDMIN(m_leftOver, length); - xorbuf(outString, inString, KeystreamBufferEnd()-m_leftOver, len); - length -= len; - m_leftOver -= len; - inString += len; - outString += len; - - if (!length) - return; - } - assert(m_leftOver == 0); - - PolicyInterface &policy = this->AccessPolicy(); - unsigned int bytesPerIteration = policy.GetBytesPerIteration(); - - if (policy.CanOperateKeystream() && length >= bytesPerIteration) - { - size_t iterations = length / bytesPerIteration; - unsigned int alignment = policy.GetAlignment(); - KeystreamOperation operation = KeystreamOperation((IsAlignedOn(inString, alignment) * 2) | (int)IsAlignedOn(outString, alignment)); - - policy.OperateKeystream(operation, outString, inString, iterations); - - inString += iterations * bytesPerIteration; - outString += iterations * bytesPerIteration; - length -= iterations * bytesPerIteration; - - if (!length) - return; - } - - size_t bufferByteSize = m_buffer.size(); - size_t bufferIterations = bufferByteSize / bytesPerIteration; - - while (length >= bufferByteSize) - { - policy.WriteKeystream(m_buffer, bufferIterations); - xorbuf(outString, inString, KeystreamBufferBegin(), bufferByteSize); - length -= bufferByteSize; - inString += bufferByteSize; - outString += bufferByteSize; - } - - if (length > 0) - { - bufferByteSize = RoundUpToMultipleOf(length, bytesPerIteration); - bufferIterations = bufferByteSize / bytesPerIteration; - - policy.WriteKeystream(KeystreamBufferEnd()-bufferByteSize, bufferIterations); - xorbuf(outString, inString, KeystreamBufferEnd()-bufferByteSize, length); - m_leftOver = bufferByteSize - length; - } -} - -template -void AdditiveCipherTemplate::Resynchronize(const byte *iv, int length) -{ - PolicyInterface &policy = this->AccessPolicy(); - m_leftOver = 0; - m_buffer.New(GetBufferByteSize(policy)); - policy.CipherResynchronize(m_buffer, iv, this->ThrowIfInvalidIVLength(length)); -} - -template -void AdditiveCipherTemplate::Seek(lword position) -{ - PolicyInterface &policy = this->AccessPolicy(); - unsigned int bytesPerIteration = policy.GetBytesPerIteration(); - - policy.SeekToIteration(position / bytesPerIteration); - position %= bytesPerIteration; - - if (position > 0) - { - policy.WriteKeystream(KeystreamBufferEnd()-bytesPerIteration, 1); - m_leftOver = bytesPerIteration - (unsigned int)position; - } - else - m_leftOver = 0; -} - -template -void CFB_CipherTemplate::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) -{ - PolicyInterface &policy = this->AccessPolicy(); - policy.CipherSetKey(params, key, length); - - if (this->IsResynchronizable()) - { - size_t ivLength; - const byte *iv = this->GetIVAndThrowIfInvalid(params, ivLength); - policy.CipherResynchronize(iv, ivLength); - } - - m_leftOver = policy.GetBytesPerIteration(); -} - -template -void CFB_CipherTemplate::Resynchronize(const byte *iv, int length) -{ - PolicyInterface &policy = this->AccessPolicy(); - policy.CipherResynchronize(iv, this->ThrowIfInvalidIVLength(length)); - m_leftOver = policy.GetBytesPerIteration(); -} - -template -void CFB_CipherTemplate::ProcessData(byte *outString, const byte *inString, size_t length) -{ - assert(length % this->MandatoryBlockSize() == 0); - - PolicyInterface &policy = this->AccessPolicy(); - unsigned int bytesPerIteration = policy.GetBytesPerIteration(); - unsigned int alignment = policy.GetAlignment(); - byte *reg = policy.GetRegisterBegin(); - - if (m_leftOver) - { - size_t len = STDMIN(m_leftOver, length); - CombineMessageAndShiftRegister(outString, reg + bytesPerIteration - m_leftOver, inString, len); - m_leftOver -= len; - length -= len; - inString += len; - outString += len; - } - - if (!length) - return; - - assert(m_leftOver == 0); - - if (policy.CanIterate() && length >= bytesPerIteration && IsAlignedOn(outString, alignment)) - { - if (IsAlignedOn(inString, alignment)) - policy.Iterate(outString, inString, GetCipherDir(*this), length / bytesPerIteration); - else - { - memcpy(outString, inString, length); - policy.Iterate(outString, outString, GetCipherDir(*this), length / bytesPerIteration); - } - inString += length - length % bytesPerIteration; - outString += length - length % bytesPerIteration; - length %= bytesPerIteration; - } - - while (length >= bytesPerIteration) - { - policy.TransformRegister(); - CombineMessageAndShiftRegister(outString, reg, inString, bytesPerIteration); - length -= bytesPerIteration; - inString += bytesPerIteration; - outString += bytesPerIteration; - } - - if (length > 0) - { - policy.TransformRegister(); - CombineMessageAndShiftRegister(outString, reg, inString, length); - m_leftOver = bytesPerIteration - length; - } -} - -template -void CFB_EncryptionTemplate::CombineMessageAndShiftRegister(byte *output, byte *reg, const byte *message, size_t length) -{ - xorbuf(reg, message, length); - memcpy(output, reg, length); -} - -template -void CFB_DecryptionTemplate::CombineMessageAndShiftRegister(byte *output, byte *reg, const byte *message, size_t length) -{ - for (unsigned int i=0; i, AdditiveCipherTemplate\<\> \> \> Encryption; - - AdditiveCipherTemplate and CFB_CipherTemplate are designed so that they don't need - to take a policy class as a template parameter (although this is allowed), so that - their code is not duplicated for each new cipher. Instead they each - get a reference to an abstract policy interface by calling AccessPolicy() on itself, so - AccessPolicy() must be overriden to return the actual policy reference. This is done - by the ConceretePolicyHolder class. Finally, SymmetricCipherFinal implements the constructors and - other functions that must be implemented by the most derived class. -*/ - -#ifndef CRYPTOPP_STRCIPHR_H -#define CRYPTOPP_STRCIPHR_H - -#include "seckey.h" -#include "secblock.h" -#include "argnames.h" - -NAMESPACE_BEGIN(CryptoPP) - -template -class CRYPTOPP_NO_VTABLE AbstractPolicyHolder : public BASE -{ -public: - typedef POLICY_INTERFACE PolicyInterface; - virtual ~AbstractPolicyHolder() {} - -protected: - virtual const POLICY_INTERFACE & GetPolicy() const =0; - virtual POLICY_INTERFACE & AccessPolicy() =0; -}; - -template -class ConcretePolicyHolder : public BASE, protected POLICY -{ -protected: - const POLICY_INTERFACE & GetPolicy() const {return *this;} - POLICY_INTERFACE & AccessPolicy() {return *this;} -}; - -enum KeystreamOperationFlags {OUTPUT_ALIGNED=1, INPUT_ALIGNED=2, INPUT_NULL = 4}; -enum KeystreamOperation { - WRITE_KEYSTREAM = INPUT_NULL, - WRITE_KEYSTREAM_ALIGNED = INPUT_NULL | OUTPUT_ALIGNED, - XOR_KEYSTREAM = 0, - XOR_KEYSTREAM_INPUT_ALIGNED = INPUT_ALIGNED, - XOR_KEYSTREAM_OUTPUT_ALIGNED= OUTPUT_ALIGNED, - XOR_KEYSTREAM_BOTH_ALIGNED = OUTPUT_ALIGNED | INPUT_ALIGNED}; - -struct CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AdditiveCipherAbstractPolicy -{ - virtual ~AdditiveCipherAbstractPolicy() {} - virtual unsigned int GetAlignment() const {return 1;} - virtual unsigned int GetBytesPerIteration() const =0; - virtual unsigned int GetOptimalBlockSize() const {return GetBytesPerIteration();} - virtual unsigned int GetIterationsToBuffer() const =0; - virtual void WriteKeystream(byte *keystream, size_t iterationCount) - {OperateKeystream(KeystreamOperation(INPUT_NULL | (KeystreamOperationFlags)IsAlignedOn(keystream, GetAlignment())), keystream, NULL, iterationCount);} - virtual bool CanOperateKeystream() const {return false;} - virtual void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount) {assert(false);} - virtual void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length) =0; - virtual void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length) {throw NotImplemented("SimpleKeyingInterface: this object doesn't support resynchronization");} - virtual bool CipherIsRandomAccess() const =0; - virtual void SeekToIteration(lword iterationCount) {assert(!CipherIsRandomAccess()); throw NotImplemented("StreamTransformation: this object doesn't support random access");} -}; - -template -struct CRYPTOPP_NO_VTABLE AdditiveCipherConcretePolicy : public BASE -{ - typedef WT WordType; - CRYPTOPP_CONSTANT(BYTES_PER_ITERATION = sizeof(WordType) * W) - -#if !(CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X64) - unsigned int GetAlignment() const {return GetAlignmentOf();} -#endif - unsigned int GetBytesPerIteration() const {return BYTES_PER_ITERATION;} - unsigned int GetIterationsToBuffer() const {return X;} - bool CanOperateKeystream() const {return true;} - virtual void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount) =0; -}; - -// use these to implement OperateKeystream -#define CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, b, i, a) \ - PutWord(bool(x & OUTPUT_ALIGNED), b, output+i*sizeof(WordType), (x & INPUT_NULL) ? a : a ^ GetWord(bool(x & INPUT_ALIGNED), b, input+i*sizeof(WordType))); -#define CRYPTOPP_KEYSTREAM_OUTPUT_XMM(x, i, a) {\ - __m128i t = (x & INPUT_NULL) ? a : _mm_xor_si128(a, (x & INPUT_ALIGNED) ? _mm_load_si128((__m128i *)input+i) : _mm_loadu_si128((__m128i *)input+i));\ - if (x & OUTPUT_ALIGNED) _mm_store_si128((__m128i *)output+i, t);\ - else _mm_storeu_si128((__m128i *)output+i, t);} -#define CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(x, y) \ - switch (operation) \ - { \ - case WRITE_KEYSTREAM: \ - x(WRITE_KEYSTREAM) \ - break; \ - case XOR_KEYSTREAM: \ - x(XOR_KEYSTREAM) \ - input += y; \ - break; \ - case XOR_KEYSTREAM_INPUT_ALIGNED: \ - x(XOR_KEYSTREAM_INPUT_ALIGNED) \ - input += y; \ - break; \ - case XOR_KEYSTREAM_OUTPUT_ALIGNED: \ - x(XOR_KEYSTREAM_OUTPUT_ALIGNED) \ - input += y; \ - break; \ - case WRITE_KEYSTREAM_ALIGNED: \ - x(WRITE_KEYSTREAM_ALIGNED) \ - break; \ - case XOR_KEYSTREAM_BOTH_ALIGNED: \ - x(XOR_KEYSTREAM_BOTH_ALIGNED) \ - input += y; \ - break; \ - } \ - output += y; - -template > -class CRYPTOPP_NO_VTABLE AdditiveCipherTemplate : public BASE, public RandomNumberGenerator -{ -public: - void GenerateBlock(byte *output, size_t size); - void ProcessData(byte *outString, const byte *inString, size_t length); - void Resynchronize(const byte *iv, int length=-1); - unsigned int OptimalBlockSize() const {return this->GetPolicy().GetOptimalBlockSize();} - unsigned int GetOptimalNextBlockSize() const {return (unsigned int)this->m_leftOver;} - unsigned int OptimalDataAlignment() const {return this->GetPolicy().GetAlignment();} - bool IsSelfInverting() const {return true;} - bool IsForwardTransformation() const {return true;} - bool IsRandomAccess() const {return this->GetPolicy().CipherIsRandomAccess();} - void Seek(lword position); - - typedef typename BASE::PolicyInterface PolicyInterface; - -protected: - void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); - - unsigned int GetBufferByteSize(const PolicyInterface &policy) const {return policy.GetBytesPerIteration() * policy.GetIterationsToBuffer();} - - inline byte * KeystreamBufferBegin() {return this->m_buffer.data();} - inline byte * KeystreamBufferEnd() {return (this->m_buffer.data() + this->m_buffer.size());} - - SecByteBlock m_buffer; - size_t m_leftOver; -}; - -class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_CipherAbstractPolicy -{ -public: - virtual ~CFB_CipherAbstractPolicy() {} - virtual unsigned int GetAlignment() const =0; - virtual unsigned int GetBytesPerIteration() const =0; - virtual byte * GetRegisterBegin() =0; - virtual void TransformRegister() =0; - virtual bool CanIterate() const {return false;} - virtual void Iterate(byte *output, const byte *input, CipherDir dir, size_t iterationCount) {assert(false); throw 0;} - virtual void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length) =0; - virtual void CipherResynchronize(const byte *iv, size_t length) {throw NotImplemented("SimpleKeyingInterface: this object doesn't support resynchronization");} -}; - -template -struct CRYPTOPP_NO_VTABLE CFB_CipherConcretePolicy : public BASE -{ - typedef WT WordType; - - unsigned int GetAlignment() const {return sizeof(WordType);} - unsigned int GetBytesPerIteration() const {return sizeof(WordType) * W;} - bool CanIterate() const {return true;} - void TransformRegister() {this->Iterate(NULL, NULL, ENCRYPTION, 1);} - - template - struct RegisterOutput - { - RegisterOutput(byte *output, const byte *input, CipherDir dir) - : m_output(output), m_input(input), m_dir(dir) {} - - inline RegisterOutput& operator()(WordType ®isterWord) - { - assert(IsAligned(m_output)); - assert(IsAligned(m_input)); - - if (!NativeByteOrderIs(B::ToEnum())) - registerWord = ByteReverse(registerWord); - - if (m_dir == ENCRYPTION) - { - if (m_input == NULL) - assert(m_output == NULL); - else - { - WordType ct = *(const WordType *)m_input ^ registerWord; - registerWord = ct; - *(WordType*)m_output = ct; - m_input += sizeof(WordType); - m_output += sizeof(WordType); - } - } - else - { - WordType ct = *(const WordType *)m_input; - *(WordType*)m_output = registerWord ^ ct; - registerWord = ct; - m_input += sizeof(WordType); - m_output += sizeof(WordType); - } - - // registerWord is left unreversed so it can be xor-ed with further input - - return *this; - } - - byte *m_output; - const byte *m_input; - CipherDir m_dir; - }; -}; - -template -class CRYPTOPP_NO_VTABLE CFB_CipherTemplate : public BASE -{ -public: - void ProcessData(byte *outString, const byte *inString, size_t length); - void Resynchronize(const byte *iv, int length=-1); - unsigned int OptimalBlockSize() const {return this->GetPolicy().GetBytesPerIteration();} - unsigned int GetOptimalNextBlockSize() const {return (unsigned int)m_leftOver;} - unsigned int OptimalDataAlignment() const {return this->GetPolicy().GetAlignment();} - bool IsRandomAccess() const {return false;} - bool IsSelfInverting() const {return false;} - - typedef typename BASE::PolicyInterface PolicyInterface; - -protected: - virtual void CombineMessageAndShiftRegister(byte *output, byte *reg, const byte *message, size_t length) =0; - - void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); - - size_t m_leftOver; -}; - -template > -class CRYPTOPP_NO_VTABLE CFB_EncryptionTemplate : public CFB_CipherTemplate -{ - bool IsForwardTransformation() const {return true;} - void CombineMessageAndShiftRegister(byte *output, byte *reg, const byte *message, size_t length); -}; - -template > -class CRYPTOPP_NO_VTABLE CFB_DecryptionTemplate : public CFB_CipherTemplate -{ - bool IsForwardTransformation() const {return false;} - void CombineMessageAndShiftRegister(byte *output, byte *reg, const byte *message, size_t length); -}; - -template -class CFB_RequireFullDataBlocks : public BASE -{ -public: - unsigned int MandatoryBlockSize() const {return this->OptimalBlockSize();} -}; - -//! _ -template -class SymmetricCipherFinal : public AlgorithmImpl, INFO> -{ -public: - SymmetricCipherFinal() {} - SymmetricCipherFinal(const byte *key) - {this->SetKey(key, this->DEFAULT_KEYLENGTH);} - SymmetricCipherFinal(const byte *key, size_t length) - {this->SetKey(key, length);} - SymmetricCipherFinal(const byte *key, size_t length, const byte *iv) - {this->SetKeyWithIV(key, length, iv);} - - Clonable * Clone() const {return static_cast(new SymmetricCipherFinal(*this));} -}; - -NAMESPACE_END - -#ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES -#include "strciphr.cpp" -#endif - -NAMESPACE_BEGIN(CryptoPP) -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractPolicyHolder; -CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate >; -CRYPTOPP_DLL_TEMPLATE_CLASS CFB_CipherTemplate >; -CRYPTOPP_DLL_TEMPLATE_CLASS CFB_EncryptionTemplate >; -CRYPTOPP_DLL_TEMPLATE_CLASS CFB_DecryptionTemplate >; -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/tea.cpp b/lib/cryptopp/tea.cpp deleted file mode 100644 index b1fb6f140..000000000 --- a/lib/cryptopp/tea.cpp +++ /dev/null @@ -1,159 +0,0 @@ -// tea.cpp - modified by Wei Dai from code in the original paper - -#include "pch.h" -#include "tea.h" -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) - -static const word32 DELTA = 0x9e3779b9; -typedef BlockGetAndPut Block; - -void TEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms) -{ - AssertValidKeyLength(length); - - GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, userKey, KEYLENGTH); - m_limit = GetRoundsAndThrowIfInvalid(params, this) * DELTA; -} - -void TEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - word32 y, z; - Block::Get(inBlock)(y)(z); - - word32 sum = 0; - while (sum != m_limit) - { - sum += DELTA; - y += (z << 4) + m_k[0] ^ z + sum ^ (z >> 5) + m_k[1]; - z += (y << 4) + m_k[2] ^ y + sum ^ (y >> 5) + m_k[3]; - } - - Block::Put(xorBlock, outBlock)(y)(z); -} - -void TEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - word32 y, z; - Block::Get(inBlock)(y)(z); - - word32 sum = m_limit; - while (sum != 0) - { - z -= (y << 4) + m_k[2] ^ y + sum ^ (y >> 5) + m_k[3]; - y -= (z << 4) + m_k[0] ^ z + sum ^ (z >> 5) + m_k[1]; - sum -= DELTA; - } - - Block::Put(xorBlock, outBlock)(y)(z); -} - -void XTEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms) -{ - AssertValidKeyLength(length); - - GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, userKey, KEYLENGTH); - m_limit = GetRoundsAndThrowIfInvalid(params, this) * DELTA; -} - -void XTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - word32 y, z; - Block::Get(inBlock)(y)(z); - -#ifdef __SUNPRO_CC - // workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 - size_t sum = 0; - while ((sum&0xffffffff) != m_limit) -#else - word32 sum = 0; - while (sum != m_limit) -#endif - { - y += (z<<4 ^ z>>5) + z ^ sum + m_k[sum&3]; - sum += DELTA; - z += (y<<4 ^ y>>5) + y ^ sum + m_k[sum>>11 & 3]; - } - - Block::Put(xorBlock, outBlock)(y)(z); -} - -void XTEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - word32 y, z; - Block::Get(inBlock)(y)(z); - -#ifdef __SUNPRO_CC - // workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 - size_t sum = m_limit; - while ((sum&0xffffffff) != 0) -#else - word32 sum = m_limit; - while (sum != 0) -#endif - { - z -= (y<<4 ^ y>>5) + y ^ sum + m_k[sum>>11 & 3]; - sum -= DELTA; - y -= (z<<4 ^ z>>5) + z ^ sum + m_k[sum&3]; - } - - Block::Put(xorBlock, outBlock)(y)(z); -} - -#define MX (z>>5^y<<2)+(y>>3^z<<4)^(sum^y)+(m_k[p&3^e]^z) - -void BTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - unsigned int n = m_blockSize / 4; - word32 *v = (word32*)outBlock; - ConditionalByteReverse(BIG_ENDIAN_ORDER, v, (const word32*)inBlock, m_blockSize); - - word32 y = v[0], z = v[n-1], e; - word32 p, q = 6+52/n; - word32 sum = 0; - - while (q-- > 0) - { - sum += DELTA; - e = sum>>2 & 3; - for (p = 0; p < n-1; p++) - { - y = v[p+1]; - z = v[p] += MX; - } - y = v[0]; - z = v[n-1] += MX; - } - - ConditionalByteReverse(BIG_ENDIAN_ORDER, v, v, m_blockSize); -} - -void BTEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const -{ - unsigned int n = m_blockSize / 4; - word32 *v = (word32*)outBlock; - ConditionalByteReverse(BIG_ENDIAN_ORDER, v, (const word32*)inBlock, m_blockSize); - - word32 y = v[0], z = v[n-1], e; - word32 p, q = 6+52/n; - word32 sum = q * DELTA; - - while (sum != 0) - { - e = sum>>2 & 3; - for (p = n-1; p > 0; p--) - { - z = v[p-1]; - y = v[p] -= MX; - } - - z = v[n-1]; - y = v[0] -= MX; - sum -= DELTA; - } - - ConditionalByteReverse(BIG_ENDIAN_ORDER, v, v, m_blockSize); -} - -NAMESPACE_END diff --git a/lib/cryptopp/tea.h b/lib/cryptopp/tea.h deleted file mode 100644 index d8ddded86..000000000 --- a/lib/cryptopp/tea.h +++ /dev/null @@ -1,132 +0,0 @@ -#ifndef CRYPTOPP_TEA_H -#define CRYPTOPP_TEA_H - -/** \file -*/ - -#include "seckey.h" -#include "secblock.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -struct TEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32> -{ - static const char *StaticAlgorithmName() {return "TEA";} -}; - -/// TEA -class TEA : public TEA_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl - { - public: - void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); - - protected: - FixedSizeSecBlock m_k; - word32 m_limit; - }; - - class CRYPTOPP_NO_VTABLE Enc : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - }; - - class CRYPTOPP_NO_VTABLE Dec : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - }; - -public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -typedef TEA::Encryption TEAEncryption; -typedef TEA::Decryption TEADecryption; - -//! _ -struct XTEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32> -{ - static const char *StaticAlgorithmName() {return "XTEA";} -}; - -/// XTEA -class XTEA : public XTEA_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl - { - public: - void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); - - protected: - FixedSizeSecBlock m_k; - word32 m_limit; - }; - - class CRYPTOPP_NO_VTABLE Enc : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - }; - - class CRYPTOPP_NO_VTABLE Dec : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - }; - -public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -//! _ -struct BTEA_Info : public FixedKeyLength<16> -{ - static const char *StaticAlgorithmName() {return "BTEA";} -}; - -//! corrected Block TEA (as described in "xxtea"). -/*! This class hasn't been tested yet. */ -class BTEA : public BTEA_Info, public BlockCipherDocumentation -{ - class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl, BTEA_Info>, public BTEA_Info - { - public: - void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) - { - m_blockSize = params.GetIntValueWithDefault("BlockSize", 60*4); - GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, key, KEYLENGTH); - } - - unsigned int BlockSize() const {return m_blockSize;} - - protected: - FixedSizeSecBlock m_k; - unsigned int m_blockSize; - }; - - class CRYPTOPP_NO_VTABLE Enc : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - }; - - class CRYPTOPP_NO_VTABLE Dec : public Base - { - public: - void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; - }; - -public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/tiger.cpp b/lib/cryptopp/tiger.cpp deleted file mode 100644 index c6c05caed..000000000 --- a/lib/cryptopp/tiger.cpp +++ /dev/null @@ -1,265 +0,0 @@ -// tiger.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "tiger.h" -#include "misc.h" -#include "cpu.h" - -NAMESPACE_BEGIN(CryptoPP) - -void Tiger::InitState(HashWordType *state) -{ - state[0] = W64LIT(0x0123456789ABCDEF); - state[1] = W64LIT(0xFEDCBA9876543210); - state[2] = W64LIT(0xF096A5B4C3B2E187); -} - -void Tiger::TruncatedFinal(byte *hash, size_t size) -{ - ThrowIfInvalidTruncatedSize(size); - - PadLastBlock(56, 0x01); - CorrectEndianess(m_data, m_data, 56); - - m_data[7] = GetBitCountLo(); - - Transform(m_state, m_data); - CorrectEndianess(m_state, m_state, DigestSize()); - memcpy(hash, m_state, size); - - Restart(); // reinit for next use -} - -void Tiger::Transform (word64 *digest, const word64 *X) -{ -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && CRYPTOPP_BOOL_X86 - if (HasSSE2()) - { -#ifdef __GNUC__ - __asm__ __volatile__ - ( - ".intel_syntax noprefix;" - AS1( push ebx) -#else - #if _MSC_VER < 1300 - const word64 *t = table; - AS2( mov edx, t) - #else - AS2( lea edx, [table]) - #endif - AS2( mov eax, digest) - AS2( mov esi, X) -#endif - AS2( movq mm0, [eax]) - AS2( movq mm1, [eax+1*8]) - AS2( movq mm5, mm1) - AS2( movq mm2, [eax+2*8]) - AS2( movq mm7, [edx+4*2048+0*8]) - AS2( movq mm6, [edx+4*2048+1*8]) - AS2( mov ecx, esp) - AS2( and esp, 0xfffffff0) - AS2( sub esp, 8*8) - AS1( push ecx) - -#define SSE2_round(a,b,c,x,mul) \ - AS2( pxor c, [x])\ - AS2( movd ecx, c)\ - AS2( movzx edi, cl)\ - AS2( movq mm3, [edx+0*2048+edi*8])\ - AS2( movzx edi, ch)\ - AS2( movq mm4, [edx+3*2048+edi*8])\ - AS2( shr ecx, 16)\ - AS2( movzx edi, cl)\ - AS2( pxor mm3, [edx+1*2048+edi*8])\ - AS2( movzx edi, ch)\ - AS2( pxor mm4, [edx+2*2048+edi*8])\ - AS3( pextrw ecx, c, 2)\ - AS2( movzx edi, cl)\ - AS2( pxor mm3, [edx+2*2048+edi*8])\ - AS2( movzx edi, ch)\ - AS2( pxor mm4, [edx+1*2048+edi*8])\ - AS3( pextrw ecx, c, 3)\ - AS2( movzx edi, cl)\ - AS2( pxor mm3, [edx+3*2048+edi*8])\ - AS2( psubq a, mm3)\ - AS2( movzx edi, ch)\ - AS2( pxor mm4, [edx+0*2048+edi*8])\ - AS2( paddq b, mm4)\ - SSE2_mul_##mul(b) - -#define SSE2_mul_5(b) \ - AS2( movq mm3, b)\ - AS2( psllq b, 2)\ - AS2( paddq b, mm3) - -#define SSE2_mul_7(b) \ - AS2( movq mm3, b)\ - AS2( psllq b, 3)\ - AS2( psubq b, mm3) - -#define SSE2_mul_9(b) \ - AS2( movq mm3, b)\ - AS2( psllq b, 3)\ - AS2( paddq b, mm3) - -#define label2_5 1 -#define label2_7 2 -#define label2_9 3 - -#define SSE2_pass(A,B,C,mul,X) \ - AS2( xor ebx, ebx)\ - ASL(mul)\ - SSE2_round(A,B,C,X+0*8+ebx,mul)\ - SSE2_round(B,C,A,X+1*8+ebx,mul)\ - AS2( cmp ebx, 6*8)\ - ASJ( je, label2_##mul, f)\ - SSE2_round(C,A,B,X+2*8+ebx,mul)\ - AS2( add ebx, 3*8)\ - ASJ( jmp, mul, b)\ - ASL(label2_##mul) - -#define SSE2_key_schedule(Y,X) \ - AS2( movq mm3, [X+7*8])\ - AS2( pxor mm3, mm6)\ - AS2( movq mm4, [X+0*8])\ - AS2( psubq mm4, mm3)\ - AS2( movq [Y+0*8], mm4)\ - AS2( pxor mm4, [X+1*8])\ - AS2( movq mm3, mm4)\ - AS2( movq [Y+1*8], mm4)\ - AS2( paddq mm4, [X+2*8])\ - AS2( pxor mm3, mm7)\ - AS2( psllq mm3, 19)\ - AS2( movq [Y+2*8], mm4)\ - AS2( pxor mm3, mm4)\ - AS2( movq mm4, [X+3*8])\ - AS2( psubq mm4, mm3)\ - AS2( movq [Y+3*8], mm4)\ - AS2( pxor mm4, [X+4*8])\ - AS2( movq mm3, mm4)\ - AS2( movq [Y+4*8], mm4)\ - AS2( paddq mm4, [X+5*8])\ - AS2( pxor mm3, mm7)\ - AS2( psrlq mm3, 23)\ - AS2( movq [Y+5*8], mm4)\ - AS2( pxor mm3, mm4)\ - AS2( movq mm4, [X+6*8])\ - AS2( psubq mm4, mm3)\ - AS2( movq [Y+6*8], mm4)\ - AS2( pxor mm4, [X+7*8])\ - AS2( movq mm3, mm4)\ - AS2( movq [Y+7*8], mm4)\ - AS2( paddq mm4, [Y+0*8])\ - AS2( pxor mm3, mm7)\ - AS2( psllq mm3, 19)\ - AS2( movq [Y+0*8], mm4)\ - AS2( pxor mm3, mm4)\ - AS2( movq mm4, [Y+1*8])\ - AS2( psubq mm4, mm3)\ - AS2( movq [Y+1*8], mm4)\ - AS2( pxor mm4, [Y+2*8])\ - AS2( movq mm3, mm4)\ - AS2( movq [Y+2*8], mm4)\ - AS2( paddq mm4, [Y+3*8])\ - AS2( pxor mm3, mm7)\ - AS2( psrlq mm3, 23)\ - AS2( movq [Y+3*8], mm4)\ - AS2( pxor mm3, mm4)\ - AS2( movq mm4, [Y+4*8])\ - AS2( psubq mm4, mm3)\ - AS2( movq [Y+4*8], mm4)\ - AS2( pxor mm4, [Y+5*8])\ - AS2( movq [Y+5*8], mm4)\ - AS2( paddq mm4, [Y+6*8])\ - AS2( movq [Y+6*8], mm4)\ - AS2( pxor mm4, [edx+4*2048+2*8])\ - AS2( movq mm3, [Y+7*8])\ - AS2( psubq mm3, mm4)\ - AS2( movq [Y+7*8], mm3) - - SSE2_pass(mm0, mm1, mm2, 5, esi) - SSE2_key_schedule(esp+4, esi) - SSE2_pass(mm2, mm0, mm1, 7, esp+4) - SSE2_key_schedule(esp+4, esp+4) - SSE2_pass(mm1, mm2, mm0, 9, esp+4) - - AS2( pxor mm0, [eax+0*8]) - AS2( movq [eax+0*8], mm0) - AS2( psubq mm1, mm5) - AS2( movq [eax+1*8], mm1) - AS2( paddq mm2, [eax+2*8]) - AS2( movq [eax+2*8], mm2) - - AS1( pop esp) - AS1( emms) -#ifdef __GNUC__ - AS1( pop ebx) - ".att_syntax prefix;" - : - : "a" (digest), "S" (X), "d" (table) - : "%ecx", "%edi", "memory", "cc" - ); -#endif - } - else -#endif - { - word64 a = digest[0]; - word64 b = digest[1]; - word64 c = digest[2]; - word64 Y[8]; - -#define t1 (table) -#define t2 (table+256) -#define t3 (table+256*2) -#define t4 (table+256*3) - -#define round(a,b,c,x,mul) \ - c ^= x; \ - a -= t1[GETBYTE(c,0)] ^ t2[GETBYTE(c,2)] ^ t3[GETBYTE(c,4)] ^ t4[GETBYTE(c,6)]; \ - b += t4[GETBYTE(c,1)] ^ t3[GETBYTE(c,3)] ^ t2[GETBYTE(c,5)] ^ t1[GETBYTE(c,7)]; \ - b *= mul - -#define pass(a,b,c,mul,X) {\ - int i=0;\ - while (true)\ - {\ - round(a,b,c,X[i+0],mul); \ - round(b,c,a,X[i+1],mul); \ - if (i==6)\ - break;\ - round(c,a,b,X[i+2],mul); \ - i+=3;\ - }} - -#define key_schedule(Y,X) \ - Y[0] = X[0] - (X[7]^W64LIT(0xA5A5A5A5A5A5A5A5)); \ - Y[1] = X[1] ^ Y[0]; \ - Y[2] = X[2] + Y[1]; \ - Y[3] = X[3] - (Y[2] ^ ((~Y[1])<<19)); \ - Y[4] = X[4] ^ Y[3]; \ - Y[5] = X[5] + Y[4]; \ - Y[6] = X[6] - (Y[5] ^ ((~Y[4])>>23)); \ - Y[7] = X[7] ^ Y[6]; \ - Y[0] += Y[7]; \ - Y[1] -= Y[0] ^ ((~Y[7])<<19); \ - Y[2] ^= Y[1]; \ - Y[3] += Y[2]; \ - Y[4] -= Y[3] ^ ((~Y[2])>>23); \ - Y[5] ^= Y[4]; \ - Y[6] += Y[5]; \ - Y[7] -= Y[6] ^ W64LIT(0x0123456789ABCDEF) - - pass(a,b,c,5,X); - key_schedule(Y,X); - pass(c,a,b,7,Y); - key_schedule(Y,Y); - pass(b,c,a,9,Y); - - digest[0] = a ^ digest[0]; - digest[1] = b - digest[1]; - digest[2] = c + digest[2]; - } -} - -NAMESPACE_END diff --git a/lib/cryptopp/tiger.h b/lib/cryptopp/tiger.h deleted file mode 100644 index 5f6e941ac..000000000 --- a/lib/cryptopp/tiger.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef CRYPTOPP_TIGER_H -#define CRYPTOPP_TIGER_H - -#include "config.h" -#include "iterhash.h" - -NAMESPACE_BEGIN(CryptoPP) - -/// Tiger -class Tiger : public IteratedHashWithStaticTransform -{ -public: - static void InitState(HashWordType *state); - static void Transform(word64 *digest, const word64 *data); - void TruncatedFinal(byte *hash, size_t size); - static const char * StaticAlgorithmName() {return "Tiger";} - -protected: - static const word64 table[4*256+3]; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/tigertab.cpp b/lib/cryptopp/tigertab.cpp deleted file mode 100644 index 5c1595b5b..000000000 --- a/lib/cryptopp/tigertab.cpp +++ /dev/null @@ -1,525 +0,0 @@ -#include "pch.h" -#include "tiger.h" - -NAMESPACE_BEGIN(CryptoPP) - -const word64 Tiger::table[4*256+3] = -{ - W64LIT(0x02AAB17CF7E90C5E) /* 0 */, W64LIT(0xAC424B03E243A8EC) /* 1 */, - W64LIT(0x72CD5BE30DD5FCD3) /* 2 */, W64LIT(0x6D019B93F6F97F3A) /* 3 */, - W64LIT(0xCD9978FFD21F9193) /* 4 */, W64LIT(0x7573A1C9708029E2) /* 5 */, - W64LIT(0xB164326B922A83C3) /* 6 */, W64LIT(0x46883EEE04915870) /* 7 */, - W64LIT(0xEAACE3057103ECE6) /* 8 */, W64LIT(0xC54169B808A3535C) /* 9 */, - W64LIT(0x4CE754918DDEC47C) /* 10 */, W64LIT(0x0AA2F4DFDC0DF40C) /* 11 */, - W64LIT(0x10B76F18A74DBEFA) /* 12 */, W64LIT(0xC6CCB6235AD1AB6A) /* 13 */, - W64LIT(0x13726121572FE2FF) /* 14 */, W64LIT(0x1A488C6F199D921E) /* 15 */, - W64LIT(0x4BC9F9F4DA0007CA) /* 16 */, W64LIT(0x26F5E6F6E85241C7) /* 17 */, - W64LIT(0x859079DBEA5947B6) /* 18 */, W64LIT(0x4F1885C5C99E8C92) /* 19 */, - W64LIT(0xD78E761EA96F864B) /* 20 */, W64LIT(0x8E36428C52B5C17D) /* 21 */, - W64LIT(0x69CF6827373063C1) /* 22 */, W64LIT(0xB607C93D9BB4C56E) /* 23 */, - W64LIT(0x7D820E760E76B5EA) /* 24 */, W64LIT(0x645C9CC6F07FDC42) /* 25 */, - W64LIT(0xBF38A078243342E0) /* 26 */, W64LIT(0x5F6B343C9D2E7D04) /* 27 */, - W64LIT(0xF2C28AEB600B0EC6) /* 28 */, W64LIT(0x6C0ED85F7254BCAC) /* 29 */, - W64LIT(0x71592281A4DB4FE5) /* 30 */, W64LIT(0x1967FA69CE0FED9F) /* 31 */, - W64LIT(0xFD5293F8B96545DB) /* 32 */, W64LIT(0xC879E9D7F2A7600B) /* 33 */, - W64LIT(0x860248920193194E) /* 34 */, W64LIT(0xA4F9533B2D9CC0B3) /* 35 */, - W64LIT(0x9053836C15957613) /* 36 */, W64LIT(0xDB6DCF8AFC357BF1) /* 37 */, - W64LIT(0x18BEEA7A7A370F57) /* 38 */, W64LIT(0x037117CA50B99066) /* 39 */, - W64LIT(0x6AB30A9774424A35) /* 40 */, W64LIT(0xF4E92F02E325249B) /* 41 */, - W64LIT(0x7739DB07061CCAE1) /* 42 */, W64LIT(0xD8F3B49CECA42A05) /* 43 */, - W64LIT(0xBD56BE3F51382F73) /* 44 */, W64LIT(0x45FAED5843B0BB28) /* 45 */, - W64LIT(0x1C813D5C11BF1F83) /* 46 */, W64LIT(0x8AF0E4B6D75FA169) /* 47 */, - W64LIT(0x33EE18A487AD9999) /* 48 */, W64LIT(0x3C26E8EAB1C94410) /* 49 */, - W64LIT(0xB510102BC0A822F9) /* 50 */, W64LIT(0x141EEF310CE6123B) /* 51 */, - W64LIT(0xFC65B90059DDB154) /* 52 */, W64LIT(0xE0158640C5E0E607) /* 53 */, - W64LIT(0x884E079826C3A3CF) /* 54 */, W64LIT(0x930D0D9523C535FD) /* 55 */, - W64LIT(0x35638D754E9A2B00) /* 56 */, W64LIT(0x4085FCCF40469DD5) /* 57 */, - W64LIT(0xC4B17AD28BE23A4C) /* 58 */, W64LIT(0xCAB2F0FC6A3E6A2E) /* 59 */, - W64LIT(0x2860971A6B943FCD) /* 60 */, W64LIT(0x3DDE6EE212E30446) /* 61 */, - W64LIT(0x6222F32AE01765AE) /* 62 */, W64LIT(0x5D550BB5478308FE) /* 63 */, - W64LIT(0xA9EFA98DA0EDA22A) /* 64 */, W64LIT(0xC351A71686C40DA7) /* 65 */, - W64LIT(0x1105586D9C867C84) /* 66 */, W64LIT(0xDCFFEE85FDA22853) /* 67 */, - W64LIT(0xCCFBD0262C5EEF76) /* 68 */, W64LIT(0xBAF294CB8990D201) /* 69 */, - W64LIT(0xE69464F52AFAD975) /* 70 */, W64LIT(0x94B013AFDF133E14) /* 71 */, - W64LIT(0x06A7D1A32823C958) /* 72 */, W64LIT(0x6F95FE5130F61119) /* 73 */, - W64LIT(0xD92AB34E462C06C0) /* 74 */, W64LIT(0xED7BDE33887C71D2) /* 75 */, - W64LIT(0x79746D6E6518393E) /* 76 */, W64LIT(0x5BA419385D713329) /* 77 */, - W64LIT(0x7C1BA6B948A97564) /* 78 */, W64LIT(0x31987C197BFDAC67) /* 79 */, - W64LIT(0xDE6C23C44B053D02) /* 80 */, W64LIT(0x581C49FED002D64D) /* 81 */, - W64LIT(0xDD474D6338261571) /* 82 */, W64LIT(0xAA4546C3E473D062) /* 83 */, - W64LIT(0x928FCE349455F860) /* 84 */, W64LIT(0x48161BBACAAB94D9) /* 85 */, - W64LIT(0x63912430770E6F68) /* 86 */, W64LIT(0x6EC8A5E602C6641C) /* 87 */, - W64LIT(0x87282515337DDD2B) /* 88 */, W64LIT(0x2CDA6B42034B701B) /* 89 */, - W64LIT(0xB03D37C181CB096D) /* 90 */, W64LIT(0xE108438266C71C6F) /* 91 */, - W64LIT(0x2B3180C7EB51B255) /* 92 */, W64LIT(0xDF92B82F96C08BBC) /* 93 */, - W64LIT(0x5C68C8C0A632F3BA) /* 94 */, W64LIT(0x5504CC861C3D0556) /* 95 */, - W64LIT(0xABBFA4E55FB26B8F) /* 96 */, W64LIT(0x41848B0AB3BACEB4) /* 97 */, - W64LIT(0xB334A273AA445D32) /* 98 */, W64LIT(0xBCA696F0A85AD881) /* 99 */, - W64LIT(0x24F6EC65B528D56C) /* 100 */, W64LIT(0x0CE1512E90F4524A) /* 101 */, - W64LIT(0x4E9DD79D5506D35A) /* 102 */, W64LIT(0x258905FAC6CE9779) /* 103 */, - W64LIT(0x2019295B3E109B33) /* 104 */, W64LIT(0xF8A9478B73A054CC) /* 105 */, - W64LIT(0x2924F2F934417EB0) /* 106 */, W64LIT(0x3993357D536D1BC4) /* 107 */, - W64LIT(0x38A81AC21DB6FF8B) /* 108 */, W64LIT(0x47C4FBF17D6016BF) /* 109 */, - W64LIT(0x1E0FAADD7667E3F5) /* 110 */, W64LIT(0x7ABCFF62938BEB96) /* 111 */, - W64LIT(0xA78DAD948FC179C9) /* 112 */, W64LIT(0x8F1F98B72911E50D) /* 113 */, - W64LIT(0x61E48EAE27121A91) /* 114 */, W64LIT(0x4D62F7AD31859808) /* 115 */, - W64LIT(0xECEBA345EF5CEAEB) /* 116 */, W64LIT(0xF5CEB25EBC9684CE) /* 117 */, - W64LIT(0xF633E20CB7F76221) /* 118 */, W64LIT(0xA32CDF06AB8293E4) /* 119 */, - W64LIT(0x985A202CA5EE2CA4) /* 120 */, W64LIT(0xCF0B8447CC8A8FB1) /* 121 */, - W64LIT(0x9F765244979859A3) /* 122 */, W64LIT(0xA8D516B1A1240017) /* 123 */, - W64LIT(0x0BD7BA3EBB5DC726) /* 124 */, W64LIT(0xE54BCA55B86ADB39) /* 125 */, - W64LIT(0x1D7A3AFD6C478063) /* 126 */, W64LIT(0x519EC608E7669EDD) /* 127 */, - W64LIT(0x0E5715A2D149AA23) /* 128 */, W64LIT(0x177D4571848FF194) /* 129 */, - W64LIT(0xEEB55F3241014C22) /* 130 */, W64LIT(0x0F5E5CA13A6E2EC2) /* 131 */, - W64LIT(0x8029927B75F5C361) /* 132 */, W64LIT(0xAD139FABC3D6E436) /* 133 */, - W64LIT(0x0D5DF1A94CCF402F) /* 134 */, W64LIT(0x3E8BD948BEA5DFC8) /* 135 */, - W64LIT(0xA5A0D357BD3FF77E) /* 136 */, W64LIT(0xA2D12E251F74F645) /* 137 */, - W64LIT(0x66FD9E525E81A082) /* 138 */, W64LIT(0x2E0C90CE7F687A49) /* 139 */, - W64LIT(0xC2E8BCBEBA973BC5) /* 140 */, W64LIT(0x000001BCE509745F) /* 141 */, - W64LIT(0x423777BBE6DAB3D6) /* 142 */, W64LIT(0xD1661C7EAEF06EB5) /* 143 */, - W64LIT(0xA1781F354DAACFD8) /* 144 */, W64LIT(0x2D11284A2B16AFFC) /* 145 */, - W64LIT(0xF1FC4F67FA891D1F) /* 146 */, W64LIT(0x73ECC25DCB920ADA) /* 147 */, - W64LIT(0xAE610C22C2A12651) /* 148 */, W64LIT(0x96E0A810D356B78A) /* 149 */, - W64LIT(0x5A9A381F2FE7870F) /* 150 */, W64LIT(0xD5AD62EDE94E5530) /* 151 */, - W64LIT(0xD225E5E8368D1427) /* 152 */, W64LIT(0x65977B70C7AF4631) /* 153 */, - W64LIT(0x99F889B2DE39D74F) /* 154 */, W64LIT(0x233F30BF54E1D143) /* 155 */, - W64LIT(0x9A9675D3D9A63C97) /* 156 */, W64LIT(0x5470554FF334F9A8) /* 157 */, - W64LIT(0x166ACB744A4F5688) /* 158 */, W64LIT(0x70C74CAAB2E4AEAD) /* 159 */, - W64LIT(0xF0D091646F294D12) /* 160 */, W64LIT(0x57B82A89684031D1) /* 161 */, - W64LIT(0xEFD95A5A61BE0B6B) /* 162 */, W64LIT(0x2FBD12E969F2F29A) /* 163 */, - W64LIT(0x9BD37013FEFF9FE8) /* 164 */, W64LIT(0x3F9B0404D6085A06) /* 165 */, - W64LIT(0x4940C1F3166CFE15) /* 166 */, W64LIT(0x09542C4DCDF3DEFB) /* 167 */, - W64LIT(0xB4C5218385CD5CE3) /* 168 */, W64LIT(0xC935B7DC4462A641) /* 169 */, - W64LIT(0x3417F8A68ED3B63F) /* 170 */, W64LIT(0xB80959295B215B40) /* 171 */, - W64LIT(0xF99CDAEF3B8C8572) /* 172 */, W64LIT(0x018C0614F8FCB95D) /* 173 */, - W64LIT(0x1B14ACCD1A3ACDF3) /* 174 */, W64LIT(0x84D471F200BB732D) /* 175 */, - W64LIT(0xC1A3110E95E8DA16) /* 176 */, W64LIT(0x430A7220BF1A82B8) /* 177 */, - W64LIT(0xB77E090D39DF210E) /* 178 */, W64LIT(0x5EF4BD9F3CD05E9D) /* 179 */, - W64LIT(0x9D4FF6DA7E57A444) /* 180 */, W64LIT(0xDA1D60E183D4A5F8) /* 181 */, - W64LIT(0xB287C38417998E47) /* 182 */, W64LIT(0xFE3EDC121BB31886) /* 183 */, - W64LIT(0xC7FE3CCC980CCBEF) /* 184 */, W64LIT(0xE46FB590189BFD03) /* 185 */, - W64LIT(0x3732FD469A4C57DC) /* 186 */, W64LIT(0x7EF700A07CF1AD65) /* 187 */, - W64LIT(0x59C64468A31D8859) /* 188 */, W64LIT(0x762FB0B4D45B61F6) /* 189 */, - W64LIT(0x155BAED099047718) /* 190 */, W64LIT(0x68755E4C3D50BAA6) /* 191 */, - W64LIT(0xE9214E7F22D8B4DF) /* 192 */, W64LIT(0x2ADDBF532EAC95F4) /* 193 */, - W64LIT(0x32AE3909B4BD0109) /* 194 */, W64LIT(0x834DF537B08E3450) /* 195 */, - W64LIT(0xFA209DA84220728D) /* 196 */, W64LIT(0x9E691D9B9EFE23F7) /* 197 */, - W64LIT(0x0446D288C4AE8D7F) /* 198 */, W64LIT(0x7B4CC524E169785B) /* 199 */, - W64LIT(0x21D87F0135CA1385) /* 200 */, W64LIT(0xCEBB400F137B8AA5) /* 201 */, - W64LIT(0x272E2B66580796BE) /* 202 */, W64LIT(0x3612264125C2B0DE) /* 203 */, - W64LIT(0x057702BDAD1EFBB2) /* 204 */, W64LIT(0xD4BABB8EACF84BE9) /* 205 */, - W64LIT(0x91583139641BC67B) /* 206 */, W64LIT(0x8BDC2DE08036E024) /* 207 */, - W64LIT(0x603C8156F49F68ED) /* 208 */, W64LIT(0xF7D236F7DBEF5111) /* 209 */, - W64LIT(0x9727C4598AD21E80) /* 210 */, W64LIT(0xA08A0896670A5FD7) /* 211 */, - W64LIT(0xCB4A8F4309EBA9CB) /* 212 */, W64LIT(0x81AF564B0F7036A1) /* 213 */, - W64LIT(0xC0B99AA778199ABD) /* 214 */, W64LIT(0x959F1EC83FC8E952) /* 215 */, - W64LIT(0x8C505077794A81B9) /* 216 */, W64LIT(0x3ACAAF8F056338F0) /* 217 */, - W64LIT(0x07B43F50627A6778) /* 218 */, W64LIT(0x4A44AB49F5ECCC77) /* 219 */, - W64LIT(0x3BC3D6E4B679EE98) /* 220 */, W64LIT(0x9CC0D4D1CF14108C) /* 221 */, - W64LIT(0x4406C00B206BC8A0) /* 222 */, W64LIT(0x82A18854C8D72D89) /* 223 */, - W64LIT(0x67E366B35C3C432C) /* 224 */, W64LIT(0xB923DD61102B37F2) /* 225 */, - W64LIT(0x56AB2779D884271D) /* 226 */, W64LIT(0xBE83E1B0FF1525AF) /* 227 */, - W64LIT(0xFB7C65D4217E49A9) /* 228 */, W64LIT(0x6BDBE0E76D48E7D4) /* 229 */, - W64LIT(0x08DF828745D9179E) /* 230 */, W64LIT(0x22EA6A9ADD53BD34) /* 231 */, - W64LIT(0xE36E141C5622200A) /* 232 */, W64LIT(0x7F805D1B8CB750EE) /* 233 */, - W64LIT(0xAFE5C7A59F58E837) /* 234 */, W64LIT(0xE27F996A4FB1C23C) /* 235 */, - W64LIT(0xD3867DFB0775F0D0) /* 236 */, W64LIT(0xD0E673DE6E88891A) /* 237 */, - W64LIT(0x123AEB9EAFB86C25) /* 238 */, W64LIT(0x30F1D5D5C145B895) /* 239 */, - W64LIT(0xBB434A2DEE7269E7) /* 240 */, W64LIT(0x78CB67ECF931FA38) /* 241 */, - W64LIT(0xF33B0372323BBF9C) /* 242 */, W64LIT(0x52D66336FB279C74) /* 243 */, - W64LIT(0x505F33AC0AFB4EAA) /* 244 */, W64LIT(0xE8A5CD99A2CCE187) /* 245 */, - W64LIT(0x534974801E2D30BB) /* 246 */, W64LIT(0x8D2D5711D5876D90) /* 247 */, - W64LIT(0x1F1A412891BC038E) /* 248 */, W64LIT(0xD6E2E71D82E56648) /* 249 */, - W64LIT(0x74036C3A497732B7) /* 250 */, W64LIT(0x89B67ED96361F5AB) /* 251 */, - W64LIT(0xFFED95D8F1EA02A2) /* 252 */, W64LIT(0xE72B3BD61464D43D) /* 253 */, - W64LIT(0xA6300F170BDC4820) /* 254 */, W64LIT(0xEBC18760ED78A77A) /* 255 */, - W64LIT(0xE6A6BE5A05A12138) /* 256 */, W64LIT(0xB5A122A5B4F87C98) /* 257 */, - W64LIT(0x563C6089140B6990) /* 258 */, W64LIT(0x4C46CB2E391F5DD5) /* 259 */, - W64LIT(0xD932ADDBC9B79434) /* 260 */, W64LIT(0x08EA70E42015AFF5) /* 261 */, - W64LIT(0xD765A6673E478CF1) /* 262 */, W64LIT(0xC4FB757EAB278D99) /* 263 */, - W64LIT(0xDF11C6862D6E0692) /* 264 */, W64LIT(0xDDEB84F10D7F3B16) /* 265 */, - W64LIT(0x6F2EF604A665EA04) /* 266 */, W64LIT(0x4A8E0F0FF0E0DFB3) /* 267 */, - W64LIT(0xA5EDEEF83DBCBA51) /* 268 */, W64LIT(0xFC4F0A2A0EA4371E) /* 269 */, - W64LIT(0xE83E1DA85CB38429) /* 270 */, W64LIT(0xDC8FF882BA1B1CE2) /* 271 */, - W64LIT(0xCD45505E8353E80D) /* 272 */, W64LIT(0x18D19A00D4DB0717) /* 273 */, - W64LIT(0x34A0CFEDA5F38101) /* 274 */, W64LIT(0x0BE77E518887CAF2) /* 275 */, - W64LIT(0x1E341438B3C45136) /* 276 */, W64LIT(0xE05797F49089CCF9) /* 277 */, - W64LIT(0xFFD23F9DF2591D14) /* 278 */, W64LIT(0x543DDA228595C5CD) /* 279 */, - W64LIT(0x661F81FD99052A33) /* 280 */, W64LIT(0x8736E641DB0F7B76) /* 281 */, - W64LIT(0x15227725418E5307) /* 282 */, W64LIT(0xE25F7F46162EB2FA) /* 283 */, - W64LIT(0x48A8B2126C13D9FE) /* 284 */, W64LIT(0xAFDC541792E76EEA) /* 285 */, - W64LIT(0x03D912BFC6D1898F) /* 286 */, W64LIT(0x31B1AAFA1B83F51B) /* 287 */, - W64LIT(0xF1AC2796E42AB7D9) /* 288 */, W64LIT(0x40A3A7D7FCD2EBAC) /* 289 */, - W64LIT(0x1056136D0AFBBCC5) /* 290 */, W64LIT(0x7889E1DD9A6D0C85) /* 291 */, - W64LIT(0xD33525782A7974AA) /* 292 */, W64LIT(0xA7E25D09078AC09B) /* 293 */, - W64LIT(0xBD4138B3EAC6EDD0) /* 294 */, W64LIT(0x920ABFBE71EB9E70) /* 295 */, - W64LIT(0xA2A5D0F54FC2625C) /* 296 */, W64LIT(0xC054E36B0B1290A3) /* 297 */, - W64LIT(0xF6DD59FF62FE932B) /* 298 */, W64LIT(0x3537354511A8AC7D) /* 299 */, - W64LIT(0xCA845E9172FADCD4) /* 300 */, W64LIT(0x84F82B60329D20DC) /* 301 */, - W64LIT(0x79C62CE1CD672F18) /* 302 */, W64LIT(0x8B09A2ADD124642C) /* 303 */, - W64LIT(0xD0C1E96A19D9E726) /* 304 */, W64LIT(0x5A786A9B4BA9500C) /* 305 */, - W64LIT(0x0E020336634C43F3) /* 306 */, W64LIT(0xC17B474AEB66D822) /* 307 */, - W64LIT(0x6A731AE3EC9BAAC2) /* 308 */, W64LIT(0x8226667AE0840258) /* 309 */, - W64LIT(0x67D4567691CAECA5) /* 310 */, W64LIT(0x1D94155C4875ADB5) /* 311 */, - W64LIT(0x6D00FD985B813FDF) /* 312 */, W64LIT(0x51286EFCB774CD06) /* 313 */, - W64LIT(0x5E8834471FA744AF) /* 314 */, W64LIT(0xF72CA0AEE761AE2E) /* 315 */, - W64LIT(0xBE40E4CDAEE8E09A) /* 316 */, W64LIT(0xE9970BBB5118F665) /* 317 */, - W64LIT(0x726E4BEB33DF1964) /* 318 */, W64LIT(0x703B000729199762) /* 319 */, - W64LIT(0x4631D816F5EF30A7) /* 320 */, W64LIT(0xB880B5B51504A6BE) /* 321 */, - W64LIT(0x641793C37ED84B6C) /* 322 */, W64LIT(0x7B21ED77F6E97D96) /* 323 */, - W64LIT(0x776306312EF96B73) /* 324 */, W64LIT(0xAE528948E86FF3F4) /* 325 */, - W64LIT(0x53DBD7F286A3F8F8) /* 326 */, W64LIT(0x16CADCE74CFC1063) /* 327 */, - W64LIT(0x005C19BDFA52C6DD) /* 328 */, W64LIT(0x68868F5D64D46AD3) /* 329 */, - W64LIT(0x3A9D512CCF1E186A) /* 330 */, W64LIT(0x367E62C2385660AE) /* 331 */, - W64LIT(0xE359E7EA77DCB1D7) /* 332 */, W64LIT(0x526C0773749ABE6E) /* 333 */, - W64LIT(0x735AE5F9D09F734B) /* 334 */, W64LIT(0x493FC7CC8A558BA8) /* 335 */, - W64LIT(0xB0B9C1533041AB45) /* 336 */, W64LIT(0x321958BA470A59BD) /* 337 */, - W64LIT(0x852DB00B5F46C393) /* 338 */, W64LIT(0x91209B2BD336B0E5) /* 339 */, - W64LIT(0x6E604F7D659EF19F) /* 340 */, W64LIT(0xB99A8AE2782CCB24) /* 341 */, - W64LIT(0xCCF52AB6C814C4C7) /* 342 */, W64LIT(0x4727D9AFBE11727B) /* 343 */, - W64LIT(0x7E950D0C0121B34D) /* 344 */, W64LIT(0x756F435670AD471F) /* 345 */, - W64LIT(0xF5ADD442615A6849) /* 346 */, W64LIT(0x4E87E09980B9957A) /* 347 */, - W64LIT(0x2ACFA1DF50AEE355) /* 348 */, W64LIT(0xD898263AFD2FD556) /* 349 */, - W64LIT(0xC8F4924DD80C8FD6) /* 350 */, W64LIT(0xCF99CA3D754A173A) /* 351 */, - W64LIT(0xFE477BACAF91BF3C) /* 352 */, W64LIT(0xED5371F6D690C12D) /* 353 */, - W64LIT(0x831A5C285E687094) /* 354 */, W64LIT(0xC5D3C90A3708A0A4) /* 355 */, - W64LIT(0x0F7F903717D06580) /* 356 */, W64LIT(0x19F9BB13B8FDF27F) /* 357 */, - W64LIT(0xB1BD6F1B4D502843) /* 358 */, W64LIT(0x1C761BA38FFF4012) /* 359 */, - W64LIT(0x0D1530C4E2E21F3B) /* 360 */, W64LIT(0x8943CE69A7372C8A) /* 361 */, - W64LIT(0xE5184E11FEB5CE66) /* 362 */, W64LIT(0x618BDB80BD736621) /* 363 */, - W64LIT(0x7D29BAD68B574D0B) /* 364 */, W64LIT(0x81BB613E25E6FE5B) /* 365 */, - W64LIT(0x071C9C10BC07913F) /* 366 */, W64LIT(0xC7BEEB7909AC2D97) /* 367 */, - W64LIT(0xC3E58D353BC5D757) /* 368 */, W64LIT(0xEB017892F38F61E8) /* 369 */, - W64LIT(0xD4EFFB9C9B1CC21A) /* 370 */, W64LIT(0x99727D26F494F7AB) /* 371 */, - W64LIT(0xA3E063A2956B3E03) /* 372 */, W64LIT(0x9D4A8B9A4AA09C30) /* 373 */, - W64LIT(0x3F6AB7D500090FB4) /* 374 */, W64LIT(0x9CC0F2A057268AC0) /* 375 */, - W64LIT(0x3DEE9D2DEDBF42D1) /* 376 */, W64LIT(0x330F49C87960A972) /* 377 */, - W64LIT(0xC6B2720287421B41) /* 378 */, W64LIT(0x0AC59EC07C00369C) /* 379 */, - W64LIT(0xEF4EAC49CB353425) /* 380 */, W64LIT(0xF450244EEF0129D8) /* 381 */, - W64LIT(0x8ACC46E5CAF4DEB6) /* 382 */, W64LIT(0x2FFEAB63989263F7) /* 383 */, - W64LIT(0x8F7CB9FE5D7A4578) /* 384 */, W64LIT(0x5BD8F7644E634635) /* 385 */, - W64LIT(0x427A7315BF2DC900) /* 386 */, W64LIT(0x17D0C4AA2125261C) /* 387 */, - W64LIT(0x3992486C93518E50) /* 388 */, W64LIT(0xB4CBFEE0A2D7D4C3) /* 389 */, - W64LIT(0x7C75D6202C5DDD8D) /* 390 */, W64LIT(0xDBC295D8E35B6C61) /* 391 */, - W64LIT(0x60B369D302032B19) /* 392 */, W64LIT(0xCE42685FDCE44132) /* 393 */, - W64LIT(0x06F3DDB9DDF65610) /* 394 */, W64LIT(0x8EA4D21DB5E148F0) /* 395 */, - W64LIT(0x20B0FCE62FCD496F) /* 396 */, W64LIT(0x2C1B912358B0EE31) /* 397 */, - W64LIT(0xB28317B818F5A308) /* 398 */, W64LIT(0xA89C1E189CA6D2CF) /* 399 */, - W64LIT(0x0C6B18576AAADBC8) /* 400 */, W64LIT(0xB65DEAA91299FAE3) /* 401 */, - W64LIT(0xFB2B794B7F1027E7) /* 402 */, W64LIT(0x04E4317F443B5BEB) /* 403 */, - W64LIT(0x4B852D325939D0A6) /* 404 */, W64LIT(0xD5AE6BEEFB207FFC) /* 405 */, - W64LIT(0x309682B281C7D374) /* 406 */, W64LIT(0xBAE309A194C3B475) /* 407 */, - W64LIT(0x8CC3F97B13B49F05) /* 408 */, W64LIT(0x98A9422FF8293967) /* 409 */, - W64LIT(0x244B16B01076FF7C) /* 410 */, W64LIT(0xF8BF571C663D67EE) /* 411 */, - W64LIT(0x1F0D6758EEE30DA1) /* 412 */, W64LIT(0xC9B611D97ADEB9B7) /* 413 */, - W64LIT(0xB7AFD5887B6C57A2) /* 414 */, W64LIT(0x6290AE846B984FE1) /* 415 */, - W64LIT(0x94DF4CDEACC1A5FD) /* 416 */, W64LIT(0x058A5BD1C5483AFF) /* 417 */, - W64LIT(0x63166CC142BA3C37) /* 418 */, W64LIT(0x8DB8526EB2F76F40) /* 419 */, - W64LIT(0xE10880036F0D6D4E) /* 420 */, W64LIT(0x9E0523C9971D311D) /* 421 */, - W64LIT(0x45EC2824CC7CD691) /* 422 */, W64LIT(0x575B8359E62382C9) /* 423 */, - W64LIT(0xFA9E400DC4889995) /* 424 */, W64LIT(0xD1823ECB45721568) /* 425 */, - W64LIT(0xDAFD983B8206082F) /* 426 */, W64LIT(0xAA7D29082386A8CB) /* 427 */, - W64LIT(0x269FCD4403B87588) /* 428 */, W64LIT(0x1B91F5F728BDD1E0) /* 429 */, - W64LIT(0xE4669F39040201F6) /* 430 */, W64LIT(0x7A1D7C218CF04ADE) /* 431 */, - W64LIT(0x65623C29D79CE5CE) /* 432 */, W64LIT(0x2368449096C00BB1) /* 433 */, - W64LIT(0xAB9BF1879DA503BA) /* 434 */, W64LIT(0xBC23ECB1A458058E) /* 435 */, - W64LIT(0x9A58DF01BB401ECC) /* 436 */, W64LIT(0xA070E868A85F143D) /* 437 */, - W64LIT(0x4FF188307DF2239E) /* 438 */, W64LIT(0x14D565B41A641183) /* 439 */, - W64LIT(0xEE13337452701602) /* 440 */, W64LIT(0x950E3DCF3F285E09) /* 441 */, - W64LIT(0x59930254B9C80953) /* 442 */, W64LIT(0x3BF299408930DA6D) /* 443 */, - W64LIT(0xA955943F53691387) /* 444 */, W64LIT(0xA15EDECAA9CB8784) /* 445 */, - W64LIT(0x29142127352BE9A0) /* 446 */, W64LIT(0x76F0371FFF4E7AFB) /* 447 */, - W64LIT(0x0239F450274F2228) /* 448 */, W64LIT(0xBB073AF01D5E868B) /* 449 */, - W64LIT(0xBFC80571C10E96C1) /* 450 */, W64LIT(0xD267088568222E23) /* 451 */, - W64LIT(0x9671A3D48E80B5B0) /* 452 */, W64LIT(0x55B5D38AE193BB81) /* 453 */, - W64LIT(0x693AE2D0A18B04B8) /* 454 */, W64LIT(0x5C48B4ECADD5335F) /* 455 */, - W64LIT(0xFD743B194916A1CA) /* 456 */, W64LIT(0x2577018134BE98C4) /* 457 */, - W64LIT(0xE77987E83C54A4AD) /* 458 */, W64LIT(0x28E11014DA33E1B9) /* 459 */, - W64LIT(0x270CC59E226AA213) /* 460 */, W64LIT(0x71495F756D1A5F60) /* 461 */, - W64LIT(0x9BE853FB60AFEF77) /* 462 */, W64LIT(0xADC786A7F7443DBF) /* 463 */, - W64LIT(0x0904456173B29A82) /* 464 */, W64LIT(0x58BC7A66C232BD5E) /* 465 */, - W64LIT(0xF306558C673AC8B2) /* 466 */, W64LIT(0x41F639C6B6C9772A) /* 467 */, - W64LIT(0x216DEFE99FDA35DA) /* 468 */, W64LIT(0x11640CC71C7BE615) /* 469 */, - W64LIT(0x93C43694565C5527) /* 470 */, W64LIT(0xEA038E6246777839) /* 471 */, - W64LIT(0xF9ABF3CE5A3E2469) /* 472 */, W64LIT(0x741E768D0FD312D2) /* 473 */, - W64LIT(0x0144B883CED652C6) /* 474 */, W64LIT(0xC20B5A5BA33F8552) /* 475 */, - W64LIT(0x1AE69633C3435A9D) /* 476 */, W64LIT(0x97A28CA4088CFDEC) /* 477 */, - W64LIT(0x8824A43C1E96F420) /* 478 */, W64LIT(0x37612FA66EEEA746) /* 479 */, - W64LIT(0x6B4CB165F9CF0E5A) /* 480 */, W64LIT(0x43AA1C06A0ABFB4A) /* 481 */, - W64LIT(0x7F4DC26FF162796B) /* 482 */, W64LIT(0x6CBACC8E54ED9B0F) /* 483 */, - W64LIT(0xA6B7FFEFD2BB253E) /* 484 */, W64LIT(0x2E25BC95B0A29D4F) /* 485 */, - W64LIT(0x86D6A58BDEF1388C) /* 486 */, W64LIT(0xDED74AC576B6F054) /* 487 */, - W64LIT(0x8030BDBC2B45805D) /* 488 */, W64LIT(0x3C81AF70E94D9289) /* 489 */, - W64LIT(0x3EFF6DDA9E3100DB) /* 490 */, W64LIT(0xB38DC39FDFCC8847) /* 491 */, - W64LIT(0x123885528D17B87E) /* 492 */, W64LIT(0xF2DA0ED240B1B642) /* 493 */, - W64LIT(0x44CEFADCD54BF9A9) /* 494 */, W64LIT(0x1312200E433C7EE6) /* 495 */, - W64LIT(0x9FFCC84F3A78C748) /* 496 */, W64LIT(0xF0CD1F72248576BB) /* 497 */, - W64LIT(0xEC6974053638CFE4) /* 498 */, W64LIT(0x2BA7B67C0CEC4E4C) /* 499 */, - W64LIT(0xAC2F4DF3E5CE32ED) /* 500 */, W64LIT(0xCB33D14326EA4C11) /* 501 */, - W64LIT(0xA4E9044CC77E58BC) /* 502 */, W64LIT(0x5F513293D934FCEF) /* 503 */, - W64LIT(0x5DC9645506E55444) /* 504 */, W64LIT(0x50DE418F317DE40A) /* 505 */, - W64LIT(0x388CB31A69DDE259) /* 506 */, W64LIT(0x2DB4A83455820A86) /* 507 */, - W64LIT(0x9010A91E84711AE9) /* 508 */, W64LIT(0x4DF7F0B7B1498371) /* 509 */, - W64LIT(0xD62A2EABC0977179) /* 510 */, W64LIT(0x22FAC097AA8D5C0E) /* 511 */, - W64LIT(0xF49FCC2FF1DAF39B) /* 512 */, W64LIT(0x487FD5C66FF29281) /* 513 */, - W64LIT(0xE8A30667FCDCA83F) /* 514 */, W64LIT(0x2C9B4BE3D2FCCE63) /* 515 */, - W64LIT(0xDA3FF74B93FBBBC2) /* 516 */, W64LIT(0x2FA165D2FE70BA66) /* 517 */, - W64LIT(0xA103E279970E93D4) /* 518 */, W64LIT(0xBECDEC77B0E45E71) /* 519 */, - W64LIT(0xCFB41E723985E497) /* 520 */, W64LIT(0xB70AAA025EF75017) /* 521 */, - W64LIT(0xD42309F03840B8E0) /* 522 */, W64LIT(0x8EFC1AD035898579) /* 523 */, - W64LIT(0x96C6920BE2B2ABC5) /* 524 */, W64LIT(0x66AF4163375A9172) /* 525 */, - W64LIT(0x2174ABDCCA7127FB) /* 526 */, W64LIT(0xB33CCEA64A72FF41) /* 527 */, - W64LIT(0xF04A4933083066A5) /* 528 */, W64LIT(0x8D970ACDD7289AF5) /* 529 */, - W64LIT(0x8F96E8E031C8C25E) /* 530 */, W64LIT(0xF3FEC02276875D47) /* 531 */, - W64LIT(0xEC7BF310056190DD) /* 532 */, W64LIT(0xF5ADB0AEBB0F1491) /* 533 */, - W64LIT(0x9B50F8850FD58892) /* 534 */, W64LIT(0x4975488358B74DE8) /* 535 */, - W64LIT(0xA3354FF691531C61) /* 536 */, W64LIT(0x0702BBE481D2C6EE) /* 537 */, - W64LIT(0x89FB24057DEDED98) /* 538 */, W64LIT(0xAC3075138596E902) /* 539 */, - W64LIT(0x1D2D3580172772ED) /* 540 */, W64LIT(0xEB738FC28E6BC30D) /* 541 */, - W64LIT(0x5854EF8F63044326) /* 542 */, W64LIT(0x9E5C52325ADD3BBE) /* 543 */, - W64LIT(0x90AA53CF325C4623) /* 544 */, W64LIT(0xC1D24D51349DD067) /* 545 */, - W64LIT(0x2051CFEEA69EA624) /* 546 */, W64LIT(0x13220F0A862E7E4F) /* 547 */, - W64LIT(0xCE39399404E04864) /* 548 */, W64LIT(0xD9C42CA47086FCB7) /* 549 */, - W64LIT(0x685AD2238A03E7CC) /* 550 */, W64LIT(0x066484B2AB2FF1DB) /* 551 */, - W64LIT(0xFE9D5D70EFBF79EC) /* 552 */, W64LIT(0x5B13B9DD9C481854) /* 553 */, - W64LIT(0x15F0D475ED1509AD) /* 554 */, W64LIT(0x0BEBCD060EC79851) /* 555 */, - W64LIT(0xD58C6791183AB7F8) /* 556 */, W64LIT(0xD1187C5052F3EEE4) /* 557 */, - W64LIT(0xC95D1192E54E82FF) /* 558 */, W64LIT(0x86EEA14CB9AC6CA2) /* 559 */, - W64LIT(0x3485BEB153677D5D) /* 560 */, W64LIT(0xDD191D781F8C492A) /* 561 */, - W64LIT(0xF60866BAA784EBF9) /* 562 */, W64LIT(0x518F643BA2D08C74) /* 563 */, - W64LIT(0x8852E956E1087C22) /* 564 */, W64LIT(0xA768CB8DC410AE8D) /* 565 */, - W64LIT(0x38047726BFEC8E1A) /* 566 */, W64LIT(0xA67738B4CD3B45AA) /* 567 */, - W64LIT(0xAD16691CEC0DDE19) /* 568 */, W64LIT(0xC6D4319380462E07) /* 569 */, - W64LIT(0xC5A5876D0BA61938) /* 570 */, W64LIT(0x16B9FA1FA58FD840) /* 571 */, - W64LIT(0x188AB1173CA74F18) /* 572 */, W64LIT(0xABDA2F98C99C021F) /* 573 */, - W64LIT(0x3E0580AB134AE816) /* 574 */, W64LIT(0x5F3B05B773645ABB) /* 575 */, - W64LIT(0x2501A2BE5575F2F6) /* 576 */, W64LIT(0x1B2F74004E7E8BA9) /* 577 */, - W64LIT(0x1CD7580371E8D953) /* 578 */, W64LIT(0x7F6ED89562764E30) /* 579 */, - W64LIT(0xB15926FF596F003D) /* 580 */, W64LIT(0x9F65293DA8C5D6B9) /* 581 */, - W64LIT(0x6ECEF04DD690F84C) /* 582 */, W64LIT(0x4782275FFF33AF88) /* 583 */, - W64LIT(0xE41433083F820801) /* 584 */, W64LIT(0xFD0DFE409A1AF9B5) /* 585 */, - W64LIT(0x4325A3342CDB396B) /* 586 */, W64LIT(0x8AE77E62B301B252) /* 587 */, - W64LIT(0xC36F9E9F6655615A) /* 588 */, W64LIT(0x85455A2D92D32C09) /* 589 */, - W64LIT(0xF2C7DEA949477485) /* 590 */, W64LIT(0x63CFB4C133A39EBA) /* 591 */, - W64LIT(0x83B040CC6EBC5462) /* 592 */, W64LIT(0x3B9454C8FDB326B0) /* 593 */, - W64LIT(0x56F56A9E87FFD78C) /* 594 */, W64LIT(0x2DC2940D99F42BC6) /* 595 */, - W64LIT(0x98F7DF096B096E2D) /* 596 */, W64LIT(0x19A6E01E3AD852BF) /* 597 */, - W64LIT(0x42A99CCBDBD4B40B) /* 598 */, W64LIT(0xA59998AF45E9C559) /* 599 */, - W64LIT(0x366295E807D93186) /* 600 */, W64LIT(0x6B48181BFAA1F773) /* 601 */, - W64LIT(0x1FEC57E2157A0A1D) /* 602 */, W64LIT(0x4667446AF6201AD5) /* 603 */, - W64LIT(0xE615EBCACFB0F075) /* 604 */, W64LIT(0xB8F31F4F68290778) /* 605 */, - W64LIT(0x22713ED6CE22D11E) /* 606 */, W64LIT(0x3057C1A72EC3C93B) /* 607 */, - W64LIT(0xCB46ACC37C3F1F2F) /* 608 */, W64LIT(0xDBB893FD02AAF50E) /* 609 */, - W64LIT(0x331FD92E600B9FCF) /* 610 */, W64LIT(0xA498F96148EA3AD6) /* 611 */, - W64LIT(0xA8D8426E8B6A83EA) /* 612 */, W64LIT(0xA089B274B7735CDC) /* 613 */, - W64LIT(0x87F6B3731E524A11) /* 614 */, W64LIT(0x118808E5CBC96749) /* 615 */, - W64LIT(0x9906E4C7B19BD394) /* 616 */, W64LIT(0xAFED7F7E9B24A20C) /* 617 */, - W64LIT(0x6509EADEEB3644A7) /* 618 */, W64LIT(0x6C1EF1D3E8EF0EDE) /* 619 */, - W64LIT(0xB9C97D43E9798FB4) /* 620 */, W64LIT(0xA2F2D784740C28A3) /* 621 */, - W64LIT(0x7B8496476197566F) /* 622 */, W64LIT(0x7A5BE3E6B65F069D) /* 623 */, - W64LIT(0xF96330ED78BE6F10) /* 624 */, W64LIT(0xEEE60DE77A076A15) /* 625 */, - W64LIT(0x2B4BEE4AA08B9BD0) /* 626 */, W64LIT(0x6A56A63EC7B8894E) /* 627 */, - W64LIT(0x02121359BA34FEF4) /* 628 */, W64LIT(0x4CBF99F8283703FC) /* 629 */, - W64LIT(0x398071350CAF30C8) /* 630 */, W64LIT(0xD0A77A89F017687A) /* 631 */, - W64LIT(0xF1C1A9EB9E423569) /* 632 */, W64LIT(0x8C7976282DEE8199) /* 633 */, - W64LIT(0x5D1737A5DD1F7ABD) /* 634 */, W64LIT(0x4F53433C09A9FA80) /* 635 */, - W64LIT(0xFA8B0C53DF7CA1D9) /* 636 */, W64LIT(0x3FD9DCBC886CCB77) /* 637 */, - W64LIT(0xC040917CA91B4720) /* 638 */, W64LIT(0x7DD00142F9D1DCDF) /* 639 */, - W64LIT(0x8476FC1D4F387B58) /* 640 */, W64LIT(0x23F8E7C5F3316503) /* 641 */, - W64LIT(0x032A2244E7E37339) /* 642 */, W64LIT(0x5C87A5D750F5A74B) /* 643 */, - W64LIT(0x082B4CC43698992E) /* 644 */, W64LIT(0xDF917BECB858F63C) /* 645 */, - W64LIT(0x3270B8FC5BF86DDA) /* 646 */, W64LIT(0x10AE72BB29B5DD76) /* 647 */, - W64LIT(0x576AC94E7700362B) /* 648 */, W64LIT(0x1AD112DAC61EFB8F) /* 649 */, - W64LIT(0x691BC30EC5FAA427) /* 650 */, W64LIT(0xFF246311CC327143) /* 651 */, - W64LIT(0x3142368E30E53206) /* 652 */, W64LIT(0x71380E31E02CA396) /* 653 */, - W64LIT(0x958D5C960AAD76F1) /* 654 */, W64LIT(0xF8D6F430C16DA536) /* 655 */, - W64LIT(0xC8FFD13F1BE7E1D2) /* 656 */, W64LIT(0x7578AE66004DDBE1) /* 657 */, - W64LIT(0x05833F01067BE646) /* 658 */, W64LIT(0xBB34B5AD3BFE586D) /* 659 */, - W64LIT(0x095F34C9A12B97F0) /* 660 */, W64LIT(0x247AB64525D60CA8) /* 661 */, - W64LIT(0xDCDBC6F3017477D1) /* 662 */, W64LIT(0x4A2E14D4DECAD24D) /* 663 */, - W64LIT(0xBDB5E6D9BE0A1EEB) /* 664 */, W64LIT(0x2A7E70F7794301AB) /* 665 */, - W64LIT(0xDEF42D8A270540FD) /* 666 */, W64LIT(0x01078EC0A34C22C1) /* 667 */, - W64LIT(0xE5DE511AF4C16387) /* 668 */, W64LIT(0x7EBB3A52BD9A330A) /* 669 */, - W64LIT(0x77697857AA7D6435) /* 670 */, W64LIT(0x004E831603AE4C32) /* 671 */, - W64LIT(0xE7A21020AD78E312) /* 672 */, W64LIT(0x9D41A70C6AB420F2) /* 673 */, - W64LIT(0x28E06C18EA1141E6) /* 674 */, W64LIT(0xD2B28CBD984F6B28) /* 675 */, - W64LIT(0x26B75F6C446E9D83) /* 676 */, W64LIT(0xBA47568C4D418D7F) /* 677 */, - W64LIT(0xD80BADBFE6183D8E) /* 678 */, W64LIT(0x0E206D7F5F166044) /* 679 */, - W64LIT(0xE258A43911CBCA3E) /* 680 */, W64LIT(0x723A1746B21DC0BC) /* 681 */, - W64LIT(0xC7CAA854F5D7CDD3) /* 682 */, W64LIT(0x7CAC32883D261D9C) /* 683 */, - W64LIT(0x7690C26423BA942C) /* 684 */, W64LIT(0x17E55524478042B8) /* 685 */, - W64LIT(0xE0BE477656A2389F) /* 686 */, W64LIT(0x4D289B5E67AB2DA0) /* 687 */, - W64LIT(0x44862B9C8FBBFD31) /* 688 */, W64LIT(0xB47CC8049D141365) /* 689 */, - W64LIT(0x822C1B362B91C793) /* 690 */, W64LIT(0x4EB14655FB13DFD8) /* 691 */, - W64LIT(0x1ECBBA0714E2A97B) /* 692 */, W64LIT(0x6143459D5CDE5F14) /* 693 */, - W64LIT(0x53A8FBF1D5F0AC89) /* 694 */, W64LIT(0x97EA04D81C5E5B00) /* 695 */, - W64LIT(0x622181A8D4FDB3F3) /* 696 */, W64LIT(0xE9BCD341572A1208) /* 697 */, - W64LIT(0x1411258643CCE58A) /* 698 */, W64LIT(0x9144C5FEA4C6E0A4) /* 699 */, - W64LIT(0x0D33D06565CF620F) /* 700 */, W64LIT(0x54A48D489F219CA1) /* 701 */, - W64LIT(0xC43E5EAC6D63C821) /* 702 */, W64LIT(0xA9728B3A72770DAF) /* 703 */, - W64LIT(0xD7934E7B20DF87EF) /* 704 */, W64LIT(0xE35503B61A3E86E5) /* 705 */, - W64LIT(0xCAE321FBC819D504) /* 706 */, W64LIT(0x129A50B3AC60BFA6) /* 707 */, - W64LIT(0xCD5E68EA7E9FB6C3) /* 708 */, W64LIT(0xB01C90199483B1C7) /* 709 */, - W64LIT(0x3DE93CD5C295376C) /* 710 */, W64LIT(0xAED52EDF2AB9AD13) /* 711 */, - W64LIT(0x2E60F512C0A07884) /* 712 */, W64LIT(0xBC3D86A3E36210C9) /* 713 */, - W64LIT(0x35269D9B163951CE) /* 714 */, W64LIT(0x0C7D6E2AD0CDB5FA) /* 715 */, - W64LIT(0x59E86297D87F5733) /* 716 */, W64LIT(0x298EF221898DB0E7) /* 717 */, - W64LIT(0x55000029D1A5AA7E) /* 718 */, W64LIT(0x8BC08AE1B5061B45) /* 719 */, - W64LIT(0xC2C31C2B6C92703A) /* 720 */, W64LIT(0x94CC596BAF25EF42) /* 721 */, - W64LIT(0x0A1D73DB22540456) /* 722 */, W64LIT(0x04B6A0F9D9C4179A) /* 723 */, - W64LIT(0xEFFDAFA2AE3D3C60) /* 724 */, W64LIT(0xF7C8075BB49496C4) /* 725 */, - W64LIT(0x9CC5C7141D1CD4E3) /* 726 */, W64LIT(0x78BD1638218E5534) /* 727 */, - W64LIT(0xB2F11568F850246A) /* 728 */, W64LIT(0xEDFABCFA9502BC29) /* 729 */, - W64LIT(0x796CE5F2DA23051B) /* 730 */, W64LIT(0xAAE128B0DC93537C) /* 731 */, - W64LIT(0x3A493DA0EE4B29AE) /* 732 */, W64LIT(0xB5DF6B2C416895D7) /* 733 */, - W64LIT(0xFCABBD25122D7F37) /* 734 */, W64LIT(0x70810B58105DC4B1) /* 735 */, - W64LIT(0xE10FDD37F7882A90) /* 736 */, W64LIT(0x524DCAB5518A3F5C) /* 737 */, - W64LIT(0x3C9E85878451255B) /* 738 */, W64LIT(0x4029828119BD34E2) /* 739 */, - W64LIT(0x74A05B6F5D3CECCB) /* 740 */, W64LIT(0xB610021542E13ECA) /* 741 */, - W64LIT(0x0FF979D12F59E2AC) /* 742 */, W64LIT(0x6037DA27E4F9CC50) /* 743 */, - W64LIT(0x5E92975A0DF1847D) /* 744 */, W64LIT(0xD66DE190D3E623FE) /* 745 */, - W64LIT(0x5032D6B87B568048) /* 746 */, W64LIT(0x9A36B7CE8235216E) /* 747 */, - W64LIT(0x80272A7A24F64B4A) /* 748 */, W64LIT(0x93EFED8B8C6916F7) /* 749 */, - W64LIT(0x37DDBFF44CCE1555) /* 750 */, W64LIT(0x4B95DB5D4B99BD25) /* 751 */, - W64LIT(0x92D3FDA169812FC0) /* 752 */, W64LIT(0xFB1A4A9A90660BB6) /* 753 */, - W64LIT(0x730C196946A4B9B2) /* 754 */, W64LIT(0x81E289AA7F49DA68) /* 755 */, - W64LIT(0x64669A0F83B1A05F) /* 756 */, W64LIT(0x27B3FF7D9644F48B) /* 757 */, - W64LIT(0xCC6B615C8DB675B3) /* 758 */, W64LIT(0x674F20B9BCEBBE95) /* 759 */, - W64LIT(0x6F31238275655982) /* 760 */, W64LIT(0x5AE488713E45CF05) /* 761 */, - W64LIT(0xBF619F9954C21157) /* 762 */, W64LIT(0xEABAC46040A8EAE9) /* 763 */, - W64LIT(0x454C6FE9F2C0C1CD) /* 764 */, W64LIT(0x419CF6496412691C) /* 765 */, - W64LIT(0xD3DC3BEF265B0F70) /* 766 */, W64LIT(0x6D0E60F5C3578A9E) /* 767 */, - W64LIT(0x5B0E608526323C55) /* 768 */, W64LIT(0x1A46C1A9FA1B59F5) /* 769 */, - W64LIT(0xA9E245A17C4C8FFA) /* 770 */, W64LIT(0x65CA5159DB2955D7) /* 771 */, - W64LIT(0x05DB0A76CE35AFC2) /* 772 */, W64LIT(0x81EAC77EA9113D45) /* 773 */, - W64LIT(0x528EF88AB6AC0A0D) /* 774 */, W64LIT(0xA09EA253597BE3FF) /* 775 */, - W64LIT(0x430DDFB3AC48CD56) /* 776 */, W64LIT(0xC4B3A67AF45CE46F) /* 777 */, - W64LIT(0x4ECECFD8FBE2D05E) /* 778 */, W64LIT(0x3EF56F10B39935F0) /* 779 */, - W64LIT(0x0B22D6829CD619C6) /* 780 */, W64LIT(0x17FD460A74DF2069) /* 781 */, - W64LIT(0x6CF8CC8E8510ED40) /* 782 */, W64LIT(0xD6C824BF3A6ECAA7) /* 783 */, - W64LIT(0x61243D581A817049) /* 784 */, W64LIT(0x048BACB6BBC163A2) /* 785 */, - W64LIT(0xD9A38AC27D44CC32) /* 786 */, W64LIT(0x7FDDFF5BAAF410AB) /* 787 */, - W64LIT(0xAD6D495AA804824B) /* 788 */, W64LIT(0xE1A6A74F2D8C9F94) /* 789 */, - W64LIT(0xD4F7851235DEE8E3) /* 790 */, W64LIT(0xFD4B7F886540D893) /* 791 */, - W64LIT(0x247C20042AA4BFDA) /* 792 */, W64LIT(0x096EA1C517D1327C) /* 793 */, - W64LIT(0xD56966B4361A6685) /* 794 */, W64LIT(0x277DA5C31221057D) /* 795 */, - W64LIT(0x94D59893A43ACFF7) /* 796 */, W64LIT(0x64F0C51CCDC02281) /* 797 */, - W64LIT(0x3D33BCC4FF6189DB) /* 798 */, W64LIT(0xE005CB184CE66AF1) /* 799 */, - W64LIT(0xFF5CCD1D1DB99BEA) /* 800 */, W64LIT(0xB0B854A7FE42980F) /* 801 */, - W64LIT(0x7BD46A6A718D4B9F) /* 802 */, W64LIT(0xD10FA8CC22A5FD8C) /* 803 */, - W64LIT(0xD31484952BE4BD31) /* 804 */, W64LIT(0xC7FA975FCB243847) /* 805 */, - W64LIT(0x4886ED1E5846C407) /* 806 */, W64LIT(0x28CDDB791EB70B04) /* 807 */, - W64LIT(0xC2B00BE2F573417F) /* 808 */, W64LIT(0x5C9590452180F877) /* 809 */, - W64LIT(0x7A6BDDFFF370EB00) /* 810 */, W64LIT(0xCE509E38D6D9D6A4) /* 811 */, - W64LIT(0xEBEB0F00647FA702) /* 812 */, W64LIT(0x1DCC06CF76606F06) /* 813 */, - W64LIT(0xE4D9F28BA286FF0A) /* 814 */, W64LIT(0xD85A305DC918C262) /* 815 */, - W64LIT(0x475B1D8732225F54) /* 816 */, W64LIT(0x2D4FB51668CCB5FE) /* 817 */, - W64LIT(0xA679B9D9D72BBA20) /* 818 */, W64LIT(0x53841C0D912D43A5) /* 819 */, - W64LIT(0x3B7EAA48BF12A4E8) /* 820 */, W64LIT(0x781E0E47F22F1DDF) /* 821 */, - W64LIT(0xEFF20CE60AB50973) /* 822 */, W64LIT(0x20D261D19DFFB742) /* 823 */, - W64LIT(0x16A12B03062A2E39) /* 824 */, W64LIT(0x1960EB2239650495) /* 825 */, - W64LIT(0x251C16FED50EB8B8) /* 826 */, W64LIT(0x9AC0C330F826016E) /* 827 */, - W64LIT(0xED152665953E7671) /* 828 */, W64LIT(0x02D63194A6369570) /* 829 */, - W64LIT(0x5074F08394B1C987) /* 830 */, W64LIT(0x70BA598C90B25CE1) /* 831 */, - W64LIT(0x794A15810B9742F6) /* 832 */, W64LIT(0x0D5925E9FCAF8C6C) /* 833 */, - W64LIT(0x3067716CD868744E) /* 834 */, W64LIT(0x910AB077E8D7731B) /* 835 */, - W64LIT(0x6A61BBDB5AC42F61) /* 836 */, W64LIT(0x93513EFBF0851567) /* 837 */, - W64LIT(0xF494724B9E83E9D5) /* 838 */, W64LIT(0xE887E1985C09648D) /* 839 */, - W64LIT(0x34B1D3C675370CFD) /* 840 */, W64LIT(0xDC35E433BC0D255D) /* 841 */, - W64LIT(0xD0AAB84234131BE0) /* 842 */, W64LIT(0x08042A50B48B7EAF) /* 843 */, - W64LIT(0x9997C4EE44A3AB35) /* 844 */, W64LIT(0x829A7B49201799D0) /* 845 */, - W64LIT(0x263B8307B7C54441) /* 846 */, W64LIT(0x752F95F4FD6A6CA6) /* 847 */, - W64LIT(0x927217402C08C6E5) /* 848 */, W64LIT(0x2A8AB754A795D9EE) /* 849 */, - W64LIT(0xA442F7552F72943D) /* 850 */, W64LIT(0x2C31334E19781208) /* 851 */, - W64LIT(0x4FA98D7CEAEE6291) /* 852 */, W64LIT(0x55C3862F665DB309) /* 853 */, - W64LIT(0xBD0610175D53B1F3) /* 854 */, W64LIT(0x46FE6CB840413F27) /* 855 */, - W64LIT(0x3FE03792DF0CFA59) /* 856 */, W64LIT(0xCFE700372EB85E8F) /* 857 */, - W64LIT(0xA7BE29E7ADBCE118) /* 858 */, W64LIT(0xE544EE5CDE8431DD) /* 859 */, - W64LIT(0x8A781B1B41F1873E) /* 860 */, W64LIT(0xA5C94C78A0D2F0E7) /* 861 */, - W64LIT(0x39412E2877B60728) /* 862 */, W64LIT(0xA1265EF3AFC9A62C) /* 863 */, - W64LIT(0xBCC2770C6A2506C5) /* 864 */, W64LIT(0x3AB66DD5DCE1CE12) /* 865 */, - W64LIT(0xE65499D04A675B37) /* 866 */, W64LIT(0x7D8F523481BFD216) /* 867 */, - W64LIT(0x0F6F64FCEC15F389) /* 868 */, W64LIT(0x74EFBE618B5B13C8) /* 869 */, - W64LIT(0xACDC82B714273E1D) /* 870 */, W64LIT(0xDD40BFE003199D17) /* 871 */, - W64LIT(0x37E99257E7E061F8) /* 872 */, W64LIT(0xFA52626904775AAA) /* 873 */, - W64LIT(0x8BBBF63A463D56F9) /* 874 */, W64LIT(0xF0013F1543A26E64) /* 875 */, - W64LIT(0xA8307E9F879EC898) /* 876 */, W64LIT(0xCC4C27A4150177CC) /* 877 */, - W64LIT(0x1B432F2CCA1D3348) /* 878 */, W64LIT(0xDE1D1F8F9F6FA013) /* 879 */, - W64LIT(0x606602A047A7DDD6) /* 880 */, W64LIT(0xD237AB64CC1CB2C7) /* 881 */, - W64LIT(0x9B938E7225FCD1D3) /* 882 */, W64LIT(0xEC4E03708E0FF476) /* 883 */, - W64LIT(0xFEB2FBDA3D03C12D) /* 884 */, W64LIT(0xAE0BCED2EE43889A) /* 885 */, - W64LIT(0x22CB8923EBFB4F43) /* 886 */, W64LIT(0x69360D013CF7396D) /* 887 */, - W64LIT(0x855E3602D2D4E022) /* 888 */, W64LIT(0x073805BAD01F784C) /* 889 */, - W64LIT(0x33E17A133852F546) /* 890 */, W64LIT(0xDF4874058AC7B638) /* 891 */, - W64LIT(0xBA92B29C678AA14A) /* 892 */, W64LIT(0x0CE89FC76CFAADCD) /* 893 */, - W64LIT(0x5F9D4E0908339E34) /* 894 */, W64LIT(0xF1AFE9291F5923B9) /* 895 */, - W64LIT(0x6E3480F60F4A265F) /* 896 */, W64LIT(0xEEBF3A2AB29B841C) /* 897 */, - W64LIT(0xE21938A88F91B4AD) /* 898 */, W64LIT(0x57DFEFF845C6D3C3) /* 899 */, - W64LIT(0x2F006B0BF62CAAF2) /* 900 */, W64LIT(0x62F479EF6F75EE78) /* 901 */, - W64LIT(0x11A55AD41C8916A9) /* 902 */, W64LIT(0xF229D29084FED453) /* 903 */, - W64LIT(0x42F1C27B16B000E6) /* 904 */, W64LIT(0x2B1F76749823C074) /* 905 */, - W64LIT(0x4B76ECA3C2745360) /* 906 */, W64LIT(0x8C98F463B91691BD) /* 907 */, - W64LIT(0x14BCC93CF1ADE66A) /* 908 */, W64LIT(0x8885213E6D458397) /* 909 */, - W64LIT(0x8E177DF0274D4711) /* 910 */, W64LIT(0xB49B73B5503F2951) /* 911 */, - W64LIT(0x10168168C3F96B6B) /* 912 */, W64LIT(0x0E3D963B63CAB0AE) /* 913 */, - W64LIT(0x8DFC4B5655A1DB14) /* 914 */, W64LIT(0xF789F1356E14DE5C) /* 915 */, - W64LIT(0x683E68AF4E51DAC1) /* 916 */, W64LIT(0xC9A84F9D8D4B0FD9) /* 917 */, - W64LIT(0x3691E03F52A0F9D1) /* 918 */, W64LIT(0x5ED86E46E1878E80) /* 919 */, - W64LIT(0x3C711A0E99D07150) /* 920 */, W64LIT(0x5A0865B20C4E9310) /* 921 */, - W64LIT(0x56FBFC1FE4F0682E) /* 922 */, W64LIT(0xEA8D5DE3105EDF9B) /* 923 */, - W64LIT(0x71ABFDB12379187A) /* 924 */, W64LIT(0x2EB99DE1BEE77B9C) /* 925 */, - W64LIT(0x21ECC0EA33CF4523) /* 926 */, W64LIT(0x59A4D7521805C7A1) /* 927 */, - W64LIT(0x3896F5EB56AE7C72) /* 928 */, W64LIT(0xAA638F3DB18F75DC) /* 929 */, - W64LIT(0x9F39358DABE9808E) /* 930 */, W64LIT(0xB7DEFA91C00B72AC) /* 931 */, - W64LIT(0x6B5541FD62492D92) /* 932 */, W64LIT(0x6DC6DEE8F92E4D5B) /* 933 */, - W64LIT(0x353F57ABC4BEEA7E) /* 934 */, W64LIT(0x735769D6DA5690CE) /* 935 */, - W64LIT(0x0A234AA642391484) /* 936 */, W64LIT(0xF6F9508028F80D9D) /* 937 */, - W64LIT(0xB8E319A27AB3F215) /* 938 */, W64LIT(0x31AD9C1151341A4D) /* 939 */, - W64LIT(0x773C22A57BEF5805) /* 940 */, W64LIT(0x45C7561A07968633) /* 941 */, - W64LIT(0xF913DA9E249DBE36) /* 942 */, W64LIT(0xDA652D9B78A64C68) /* 943 */, - W64LIT(0x4C27A97F3BC334EF) /* 944 */, W64LIT(0x76621220E66B17F4) /* 945 */, - W64LIT(0x967743899ACD7D0B) /* 946 */, W64LIT(0xF3EE5BCAE0ED6782) /* 947 */, - W64LIT(0x409F753600C879FC) /* 948 */, W64LIT(0x06D09A39B5926DB6) /* 949 */, - W64LIT(0x6F83AEB0317AC588) /* 950 */, W64LIT(0x01E6CA4A86381F21) /* 951 */, - W64LIT(0x66FF3462D19F3025) /* 952 */, W64LIT(0x72207C24DDFD3BFB) /* 953 */, - W64LIT(0x4AF6B6D3E2ECE2EB) /* 954 */, W64LIT(0x9C994DBEC7EA08DE) /* 955 */, - W64LIT(0x49ACE597B09A8BC4) /* 956 */, W64LIT(0xB38C4766CF0797BA) /* 957 */, - W64LIT(0x131B9373C57C2A75) /* 958 */, W64LIT(0xB1822CCE61931E58) /* 959 */, - W64LIT(0x9D7555B909BA1C0C) /* 960 */, W64LIT(0x127FAFDD937D11D2) /* 961 */, - W64LIT(0x29DA3BADC66D92E4) /* 962 */, W64LIT(0xA2C1D57154C2ECBC) /* 963 */, - W64LIT(0x58C5134D82F6FE24) /* 964 */, W64LIT(0x1C3AE3515B62274F) /* 965 */, - W64LIT(0xE907C82E01CB8126) /* 966 */, W64LIT(0xF8ED091913E37FCB) /* 967 */, - W64LIT(0x3249D8F9C80046C9) /* 968 */, W64LIT(0x80CF9BEDE388FB63) /* 969 */, - W64LIT(0x1881539A116CF19E) /* 970 */, W64LIT(0x5103F3F76BD52457) /* 971 */, - W64LIT(0x15B7E6F5AE47F7A8) /* 972 */, W64LIT(0xDBD7C6DED47E9CCF) /* 973 */, - W64LIT(0x44E55C410228BB1A) /* 974 */, W64LIT(0xB647D4255EDB4E99) /* 975 */, - W64LIT(0x5D11882BB8AAFC30) /* 976 */, W64LIT(0xF5098BBB29D3212A) /* 977 */, - W64LIT(0x8FB5EA14E90296B3) /* 978 */, W64LIT(0x677B942157DD025A) /* 979 */, - W64LIT(0xFB58E7C0A390ACB5) /* 980 */, W64LIT(0x89D3674C83BD4A01) /* 981 */, - W64LIT(0x9E2DA4DF4BF3B93B) /* 982 */, W64LIT(0xFCC41E328CAB4829) /* 983 */, - W64LIT(0x03F38C96BA582C52) /* 984 */, W64LIT(0xCAD1BDBD7FD85DB2) /* 985 */, - W64LIT(0xBBB442C16082AE83) /* 986 */, W64LIT(0xB95FE86BA5DA9AB0) /* 987 */, - W64LIT(0xB22E04673771A93F) /* 988 */, W64LIT(0x845358C9493152D8) /* 989 */, - W64LIT(0xBE2A488697B4541E) /* 990 */, W64LIT(0x95A2DC2DD38E6966) /* 991 */, - W64LIT(0xC02C11AC923C852B) /* 992 */, W64LIT(0x2388B1990DF2A87B) /* 993 */, - W64LIT(0x7C8008FA1B4F37BE) /* 994 */, W64LIT(0x1F70D0C84D54E503) /* 995 */, - W64LIT(0x5490ADEC7ECE57D4) /* 996 */, W64LIT(0x002B3C27D9063A3A) /* 997 */, - W64LIT(0x7EAEA3848030A2BF) /* 998 */, W64LIT(0xC602326DED2003C0) /* 999 */, - W64LIT(0x83A7287D69A94086) /* 1000 */, W64LIT(0xC57A5FCB30F57A8A) /* 1001 */, - W64LIT(0xB56844E479EBE779) /* 1002 */, W64LIT(0xA373B40F05DCBCE9) /* 1003 */, - W64LIT(0xD71A786E88570EE2) /* 1004 */, W64LIT(0x879CBACDBDE8F6A0) /* 1005 */, - W64LIT(0x976AD1BCC164A32F) /* 1006 */, W64LIT(0xAB21E25E9666D78B) /* 1007 */, - W64LIT(0x901063AAE5E5C33C) /* 1008 */, W64LIT(0x9818B34448698D90) /* 1009 */, - W64LIT(0xE36487AE3E1E8ABB) /* 1010 */, W64LIT(0xAFBDF931893BDCB4) /* 1011 */, - W64LIT(0x6345A0DC5FBBD519) /* 1012 */, W64LIT(0x8628FE269B9465CA) /* 1013 */, - W64LIT(0x1E5D01603F9C51EC) /* 1014 */, W64LIT(0x4DE44006A15049B7) /* 1015 */, - W64LIT(0xBF6C70E5F776CBB1) /* 1016 */, W64LIT(0x411218F2EF552BED) /* 1017 */, - W64LIT(0xCB0C0708705A36A3) /* 1018 */, W64LIT(0xE74D14754F986044) /* 1019 */, - W64LIT(0xCD56D9430EA8280E) /* 1020 */, W64LIT(0xC12591D7535F5065) /* 1021 */, - W64LIT(0xC83223F1720AEF96) /* 1022 */, W64LIT(0xC3A0396F7363A51F) /* 1023 */, - W64LIT(0xffffffffffffffff), - W64LIT(0xA5A5A5A5A5A5A5A5), - W64LIT(0x0123456789ABCDEF), -}; - -NAMESPACE_END diff --git a/lib/cryptopp/trdlocal.cpp b/lib/cryptopp/trdlocal.cpp deleted file mode 100644 index 6d6b822c0..000000000 --- a/lib/cryptopp/trdlocal.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// trdlocal.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" - -#ifndef CRYPTOPP_IMPORTS -#ifdef THREADS_AVAILABLE - -#include "trdlocal.h" - -#ifdef HAS_WINTHREADS -#include -#endif - -NAMESPACE_BEGIN(CryptoPP) - -ThreadLocalStorage::Err::Err(const std::string& operation, int error) - : OS_Error(OTHER_ERROR, "ThreadLocalStorage: " + operation + " operation failed with error 0x" + IntToString(error, 16), operation, error) -{ -} - -ThreadLocalStorage::ThreadLocalStorage() -{ -#ifdef HAS_WINTHREADS - m_index = TlsAlloc(); - if (m_index == TLS_OUT_OF_INDEXES) - throw Err("TlsAlloc", GetLastError()); -#else - int error = pthread_key_create(&m_index, NULL); - if (error) - throw Err("pthread_key_create", error); -#endif -} - -ThreadLocalStorage::~ThreadLocalStorage() -{ -#ifdef HAS_WINTHREADS - if (!TlsFree(m_index)) - throw Err("TlsFree", GetLastError()); -#else - int error = pthread_key_delete(m_index); - if (error) - throw Err("pthread_key_delete", error); -#endif -} - -void ThreadLocalStorage::SetValue(void *value) -{ -#ifdef HAS_WINTHREADS - if (!TlsSetValue(m_index, value)) - throw Err("TlsSetValue", GetLastError()); -#else - int error = pthread_setspecific(m_index, value); - if (error) - throw Err("pthread_key_getspecific", error); -#endif -} - -void *ThreadLocalStorage::GetValue() const -{ -#ifdef HAS_WINTHREADS - void *result = TlsGetValue(m_index); - if (!result && GetLastError() != NO_ERROR) - throw Err("TlsGetValue", GetLastError()); -#else - void *result = pthread_getspecific(m_index); -#endif - return result; -} - -NAMESPACE_END - -#endif // #ifdef THREADS_AVAILABLE -#endif diff --git a/lib/cryptopp/trdlocal.h b/lib/cryptopp/trdlocal.h deleted file mode 100644 index 92d244a0a..000000000 --- a/lib/cryptopp/trdlocal.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef CRYPTOPP_TRDLOCAL_H -#define CRYPTOPP_TRDLOCAL_H - -#include "config.h" - -#ifdef THREADS_AVAILABLE - -#include "misc.h" - -#ifdef HAS_WINTHREADS -typedef unsigned long ThreadLocalIndexType; -#else -#include -typedef pthread_key_t ThreadLocalIndexType; -#endif - -NAMESPACE_BEGIN(CryptoPP) - -//! thread local storage -class CRYPTOPP_DLL ThreadLocalStorage : public NotCopyable -{ -public: - //! exception thrown by ThreadLocalStorage class - class Err : public OS_Error - { - public: - Err(const std::string& operation, int error); - }; - - ThreadLocalStorage(); - ~ThreadLocalStorage(); - - void SetValue(void *value); - void *GetValue() const; - -private: - ThreadLocalIndexType m_index; -}; - -NAMESPACE_END - -#endif // #ifdef THREADS_AVAILABLE - -#endif diff --git a/lib/cryptopp/trunhash.h b/lib/cryptopp/trunhash.h deleted file mode 100644 index c1c4e9b64..000000000 --- a/lib/cryptopp/trunhash.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef CRYPTOPP_TRUNHASH_H -#define CRYPTOPP_TRUNHASH_H - -#include "cryptlib.h" - -NAMESPACE_BEGIN(CryptoPP) - -class NullHash : public HashTransformation -{ -public: - void Update(const byte *input, size_t length) {} - unsigned int DigestSize() const {return 0;} - void TruncatedFinal(byte *digest, size_t digestSize) {} - bool TruncatedVerify(const byte *digest, size_t digestLength) {return true;} -}; - -//! construct new HashModule with smaller DigestSize() from existing one -template -class TruncatedHashTemplate : public HashTransformation -{ -public: - TruncatedHashTemplate(T hm, unsigned int digestSize) - : m_hm(hm), m_digestSize(digestSize) {} - TruncatedHashTemplate(const byte *key, size_t keyLength, unsigned int digestSize) - : m_hm(key, keyLength), m_digestSize(digestSize) {} - TruncatedHashTemplate(size_t digestSize) - : m_digestSize(digestSize) {} - - void Restart() - {m_hm.Restart();} - void Update(const byte *input, size_t length) - {m_hm.Update(input, length);} - unsigned int DigestSize() const {return m_digestSize;} - void TruncatedFinal(byte *digest, size_t digestSize) - {m_hm.TruncatedFinal(digest, digestSize);} - bool TruncatedVerify(const byte *digest, size_t digestLength) - {return m_hm.TruncatedVerify(digest, digestLength);} - -private: - T m_hm; - unsigned int m_digestSize; -}; - -typedef TruncatedHashTemplate TruncatedHashModule; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/ttmac.cpp b/lib/cryptopp/ttmac.cpp deleted file mode 100644 index d4ff38104..000000000 --- a/lib/cryptopp/ttmac.cpp +++ /dev/null @@ -1,338 +0,0 @@ -// ttmac.cpp - written and placed in the public domain by Kevin Springle - -#include "pch.h" -#include "ttmac.h" -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) - -void TTMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &) -{ - AssertValidKeyLength(keylength); - - memcpy(m_key, userKey, KEYLENGTH); - CorrectEndianess(m_key, m_key, KEYLENGTH); - - Init(); -} - -void TTMAC_Base::Init() -{ - m_digest[0] = m_digest[5] = m_key[0]; - m_digest[1] = m_digest[6] = m_key[1]; - m_digest[2] = m_digest[7] = m_key[2]; - m_digest[3] = m_digest[8] = m_key[3]; - m_digest[4] = m_digest[9] = m_key[4]; -} - -void TTMAC_Base::TruncatedFinal(byte *hash, size_t size) -{ - PadLastBlock(BlockSize() - 2*sizeof(HashWordType)); - CorrectEndianess(m_data, m_data, BlockSize() - 2*sizeof(HashWordType)); - - m_data[m_data.size()-2] = GetBitCountLo(); - m_data[m_data.size()-1] = GetBitCountHi(); - - Transform(m_digest, m_data, true); - - word32 t2 = m_digest[2]; - word32 t3 = m_digest[3]; - if (size != DIGESTSIZE) - { - switch (size) - { - case 16: - m_digest[3] += m_digest[1] + m_digest[4]; - - case 12: - m_digest[2] += m_digest[0] + t3; - - case 8: - m_digest[0] += m_digest[1] + t3; - m_digest[1] += m_digest[4] + t2; - break; - - case 4: - m_digest[0] += - m_digest[1] + - m_digest[2] + - m_digest[3] + - m_digest[4]; - break; - - case 0: - // Used by HashTransformation::Restart() - break; - - default: - throw InvalidArgument("TTMAC_Base: can't truncate a Two-Track-MAC 20 byte digest to " + IntToString(size) + " bytes"); - break; - } - } - - CorrectEndianess(m_digest, m_digest, size); - memcpy(hash, m_digest, size); - - Restart(); // reinit for next use -} - -// RIPEMD-160 definitions used by Two-Track-MAC - -#define F(x, y, z) (x ^ y ^ z) -#define G(x, y, z) (z ^ (x & (y^z))) -#define H(x, y, z) (z ^ (x | ~y)) -#define I(x, y, z) (y ^ (z & (x^y))) -#define J(x, y, z) (x ^ (y | ~z)) - -#define k0 0 -#define k1 0x5a827999UL -#define k2 0x6ed9eba1UL -#define k3 0x8f1bbcdcUL -#define k4 0xa953fd4eUL -#define k5 0x50a28be6UL -#define k6 0x5c4dd124UL -#define k7 0x6d703ef3UL -#define k8 0x7a6d76e9UL -#define k9 0 - -void TTMAC_Base::Transform(word32 *digest, const word32 *X, bool last) -{ -#define Subround(f, a, b, c, d, e, x, s, k) \ - a += f(b, c, d) + x + k;\ - a = rotlFixed((word32)a, s) + e;\ - c = rotlFixed((word32)c, 10U) - - word32 a1, b1, c1, d1, e1, a2, b2, c2, d2, e2; - word32 *trackA, *trackB; - - if (!last) - { - trackA = digest; - trackB = digest+5; - } - else - { - trackB = digest; - trackA = digest+5; - } - a1 = trackA[0]; - b1 = trackA[1]; - c1 = trackA[2]; - d1 = trackA[3]; - e1 = trackA[4]; - a2 = trackB[0]; - b2 = trackB[1]; - c2 = trackB[2]; - d2 = trackB[3]; - e2 = trackB[4]; - - Subround(F, a1, b1, c1, d1, e1, X[ 0], 11, k0); - Subround(F, e1, a1, b1, c1, d1, X[ 1], 14, k0); - Subround(F, d1, e1, a1, b1, c1, X[ 2], 15, k0); - Subround(F, c1, d1, e1, a1, b1, X[ 3], 12, k0); - Subround(F, b1, c1, d1, e1, a1, X[ 4], 5, k0); - Subround(F, a1, b1, c1, d1, e1, X[ 5], 8, k0); - Subround(F, e1, a1, b1, c1, d1, X[ 6], 7, k0); - Subround(F, d1, e1, a1, b1, c1, X[ 7], 9, k0); - Subround(F, c1, d1, e1, a1, b1, X[ 8], 11, k0); - Subround(F, b1, c1, d1, e1, a1, X[ 9], 13, k0); - Subround(F, a1, b1, c1, d1, e1, X[10], 14, k0); - Subround(F, e1, a1, b1, c1, d1, X[11], 15, k0); - Subround(F, d1, e1, a1, b1, c1, X[12], 6, k0); - Subround(F, c1, d1, e1, a1, b1, X[13], 7, k0); - Subround(F, b1, c1, d1, e1, a1, X[14], 9, k0); - Subround(F, a1, b1, c1, d1, e1, X[15], 8, k0); - - Subround(G, e1, a1, b1, c1, d1, X[ 7], 7, k1); - Subround(G, d1, e1, a1, b1, c1, X[ 4], 6, k1); - Subround(G, c1, d1, e1, a1, b1, X[13], 8, k1); - Subround(G, b1, c1, d1, e1, a1, X[ 1], 13, k1); - Subround(G, a1, b1, c1, d1, e1, X[10], 11, k1); - Subround(G, e1, a1, b1, c1, d1, X[ 6], 9, k1); - Subround(G, d1, e1, a1, b1, c1, X[15], 7, k1); - Subround(G, c1, d1, e1, a1, b1, X[ 3], 15, k1); - Subround(G, b1, c1, d1, e1, a1, X[12], 7, k1); - Subround(G, a1, b1, c1, d1, e1, X[ 0], 12, k1); - Subround(G, e1, a1, b1, c1, d1, X[ 9], 15, k1); - Subround(G, d1, e1, a1, b1, c1, X[ 5], 9, k1); - Subround(G, c1, d1, e1, a1, b1, X[ 2], 11, k1); - Subround(G, b1, c1, d1, e1, a1, X[14], 7, k1); - Subround(G, a1, b1, c1, d1, e1, X[11], 13, k1); - Subround(G, e1, a1, b1, c1, d1, X[ 8], 12, k1); - - Subround(H, d1, e1, a1, b1, c1, X[ 3], 11, k2); - Subround(H, c1, d1, e1, a1, b1, X[10], 13, k2); - Subround(H, b1, c1, d1, e1, a1, X[14], 6, k2); - Subround(H, a1, b1, c1, d1, e1, X[ 4], 7, k2); - Subround(H, e1, a1, b1, c1, d1, X[ 9], 14, k2); - Subround(H, d1, e1, a1, b1, c1, X[15], 9, k2); - Subround(H, c1, d1, e1, a1, b1, X[ 8], 13, k2); - Subround(H, b1, c1, d1, e1, a1, X[ 1], 15, k2); - Subround(H, a1, b1, c1, d1, e1, X[ 2], 14, k2); - Subround(H, e1, a1, b1, c1, d1, X[ 7], 8, k2); - Subround(H, d1, e1, a1, b1, c1, X[ 0], 13, k2); - Subround(H, c1, d1, e1, a1, b1, X[ 6], 6, k2); - Subround(H, b1, c1, d1, e1, a1, X[13], 5, k2); - Subround(H, a1, b1, c1, d1, e1, X[11], 12, k2); - Subround(H, e1, a1, b1, c1, d1, X[ 5], 7, k2); - Subround(H, d1, e1, a1, b1, c1, X[12], 5, k2); - - Subround(I, c1, d1, e1, a1, b1, X[ 1], 11, k3); - Subround(I, b1, c1, d1, e1, a1, X[ 9], 12, k3); - Subround(I, a1, b1, c1, d1, e1, X[11], 14, k3); - Subround(I, e1, a1, b1, c1, d1, X[10], 15, k3); - Subround(I, d1, e1, a1, b1, c1, X[ 0], 14, k3); - Subround(I, c1, d1, e1, a1, b1, X[ 8], 15, k3); - Subround(I, b1, c1, d1, e1, a1, X[12], 9, k3); - Subround(I, a1, b1, c1, d1, e1, X[ 4], 8, k3); - Subround(I, e1, a1, b1, c1, d1, X[13], 9, k3); - Subround(I, d1, e1, a1, b1, c1, X[ 3], 14, k3); - Subround(I, c1, d1, e1, a1, b1, X[ 7], 5, k3); - Subround(I, b1, c1, d1, e1, a1, X[15], 6, k3); - Subround(I, a1, b1, c1, d1, e1, X[14], 8, k3); - Subround(I, e1, a1, b1, c1, d1, X[ 5], 6, k3); - Subround(I, d1, e1, a1, b1, c1, X[ 6], 5, k3); - Subround(I, c1, d1, e1, a1, b1, X[ 2], 12, k3); - - Subround(J, b1, c1, d1, e1, a1, X[ 4], 9, k4); - Subround(J, a1, b1, c1, d1, e1, X[ 0], 15, k4); - Subround(J, e1, a1, b1, c1, d1, X[ 5], 5, k4); - Subround(J, d1, e1, a1, b1, c1, X[ 9], 11, k4); - Subround(J, c1, d1, e1, a1, b1, X[ 7], 6, k4); - Subround(J, b1, c1, d1, e1, a1, X[12], 8, k4); - Subround(J, a1, b1, c1, d1, e1, X[ 2], 13, k4); - Subround(J, e1, a1, b1, c1, d1, X[10], 12, k4); - Subround(J, d1, e1, a1, b1, c1, X[14], 5, k4); - Subround(J, c1, d1, e1, a1, b1, X[ 1], 12, k4); - Subround(J, b1, c1, d1, e1, a1, X[ 3], 13, k4); - Subround(J, a1, b1, c1, d1, e1, X[ 8], 14, k4); - Subround(J, e1, a1, b1, c1, d1, X[11], 11, k4); - Subround(J, d1, e1, a1, b1, c1, X[ 6], 8, k4); - Subround(J, c1, d1, e1, a1, b1, X[15], 5, k4); - Subround(J, b1, c1, d1, e1, a1, X[13], 6, k4); - - Subround(J, a2, b2, c2, d2, e2, X[ 5], 8, k5); - Subround(J, e2, a2, b2, c2, d2, X[14], 9, k5); - Subround(J, d2, e2, a2, b2, c2, X[ 7], 9, k5); - Subround(J, c2, d2, e2, a2, b2, X[ 0], 11, k5); - Subround(J, b2, c2, d2, e2, a2, X[ 9], 13, k5); - Subround(J, a2, b2, c2, d2, e2, X[ 2], 15, k5); - Subround(J, e2, a2, b2, c2, d2, X[11], 15, k5); - Subround(J, d2, e2, a2, b2, c2, X[ 4], 5, k5); - Subround(J, c2, d2, e2, a2, b2, X[13], 7, k5); - Subround(J, b2, c2, d2, e2, a2, X[ 6], 7, k5); - Subround(J, a2, b2, c2, d2, e2, X[15], 8, k5); - Subround(J, e2, a2, b2, c2, d2, X[ 8], 11, k5); - Subround(J, d2, e2, a2, b2, c2, X[ 1], 14, k5); - Subround(J, c2, d2, e2, a2, b2, X[10], 14, k5); - Subround(J, b2, c2, d2, e2, a2, X[ 3], 12, k5); - Subround(J, a2, b2, c2, d2, e2, X[12], 6, k5); - - Subround(I, e2, a2, b2, c2, d2, X[ 6], 9, k6); - Subround(I, d2, e2, a2, b2, c2, X[11], 13, k6); - Subround(I, c2, d2, e2, a2, b2, X[ 3], 15, k6); - Subround(I, b2, c2, d2, e2, a2, X[ 7], 7, k6); - Subround(I, a2, b2, c2, d2, e2, X[ 0], 12, k6); - Subround(I, e2, a2, b2, c2, d2, X[13], 8, k6); - Subround(I, d2, e2, a2, b2, c2, X[ 5], 9, k6); - Subround(I, c2, d2, e2, a2, b2, X[10], 11, k6); - Subround(I, b2, c2, d2, e2, a2, X[14], 7, k6); - Subround(I, a2, b2, c2, d2, e2, X[15], 7, k6); - Subround(I, e2, a2, b2, c2, d2, X[ 8], 12, k6); - Subround(I, d2, e2, a2, b2, c2, X[12], 7, k6); - Subround(I, c2, d2, e2, a2, b2, X[ 4], 6, k6); - Subround(I, b2, c2, d2, e2, a2, X[ 9], 15, k6); - Subround(I, a2, b2, c2, d2, e2, X[ 1], 13, k6); - Subround(I, e2, a2, b2, c2, d2, X[ 2], 11, k6); - - Subround(H, d2, e2, a2, b2, c2, X[15], 9, k7); - Subround(H, c2, d2, e2, a2, b2, X[ 5], 7, k7); - Subround(H, b2, c2, d2, e2, a2, X[ 1], 15, k7); - Subround(H, a2, b2, c2, d2, e2, X[ 3], 11, k7); - Subround(H, e2, a2, b2, c2, d2, X[ 7], 8, k7); - Subround(H, d2, e2, a2, b2, c2, X[14], 6, k7); - Subround(H, c2, d2, e2, a2, b2, X[ 6], 6, k7); - Subround(H, b2, c2, d2, e2, a2, X[ 9], 14, k7); - Subround(H, a2, b2, c2, d2, e2, X[11], 12, k7); - Subround(H, e2, a2, b2, c2, d2, X[ 8], 13, k7); - Subround(H, d2, e2, a2, b2, c2, X[12], 5, k7); - Subround(H, c2, d2, e2, a2, b2, X[ 2], 14, k7); - Subround(H, b2, c2, d2, e2, a2, X[10], 13, k7); - Subround(H, a2, b2, c2, d2, e2, X[ 0], 13, k7); - Subround(H, e2, a2, b2, c2, d2, X[ 4], 7, k7); - Subround(H, d2, e2, a2, b2, c2, X[13], 5, k7); - - Subround(G, c2, d2, e2, a2, b2, X[ 8], 15, k8); - Subround(G, b2, c2, d2, e2, a2, X[ 6], 5, k8); - Subround(G, a2, b2, c2, d2, e2, X[ 4], 8, k8); - Subround(G, e2, a2, b2, c2, d2, X[ 1], 11, k8); - Subround(G, d2, e2, a2, b2, c2, X[ 3], 14, k8); - Subround(G, c2, d2, e2, a2, b2, X[11], 14, k8); - Subround(G, b2, c2, d2, e2, a2, X[15], 6, k8); - Subround(G, a2, b2, c2, d2, e2, X[ 0], 14, k8); - Subround(G, e2, a2, b2, c2, d2, X[ 5], 6, k8); - Subround(G, d2, e2, a2, b2, c2, X[12], 9, k8); - Subround(G, c2, d2, e2, a2, b2, X[ 2], 12, k8); - Subround(G, b2, c2, d2, e2, a2, X[13], 9, k8); - Subround(G, a2, b2, c2, d2, e2, X[ 9], 12, k8); - Subround(G, e2, a2, b2, c2, d2, X[ 7], 5, k8); - Subround(G, d2, e2, a2, b2, c2, X[10], 15, k8); - Subround(G, c2, d2, e2, a2, b2, X[14], 8, k8); - - Subround(F, b2, c2, d2, e2, a2, X[12], 8, k9); - Subround(F, a2, b2, c2, d2, e2, X[15], 5, k9); - Subround(F, e2, a2, b2, c2, d2, X[10], 12, k9); - Subround(F, d2, e2, a2, b2, c2, X[ 4], 9, k9); - Subround(F, c2, d2, e2, a2, b2, X[ 1], 12, k9); - Subround(F, b2, c2, d2, e2, a2, X[ 5], 5, k9); - Subround(F, a2, b2, c2, d2, e2, X[ 8], 14, k9); - Subround(F, e2, a2, b2, c2, d2, X[ 7], 6, k9); - Subround(F, d2, e2, a2, b2, c2, X[ 6], 8, k9); - Subround(F, c2, d2, e2, a2, b2, X[ 2], 13, k9); - Subround(F, b2, c2, d2, e2, a2, X[13], 6, k9); - Subround(F, a2, b2, c2, d2, e2, X[14], 5, k9); - Subround(F, e2, a2, b2, c2, d2, X[ 0], 15, k9); - Subround(F, d2, e2, a2, b2, c2, X[ 3], 13, k9); - Subround(F, c2, d2, e2, a2, b2, X[ 9], 11, k9); - Subround(F, b2, c2, d2, e2, a2, X[11], 11, k9); - - a1 -= trackA[0]; - b1 -= trackA[1]; - c1 -= trackA[2]; - d1 -= trackA[3]; - e1 -= trackA[4]; - a2 -= trackB[0]; - b2 -= trackB[1]; - c2 -= trackB[2]; - d2 -= trackB[3]; - e2 -= trackB[4]; - - if (!last) - { - trackA[0] = (b1 + e1) - d2; - trackA[1] = c1 - e2; - trackA[2] = d1 - a2; - trackA[3] = e1 - b2; - trackA[4] = a1 - c2; - trackB[0] = d1 - e2; - trackB[1] = (e1 + c1) - a2; - trackB[2] = a1 - b2; - trackB[3] = b1 - c2; - trackB[4] = c1 - d2; - } - else - { - trackB[0] = a2 - a1; - trackB[1] = b2 - b1; - trackB[2] = c2 - c1; - trackB[3] = d2 - d1; - trackB[4] = e2 - e1; - trackA[0] = 0; - trackA[1] = 0; - trackA[2] = 0; - trackA[3] = 0; - trackA[4] = 0; - } -} - -NAMESPACE_END diff --git a/lib/cryptopp/ttmac.h b/lib/cryptopp/ttmac.h deleted file mode 100644 index b4bf86e26..000000000 --- a/lib/cryptopp/ttmac.h +++ /dev/null @@ -1,38 +0,0 @@ -// ttmac.h - written and placed in the public domain by Kevin Springle - -#ifndef CRYPTOPP_TTMAC_H -#define CRYPTOPP_TTMAC_H - -#include "seckey.h" -#include "iterhash.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -class CRYPTOPP_NO_VTABLE TTMAC_Base : public FixedKeyLength<20>, public IteratedHash -{ -public: - static std::string StaticAlgorithmName() {return std::string("Two-Track-MAC");} - CRYPTOPP_CONSTANT(DIGESTSIZE=20) - - unsigned int DigestSize() const {return DIGESTSIZE;}; - void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms); - void TruncatedFinal(byte *mac, size_t size); - -protected: - static void Transform (word32 *digest, const word32 *X, bool last); - void HashEndianCorrectedBlock(const word32 *data) {Transform(m_digest, data, false);} - void Init(); - word32* StateBuf() {return m_digest;} - - FixedSizeSecBlock m_digest; - FixedSizeSecBlock m_key; -}; - -//! Two-Track-MAC -/*! 160 Bit MAC with 160 Bit Key */ -DOCUMENTED_TYPEDEF(MessageAuthenticationCodeFinal, TTMAC) - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/validate.h b/lib/cryptopp/validate.h deleted file mode 100644 index 0ab23cba3..000000000 --- a/lib/cryptopp/validate.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef CRYPTOPP_VALIDATE_H -#define CRYPTOPP_VALIDATE_H - -#include "cryptlib.h" - -bool ValidateAll(bool thorough); -bool TestSettings(); -bool TestOS_RNG(); -bool ValidateBaseCode(); - -bool ValidateCRC32(); -bool ValidateAdler32(); -bool ValidateMD2(); -bool ValidateMD4(); -bool ValidateMD5(); -bool ValidateSHA(); -bool ValidateSHA2(); -bool ValidateTiger(); -bool ValidateRIPEMD(); -bool ValidatePanama(); -bool ValidateWhirlpool(); - -bool ValidateHMAC(); -bool ValidateTTMAC(); - -bool ValidateCipherModes(); -bool ValidatePBKDF(); - -bool ValidateDES(); -bool ValidateIDEA(); -bool ValidateSAFER(); -bool ValidateRC2(); -bool ValidateARC4(); - -bool ValidateRC5(); -bool ValidateBlowfish(); -bool ValidateThreeWay(); -bool ValidateGOST(); -bool ValidateSHARK(); -bool ValidateSEAL(); -bool ValidateCAST(); -bool ValidateSquare(); -bool ValidateSKIPJACK(); -bool ValidateRC6(); -bool ValidateMARS(); -bool ValidateRijndael(); -bool ValidateTwofish(); -bool ValidateSerpent(); -bool ValidateSHACAL2(); -bool ValidateCamellia(); -bool ValidateSalsa(); -bool ValidateSosemanuk(); -bool ValidateVMAC(); -bool ValidateCCM(); -bool ValidateGCM(); -bool ValidateCMAC(); - -bool ValidateBBS(); -bool ValidateDH(); -bool ValidateMQV(); -bool ValidateRSA(); -bool ValidateElGamal(); -bool ValidateDLIES(); -bool ValidateNR(); -bool ValidateDSA(bool thorough); -bool ValidateLUC(); -bool ValidateLUC_DL(); -bool ValidateLUC_DH(); -bool ValidateXTR_DH(); -bool ValidateRabin(); -bool ValidateRW(); -//bool ValidateBlumGoldwasser(); -bool ValidateECP(); -bool ValidateEC2N(); -bool ValidateECDSA(); -bool ValidateESIGN(); - -CryptoPP::RandomNumberGenerator & GlobalRNG(); -bool RunTestDataFile(const char *filename, const CryptoPP::NameValuePairs &overrideParameters=CryptoPP::g_nullNameValuePairs, bool thorough=true); - -#endif diff --git a/lib/cryptopp/vmac.cpp b/lib/cryptopp/vmac.cpp deleted file mode 100644 index 6b490f904..000000000 --- a/lib/cryptopp/vmac.cpp +++ /dev/null @@ -1,832 +0,0 @@ -// vmac.cpp - written and placed in the public domain by Wei Dai -// based on Ted Krovetz's public domain vmac.c and draft-krovetz-vmac-01.txt - -#include "pch.h" -#include "vmac.h" -#include "argnames.h" -#include "cpu.h" - -NAMESPACE_BEGIN(CryptoPP) - -#if defined(_MSC_VER) && !CRYPTOPP_BOOL_SLOW_WORD64 -#include -#endif - -#define VMAC_BOOL_WORD128 (defined(CRYPTOPP_WORD128_AVAILABLE) && !defined(CRYPTOPP_X64_ASM_AVAILABLE)) -#ifdef __BORLANDC__ -#define const // Turbo C++ 2006 workaround -#endif -static const word64 p64 = W64LIT(0xfffffffffffffeff); /* 2^64 - 257 prime */ -static const word64 m62 = W64LIT(0x3fffffffffffffff); /* 62-bit mask */ -static const word64 m63 = W64LIT(0x7fffffffffffffff); /* 63-bit mask */ -static const word64 m64 = W64LIT(0xffffffffffffffff); /* 64-bit mask */ -static const word64 mpoly = W64LIT(0x1fffffff1fffffff); /* Poly key mask */ -#ifdef __BORLANDC__ -#undef const -#endif -#if VMAC_BOOL_WORD128 -#ifdef __powerpc__ -// workaround GCC Bug 31690: ICE with const __uint128_t and C++ front-end -#define m126 ((word128(m62)<<64)|m64) -#else -static const word128 m126 = (word128(m62)<<64)|m64; /* 126-bit mask */ -#endif -#endif - -void VMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms) -{ - int digestLength = params.GetIntValueWithDefault(Name::DigestSize(), DefaultDigestSize()); - if (digestLength != 8 && digestLength != 16) - throw InvalidArgument("VMAC: DigestSize must be 8 or 16"); - m_is128 = digestLength == 16; - - m_L1KeyLength = params.GetIntValueWithDefault(Name::L1KeyLength(), 128); - if (m_L1KeyLength <= 0 || m_L1KeyLength % 128 != 0) - throw InvalidArgument("VMAC: L1KeyLength must be a positive multiple of 128"); - - AllocateBlocks(); - - BlockCipher &cipher = AccessCipher(); - cipher.SetKey(userKey, keylength, params); - unsigned int blockSize = cipher.BlockSize(); - unsigned int blockSizeInWords = blockSize / sizeof(word64); - SecBlock out(blockSizeInWords); - SecByteBlock in; - in.CleanNew(blockSize); - size_t i; - - /* Fill nh key */ - in[0] = 0x80; - cipher.AdvancedProcessBlocks(in, NULL, (byte *)m_nhKey(), m_nhKeySize()*sizeof(word64), cipher.BT_InBlockIsCounter); - ConditionalByteReverse(BIG_ENDIAN_ORDER, m_nhKey(), m_nhKey(), m_nhKeySize()*sizeof(word64)); - - /* Fill poly key */ - in[0] = 0xC0; - in[15] = 0; - for (i = 0; i <= (size_t)m_is128; i++) - { - cipher.ProcessBlock(in, out.BytePtr()); - m_polyState()[i*4+2] = GetWord(true, BIG_ENDIAN_ORDER, out.BytePtr()) & mpoly; - m_polyState()[i*4+3] = GetWord(true, BIG_ENDIAN_ORDER, out.BytePtr()+8) & mpoly; - in[15]++; - } - - /* Fill ip key */ - in[0] = 0xE0; - in[15] = 0; - word64 *l3Key = m_l3Key(); - for (i = 0; i <= (size_t)m_is128; i++) - do - { - cipher.ProcessBlock(in, out.BytePtr()); - l3Key[i*2+0] = GetWord(true, BIG_ENDIAN_ORDER, out.BytePtr()); - l3Key[i*2+1] = GetWord(true, BIG_ENDIAN_ORDER, out.BytePtr()+8); - in[15]++; - } while ((l3Key[i*2+0] >= p64) || (l3Key[i*2+1] >= p64)); - - m_padCached = false; - size_t nonceLength; - const byte *nonce = GetIVAndThrowIfInvalid(params, nonceLength); - Resynchronize(nonce, (int)nonceLength); -} - -void VMAC_Base::GetNextIV(RandomNumberGenerator &rng, byte *IV) -{ - SimpleKeyingInterface::GetNextIV(rng, IV); - IV[0] &= 0x7f; -} - -void VMAC_Base::Resynchronize(const byte *nonce, int len) -{ - size_t length = ThrowIfInvalidIVLength(len); - size_t s = IVSize(); - byte *storedNonce = m_nonce(); - - if (m_is128) - { - memset(storedNonce, 0, s-length); - memcpy(storedNonce+s-length, nonce, length); - AccessCipher().ProcessBlock(storedNonce, m_pad()); - } - else - { - if (m_padCached && (storedNonce[s-1] | 1) == (nonce[length-1] | 1)) - { - m_padCached = VerifyBufsEqual(storedNonce+s-length, nonce, length-1); - for (size_t i=0; m_padCached && i>64); rl = word64(p);} - #define AccumulateNH(a, b, c) a += word128(b)*(c) - #define Multiply128(r, i1, i2) r = word128(word64(i1)) * word64(i2) -#else - #if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER) - #define MUL32(a, b) __emulu(word32(a), word32(b)) - #else - #define MUL32(a, b) ((word64)((word32)(a)) * (word32)(b)) - #endif - #if defined(CRYPTOPP_X64_ASM_AVAILABLE) - #define DeclareNH(a) word64 a##0=0, a##1=0 - #define MUL64(rh,rl,i1,i2) asm ("mulq %3" : "=a"(rl), "=d"(rh) : "a"(i1), "g"(i2) : "cc"); - #define AccumulateNH(a, b, c) asm ("mulq %3; addq %%rax, %0; adcq %%rdx, %1" : "+r"(a##0), "+r"(a##1) : "a"(b), "g"(c) : "%rdx", "cc"); - #define ADD128(rh,rl,ih,il) asm ("addq %3, %1; adcq %2, %0" : "+r"(rh),"+r"(rl) : "r"(ih),"r"(il) : "cc"); - #elif defined(_MSC_VER) && !CRYPTOPP_BOOL_SLOW_WORD64 - #define DeclareNH(a) word64 a##0=0, a##1=0 - #define MUL64(rh,rl,i1,i2) (rl) = _umul128(i1,i2,&(rh)); - #define AccumulateNH(a, b, c) {\ - word64 ph, pl;\ - pl = _umul128(b,c,&ph);\ - a##0 += pl;\ - a##1 += ph + (a##0 < pl);} - #else - #define VMAC_BOOL_32BIT 1 - #define DeclareNH(a) word64 a##0=0, a##1=0, a##2=0 - #define MUL64(rh,rl,i1,i2) \ - { word64 _i1 = (i1), _i2 = (i2); \ - word64 m1= MUL32(_i1,_i2>>32); \ - word64 m2= MUL32(_i1>>32,_i2); \ - rh = MUL32(_i1>>32,_i2>>32); \ - rl = MUL32(_i1,_i2); \ - ADD128(rh,rl,(m1 >> 32),(m1 << 32)); \ - ADD128(rh,rl,(m2 >> 32),(m2 << 32)); \ - } - #define AccumulateNH(a, b, c) {\ - word64 p = MUL32(b, c);\ - a##1 += word32((p)>>32);\ - a##0 += word32(p);\ - p = MUL32((b)>>32, c);\ - a##2 += word32((p)>>32);\ - a##1 += word32(p);\ - p = MUL32((b)>>32, (c)>>32);\ - a##2 += p;\ - p = MUL32(b, (c)>>32);\ - a##1 += word32(p);\ - a##2 += word32(p>>32);} - #endif -#endif -#ifndef VMAC_BOOL_32BIT - #define VMAC_BOOL_32BIT 0 -#endif -#ifndef ADD128 - #define ADD128(rh,rl,ih,il) \ - { word64 _il = (il); \ - (rl) += (_il); \ - (rh) += (ih) + ((rl) < (_il)); \ - } -#endif - -#if !(defined(_MSC_VER) && _MSC_VER < 1300) -template -#endif -void VMAC_Base::VHASH_Update_Template(const word64 *data, size_t blocksRemainingInWord64) -{ - #define INNER_LOOP_ITERATION(j) {\ - word64 d0 = ConditionalByteReverse(LITTLE_ENDIAN_ORDER, data[i+2*j+0]);\ - word64 d1 = ConditionalByteReverse(LITTLE_ENDIAN_ORDER, data[i+2*j+1]);\ - AccumulateNH(nhA, d0+nhK[i+2*j+0], d1+nhK[i+2*j+1]);\ - if (T_128BitTag)\ - AccumulateNH(nhB, d0+nhK[i+2*j+2], d1+nhK[i+2*j+3]);\ - } - -#if (defined(_MSC_VER) && _MSC_VER < 1300) - bool T_128BitTag = m_is128; -#endif - size_t L1KeyLengthInWord64 = m_L1KeyLength / 8; - size_t innerLoopEnd = L1KeyLengthInWord64; - const word64 *nhK = m_nhKey(); - word64 *polyS = m_polyState(); - bool isFirstBlock = true; - size_t i; - - #if !VMAC_BOOL_32BIT - #if VMAC_BOOL_WORD128 - word128 a1, a2; - #else - word64 ah1, al1, ah2, al2; - #endif - word64 kh1, kl1, kh2, kl2; - kh1=(polyS+0*4+2)[0]; kl1=(polyS+0*4+2)[1]; - if (T_128BitTag) - { - kh2=(polyS+1*4+2)[0]; kl2=(polyS+1*4+2)[1]; - } - #endif - - do - { - DeclareNH(nhA); - DeclareNH(nhB); - - i = 0; - if (blocksRemainingInWord64 < L1KeyLengthInWord64) - { - if (blocksRemainingInWord64 % 8) - { - innerLoopEnd = blocksRemainingInWord64 % 8; - for (; i> 32); - nh1[0] = word32(nhA1); - nh2[0] = (nhA2 + (nhA1 >> 32)) & m62; - - if (T_128BitTag) - { - nh0[1] = word32(nhB0); - nhB1 += (nhB0 >> 32); - nh1[1] = word32(nhB1); - nh2[1] = (nhB2 + (nhB1 >> 32)) & m62; - } - - #define a0 (((word32 *)(polyS+i*4))[2+NativeByteOrder::ToEnum()]) - #define a1 (*(((word32 *)(polyS+i*4))+3-NativeByteOrder::ToEnum())) // workaround for GCC 3.2 - #define a2 (((word32 *)(polyS+i*4))[0+NativeByteOrder::ToEnum()]) - #define a3 (*(((word32 *)(polyS+i*4))+1-NativeByteOrder::ToEnum())) - #define aHi ((polyS+i*4)[0]) - #define k0 (((word32 *)(polyS+i*4+2))[2+NativeByteOrder::ToEnum()]) - #define k1 (*(((word32 *)(polyS+i*4+2))+3-NativeByteOrder::ToEnum())) - #define k2 (((word32 *)(polyS+i*4+2))[0+NativeByteOrder::ToEnum()]) - #define k3 (*(((word32 *)(polyS+i*4+2))+1-NativeByteOrder::ToEnum())) - #define kHi ((polyS+i*4+2)[0]) - - if (isFirstBlock) - { - isFirstBlock = false; - if (m_isFirstBlock) - { - m_isFirstBlock = false; - for (i=0; i<=(size_t)T_128BitTag; i++) - { - word64 t = (word64)nh0[i] + k0; - a0 = (word32)t; - t = (t >> 32) + nh1[i] + k1; - a1 = (word32)t; - aHi = (t >> 32) + nh2[i] + kHi; - } - continue; - } - } - for (i=0; i<=(size_t)T_128BitTag; i++) - { - word64 p, t; - word32 t2; - - p = MUL32(a3, 2*k3); - p += nh2[i]; - p += MUL32(a0, k2); - p += MUL32(a1, k1); - p += MUL32(a2, k0); - t2 = (word32)p; - p >>= 32; - p += MUL32(a0, k3); - p += MUL32(a1, k2); - p += MUL32(a2, k1); - p += MUL32(a3, k0); - t = (word64(word32(p) & 0x7fffffff) << 32) | t2; - p >>= 31; - p += nh0[i]; - p += MUL32(a0, k0); - p += MUL32(a1, 2*k3); - p += MUL32(a2, 2*k2); - p += MUL32(a3, 2*k1); - t2 = (word32)p; - p >>= 32; - p += nh1[i]; - p += MUL32(a0, k1); - p += MUL32(a1, k0); - p += MUL32(a2, 2*k3); - p += MUL32(a3, 2*k2); - a0 = t2; - a1 = (word32)p; - aHi = (p >> 32) + t; - } - - #undef a0 - #undef a1 - #undef a2 - #undef a3 - #undef aHi - #undef k0 - #undef k1 - #undef k2 - #undef k3 - #undef kHi - #else // #if VMAC_BOOL_32BIT - if (isFirstBlock) - { - isFirstBlock = false; - if (m_isFirstBlock) - { - m_isFirstBlock = false; - #if VMAC_BOOL_WORD128 - #define first_poly_step(a, kh, kl, m) a = (m & m126) + ((word128(kh) << 64) | kl) - - first_poly_step(a1, kh1, kl1, nhA); - if (T_128BitTag) - first_poly_step(a2, kh2, kl2, nhB); - #else - #define first_poly_step(ah, al, kh, kl, mh, ml) {\ - mh &= m62;\ - ADD128(mh, ml, kh, kl); \ - ah = mh; al = ml;} - - first_poly_step(ah1, al1, kh1, kl1, nhA1, nhA0); - if (T_128BitTag) - first_poly_step(ah2, al2, kh2, kl2, nhB1, nhB0); - #endif - continue; - } - else - { - #if VMAC_BOOL_WORD128 - a1 = (word128((polyS+0*4)[0]) << 64) | (polyS+0*4)[1]; - #else - ah1=(polyS+0*4)[0]; al1=(polyS+0*4)[1]; - #endif - if (T_128BitTag) - { - #if VMAC_BOOL_WORD128 - a2 = (word128((polyS+1*4)[0]) << 64) | (polyS+1*4)[1]; - #else - ah2=(polyS+1*4)[0]; al2=(polyS+1*4)[1]; - #endif - } - } - } - - #if VMAC_BOOL_WORD128 - #define poly_step(a, kh, kl, m) \ - { word128 t1, t2, t3, t4;\ - Multiply128(t2, a>>64, kl);\ - Multiply128(t3, a, kh);\ - Multiply128(t1, a, kl);\ - Multiply128(t4, a>>64, 2*kh);\ - t2 += t3;\ - t4 += t1;\ - t2 += t4>>64;\ - a = (word128(word64(t2)&m63) << 64) | word64(t4);\ - t2 *= 2;\ - a += m & m126;\ - a += t2>>64;} - - poly_step(a1, kh1, kl1, nhA); - if (T_128BitTag) - poly_step(a2, kh2, kl2, nhB); - #else - #define poly_step(ah, al, kh, kl, mh, ml) \ - { word64 t1h, t1l, t2h, t2l, t3h, t3l, z=0; \ - /* compute ab*cd, put bd into result registers */ \ - MUL64(t2h,t2l,ah,kl); \ - MUL64(t3h,t3l,al,kh); \ - MUL64(t1h,t1l,ah,2*kh); \ - MUL64(ah,al,al,kl); \ - /* add together ad + bc */ \ - ADD128(t2h,t2l,t3h,t3l); \ - /* add 2 * ac to result */ \ - ADD128(ah,al,t1h,t1l); \ - /* now (ah,al), (t2l,2*t2h) need summing */ \ - /* first add the high registers, carrying into t2h */ \ - ADD128(t2h,ah,z,t2l); \ - /* double t2h and add top bit of ah */ \ - t2h += t2h + (ah >> 63); \ - ah &= m63; \ - /* now add the low registers */ \ - mh &= m62; \ - ADD128(ah,al,mh,ml); \ - ADD128(ah,al,z,t2h); \ - } - - poly_step(ah1, al1, kh1, kl1, nhA1, nhA0); - if (T_128BitTag) - poly_step(ah2, al2, kh2, kl2, nhB1, nhB0); - #endif - #endif // #if VMAC_BOOL_32BIT - } while (blocksRemainingInWord64); - - #if VMAC_BOOL_WORD128 - (polyS+0*4)[0]=word64(a1>>64); (polyS+0*4)[1]=word64(a1); - if (T_128BitTag) - { - (polyS+1*4)[0]=word64(a2>>64); (polyS+1*4)[1]=word64(a2); - } - #elif !VMAC_BOOL_32BIT - (polyS+0*4)[0]=ah1; (polyS+0*4)[1]=al1; - if (T_128BitTag) - { - (polyS+1*4)[0]=ah2; (polyS+1*4)[1]=al2; - } - #endif -} - -inline void VMAC_Base::VHASH_Update(const word64 *data, size_t blocksRemainingInWord64) -{ -#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && CRYPTOPP_BOOL_X86 - if (HasSSE2()) - { - VHASH_Update_SSE2(data, blocksRemainingInWord64, 0); - if (m_is128) - VHASH_Update_SSE2(data, blocksRemainingInWord64, 1); - m_isFirstBlock = false; - } - else -#endif - { -#if defined(_MSC_VER) && _MSC_VER < 1300 - VHASH_Update_Template(data, blocksRemainingInWord64); -#else - if (m_is128) - VHASH_Update_Template(data, blocksRemainingInWord64); - else - VHASH_Update_Template(data, blocksRemainingInWord64); -#endif - } -} - -size_t VMAC_Base::HashMultipleBlocks(const word64 *data, size_t length) -{ - size_t remaining = ModPowerOf2(length, m_L1KeyLength); - VHASH_Update(data, (length-remaining)/8); - return remaining; -} - -static word64 L3Hash(const word64 *input, const word64 *l3Key, size_t len) -{ - word64 rh, rl, t, z=0; - word64 p1 = input[0], p2 = input[1]; - word64 k1 = l3Key[0], k2 = l3Key[1]; - - /* fully reduce (p1,p2)+(len,0) mod p127 */ - t = p1 >> 63; - p1 &= m63; - ADD128(p1, p2, len, t); - /* At this point, (p1,p2) is at most 2^127+(len<<64) */ - t = (p1 > m63) + ((p1 == m63) & (p2 == m64)); - ADD128(p1, p2, z, t); - p1 &= m63; - - /* compute (p1,p2)/(2^64-2^32) and (p1,p2)%(2^64-2^32) */ - t = p1 + (p2 >> 32); - t += (t >> 32); - t += (word32)t > 0xfffffffeU; - p1 += (t >> 32); - p2 += (p1 << 32); - - /* compute (p1+k1)%p64 and (p2+k2)%p64 */ - p1 += k1; - p1 += (0 - (p1 < k1)) & 257; - p2 += k2; - p2 += (0 - (p2 < k2)) & 257; - - /* compute (p1+k1)*(p2+k2)%p64 */ - MUL64(rh, rl, p1, p2); - t = rh >> 56; - ADD128(t, rl, z, rh); - rh <<= 8; - ADD128(t, rl, z, rh); - t += t << 8; - rl += t; - rl += (0 - (rl < t)) & 257; - rl += (0 - (rl > p64-1)) & 257; - return rl; -} - -void VMAC_Base::TruncatedFinal(byte *mac, size_t size) -{ - size_t len = ModPowerOf2(GetBitCountLo()/8, m_L1KeyLength); - - if (len) - { - memset(m_data()+len, 0, (0-len)%16); - VHASH_Update(DataBuf(), ((len+15)/16)*2); - len *= 8; // convert to bits - } - else if (m_isFirstBlock) - { - // special case for empty string - m_polyState()[0] = m_polyState()[2]; - m_polyState()[1] = m_polyState()[3]; - if (m_is128) - { - m_polyState()[4] = m_polyState()[6]; - m_polyState()[5] = m_polyState()[7]; - } - } - - if (m_is128) - { - word64 t[2]; - t[0] = L3Hash(m_polyState(), m_l3Key(), len) + GetWord(true, BIG_ENDIAN_ORDER, m_pad()); - t[1] = L3Hash(m_polyState()+4, m_l3Key()+2, len) + GetWord(true, BIG_ENDIAN_ORDER, m_pad()+8); - if (size == 16) - { - PutWord(false, BIG_ENDIAN_ORDER, mac, t[0]); - PutWord(false, BIG_ENDIAN_ORDER, mac+8, t[1]); - } - else - { - t[0] = ConditionalByteReverse(BIG_ENDIAN_ORDER, t[0]); - t[1] = ConditionalByteReverse(BIG_ENDIAN_ORDER, t[1]); - memcpy(mac, t, size); - } - } - else - { - word64 t = L3Hash(m_polyState(), m_l3Key(), len); - t += GetWord(true, BIG_ENDIAN_ORDER, m_pad() + (m_nonce()[IVSize()-1]&1) * 8); - if (size == 8) - PutWord(false, BIG_ENDIAN_ORDER, mac, t); - else - { - t = ConditionalByteReverse(BIG_ENDIAN_ORDER, t); - memcpy(mac, &t, size); - } - } -} - -NAMESPACE_END diff --git a/lib/cryptopp/vmac.h b/lib/cryptopp/vmac.h deleted file mode 100644 index 07240173c..000000000 --- a/lib/cryptopp/vmac.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef CRYPTOPP_VMAC_H -#define CRYPTOPP_VMAC_H - -#include "iterhash.h" -#include "seckey.h" - -NAMESPACE_BEGIN(CryptoPP) - -/// . -class VMAC_Base : public IteratedHashBase -{ -public: - std::string AlgorithmName() const {return std::string("VMAC(") + GetCipher().AlgorithmName() + ")-" + IntToString(DigestSize()*8);} - unsigned int IVSize() const {return GetCipher().BlockSize();} - unsigned int MinIVLength() const {return 1;} - void Resynchronize(const byte *nonce, int length=-1); - void GetNextIV(RandomNumberGenerator &rng, byte *IV); - unsigned int DigestSize() const {return m_is128 ? 16 : 8;}; - void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms); - void TruncatedFinal(byte *mac, size_t size); - unsigned int BlockSize() const {return m_L1KeyLength;} - ByteOrder GetByteOrder() const {return LITTLE_ENDIAN_ORDER;} - -protected: - virtual BlockCipher & AccessCipher() =0; - virtual int DefaultDigestSize() const =0; - const BlockCipher & GetCipher() const {return const_cast(this)->AccessCipher();} - void HashEndianCorrectedBlock(const word64 *data); - size_t HashMultipleBlocks(const word64 *input, size_t length); - void Init() {} - word64* StateBuf() {return NULL;} - word64* DataBuf() {return (word64 *)m_data();} - - void VHASH_Update_SSE2(const word64 *data, size_t blocksRemainingInWord64, int tagPart); -#if !(defined(_MSC_VER) && _MSC_VER < 1300) // can't use function template here with VC6 - template -#endif - void VHASH_Update_Template(const word64 *data, size_t blockRemainingInWord128); - void VHASH_Update(const word64 *data, size_t blocksRemainingInWord128); - - CRYPTOPP_BLOCK_1(polyState, word64, 4*(m_is128+1)) - CRYPTOPP_BLOCK_2(nhKey, word64, m_L1KeyLength/sizeof(word64) + 2*m_is128) - CRYPTOPP_BLOCK_3(data, byte, m_L1KeyLength) - CRYPTOPP_BLOCK_4(l3Key, word64, 2*(m_is128+1)) - CRYPTOPP_BLOCK_5(nonce, byte, IVSize()) - CRYPTOPP_BLOCK_6(pad, byte, IVSize()) - CRYPTOPP_BLOCKS_END(6) - - bool m_is128, m_padCached, m_isFirstBlock; - int m_L1KeyLength; -}; - -/// VMAC -template -class VMAC : public SimpleKeyingInterfaceImpl > -{ -public: - static std::string StaticAlgorithmName() {return std::string("VMAC(") + T_BlockCipher::StaticAlgorithmName() + ")-" + IntToString(T_DigestBitSize);} - -private: - BlockCipher & AccessCipher() {return m_cipher;} - int DefaultDigestSize() const {return T_DigestBitSize/8;} - typename T_BlockCipher::Encryption m_cipher; -}; - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/wait.cpp b/lib/cryptopp/wait.cpp deleted file mode 100644 index 198785838..000000000 --- a/lib/cryptopp/wait.cpp +++ /dev/null @@ -1,397 +0,0 @@ -// wait.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "wait.h" -#include "misc.h" - -#ifdef SOCKETS_AVAILABLE - -#ifdef USE_BERKELEY_STYLE_SOCKETS -#include -#include -#include -#include -#endif - -NAMESPACE_BEGIN(CryptoPP) - -unsigned int WaitObjectContainer::MaxWaitObjects() -{ -#ifdef USE_WINDOWS_STYLE_SOCKETS - return MAXIMUM_WAIT_OBJECTS * (MAXIMUM_WAIT_OBJECTS-1); -#else - return FD_SETSIZE; -#endif -} - -WaitObjectContainer::WaitObjectContainer(WaitObjectsTracer* tracer) - : m_tracer(tracer), m_eventTimer(Timer::MILLISECONDS) - , m_sameResultCount(0), m_noWaitTimer(Timer::MILLISECONDS) -{ - Clear(); - m_eventTimer.StartTimer(); -} - -void WaitObjectContainer::Clear() -{ -#ifdef USE_WINDOWS_STYLE_SOCKETS - m_handles.clear(); -#else - m_maxFd = 0; - FD_ZERO(&m_readfds); - FD_ZERO(&m_writefds); -#endif - m_noWait = false; - m_firstEventTime = 0; -} - -inline void WaitObjectContainer::SetLastResult(LastResultType result) -{ - if (result == m_lastResult) - m_sameResultCount++; - else - { - m_lastResult = result; - m_sameResultCount = 0; - } -} - -void WaitObjectContainer::DetectNoWait(LastResultType result, CallStack const& callStack) -{ - if (result == m_lastResult && m_noWaitTimer.ElapsedTime() > 1000) - { - if (m_sameResultCount > m_noWaitTimer.ElapsedTime()) - { - if (m_tracer) - { - std::string desc = "No wait loop detected - m_lastResult: "; - desc.append(IntToString(m_lastResult)).append(", call stack:"); - for (CallStack const* cs = &callStack; cs; cs = cs->Prev()) - desc.append("\n- ").append(cs->Format()); - m_tracer->TraceNoWaitLoop(desc); - } - try { throw 0; } catch (...) {} // help debugger break - } - - m_noWaitTimer.StartTimer(); - m_sameResultCount = 0; - } -} - -void WaitObjectContainer::SetNoWait(CallStack const& callStack) -{ - DetectNoWait(LASTRESULT_NOWAIT, CallStack("WaitObjectContainer::SetNoWait()", &callStack)); - m_noWait = true; -} - -void WaitObjectContainer::ScheduleEvent(double milliseconds, CallStack const& callStack) -{ - if (milliseconds <= 3) - DetectNoWait(LASTRESULT_SCHEDULED, CallStack("WaitObjectContainer::ScheduleEvent()", &callStack)); - double thisEventTime = m_eventTimer.ElapsedTimeAsDouble() + milliseconds; - if (!m_firstEventTime || thisEventTime < m_firstEventTime) - m_firstEventTime = thisEventTime; -} - -#ifdef USE_WINDOWS_STYLE_SOCKETS - -struct WaitingThreadData -{ - bool waitingToWait, terminate; - HANDLE startWaiting, stopWaiting; - const HANDLE *waitHandles; - unsigned int count; - HANDLE threadHandle; - DWORD threadId; - DWORD* error; -}; - -WaitObjectContainer::~WaitObjectContainer() -{ - try // don't let exceptions escape destructor - { - if (!m_threads.empty()) - { - HANDLE threadHandles[MAXIMUM_WAIT_OBJECTS]; - unsigned int i; - for (i=0; i pThread((WaitingThreadData *)lParam); - WaitingThreadData &thread = *pThread; - std::vector handles; - - while (true) - { - thread.waitingToWait = true; - ::WaitForSingleObject(thread.startWaiting, INFINITE); - thread.waitingToWait = false; - - if (thread.terminate) - break; - if (!thread.count) - continue; - - handles.resize(thread.count + 1); - handles[0] = thread.stopWaiting; - std::copy(thread.waitHandles, thread.waitHandles+thread.count, handles.begin()+1); - - DWORD result = ::WaitForMultipleObjects((DWORD)handles.size(), &handles[0], FALSE, INFINITE); - - if (result == WAIT_OBJECT_0) - continue; // another thread finished waiting first, so do nothing - SetEvent(thread.stopWaiting); - if (!(result > WAIT_OBJECT_0 && result < WAIT_OBJECT_0 + handles.size())) - { - assert(!"error in WaitingThread"); // break here so we can see which thread has an error - *thread.error = ::GetLastError(); - } - } - - return S_OK; // return a value here to avoid compiler warning -} - -void WaitObjectContainer::CreateThreads(unsigned int count) -{ - size_t currentCount = m_threads.size(); - if (currentCount == 0) - { - m_startWaiting = ::CreateEvent(NULL, TRUE, FALSE, NULL); - m_stopWaiting = ::CreateEvent(NULL, TRUE, FALSE, NULL); - } - - if (currentCount < count) - { - m_threads.resize(count); - for (size_t i=currentCount; i MAXIMUM_WAIT_OBJECTS) - { - // too many wait objects for a single WaitForMultipleObjects call, so use multiple threads - static const unsigned int WAIT_OBJECTS_PER_THREAD = MAXIMUM_WAIT_OBJECTS-1; - unsigned int nThreads = (unsigned int)((m_handles.size() + WAIT_OBJECTS_PER_THREAD - 1) / WAIT_OBJECTS_PER_THREAD); - if (nThreads > MAXIMUM_WAIT_OBJECTS) // still too many wait objects, maybe implement recursive threading later? - throw Err("WaitObjectContainer: number of wait objects exceeds limit"); - CreateThreads(nThreads); - DWORD error = S_OK; - - for (unsigned int i=0; i 0) - { - unsigned long timeAfterWait = t.ElapsedTime(); - OutputDebugString(("Handles " + IntToString(m_handles.size()) + ", Woke up by " + IntToString(result-WAIT_OBJECT_0) + ", Busied for " + IntToString(timeBeforeWait-lastTime) + " us, Waited for " + IntToString(timeAfterWait-timeBeforeWait) + " us, max " + IntToString(milliseconds) + "ms\n").c_str()); - lastTime = timeAfterWait; - } -#endif - if (result >= WAIT_OBJECT_0 && result < WAIT_OBJECT_0 + m_handles.size()) - { - if (result == m_lastResult) - m_sameResultCount++; - else - { - m_lastResult = result; - m_sameResultCount = 0; - } - return true; - } - else if (result == WAIT_TIMEOUT) - { - SetLastResult(timeoutIsScheduledEvent ? LASTRESULT_SCHEDULED : LASTRESULT_TIMEOUT); - return timeoutIsScheduledEvent; - } - else - throw Err("WaitObjectContainer: WaitForMultipleObjects failed with error " + IntToString(::GetLastError())); - } -} - -#else // #ifdef USE_WINDOWS_STYLE_SOCKETS - -void WaitObjectContainer::AddReadFd(int fd, CallStack const& callStack) // TODO: do something with callStack -{ - FD_SET(fd, &m_readfds); - m_maxFd = STDMAX(m_maxFd, fd); -} - -void WaitObjectContainer::AddWriteFd(int fd, CallStack const& callStack) // TODO: do something with callStack -{ - FD_SET(fd, &m_writefds); - m_maxFd = STDMAX(m_maxFd, fd); -} - -bool WaitObjectContainer::Wait(unsigned long milliseconds) -{ - if (m_noWait || (!m_maxFd && !m_firstEventTime)) - return true; - - bool timeoutIsScheduledEvent = false; - - if (m_firstEventTime) - { - double timeToFirstEvent = SaturatingSubtract(m_firstEventTime, m_eventTimer.ElapsedTimeAsDouble()); - if (timeToFirstEvent <= milliseconds) - { - milliseconds = (unsigned long)timeToFirstEvent; - timeoutIsScheduledEvent = true; - } - } - - timeval tv, *timeout; - - if (milliseconds == INFINITE_TIME) - timeout = NULL; - else - { - tv.tv_sec = milliseconds / 1000; - tv.tv_usec = (milliseconds % 1000) * 1000; - timeout = &tv; - } - - int result = select(m_maxFd+1, &m_readfds, &m_writefds, NULL, timeout); - - if (result > 0) - return true; - else if (result == 0) - return timeoutIsScheduledEvent; - else - throw Err("WaitObjectContainer: select failed with error " + errno); -} - -#endif - -// ******************************************************** - -std::string CallStack::Format() const -{ - return m_info; -} - -std::string CallStackWithNr::Format() const -{ - return std::string(m_info) + " / nr: " + IntToString(m_nr); -} - -std::string CallStackWithStr::Format() const -{ - return std::string(m_info) + " / " + std::string(m_z); -} - -bool Waitable::Wait(unsigned long milliseconds, CallStack const& callStack) -{ - WaitObjectContainer container; - GetWaitObjects(container, callStack); // reduce clutter by not adding this func to stack - return container.Wait(milliseconds); -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/wait.h b/lib/cryptopp/wait.h deleted file mode 100644 index 045afbc18..000000000 --- a/lib/cryptopp/wait.h +++ /dev/null @@ -1,208 +0,0 @@ -#ifndef CRYPTOPP_WAIT_H -#define CRYPTOPP_WAIT_H - -#include "config.h" - -#ifdef SOCKETS_AVAILABLE - -#include "misc.h" -#include "cryptlib.h" -#include - -#ifdef USE_WINDOWS_STYLE_SOCKETS -#include -#else -#include -#endif - -#include "hrtimer.h" - -NAMESPACE_BEGIN(CryptoPP) - -class Tracer -{ -public: - Tracer(unsigned int level) : m_level(level) {} - virtual ~Tracer() {} - -protected: - //! Override this in your most-derived tracer to do the actual tracing. - virtual void Trace(unsigned int n, std::string const& s) = 0; - - /*! By default, tracers will decide which trace messages to trace according to a trace level - mechanism. If your most-derived tracer uses a different mechanism, override this to - return false. If this method returns false, the default TraceXxxx(void) methods will all - return 0 and must be overridden explicitly by your tracer for trace messages you want. */ - virtual bool UsingDefaults() const { return true; } - -protected: - unsigned int m_level; - - void TraceIf(unsigned int n, std::string const&s) - { if (n) Trace(n, s); } - - /*! Returns nr if, according to the default log settings mechanism (using log levels), - the message should be traced. Returns 0 if the default trace level mechanism is not - in use, or if it is in use but the event should not be traced. Provided as a utility - method for easier and shorter coding of default TraceXxxx(void) implementations. */ - unsigned int Tracing(unsigned int nr, unsigned int minLevel) const - { return (UsingDefaults() && m_level >= minLevel) ? nr : 0; } -}; - -// Your Tracer-derived class should inherit as virtual public from Tracer or another -// Tracer-derived class, and should pass the log level in its constructor. You can use the -// following methods to begin and end your Tracer definition. - -// This constructor macro initializes Tracer directly even if not derived directly from it; -// this is intended, virtual base classes are always initialized by the most derived class. -#define CRYPTOPP_TRACER_CONSTRUCTOR(DERIVED) \ - public: DERIVED(unsigned int level = 0) : Tracer(level) {} - -#define CRYPTOPP_BEGIN_TRACER_CLASS_1(DERIVED, BASE1) \ - class DERIVED : virtual public BASE1 { CRYPTOPP_TRACER_CONSTRUCTOR(DERIVED) - -#define CRYPTOPP_BEGIN_TRACER_CLASS_2(DERIVED, BASE1, BASE2) \ - class DERIVED : virtual public BASE1, virtual public BASE2 { CRYPTOPP_TRACER_CONSTRUCTOR(DERIVED) - -#define CRYPTOPP_END_TRACER_CLASS }; - -// In your Tracer-derived class, you should define a globally unique event number for each -// new event defined. This can be done using the following macros. - -#define CRYPTOPP_BEGIN_TRACER_EVENTS(UNIQUENR) enum { EVENTBASE = UNIQUENR, -#define CRYPTOPP_TRACER_EVENT(EVENTNAME) EventNr_##EVENTNAME, -#define CRYPTOPP_END_TRACER_EVENTS }; - -// In your own Tracer-derived class, you must define two methods per new trace event type: -// - unsigned int TraceXxxx() const -// Your default implementation of this method should return the event number if according -// to the default trace level system the event should be traced, or 0 if it should not. -// - void TraceXxxx(string const& s) -// This method should call TraceIf(TraceXxxx(), s); to do the tracing. -// For your convenience, a macro to define these two types of methods are defined below. -// If you use this macro, you should also use the TRACER_EVENTS macros above to associate -// event names with numbers. - -#define CRYPTOPP_TRACER_EVENT_METHODS(EVENTNAME, LOGLEVEL) \ - virtual unsigned int Trace##EVENTNAME() const { return Tracing(EventNr_##EVENTNAME, LOGLEVEL); } \ - virtual void Trace##EVENTNAME(std::string const& s) { TraceIf(Trace##EVENTNAME(), s); } - - -/*! A simple unidirectional linked list with m_prev == 0 to indicate the final entry. - The aim of this implementation is to provide a very lightweight and practical - tracing mechanism with a low performance impact. Functions and methods supporting - this call-stack mechanism would take a parameter of the form "CallStack const& callStack", - and would pass this parameter to subsequent functions they call using the construct: - - SubFunc(arg1, arg2, CallStack("my func at place such and such", &callStack)); - - The advantage of this approach is that it is easy to use and should be very efficient, - involving no allocation from the heap, just a linked list of stack objects containing - pointers to static ASCIIZ strings (or possibly additional but simple data if derived). */ -class CallStack -{ -public: - CallStack(char const* i, CallStack const* p) : m_info(i), m_prev(p) {} - CallStack const* Prev() const { return m_prev; } - virtual std::string Format() const; - -protected: - char const* m_info; - CallStack const* m_prev; -}; - -/*! An extended CallStack entry type with an additional numeric parameter. */ -class CallStackWithNr : public CallStack -{ -public: - CallStackWithNr(char const* i, word32 n, CallStack const* p) : CallStack(i, p), m_nr(n) {} - std::string Format() const; - -protected: - word32 m_nr; -}; - -/*! An extended CallStack entry type with an additional string parameter. */ -class CallStackWithStr : public CallStack -{ -public: - CallStackWithStr(char const* i, char const* z, CallStack const* p) : CallStack(i, p), m_z(z) {} - std::string Format() const; - -protected: - char const* m_z; -}; - -CRYPTOPP_BEGIN_TRACER_CLASS_1(WaitObjectsTracer, Tracer) - CRYPTOPP_BEGIN_TRACER_EVENTS(0x48752841) - CRYPTOPP_TRACER_EVENT(NoWaitLoop) - CRYPTOPP_END_TRACER_EVENTS - CRYPTOPP_TRACER_EVENT_METHODS(NoWaitLoop, 1) -CRYPTOPP_END_TRACER_CLASS - -struct WaitingThreadData; - -//! container of wait objects -class WaitObjectContainer : public NotCopyable -{ -public: - //! exception thrown by WaitObjectContainer - class Err : public Exception - { - public: - Err(const std::string& s) : Exception(IO_ERROR, s) {} - }; - - static unsigned int MaxWaitObjects(); - - WaitObjectContainer(WaitObjectsTracer* tracer = 0); - - void Clear(); - void SetNoWait(CallStack const& callStack); - void ScheduleEvent(double milliseconds, CallStack const& callStack); - // returns false if timed out - bool Wait(unsigned long milliseconds); - -#ifdef USE_WINDOWS_STYLE_SOCKETS - ~WaitObjectContainer(); - void AddHandle(HANDLE handle, CallStack const& callStack); -#else - void AddReadFd(int fd, CallStack const& callStack); - void AddWriteFd(int fd, CallStack const& callStack); -#endif - -private: - WaitObjectsTracer* m_tracer; - -#ifdef USE_WINDOWS_STYLE_SOCKETS - void CreateThreads(unsigned int count); - std::vector m_handles; - std::vector m_threads; - HANDLE m_startWaiting; - HANDLE m_stopWaiting; -#else - fd_set m_readfds, m_writefds; - int m_maxFd; -#endif - bool m_noWait; - double m_firstEventTime; - Timer m_eventTimer; - -#ifdef USE_WINDOWS_STYLE_SOCKETS - typedef size_t LastResultType; -#else - typedef int LastResultType; -#endif - enum { LASTRESULT_NOWAIT = -1, LASTRESULT_SCHEDULED = -2, LASTRESULT_TIMEOUT = -3 }; - LastResultType m_lastResult; - unsigned int m_sameResultCount; - Timer m_noWaitTimer; - void SetLastResult(LastResultType result); - void DetectNoWait(LastResultType result, CallStack const& callStack); -}; - -NAMESPACE_END - -#endif - -#endif diff --git a/lib/cryptopp/winpipes.cpp b/lib/cryptopp/winpipes.cpp deleted file mode 100644 index 1c2e047b0..000000000 --- a/lib/cryptopp/winpipes.cpp +++ /dev/null @@ -1,205 +0,0 @@ -// winpipes.cpp - written and placed in the public domain by Wei Dai - -#include "pch.h" -#include "winpipes.h" - -#ifdef WINDOWS_PIPES_AVAILABLE - -#include "wait.h" - -NAMESPACE_BEGIN(CryptoPP) - -WindowsHandle::WindowsHandle(HANDLE h, bool own) - : m_h(h), m_own(own) -{ -} - -WindowsHandle::~WindowsHandle() -{ - if (m_own) - { - try - { - CloseHandle(); - } - catch (...) - { - } - } -} - -bool WindowsHandle::HandleValid() const -{ - return m_h && m_h != INVALID_HANDLE_VALUE; -} - -void WindowsHandle::AttachHandle(HANDLE h, bool own) -{ - if (m_own) - CloseHandle(); - - m_h = h; - m_own = own; - HandleChanged(); -} - -HANDLE WindowsHandle::DetachHandle() -{ - HANDLE h = m_h; - m_h = INVALID_HANDLE_VALUE; - HandleChanged(); - return h; -} - -void WindowsHandle::CloseHandle() -{ - if (m_h != INVALID_HANDLE_VALUE) - { - ::CloseHandle(m_h); - m_h = INVALID_HANDLE_VALUE; - HandleChanged(); - } -} - -// ******************************************************** - -void WindowsPipe::HandleError(const char *operation) const -{ - DWORD err = GetLastError(); - throw Err(GetHandle(), operation, err); -} - -WindowsPipe::Err::Err(HANDLE s, const std::string& operation, int error) - : OS_Error(IO_ERROR, "WindowsPipe: " + operation + " operation failed with error 0x" + IntToString(error, 16), operation, error) - , m_h(s) -{ -} - -// ************************************************************* - -WindowsPipeReceiver::WindowsPipeReceiver() - : m_resultPending(false), m_eofReceived(false) -{ - m_event.AttachHandle(CreateEvent(NULL, true, false, NULL), true); - CheckAndHandleError("CreateEvent", m_event.HandleValid()); - memset(&m_overlapped, 0, sizeof(m_overlapped)); - m_overlapped.hEvent = m_event; -} - -bool WindowsPipeReceiver::Receive(byte* buf, size_t bufLen) -{ - assert(!m_resultPending && !m_eofReceived); - - HANDLE h = GetHandle(); - // don't queue too much at once, or we might use up non-paged memory - if (ReadFile(h, buf, UnsignedMin((DWORD)128*1024, bufLen), &m_lastResult, &m_overlapped)) - { - if (m_lastResult == 0) - m_eofReceived = true; - } - else - { - switch (GetLastError()) - { - default: - CheckAndHandleError("ReadFile", false); - case ERROR_BROKEN_PIPE: - case ERROR_HANDLE_EOF: - m_lastResult = 0; - m_eofReceived = true; - break; - case ERROR_IO_PENDING: - m_resultPending = true; - } - } - return !m_resultPending; -} - -void WindowsPipeReceiver::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) -{ - if (m_resultPending) - container.AddHandle(m_event, CallStack("WindowsPipeReceiver::GetWaitObjects() - result pending", &callStack)); - else if (!m_eofReceived) - container.SetNoWait(CallStack("WindowsPipeReceiver::GetWaitObjects() - result ready", &callStack)); -} - -unsigned int WindowsPipeReceiver::GetReceiveResult() -{ - if (m_resultPending) - { - HANDLE h = GetHandle(); - if (GetOverlappedResult(h, &m_overlapped, &m_lastResult, false)) - { - if (m_lastResult == 0) - m_eofReceived = true; - } - else - { - switch (GetLastError()) - { - default: - CheckAndHandleError("GetOverlappedResult", false); - case ERROR_BROKEN_PIPE: - case ERROR_HANDLE_EOF: - m_lastResult = 0; - m_eofReceived = true; - } - } - m_resultPending = false; - } - return m_lastResult; -} - -// ************************************************************* - -WindowsPipeSender::WindowsPipeSender() - : m_resultPending(false), m_lastResult(0) -{ - m_event.AttachHandle(CreateEvent(NULL, true, false, NULL), true); - CheckAndHandleError("CreateEvent", m_event.HandleValid()); - memset(&m_overlapped, 0, sizeof(m_overlapped)); - m_overlapped.hEvent = m_event; -} - -void WindowsPipeSender::Send(const byte* buf, size_t bufLen) -{ - DWORD written = 0; - HANDLE h = GetHandle(); - // don't queue too much at once, or we might use up non-paged memory - if (WriteFile(h, buf, UnsignedMin((DWORD)128*1024, bufLen), &written, &m_overlapped)) - { - m_resultPending = false; - m_lastResult = written; - } - else - { - if (GetLastError() != ERROR_IO_PENDING) - CheckAndHandleError("WriteFile", false); - - m_resultPending = true; - } -} - -void WindowsPipeSender::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) -{ - if (m_resultPending) - container.AddHandle(m_event, CallStack("WindowsPipeSender::GetWaitObjects() - result pending", &callStack)); - else - container.SetNoWait(CallStack("WindowsPipeSender::GetWaitObjects() - result ready", &callStack)); -} - -unsigned int WindowsPipeSender::GetSendResult() -{ - if (m_resultPending) - { - HANDLE h = GetHandle(); - BOOL result = GetOverlappedResult(h, &m_overlapped, &m_lastResult, false); - CheckAndHandleError("GetOverlappedResult", result); - m_resultPending = false; - } - return m_lastResult; -} - -NAMESPACE_END - -#endif diff --git a/lib/cryptopp/winpipes.h b/lib/cryptopp/winpipes.h deleted file mode 100644 index 07225f9f1..000000000 --- a/lib/cryptopp/winpipes.h +++ /dev/null @@ -1,142 +0,0 @@ -#ifndef CRYPTOPP_WINPIPES_H -#define CRYPTOPP_WINPIPES_H - -#include "config.h" - -#ifdef WINDOWS_PIPES_AVAILABLE - -#include "network.h" -#include "queue.h" -#include - -NAMESPACE_BEGIN(CryptoPP) - -//! Windows Handle -class WindowsHandle -{ -public: - WindowsHandle(HANDLE h = INVALID_HANDLE_VALUE, bool own=false); - WindowsHandle(const WindowsHandle &h) : m_h(h.m_h), m_own(false) {} - virtual ~WindowsHandle(); - - bool GetOwnership() const {return m_own;} - void SetOwnership(bool own) {m_own = own;} - - operator HANDLE() {return m_h;} - HANDLE GetHandle() const {return m_h;} - bool HandleValid() const; - void AttachHandle(HANDLE h, bool own=false); - HANDLE DetachHandle(); - void CloseHandle(); - -protected: - virtual void HandleChanged() {} - - HANDLE m_h; - bool m_own; -}; - -//! Windows Pipe -class WindowsPipe -{ -public: - class Err : public OS_Error - { - public: - Err(HANDLE h, const std::string& operation, int error); - HANDLE GetHandle() const {return m_h;} - - private: - HANDLE m_h; - }; - -protected: - virtual HANDLE GetHandle() const =0; - virtual void HandleError(const char *operation) const; - void CheckAndHandleError(const char *operation, BOOL result) const - {assert(result==TRUE || result==FALSE); if (!result) HandleError(operation);} -}; - -//! pipe-based implementation of NetworkReceiver -class WindowsPipeReceiver : public WindowsPipe, public NetworkReceiver -{ -public: - WindowsPipeReceiver(); - - bool MustWaitForResult() {return true;} - bool Receive(byte* buf, size_t bufLen); - unsigned int GetReceiveResult(); - bool EofReceived() const {return m_eofReceived;} - - unsigned int GetMaxWaitObjectCount() const {return 1;} - void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack); - -private: - WindowsHandle m_event; - OVERLAPPED m_overlapped; - bool m_resultPending; - DWORD m_lastResult; - bool m_eofReceived; -}; - -//! pipe-based implementation of NetworkSender -class WindowsPipeSender : public WindowsPipe, public NetworkSender -{ -public: - WindowsPipeSender(); - - bool MustWaitForResult() {return true;} - void Send(const byte* buf, size_t bufLen); - unsigned int GetSendResult(); - bool MustWaitForEof() { return false; } - void SendEof() {} - - unsigned int GetMaxWaitObjectCount() const {return 1;} - void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack); - -private: - WindowsHandle m_event; - OVERLAPPED m_overlapped; - bool m_resultPending; - DWORD m_lastResult; -}; - -//! Windows Pipe Source -class WindowsPipeSource : public WindowsHandle, public NetworkSource, public WindowsPipeReceiver -{ -public: - WindowsPipeSource(HANDLE h=INVALID_HANDLE_VALUE, bool pumpAll=false, BufferedTransformation *attachment=NULL) - : WindowsHandle(h), NetworkSource(attachment) - { - if (pumpAll) - PumpAll(); - } - - NetworkSource::GetMaxWaitObjectCount; - NetworkSource::GetWaitObjects; - -private: - HANDLE GetHandle() const {return WindowsHandle::GetHandle();} - NetworkReceiver & AccessReceiver() {return *this;} -}; - -//! Windows Pipe Sink -class WindowsPipeSink : public WindowsHandle, public NetworkSink, public WindowsPipeSender -{ -public: - WindowsPipeSink(HANDLE h=INVALID_HANDLE_VALUE, unsigned int maxBufferSize=0, unsigned int autoFlushBound=16*1024) - : WindowsHandle(h), NetworkSink(maxBufferSize, autoFlushBound) {} - - NetworkSink::GetMaxWaitObjectCount; - NetworkSink::GetWaitObjects; - -private: - HANDLE GetHandle() const {return WindowsHandle::GetHandle();} - NetworkSender & AccessSender() {return *this;} -}; - -NAMESPACE_END - -#endif - -#endif diff --git a/lib/cryptopp/words.h b/lib/cryptopp/words.h deleted file mode 100644 index d5fda71da..000000000 --- a/lib/cryptopp/words.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef CRYPTOPP_WORDS_H -#define CRYPTOPP_WORDS_H - -#include "misc.h" - -NAMESPACE_BEGIN(CryptoPP) - -inline size_t CountWords(const word *X, size_t N) -{ - while (N && X[N-1]==0) - N--; - return N; -} - -inline void SetWords(word *r, word a, size_t n) -{ - for (size_t i=0; i> (WORD_BITS-shiftBits); - } - return carry; -} - -inline word ShiftWordsRightByBits(word *r, size_t n, unsigned int shiftBits) -{ - assert (shiftBits0; i--) - { - u = r[i-1]; - r[i-1] = (u >> shiftBits) | carry; - carry = u << (WORD_BITS-shiftBits); - } - return carry; -} - -inline void ShiftWordsLeftByWords(word *r, size_t n, size_t shiftWords) -{ - shiftWords = STDMIN(shiftWords, n); - if (shiftWords) - { - for (size_t i=n-1; i>=shiftWords; i--) - r[i] = r[i-shiftWords]; - SetWords(r, 0, shiftWords); - } -} - -inline void ShiftWordsRightByWords(word *r, size_t n, size_t shiftWords) -{ - shiftWords = STDMIN(shiftWords, n); - if (shiftWords) - { - for (size_t i=0; i+shiftWords Date: Thu, 23 Jan 2014 00:27:39 -0700 Subject: Split TossItem into three Toss functions (Held, Equipped and Pickup) --- .../Plugins/APIDump/Hooks/OnPlayerTossingItem.lua | 7 +- src/ClientHandle.cpp | 5 +- src/Entities/Player.cpp | 107 +++++++++++---------- src/Entities/Player.h | 9 +- src/UI/Window.cpp | 37 ++++++- 5 files changed, 105 insertions(+), 60 deletions(-) diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua index 85c943721..2b65294ef 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua @@ -5,7 +5,7 @@ return CalledWhen = "A player is tossing an item. Plugin may override / refuse.", DefaultFnName = "OnPlayerTossingItem", -- also used as pagename Desc = [[ - This hook is called when a {{cPlayer|player}} has tossed an item (Q keypress). The + This hook is called when a {{cPlayer|player}} has tossed an item. The {{cPickup|pickup}} has not been spawned yet. Plugins may disallow the tossing, but in that case they need to clean up - the player's client already thinks the item has been tossed so the {{cInventory|inventory}} needs to be re-sent to the player.

@@ -18,8 +18,9 @@ return }, Returns = [[ If the function returns false or no value, other plugins' callbacks are called and finally MCServer - creates the pickup for the item and tosses it, using {{cPlayer}}:TossItem. If the function returns - true, no other callbacks are called for this event and MCServer doesn't toss the item. + creates the pickup for the item and tosses it, using {{cPlayer}}:TossHeldItem, {{cPlayer}}:TossEquippedItem, + or {{cPlayer}}:TossPickup. If the function returns true, no other callbacks are called for this event + and MCServer doesn't toss the item. ]], }, -- HOOK_PLAYER_TOSSING_ITEM } diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 74d192129..ab3c85ba9 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -658,7 +658,8 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, ch // A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch) return; } - m_Player->TossItem(false); + + m_Player->TossEquippedItem(); return; } @@ -713,7 +714,7 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, ch // A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch) return; } - m_Player->TossItem(false, 64); // Toss entire slot - if there aren't enough items, the maximum will be ejected + m_Player->TossEquippedItem(64); // Toss entire slot - if there aren't enough items, the maximum will be ejected return; } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c1f2456eb..ca39d4d9d 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1342,59 +1342,68 @@ AString cPlayer::GetColor(void) const -void cPlayer::TossItem( - bool a_bDraggingItem, - char a_Amount /* = 1 */, - short a_CreateType /* = 0 */, - short a_CreateHealth /* = 0 */ -) +void cPlayer::TossEquippedItem(char a_Amount) { cItems Drops; - if (a_CreateType != 0) - { - // Just create item without touching the inventory (used in creative mode) - Drops.push_back(cItem(a_CreateType, a_Amount, a_CreateHealth)); - } - else - { - // Drop an item from the inventory: - if (a_bDraggingItem) - { - cItem & Item = GetDraggingItem(); - if (!Item.IsEmpty()) - { - char OriginalItemAmount = Item.m_ItemCount; - Item.m_ItemCount = std::min(OriginalItemAmount, a_Amount); - Drops.push_back(Item); - if (OriginalItemAmount > a_Amount) - { - Item.m_ItemCount = OriginalItemAmount - (char)a_Amount; - } - else - { - Item.Empty(); - } - } - } - else - { - // Else drop equipped item - cItem DroppedItem(GetInventory().GetEquippedItem()); - if (!DroppedItem.IsEmpty()) - { - char NewAmount = a_Amount; - if (NewAmount > GetInventory().GetEquippedItem().m_ItemCount) - { - NewAmount = GetInventory().GetEquippedItem().m_ItemCount; // Drop only what's there - } + cItem DroppedItem(GetInventory().GetEquippedItem()); + if (!DroppedItem.IsEmpty()) + { + char NewAmount = a_Amount; + if (NewAmount > GetInventory().GetEquippedItem().m_ItemCount) + { + NewAmount = GetInventory().GetEquippedItem().m_ItemCount; // Drop only what's there + } - GetInventory().GetHotbarGrid().ChangeSlotCount(GetInventory().GetEquippedSlotNum() /* Returns hotbar subslot, which HotbarGrid takes */, -a_Amount); + GetInventory().GetHotbarGrid().ChangeSlotCount(GetInventory().GetEquippedSlotNum() /* Returns hotbar subslot, which HotbarGrid takes */, -a_Amount); + + DroppedItem.m_ItemCount = NewAmount; + Drops.push_back(DroppedItem); + } + + double vX = 0, vY = 0, vZ = 0; + EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); + vY = -vY * 2 + 1.f; + m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player +} + + + + + +void cPlayer::TossHeldItem(char a_Amount) +{ + cItems Drops; + cItem & Item = GetDraggingItem(); + if (!Item.IsEmpty()) + { + char OriginalItemAmount = Item.m_ItemCount; + Item.m_ItemCount = std::min(OriginalItemAmount, a_Amount); + Drops.push_back(Item); + if (OriginalItemAmount > a_Amount) + { + Item.m_ItemCount = OriginalItemAmount - a_Amount; + } + else + { + Item.Empty(); + } + } + + double vX = 0, vY = 0, vZ = 0; + EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); + vY = -vY * 2 + 1.f; + m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player +} + + + + + +void cPlayer::TossPickup(const cItem & a_Item) +{ + cItems Drops; + Drops.push_back(a_Item); - DroppedItem.m_ItemCount = NewAmount; - Drops.push_back(DroppedItem); - } - } - } double vX = 0, vY = 0, vZ = 0; EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; diff --git a/src/Entities/Player.h b/src/Entities/Player.h index bf3ca08e8..71033ab77 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -214,7 +214,14 @@ public: /// Returns the full color code to use for this player, based on their primary group or set in m_Color AString GetColor(void) const; - void TossItem(bool a_bDraggingItem, char a_Amount = 1, short a_CreateType = 0, short a_CreateHealth = 0); + // tosses the item in the selected hotbar slot + void TossEquippedItem(char a_Amount = 1); + + // tosses the item held in hand (when in UI windows) + void TossHeldItem(char a_Amount = 1); + + // tosses a pickup newly created from a_Item + void TossPickup(const cItem & a_Item); /// Heals the player by the specified amount of HPs (positive only); sends health update void Heal(int a_Health); diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 3ffeff7a0..3dd6d2264 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -13,7 +13,8 @@ #include "../BlockEntities/DropSpenserEntity.h" #include "../BlockEntities/EnderChestEntity.h" #include "../BlockEntities/HopperEntity.h" - +#include "../Root.h" +#include "../Bindings/PluginManager.h" @@ -169,6 +170,8 @@ void cWindow::Clicked( const cItem & a_ClickedItem ) { + cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); + if (a_WindowID != m_WindowID) { LOGWARNING("%s: Wrong window ID (exp %d, got %d) received from \"%s\"; ignoring click.", __FUNCTION__, m_WindowID, a_WindowID, a_Player.GetName().c_str()); @@ -179,14 +182,36 @@ void cWindow::Clicked( { case caRightClickOutside: { + if (PlgMgr->CallHookPlayerTossingItem(a_Player)) + { + // A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch) + return; + } + + if (a_Player.IsGameModeCreative()) + { + a_Player.TossPickup(a_ClickedItem); + } + // Toss one of the dragged items: - a_Player.TossItem(true); + a_Player.TossHeldItem(); return; } case caLeftClickOutside: { + if (PlgMgr->CallHookPlayerTossingItem(a_Player)) + { + // A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch) + return; + } + + if (a_Player.IsGameModeCreative()) + { + a_Player.TossPickup(a_ClickedItem); + } + // Toss all dragged items: - a_Player.TossItem(true, a_Player.GetDraggingItem().m_ItemCount); + a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount); return; } case caLeftClickOutsideHoldNothing: @@ -259,11 +284,13 @@ void cWindow::OpenedByPlayer(cPlayer & a_Player) bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) { + cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); + // Checks whether the player is still holding an item if (a_Player.IsDraggingItem()) { - LOGD("Player holds item! Dropping it..."); - a_Player.TossItem(true, a_Player.GetDraggingItem().m_ItemCount); + LOGD("Player holds item! Dropping it..."); + a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount); } cClientHandle * ClientHandle = a_Player.GetClientHandle(); -- cgit v1.2.3 From 00d73177463936c149b31171b8d4b00daacc608d Mon Sep 17 00:00:00 2001 From: Mike Hunsinger Date: Thu, 23 Jan 2014 00:53:00 -0700 Subject: Removed extra line --- src/UI/Window.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 3dd6d2264..3d23dfd07 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -284,8 +284,6 @@ void cWindow::OpenedByPlayer(cPlayer & a_Player) bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) { - cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); - // Checks whether the player is still holding an item if (a_Player.IsDraggingItem()) { -- cgit v1.2.3 From 4ef61d8bf6d815b164a32bdab6a18744cbf0abd2 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 23 Jan 2014 14:57:04 +0200 Subject: Command block fixes 2 --- src/BlockEntities/CommandBlockEntity.cpp | 26 +++++++++++++++++----- src/ClientHandle.cpp | 25 ++++++++------------- src/World.cpp | 27 ++++++++++++++++++++++- src/World.h | 9 ++++++++ src/WorldStorage/NBTChunkSerializer.cpp | 19 ++++++++-------- src/WorldStorage/WSSCompact.cpp | 38 +++++++++++++++++++++++++------- 6 files changed, 104 insertions(+), 40 deletions(-) diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp index 7e9015d33..db8eb1436 100644 --- a/src/BlockEntities/CommandBlockEntity.cpp +++ b/src/BlockEntities/CommandBlockEntity.cpp @@ -151,9 +151,13 @@ void cCommandBlockEntity::SendTo(cClientHandle & a_Client) bool cCommandBlockEntity::LoadFromJson(const Json::Value & a_Value) { - m_Command = a_Value.get("Command", "").asString(); + m_PosX = a_Value.get("x", 0).asInt(); + m_PosY = a_Value.get("y", 0).asInt(); + m_PosZ = a_Value.get("z", 0).asInt(); - m_LastOutput = a_Value.get("LastOutput", "").asString(); + m_Command = a_Value.get("Command", "").asString(); + m_LastOutput = a_Value.get("LastOutput", "").asString(); + m_Result = a_Value.get("SuccessCount", 0).asInt(); return true; } @@ -164,9 +168,13 @@ bool cCommandBlockEntity::LoadFromJson(const Json::Value & a_Value) void cCommandBlockEntity::SaveToJson(Json::Value & a_Value) { - a_Value["Command"] = m_Command; + a_Value["x"] = m_PosX; + a_Value["y"] = m_PosY; + a_Value["z"] = m_PosZ; - a_Value["LastOutput"] = m_LastOutput; + a_Value["Command"] = m_Command; + a_Value["LastOutput"] = m_LastOutput; + a_Value["SuccessCount"] = m_Result; } @@ -175,6 +183,14 @@ void cCommandBlockEntity::SaveToJson(Json::Value & a_Value) void cCommandBlockEntity::Execute() { + if (m_World) + { + if (!m_World->AreCommandBlocksEnabled()) + { + return; + } + } + class CommandBlockOutCb : public cCommandOutputCallback { @@ -185,8 +201,6 @@ void cCommandBlockEntity::Execute() virtual void Out(const AString & a_Text) { - ASSERT(m_CmdBlock != NULL); - // Overwrite field m_CmdBlock->SetLastOutput(a_Text); } diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 0a2d3c1be..ed04edac0 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -610,25 +610,18 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a } } - class cUpdateCommandBlock : - public cCommandBlockCallback - { - AString m_Command; - public: - cUpdateCommandBlock(const AString & a_Command) : m_Command(a_Command) {} - - virtual bool Item(cCommandBlockEntity * a_CommandBlock) override - { - a_CommandBlock->SetCommand(m_Command); - return false; - } - } CmdBlockCB (Command); - cWorld * World = m_Player->GetWorld(); - World->DoWithCommandBlockAt(BlockX, BlockY, BlockZ, CmdBlockCB); + if (World->AreCommandBlocksEnabled()) + { + World->SetCommandBlockCommand(BlockX, BlockY, BlockZ, Command); - SendChat(Printf("%s[INFO]%s Successfully set command block command", cChatColor::Green.c_str(), cChatColor::White.c_str())); + SendChat(Printf("%s[INFO]%s Successfully set command block command", cChatColor::Green.c_str(), cChatColor::White.c_str())); + } + else + { + SendChat(Printf("%s[INFO]%s Command blocks are not enabled on this server", cChatColor::Green.c_str(), cChatColor::White.c_str())); + } } diff --git a/src/World.cpp b/src/World.cpp index 49d42f08e..453a22c2d 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -22,6 +22,8 @@ #include "Entities/Player.h" #include "Entities/TNTEntity.h" +#include "BlockEntities/CommandBlockEntity.h" + // Simulators: #include "Simulator/SimulatorManager.h" #include "Simulator/FloodyFluidSimulator.h" @@ -523,7 +525,7 @@ void cWorld::Start(void) } m_StorageSchema = IniFile.GetValueSet ("Storage", "Schema", m_StorageSchema); - m_StorageCompressionFactor = IniFile.GetValueSetI ("Storage", "CompressionFactor", m_StorageCompressionFactor); + m_StorageCompressionFactor = IniFile.GetValueSetI("Storage", "CompressionFactor", m_StorageCompressionFactor); m_MaxCactusHeight = IniFile.GetValueSetI("Plants", "MaxCactusHeight", 3); m_MaxSugarcaneHeight = IniFile.GetValueSetI("Plants", "MaxSugarcaneHeight", 3); m_IsCactusBonemealable = IniFile.GetValueSetB("Plants", "IsCactusBonemealable", false); @@ -540,6 +542,7 @@ void cWorld::Start(void) m_bEnabledPVP = IniFile.GetValueSetB("PVP", "Enabled", true); m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", false); m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true); + m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false); m_GameMode = (eGameMode)IniFile.GetValueSetI("GameMode", "GameMode", m_GameMode); @@ -2611,6 +2614,28 @@ bool cWorld::UpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString +bool cWorld::SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command) +{ + class cUpdateCommandBlock : public cCommandBlockCallback + { + AString m_Command; + public: + cUpdateCommandBlock(const AString & a_Command) : m_Command(a_Command) {} + + virtual bool Item(cCommandBlockEntity * a_CommandBlock) override + { + a_CommandBlock->SetCommand(m_Command); + return false; + } + } CmdBlockCB (a_Command); + + return DoWithCommandBlockAt(a_BlockX, a_BlockY, a_BlockZ, CmdBlockCB); +} + + + + + void cWorld::ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay) { m_ChunkMap->ChunksStay(a_Chunks, a_Stay); diff --git a/src/World.h b/src/World.h index 2d6baa99f..61c7604df 100644 --- a/src/World.h +++ b/src/World.h @@ -296,6 +296,9 @@ public: /** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be NULL. Returns true if sign text changed. Same as SetSignLines() */ bool UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = NULL); // Exported in ManualBindings.cpp + /** Sets the command block command. Returns true if command changed. */ + bool SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command); // tolua_export + /** Marks (a_Stay == true) or unmarks (a_Stay == false) chunks as non-unloadable. To be used only by cChunkStay! */ void ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay = true); @@ -511,6 +514,10 @@ public: /// Returns the associated scoreboard instance cScoreboard & GetScoreBoard(void) { return m_Scoreboard; } + + bool AreCommandBlocksEnabled(void) const { return m_bCommandBlocksEnabled; } + + void SetCommandBlocksEnabled(bool a_Flag) { m_bCommandBlocksEnabled = a_Flag; } // tolua_end @@ -774,6 +781,8 @@ private: bool m_IsPumpkinBonemealable; bool m_IsSaplingBonemealable; bool m_IsSugarcaneBonemealable; + + bool m_bCommandBlocksEnabled; cCriticalSection m_CSFastSetBlock; sSetBlockList m_FastSetBlockQueue; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index c84128022..e46a28caa 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -652,20 +652,21 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) m_Writer.BeginList("TileEntities", TAG_Compound); } m_IsTagOpen = true; - + // Add tile-entity into NBT: switch (a_Entity->GetBlockType()) { - case E_BLOCK_CHEST: AddChestEntity ((cChestEntity *) a_Entity); break; - case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break; - case E_BLOCK_DROPPER: AddDropperEntity ((cDropperEntity *) a_Entity); break; - case E_BLOCK_FURNACE: AddFurnaceEntity ((cFurnaceEntity *) a_Entity); break; - case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; + case E_BLOCK_CHEST: AddChestEntity ((cChestEntity *) a_Entity); break; + case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break; + case E_BLOCK_DROPPER: AddDropperEntity ((cDropperEntity *) a_Entity); break; + case E_BLOCK_FURNACE: AddFurnaceEntity ((cFurnaceEntity *) a_Entity); break; + case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; case E_BLOCK_SIGN_POST: - case E_BLOCK_WALLSIGN: AddSignEntity ((cSignEntity *) a_Entity); break; - case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break; - case E_BLOCK_JUKEBOX: AddJukeboxEntity ((cJukeboxEntity *) a_Entity); break; + case E_BLOCK_WALLSIGN: AddSignEntity ((cSignEntity *) a_Entity); break; + case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break; + case E_BLOCK_JUKEBOX: AddJukeboxEntity ((cJukeboxEntity *) a_Entity); break; case E_BLOCK_COMMAND_BLOCK: AddCommandBlockEntity((cCommandBlockEntity *) a_Entity); break; + default: { ASSERT(!"Unhandled block entity saved into Anvil"); diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index ea17a8ec1..d020b73cc 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -10,6 +10,7 @@ #include "json/json.h" #include "../StringCompression.h" #include "../BlockEntities/ChestEntity.h" +#include "../BlockEntities/CommandBlockEntity.h" #include "../BlockEntities/DispenserEntity.h" #include "../BlockEntities/FurnaceEntity.h" #include "../BlockEntities/JukeboxEntity.h" @@ -71,14 +72,15 @@ void cJsonChunkSerializer::BlockEntity(cBlockEntity * a_BlockEntity) const char * SaveInto = NULL; switch (a_BlockEntity->GetBlockType()) { - case E_BLOCK_CHEST: SaveInto = "Chests"; break; - case E_BLOCK_DISPENSER: SaveInto = "Dispensers"; break; - case E_BLOCK_DROPPER: SaveInto = "Droppers"; break; - case E_BLOCK_FURNACE: SaveInto = "Furnaces"; break; - case E_BLOCK_SIGN_POST: SaveInto = "Signs"; break; - case E_BLOCK_WALLSIGN: SaveInto = "Signs"; break; - case E_BLOCK_NOTE_BLOCK: SaveInto = "Notes"; break; - case E_BLOCK_JUKEBOX: SaveInto = "Jukeboxes"; break; + case E_BLOCK_CHEST: SaveInto = "Chests"; break; + case E_BLOCK_DISPENSER: SaveInto = "Dispensers"; break; + case E_BLOCK_DROPPER: SaveInto = "Droppers"; break; + case E_BLOCK_FURNACE: SaveInto = "Furnaces"; break; + case E_BLOCK_SIGN_POST: SaveInto = "Signs"; break; + case E_BLOCK_WALLSIGN: SaveInto = "Signs"; break; + case E_BLOCK_NOTE_BLOCK: SaveInto = "Notes"; break; + case E_BLOCK_JUKEBOX: SaveInto = "Jukeboxes"; break; + case E_BLOCK_COMMAND_BLOCK: SaveInto = "CommandBlocks"; break; default: { @@ -383,6 +385,26 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En } } // for itr - AllJukeboxes[] } + + // Load command blocks + Json::Value AllCommandBlocks = a_Value.get("CommandBlocks", Json::nullValue); + if( !AllCommandBlocks.empty() ) + { + for( Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr ) + { + Json::Value & CommandBlock = *itr; + cCommandBlockEntity * CommandBlockEntity = new cCommandBlockEntity(0, 0, 0, a_World); + if ( !CommandBlockEntity->LoadFromJson( CommandBlock ) ) + { + LOGERROR("ERROR READING COMMAND BLOCK FROM JSON!" ); + delete CommandBlockEntity; + } + else + { + a_BlockEntities.push_back( CommandBlockEntity ); + } + } // for itr - AllCommandBlocks[] + } } -- cgit v1.2.3 From 97ee3340e302bd4bdd93054262bb9743ca37c764 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 23 Jan 2014 14:14:33 +0100 Subject: Minor style improvements for the merged PR. --- src/BlockEntities/CommandBlockEntity.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp index db8eb1436..0bc6ca359 100644 --- a/src/BlockEntities/CommandBlockEntity.cpp +++ b/src/BlockEntities/CommandBlockEntity.cpp @@ -183,7 +183,7 @@ void cCommandBlockEntity::SaveToJson(Json::Value & a_Value) void cCommandBlockEntity::Execute() { - if (m_World) + if (m_World != NULL) { if (!m_World->AreCommandBlocksEnabled()) { @@ -194,10 +194,10 @@ void cCommandBlockEntity::Execute() class CommandBlockOutCb : public cCommandOutputCallback { - cCommandBlockEntity* m_CmdBlock; + cCommandBlockEntity * m_CmdBlock; public: - CommandBlockOutCb(cCommandBlockEntity* a_CmdBlock) : m_CmdBlock(a_CmdBlock) {} + CommandBlockOutCb(cCommandBlockEntity * a_CmdBlock) : m_CmdBlock(a_CmdBlock) {} virtual void Out(const AString & a_Text) { @@ -208,7 +208,7 @@ void cCommandBlockEntity::Execute() LOGD("cCommandBlockEntity: Executing command %s", m_Command.c_str()); - cServer* Server = cRoot::Get()->GetServer(); + cServer * Server = cRoot::Get()->GetServer(); Server->ExecuteConsoleCommand(m_Command, CmdBlockOutCb); -- cgit v1.2.3 From 9ae31d913c40c86988f12ffc51d3e9e7ab982822 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 23 Jan 2014 14:21:56 +0100 Subject: Improved code safety for the Compact world storage. That was a huge chunk of smelly code. --- src/WorldStorage/WSSCompact.cpp | 176 ++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 104 deletions(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index d020b73cc..4c0684dd8 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -265,146 +265,114 @@ bool cWSSCompact::EraseChunkData(const cChunkCoords & a_Chunk) void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities, cWorld * a_World) { - // Load chests + // Load chests: Json::Value AllChests = a_Value.get("Chests", Json::nullValue); if (!AllChests.empty()) { for (Json::Value::iterator itr = AllChests.begin(); itr != AllChests.end(); ++itr ) { - Json::Value & Chest = *itr; - cChestEntity * ChestEntity = new cChestEntity(0,0,0, a_World); - if (!ChestEntity->LoadFromJson( Chest ) ) + std::auto_ptr ChestEntity(new cChestEntity(0, 0, 0, a_World)); + if (!ChestEntity->LoadFromJson(*itr)) { - LOGERROR("ERROR READING CHEST FROM JSON!" ); - delete ChestEntity; + LOGWARNING("ERROR READING CHEST FROM JSON!" ); } else { - a_BlockEntities.push_back( ChestEntity ); + a_BlockEntities.push_back(ChestEntity.release()); } } // for itr - AllChests[] } - // Load dispensers + // Load dispensers: Json::Value AllDispensers = a_Value.get("Dispensers", Json::nullValue); - if( !AllDispensers.empty() ) + for (Json::Value::iterator itr = AllDispensers.begin(); itr != AllDispensers.end(); ++itr) { - for( Json::Value::iterator itr = AllDispensers.begin(); itr != AllDispensers.end(); ++itr ) + std::auto_ptr DispenserEntity(new cDispenserEntity(0, 0, 0, a_World)); + if (!DispenserEntity->LoadFromJson(*itr)) { - Json::Value & Dispenser = *itr; - cDispenserEntity * DispenserEntity = new cDispenserEntity(0,0,0, a_World); - if( !DispenserEntity->LoadFromJson( Dispenser ) ) - { - LOGERROR("ERROR READING DISPENSER FROM JSON!" ); - delete DispenserEntity; - } - else - { - a_BlockEntities.push_back( DispenserEntity ); - } - } // for itr - AllDispensers[] - } + LOGWARNING("ERROR READING DISPENSER FROM JSON!" ); + } + else + { + a_BlockEntities.push_back(DispenserEntity.release()); + } + } // for itr - AllDispensers[] - // Load furnaces + // Load furnaces: Json::Value AllFurnaces = a_Value.get("Furnaces", Json::nullValue); - if( !AllFurnaces.empty() ) + for (Json::Value::iterator itr = AllFurnaces.begin(); itr != AllFurnaces.end(); ++itr) { - for( Json::Value::iterator itr = AllFurnaces.begin(); itr != AllFurnaces.end(); ++itr ) + // TODO: The block type and meta aren't correct, there's no way to get them here + std::auto_ptr FurnaceEntity(new cFurnaceEntity(0, 0, 0, E_BLOCK_FURNACE, 0, a_World)); + if (!FurnaceEntity->LoadFromJson(*itr)) { - Json::Value & Furnace = *itr; - // TODO: The block type and meta aren't correct, there's no way to get them here - cFurnaceEntity * FurnaceEntity = new cFurnaceEntity(0, 0, 0, E_BLOCK_FURNACE, 0, a_World); - if (!FurnaceEntity->LoadFromJson(Furnace)) - { - LOGERROR("ERROR READING FURNACE FROM JSON!" ); - delete FurnaceEntity; - } - else - { - a_BlockEntities.push_back(FurnaceEntity); - } - } // for itr - AllFurnaces[] - } + LOGWARNING("ERROR READING FURNACE FROM JSON!" ); + } + else + { + a_BlockEntities.push_back(FurnaceEntity.release()); + } + } // for itr - AllFurnaces[] - // Load signs + // Load signs: Json::Value AllSigns = a_Value.get("Signs", Json::nullValue); - if( !AllSigns.empty() ) + for (Json::Value::iterator itr = AllSigns.begin(); itr != AllSigns.end(); ++itr) { - for( Json::Value::iterator itr = AllSigns.begin(); itr != AllSigns.end(); ++itr ) + std::auto_ptr SignEntity(new cSignEntity(E_BLOCK_SIGN_POST, 0, 0, 0, a_World)); + if (!SignEntity->LoadFromJson(*itr)) { - Json::Value & Sign = *itr; - cSignEntity * SignEntity = new cSignEntity( E_BLOCK_SIGN_POST, 0,0,0, a_World); - if ( !SignEntity->LoadFromJson( Sign ) ) - { - LOGERROR("ERROR READING SIGN FROM JSON!" ); - delete SignEntity; - } - else - { - a_BlockEntities.push_back( SignEntity ); - } - } // for itr - AllSigns[] - } + LOGWARNING("ERROR READING SIGN FROM JSON!"); + } + else + { + a_BlockEntities.push_back(SignEntity.release()); + } + } // for itr - AllSigns[] - // Load note blocks + // Load note blocks: Json::Value AllNotes = a_Value.get("Notes", Json::nullValue); - if( !AllNotes.empty() ) + for( Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr ) { - for( Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr ) + std::auto_ptr NoteEntity(new cNoteEntity(0, 0, 0, a_World)); + if (!NoteEntity->LoadFromJson(*itr)) { - Json::Value & Note = *itr; - cNoteEntity * NoteEntity = new cNoteEntity(0, 0, 0, a_World); - if ( !NoteEntity->LoadFromJson( Note ) ) - { - LOGERROR("ERROR READING NOTE BLOCK FROM JSON!" ); - delete NoteEntity; - } - else - { - a_BlockEntities.push_back( NoteEntity ); - } - } // for itr - AllNotes[] - } + LOGWARNING("ERROR READING NOTE BLOCK FROM JSON!" ); + } + else + { + a_BlockEntities.push_back(NoteEntity.release()); + } + } // for itr - AllNotes[] - // Load jukeboxes + // Load jukeboxes: Json::Value AllJukeboxes = a_Value.get("Jukeboxes", Json::nullValue); - if( !AllJukeboxes.empty() ) + for( Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr ) { - for( Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr ) + std::auto_ptr JukeboxEntity(new cJukeboxEntity(0, 0, 0, a_World)); + if (!JukeboxEntity->LoadFromJson(*itr)) { - Json::Value & Jukebox = *itr; - cJukeboxEntity * JukeboxEntity = new cJukeboxEntity(0, 0, 0, a_World); - if ( !JukeboxEntity->LoadFromJson( Jukebox ) ) - { - LOGERROR("ERROR READING JUKEBOX FROM JSON!" ); - delete JukeboxEntity; - } - else - { - a_BlockEntities.push_back( JukeboxEntity ); - } - } // for itr - AllJukeboxes[] - } + LOGWARNING("ERROR READING JUKEBOX FROM JSON!" ); + } + else + { + a_BlockEntities.push_back(JukeboxEntity.release()); + } + } // for itr - AllJukeboxes[] - // Load command blocks + // Load command blocks: Json::Value AllCommandBlocks = a_Value.get("CommandBlocks", Json::nullValue); - if( !AllCommandBlocks.empty() ) + for( Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr ) { - for( Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr ) + std::auto_ptr CommandBlockEntity(new cCommandBlockEntity(0, 0, 0, a_World)); + if (!CommandBlockEntity->LoadFromJson(*itr)) { - Json::Value & CommandBlock = *itr; - cCommandBlockEntity * CommandBlockEntity = new cCommandBlockEntity(0, 0, 0, a_World); - if ( !CommandBlockEntity->LoadFromJson( CommandBlock ) ) - { - LOGERROR("ERROR READING COMMAND BLOCK FROM JSON!" ); - delete CommandBlockEntity; - } - else - { - a_BlockEntities.push_back( CommandBlockEntity ); - } - } // for itr - AllCommandBlocks[] - } + LOGWARNING("ERROR READING COMMAND BLOCK FROM JSON!" ); + } + else + { + a_BlockEntities.push_back(CommandBlockEntity.release()); + } + } // for itr - AllCommandBlocks[] } -- cgit v1.2.3 From bafa0347a349af663a6181173a2c81a73d6b29de Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 23 Jan 2014 16:27:23 +0200 Subject: Fixed scoreboard serialization --- src/WorldStorage/ScoreboardSerializer.cpp | 61 +++++++++++++------------------ 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp index dabc5e2e1..d41456d15 100644 --- a/src/WorldStorage/ScoreboardSerializer.cpp +++ b/src/WorldStorage/ScoreboardSerializer.cpp @@ -13,11 +13,6 @@ -#define SCOREBOARD_INFLATE_MAX 16 KiB - - - - cScoreboardSerializer::cScoreboardSerializer(const AString & a_WorldName, cScoreboard* a_ScoreBoard) : m_ScoreBoard(a_ScoreBoard) @@ -37,37 +32,25 @@ cScoreboardSerializer::cScoreboardSerializer(const AString & a_WorldName, cScore bool cScoreboardSerializer::Load(void) { cFile File; - - if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmReadWrite)) + if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmRead)) { return false; } AString Data; - File.ReadRestOfFile(Data); - File.Close(); - char Uncompressed[SCOREBOARD_INFLATE_MAX]; - z_stream strm; - strm.zalloc = (alloc_func)NULL; - strm.zfree = (free_func)NULL; - strm.opaque = NULL; - inflateInit(&strm); - strm.next_out = (Bytef *)Uncompressed; - strm.avail_out = sizeof(Uncompressed); - strm.next_in = (Bytef *)Data.data(); - strm.avail_in = Data.size(); - int res = inflate(&strm, Z_FINISH); - inflateEnd(&strm); - if (res != Z_STREAM_END) + AString Uncompressed; + int res = UncompressStringGZIP(Data.data(), Data.size(), Uncompressed); + + if (res != Z_OK) { return false; } // Parse the NBT data: - cParsedNBT NBT(Uncompressed, strm.total_out); + cParsedNBT NBT(Uncompressed.data(), Uncompressed.size()); if (!NBT.IsValid()) { // NBT Parsing failed @@ -85,11 +68,8 @@ bool cScoreboardSerializer::Save(void) { cFastNBTWriter Writer; - Writer.BeginCompound(""); - m_ScoreBoard->RegisterObjective("test","test",cObjective::E_TYPE_DUMMY)->AddScore("dot", 2); SaveScoreboardToNBT(Writer); - Writer.EndCompound(); Writer.Finish(); #ifdef _DEBUG @@ -97,12 +77,22 @@ bool cScoreboardSerializer::Save(void) ASSERT(TestParse.IsValid()); #endif // _DEBUG - gzFile gz = gzopen((FILE_IO_PREFIX + m_Path).c_str(), "wb"); - if (gz != NULL) + cFile File; + if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmWrite)) + { + return false; + } + + AString Compressed; + int res = CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed); + + if (res != Z_OK) { - gzwrite(gz, Writer.GetResult().data(), Writer.GetResult().size()); + return false; } - gzclose(gz); + + File.Write(Compressed.data(), Compressed.size()); + File.Close(); return true; } @@ -130,7 +120,7 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer) a_Writer.EndCompound(); } - a_Writer.EndList(); + a_Writer.EndList(); // Objectives a_Writer.BeginList("PlayerScores", TAG_Compound); @@ -151,7 +141,7 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer) } } - a_Writer.EndList(); + a_Writer.EndList(); // PlayerScores a_Writer.BeginList("Teams", TAG_Compound); @@ -182,8 +172,9 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer) a_Writer.EndCompound(); } - a_Writer.EndList(); - a_Writer.EndCompound(); + a_Writer.EndList(); // Teams + + a_Writer.EndCompound(); // Data a_Writer.BeginCompound("DisplaySlots"); @@ -196,7 +187,7 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer) Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_NAME); a_Writer.AddString("slot_2", (Objective == NULL) ? "" : Objective->GetName()); - a_Writer.EndCompound(); + a_Writer.EndCompound(); // DisplaySlots } -- cgit v1.2.3 From 5c04e216eb16a899719511c97ffb6139b2259c01 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 23 Jan 2014 16:42:01 +0200 Subject: Fixed scoreboard.dat structure --- src/WorldStorage/ScoreboardSerializer.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp index d41456d15..a53971dc2 100644 --- a/src/WorldStorage/ScoreboardSerializer.cpp +++ b/src/WorldStorage/ScoreboardSerializer.cpp @@ -103,7 +103,8 @@ bool cScoreboardSerializer::Save(void) void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer) { - a_Writer.BeginCompound("Data"); + a_Writer.BeginCompound("data"); + a_Writer.BeginList("Objectives", TAG_Compound); for (cScoreboard::cObjectiveMap::const_iterator it = m_ScoreBoard->m_Objectives.begin(); it != m_ScoreBoard->m_Objectives.end(); ++it) @@ -174,8 +175,6 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer) a_Writer.EndList(); // Teams - a_Writer.EndCompound(); // Data - a_Writer.BeginCompound("DisplaySlots"); cObjective * Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_LIST); @@ -188,6 +187,8 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer) a_Writer.AddString("slot_2", (Objective == NULL) ? "" : Objective->GetName()); a_Writer.EndCompound(); // DisplaySlots + + a_Writer.EndCompound(); // Data } @@ -196,7 +197,7 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer) bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT) { - int Data = a_NBT.FindChildByName(0, "Data"); + int Data = a_NBT.FindChildByName(0, "data"); if (Data < 0) { return false; @@ -338,7 +339,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT) } } - int DisplaySlots = a_NBT.FindChildByName(0, "DisplaySlots"); + int DisplaySlots = a_NBT.FindChildByName(Data, "DisplaySlots"); if (DisplaySlots < 0) { return false; -- cgit v1.2.3 From 435eae38583f77154039273085d1145c80a263bb Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 23 Jan 2014 16:14:00 +0100 Subject: Fixed crash while calling disabled plugins. --- src/Bindings/PluginManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 92c06487c..e582fde86 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -1740,7 +1740,7 @@ bool cPluginManager::DoWithPlugin(const AString & a_PluginName, cPluginCallback { // TODO: Implement locking for plugins PluginMap::iterator itr = m_Plugins.find(a_PluginName); - if (itr == m_Plugins.end()) + if ((itr == m_Plugins.end()) || (itr->second == NULL)) { return false; } -- cgit v1.2.3 From 9774da81221fbadf45a3f856e1ae09e592d7ec33 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 23 Jan 2014 17:54:38 +0100 Subject: Fixed a bug in LeakFinder. --- src/LeakFinder.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/LeakFinder.cpp b/src/LeakFinder.cpp index 9d7f185ba..42a5afe56 100644 --- a/src/LeakFinder.cpp +++ b/src/LeakFinder.cpp @@ -862,8 +862,10 @@ static int MyAllocHook(int nAllocType, void *pvData, { // RequestID was found size_t temp = g_CurrentMemUsage; - g_CurrentMemUsage -= nSize ; - g_pCRTTable->Remove(lRequest); + if (g_pCRTTable->Remove(lRequest)) + { + g_CurrentMemUsage -= nSize; + } if (g_CurrentMemUsage > temp) { printf("********************************************\n"); @@ -896,8 +898,11 @@ static int MyAllocHook(int nAllocType, void *pvData, // Try to find the RequestID in the Hash-Table, mark it that it was freed lReallocRequest = pHead->lRequest; size_t temp = g_CurrentMemUsage; - g_CurrentMemUsage -= pHead->nDataSize; bRet = g_pCRTTable->Remove(lReallocRequest); + if (bRet) + { + g_CurrentMemUsage -= pHead->nDataSize; + } if (g_CurrentMemUsage > temp) { printf("********************************************\n"); -- cgit v1.2.3 From 741957914073eb9f4a1fa0cd5ae90cc17078a623 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 23 Jan 2014 10:25:56 -0800 Subject: Switched cEvent to use strerror_r for error messages --- src/OSSupport/Event.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/OSSupport/Event.cpp b/src/OSSupport/Event.cpp index cbacbba17..fe1128dc9 100644 --- a/src/OSSupport/Event.cpp +++ b/src/OSSupport/Event.cpp @@ -7,7 +7,9 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Event.h" - +#if not defined(_WIN32) +#include +#endif @@ -35,14 +37,18 @@ cEvent::cEvent(void) m_Event = sem_open(EventName.c_str(), O_CREAT, 777, 0 ); if (m_Event == SEM_FAILED) { - LOGERROR("cEvent: Cannot create event, errno = %i. Aborting server.", errno); + char buffer[1024]; + strerror_r(errno,buffer,1024); + LOGERROR("cEvent: Cannot create event, err = %s. Aborting server.", buffer); abort(); } // Unlink the semaphore immediately - it will continue to function but will not pollute the namespace // We don't store the name, so can't call this in the destructor if (sem_unlink(EventName.c_str()) != 0) { - LOGWARN("ERROR: Could not unlink cEvent. (%i)", errno); + char buffer[1024]; + strerror_r(errno,buffer,1024); + LOGWARN("ERROR: Could not unlink cEvent. (%s)", buffer); } } #endif // *nix @@ -61,7 +67,9 @@ cEvent::~cEvent() { if (sem_close(m_Event) != 0) { - LOGERROR("ERROR: Could not close cEvent. (%i)", errno); + char buffer[1024]; + strerror_r(errno,buffer,1024); + LOGERROR("ERROR: Could not close cEvent. (%s)", buffer); } } else @@ -88,7 +96,9 @@ void cEvent::Wait(void) int res = sem_wait(m_Event); if (res != 0 ) { - LOGWARN("cEvent: waiting for the event failed: %i, errno = %i. Continuing, but server may be unstable.", res, errno); + char buffer[1024]; + strerror_r(errno,buffer,1024); + LOGWARN("cEvent: waiting for the event failed: %i, err = %s. Continuing, but server may be unstable.", res, buffer); } #endif } @@ -108,7 +118,9 @@ void cEvent::Set(void) int res = sem_post(m_Event); if (res != 0) { - LOGWARN("cEvent: Could not set cEvent: %i, errno = %d", res, errno); + char buffer[1024]; + strerror_r(errno,buffer,1024); + LOGWARN("cEvent: Could not set cEvent: %i, err = %s", res, buffer); } #endif } -- cgit v1.2.3 From e0956be0a7905451666cc6d6a3bbf088d3293f21 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 23 Jan 2014 10:41:08 -0800 Subject: added dependecies for bindings regen --- src/Bindings/CMakeLists.txt | 14 -------------- src/CMakeLists.txt | 46 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index 50b81e42a..c181f4355 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -4,20 +4,6 @@ project (MCServer) # NOTE: This CMake file is processed only for Unix builds; Windows(MSVC) builds handle all the subfolders in /src in a single file, /src/CMakeLists.txt -include_directories ("${PROJECT_SOURCE_DIR}/../") - -ADD_CUSTOM_COMMAND( - # add any new generated bindings here - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/Bindings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Bindings.h - - # command execuded to regerate bindings - COMMAND tolua -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - - # add any new generation dependencies here - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/virtual_method_hooks.lua ${CMAKE_CURRENT_SOURCE_DIR}/AllToLua.pkg tolua -) - #add cpp files here add_library(Bindings PluginManager LuaState WebPlugin Bindings ManualBindings LuaWindow Plugin PluginLua WebPlugin) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 275099540..08b4971b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,52 @@ set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities) if (NOT MSVC) + + #Bindings needs to reference other folders so are done here + + #lib dependecies are not included + + set(BINDING_DEPENDECIES ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/virtual_method_hooks.lua) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/AllToLua.pkg) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} toluaGlobals.h ChunkDef.h BiomeDef.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} OSSupport/File.h Bindings/LuaFunctions.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Bindings/PluginManager.h Bindings/Plugin.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Bindings/PluginLua.h Bindings/WebPlugin.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Bindings/LuaWindow.h BlockID.h StringUtils.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Defines.h ChatColor.h ClientHandle.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Entities/Entity.h Entities/Floater.h ) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Entities/Pawn.h Entities/Player.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Entities/Pickup.h Entities/ProjectileEntity.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Entities/TNTEntity.h Entities/Effects.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Server.h World.h Inventory.h Enchantments.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Item.h ItemGrid.h BlockEntities/BlockEntity.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/BlockEntityWithItems.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/ChestEntity.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/DropSpenserEntity.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/DispenserEntity.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/DropperEntity.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/FurnaceEntity.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/HopperEntity.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/JukeboxEntity.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/NoteEntity.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/SignEntity.h WebAdmin.h Root.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Vector3f.h Vector3d.h Vector3i.h Matrix4f.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Cuboid.h BoundingBox.h Tracer.h Group.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockArea.h Generating/ChunkDesc.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} CraftingRecipes.h UI/Window.h Mobs/Monster.h) + + ADD_CUSTOM_COMMAND( + # add any new generated bindings here + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/Bindings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/Bindings.h + + # command execuded to regerate bindings + COMMAND tolua -L Bindings/virtual_method_hooks.lua -o Bindings/Bindings.cpp -H Bindings/Bindings.h Bindings/AllToLua.pkg + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/ + + # add any new generation dependencies here + DEPENDS ${BINDING_DEPENDECIES} + ) + foreach(folder ${FOLDERS}) add_subdirectory(${folder}) endforeach(folder) -- cgit v1.2.3 From 27d1d5d4910460f047fdc2412e78952876f40729 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 23 Jan 2014 11:00:36 -0800 Subject: Bugfixes --- src/Bindings/CMakeLists.txt | 10 ---------- src/CMakeLists.txt | 11 +++++++++-- 2 files changed, 9 insertions(+), 12 deletions(-) delete mode 100644 src/Bindings/CMakeLists.txt diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt deleted file mode 100644 index c181f4355..000000000 --- a/src/Bindings/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ - -cmake_minimum_required (VERSION 2.6) -project (MCServer) - -# NOTE: This CMake file is processed only for Unix builds; Windows(MSVC) builds handle all the subfolders in /src in a single file, /src/CMakeLists.txt - -#add cpp files here -add_library(Bindings PluginManager LuaState WebPlugin Bindings ManualBindings LuaWindow Plugin PluginLua WebPlugin) - -target_link_libraries(Bindings lua sqlite tolualib) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 08b4971b0..309e1ce5b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,7 +18,7 @@ if (NOT MSVC) set(BINDING_DEPENDECIES ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/virtual_method_hooks.lua) set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/AllToLua.pkg) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} toluaGlobals.h ChunkDef.h BiomeDef.h) + set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} ChunkDef.h BiomeDef.h) set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} OSSupport/File.h Bindings/LuaFunctions.h) set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Bindings/PluginManager.h Bindings/Plugin.h) set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Bindings/PluginLua.h Bindings/WebPlugin.h) @@ -45,17 +45,24 @@ if (NOT MSVC) set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockArea.h Generating/ChunkDesc.h) set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} CraftingRecipes.h UI/Window.h Mobs/Monster.h) + include_directories(Bindings) + include_directories(.) + ADD_CUSTOM_COMMAND( # add any new generated bindings here OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/Bindings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/Bindings.h # command execuded to regerate bindings - COMMAND tolua -L Bindings/virtual_method_hooks.lua -o Bindings/Bindings.cpp -H Bindings/Bindings.h Bindings/AllToLua.pkg + COMMAND tolua -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/ # add any new generation dependencies here DEPENDS ${BINDING_DEPENDECIES} ) + #add cpp files here + add_library(Bindings Bindings/PluginManager Bindings/LuaState Bindings/WebPlugin Bindings/Bindings Bindings/ManualBindings Bindings/LuaWindow Bindings/Plugin Bindings/PluginLua Bindings/WebPlugin) + + target_link_libraries(Bindings lua sqlite tolualib) foreach(folder ${FOLDERS}) add_subdirectory(${folder}) -- cgit v1.2.3 From ce2fb844aa0fc60af5556ccd1cd9fe316d18dd19 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 23 Jan 2014 11:03:49 -0800 Subject: Removed Bindings folder subcmake on *nix --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 309e1ce5b..c61563bd2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,7 @@ project (MCServer) include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/") include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/jsoncpp/include") -set(FOLDERS OSSupport HTTPServer Bindings Items Blocks Protocol Generating) +set(FOLDERS OSSupport HTTPServer Items Blocks Protocol Generating) set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities) @@ -97,6 +97,7 @@ else () # Add all subfolders as solution-folders: list(APPEND FOLDERS "Resources") + list(APPEND FOLDERS "Bindings") function(includefolder PATH) FILE(GLOB FOLDER_FILES "${PATH}/*.cpp" -- cgit v1.2.3 From b21b682d851ac64bae0751a6a6ea3ca77bc4ddf7 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 23 Jan 2014 21:06:05 +0200 Subject: Fixed 1.5.x scoreboard packet IDs --- src/Protocol/Protocol15x.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/Protocol15x.cpp b/src/Protocol/Protocol15x.cpp index c33aec7d5..264a596b9 100644 --- a/src/Protocol/Protocol15x.cpp +++ b/src/Protocol/Protocol15x.cpp @@ -37,9 +37,9 @@ enum { PACKET_WINDOW_OPEN = 0x64, PACKET_PARTICLE_EFFECT = 0x3F, - PACKET_SCOREBOARD_OBJECTIVE = 0x3B, - PACKET_SCORE_UPDATE = 0x3C, - PACKET_DISPLAY_OBJECTIVE = 0x3D + PACKET_SCOREBOARD_OBJECTIVE = 0xCE, + PACKET_SCORE_UPDATE = 0xCF, + PACKET_DISPLAY_OBJECTIVE = 0xD0 } ; -- cgit v1.2.3 From b95e005d911722fec4a7a728d73c4371cb490e46 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 23 Jan 2014 11:06:42 -0800 Subject: Make clean now effects Bindings --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c61563bd2..51182d3bc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,6 +64,8 @@ if (NOT MSVC) target_link_libraries(Bindings lua sqlite tolualib) + set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "Bindings.cpp Bindings.h") + foreach(folder ${FOLDERS}) add_subdirectory(${folder}) endforeach(folder) -- cgit v1.2.3 From 5f34c78091a7c884a9c27c0f0691cd1f03174dfe Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 23 Jan 2014 23:35:23 +0100 Subject: PolarSSL is fully used for 1.3.2 protocol encryption. --- src/CMakeLists.txt | 1 + src/Crypto.cpp | 401 ++++++++++++++++++++++++++++++++++++ src/Crypto.h | 164 +++++++++++++++ src/Defines.h | 2 - src/Globals.h | 3 + src/Protocol/Protocol132.cpp | 149 +++----------- src/Protocol/Protocol132.h | 16 +- src/Protocol/Protocol14x.cpp | 2 - src/Protocol/Protocol17x.cpp | 8 +- src/Protocol/Protocol17x.h | 13 +- src/Protocol/ProtocolRecognizer.cpp | 2 +- src/Server.cpp | 12 +- src/Server.h | 14 +- 13 files changed, 630 insertions(+), 157 deletions(-) create mode 100644 src/Crypto.cpp create mode 100644 src/Crypto.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ba642f7e6..ab3b2786e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,7 @@ project (MCServer) include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/") include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/jsoncpp/include") +include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/polarssl/include") set(FOLDERS OSSupport HTTPServer Bindings Items Blocks Protocol Generating) set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities) diff --git a/src/Crypto.cpp b/src/Crypto.cpp new file mode 100644 index 000000000..5ad866f34 --- /dev/null +++ b/src/Crypto.cpp @@ -0,0 +1,401 @@ + +// Crypto.cpp + +// Implements classes that wrap the cryptographic code library + +#include "Globals.h" +#include "Crypto.h" + +#include "polarssl/pk.h" + + + + + +/* +// Self-test the hash formatting for known values: +// sha1(Notch) : 4ed1f46bbe04bc756bcb17c0c7ce3e4632f06a48 +// sha1(jeb_) : -7c9d5b0044c130109a5d7b5fb5c317c02b4e28c1 +// sha1(simon) : 88e16a1019277b15d58faf0541e11910eb756f6 + +class Test +{ +public: + Test(void) + { + AString DigestNotch, DigestJeb, DigestSimon; + Byte Digest[20]; + cSHA1Checksum Checksum; + Checksum.Update((const Byte *)"Notch", 5); + Checksum.Finalize(Digest); + cSHA1Checksum::DigestToJava(Digest, DigestNotch); + Checksum.Restart(); + Checksum.Update((const Byte *)"jeb_", 4); + Checksum.Finalize(Digest); + cSHA1Checksum::DigestToJava(Digest, DigestJeb); + Checksum.Restart(); + Checksum.Update((const Byte *)"simon", 5); + Checksum.Finalize(Digest); + cSHA1Checksum::DigestToJava(Digest, DigestSimon); + printf("Notch: \"%s\"\n", DigestNotch.c_str()); + printf("jeb_: \"%s\"\n", DigestJeb.c_str()); + printf("simon: \"%s\"\n", DigestSimon.c_str()); + assert(DigestNotch == "4ed1f46bbe04bc756bcb17c0c7ce3e4632f06a48"); + assert(DigestJeb == "-7c9d5b0044c130109a5d7b5fb5c317c02b4e28c1"); + assert(DigestSimon == "88e16a1019277b15d58faf0541e11910eb756f6"); + } +} test; +*/ + + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cRSAPrivateKey: + +cRSAPrivateKey::cRSAPrivateKey(void) +{ + rsa_init(&m_Rsa, RSA_PKCS_V15, 0); + InitRnd(); +} + + + + + +cRSAPrivateKey::cRSAPrivateKey(const cRSAPrivateKey & a_Other) +{ + rsa_init(&m_Rsa, RSA_PKCS_V15, 0); + rsa_copy(&m_Rsa, &a_Other.m_Rsa); + InitRnd(); +} + + + + + +cRSAPrivateKey::~cRSAPrivateKey() +{ + entropy_free(&m_Entropy); + rsa_free(&m_Rsa); +} + + + + + +void cRSAPrivateKey::InitRnd(void) +{ + entropy_init(&m_Entropy); + const unsigned char pers[] = "rsa_genkey"; + ctr_drbg_init(&m_Ctr_drbg, entropy_func, &m_Entropy, pers, sizeof(pers) - 1); +} + + + + + +bool cRSAPrivateKey::Generate(unsigned a_KeySizeBits) +{ + if (rsa_gen_key(&m_Rsa, ctr_drbg_random, &m_Ctr_drbg, a_KeySizeBits, 65537) != 0) + { + // Key generation failed + return false; + } + + return true; +} + + + + + +AString cRSAPrivateKey::GetPubKeyDER(void) +{ + class cPubKey + { + public: + cPubKey(rsa_context * a_Rsa) : + m_IsValid(false) + { + pk_init(&m_Key); + if (pk_init_ctx(&m_Key, pk_info_from_type(POLARSSL_PK_RSA)) != 0) + { + ASSERT(!"Cannot init PrivKey context"); + return; + } + if (rsa_copy(pk_rsa(m_Key), a_Rsa) != 0) + { + ASSERT(!"Cannot copy PrivKey to PK context"); + return; + } + m_IsValid = true; + } + + ~cPubKey() + { + if (m_IsValid) + { + pk_free(&m_Key); + } + } + + operator pk_context * (void) { return &m_Key; } + + protected: + bool m_IsValid; + pk_context m_Key; + } PkCtx(&m_Rsa); + + unsigned char buf[3000]; + int res = pk_write_pubkey_der(PkCtx, buf, sizeof(buf)); + if (res < 0) + { + return AString(); + } + return AString((const char *)(buf + sizeof(buf) - res), (size_t)res); +} + + + + + +int cRSAPrivateKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength) +{ + if (a_EncryptedLength < m_Rsa.len) + { + LOGD("%s: Invalid a_EncryptedLength: got %u, exp at least %u", + __FUNCTION__, (unsigned)a_EncryptedLength, (unsigned)(m_Rsa.len) + ); + ASSERT(!"Invalid a_DecryptedMaxLength!"); + return -1; + } + if (a_DecryptedMaxLength < m_Rsa.len) + { + LOGD("%s: Invalid a_DecryptedMaxLength: got %u, exp at least %u", + __FUNCTION__, (unsigned)a_EncryptedLength, (unsigned)(m_Rsa.len) + ); + ASSERT(!"Invalid a_DecryptedMaxLength!"); + return -1; + } + size_t DecryptedLength; + int res = rsa_pkcs1_decrypt( + &m_Rsa, ctr_drbg_random, &m_Ctr_drbg, RSA_PRIVATE, &DecryptedLength, + a_EncryptedData, a_DecryptedData, a_DecryptedMaxLength + ); + if (res != 0) + { + return -1; + } + return (int)DecryptedLength; +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cAESCFBDecryptor: + +cAESCFBDecryptor::cAESCFBDecryptor(void) : + m_IsValid(false), + m_IVOffset(0) +{ +} + + + + + +cAESCFBDecryptor::~cAESCFBDecryptor() +{ + // Clear the leftover in-memory data, so that they can't be accessed by a backdoor + memset(&m_Aes, 0, sizeof(m_Aes)); +} + + + + + +void cAESCFBDecryptor::Init(const Byte a_Key[16], const Byte a_IV[16]) +{ + ASSERT(!IsValid()); // Cannot Init twice + + memcpy(m_IV, a_IV, 16); + aes_setkey_enc(&m_Aes, a_Key, 128); + m_IsValid = true; +} + + + + + +void cAESCFBDecryptor::ProcessData(Byte * a_DecryptedOut, const Byte * a_EncryptedIn, size_t a_Length) +{ + ASSERT(IsValid()); // Must Init() first + + // PolarSSL doesn't support AES-CFB8, need to implement it manually: + for (size_t i = 0; i < a_Length; i++) + { + Byte Buffer[sizeof(m_IV)]; + aes_crypt_ecb(&m_Aes, AES_ENCRYPT, m_IV, Buffer); + for (size_t idx = 0; idx < sizeof(m_IV) - 1; idx++) + { + m_IV[idx] = m_IV[idx + 1]; + } + m_IV[sizeof(m_IV) - 1] = a_EncryptedIn[i]; + a_DecryptedOut[i] = a_EncryptedIn[i] ^ Buffer[0]; + } +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cAESCFBEncryptor: + +cAESCFBEncryptor::cAESCFBEncryptor(void) : + m_IsValid(false), + m_IVOffset(0) +{ +} + + + + + +cAESCFBEncryptor::~cAESCFBEncryptor() +{ + // Clear the leftover in-memory data, so that they can't be accessed by a backdoor + memset(&m_Aes, 0, sizeof(m_Aes)); +} + + + + + +void cAESCFBEncryptor::Init(const Byte a_Key[16], const Byte a_IV[16]) +{ + ASSERT(!IsValid()); // Cannot Init twice + ASSERT(m_IVOffset == 0); + + memcpy(m_IV, a_IV, 16); + aes_setkey_enc(&m_Aes, a_Key, 128); + m_IsValid = true; +} + + + + + +void cAESCFBEncryptor::ProcessData(Byte * a_EncryptedOut, const Byte * a_PlainIn, size_t a_Length) +{ + ASSERT(IsValid()); // Must Init() first + + // PolarSSL doesn't do AES-CFB8, so we need to implement it ourselves: + for (size_t i = 0; i < a_Length; i++) + { + Byte Buffer[sizeof(m_IV)]; + aes_crypt_ecb(&m_Aes, AES_ENCRYPT, m_IV, Buffer); + for (size_t idx = 0; idx < sizeof(m_IV) - 1; idx++) + { + m_IV[idx] = m_IV[idx + 1]; + } + a_EncryptedOut[i] = a_PlainIn[i] ^ Buffer[0]; + m_IV[sizeof(m_IV) - 1] = a_EncryptedOut[i]; + } +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSHA1Checksum: + +cSHA1Checksum::cSHA1Checksum(void) : + m_DoesAcceptInput(true) +{ + sha1_starts(&m_Sha1); +} + + + + + +void cSHA1Checksum::Update(const Byte * a_Data, size_t a_Length) +{ + ASSERT(m_DoesAcceptInput); // Not Finalize()-d yet, or Restart()-ed + + sha1_update(&m_Sha1, a_Data, a_Length); +} + + + + + +void cSHA1Checksum::Finalize(cSHA1Checksum::Checksum & a_Output) +{ + ASSERT(m_DoesAcceptInput); // Not Finalize()-d yet, or Restart()-ed + + sha1_finish(&m_Sha1, a_Output); + m_DoesAcceptInput = false; +} + + + + + +void cSHA1Checksum::DigestToJava(const Checksum & a_Digest, AString & a_Out) +{ + Checksum Digest; + memcpy(Digest, a_Digest, sizeof(Digest)); + + bool IsNegative = (Digest[0] >= 0x80); + if (IsNegative) + { + // Two's complement: + bool carry = true; // Add one to the whole number + for (int i = 19; i >= 0; i--) + { + Digest[i] = ~Digest[i]; + if (carry) + { + carry = (Digest[i] == 0xff); + Digest[i]++; + } + } + } + a_Out.clear(); + a_Out.reserve(40); + for (int i = 0; i < 20; i++) + { + AppendPrintf(a_Out, "%02x", Digest[i]); + } + while ((a_Out.length() > 0) && (a_Out[0] == '0')) + { + a_Out.erase(0, 1); + } + if (IsNegative) + { + a_Out.insert(0, "-"); + } +} + + + + + + +void cSHA1Checksum::Restart(void) +{ + sha1_starts(&m_Sha1); + m_DoesAcceptInput = true; +} + + + + diff --git a/src/Crypto.h b/src/Crypto.h new file mode 100644 index 000000000..6b576f55b --- /dev/null +++ b/src/Crypto.h @@ -0,0 +1,164 @@ + +// Crypto.h + +// Declares classes that wrap the cryptographic code library + + + + + +#pragma once + +#include "polarssl/rsa.h" +#include "polarssl/aes.h" +#include "polarssl/entropy.h" +#include "polarssl/ctr_drbg.h" +#include "polarssl/sha1.h" + + + + + +/** Encapsulates an RSA private key used in PKI cryptography */ +class cRSAPrivateKey +{ +public: + /** Creates a new empty object, the key is not assigned */ + cRSAPrivateKey(void); + + /** Deep-copies the key from a_Other */ + cRSAPrivateKey(const cRSAPrivateKey & a_Other); + + ~cRSAPrivateKey(); + + /** Generates a new key within this object, with the specified size in bits. + Returns true on success, false on failure. */ + bool Generate(unsigned a_KeySizeBits = 1024); + + /** Returns the public key part encoded in ASN1 DER encoding */ + AString GetPubKeyDER(void); + + /** Decrypts the data using RSAES-PKCS#1 algorithm. + Both a_EncryptedData and a_DecryptedData must be at least bytes large. + Returns the number of bytes decrypted, or negative number for error. */ + int Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength); + +protected: + rsa_context m_Rsa; + entropy_context m_Entropy; + ctr_drbg_context m_Ctr_drbg; + + /** Initializes the m_Entropy and m_Ctr_drbg contexts + Common part of this object's construction, called from all constructors. */ + void InitRnd(void); +} ; + + + + + +/** Decrypts data using the AES / CFB (128) algorithm */ +class cAESCFBDecryptor +{ +public: + Byte test; + + cAESCFBDecryptor(void); + ~cAESCFBDecryptor(); + + /** Initializes the decryptor with the specified Key / IV */ + void Init(const Byte a_Key[16], const Byte a_IV[16]); + + /** Decrypts a_Length bytes of the encrypted data; produces a_Length output bytes */ + void ProcessData(Byte * a_DecryptedOut, const Byte * a_EncryptedIn, size_t a_Length); + + /** Returns true if the object has been initialized with the Key / IV */ + bool IsValid(void) const { return m_IsValid; } + +protected: + aes_context m_Aes; + + /** The InitialVector, used by the CFB mode decryption */ + Byte m_IV[16]; + + /** Current offset in the m_IV, used by the CFB mode decryption */ + size_t m_IVOffset; + + /** Indicates whether the object has been initialized with the Key / IV */ + bool m_IsValid; +} ; + + + + + +/** Encrypts data using the AES / CFB (128) algorithm */ +class cAESCFBEncryptor +{ +public: + Byte test; + + cAESCFBEncryptor(void); + ~cAESCFBEncryptor(); + + /** Initializes the decryptor with the specified Key / IV */ + void Init(const Byte a_Key[16], const Byte a_IV[16]); + + /** Encrypts a_Length bytes of the plain data; produces a_Length output bytes */ + void ProcessData(Byte * a_EncryptedOut, const Byte * a_PlainIn, size_t a_Length); + + /** Returns true if the object has been initialized with the Key / IV */ + bool IsValid(void) const { return m_IsValid; } + +protected: + aes_context m_Aes; + + /** The InitialVector, used by the CFB mode encryption */ + Byte m_IV[16]; + + /** Current offset in the m_IV, used by the CFB mode encryption */ + size_t m_IVOffset; + + /** Indicates whether the object has been initialized with the Key / IV */ + bool m_IsValid; +} ; + + + + + +/** Calculates a SHA1 checksum for data stream */ +class cSHA1Checksum +{ +public: + typedef Byte Checksum[20]; // The type used for storing the checksum + + cSHA1Checksum(void); + + /** Adds the specified data to the checksum */ + void Update(const Byte * a_Data, size_t a_Length); + + /** Calculates and returns the final checksum */ + void Finalize(Checksum & a_Output); + + /** Returns true if the object is accepts more input data, false if Finalize()-d (need to Restart()) */ + bool DoesAcceptInput(void) const { return m_DoesAcceptInput; } + + /** Converts a raw 160-bit SHA1 digest into a Java Hex representation + According to http://wiki.vg/wiki/index.php?title=Protocol_Encryption&oldid=2802 + */ + static void DigestToJava(const Checksum & a_Digest, AString & a_JavaOut); + + /** Clears the current context and start a new checksum calculation */ + void Restart(void); + +protected: + /** True if the object is accepts more input data, false if Finalize()-d (need to Restart()) */ + bool m_DoesAcceptInput; + + sha1_context m_Sha1; +} ; + + + + diff --git a/src/Defines.h b/src/Defines.h index 7a86f499e..0dcc3214a 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -5,8 +5,6 @@ -typedef unsigned char Byte; - /// List of slot numbers, used for inventory-painting typedef std::vector cSlotNums; diff --git a/src/Globals.h b/src/Globals.h index d2080b8eb..7e53da80e 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -91,6 +91,9 @@ typedef unsigned long long UInt64; typedef unsigned int UInt32; typedef unsigned short UInt16; +typedef unsigned char Byte; + + diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index b4ca37d37..f5fd95c7e 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -28,13 +28,14 @@ #pragma warning(disable:4702) #endif -#include "cryptopp/randpool.h" - #ifdef _MSC_VER #pragma warning(pop) #endif + + + #define HANDLE_PACKET_READ(Proc, Type, Var) \ Type Var; \ { \ @@ -49,17 +50,6 @@ -typedef unsigned char Byte; - - - - - -using namespace CryptoPP; - - - - const int MAX_ENC_LEN = 512; // Maximum size of the encrypted message; should be 128, but who knows... @@ -93,81 +83,6 @@ enum -// Converts a raw 160-bit SHA1 digest into a Java Hex representation -// According to http://wiki.vg/wiki/index.php?title=Protocol_Encryption&oldid=2802 -static void DigestToJava(byte a_Digest[20], AString & a_Out) -{ - bool IsNegative = (a_Digest[0] >= 0x80); - if (IsNegative) - { - // Two's complement: - bool carry = true; // Add one to the whole number - for (int i = 19; i >= 0; i--) - { - a_Digest[i] = ~a_Digest[i]; - if (carry) - { - carry = (a_Digest[i] == 0xff); - a_Digest[i]++; - } - } - } - a_Out.clear(); - a_Out.reserve(40); - for (int i = 0; i < 20; i++) - { - AppendPrintf(a_Out, "%02x", a_Digest[i]); - } - while ((a_Out.length() > 0) && (a_Out[0] == '0')) - { - a_Out.erase(0, 1); - } - if (IsNegative) - { - a_Out.insert(0, "-"); - } -} - - - - - -/* -// Self-test the hash formatting for known values: -// sha1(Notch) : 4ed1f46bbe04bc756bcb17c0c7ce3e4632f06a48 -// sha1(jeb_) : -7c9d5b0044c130109a5d7b5fb5c317c02b4e28c1 -// sha1(simon) : 88e16a1019277b15d58faf0541e11910eb756f6 - -class Test -{ -public: - Test(void) - { - AString DigestNotch, DigestJeb, DigestSimon; - byte Digest[20]; - CryptoPP::SHA1 Checksum; - Checksum.Update((const byte *)"Notch", 5); - Checksum.Final(Digest); - DigestToJava(Digest, DigestNotch); - Checksum.Restart(); - Checksum.Update((const byte *)"jeb_", 4); - Checksum.Final(Digest); - DigestToJava(Digest, DigestJeb); - Checksum.Restart(); - Checksum.Update((const byte *)"simon", 5); - Checksum.Final(Digest); - DigestToJava(Digest, DigestSimon); - printf("Notch: \"%s\"", DigestNotch.c_str()); - printf("jeb_: \"%s\"", DigestJeb.c_str()); - printf("simon: \"%s\"", DigestSimon.c_str()); - } -} test; -*/ - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cProtocol132: @@ -197,11 +112,11 @@ void cProtocol132::DataReceived(const char * a_Data, int a_Size) { if (m_IsEncrypted) { - byte Decrypted[512]; + Byte Decrypted[512]; while (a_Size > 0) { int NumBytes = (a_Size > (int)sizeof(Decrypted)) ? (int)sizeof(Decrypted) : a_Size; - m_Decryptor.ProcessData(Decrypted, (byte *)a_Data, NumBytes); + m_Decryptor.ProcessData(Decrypted, (Byte *)a_Data, NumBytes); super::DataReceived((const char *)Decrypted, NumBytes); a_Size -= NumBytes; a_Data += NumBytes; @@ -582,9 +497,7 @@ int cProtocol132::ParseHandshake(void) return PARSE_OK; // Player is not allowed into the server } - // Send a 0xFD Encryption Key Request http://wiki.vg/Protocol#0xFD - CryptoPP::StringSink sink(m_ServerPublicKey); // GCC won't allow inline instantiation in the following line, damned temporary refs - cRoot::Get()->GetServer()->GetPublicKey().Save(sink); + // Send a 0xfd Encryption Key Request http://wiki.vg/Protocol#0xFD SendEncryptionKeyRequest(); return PARSE_OK; @@ -596,7 +509,7 @@ int cProtocol132::ParseHandshake(void) int cProtocol132::ParseClientStatuses(void) { - HANDLE_PACKET_READ(ReadByte, byte, Status); + HANDLE_PACKET_READ(ReadByte, Byte, Status); if ((Status & 1) == 0) { m_Client->HandleLogin(39, m_Username); @@ -714,11 +627,11 @@ void cProtocol132::Flush(void) int a_Size = m_DataToSend.size(); if (m_IsEncrypted) { - byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks) + Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks) while (a_Size > 0) { int NumBytes = (a_Size > (int)sizeof(Encrypted)) ? (int)sizeof(Encrypted) : a_Size; - m_Encryptor.ProcessData(Encrypted, (byte *)a_Data, NumBytes); + m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes); super::SendData((const char *)Encrypted, NumBytes); a_Size -= NumBytes; a_Data += NumBytes; @@ -880,8 +793,8 @@ void cProtocol132::SendEncryptionKeyRequest(void) cCSLock Lock(m_CSPacket); WriteByte(0xfd); WriteString(cRoot::Get()->GetServer()->GetServerID()); - WriteShort((short)m_ServerPublicKey.size()); - SendData(m_ServerPublicKey.data(), m_ServerPublicKey.size()); + WriteShort((short)(cRoot::Get()->GetServer()->GetPublicKeyDER().size())); + SendData(cRoot::Get()->GetServer()->GetPublicKeyDER().data(), cRoot::Get()->GetServer()->GetPublicKeyDER().size()); WriteShort(4); WriteInt((int)(intptr_t)this); // Using 'this' as the cryptographic nonce, so that we don't have to generate one each time :) Flush(); @@ -894,13 +807,11 @@ void cProtocol132::SendEncryptionKeyRequest(void) void cProtocol132::HandleEncryptionKeyResponse(const AString & a_EncKey, const AString & a_EncNonce) { // Decrypt EncNonce using privkey - RSAES::Decryptor rsaDecryptor(cRoot::Get()->GetServer()->GetPrivateKey()); - time_t CurTime = time(NULL); - CryptoPP::RandomPool rng; - rng.Put((const byte *)&CurTime, sizeof(CurTime)); + cRSAPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey(); + Int32 DecryptedNonce[MAX_ENC_LEN / sizeof(Int32)]; - DecodingResult res = rsaDecryptor.Decrypt(rng, (const byte *)a_EncNonce.data(), a_EncNonce.size(), (byte *)DecryptedNonce); - if (!res.isValidCoding || (res.messageLength != 4)) + int res = rsaDecryptor.Decrypt((const Byte *)a_EncNonce.data(), a_EncNonce.size(), (Byte *)DecryptedNonce, sizeof(DecryptedNonce)); + if (res != 4) { LOGD("Bad nonce length"); m_Client->Kick("Hacked client"); @@ -914,9 +825,9 @@ void cProtocol132::HandleEncryptionKeyResponse(const AString & a_EncKey, const A } // Decrypt the symmetric encryption key using privkey: - byte DecryptedKey[MAX_ENC_LEN]; - res = rsaDecryptor.Decrypt(rng, (const byte *)a_EncKey.data(), a_EncKey.size(), DecryptedKey); - if (!res.isValidCoding || (res.messageLength != 16)) + Byte DecryptedKey[MAX_ENC_LEN]; + res = rsaDecryptor.Decrypt((const Byte *)a_EncKey.data(), a_EncKey.size(), DecryptedKey, sizeof(DecryptedKey)); + if (res != 16) { LOGD("Bad key length"); m_Client->Kick("Hacked client"); @@ -932,6 +843,12 @@ void cProtocol132::HandleEncryptionKeyResponse(const AString & a_EncKey, const A Flush(); } + #ifdef _DEBUG + AString DecryptedKeyHex; + CreateHexDump(DecryptedKeyHex, DecryptedKey, res, 16); + LOGD("Received encryption key, %d bytes:\n%s", res, DecryptedKeyHex.c_str()); + #endif + StartEncryption(DecryptedKey); return; } @@ -940,21 +857,21 @@ void cProtocol132::HandleEncryptionKeyResponse(const AString & a_EncKey, const A -void cProtocol132::StartEncryption(const byte * a_Key) +void cProtocol132::StartEncryption(const Byte * a_Key) { - m_Encryptor.SetKey(a_Key, 16, MakeParameters(Name::IV(), ConstByteArrayParameter(a_Key, 16))(Name::FeedbackSize(), 1)); - m_Decryptor.SetKey(a_Key, 16, MakeParameters(Name::IV(), ConstByteArrayParameter(a_Key, 16))(Name::FeedbackSize(), 1)); + m_Encryptor.Init(a_Key, a_Key); + m_Decryptor.Init(a_Key, a_Key); m_IsEncrypted = true; // Prepare the m_AuthServerID: - CryptoPP::SHA1 Checksum; + cSHA1Checksum Checksum; AString ServerID = cRoot::Get()->GetServer()->GetServerID(); - Checksum.Update((const byte *)ServerID.c_str(), ServerID.length()); + Checksum.Update((const Byte *)ServerID.c_str(), ServerID.length()); Checksum.Update(a_Key, 16); - Checksum.Update((const byte *)m_ServerPublicKey.c_str(), m_ServerPublicKey.length()); - byte Digest[20]; - Checksum.Final(Digest); - DigestToJava(Digest, m_AuthServerID); + Checksum.Update((const Byte *)cRoot::Get()->GetServer()->GetPublicKeyDER().data(), cRoot::Get()->GetServer()->GetPublicKeyDER().size()); + Byte Digest[20]; + Checksum.Finalize(Digest); + cSHA1Checksum::DigestToJava(Digest, m_AuthServerID); } diff --git a/src/Protocol/Protocol132.h b/src/Protocol/Protocol132.h index 80fc8740a..89f4636f5 100644 --- a/src/Protocol/Protocol132.h +++ b/src/Protocol/Protocol132.h @@ -20,13 +20,12 @@ #pragma warning(disable:4702) #endif -#include "cryptopp/modes.h" -#include "cryptopp/aes.h" - #ifdef _MSC_VER #pragma warning(pop) #endif +#include "../Crypto.h" + @@ -79,16 +78,15 @@ public: protected: bool m_IsEncrypted; - CryptoPP::CFB_Mode::Decryption m_Decryptor; - CryptoPP::CFB_Mode::Encryption m_Encryptor; + + cAESCFBDecryptor m_Decryptor; + cAESCFBEncryptor m_Encryptor; + AString m_DataToSend; /// The ServerID used for session authentication; set in StartEncryption(), used in GetAuthServerID() AString m_AuthServerID; - /// The server's public key, as used by SendEncryptionKeyRequest() and StartEncryption() - AString m_ServerPublicKey; - virtual void SendData(const char * a_Data, int a_Size) override; // DEBUG: @@ -108,7 +106,7 @@ protected: void HandleEncryptionKeyResponse(const AString & a_EncKey, const AString & a_EncNonce); /// Starts the symmetric encryption with the specified key; also sets m_AuthServerID - void StartEncryption(const byte * a_Key); + void StartEncryption(const Byte * a_Key); } ; diff --git a/src/Protocol/Protocol14x.cpp b/src/Protocol/Protocol14x.cpp index 127ce9d4b..f82e6de45 100644 --- a/src/Protocol/Protocol14x.cpp +++ b/src/Protocol/Protocol14x.cpp @@ -33,8 +33,6 @@ Implements the 1.4.x protocol classes representing these protocols: #pragma warning(disable:4702) #endif -#include "cryptopp/randpool.h" - #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 9506332dc..bcc638796 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -73,11 +73,11 @@ void cProtocol172::DataReceived(const char * a_Data, int a_Size) { if (m_IsEncrypted) { - byte Decrypted[512]; + Byte Decrypted[512]; while (a_Size > 0) { int NumBytes = (a_Size > sizeof(Decrypted)) ? sizeof(Decrypted) : a_Size; - m_Decryptor.ProcessData(Decrypted, (byte *)a_Data, NumBytes); + m_Decryptor.ProcessData(Decrypted, (Byte *)a_Data, NumBytes); AddReceivedData((const char *)Decrypted, NumBytes); a_Size -= NumBytes; a_Data += NumBytes; @@ -1664,11 +1664,11 @@ void cProtocol172::SendData(const char * a_Data, int a_Size) { if (m_IsEncrypted) { - byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks) + Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks) while (a_Size > 0) { int NumBytes = (a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : a_Size; - m_Encryptor.ProcessData(Encrypted, (byte *)a_Data, NumBytes); + m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes); m_Client->SendData((const char *)Encrypted, NumBytes); a_Size -= NumBytes; a_Data += NumBytes; diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 3f440f313..0617b6c00 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -26,21 +26,20 @@ Declares the 1.7.x protocol classes: #pragma warning(disable:4702) #endif -#include "cryptopp/modes.h" -#include "cryptopp/aes.h" - #ifdef _MSC_VER #pragma warning(pop) #endif +#include "../Crypto.h" + class cProtocol172 : - public cProtocol // TODO + public cProtocol { - typedef cProtocol super; // TODO + typedef cProtocol super; public: @@ -220,9 +219,9 @@ protected: cByteBuffer m_OutPacketLenBuffer; bool m_IsEncrypted; - CryptoPP::CFB_Mode::Decryption m_Decryptor; - CryptoPP::CFB_Mode::Encryption m_Encryptor; + cAESCFBDecryptor m_Decryptor; + cAESCFBEncryptor m_Encryptor; /// Adds the received (unencrypted) data to m_ReceivedData, parses complete packets void AddReceivedData(const char * a_Data, int a_Size); diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index de5dd3fb9..32409c2aa 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -965,7 +965,7 @@ void cProtocolRecognizer::SendLengthlessServerPing(void) m_Buffer.ResetRead(); if (m_Buffer.CanReadBytes(2)) { - byte val; + Byte val; m_Buffer.ReadByte(val); // Packet type - Serverlist ping m_Buffer.ReadByte(val); // 0x01 magic value ASSERT(val == 0x01); diff --git a/src/Server.cpp b/src/Server.cpp index 34ee066cb..f64af62eb 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -284,17 +284,9 @@ int cServer::GetNumPlayers(void) void cServer::PrepareKeys(void) { - // TODO: Save and load key for persistence across sessions - // But generating the key takes only a moment, do we even need that? - LOGD("Generating protocol encryption keypair..."); - - time_t CurTime = time(NULL); - CryptoPP::RandomPool rng; - rng.Put((const byte *)&CurTime, sizeof(CurTime)); - m_PrivateKey.GenerateRandomWithKeySize(rng, 1024); - CryptoPP::RSA::PublicKey pk(m_PrivateKey); - m_PublicKey = pk; + VERIFY(m_PrivateKey.Generate(1024)); + m_PublicKeyDER = m_PrivateKey.GetPubKeyDER(); } diff --git a/src/Server.h b/src/Server.h index bb55e81b6..15eafc00a 100644 --- a/src/Server.h +++ b/src/Server.h @@ -23,8 +23,7 @@ #pragma warning(disable:4702) #endif -#include "cryptopp/rsa.h" -#include "cryptopp/randpool.h" +#include "Crypto.h" #ifdef _MSC_VER #pragma warning(pop) @@ -110,8 +109,8 @@ public: // tolua_export /** Returns base64 encoded favicon data (obtained from favicon.png) */ const AString & GetFaviconData(void) const { return m_FaviconData; } - CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; } - CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; } + cRSAPrivateKey & GetPrivateKey(void) { return m_PrivateKey; } + const AString & GetPublicKeyDER(void) const { return m_PublicKeyDER; } private: @@ -180,8 +179,11 @@ private: bool m_bRestarting; - CryptoPP::RSA::PrivateKey m_PrivateKey; - CryptoPP::RSA::PublicKey m_PublicKey; + /** The private key used for the assymetric encryption start in the protocols */ + cRSAPrivateKey m_PrivateKey; + + /** Public key for m_PrivateKey, ASN1-DER-encoded */ + AString m_PublicKeyDER; cRCONServer m_RCONServer; -- cgit v1.2.3 From e251e526739b72554b99260e047727d1e85aadf9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 23 Jan 2014 23:45:28 +0100 Subject: Fixed a warning in ScoreboardSerializer. --- src/WorldStorage/ScoreboardSerializer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp index dabc5e2e1..0788aff17 100644 --- a/src/WorldStorage/ScoreboardSerializer.cpp +++ b/src/WorldStorage/ScoreboardSerializer.cpp @@ -321,13 +321,13 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT) CurrLine = a_NBT.FindChildByName(Child, "AllowFriendlyFire"); if (CurrLine >= 0) { - AllowsFriendlyFire = a_NBT.GetInt(CurrLine); + AllowsFriendlyFire = (a_NBT.GetInt(CurrLine) != 0); } CurrLine = a_NBT.FindChildByName(Child, "SeeFriendlyInvisibles"); if (CurrLine >= 0) { - CanSeeFriendlyInvisible = a_NBT.GetInt(CurrLine); + CanSeeFriendlyInvisible = (a_NBT.GetInt(CurrLine) != 0); } cTeam * Team = m_ScoreBoard->RegisterTeam(Name, DisplayName, Prefix, Suffix); -- cgit v1.2.3 From 11948b1d4b98e0147217eef2928a2391c2d8e958 Mon Sep 17 00:00:00 2001 From: Mike Hunsinger Date: Thu, 23 Jan 2014 19:54:00 -0700 Subject: Fixed spacing and doxycomments. --- .../Plugins/APIDump/Hooks/OnPlayerTossingItem.lua | 4 ++-- src/Entities/Player.cpp | 6 +++--- src/Entities/Player.h | 6 +++--- src/UI/Window.cpp | 22 ++++++++++------------ 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua index 2b65294ef..48aac2aa0 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua @@ -19,8 +19,8 @@ return Returns = [[ If the function returns false or no value, other plugins' callbacks are called and finally MCServer creates the pickup for the item and tosses it, using {{cPlayer}}:TossHeldItem, {{cPlayer}}:TossEquippedItem, - or {{cPlayer}}:TossPickup. If the function returns true, no other callbacks are called for this event - and MCServer doesn't toss the item. + or {{cPlayer}}:TossPickup. If the function returns true, no other callbacks are called for this event + and MCServer doesn't toss the item. ]], }, -- HOOK_PLAYER_TOSSING_ITEM } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index ca39d4d9d..64cd334d1 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1389,8 +1389,8 @@ void cPlayer::TossHeldItem(char a_Amount) } } - double vX = 0, vY = 0, vZ = 0; - EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); + double vX = 0, vY = 0, vZ = 0; + EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player } @@ -1402,7 +1402,7 @@ void cPlayer::TossHeldItem(char a_Amount) void cPlayer::TossPickup(const cItem & a_Item) { cItems Drops; - Drops.push_back(a_Item); + Drops.push_back(a_Item); double vX = 0, vY = 0, vZ = 0; EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 71033ab77..7925e70a1 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -214,13 +214,13 @@ public: /// Returns the full color code to use for this player, based on their primary group or set in m_Color AString GetColor(void) const; - // tosses the item in the selected hotbar slot + /** tosses the item in the selected hotbar slot */ void TossEquippedItem(char a_Amount = 1); - // tosses the item held in hand (when in UI windows) + /** tosses the item held in hand (when in UI windows) */ void TossHeldItem(char a_Amount = 1); - // tosses a pickup newly created from a_Item + /** tosses a pickup newly created from a_Item */ void TossPickup(const cItem & a_Item); /// Heals the player by the specified amount of HPs (positive only); sends health update diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 3d23dfd07..4261a58d9 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -171,7 +171,6 @@ void cWindow::Clicked( ) { cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); - if (a_WindowID != m_WindowID) { LOGWARNING("%s: Wrong window ID (exp %d, got %d) received from \"%s\"; ignoring click.", __FUNCTION__, m_WindowID, a_WindowID, a_Player.GetName().c_str()); @@ -182,16 +181,15 @@ void cWindow::Clicked( { case caRightClickOutside: { - if (PlgMgr->CallHookPlayerTossingItem(a_Player)) + if (PlgMgr->CallHookPlayerTossingItem(a_Player)) { // A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch) return; } - - if (a_Player.IsGameModeCreative()) - { - a_Player.TossPickup(a_ClickedItem); - } + if (a_Player.IsGameModeCreative()) + { + a_Player.TossPickup(a_ClickedItem); + } // Toss one of the dragged items: a_Player.TossHeldItem(); @@ -205,10 +203,10 @@ void cWindow::Clicked( return; } - if (a_Player.IsGameModeCreative()) - { - a_Player.TossPickup(a_ClickedItem); - } + if (a_Player.IsGameModeCreative()) + { + a_Player.TossPickup(a_ClickedItem); + } // Toss all dragged items: a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount); @@ -288,7 +286,7 @@ bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) if (a_Player.IsDraggingItem()) { LOGD("Player holds item! Dropping it..."); - a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount); + a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount); } cClientHandle * ClientHandle = a_Player.GetClientHandle(); -- cgit v1.2.3 From 9926ea58e841af94ded4ea55e409020c732f6cb7 Mon Sep 17 00:00:00 2001 From: Mike Hunsinger Date: Thu, 23 Jan 2014 20:01:08 -0700 Subject: Fixed indentation and doxygen comments... For real this time. --- .../Plugins/APIDump/Hooks/OnPlayerTossingItem.lua | 4 ++-- src/Entities/Player.cpp | 6 +++--- src/UI/Window.cpp | 24 +++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua index 48aac2aa0..ad2a87ed6 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua @@ -19,8 +19,8 @@ return Returns = [[ If the function returns false or no value, other plugins' callbacks are called and finally MCServer creates the pickup for the item and tosses it, using {{cPlayer}}:TossHeldItem, {{cPlayer}}:TossEquippedItem, - or {{cPlayer}}:TossPickup. If the function returns true, no other callbacks are called for this event - and MCServer doesn't toss the item. + or {{cPlayer}}:TossPickup. If the function returns true, no other callbacks are called for this event + and MCServer doesn't toss the item. ]], }, -- HOOK_PLAYER_TOSSING_ITEM } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 64cd334d1..54de4dee9 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1389,8 +1389,8 @@ void cPlayer::TossHeldItem(char a_Amount) } } - double vX = 0, vY = 0, vZ = 0; - EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); + double vX = 0, vY = 0, vZ = 0; + EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player } @@ -1402,7 +1402,7 @@ void cPlayer::TossHeldItem(char a_Amount) void cPlayer::TossPickup(const cItem & a_Item) { cItems Drops; - Drops.push_back(a_Item); + Drops.push_back(a_Item); double vX = 0, vY = 0, vZ = 0; EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 4261a58d9..dd058b304 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -170,7 +170,7 @@ void cWindow::Clicked( const cItem & a_ClickedItem ) { - cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); + cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); if (a_WindowID != m_WindowID) { LOGWARNING("%s: Wrong window ID (exp %d, got %d) received from \"%s\"; ignoring click.", __FUNCTION__, m_WindowID, a_WindowID, a_Player.GetName().c_str()); @@ -181,15 +181,15 @@ void cWindow::Clicked( { case caRightClickOutside: { - if (PlgMgr->CallHookPlayerTossingItem(a_Player)) + if (PlgMgr->CallHookPlayerTossingItem(a_Player)) { // A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch) return; } - if (a_Player.IsGameModeCreative()) - { - a_Player.TossPickup(a_ClickedItem); - } + if (a_Player.IsGameModeCreative()) + { + a_Player.TossPickup(a_ClickedItem); + } // Toss one of the dragged items: a_Player.TossHeldItem(); @@ -203,10 +203,10 @@ void cWindow::Clicked( return; } - if (a_Player.IsGameModeCreative()) - { - a_Player.TossPickup(a_ClickedItem); - } + if (a_Player.IsGameModeCreative()) + { + a_Player.TossPickup(a_ClickedItem); + } // Toss all dragged items: a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount); @@ -285,8 +285,8 @@ bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) // Checks whether the player is still holding an item if (a_Player.IsDraggingItem()) { - LOGD("Player holds item! Dropping it..."); - a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount); + LOGD("Player holds item! Dropping it..."); + a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount); } cClientHandle * ClientHandle = a_Player.GetClientHandle(); -- cgit v1.2.3 From 7c12247263502030fbf50fc6fda12bb8f67a269b Mon Sep 17 00:00:00 2001 From: Mike Hunsinger Date: Thu, 23 Jan 2014 20:11:10 -0700 Subject: Fixed indentation once and for all. --- src/Entities/Player.cpp | 62 ++++++++++++++++++++++++------------------------- src/UI/Window.cpp | 30 ++++++++++++------------ 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 54de4dee9..b2574c433 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1345,20 +1345,20 @@ AString cPlayer::GetColor(void) const void cPlayer::TossEquippedItem(char a_Amount) { cItems Drops; - cItem DroppedItem(GetInventory().GetEquippedItem()); - if (!DroppedItem.IsEmpty()) - { - char NewAmount = a_Amount; - if (NewAmount > GetInventory().GetEquippedItem().m_ItemCount) - { - NewAmount = GetInventory().GetEquippedItem().m_ItemCount; // Drop only what's there - } + cItem DroppedItem(GetInventory().GetEquippedItem()); + if (!DroppedItem.IsEmpty()) + { + char NewAmount = a_Amount; + if (NewAmount > GetInventory().GetEquippedItem().m_ItemCount) + { + NewAmount = GetInventory().GetEquippedItem().m_ItemCount; // Drop only what's there + } - GetInventory().GetHotbarGrid().ChangeSlotCount(GetInventory().GetEquippedSlotNum() /* Returns hotbar subslot, which HotbarGrid takes */, -a_Amount); + GetInventory().GetHotbarGrid().ChangeSlotCount(GetInventory().GetEquippedSlotNum() /* Returns hotbar subslot, which HotbarGrid takes */, -a_Amount); - DroppedItem.m_ItemCount = NewAmount; - Drops.push_back(DroppedItem); - } + DroppedItem.m_ItemCount = NewAmount; + Drops.push_back(DroppedItem); + } double vX = 0, vY = 0, vZ = 0; EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); @@ -1373,24 +1373,24 @@ void cPlayer::TossEquippedItem(char a_Amount) void cPlayer::TossHeldItem(char a_Amount) { cItems Drops; - cItem & Item = GetDraggingItem(); - if (!Item.IsEmpty()) - { - char OriginalItemAmount = Item.m_ItemCount; - Item.m_ItemCount = std::min(OriginalItemAmount, a_Amount); - Drops.push_back(Item); - if (OriginalItemAmount > a_Amount) - { - Item.m_ItemCount = OriginalItemAmount - a_Amount; - } - else - { - Item.Empty(); - } - } - - double vX = 0, vY = 0, vZ = 0; - EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); + cItem & Item = GetDraggingItem(); + if (!Item.IsEmpty()) + { + char OriginalItemAmount = Item.m_ItemCount; + Item.m_ItemCount = std::min(OriginalItemAmount, a_Amount); + Drops.push_back(Item); + if (OriginalItemAmount > a_Amount) + { + Item.m_ItemCount = OriginalItemAmount - a_Amount; + } + else + { + Item.Empty(); + } + } + + double vX = 0, vY = 0, vZ = 0; + EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player } @@ -1402,7 +1402,7 @@ void cPlayer::TossHeldItem(char a_Amount) void cPlayer::TossPickup(const cItem & a_Item) { cItems Drops; - Drops.push_back(a_Item); + Drops.push_back(a_Item); double vX = 0, vY = 0, vZ = 0; EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index dd058b304..1a8456f70 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -181,15 +181,15 @@ void cWindow::Clicked( { case caRightClickOutside: { - if (PlgMgr->CallHookPlayerTossingItem(a_Player)) + if (PlgMgr->CallHookPlayerTossingItem(a_Player)) + { + // A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch) + return; + } + if (a_Player.IsGameModeCreative()) { - // A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch) - return; + a_Player.TossPickup(a_ClickedItem); } - if (a_Player.IsGameModeCreative()) - { - a_Player.TossPickup(a_ClickedItem); - } // Toss one of the dragged items: a_Player.TossHeldItem(); @@ -199,14 +199,14 @@ void cWindow::Clicked( { if (PlgMgr->CallHookPlayerTossingItem(a_Player)) { - // A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch) - return; + // A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch) + return; } - if (a_Player.IsGameModeCreative()) - { - a_Player.TossPickup(a_ClickedItem); - } + if (a_Player.IsGameModeCreative()) + { + a_Player.TossPickup(a_ClickedItem); + } // Toss all dragged items: a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount); @@ -285,8 +285,8 @@ bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) // Checks whether the player is still holding an item if (a_Player.IsDraggingItem()) { - LOGD("Player holds item! Dropping it..."); - a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount); + LOGD("Player holds item! Dropping it..."); + a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount); } cClientHandle * ClientHandle = a_Player.GetClientHandle(); -- cgit v1.2.3 From 22d101034ffe810297455fb4caa27baf138a6342 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 23 Jan 2014 22:24:20 +0100 Subject: Fixed flint&steel failure on the Y world edges. --- src/Items/ItemLighter.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Items/ItemLighter.h b/src/Items/ItemLighter.h index 4281a2d0c..8f3389d95 100644 --- a/src/Items/ItemLighter.h +++ b/src/Items/ItemLighter.h @@ -42,6 +42,10 @@ public: { // Light a fire next to/on top of the block if air: AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); + if ((a_BlockY < 0) || (a_BlockY >= cChunkDef::Height)) + { + break; + } if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) { a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 0); -- cgit v1.2.3 From ebc3f6aa28cae2510efa4d5de9562d24e6d8e96a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 08:59:21 +0100 Subject: APIDump: Fixed indent after merge. --- MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua index ad2a87ed6..82d5bb390 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerTossingItem.lua @@ -19,8 +19,8 @@ return Returns = [[ If the function returns false or no value, other plugins' callbacks are called and finally MCServer creates the pickup for the item and tosses it, using {{cPlayer}}:TossHeldItem, {{cPlayer}}:TossEquippedItem, - or {{cPlayer}}:TossPickup. If the function returns true, no other callbacks are called for this event - and MCServer doesn't toss the item. + or {{cPlayer}}:TossPickup. If the function returns true, no other callbacks are called for this event + and MCServer doesn't toss the item. ]], }, -- HOOK_PLAYER_TOSSING_ITEM } -- cgit v1.2.3 From b02940209d64e4239ac6c0e7c8cb4f1d8280b7aa Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 09:57:12 +0100 Subject: Fixed crash with failed entity-loading. This should fix issues reported in: http://forum.mc-server.org/showthread.php?tid=1328 http://forum.mc-server.org/showthread.php?tid=1308 --- src/Entities/Entity.cpp | 3 ++- src/WorldStorage/WSSAnvil.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 565c78dfd..09fb7052d 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -73,7 +73,8 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d cEntity::~cEntity() { - ASSERT(!m_World->HasEntity(m_UniqueID)); // Before deleting, the entity needs to have been removed from the world + // Before deleting, the entity needs to have been removed from the world, if ever added + ASSERT((m_World == NULL) || !m_World->HasEntity(m_UniqueID)); /* // DEBUG: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 8be6372e2..e2a882f65 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1926,14 +1926,19 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N double Speed[3]; if (!LoadDoublesListFromNBT(Speed, 3, a_NBT, a_NBT.FindChildByName(a_TagIdx, "Motion"))) { - return false; + // Provide default speed: + Speed[0] = 0; + Speed[1] = 0; + Speed[2] = 0; } a_Entity.SetSpeed(Speed[0], Speed[1], Speed[2]); double Rotation[3]; if (!LoadDoublesListFromNBT(Rotation, 2, a_NBT, a_NBT.FindChildByName(a_TagIdx, "Rotation"))) { - return false; + // Provide default rotation: + Rotation[0] = 0; + Rotation[1] = 0; } a_Entity.SetYaw(Rotation[0]); a_Entity.SetRoll(Rotation[1]); -- cgit v1.2.3 From 0369c585fb16777acd4639122f8cee2d7c60833d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 09:58:40 +0100 Subject: Fixed a few compile-time and runtime warnings in ScoreboardSerializer. --- src/WorldStorage/ScoreboardSerializer.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp index a53971dc2..c65e13f98 100644 --- a/src/WorldStorage/ScoreboardSerializer.cpp +++ b/src/WorldStorage/ScoreboardSerializer.cpp @@ -31,16 +31,12 @@ cScoreboardSerializer::cScoreboardSerializer(const AString & a_WorldName, cScore bool cScoreboardSerializer::Load(void) { - cFile File; - if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmRead)) + AString Data = cFile::ReadWholeFile(FILE_IO_PREFIX + m_Path); + if (Data.empty()) { return false; } - AString Data; - File.ReadRestOfFile(Data); - File.Close(); - AString Uncompressed; int res = UncompressStringGZIP(Data.data(), Data.size(), Uncompressed); @@ -313,13 +309,13 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT) CurrLine = a_NBT.FindChildByName(Child, "AllowFriendlyFire"); if (CurrLine >= 0) { - AllowsFriendlyFire = a_NBT.GetInt(CurrLine); + AllowsFriendlyFire = (a_NBT.GetInt(CurrLine) != 0); } CurrLine = a_NBT.FindChildByName(Child, "SeeFriendlyInvisibles"); if (CurrLine >= 0) { - CanSeeFriendlyInvisible = a_NBT.GetInt(CurrLine); + CanSeeFriendlyInvisible = (a_NBT.GetInt(CurrLine) != 0); } cTeam * Team = m_ScoreBoard->RegisterTeam(Name, DisplayName, Prefix, Suffix); -- cgit v1.2.3 From e75f979e01b34fbd1a2993be9fd4aa7211da26cf Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 10:24:24 +0100 Subject: Fixed Win nightbuilds not producing PDBs. --- Install/Zip2008_PDBs.list | 8 +------- src/CMakeLists.txt | 7 +++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Install/Zip2008_PDBs.list b/Install/Zip2008_PDBs.list index b9c822c38..608b0185b 100644 --- a/Install/Zip2008_PDBs.list +++ b/Install/Zip2008_PDBs.list @@ -1,8 +1,2 @@ MCServer\*.pdb -VC2008\Release\*.pdb -VC2008\Release\JsonCpp\*.pdb -VC2008\Release\Lua\*.pdb -VC2008\Release\ToLua\*.pdb -VC2008\Release\webserver\*.pdb -VC2008\Release\zlib\*.pdb -src\Bindings.* \ No newline at end of file +src\Bindings\Bindings.* \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 51182d3bc..a8cc0530d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -134,6 +134,13 @@ else () "StackWalker.cpp LeakFinder.h" PROPERTIES COMPILE_FLAGS "/Yc\"Globals.h\"" ) list(APPEND SOURCE "Resources/MCServer.rc") + + # Make MSVC generate the PDB files even for the release build: + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG") + set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /DEBUG") endif() set(EXECUTABLE MCServer) -- cgit v1.2.3 From 17c949ea6900f01a31d951cc4228139f9a6334df Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 13:53:19 +0000 Subject: Removed unnecessary define --- CMakeLists.txt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a10db7d49..181b286e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,3 @@ - cmake_minimum_required (VERSION 2.6) # Without this, the MSVC variable isn't defined for MSVC builds ( http://www.cmake.org/pipermail/cmake/2011-November/047130.html ) @@ -92,12 +91,6 @@ else() endif() -# Under clang, we need to disable ASM support in CryptoPP: -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_definitions(-DCRYPTOPP_DISABLE_ASM) -endif() - - # Under Windows, we need Lua as DLL; on *nix we need it linked statically: if (WIN32) add_definitions(-DLUA_BUILD_AS_DLL) -- cgit v1.2.3 From d8014d1ed8dd2374f77d670a1368958c8a10541a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 18:51:15 +0100 Subject: ProtoProxy: Fixed connection on *nix. --- Tools/ProtoProxy/Connection.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index cd66e2dfd..b63935f38 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -243,7 +243,8 @@ void cConnection::Run(void) FD_ZERO(&ReadFDs); FD_SET(m_ServerSocket, &ReadFDs); FD_SET(m_ClientSocket, &ReadFDs); - int res = select(2, &ReadFDs, NULL, NULL, NULL); + SOCKET MaxSocket = std::max(m_ServerSocket, m_ClientSocket); + int res = select(MaxSocket + 1, &ReadFDs, NULL, NULL, NULL); if (res <= 0) { printf("select() failed: %d; aborting client", SocketError); -- cgit v1.2.3 From f39daabf7eb4f54bda0f6385aff75dd4f22f75ca Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 19:39:39 +0000 Subject: Added more minecart powered rail directions --- src/Entities/Minecart.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++--- src/ReferenceManager.cpp | 43 ------------------------------ src/ReferenceManager.h | 34 ------------------------ 3 files changed, 63 insertions(+), 80 deletions(-) delete mode 100644 src/ReferenceManager.cpp delete mode 100644 src/ReferenceManager.h diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 6477fb1ca..78ec017cd 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -474,7 +474,7 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) } break; } - case E_META_RAIL_ASCEND_XM: + case E_META_RAIL_ASCEND_XM: // ASCEND EAST { SetYaw(180); SetSpeedZ(0); @@ -483,16 +483,76 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) { if (GetSpeedX() <= MAX_SPEED) { - AddSpeedX(1); + AddSpeedX(AccelDecelSpeed); SetSpeedY(-GetSpeedX()); } } else { - AddSpeedX(-1); + AddSpeedX(AccelDecelNegSpeed); SetSpeedY(-GetSpeedX()); } break; + } + case E_META_RAIL_ASCEND_XP: // ASCEND WEST + { + SetYaw(180); + SetSpeedZ(0); + + if (GetSpeedX() > 0) + { + AddSpeedX(AccelDecelSpeed); + SetSpeedY(GetSpeedX()); + } + else + { + if (GetSpeedX() >= MAX_SPEED_NEGATIVE) + { + AddSpeedX(AccelDecelNegSpeed); + SetSpeedY(GetSpeedX()); + } + } + break; + } + case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH + { + SetYaw(270); + SetSpeedX(0); + + if (GetSpeedZ() >= 0) + { + if (GetSpeedZ() <= MAX_SPEED) + { + AddSpeedZ(AccelDecelSpeed); + SetSpeedY(-GetSpeedZ()); + } + } + else + { + AddSpeedZ(AccelDecelNegSpeed); + SetSpeedY(-GetSpeedZ()); + } + break; + } + case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH + { + SetYaw(270); + SetSpeedX(0); + + if (GetSpeedZ() > 0) + { + AddSpeedZ(AccelDecelSpeed); + SetSpeedY(GetSpeedZ()); + } + else + { + if (GetSpeedZ() >= MAX_SPEED_NEGATIVE) + { + AddSpeedZ(AccelDecelNegSpeed); + SetSpeedY(GetSpeedZ()); + } + } + break; } default: ASSERT(!"Unhandled powered rail metadata!"); break; } diff --git a/src/ReferenceManager.cpp b/src/ReferenceManager.cpp deleted file mode 100644 index 6a9ed0e43..000000000 --- a/src/ReferenceManager.cpp +++ /dev/null @@ -1,43 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ReferenceManager.h" -#include "Entities/Entity.h" - - - - - -cReferenceManager::cReferenceManager( ENUM_REFERENCE_MANAGER_TYPE a_Type ) - : m_Type( a_Type ) -{ -} - -cReferenceManager::~cReferenceManager() -{ - if( m_Type == RFMNGR_REFERENCERS ) - { - for( std::list< cEntity** >::iterator itr = m_References.begin(); itr != m_References.end(); ++itr ) - { - *(*itr) = 0; // Set referenced pointer to 0 - } - } - else - { - for( std::list< cEntity** >::iterator itr = m_References.begin(); itr != m_References.end(); ++itr ) - { - cEntity* Ptr = (*(*itr)); - if( Ptr ) Ptr->Dereference( *(*itr) ); - } - } -} - -void cReferenceManager::AddReference( cEntity*& a_EntityPtr ) -{ - m_References.push_back( &a_EntityPtr ); -} - -void cReferenceManager::Dereference( cEntity*& a_EntityPtr ) -{ - m_References.remove( &a_EntityPtr ); -} \ No newline at end of file diff --git a/src/ReferenceManager.h b/src/ReferenceManager.h deleted file mode 100644 index bcd451f72..000000000 --- a/src/ReferenceManager.h +++ /dev/null @@ -1,34 +0,0 @@ - -#pragma once - - - - - -class cEntity; - - - - - -class cReferenceManager -{ -public: - enum ENUM_REFERENCE_MANAGER_TYPE - { - RFMNGR_REFERENCERS, - RFMNGR_REFERENCES, - }; - cReferenceManager( ENUM_REFERENCE_MANAGER_TYPE a_Type ); - ~cReferenceManager(); - - void AddReference( cEntity*& a_EntityPtr ); - void Dereference( cEntity*& a_EntityPtr ); -private: - ENUM_REFERENCE_MANAGER_TYPE m_Type; - std::list< cEntity** > m_References; -}; - - - - -- cgit v1.2.3 From 2ce26574efa89a5709f121acdf289ad3366d3881 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 19:46:45 +0000 Subject: Removed unused ReferenceManager --- src/Entities/Entity.cpp | 36 ------------------------------------ src/Entities/Entity.h | 10 +--------- src/ReferenceManager.cpp | 43 ------------------------------------------- src/ReferenceManager.h | 34 ---------------------------------- 4 files changed, 1 insertion(+), 122 deletions(-) delete mode 100644 src/ReferenceManager.cpp delete mode 100644 src/ReferenceManager.h diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 09fb7052d..ae98a1e91 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -4,9 +4,7 @@ #include "../World.h" #include "../Server.h" #include "../Root.h" -#include "../Vector3d.h" #include "../Matrix4f.h" -#include "../ReferenceManager.h" #include "../ClientHandle.h" #include "../Chunk.h" #include "../Simulator/FluidSimulator.h" @@ -32,8 +30,6 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_MaxHealth(1) , m_AttachedTo(NULL) , m_Attachee(NULL) - , m_Referencers(new cReferenceManager(cReferenceManager::RFMNGR_REFERENCERS)) - , m_References(new cReferenceManager(cReferenceManager::RFMNGR_REFERENCES)) , m_bDirtyHead(true) , m_bDirtyOrientation(true) , m_bDirtyPosition(true) @@ -100,8 +96,6 @@ cEntity::~cEntity() LOGWARNING("ERROR: Entity deallocated without being destroyed"); ASSERT(!"Entity deallocated without being destroyed or unlinked"); } - delete m_Referencers; - delete m_References; } @@ -1430,33 +1424,3 @@ void cEntity::SetPosZ(double a_PosZ) - -////////////////////////////////////////////////////////////////////////// -// Reference stuffs -void cEntity::AddReference(cEntity * & a_EntityPtr) -{ - m_References->AddReference(a_EntityPtr); - a_EntityPtr->ReferencedBy(a_EntityPtr); -} - - - - - -void cEntity::ReferencedBy(cEntity * & a_EntityPtr) -{ - m_Referencers->AddReference(a_EntityPtr); -} - - - - - -void cEntity::Dereference(cEntity * & a_EntityPtr) -{ - m_Referencers->Dereference(a_EntityPtr); -} - - - - diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 91463bfd6..62dc42c3f 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -4,6 +4,7 @@ #include "../Item.h" #include "../Vector3d.h" #include "../Vector3f.h" +#include "../Vector3i.h" @@ -33,7 +34,6 @@ class cWorld; -class cReferenceManager; class cClientHandle; class cPlayer; class cChunk; @@ -373,9 +373,6 @@ protected: /// The entity which is attached to this entity (rider), NULL if none cEntity * m_Attachee; - cReferenceManager* m_Referencers; - cReferenceManager* m_References; - // Flags that signal that we haven't updated the clients with the latest. bool m_bDirtyHead; bool m_bDirtyOrientation; @@ -416,11 +413,6 @@ protected: void SetWorld(cWorld * a_World) { m_World = a_World; } - friend class cReferenceManager; - void AddReference( cEntity*& a_EntityPtr ); - void ReferencedBy( cEntity*& a_EntityPtr ); - void Dereference( cEntity*& a_EntityPtr ); - private: // Measured in degrees, [-180, +180) double m_HeadYaw; diff --git a/src/ReferenceManager.cpp b/src/ReferenceManager.cpp deleted file mode 100644 index 6a9ed0e43..000000000 --- a/src/ReferenceManager.cpp +++ /dev/null @@ -1,43 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ReferenceManager.h" -#include "Entities/Entity.h" - - - - - -cReferenceManager::cReferenceManager( ENUM_REFERENCE_MANAGER_TYPE a_Type ) - : m_Type( a_Type ) -{ -} - -cReferenceManager::~cReferenceManager() -{ - if( m_Type == RFMNGR_REFERENCERS ) - { - for( std::list< cEntity** >::iterator itr = m_References.begin(); itr != m_References.end(); ++itr ) - { - *(*itr) = 0; // Set referenced pointer to 0 - } - } - else - { - for( std::list< cEntity** >::iterator itr = m_References.begin(); itr != m_References.end(); ++itr ) - { - cEntity* Ptr = (*(*itr)); - if( Ptr ) Ptr->Dereference( *(*itr) ); - } - } -} - -void cReferenceManager::AddReference( cEntity*& a_EntityPtr ) -{ - m_References.push_back( &a_EntityPtr ); -} - -void cReferenceManager::Dereference( cEntity*& a_EntityPtr ) -{ - m_References.remove( &a_EntityPtr ); -} \ No newline at end of file diff --git a/src/ReferenceManager.h b/src/ReferenceManager.h deleted file mode 100644 index bcd451f72..000000000 --- a/src/ReferenceManager.h +++ /dev/null @@ -1,34 +0,0 @@ - -#pragma once - - - - - -class cEntity; - - - - - -class cReferenceManager -{ -public: - enum ENUM_REFERENCE_MANAGER_TYPE - { - RFMNGR_REFERENCERS, - RFMNGR_REFERENCES, - }; - cReferenceManager( ENUM_REFERENCE_MANAGER_TYPE a_Type ); - ~cReferenceManager(); - - void AddReference( cEntity*& a_EntityPtr ); - void Dereference( cEntity*& a_EntityPtr ); -private: - ENUM_REFERENCE_MANAGER_TYPE m_Type; - std::list< cEntity** > m_References; -}; - - - - -- cgit v1.2.3 From 3e675f8c38720cd6c483ee0f9733a9c060ded936 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 19:52:52 +0000 Subject: Implemented creeper abilities * Creepers now explode with a sound effect * Creepers drop a music disc on the unlikely event of being killed by a skeleton's arrow Inspired by @maniak89's PR #132. --- MCServer/monsters.ini | 2 +- src/Mobs/Creeper.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- src/Mobs/Creeper.h | 3 +++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/MCServer/monsters.ini b/MCServer/monsters.ini index 94454c355..a1b63423e 100644 --- a/MCServer/monsters.ini +++ b/MCServer/monsters.ini @@ -62,7 +62,7 @@ SightDistance=25.0 MaxHealth=12 [Creeper] -AttackRange=5.0 +AttackRange=3.0 AttackRate=1 AttackDamage=0.0 SightDistance=25.0 diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 4e11ae13e..ad8fe10a1 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -3,6 +3,7 @@ #include "Creeper.h" #include "../World.h" +#include "../Entities/ProjectileEntity.h" @@ -11,7 +12,8 @@ cCreeper::cCreeper(void) : super("Creeper", mtCreeper, "mob.creeper.say", "mob.creeper.say", 0.6, 1.8), m_bIsBlowing(false), - m_bIsCharged(false) + m_bIsCharged(false), + m_ExplodingTimer(0) { } @@ -19,11 +21,34 @@ cCreeper::cCreeper(void) : +void cCreeper::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + + if (!ReachedFinalDestination()) + { + m_ExplodingTimer = 0; + m_bIsBlowing = false; + m_World->BroadcastEntityMetadata(*this); + } +} + + + + + void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) { AddRandomDropItem(a_Drops, 0, 2, E_ITEM_GUNPOWDER); - // TODO Check if killed by a skeleton, then drop random music disk + if ((a_Killer != NULL) && (a_Killer->IsProjectile())) + { + if (((cMonster *)((cProjectileEntity *)a_Killer)->GetCreator())->GetMobType() == mtSkeleton) + { + // 12 music discs. TickRand starts from 0, so range = 11. Disk IDs start at 2256, so add that. There. + AddRandomDropItem(a_Drops, 1, 1, (short)m_World->GetTickRandomNumber(11) + 2256); + } + } } @@ -45,3 +70,23 @@ void cCreeper::DoTakeDamage(TakeDamageInfo & a_TDI) + +void cCreeper::Attack(float a_Dt) +{ + UNUSED(a_Dt); + + m_ExplodingTimer += 1; + + if (!m_bIsBlowing) + { + m_World->BroadcastSoundEffect("random.fuse", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 1.f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_bIsBlowing = true; + m_World->BroadcastEntityMetadata(*this); + } + + if (m_ExplodingTimer == 20) + { + m_World->DoExplosionAt((m_bIsCharged ? 5 : 3), GetPosX(), GetPosY(), GetPosZ(), false, esMonster, this); + Destroy(); + } +} \ No newline at end of file diff --git a/src/Mobs/Creeper.h b/src/Mobs/Creeper.h index c3d4edeae..0f71e5ad2 100644 --- a/src/Mobs/Creeper.h +++ b/src/Mobs/Creeper.h @@ -19,6 +19,8 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual void Attack(float a_Dt) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; bool IsBlowing(void) const {return m_bIsBlowing; } bool IsCharged(void) const {return m_bIsCharged; } @@ -26,6 +28,7 @@ public: private: bool m_bIsBlowing, m_bIsCharged; + int m_ExplodingTimer; } ; -- cgit v1.2.3 From 161a1c72745fcb9274483d75af5238a6b7740ba3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 19:54:13 +0000 Subject: Fixed mobs too close to player not ticking A condition would never be fulfilled. A number squared was compared to -1, but there is nothing that, multiplied by itself, gives -1. --- src/MobProximityCounter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MobProximityCounter.cpp b/src/MobProximityCounter.cpp index 583a71579..6c44ea458 100644 --- a/src/MobProximityCounter.cpp +++ b/src/MobProximityCounter.cpp @@ -59,7 +59,7 @@ cMobProximityCounter::sIterablePair cMobProximityCounter::getMobWithinThosesDist { if (toReturn.m_Begin == m_DistanceToMonster.end()) { - if (a_DistanceMin == -1 || itr->first > a_DistanceMin) + if ((a_DistanceMin == 1) || (itr->first > a_DistanceMin)) { toReturn.m_Begin = itr; // this is the first one with distance > a_DistanceMin; } @@ -67,7 +67,7 @@ cMobProximityCounter::sIterablePair cMobProximityCounter::getMobWithinThosesDist if (toReturn.m_Begin != m_DistanceToMonster.end()) { - if (a_DistanceMax != -1 && itr->first > a_DistanceMax) + if ((a_DistanceMax != 1) && (itr->first > a_DistanceMax)) { toReturn.m_End = itr; // this is just after the last one with distance < a_DistanceMax // Note : if we are not going through this, it's ok, toReturn.m_End will be end(); -- cgit v1.2.3 From 9c0e3615ce61dba0ae973b97807833bd6ddd5bda Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 19:57:32 +0000 Subject: Large reworking of mob code [SEE DESC] + Implemented better pathfinding - Removed lots of unused variables, functions, etc. * Changed some variable types * Other miscellaneous fixes, and also completes the previous PRs --- src/Mobs/AggressiveMonster.cpp | 65 ++++--- src/Mobs/AggressiveMonster.h | 5 +- src/Mobs/Monster.cpp | 400 ++++++++++++++++++++++++----------------- src/Mobs/Monster.h | 68 +++++-- src/Mobs/PassiveMonster.cpp | 16 +- src/Mobs/Wolf.cpp | 2 +- src/MonsterConfig.cpp | 20 +-- 7 files changed, 334 insertions(+), 242 deletions(-) diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index cc7e7da2b..a4b3eede1 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -4,7 +4,6 @@ #include "AggressiveMonster.h" #include "../World.h" -#include "../Vector3f.h" #include "../Entities/Player.h" #include "../MersenneTwister.h" @@ -13,8 +12,7 @@ cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) : - super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height), - m_ChaseTime(999999) + super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height) { m_EMPersonality = AGGRESSIVE; } @@ -27,32 +25,23 @@ cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eType a_Mob void cAggressiveMonster::InStateChasing(float a_Dt) { super::InStateChasing(a_Dt); - m_ChaseTime += a_Dt; + if (m_Target != NULL) { if (m_Target->IsPlayer()) { - cPlayer * Player = (cPlayer *) m_Target; - if (Player->IsGameModeCreative()) + if (((cPlayer *)m_Target)->IsGameModeCreative()) { m_EMState = IDLE; return; } } - Vector3f Pos = Vector3f( GetPosition() ); - Vector3f Their = Vector3f( m_Target->GetPosition() ); - if ((Their - Pos).Length() <= m_AttackRange) + if (((float)m_FinalDestination.x != (float)m_Target->GetPosX()) || ((float)m_FinalDestination.z != (float)m_Target->GetPosZ())) { - Attack(a_Dt); + MoveToPosition(m_Target->GetPosition()); } - MoveToPosition(Their + Vector3f(0, 0.65f, 0)); } - else if (m_ChaseTime > 5.f) - { - m_ChaseTime = 0; - m_EMState = IDLE; - } } @@ -62,7 +51,10 @@ void cAggressiveMonster::InStateChasing(float a_Dt) void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity) { super::EventSeePlayer(a_Entity); - m_EMState = CHASING; + if (!((cPlayer *)a_Entity)->IsGameModeCreative()) + { + m_EMState = CHASING; + } } @@ -73,25 +65,32 @@ void cAggressiveMonster::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - m_SeePlayerInterval += a_Dt; - - if (m_SeePlayerInterval > 1) + if (m_EMState == CHASING) + { + CheckEventLostPlayer(); + } + else { - int rem = m_World->GetTickRandomNumber(3) + 1; // Check most of the time but miss occasionally + CheckEventSeePlayer(); + } +} - m_SeePlayerInterval = 0.0; - if (rem >= 2) - { - if (m_EMState == CHASING) - { - CheckEventLostPlayer(); - } - else - { - CheckEventSeePlayer(); - } - } + + + + +void cAggressiveMonster::Attack(float a_Dt) +{ + super::Attack(a_Dt); + + if ((m_Target != NULL) && (m_AttackInterval > 3.0)) + { + // Setting this higher gives us more wiggle room for attackrate + m_AttackInterval = 0.0; + m_Target->TakeDamage(dtMobAttack, this, m_AttackDamage, 0); } } + + diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h index 5a0d93f3d..9cee4e7a7 100644 --- a/src/Mobs/AggressiveMonster.h +++ b/src/Mobs/AggressiveMonster.h @@ -13,16 +13,15 @@ class cAggressiveMonster : typedef cMonster super; public: + cAggressiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height); virtual void Tick (float a_Dt, cChunk & a_Chunk) override; virtual void InStateChasing(float a_Dt) override; virtual void EventSeePlayer(cEntity *) override; + virtual void Attack(float a_Dt) override; - -protected: - float m_ChaseTime; } ; diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 98b6c1d28..91ecf3b52 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -8,13 +8,9 @@ #include "../World.h" #include "../Entities/Player.h" #include "../Entities/ExpOrb.h" -#include "../Defines.h" #include "../MonsterConfig.h" #include "../MersenneTwister.h" -#include "../Vector3f.h" -#include "../Vector3i.h" -#include "../Vector3d.h" #include "../Tracer.h" #include "../Chunk.h" #include "../FastRandom.h" @@ -81,11 +77,9 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_bMovingToDestination(false) , m_DestinationTime( 0 ) , m_DestroyTimer( 0 ) - , m_Jump(0) , m_MobType(a_MobType) , m_SoundHurt(a_SoundHurt) , m_SoundDeath(a_SoundDeath) - , m_SeePlayerInterval (0) , m_AttackDamage(1.0f) , m_AttackRange(2.0f) , m_AttackInterval(0) @@ -110,11 +104,105 @@ void cMonster::SpawnOn(cClientHandle & a_Client) -void cMonster::MoveToPosition( const Vector3f & a_Position ) +void cMonster::TickPathFinding() { + int PosX = (int)floor(GetPosX()); + int PosY = (int)floor(GetPosY()); + int PosZ = (int)floor(GetPosZ()); + + m_FinalDestination.y = (double)FindFirstNonAirBlockPosition(m_FinalDestination.x, m_FinalDestination.z); + + std::vector m_PotentialCoordinates; + m_TraversedCoordinates.push_back(Vector3i(PosX, PosY, PosZ)); + + static const struct // Define which directions the torch can power + { + int x, z; + } gCrossCoords[] = + { + { 1, 0}, + {-1, 0}, + { 0, 1}, + { 0,-1}, + } ; + + for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) + { + if ((gCrossCoords[i].x + PosX == PosX) && (gCrossCoords[i].z + PosZ == PosZ)) + { + continue; + } + + if (IsCoordinateInTraversedList(Vector3i(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ))) + { + continue; + } + + BLOCKTYPE BlockAtY = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ); + BLOCKTYPE BlockAtYP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 1, gCrossCoords[i].z + PosZ); + BLOCKTYPE BlockAtYPP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 2, gCrossCoords[i].z + PosZ); + BLOCKTYPE BlockAtYM = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY - 1, gCrossCoords[i].z + PosZ); + + if (!g_BlockIsSolid[BlockAtY] && !g_BlockIsSolid[BlockAtYP] && !IsBlockLava(BlockAtYM)) + { + m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY, gCrossCoords[i].z + PosZ)); + } + else if (g_BlockIsSolid[BlockAtY] && !g_BlockIsSolid[BlockAtYP] && !g_BlockIsSolid[BlockAtYPP] && !IsBlockLava(BlockAtYM)) + { + m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY + 1, gCrossCoords[i].z + PosZ)); + } + } + + if (!m_PotentialCoordinates.empty()) + { + Vector3f ShortestCoords = m_PotentialCoordinates.front(); + for (std::vector::const_iterator itr = m_PotentialCoordinates.begin(); itr != m_PotentialCoordinates.end(); ++itr) + { + Vector3f Distance = m_FinalDestination - ShortestCoords; + Vector3f Distance2 = m_FinalDestination - *itr; + if (Distance.SqrLength() > Distance2.SqrLength()) + { + ShortestCoords = *itr; + } + } + + m_Destination = ShortestCoords; + m_Destination.z += 0.5f; + m_Destination.x += 0.5f; + } + else + { + FinishPathFinding(); + } +} + + + + + +void cMonster::MoveToPosition(const Vector3f & a_Position) +{ + FinishPathFinding(); + + m_FinalDestination = a_Position; m_bMovingToDestination = true; + TickPathFinding(); +} + + + + +bool cMonster::IsCoordinateInTraversedList(Vector3i a_Coords) +{ + for (std::vector::const_iterator itr = m_TraversedCoordinates.begin(); itr != m_TraversedCoordinates.end(); ++itr) + { + if (itr->Equals(a_Coords)) + { + return true; + } + } - m_Destination = a_Position; + return false; } @@ -123,10 +211,24 @@ void cMonster::MoveToPosition( const Vector3f & a_Position ) bool cMonster::ReachedDestination() { - Vector3f Distance = (m_Destination) - GetPosition(); - if( Distance.SqrLength() < 2.f ) + if ((m_Destination - GetPosition()).Length() < 0.5f) + { return true; + } + + return false; +} + + + +bool cMonster::ReachedFinalDestination() +{ + if ((GetPosition() - m_FinalDestination).Length() <= m_AttackRange) + { + return true; + } + return false; } @@ -151,23 +253,19 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) // Burning in daylight HandleDaylightBurning(a_Chunk); - - HandlePhysics(a_Dt,a_Chunk); - BroadcastMovementUpdate(); a_Dt /= 1000; if (m_bMovingToDestination) { - Vector3f Pos( GetPosition() ); - Vector3f Distance = m_Destination - Pos; - if( !ReachedDestination() ) + Vector3f Distance = m_Destination - GetPosition(); + if(!ReachedDestination() && !ReachedFinalDestination()) // If we haven't reached any sort of destination, move { Distance.y = 0; Distance.Normalize(); Distance *= 3; - SetSpeedX( Distance.x ); - SetSpeedZ( Distance.z ); + SetSpeedX(Distance.x); + SetSpeedZ(Distance.z); if (m_EMState == ESCAPING) { //Runs Faster when escaping :D otherwise they just walk away @@ -177,40 +275,32 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) } else { - m_bMovingToDestination = false; + if (ReachedFinalDestination()) // If we have reached the ultimate, final destination, stop pathfinding and attack if appropriate + { + FinishPathFinding(); + } + else + { + TickPathFinding(); // We have reached the next point in our path, calculate another point + } } - if( GetSpeed().SqrLength() > 0.f ) + if(m_bOnGround) { - if( m_bOnGround ) + int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z); + + if (IsNextYPosReachable(NextHeight)) { - Vector3f NormSpeed = Vector3f(GetSpeed()).NormalizeCopy(); - Vector3f NextBlock = Vector3f( GetPosition() ) + NormSpeed; - int NextHeight; - if (!m_World->TryGetHeight((int)NextBlock.x, (int)NextBlock.z, NextHeight)) - { - // The chunk at NextBlock is not loaded - return; - } - if( NextHeight > (GetPosY() - 1.0) && (NextHeight - GetPosY()) < 2.5 ) - { - m_bOnGround = false; - SetSpeedY(5.f); // Jump!! - } + m_bOnGround = false; + SetSpeedY(5.f); // Jump!! } } } - Vector3d Distance = m_Destination - GetPosition(); - if (Distance.SqrLength() > 0.1f) - { - double Rotation, Pitch; - Distance.Normalize(); - VectorToEuler( Distance.x, Distance.y, Distance.z, Rotation, Pitch ); - SetHeadYaw (Rotation); - SetYaw( Rotation ); - SetPitch( -Pitch ); - } + if (ReachedFinalDestination()) + Attack(a_Dt); + + SetPitchAndYawFromDestination(); switch (m_EMState) { @@ -219,21 +309,87 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) // If enemy passive we ignore checks for player visibility InStateIdle(a_Dt); break; - } - + } case CHASING: { // If we do not see a player anymore skip chasing action InStateChasing(a_Dt); break; - } - + } case ESCAPING: { InStateEscaping(a_Dt); break; } } // switch (m_EMState) + + BroadcastMovementUpdate(); +} + + + + +void cMonster::SetPitchAndYawFromDestination() +{ + Vector3d FinalDestination = m_FinalDestination; + if (m_Target != NULL) + { + if (m_Target->IsPlayer()) + { + FinalDestination.y = ((cPlayer *)m_Target)->GetStance(); + } + else + { + FinalDestination.y = GetHeight(); + } + } + + Vector3d Distance = FinalDestination - GetPosition(); + if (Distance.SqrLength() > 0.1f) + { + { + double Rotation, Pitch; + Distance.Normalize(); + VectorToEuler(Distance.x, Distance.y, Distance.z, Rotation, Pitch); + SetHeadYaw(Rotation); + SetPitch(-Pitch); + } + + { + Vector3d BodyDistance = m_Destination - GetPosition(); + double Rotation, Pitch; + Distance.Normalize(); + VectorToEuler(BodyDistance.x, BodyDistance.y, BodyDistance.z, Rotation, Pitch); + SetYaw(Rotation); + } + } +} + + + + +int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) +{ + int PosY = (int)floor(GetPosY()); + + if (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))]) + { + while (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY > 0)) + { + PosY--; + } + + return PosY + 1; + } + else + { + while (g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY < cChunkDef::Height)) + { + PosY++; + } + + return PosY; + } } @@ -244,11 +400,13 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) void cMonster::DoTakeDamage(TakeDamageInfo & a_TDI) { super::DoTakeDamage(a_TDI); - if((m_SoundHurt != "") && (m_Health > 0)) m_World->BroadcastSoundEffect(m_SoundHurt, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f); + + if((m_SoundHurt != "") && (m_Health > 0)) + m_World->BroadcastSoundEffect(m_SoundHurt, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f); + if (a_TDI.Attacker != NULL) { m_Target = a_TDI.Attacker; - AddReference(m_Target); } } @@ -330,55 +488,12 @@ void cMonster::KilledBy(cEntity * a_Killer) -//----State Logic - -const char *cMonster::GetState() -{ - switch(m_EMState) - { - case IDLE: return "Idle"; - case ATTACKING: return "Attacking"; - case CHASING: return "Chasing"; - default: return "Unknown"; - } -} - - - - - -// for debugging -void cMonster::SetState(const AString & a_State) -{ - if (a_State.compare("Idle") == 0) - { - m_EMState = IDLE; - } - else if (a_State.compare("Attacking") == 0) - { - m_EMState = ATTACKING; - } - else if (a_State.compare("Chasing") == 0) - { - m_EMState = CHASING; - } - else - { - LOGD("cMonster::SetState(): Invalid state"); - ASSERT(!"Invalid state"); - } -} - - - - - //Checks to see if EventSeePlayer should be fired //monster sez: Do I see the player void cMonster::CheckEventSeePlayer(void) { // TODO: Rewrite this to use cWorld's DoWithPlayers() - cPlayer * Closest = FindClosestPlayer(); + cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), m_SightDistance); if (Closest != NULL) { @@ -398,7 +513,10 @@ void cMonster::CheckEventLostPlayer(void) if (m_Target != NULL) { pos = m_Target->GetPosition(); - if ((pos - GetPosition()).Length() > m_SightDistance || LineOfSight.Trace(GetPosition(),(pos - GetPosition()), (int)(pos - GetPosition()).Length())) + if ( + ((pos - GetPosition()).Length() > m_SightDistance) || + LineOfSight.Trace(Vector3d(GetPosX(), GetPosY() + 1, GetPosZ()), (pos - GetPosition()), (int)(pos - GetPosition()).Length()) + ) { EventLosePlayer(); } @@ -418,7 +536,6 @@ void cMonster::CheckEventLostPlayer(void) void cMonster::EventSeePlayer(cEntity * a_SeenPlayer) { m_Target = a_SeenPlayer; - AddReference(m_Target); } @@ -427,7 +544,6 @@ void cMonster::EventSeePlayer(cEntity * a_SeenPlayer) void cMonster::EventLosePlayer(void) { - Dereference(m_Target); m_Target = NULL; m_EMState = IDLE; } @@ -436,27 +552,30 @@ void cMonster::EventLosePlayer(void) -// What to do if in Idle State void cMonster::InStateIdle(float a_Dt) { m_IdleInterval += a_Dt; + if (m_IdleInterval > 1) { - // at this interval the results are predictable + // At this interval the results are predictable int rem = m_World->GetTickRandomNumber(6) + 1; - // LOGD("Moving: int: %3.3f rem: %i",idle_interval,rem); - m_IdleInterval -= 1; // So nothing gets dropped when the server hangs for a few seconds - Vector3f Dist; - Dist.x = (float)(m_World->GetTickRandomNumber(10) - 5); - Dist.z = (float)(m_World->GetTickRandomNumber(10) - 5); + m_IdleInterval -= 1; // So nothing gets dropped when the server hangs for a few seconds + + Vector3d Dist; + Dist.x = (double)m_World->GetTickRandomNumber(m_SightDistance * 2) - m_SightDistance; + Dist.z = (double)m_World->GetTickRandomNumber(m_SightDistance * 2) - m_SightDistance; + if ((Dist.SqrLength() > 2) && (rem >= 3)) { - m_Destination.x = (float)(GetPosX() + Dist.x); - m_Destination.z = (float)(GetPosZ() + Dist.z); - int PosY; - if (m_World->TryGetHeight((int)m_Destination.x, (int)m_Destination.z, PosY)) + m_Destination.x = GetPosX() + Dist.x; + m_Destination.z = GetPosZ() + Dist.z; + + int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z); + + if (IsNextYPosReachable(NextHeight + 1)) { - m_Destination.y = (float)PosY + 1.2f; + m_Destination.y = (double)NextHeight; MoveToPosition(m_Destination); } } @@ -505,22 +624,6 @@ void cMonster::InStateEscaping(float a_Dt) void cMonster::Attack(float a_Dt) { m_AttackInterval += a_Dt * m_AttackRate; - if ((m_Target != NULL) && (m_AttackInterval > 3.0)) - { - // Setting this higher gives us more wiggle room for attackrate - m_AttackInterval = 0.0; - ((cPawn *)m_Target)->TakeDamage(*this); - } -} - - - - - -// Checks for Players close by and if they are visible return the closest -cPlayer * cMonster::FindClosestPlayer(void) -{ - return m_World->FindClosestPlayer(GetPosition(), m_SightDistance); } @@ -536,42 +639,6 @@ void cMonster::GetMonsterConfig(const AString & a_Name) -void cMonster::SetAttackRate(int ar) -{ - m_AttackRate = (float)ar; -} - - - - - -void cMonster::SetAttackRange(float ar) -{ - m_AttackRange = ar; -} - - - - - -void cMonster::SetAttackDamage(float ad) -{ - m_AttackDamage = ad; -} - - - - - -void cMonster::SetSightDistance(float sd) -{ - m_SightDistance = sd; -} - - - - - AString cMonster::MobTypeToString(cMonster::eType a_MobType) { // Mob types aren't sorted, so we need to search linearly: @@ -635,6 +702,8 @@ cMonster::eType cMonster::StringToMobType(const AString & a_Name) cMonster::eFamily cMonster::FamilyFromType(eType a_Type) { + // Passive-agressive mobs are counted in mob spawning code as passive + switch (a_Type) { case mtBat: return mfAmbient; @@ -699,7 +768,7 @@ cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType) case mtMagmaCube: case mtSlime: { - toReturn = new cSlime (Random.NextInt(2) + 1); + toReturn = new cSlime(Random.NextInt(2) + 1); break; } case mtSkeleton: @@ -803,6 +872,13 @@ void cMonster::HandleDaylightBurning(cChunk & a_Chunk) int RelX = (int)floor(GetPosX()) - GetChunkX() * cChunkDef::Width; int RelZ = (int)floor(GetPosZ()) - GetChunkZ() * cChunkDef::Width; + + if (!a_Chunk.IsLightValid()) + { + m_World->QueueLightChunk(GetChunkX(), GetChunkZ()); + return; + } + if ( (a_Chunk.GetSkyLight(RelX, RelY, RelZ) == 15) && // In the daylight (a_Chunk.GetBlock(RelX, RelY, RelZ) != E_BLOCK_SOULSAND) && // Not on soulsand diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index dafb33574..5f32650cf 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -10,7 +10,6 @@ -class Vector3f; class cClientHandle; class cWorld; @@ -74,8 +73,6 @@ public: enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState; enum MPersonality{PASSIVE,AGGRESSIVE,COWARDLY} m_EMPersonality; - float m_SightDistance; - /** Creates the mob object. * If a_ConfigName is not empty, the configuration is loaded using GetMonsterConfig() * a_MobType is the type of the mob (also used in the protocol ( http://wiki.vg/Entities#Mobs , 2012_12_22)) @@ -100,14 +97,9 @@ public: eType GetMobType(void) const {return m_MobType; } eFamily GetMobFamily(void) const; // tolua_end - - - const char * GetState(); - void SetState(const AString & str); virtual void CheckEventSeePlayer(void); virtual void EventSeePlayer(cEntity * a_Player); - virtual cPlayer * FindClosestPlayer(); // non static is easier. also virtual so other mobs can implement their own searching algo /// Reads the monster configuration for the specified monster name and assigns it to this object. void GetMonsterConfig(const AString & a_Name); @@ -121,11 +113,11 @@ public: virtual void Attack(float a_Dt); - int GetAttackRate(){return (int)m_AttackRate;} - void SetAttackRate(int ar); - void SetAttackRange(float ar); - void SetAttackDamage(float ad); - void SetSightDistance(float sd); + int GetAttackRate() { return (int)m_AttackRate; } + void SetAttackRate(float a_AttackRate) { m_AttackRate = a_AttackRate; } + void SetAttackRange(int a_AttackRange) { m_AttackRange = a_AttackRange; } + void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; } + void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; } /// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; } @@ -159,34 +151,72 @@ public: protected: + /* ======= PATHFINDING ======= */ + + /** A pointer to the entity this mobile is aiming to reach */ cEntity * m_Target; + /** Coordinates of the next position that should be reached */ + Vector3d m_Destination; + /** Coordinates for the ultimate, final destination. */ + Vector3d m_FinalDestination; + /** Returns if the ultimate, final destination has been reached */ + bool ReachedFinalDestination(void); + + /** Stores if mobile is currently moving towards the ultimate, final destination */ + bool m_bMovingToDestination; + /** Finds the first non-air block position (not the highest, as cWorld::GetHeight does) + If current Y is nonsolid, goes down to try to find a solid block, then returns that + 1 + If current Y is solid, goes up to find first nonsolid block, and returns that */ + int FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ); + + /** A semi-temporary list to store the traversed coordinates during active pathfinding so we don't visit them again */ + std::vector m_TraversedCoordinates; + /** Returns if coordinate is in the traversed list */ + bool IsCoordinateInTraversedList(Vector3i a_Coords); + + /** Finds the next place to go + This is based on the ultimate, final destination and the current position, as well as the traversed coordinates, and any environmental hazards */ + void TickPathFinding(void); + /** Finishes a pathfinding task, be it due to failure or something else */ + inline void FinishPathFinding(void) + { + m_TraversedCoordinates.clear(); + m_bMovingToDestination = false; + } + /** Sets the body yaw and head yaw/pitch based on next/ultimate destinations */ + void SetPitchAndYawFromDestination(void); + + /* ===========================*/ + float m_AttackRate; float m_IdleInterval; - Vector3f m_Destination; - bool m_bMovingToDestination; + bool m_bPassiveAggressive; float m_DestinationTime; float m_DestroyTimer; - float m_Jump; eType m_MobType; AString m_SoundHurt; AString m_SoundDeath; - float m_SeePlayerInterval; - float m_AttackDamage; - float m_AttackRange; + int m_AttackDamage; + int m_AttackRange; float m_AttackInterval; + int m_SightDistance; bool m_BurnsInDaylight; void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); void HandleDaylightBurning(cChunk & a_Chunk); + inline bool IsNextYPosReachable(int a_PosY) + { + return (a_PosY > (int)floor(GetPosY())) && (a_PosY == (int)floor(GetPosY()) + 1); + } } ; // tolua_export diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp index 91ceb5a53..d774d3170 100644 --- a/src/Mobs/PassiveMonster.cpp +++ b/src/Mobs/PassiveMonster.cpp @@ -2,7 +2,6 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "PassiveMonster.h" -#include "../MersenneTwister.h" #include "../World.h" @@ -36,20 +35,9 @@ void cPassiveMonster::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - m_SeePlayerInterval += a_Dt; - - if (m_SeePlayerInterval > 1) // Check every second + if (m_EMState == ESCAPING) { - int rem = m_World->GetTickRandomNumber(3) + 1; // Check most of the time but miss occasionally - - m_SeePlayerInterval = 0.0; - if (rem >= 2) - { - if (m_EMState == ESCAPING) - { - CheckEventLostPlayer(); - } - } + CheckEventLostPlayer(); } } diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 3d4e97c80..483f1d193 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -108,7 +108,7 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) m_bMovingToDestination = false; } - cPlayer * a_Closest_Player = FindClosestPlayer(); + cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), m_SightDistance); if (a_Closest_Player != NULL) { switch (a_Closest_Player->GetEquippedItem().m_ItemType) diff --git a/src/MonsterConfig.cpp b/src/MonsterConfig.cpp index 6165606f0..c06bd6b6f 100644 --- a/src/MonsterConfig.cpp +++ b/src/MonsterConfig.cpp @@ -12,9 +12,9 @@ struct cMonsterConfig::sAttributesStruct { AString m_Name; - double m_SightDistance; - double m_AttackDamage; - double m_AttackRange; + int m_SightDistance; + int m_AttackDamage; + int m_AttackRange; double m_AttackRate; int m_MaxHealth; }; @@ -67,9 +67,9 @@ void cMonsterConfig::Initialize() sAttributesStruct Attributes; AString Name = MonstersIniFile.GetKeyName(i); Attributes.m_Name = Name; - Attributes.m_AttackDamage = MonstersIniFile.GetValueF(Name, "AttackDamage", 0); - Attributes.m_AttackRange = MonstersIniFile.GetValueF(Name, "AttackRange", 0); - Attributes.m_SightDistance = MonstersIniFile.GetValueF(Name, "SightDistance", 0); + Attributes.m_AttackDamage = MonstersIniFile.GetValueI(Name, "AttackDamage", 0); + Attributes.m_AttackRange = MonstersIniFile.GetValueI(Name, "AttackRange", 0); + Attributes.m_SightDistance = MonstersIniFile.GetValueI(Name, "SightDistance", 0); Attributes.m_AttackRate = MonstersIniFile.GetValueF(Name, "AttackRate", 0); Attributes.m_MaxHealth = MonstersIniFile.GetValueI(Name, "MaxHealth", 1); m_pState->AttributesList.push_front(Attributes); @@ -87,10 +87,10 @@ void cMonsterConfig::AssignAttributes(cMonster * a_Monster, const AString & a_Na { if (itr->m_Name.compare(a_Name) == 0) { - a_Monster->SetAttackDamage ((float)itr->m_AttackDamage); - a_Monster->SetAttackRange ((float)itr->m_AttackRange); - a_Monster->SetSightDistance((float)itr->m_SightDistance); - a_Monster->SetAttackRate ((int)itr->m_AttackRate); + a_Monster->SetAttackDamage (itr->m_AttackDamage); + a_Monster->SetAttackRange (itr->m_AttackRange); + a_Monster->SetSightDistance(itr->m_SightDistance); + a_Monster->SetAttackRate ((float)itr->m_AttackRate); a_Monster->SetMaxHealth (itr->m_MaxHealth); return; } -- cgit v1.2.3 From 4eb52b25db3dfa8a2d4574243e829480dcad6e38 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 19:58:37 +0000 Subject: Updated Core --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 759cf48ba..5fe3662a8 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 759cf48ba3f1409e6d7b60cb821ee17e589bdef8 +Subproject commit 5fe3662a8719f79cb2ca0a16150c716a3c5eb19c -- cgit v1.2.3 From 1f82b6e1920d0f56cad0f7a04c81cb0cf9823a1d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 20:46:22 +0000 Subject: Monsters no longer check for direct line of sight --- src/Mobs/Monster.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 91ecf3b52..bd7894bf9 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -11,7 +11,6 @@ #include "../MonsterConfig.h" #include "../MersenneTwister.h" -#include "../Tracer.h" #include "../Chunk.h" #include "../FastRandom.h" @@ -506,17 +505,10 @@ void cMonster::CheckEventSeePlayer(void) void cMonster::CheckEventLostPlayer(void) -{ - Vector3f pos; - cTracer LineOfSight(GetWorld()); - +{ if (m_Target != NULL) { - pos = m_Target->GetPosition(); - if ( - ((pos - GetPosition()).Length() > m_SightDistance) || - LineOfSight.Trace(Vector3d(GetPosX(), GetPosY() + 1, GetPosZ()), (pos - GetPosition()), (int)(pos - GetPosition()).Length()) - ) + if ((m_Target->GetPosition() - GetPosition()).Length() > m_SightDistance) { EventLosePlayer(); } -- cgit v1.2.3 From 0583b9df391d3b7c8a7ff4f982c4d2e28c42fa36 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 20:46:47 +0000 Subject: Made wolves compatible with new AI code --- src/Mobs/Wolf.cpp | 36 +++++++++++++++++++++++++----------- src/Mobs/Wolf.h | 1 + 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 483f1d193..11e3f690a 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -37,6 +37,26 @@ void cWolf::DoTakeDamage(TakeDamageInfo & a_TDI) +void cWolf::Attack(float a_Dt) +{ + UNUSED(a_Dt); + + if ((m_Target != NULL) && (m_Target->IsPlayer())) + { + if (((cPlayer *)m_Target)->GetName() != m_OwnerName) + { + super::Attack(a_Dt); + } + } + else + { + super::Attack(a_Dt); + } +} + + + + void cWolf::OnRightClicked(cPlayer & a_Player) { @@ -108,7 +128,7 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) m_bMovingToDestination = false; } - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), m_SightDistance); + cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); if (a_Closest_Player != NULL) { switch (a_Closest_Player->GetEquippedItem().m_ItemType) @@ -125,9 +145,7 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) SetIsBegging(true); m_World->BroadcastEntityMetadata(*this); } - Vector3f a_NewDestination = a_Closest_Player->GetPosition(); - a_NewDestination.y = a_NewDestination.y + 1; // Look at the head of the player, not his feet. - m_Destination = Vector3f(a_NewDestination); + m_FinalDestination = a_Closest_Player->GetPosition();; m_bMovingToDestination = false; break; } @@ -163,23 +181,19 @@ void cWolf::TickFollowPlayer() return false; } public: - Vector3f OwnerPos; + Vector3d OwnerPos; } Callback; if (m_World->DoWithPlayer(m_OwnerName, Callback)) { // The player is present in the world, follow them: double Distance = (Callback.OwnerPos - GetPosition()).Length(); - if (Distance < 3) - { - m_bMovingToDestination = false; - } - else if ((Distance > 30) && (!IsSitting())) + if ((Distance > 30) && (!IsSitting())) { TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z); } else { - m_Destination = Callback.OwnerPos; + MoveToPosition(Callback.OwnerPos); } } } diff --git a/src/Mobs/Wolf.h b/src/Mobs/Wolf.h index 040e2cf7a..9e5ad03c7 100644 --- a/src/Mobs/Wolf.h +++ b/src/Mobs/Wolf.h @@ -22,6 +22,7 @@ public: virtual void OnRightClicked(cPlayer & a_Player) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void TickFollowPlayer(); + virtual void Attack(float a_Dt) override; // Get functions bool IsSitting (void) const { return m_IsSitting; } -- cgit v1.2.3 From f0a75f7f73effcaccc6dcb73c42fd8c9f4492dcd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 19:22:10 +0100 Subject: Fixed a failure in cSquid. Probably due to rounding errors the squid was querying out-of-chunk coords. --- src/Mobs/Squid.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index a311108ae..5a27762ff 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -43,7 +43,8 @@ void cSquid::Tick(float a_Dt, cChunk & a_Chunk) } int RelX = (int)floor(Pos.x) - a_Chunk.GetPosX() * cChunkDef::Width; int RelZ = (int)floor(Pos.z) - a_Chunk.GetPosZ() * cChunkDef::Width; - if (!IsBlockWater(a_Chunk.GetBlock(RelX, RelY, RelZ)) && !IsOnFire()) + BLOCKTYPE BlockType; + if (a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockType) && !IsBlockWater(BlockType) && !IsOnFire()) { // Burn for 10 ticks, then decide again StartBurning(10); -- cgit v1.2.3 From 6c1d992eeba5c300da1a2b7a50fbda52b3774ff4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 22:23:33 +0100 Subject: Fixed a possible deadlock on client disconnect. --- src/ClientHandle.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 18e3d560e..56ad4e4ba 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -148,15 +148,6 @@ cClientHandle::~cClientHandle() SendDisconnect("Server shut down? Kthnxbai"); } - // Queue all remaining outgoing packets to cSocketThreads: - { - cCSLock Lock(m_CSOutgoingData); - AString Data; - m_OutgoingData.ReadAll(Data); - m_OutgoingData.CommitRead(); - cRoot::Get()->GetServer()->WriteToClient(this, Data); - } - // Close the socket as soon as it sends all outgoing data: cRoot::Get()->GetServer()->RemoveClient(this); -- cgit v1.2.3 From bf2af73899ba678e1280aded70703a5d105d295d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 21:54:20 +0000 Subject: Changed a condition to IsGameMode --- src/Mobs/PassiveAggressiveMonster.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Mobs/PassiveAggressiveMonster.cpp b/src/Mobs/PassiveAggressiveMonster.cpp index 28de65905..4b45f9a2a 100644 --- a/src/Mobs/PassiveAggressiveMonster.cpp +++ b/src/Mobs/PassiveAggressiveMonster.cpp @@ -25,8 +25,7 @@ void cPassiveAggressiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI) if ((m_Target != NULL) && (m_Target->IsPlayer())) { - cPlayer * Player = (cPlayer *) m_Target; - if (Player->GetGameMode() != 1) + if (!((cPlayer *)m_Target)->IsGameModeCreative()) { m_EMState = CHASING; } -- cgit v1.2.3 From a988063915aa288bf0183509783987941574e2ae Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 21:55:04 +0000 Subject: Miscellaneous improvements --- src/Entities/Pickup.cpp | 14 ++++---------- src/Mobs/Monster.cpp | 9 ++++----- src/Mobs/Monster.h | 22 +++++++++------------- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index 001e386a7..55c878b57 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -6,30 +6,24 @@ #endif #include "Pickup.h" +#include "Player.h" #include "../ClientHandle.h" -#include "../Inventory.h" #include "../World.h" -#include "../Simulator/FluidSimulator.h" #include "../Server.h" -#include "Player.h" #include "../Bindings/PluginManager.h" -#include "../Item.h" #include "../Root.h" #include "../Chunk.h" -#include "../Vector3d.h" -#include "../Vector3f.h" - cPickup::cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) : cEntity(etPickup, a_PosX, a_PosY, a_PosZ, 0.2, 0.2) - , m_Timer( 0.f ) + , m_Timer(0.f) , m_Item(a_Item) - , m_bCollected( false ) - , m_bIsPlayerCreated( IsPlayerCreated ) + , m_bCollected(false) + , m_bIsPlayerCreated(IsPlayerCreated) { SetGravity(-10.5f); SetMaxHealth(5); diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index bd7894bf9..3b453552b 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -74,13 +74,12 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_AttackRate(3) , m_IdleInterval(0) , m_bMovingToDestination(false) - , m_DestinationTime( 0 ) - , m_DestroyTimer( 0 ) + , m_DestroyTimer(0) , m_MobType(a_MobType) , m_SoundHurt(a_SoundHurt) , m_SoundDeath(a_SoundDeath) - , m_AttackDamage(1.0f) - , m_AttackRange(2.0f) + , m_AttackDamage(1) + , m_AttackRange(2) , m_AttackInterval(0) , m_BurnsInDaylight(false) { @@ -492,7 +491,7 @@ void cMonster::KilledBy(cEntity * a_Killer) void cMonster::CheckEventSeePlayer(void) { // TODO: Rewrite this to use cWorld's DoWithPlayers() - cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), m_SightDistance); + cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); if (Closest != NULL) { diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 5f32650cf..c8129e63d 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -168,6 +168,11 @@ protected: If current Y is nonsolid, goes down to try to find a solid block, then returns that + 1 If current Y is solid, goes up to find first nonsolid block, and returns that */ int FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ); + /** Returns if a monster can actually reach a given height by jumping */ + inline bool IsNextYPosReachable(int a_PosY) + { + return (a_PosY > (int)floor(GetPosY())) && (a_PosY == (int)floor(GetPosY()) + 1); + } /** A semi-temporary list to store the traversed coordinates during active pathfinding so we don't visit them again */ std::vector m_TraversedCoordinates; @@ -188,14 +193,9 @@ protected: /* ===========================*/ - float m_AttackRate; - float m_IdleInterval; - - bool m_bPassiveAggressive; - - float m_DestinationTime; + float m_IdleInterval; float m_DestroyTimer; eType m_MobType; @@ -203,20 +203,16 @@ protected: AString m_SoundHurt; AString m_SoundDeath; + float m_AttackRate; int m_AttackDamage; int m_AttackRange; float m_AttackInterval; int m_SightDistance; + void HandleDaylightBurning(cChunk & a_Chunk); bool m_BurnsInDaylight; - void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); - - void HandleDaylightBurning(cChunk & a_Chunk); - inline bool IsNextYPosReachable(int a_PosY) - { - return (a_PosY > (int)floor(GetPosY())) && (a_PosY == (int)floor(GetPosY()) + 1); - } + void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); } ; // tolua_export -- cgit v1.2.3 From d0da5d392f64c63fefde352a2a0b569317ca59cc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 23:03:48 +0100 Subject: Added per-connection comm logging in debug mode. It is meant for debugging only, so it is compiled only into debug mode. It is activated by starting the server with "/logcomm" parameter. --- src/Protocol/Protocol17x.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++ src/Protocol/Protocol17x.h | 5 ++++ src/main.cpp | 25 ++++++++++++++++- 3 files changed, 93 insertions(+), 1 deletion(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 9506332dc..d2d0df7f7 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -53,6 +53,18 @@ Implements the 1.7.x protocol classes: +#ifdef _DEBUG +// fwd: main.cpp: +extern bool g_ShouldLogComm; +#endif + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cProtocol172: + cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : super(a_Client), m_ServerAddress(a_ServerAddress), @@ -63,6 +75,15 @@ cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAdd m_OutPacketLenBuffer(20), // 20 bytes is more than enough for one VarInt m_IsEncrypted(false) { + // Create the comm log file, if so requested: + #ifdef _DEBUG + if (g_ShouldLogComm) + { + cFile::CreateFolder("CommLogs"); + AString FileName = Printf("CommLogs/%x__%s.log", (unsigned)time(NULL), a_Client->GetIPString().c_str()); + m_CommLogFile.Open(FileName, cFile::fmWrite); + } + #endif // _DEBUG } @@ -1065,6 +1086,18 @@ void cProtocol172::SendWindowProperty(const cWindow & a_Window, short a_Property void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) { + // Write the incoming data into the comm log file: + #ifdef _DEBUG + if (g_ShouldLogComm) + { + AString Hex; + CreateHexDump(Hex, a_Data, a_Size, 16); + m_CommLogFile.Printf("Incoming data: %d bytes. %d bytes unparsed already present in buffer.\n%s\n", + a_Size, m_ReceivedData.GetReadableSpace(), Hex.c_str() + ); + } + #endif + if (!m_ReceivedData.Write(a_Data, a_Size)) { // Too much data in the incoming queue, report to caller: @@ -1100,6 +1133,24 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) return; } + // Log the packet info into the comm log file: + #ifdef _DEBUG + if (g_ShouldLogComm) + { + AString PacketData; + bb.ReadAll(PacketData); + bb.ResetRead(); + bb.ReadVarInt(PacketType); + ASSERT(PacketData.size() > 0); + PacketData.resize(PacketData.size() - 1); + AString PacketDataHex; + CreateHexDump(PacketDataHex, PacketData.data(), PacketData.size(), 16); + m_CommLogFile.Printf("Next incoming packet is type %u (0x%x), length %u (0x%x) at state %d. Payload:\n%s\n", + PacketType, PacketType, PacketLen, PacketLen, m_State, PacketDataHex.c_str() + ); + } + #endif // _DEBUG + if (!HandlePacket(bb, PacketType)) { // Unknown packet, already been reported, but without the length. Log the length here: @@ -1807,6 +1858,19 @@ cProtocol172::cPacketizer::~cPacketizer() m_Out.ReadAll(DataToSend); m_Protocol.SendData(DataToSend.data(), DataToSend.size()); m_Out.CommitRead(); + + // Log the comm into logfile: + #ifdef _DEBUG + if (g_ShouldLogComm) + { + AString Hex; + ASSERT(DataToSend.size() > 0); + CreateHexDump(Hex, DataToSend.data() + 1, DataToSend.size() - 1, 16); + m_Protocol.m_CommLogFile.Printf("Outgoing packet: type %d (0x%x), length %u (0x%x), state %d. Payload:\n%s\n", + DataToSend[0], DataToSend[0], PacketLen, PacketLen, m_Protocol.m_State, Hex.c_str() + ); + } + #endif // _DEBUG } diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 3f440f313..b04a1f019 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -223,6 +223,11 @@ protected: CryptoPP::CFB_Mode::Decryption m_Decryptor; CryptoPP::CFB_Mode::Encryption m_Encryptor; + #ifdef _DEBUG + /** The logfile where the comm is logged, when g_ShouldLogComm is true */ + cFile m_CommLogFile; + #endif + /// Adds the received (unencrypted) data to m_ReceivedData, parses complete packets void AddReceivedData(const char * a_Data, int a_Size); diff --git a/src/main.cpp b/src/main.cpp index 340149e0b..68bf6683f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,15 @@ bool g_SERVER_TERMINATED = false; // Set to true when the server terminates, so +#ifdef _DEBUG +/** If set to true, the protocols will log each player's communication to a separate logfile */ +bool g_ShouldLogComm; +#endif + + + + + /// If defined, a thorough leak finder will be used (debug MSVC only); leaks will be output to the Output window #define ENABLE_LEAK_FINDER @@ -216,12 +225,26 @@ int main( int argc, char **argv ) #ifndef _DEBUG std::signal(SIGSEGV, NonCtrlHandler); std::signal(SIGTERM, NonCtrlHandler); - std::signal(SIGINT, NonCtrlHandler); + std::signal(SIGINT, NonCtrlHandler); #endif // DEBUG: test the dumpfile creation: // *((int *)0) = 0; + // Check if comm logging is to be enabled: + #ifdef _DEBUG + for (int i = 0; i < argc; i++) + { + if ( + (_stricmp(argv[i], "/commlog") == 0) || + (_stricmp(argv[i], "/logcomm") == 0) + ) + { + g_ShouldLogComm = true; + } + } + #endif // _DEBUG + #if !defined(ANDROID_NDK) try #endif -- cgit v1.2.3 From ebcaaad63aaf854e01f63104a820dfcbd76cc80e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 23:05:26 +0100 Subject: Fixed *nix compilation for previous commit. --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 68bf6683f..902e9e43b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -236,8 +236,8 @@ int main( int argc, char **argv ) for (int i = 0; i < argc; i++) { if ( - (_stricmp(argv[i], "/commlog") == 0) || - (_stricmp(argv[i], "/logcomm") == 0) + (NoCaseCompare(argv[i], "/commlog") == 0) || + (NoCaseCompare(argv[i], "/logcomm") == 0) ) { g_ShouldLogComm = true; -- cgit v1.2.3 From b367a74d3e56927e3a1f55738fb13abd6d667814 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 23:56:05 +0000 Subject: Zombies and skeletons use AI --- src/Mobs/Skeleton.cpp | 11 +++++++---- src/Mobs/Zombie.cpp | 13 ++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 509c2191e..4c8e78988 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -30,15 +30,18 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSkeleton::MoveToPosition(const Vector3f & a_Position) { - m_Destination = a_Position; - // If the destination is in the sun and if it is not night AND the skeleton isn't on fire then block the movement. - if (!IsOnFire() && m_World->GetTimeOfDay() < 13187 && m_World->GetBlockSkyLight((int) a_Position.x, (int) a_Position.y, (int) a_Position.z) == 15) + if ( + !IsOnFire() && + (m_World->GetTimeOfDay() < 13187) && + (m_World->GetBlockSkyLight((int) a_Position.x, (int) a_Position.y, (int) a_Position.z) == 15) + ) { m_bMovingToDestination = false; return; } - m_bMovingToDestination = true; + + super::MoveToPosition(a_Position); } diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index a046fcc92..27e8ed5fb 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -34,15 +34,18 @@ void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cZombie::MoveToPosition(const Vector3f & a_Position) { - m_Destination = a_Position; - - // If the destination is in the sun and if it is not night AND the skeleton isn't on fire then block the movement. - if ((m_World->GetBlockSkyLight((int) a_Position.x, (int) a_Position.y, (int) a_Position.z) == 15) && (m_World->GetTimeOfDay() < 13187) && !IsOnFire()) + // If the destination is in the sun and if it is not night AND the zombie isn't on fire then block the movement. + if ( + !IsOnFire() && + (m_World->GetTimeOfDay() < 13187) && + (m_World->GetBlockSkyLight((int)a_Position.x, (int)a_Position.y, (int)a_Position.z) == 15) + ) { m_bMovingToDestination = false; return; } - m_bMovingToDestination = true; + + super::MoveToPosition(a_Position); } -- cgit v1.2.3 From 1112f5adc6f66195ae030673e7831e46ae06c7b0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 23:56:19 +0000 Subject: Fixed a generator bug --- src/Generating/ChunkGenerator.cpp | 7 ++++++- src/Mobs/Monster.cpp | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index baa5b76b8..27210f49d 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -201,7 +201,7 @@ void cChunkGenerator::Execute(void) while (!m_ShouldTerminate) { cCSLock Lock(m_CS); - while (m_Queue.size() == 0) + while (m_Queue.empty()) { if ((NumChunksGenerated > 16) && (clock() - LastReportTick > CLOCKS_PER_SEC)) { @@ -221,6 +221,11 @@ void cChunkGenerator::Execute(void) LastReportTick = clock(); } + if (m_Queue.empty()) + { + continue; + } + cChunkCoords coords = m_Queue.front(); // Get next coord from queue m_Queue.erase( m_Queue.begin() ); // Remove coordinate from queue bool SkipEnabled = (m_Queue.size() > QUEUE_SKIP_LIMIT); diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 3b453552b..1db16ab71 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -249,6 +249,9 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) return; } + if ((m_Target != NULL) && m_Target->IsDestroyed()) + m_Target = NULL; + // Burning in daylight HandleDaylightBurning(a_Chunk); -- cgit v1.2.3 From fd7fc7e59efebd6b28012c8e8433f53ac853c555 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 24 Jan 2014 23:58:51 +0000 Subject: All mobs now drown (fixes #54) * Implemented mob drowning * Iron Golems and squids are excluded --- src/Entities/Entity.cpp | 95 ++++++++++++++++++++++++++++++++++++++- src/Entities/Entity.h | 23 +++++++++- src/Entities/Player.cpp | 117 ++++++------------------------------------------ src/Entities/Player.h | 22 --------- src/Mobs/IronGolem.h | 4 ++ src/Mobs/Squid.h | 3 ++ 6 files changed, 137 insertions(+), 127 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index ae98a1e91..e22f689d9 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -57,6 +57,8 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_Mass (0.001) // Default 1g , m_Width(a_Width) , m_Height(a_Height) + , m_IsSubmerged(false) + , m_IsSwimming(false) { cCSLock Lock(m_CSCount); m_EntityCount++; @@ -529,7 +531,17 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) { TickInVoid(a_Chunk); } - else { m_TicksSinceLastVoidDamage = 0; } + else + m_TicksSinceLastVoidDamage = 0; + + if (IsMob() || IsPlayer()) + { + // Set swimming state + SetSwimState(a_Chunk); + + // Handle drowning + HandleAir(); + } } @@ -907,6 +919,87 @@ void cEntity::TickInVoid(cChunk & a_Chunk) +void cEntity::SetSwimState(cChunk & a_Chunk) +{ + int RelY = (int)floor(m_LastPosY + 0.1); + if ((RelY < 0) || (RelY >= cChunkDef::Height - 1)) + { + m_IsSwimming = false; + m_IsSubmerged = false; + return; + } + + BLOCKTYPE BlockIn; + int RelX = (int)floor(m_LastPosX) - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = (int)floor(m_LastPosZ) - a_Chunk.GetPosZ() * cChunkDef::Width; + + // Check if the player is swimming: + // Use Unbounded, because we're being called *after* processing super::Tick(), which could have changed our chunk + if (!a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockIn)) + { + // This sometimes happens on Linux machines + // Ref.: http://forum.mc-server.org/showthread.php?tid=1244 + LOGD("SetSwimState failure: RelX = %d, RelZ = %d, LastPos = {%.02f, %.02f}, Pos = %.02f, %.02f}", + RelX, RelY, m_LastPosX, m_LastPosZ, GetPosX(), GetPosZ() + ); + m_IsSwimming = false; + m_IsSubmerged = false; + return; + } + m_IsSwimming = IsBlockWater(BlockIn); + + // Check if the player is submerged: + VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, RelY + 1, RelZ, BlockIn)); + m_IsSubmerged = IsBlockWater(BlockIn); +} + + + + + +void cEntity::HandleAir(void) +{ + // Ref.: http://www.minecraftwiki.net/wiki/Chunk_format + // See if the entity is /submerged/ water (block above is water) + // Get the type of block the entity is standing in: + + if (IsSubmerged()) + { + SetSpeedY(1); // Float in the water + + // Either reduce air level or damage player + if (m_AirLevel < 1) + { + if (m_AirTickTimer < 1) + { + // Damage player + TakeDamage(dtDrowning, NULL, 1, 1, 0); + // Reset timer + m_AirTickTimer = DROWNING_TICKS; + } + else + { + m_AirTickTimer -= 1; + } + } + else + { + // Reduce air supply + m_AirLevel -= 1; + } + } + else + { + // Set the air back to maximum + m_AirLevel = MAX_AIR_LEVEL; + m_AirTickTimer = DROWNING_TICKS; + } +} + + + + + /// Called when the entity starts burning void cEntity::OnStartedBurning(void) { diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 62dc42c3f..f6fa58bb2 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -110,6 +110,8 @@ public: BURN_TICKS_PER_DAMAGE = 20, ///< How many ticks to wait between damaging an entity when it is burning BURN_DAMAGE = 1, ///< How much damage to deal when the entity is burning BURN_TICKS = 200, ///< How long to keep an entity burning after it has stood in lava / fire + MAX_AIR_LEVEL = 300, ///< Maximum air an entity can have + DROWNING_TICKS = 20, ///< Number of ticks per heart of damage } ; cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height); @@ -344,7 +346,14 @@ public: virtual bool IsRiding (void) const {return false; } virtual bool IsSprinting(void) const {return false; } virtual bool IsRclking (void) const {return false; } - virtual bool IsInvisible(void) const {return false; } + virtual bool IsInvisible(void) const { return false; } + + /** Returns whether the player is swimming or not */ + virtual bool IsSwimming(void) const{ return m_IsSwimming; } + /** Return whether the player is under water or not */ + virtual bool IsSubmerged(void) const{ return m_IsSubmerged; } + /** Gets remaining air of a monster */ + int GetAirLevel(void) const { return m_AirLevel; } // tolua_end @@ -412,6 +421,18 @@ protected: virtual void Destroyed(void) {} // Called after the entity has been destroyed void SetWorld(cWorld * a_World) { m_World = a_World; } + + /** Called in each tick to handle air-related processing i.e. drowning */ + virtual void HandleAir(); + /** Called once per tick to set IsSwimming and IsSubmerged */ + virtual void SetSwimState(cChunk & a_Chunk); + + /** If an entity is currently swimming in or submerged under water */ + bool m_IsSwimming, m_IsSubmerged; + + /** Air level of a mobile */ + int m_AirLevel; + int m_AirTickTimer; private: // Measured in degrees, [-180, +180) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 377194efc..2a5baedb6 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -7,7 +7,6 @@ #include "../UI/Window.h" #include "../UI/WindowOwner.h" #include "../World.h" -#include "Pickup.h" #include "../Bindings/PluginManager.h" #include "../BlockEntities/BlockEntity.h" #include "../GroupManager.h" @@ -36,8 +35,6 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) : super(etPlayer, 0.6, 1.8) - , m_AirLevel( MAX_AIR_LEVEL ) - , m_AirTickTimer(DROWNING_TICKS) , m_bVisible(true) , m_FoodLevel(MAX_FOOD_LEVEL) , m_FoodSaturationLevel(5) @@ -108,9 +105,23 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ() ); } + m_LastJumpHeight = (float)(GetPosY()); m_LastGroundHeight = (float)(GetPosY()); m_Stance = GetPosY() + 1.62; + + if (m_GameMode == gmNotSet) + { + cWorld * World = cRoot::Get()->GetWorld(GetLoadedWorldName()); + if (World == NULL) + { + World = cRoot::Get()->GetDefaultWorld(); + } + if (World->IsGameModeCreative()) + { + m_CanFly = true; + } + } cRoot::Get()->GetServer()->PlayerCreated(this); } @@ -197,12 +208,6 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) super::Tick(a_Dt, a_Chunk); - // Set player swimming state - SetSwimState(a_Chunk); - - // Handle air drowning stuff - HandleAir(); - // Handle charging the bow: if (m_IsChargingBow) { @@ -1630,27 +1635,12 @@ bool cPlayer::LoadFromDisk() m_CurrentXp = (short) root.get("xpCurrent", 0).asInt(); m_IsFlying = root.get("isflying", 0).asBool(); - //SetExperience(root.get("experience", 0).asInt()); - m_GameMode = (eGameMode) root.get("gamemode", eGameMode_NotSet).asInt(); if (m_GameMode == eGameMode_Creative) { m_CanFly = true; } - else if (m_GameMode == eGameMode_NotSet) - { - cWorld * World = cRoot::Get()->GetWorld(GetLoadedWorldName()); - if (World == NULL) - { - World = cRoot::Get()->GetDefaultWorld(); - } - - if (World->GetGameMode() == eGameMode_Creative) - { - m_CanFly = true; - } - } m_Inventory.LoadFromJson(root["inventory"]); @@ -1767,85 +1757,6 @@ void cPlayer::UseEquippedItem(void) -void cPlayer::SetSwimState(cChunk & a_Chunk) -{ - int RelY = (int)floor(m_LastPosY + 0.1); - if ((RelY < 0) || (RelY >= cChunkDef::Height - 1)) - { - m_IsSwimming = false; - m_IsSubmerged = false; - return; - } - - BLOCKTYPE BlockIn; - int RelX = (int)floor(m_LastPosX) - a_Chunk.GetPosX() * cChunkDef::Width; - int RelZ = (int)floor(m_LastPosZ) - a_Chunk.GetPosZ() * cChunkDef::Width; - - // Check if the player is swimming: - // Use Unbounded, because we're being called *after* processing super::Tick(), which could have changed our chunk - if (!a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockIn)) - { - // This sometimes happens on Linux machines - // Ref.: http://forum.mc-server.org/showthread.php?tid=1244 - LOGD("SetSwimState failure: RelX = %d, RelZ = %d, LastPos = {%.02f, %.02f}, Pos = %.02f, %.02f}", - RelX, RelY, m_LastPosX, m_LastPosZ, GetPosX(), GetPosZ() - ); - m_IsSwimming = false; - m_IsSubmerged = false; - return; - } - m_IsSwimming = IsBlockWater(BlockIn); - - // Check if the player is submerged: - VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, RelY + 1, RelZ, BlockIn)); - m_IsSubmerged = IsBlockWater(BlockIn); -} - - - - - -void cPlayer::HandleAir(void) -{ - // Ref.: http://www.minecraftwiki.net/wiki/Chunk_format - // see if the player is /submerged/ water (block above is water) - // Get the type of block the player's standing in: - - if (IsSubmerged()) - { - // either reduce air level or damage player - if (m_AirLevel < 1) - { - if (m_AirTickTimer < 1) - { - // damage player - TakeDamage(dtDrowning, NULL, 1, 1, 0); - // reset timer - m_AirTickTimer = DROWNING_TICKS; - } - else - { - m_AirTickTimer -= 1; - } - } - else - { - // reduce air supply - m_AirLevel -= 1; - } - } - else - { - // set the air back to maximum - m_AirLevel = MAX_AIR_LEVEL; - m_AirTickTimer = DROWNING_TICKS; - } -} - - - - - void cPlayer::HandleFood(void) { // Ref.: http://www.minecraftwiki.net/wiki/Hunger diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 46d0de69d..449df978f 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -31,8 +31,6 @@ public: MAX_HEALTH = 20, MAX_FOOD_LEVEL = 20, EATING_TICKS = 30, ///< Number of ticks it takes to eat an item - MAX_AIR_LEVEL = 300, - DROWNING_TICKS = 10, //number of ticks per heart of damage } ; // tolua_end @@ -241,8 +239,6 @@ public: int GetFoodTickTimer (void) const { return m_FoodTickTimer; } double GetFoodExhaustionLevel (void) const { return m_FoodExhaustionLevel; } int GetFoodPoisonedTicksRemaining(void) const { return m_FoodPoisonedTicksRemaining; } - - int GetAirLevel (void) const { return m_AirLevel; } /// Returns true if the player is satiated, i. e. their foodlevel is at the max and they cannot eat anymore bool IsSatiated(void) const { return (m_FoodLevel >= MAX_FOOD_LEVEL); } @@ -353,12 +349,6 @@ public: /// If true the player can fly even when he's not in creative. void SetCanFly(bool a_CanFly); - /// Returns whether the player is swimming or not - virtual bool IsSwimming(void) const{ return m_IsSwimming; } - - /// Return whether the player is under water or not - virtual bool IsSubmerged(void) const{ return m_IsSubmerged; } - /// Returns wheter the player can fly or not. virtual bool CanFly(void) const { return m_CanFly; } // tolua_end @@ -389,12 +379,6 @@ protected: XP_TO_LEVEL30 = 825 } ; - /// Player's air level (for swimming) - int m_AirLevel; - - /// used to time ticks between damage taken via drowning/suffocation - int m_AirTickTimer; - bool m_bVisible; // Food-related variables: @@ -490,12 +474,6 @@ protected: /// Called in each tick if the player is fishing to make sure the floater dissapears when the player doesn't have a fishing rod as equipped item. void HandleFloater(void); - - /// Called in each tick to handle air-related processing i.e. drowning - void HandleAir(); - - /// Called once per tick to set IsSwimming and IsSubmerged - void SetSwimState(cChunk & a_Chunk); /// Adds food exhaustion based on the difference between Pos and LastPos, sprinting status and swimming (in water block) void ApplyFoodExhaustionFromMovement(); diff --git a/src/Mobs/IronGolem.h b/src/Mobs/IronGolem.h index d49ff4cab..41c60438c 100644 --- a/src/Mobs/IronGolem.h +++ b/src/Mobs/IronGolem.h @@ -18,6 +18,10 @@ public: CLASS_PROTODEF(cIronGolem); virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + + // Iron golems do not drown + virtual void HandleAir(void) override {} + virtual void SetSwimState(cChunk & a_Chunk) override {} } ; diff --git a/src/Mobs/Squid.h b/src/Mobs/Squid.h index ad299b95c..a9dba8b70 100644 --- a/src/Mobs/Squid.h +++ b/src/Mobs/Squid.h @@ -21,6 +21,9 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + // Squids do not drown (or float) + virtual void HandleAir(void) override {} + virtual void SetSwimState(cChunk & a_Chunk) override {} } ; -- cgit v1.2.3 From bac750b24e673358ec55d3bf71c118a749fe5d0c Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 25 Jan 2014 11:25:22 +0100 Subject: Added "player destroying" and "player destroyed" hooks Hooks: HOOK_PLAYER_DESTROYING HOOK_PLAYER_DESTROYED Idea from: https://github.com/mc-server/MCServer/issues/473 --- src/Bindings/Plugin.h | 2 ++ src/Bindings/PluginLua.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/Bindings/PluginLua.h | 2 ++ src/Bindings/PluginManager.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/Bindings/PluginManager.h | 4 ++++ src/Entities/Player.cpp | 4 ++++ 6 files changed, 94 insertions(+) diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index f4a117721..f50d1f561 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -67,6 +67,8 @@ public: virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; + virtual bool OnPlayerDestroying (cPlayer & a_Player) = 0; + virtual bool OnPlayerDestroyed (cPlayer & a_Player) = 0; virtual bool OnPlayerEating (cPlayer & a_Player) = 0; virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) = 0; virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 4c4664815..2b34e92c9 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -623,6 +623,46 @@ bool cPluginLua::OnPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX, int a_Blo +bool cPluginLua::OnPlayerDestroying(cPlayer & a_Player) +{ + cCSLock Lock(m_CriticalSection); + bool res = false; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_DESTROYING]; + for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) + { + m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res); + if (res) + { + return true; + } + } + return false; +} + + + + + +bool cPluginLua::OnPlayerDestroyed(cPlayer & a_Player) +{ + cCSLock Lock(m_CriticalSection); + bool res = false; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_DESTROYED]; + for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) + { + m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res); + if (res) + { + return true; + } + } + return false; +} + + + + + bool cPluginLua::OnPlayerEating(cPlayer & a_Player) { cCSLock Lock(m_CriticalSection); diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index c01f5ca89..f173be179 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -64,6 +64,8 @@ public: virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; + virtual bool OnPlayerDestroying (cPlayer & a_Player) override; + virtual bool OnPlayerDestroyed (cPlayer & a_Player) override; virtual bool OnPlayerEating (cPlayer & a_Player) override; virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) override; virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 24bb914d1..1bab8cb0f 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -673,6 +673,48 @@ bool cPluginManager::CallHookPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX, +bool cPluginManager::CallHookPlayerDestroying(cPlayer & a_Player) +{ + HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_DESTROYING); + if (Plugins == m_Hooks.end()) + { + return false; + } + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnPlayerDestroying(a_Player)) + { + return true; + } + } + return false; +} + + + + + +bool cPluginManager::CallHookPlayerDestroyed(cPlayer & a_Player) +{ + HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_DESTROYED); + if (Plugins == m_Hooks.end()) + { + return false; + } + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnPlayerDestroyed(a_Player)) + { + return true; + } + } + return false; +} + + + + + bool cPluginManager::CallHookPlayerEating(cPlayer & a_Player) { HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_EATING); diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 9936f5a35..38d5a8ca3 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -79,6 +79,8 @@ public: // tolua_export HOOK_LOGIN, HOOK_PLAYER_BREAKING_BLOCK, HOOK_PLAYER_BROKEN_BLOCK, + HOOK_PLAYER_DESTROYING, + HOOK_PLAYER_DESTROYED, HOOK_PLAYER_EATING, HOOK_PLAYER_FISHED, HOOK_PLAYER_FISHING, @@ -170,6 +172,8 @@ public: // tolua_export bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation); bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + bool CallHookPlayerDestroying (cPlayer & a_Player); + bool CallHookPlayerDestroyed (cPlayer & a_Player); bool CallHookPlayerEating (cPlayer & a_Player); bool CallHookPlayerFished (cPlayer & a_Player, const cItems a_Reward); bool CallHookPlayerFishing (cPlayer & a_Player, cItems a_Reward); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c1f2456eb..abdd792e0 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -120,6 +120,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) cPlayer::~cPlayer(void) { + cRoot::Get()->GetPluginManager()->CallHookPlayerDestroying(*this); + LOGD("Deleting cPlayer \"%s\" at %p, ID %d", m_PlayerName.c_str(), this, GetUniqueID()); // Notify the server that the player is being destroyed @@ -134,6 +136,8 @@ cPlayer::~cPlayer(void) delete m_InventoryWindow; LOGD("Player %p deleted", this); + + cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this); } -- cgit v1.2.3 From b2fd91ee6b391b36a8b2d88d818fe370798238e8 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 25 Jan 2014 05:25:43 -0800 Subject: Reformatted Bindings Dependecies --- src/CMakeLists.txt | 86 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 51182d3bc..4058c1873 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,34 +16,64 @@ if (NOT MSVC) #lib dependecies are not included - set(BINDING_DEPENDECIES ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/virtual_method_hooks.lua) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/AllToLua.pkg) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} ChunkDef.h BiomeDef.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} OSSupport/File.h Bindings/LuaFunctions.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Bindings/PluginManager.h Bindings/Plugin.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Bindings/PluginLua.h Bindings/WebPlugin.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Bindings/LuaWindow.h BlockID.h StringUtils.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Defines.h ChatColor.h ClientHandle.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Entities/Entity.h Entities/Floater.h ) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Entities/Pawn.h Entities/Player.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Entities/Pickup.h Entities/ProjectileEntity.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Entities/TNTEntity.h Entities/Effects.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Server.h World.h Inventory.h Enchantments.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Item.h ItemGrid.h BlockEntities/BlockEntity.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/BlockEntityWithItems.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/ChestEntity.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/DropSpenserEntity.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/DispenserEntity.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/DropperEntity.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/FurnaceEntity.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/HopperEntity.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/JukeboxEntity.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/NoteEntity.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockEntities/SignEntity.h WebAdmin.h Root.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Vector3f.h Vector3d.h Vector3i.h Matrix4f.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} Cuboid.h BoundingBox.h Tracer.h Group.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} BlockArea.h Generating/ChunkDesc.h) - set(BINDING_DEPENDECIES ${BINDING_DEPENDECIES} CraftingRecipes.h UI/Window.h Mobs/Monster.h) + set(BINDING_DEPENDECIES + ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/virtual_method_hooks.lua + ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/AllToLua.pkg + ChunkDef.h + BiomeDef.h + OSSupport/File.h + Bindings/LuaFunctions.h + Bindings/PluginManager.h + Bindings/Plugin.h + Bindings/PluginLua.h + Bindings/WebPlugin.h + Bindings/LuaWindow.h + BlockID.h + StringUtils.h + Defines.h + ChatColor.h + ClientHandle.h + Entities/Entity.h + Entities/Floater.h + Entities/Pawn.h + Entities/Player.h + Entities/Pickup.h + Entities/ProjectileEntity.h + Entities/TNTEntity.h + Entities/Effects.h + Server.h + World.h + Inventory.h + Enchantments.h + Item.h + ItemGrid.h + BlockEntities/BlockEntity.h + BlockEntities/BlockEntityWithItems.h + BlockEntities/ChestEntity.h + BlockEntities/DropSpenserEntity.h + BlockEntities/DispenserEntity.h + BlockEntities/DropperEntity.h + BlockEntities/FurnaceEntity.h + BlockEntities/HopperEntity.h + BlockEntities/JukeboxEntity.h + BlockEntities/NoteEntity.h + BlockEntities/SignEntity.h + WebAdmin.h + Root.h + Vector3f.h + Vector3d.h + Vector3i.h + Matrix4f.h + Cuboid.h + BoundingBox.h + Tracer.h + Group.h + BlockArea.h + Generating/ChunkDesc.h + CraftingRecipes.h + UI/Window.h + Mobs/Monster.h + ) include_directories(Bindings) include_directories(.) -- cgit v1.2.3 From 45bc1ff033271bc0c6a9e5931a00c554e065c375 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 25 Jan 2014 05:35:04 -0800 Subject: Added dependecy output to Bindings/BindingsDependencies.txt --- .gitignore | 1 + src/CMakeLists.txt | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index a108a9ece..923735d25 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ install_mainfest.txt src/MCServer lib/tolua++/tolua src/Bindings/Bindings.* +src/Bindings/BindingsDependecies.txt MCServer.dir/ #win32 cmake stuff diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4058c1873..9d03a4ffa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -94,6 +94,13 @@ if (NOT MSVC) target_link_libraries(Bindings lua sqlite tolualib) + #clear file + file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/BindingDependecies.txt) + foreach(dependecy ${BINDING_DEPENDECIES}) + #write each dependecy on a seperate line + file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/BindingDependecies.txt "${dependecy}\n") + endforeach() + set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "Bindings.cpp Bindings.h") foreach(folder ${FOLDERS}) -- cgit v1.2.3 From cb7c5a6181cd17485c518dd18b82d72af933e7bd Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 25 Jan 2014 05:37:19 -0800 Subject: Simplified .gitignore --- .gitignore | 60 +++++------------------------------------------------------- 1 file changed, 5 insertions(+), 55 deletions(-) diff --git a/.gitignore b/.gitignore index 923735d25..007b21519 100644 --- a/.gitignore +++ b/.gitignore @@ -71,58 +71,8 @@ MCServer.dir/ #cmake output folders ZERO_CHECK.dir/ -lib/cryptopp/Debug/ -lib/cryptopp/DebugProfile/ -lib/cryptopp/Release/ -lib/cryptopp/ReleaseProfile/ -lib/cryptopp/cryptopp.dir/ -lib/expat/Debug/ -lib/expat/DebugProfile/ -lib/expat/Release/ -lib/expat/ReleaseProfile/ -lib/expat/expat.dir/ -lib/inifile/Debug/ -lib/inifile/DebugProfile/ -lib/inifile/Release/ -lib/inifile/ReleaseProfile/ -lib/inifile/inifile.dir/ -lib/jsoncpp/Debug/ -lib/jsoncpp/DebugProfile/ -lib/jsoncpp/Release/ -lib/jsoncpp/ReleaseProfile/ -lib/jsoncpp/jsoncpp.dir/ -lib/lua/Debug/ -lib/lua/DebugProfile/ -lib/lua/Release/ -lib/lua/ReleaseProfile/ -lib/lua/lua.dir/ -lib/luaexpat/Debug/ -lib/luaexpat/DebugProfile/ -lib/luaexpat/Release/ -lib/luaexpat/ReleaseProfile/ -lib/luaexpat/luaexpat.dir/ -lib/md5/Debug/ -lib/md5/DebugProfile/ -lib/md5/Release/ -lib/md5/ReleaseProfile/ -lib/md5/md5.dir/ -lib/sqlite/Debug/ -lib/sqlite/DebugProfile/ -lib/sqlite/Release/ -lib/sqlite/ReleaseProfile/ -lib/sqlite/sqlite.dir/ -lib/tolua++/Debug/ -lib/tolua++/DebugProfile/ -lib/tolua++/Release/ -lib/tolua++/ReleaseProfile/ -lib/tolua++/tolua.dir/ -lib/tolua++/tolualib.dir/ -lib/zlib/Debug/ -lib/zlib/DebugProfile/ -lib/zlib/Release/ -lib/zlib/ReleaseProfile/ -lib/zlib/zlib.dir/ -src/Debug/ -src/DebugProfile/ -src/Release/ -src/ReleaseProfile/ +Debug/ +DebugProfile/ +Release/ +ReleaseProfile/ +*.dir/ -- cgit v1.2.3 From 59b8205f02eb7bf2954acba56fd63f485a30ece5 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 25 Jan 2014 05:51:03 -0800 Subject: Extracted cSocket::GetErrorString into GetOSErrorString --- src/OSSupport/BlockingTCPLink.cpp | 4 +-- src/OSSupport/Errors.cpp | 52 +++++++++++++++++++++++++++++++++++++++ src/OSSupport/Errors.h | 3 +++ src/OSSupport/Socket.cpp | 52 --------------------------------------- src/OSSupport/Socket.h | 7 +++--- src/OSSupport/SocketThreads.cpp | 3 ++- 6 files changed, 62 insertions(+), 59 deletions(-) create mode 100644 src/OSSupport/Errors.cpp create mode 100644 src/OSSupport/Errors.h diff --git a/src/OSSupport/BlockingTCPLink.cpp b/src/OSSupport/BlockingTCPLink.cpp index 08aec0c65..af50eda5d 100644 --- a/src/OSSupport/BlockingTCPLink.cpp +++ b/src/OSSupport/BlockingTCPLink.cpp @@ -2,7 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "BlockingTCPLink.h" - +#include "Errors.h" @@ -75,7 +75,7 @@ bool cBlockingTCPLink::Connect(const char * iAddress, unsigned int iPort) server.sin_port = htons( (unsigned short)iPort); if (connect(m_Socket, (struct sockaddr *)&server, sizeof(server))) { - LOGWARN("cTCPLink: Connection to \"%s:%d\" failed (%s)", iAddress, iPort, cSocket::GetErrorString( cSocket::GetLastError() ).c_str() ); + LOGWARN("cTCPLink: Connection to \"%s:%d\" failed (%s)", iAddress, iPort,GetOSErrorString( cSocket::GetLastError() ).c_str() ); CloseSocket(); return false; } diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp new file mode 100644 index 000000000..b2e8880bb --- /dev/null +++ b/src/OSSupport/Errors.cpp @@ -0,0 +1,52 @@ + +#include "Globals.h" + +#include "Errors.h" + +AString GetOSErrorString( int a_ErrNo ) +{ + char buffer[ 1024 ]; + AString Out; + + #ifdef _WIN32 + + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, a_ErrNo, 0, buffer, ARRAYCOUNT(buffer), NULL); + Printf(Out, "%d: %s", a_ErrNo, buffer); + if (!Out.empty() && (Out[Out.length() - 1] == '\n')) + { + Out.erase(Out.length() - 2); + } + return Out; + + #else // _WIN32 + + // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r(): + + #if ( _GNU_SOURCE ) && !defined(ANDROID_NDK) // GNU version of strerror_r() + + char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) ); + if( res != NULL ) + { + Printf(Out, "%d: %s", a_ErrNo, res); + return Out; + } + + #else // XSI version of strerror_r(): + + int res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) ); + if( res == 0 ) + { + Printf(Out, "%d: %s", a_ErrNo, buffer); + return Out; + } + + #endif // strerror_r() version + + else + { + Printf(Out, "Error %d while getting error string for error #%d!", errno, a_ErrNo); + return Out; + } + + #endif // else _WIN32 +} diff --git a/src/OSSupport/Errors.h b/src/OSSupport/Errors.h new file mode 100644 index 000000000..72ba98862 --- /dev/null +++ b/src/OSSupport/Errors.h @@ -0,0 +1,3 @@ + +AString GetOSErrorString(int a_ErrNo); + diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp index d80c9bb3d..4226a7535 100644 --- a/src/OSSupport/Socket.cpp +++ b/src/OSSupport/Socket.cpp @@ -105,58 +105,6 @@ void cSocket::ShutdownReadWrite(void) - -AString cSocket::GetErrorString( int a_ErrNo ) -{ - char buffer[ 1024 ]; - AString Out; - - #ifdef _WIN32 - - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, a_ErrNo, 0, buffer, ARRAYCOUNT(buffer), NULL); - Printf(Out, "%d: %s", a_ErrNo, buffer); - if (!Out.empty() && (Out[Out.length() - 1] == '\n')) - { - Out.erase(Out.length() - 2); - } - return Out; - - #else // _WIN32 - - // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r(): - - #if ( _GNU_SOURCE ) && !defined(ANDROID_NDK) // GNU version of strerror_r() - - char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) ); - if( res != NULL ) - { - Printf(Out, "%d: %s", a_ErrNo, res); - return Out; - } - - #else // XSI version of strerror_r(): - - int res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) ); - if( res == 0 ) - { - Printf(Out, "%d: %s", a_ErrNo, buffer); - return Out; - } - - #endif // strerror_r() version - - else - { - Printf(Out, "Error %d while getting error string for error #%d!", errno, a_ErrNo); - return Out; - } - - #endif // else _WIN32 -} - - - - int cSocket::GetLastError() { #ifdef _WIN32 diff --git a/src/OSSupport/Socket.h b/src/OSSupport/Socket.h index 91c9ca5fd..4ca3d61f4 100644 --- a/src/OSSupport/Socket.h +++ b/src/OSSupport/Socket.h @@ -14,7 +14,7 @@ #endif - +#include "Errors.h" class cSocket @@ -57,11 +57,10 @@ public: /// Initializes the network stack. Returns 0 on success, or another number as an error code. static int WSAStartup(void); - static AString GetErrorString(int a_ErrNo); static int GetLastError(); static AString GetLastErrorString(void) { - return GetErrorString(GetLastError()); + return GetOSErrorString(GetLastError()); } /// Creates a new socket of the specified address family @@ -115,4 +114,4 @@ public: private: xSocket m_Socket; AString m_IPString; -}; \ No newline at end of file +}; diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp index b8069cf00..74932daf8 100644 --- a/src/OSSupport/SocketThreads.cpp +++ b/src/OSSupport/SocketThreads.cpp @@ -7,6 +7,7 @@ #include "Globals.h" #include "SocketThreads.h" +#include "Errors.h" @@ -556,7 +557,7 @@ void cSocketThreads::cSocketThread::WriteToSockets(fd_set * a_Write) if (Sent < 0) { int Err = cSocket::GetLastError(); - LOGWARNING("Error %d while writing to client \"%s\", disconnecting. \"%s\"", Err, m_Slots[i].m_Socket.GetIPString().c_str(), cSocket::GetErrorString(Err).c_str()); + LOGWARNING("Error %d while writing to client \"%s\", disconnecting. \"%s\"", Err, m_Slots[i].m_Socket.GetIPString().c_str(), GetOSErrorString(Err).c_str()); m_Slots[i].m_Socket.CloseSocket(); if (m_Slots[i].m_Client != NULL) { -- cgit v1.2.3 From 977e277094750a22284b4a738269db295af3cad3 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 25 Jan 2014 06:02:20 -0800 Subject: Switched cEvent to GetOSErrorString --- src/OSSupport/Errors.cpp | 1 + src/OSSupport/Errors.h | 2 ++ src/OSSupport/Event.cpp | 29 +++++++++++------------------ 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp index b2e8880bb..2e05f1df1 100644 --- a/src/OSSupport/Errors.cpp +++ b/src/OSSupport/Errors.cpp @@ -50,3 +50,4 @@ AString GetOSErrorString( int a_ErrNo ) #endif // else _WIN32 } + diff --git a/src/OSSupport/Errors.h b/src/OSSupport/Errors.h index 72ba98862..8ce9deb10 100644 --- a/src/OSSupport/Errors.h +++ b/src/OSSupport/Errors.h @@ -1,3 +1,5 @@ +#pragma once + AString GetOSErrorString(int a_ErrNo); diff --git a/src/OSSupport/Event.cpp b/src/OSSupport/Event.cpp index fe1128dc9..649a0a3cf 100644 --- a/src/OSSupport/Event.cpp +++ b/src/OSSupport/Event.cpp @@ -7,9 +7,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Event.h" -#if not defined(_WIN32) -#include -#endif +#include "Errors.h" @@ -37,18 +35,16 @@ cEvent::cEvent(void) m_Event = sem_open(EventName.c_str(), O_CREAT, 777, 0 ); if (m_Event == SEM_FAILED) { - char buffer[1024]; - strerror_r(errno,buffer,1024); - LOGERROR("cEvent: Cannot create event, err = %s. Aborting server.", buffer); + AString error = GetOSErrorString(errno); + LOGERROR("cEvent: Cannot create event, err = %s. Aborting server.", error.c_str()); abort(); } // Unlink the semaphore immediately - it will continue to function but will not pollute the namespace // We don't store the name, so can't call this in the destructor if (sem_unlink(EventName.c_str()) != 0) { - char buffer[1024]; - strerror_r(errno,buffer,1024); - LOGWARN("ERROR: Could not unlink cEvent. (%s)", buffer); + AString error = GetOSErrorString(errno); + LOGWARN("ERROR: Could not unlink cEvent. (%s)", error.c_str()); } } #endif // *nix @@ -67,9 +63,8 @@ cEvent::~cEvent() { if (sem_close(m_Event) != 0) { - char buffer[1024]; - strerror_r(errno,buffer,1024); - LOGERROR("ERROR: Could not close cEvent. (%s)", buffer); + AString error = GetOSErrorString(errno); + LOGERROR("ERROR: Could not close cEvent. (%s)", error.c_str()); } } else @@ -96,9 +91,8 @@ void cEvent::Wait(void) int res = sem_wait(m_Event); if (res != 0 ) { - char buffer[1024]; - strerror_r(errno,buffer,1024); - LOGWARN("cEvent: waiting for the event failed: %i, err = %s. Continuing, but server may be unstable.", res, buffer); + AString error = GetOSErrorString(errno); + LOGWARN("cEvent: waiting for the event failed: %i, err = %s. Continuing, but server may be unstable.", res, error.c_str()); } #endif } @@ -118,9 +112,8 @@ void cEvent::Set(void) int res = sem_post(m_Event); if (res != 0) { - char buffer[1024]; - strerror_r(errno,buffer,1024); - LOGWARN("cEvent: Could not set cEvent: %i, err = %s", res, buffer); + AString error = GetOSErrorString(errno); + LOGWARN("cEvent: Could not set cEvent: %i, err = %s", res, error.c_str()); } #endif } -- cgit v1.2.3 From 9d1ebaaf0d7260b6b5d3e7d78bc0980c90192543 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 23:06:06 +0100 Subject: Ignoring the Comm Logs. --- MCServer/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/MCServer/.gitignore b/MCServer/.gitignore index c18dd7a67..e3aebbf92 100644 --- a/MCServer/.gitignore +++ b/MCServer/.gitignore @@ -4,6 +4,7 @@ *.lib *.ini MCServer +CommLogs/ logs players world* -- cgit v1.2.3 From 96b4af15963ac70b25ab243d84d48221a3d41369 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 25 Jan 2014 15:06:21 +0100 Subject: Protocol17: Comm logging shows the data left over from previous parse. --- src/Protocol/Protocol17x.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index d2d0df7f7..8abe4f259 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1090,10 +1090,23 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) #ifdef _DEBUG if (g_ShouldLogComm) { + if (m_ReceivedData.GetReadableSpace() > 0) + { + AString AllData; + int OldReadableSpace = m_ReceivedData.GetReadableSpace(); + m_ReceivedData.ReadAll(AllData); + m_ReceivedData.ResetRead(); + m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace); + AString Hex; + CreateHexDump(Hex, AllData.data(), AllData.size(), 16); + m_CommLogFile.Printf("Incoming data, %d (0x%x) bytes unparsed already present in buffer:\n%s\n", + AllData.size(), AllData.size(), Hex.c_str() + ); + } AString Hex; CreateHexDump(Hex, a_Data, a_Size, 16); - m_CommLogFile.Printf("Incoming data: %d bytes. %d bytes unparsed already present in buffer.\n%s\n", - a_Size, m_ReceivedData.GetReadableSpace(), Hex.c_str() + m_CommLogFile.Printf("Incoming data: %d (0x%x) bytes: \n%s\n", + a_Size, a_Size, Hex.c_str() ); } #endif -- cgit v1.2.3 From 2806b48afa4e3d087c8a123d81f9eabe3ec797c5 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 25 Jan 2014 06:06:30 -0800 Subject: Fixed exports --- src/Bindings/AllToLua.pkg | 1 - src/Bindings/ManualBindings.cpp | 2 -- src/WorldStorage/SchematicFileSerializer.h | 5 +---- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 8b2a78d05..f65aed9bb 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -70,7 +70,6 @@ $cfile "../Generating/ChunkDesc.h" $cfile "../CraftingRecipes.h" $cfile "../UI/Window.h" $cfile "../Mobs/Monster.h" -$cfile "../WorldStorage/SchematicFileSerializer.h" diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 299dfd9ee..4e92da5ae 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2258,7 +2258,6 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) } AString Filename = tolua_tostring(tolua_S, 2, 0); - LOGWARNING("cBlockArea::LoadFromSchematic file is depreciated. Please use cSchematicFileSerilizer::LoadFromSchematicFile."); bool res = cSchematicFileSerializer::LoadFromSchematicFile(*self,Filename); tolua_pushboolean(tolua_S, res); return 1; @@ -2287,7 +2286,6 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) return 0; } AString Filename = tolua_tostring(tolua_S, 2, 0); - LOGWARNING("cBlockArea::SaveToSchematic file is depreciated. Please use cSchematicFileSerializer::SaveToSchematicFile."); bool res = cSchematicFileSerializer::SaveToSchematicFile(*self,Filename); tolua_pushboolean(tolua_S, res); return 1; diff --git a/src/WorldStorage/SchematicFileSerializer.h b/src/WorldStorage/SchematicFileSerializer.h index 31b36695c..9be2e5b57 100644 --- a/src/WorldStorage/SchematicFileSerializer.h +++ b/src/WorldStorage/SchematicFileSerializer.h @@ -13,7 +13,6 @@ class cParsedNBT; -// tolua_begin class cSchematicFileSerializer { public: @@ -24,9 +23,7 @@ public: /// Saves the area into a .schematic file. Returns true if successful static bool SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName); - // tolua_end - private: /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful. static bool LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT); -}; // tolua_export +}; -- cgit v1.2.3 From 5aa3fc4c564252359613eb0d91225247f65e0d45 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 25 Jan 2014 15:27:34 +0100 Subject: Added cFile::Flush(). This is useful when using cFile as a log file and we know the server may crash after a specific write, so we flush the file before continuing. --- src/OSSupport/File.cpp | 9 +++++++++ src/OSSupport/File.h | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 9f7c0d439..0ebd04915 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -450,3 +450,12 @@ int cFile::Printf(const char * a_Fmt, ...) + +void cFile::Flush(void) +{ + fflush(m_File); +} + + + + diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index 01663a229..07fce6661 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -18,6 +18,8 @@ Usage: 2, Check if the file was opened using IsOpen() 3, Read / write 4, Destroy the instance + +For reading entire files into memory, just use the static cFile::ReadWholeFile() */ @@ -55,7 +57,7 @@ public: static const char PathSeparator = '/'; #endif - /// The mode in which to open the file + /** The mode in which to open the file */ enum eMode { fmRead, // Read-only. If the file doesn't exist, object will not be valid @@ -63,13 +65,13 @@ public: fmReadWrite // Read/write. If the file already exists, it will be left intact; writing will overwrite the data from the beginning } ; - /// Simple constructor - creates an unopened file object, use Open() to open / create a real file + /** Simple constructor - creates an unopened file object, use Open() to open / create a real file */ cFile(void); - /// Constructs and opens / creates the file specified, use IsOpen() to check for success + /** Constructs and opens / creates the file specified, use IsOpen() to check for success */ cFile(const AString & iFileName, eMode iMode); - /// Auto-closes the file, if open + /** Auto-closes the file, if open */ ~cFile(); bool Open(const AString & iFileName, eMode iMode); @@ -77,60 +79,63 @@ public: bool IsOpen(void) const; bool IsEOF(void) const; - /// Reads up to iNumBytes bytes into iBuffer, returns the number of bytes actually read, or -1 on failure; asserts if not open + /** Reads up to iNumBytes bytes into iBuffer, returns the number of bytes actually read, or -1 on failure; asserts if not open */ int Read (void * iBuffer, int iNumBytes); - /// Writes up to iNumBytes bytes from iBuffer, returns the number of bytes actually written, or -1 on failure; asserts if not open + /** Writes up to iNumBytes bytes from iBuffer, returns the number of bytes actually written, or -1 on failure; asserts if not open */ int Write(const void * iBuffer, int iNumBytes); - /// Seeks to iPosition bytes from file start, returns old position or -1 for failure; asserts if not open + /** Seeks to iPosition bytes from file start, returns old position or -1 for failure; asserts if not open */ int Seek (int iPosition); - /// Returns the current position (bytes from file start) or -1 for failure; asserts if not open + /** Returns the current position (bytes from file start) or -1 for failure; asserts if not open */ int Tell (void) const; - /// Returns the size of file, in bytes, or -1 for failure; asserts if not open + /** Returns the size of file, in bytes, or -1 for failure; asserts if not open */ int GetSize(void) const; - /// Reads the file from current position till EOF into an AString; returns the number of bytes read or -1 for error + /** Reads the file from current position till EOF into an AString; returns the number of bytes read or -1 for error */ int ReadRestOfFile(AString & a_Contents); // tolua_begin - /// Returns true if the file specified exists + /** Returns true if the file specified exists */ static bool Exists(const AString & a_FileName); - /// Deletes a file, returns true if successful + /** Deletes a file, returns true if successful */ static bool Delete(const AString & a_FileName); - /// Renames a file or folder, returns true if successful. May fail if dest already exists (libc-dependant)! + /** Renames a file or folder, returns true if successful. May fail if dest already exists (libc-dependant)! */ static bool Rename(const AString & a_OrigPath, const AString & a_NewPath); - /// Copies a file, returns true if successful. + /** Copies a file, returns true if successful. */ static bool Copy(const AString & a_SrcFileName, const AString & a_DstFileName); - /// Returns true if the specified path is a folder + /** Returns true if the specified path is a folder */ static bool IsFolder(const AString & a_Path); - /// Returns true if the specified path is a regular file + /** Returns true if the specified path is a regular file */ static bool IsFile(const AString & a_Path); - /// Returns the size of the file, or a negative number on error + /** Returns the size of the file, or a negative number on error */ static int GetSize(const AString & a_FileName); - /// Creates a new folder with the specified name. Returns true if successful. Path may be relative or absolute + /** Creates a new folder with the specified name. Returns true if successful. Path may be relative or absolute */ static bool CreateFolder(const AString & a_FolderPath); - /// Returns the entire contents of the specified file as a string. Returns empty string on error. + /** Returns the entire contents of the specified file as a string. Returns empty string on error. */ static AString ReadWholeFile(const AString & a_FileName); // tolua_end - /// Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). + /** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */ static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp int Printf(const char * a_Fmt, ...); + /** Flushes all the bufferef output into the file (only when writing) */ + void Flush(void); + private: #ifdef USE_STDIO_FILE FILE * m_File; -- cgit v1.2.3 From ff066453b805748d6e665b3ad219a62c777e4453 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 25 Jan 2014 15:28:16 +0100 Subject: Comm logging is available in both Debug and Release modes. --- src/Protocol/Protocol17x.cpp | 26 ++++++++++++++++---------- src/Protocol/Protocol17x.h | 2 -- src/main.cpp | 4 ---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 8abe4f259..504dd99c3 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -53,10 +53,8 @@ Implements the 1.7.x protocol classes: -#ifdef _DEBUG // fwd: main.cpp: extern bool g_ShouldLogComm; -#endif @@ -76,14 +74,12 @@ cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAdd m_IsEncrypted(false) { // Create the comm log file, if so requested: - #ifdef _DEBUG if (g_ShouldLogComm) { cFile::CreateFolder("CommLogs"); AString FileName = Printf("CommLogs/%x__%s.log", (unsigned)time(NULL), a_Client->GetIPString().c_str()); m_CommLogFile.Open(FileName, cFile::fmWrite); } - #endif // _DEBUG } @@ -1087,7 +1083,6 @@ void cProtocol172::SendWindowProperty(const cWindow & a_Window, short a_Property void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) { // Write the incoming data into the comm log file: - #ifdef _DEBUG if (g_ShouldLogComm) { if (m_ReceivedData.GetReadableSpace() > 0) @@ -1109,7 +1104,6 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) a_Size, a_Size, Hex.c_str() ); } - #endif if (!m_ReceivedData.Write(a_Data, a_Size)) { @@ -1147,7 +1141,6 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) } // Log the packet info into the comm log file: - #ifdef _DEBUG if (g_ShouldLogComm) { AString PacketData; @@ -1162,7 +1155,6 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) PacketType, PacketType, PacketLen, PacketLen, m_State, PacketDataHex.c_str() ); } - #endif // _DEBUG if (!HandlePacket(bb, PacketType)) { @@ -1180,6 +1172,12 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) LOGD("Packet contents:\n%s", Out.c_str()); #endif // _DEBUG + // Put a message in the comm log: + if (g_ShouldLogComm) + { + m_CommLogFile.Printf("^^^^^^ Unhandled packet ^^^^^^\n\n\n"); + } + return; } @@ -1189,6 +1187,16 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read %u bytes, packet contained %u bytes", PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen ); + + // Put a message in the comm log: + if (g_ShouldLogComm) + { + m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %d left) ^^^^^^\n\n\n", + 1, bb.GetReadableSpace() + ); + m_CommLogFile.Flush(); + } + ASSERT(!"Read wrong number of bytes!"); m_Client->PacketError(PacketType); } @@ -1873,7 +1881,6 @@ cProtocol172::cPacketizer::~cPacketizer() m_Out.CommitRead(); // Log the comm into logfile: - #ifdef _DEBUG if (g_ShouldLogComm) { AString Hex; @@ -1883,7 +1890,6 @@ cProtocol172::cPacketizer::~cPacketizer() DataToSend[0], DataToSend[0], PacketLen, PacketLen, m_Protocol.m_State, Hex.c_str() ); } - #endif // _DEBUG } diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index b04a1f019..cac7f0d29 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -223,10 +223,8 @@ protected: CryptoPP::CFB_Mode::Decryption m_Decryptor; CryptoPP::CFB_Mode::Encryption m_Encryptor; - #ifdef _DEBUG /** The logfile where the comm is logged, when g_ShouldLogComm is true */ cFile m_CommLogFile; - #endif /// Adds the received (unencrypted) data to m_ReceivedData, parses complete packets diff --git a/src/main.cpp b/src/main.cpp index 902e9e43b..06b344c25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,10 +19,8 @@ bool g_SERVER_TERMINATED = false; // Set to true when the server terminates, so -#ifdef _DEBUG /** If set to true, the protocols will log each player's communication to a separate logfile */ bool g_ShouldLogComm; -#endif @@ -232,7 +230,6 @@ int main( int argc, char **argv ) // *((int *)0) = 0; // Check if comm logging is to be enabled: - #ifdef _DEBUG for (int i = 0; i < argc; i++) { if ( @@ -243,7 +240,6 @@ int main( int argc, char **argv ) g_ShouldLogComm = true; } } - #endif // _DEBUG #if !defined(ANDROID_NDK) try -- cgit v1.2.3 From 314fc3cdac702a44a257ada5fab52f0a7d37ffcd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 25 Jan 2014 14:42:26 +0000 Subject: Mob bugfixes * Mobs no longer require constant line-of-sight to a player to remain aggravated * Fixed an ASSERT * Fixed mobs jumping * Fixed Idle state not properly using AI + Added FILE_IO_PREFIX to favicon loading + Implemented #563 --- src/Generating/ChunkGenerator.cpp | 2 ++ src/Mobs/Monster.cpp | 49 +++++++++++++++++++++++---------------- src/Mobs/Monster.h | 12 ++++++++-- src/Server.cpp | 2 +- src/World.cpp | 13 +++++++++-- src/World.h | 2 +- 6 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index 27210f49d..ef38f1399 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -223,6 +223,8 @@ void cChunkGenerator::Execute(void) if (m_Queue.empty()) { + // Sometimes the queue remains empty + // If so, we can't do any front() operations on it! continue; } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 1db16ab71..9ba18f4d1 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -259,6 +259,17 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) if (m_bMovingToDestination) { + if (m_bOnGround) + { + int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z); + + if (DoesPosYRequireJump(NextHeight)) + { + m_bOnGround = false; + AddPosY(1.5); // Jump!! + } + } + Vector3f Distance = m_Destination - GetPosition(); if(!ReachedDestination() && !ReachedFinalDestination()) // If we haven't reached any sort of destination, move { @@ -285,17 +296,6 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) TickPathFinding(); // We have reached the next point in our path, calculate another point } } - - if(m_bOnGround) - { - int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z); - - if (IsNextYPosReachable(NextHeight)) - { - m_bOnGround = false; - SetSpeedY(5.f); // Jump!! - } - } } if (ReachedFinalDestination()) @@ -373,6 +373,11 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) { int PosY = (int)floor(GetPosY()); + if (PosY < 0) + PosY = 0; + else if (PosY > cChunkDef::Height) + PosY = cChunkDef::Height; + if (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))]) { while (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY > 0)) @@ -494,7 +499,7 @@ void cMonster::KilledBy(cEntity * a_Killer) void cMonster::CheckEventSeePlayer(void) { // TODO: Rewrite this to use cWorld's DoWithPlayers() - cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); + cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance, false); if (Closest != NULL) { @@ -548,6 +553,11 @@ void cMonster::EventLosePlayer(void) void cMonster::InStateIdle(float a_Dt) { + if (m_bMovingToDestination) + { + return; // Still getting there + } + m_IdleInterval += a_Dt; if (m_IdleInterval > 1) @@ -557,20 +567,19 @@ void cMonster::InStateIdle(float a_Dt) m_IdleInterval -= 1; // So nothing gets dropped when the server hangs for a few seconds Vector3d Dist; - Dist.x = (double)m_World->GetTickRandomNumber(m_SightDistance * 2) - m_SightDistance; - Dist.z = (double)m_World->GetTickRandomNumber(m_SightDistance * 2) - m_SightDistance; + Dist.x = (double)m_World->GetTickRandomNumber(10) - 5; + Dist.z = (double)m_World->GetTickRandomNumber(10) - 5; if ((Dist.SqrLength() > 2) && (rem >= 3)) { - m_Destination.x = GetPosX() + Dist.x; - m_Destination.z = GetPosZ() + Dist.z; + Vector3d Destination(GetPosX() + Dist.x, 0, GetPosZ() + Dist.z); - int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z); + int NextHeight = FindFirstNonAirBlockPosition(Destination.x, Destination.z); - if (IsNextYPosReachable(NextHeight + 1)) + if (IsNextYPosReachable(NextHeight)) { - m_Destination.y = (double)NextHeight; - MoveToPosition(m_Destination); + Destination.y = NextHeight; + MoveToPosition(Destination); } } } diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index c8129e63d..d04cb8941 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -168,10 +168,18 @@ protected: If current Y is nonsolid, goes down to try to find a solid block, then returns that + 1 If current Y is solid, goes up to find first nonsolid block, and returns that */ int FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ); - /** Returns if a monster can actually reach a given height by jumping */ + /** Returns if a monster can actually reach a given height by jumping or walking */ inline bool IsNextYPosReachable(int a_PosY) { - return (a_PosY > (int)floor(GetPosY())) && (a_PosY == (int)floor(GetPosY()) + 1); + return ( + (a_PosY <= (int)floor(GetPosY())) || + DoesPosYRequireJump(a_PosY) + ); + } + /** Returns if a monster can reach a given height by jumping */ + inline bool DoesPosYRequireJump(int a_PosY) + { + return ((a_PosY > (int)floor(GetPosY())) && (a_PosY == (int)floor(GetPosY()) + 1)); } /** A semi-temporary list to store the traversed coordinates during active pathfinding so we don't visit them again */ diff --git a/src/Server.cpp b/src/Server.cpp index 34ee066cb..2774c8b46 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -194,7 +194,7 @@ bool cServer::InitServer(cIniFile & a_SettingsIni) m_PlayerCount = 0; m_PlayerCountDiff = 0; - m_FaviconData = Base64Encode(cFile::ReadWholeFile("favicon.png")); // Will return empty string if file nonexistant; client doesn't mind + m_FaviconData = Base64Encode(cFile::ReadWholeFile(FILE_IO_PREFIX + AString("favicon.png"))); // Will return empty string if file nonexistant; client doesn't mind if (m_bIsConnected) { diff --git a/src/World.cpp b/src/World.cpp index 453a22c2d..514524991 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -234,7 +234,11 @@ cWorld::cWorld(const AString & a_WorldName) : m_WorldName(a_WorldName), m_IniFileName(m_WorldName + "/world.ini"), m_StorageSchema("Default"), +#ifdef _arm_ + m_StorageCompressionFactor(3), +#else m_StorageCompressionFactor(6), +#endif m_IsSpawnExplicitlySet(false), m_WorldAgeSecs(0), m_TimeOfDaySecs(0), @@ -2419,7 +2423,7 @@ bool cWorld::FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCa // TODO: This interface is dangerous! -cPlayer * cWorld::FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit) +cPlayer * cWorld::FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit, bool a_CheckLineOfSight) { cTracer LineOfSight(this); @@ -2434,7 +2438,12 @@ cPlayer * cWorld::FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit) if (Distance < ClosestDistance) { - if (!LineOfSight.Trace(a_Pos,(Pos - a_Pos),(int)(Pos - a_Pos).Length())) + if (a_CheckLineOfSight && !LineOfSight.Trace(a_Pos,(Pos - a_Pos),(int)(Pos - a_Pos).Length())) + { + ClosestDistance = Distance; + ClosestPlayer = *itr; + } + else { ClosestDistance = Distance; ClosestPlayer = *itr; diff --git a/src/World.h b/src/World.h index 61c7604df..933e3ba6f 100644 --- a/src/World.h +++ b/src/World.h @@ -239,7 +239,7 @@ public: bool FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << // TODO: This interface is dangerous - rewrite to DoWithClosestPlayer(pos, sight, action) - cPlayer * FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit); + cPlayer * FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit, bool a_CheckLineOfSight = true); void SendPlayerList(cPlayer * a_DestPlayer); // Sends playerlist to the player -- cgit v1.2.3 From d9707a92917308fcf29827e6ca5f577624418a1c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 25 Jan 2014 15:19:56 +0000 Subject: Implemented pickup combining * Fixes FS393 * Part of #131 --- src/Entities/Pickup.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index 55c878b57..bfe162b69 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -17,6 +17,51 @@ +class cPickupCombiningCallback : + public cEntityCallback +{ +public: + cPickupCombiningCallback(Vector3d a_Position, cPickup * a_Pickup) : + m_Position(a_Position), + m_Pickup(a_Pickup), + m_FoundMatchingPickup(false) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + if (!a_Entity->IsPickup() || (a_Entity->GetUniqueID() == m_Pickup->GetUniqueID()) || a_Entity->IsDestroyed()) + { + return false; + } + + Vector3d EntityPos = a_Entity->GetPosition(); + double Distance = (EntityPos - m_Position).Length(); + + if ((Distance < 1.2) && ((cPickup *)a_Entity)->GetItem().IsEqual(m_Pickup->GetItem())) + { + m_Pickup->GetItem().AddCount(((cPickup *)a_Entity)->GetItem().m_ItemCount); + a_Entity->Destroy(); + m_FoundMatchingPickup = true; + } + return false; + } + + inline bool FoundMatchingPickup() + { + return m_FoundMatchingPickup; + } + +protected: + bool m_FoundMatchingPickup; + + Vector3d m_Position; + cPickup * m_Pickup; +}; + + + + cPickup::cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) : cEntity(etPickup, a_PosX, a_PosY, a_PosZ, 0.2, 0.2) @@ -83,6 +128,16 @@ void cPickup::Tick(float a_Dt, cChunk & a_Chunk) return; } } + + if (!IsDestroyed()) // Don't try to combine if someone has tried to combine me + { + cPickupCombiningCallback PickupCombiningCallback(GetPosition(), this); + m_World->ForEachEntity(PickupCombiningCallback); // Not ForEachEntityInChunk, otherwise pickups don't combine across chunk boundaries + if (PickupCombiningCallback.FoundMatchingPickup()) + { + m_World->BroadcastEntityMetadata(*this); + } + } } } } -- cgit v1.2.3 From 2a18feb0159da6288efab79e39550b3c31bb71c1 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 25 Jan 2014 10:13:54 -0800 Subject: Stupid Mistake fixed --- src/Bindings/ManualBindings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 4e92da5ae..e7c66c6fb 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2308,12 +2308,12 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "GetFolderContents", tolua_cFile_GetFolderContents); tolua_endmodule(tolua_S); - tolua_beginmodule(tolua_S, "cHopperEntity"); + tolua_beginmodule(tolua_S, "cBlockArea"); tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile); tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); tolua_endmodule(tolua_S); - tolua_beginmodule(tolua_S, "cBlockArea"); + tolua_beginmodule(tolua_S, "cHopperEntity"); tolua_function(tolua_S, "GetOutputBlockPos", tolua_cHopperEntity_GetOutputBlockPos); tolua_endmodule(tolua_S); -- cgit v1.2.3 From ca0e51d89c5b3979f38918b3df7e0f9137f251ce Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 25 Jan 2014 19:19:17 +0100 Subject: Added RSA encryption to crypto wrappers. --- src/Crypto.cpp | 34 ++++++++++++++++++++++++++++++++++ src/Crypto.h | 5 +++++ 2 files changed, 39 insertions(+) diff --git a/src/Crypto.cpp b/src/Crypto.cpp index 5ad866f34..2045d0385 100644 --- a/src/Crypto.cpp +++ b/src/Crypto.cpp @@ -196,6 +196,40 @@ int cRSAPrivateKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLeng +int cRSAPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength) +{ + if (a_EncryptedMaxLength < m_Rsa.len) + { + LOGD("%s: Invalid a_EncryptedMaxLength: got %u, exp at least %u", + __FUNCTION__, (unsigned)a_EncryptedMaxLength, (unsigned)(m_Rsa.len) + ); + ASSERT(!"Invalid a_DecryptedMaxLength!"); + return -1; + } + if (a_PlainLength < m_Rsa.len) + { + LOGD("%s: Invalid a_PlainLength: got %u, exp at least %u", + __FUNCTION__, (unsigned)a_PlainLength, (unsigned)(m_Rsa.len) + ); + ASSERT(!"Invalid a_PlainLength!"); + return -1; + } + size_t DecryptedLength; + int res = rsa_pkcs1_encrypt( + &m_Rsa, ctr_drbg_random, &m_Ctr_drbg, RSA_PUBLIC, + a_PlainLength, a_PlainData, a_EncryptedData + ); + if (res != 0) + { + return -1; + } + return (int)DecryptedLength; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cAESCFBDecryptor: diff --git a/src/Crypto.h b/src/Crypto.h index 6b576f55b..a97f34fbf 100644 --- a/src/Crypto.h +++ b/src/Crypto.h @@ -43,6 +43,11 @@ public: Returns the number of bytes decrypted, or negative number for error. */ int Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength); + /** Encrypts the data using RSAES-PKCS#1 algorithm. + Both a_EncryptedData and a_DecryptedData must be at least bytes large. + Returns the number of bytes decrypted, or negative number for error. */ + int Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength); + protected: rsa_context m_Rsa; entropy_context m_Entropy; -- cgit v1.2.3 From 8f1890e877467bd458910e4b7e5d8dcaceb25854 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 25 Jan 2014 19:19:37 +0100 Subject: ProtoProxy: Modified to use PolarSSL. --- Tools/ProtoProxy/CMakeLists.txt | 18 +++++++++------ Tools/ProtoProxy/Connection.cpp | 51 ++++++++++++++++------------------------- Tools/ProtoProxy/Connection.h | 12 ++++------ Tools/ProtoProxy/Globals.h | 8 +++---- Tools/ProtoProxy/Server.cpp | 8 ++----- Tools/ProtoProxy/Server.h | 8 +++---- 6 files changed, 45 insertions(+), 60 deletions(-) diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt index f8a01a134..9e233a688 100644 --- a/Tools/ProtoProxy/CMakeLists.txt +++ b/Tools/ProtoProxy/CMakeLists.txt @@ -63,9 +63,11 @@ endif() # Set include paths to the used libraries: include_directories("../../lib") +include_directories("../../lib/polarssl/include") include_directories("../../src") + function(flatten_files arg1) set(res "") foreach(f ${${arg1}}) @@ -77,11 +79,11 @@ endfunction() # Include the libraries: -file(GLOB CRYPTOPP_SRC "../../lib/cryptopp/*.cpp") -file(GLOB CRYPTOPP_HDR "../../lib/cryptopp/*.h") -flatten_files(CRYPTOPP_SRC) -flatten_files(CRYPTOPP_HDR) -source_group("CryptoPP" FILES ${CRYPTOPP_SRC} ${CRYPTOPP_HDR}) +file(GLOB POLARSSL_SRC "../../lib/polarssl/library/*.c") +file(GLOB POLARSSL_HDR "../../lib/polarssl/include/polarssl/*.h") +flatten_files(POLARSSL_SRC) +flatten_files(POLARSSL_HDR) +source_group("PolarSSL" FILES ${POLARSSL_SRC} ${POLARSSL_HDR}) file(GLOB ZLIB_SRC "../../lib/zlib/*.c") file(GLOB ZLIB_HDR "../../lib/zlib/*.h") @@ -96,12 +98,14 @@ set(SHARED_SRC ../../src/StringUtils.cpp ../../src/Log.cpp ../../src/MCLogger.cpp + ../../src/Crypto.cpp ) set(SHARED_HDR ../../src/ByteBuffer.h ../../src/StringUtils.h ../../src/Log.h ../../src/MCLogger.h + ../../src/Crypto.h ) set(SHARED_OSS_SRC ../../src/OSSupport/CriticalSection.cpp @@ -145,8 +149,8 @@ add_executable(ProtoProxy ${SHARED_HDR} ${SHARED_OSS_SRC} ${SHARED_OSS_HDR} - ${CRYPTOPP_SRC} - ${CRYPTOPP_HDR} + ${POLARSSL_SRC} + ${POLARSSL_HDR} ${ZLIB_SRC} ${ZLIB_HDR} ) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index b63935f38..510d3645d 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -378,13 +378,13 @@ bool cConnection::RelayFromServer(void) } case csEncryptedUnderstood: { - m_ServerDecryptor.ProcessData((byte *)Buffer, (byte *)Buffer, res); + m_ServerDecryptor.ProcessData((Byte *)Buffer, (Byte *)Buffer, res); DataLog(Buffer, res, "Decrypted %d bytes from the SERVER", res); return DecodeServersPackets(Buffer, res); } case csEncryptedUnknown: { - m_ServerDecryptor.ProcessData((byte *)Buffer, (byte *)Buffer, res); + m_ServerDecryptor.ProcessData((Byte *)Buffer, (Byte *)Buffer, res); DataLog(Buffer, res, "Decrypted %d bytes from the SERVER", res); return CLIENTSEND(Buffer, res); } @@ -423,7 +423,7 @@ bool cConnection::RelayFromClient(void) case csEncryptedUnknown: { DataLog(Buffer, res, "Decrypted %d bytes from the CLIENT", res); - m_ServerEncryptor.ProcessData((byte *)Buffer, (byte *)Buffer, res); + m_ServerEncryptor.ProcessData((Byte *)Buffer, (Byte *)Buffer, res); return SERVERSEND(Buffer, res); } } @@ -473,13 +473,13 @@ bool cConnection::SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a -bool cConnection::SendEncryptedData(SOCKET a_Socket, Encryptor & a_Encryptor, const char * a_Data, int a_Size, const char * a_Peer) +bool cConnection::SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, int a_Size, const char * a_Peer) { DataLog(a_Data, a_Size, "Encrypting %d bytes to %s", a_Size, a_Peer); - const byte * Data = (const byte *)a_Data; + const Byte * Data = (const Byte *)a_Data; while (a_Size > 0) { - byte Buffer[64 KiB]; + Byte Buffer[64 KiB]; int NumBytes = (a_Size > sizeof(Buffer)) ? sizeof(Buffer) : a_Size; a_Encryptor.ProcessData(Buffer, Data, NumBytes); bool res = SendData(a_Socket, (const char *)Buffer, NumBytes, a_Peer); @@ -497,7 +497,7 @@ bool cConnection::SendEncryptedData(SOCKET a_Socket, Encryptor & a_Encryptor, co -bool cConnection::SendEncryptedData(SOCKET a_Socket, Encryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer) +bool cConnection::SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer) { AString All; a_Data.ReadAll(All); @@ -2701,7 +2701,7 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata) int Length = 0; switch (Type) { - case 0: Length = 1; break; // byte + case 0: Length = 1; break; // Byte case 1: Length = 2; break; // short case 2: Length = 4; break; // int case 3: Length = 4; break; // float @@ -2860,37 +2860,26 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) void cConnection::SendEncryptionKeyResponse(const AString & a_ServerPublicKey, const AString & a_Nonce) { // Generate the shared secret and encrypt using the server's public key - byte SharedSecret[16]; - byte EncryptedSecret[128]; + Byte SharedSecret[16]; + Byte EncryptedSecret[128]; memset(SharedSecret, 0, sizeof(SharedSecret)); // Use all zeroes for the initial secret - RSA::PublicKey pk; - CryptoPP::StringSource src(a_ServerPublicKey, true); - ByteQueue bq; - src.TransferTo(bq); - bq.MessageEnd(); - pk.Load(bq); - RSAES::Encryptor rsaEncryptor(pk); - RandomPool rng; - time_t CurTime = time(NULL); - rng.Put((const byte *)&CurTime, sizeof(CurTime)); - int EncryptedLength = rsaEncryptor.FixedCiphertextLength(); - ASSERT(EncryptedLength <= sizeof(EncryptedSecret)); - rsaEncryptor.Encrypt(rng, SharedSecret, sizeof(SharedSecret), EncryptedSecret); - m_ServerEncryptor.SetKey(SharedSecret, 16, MakeParameters(Name::IV(), ConstByteArrayParameter(SharedSecret, 16, true))(Name::FeedbackSize(), 1)); - m_ServerDecryptor.SetKey(SharedSecret, 16, MakeParameters(Name::IV(), ConstByteArrayParameter(SharedSecret, 16, true))(Name::FeedbackSize(), 1)); + m_Server.GetPrivateKey().Encrypt(SharedSecret, sizeof(SharedSecret), EncryptedSecret, sizeof(EncryptedSecret)); + + m_ServerEncryptor.Init(SharedSecret, SharedSecret); + m_ServerDecryptor.Init(SharedSecret, SharedSecret); // Encrypt the nonce: - byte EncryptedNonce[128]; - rsaEncryptor.Encrypt(rng, (const byte *)(a_Nonce.data()), a_Nonce.size(), EncryptedNonce); + Byte EncryptedNonce[128]; + m_Server.GetPrivateKey().Encrypt((const Byte *)a_Nonce.data(), a_Nonce.size(), EncryptedNonce, sizeof(EncryptedNonce)); // Send the packet to the server: Log("Sending PACKET_ENCRYPTION_KEY_RESPONSE to the SERVER"); cByteBuffer ToServer(1024); ToServer.WriteByte(0x01); // To server: Encryption key response - ToServer.WriteBEShort(EncryptedLength); - ToServer.WriteBuf(EncryptedSecret, EncryptedLength); - ToServer.WriteBEShort(EncryptedLength); - ToServer.WriteBuf(EncryptedNonce, EncryptedLength); + ToServer.WriteBEShort((short)sizeof(EncryptedSecret)); + ToServer.WriteBuf(EncryptedSecret, sizeof(EncryptedSecret)); + ToServer.WriteBEShort((short)sizeof(EncryptedNonce)); + ToServer.WriteBuf(EncryptedNonce, sizeof(EncryptedNonce)); SERVERSEND(ToServer); m_ServerState = csEncryptedUnderstood; m_IsServerEncrypted = true; diff --git a/Tools/ProtoProxy/Connection.h b/Tools/ProtoProxy/Connection.h index abb8b6cd0..5e4f8cd7b 100644 --- a/Tools/ProtoProxy/Connection.h +++ b/Tools/ProtoProxy/Connection.h @@ -62,14 +62,12 @@ public: void LogFlush(void); protected: - typedef CFB_Mode::Encryption Encryptor; - typedef CFB_Mode::Decryption Decryptor; - + cByteBuffer m_ClientBuffer; cByteBuffer m_ServerBuffer; - Decryptor m_ServerDecryptor; - Encryptor m_ServerEncryptor; + cAESCFBDecryptor m_ServerDecryptor; + cAESCFBEncryptor m_ServerEncryptor; AString m_ServerEncryptionBuffer; // Buffer for the data to be sent to the server once encryption is established @@ -111,10 +109,10 @@ protected: bool SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a_Peer); /// Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false - bool SendEncryptedData(SOCKET a_Socket, Encryptor & a_Encryptor, const char * a_Data, int a_Size, const char * a_Peer); + bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, int a_Size, const char * a_Peer); /// Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false - bool SendEncryptedData(SOCKET a_Socket, Encryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer); + bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer); /// Decodes packets coming from the client, sends appropriate counterparts to the server; returns false if the connection is to be dropped bool DecodeClientsPackets(const char * a_Data, int a_Size); diff --git a/Tools/ProtoProxy/Globals.h b/Tools/ProtoProxy/Globals.h index 7415c9e62..547903e7a 100644 --- a/Tools/ProtoProxy/Globals.h +++ b/Tools/ProtoProxy/Globals.h @@ -74,6 +74,8 @@ typedef unsigned long long UInt64; typedef unsigned int UInt32; typedef unsigned short UInt16; +typedef unsigned char Byte; + @@ -223,12 +225,8 @@ public: -#include "cryptopp/randpool.h" -#include "cryptopp/aes.h" -#include "cryptopp/rsa.h" -#include "cryptopp/modes.h" +#include "../../src/Crypto.h" -using namespace CryptoPP; diff --git a/Tools/ProtoProxy/Server.cpp b/Tools/ProtoProxy/Server.cpp index 71b5ecb94..bb042b259 100644 --- a/Tools/ProtoProxy/Server.cpp +++ b/Tools/ProtoProxy/Server.cpp @@ -34,12 +34,8 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort) #endif // _WIN32 printf("Generating protocol encryption keypair...\n"); - time_t CurTime = time(NULL); - RandomPool rng; - rng.Put((const byte *)&CurTime, sizeof(CurTime)); - m_PrivateKey.GenerateRandomWithKeySize(rng, 1024); - RSA::PublicKey pk(m_PrivateKey); - m_PublicKey = pk; + m_PrivateKey.Generate(); + m_PublicKeyDER = m_PrivateKey.GetPubKeyDER(); m_ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); sockaddr_in local; diff --git a/Tools/ProtoProxy/Server.h b/Tools/ProtoProxy/Server.h index e69dbb5e0..85f817a4d 100644 --- a/Tools/ProtoProxy/Server.h +++ b/Tools/ProtoProxy/Server.h @@ -17,8 +17,8 @@ class cServer { SOCKET m_ListenSocket; - RSA::PrivateKey m_PrivateKey; - RSA::PublicKey m_PublicKey; + cRSAPrivateKey m_PrivateKey; + AString m_PublicKeyDER; short m_ConnectPort; public: @@ -27,8 +27,8 @@ public: int Init(short a_ListenPort, short a_ConnectPort); void Run(void); - RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; } - RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; } + cRSAPrivateKey & GetPrivateKey(void) { return m_PrivateKey; } + const AString & GetPublicKeyDER (void) { return m_PublicKeyDER; } short GetConnectPort(void) const { return m_ConnectPort; } } ; -- cgit v1.2.3 From 03b08456b6361cffc37f71bda7ac93da915a80d9 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 25 Jan 2014 10:23:18 -0800 Subject: dded dependecy on Blocks to Generator --- src/Generating/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generating/CMakeLists.txt b/src/Generating/CMakeLists.txt index 793f48890..1147744c0 100644 --- a/src/Generating/CMakeLists.txt +++ b/src/Generating/CMakeLists.txt @@ -10,4 +10,4 @@ file(GLOB SOURCE add_library(Generating ${SOURCE}) -target_link_libraries(Generating OSSupport iniFile) +target_link_libraries(Generating OSSupport iniFile Blocks) -- cgit v1.2.3 From 60b7f5f23d117d48f230f80371b2adf13b85a09e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 25 Jan 2014 19:00:50 +0000 Subject: Attack() is no longer always called --- src/Mobs/AggressiveMonster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index a4b3eede1..f2f0c404c 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -50,9 +50,9 @@ void cAggressiveMonster::InStateChasing(float a_Dt) void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity) { - super::EventSeePlayer(a_Entity); if (!((cPlayer *)a_Entity)->IsGameModeCreative()) { + super::EventSeePlayer(a_Entity); m_EMState = CHASING; } } -- cgit v1.2.3 From 7468ba0f107ed01275f346c87ff5bb265dbbff3d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 25 Jan 2014 19:02:13 +0000 Subject: Implemented fall damage for mobs + Implemented mobile fall damage * Formatting fixes + Defined new Position->Integer macros --- src/Entities/Entity.h | 5 +++++ src/Entities/Player.cpp | 6 ++---- src/Entities/Player.h | 2 +- src/Mobs/Monster.cpp | 31 +++++++++++++++++++++++++++---- src/Mobs/Monster.h | 8 ++++++-- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index f6fa58bb2..b2edfc2b4 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -29,6 +29,11 @@ return super::GetClass(); \ } +#define POSX_TOINT (int)floor(GetPosX()) +#define POSY_TOINT (int)floor(GetPosY()) +#define POSZ_TOINT (int)floor(GetPosZ()) +#define POS_TOINT Vector3i(POSXTOINT, POSYTOINT, POSZTOINT) + diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 2a5baedb6..71e304967 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -26,8 +26,6 @@ #include "inifile/iniFile.h" #include "json/json.h" -#define float2int(x) ((x)<0 ? ((int)(x))-1 : (int)(x)) - @@ -440,7 +438,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) cWorld * World = GetWorld(); if ((GetPosY() >= 0) && (GetPosY() < cChunkDef::Height)) { - BLOCKTYPE BlockType = World->GetBlock(float2int(GetPosX()), float2int(GetPosY()), float2int(GetPosZ())); + BLOCKTYPE BlockType = World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); if (BlockType != E_BLOCK_AIR) { m_bTouchGround = true; @@ -470,7 +468,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) TakeDamage(dtFalling, NULL, Damage, Damage, 0); } - // Mojang uses floor() to get X and Z positions, instead of just casting it to an (int) + // Fall particles GetWorld()->BroadcastSoundParticleEffect(2006, (int)floor(GetPosX()), (int)GetPosY() - 1, (int)floor(GetPosZ()), Damage /* Used as particle effect speed modifier */); } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 449df978f..50f7560d6 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -415,7 +415,7 @@ protected: float m_LastBlockActionTime; int m_LastBlockActionCnt; eGameMode m_GameMode; - std::string m_IP; + AString m_IP; /// The item being dragged by the cursor while in a UI window cItem m_DraggingItem; diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 9ba18f4d1..42c7d2899 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -82,6 +82,7 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_AttackRange(2) , m_AttackInterval(0) , m_BurnsInDaylight(false) + , m_LastGroundHeight(POSY_TOINT) { if (!a_ConfigName.empty()) { @@ -113,7 +114,7 @@ void cMonster::TickPathFinding() std::vector m_PotentialCoordinates; m_TraversedCoordinates.push_back(Vector3i(PosX, PosY, PosZ)); - static const struct // Define which directions the torch can power + static const struct // Define which directions to try to move to { int x, z; } gCrossCoords[] = @@ -261,9 +262,9 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) { if (m_bOnGround) { - int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z); + m_Destination.y = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z); - if (DoesPosYRequireJump(NextHeight)) + if (DoesPosYRequireJump(m_Destination.y)) { m_bOnGround = false; AddPosY(1.5); // Jump!! @@ -298,10 +299,11 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) } } - if (ReachedFinalDestination()) + if (ReachedFinalDestination() && (m_Target != NULL)) Attack(a_Dt); SetPitchAndYawFromDestination(); + HandleFalling(); switch (m_EMState) { @@ -369,6 +371,27 @@ void cMonster::SetPitchAndYawFromDestination() +void cMonster::HandleFalling() +{ + if (m_bOnGround) + { + int Damage = (m_LastGroundHeight - POSY_TOINT) - 3; + + if (Damage > 0) + { + TakeDamage(dtFalling, NULL, Damage, Damage, 0); + + // Fall particles + GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, POSY_TOINT - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */); + } + + m_LastGroundHeight = (int)floor(GetPosY()); + } +} + + + + int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) { int PosY = (int)floor(GetPosY()); diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index d04cb8941..1dd302cdc 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -199,9 +199,13 @@ protected: /** Sets the body yaw and head yaw/pitch based on next/ultimate destinations */ void SetPitchAndYawFromDestination(void); - /* ===========================*/ + /* =========================== */ + /* ========= FALLING ========= */ - + virtual void HandleFalling(void); + int m_LastGroundHeight; + + /* =========================== */ float m_IdleInterval; float m_DestroyTimer; -- cgit v1.2.3 From 6fa3a0cf70bd631fe809c006e5b315199086cc59 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 25 Jan 2014 19:05:44 +0000 Subject: Two minor changes --- src/ClientHandle.cpp | 2 +- src/Entities/Player.cpp | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 18e3d560e..68bf28af7 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -620,7 +620,7 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a } else { - SendChat(Printf("%s[INFO]%s Command blocks are not enabled on this server", cChatColor::Green.c_str(), cChatColor::White.c_str())); + SendChat(Printf("%s[INFO]%s Command blocks are not enabled on this server", cChatColor::Yellow.c_str(), cChatColor::White.c_str())); } } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 71e304967..82e31ae65 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -463,10 +463,8 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) if (Damage > 0) { - if (!IsGameModeCreative()) - { - TakeDamage(dtFalling, NULL, Damage, Damage, 0); - } + // cPlayer makes sure damage isn't applied in creative, no need to check here + TakeDamage(dtFalling, NULL, Damage, Damage, 0); // Fall particles GetWorld()->BroadcastSoundParticleEffect(2006, (int)floor(GetPosX()), (int)GetPosY() - 1, (int)floor(GetPosZ()), Damage /* Used as particle effect speed modifier */); @@ -790,7 +788,7 @@ void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if (IsGameModeCreative()) { - // No damage / health in creative mode + // No damage / health in creative mode if not void damage return; } } -- cgit v1.2.3 From 15b92af166e03e3deb8baf5eb2ec6b0be5981646 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 25 Jan 2014 11:14:14 -0800 Subject: First attempt at Implementing Interfaces --- src/Blocks/BlockBed.cpp | 32 ++++++++++++++++---------------- src/Blocks/BlockBed.h | 9 +++++---- src/Blocks/BlockButton.h | 2 +- src/Blocks/BlockCauldron.h | 2 +- src/Blocks/BlockComparator.h | 2 +- src/Blocks/BlockDoor.cpp | 2 +- src/Blocks/BlockDoor.h | 2 +- src/Blocks/BlockEntity.h | 2 +- src/Blocks/BlockFenceGate.h | 2 +- src/Blocks/BlockFlowerPot.h | 2 +- src/Blocks/BlockHandler.cpp | 2 +- src/Blocks/BlockHandler.h | 3 ++- src/Blocks/BlockRedstoneRepeater.h | 2 +- src/Blocks/BlockTrapdoor.h | 2 +- src/Blocks/BlockWorkbench.h | 2 +- src/Blocks/ChunkInterface.h | 26 ++++++++++++++++++++++++++ src/Blocks/WorldInterface.h | 13 +++++++++++++ src/ClientHandle.cpp | 2 +- src/World.h | 9 +++++---- 19 files changed, 80 insertions(+), 38 deletions(-) create mode 100644 src/Blocks/ChunkInterface.h create mode 100644 src/Blocks/WorldInterface.h diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 66eb9130c..9c6f15698 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -6,7 +6,7 @@ void cBlockBedHandler::OnPlacedByPlayer( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -15,7 +15,7 @@ void cBlockBedHandler::OnPlacedByPlayer( if (a_BlockMeta < 8) { Vector3i Direction = MetaDataToDirection(a_BlockMeta); - a_World->SetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); + a_ChunkInterface->SetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); } } @@ -23,26 +23,26 @@ void cBlockBedHandler::OnPlacedByPlayer( -void cBlockBedHandler::OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockBedHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE OldMeta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); Vector3i ThisPos( a_BlockX, a_BlockY, a_BlockZ ); Vector3i Direction = MetaDataToDirection( OldMeta & 0x7 ); if (OldMeta & 0x8) { // Was pillow - if (a_World->GetBlock(ThisPos - Direction) == E_BLOCK_BED) + if (a_ChunkInterface->GetBlock(ThisPos - Direction) == E_BLOCK_BED) { - a_World->FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0); } } else { // Was foot end - if (a_World->GetBlock(ThisPos + Direction) == E_BLOCK_BED) + if (a_ChunkInterface->GetBlock(ThisPos + Direction) == E_BLOCK_BED) { - a_World->FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0); } } } @@ -51,30 +51,30 @@ void cBlockBedHandler::OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, -void cBlockBedHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockBedHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { - if (a_World->GetDimension() != dimOverworld) + if (a_WorldInterface->GetDimension() != dimOverworld) { Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ); - a_World->DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); + a_ChunkInterface->DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); } else { - if (a_World->GetTimeOfDay() > 13000) + if (a_WorldInterface->GetTimeOfDay() > 13000) { - NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); if (Meta & 0x8) { // Is pillow - a_World->BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_WorldInterface->BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); } else { // Is foot end Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); - if (a_World->GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + if (a_ChunkInterface->GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping { - a_World->BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + a_WorldInterface->BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); } } } else { diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 8a289b22c..2004effb5 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -2,7 +2,8 @@ #pragma once #include "BlockHandler.h" -#include "../World.h" +#include "ChunkInterface.h" +#include "WorldInterface.h" #include "../Entities/Player.h" @@ -19,9 +20,9 @@ public: } - virtual void OnPlacedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; - virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override; - virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; + virtual void OnPlacedByPlayer(cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; + virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; virtual bool IsUseable(void) override diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index c898a0466..7d75c5bad 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -16,7 +16,7 @@ public: } - virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Set p the ON bit to on NIBBLETYPE Meta = (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); diff --git a/src/Blocks/BlockCauldron.h b/src/Blocks/BlockCauldron.h index b0e00f869..9dd486a0a 100644 --- a/src/Blocks/BlockCauldron.h +++ b/src/Blocks/BlockCauldron.h @@ -21,7 +21,7 @@ public: a_Pickups.push_back(cItem(E_ITEM_CAULDRON, 1, 0)); } - void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) + void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) { char Meta = a_World->GetBlockMeta( a_BlockX, a_BlockY, a_BlockZ ); switch( a_Player->GetEquippedItem().m_ItemType ) diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index 5a8e54eda..732afd9f6 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -18,7 +18,7 @@ public: } - virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); Meta ^= 0x04; // Toggle 3rd (addition/subtraction) bit with XOR diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index e91211559..20b0a6324 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -44,7 +44,7 @@ void cBlockDoorHandler::OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY -void cBlockDoorHandler::OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockDoorHandler::OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_DOOR) { diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 1e86446dd..cf0572284 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -16,7 +16,7 @@ public: cBlockDoorHandler(BLOCKTYPE a_BlockType); virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override; - virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; + virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; virtual const char * GetStepSound(void) override; diff --git a/src/Blocks/BlockEntity.h b/src/Blocks/BlockEntity.h index 9c6b23665..073b5fc49 100644 --- a/src/Blocks/BlockEntity.h +++ b/src/Blocks/BlockEntity.h @@ -15,7 +15,7 @@ public: { } - virtual void OnUse(cWorld * a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { a_World->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); } diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index 779f12ee1..ff4f80c3c 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -30,7 +30,7 @@ public: } - virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { NIBBLETYPE OldMetaData = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); NIBBLETYPE NewMetaData = PlayerYawToMetaData(a_Player->GetYaw()); diff --git a/src/Blocks/BlockFlowerPot.h b/src/Blocks/BlockFlowerPot.h index b0faf5218..4de85f629 100644 --- a/src/Blocks/BlockFlowerPot.h +++ b/src/Blocks/BlockFlowerPot.h @@ -44,7 +44,7 @@ public: } - void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) + void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) { NIBBLETYPE Meta = a_World->GetBlockMeta( a_BlockX, a_BlockY, a_BlockZ ); if (Meta != 0) diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index b9c0887ce..1997c87d4 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -342,7 +342,7 @@ void cBlockHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, -void cBlockHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockHandler::OnUse(cWorld *a_World, cWorldInterface * a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { } diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index a732aa797..6b28c60ab 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -4,6 +4,7 @@ #include "../Defines.h" #include "../Item.h" #include "../Chunk.h" +#include "WorldInterface.h" @@ -65,7 +66,7 @@ public: virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called if the user right clicks the block and the block is useable - virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); + virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); /// Called when the item is mined to convert it into pickups. Pickups may specify multiple items. Appends items to a_Pickups, preserves its original contents virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta); diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h index 713664659..18aa765a6 100644 --- a/src/Blocks/BlockRedstoneRepeater.h +++ b/src/Blocks/BlockRedstoneRepeater.h @@ -30,7 +30,7 @@ public: } - virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f)); } diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 57718b45f..1843c1221 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -32,7 +32,7 @@ public: return true; } - virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Flip the ON bit on/off using the XOR bitwise operation NIBBLETYPE Meta = (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x04); diff --git a/src/Blocks/BlockWorkbench.h b/src/Blocks/BlockWorkbench.h index a2cc6119c..d15447db4 100644 --- a/src/Blocks/BlockWorkbench.h +++ b/src/Blocks/BlockWorkbench.h @@ -19,7 +19,7 @@ public: } - virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { cWindow * Window = new cCraftingWindow(a_BlockX, a_BlockY, a_BlockZ); a_Player->OpenWindow(Window); diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h new file mode 100644 index 000000000..91a635dcf --- /dev/null +++ b/src/Blocks/ChunkInterface.h @@ -0,0 +1,26 @@ + +#pragma once + +class cChunkInterface +{ +public: + + BLOCKTYPE GetBlock (int a_BlockX, int a_BlockY, int a_BlockZ); + BLOCKTYPE GetBlock (const Vector3i & a_Pos ) { return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z ); } + NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ); + + /** Sets the block at the specified coords to the specified value. + Full processing, incl. updating neighbors, is performed. + */ + void SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + + + /** Sets the block at the specified coords to the specified value. + The replacement doesn't trigger block updates. + The replaced blocks aren't checked for block entities (block entity is leaked if it exists at this block) + */ + void FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + void FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) { FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta ); } + + void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); +}; diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h new file mode 100644 index 000000000..8cf2103d1 --- /dev/null +++ b/src/Blocks/WorldInterface.h @@ -0,0 +1,13 @@ + +#pragma once + +class cWorldInterface +{ +public: + + virtual Int64 GetTimeOfDay(void) const; + + virtual eDimension GetDimension(void) const; + + virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ); +}; diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 0a2d3c1be..083dad833 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -916,7 +916,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, c // A plugin doesn't agree with using the block, abort return; } - BlockHandler->OnUse(World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ); + BlockHandler->OnUse(World, World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ); PlgMgr->CallHookPlayerUsedBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta); return; } diff --git a/src/World.h b/src/World.h index d941772aa..c5852f118 100644 --- a/src/World.h +++ b/src/World.h @@ -24,6 +24,7 @@ #include "Entities/ProjectileEntity.h" #include "ForEachChunkProvider.h" #include "Scoreboard.h" +#include "Blocks/WorldInterface.h" @@ -62,7 +63,7 @@ typedef cItemCallback cCommandBlockCallback; // tolua_begin -class cWorld : public cForEachChunkProvider +class cWorld : public cForEachChunkProvider, public cWorldInterface { public: @@ -107,7 +108,7 @@ public: int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; } Int64 GetWorldAge(void) const { return m_WorldAge; } - Int64 GetTimeOfDay(void) const { return m_TimeOfDay; } + virtual Int64 GetTimeOfDay(void) const { return m_TimeOfDay; } void SetTicksUntilWeatherChange(int a_WeatherInterval) { @@ -138,7 +139,7 @@ public: bool ShouldLavaSpawnFire(void) const { return m_ShouldLavaSpawnFire; } - eDimension GetDimension(void) const { return m_Dimension; } + virtual eDimension GetDimension(void) const { return m_Dimension; } /** Returns the world height at the specified coords; waits for the chunk to get loaded / generated */ int GetHeight(int a_BlockX, int a_BlockZ); @@ -180,7 +181,7 @@ public: void BroadcastTeleportEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL); - void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ); + virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ); void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL); /** If there is a block entity at the specified coords, sends it to the client specified */ -- cgit v1.2.3 From 1d0e1bdcb12e648ba2b0b6d54a8bdba4bcaad1d5 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 25 Jan 2014 19:36:20 +0000 Subject: Improved AllToLua UI experience --- src/Bindings/AllToLua.bat | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Bindings/AllToLua.bat b/src/Bindings/AllToLua.bat index b2a192880..f9bcbda45 100644 --- a/src/Bindings/AllToLua.bat +++ b/src/Bindings/AllToLua.bat @@ -4,18 +4,24 @@ :: When called without any parameters, it will pause for a keypress at the end :: Call with any parameter to disable the wait (for buildserver use) +@echo off + :: Regenerate the files: -"tolua++.exe" -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg +echo Regenerating LUA bindings... +"tolua++.exe" -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg >nul : Wait for keypress, if no param given: -if %ALLTOLUA_WAIT%N == N pause +echo Bindings were generated +echo. +echo Please depress the 'any' key to continue +if %ALLTOLUA_WAIT%N == N pause >nul -- cgit v1.2.3 From 7b8dc01db32be3d780f38ffbe788500f82983d62 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 25 Jan 2014 21:19:52 +0100 Subject: Implemented sheeps eating grass. --- src/Mobs/Sheep.cpp | 39 ++++++++++++++++++++++++++++++++++++++- src/Mobs/Sheep.h | 3 +++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index bda4ccff8..702108ae4 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -13,7 +13,8 @@ cSheep::cSheep(int a_Color) : super("Sheep", mtSheep, "mob.sheep.say", "mob.sheep.say", 0.6, 1.3), m_IsSheared(false), - m_WoolColor(a_Color) + m_WoolColor(a_Color), + m_TimeToStopEating(-1) { } @@ -60,3 +61,39 @@ void cSheep::OnRightClicked(cPlayer & a_Player) m_World->BroadcastEntityMetadata(*this); } } + + + + + +void cSheep::Tick(float a_Dt, cChunk & a_Chunk) +{ + // The sheep should not move when he's eating so only handle the physics. + if (m_TimeToStopEating > 0) + { + HandlePhysics(a_Dt, a_Chunk); + m_TimeToStopEating--; + if (m_TimeToStopEating == 0) + { + if (m_World->GetBlock((int) GetPosX(), (int) GetPosY() - 1, (int) GetPosZ()) == E_BLOCK_GRASS) + { + // The sheep ate the grass so we change it to dirt. + m_World->SetBlock((int) GetPosX(), (int) GetPosY() - 1, (int) GetPosZ(), E_BLOCK_DIRT, 0); + m_IsSheared = false; + m_World->BroadcastEntityMetadata(*this); + } + } + } + else + { + super::Tick(a_Dt, a_Chunk); + if (m_World->GetTickRandomNumber(600) == 1) + { + if (m_World->GetBlock((int) GetPosX(), (int) GetPosY() - 1, (int) GetPosZ()) == E_BLOCK_GRASS) + { + m_World->BroadcastEntityStatus(*this, 10); + m_TimeToStopEating = 40; + } + } + } +} diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h index 8293a2c05..4eee3db1c 100644 --- a/src/Mobs/Sheep.h +++ b/src/Mobs/Sheep.h @@ -19,6 +19,8 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void OnRightClicked(cPlayer & a_Player) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + bool IsSheared(void) const { return m_IsSheared; } int GetFurColor(void) const { return m_WoolColor; } @@ -26,6 +28,7 @@ private: bool m_IsSheared; int m_WoolColor; + int m_TimeToStopEating; } ; -- cgit v1.2.3 From 398e159f5f3c913079b0f89c6bf4f5fa41466307 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 25 Jan 2014 20:33:23 +0000 Subject: Rail speed tweak --- src/Entities/Minecart.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 78ec017cd..a650927b1 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -416,8 +416,8 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) { // Initialise to 'slow down' values - int AccelDecelSpeed = -1; - int AccelDecelNegSpeed = 1; + int AccelDecelSpeed = -2; + int AccelDecelNegSpeed = 2; if ((a_RailMeta & 0x8) == 0x8) { -- cgit v1.2.3 From cdd6478ceacb7cf5bab8f425390372fca7883a1e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 25 Jan 2014 21:29:27 +0000 Subject: Did what xoft recommended --- src/Mobs/Creeper.cpp | 6 +++++- src/World.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index ad8fe10a1..2e1ece865 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -89,4 +89,8 @@ void cCreeper::Attack(float a_Dt) m_World->DoExplosionAt((m_bIsCharged ? 5 : 3), GetPosX(), GetPosY(), GetPosZ(), false, esMonster, this); Destroy(); } -} \ No newline at end of file +} + + + + diff --git a/src/World.cpp b/src/World.cpp index 514524991..5205c2616 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -235,7 +235,7 @@ cWorld::cWorld(const AString & a_WorldName) : m_IniFileName(m_WorldName + "/world.ini"), m_StorageSchema("Default"), #ifdef _arm_ - m_StorageCompressionFactor(3), + m_StorageCompressionFactor(0), #else m_StorageCompressionFactor(6), #endif -- cgit v1.2.3 From a2d3eea80be80be6c522943222c02b3861329e55 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 25 Jan 2014 15:02:31 -0800 Subject: Added support for overide in c++11 supporting varients of gcc/clang --- src/Globals.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Globals.h b/src/Globals.h index d2080b8eb..6c0b4e0fd 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -44,8 +44,10 @@ // TODO: Can GCC explicitly mark classes as abstract (no instances can be created)? #define abstract - // TODO: Can GCC mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class) - #define override + // override is part of c++11 + #if __cplusplus < 201103L + #define override + #endif #define OBSOLETE __attribute__((deprecated)) -- cgit v1.2.3 From 52f7467fe1d0c9ce68259b43cf6f74227318dda8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 25 Jan 2014 23:48:48 +0000 Subject: Reduced unnecessary echoes (thanks xoft) --- src/Bindings/AllToLua.bat | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Bindings/AllToLua.bat b/src/Bindings/AllToLua.bat index f9bcbda45..f085af9e9 100644 --- a/src/Bindings/AllToLua.bat +++ b/src/Bindings/AllToLua.bat @@ -11,17 +11,15 @@ :: Regenerate the files: -echo Regenerating LUA bindings... -"tolua++.exe" -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg >nul +echo Regenerating LUA bindings . . . +"tolua++.exe" -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg : Wait for keypress, if no param given: -echo Bindings were generated echo. -echo Please depress the 'any' key to continue -if %ALLTOLUA_WAIT%N == N pause >nul +if %ALLTOLUA_WAIT%N == N pause -- cgit v1.2.3 From 70113b57309060b785b070bb2a0075801bc4d844 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 26 Jan 2014 00:14:00 +0000 Subject: Fixed segmentation fault on villager damage It occurred when attack was environmental. --- src/Mobs/Villager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 7f89fb6cc..c8ff4f101 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -21,7 +21,7 @@ cVillager::cVillager(eVillagerType VillagerType) : void cVillager::DoTakeDamage(TakeDamageInfo & a_TDI) { super::DoTakeDamage(a_TDI); - if (a_TDI.Attacker->IsPlayer()) + if ((a_TDI.Attacker != NULL) && a_TDI.Attacker->IsPlayer()) { if (m_World->GetTickRandomNumber(5) == 3) { -- cgit v1.2.3 From a533386144f234dcfb61ad6bc5341712ea244afd Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 26 Jan 2014 13:07:21 +0100 Subject: Small fix since the new AI and a new small feature. You get particles when trying to tame wolfs. They don't walk anymore when they are sitting. --- src/Mobs/Wolf.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 11e3f690a..217834eb1 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -75,10 +75,12 @@ void cWolf::OnRightClicked(cPlayer & a_Player) SetIsTame(true); SetOwner(a_Player.GetName()); m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED); + m_World->BroadcastParticleEffect("heart", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5); } else { m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMING); + m_World->BroadcastParticleEffect("smoke", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5); } } } @@ -122,7 +124,8 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); } - + + // The wolf is sitting so don't move him at all. if (IsSitting()) { m_bMovingToDestination = false; @@ -145,8 +148,18 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) SetIsBegging(true); m_World->BroadcastEntityMetadata(*this); } - m_FinalDestination = a_Closest_Player->GetPosition();; - m_bMovingToDestination = false; + // Don't move to the player if the wolf is sitting. + if (IsSitting()) + { + m_bMovingToDestination = false; + } + else + { + m_bMovingToDestination = true; + } + Vector3d PlayerPos = a_Closest_Player->GetPosition(); + PlayerPos.y++; + m_FinalDestination = PlayerPos; break; } default: @@ -185,15 +198,23 @@ void cWolf::TickFollowPlayer() } Callback; if (m_World->DoWithPlayer(m_OwnerName, Callback)) { - // The player is present in the world, follow them: + // The player is present in the world, follow him: double Distance = (Callback.OwnerPos - GetPosition()).Length(); - if ((Distance > 30) && (!IsSitting())) + if (Distance > 30) { TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z); } else { - MoveToPosition(Callback.OwnerPos); + m_FinalDestination = Callback.OwnerPos; + if (IsSitting()) + { + m_bMovingToDestination = false; + } + else + { + m_bMovingToDestination = true; + } } } } -- cgit v1.2.3 From 4c780e7b4490c34694e9f76e6944d5959299eb84 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 26 Jan 2014 13:27:35 +0100 Subject: Fixed bug where wolfs would teleport while they were sitting. --- src/Mobs/Wolf.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 217834eb1..c0c7892e3 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -202,7 +202,10 @@ void cWolf::TickFollowPlayer() double Distance = (Callback.OwnerPos - GetPosition()).Length(); if (Distance > 30) { - TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z); + if (!IsSitting()) + { + TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z); + } } else { -- cgit v1.2.3 From 14e48ccb4bbad6f43121dc27f042083cda160f45 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 26 Jan 2014 06:20:39 -0800 Subject: Refactored cBlockHandler::OnUse and dependents --- src/Blocks/BlockBed.cpp | 10 +-- src/Blocks/BlockBed.h | 2 +- src/Blocks/BlockButton.h | 12 ++-- src/Blocks/BlockCarpet.h | 2 +- src/Blocks/BlockCauldron.h | 8 +-- src/Blocks/BlockChest.h | 26 ++++---- src/Blocks/BlockEntity.h | 4 +- src/Blocks/BlockHandler.cpp | 36 +++++----- src/Blocks/BlockHandler.h | 12 ++-- src/Blocks/BlockLeaves.h | 8 +-- src/Blocks/BlockRail.h | 142 ++++++++++++++++++++-------------------- src/Blocks/BlockWorkbench.h | 2 +- src/Blocks/BroadcastInterface.h | 10 +++ src/Blocks/ChunkInterface.h | 58 ++++++++++++++-- src/Blocks/WorldInterface.h | 18 ++++- src/ChunkDef.h | 1 - src/ChunkMap.cpp | 59 ++++++++++++++++- src/ChunkMap.h | 9 ++- src/ClientHandle.cpp | 5 +- src/World.cpp | 93 ++------------------------ src/World.h | 56 ++++++++-------- 21 files changed, 310 insertions(+), 263 deletions(-) create mode 100644 src/Blocks/BroadcastInterface.h diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 9c6f15698..02cdd58c7 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -6,7 +6,7 @@ void cBlockBedHandler::OnPlacedByPlayer( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -15,7 +15,7 @@ void cBlockBedHandler::OnPlacedByPlayer( if (a_BlockMeta < 8) { Vector3i Direction = MetaDataToDirection(a_BlockMeta); - a_ChunkInterface->SetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); + a_ChunkInterface->SetBlock(a_WorldInterface,a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); } } @@ -56,7 +56,7 @@ void cBlockBedHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface if (a_WorldInterface->GetDimension() != dimOverworld) { Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ); - a_ChunkInterface->DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); + a_WorldInterface->DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); } else { @@ -66,7 +66,7 @@ void cBlockBedHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface if (Meta & 0x8) { // Is pillow - a_WorldInterface->BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_WorldInterface->GetBroadcastManager()->BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); } else { @@ -74,7 +74,7 @@ void cBlockBedHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); if (a_ChunkInterface->GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping { - a_WorldInterface->BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + a_WorldInterface->GetBroadcastManager()->BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); } } } else { diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 2004effb5..8c2063443 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -20,7 +20,7 @@ public: } - virtual void OnPlacedByPlayer(cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; + virtual void OnPlacedByPlayer(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 7d75c5bad..53c905576 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -16,16 +16,16 @@ public: } - virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Set p the ON bit to on - NIBBLETYPE Meta = (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); + NIBBLETYPE Meta = (a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); - a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); - a_World->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); + a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); + a_WorldInterface->GetBroadcastManager()->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); // Queue a button reset (unpress) - a_World->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 30, m_BlockType); + a_ChunkInterface->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 30, m_BlockType, a_WorldInterface); } @@ -43,7 +43,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockCarpet.h b/src/Blocks/BlockCarpet.h index 5eafd8c21..22fd97710 100644 --- a/src/Blocks/BlockCarpet.h +++ b/src/Blocks/BlockCarpet.h @@ -31,7 +31,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockCauldron.h b/src/Blocks/BlockCauldron.h index 9dd486a0a..09d5c3cbb 100644 --- a/src/Blocks/BlockCauldron.h +++ b/src/Blocks/BlockCauldron.h @@ -21,14 +21,14 @@ public: a_Pickups.push_back(cItem(E_ITEM_CAULDRON, 1, 0)); } - void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) + void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) { - char Meta = a_World->GetBlockMeta( a_BlockX, a_BlockY, a_BlockZ ); + char Meta = a_ChunkInterface->GetBlockMeta( a_BlockX, a_BlockY, a_BlockZ ); switch( a_Player->GetEquippedItem().m_ItemType ) { case E_ITEM_WATER_BUCKET: { - a_World->SetBlockMeta( a_BlockX, a_BlockY, a_BlockZ, 3 ); + a_ChunkInterface->SetBlockMeta( a_BlockX, a_BlockY, a_BlockZ, 3 ); a_Player->GetInventory().RemoveOneEquippedItem(); cItem NewItem(E_ITEM_BUCKET, 1); a_Player->GetInventory().AddItem(NewItem); @@ -38,7 +38,7 @@ public: { if( Meta > 0 ) { - a_World->SetBlockMeta( a_BlockX, a_BlockY, a_BlockZ, --Meta); + a_ChunkInterface->SetBlockMeta( a_BlockX, a_BlockY, a_BlockZ, --Meta); a_Player->GetInventory().RemoveOneEquippedItem(); cItem NewItem(E_ITEM_POTIONS, 1, 0); a_Player->GetInventory().AddItem(NewItem); diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 88f7c4b32..23f969dbe 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -21,7 +21,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -30,7 +30,7 @@ public: a_BlockType = m_BlockType; // Is there a doublechest already next to this block? - if (!CanBeAt(a_World, a_BlockX, a_BlockY, a_BlockZ)) + if (!CanBeAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ)) { // Yup, cannot form a triple-chest, refuse: return false; @@ -38,7 +38,7 @@ public: // Check if this forms a doublechest, if so, need to adjust the meta: cBlockArea Area; - if (!Area.Read(a_World, a_BlockX - 1, a_BlockX + 1, a_BlockY, a_BlockY, a_BlockZ - 1, a_BlockZ + 1)) + if (!Area.Read(a_ChunkInterface, a_BlockX - 1, a_BlockX + 1, a_BlockY, a_BlockY, a_BlockZ - 1, a_BlockZ + 1)) { return false; } @@ -67,7 +67,7 @@ public: virtual void OnPlacedByPlayer( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -75,7 +75,7 @@ public: { // Check if this forms a doublechest, if so, need to adjust the meta: cBlockArea Area; - if (!Area.Read(a_World, a_BlockX - 1, a_BlockX + 1, a_BlockY, a_BlockY, a_BlockZ - 1, a_BlockZ + 1)) + if (!Area.Read(a_ChunkInterface, a_BlockX - 1, a_BlockX + 1, a_BlockY, a_BlockY, a_BlockZ - 1, a_BlockZ + 1)) { return; } @@ -84,8 +84,8 @@ public: // Choose meta from player rotation, choose only between 2 or 3 NIBBLETYPE NewMeta = ((rot >= -90) && (rot < 90)) ? 2 : 3; if ( - CheckAndAdjustNeighbor(a_World, Area, 0, 1, NewMeta) || - CheckAndAdjustNeighbor(a_World, Area, 2, 1, NewMeta) + CheckAndAdjustNeighbor(a_ChunkInterface, Area, 0, 1, NewMeta) || + CheckAndAdjustNeighbor(a_ChunkInterface, Area, 2, 1, NewMeta) ) { // Forming a double chest in the X direction @@ -94,8 +94,8 @@ public: // Choose meta from player rotation, choose only between 4 or 5 NewMeta = (rot < 0) ? 4 : 5; if ( - CheckAndAdjustNeighbor(a_World, Area, 1, 0, NewMeta) || - CheckAndAdjustNeighbor(a_World, Area, 2, 2, NewMeta) + CheckAndAdjustNeighbor(a_ChunkInterface, Area, 1, 0, NewMeta) || + CheckAndAdjustNeighbor(a_ChunkInterface, Area, 2, 2, NewMeta) ) { // Forming a double chest in the Z direction @@ -112,10 +112,10 @@ public: } - virtual bool CanBeAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { cBlockArea Area; - if (!Area.Read(a_World, a_BlockX - 2, a_BlockX + 2, a_BlockY, a_BlockY, a_BlockZ - 2, a_BlockZ + 2)) + if (!Area.Read(a_ChunkInterface, a_BlockX - 2, a_BlockX + 2, a_BlockY, a_BlockY, a_BlockZ - 2, a_BlockZ + 2)) { // Cannot read the surroundings, probably at the edge of loaded chunks. Disallow. return false; @@ -207,13 +207,13 @@ public: /// If there's a chest in the a_Area in the specified coords, modifies its meta to a_NewMeta and returns true. - bool CheckAndAdjustNeighbor(cWorld * a_World, const cBlockArea & a_Area, int a_RelX, int a_RelZ, NIBBLETYPE a_NewMeta) + bool CheckAndAdjustNeighbor(cChunkInterface * a_ChunkInterface, const cBlockArea & a_Area, int a_RelX, int a_RelZ, NIBBLETYPE a_NewMeta) override { if (a_Area.GetRelBlockType(a_RelX, 0, a_RelZ) != E_BLOCK_CHEST) { return false; } - a_World->SetBlockMeta(a_Area.GetOriginX() + a_RelX, a_Area.GetOriginY(), a_Area.GetOriginZ() + a_RelZ, a_NewMeta); + a_ChunkInterface->SetBlockMeta(a_Area.GetOriginX() + a_RelX, a_Area.GetOriginY(), a_Area.GetOriginZ() + a_RelZ, a_NewMeta); return true; } } ; diff --git a/src/Blocks/BlockEntity.h b/src/Blocks/BlockEntity.h index 073b5fc49..513659194 100644 --- a/src/Blocks/BlockEntity.h +++ b/src/Blocks/BlockEntity.h @@ -15,9 +15,9 @@ public: { } - virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - a_World->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_ChunkInterface->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); } virtual bool IsUseable() override diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 1997c87d4..5d74ee5c6 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -284,41 +284,41 @@ void cBlockHandler::OnDestroyedByPlayer(cWorld *a_World, cPlayer * a_Player, int -void cBlockHandler::OnPlaced(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +void cBlockHandler::OnPlaced(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { // Notify the neighbors - NeighborChanged(a_World, a_BlockX - 1, a_BlockY, a_BlockZ); - NeighborChanged(a_World, a_BlockX + 1, a_BlockY, a_BlockZ); - NeighborChanged(a_World, a_BlockX, a_BlockY - 1, a_BlockZ); - NeighborChanged(a_World, a_BlockX, a_BlockY + 1, a_BlockZ); - NeighborChanged(a_World, a_BlockX, a_BlockY, a_BlockZ - 1); - NeighborChanged(a_World, a_BlockX, a_BlockY, a_BlockZ + 1); + NeighborChanged(a_ChunkInterface, a_BlockX - 1, a_BlockY, a_BlockZ); + NeighborChanged(a_ChunkInterface, a_BlockX + 1, a_BlockY, a_BlockZ); + NeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ); + NeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ); + NeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ - 1); + NeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ + 1); } -void cBlockHandler::OnDestroyed(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { // Notify the neighbors - NeighborChanged(a_World, a_BlockX - 1, a_BlockY, a_BlockZ); - NeighborChanged(a_World, a_BlockX + 1, a_BlockY, a_BlockZ); - NeighborChanged(a_World, a_BlockX, a_BlockY - 1, a_BlockZ); - NeighborChanged(a_World, a_BlockX, a_BlockY + 1, a_BlockZ); - NeighborChanged(a_World, a_BlockX, a_BlockY, a_BlockZ - 1); - NeighborChanged(a_World, a_BlockX, a_BlockY, a_BlockZ + 1); + NeighborChanged(a_ChunkInterface, a_BlockX - 1, a_BlockY, a_BlockZ); + NeighborChanged(a_ChunkInterface, a_BlockX + 1, a_BlockY, a_BlockZ); + NeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ); + NeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ); + NeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ - 1); + NeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ + 1); } -void cBlockHandler::NeighborChanged(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockHandler::NeighborChanged(cChunkInterface *a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { if ((a_BlockY >= 0) && (a_BlockY < cChunkDef::Height)) { - GetBlockHandler(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnNeighborChanged(a_World, a_BlockX, a_BlockY, a_BlockZ); + GetBlockHandler(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); } } @@ -326,7 +326,7 @@ void cBlockHandler::NeighborChanged(cWorld *a_World, int a_BlockX, int a_BlockY, -void cBlockHandler::OnNeighborChanged(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockHandler::OnNeighborChanged(cChunkInterface *a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { } @@ -342,7 +342,7 @@ void cBlockHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, -void cBlockHandler::OnUse(cWorld *a_World, cWorldInterface * a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { } diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 6b28c60ab..83087f27e 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -5,13 +5,13 @@ #include "../Item.h" #include "../Chunk.h" #include "WorldInterface.h" +#include "ChunkInterface.h" // fwd: -class cWorld; class cPlayer; @@ -40,7 +40,7 @@ public: ); /// Called by cWorld::SetBlock() after the block has been set - virtual void OnPlaced(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + virtual void OnPlaced(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); /// Called by cClientHandle::HandlePlaceBlock() after the player has placed a new block. Called after OnPlaced(). virtual void OnPlacedByPlayer( @@ -54,19 +54,19 @@ public: virtual void OnDestroyedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called before a block gets destroyed / replaced with air - virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ); + virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called when a direct neighbor of this block has been changed (The position is the own position, not the neighbor position) - virtual void OnNeighborChanged(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ); + virtual void OnNeighborChanged(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ); /// Notifies all neighbors of the given block about a change - static void NeighborChanged(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ); + static void NeighborChanged(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called while the player diggs the block. virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called if the user right clicks the block and the block is useable - virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); + virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); /// Called when the item is mined to convert it into pickups. Pickups may specify multiple items. Appends items to a_Pickups, preserves its original contents virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta); diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 539d12a49..730906bee 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -53,19 +53,19 @@ public: } - void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override + void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { - cBlockHandler::OnDestroyed(a_World, a_BlockX, a_BlockY, a_BlockZ); + cBlockHandler::OnDestroyed(a_ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); //0.5% chance of dropping an apple - NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); //check if Oak (0x1 and 0x2 bit not set) MTRand rand; if(!(Meta & 3) && rand.randInt(200) == 100) { cItems Drops; Drops.push_back(cItem(E_ITEM_RED_APPLE, 1, 0)); - a_World->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ); + a_WorldInterface->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ); } } diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 55cadfa48..59d7182ba 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -31,58 +31,58 @@ public: } virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override { a_BlockType = m_BlockType; - a_BlockMeta = FindMeta(a_World, a_BlockX, a_BlockY, a_BlockZ); + a_BlockMeta = FindMeta(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); return true; } - virtual void OnPlaced(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override + virtual void OnPlaced(cChunkInterface *a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override { - super::OnPlaced(a_World, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + super::OnPlaced(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); // Alert diagonal rails - OnNeighborChanged(a_World, a_BlockX + 1, a_BlockY + 1, a_BlockZ); - OnNeighborChanged(a_World, a_BlockX - 1, a_BlockY + 1, a_BlockZ); - OnNeighborChanged(a_World, a_BlockX, a_BlockY + 1, a_BlockZ + 1); - OnNeighborChanged(a_World, a_BlockX, a_BlockY + 1, a_BlockZ - 1); - - OnNeighborChanged(a_World, a_BlockX + 1, a_BlockY - 1, a_BlockZ); - OnNeighborChanged(a_World, a_BlockX - 1, a_BlockY - 1, a_BlockZ); - OnNeighborChanged(a_World, a_BlockX, a_BlockY - 1, a_BlockZ + 1); - OnNeighborChanged(a_World, a_BlockX, a_BlockY - 1, a_BlockZ - 1); + OnNeighborChanged(a_ChunkInterface, a_BlockX + 1, a_BlockY + 1, a_BlockZ); + OnNeighborChanged(a_ChunkInterface, a_BlockX - 1, a_BlockY + 1, a_BlockZ); + OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ + 1); + OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ - 1); + + OnNeighborChanged(a_ChunkInterface, a_BlockX + 1, a_BlockY - 1, a_BlockZ); + OnNeighborChanged(a_ChunkInterface, a_BlockX - 1, a_BlockY - 1, a_BlockZ); + OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ + 1); + OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ - 1); } - virtual void OnDestroyed(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override + virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { - super::OnDestroyed(a_World, a_BlockX, a_BlockY, a_BlockZ); + super::OnDestroyed(a_ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); // Alert diagonal rails - OnNeighborChanged(a_World, a_BlockX + 1, a_BlockY + 1, a_BlockZ); - OnNeighborChanged(a_World, a_BlockX - 1, a_BlockY + 1, a_BlockZ); - OnNeighborChanged(a_World, a_BlockX, a_BlockY + 1, a_BlockZ + 1); - OnNeighborChanged(a_World, a_BlockX, a_BlockY + 1, a_BlockZ - 1); - - OnNeighborChanged(a_World, a_BlockX + 1, a_BlockY - 1, a_BlockZ); - OnNeighborChanged(a_World, a_BlockX - 1, a_BlockY - 1, a_BlockZ); - OnNeighborChanged(a_World, a_BlockX, a_BlockY - 1, a_BlockZ + 1); - OnNeighborChanged(a_World, a_BlockX, a_BlockY - 1, a_BlockZ - 1); + OnNeighborChanged(a_ChunkInterface, a_BlockX + 1, a_BlockY + 1, a_BlockZ); + OnNeighborChanged(a_ChunkInterface, a_BlockX - 1, a_BlockY + 1, a_BlockZ); + OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ + 1); + OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ - 1); + + OnNeighborChanged(a_ChunkInterface, a_BlockX + 1, a_BlockY - 1, a_BlockZ); + OnNeighborChanged(a_ChunkInterface, a_BlockX - 1, a_BlockY - 1, a_BlockZ); + OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ + 1); + OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ - 1); } - virtual void OnNeighborChanged(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override + virtual void OnNeighborChanged(cChunkInterface *a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { - NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if (IsUnstable(a_World, a_BlockX, a_BlockY, a_BlockZ) && (Meta != FindMeta(a_World, a_BlockX, a_BlockY, a_BlockZ))) + NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + if (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ) && (Meta != FindMeta(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ))) { - a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, FindMeta(a_World, a_BlockX, a_BlockY, a_BlockZ)); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, FindMeta(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ)); } } @@ -137,27 +137,27 @@ public: return true; } - NIBBLETYPE FindMeta(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ) + NIBBLETYPE FindMeta(cChunkInterface *a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { NIBBLETYPE Meta = 0; char RailsCnt = 0; bool Neighbors[8]; // 0 - EAST, 1 - WEST, 2 - NORTH, 3 - SOUTH, 4 - EAST UP, 5 - WEST UP, 6 - NORTH UP, 7 - SOUTH UP memset(Neighbors, false, sizeof(Neighbors)); - Neighbors[0] = (IsUnstable(a_World, a_BlockX + 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST, E_PURE_DOWN)); - Neighbors[1] = (IsUnstable(a_World, a_BlockX - 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST, E_PURE_DOWN)); - Neighbors[2] = (IsUnstable(a_World, a_BlockX, a_BlockY, a_BlockZ - 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_DOWN)); - Neighbors[3] = (IsUnstable(a_World, a_BlockX, a_BlockY, a_BlockZ + 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_DOWN)); - Neighbors[4] = (IsUnstable(a_World, a_BlockX + 1, a_BlockY + 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_EAST, E_PURE_NONE)); - Neighbors[5] = (IsUnstable(a_World, a_BlockX - 1, a_BlockY + 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_WEST, E_PURE_NONE)); - Neighbors[6] = (IsUnstable(a_World, a_BlockX, a_BlockY + 1, a_BlockZ - 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_NONE)); - Neighbors[7] = (IsUnstable(a_World, a_BlockX, a_BlockY + 1, a_BlockZ + 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_NONE)); - if (IsUnstable(a_World, a_BlockX + 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_EAST)) + Neighbors[0] = (IsUnstable(a_ChunkInterface, a_BlockX + 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST, E_PURE_DOWN)); + Neighbors[1] = (IsUnstable(a_ChunkInterface, a_BlockX - 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST, E_PURE_DOWN)); + Neighbors[2] = (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ - 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_DOWN)); + Neighbors[3] = (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ + 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_DOWN)); + Neighbors[4] = (IsUnstable(a_ChunkInterface, a_BlockX + 1, a_BlockY + 1, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_EAST, E_PURE_NONE)); + Neighbors[5] = (IsUnstable(a_ChunkInterface, a_BlockX - 1, a_BlockY + 1, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_WEST, E_PURE_NONE)); + Neighbors[6] = (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ - 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_NONE)); + Neighbors[7] = (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ + 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_NONE)); + if (IsUnstable(a_ChunkInterface, a_BlockX + 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_EAST)) Neighbors[0] = true; - if (IsUnstable(a_World, a_BlockX - 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_WEST)) + if (IsUnstable(a_ChunkInterface, a_BlockX - 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_WEST)) Neighbors[1] = true; - if (IsUnstable(a_World, a_BlockX, a_BlockY - 1, a_BlockZ - 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_NORTH)) + if (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ - 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_NORTH)) Neighbors[2] = true; - if (IsUnstable(a_World, a_BlockX, a_BlockY - 1, a_BlockZ + 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_SOUTH)) + if (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ + 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_SOUTH)) Neighbors[3] = true; for (int i = 0; i < 8; i++) { @@ -202,20 +202,20 @@ public: } - bool IsUnstable(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) + bool IsUnstable(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_RAIL) + if (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_RAIL) { return false; } - NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); switch (Meta) { case E_META_RAIL_ZM_ZP: { if ( - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_DOWN) || - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_DOWN) + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_DOWN) || + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_DOWN) ) { return true; @@ -226,8 +226,8 @@ public: case E_META_RAIL_XM_XP: { if ( - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST, E_PURE_DOWN) || - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST, E_PURE_DOWN) + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST, E_PURE_DOWN) || + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST, E_PURE_DOWN) ) { return true; @@ -238,8 +238,8 @@ public: case E_META_RAIL_ASCEND_XP: { if ( - IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_EAST) || - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST) + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_EAST) || + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST) ) { return true; @@ -250,8 +250,8 @@ public: case E_META_RAIL_ASCEND_XM: { if ( - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST) || - IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_WEST) + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST) || + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_WEST) ) { return true; @@ -262,8 +262,8 @@ public: case E_META_RAIL_ASCEND_ZM: { if ( - IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_NORTH) || - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_NORTH) || + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) ) { return true; @@ -274,8 +274,8 @@ public: case E_META_RAIL_ASCEND_ZP: { if ( - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || - IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_SOUTH) + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_SOUTH) ) { return true; @@ -286,8 +286,8 @@ public: case E_META_RAIL_CURVED_ZP_XP: { if ( - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) || - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST) + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) || + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST) ) { return true; @@ -298,8 +298,8 @@ public: case E_META_RAIL_CURVED_ZP_XM: { if ( - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) || - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST) + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) || + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST) ) { return true; @@ -310,8 +310,8 @@ public: case E_META_RAIL_CURVED_ZM_XM: { if ( - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST) + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST) ) { return true; @@ -322,8 +322,8 @@ public: case E_META_RAIL_CURVED_ZM_XP: { if ( - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || - IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST) + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || + IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST) ) { return true; @@ -335,31 +335,31 @@ public: } - bool IsNotConnected(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Pure = 0) + bool IsNotConnected(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Pure = 0) { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, false); NIBBLETYPE Meta; - if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_RAIL) + if (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_RAIL) { - if ((a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ) != E_BLOCK_RAIL) || (a_Pure != E_PURE_UPDOWN)) + if ((a_ChunkInterface->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ) != E_BLOCK_RAIL) || (a_Pure != E_PURE_UPDOWN)) { - if ((a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) != E_BLOCK_RAIL) || (a_Pure == E_PURE_NONE)) + if ((a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) != E_BLOCK_RAIL) || (a_Pure == E_PURE_NONE)) { return true; } else { - Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ); + Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ); } } else { - Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY + 1, a_BlockZ); + Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY + 1, a_BlockZ); } } else { - Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); } switch (a_BlockFace) diff --git a/src/Blocks/BlockWorkbench.h b/src/Blocks/BlockWorkbench.h index d15447db4..5c60f1ef1 100644 --- a/src/Blocks/BlockWorkbench.h +++ b/src/Blocks/BlockWorkbench.h @@ -19,7 +19,7 @@ public: } - virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { cWindow * Window = new cCraftingWindow(a_BlockX, a_BlockY, a_BlockZ); a_Player->OpenWindow(Window); diff --git a/src/Blocks/BroadcastInterface.h b/src/Blocks/BroadcastInterface.h new file mode 100644 index 000000000..f6ccd580b --- /dev/null +++ b/src/Blocks/BroadcastInterface.h @@ -0,0 +1,10 @@ + +#pragma once + +class cBroadcastInterface +{ +public: + + virtual void BroadcastUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0; + virtual void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL) = 0; +}; diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h index 91a635dcf..a16c68013 100644 --- a/src/Blocks/ChunkInterface.h +++ b/src/Blocks/ChunkInterface.h @@ -1,26 +1,70 @@ #pragma once -class cChunkInterface +#include "../ChunkMap.h" +#include "../ForEachChunkProvider.h" + +class cChunkInterface : public cForEachChunkProvider { public: - BLOCKTYPE GetBlock (int a_BlockX, int a_BlockY, int a_BlockZ); - BLOCKTYPE GetBlock (const Vector3i & a_Pos ) { return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z ); } - NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ); + cChunkInterface(cChunkMap * a_ChunkMap) : m_ChunkMap(a_ChunkMap) {} + + BLOCKTYPE GetBlock (int a_BlockX, int a_BlockY, int a_BlockZ) + { + return m_ChunkMap->GetBlock(a_BlockX,a_BlockY,a_BlockZ); + } + BLOCKTYPE GetBlock (const Vector3i & a_Pos ) + { + return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z ); + } + NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ) + { + return m_ChunkMap->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + } /** Sets the block at the specified coords to the specified value. Full processing, incl. updating neighbors, is performed. */ - void SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + void SetBlock(cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) + { + m_ChunkMap->SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + } + void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData) + { + m_ChunkMap->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_MetaData); + } + void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay, BLOCKTYPE a_PreviousBlockType, cWorldInterface * a_WorldInterface) + { + m_ChunkMap->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_WorldInterface->GetWorldAge() + a_TickDelay, a_PreviousBlockType); + } /** Sets the block at the specified coords to the specified value. The replacement doesn't trigger block updates. The replaced blocks aren't checked for block entities (block entity is leaked if it exists at this block) */ - void FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + void FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) + { + m_ChunkMap->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + } void FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) { FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta ); } + + void UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) + { + m_ChunkMap->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); + } + + virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) override + { + return m_ChunkMap->ForEachChunkInRect(a_MinChunkX, a_MaxChunkX, a_MinChunkZ, a_MaxChunkZ, a_Callback); + } + + virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) override + { + return m_ChunkMap->WriteBlockArea(a_Area, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes); + } - void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); +private: + cChunkMap * m_ChunkMap; }; diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index 8cf2103d1..a29d7a73a 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -1,13 +1,25 @@ #pragma once +#include "BroadcastInterface.h" + class cWorldInterface { public: - virtual Int64 GetTimeOfDay(void) const; + virtual Int64 GetTimeOfDay(void) const = 0; + virtual Int64 GetWorldAge(void) const = 0; + + virtual eDimension GetDimension(void) const = 0; + + virtual cBroadcastInterface * GetBroadcastManager() = 0; + + virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData) = 0; + + /** Spawns item pickups for each item in the list. May compress pickups if too many entities: */ + virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false) = 0; - virtual eDimension GetDimension(void) const; + /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified: */ + virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false) = 0; - virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ); }; diff --git a/src/ChunkDef.h b/src/ChunkDef.h index d1288994c..09bd766da 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -92,7 +92,6 @@ public: /// Converts absolute block coords into relative (chunk + block) coords: inline static void AbsoluteToRelative(/* in-out */ int & a_X, int & a_Y, int & a_Z, /* out */ int & a_ChunkX, int & a_ChunkZ ) { - UNUSED(a_Y); BlockToChunk(a_X, a_Z, a_ChunkX, a_ChunkZ); a_X = a_X - a_ChunkX * Width; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 5797eb453..d0bccb837 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1117,6 +1117,21 @@ void cChunkMap::CollectPickupsByPlayer(cPlayer * a_Player) BLOCKTYPE cChunkMap::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ) { + // First check if it isn't queued in the m_FastSetBlockQueue: + { + int X = a_BlockX, Y = a_BlockY, Z = a_BlockZ; + int ChunkX, ChunkY, ChunkZ; + cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); + ChunkY = 0; + cCSLock Lock(m_CSFastSetBlock); + for (sSetBlockList::iterator itr = m_FastSetBlockQueue.begin(); itr != m_FastSetBlockQueue.end(); ++itr) + { + if ((itr->x == X) && (itr->y == Y) && (itr->z == Z) && (itr->ChunkX == ChunkX) && (itr->ChunkZ == ChunkZ)) + { + return itr->BlockType; + } + } // for itr - m_FastSetBlockQueue[] + } int ChunkX, ChunkZ; cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ ); @@ -1135,6 +1150,17 @@ BLOCKTYPE cChunkMap::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ) NIBBLETYPE cChunkMap::GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ) { + // First check if it isn't queued in the m_FastSetBlockQueue: + { + cCSLock Lock(m_CSFastSetBlock); + for (sSetBlockList::iterator itr = m_FastSetBlockQueue.begin(); itr != m_FastSetBlockQueue.end(); ++itr) + { + if ((itr->x == a_BlockX) && (itr->y == a_BlockY) && (itr->z == a_BlockZ)) + { + return itr->BlockMeta; + } + } // for itr - m_FastSetBlockQueue[] + } int ChunkX, ChunkZ; cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ ); @@ -1207,8 +1233,14 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP -void cChunkMap::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta) +void cChunkMap::SetBlock(cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta) { + cChunkInterface *ChunkInterface = new cChunkInterface(this); + if (a_BlockType == E_BLOCK_AIR) + { + BlockHandler(GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnDestroyed(ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); + } + int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ; cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ ); @@ -1219,6 +1251,8 @@ void cChunkMap::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_B Chunk->SetBlock(X, Y, Z, a_BlockType, a_BlockMeta ); m_World->GetSimulatorManager()->WakeUp(a_BlockX, a_BlockY, a_BlockZ, Chunk); } + BlockHandler(a_BlockType)->OnPlaced(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + delete ChunkInterface; } @@ -2692,6 +2726,28 @@ void cChunkMap::cChunkLayer::UnloadUnusedChunks(void) +void cChunkMap::FastSetBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +{ + cCSLock Lock(m_CSFastSetBlock); + m_FastSetBlockQueue.push_back(sSetBlock(a_X, a_Y, a_Z, a_BlockType, a_BlockMeta)); +} + +void cChunkMap::FastSetQueuedBlocks() +{ + // Asynchronously set blocks: + sSetBlockList FastSetBlockQueueCopy; + { + cCSLock Lock(m_CSFastSetBlock); + std::swap(FastSetBlockQueueCopy, m_FastSetBlockQueue); + } + this->FastSetBlocks(FastSetBlockQueueCopy); + if (!FastSetBlockQueueCopy.empty()) + { + // Some blocks failed, store them for next tick: + cCSLock Lock(m_CSFastSetBlock); + m_FastSetBlockQueue.splice(m_FastSetBlockQueue.end(), FastSetBlockQueueCopy); + } +} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2801,4 +2857,3 @@ void cChunkStay::Disable(void) - diff --git a/src/ChunkMap.h b/src/ChunkMap.h index e9d8ee30b..59a55dc17 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -12,6 +12,7 @@ class cWorld; +class cWorldInterface; class cItem; class MTRand; class cChunkStay; @@ -136,6 +137,9 @@ public: bool HasChunkAnyClients (int a_ChunkX, int a_ChunkZ); int GetHeight (int a_BlockX, int a_BlockZ); // Waits for the chunk to get loaded / generated bool TryGetHeight (int a_BlockX, int a_BlockZ, int & a_Height); // Returns false if chunk not loaded / generated + void FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + + void FastSetQueuedBlocks(); void FastSetBlocks (sSetBlockList & a_BlockList); void CollectPickupsByPlayer(cPlayer * a_Player); @@ -144,7 +148,7 @@ public: NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ); NIBBLETYPE GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_BlockZ); void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockMeta); - void SetBlock (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta); + void SetBlock (cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta); void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR); bool GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); bool GetBlockInfo (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight); @@ -388,6 +392,9 @@ private: cEvent m_evtChunkValid; // Set whenever any chunk becomes valid, via ChunkValidated() cWorld * m_World; + + cCriticalSection m_CSFastSetBlock; + sSetBlockList m_FastSetBlockQueue; cChunkPtr GetChunk (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 083dad833..fa3827d73 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -20,6 +20,7 @@ #include "Items/ItemHandler.h" #include "Blocks/BlockHandler.h" #include "Blocks/BlockSlab.h" +#include "Blocks/ChunkInterface.h" #include "Vector3f.h" #include "Vector3d.h" @@ -916,7 +917,9 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, c // A plugin doesn't agree with using the block, abort return; } - BlockHandler->OnUse(World, World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ); + cChunkInterface *ChunkInterface = new cChunkInterface(World->GetChunkMap()); + BlockHandler->OnUse(ChunkInterface, World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ); + delete ChunkInterface; PlgMgr->CallHookPlayerUsedBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta); return; } diff --git a/src/World.cpp b/src/World.cpp index 49d42f08e..ee855c67d 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -709,19 +709,7 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec) TickWeather(a_Dt); - // Asynchronously set blocks: - sSetBlockList FastSetBlockQueueCopy; - { - cCSLock Lock(m_CSFastSetBlock); - std::swap(FastSetBlockQueueCopy, m_FastSetBlockQueue); - } - m_ChunkMap->FastSetBlocks(FastSetBlockQueueCopy); - if (!FastSetBlockQueueCopy.empty()) - { - // Some blocks failed, store them for next tick: - cCSLock Lock(m_CSFastSetBlock); - m_FastSetBlockQueue.splice(m_FastSetBlockQueue.end(), FastSetBlockQueueCopy); - } + m_ChunkMap->FastSetQueuedBlocks(); if (m_WorldAge - m_LastSave > 60 * 5 * 20) // Save each 5 minutes { @@ -1491,84 +1479,11 @@ int cWorld::GetBiomeAt (int a_BlockX, int a_BlockZ) void cWorld::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { - if (a_BlockType == E_BLOCK_AIR) - { - BlockHandler(GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnDestroyed(this, a_BlockX, a_BlockY, a_BlockZ); - } - m_ChunkMap->SetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); - - BlockHandler(a_BlockType)->OnPlaced(this, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); -} - - - - - -void cWorld::FastSetBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) -{ - cCSLock Lock(m_CSFastSetBlock); - m_FastSetBlockQueue.push_back(sSetBlock(a_X, a_Y, a_Z, a_BlockType, a_BlockMeta)); -} - - - - - -void cWorld::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay, BLOCKTYPE a_PreviousBlockType) -{ - m_ChunkMap->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, GetWorldAge() + a_TickDelay, a_PreviousBlockType); -} - - - - - -BLOCKTYPE cWorld::GetBlock(int a_X, int a_Y, int a_Z) -{ - // First check if it isn't queued in the m_FastSetBlockQueue: - { - int X = a_X, Y = a_Y, Z = a_Z; - int ChunkX, ChunkY, ChunkZ; - AbsoluteToRelative(X, Y, Z, ChunkX, ChunkY, ChunkZ); - - cCSLock Lock(m_CSFastSetBlock); - for (sSetBlockList::iterator itr = m_FastSetBlockQueue.begin(); itr != m_FastSetBlockQueue.end(); ++itr) - { - if ((itr->x == X) && (itr->y == Y) && (itr->z == Z) && (itr->ChunkX == ChunkX) && (itr->ChunkZ == ChunkZ)) - { - return itr->BlockType; - } - } // for itr - m_FastSetBlockQueue[] - } - - return m_ChunkMap->GetBlock(a_X, a_Y, a_Z); + m_ChunkMap->SetBlock(this, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); } - - -NIBBLETYPE cWorld::GetBlockMeta(int a_X, int a_Y, int a_Z) -{ - // First check if it isn't queued in the m_FastSetBlockQueue: - { - cCSLock Lock(m_CSFastSetBlock); - for (sSetBlockList::iterator itr = m_FastSetBlockQueue.begin(); itr != m_FastSetBlockQueue.end(); ++itr) - { - if ((itr->x == a_X) && (itr->y == a_Y) && (itr->y == a_Y)) - { - return itr->BlockMeta; - } - } // for itr - m_FastSetBlockQueue[] - } - - return m_ChunkMap->GetBlockMeta(a_X, a_Y, a_Z); -} - - - - - void cWorld::SetBlockMeta(int a_X, int a_Y, int a_Z, NIBBLETYPE a_MetaData) { m_ChunkMap->SetBlockMeta(a_X, a_Y, a_Z, a_MetaData); @@ -1750,7 +1665,9 @@ bool cWorld::GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure) bool cWorld::DigBlock(int a_X, int a_Y, int a_Z) { cBlockHandler *Handler = cBlockHandler::GetBlockHandler(GetBlock(a_X, a_Y, a_Z)); - Handler->OnDestroyed(this, a_X, a_Y, a_Z); + cChunkInterface *ChunkInterface = new cChunkInterface(GetChunkMap()); + Handler->OnDestroyed(ChunkInterface, this, a_X, a_Y, a_Z); + delete ChunkInterface; return m_ChunkMap->DigBlock(a_X, a_Y, a_Z); } diff --git a/src/World.h b/src/World.h index c5852f118..d489e574a 100644 --- a/src/World.h +++ b/src/World.h @@ -25,7 +25,7 @@ #include "ForEachChunkProvider.h" #include "Scoreboard.h" #include "Blocks/WorldInterface.h" - +#include "Blocks/BroadcastInterface.h" @@ -63,7 +63,7 @@ typedef cItemCallback cCommandBlockCallback; // tolua_begin -class cWorld : public cForEachChunkProvider, public cWorldInterface +class cWorld : public cForEachChunkProvider, public cWorldInterface, public cBroadcastInterface { public: @@ -107,7 +107,7 @@ public: // tolua_begin int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; } - Int64 GetWorldAge(void) const { return m_WorldAge; } + virtual Int64 GetWorldAge(void) const { return m_WorldAge; } virtual Int64 GetTimeOfDay(void) const { return m_TimeOfDay; } void SetTicksUntilWeatherChange(int a_WeatherInterval) @@ -184,6 +184,11 @@ public: virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ); void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL); + virtual cBroadcastInterface * GetBroadcastManager() + { + return this; + } + /** If there is a block entity at the specified coords, sends it to the client specified */ void SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle & a_Client); @@ -326,15 +331,28 @@ public: The replacement doesn't trigger block updates. The replaced blocks aren't checked for block entities (block entity is leaked if it exists at this block) */ - void FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + void FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) + { + m_ChunkMap->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + } /** Queues a SetBlock() with the specified parameters after the specified number of ticks. Calls SetBlock(), so performs full processing of the replaced block. */ - void QueueSetBlock(int a_BlockX, int a_BLockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR); + void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR) + { + m_ChunkMap->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, GetWorldAge() + a_TickDelay, a_PreviousBlockType); + } + + BLOCKTYPE GetBlock (int a_BlockX, int a_BlockY, int a_BlockZ) + { + return m_ChunkMap->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + } - BLOCKTYPE GetBlock (int a_BlockX, int a_BlockY, int a_BlockZ); - NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ); + NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ) + { + return m_ChunkMap->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + } void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData); NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ); NIBBLETYPE GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_BlockZ); @@ -364,10 +382,10 @@ public: // tolua_begin /** Spawns item pickups for each item in the list. May compress pickups if too many entities: */ - void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false); + virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false); /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified: */ - void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false); + virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false); /** Spawns an falling block entity at the given position. It returns the UniqueID of the spawned falling block. */ int SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta); @@ -442,7 +460,7 @@ public: | esWitherBirth | TBD | | esPlugin | void * | */ - void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); // tolua_export + virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); // tolua_export /** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */ bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Exported in ManualBindings.cpp @@ -515,21 +533,6 @@ public: cScoreboard & GetScoreBoard(void) { return m_Scoreboard; } // tolua_end - - inline static void AbsoluteToRelative( int & a_X, int & a_Y, int & a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ ) - { - // TODO: Use floor() instead of weird if statements - // Also fix Y - a_ChunkX = a_X/cChunkDef::Width; - if(a_X < 0 && a_X % cChunkDef::Width != 0) a_ChunkX--; - a_ChunkY = 0; - a_ChunkZ = a_Z/cChunkDef::Width; - if(a_Z < 0 && a_Z % cChunkDef::Width != 0) a_ChunkZ--; - - a_X = a_X - a_ChunkX*cChunkDef::Width; - a_Y = a_Y - a_ChunkY*cChunkDef::Height; - a_Z = a_Z - a_ChunkZ*cChunkDef::Width; - } inline static void BlockToChunk( int a_X, int a_Y, int a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ ) { @@ -776,9 +779,6 @@ private: bool m_IsPumpkinBonemealable; bool m_IsSaplingBonemealable; bool m_IsSugarcaneBonemealable; - - cCriticalSection m_CSFastSetBlock; - sSetBlockList m_FastSetBlockQueue; cChunkGenerator m_Generator; -- cgit v1.2.3 From a13d009a30988037707ff79aab81be4acd8b6a77 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 26 Jan 2014 07:06:25 -0800 Subject: Refactored GetPlacementBlockTypeMeta --- src/Blocks/BlockChest.h | 1 - src/Blocks/BlockComparator.h | 8 ++++---- src/Blocks/BlockHandler.cpp | 2 +- src/Blocks/BlockHandler.h | 2 +- src/Blocks/BlockRail.h | 1 - src/Items/ItemDoor.h | 6 ++++-- src/Items/ItemHandler.cpp | 3 ++- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 23f969dbe..84dc324fb 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -2,7 +2,6 @@ #pragma once #include "BlockEntity.h" -#include "../World.h" #include "../BlockArea.h" #include "../Entities/Player.h" diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index 732afd9f6..7cb874556 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -18,11 +18,11 @@ public: } - virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); Meta ^= 0x04; // Toggle 3rd (addition/subtraction) bit with XOR - a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); + a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); } @@ -46,7 +46,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 5d74ee5c6..68907c9a3 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -244,7 +244,7 @@ cBlockHandler::cBlockHandler(BLOCKTYPE a_BlockType) bool cBlockHandler::GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 83087f27e..ffded50e0 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -33,7 +33,7 @@ public: Called by cItemHandler::GetPlacementBlockTypeMeta() if the item is a block */ virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 30a8bc10c..e414e16ce 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -2,7 +2,6 @@ #pragma once #include "BlockEntity.h" -#include "../World.h" diff --git a/src/Items/ItemDoor.h b/src/Items/ItemDoor.h index 72ea0beed..d5c1d887a 100644 --- a/src/Items/ItemDoor.h +++ b/src/Items/ItemDoor.h @@ -31,12 +31,14 @@ public: ) override { a_BlockType = (m_ItemType == E_ITEM_WOODEN_DOOR) ? E_BLOCK_WOODEN_DOOR : E_BLOCK_IRON_DOOR; - return BlockHandler(a_BlockType)->GetPlacementBlockTypeMeta( - a_World, a_Player, + cChunkInterface ChunkInterface(a_World->GetChunkMap()); + bool Meta = BlockHandler(a_BlockType)->GetPlacementBlockTypeMeta( + &ChunkInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta ); + return Meta; } } ; diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 250e21dc4..32f9cb3b9 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -465,8 +465,9 @@ bool cItemHandler::GetPlacementBlockTypeMeta( } cBlockHandler * BlockH = BlockHandler(m_ItemType); + cChunkInterface ChunkInterface(a_World->GetChunkMap()); return BlockH->GetPlacementBlockTypeMeta( - a_World, a_Player, + &ChunkInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta -- cgit v1.2.3 From 6e6409b1a080cc4e17a246916968f2e2b1dbe68e Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 26 Jan 2014 07:09:24 -0800 Subject: Removed cWorld Include --- src/Blocks/BlockCrops.h | 1 - src/Blocks/BlockDeadBush.h | 1 - src/Blocks/BlockDirt.h | 1 - 3 files changed, 3 deletions(-) diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index 9c4964e02..ad3057275 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -3,7 +3,6 @@ #include "BlockHandler.h" #include "../MersenneTwister.h" -#include "../World.h" diff --git a/src/Blocks/BlockDeadBush.h b/src/Blocks/BlockDeadBush.h index 14617d006..059fb7091 100644 --- a/src/Blocks/BlockDeadBush.h +++ b/src/Blocks/BlockDeadBush.h @@ -2,7 +2,6 @@ #pragma once #include "BlockHandler.h" -#include "../World.h" diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index 46210e406..1cc6bc0c3 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -3,7 +3,6 @@ #include "BlockHandler.h" #include "../MersenneTwister.h" -#include "../World.h" -- cgit v1.2.3 From 6952b24e88290dcbce9b15c39613ee35a5af7f12 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 26 Jan 2014 07:16:24 -0800 Subject: Changed it so std was actually set to c++11 in clang not gcc on OS X --- CMakeLists.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 70728706d..8f336e20f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,13 +44,22 @@ if(MSVC) set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG") elseif(APPLE) #on os x clang adds pthread for us but we need to add it for gcc - if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11") + else() add_flags_cxx("-pthread") - add_flags_cxx("-std=c++11") endif() + else() # Let gcc / clang know that we're compiling a multi-threaded app: add_flags_cxx("-pthread") + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11") + endif() endif() -- cgit v1.2.3 From ea9de4bbb70192626b00a810482671cf14bd7f8c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 26 Jan 2014 16:15:05 +0000 Subject: Added SIGABRT to catchers list --- src/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 06b344c25..0f6895d03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,9 +68,10 @@ void NonCtrlHandler(int a_Signal) LOGERROR("Details | SIGABRT: Server self-terminated due to an internal fault"); break; } + case SIGINT: case SIGTERM: { - std::signal(SIGTERM, SIG_IGN); // Server is shutting down, wait for it... + std::signal(a_Signal, SIG_IGN); // Server is shutting down, wait for it... break; } default: break; @@ -224,6 +225,10 @@ int main( int argc, char **argv ) std::signal(SIGSEGV, NonCtrlHandler); std::signal(SIGTERM, NonCtrlHandler); std::signal(SIGINT, NonCtrlHandler); + std::signal(SIGABRT, NonCtrlHandler); + #ifdef SIGABRT_COMPAT + std::signal(SIGABRT_COMPAT, NonCtrlHandler); + #endif // SIGABRT_COMPAT #endif // DEBUG: test the dumpfile creation: -- cgit v1.2.3 From a3ac1be7b7ed48dbaadc57650a17161fc18a5e84 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 26 Jan 2014 14:42:25 +0100 Subject: Fixed Byte-order reading. The functions would fail on bytes that were above 127. --- src/StringUtils.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 0dbd41c12..3fe75d611 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -833,7 +833,8 @@ AString Base64Encode(const AString & a_Input) short GetBEShort(const char * a_Mem) { - return (((short)a_Mem[0]) << 8) | a_Mem[1]; + const Byte * Bytes = (const Byte *)a_Mem; + return (Bytes[0] << 8) | Bytes[1]; } @@ -842,7 +843,8 @@ short GetBEShort(const char * a_Mem) int GetBEInt(const char * a_Mem) { - return (((int)a_Mem[0]) << 24) | (((int)a_Mem[1]) << 16) | (((int)a_Mem[2]) << 8) | a_Mem[3]; + const Byte * Bytes = (const Byte *)a_Mem; + return (Bytes[0] << 24) | (Bytes[1] << 16) | (Bytes[2] << 8) | Bytes[3]; } -- cgit v1.2.3 From 61848ff5a0866a8e14f81c12ab85088dfe460708 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 26 Jan 2014 14:43:54 +0100 Subject: Item-loading now checks for weird bytes. --- src/WorldStorage/WSSAnvil.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index e2a882f65..a0f9136d8 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -611,12 +611,18 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con bool cWSSAnvil::LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_TagIdx) { - int ID = a_NBT.FindChildByName(a_TagIdx, "id"); - if ((ID < 0) || (a_NBT.GetType(ID) != TAG_Short)) + int Type = a_NBT.FindChildByName(a_TagIdx, "id"); + if ((Type < 0) || (a_NBT.GetType(Type) != TAG_Short)) { return false; } - a_Item.m_ItemType = (ENUM_ITEM_ID)(a_NBT.GetShort(ID)); + a_Item.m_ItemType = a_NBT.GetShort(Type); + if (a_Item.m_ItemType < 0) + { + LOGD("Encountered an item with negative type (%d). Replacing with an empty item.", a_NBT.GetShort(Type)); + a_Item.Empty(); + return true; + } int Damage = a_NBT.FindChildByName(a_TagIdx, "Damage"); if ((Damage < 0) || (a_NBT.GetType(Damage) != TAG_Short)) -- cgit v1.2.3 From ab4672be40f0576ab90418e11043d686de6c5855 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 26 Jan 2014 17:48:09 +0100 Subject: cByteBuffer has more self-tests. --- src/ByteBuffer.cpp | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index e06f63a0e..d2d3beb97 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -54,6 +54,7 @@ public: { TestRead(); TestWrite(); + TestWrap(); } void TestRead(void) @@ -61,11 +62,11 @@ public: cByteBuffer buf(50); buf.Write("\x05\xac\x02\x00", 4); UInt32 v1; - ASSERT(buf.ReadVarInt(v1) && (v1 == 5)); + assert(buf.ReadVarInt(v1) && (v1 == 5)); UInt32 v2; - ASSERT(buf.ReadVarInt(v2) && (v2 == 300)); + assert(buf.ReadVarInt(v2) && (v2 == 300)); UInt32 v3; - ASSERT(buf.ReadVarInt(v3) && (v3 == 0)); + assert(buf.ReadVarInt(v3) && (v3 == 0)); } void TestWrite(void) @@ -76,9 +77,30 @@ public: buf.WriteVarInt(0); AString All; buf.ReadAll(All); - ASSERT(All.size() == 4); - ASSERT(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0); + assert(All.size() == 4); + assert(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0); } + + void TestWrap(void) + { + cByteBuffer buf(3); + for (int i = 0; i < 1000; i++) + { + int FreeSpace = buf.GetFreeSpace(); + assert(buf.GetReadableSpace() == 0); + assert(FreeSpace > 0); + assert(buf.Write("a", 1)); + assert(buf.CanReadBytes(1)); + assert(buf.GetReadableSpace() == 1); + unsigned char v = 0; + assert(buf.ReadByte(v)); + assert(v == 'a'); + assert(buf.GetReadableSpace() == 0); + buf.CommitRead(); + assert(buf.GetFreeSpace() == FreeSpace); // We're back to normal + } + } + } g_ByteBufferTest; #endif @@ -159,7 +181,7 @@ bool cByteBuffer::Write(const char * a_Bytes, int a_Count) int CurReadableSpace = GetReadableSpace(); int WrittenBytes = 0; - if (GetFreeSpace() < a_Count) + if (CurFreeSpace < a_Count) { return false; } @@ -864,3 +886,4 @@ void cByteBuffer::CheckValid(void) const + -- cgit v1.2.3 From 30c431b479673b2c94b9d642fc7de73679cf3e6f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 26 Jan 2014 17:54:18 +0100 Subject: Fixed client packet parsing. When the packet wouldn't fit the current buffer, the server would mis-parse the next packet. This was the cause for #541. Also modified comm logging, now each direction can be turned on separately. --- src/Protocol/Protocol17x.cpp | 45 ++++++++++++++++++++++++++++++++------------ src/main.cpp | 26 ++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 9bb2cfbf0..0d349de03 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -54,7 +54,7 @@ Implements the 1.7.x protocol classes: // fwd: main.cpp: -extern bool g_ShouldLogComm; +extern bool g_ShouldLogCommIn, g_ShouldLogCommOut; @@ -74,7 +74,7 @@ cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAdd m_IsEncrypted(false) { // Create the comm log file, if so requested: - if (g_ShouldLogComm) + if (g_ShouldLogCommIn || g_ShouldLogCommOut) { cFile::CreateFolder("CommLogs"); AString FileName = Printf("CommLogs/%x__%s.log", (unsigned)time(NULL), a_Client->GetIPString().c_str()); @@ -1083,7 +1083,7 @@ void cProtocol172::SendWindowProperty(const cWindow & a_Window, short a_Property void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) { // Write the incoming data into the comm log file: - if (g_ShouldLogComm) + if (g_ShouldLogCommIn) { if (m_ReceivedData.GetReadableSpace() > 0) { @@ -1092,9 +1092,10 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) m_ReceivedData.ReadAll(AllData); m_ReceivedData.ResetRead(); m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace); + ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); AString Hex; CreateHexDump(Hex, AllData.data(), AllData.size(), 16); - m_CommLogFile.Printf("Incoming data, %d (0x%x) bytes unparsed already present in buffer:\n%s\n", + m_CommLogFile.Printf("Incoming data, %d (0x%x) unparsed bytes already present in buffer:\n%s\n", AllData.size(), AllData.size(), Hex.c_str() ); } @@ -1103,6 +1104,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) m_CommLogFile.Printf("Incoming data: %d (0x%x) bytes: \n%s\n", a_Size, a_Size, Hex.c_str() ); + m_CommLogFile.Flush(); } if (!m_ReceivedData.Write(a_Data, a_Size)) @@ -1119,12 +1121,14 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) if (!m_ReceivedData.ReadVarInt(PacketLen)) { // Not enough data - return; + m_ReceivedData.ResetRead(); + break; } if (!m_ReceivedData.CanReadBytes(PacketLen)) { // The full packet hasn't been received yet - return; + m_ReceivedData.ResetRead(); + break; } cByteBuffer bb(PacketLen + 1); VERIFY(m_ReceivedData.ReadToByteBuffer(bb, (int)PacketLen)); @@ -1137,11 +1141,11 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) if (!bb.ReadVarInt(PacketType)) { // Not enough data - return; + break; } // Log the packet info into the comm log file: - if (g_ShouldLogComm) + if (g_ShouldLogCommIn) { AString PacketData; bb.ReadAll(PacketData); @@ -1173,7 +1177,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) #endif // _DEBUG // Put a message in the comm log: - if (g_ShouldLogComm) + if (g_ShouldLogCommIn) { m_CommLogFile.Printf("^^^^^^ Unhandled packet ^^^^^^\n\n\n"); } @@ -1189,7 +1193,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) ); // Put a message in the comm log: - if (g_ShouldLogComm) + if (g_ShouldLogCommIn) { m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %d left) ^^^^^^\n\n\n", 1, bb.GetReadableSpace() @@ -1200,7 +1204,24 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) ASSERT(!"Read wrong number of bytes!"); m_Client->PacketError(PacketType); } - } // while (true) + } // for(ever) + + // Log any leftover bytes into the logfile: + if (g_ShouldLogCommIn && (m_ReceivedData.GetReadableSpace() > 0)) + { + AString AllData; + int OldReadableSpace = m_ReceivedData.GetReadableSpace(); + m_ReceivedData.ReadAll(AllData); + m_ReceivedData.ResetRead(); + m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace); + ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); + AString Hex; + CreateHexDump(Hex, AllData.data(), AllData.size(), 16); + m_CommLogFile.Printf("There are %d (0x%x) bytes of non-parse-able data left in the buffer:\n%s", + m_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str() + ); + m_CommLogFile.Flush(); + } } @@ -1881,7 +1902,7 @@ cProtocol172::cPacketizer::~cPacketizer() m_Out.CommitRead(); // Log the comm into logfile: - if (g_ShouldLogComm) + if (g_ShouldLogCommOut) { AString Hex; ASSERT(DataToSend.size() > 0); diff --git a/src/main.cpp b/src/main.cpp index 0f6895d03..9acc7db3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,8 +19,11 @@ bool g_SERVER_TERMINATED = false; // Set to true when the server terminates, so -/** If set to true, the protocols will log each player's communication to a separate logfile */ -bool g_ShouldLogComm; +/** If set to true, the protocols will log each player's incoming (C->S) communication to a per-connection logfile */ +bool g_ShouldLogCommIn; + +/** If set to true, the protocols will log each player's outgoing (S->C) communication to a per-connection logfile */ +bool g_ShouldLogCommOut; @@ -242,7 +245,24 @@ int main( int argc, char **argv ) (NoCaseCompare(argv[i], "/logcomm") == 0) ) { - g_ShouldLogComm = true; + g_ShouldLogCommIn = true; + g_ShouldLogCommOut = true; + } + if ( + (NoCaseCompare(argv[i], "/commlogin") == 0) || + (NoCaseCompare(argv[i], "/comminlog") == 0) || + (NoCaseCompare(argv[i], "/logcommin") == 0) + ) + { + g_ShouldLogCommIn = true; + } + if ( + (NoCaseCompare(argv[i], "/commlogout") == 0) || + (NoCaseCompare(argv[i], "/commoutlog") == 0) || + (NoCaseCompare(argv[i], "/logcommout") == 0) + ) + { + g_ShouldLogCommOut = true; } } -- cgit v1.2.3 From ed95f4d81b3f54111430aec00d429aff267dfa92 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 14:40:31 +0100 Subject: Makes farmers farm crops. --- src/Mobs/Villager.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/Mobs/Villager.h | 5 ++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index c8ff4f101..0bf87157a 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -3,6 +3,8 @@ #include "Villager.h" #include "../World.h" +#include "../Blockarea.h" +#include "../Blocks/BlockHandler.h" @@ -10,7 +12,8 @@ cVillager::cVillager(eVillagerType VillagerType) : super("Villager", mtVillager, "", "", 0.6, 1.8), - m_Type(VillagerType) + m_Type(VillagerType), + m_DidFindCrops(false) { } @@ -33,3 +36,70 @@ void cVillager::DoTakeDamage(TakeDamageInfo & a_TDI) + +void cVillager::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + if (m_DidFindCrops) + { + Vector3i Pos = Vector3i(GetPosition()); + std::cout << Pos.Equals(m_CropsPos) << "\n"; + if (Pos.Equals(m_CropsPos)) + { + cBlockHandler Handler(E_BLOCK_CROPS); + Handler.DropBlock(m_World, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); + m_DidFindCrops = false; + } + } + + if (m_World->GetTickRandomNumber(50) != 0) + { + return; + } + + switch (m_Type) + { + case vtFarmer: + { + HandleFarmer(); + } + } + +} + + + + +void cVillager::HandleFarmer() +{ + cBlockArea Surrounding; + Surrounding.Read(m_World, + (int) GetPosX() - 5, + (int) GetPosX() + 5, + (int) GetPosY() - 3, + (int) GetPosY() + 3, + (int) GetPosZ() - 5, + (int) GetPosZ() + 5); + + // Check for crops in a 10x6x10 area. + for (int X = 0; X < 10; X++) + { + for (int Y = 0; Y < 6; Y++) + { + for (int Z = 0; Z < 10; Z++) + { + if (Surrounding.GetRelBlockType(X, Y, Z) == E_BLOCK_CROPS && Surrounding.GetRelBlockMeta(X, Y, Z) == 0x7) + { + m_DidFindCrops = true; + m_CropsPos = Vector3i((int) GetPosX() + X - 5, (int) GetPosY() + Y - 3, (int) GetPosZ() + Z - 5); + MoveToPosition(Vector3f((float) GetPosX() + X - 5, (float) GetPosY() + Y - 3, (float) GetPosZ() + Z - 5)); + return; + } + } + } + } +} + + + + diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index 4cd9aaa8e..b7cbe8ed0 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -30,11 +30,16 @@ public: CLASS_PROTODEF(cVillager); virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual void Tick (float a_Dt, cChunk & a_Chunk) override; + + void HandleFarmer(); int GetVilType(void) const { return m_Type; } private: int m_Type; + bool m_DidFindCrops; + Vector3i m_CropsPos; } ; -- cgit v1.2.3 From 969bf05a2686a24ccae6838d2cb9b3b2a0c55111 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 15:44:55 +0100 Subject: Villagers: Farmers can also harvest carrots and potatoes. --- src/Mobs/Villager.cpp | 46 +++++++++++++++++++++++++++++++++++++--------- src/Mobs/Villager.h | 1 + 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 0bf87157a..71907f6b7 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -43,11 +43,19 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) if (m_DidFindCrops) { Vector3i Pos = Vector3i(GetPosition()); - std::cout << Pos.Equals(m_CropsPos) << "\n"; if (Pos.Equals(m_CropsPos)) { - cBlockHandler Handler(E_BLOCK_CROPS); - Handler.DropBlock(m_World, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); + BLOCKTYPE CropBlock = m_World->GetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); + if (IsBlockFarmable(CropBlock) && m_World->GetBlockMeta(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z) == 0x7) + { + cItems Pickups; + //Pickups.Add(E_ITEM_WHEAT, 1, 0); + //Pickups.Add(E_ITEM_SEEDS, 1 + m_World->GetTickRandomNumber( + cBlockHandler Handler(CropBlock); + Handler.ConvertToPickups(Pickups, 0x7); + m_World->SpawnItemPickups(Pickups, m_CropsPos.x + 0.5, m_CropsPos.y + 0.5, m_CropsPos.z + 0.5); + m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_AIR, 0); + } m_DidFindCrops = false; } } @@ -64,7 +72,6 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) HandleFarmer(); } } - } @@ -88,13 +95,19 @@ void cVillager::HandleFarmer() { for (int Z = 0; Z < 10; Z++) { - if (Surrounding.GetRelBlockType(X, Y, Z) == E_BLOCK_CROPS && Surrounding.GetRelBlockMeta(X, Y, Z) == 0x7) + if (!IsBlockFarmable(Surrounding.GetRelBlockType(X, Y, Z))) { - m_DidFindCrops = true; - m_CropsPos = Vector3i((int) GetPosX() + X - 5, (int) GetPosY() + Y - 3, (int) GetPosZ() + Z - 5); - MoveToPosition(Vector3f((float) GetPosX() + X - 5, (float) GetPosY() + Y - 3, (float) GetPosZ() + Z - 5)); - return; + continue; } + if (Surrounding.GetRelBlockMeta(X, Y, Z) != 0x7) + { + continue; + } + + m_DidFindCrops = true; + m_CropsPos = Vector3i((int) GetPosX() + X - 5, (int) GetPosY() + Y - 3, (int) GetPosZ() + Z - 5); + MoveToPosition(Vector3f((float) (m_CropsPos.x + 0.5), (float) (m_CropsPos.y), (float) (m_CropsPos.z + 0.5))); + return; } } } @@ -103,3 +116,18 @@ void cVillager::HandleFarmer() + +bool cVillager::IsBlockFarmable(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_CROPS: + case E_BLOCK_POTATOES: + case E_BLOCK_CARROTS: + { + return true; + } + } + return false; +} + diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index b7cbe8ed0..9502f387c 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -33,6 +33,7 @@ public: virtual void Tick (float a_Dt, cChunk & a_Chunk) override; void HandleFarmer(); + bool IsBlockFarmable(BLOCKTYPE a_BlockType); int GetVilType(void) const { return m_Type; } private: -- cgit v1.2.3 From 89a620ca54bbeb9475ded781ef7af145571ab01a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 17:19:13 +0100 Subject: E_BLOCK_POTATOES isn't an solid block. Villagers were floating above them. --- src/BlockID.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BlockID.cpp b/src/BlockID.cpp index 095865d07..fbb5a0720 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -767,6 +767,7 @@ public: g_BlockIsSolid[E_BLOCK_MELON_STEM] = false; g_BlockIsSolid[E_BLOCK_NETHER_PORTAL] = false; g_BlockIsSolid[E_BLOCK_PISTON_EXTENSION] = false; + g_BlockIsSolid[E_BLOCK_POTATOES] = false; g_BlockIsSolid[E_BLOCK_POWERED_RAIL] = false; g_BlockIsSolid[E_BLOCK_RAIL] = false; g_BlockIsSolid[E_BLOCK_REDSTONE_TORCH_OFF] = false; -- cgit v1.2.3 From ca12decaf60bc7d6a32ee45c1a796edcde076e86 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 17:20:39 +0100 Subject: Villagers don't look for new crops when they already found one. Slight cleanup. --- src/Mobs/Villager.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 71907f6b7..b42c3ecaa 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -40,24 +40,19 @@ void cVillager::DoTakeDamage(TakeDamageInfo & a_TDI) void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - if (m_DidFindCrops) + if (m_DidFindCrops && !m_bMovingToDestination) { - Vector3i Pos = Vector3i(GetPosition()); - if (Pos.Equals(m_CropsPos)) + if ((GetPosition() - m_CropsPos).Length() < 2) { BLOCKTYPE CropBlock = m_World->GetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); if (IsBlockFarmable(CropBlock) && m_World->GetBlockMeta(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z) == 0x7) { - cItems Pickups; - //Pickups.Add(E_ITEM_WHEAT, 1, 0); - //Pickups.Add(E_ITEM_SEEDS, 1 + m_World->GetTickRandomNumber( cBlockHandler Handler(CropBlock); - Handler.ConvertToPickups(Pickups, 0x7); - m_World->SpawnItemPickups(Pickups, m_CropsPos.x + 0.5, m_CropsPos.y + 0.5, m_CropsPos.z + 0.5); + Handler.DropBlock(m_World, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_AIR, 0); } - m_DidFindCrops = false; } + m_DidFindCrops = false; } if (m_World->GetTickRandomNumber(50) != 0) @@ -69,7 +64,10 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { case vtFarmer: { - HandleFarmer(); + if (!m_DidFindCrops) + { + HandleFarmer(); + } } } } @@ -106,7 +104,7 @@ void cVillager::HandleFarmer() m_DidFindCrops = true; m_CropsPos = Vector3i((int) GetPosX() + X - 5, (int) GetPosY() + Y - 3, (int) GetPosZ() + Z - 5); - MoveToPosition(Vector3f((float) (m_CropsPos.x + 0.5), (float) (m_CropsPos.y), (float) (m_CropsPos.z + 0.5))); + MoveToPosition(Vector3f((float) (m_CropsPos.x + 0.5), (float) m_CropsPos.y, (float) (m_CropsPos.z + 0.5))); return; } } -- cgit v1.2.3 From 2cdd8f1961252da2723e7a1047e91ec4914eef57 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 17:30:18 +0100 Subject: Villagers: Fixed only gettings the crops block when farming. --- src/Mobs/Villager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index b42c3ecaa..4d358e0a6 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -47,8 +47,8 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) BLOCKTYPE CropBlock = m_World->GetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); if (IsBlockFarmable(CropBlock) && m_World->GetBlockMeta(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z) == 0x7) { - cBlockHandler Handler(CropBlock); - Handler.DropBlock(m_World, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); + cBlockHandler * Handler = cBlockHandler::GetBlockHandler(CropBlock); + Handler->DropBlock(m_World, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_AIR, 0); } } -- cgit v1.2.3 From 06c3bc1ea5e20c3ddc88f66631f675523789f398 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 18:27:57 +0100 Subject: Villagers: Farmers now replant the crops. --- src/Mobs/Villager.cpp | 17 ++++++++++++++++- src/Mobs/Villager.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 4d358e0a6..f52d60ffa 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -13,7 +13,8 @@ cVillager::cVillager(eVillagerType VillagerType) : super("Villager", mtVillager, "", "", 0.6, 1.8), m_Type(VillagerType), - m_DidFindCrops(false) + m_DidFindCrops(false), + m_ActionCountDown(-1) { } @@ -40,6 +41,19 @@ void cVillager::DoTakeDamage(TakeDamageInfo & a_TDI) void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (m_ActionCountDown > -1) + { + m_ActionCountDown--; + if (m_ActionCountDown == 0) + { + switch (m_Type) + { + case vtFarmer: m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_CROPS, 0); + } + } + return; + } + if (m_DidFindCrops && !m_bMovingToDestination) { if ((GetPosition() - m_CropsPos).Length() < 2) @@ -50,6 +64,7 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) cBlockHandler * Handler = cBlockHandler::GetBlockHandler(CropBlock); Handler->DropBlock(m_World, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_AIR, 0); + m_ActionCountDown = 20; } } m_DidFindCrops = false; diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index 9502f387c..bdbcab39b 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -38,6 +38,7 @@ public: private: + int m_ActionCountDown; int m_Type; bool m_DidFindCrops; Vector3i m_CropsPos; -- cgit v1.2.3 From 9807056a9cfcce00cf5c33ce6eae25f818ec9cf7 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 18:33:57 +0100 Subject: Added GetCropsPos and DidFindCrops functions. --- src/Mobs/Villager.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index bdbcab39b..235e1f40e 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -29,12 +29,18 @@ public: CLASS_PROTODEF(cVillager); + // Override functions virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void Tick (float a_Dt, cChunk & a_Chunk) override; + // cVillager functions void HandleFarmer(); bool IsBlockFarmable(BLOCKTYPE a_BlockType); + + // Get and set functions. int GetVilType(void) const { return m_Type; } + Vector3i GetCropsPos(void) const { return m_CropsPos; } + bool DidFindCrops(void) const { return m_DidFindCrops; } private: -- cgit v1.2.3 From 3dbe6c6de941873461951fc2fa8dc1be9d199768 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 18:58:09 +0100 Subject: Villager: Farmer: Crops finding is more random. --- src/Mobs/Villager.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index f52d60ffa..31e6e87a0 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -101,29 +101,30 @@ void cVillager::HandleFarmer() (int) GetPosZ() - 5, (int) GetPosZ() + 5); - // Check for crops in a 10x6x10 area. - for (int X = 0; X < 10; X++) + + for (int I = 0; I < 5; I++) { for (int Y = 0; Y < 6; Y++) { - for (int Z = 0; Z < 10; Z++) + // Pick random coordinates and check for crops. + int X = m_World->GetTickRandomNumber(11); + int Z = m_World->GetTickRandomNumber(11); + + if (!IsBlockFarmable(Surrounding.GetRelBlockType(X, Y, Z))) { - if (!IsBlockFarmable(Surrounding.GetRelBlockType(X, Y, Z))) - { - continue; - } - if (Surrounding.GetRelBlockMeta(X, Y, Z) != 0x7) - { - continue; - } - - m_DidFindCrops = true; - m_CropsPos = Vector3i((int) GetPosX() + X - 5, (int) GetPosY() + Y - 3, (int) GetPosZ() + Z - 5); - MoveToPosition(Vector3f((float) (m_CropsPos.x + 0.5), (float) m_CropsPos.y, (float) (m_CropsPos.z + 0.5))); - return; + continue; } - } - } + if (Surrounding.GetRelBlockMeta(X, Y, Z) != 0x7) + { + continue; + } + + m_DidFindCrops = true; + m_CropsPos = Vector3i((int) GetPosX() + X - 5, (int) GetPosY() + Y - 3, (int) GetPosZ() + Z - 5); + MoveToPosition(Vector3f((float) (m_CropsPos.x + 0.5), (float) m_CropsPos.y, (float) (m_CropsPos.z + 0.5))); + return; + } // for Y loop. + } // Repeat the procces 5 times. } -- cgit v1.2.3 From 9cf006eceafac87aa7fc5d74ee3eed3740f95b60 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 19:06:50 +0100 Subject: Fixed compiler error. --- src/Mobs/Villager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 31e6e87a0..ef362b559 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -3,7 +3,7 @@ #include "Villager.h" #include "../World.h" -#include "../Blockarea.h" +#include "../BlockArea.h" #include "../Blocks/BlockHandler.h" -- cgit v1.2.3 From fc9e5278304adf811becf90e62311c1318e9658d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 27 Jan 2014 18:57:14 +0000 Subject: SIGABRT exits with failure. --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 9acc7db3a..c8cd2d4fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,6 +69,7 @@ void NonCtrlHandler(int a_Signal) std::signal(a_Signal, SIG_DFL); LOGERROR(" D: | MCServer has encountered an error and needs to close"); LOGERROR("Details | SIGABRT: Server self-terminated due to an internal fault"); + exit(EXIT_FAILURE); break; } case SIGINT: -- cgit v1.2.3 From f5589a1ec722474bfde7e2a6a619388169bd5271 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 27 Jan 2014 19:34:18 +0000 Subject: Updated polarssl --- lib/polarssl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/polarssl b/lib/polarssl index c78c8422c..2cb1a0c40 160000 --- a/lib/polarssl +++ b/lib/polarssl @@ -1 +1 @@ -Subproject commit c78c8422c25b9dc38f09eded3200d565375522e2 +Subproject commit 2cb1a0c4009ecf368ecc74eb428394e10f9e6d00 -- cgit v1.2.3 From 5b983b72fa0508fee5135153c9273f5e37fb5467 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 20:44:18 +0100 Subject: Villager: Farmers can't place crops on blocks other then farmland. --- src/Mobs/Villager.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index ef362b559..5d6d7482f 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -48,7 +48,13 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { switch (m_Type) { - case vtFarmer: m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_CROPS, 0); + case vtFarmer: + { + if (m_World->GetBlock(m_CropsPos.x, m_CropsPos.y - 1, m_CropsPos.z) == E_BLOCK_FARMLAND) + { + m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_CROPS, 0); + } + } } } return; -- cgit v1.2.3 From 723bb78dd144a34adae5502b4d526ab887b911d5 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 20:52:42 +0100 Subject: Villagers: Harvesting is more rare. --- src/Mobs/Villager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 5d6d7482f..46346fa9f 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -76,7 +76,7 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) m_DidFindCrops = false; } - if (m_World->GetTickRandomNumber(50) != 0) + if (m_World->GetTickRandomNumber(100) != 0) { return; } -- cgit v1.2.3 From cc1284a753874aa7d351a6ea41aaec4662ca6e57 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 27 Jan 2014 21:27:13 +0100 Subject: Rewritten networking to use non-blocking sockets. This fixes #592. --- src/OSSupport/Socket.cpp | 31 +++++++- src/OSSupport/Socket.h | 9 +++ src/OSSupport/SocketThreads.cpp | 172 +++++++++++++++++++++++++++------------- src/OSSupport/SocketThreads.h | 26 ++++-- 4 files changed, 176 insertions(+), 62 deletions(-) diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp index 4226a7535..3248eed88 100644 --- a/src/OSSupport/Socket.cpp +++ b/src/OSSupport/Socket.cpp @@ -320,7 +320,7 @@ bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Por -int cSocket::Receive(char* a_Buffer, unsigned int a_Length, unsigned int a_Flags) +int cSocket::Receive(char * a_Buffer, unsigned int a_Length, unsigned int a_Flags) { return recv(m_Socket, a_Buffer, a_Length, a_Flags); } @@ -354,3 +354,32 @@ unsigned short cSocket::GetPort(void) const + +void cSocket::SetNonBlocking(void) +{ + #ifdef _WIN32 + u_long NonBlocking = 1; + int res = ioctlsocket(m_Socket, FIONBIO, &NonBlocking); + if (res != 0) + { + LOGERROR("Cannot set socket to non-blocking. This would make the server deadlock later on, aborting.\nErr: %d, %d, %s", + res, GetLastError(), GetLastErrorString().c_str() + ); + abort(); + } + #else + int NonBlocking = 1; + int res = ioctl(m_Socket, FIONBIO, (char *)&NonBlocking); + if (res != 0) + { + LOGERROR("Cannot set socket to non-blocking. This would make the server deadlock later on, aborting.\nErr: %d, %d, %s", + res, GetLastError(), GetLastErrorString().c_str() + ); + abort(); + } + #endif +} + + + + diff --git a/src/OSSupport/Socket.h b/src/OSSupport/Socket.h index 4ca3d61f4..bdc2babf5 100644 --- a/src/OSSupport/Socket.h +++ b/src/OSSupport/Socket.h @@ -24,6 +24,12 @@ public: { IPv4 = AF_INET, IPv6 = AF_INET6, + + #ifdef _WIN32 + ErrWouldBlock = WSAEWOULDBLOCK, + #else + ErrWouldBlock = EWOULDBLOCK, + #endif } ; #ifdef _WIN32 @@ -110,6 +116,9 @@ public: unsigned short GetPort(void) const; // Returns 0 on failure const AString & GetIPString(void) const { return m_IPString; } + + /** Sets the socket into non-blocking mode */ + void SetNonBlocking(void); private: xSocket m_Socket; diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp index 74932daf8..3e2631733 100644 --- a/src/OSSupport/SocketThreads.cpp +++ b/src/OSSupport/SocketThreads.cpp @@ -175,6 +175,7 @@ void cSocketThreads::cSocketThread::AddClient(const cSocket & a_Socket, cCallbac m_Slots[m_NumSlots].m_Client = a_Client; m_Slots[m_NumSlots].m_Socket = a_Socket; + m_Slots[m_NumSlots].m_Socket.SetNonBlocking(); m_Slots[m_NumSlots].m_Outgoing.clear(); m_Slots[m_NumSlots].m_State = sSlot::ssNormal; m_NumSlots++; @@ -213,7 +214,9 @@ bool cSocketThreads::cSocketThread::RemoveClient(const cCallback * a_Client) else { // Query and queue the last batch of outgoing data: - m_Slots[i].m_Client->GetOutgoingData(m_Slots[i].m_Outgoing); + AString Data; + m_Slots[i].m_Client->GetOutgoingData(Data); + m_Slots[i].m_Outgoing.append(Data); if (m_Slots[i].m_Outgoing.empty()) { // No more outgoing data, shut the socket down immediately: @@ -386,38 +389,28 @@ void cSocketThreads::cSocketThread::Execute(void) // The main thread loop: while (!m_ShouldTerminate) { - // Put all sockets into the Read set: + // Read outgoing data from the clients: + QueueOutgoingData(); + + // Put sockets into the sets fd_set fdRead; + fd_set fdWrite; cSocket::xSocket Highest = m_ControlSocket1.GetSocket(); - - PrepareSet(&fdRead, Highest, false); + PrepareSets(&fdRead, &fdWrite, Highest); // Wait for the sockets: timeval Timeout; Timeout.tv_sec = 5; Timeout.tv_usec = 0; - if (select(Highest + 1, &fdRead, NULL, NULL, &Timeout) == -1) + if (select(Highest + 1, &fdRead, &fdWrite, NULL, &Timeout) == -1) { - LOG("select(R) call failed in cSocketThread: \"%s\"", cSocket::GetLastErrorString().c_str()); + LOG("select() call failed in cSocketThread: \"%s\"", cSocket::GetLastErrorString().c_str()); continue; } + // Perform the IO: ReadFromSockets(&fdRead); - - // Test sockets for writing: - fd_set fdWrite; - Highest = m_ControlSocket1.GetSocket(); - PrepareSet(&fdWrite, Highest, true); - Timeout.tv_sec = 0; - Timeout.tv_usec = 0; - if (select(Highest + 1, NULL, &fdWrite, NULL, &Timeout) == -1) - { - LOG("select(W) call failed in cSocketThread: \"%s\"", cSocket::GetLastErrorString().c_str()); - continue; - } - WriteToSockets(&fdWrite); - CleanUpShutSockets(); } // while (!mShouldTerminate) } @@ -426,10 +419,11 @@ void cSocketThreads::cSocketThread::Execute(void) -void cSocketThreads::cSocketThread::PrepareSet(fd_set * a_Set, cSocket::xSocket & a_Highest, bool a_IsForWriting) +void cSocketThreads::cSocketThread::PrepareSets(fd_set * a_Read, fd_set * a_Write, cSocket::xSocket & a_Highest) { - FD_ZERO(a_Set); - FD_SET(m_ControlSocket1.GetSocket(), a_Set); + FD_ZERO(a_Read); + FD_ZERO(a_Write); + FD_SET(m_ControlSocket1.GetSocket(), a_Read); cCSLock Lock(m_Parent->m_CS); for (int i = m_NumSlots - 1; i >= 0; --i) @@ -444,11 +438,16 @@ void cSocketThreads::cSocketThread::PrepareSet(fd_set * a_Set, cSocket::xSocket continue; } cSocket::xSocket s = m_Slots[i].m_Socket.GetSocket(); - FD_SET(s, a_Set); + FD_SET(s, a_Read); if (s > a_Highest) { a_Highest = s; } + if (!m_Slots[i].m_Outgoing.empty()) + { + // There's outgoing data for the socket, put it in the Write set + FD_SET(s, a_Write); + } } // for i - m_Slots[] } @@ -480,34 +479,37 @@ void cSocketThreads::cSocketThread::ReadFromSockets(fd_set * a_Read) int Received = m_Slots[i].m_Socket.Receive(Buffer, ARRAYCOUNT(Buffer), 0); if (Received <= 0) { - // The socket has been closed by the remote party - switch (m_Slots[i].m_State) + if (cSocket::GetLastError() != cSocket::ErrWouldBlock) { - case sSlot::ssNormal: - { - // Notify the callback that the remote has closed the socket; keep the slot - m_Slots[i].m_Client->SocketClosed(); - m_Slots[i].m_State = sSlot::ssRemoteClosed; - break; - } - case sSlot::ssWritingRestOut: - case sSlot::ssShuttingDown: - case sSlot::ssShuttingDown2: - { - // Force-close the socket and remove the slot: - m_Slots[i].m_Socket.CloseSocket(); - m_Slots[i] = m_Slots[--m_NumSlots]; - break; - } - default: + // The socket has been closed by the remote party + switch (m_Slots[i].m_State) { - LOG("%s: Unexpected socket state: %d (%s)", - __FUNCTION__, m_Slots[i].m_Socket.GetSocket(), m_Slots[i].m_Socket.GetIPString().c_str() - ); - ASSERT(!"Unexpected socket state"); - break; - } - } // switch (m_Slots[i].m_State) + case sSlot::ssNormal: + { + // Notify the callback that the remote has closed the socket; keep the slot + m_Slots[i].m_Client->SocketClosed(); + m_Slots[i].m_State = sSlot::ssRemoteClosed; + break; + } + case sSlot::ssWritingRestOut: + case sSlot::ssShuttingDown: + case sSlot::ssShuttingDown2: + { + // Force-close the socket and remove the slot: + m_Slots[i].m_Socket.CloseSocket(); + m_Slots[i] = m_Slots[--m_NumSlots]; + break; + } + default: + { + LOG("%s: Unexpected socket state: %d (%s)", + __FUNCTION__, m_Slots[i].m_Socket.GetSocket(), m_Slots[i].m_Socket.GetIPString().c_str() + ); + ASSERT(!"Unexpected socket state"); + break; + } + } // switch (m_Slots[i].m_State) + } } else { @@ -539,7 +541,9 @@ void cSocketThreads::cSocketThread::WriteToSockets(fd_set * a_Write) // Request another chunk of outgoing data: if (m_Slots[i].m_Client != NULL) { - m_Slots[i].m_Client->GetOutgoingData(m_Slots[i].m_Outgoing); + AString Data; + m_Slots[i].m_Client->GetOutgoingData(Data); + m_Slots[i].m_Outgoing.append(Data); } if (m_Slots[i].m_Outgoing.empty()) { @@ -553,8 +557,7 @@ void cSocketThreads::cSocketThread::WriteToSockets(fd_set * a_Write) } } // if (outgoing data is empty) - int Sent = m_Slots[i].m_Socket.Send(m_Slots[i].m_Outgoing.data(), m_Slots[i].m_Outgoing.size()); - if (Sent < 0) + if (!SendDataThroughSocket(m_Slots[i].m_Socket, m_Slots[i].m_Outgoing)) { int Err = cSocket::GetLastError(); LOGWARNING("Error %d while writing to client \"%s\", disconnecting. \"%s\"", Err, m_Slots[i].m_Socket.GetIPString().c_str(), GetOSErrorString(Err).c_str()); @@ -565,7 +568,6 @@ void cSocketThreads::cSocketThread::WriteToSockets(fd_set * a_Write) } return; } - m_Slots[i].m_Outgoing.erase(0, Sent); if (m_Slots[i].m_Outgoing.empty() && (m_Slots[i].m_State == sSlot::ssWritingRestOut)) { @@ -590,8 +592,41 @@ void cSocketThreads::cSocketThread::WriteToSockets(fd_set * a_Write) +bool cSocketThreads::cSocketThread::SendDataThroughSocket(cSocket & a_Socket, AString & a_Data) +{ + // Send data in smaller chunks, so that the OS send buffers aren't overflown easily + while (!a_Data.empty()) + { + size_t NumToSend = std::min(a_Data.size(), (size_t)1024); + int Sent = a_Socket.Send(a_Data.data(), NumToSend); + if (Sent < 0) + { + int Err = cSocket::GetLastError(); + if (Err == cSocket::ErrWouldBlock) + { + // The OS send buffer is full, leave the outgoing data for the next time + return true; + } + // An error has occured + return false; + } + if (Sent == 0) + { + a_Socket.CloseSocket(); + return true; + } + a_Data.erase(0, Sent); + } + return true; +} + + + + + void cSocketThreads::cSocketThread::CleanUpShutSockets(void) { + cCSLock Lock(m_Parent->m_CS); for (int i = m_NumSlots - 1; i >= 0; i--) { switch (m_Slots[i].m_State) @@ -617,3 +652,32 @@ void cSocketThreads::cSocketThread::CleanUpShutSockets(void) +void cSocketThreads::cSocketThread::QueueOutgoingData(void) +{ + cCSLock Lock(m_Parent->m_CS); + for (int i = 0; i < m_NumSlots; i++) + { + if (m_Slots[i].m_Client != NULL) + { + AString Data; + m_Slots[i].m_Client->GetOutgoingData(Data); + m_Slots[i].m_Outgoing.append(Data); + } + if (m_Slots[i].m_Outgoing.empty()) + { + // No outgoing data is ready + if (m_Slots[i].m_State == sSlot::ssWritingRestOut) + { + // The socket doesn't want to be kept alive anymore, and doesn't have any remaining data to send. + // Shut it down and then close it after a timeout, or when the other side agrees + m_Slots[i].m_State = sSlot::ssShuttingDown; + m_Slots[i].m_Socket.ShutdownReadWrite(); + } + continue; + } + } +} + + + + diff --git a/src/OSSupport/SocketThreads.h b/src/OSSupport/SocketThreads.h index 9e1947ab6..fcd2ce11f 100644 --- a/src/OSSupport/SocketThreads.h +++ b/src/OSSupport/SocketThreads.h @@ -66,7 +66,8 @@ public: /** Called when data is received from the remote party */ virtual void DataReceived(const char * a_Data, int a_Size) = 0; - /** Called when data can be sent to remote party; the function is supposed to *append* outgoing data to a_Data */ + /** Called when data can be sent to remote party + The function is supposed to *set* outgoing data to a_Data (overwrite) */ virtual void GetOutgoingData(AString & a_Data) = 0; /** Called when the socket has been closed for any reason */ @@ -156,16 +157,27 @@ private: virtual void Execute(void) override; - /** Puts all sockets into the set, along with m_ControlSocket1. - Only sockets that are able to send and receive data are put in the Set. - Is a_IsForWriting is true, the ssWritingRestOut sockets are added as well. */ - void PrepareSet(fd_set * a_Set, cSocket::xSocket & a_Highest, bool a_IsForWriting); + /** Prepares the Read and Write socket sets for select() + Puts all sockets into the read set, along with m_ControlSocket1. + Only sockets that have outgoing data queued on them are put in the write set.*/ + void PrepareSets(fd_set * a_ReadSet, fd_set * a_WriteSet, cSocket::xSocket & a_Highest); - void ReadFromSockets(fd_set * a_Read); // Reads from sockets indicated in a_Read - void WriteToSockets (fd_set * a_Write); // Writes to sockets indicated in a_Write + /** Reads from sockets indicated in a_Read */ + void ReadFromSockets(fd_set * a_Read); + /** Writes to sockets indicated in a_Write */ + void WriteToSockets (fd_set * a_Write); + + /** Sends data through the specified socket, trying to fill the OS send buffer in chunks. + Returns true if there was no error while sending, false if an error has occured. + Modifies a_Data to contain only the unsent data. */ + bool SendDataThroughSocket(cSocket & a_Socket, AString & a_Data); + /** Removes those slots in ssShuttingDown2 state, sets those with ssShuttingDown state to ssShuttingDown2 */ void CleanUpShutSockets(void); + + /** Calls each client's callback to retrieve outgoing data for that client. */ + void QueueOutgoingData(void); } ; typedef std::list cSocketThreadList; -- cgit v1.2.3 From 4169af1ce1a022d364edfa3313aa5a21d594f198 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 27 Jan 2014 21:33:06 +0100 Subject: Fixed Linux compilation. --- src/OSSupport/Socket.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp index 3248eed88..064abbab5 100644 --- a/src/OSSupport/Socket.cpp +++ b/src/OSSupport/Socket.cpp @@ -6,7 +6,8 @@ #ifndef _WIN32 #include #include - #include //inet_ntoa() + #include // inet_ntoa() + #include // ioctl() #else #define socklen_t int #endif -- cgit v1.2.3 From 33ad2761a0acb79ce938ebf518a731264617c03d Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 21:34:22 +0100 Subject: Cleanup Most code in Tick is now split up in different functions. --- src/Mobs/Villager.cpp | 86 ++++++++++++++++++++++++++++++++++----------------- src/Mobs/Villager.h | 10 ++++-- 2 files changed, 65 insertions(+), 31 deletions(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 46346fa9f..e39d8bc1f 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -13,7 +13,7 @@ cVillager::cVillager(eVillagerType VillagerType) : super("Villager", mtVillager, "", "", 0.6, 1.8), m_Type(VillagerType), - m_DidFindCrops(false), + m_VillagerAction(false), m_ActionCountDown(-1) { } @@ -50,33 +50,33 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { case vtFarmer: { - if (m_World->GetBlock(m_CropsPos.x, m_CropsPos.y - 1, m_CropsPos.z) == E_BLOCK_FARMLAND) - { - m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_CROPS, 0); - } + HandleFarmerNoCountDown(); } } } return; } - if (m_DidFindCrops && !m_bMovingToDestination) + if (m_VillagerAction) { - if ((GetPosition() - m_CropsPos).Length() < 2) + switch (m_Type) { - BLOCKTYPE CropBlock = m_World->GetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); - if (IsBlockFarmable(CropBlock) && m_World->GetBlockMeta(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z) == 0x7) + case vtFarmer: { - cBlockHandler * Handler = cBlockHandler::GetBlockHandler(CropBlock); - Handler->DropBlock(m_World, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); - m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_AIR, 0); - m_ActionCountDown = 20; + HandleFarmerAction(); } } - m_DidFindCrops = false; + m_VillagerAction = false; } - if (m_World->GetTickRandomNumber(100) != 0) + // The villager already has an special action activated. + if (m_VillagerAction) + { + return; + } + + // Don't always try to do a special action. Each tick has 1% to do a special action. + if (m_World->GetTickRandomNumber(99) != 0) { return; } @@ -85,10 +85,7 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { case vtFarmer: { - if (!m_DidFindCrops) - { - HandleFarmer(); - } + HandleFarmerAttemptSpecialAction(); } } } @@ -96,16 +93,19 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) -void cVillager::HandleFarmer() +void cVillager::HandleFarmerAttemptSpecialAction() { cBlockArea Surrounding; - Surrounding.Read(m_World, - (int) GetPosX() - 5, - (int) GetPosX() + 5, - (int) GetPosY() - 3, - (int) GetPosY() + 3, - (int) GetPosZ() - 5, - (int) GetPosZ() + 5); + /// Read a 11x7x11 area. + Surrounding.Read( + m_World, + (int) GetPosX() - 5, + (int) GetPosX() + 5, + (int) GetPosY() - 3, + (int) GetPosY() + 3, + (int) GetPosZ() - 5, + (int) GetPosZ() + 5 + ); for (int I = 0; I < 5; I++) @@ -125,7 +125,7 @@ void cVillager::HandleFarmer() continue; } - m_DidFindCrops = true; + m_VillagerAction = true; m_CropsPos = Vector3i((int) GetPosX() + X - 5, (int) GetPosY() + Y - 3, (int) GetPosZ() + Z - 5); MoveToPosition(Vector3f((float) (m_CropsPos.x + 0.5), (float) m_CropsPos.y, (float) (m_CropsPos.z + 0.5))); return; @@ -137,6 +137,36 @@ void cVillager::HandleFarmer() +void cVillager::HandleFarmerAction() +{ + if (!m_bMovingToDestination && (GetPosition() - m_CropsPos).Length() < 2) + { + BLOCKTYPE CropBlock = m_World->GetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); + if (IsBlockFarmable(CropBlock) && m_World->GetBlockMeta(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z) == 0x7) + { + cBlockHandler * Handler = cBlockHandler::GetBlockHandler(CropBlock); + Handler->DropBlock(m_World, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); + m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_AIR, 0); + m_ActionCountDown = 20; + } + } +} + + + + +void cVillager::HandleFarmerNoCountDown() +{ + if (m_World->GetBlock(m_CropsPos.x, m_CropsPos.y - 1, m_CropsPos.z) == E_BLOCK_FARMLAND) + { + m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_CROPS, 0); + } +} + + + + + bool cVillager::IsBlockFarmable(BLOCKTYPE a_BlockType) { switch (a_BlockType) diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index 235e1f40e..20dbada61 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -34,19 +34,23 @@ public: virtual void Tick (float a_Dt, cChunk & a_Chunk) override; // cVillager functions - void HandleFarmer(); bool IsBlockFarmable(BLOCKTYPE a_BlockType); + // Farmer functions + void HandleFarmerAttemptSpecialAction(); + void HandleFarmerAction(); + void HandleFarmerNoCountDown(); + // Get and set functions. int GetVilType(void) const { return m_Type; } Vector3i GetCropsPos(void) const { return m_CropsPos; } - bool DidFindCrops(void) const { return m_DidFindCrops; } + bool DoesHaveActionActivated(void) const { return m_VillagerAction; } private: int m_ActionCountDown; int m_Type; - bool m_DidFindCrops; + bool m_VillagerAction; Vector3i m_CropsPos; } ; -- cgit v1.2.3 From a359275064ecbaf3608995e82875532419a8ed80 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 27 Jan 2014 21:34:54 +0100 Subject: Squashed common code. --- src/OSSupport/Socket.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp index 064abbab5..6afaceedf 100644 --- a/src/OSSupport/Socket.cpp +++ b/src/OSSupport/Socket.cpp @@ -361,24 +361,17 @@ void cSocket::SetNonBlocking(void) #ifdef _WIN32 u_long NonBlocking = 1; int res = ioctlsocket(m_Socket, FIONBIO, &NonBlocking); - if (res != 0) - { - LOGERROR("Cannot set socket to non-blocking. This would make the server deadlock later on, aborting.\nErr: %d, %d, %s", - res, GetLastError(), GetLastErrorString().c_str() - ); - abort(); - } #else int NonBlocking = 1; int res = ioctl(m_Socket, FIONBIO, (char *)&NonBlocking); - if (res != 0) - { - LOGERROR("Cannot set socket to non-blocking. This would make the server deadlock later on, aborting.\nErr: %d, %d, %s", - res, GetLastError(), GetLastErrorString().c_str() - ); - abort(); - } #endif + if (res != 0) + { + LOGERROR("Cannot set socket to non-blocking. This would make the server deadlock later on, aborting.\nErr: %d, %d, %s", + res, GetLastError(), GetLastErrorString().c_str() + ); + abort(); + } } -- cgit v1.2.3 From 8bf9043f98900a870c18389fe367e156da6b9f6c Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 21:39:00 +0100 Subject: Villager: Few more comments. --- src/Mobs/Villager.cpp | 11 ++++++++--- src/Mobs/Villager.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index e39d8bc1f..262f13a99 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -50,7 +50,7 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { case vtFarmer: { - HandleFarmerNoCountDown(); + HandleFarmerEndCountDown(); } } } @@ -93,6 +93,8 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) +//////////////////////////////////////////////////////////////////////////////// +// Farmer functions. void cVillager::HandleFarmerAttemptSpecialAction() { cBlockArea Surrounding; @@ -107,7 +109,6 @@ void cVillager::HandleFarmerAttemptSpecialAction() (int) GetPosZ() + 5 ); - for (int I = 0; I < 5; I++) { for (int Y = 0; Y < 6; Y++) @@ -116,6 +117,7 @@ void cVillager::HandleFarmerAttemptSpecialAction() int X = m_World->GetTickRandomNumber(11); int Z = m_World->GetTickRandomNumber(11); + // A villager can't farm this. if (!IsBlockFarmable(Surrounding.GetRelBlockType(X, Y, Z))) { continue; @@ -139,8 +141,10 @@ void cVillager::HandleFarmerAttemptSpecialAction() void cVillager::HandleFarmerAction() { + // Harvest the crops if the villager isn't moving and if the crops are closer then 2 blocks. if (!m_bMovingToDestination && (GetPosition() - m_CropsPos).Length() < 2) { + // Check if the blocks didn't change while the villager was walking to the coordinates. BLOCKTYPE CropBlock = m_World->GetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); if (IsBlockFarmable(CropBlock) && m_World->GetBlockMeta(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z) == 0x7) { @@ -155,8 +159,9 @@ void cVillager::HandleFarmerAction() -void cVillager::HandleFarmerNoCountDown() +void cVillager::HandleFarmerEndCountDown() { + // Check if there is still farmland at the spot where the crops were. if (m_World->GetBlock(m_CropsPos.x, m_CropsPos.y - 1, m_CropsPos.z) == E_BLOCK_FARMLAND) { m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_CROPS, 0); diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index 20dbada61..979d2a3ac 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -39,7 +39,7 @@ public: // Farmer functions void HandleFarmerAttemptSpecialAction(); void HandleFarmerAction(); - void HandleFarmerNoCountDown(); + void HandleFarmerEndCountDown(); // Get and set functions. int GetVilType(void) const { return m_Type; } -- cgit v1.2.3 From babc80ed777f2ee74ce770d95bd3ec5743370570 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 22:02:19 +0100 Subject: The world can now be configured wether farmers should be able to harvest crops. --- src/Mobs/Villager.cpp | 10 ++++++++++ src/World.cpp | 1 + src/World.h | 3 +++ 3 files changed, 14 insertions(+) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 262f13a99..74a2a6d99 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -141,6 +141,11 @@ void cVillager::HandleFarmerAttemptSpecialAction() void cVillager::HandleFarmerAction() { + if (!m_World->VillagersShouldHarvestCrops()) + { + return; + } + // Harvest the crops if the villager isn't moving and if the crops are closer then 2 blocks. if (!m_bMovingToDestination && (GetPosition() - m_CropsPos).Length() < 2) { @@ -161,6 +166,11 @@ void cVillager::HandleFarmerAction() void cVillager::HandleFarmerEndCountDown() { + if (!m_World->VillagersShouldHarvestCrops()) + { + return; + } + // Check if there is still farmland at the spot where the crops were. if (m_World->GetBlock(m_CropsPos.x, m_CropsPos.y - 1, m_CropsPos.z) == E_BLOCK_FARMLAND) { diff --git a/src/World.cpp b/src/World.cpp index 5205c2616..88bbf5f8a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -547,6 +547,7 @@ void cWorld::Start(void) m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", false); m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true); m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false); + m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true); m_GameMode = (eGameMode)IniFile.GetValueSetI("GameMode", "GameMode", m_GameMode); diff --git a/src/World.h b/src/World.h index d7a7241d1..4d5659ee6 100644 --- a/src/World.h +++ b/src/World.h @@ -138,6 +138,8 @@ public: bool ShouldLavaSpawnFire(void) const { return m_ShouldLavaSpawnFire; } + bool VillagersShouldHarvestCrops(void) const { return m_VillagersShouldHarvestCrops; } + eDimension GetDimension(void) const { return m_Dimension; } /** Returns the world height at the specified coords; waits for the chunk to get loaded / generated */ @@ -743,6 +745,7 @@ private: bool m_bEnabledPVP; bool m_IsDeepSnowEnabled; bool m_ShouldLavaSpawnFire; + bool m_VillagersShouldHarvestCrops; std::vector m_BlockTickQueue; std::vector m_BlockTickQueueCopy; // Second is for safely removing the objects from the queue -- cgit v1.2.3 From 807a4dba989ad397c5f624f0a245df55103ee117 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 22:04:24 +0100 Subject: Villager doesn't check the environment for crops if it doesn't need to. --- src/Mobs/Villager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 74a2a6d99..4a3cce26e 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -97,6 +97,11 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) // Farmer functions. void cVillager::HandleFarmerAttemptSpecialAction() { + if (!m_World->VillagersShouldHarvestCrops()) + { + return; + } + cBlockArea Surrounding; /// Read a 11x7x11 area. Surrounding.Read( -- cgit v1.2.3 From 81837edb22197b48c3da4c47954681096a867766 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 28 Jan 2014 09:50:48 +0100 Subject: Fixed a slight bug in RSA encryption code. --- src/Crypto.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Crypto.cpp b/src/Crypto.cpp index 2045d0385..540b5cfde 100644 --- a/src/Crypto.cpp +++ b/src/Crypto.cpp @@ -214,7 +214,6 @@ int cRSAPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte ASSERT(!"Invalid a_PlainLength!"); return -1; } - size_t DecryptedLength; int res = rsa_pkcs1_encrypt( &m_Rsa, ctr_drbg_random, &m_Ctr_drbg, RSA_PUBLIC, a_PlainLength, a_PlainData, a_EncryptedData @@ -223,7 +222,7 @@ int cRSAPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte { return -1; } - return (int)DecryptedLength; + return (int)m_Rsa.len; } -- cgit v1.2.3 From b2bacf3a25001ed855319d6f2146a3d5e734f43c Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 28 Jan 2014 15:40:13 +0100 Subject: Villager: NoCountDown and Action function don't check VillagersShouldHarvestCrops anymore because it shoudn't even be activated anywhere. --- src/Mobs/Villager.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 4a3cce26e..021d4c672 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -146,11 +146,6 @@ void cVillager::HandleFarmerAttemptSpecialAction() void cVillager::HandleFarmerAction() { - if (!m_World->VillagersShouldHarvestCrops()) - { - return; - } - // Harvest the crops if the villager isn't moving and if the crops are closer then 2 blocks. if (!m_bMovingToDestination && (GetPosition() - m_CropsPos).Length() < 2) { @@ -171,11 +166,6 @@ void cVillager::HandleFarmerAction() void cVillager::HandleFarmerEndCountDown() { - if (!m_World->VillagersShouldHarvestCrops()) - { - return; - } - // Check if there is still farmland at the spot where the crops were. if (m_World->GetBlock(m_CropsPos.x, m_CropsPos.y - 1, m_CropsPos.z) == E_BLOCK_FARMLAND) { -- cgit v1.2.3 From 8ca98e0c0e09706561ed54cf8be95a731157a59e Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 28 Jan 2014 16:26:44 +0100 Subject: Renamed Farmer functions and added doxycomments --- src/Mobs/Villager.cpp | 18 +++++++----------- src/Mobs/Villager.h | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 021d4c672..44ec14295 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -41,6 +41,7 @@ void cVillager::DoTakeDamage(TakeDamageInfo & a_TDI) void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (m_ActionCountDown > -1) { m_ActionCountDown--; @@ -50,7 +51,7 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { case vtFarmer: { - HandleFarmerEndCountDown(); + HandleFarmerPlaceCrops(); } } } @@ -63,15 +64,10 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { case vtFarmer: { - HandleFarmerAction(); + HandleFarmerTryHarvestCrops(); } } m_VillagerAction = false; - } - - // The villager already has an special action activated. - if (m_VillagerAction) - { return; } @@ -85,7 +81,7 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { case vtFarmer: { - HandleFarmerAttemptSpecialAction(); + HandleFarmerPrepareFarmCrops(); } } } @@ -95,7 +91,7 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) //////////////////////////////////////////////////////////////////////////////// // Farmer functions. -void cVillager::HandleFarmerAttemptSpecialAction() +void cVillager::HandleFarmerPrepareFarmCrops() { if (!m_World->VillagersShouldHarvestCrops()) { @@ -144,7 +140,7 @@ void cVillager::HandleFarmerAttemptSpecialAction() -void cVillager::HandleFarmerAction() +void cVillager::HandleFarmerTryHarvestCrops() { // Harvest the crops if the villager isn't moving and if the crops are closer then 2 blocks. if (!m_bMovingToDestination && (GetPosition() - m_CropsPos).Length() < 2) @@ -164,7 +160,7 @@ void cVillager::HandleFarmerAction() -void cVillager::HandleFarmerEndCountDown() +void cVillager::HandleFarmerPlaceCrops() { // Check if there is still farmland at the spot where the crops were. if (m_World->GetBlock(m_CropsPos.x, m_CropsPos.y - 1, m_CropsPos.z) == E_BLOCK_FARMLAND) diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index 979d2a3ac..b99ae876f 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -34,17 +34,24 @@ public: virtual void Tick (float a_Dt, cChunk & a_Chunk) override; // cVillager functions + /** return true if the given blocktype are: crops, potatoes or carrots.*/ bool IsBlockFarmable(BLOCKTYPE a_BlockType); + ////////////////////////////////////////////////////////////////// // Farmer functions - void HandleFarmerAttemptSpecialAction(); - void HandleFarmerAction(); - void HandleFarmerEndCountDown(); + /** It searches in a 11x7x11 area for crops. If it found some it will navigate to them.*/ + void HandleFarmerPrepareFarmCrops(); + + /** Looks if the farmer has reached it's destination, and if it's still crops and the destination is closer then 2 blocks it will harvest them.*/ + void HandleFarmerTryHarvestCrops(); + + /** Replaces the crops he harvested.*/ + void HandleFarmerPlaceCrops(); // Get and set functions. - int GetVilType(void) const { return m_Type; } - Vector3i GetCropsPos(void) const { return m_CropsPos; } - bool DoesHaveActionActivated(void) const { return m_VillagerAction; } + int GetVilType(void) const { return m_Type; } + Vector3i GetCropsPos(void) const { return m_CropsPos; } + bool DoesHaveActionActivated(void) const { return m_VillagerAction; } private: -- cgit v1.2.3 From 76457d367338b603808b7821036cf9edc6f95afb Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 28 Jan 2014 16:28:55 +0100 Subject: Fixed timing on *nix. --- src/OSSupport/Timer.cpp | 2 +- src/Root.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OSSupport/Timer.cpp b/src/OSSupport/Timer.cpp index ed16f9e3a..fd838dd0d 100644 --- a/src/OSSupport/Timer.cpp +++ b/src/OSSupport/Timer.cpp @@ -28,7 +28,7 @@ long long cTimer::GetNowTime(void) #else struct timeval now; gettimeofday(&now, NULL); - return (long long)(now.tv_sec * 1000 + now.tv_usec / 1000); + return (long long)now.tv_sec * 1000 + (long long)now.tv_usec / 1000; #endif } diff --git a/src/Root.cpp b/src/Root.cpp index fa1fdb37a..883bfe76e 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -200,7 +200,7 @@ void cRoot::Start(void) long long finishmseconds = Time.GetNowTime(); finishmseconds -= mseconds; - LOG("Startup complete, took %i ms!", finishmseconds); + LOG("Startup complete, took %lld ms!", finishmseconds); #ifdef _WIN32 EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button #endif -- cgit v1.2.3 From f7cbb07b54e3cafdef7578693ea5340fcaf9ac3d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 28 Jan 2014 23:15:04 +0100 Subject: Fixed an error in Crypto. --- src/Crypto.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Crypto.cpp b/src/Crypto.cpp index 540b5cfde..6f7047ab0 100644 --- a/src/Crypto.cpp +++ b/src/Crypto.cpp @@ -206,7 +206,7 @@ int cRSAPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte ASSERT(!"Invalid a_DecryptedMaxLength!"); return -1; } - if (a_PlainLength < m_Rsa.len) + if (a_EncryptedMaxLength < m_Rsa.len) { LOGD("%s: Invalid a_PlainLength: got %u, exp at least %u", __FUNCTION__, (unsigned)a_PlainLength, (unsigned)(m_Rsa.len) @@ -215,7 +215,7 @@ int cRSAPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte return -1; } int res = rsa_pkcs1_encrypt( - &m_Rsa, ctr_drbg_random, &m_Ctr_drbg, RSA_PUBLIC, + &m_Rsa, ctr_drbg_random, &m_Ctr_drbg, RSA_PRIVATE, a_PlainLength, a_PlainData, a_EncryptedData ); if (res != 0) -- cgit v1.2.3 From 9de52252acb22104584ff7a0746ee81734c3f19e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 28 Jan 2014 23:38:56 +0100 Subject: Crypto: Added public key encryption / decryption. --- src/Crypto.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Crypto.h | 31 ++++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/src/Crypto.cpp b/src/Crypto.cpp index 6f7047ab0..7a06d7fa3 100644 --- a/src/Crypto.cpp +++ b/src/Crypto.cpp @@ -229,6 +229,81 @@ int cRSAPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPublicKey: + +cPublicKey::cPublicKey(const AString & a_PublicKeyDER) +{ + pk_init(&m_Pk); + if (pk_parse_public_key(&m_Pk, (const Byte *)a_PublicKeyDER.data(), a_PublicKeyDER.size()) != 0) + { + ASSERT(!"Cannot parse PubKey"); + return; + } + InitRnd(); +} + + + + + +cPublicKey::~cPublicKey() +{ + pk_free(&m_Pk); +} + + + + + +int cPublicKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength) +{ + size_t DecryptedLen = a_DecryptedMaxLength; + int res = pk_decrypt(&m_Pk, + a_EncryptedData, a_EncryptedLength, + a_DecryptedData, &DecryptedLen, a_DecryptedMaxLength, + ctr_drbg_random, &m_Ctr_drbg + ); + if (res != 0) + { + return res; + } + return (int)DecryptedLen; +} + + + + + +int cPublicKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength) +{ + size_t EncryptedLength = a_EncryptedMaxLength; + int res = pk_encrypt(&m_Pk, + a_PlainData, a_PlainLength, a_EncryptedData, &EncryptedLength, a_EncryptedMaxLength, + ctr_drbg_random, &m_Ctr_drbg + ); + if (res != 0) + { + return res; + } + return (int)EncryptedLength; +} + + + + + +void cPublicKey::InitRnd(void) +{ + entropy_init(&m_Entropy); + const unsigned char pers[] = "rsa_genkey"; + ctr_drbg_init(&m_Ctr_drbg, entropy_func, &m_Entropy, pers, sizeof(pers) - 1); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cAESCFBDecryptor: diff --git a/src/Crypto.h b/src/Crypto.h index a97f34fbf..d68f7ec24 100644 --- a/src/Crypto.h +++ b/src/Crypto.h @@ -14,6 +14,7 @@ #include "polarssl/entropy.h" #include "polarssl/ctr_drbg.h" #include "polarssl/sha1.h" +#include "polarssl/pk.h" @@ -62,6 +63,36 @@ protected: +class cPublicKey +{ +public: + cPublicKey(const AString & a_PublicKeyDER); + ~cPublicKey(); + + /** Decrypts the data using the stored public key + Both a_EncryptedData and a_DecryptedData must be at least bytes large. + Returns the number of bytes decrypted, or negative number for error. */ + int Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength); + + /** Encrypts the data using the stored public key + Both a_EncryptedData and a_DecryptedData must be at least bytes large. + Returns the number of bytes decrypted, or negative number for error. */ + int Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength); + +protected: + pk_context m_Pk; + entropy_context m_Entropy; + ctr_drbg_context m_Ctr_drbg; + + /** Initializes the m_Entropy and m_Ctr_drbg contexts + Common part of this object's construction, called from all constructors. */ + void InitRnd(void); +} ; + + + + + /** Decrypts data using the AES / CFB (128) algorithm */ class cAESCFBDecryptor { -- cgit v1.2.3 From bc6fc859f4c245d17d3bbc2028d93b42b1232d01 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 28 Jan 2014 23:53:07 +0100 Subject: Protocol 1.7: Forced encryption on all connections. This is for testing purposes only, to find bugs in the encryption. Once the encryption is deemed stable, it will be enabled only for servers with enabled Authentication. --- src/Protocol/Protocol17x.cpp | 102 +++++++++++++++++++++++++++++++++++++++++-- src/Protocol/Protocol17x.h | 2 + src/Server.cpp | 3 +- src/Server.h | 28 +++++++----- 4 files changed, 120 insertions(+), 15 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 0d349de03..267c18a99 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -53,6 +53,12 @@ Implements the 1.7.x protocol classes: +const int MAX_ENC_LEN = 512; // Maximum size of the encrypted message; should be 128, but who knows... + + + + + // fwd: main.cpp: extern bool g_ShouldLogCommIn, g_ShouldLogCommOut; @@ -1351,7 +1357,64 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer) { - // TODO: Add protocol encryption + short EncKeyLength, EncNonceLength; + a_ByteBuffer.ReadBEShort(EncKeyLength); + AString EncKey; + if (!a_ByteBuffer.ReadString(EncKey, EncKeyLength)) + { + return; + } + a_ByteBuffer.ReadBEShort(EncNonceLength); + AString EncNonce; + if (!a_ByteBuffer.ReadString(EncNonce, EncNonceLength)) + { + return; + } + if ((EncKeyLength > MAX_ENC_LEN) || (EncNonceLength > MAX_ENC_LEN)) + { + LOGD("Too long encryption"); + m_Client->Kick("Hacked client"); + return; + } + + // Decrypt EncNonce using privkey + cRSAPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey(); + Int32 DecryptedNonce[MAX_ENC_LEN / sizeof(Int32)]; + int res = rsaDecryptor.Decrypt((const Byte *)EncNonce.data(), EncNonce.size(), (Byte *)DecryptedNonce, sizeof(DecryptedNonce)); + if (res != 4) + { + LOGD("Bad nonce length: got %d, exp %d", res, 4); + m_Client->Kick("Hacked client"); + return; + } + if (ntohl(DecryptedNonce[0]) != (unsigned)(uintptr_t)this) + { + LOGD("Bad nonce value"); + m_Client->Kick("Hacked client"); + return; + } + + // Decrypt the symmetric encryption key using privkey: + Byte DecryptedKey[MAX_ENC_LEN]; + res = rsaDecryptor.Decrypt((const Byte *)EncKey.data(), EncKey.size(), DecryptedKey, sizeof(DecryptedKey)); + if (res != 16) + { + LOGD("Bad key length"); + m_Client->Kick("Hacked client"); + return; + } + + StartEncryption(DecryptedKey); + + // Send login success: + { + cPacketizer Pkt(*this, 0x02); // Login success packet + Pkt.WriteString(Printf("%d", m_Client->GetUniqueID())); // TODO: proper UUID + Pkt.WriteString(m_Client->GetUsername()); + } + + m_State = 3; // State = Game + m_Client->HandleLogin(4, m_Client->GetUsername()); } @@ -1363,14 +1426,26 @@ void cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) AString Username; a_ByteBuffer.ReadVarUTF8String(Username); - // TODO: Protocol encryption should be set up here if not localhost / auth - if (!m_Client->HandleHandshake(Username)) { // The client is not welcome here, they have been sent a Kick packet already return; } + // If auth is required, then send the encryption request: + // if (cRoot::Get()->GetServer()->ShouldAuthenticate()) + { + cPacketizer Pkt(*this, 0x01); + Pkt.WriteString(cRoot::Get()->GetServer()->GetServerID()); + const AString & PubKeyDer = cRoot::Get()->GetServer()->GetPublicKeyDER(); + Pkt.WriteShort(PubKeyDer.size()); + Pkt.WriteBuf(PubKeyDer.data(), PubKeyDer.size()); + Pkt.WriteShort(4); + Pkt.WriteInt((int)(intptr_t)this); // Using 'this' as the cryptographic nonce, so that we don't have to generate one each time :) + m_Client->SetUsername(Username); + return; + } + // Send login success: { cPacketizer Pkt(*this, 0x02); // Login success packet @@ -1882,6 +1957,27 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) +void cProtocol172::StartEncryption(const Byte * a_Key) +{ + m_Encryptor.Init(a_Key, a_Key); + m_Decryptor.Init(a_Key, a_Key); + m_IsEncrypted = true; + + // Prepare the m_AuthServerID: + cSHA1Checksum Checksum; + const AString & ServerID = cRoot::Get()->GetServer()->GetServerID(); + Checksum.Update((const Byte *)ServerID.c_str(), ServerID.length()); + Checksum.Update(a_Key, 16); + Checksum.Update((const Byte *)cRoot::Get()->GetServer()->GetPublicKeyDER().data(), cRoot::Get()->GetServer()->GetPublicKeyDER().size()); + Byte Digest[20]; + Checksum.Finalize(Digest); + cSHA1Checksum::DigestToJava(Digest, m_AuthServerID); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cProtocol172::cPacketizer: diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 72544b575..6a75e41c8 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -281,6 +281,8 @@ protected: /// Parses item metadata as read by ReadItem(), into the item enchantments. void ParseItemMetadata(cItem & a_Item, const AString & a_Metadata); + + void StartEncryption(const Byte * a_Key); } ; diff --git a/src/Server.cpp b/src/Server.cpp index 3f9f8a4ac..ba2b46d55 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -237,7 +237,8 @@ bool cServer::InitServer(cIniFile & a_SettingsIni) m_bIsConnected = true; m_ServerID = "-"; - if (a_SettingsIni.GetValueSetB("Authentication", "Authenticate", true)) + m_ShouldAuthenticate = a_SettingsIni.GetValueSetB("Authentication", "Authenticate", true); + if (m_ShouldAuthenticate) { MTRand mtrand1; unsigned int r1 = (mtrand1.randInt() % 1147483647) + 1000000000; diff --git a/src/Server.h b/src/Server.h index 15eafc00a..b5280c59d 100644 --- a/src/Server.h +++ b/src/Server.h @@ -71,13 +71,13 @@ public: // tolua_export bool Command(cClientHandle & a_Client, AString & a_Cmd); - /// Executes the console command, sends output through the specified callback + /** Executes the console command, sends output through the specified callback */ void ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output); - /// Lists all available console commands and their helpstrings + /** Lists all available console commands and their helpstrings */ void PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & a_Output); - /// Binds the built-in console commands with the plugin manager + /** Binds the built-in console commands with the plugin manager */ static void BindBuiltInConsoleCommands(void); void Shutdown(void); @@ -97,13 +97,13 @@ public: // tolua_export void RemoveClient(const cClientHandle * a_Client); // Removes the clienthandle from m_SocketThreads - /// Don't tick a_Client anymore, it will be ticked from its cPlayer instead + /** Don't tick a_Client anymore, it will be ticked from its cPlayer instead */ void ClientMovedToWorld(const cClientHandle * a_Client); - /// Notifies the server that a player was created; the server uses this to adjust the number of players + /** Notifies the server that a player was created; the server uses this to adjust the number of players */ void PlayerCreated(const cPlayer * a_Player); - /// Notifies the server that a player is being destroyed; the server uses this to adjust the number of players + /** Notifies the server that a player is being destroyed; the server uses this to adjust the number of players */ void PlayerDestroying(const cPlayer * a_Player); /** Returns base64 encoded favicon data (obtained from favicon.png) */ @@ -112,11 +112,13 @@ public: // tolua_export cRSAPrivateKey & GetPrivateKey(void) { return m_PrivateKey; } const AString & GetPublicKeyDER(void) const { return m_PublicKeyDER; } + bool ShouldAuthenticate(void) const { return m_ShouldAuthenticate; } + private: friend class cRoot; // so cRoot can create and destroy cServer - /// When NotifyClientWrite() is called, it is queued for this thread to process (to avoid deadlocks between cSocketThreads, cClientHandle and cChunkMap) + /** When NotifyClientWrite() is called, it is queued for this thread to process (to avoid deadlocks between cSocketThreads, cClientHandle and cChunkMap) */ class cNotifyWriteThread : public cIsThread { @@ -140,7 +142,7 @@ private: void NotifyClientWrite(const cClientHandle * a_Client); } ; - /// The server tick thread takes care of the players who aren't yet spawned in a world + /** The server tick thread takes care of the players who aren't yet spawned in a world */ class cTickThread : public cIsThread { @@ -195,18 +197,22 @@ private: cTickThread m_TickThread; cEvent m_RestartEvent; - /// The server ID used for client authentication + /** The server ID used for client authentication */ AString m_ServerID; + /** If true, players will be online-authenticated agains Mojang servers. + This setting is the same as the "online-mode" setting in Vanilla. */ + bool m_ShouldAuthenticate; + cServer(void); - /// Loads, or generates, if missing, RSA keys for protocol encryption + /** Loads, or generates, if missing, RSA keys for protocol encryption */ void PrepareKeys(void); bool Tick(float a_Dt); - /// Ticks the clients in m_Clients, manages the list in respect to removing clients + /** Ticks the clients in m_Clients, manages the list in respect to removing clients */ void TickClients(float a_Dt); // cListenThread::cCallback overrides: -- cgit v1.2.3 From ae897804a0474994eff56ec63bd1eb8ca7b3aaaa Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 28 Jan 2014 23:53:33 +0100 Subject: ProtoProxy: Added encryption support. --- Tools/ProtoProxy/Connection.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index 510d3645d..91d2fc42f 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -1302,6 +1302,7 @@ bool cConnection::HandleServerLoginEncryptionKeyRequest(void) } Log("Got PACKET_ENCRYPTION_KEY_REQUEST from the SERVER:"); Log(" ServerID = %s", ServerID.c_str()); + DataLog(PublicKey.data(), PublicKey.size(), " Public key (%u bytes)", (unsigned)PublicKey.size()); // Reply to the server: SendEncryptionKeyResponse(PublicKey, Nonce); @@ -2863,14 +2864,25 @@ void cConnection::SendEncryptionKeyResponse(const AString & a_ServerPublicKey, c Byte SharedSecret[16]; Byte EncryptedSecret[128]; memset(SharedSecret, 0, sizeof(SharedSecret)); // Use all zeroes for the initial secret - m_Server.GetPrivateKey().Encrypt(SharedSecret, sizeof(SharedSecret), EncryptedSecret, sizeof(EncryptedSecret)); + cPublicKey PubKey(a_ServerPublicKey); + int res = PubKey.Encrypt(SharedSecret, sizeof(SharedSecret), EncryptedSecret, sizeof(EncryptedSecret)); + if (res < 0) + { + Log("Shared secret encryption failed: %d (0x%x)", res, res); + return; + } m_ServerEncryptor.Init(SharedSecret, SharedSecret); m_ServerDecryptor.Init(SharedSecret, SharedSecret); // Encrypt the nonce: Byte EncryptedNonce[128]; - m_Server.GetPrivateKey().Encrypt((const Byte *)a_Nonce.data(), a_Nonce.size(), EncryptedNonce, sizeof(EncryptedNonce)); + res = PubKey.Encrypt((const Byte *)a_Nonce.data(), a_Nonce.size(), EncryptedNonce, sizeof(EncryptedNonce)); + if (res < 0) + { + Log("Nonce encryption failed: %d (0x%x)", res, res); + return; + } // Send the packet to the server: Log("Sending PACKET_ENCRYPTION_KEY_RESPONSE to the SERVER"); @@ -2880,6 +2892,11 @@ void cConnection::SendEncryptionKeyResponse(const AString & a_ServerPublicKey, c ToServer.WriteBuf(EncryptedSecret, sizeof(EncryptedSecret)); ToServer.WriteBEShort((short)sizeof(EncryptedNonce)); ToServer.WriteBuf(EncryptedNonce, sizeof(EncryptedNonce)); + DataLog(EncryptedSecret, sizeof(EncryptedSecret), "Encrypted secret (%u bytes)", (unsigned)sizeof(EncryptedSecret)); + DataLog(EncryptedNonce, sizeof(EncryptedNonce), "Encrypted nonce (%u bytes)", (unsigned)sizeof(EncryptedNonce)); + cByteBuffer Len(5); + Len.WriteVarInt(ToServer.GetReadableSpace()); + SERVERSEND(Len); SERVERSEND(ToServer); m_ServerState = csEncryptedUnderstood; m_IsServerEncrypted = true; -- cgit v1.2.3 From 3bbca8c29187c2f3c3a23912a25e4c43e57131b2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 29 Jan 2014 09:56:31 +0100 Subject: Protocol 1.7: Encryption is enabled only with auth. --- src/Protocol/Protocol17x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 267c18a99..0e9759194 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1433,7 +1433,7 @@ void cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) } // If auth is required, then send the encryption request: - // if (cRoot::Get()->GetServer()->ShouldAuthenticate()) + if (cRoot::Get()->GetServer()->ShouldAuthenticate()) { cPacketizer Pkt(*this, 0x01); Pkt.WriteString(cRoot::Get()->GetServer()->GetServerID()); -- cgit v1.2.3 From 789cf6374053dbb5571f26db1c68ec82cdb48740 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 29 Jan 2014 12:16:27 +0100 Subject: Added 1.7.4 to the list of supported protocols. --- src/Protocol/ProtocolRecognizer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index daeed1845..f58c66d10 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -18,7 +18,7 @@ // Adjust these if a new protocol is added or an old one is removed: -#define MCS_CLIENT_VERSIONS "1.2.4, 1.2.5, 1.3.1, 1.3.2, 1.4.2, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.5, 1.5.1, 1.5.2, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.7.2" +#define MCS_CLIENT_VERSIONS "1.2.4, 1.2.5, 1.3.1, 1.3.2, 1.4.2, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.5, 1.5.1, 1.5.2, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.7.2, 1.7.4" #define MCS_PROTOCOL_VERSIONS "29, 39, 47, 49, 51, 60, 61, 73, 74, 77, 78, 4" -- cgit v1.2.3 From 374034e615e6c7aee2f5b0262bcb0548a3093819 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 29 Jan 2014 13:27:03 +0100 Subject: Bottle o' Enchanting spawns an experience orb. --- src/Entities/ProjectileEntity.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 12ce9a303..16b832539 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -679,7 +679,8 @@ super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) { - // TODO: Spawn experience orbs + // Spawn an experience orb with a reward between 3 and 11. + m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); Destroy(); } -- cgit v1.2.3 From 5e3f7947ae1c835d85e5813b7981bebe8014cc8a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 29 Jan 2014 13:28:08 +0100 Subject: Removed debug message when a firework entity hit a solid block. --- src/Entities/ProjectileEntity.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 16b832539..bffa790a3 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -711,8 +711,6 @@ void cFireworkEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) SetSpeed(0, 0, 0); SetPosition(GetPosX(), GetPosY() - 0.5, GetPosZ()); - std::cout << a_HitPos.x << " " << a_HitPos.y << " " << a_HitPos.z << std::endl; - m_IsInGround = true; BroadcastMovementUpdate(); -- cgit v1.2.3 From 4d53eb27110cce4a79a4ecce60a2bfad2879fa41 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 29 Jan 2014 15:36:53 +0100 Subject: Documented cFloater. --- MCServer/Plugins/APIDump/APIDesc.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 07345d51e..cbdb7797b 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -813,6 +813,20 @@ cFile:Delete("/usr/bin/virus.exe"); }, }, -- cFile + cFloater = + { + Desc = [[ + When a player uses his/her fishing rod it creates a floater entity. This class manages it. + ]], + Functions = + { + CanPickup = { Params = "", Return = "bool", Notes = "Returns true if the floater gives an item when the player right clicks." }, + GetAttachedMobID = { Params = "", Return = "EntityID", Notes = "A floater can get attached to an mob. When it is and this functions gets called it returns the mob ID. If it isn't attached to a mob it returns -1" }, + GetOwnerID = { Params = "", Return = "EntityID", Notes = "Returns the EntityID of the player who owns the floater." }, + }, + Inherits = "cEntity", + }, + cGroup = { Desc = [[ -- cgit v1.2.3 From e40c5a20c8efd03fdb3146eb7ec48e26a5e8c655 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 29 Jan 2014 17:47:32 +0100 Subject: Plugin files are loaded in alphabetical order. Except for the Info.lua file which gets loaded always last. Implements #597. --- src/Bindings/PluginLua.cpp | 52 +++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 1d8c4c6ed..7b2362887 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -88,36 +88,55 @@ bool cPluginLua::Initialize(void) std::string PluginPath = FILE_IO_PREFIX + GetLocalFolder() + "/"; - // Load all files for this plugin, and execute them + // List all Lua files for this plugin. Info.lua has a special handling - make it the last to load: AStringVector Files = cFile::GetFolderContents(PluginPath.c_str()); - - int numFiles = 0; - for (AStringVector::const_iterator itr = Files.begin(); itr != Files.end(); ++itr) + AStringVector LuaFiles; + bool HasInfoLua = false; + for (AStringVector::const_iterator itr = Files.begin(), end = Files.end(); itr != end; ++itr) { - if (itr->rfind(".lua") == AString::npos) + if (itr->rfind(".lua") != AString::npos) { - continue; + if (*itr == "Info.lua") + { + HasInfoLua = true; + } + else + { + LuaFiles.push_back(*itr); + } } + } + std::sort(LuaFiles.begin(), LuaFiles.end()); + + // Warn if there are no Lua files in the plugin folder: + if (LuaFiles.empty()) + { + LOGWARNING("No lua files found: plugin %s is missing.", GetName().c_str()); + Close(); + return false; + } + + // Load all files in the list, including the Info.lua as last, if it exists: + for (AStringVector::const_iterator itr = LuaFiles.begin(), end = LuaFiles.end(); itr != end; ++itr) + { AString Path = PluginPath + *itr; if (!m_LuaState.LoadFile(Path)) { Close(); return false; - } - else - { - numFiles++; } } // for itr - Files[] - - if (numFiles == 0) + if (HasInfoLua) { - LOGWARNING("No lua files found: plugin %s is missing.", GetName().c_str()); - Close(); - return false; + AString Path = PluginPath + "Info.lua"; + if (!m_LuaState.LoadFile(Path)) + { + Close(); + return false; + } } - // Call intialize function + // Call the Initialize function: bool res = false; if (!m_LuaState.Call("Initialize", this, cLuaState::Return, res)) { @@ -125,7 +144,6 @@ bool cPluginLua::Initialize(void) Close(); return false; } - if (!res) { LOGINFO("Plugin %s: Initialize() call failed, plugin is temporarily disabled.", GetName().c_str()); -- cgit v1.2.3 From 04107fa85d142e31576042cff5677a36e392f9f4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 29 Jan 2014 17:59:49 +0100 Subject: Limited sign lines to 15 chars. Fixes #598. --- src/Protocol/Protocol17x.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 0e9759194..04bade867 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -985,10 +985,11 @@ void cProtocol172::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, cons Pkt.WriteInt(a_BlockX); Pkt.WriteShort((short)a_BlockY); Pkt.WriteInt(a_BlockZ); - Pkt.WriteString(a_Line1); - Pkt.WriteString(a_Line2); - Pkt.WriteString(a_Line3); - Pkt.WriteString(a_Line4); + // Need to send only up to 15 chars, otherwise the client crashes (#598) + Pkt.WriteString(a_Line1.substr(0, 15)); + Pkt.WriteString(a_Line2.substr(0, 15)); + Pkt.WriteString(a_Line3.substr(0, 15)); + Pkt.WriteString(a_Line4.substr(0, 15)); } -- cgit v1.2.3 From ebe0f9372fa8787b3fe709937ebd3af30810f910 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Wed, 29 Jan 2014 18:08:33 +0100 Subject: Now mobs follow you when holding their breed item --- src/Mobs/Chicken.cpp | 25 ++++++++++++++++++++++++- src/Mobs/Chicken.h | 3 +++ src/Mobs/Cow.cpp | 28 ++++++++++++++++++++++++++-- src/Mobs/Cow.h | 8 ++++++++ src/Mobs/Mooshroom.cpp | 27 +++++++++++++++++++++++++++ src/Mobs/Mooshroom.h | 8 ++++++++ src/Mobs/Pig.cpp | 27 ++++++++++++++++++++++++++- src/Mobs/Pig.h | 4 ++++ src/Mobs/Sheep.cpp | 24 ++++++++++++++++++++++++ src/Mobs/Sheep.h | 4 +++- 10 files changed, 153 insertions(+), 5 deletions(-) diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index 087fd088a..52c8d3788 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -2,7 +2,7 @@ #include "Chicken.h" #include "../World.h" - +#include "../Entities/Player.h" @@ -41,6 +41,29 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk) { m_EggDropTimer++; } + cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); + if (a_Closest_Player != NULL) + { + if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_SEEDS) + { + if (!IsBegging()) + { + m_IsBegging = true; + m_World->BroadcastEntityMetadata(*this); + } + Vector3d PlayerPos = a_Closest_Player->GetPosition(); + PlayerPos.y++; + m_FinalDestination = PlayerPos; + } + else + { + if (IsBegging()) + { + m_IsBegging = false; + m_World->BroadcastEntityMetadata(*this); + } + } + } } diff --git a/src/Mobs/Chicken.h b/src/Mobs/Chicken.h index 979c4d8a0..b9cff40d4 100644 --- a/src/Mobs/Chicken.h +++ b/src/Mobs/Chicken.h @@ -19,10 +19,13 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + bool IsBegging (void) const { return m_IsBegging; } + private: int m_EggDropTimer; + bool m_IsBegging; } ; diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index 9eb74dac2..205ecc73f 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -41,5 +41,29 @@ void cCow::OnRightClicked(cPlayer & a_Player) } } - - +void cCow::Tick(float a_Dt, cChunk & a_Chunk) +{ + cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); + if (a_Closest_Player != NULL) + { + if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT) + { + if (!IsBegging()) + { + m_IsBegging = true; + m_World->BroadcastEntityMetadata(*this); + } + Vector3d PlayerPos = a_Closest_Player->GetPosition(); + PlayerPos.y++; + m_FinalDestination = PlayerPos; + } + else + { + if (IsBegging()) + { + m_IsBegging = false; + m_World->BroadcastEntityMetadata(*this); + } + } + } +} diff --git a/src/Mobs/Cow.h b/src/Mobs/Cow.h index 0391d4a31..b001ea856 100644 --- a/src/Mobs/Cow.h +++ b/src/Mobs/Cow.h @@ -19,6 +19,14 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void OnRightClicked(cPlayer & a_Player) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + + bool IsBegging (void) const { return m_IsBegging; } + +private: + + bool m_IsBegging; + } ; diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 940e2db44..1ff90392d 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Mooshroom.h" +#include "../Entities/Player.h" @@ -29,5 +30,31 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) } +void cMooshroom::Tick(float a_Dt, cChunk & a_Chunk) +{ + cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); + if (a_Closest_Player != NULL) + { + if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT) + { + if (!IsBegging()) + { + m_IsBegging = true; + m_World->BroadcastEntityMetadata(*this); + } + Vector3d PlayerPos = a_Closest_Player->GetPosition(); + PlayerPos.y++; + m_FinalDestination = PlayerPos; + } + else + { + if (IsBegging()) + { + m_IsBegging = false; + m_World->BroadcastEntityMetadata(*this); + } + } + } +} diff --git a/src/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h index 73f6348b6..c288f68a9 100644 --- a/src/Mobs/Mooshroom.h +++ b/src/Mobs/Mooshroom.h @@ -18,6 +18,14 @@ public: CLASS_PROTODEF(cMooshroom); virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + + bool IsBegging (void) const { return m_IsBegging; } + +private: + + bool m_IsBegging; + } ; diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index 0871a38a9..e31bc90ba 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -71,7 +71,32 @@ void cPig::OnRightClicked(cPlayer & a_Player) } } - +void cPig::Tick(float a_Dt, cChunk & a_Chunk) +{ + cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); + if (a_Closest_Player != NULL) + { + if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_CARROT) + { + if (!IsBegging()) + { + m_IsBegging = true; + m_World->BroadcastEntityMetadata(*this); + } + Vector3d PlayerPos = a_Closest_Player->GetPosition(); + PlayerPos.y++; + m_FinalDestination = PlayerPos; + } + else + { + if (IsBegging()) + { + m_IsBegging = false; + m_World->BroadcastEntityMetadata(*this); + } + } + } +} diff --git a/src/Mobs/Pig.h b/src/Mobs/Pig.h index 4fd0d8db8..f42a4f412 100644 --- a/src/Mobs/Pig.h +++ b/src/Mobs/Pig.h @@ -19,10 +19,14 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void OnRightClicked(cPlayer & a_Player) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + bool IsSaddled(void) const { return m_bIsSaddled; } + bool IsBegging (void) const { return m_IsBegging; } private: + bool m_IsBegging; bool m_bIsSaddled; } ; diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index 702108ae4..3fb9351ad 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -96,4 +96,28 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk) } } } + cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); + if (a_Closest_Player != NULL) + { + if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT) + { + if (!IsBegging()) + { + m_IsBegging = true; + m_World->BroadcastEntityMetadata(*this); + } + Vector3d PlayerPos = a_Closest_Player->GetPosition(); + PlayerPos.y++; + m_FinalDestination = PlayerPos; + } + else + { + if (IsBegging()) + { + m_IsBegging = false; + m_World->BroadcastEntityMetadata(*this); + } + } + } } + diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h index 4eee3db1c..322b31dd9 100644 --- a/src/Mobs/Sheep.h +++ b/src/Mobs/Sheep.h @@ -21,11 +21,13 @@ public: virtual void OnRightClicked(cPlayer & a_Player) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + bool IsBegging(void) const { return m_IsBegging; } bool IsSheared(void) const { return m_IsSheared; } int GetFurColor(void) const { return m_WoolColor; } private: - + + bool m_IsBegging; bool m_IsSheared; int m_WoolColor; int m_TimeToStopEating; -- cgit v1.2.3 From 73d9a285d511a3cd1016aafc8c492924e6a7b249 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Wed, 29 Jan 2014 18:25:10 +0100 Subject: Fixed a copypasta error... --- src/Mobs/Cow.cpp | 3 ++- src/Mobs/Mooshroom.cpp | 1 + src/Mobs/Pig.cpp | 1 + src/Mobs/Sheep.cpp | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index 205ecc73f..4063f034d 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -42,7 +42,8 @@ void cCow::OnRightClicked(cPlayer & a_Player) } void cCow::Tick(float a_Dt, cChunk & a_Chunk) -{ +{ + super::Tick(a_Dt, a_Chunk); cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); if (a_Closest_Player != NULL) { diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 1ff90392d..60721f0ee 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -32,6 +32,7 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cMooshroom::Tick(float a_Dt, cChunk & a_Chunk) { + super::Tick(a_Dt, a_Chunk); cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); if (a_Closest_Player != NULL) { diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index e31bc90ba..b6d11d856 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -73,6 +73,7 @@ void cPig::OnRightClicked(cPlayer & a_Player) void cPig::Tick(float a_Dt, cChunk & a_Chunk) { + super::Tick(a_Dt, a_Chunk); cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); if (a_Closest_Player != NULL) { diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index 3fb9351ad..2478ec79c 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -68,6 +68,7 @@ void cSheep::OnRightClicked(cPlayer & a_Player) void cSheep::Tick(float a_Dt, cChunk & a_Chunk) { + super::Tick(a_Dt, a_Chunk); // The sheep should not move when he's eating so only handle the physics. if (m_TimeToStopEating > 0) { -- cgit v1.2.3 From ba4865f7ee99490ff46d4b584ffa0ae85fa21aae Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Wed, 29 Jan 2014 18:32:46 +0100 Subject: Fixed sheep --- src/Mobs/Sheep.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index 2478ec79c..c8ff8f5c8 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -68,7 +68,6 @@ void cSheep::OnRightClicked(cPlayer & a_Player) void cSheep::Tick(float a_Dt, cChunk & a_Chunk) { - super::Tick(a_Dt, a_Chunk); // The sheep should not move when he's eating so only handle the physics. if (m_TimeToStopEating > 0) { @@ -96,27 +95,27 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk) m_TimeToStopEating = 40; } } - } - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); - if (a_Closest_Player != NULL) - { - if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT) + cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); + if (a_Closest_Player != NULL) { - if (!IsBegging()) + if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT) { - m_IsBegging = true; - m_World->BroadcastEntityMetadata(*this); + if (!IsBegging()) + { + m_IsBegging = true; + m_World->BroadcastEntityMetadata(*this); + } + Vector3d PlayerPos = a_Closest_Player->GetPosition(); + PlayerPos.y++; + m_FinalDestination = PlayerPos; } - Vector3d PlayerPos = a_Closest_Player->GetPosition(); - PlayerPos.y++; - m_FinalDestination = PlayerPos; - } - else - { - if (IsBegging()) + else { - m_IsBegging = false; - m_World->BroadcastEntityMetadata(*this); + if (IsBegging()) + { + m_IsBegging = false; + m_World->BroadcastEntityMetadata(*this); + } } } } -- cgit v1.2.3 From 6accedffd56fd243f384a17dc467d0ae0114da35 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 29 Jan 2014 19:10:59 +0100 Subject: Added instructions for ZIP source downloads. The ZIP file doesn't contain git submodules, people complained about not being able to compile from it. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a5d48f2d..a16062574 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ Installation To install MCServer, you can either download the repository and compile it, or download a pre-compiled version. -After you've cloned the repository, you probably want to pull down the submodules (core plugins, some dependencies). This can be achieved with `git submodule init` and then on a regular basis (to keep up to date) `git submodule update`. +If you've cloned the repository using Git, you need to pull down the submodules (core plugins, some dependencies). This can be achieved with `git submodule init` and then on a regular basis (to keep up to date) `git submodule update`. + +If you downloaded a ZIP file of the sources instead, you will need to download PolarSSL, too, from https://github.com/polarssl/polarssl , and unpack it into the `lib/polarssl` folder. You will also need to manually download all the plugins that you want included. Compilation instructions are available in the COMPILING file. -- cgit v1.2.3 From 1c1832b6ce08de71e6a46187420d91eacb18d16e Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Wed, 29 Jan 2014 19:15:26 +0100 Subject: Rewritten code. Implemented xoft suggestion. Using MoveToPosition as tigerw suggested. --- src/Mobs/Chicken.cpp | 23 ----------------------- src/Mobs/Chicken.h | 4 +--- src/Mobs/Cow.cpp | 27 --------------------------- src/Mobs/Cow.h | 7 +------ src/Mobs/Mooshroom.cpp | 28 ---------------------------- src/Mobs/Mooshroom.h | 8 +------- src/Mobs/PassiveMonster.cpp | 16 +++++++++++++++- src/Mobs/PassiveMonster.h | 2 ++ src/Mobs/Pig.cpp | 28 ---------------------------- src/Mobs/Pig.h | 5 ++--- src/Mobs/Sheep.cpp | 23 ----------------------- src/Mobs/Sheep.h | 6 +++--- 12 files changed, 25 insertions(+), 152 deletions(-) diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index 52c8d3788..90d56d1de 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -41,29 +41,6 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk) { m_EggDropTimer++; } - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); - if (a_Closest_Player != NULL) - { - if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_SEEDS) - { - if (!IsBegging()) - { - m_IsBegging = true; - m_World->BroadcastEntityMetadata(*this); - } - Vector3d PlayerPos = a_Closest_Player->GetPosition(); - PlayerPos.y++; - m_FinalDestination = PlayerPos; - } - else - { - if (IsBegging()) - { - m_IsBegging = false; - m_World->BroadcastEntityMetadata(*this); - } - } - } } diff --git a/src/Mobs/Chicken.h b/src/Mobs/Chicken.h index b9cff40d4..a4c1d6b9e 100644 --- a/src/Mobs/Chicken.h +++ b/src/Mobs/Chicken.h @@ -19,13 +19,11 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - bool IsBegging (void) const { return m_IsBegging; } + virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_SEEDS); } private: - int m_EggDropTimer; - bool m_IsBegging; } ; diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index 4063f034d..d8e905217 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -41,30 +41,3 @@ void cCow::OnRightClicked(cPlayer & a_Player) } } -void cCow::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); - if (a_Closest_Player != NULL) - { - if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT) - { - if (!IsBegging()) - { - m_IsBegging = true; - m_World->BroadcastEntityMetadata(*this); - } - Vector3d PlayerPos = a_Closest_Player->GetPosition(); - PlayerPos.y++; - m_FinalDestination = PlayerPos; - } - else - { - if (IsBegging()) - { - m_IsBegging = false; - m_World->BroadcastEntityMetadata(*this); - } - } - } -} diff --git a/src/Mobs/Cow.h b/src/Mobs/Cow.h index b001ea856..973171ab5 100644 --- a/src/Mobs/Cow.h +++ b/src/Mobs/Cow.h @@ -19,13 +19,8 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void OnRightClicked(cPlayer & a_Player) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - bool IsBegging (void) const { return m_IsBegging; } - -private: - - bool m_IsBegging; + virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } } ; diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 60721f0ee..00ba339a6 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -30,32 +30,4 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) } -void cMooshroom::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); - if (a_Closest_Player != NULL) - { - if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT) - { - if (!IsBegging()) - { - m_IsBegging = true; - m_World->BroadcastEntityMetadata(*this); - } - Vector3d PlayerPos = a_Closest_Player->GetPosition(); - PlayerPos.y++; - m_FinalDestination = PlayerPos; - } - else - { - if (IsBegging()) - { - m_IsBegging = false; - m_World->BroadcastEntityMetadata(*this); - } - } - } -} - diff --git a/src/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h index c288f68a9..c94301098 100644 --- a/src/Mobs/Mooshroom.h +++ b/src/Mobs/Mooshroom.h @@ -18,14 +18,8 @@ public: CLASS_PROTODEF(cMooshroom); virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - - bool IsBegging (void) const { return m_IsBegging; } - -private: - - bool m_IsBegging; + virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } } ; diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp index d774d3170..903761a95 100644 --- a/src/Mobs/PassiveMonster.cpp +++ b/src/Mobs/PassiveMonster.cpp @@ -3,7 +3,7 @@ #include "PassiveMonster.h" #include "../World.h" - +#include "../Entities/Player.h" @@ -39,6 +39,20 @@ void cPassiveMonster::Tick(float a_Dt, cChunk & a_Chunk) { CheckEventLostPlayer(); } + cItem FollowedItem = GetFollowedItem(); + if (FollowedItem.IsEmpty()) + { + return; + } + cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); + if (a_Closest_Player != NULL) + { + if (a_Closest_Player->GetEquippedItem().m_ItemType == FollowedItem.m_ItemType) + { + Vector3d PlayerPos = a_Closest_Player->GetPosition(); + MoveToPosition(PlayerPos); + } + } } diff --git a/src/Mobs/PassiveMonster.h b/src/Mobs/PassiveMonster.h index 14a6be6b1..7da5d71bc 100644 --- a/src/Mobs/PassiveMonster.h +++ b/src/Mobs/PassiveMonster.h @@ -20,6 +20,8 @@ public: /// When hit by someone, run away virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual const cItem GetFollowedItem(void) const { return cItem(); } + } ; diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index b6d11d856..d8f3dda37 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -71,33 +71,5 @@ void cPig::OnRightClicked(cPlayer & a_Player) } } -void cPig::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); - if (a_Closest_Player != NULL) - { - if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_CARROT) - { - if (!IsBegging()) - { - m_IsBegging = true; - m_World->BroadcastEntityMetadata(*this); - } - Vector3d PlayerPos = a_Closest_Player->GetPosition(); - PlayerPos.y++; - m_FinalDestination = PlayerPos; - } - else - { - if (IsBegging()) - { - m_IsBegging = false; - m_World->BroadcastEntityMetadata(*this); - } - } - } -} - diff --git a/src/Mobs/Pig.h b/src/Mobs/Pig.h index f42a4f412..d434324c1 100644 --- a/src/Mobs/Pig.h +++ b/src/Mobs/Pig.h @@ -19,14 +19,13 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void OnRightClicked(cPlayer & a_Player) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + + virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_CARROT); } bool IsSaddled(void) const { return m_bIsSaddled; } - bool IsBegging (void) const { return m_IsBegging; } private: - bool m_IsBegging; bool m_bIsSaddled; } ; diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index c8ff8f5c8..4761103e5 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -95,29 +95,6 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk) m_TimeToStopEating = 40; } } - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); - if (a_Closest_Player != NULL) - { - if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT) - { - if (!IsBegging()) - { - m_IsBegging = true; - m_World->BroadcastEntityMetadata(*this); - } - Vector3d PlayerPos = a_Closest_Player->GetPosition(); - PlayerPos.y++; - m_FinalDestination = PlayerPos; - } - else - { - if (IsBegging()) - { - m_IsBegging = false; - m_World->BroadcastEntityMetadata(*this); - } - } - } } } diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h index 322b31dd9..402e8e61c 100644 --- a/src/Mobs/Sheep.h +++ b/src/Mobs/Sheep.h @@ -21,13 +21,13 @@ public: virtual void OnRightClicked(cPlayer & a_Player) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - bool IsBegging(void) const { return m_IsBegging; } + virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } + bool IsSheared(void) const { return m_IsSheared; } int GetFurColor(void) const { return m_WoolColor; } private: - - bool m_IsBegging; + bool m_IsSheared; int m_WoolColor; int m_TimeToStopEating; -- cgit v1.2.3 From e9c1d1ea9c79d9a57d48b625d9a31604e927609c Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Wed, 29 Jan 2014 20:02:41 +0100 Subject: Did what xoft said --- src/Mobs/Chicken.cpp | 1 - src/Mobs/Mooshroom.cpp | 2 -- src/Mobs/PassiveMonster.cpp | 2 +- src/Mobs/PassiveMonster.h | 3 ++- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index 90d56d1de..fab92ce49 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -2,7 +2,6 @@ #include "Chicken.h" #include "../World.h" -#include "../Entities/Player.h" diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 00ba339a6..88101cd83 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -2,8 +2,6 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Mooshroom.h" -#include "../Entities/Player.h" - diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp index 903761a95..904cd63cc 100644 --- a/src/Mobs/PassiveMonster.cpp +++ b/src/Mobs/PassiveMonster.cpp @@ -47,7 +47,7 @@ void cPassiveMonster::Tick(float a_Dt, cChunk & a_Chunk) cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); if (a_Closest_Player != NULL) { - if (a_Closest_Player->GetEquippedItem().m_ItemType == FollowedItem.m_ItemType) + if (a_Closest_Player->GetEquippedItem().IsEqual(FollowedItem)) { Vector3d PlayerPos = a_Closest_Player->GetPosition(); MoveToPosition(PlayerPos); diff --git a/src/Mobs/PassiveMonster.h b/src/Mobs/PassiveMonster.h index 7da5d71bc..0b3c155da 100644 --- a/src/Mobs/PassiveMonster.h +++ b/src/Mobs/PassiveMonster.h @@ -19,7 +19,8 @@ public: /// When hit by someone, run away virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; - + /** Returns the item that the animal of this class follows when a player holds it in hand + Return an empty item not to follow (default). */ virtual const cItem GetFollowedItem(void) const { return cItem(); } } ; -- cgit v1.2.3 From ed7816419d2b1d2ddd3a371efb4276ca67dfb4d8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 29 Jan 2014 19:19:14 +0000 Subject: Fixed redstone simulator crash found in #570 --- src/ChunkDef.h | 16 +++++++++++----- src/Simulator/RedstoneSimulator.cpp | 25 +++++++++++++------------ src/Simulator/RedstoneSimulator.h | 2 +- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index d1288994c..13933e6f1 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -499,13 +499,14 @@ public: /// Generic template that can store any kind of data together with a triplet of 3 coords: -template class cCoordWithData +template class cCoordWithData { public: int x; int y; int z; X Data; + Y SecondData; cCoordWithData(int a_X, int a_Y, int a_Z) : x(a_X), y(a_Y), z(a_Z) @@ -516,14 +517,19 @@ public: x(a_X), y(a_Y), z(a_Z), Data(a_Data) { } + + cCoordWithData(int a_X, int a_Y, int a_Z, const X & a_Data, const Y & a_SecondData) : + x(a_X), y(a_Y), z(a_Z), Data(a_Data), SecondData(a_SecondData) + { + } } ; -// Illegal in C++03: typedef std::list< cCoordWithData > cCoordWithDataList; -typedef cCoordWithData cCoordWithInt; -typedef cCoordWithData cCoordWithBlock; +typedef cCoordWithData cCoordWithInt; +typedef cCoordWithData cCoordWithBlockAndBool; + typedef std::list cCoordWithIntList; typedef std::vector cCoordWithIntVector; -typedef std::vector cCoordWithBlockVector; +typedef std::vector cCoordWithBlockAndBoolVector; diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index e361cbf49..357643ecc 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -9,7 +9,6 @@ #include "../Blocks/BlockTorch.h" #include "../Blocks/BlockDoor.h" #include "../Piston.h" -#include "../Tracer.h" @@ -170,7 +169,7 @@ void cRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChu { if (!IsAllowedBlock(Block)) { - ChunkData.erase(itr); // The new blocktype is not redstone; it must be removed from this list + itr->SecondData = true; // The new blocktype is not redstone; it must be queued to be removed from this list } else { @@ -185,7 +184,7 @@ void cRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChu return; } - ChunkData.push_back(cCoordWithBlock(RelX, a_BlockY, RelZ, Block)); + ChunkData.push_back(cCoordWithBlockAndBool(RelX, a_BlockY, RelZ, Block, false)); } @@ -208,8 +207,14 @@ void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, c int BaseX = a_Chunk->GetPosX() * cChunkDef::Width; int BaseZ = a_Chunk->GetPosZ() * cChunkDef::Width; - for (cRedstoneSimulatorChunkData::const_iterator dataitr = ChunkData.begin(); dataitr != ChunkData.end(); ++dataitr) + for (cRedstoneSimulatorChunkData::iterator dataitr = ChunkData.begin(); dataitr != ChunkData.end();) { + if (dataitr->SecondData) + { + dataitr = ChunkData.erase(dataitr); + continue; + } + int a_X = BaseX + dataitr->x; int a_Z = BaseZ + dataitr->z; switch (dataitr->Data) @@ -279,6 +284,7 @@ void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, c break; } } + ++dataitr; } } @@ -917,7 +923,7 @@ void cRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_BlockY, int a_B case E_BLOCK_STONE_PRESSURE_PLATE: { // MCS feature - stone pressure plates can only be triggered by players :D - cPlayer * a_Player = m_World.FindClosestPlayer(Vector3f(a_BlockX + 0.5f, (float)a_BlockY, a_BlockZ + 0.5f), 0.5f); + cPlayer * a_Player = m_World.FindClosestPlayer(Vector3f(a_BlockX + 0.5f, (float)a_BlockY, a_BlockZ + 0.5f), 0.5f, false); if (a_Player != NULL) { @@ -948,19 +954,14 @@ void cRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_BlockY, int a_B virtual bool Item(cEntity * a_Entity) override { - cTracer LineOfSight(m_World); - Vector3f EntityPos = a_Entity->GetPosition(); Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f); float Distance = (EntityPos - BlockPos).Length(); if (Distance < 0.5) { - if (!LineOfSight.Trace(BlockPos, (EntityPos - BlockPos), (int)(EntityPos - BlockPos).Length())) - { - m_Entity = a_Entity; - return true; // Break out, we only need to know for wooden plates that at least one entity is on top - } + m_Entity = a_Entity; + return true; // Break out, we only need to know for wooden plates that at least one entity is on top } return false; } diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index bb2efeb8a..c505b2a0f 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -4,7 +4,7 @@ #include "Simulator.h" /// Per-chunk data for the simulator, specified individual chunks to simulate; 'Data' is not used -typedef cCoordWithBlockVector cRedstoneSimulatorChunkData; +typedef cCoordWithBlockAndBoolVector cRedstoneSimulatorChunkData; -- cgit v1.2.3 From 7d03876a3e11aedff0201a8330bfdb2b5523fc5e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 29 Jan 2014 19:22:03 +0000 Subject: Added LOGREPLACELINE for line replacement --- src/Log.cpp | 31 ++++++++++++++++++++++++++++-- src/Log.h | 4 ++-- src/MCLogger.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++------ src/MCLogger.h | 7 ++++++- src/World.cpp | 10 +++++----- 5 files changed, 94 insertions(+), 16 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index 2d6be0f59..a23a79ccc 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -99,7 +99,7 @@ void cLog::ClearLog() -void cLog::Log(const char * a_Format, va_list argList) +void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine) { AString Message; AppendVPrintf(Message, a_Format, argList); @@ -134,7 +134,34 @@ void cLog::Log(const char * a_Format, va_list argList) __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str() ); //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); #else - printf("%s", Line.c_str()); + if (a_ReplaceCurrentLine) + { +#ifdef _WIN32 + if (m_LastStringSize == 0) + { + m_LastStringSize = Line.length(); + } + else if (Line.length() < m_LastStringSize) // If last printed line was longer than current, clear this line + { + for (size_t X = 0; X != m_LastStringSize; ++X) + { + fputs(" ", stdout); + } + } +#else // _WIN32 + fputs("\033[K", stdout); // Clear current line +#endif + + printf("\r%s", Line.c_str()); + +#ifdef __linux + fputs("\033[1B", stdout); // Move down one line +#endif // __linux + } + else + { + printf("%s", Line.c_str()); + } #endif #if defined (_WIN32) && defined(_DEBUG) diff --git a/src/Log.h b/src/Log.h index cba248dae..c8c26913b 100644 --- a/src/Log.h +++ b/src/Log.h @@ -10,11 +10,11 @@ class cLog private: FILE * m_File; static cLog * s_Log; - + size_t m_LastStringSize = 0; public: cLog(const AString & a_FileName); ~cLog(); - void Log(const char * a_Format, va_list argList); + void Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine = false); void Log(const char * a_Format, ...); // tolua_begin void SimpleLog(const char * a_String); diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index 4f3e5dc0f..632ea2efe 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -119,13 +119,51 @@ void cMCLogger::LogSimple(const char* a_Text, int a_LogType /* = 0 */ ) -void cMCLogger::Log(const char * a_Format, va_list a_ArgList) +void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldReplaceLine) { cCSLock Lock(m_CriticalSection); - SetColor(csRegular); - m_Log->Log(a_Format, a_ArgList); - ResetColor(); - puts(""); + + if (!m_BeginLineUpdate && a_ShouldReplaceLine) + { + a_ShouldReplaceLine = false; // Print a normal line first if this is the initial replace line + m_BeginLineUpdate = true; + } + else if (m_BeginLineUpdate && !a_ShouldReplaceLine) + { + m_BeginLineUpdate = false; + } + + if (a_ShouldReplaceLine) + { +#ifdef _WIN32 + HANDLE Output = GetStdHandle(STD_OUTPUT_HANDLE); + + CONSOLE_SCREEN_BUFFER_INFO csbi; + GetConsoleScreenBufferInfo(Output, &csbi); + + COORD Position = { 0, csbi.dwCursorPosition.Y - 1 }; // Move cursor up one line + SetConsoleCursorPosition(Output, Position); + + SetColor(csRegular); + m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); + ResetColor(); + + Position = { 0, csbi.dwCursorPosition.Y }; // Set cursor to original position + SetConsoleCursorPosition(Output, Position); +#else // _WIN32 + fputs("\033[1A", stdout); // Move cursor up one line + SetColor(csRegular); + m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); + ResetColor(); +#endif + } + else + { + SetColor(csRegular); + m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); + ResetColor(); + puts(""); + } } @@ -188,7 +226,7 @@ void cMCLogger::SetColor(eColorScheme a_Scheme) default: ASSERT(!"Unhandled color scheme"); } SetConsoleTextAttribute(g_Console, Attrib); - #elif defined(__linux) && !defined(ANDROID_NDK) + #elif (defined(__linux) || defined(__apple)) && !defined(ANDROID_NDK) switch (a_Scheme) { case csRegular: printf("\x1b[0m"); break; // Whatever the console default is @@ -224,6 +262,14 @@ void cMCLogger::ResetColor(void) ////////////////////////////////////////////////////////////////////////// // Global functions +void LOGREPLACELINE(const char* a_Format, ...) +{ + va_list argList; + va_start(argList, a_Format); + cMCLogger::GetInstance()->Log(a_Format, argList, true); + va_end(argList); +} + void LOG(const char* a_Format, ...) { va_list argList; diff --git a/src/MCLogger.h b/src/MCLogger.h index c949a4cdf..7bcc195dd 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -21,7 +21,7 @@ public: // tolua_export ~cMCLogger(); // tolua_export - void Log(const char* a_Format, va_list a_ArgList); + void Log(const char* a_Format, va_list a_ArgList, bool a_ShouldReplaceLine = false); void Info(const char* a_Format, va_list a_ArgList); void Warn(const char* a_Format, va_list a_ArgList); void Error(const char* a_Format, va_list a_ArgList); @@ -51,12 +51,17 @@ private: /// Common initialization for all constructors, creates a logfile with the specified name and assigns s_MCLogger to this void InitLog(const AString & a_FileName); + + /** Flag to show whether a 'replace line' log command has been issued + Used to decide when to put a newline */ + bool m_BeginLineUpdate = false; }; // tolua_export +extern void LOGREPLACELINE(const char* a_Format, ...); extern void LOG(const char* a_Format, ...); extern void LOGINFO(const char* a_Format, ...); extern void LOGWARN(const char* a_Format, ...); diff --git a/src/World.cpp b/src/World.cpp index 88bbf5f8a..bac529d4a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -100,13 +100,13 @@ protected: { for (;;) { - LOG("%d chunks to load, %d chunks to generate", + LOGREPLACELINE("%d chunks to load, %d chunks to generate", m_World->GetStorage().GetLoadQueueLength(), m_World->GetGenerator().GetQueueLength() ); - // Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish - for (int i = 0; i < 20; i++) + // Wait for 0.5 sec, but be "reasonably wakeable" when the thread is to finish + for (int i = 0; i < 5; i++) { cSleep::MilliSleep(100); if (m_ShouldTerminate) @@ -152,10 +152,10 @@ protected: { for (;;) { - LOG("%d chunks remaining to light", m_Lighting->GetQueueLength() + LOGREPLACELINE("%d chunks remaining to light", m_Lighting->GetQueueLength() ); - // Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish + // Wait for 0.5 sec, but be "reasonably wakeable" when the thread is to finish for (int i = 0; i < 20; i++) { cSleep::MilliSleep(100); -- cgit v1.2.3 From b61a74d6a20f063e776bb02e471a213da32c1000 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 29 Jan 2014 22:56:23 +0100 Subject: Lua: Fixed an error in table-functions callbacks. --- src/Bindings/LuaState.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 2fca7142c..d49cd8ef3 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -289,9 +289,13 @@ bool cLuaState::PushFunction(const cTableRef & a_TableRef) if (lua_isnil(m_LuaState, -1) || !lua_isfunction(m_LuaState, -1)) { // Not a valid function, bail out - lua_pop(m_LuaState, 2); + lua_pop(m_LuaState, 3); return false; } + + // Pop the table off the stack: + lua_remove(m_LuaState, -2); + Printf(m_CurrentFunctionName, "", a_TableRef.GetFnName()); m_NumCurrentFunctionArgs = 0; return true; -- cgit v1.2.3 From 16a939a75763569352ffdc685b38f41ddd278ff1 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Thu, 30 Jan 2014 18:02:37 +0100 Subject: Attempt at implementing #563 Not tested (I don't have RasPi) --- src/World.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index 88bbf5f8a..5739098e4 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1,4 +1,3 @@ - #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "BlockID.h" @@ -234,7 +233,7 @@ cWorld::cWorld(const AString & a_WorldName) : m_WorldName(a_WorldName), m_IniFileName(m_WorldName + "/world.ini"), m_StorageSchema("Default"), -#ifdef _arm_ +#ifdef __arm__ m_StorageCompressionFactor(0), #else m_StorageCompressionFactor(6), -- cgit v1.2.3 From e0cb06dfae8fcb4b58d7b00db0bba9317d19ae95 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Thu, 30 Jan 2014 17:54:10 +0000 Subject: Update Core --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 5fe3662a8..1a36a2922 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 5fe3662a8719f79cb2ca0a16150c716a3c5eb19c +Subproject commit 1a36a2922d97062230fd93dee3d4638d69feb7c6 -- cgit v1.2.3 From 419778a3067fda111c7b3e02b062afc592abb605 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 30 Jan 2014 21:39:31 +0100 Subject: Fixes #606 --- src/WorldStorage/NBTChunkSerializer.cpp | 4 ++-- src/WorldStorage/WSSAnvil.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index e46a28caa..9c454c028 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -454,8 +454,8 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) } case cMonster::mtWolf: { - // TODO: - // _X: CopyPasta error: m_Writer.AddInt("Profession", ((const cVillager *)a_Monster)->GetVilType()); + m_Writer.AddString("Owner", ((const cWolf *)a_Monster)->GetOwner()); + m_Writer.AddByte("Sitting", ((const cWolf *)a_Monster)->IsSitting()); break; } case cMonster::mtZombie: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index a0f9136d8..ab85cf3e2 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1876,6 +1876,13 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N { return; } + int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner"); + AString OwnerName = a_NBT.GetString(OwnerIdx); + if (OwnerName != "") + { + Monster->SetOwner(OwnerName); + Monster->SetIsTame(true); + } a_Entities.push_back(Monster.release()); } -- cgit v1.2.3 From 1a361be44fe2a454734e3ac0e93211e33e566976 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 30 Jan 2014 21:46:45 +0100 Subject: Check if the tag is found. --- src/WorldStorage/WSSAnvil.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index ab85cf3e2..1827eff58 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1877,6 +1877,11 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N return; } int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner"); + if (TypeIdx < 0) + { + return; + } + AString OwnerName = a_NBT.GetString(OwnerIdx); if (OwnerName != "") { -- cgit v1.2.3 From 550a09020d4e40904a205ebe7daf1d2421e51070 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 30 Jan 2014 21:49:39 +0100 Subject: Fixed bad variable. --- src/WorldStorage/WSSAnvil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 1827eff58..e581c433e 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1877,7 +1877,7 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N return; } int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner"); - if (TypeIdx < 0) + if (OwnerIdx < 0) { return; } -- cgit v1.2.3 From d3b8796c48f5c79cfa3b137af9699e698ab3c81a Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Thu, 30 Jan 2014 21:19:45 +0000 Subject: Fixed at least a little of the plugin guide. --- .../Plugins/APIDump/Writing-a-MCServer-plugin.html | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html b/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html index 0e07cebdf..bdb80186f 100644 --- a/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html +++ b/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html @@ -25,7 +25,7 @@

Next, we must obtain a copy of CoreMessaging.lua. This can be found - here. + here. This is used to provide messaging support that is compliant with MCServer standards.

Creating the basic template

@@ -35,19 +35,14 @@ Format it like so:

-local PLUGIN
+PLUGIN = nil
 
 function Initialize(Plugin)
-	Plugin:SetName("DerpyPlugin")
+	Plugin:SetName("NewPlugin")
 	Plugin:SetVersion(1)
 	
 	PLUGIN = Plugin
 
-	-- Hooks
-
-	local PluginManager = cPluginManager:Get()
-	-- Command bindings
-
 	LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
 	return true
 end
@@ -84,7 +79,7 @@ end
 			To register a hook, insert the following code template into the "-- Hooks" area in the previous code example.
 			

-cPluginManager:AddHook(cPluginManager.HOOK_NAME_HERE, FunctionNameToBeCalled)
+cPluginManager.AddHook(cPluginManager.HOOK_NAME_HERE, FunctionNameToBeCalled)
 			

What does this code do? @@ -102,10 +97,7 @@ function Initialize(Plugin) Plugin:SetName("DerpyPlugin") Plugin:SetVersion(1) - cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_MOVING, OnPlayerMoving) - - local PluginManager = cPluginManager:Get() - -- Command bindings + cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_MOVING, OnPlayerMoving) LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) return true @@ -127,10 +119,10 @@ end

 -- ADD THIS IF COMMAND DOES NOT REQUIRE A PARAMETER (/explode)
-PluginManager:BindCommand("/commandname", "permissionnode", FunctionToCall, " - Description of command")
+PluginManager.BindCommand("/commandname", "permissionnode", FunctionToCall, " - Description of command")
 
 -- ADD THIS IF COMMAND DOES REQUIRE A PARAMETER (/explode Notch)
-PluginManager:BindCommand("/commandname", "permissionnode", FunctionToCall, " ~ Description of command and parameter(s)")
+PluginManager.BindCommand("/commandname", "permissionnode", FunctionToCall, " ~ Description of command and parameter(s)")
 			

What does it do, and why are there two? -- cgit v1.2.3 From d8aa0b0ec7a2ebea2fc157c623ae8cd7d0b6ba1c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 31 Jan 2014 00:04:57 +0000 Subject: Improved code * Fixed some issues * Fixed standard violation --- src/Log.cpp | 14 +++++++++----- src/MCLogger.cpp | 12 ++++++++---- src/MCLogger.h | 4 ---- src/World.cpp | 2 ++ 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index a23a79ccc..37f1376db 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -134,14 +134,15 @@ void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str() ); //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); #else + size_t LineLength = Line.length(); + + if (m_LastStringSize == 0) + m_LastStringSize = LineLength; + if (a_ReplaceCurrentLine) { #ifdef _WIN32 - if (m_LastStringSize == 0) - { - m_LastStringSize = Line.length(); - } - else if (Line.length() < m_LastStringSize) // If last printed line was longer than current, clear this line + if (LineLength < m_LastStringSize) // If last printed line was longer than current, clear this line { for (size_t X = 0; X != m_LastStringSize; ++X) { @@ -162,6 +163,9 @@ void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine { printf("%s", Line.c_str()); } + + m_LastStringSize = LineLength; + #endif #if defined (_WIN32) && defined(_DEBUG) diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index 632ea2efe..aebe3e1c9 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -11,6 +11,10 @@ cMCLogger * cMCLogger::s_MCLogger = NULL; bool g_ShouldColorOutput = false; +/** Flag to show whether a 'replace line' log command has been issued +Used to decide when to put a newline */ +bool g_BeginLineUpdate = false; + #ifdef _WIN32 #include // Needed for _isatty(), not available on Linux @@ -123,14 +127,14 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla { cCSLock Lock(m_CriticalSection); - if (!m_BeginLineUpdate && a_ShouldReplaceLine) + if (!g_BeginLineUpdate && a_ShouldReplaceLine) { a_ShouldReplaceLine = false; // Print a normal line first if this is the initial replace line - m_BeginLineUpdate = true; + g_BeginLineUpdate = true; } - else if (m_BeginLineUpdate && !a_ShouldReplaceLine) + else if (g_BeginLineUpdate && !a_ShouldReplaceLine) { - m_BeginLineUpdate = false; + g_BeginLineUpdate = false; } if (a_ShouldReplaceLine) diff --git a/src/MCLogger.h b/src/MCLogger.h index 7bcc195dd..c105ab6e2 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -51,10 +51,6 @@ private: /// Common initialization for all constructors, creates a logfile with the specified name and assigns s_MCLogger to this void InitLog(const AString & a_FileName); - - /** Flag to show whether a 'replace line' log command has been issued - Used to decide when to put a newline */ - bool m_BeginLineUpdate = false; }; // tolua_export diff --git a/src/World.cpp b/src/World.cpp index bac529d4a..f2981bf84 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -111,6 +111,7 @@ protected: cSleep::MilliSleep(100); if (m_ShouldTerminate) { + LOGREPLACELINE("World successfully loaded!"); return; } } @@ -161,6 +162,7 @@ protected: cSleep::MilliSleep(100); if (m_ShouldTerminate) { + LOGREPLACELINE("Lighting successful!"); return; } } -- cgit v1.2.3 From 7ae5631d89426df6f05b6c8ba656ba02b9d15f93 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 31 Jan 2014 00:05:23 +0000 Subject: Added a comment --- src/Log.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Log.cpp b/src/Log.cpp index 37f1376db..cbb83097c 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -137,7 +137,7 @@ void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine size_t LineLength = Line.length(); if (m_LastStringSize == 0) - m_LastStringSize = LineLength; + m_LastStringSize = LineLength; // Initialise m_LastStringSize if (a_ReplaceCurrentLine) { -- cgit v1.2.3 From 79ef653cb79a47f2b4bcec47e13aff16f8ca1b43 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Fri, 31 Jan 2014 07:41:21 +0000 Subject: Fixed some more. --- MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html b/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html index bdb80186f..1eec4842a 100644 --- a/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html +++ b/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html @@ -119,10 +119,10 @@ end

 -- ADD THIS IF COMMAND DOES NOT REQUIRE A PARAMETER (/explode)
-PluginManager.BindCommand("/commandname", "permissionnode", FunctionToCall, " - Description of command")
+cPluginManager.BindCommand("/commandname", "permissionnode", FunctionToCall, " - Description of command")
 
 -- ADD THIS IF COMMAND DOES REQUIRE A PARAMETER (/explode Notch)
-PluginManager.BindCommand("/commandname", "permissionnode", FunctionToCall, " ~ Description of command and parameter(s)")
+cPluginManager.BindCommand("/commandname", "permissionnode", FunctionToCall, " ~ Description of command and parameter(s)")
 			

What does it do, and why are there two? @@ -189,8 +189,7 @@ function Initialize(Plugin) Plugin:SetName("DerpyPluginThatBlowsPeopleUp") Plugin:SetVersion(9001) - local PluginManager = cPluginManager:Get() - PluginManager:BindCommand("/explode", "derpyplugin.explode", Explode, " ~ Explode a player"); + cPluginManager.BindCommand("/explode", "derpyplugin.explode", Explode, " ~ Explode a player"); cPluginManager:AddHook(cPluginManager.HOOK_COLLECTING_PICKUP, OnCollectingPickup) -- cgit v1.2.3 From 66427d754b66c91ce76ca23cdbf6bf9c1b377d23 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 30 Jan 2014 17:41:57 +0100 Subject: Added cChunkDest::UpdateHeightmap() This function is necessary for plugins manipulating the generated chunks, they need to update the heightmap before it is passed back to the generator. --- src/Generating/ChunkDesc.cpp | 25 +++++++++++++++++++++++++ src/Generating/ChunkDesc.h | 40 +++++++++++++++++++++++----------------- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp index af1a8a6c7..87566aa78 100644 --- a/src/Generating/ChunkDesc.cpp +++ b/src/Generating/ChunkDesc.cpp @@ -562,6 +562,31 @@ cBlockEntity * cChunkDesc::GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ) +void cChunkDesc::UpdateHeightmap(void) +{ + for (int x = 0; x < cChunkDef::Width; x++) + { + for (int z = 0; z < cChunkDef::Width; z++) + { + int Height = 0; + for (int y = cChunkDef::Height - 1; y > 0; y--) + { + BLOCKTYPE BlockType = GetBlockType(x, y, z); + if (BlockType != E_BLOCK_AIR) + { + Height = y; + break; + } + } // for y + SetHeight(x, z, Height); + } // for z + } // for x +} + + + + + void cChunkDesc::CompressBlockMetas(cChunkDef::BlockNibbles & a_DestMetas) { const NIBBLETYPE * AreaMetas = m_BlockArea.GetBlockMetas(); diff --git a/src/Generating/ChunkDesc.h b/src/Generating/ChunkDesc.h index e130c463f..e258383d5 100644 --- a/src/Generating/ChunkDesc.h +++ b/src/Generating/ChunkDesc.h @@ -30,7 +30,7 @@ class cChunkDesc public: // tolua_end - /// Uncompressed block metas, 1 meta per byte + /** Uncompressed block metas, 1 meta per byte */ typedef NIBBLETYPE BlockNibbleBytes[cChunkDef::NumBlocks]; cChunkDesc(int a_ChunkX, int a_ChunkZ); @@ -56,6 +56,8 @@ public: void SetBiome(int a_RelX, int a_RelZ, int a_BiomeID); EMCSBiome GetBiome(int a_RelX, int a_RelZ); + // These operate on the heightmap, so they could get out of sync with the data + // Use UpdateHeightmap() to re-sync void SetHeight(int a_RelX, int a_RelZ, int a_Height); int GetHeight(int a_RelX, int a_RelZ); @@ -71,16 +73,16 @@ public: void SetUseDefaultFinish(bool a_bUseDefaultFinish); bool IsUsingDefaultFinish(void) const; - /// Writes the block area into the chunk, with its origin set at the specified relative coords. Area's data overwrite everything in the chunk. + /** Writes the block area into the chunk, with its origin set at the specified relative coords. Area's data overwrite everything in the chunk. */ void WriteBlockArea(const cBlockArea & a_BlockArea, int a_RelX, int a_RelY, int a_RelZ, cBlockArea::eMergeStrategy a_MergeStrategy = cBlockArea::msOverwrite); - /// Reads an area from the chunk into a cBlockArea, blocktypes and blockmetas + /** Reads an area from the chunk into a cBlockArea, blocktypes and blockmetas */ void ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ); - /// Returns the maximum height value in the heightmap + /** Returns the maximum height value in the heightmap */ HEIGHTTYPE GetMaxHeight(void) const; - /// Fills the relative cuboid with specified block; allows cuboid out of range of this chunk + /** Fills the relative cuboid with specified block; allows cuboid out of range of this chunk */ void FillRelCuboid( int a_MinX, int a_MaxX, int a_MinY, int a_MaxY, @@ -88,7 +90,7 @@ public: BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ); - /// Fills the relative cuboid with specified block; allows cuboid out of range of this chunk + /** Fills the relative cuboid with specified block; allows cuboid out of range of this chunk */ void FillRelCuboid(const cCuboid & a_RelCuboid, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { FillRelCuboid( @@ -99,7 +101,7 @@ public: ); } - /// Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk + /** Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk */ void ReplaceRelCuboid( int a_MinX, int a_MaxX, int a_MinY, int a_MaxY, @@ -108,7 +110,7 @@ public: BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta ); - /// Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk + /** Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk */ void ReplaceRelCuboid( const cCuboid & a_RelCuboid, BLOCKTYPE a_SrcType, NIBBLETYPE a_SrcMeta, @@ -124,7 +126,7 @@ public: ); } - /// Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk + /** Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk */ void FloorRelCuboid( int a_MinX, int a_MaxX, int a_MinY, int a_MaxY, @@ -132,7 +134,7 @@ public: BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta ); - /// Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk + /** Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk */ void FloorRelCuboid( const cCuboid & a_RelCuboid, BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta @@ -146,7 +148,7 @@ public: ); } - /// Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk + /** Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk */ void RandomFillRelCuboid( int a_MinX, int a_MaxX, int a_MinY, int a_MaxY, @@ -155,7 +157,7 @@ public: int a_RandomSeed, int a_ChanceOutOf10k ); - /// Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk + /** Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk */ void RandomFillRelCuboid( const cCuboid & a_RelCuboid, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_RandomSeed, int a_ChanceOutOf10k @@ -170,11 +172,15 @@ public: ); } - /// Returns the block entity at the specified coords. - /// If there is no block entity at those coords, tries to create one, based on the block type - /// If the blocktype doesn't support a block entity, returns NULL. + /** Returns the block entity at the specified coords. + If there is no block entity at those coords, tries to create one, based on the block type + If the blocktype doesn't support a block entity, returns NULL. */ cBlockEntity * GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ); + /** Updates the heightmap to match the current contents. + Useful for plugins when writing custom block areas into the chunk */ + void UpdateHeightmap(void); + // tolua_end // Accessors used by cChunkGenerator::Generator descendants: @@ -187,11 +193,11 @@ public: inline cEntityList & GetEntities (void) { return m_Entities; } inline cBlockEntityList & GetBlockEntities (void) { return m_BlockEntities; } - /// Compresses the metas from the BlockArea format (1 meta per byte) into regular format (2 metas per byte) + /** Compresses the metas from the BlockArea format (1 meta per byte) into regular format (2 metas per byte) */ void CompressBlockMetas(cChunkDef::BlockNibbles & a_DestMetas); #ifdef _DEBUG - /// Verifies that the heightmap corresponds to blocktype contents; if not, asserts on that column + /** Verifies that the heightmap corresponds to blocktype contents; if not, asserts on that column */ void VerifyHeightmap(void); #endif // _DEBUG -- cgit v1.2.3 From 5092ae526629b8eb8e611531a2f312c9177f0673 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 31 Jan 2014 09:19:46 +0100 Subject: Added cPluginManager:BindCommand() form to the API. That's the canonical way to call static functions. --- src/Bindings/ManualBindings.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index e7c66c6fb..ddc93b8c7 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1429,7 +1429,10 @@ static int tolua_cPluginManager_BindCommand(lua_State * L) // Read the arguments to this API call: tolua_Error tolua_err; int idx = 1; - if (tolua_isusertype(L, 1, "cPluginManager", 0, &tolua_err)) + if ( + tolua_isusertype (L, 1, "cPluginManager", 0, &tolua_err) || + tolua_isusertable(L, 1, "cPluginManager", 0, &tolua_err) + ) { idx++; } -- cgit v1.2.3 From 882d10862202795b8249c1b421fc62bf8bda3892 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 31 Jan 2014 10:20:06 +0100 Subject: Fixed cLineBlockTracer:Trace() signature. --- src/Bindings/ManualBindings.cpp | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index ddc93b8c7..dbaf32756 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2131,26 +2131,40 @@ protected: static int tolua_cLineBlockTracer_Trace(lua_State * tolua_S) { - // cLineBlockTracer.Trace(World, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ) + /* Supported function signatures: + cLineBlockTracer:Trace(World, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ) // Canonical + cLineBlockTracer.Trace(World, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ) + */ + + // If the first param is the cLineBlockTracer class, shift param index by one: + int idx = 1; + tolua_Error err; + if (tolua_isusertable(tolua_S, 1, "cLineBlockTracer", 0, &err)) + { + idx = 2; + } + + // Check params: cLuaState L(tolua_S); if ( - !L.CheckParamUserType(1, "cWorld") || - !L.CheckParamTable (2) || - !L.CheckParamNumber (3, 8) || - !L.CheckParamEnd (9) + !L.CheckParamUserType(idx, "cWorld") || + !L.CheckParamTable (idx + 1) || + !L.CheckParamNumber (idx + 2, idx + 7) || + !L.CheckParamEnd (idx + 8) ) { return 0; } - cWorld * World = (cWorld *)tolua_tousertype(L, 1, NULL); - cLuaBlockTracerCallbacks Callbacks(L, 2); - double StartX = tolua_tonumber(L, 3, 0); - double StartY = tolua_tonumber(L, 4, 0); - double StartZ = tolua_tonumber(L, 5, 0); - double EndX = tolua_tonumber(L, 6, 0); - double EndY = tolua_tonumber(L, 7, 0); - double EndZ = tolua_tonumber(L, 8, 0); + // Trace: + cWorld * World = (cWorld *)tolua_tousertype(L, idx, NULL); + cLuaBlockTracerCallbacks Callbacks(L, idx + 1); + double StartX = tolua_tonumber(L, idx + 2, 0); + double StartY = tolua_tonumber(L, idx + 3, 0); + double StartZ = tolua_tonumber(L, idx + 4, 0); + double EndX = tolua_tonumber(L, idx + 5, 0); + double EndY = tolua_tonumber(L, idx + 6, 0); + double EndZ = tolua_tonumber(L, idx + 7, 0); bool res = cLineBlockTracer::Trace(*World, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ); tolua_pushboolean(L, res ? 1 : 0); return 1; -- cgit v1.2.3 From c7e4ade7c357ce152319bf01527410d8323b929d Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Fri, 31 Jan 2014 16:27:21 +0100 Subject: Wolf: If Owner tag is missing a normal ownerless wolf will spawn. --- src/WorldStorage/WSSAnvil.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index e581c433e..0df97d759 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1879,16 +1879,13 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner"); if (OwnerIdx < 0) { - return; - } - - AString OwnerName = a_NBT.GetString(OwnerIdx); - if (OwnerName != "") - { - Monster->SetOwner(OwnerName); - Monster->SetIsTame(true); + AString OwnerName = a_NBT.GetString(OwnerIdx); + if (OwnerName != "") + { + Monster->SetOwner(OwnerName); + Monster->SetIsTame(true); + } } - a_Entities.push_back(Monster.release()); } -- cgit v1.2.3 From 19e5122b772dc3183afa204814cec5cd52e5ec1a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Fri, 31 Jan 2014 16:31:55 +0100 Subject: Inversed condition. --- src/WorldStorage/WSSAnvil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 0df97d759..02396bb16 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1877,7 +1877,7 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N return; } int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner"); - if (OwnerIdx < 0) + if (OwnerIdx > 0) { AString OwnerName = a_NBT.GetString(OwnerIdx); if (OwnerName != "") -- cgit v1.2.3 From f9a4c49fd47db92bba61b0d83f3e0d30b1ef55e7 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Fri, 31 Jan 2014 17:16:08 +0000 Subject: Contributors now match real life, and are alpha-sorted. --- CONTRIBUTORS | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b15a36a38..2392d8523 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1,25 +1,30 @@ Many people have contributed to MCServer, and this list attempts to broadcast at least some of them. -faketruth (founder) -xoft -keyboard -STR_Warrior -mgueydan -tigerw bearbin (Alexander Harkness) -Lapayo -rs2k +derouinw +Diusrex Duralex -mtilden +FakeTruth (founder) +keyboard +Lapayo Luksor marmot21 -Sofapriester mborland +mgueydan +MikeHunsinger +mtilden +nesco +rs2k SamJBarney -worktycho +Sofapriester +STR_Warrior +structinf (xdot) Sxw1212 +Taugeshtu +tigerw (Tiger Wang) tonibm19 -Diusrex -structinf (xdot) +worktycho +xoft + Please add yourself to this list if you contribute to MCServer. -- cgit v1.2.3 From 8180b643fff149e6411a57d0250ae54d94fcd29a Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Fri, 31 Jan 2014 21:34:00 +0400 Subject: Added reading saved state of the wolf (sitting or standing). --- src/WorldStorage/WSSAnvil.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 02396bb16..63999add3 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1886,6 +1886,12 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N Monster->SetIsTame(true); } } + int SittingIdx = a_NBT.FindChildByName(a_TagIdx, "Sitting"); + if (SittingIdx > 0) + { + bool IsSitting = (a_NBT.GetByte(SittingIdx) > 0); + Monster->SetIsSitting(IsSitting); + } a_Entities.push_back(Monster.release()); } -- cgit v1.2.3 From 02e752789399ad1b65a0443534ea6a8721efd78c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 31 Jan 2014 20:50:29 +0000 Subject: Properly initialised variables --- src/Log.cpp | 3 ++- src/Log.h | 2 +- src/MCLogger.cpp | 14 ++++++-------- src/MCLogger.h | 4 ++++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index cbb83097c..3938f2c24 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -18,7 +18,8 @@ cLog* cLog::s_Log = NULL; cLog::cLog(const AString & a_FileName ) - : m_File(NULL) + : m_File(NULL), + m_LastStringSize(0) { s_Log = this; diff --git a/src/Log.h b/src/Log.h index c8c26913b..8a0ee9fc7 100644 --- a/src/Log.h +++ b/src/Log.h @@ -10,7 +10,7 @@ class cLog private: FILE * m_File; static cLog * s_Log; - size_t m_LastStringSize = 0; + size_t m_LastStringSize; public: cLog(const AString & a_FileName); ~cLog(); diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index aebe3e1c9..b7b826374 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -11,10 +11,6 @@ cMCLogger * cMCLogger::s_MCLogger = NULL; bool g_ShouldColorOutput = false; -/** Flag to show whether a 'replace line' log command has been issued -Used to decide when to put a newline */ -bool g_BeginLineUpdate = false; - #ifdef _WIN32 #include // Needed for _isatty(), not available on Linux @@ -38,6 +34,7 @@ cMCLogger * cMCLogger::GetInstance(void) cMCLogger::cMCLogger(void) + : m_BeginLineUpdate(false) { AString FileName; Printf(FileName, "LOG_%d.txt", (int)time(NULL)); @@ -49,6 +46,7 @@ cMCLogger::cMCLogger(void) cMCLogger::cMCLogger(const AString & a_FileName) + : m_BeginLineUpdate(false) { InitLog(a_FileName); } @@ -127,14 +125,14 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla { cCSLock Lock(m_CriticalSection); - if (!g_BeginLineUpdate && a_ShouldReplaceLine) + if (!m_BeginLineUpdate && a_ShouldReplaceLine) { a_ShouldReplaceLine = false; // Print a normal line first if this is the initial replace line - g_BeginLineUpdate = true; + m_BeginLineUpdate = true; } - else if (g_BeginLineUpdate && !a_ShouldReplaceLine) + else if (m_BeginLineUpdate && !a_ShouldReplaceLine) { - g_BeginLineUpdate = false; + m_BeginLineUpdate = false; } if (a_ShouldReplaceLine) diff --git a/src/MCLogger.h b/src/MCLogger.h index c105ab6e2..4550cc55d 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -51,6 +51,10 @@ private: /// Common initialization for all constructors, creates a logfile with the specified name and assigns s_MCLogger to this void InitLog(const AString & a_FileName); + + /** Flag to show whether a 'replace line' log command has been issued + Used to decide when to put a newline */ + bool m_BeginLineUpdate; }; // tolua_export -- cgit v1.2.3 From 6b18add09b5e9d6d6c2a61e90bdd7011f56f4c82 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 31 Jan 2014 23:02:26 +0000 Subject: Fixed issues with insufficient console space --- src/Log.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++------------ src/Log.h | 11 +++++- src/MCLogger.cpp | 14 +++++-- 3 files changed, 114 insertions(+), 29 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index 3938f2c24..e7d3e0629 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -100,29 +100,29 @@ void cLog::ClearLog() -void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine) +bool cLog::LogReplaceLine(const char * a_Format, va_list argList) { AString Message; AppendVPrintf(Message, a_Format, argList); time_t rawtime; - time ( &rawtime ); - + time(&rawtime); + struct tm* timeinfo; #ifdef _MSC_VER struct tm timeinforeal; timeinfo = &timeinforeal; - localtime_s(timeinfo, &rawtime ); + localtime_s(timeinfo, &rawtime); #else - timeinfo = localtime( &rawtime ); + timeinfo = localtime(&rawtime); #endif AString Line; - #ifdef _DEBUG +#ifdef _DEBUG Printf(Line, "[%04x|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); - #else +#else Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); - #endif +#endif if (m_File) { fprintf(m_File, "%s\n", Line.c_str()); @@ -132,7 +132,7 @@ void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine // Print to console: #if defined(ANDROID_NDK) //__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList); - __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str() ); + __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str()); //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); #else size_t LineLength = Line.length(); @@ -140,35 +140,103 @@ void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine if (m_LastStringSize == 0) m_LastStringSize = LineLength; // Initialise m_LastStringSize - if (a_ReplaceCurrentLine) + HANDLE Output = GetStdHandle(STD_OUTPUT_HANDLE); + + CONSOLE_SCREEN_BUFFER_INFO csbi; + GetConsoleScreenBufferInfo(Output, &csbi); + + if ((size_t)((csbi.srWindow.Right - csbi.srWindow.Left) + 1) < LineLength) { + printf("\r%s", Line.c_str()); + return false; + } #ifdef _WIN32 - if (LineLength < m_LastStringSize) // If last printed line was longer than current, clear this line + if (LineLength < m_LastStringSize) // If last printed line was longer than current, clear this line + { + for (size_t X = 0; X != m_LastStringSize + 1; ++X) { - for (size_t X = 0; X != m_LastStringSize; ++X) - { - fputs(" ", stdout); - } + fputs(" ", stdout); } + } #else // _WIN32 - fputs("\033[K", stdout); // Clear current line -#endif - - printf("\r%s", Line.c_str()); - -#ifdef __linux - fputs("\033[1B", stdout); // Move down one line -#endif // __linux + struct ttysize ts; +#ifdef TIOCGSIZE + ioctl(STDIN_FILENO, TIOCGSIZE, &ts); + if (ts.ts_cols < LineLength) + { + return false; } - else +#elif defined(TIOCGWINSZ) + ioctl(STDIN_FILENO, TIOCGWINSZ, &ts); + if (ts.ts_cols < LineLength) { - printf("%s", Line.c_str()); + return false; } +#else /* TIOCGSIZE */ + return false; +#endif + fputs("\033[K", stdout); // Clear current line +#endif + printf("\r%s", Line.c_str()); +#ifdef __linux + fputs("\033[1B", stdout); // Move down one line +#endif // __linux m_LastStringSize = LineLength; +#endif // ANDROID_NDK + +#if defined (_WIN32) && defined(_DEBUG) + // In a Windows Debug build, output the log to debug console as well: + OutputDebugStringA((Line + "\n").c_str()); +#endif // _WIN32 + + return true; +} + + + + + +void cLog::Log(const char * a_Format, va_list argList) +{ + AString Message; + AppendVPrintf(Message, a_Format, argList); + + time_t rawtime; + time ( &rawtime ); + + struct tm* timeinfo; +#ifdef _MSC_VER + struct tm timeinforeal; + timeinfo = &timeinforeal; + localtime_s(timeinfo, &rawtime ); +#else + timeinfo = localtime( &rawtime ); #endif + AString Line; + #ifdef _DEBUG + Printf(Line, "[%04x|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); + #else + Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); + #endif + + if (m_File) + { + fprintf(m_File, "%s\n", Line.c_str()); + fflush(m_File); + } + + // Print to console: + #if defined(ANDROID_NDK) + //__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList); + __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str() ); + //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); + #else + printf("%s", Line.c_str()); + #endif + #if defined (_WIN32) && defined(_DEBUG) // In a Windows Debug build, output the log to debug console as well: OutputDebugStringA((Line + "\n").c_str()); diff --git a/src/Log.h b/src/Log.h index 8a0ee9fc7..c9ca17864 100644 --- a/src/Log.h +++ b/src/Log.h @@ -8,20 +8,29 @@ class cLog { // tolua_export private: + FILE * m_File; static cLog * s_Log; size_t m_LastStringSize; + public: + cLog(const AString & a_FileName); ~cLog(); - void Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine = false); + + /** Replaces current line of console with given text. + Returns true if successful, false if not (screen too narrow etc.) */ + bool LogReplaceLine(const char * a_Format, va_list argList); + void Log(const char * a_Format, va_list argList); void Log(const char * a_Format, ...); + // tolua_begin void SimpleLog(const char * a_String); void OpenLog(const char * a_FileName); void CloseLog(); void ClearLog(); static cLog* GetInstance(); + }; // tolua_end diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index b7b826374..0828b7fe4 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -147,7 +147,11 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla SetConsoleCursorPosition(Output, Position); SetColor(csRegular); - m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); + if (!m_Log->LogReplaceLine(a_Format, a_ArgList)) + { + m_BeginLineUpdate = false; + puts(""); + } ResetColor(); Position = { 0, csbi.dwCursorPosition.Y }; // Set cursor to original position @@ -155,14 +159,18 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla #else // _WIN32 fputs("\033[1A", stdout); // Move cursor up one line SetColor(csRegular); - m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); + if (!m_Log->LogReplaceLine(a_Format, a_ArgList)) + { + m_BeginLineUpdate = false; + puts(""); + } ResetColor(); #endif } else { SetColor(csRegular); - m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); + m_Log->Log(a_Format, a_ArgList); ResetColor(); puts(""); } -- cgit v1.2.3 From 25ec7750aac9800bec83a844020a6eeda5cd4d74 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 31 Jan 2014 15:17:41 -0800 Subject: Changed signitures of Several BLockHandler Methods Changed the signitures of the following to use interfaces: GetPlacementBlockTypeMeta OnPlaced OnPlacedByPlayer OnDestroyed OnNeighbourChanged NeighbourChanged OnUse CanBeAt Check --- src/Blocks/BlockBed.cpp | 2 +- src/Blocks/BlockBed.h | 2 +- src/Blocks/BlockButton.h | 2 +- src/Blocks/BlockCactus.h | 2 +- src/Blocks/BlockCarpet.h | 2 +- src/Blocks/BlockChest.h | 11 ++++++-- src/Blocks/BlockComparator.h | 2 +- src/Blocks/BlockCrops.h | 2 +- src/Blocks/BlockDeadBush.h | 2 +- src/Blocks/BlockDoor.cpp | 31 ++++++++++---------- src/Blocks/BlockDoor.h | 33 +++++++++++----------- src/Blocks/BlockDropSpenser.h | 2 +- src/Blocks/BlockEnderchest.h | 2 +- src/Blocks/BlockFenceGate.h | 10 +++---- src/Blocks/BlockFire.h | 56 ++++++++++++++++++------------------- src/Blocks/BlockFlower.h | 2 +- src/Blocks/BlockFluid.h | 4 +-- src/Blocks/BlockFurnace.h | 2 +- src/Blocks/BlockHandler.cpp | 10 +++---- src/Blocks/BlockHandler.h | 8 +++--- src/Blocks/BlockHopper.h | 2 +- src/Blocks/BlockIce.h | 4 +-- src/Blocks/BlockLadder.h | 18 ++++++------ src/Blocks/BlockLeaves.h | 6 ++-- src/Blocks/BlockLever.h | 12 ++++---- src/Blocks/BlockMushroom.h | 2 +- src/Blocks/BlockNetherWart.h | 4 +-- src/Blocks/BlockPiston.cpp | 10 +++---- src/Blocks/BlockPiston.h | 4 +-- src/Blocks/BlockPlanks.h | 2 +- src/Blocks/BlockPortal.h | 4 +-- src/Blocks/BlockPumpkin.h | 48 +++++++++++++++---------------- src/Blocks/BlockRail.h | 6 ++-- src/Blocks/BlockRedstone.h | 2 +- src/Blocks/BlockRedstoneRepeater.h | 8 +++--- src/Blocks/BlockSapling.h | 2 +- src/Blocks/BlockSign.h | 2 +- src/Blocks/BlockSlab.h | 4 +-- src/Blocks/BlockSnow.h | 6 ++-- src/Blocks/BlockStairs.h | 2 +- src/Blocks/BlockStems.h | 2 +- src/Blocks/BlockSugarcane.h | 2 +- src/Blocks/BlockTallGrass.h | 2 +- src/Blocks/BlockTorch.h | 14 +++++----- src/Blocks/BlockTrapdoor.h | 10 +++---- src/Blocks/BlockVine.h | 6 ++-- src/Blocks/BlockWood.h | 2 +- src/Blocks/ChunkInterface.h | 4 +++ src/Blocks/WorldInterface.h | 2 ++ src/Chunk.cpp | 6 ++-- src/Chunk.h | 2 +- src/ChunkMap.cpp | 7 ++--- src/ClientHandle.cpp | 3 +- src/Simulator/RedstoneSimulator.cpp | 6 ++-- src/World.h | 2 +- 55 files changed, 209 insertions(+), 196 deletions(-) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 02cdd58c7..425e286ec 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -23,7 +23,7 @@ void cBlockBedHandler::OnPlacedByPlayer( -void cBlockBedHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockBedHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { NIBBLETYPE OldMeta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 8c2063443..0948a9198 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -21,7 +21,7 @@ public: virtual void OnPlacedByPlayer(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; - virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 53c905576..7b25ec7aa 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -93,7 +93,7 @@ public: } } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { NIBBLETYPE Meta; a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta); diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h index 88be25dc0..b44c1bc2d 100644 --- a/src/Blocks/BlockCactus.h +++ b/src/Blocks/BlockCactus.h @@ -24,7 +24,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if (a_RelY <= 0) { diff --git a/src/Blocks/BlockCarpet.h b/src/Blocks/BlockCarpet.h index 22fd97710..aa92b0a08 100644 --- a/src/Blocks/BlockCarpet.h +++ b/src/Blocks/BlockCarpet.h @@ -49,7 +49,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return (a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR); } diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 84dc324fb..b22c5f450 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -66,7 +66,7 @@ public: virtual void OnPlacedByPlayer( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -110,8 +110,13 @@ public: return "step.wood"; } + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, const cChunk & a_Chunk) override + { + return CanBeAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + } + - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { cBlockArea Area; if (!Area.Read(a_ChunkInterface, a_BlockX - 2, a_BlockX + 2, a_BlockY, a_BlockY, a_BlockZ - 2, a_BlockZ + 2)) @@ -206,7 +211,7 @@ public: /// If there's a chest in the a_Area in the specified coords, modifies its meta to a_NewMeta and returns true. - bool CheckAndAdjustNeighbor(cChunkInterface * a_ChunkInterface, const cBlockArea & a_Area, int a_RelX, int a_RelZ, NIBBLETYPE a_NewMeta) override + bool CheckAndAdjustNeighbor(cChunkInterface * a_ChunkInterface, const cBlockArea & a_Area, int a_RelX, int a_RelZ, NIBBLETYPE a_NewMeta) { if (a_Area.GetRelBlockType(a_RelX, 0, a_RelZ) != E_BLOCK_CHEST) { diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index 7cb874556..fe0882072 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -39,7 +39,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); } diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index ad3057275..f0e05c2c3 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -96,7 +96,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_FARMLAND)); } diff --git a/src/Blocks/BlockDeadBush.h b/src/Blocks/BlockDeadBush.h index 059fb7091..3bd89b5ce 100644 --- a/src/Blocks/BlockDeadBush.h +++ b/src/Blocks/BlockDeadBush.h @@ -23,7 +23,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return (a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_SAND); } diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index 20b0a6324..971784d0c 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -2,7 +2,6 @@ #include "Globals.h" #include "BlockDoor.h" #include "../Item.h" -#include "../World.h" #include "../Entities/Player.h" @@ -18,24 +17,24 @@ cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockType) -void cBlockDoorHandler::OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockDoorHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE OldMeta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); if (OldMeta & 8) { // Was upper part of door - if (IsDoor(a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ))) + if (IsDoor(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ))) { - a_World->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); } } else { // Was lower part - if (IsDoor(a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))) + if (IsDoor(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))) { - a_World->FastSetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, E_BLOCK_AIR, 0); } } } @@ -44,11 +43,11 @@ void cBlockDoorHandler::OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY -void cBlockDoorHandler::OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockDoorHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { - if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_DOOR) + if (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_DOOR) { - ChangeDoor(a_World, a_BlockX, a_BlockY, a_BlockZ); + ChangeDoor(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); } } @@ -57,7 +56,7 @@ void cBlockDoorHandler::OnUse(cWorld * a_World, cWorldInterface * a_WorldInterfa void cBlockDoorHandler::OnPlacedByPlayer( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -65,15 +64,15 @@ void cBlockDoorHandler::OnPlacedByPlayer( { NIBBLETYPE a_TopBlockMeta = 8; if ( - ((a_BlockMeta == 0) && (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1) == m_BlockType)) || - ((a_BlockMeta == 1) && (a_World->GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == m_BlockType)) || - ((a_BlockMeta == 2) && (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1) == m_BlockType)) || - ((a_BlockMeta == 3) && (a_World->GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == m_BlockType)) + ((a_BlockMeta == 0) && (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1) == m_BlockType)) || + ((a_BlockMeta == 1) && (a_ChunkInterface->GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == m_BlockType)) || + ((a_BlockMeta == 2) && (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1) == m_BlockType)) || + ((a_BlockMeta == 3) && (a_ChunkInterface->GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == m_BlockType)) ) { a_TopBlockMeta = 9; } - a_World->SetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, a_TopBlockMeta); + a_ChunkInterface->SetBlock(a_WorldInterface, a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, a_TopBlockMeta); } diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index cf0572284..3a72f7a39 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -2,7 +2,6 @@ #pragma once #include "BlockHandler.h" -#include "../World.h" #include "../Entities/Player.h" @@ -15,13 +14,13 @@ class cBlockDoorHandler : public: cBlockDoorHandler(BLOCKTYPE a_BlockType); - virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override; - virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; + virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; virtual const char * GetStepSound(void) override; virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -34,8 +33,8 @@ public: } if ( - !CanReplaceBlock(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ)) || - !CanReplaceBlock(a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)) + !CanReplaceBlock(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ)) || + !CanReplaceBlock(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)) ) { return false; @@ -54,7 +53,7 @@ public: virtual void OnPlacedByPlayer( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -67,7 +66,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); } @@ -137,32 +136,32 @@ public: /// Changes the door at the specified coords from open to close or vice versa - static void ChangeDoor(cWorld * a_World, int a_X, int a_Y, int a_Z) + static void ChangeDoor(cChunkInterface * a_ChunkInterface, int a_X, int a_Y, int a_Z) { - NIBBLETYPE OldMetaData = a_World->GetBlockMeta(a_X, a_Y, a_Z); + NIBBLETYPE OldMetaData = a_ChunkInterface->GetBlockMeta(a_X, a_Y, a_Z); - a_World->SetBlockMeta(a_X, a_Y, a_Z, ChangeStateMetaData(OldMetaData)); + a_ChunkInterface->SetBlockMeta(a_X, a_Y, a_Z, ChangeStateMetaData(OldMetaData)); if (OldMetaData & 8) { // Current block is top of the door - BLOCKTYPE BottomBlock = a_World->GetBlock(a_X, a_Y - 1, a_Z); - NIBBLETYPE BottomMeta = a_World->GetBlockMeta(a_X, a_Y - 1, a_Z); + BLOCKTYPE BottomBlock = a_ChunkInterface->GetBlock(a_X, a_Y - 1, a_Z); + NIBBLETYPE BottomMeta = a_ChunkInterface->GetBlockMeta(a_X, a_Y - 1, a_Z); if (IsDoor(BottomBlock) && !(BottomMeta & 8)) { - a_World->SetBlockMeta(a_X, a_Y - 1, a_Z, ChangeStateMetaData(BottomMeta)); + a_ChunkInterface->SetBlockMeta(a_X, a_Y - 1, a_Z, ChangeStateMetaData(BottomMeta)); } } else { // Current block is bottom of the door - BLOCKTYPE TopBlock = a_World->GetBlock(a_X, a_Y + 1, a_Z); - NIBBLETYPE TopMeta = a_World->GetBlockMeta(a_X, a_Y + 1, a_Z); + BLOCKTYPE TopBlock = a_ChunkInterface->GetBlock(a_X, a_Y + 1, a_Z); + NIBBLETYPE TopMeta = a_ChunkInterface->GetBlockMeta(a_X, a_Y + 1, a_Z); if (IsDoor(TopBlock) && (TopMeta & 8)) { - a_World->SetBlockMeta(a_X, a_Y + 1, a_Z, ChangeStateMetaData(TopMeta)); + a_ChunkInterface->SetBlockMeta(a_X, a_Y + 1, a_Z, ChangeStateMetaData(TopMeta)); } } } diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index ce9cc0c5d..b9071ce12 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -22,7 +22,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index b648248d0..9e76d8b95 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -23,7 +23,7 @@ public: } virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index ff4f80c3c..0f0a75b70 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -30,20 +30,20 @@ public: } - virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - NIBBLETYPE OldMetaData = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMetaData = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); NIBBLETYPE NewMetaData = PlayerYawToMetaData(a_Player->GetYaw()); OldMetaData ^= 4; // Toggle the gate if ((OldMetaData & 1) == (NewMetaData & 1)) { // Standing in front of the gate - apply new direction - a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (OldMetaData & 4) | (NewMetaData & 3)); + a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (OldMetaData & 4) | (NewMetaData & 3)); } else { // Standing aside - use last direction - a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, OldMetaData); + a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, OldMetaData); } } diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h index a69fe2131..21e37d04e 100644 --- a/src/Blocks/BlockFire.h +++ b/src/Blocks/BlockFire.h @@ -19,7 +19,7 @@ public: /// Portal boundary and direction variables int XZP, XZM, Dir; // For wont of a better name... - virtual void OnPlaced(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override + virtual void OnPlaced(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override { /* PORTAL FINDING ALGORITH @@ -35,7 +35,7 @@ public: */ a_BlockY--; // Because we want the block below the fire - FindAndSetPortalFrame(a_BlockX, a_BlockY, a_BlockZ, a_World); // Brought to you by Aperture Science + FindAndSetPortalFrame(a_BlockX, a_BlockY, a_BlockZ, a_ChunkInterface, a_WorldInterface); // Brought to you by Aperture Science } virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override @@ -60,9 +60,9 @@ public: /// Traces along YP until it finds an obsidian block, returns Y difference or 0 if no portal, and -1 for border /// Takes the X, Y, and Z of the base block; with an optional MaxY for portal border finding - int FindObsidianCeiling(int X, int Y, int Z, cWorld * a_World, int MaxY = 0) + int FindObsidianCeiling(int X, int Y, int Z, cChunkInterface * a_ChunkInterface, int MaxY = 0) { - if (a_World->GetBlock(X, Y, Z) != E_BLOCK_OBSIDIAN) + if (a_ChunkInterface->GetBlock(X, Y, Z) != E_BLOCK_OBSIDIAN) { return 0; } @@ -70,7 +70,7 @@ public: for (int newY = Y + 1; newY < cChunkDef::Height; newY++) { - BLOCKTYPE Block = a_World->GetBlock(X, newY, Z); + BLOCKTYPE Block = a_ChunkInterface->GetBlock(X, newY, Z); if ((Block == E_BLOCK_AIR) || (Block == E_BLOCK_FIRE)) { continue; @@ -82,7 +82,7 @@ public: // This is because the frame is a solid obsidian pillar if ((MaxY != 0) && (newY == Y + 1)) { - return EvaluatePortalBorder(X, newY, Z, MaxY, a_World); + return EvaluatePortalBorder(X, newY, Z, MaxY, a_ChunkInterface); } else { @@ -97,11 +97,11 @@ public: } /// Evaluates if coords have a valid border on top, based on MaxY - int EvaluatePortalBorder(int X, int FoundObsidianY, int Z, int MaxY, cWorld * a_World) + int EvaluatePortalBorder(int X, int FoundObsidianY, int Z, int MaxY, cChunkInterface * a_ChunkInterface) { for (int checkBorder = FoundObsidianY + 1; checkBorder <= MaxY - 1; checkBorder++) // FoundObsidianY + 1: FoundObsidianY has already been checked in FindObsidianCeiling; MaxY - 1: portal doesn't need corners { - if (a_World->GetBlock(X, checkBorder, Z) != E_BLOCK_OBSIDIAN) + if (a_ChunkInterface->GetBlock(X, checkBorder, Z) != E_BLOCK_OBSIDIAN) { // Base obsidian, base + 1 obsidian, base + x NOT obsidian -> not complete portal return 0; @@ -112,9 +112,9 @@ public: } /// Finds entire frame in any direction with the coordinates of a base block and fills hole with nether portal (START HERE) - void FindAndSetPortalFrame(int X, int Y, int Z, cWorld * a_World) + void FindAndSetPortalFrame(int X, int Y, int Z, cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface) { - int MaxY = FindObsidianCeiling(X, Y, Z, a_World); // Get topmost obsidian block as reference for all other checks + int MaxY = FindObsidianCeiling(X, Y, Z, a_ChunkInterface); // Get topmost obsidian block as reference for all other checks int X1 = X + 1, Z1 = Z + 1, X2 = X - 1, Z2 = Z - 1; // Duplicate XZ values, add/subtract one as we've checked the original already the line above if (MaxY == 0) // Oh noes! Not a portal coordinate :( @@ -122,9 +122,9 @@ public: return; } - if (!FindPortalSliceX(X1, X2, Y, Z, MaxY, a_World)) + if (!FindPortalSliceX(X1, X2, Y, Z, MaxY, a_ChunkInterface)) { - if (!FindPortalSliceZ(X, Y, Z1, Z2, MaxY, a_World)) + if (!FindPortalSliceZ(X, Y, Z1, Z2, MaxY, a_ChunkInterface)) { return; // No eligible portal construct, abort abort abort!! } @@ -136,11 +136,11 @@ public: { if (Dir == 1) { - a_World->SetBlock(Width, Height, Z, E_BLOCK_NETHER_PORTAL, Dir); + a_ChunkInterface->SetBlock(a_WorldInterface, Width, Height, Z, E_BLOCK_NETHER_PORTAL, Dir); } else { - a_World->SetBlock(X, Height, Width, E_BLOCK_NETHER_PORTAL, Dir); + a_ChunkInterface->SetBlock(a_WorldInterface, X, Height, Width, E_BLOCK_NETHER_PORTAL, Dir); } } } @@ -150,14 +150,14 @@ public: /// Evaluates if coordinates are a portal going XP/XM; returns true if so, and writes boundaries to variable /// Takes coordinates of base block and Y coord of target obsidian ceiling - bool FindPortalSliceX(int X1, int X2, int Y, int Z, int MaxY, cWorld * a_World) + bool FindPortalSliceX(int X1, int X2, int Y, int Z, int MaxY, cChunkInterface * a_ChunkInterface) { Dir = 1; // Set assumed direction (will change if portal turns out to be facing the other direction) bool FoundFrameXP = false, FoundFrameXM = false; - for (; ((a_World->GetBlock(X1, Y, Z) == E_BLOCK_OBSIDIAN) || (a_World->GetBlock(X1, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X1++) // Check XP for obsidian blocks, exempting corners + for (; ((a_ChunkInterface->GetBlock(X1, Y, Z) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface->GetBlock(X1, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X1++) // Check XP for obsidian blocks, exempting corners { - int Value = FindObsidianCeiling(X1, Y, Z, a_World, MaxY); - int ValueTwo = FindObsidianCeiling(X1, Y + 1, Z, a_World, MaxY); // For corners without obsidian + int Value = FindObsidianCeiling(X1, Y, Z, a_ChunkInterface, MaxY); + int ValueTwo = FindObsidianCeiling(X1, Y + 1, Z, a_ChunkInterface, MaxY); // For corners without obsidian if ((Value == -1) || (ValueTwo == -1)) // FindObsidianCeiling returns -1 upon frame-find { FoundFrameXP = true; // Found a frame border in this direction, proceed in other direction (don't go further) @@ -168,10 +168,10 @@ public: return false; // Not valid slice, no portal can be formed } } XZP = X1 - 1; // Set boundary of frame interior, note that for some reason, the loop of X and the loop of Z go to different numbers, hence -1 here and -2 there - for (; ((a_World->GetBlock(X2, Y, Z) == E_BLOCK_OBSIDIAN) || (a_World->GetBlock(X2, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X2--) // Go the other direction (XM) + for (; ((a_ChunkInterface->GetBlock(X2, Y, Z) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface->GetBlock(X2, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X2--) // Go the other direction (XM) { - int Value = FindObsidianCeiling(X2, Y, Z, a_World, MaxY); - int ValueTwo = FindObsidianCeiling(X2, Y + 1, Z, a_World, MaxY); + int Value = FindObsidianCeiling(X2, Y, Z, a_ChunkInterface, MaxY); + int ValueTwo = FindObsidianCeiling(X2, Y + 1, Z, a_ChunkInterface, MaxY); if ((Value == -1) || (ValueTwo == -1)) { FoundFrameXM = true; @@ -186,14 +186,14 @@ public: } /// Evaluates if coords are a portal going ZP/ZM; returns true if so, and writes boundaries to variable - bool FindPortalSliceZ(int X, int Y, int Z1, int Z2, int MaxY, cWorld * a_World) + bool FindPortalSliceZ(int X, int Y, int Z1, int Z2, int MaxY, cChunkInterface * a_ChunkInterface) { Dir = 2; bool FoundFrameZP = false, FoundFrameZM = false; - for (; ((a_World->GetBlock(X, Y, Z1) == E_BLOCK_OBSIDIAN) || (a_World->GetBlock(X, Y + 1, Z1) == E_BLOCK_OBSIDIAN)); Z1++) + for (; ((a_ChunkInterface->GetBlock(X, Y, Z1) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface->GetBlock(X, Y + 1, Z1) == E_BLOCK_OBSIDIAN)); Z1++) { - int Value = FindObsidianCeiling(X, Y, Z1, a_World, MaxY); - int ValueTwo = FindObsidianCeiling(X, Y + 1, Z1, a_World, MaxY); + int Value = FindObsidianCeiling(X, Y, Z1, a_ChunkInterface, MaxY); + int ValueTwo = FindObsidianCeiling(X, Y + 1, Z1, a_ChunkInterface, MaxY); if ((Value == -1) || (ValueTwo == -1)) { FoundFrameZP = true; @@ -204,10 +204,10 @@ public: return false; } } XZP = Z1 - 2; - for (; ((a_World->GetBlock(X, Y, Z2) == E_BLOCK_OBSIDIAN) || (a_World->GetBlock(X, Y + 1, Z2) == E_BLOCK_OBSIDIAN)); Z2--) + for (; ((a_ChunkInterface->GetBlock(X, Y, Z2) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface->GetBlock(X, Y + 1, Z2) == E_BLOCK_OBSIDIAN)); Z2--) { - int Value = FindObsidianCeiling(X, Y, Z2, a_World, MaxY); - int ValueTwo = FindObsidianCeiling(X, Y + 1, Z2, a_World, MaxY); + int Value = FindObsidianCeiling(X, Y, Z2, a_ChunkInterface, MaxY); + int ValueTwo = FindObsidianCeiling(X, Y + 1, Z2, a_ChunkInterface, MaxY); if ((Value == -1) || (ValueTwo == -1)) { FoundFrameZM = true; diff --git a/src/Blocks/BlockFlower.h b/src/Blocks/BlockFlower.h index 421e2d5d8..f296f7be3 100644 --- a/src/Blocks/BlockFlower.h +++ b/src/Blocks/BlockFlower.h @@ -24,7 +24,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return (a_RelY > 0) && IsBlockTypeOfDirt(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)); } diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index bce5064bc..d57192d78 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -32,7 +32,7 @@ public: } - virtual void Check(int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override + virtual void Check(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override { switch (m_BlockType) { @@ -47,7 +47,7 @@ public: break; } } - super::Check(a_RelX, a_RelY, a_RelZ, a_Chunk); + super::Check(a_ChunkInterface, a_RelX, a_RelY, a_RelZ, a_Chunk); } } ; diff --git a/src/Blocks/BlockFurnace.h b/src/Blocks/BlockFurnace.h index 693eac331..42b3ee4be 100644 --- a/src/Blocks/BlockFurnace.h +++ b/src/Blocks/BlockFurnace.h @@ -26,7 +26,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 68907c9a3..0eedf7f4f 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -268,7 +268,7 @@ void cBlockHandler::OnUpdate(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a -void cBlockHandler::OnPlacedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +void cBlockHandler::OnPlacedByPlayer(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { } @@ -284,7 +284,7 @@ void cBlockHandler::OnDestroyedByPlayer(cWorld *a_World, cPlayer * a_Player, int -void cBlockHandler::OnPlaced(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +void cBlockHandler::OnPlaced(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { // Notify the neighbors NeighborChanged(a_ChunkInterface, a_BlockX - 1, a_BlockY, a_BlockZ); @@ -400,7 +400,7 @@ const char * cBlockHandler::GetStepSound() -bool cBlockHandler::CanBeAt(int a_BlockX, int a_BlockY, int a_BlockZ, const cChunk & a_Chunk) +bool cBlockHandler::CanBeAt(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, const cChunk & a_Chunk) { return true; } @@ -445,9 +445,9 @@ bool cBlockHandler::DoesDropOnUnsuitable(void) -void cBlockHandler::Check(int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) +void cBlockHandler::Check(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) { - if (!CanBeAt(a_RelX, a_RelY, a_RelZ, a_Chunk)) + if (!CanBeAt(a_ChunkInterface, a_RelX, a_RelY, a_RelZ, a_Chunk)) { if (DoesDropOnUnsuitable()) { diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index ffded50e0..8a0206c25 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -40,11 +40,11 @@ public: ); /// Called by cWorld::SetBlock() after the block has been set - virtual void OnPlaced(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + virtual void OnPlaced(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); /// Called by cClientHandle::HandlePlaceBlock() after the player has placed a new block. Called after OnPlaced(). virtual void OnPlacedByPlayer( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -78,7 +78,7 @@ public: virtual const char * GetStepSound(void); /// Checks if the block can stay at the specified relative coords in the chunk - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk); + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk); /** Checks if the block can be placed at this point. Default: CanBeAt(...) @@ -113,7 +113,7 @@ public: By default drops if position no more suitable (CanBeAt(), DoesDropOnUnsuitable(), Drop()), and wakes up all simulators on the block. */ - virtual void Check(int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk); + virtual void Check(cChunkInterface * ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk); ///

Rotates a given block meta counter-clockwise. Default: no change /// Block meta following rotation diff --git a/src/Blocks/BlockHopper.h b/src/Blocks/BlockHopper.h index 3998276d7..2694acc99 100644 --- a/src/Blocks/BlockHopper.h +++ b/src/Blocks/BlockHopper.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockIce.h b/src/Blocks/BlockIce.h index af4961114..42521941d 100644 --- a/src/Blocks/BlockIce.h +++ b/src/Blocks/BlockIce.h @@ -24,10 +24,10 @@ public: } - virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override + virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { // TODO: Ice destroyed with air below it should turn into air instead of water - a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_WATER, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_WATER, 0); // This is called later than the real destroying of this ice block } } ; diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h index c0aa25f60..fa1f80a6e 100644 --- a/src/Blocks/BlockLadder.h +++ b/src/Blocks/BlockLadder.h @@ -19,15 +19,15 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override { - if (!LadderCanBePlacedAt(a_World, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace)) + if (!LadderCanBePlacedAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace)) { - a_BlockFace = FindSuitableBlockFace(a_World, a_BlockX, a_BlockY, a_BlockZ); + a_BlockFace = FindSuitableBlockFace(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); if (a_BlockFace == BLOCK_FACE_BOTTOM) { @@ -68,11 +68,11 @@ public: /// Finds a suitable Direction for the Ladder. Returns BLOCK_FACE_BOTTOM on failure - static char FindSuitableBlockFace(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) + static char FindSuitableBlockFace(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { for (int Face = 2; Face <= 5; Face++) { - if (LadderCanBePlacedAt(a_World, a_BlockX, a_BlockY, a_BlockZ, Face)) + if (LadderCanBePlacedAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, Face)) { return Face; } @@ -81,7 +81,7 @@ public: } - static bool LadderCanBePlacedAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) + static bool LadderCanBePlacedAt(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) { if ((a_BlockFace == BLOCK_FACE_BOTTOM) || (a_BlockFace == BLOCK_FACE_TOP)) { @@ -90,17 +90,17 @@ public: AddFaceDirection( a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); - return g_BlockIsSolid[a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ)]; + return g_BlockIsSolid[a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ)]; } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface,int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { // TODO: Use AdjustCoordsByMeta(), then cChunk::UnboundedRelGetBlock() and finally some comparison char BlockFace = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width; int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width; - return LadderCanBePlacedAt(a_Chunk.GetWorld(), BlockX, a_RelY, BlockZ, BlockFace); + return LadderCanBePlacedAt(a_ChunkInterface, BlockX, a_RelY, BlockZ, BlockFace); } diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 730906bee..58ef0a0a4 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -70,10 +70,10 @@ public: } - virtual void OnNeighborChanged(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override + virtual void OnNeighborChanged(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { - NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0x7); // Unset 0x8 bit so it gets checked for decay + NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0x7); // Unset 0x8 bit so it gets checked for decay } diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index 5b0c89127..b77078a08 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -15,13 +15,13 @@ public: { } - virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Flip the ON bit on/off using the XOR bitwise operation - NIBBLETYPE Meta = (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08); + NIBBLETYPE Meta = (a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08); - a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LEVER, Meta); // SetMeta doesn't work for unpowering levers, so setblock - a_World->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); + a_ChunkInterface->SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LEVER, Meta); // SetMeta doesn't work for unpowering levers, so setblock + a_WorldInterface->GetBroadcastManager()->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); } @@ -39,7 +39,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -94,7 +94,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { NIBBLETYPE Meta; a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta); diff --git a/src/Blocks/BlockMushroom.h b/src/Blocks/BlockMushroom.h index 2846a6317..49fd216a3 100644 --- a/src/Blocks/BlockMushroom.h +++ b/src/Blocks/BlockMushroom.h @@ -24,7 +24,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if (a_RelY <= 0) { diff --git a/src/Blocks/BlockNetherWart.h b/src/Blocks/BlockNetherWart.h index 4cc3d989a..d30cce37a 100644 --- a/src/Blocks/BlockNetherWart.h +++ b/src/Blocks/BlockNetherWart.h @@ -45,8 +45,8 @@ public: } } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_SOULSAND)); } -} ; \ No newline at end of file +} ; diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp index 88259d96e..0b7dd5863 100644 --- a/src/Blocks/BlockPiston.cpp +++ b/src/Blocks/BlockPiston.cpp @@ -33,18 +33,18 @@ cBlockPistonHandler::cBlockPistonHandler(BLOCKTYPE a_BlockType) -void cBlockPistonHandler::OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockPistonHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE OldMeta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); int newX = a_BlockX; int newY = a_BlockY; int newZ = a_BlockZ; AddPistonDir(newX, newY, newZ, OldMeta & ~(8), 1); - if (a_World->GetBlock(newX, newY, newZ) == E_BLOCK_PISTON_EXTENSION) + if (a_ChunkInterface->GetBlock(newX, newY, newZ) == E_BLOCK_PISTON_EXTENSION) { - a_World->SetBlock(newX, newY, newZ, E_BLOCK_AIR, 0); + a_ChunkInterface->SetBlock(a_WorldInterface, newX, newY, newZ, E_BLOCK_AIR, 0); } } @@ -53,7 +53,7 @@ void cBlockPistonHandler::OnDestroyed(cWorld * a_World, int a_BlockX, int a_Bloc bool cBlockPistonHandler::GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index 36fa6a572..627b58244 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -13,10 +13,10 @@ class cBlockPistonHandler : public: cBlockPistonHandler(BLOCKTYPE a_BlockType); - virtual void OnDestroyed(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockPlanks.h b/src/Blocks/BlockPlanks.h index f3b8dbfb6..9fd51e8e6 100644 --- a/src/Blocks/BlockPlanks.h +++ b/src/Blocks/BlockPlanks.h @@ -17,7 +17,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockPortal.h b/src/Blocks/BlockPortal.h index d88d14fc9..2c63f96b2 100644 --- a/src/Blocks/BlockPortal.h +++ b/src/Blocks/BlockPortal.h @@ -17,7 +17,7 @@ public: } virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -39,7 +39,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if ((a_RelY - 1 < 0) || (a_RelY + 1 > cChunkDef::Height)) { diff --git a/src/Blocks/BlockPumpkin.h b/src/Blocks/BlockPumpkin.h index 5187f24eb..0f6e365f4 100644 --- a/src/Blocks/BlockPumpkin.h +++ b/src/Blocks/BlockPumpkin.h @@ -14,7 +14,7 @@ public: { } - virtual void OnPlacedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override + virtual void OnPlacedByPlayer(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override { // Check whether the pumpkin is a part of a golem or a snowman @@ -24,16 +24,16 @@ public: return; } - BLOCKTYPE BlockY1 = a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); - BLOCKTYPE BlockY2 = a_World->GetBlock(a_BlockX, a_BlockY - 2, a_BlockZ); + BLOCKTYPE BlockY1 = a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); + BLOCKTYPE BlockY2 = a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 2, a_BlockZ); // Check for a snow golem: if ((BlockY1 == E_BLOCK_SNOW_BLOCK) && (BlockY2 == E_BLOCK_SNOW_BLOCK)) { - a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - a_World->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); - a_World->FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); - a_World->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtSnowGolem); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); + a_WorldInterface->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtSnowGolem); return; } @@ -46,40 +46,40 @@ public: // Now check both orientations for hands: if ( - (a_World->GetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ) == E_BLOCK_IRON_BLOCK) && - (a_World->GetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ) == E_BLOCK_IRON_BLOCK) + (a_ChunkInterface->GetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ) == E_BLOCK_IRON_BLOCK) && + (a_ChunkInterface->GetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ) == E_BLOCK_IRON_BLOCK) ) { // Remove the iron blocks: - a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - a_World->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); - a_World->FastSetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); - a_World->FastSetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); - a_World->FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); // Spawn the golem: - a_World->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtIronGolem); + a_WorldInterface->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtIronGolem); } else if ( - (a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1) == E_BLOCK_IRON_BLOCK) && - (a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1) == E_BLOCK_IRON_BLOCK) + (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1) == E_BLOCK_IRON_BLOCK) && + (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1) == E_BLOCK_IRON_BLOCK) ) { // Remove the iron blocks: - a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - a_World->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); - a_World->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1, E_BLOCK_AIR, 0); - a_World->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1, E_BLOCK_AIR, 0); - a_World->FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); // Spawn the golem: - a_World->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtIronGolem); + a_WorldInterface->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtIronGolem); } } virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index e414e16ce..203ee297c 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -42,9 +42,9 @@ public: } - virtual void OnPlaced(cChunkInterface *a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override + virtual void OnPlaced(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override { - super::OnPlaced(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + super::OnPlaced(a_ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); // Alert diagonal rails OnNeighborChanged(a_ChunkInterface, a_BlockX + 1, a_BlockY + 1, a_BlockZ); @@ -92,7 +92,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if (a_RelY <= 0) { diff --git a/src/Blocks/BlockRedstone.h b/src/Blocks/BlockRedstone.h index 5ffb77fb6..45e668529 100644 --- a/src/Blocks/BlockRedstone.h +++ b/src/Blocks/BlockRedstone.h @@ -18,7 +18,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && g_BlockFullyOccupiesVoxel[a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)]); } diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h index 18aa765a6..c995a6787 100644 --- a/src/Blocks/BlockRedstoneRepeater.h +++ b/src/Blocks/BlockRedstoneRepeater.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -30,9 +30,9 @@ public: } - virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f)); + a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, ((a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f)); } @@ -49,7 +49,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); } diff --git a/src/Blocks/BlockSapling.h b/src/Blocks/BlockSapling.h index 0dcae1f93..3fb67fe72 100644 --- a/src/Blocks/BlockSapling.h +++ b/src/Blocks/BlockSapling.h @@ -25,7 +25,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return (a_RelY > 0) && IsBlockTypeOfDirt(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)); } diff --git a/src/Blocks/BlockSign.h b/src/Blocks/BlockSign.h index 7fbe61893..68506e307 100644 --- a/src/Blocks/BlockSign.h +++ b/src/Blocks/BlockSign.h @@ -63,7 +63,7 @@ public: virtual void OnPlacedByPlayer( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index 7c1251b28..a1e73c94e 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -33,7 +33,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -47,7 +47,7 @@ public: cItemHandler * ItemHandler = cItemHandler::GetItemHandler(GetDoubleSlabType(Type)); // Check if the block at the coordinates is a slab. Eligibility for combining has already been processed in ClientHandle - if (IsAnySlabType(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ))) + if (IsAnySlabType(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ))) { // Call the function in ClientHandle that places a block when the client sends the packet, // so that plugins may interfere with the placement. diff --git a/src/Blocks/BlockSnow.h b/src/Blocks/BlockSnow.h index d7fd1e19e..235ac3251 100644 --- a/src/Blocks/BlockSnow.h +++ b/src/Blocks/BlockSnow.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -28,7 +28,7 @@ public: BLOCKTYPE BlockBeforePlacement; NIBBLETYPE MetaBeforePlacement; - a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockBeforePlacement, MetaBeforePlacement); + a_ChunkInterface->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockBeforePlacement, MetaBeforePlacement); if ((BlockBeforePlacement == E_BLOCK_SNOW) && (MetaBeforePlacement < 7)) { @@ -65,7 +65,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if (a_RelY > 0) { diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index e463612f5..a43d81b4d 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -19,7 +19,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockStems.h b/src/Blocks/BlockStems.h index d860639a5..8f546029d 100644 --- a/src/Blocks/BlockStems.h +++ b/src/Blocks/BlockStems.h @@ -42,7 +42,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_FARMLAND)); } diff --git a/src/Blocks/BlockSugarcane.h b/src/Blocks/BlockSugarcane.h index 9cff94800..fbdd5a0a8 100644 --- a/src/Blocks/BlockSugarcane.h +++ b/src/Blocks/BlockSugarcane.h @@ -23,7 +23,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if (a_RelY <= 0) { diff --git a/src/Blocks/BlockTallGrass.h b/src/Blocks/BlockTallGrass.h index cd27ab7e6..52aa039bc 100644 --- a/src/Blocks/BlockTallGrass.h +++ b/src/Blocks/BlockTallGrass.h @@ -34,7 +34,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); } diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index faba9c4f5..a9a3bd1f8 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -28,7 +28,7 @@ public: if ((a_BlockFace == BLOCK_FACE_TOP) || (a_BlockFace == BLOCK_FACE_BOTTOM)) { - a_BlockFace = FindSuitableFace(a_World, a_BlockX, a_BlockY, a_BlockZ); // Top or bottom faces clicked, find a suitable face + a_BlockFace = FindSuitableFace(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); // Top or bottom faces clicked, find a suitable face if (a_BlockFace == BLOCK_FACE_NONE) { // Client wouldn't have sent anything anyway, but whatever @@ -39,10 +39,10 @@ public: { // Not top or bottom faces, try to preserve whatever face was clicked AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); - if (!CanBePlacedOn(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ), a_BlockFace)) + if (!CanBePlacedOn(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ), a_BlockFace)) { // Torch couldn't be placed on whatever face was clicked, last ditch resort - find another face - a_BlockFace = FindSuitableFace(a_World, a_BlockX, a_BlockY, a_BlockZ); + a_BlockFace = FindSuitableFace(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); if (a_BlockFace == BLOCK_FACE_NONE) { return false; @@ -110,12 +110,12 @@ public: /// Finds a suitable face to place the torch, returning BLOCK_FACE_NONE on failure - static char FindSuitableFace(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) + static char FindSuitableFace(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { for (int i = BLOCK_FACE_YM; i <= BLOCK_FACE_XP; i++) // Loop through all directions { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, i, true); - BLOCKTYPE BlockInQuestion = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + BLOCKTYPE BlockInQuestion = a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ); if ( // If on a block that can only hold a torch if torch is standing on it, return that face ((BlockInQuestion == E_BLOCK_GLASS) || @@ -142,7 +142,7 @@ public: } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { char Face = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 1843c1221..0fb48005d 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -32,16 +32,16 @@ public: return true; } - virtual void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Flip the ON bit on/off using the XOR bitwise operation - NIBBLETYPE Meta = (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x04); + NIBBLETYPE Meta = (a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x04); - a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); + a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); } virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -89,7 +89,7 @@ public: } } - virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { NIBBLETYPE Meta; a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta); diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index 60aaa9e4b..b6a88524b 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -27,7 +27,7 @@ public: // TODO: Disallow placement where the vine doesn't attach to something properly BLOCKTYPE BlockType = 0; NIBBLETYPE BlockMeta; - a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); + a_ChunkInterface->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); if (BlockType == m_BlockType) { a_BlockMeta = BlockMeta | DirectionToMetaData(a_BlockFace); @@ -105,7 +105,7 @@ public: } - void Check(int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override + void Check(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override { NIBBLETYPE CurMeta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); NIBBLETYPE MaxMeta = GetMaxMeta(a_Chunk, a_RelX, a_RelY, a_RelZ); diff --git a/src/Blocks/BlockWood.h b/src/Blocks/BlockWood.h index cb5ee995a..f2fdbff6a 100644 --- a/src/Blocks/BlockWood.h +++ b/src/Blocks/BlockWood.h @@ -17,7 +17,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h index a16c68013..b0faf5b05 100644 --- a/src/Blocks/ChunkInterface.h +++ b/src/Blocks/ChunkInterface.h @@ -23,6 +23,10 @@ public: return m_ChunkMap->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); } + bool GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) + { + return m_ChunkMap->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + } /** Sets the block at the specified coords to the specified value. Full processing, incl. updating neighbors, is performed. */ diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index a29d7a73a..c50bd1ad7 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -22,4 +22,6 @@ public: /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified: */ virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false) = 0; + /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */ + virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) = 0; }; diff --git a/src/Chunk.cpp b/src/Chunk.cpp index a72464ec3..4fdaf4b69 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -753,7 +753,7 @@ void cChunk::BroadcastPendingBlockChanges(void) -void cChunk::CheckBlocks(void) +void cChunk::CheckBlocks() { if (m_ToTickBlocks.size() == 0) { @@ -762,13 +762,15 @@ void cChunk::CheckBlocks(void) std::vector ToTickBlocks; std::swap(m_ToTickBlocks, ToTickBlocks); + cChunkInterface ChunkInterface(m_World->GetChunkMap()); + for (std::vector::const_iterator itr = ToTickBlocks.begin(), end = ToTickBlocks.end(); itr != end; ++itr) { unsigned int index = (*itr); Vector3i BlockPos = IndexToCoordinate(index); cBlockHandler * Handler = BlockHandler(GetBlock(index)); - Handler->Check(BlockPos.x, BlockPos.y, BlockPos.z, *this); + Handler->Check(&ChunkInterface, BlockPos.x, BlockPos.y, BlockPos.z, *this); } // for itr - ToTickBlocks[] } diff --git a/src/Chunk.h b/src/Chunk.h index 4ac38c46c..83d69d12c 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -440,7 +440,7 @@ private: void BroadcastPendingBlockChanges(void); /// Checks the block scheduled for checking in m_ToTickBlocks[] - void CheckBlocks(void); + void CheckBlocks(); /// Ticks several random blocks in the chunk void TickBlocks(void); diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index d0bccb837..fb2495dd1 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1235,10 +1235,10 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP void cChunkMap::SetBlock(cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta) { - cChunkInterface *ChunkInterface = new cChunkInterface(this); + cChunkInterface ChunkInterface(this); if (a_BlockType == E_BLOCK_AIR) { - BlockHandler(GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnDestroyed(ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); + BlockHandler(GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnDestroyed(&ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); } int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ; @@ -1251,8 +1251,7 @@ void cChunkMap::SetBlock(cWorldInterface * a_WorldInterface, int a_BlockX, int a Chunk->SetBlock(X, Y, Z, a_BlockType, a_BlockMeta ); m_World->GetSimulatorManager()->WakeUp(a_BlockX, a_BlockY, a_BlockZ, Chunk); } - BlockHandler(a_BlockType)->OnPlaced(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); - delete ChunkInterface; + BlockHandler(a_BlockType)->OnPlaced(&ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); } diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 60d2efbb2..3cad46adf 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1064,7 +1064,8 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, c { m_Player->GetInventory().RemoveOneEquippedItem(); } - NewBlock->OnPlacedByPlayer(World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta); + cChunkInterface ChunkInterface(World->GetChunkMap()); + NewBlock->OnPlacedByPlayer(&ChunkInterface,World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta); // Step sound with 0.8f pitch is used as block placement sound World->BroadcastSoundEffect(NewBlock->GetStepSound(), a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 1.0f, 0.8f); diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index e361cbf49..e672c2e49 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -747,7 +747,8 @@ void cRedstoneSimulator::HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ) { if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) { - cBlockDoorHandler::ChangeDoor(&m_World, a_BlockX, a_BlockY, a_BlockZ); + cChunkInterface ChunkInterface(m_World.GetChunkMap()); + cBlockDoorHandler::ChangeDoor(&ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); } } @@ -755,7 +756,8 @@ void cRedstoneSimulator::HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ) { if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) { - cBlockDoorHandler::ChangeDoor(&m_World, a_BlockX, a_BlockY, a_BlockZ); + cChunkInterface ChunkInterface(m_World.GetChunkMap()); + cBlockDoorHandler::ChangeDoor(&ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); } } diff --git a/src/World.h b/src/World.h index 7b2782421..6d5df7b8f 100644 --- a/src/World.h +++ b/src/World.h @@ -635,7 +635,7 @@ public: bool IsBlockDirectlyWatered(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */ - int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType); // tolua_export + virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType); // tolua_export int SpawnMobFinalize(cMonster* a_Monster); /** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise */ -- cgit v1.2.3 From 397208145ebe5c95ebf32f2985f6800634932230 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 31 Jan 2014 23:25:15 +0000 Subject: A newline issue is resolved --- src/Log.cpp | 2 +- src/MCLogger.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index e7d3e0629..b246e8196 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -147,7 +147,7 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) if ((size_t)((csbi.srWindow.Right - csbi.srWindow.Left) + 1) < LineLength) { - printf("\r%s", Line.c_str()); + printf("\n%s", Line.c_str()); // We are at line to be replaced, but since we can't, add a new line return false; } #ifdef _WIN32 diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index 0828b7fe4..11fd451a7 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -150,7 +150,6 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla if (!m_Log->LogReplaceLine(a_Format, a_ArgList)) { m_BeginLineUpdate = false; - puts(""); } ResetColor(); @@ -162,7 +161,6 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla if (!m_Log->LogReplaceLine(a_Format, a_ArgList)) { m_BeginLineUpdate = false; - puts(""); } ResetColor(); #endif -- cgit v1.2.3 From 5becfe850a2b4827a21e8ede989545334efbbead Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 1 Feb 2014 01:47:21 +0000 Subject: Fixed Linux compile --- src/Log.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Log.cpp b/src/Log.cpp index b246e8196..44dab33c9 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -135,6 +135,7 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str()); //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); #else +#ifdef _WIN32 size_t LineLength = Line.length(); if (m_LastStringSize == 0) @@ -150,7 +151,7 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) printf("\n%s", Line.c_str()); // We are at line to be replaced, but since we can't, add a new line return false; } -#ifdef _WIN32 + if (LineLength < m_LastStringSize) // If last printed line was longer than current, clear this line { for (size_t X = 0; X != m_LastStringSize + 1; ++X) -- cgit v1.2.3 From 6f660b379ecbc091b9bd92093e0dad01a4f6bf38 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 1 Feb 2014 01:54:26 +0000 Subject: Another Linux fix --- src/Log.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Log.cpp b/src/Log.cpp index 44dab33c9..aa9f22f84 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -7,6 +7,12 @@ #include #include "OSSupport/IsThread.h" +#ifdef __linux +#include +#include +#endif // __linux + + #if defined(ANDROID_NDK) #include #include "ToJava.h" -- cgit v1.2.3 From dbbd47b96d3b3dd5ca0680eda8191808f30e3927 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 1 Feb 2014 13:27:44 +0100 Subject: Removed "player destroying" hook --- src/Bindings/Plugin.h | 1 - src/Bindings/PluginLua.cpp | 20 -------------------- src/Bindings/PluginLua.h | 1 - src/Bindings/PluginManager.cpp | 21 --------------------- src/Bindings/PluginManager.h | 2 -- src/Entities/Player.cpp | 4 +--- 6 files changed, 1 insertion(+), 48 deletions(-) diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index f50d1f561..949e4693a 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -67,7 +67,6 @@ public: virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; - virtual bool OnPlayerDestroying (cPlayer & a_Player) = 0; virtual bool OnPlayerDestroyed (cPlayer & a_Player) = 0; virtual bool OnPlayerEating (cPlayer & a_Player) = 0; virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 2b34e92c9..7fc1db391 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -623,26 +623,6 @@ bool cPluginLua::OnPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX, int a_Blo -bool cPluginLua::OnPlayerDestroying(cPlayer & a_Player) -{ - cCSLock Lock(m_CriticalSection); - bool res = false; - cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_DESTROYING]; - for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) - { - m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res); - if (res) - { - return true; - } - } - return false; -} - - - - - bool cPluginLua::OnPlayerDestroyed(cPlayer & a_Player) { cCSLock Lock(m_CriticalSection); diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index f173be179..589de66fa 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -64,7 +64,6 @@ public: virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; - virtual bool OnPlayerDestroying (cPlayer & a_Player) override; virtual bool OnPlayerDestroyed (cPlayer & a_Player) override; virtual bool OnPlayerEating (cPlayer & a_Player) override; virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 1bab8cb0f..9e318554a 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -673,27 +673,6 @@ bool cPluginManager::CallHookPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX, -bool cPluginManager::CallHookPlayerDestroying(cPlayer & a_Player) -{ - HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_DESTROYING); - if (Plugins == m_Hooks.end()) - { - return false; - } - for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) - { - if ((*itr)->OnPlayerDestroying(a_Player)) - { - return true; - } - } - return false; -} - - - - - bool cPluginManager::CallHookPlayerDestroyed(cPlayer & a_Player) { HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_DESTROYED); diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 38d5a8ca3..a700ef6ce 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -79,7 +79,6 @@ public: // tolua_export HOOK_LOGIN, HOOK_PLAYER_BREAKING_BLOCK, HOOK_PLAYER_BROKEN_BLOCK, - HOOK_PLAYER_DESTROYING, HOOK_PLAYER_DESTROYED, HOOK_PLAYER_EATING, HOOK_PLAYER_FISHED, @@ -172,7 +171,6 @@ public: // tolua_export bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation); bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); - bool CallHookPlayerDestroying (cPlayer & a_Player); bool CallHookPlayerDestroyed (cPlayer & a_Player); bool CallHookPlayerEating (cPlayer & a_Player); bool CallHookPlayerFished (cPlayer & a_Player, const cItems a_Reward); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index abdd792e0..9a935520f 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -120,7 +120,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) cPlayer::~cPlayer(void) { - cRoot::Get()->GetPluginManager()->CallHookPlayerDestroying(*this); + cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this); LOGD("Deleting cPlayer \"%s\" at %p, ID %d", m_PlayerName.c_str(), this, GetUniqueID()); @@ -136,8 +136,6 @@ cPlayer::~cPlayer(void) delete m_InventoryWindow; LOGD("Player %p deleted", this); - - cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this); } -- cgit v1.2.3 From b34ba6be7b35c75bf5272e366ea42f513b0cf501 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 1 Feb 2014 13:58:35 +0100 Subject: Added PlayerDestroyedHook Documentation --- .../Plugins/APIDump/Hooks/OnPlayerDestroyed.lua | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua new file mode 100644 index 000000000..8e503658c --- /dev/null +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua @@ -0,0 +1,23 @@ +return +{ + HOOK_PLAYER_DESTROYED = + { + CalledWhen = "A player is about to get destroyed.", + DefaultFnName = "OnPlayerDestroyed", -- also used as pagename + Desc = [[ + This function is called when a {{cPlayer|player}} is about to get destroyed. But the player isn't already destroyed. + ]], + Params = + { + { Name = "Player", Type = "{{cPlayer}}", Notes = "The destroyed player" }, + }, + Returns = [[ + It's only for notification. Can't be returned. + ]], + }, -- HOOK_PLAYER_DESTROYED +} + + + + + -- cgit v1.2.3 From c6304b2b4faf31c2e4a91a07bcac298467898dba Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Feb 2014 05:06:32 -0800 Subject: Changed pointers to references --- src/Blocks/BlockBed.cpp | 32 ++++++++++++------------- src/Blocks/BlockBed.h | 6 ++--- src/Blocks/BlockButton.h | 14 +++++------ src/Blocks/BlockCactus.h | 2 +- src/Blocks/BlockCarpet.h | 4 ++-- src/Blocks/BlockChest.h | 18 +++++++------- src/Blocks/BlockComparator.h | 10 ++++---- src/Blocks/BlockCrops.h | 2 +- src/Blocks/BlockDeadBush.h | 2 +- src/Blocks/BlockDoor.cpp | 28 +++++++++++----------- src/Blocks/BlockDoor.h | 32 ++++++++++++------------- src/Blocks/BlockDropSpenser.h | 2 +- src/Blocks/BlockEnderchest.h | 2 +- src/Blocks/BlockEntity.h | 4 ++-- src/Blocks/BlockFenceGate.h | 10 ++++---- src/Blocks/BlockFire.h | 30 +++++++++++------------ src/Blocks/BlockFlower.h | 2 +- src/Blocks/BlockFluid.h | 2 +- src/Blocks/BlockFurnace.h | 2 +- src/Blocks/BlockHandler.cpp | 20 ++++++++-------- src/Blocks/BlockHandler.h | 18 +++++++------- src/Blocks/BlockHopper.h | 2 +- src/Blocks/BlockIce.h | 4 ++-- src/Blocks/BlockLadder.h | 10 ++++---- src/Blocks/BlockLeaves.h | 12 +++++----- src/Blocks/BlockLever.h | 12 +++++----- src/Blocks/BlockMushroom.h | 2 +- src/Blocks/BlockNetherWart.h | 2 +- src/Blocks/BlockPiston.cpp | 10 ++++---- src/Blocks/BlockPiston.h | 4 ++-- src/Blocks/BlockPlanks.h | 2 +- src/Blocks/BlockPortal.h | 4 ++-- src/Blocks/BlockPumpkin.h | 48 ++++++++++++++++++------------------- src/Blocks/BlockRail.h | 36 ++++++++++++++-------------- src/Blocks/BlockRedstone.h | 2 +- src/Blocks/BlockRedstoneRepeater.h | 8 +++---- src/Blocks/BlockSapling.h | 2 +- src/Blocks/BlockSign.h | 2 +- src/Blocks/BlockSlab.h | 4 ++-- src/Blocks/BlockSnow.h | 6 ++--- src/Blocks/BlockStairs.h | 2 +- src/Blocks/BlockStems.h | 2 +- src/Blocks/BlockSugarcane.h | 2 +- src/Blocks/BlockTallGrass.h | 2 +- src/Blocks/BlockTorch.h | 10 ++++---- src/Blocks/BlockTrapdoor.h | 10 ++++---- src/Blocks/BlockVine.h | 6 ++--- src/Blocks/BlockWood.h | 2 +- src/Blocks/BlockWorkbench.h | 2 +- src/Blocks/ChunkInterface.h | 6 ++--- src/Blocks/WorldInterface.h | 2 +- src/Chunk.cpp | 2 +- src/ChunkMap.cpp | 6 ++--- src/ChunkMap.h | 2 +- src/ClientHandle.cpp | 7 +++--- src/Items/ItemDoor.h | 2 +- src/Items/ItemHandler.cpp | 2 +- src/Simulator/RedstoneSimulator.cpp | 4 ++-- src/World.cpp | 7 +++--- src/World.h | 4 ++-- 60 files changed, 247 insertions(+), 249 deletions(-) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 425e286ec..65d397b36 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -6,7 +6,7 @@ void cBlockBedHandler::OnPlacedByPlayer( - cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -15,7 +15,7 @@ void cBlockBedHandler::OnPlacedByPlayer( if (a_BlockMeta < 8) { Vector3i Direction = MetaDataToDirection(a_BlockMeta); - a_ChunkInterface->SetBlock(a_WorldInterface,a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); + a_ChunkInterface.SetBlock(a_WorldInterface,a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); } } @@ -23,26 +23,26 @@ void cBlockBedHandler::OnPlacedByPlayer( -void cBlockBedHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE OldMeta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); Vector3i ThisPos( a_BlockX, a_BlockY, a_BlockZ ); Vector3i Direction = MetaDataToDirection( OldMeta & 0x7 ); if (OldMeta & 0x8) { // Was pillow - if (a_ChunkInterface->GetBlock(ThisPos - Direction) == E_BLOCK_BED) + if (a_ChunkInterface.GetBlock(ThisPos - Direction) == E_BLOCK_BED) { - a_ChunkInterface->FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0); } } else { // Was foot end - if (a_ChunkInterface->GetBlock(ThisPos + Direction) == E_BLOCK_BED) + if (a_ChunkInterface.GetBlock(ThisPos + Direction) == E_BLOCK_BED) { - a_ChunkInterface->FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0); } } } @@ -51,30 +51,30 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInt -void cBlockBedHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { - if (a_WorldInterface->GetDimension() != dimOverworld) + if (a_WorldInterface.GetDimension() != dimOverworld) { Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ); - a_WorldInterface->DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); + a_WorldInterface.DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); } else { - if (a_WorldInterface->GetTimeOfDay() > 13000) + if (a_WorldInterface.GetTimeOfDay() > 13000) { - NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); if (Meta & 0x8) { // Is pillow - a_WorldInterface->GetBroadcastManager()->BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); } else { // Is foot end Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); - if (a_ChunkInterface->GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping { - a_WorldInterface->GetBroadcastManager()->BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); } } } else { diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 0948a9198..0b86fe5e7 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -20,9 +20,9 @@ public: } - virtual void OnPlacedByPlayer(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; - virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; - virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; + virtual void OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; + virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; virtual bool IsUseable(void) override diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 7b25ec7aa..62fae6abc 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -16,16 +16,16 @@ public: } - virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Set p the ON bit to on - NIBBLETYPE Meta = (a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); + NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); - a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); - a_WorldInterface->GetBroadcastManager()->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); + a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); // Queue a button reset (unpress) - a_ChunkInterface->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 30, m_BlockType, a_WorldInterface); + a_ChunkInterface.QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 30, m_BlockType, a_WorldInterface); } @@ -43,7 +43,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -93,7 +93,7 @@ public: } } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { NIBBLETYPE Meta; a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta); diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h index b44c1bc2d..70c9c5257 100644 --- a/src/Blocks/BlockCactus.h +++ b/src/Blocks/BlockCactus.h @@ -24,7 +24,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if (a_RelY <= 0) { diff --git a/src/Blocks/BlockCarpet.h b/src/Blocks/BlockCarpet.h index aa92b0a08..757d62c33 100644 --- a/src/Blocks/BlockCarpet.h +++ b/src/Blocks/BlockCarpet.h @@ -31,7 +31,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -49,7 +49,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return (a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR); } diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index b22c5f450..bebf4b5f5 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -20,7 +20,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -37,7 +37,7 @@ public: // Check if this forms a doublechest, if so, need to adjust the meta: cBlockArea Area; - if (!Area.Read(a_ChunkInterface, a_BlockX - 1, a_BlockX + 1, a_BlockY, a_BlockY, a_BlockZ - 1, a_BlockZ + 1)) + if (!Area.Read(&a_ChunkInterface, a_BlockX - 1, a_BlockX + 1, a_BlockY, a_BlockY, a_BlockZ - 1, a_BlockZ + 1)) { return false; } @@ -66,7 +66,7 @@ public: virtual void OnPlacedByPlayer( - cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -74,7 +74,7 @@ public: { // Check if this forms a doublechest, if so, need to adjust the meta: cBlockArea Area; - if (!Area.Read(a_ChunkInterface, a_BlockX - 1, a_BlockX + 1, a_BlockY, a_BlockY, a_BlockZ - 1, a_BlockZ + 1)) + if (!Area.Read(&a_ChunkInterface, a_BlockX - 1, a_BlockX + 1, a_BlockY, a_BlockY, a_BlockZ - 1, a_BlockZ + 1)) { return; } @@ -110,16 +110,16 @@ public: return "step.wood"; } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, const cChunk & a_Chunk) override { return CanBeAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { cBlockArea Area; - if (!Area.Read(a_ChunkInterface, a_BlockX - 2, a_BlockX + 2, a_BlockY, a_BlockY, a_BlockZ - 2, a_BlockZ + 2)) + if (!Area.Read(&a_ChunkInterface, a_BlockX - 2, a_BlockX + 2, a_BlockY, a_BlockY, a_BlockZ - 2, a_BlockZ + 2)) { // Cannot read the surroundings, probably at the edge of loaded chunks. Disallow. return false; @@ -211,13 +211,13 @@ public: /// If there's a chest in the a_Area in the specified coords, modifies its meta to a_NewMeta and returns true. - bool CheckAndAdjustNeighbor(cChunkInterface * a_ChunkInterface, const cBlockArea & a_Area, int a_RelX, int a_RelZ, NIBBLETYPE a_NewMeta) + bool CheckAndAdjustNeighbor(cChunkInterface & a_ChunkInterface, const cBlockArea & a_Area, int a_RelX, int a_RelZ, NIBBLETYPE a_NewMeta) { if (a_Area.GetRelBlockType(a_RelX, 0, a_RelZ) != E_BLOCK_CHEST) { return false; } - a_ChunkInterface->SetBlockMeta(a_Area.GetOriginX() + a_RelX, a_Area.GetOriginY(), a_Area.GetOriginZ() + a_RelZ, a_NewMeta); + a_ChunkInterface.SetBlockMeta(a_Area.GetOriginX() + a_RelX, a_Area.GetOriginY(), a_Area.GetOriginZ() + a_RelZ, a_NewMeta); return true; } } ; diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index fe0882072..3b32efd6b 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -18,11 +18,11 @@ public: } - virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); Meta ^= 0x04; // Toggle 3rd (addition/subtraction) bit with XOR - a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); } @@ -39,14 +39,14 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); } virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index f0e05c2c3..c86183ca4 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -96,7 +96,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_FARMLAND)); } diff --git a/src/Blocks/BlockDeadBush.h b/src/Blocks/BlockDeadBush.h index 3bd89b5ce..5b687c710 100644 --- a/src/Blocks/BlockDeadBush.h +++ b/src/Blocks/BlockDeadBush.h @@ -23,7 +23,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return (a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_SAND); } diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index 971784d0c..9d891f2b2 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -17,24 +17,24 @@ cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockType) -void cBlockDoorHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockDoorHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE OldMeta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); if (OldMeta & 8) { // Was upper part of door - if (IsDoor(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ))) + if (IsDoor(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ))) { - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); } } else { // Was lower part - if (IsDoor(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))) + if (IsDoor(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))) { - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, E_BLOCK_AIR, 0); } } } @@ -43,9 +43,9 @@ void cBlockDoorHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldIn -void cBlockDoorHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockDoorHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { - if (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_DOOR) + if (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_DOOR) { ChangeDoor(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); } @@ -56,7 +56,7 @@ void cBlockDoorHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterfac void cBlockDoorHandler::OnPlacedByPlayer( - cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -64,15 +64,15 @@ void cBlockDoorHandler::OnPlacedByPlayer( { NIBBLETYPE a_TopBlockMeta = 8; if ( - ((a_BlockMeta == 0) && (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1) == m_BlockType)) || - ((a_BlockMeta == 1) && (a_ChunkInterface->GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == m_BlockType)) || - ((a_BlockMeta == 2) && (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1) == m_BlockType)) || - ((a_BlockMeta == 3) && (a_ChunkInterface->GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == m_BlockType)) + ((a_BlockMeta == 0) && (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1) == m_BlockType)) || + ((a_BlockMeta == 1) && (a_ChunkInterface.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == m_BlockType)) || + ((a_BlockMeta == 2) && (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1) == m_BlockType)) || + ((a_BlockMeta == 3) && (a_ChunkInterface.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == m_BlockType)) ) { a_TopBlockMeta = 9; } - a_ChunkInterface->SetBlock(a_WorldInterface, a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, a_TopBlockMeta); + a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, a_TopBlockMeta); } diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 3a72f7a39..31d1bb797 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -14,13 +14,13 @@ class cBlockDoorHandler : public: cBlockDoorHandler(BLOCKTYPE a_BlockType); - virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; - virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; + virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; virtual const char * GetStepSound(void) override; virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -33,8 +33,8 @@ public: } if ( - !CanReplaceBlock(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ)) || - !CanReplaceBlock(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)) + !CanReplaceBlock(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ)) || + !CanReplaceBlock(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)) ) { return false; @@ -53,7 +53,7 @@ public: virtual void OnPlacedByPlayer( - cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -66,7 +66,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); } @@ -136,32 +136,32 @@ public: /// Changes the door at the specified coords from open to close or vice versa - static void ChangeDoor(cChunkInterface * a_ChunkInterface, int a_X, int a_Y, int a_Z) + static void ChangeDoor(cChunkInterface & a_ChunkInterface, int a_X, int a_Y, int a_Z) { - NIBBLETYPE OldMetaData = a_ChunkInterface->GetBlockMeta(a_X, a_Y, a_Z); + NIBBLETYPE OldMetaData = a_ChunkInterface.GetBlockMeta(a_X, a_Y, a_Z); - a_ChunkInterface->SetBlockMeta(a_X, a_Y, a_Z, ChangeStateMetaData(OldMetaData)); + a_ChunkInterface.SetBlockMeta(a_X, a_Y, a_Z, ChangeStateMetaData(OldMetaData)); if (OldMetaData & 8) { // Current block is top of the door - BLOCKTYPE BottomBlock = a_ChunkInterface->GetBlock(a_X, a_Y - 1, a_Z); - NIBBLETYPE BottomMeta = a_ChunkInterface->GetBlockMeta(a_X, a_Y - 1, a_Z); + BLOCKTYPE BottomBlock = a_ChunkInterface.GetBlock(a_X, a_Y - 1, a_Z); + NIBBLETYPE BottomMeta = a_ChunkInterface.GetBlockMeta(a_X, a_Y - 1, a_Z); if (IsDoor(BottomBlock) && !(BottomMeta & 8)) { - a_ChunkInterface->SetBlockMeta(a_X, a_Y - 1, a_Z, ChangeStateMetaData(BottomMeta)); + a_ChunkInterface.SetBlockMeta(a_X, a_Y - 1, a_Z, ChangeStateMetaData(BottomMeta)); } } else { // Current block is bottom of the door - BLOCKTYPE TopBlock = a_ChunkInterface->GetBlock(a_X, a_Y + 1, a_Z); - NIBBLETYPE TopMeta = a_ChunkInterface->GetBlockMeta(a_X, a_Y + 1, a_Z); + BLOCKTYPE TopBlock = a_ChunkInterface.GetBlock(a_X, a_Y + 1, a_Z); + NIBBLETYPE TopMeta = a_ChunkInterface.GetBlockMeta(a_X, a_Y + 1, a_Z); if (IsDoor(TopBlock) && (TopMeta & 8)) { - a_ChunkInterface->SetBlockMeta(a_X, a_Y + 1, a_Z, ChangeStateMetaData(TopMeta)); + a_ChunkInterface.SetBlockMeta(a_X, a_Y + 1, a_Z, ChangeStateMetaData(TopMeta)); } } } diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index b9071ce12..0c285612e 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -22,7 +22,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index 9e76d8b95..7ea09cd4c 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -23,7 +23,7 @@ public: } virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockEntity.h b/src/Blocks/BlockEntity.h index 513659194..f05bf16b1 100644 --- a/src/Blocks/BlockEntity.h +++ b/src/Blocks/BlockEntity.h @@ -15,9 +15,9 @@ public: { } - virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - a_ChunkInterface->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_ChunkInterface.UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); } virtual bool IsUseable() override diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index 0f0a75b70..2d0cfb8fd 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -30,20 +30,20 @@ public: } - virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - NIBBLETYPE OldMetaData = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMetaData = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); NIBBLETYPE NewMetaData = PlayerYawToMetaData(a_Player->GetYaw()); OldMetaData ^= 4; // Toggle the gate if ((OldMetaData & 1) == (NewMetaData & 1)) { // Standing in front of the gate - apply new direction - a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (OldMetaData & 4) | (NewMetaData & 3)); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (OldMetaData & 4) | (NewMetaData & 3)); } else { // Standing aside - use last direction - a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, OldMetaData); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, OldMetaData); } } diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h index 21e37d04e..a85808c89 100644 --- a/src/Blocks/BlockFire.h +++ b/src/Blocks/BlockFire.h @@ -19,7 +19,7 @@ public: /// Portal boundary and direction variables int XZP, XZM, Dir; // For wont of a better name... - virtual void OnPlaced(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override + virtual void OnPlaced(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override { /* PORTAL FINDING ALGORITH @@ -60,9 +60,9 @@ public: /// Traces along YP until it finds an obsidian block, returns Y difference or 0 if no portal, and -1 for border /// Takes the X, Y, and Z of the base block; with an optional MaxY for portal border finding - int FindObsidianCeiling(int X, int Y, int Z, cChunkInterface * a_ChunkInterface, int MaxY = 0) + int FindObsidianCeiling(int X, int Y, int Z, cChunkInterface & a_ChunkInterface, int MaxY = 0) { - if (a_ChunkInterface->GetBlock(X, Y, Z) != E_BLOCK_OBSIDIAN) + if (a_ChunkInterface.GetBlock(X, Y, Z) != E_BLOCK_OBSIDIAN) { return 0; } @@ -70,7 +70,7 @@ public: for (int newY = Y + 1; newY < cChunkDef::Height; newY++) { - BLOCKTYPE Block = a_ChunkInterface->GetBlock(X, newY, Z); + BLOCKTYPE Block = a_ChunkInterface.GetBlock(X, newY, Z); if ((Block == E_BLOCK_AIR) || (Block == E_BLOCK_FIRE)) { continue; @@ -97,11 +97,11 @@ public: } /// Evaluates if coords have a valid border on top, based on MaxY - int EvaluatePortalBorder(int X, int FoundObsidianY, int Z, int MaxY, cChunkInterface * a_ChunkInterface) + int EvaluatePortalBorder(int X, int FoundObsidianY, int Z, int MaxY, cChunkInterface & a_ChunkInterface) { for (int checkBorder = FoundObsidianY + 1; checkBorder <= MaxY - 1; checkBorder++) // FoundObsidianY + 1: FoundObsidianY has already been checked in FindObsidianCeiling; MaxY - 1: portal doesn't need corners { - if (a_ChunkInterface->GetBlock(X, checkBorder, Z) != E_BLOCK_OBSIDIAN) + if (a_ChunkInterface.GetBlock(X, checkBorder, Z) != E_BLOCK_OBSIDIAN) { // Base obsidian, base + 1 obsidian, base + x NOT obsidian -> not complete portal return 0; @@ -112,7 +112,7 @@ public: } /// Finds entire frame in any direction with the coordinates of a base block and fills hole with nether portal (START HERE) - void FindAndSetPortalFrame(int X, int Y, int Z, cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface) + void FindAndSetPortalFrame(int X, int Y, int Z, cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface) { int MaxY = FindObsidianCeiling(X, Y, Z, a_ChunkInterface); // Get topmost obsidian block as reference for all other checks int X1 = X + 1, Z1 = Z + 1, X2 = X - 1, Z2 = Z - 1; // Duplicate XZ values, add/subtract one as we've checked the original already the line above @@ -136,11 +136,11 @@ public: { if (Dir == 1) { - a_ChunkInterface->SetBlock(a_WorldInterface, Width, Height, Z, E_BLOCK_NETHER_PORTAL, Dir); + a_ChunkInterface.SetBlock(a_WorldInterface, Width, Height, Z, E_BLOCK_NETHER_PORTAL, Dir); } else { - a_ChunkInterface->SetBlock(a_WorldInterface, X, Height, Width, E_BLOCK_NETHER_PORTAL, Dir); + a_ChunkInterface.SetBlock(a_WorldInterface, X, Height, Width, E_BLOCK_NETHER_PORTAL, Dir); } } } @@ -150,11 +150,11 @@ public: /// Evaluates if coordinates are a portal going XP/XM; returns true if so, and writes boundaries to variable /// Takes coordinates of base block and Y coord of target obsidian ceiling - bool FindPortalSliceX(int X1, int X2, int Y, int Z, int MaxY, cChunkInterface * a_ChunkInterface) + bool FindPortalSliceX(int X1, int X2, int Y, int Z, int MaxY, cChunkInterface & a_ChunkInterface) { Dir = 1; // Set assumed direction (will change if portal turns out to be facing the other direction) bool FoundFrameXP = false, FoundFrameXM = false; - for (; ((a_ChunkInterface->GetBlock(X1, Y, Z) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface->GetBlock(X1, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X1++) // Check XP for obsidian blocks, exempting corners + for (; ((a_ChunkInterface.GetBlock(X1, Y, Z) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X1, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X1++) // Check XP for obsidian blocks, exempting corners { int Value = FindObsidianCeiling(X1, Y, Z, a_ChunkInterface, MaxY); int ValueTwo = FindObsidianCeiling(X1, Y + 1, Z, a_ChunkInterface, MaxY); // For corners without obsidian @@ -168,7 +168,7 @@ public: return false; // Not valid slice, no portal can be formed } } XZP = X1 - 1; // Set boundary of frame interior, note that for some reason, the loop of X and the loop of Z go to different numbers, hence -1 here and -2 there - for (; ((a_ChunkInterface->GetBlock(X2, Y, Z) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface->GetBlock(X2, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X2--) // Go the other direction (XM) + for (; ((a_ChunkInterface.GetBlock(X2, Y, Z) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X2, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X2--) // Go the other direction (XM) { int Value = FindObsidianCeiling(X2, Y, Z, a_ChunkInterface, MaxY); int ValueTwo = FindObsidianCeiling(X2, Y + 1, Z, a_ChunkInterface, MaxY); @@ -186,11 +186,11 @@ public: } /// Evaluates if coords are a portal going ZP/ZM; returns true if so, and writes boundaries to variable - bool FindPortalSliceZ(int X, int Y, int Z1, int Z2, int MaxY, cChunkInterface * a_ChunkInterface) + bool FindPortalSliceZ(int X, int Y, int Z1, int Z2, int MaxY, cChunkInterface & a_ChunkInterface) { Dir = 2; bool FoundFrameZP = false, FoundFrameZM = false; - for (; ((a_ChunkInterface->GetBlock(X, Y, Z1) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface->GetBlock(X, Y + 1, Z1) == E_BLOCK_OBSIDIAN)); Z1++) + for (; ((a_ChunkInterface.GetBlock(X, Y, Z1) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X, Y + 1, Z1) == E_BLOCK_OBSIDIAN)); Z1++) { int Value = FindObsidianCeiling(X, Y, Z1, a_ChunkInterface, MaxY); int ValueTwo = FindObsidianCeiling(X, Y + 1, Z1, a_ChunkInterface, MaxY); @@ -204,7 +204,7 @@ public: return false; } } XZP = Z1 - 2; - for (; ((a_ChunkInterface->GetBlock(X, Y, Z2) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface->GetBlock(X, Y + 1, Z2) == E_BLOCK_OBSIDIAN)); Z2--) + for (; ((a_ChunkInterface.GetBlock(X, Y, Z2) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X, Y + 1, Z2) == E_BLOCK_OBSIDIAN)); Z2--) { int Value = FindObsidianCeiling(X, Y, Z2, a_ChunkInterface, MaxY); int ValueTwo = FindObsidianCeiling(X, Y + 1, Z2, a_ChunkInterface, MaxY); diff --git a/src/Blocks/BlockFlower.h b/src/Blocks/BlockFlower.h index f296f7be3..e8fd4c7f6 100644 --- a/src/Blocks/BlockFlower.h +++ b/src/Blocks/BlockFlower.h @@ -24,7 +24,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return (a_RelY > 0) && IsBlockTypeOfDirt(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)); } diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index d57192d78..fbdbec26c 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -32,7 +32,7 @@ public: } - virtual void Check(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override + virtual void Check(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override { switch (m_BlockType) { diff --git a/src/Blocks/BlockFurnace.h b/src/Blocks/BlockFurnace.h index 42b3ee4be..bbc50de9f 100644 --- a/src/Blocks/BlockFurnace.h +++ b/src/Blocks/BlockFurnace.h @@ -26,7 +26,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 0eedf7f4f..374c64fd8 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -244,7 +244,7 @@ cBlockHandler::cBlockHandler(BLOCKTYPE a_BlockType) bool cBlockHandler::GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -268,7 +268,7 @@ void cBlockHandler::OnUpdate(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a -void cBlockHandler::OnPlacedByPlayer(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +void cBlockHandler::OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { } @@ -284,7 +284,7 @@ void cBlockHandler::OnDestroyedByPlayer(cWorld *a_World, cPlayer * a_Player, int -void cBlockHandler::OnPlaced(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +void cBlockHandler::OnPlaced(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { // Notify the neighbors NeighborChanged(a_ChunkInterface, a_BlockX - 1, a_BlockY, a_BlockZ); @@ -299,7 +299,7 @@ void cBlockHandler::OnPlaced(cChunkInterface * a_ChunkInterface, cWorldInterface -void cBlockHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { // Notify the neighbors NeighborChanged(a_ChunkInterface, a_BlockX - 1, a_BlockY, a_BlockZ); @@ -314,11 +314,11 @@ void cBlockHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterf -void cBlockHandler::NeighborChanged(cChunkInterface *a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { if ((a_BlockY >= 0) && (a_BlockY < cChunkDef::Height)) { - GetBlockHandler(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + GetBlockHandler(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); } } @@ -326,7 +326,7 @@ void cBlockHandler::NeighborChanged(cChunkInterface *a_ChunkInterface, int a_Blo -void cBlockHandler::OnNeighborChanged(cChunkInterface *a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockHandler::OnNeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { } @@ -342,7 +342,7 @@ void cBlockHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, -void cBlockHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { } @@ -400,7 +400,7 @@ const char * cBlockHandler::GetStepSound() -bool cBlockHandler::CanBeAt(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, const cChunk & a_Chunk) +bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, const cChunk & a_Chunk) { return true; } @@ -445,7 +445,7 @@ bool cBlockHandler::DoesDropOnUnsuitable(void) -void cBlockHandler::Check(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) +void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) { if (!CanBeAt(a_ChunkInterface, a_RelX, a_RelY, a_RelZ, a_Chunk)) { diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 8a0206c25..73a658b3f 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -33,18 +33,18 @@ public: Called by cItemHandler::GetPlacementBlockTypeMeta() if the item is a block */ virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ); /// Called by cWorld::SetBlock() after the block has been set - virtual void OnPlaced(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + virtual void OnPlaced(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); /// Called by cClientHandle::HandlePlaceBlock() after the player has placed a new block. Called after OnPlaced(). virtual void OnPlacedByPlayer( - cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -54,19 +54,19 @@ public: virtual void OnDestroyedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called before a block gets destroyed / replaced with air - virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ); + virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called when a direct neighbor of this block has been changed (The position is the own position, not the neighbor position) - virtual void OnNeighborChanged(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ); + virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ); /// Notifies all neighbors of the given block about a change - static void NeighborChanged(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ); + static void NeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called while the player diggs the block. virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called if the user right clicks the block and the block is useable - virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); /// Called when the item is mined to convert it into pickups. Pickups may specify multiple items. Appends items to a_Pickups, preserves its original contents virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta); @@ -78,7 +78,7 @@ public: virtual const char * GetStepSound(void); /// Checks if the block can stay at the specified relative coords in the chunk - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk); + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk); /** Checks if the block can be placed at this point. Default: CanBeAt(...) @@ -113,7 +113,7 @@ public: By default drops if position no more suitable (CanBeAt(), DoesDropOnUnsuitable(), Drop()), and wakes up all simulators on the block. */ - virtual void Check(cChunkInterface * ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk); + virtual void Check(cChunkInterface & ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk); /// Rotates a given block meta counter-clockwise. Default: no change /// Block meta following rotation diff --git a/src/Blocks/BlockHopper.h b/src/Blocks/BlockHopper.h index 2694acc99..aa0317660 100644 --- a/src/Blocks/BlockHopper.h +++ b/src/Blocks/BlockHopper.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockIce.h b/src/Blocks/BlockIce.h index 42521941d..8dfe7ddac 100644 --- a/src/Blocks/BlockIce.h +++ b/src/Blocks/BlockIce.h @@ -24,10 +24,10 @@ public: } - virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override + virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { // TODO: Ice destroyed with air below it should turn into air instead of water - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_WATER, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_WATER, 0); // This is called later than the real destroying of this ice block } } ; diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h index fa1f80a6e..5c2b542c0 100644 --- a/src/Blocks/BlockLadder.h +++ b/src/Blocks/BlockLadder.h @@ -19,7 +19,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -68,7 +68,7 @@ public: /// Finds a suitable Direction for the Ladder. Returns BLOCK_FACE_BOTTOM on failure - static char FindSuitableBlockFace(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + static char FindSuitableBlockFace(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { for (int Face = 2; Face <= 5; Face++) { @@ -81,7 +81,7 @@ public: } - static bool LadderCanBePlacedAt(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) + static bool LadderCanBePlacedAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) { if ((a_BlockFace == BLOCK_FACE_BOTTOM) || (a_BlockFace == BLOCK_FACE_TOP)) { @@ -90,11 +90,11 @@ public: AddFaceDirection( a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); - return g_BlockIsSolid[a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ)]; + return g_BlockIsSolid[a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ)]; } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface,int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface,int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { // TODO: Use AdjustCoordsByMeta(), then cChunk::UnboundedRelGetBlock() and finally some comparison char BlockFace = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 58ef0a0a4..069849361 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -53,27 +53,27 @@ public: } - void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override + void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { cBlockHandler::OnDestroyed(a_ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); //0.5% chance of dropping an apple - NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); //check if Oak (0x1 and 0x2 bit not set) MTRand rand; if(!(Meta & 3) && rand.randInt(200) == 100) { cItems Drops; Drops.push_back(cItem(E_ITEM_RED_APPLE, 1, 0)); - a_WorldInterface->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ); + a_WorldInterface.SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ); } } - virtual void OnNeighborChanged(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override + virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { - NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0x7); // Unset 0x8 bit so it gets checked for decay + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0x7); // Unset 0x8 bit so it gets checked for decay } diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index b77078a08..09b600759 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -15,13 +15,13 @@ public: { } - virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Flip the ON bit on/off using the XOR bitwise operation - NIBBLETYPE Meta = (a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08); + NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08); - a_ChunkInterface->SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LEVER, Meta); // SetMeta doesn't work for unpowering levers, so setblock - a_WorldInterface->GetBroadcastManager()->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); + a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LEVER, Meta); // SetMeta doesn't work for unpowering levers, so setblock + a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); } @@ -39,7 +39,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -94,7 +94,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { NIBBLETYPE Meta; a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta); diff --git a/src/Blocks/BlockMushroom.h b/src/Blocks/BlockMushroom.h index 49fd216a3..623cfda64 100644 --- a/src/Blocks/BlockMushroom.h +++ b/src/Blocks/BlockMushroom.h @@ -24,7 +24,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if (a_RelY <= 0) { diff --git a/src/Blocks/BlockNetherWart.h b/src/Blocks/BlockNetherWart.h index d30cce37a..937d2b4b5 100644 --- a/src/Blocks/BlockNetherWart.h +++ b/src/Blocks/BlockNetherWart.h @@ -45,7 +45,7 @@ public: } } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_SOULSAND)); } diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp index 0b7dd5863..43afda45a 100644 --- a/src/Blocks/BlockPiston.cpp +++ b/src/Blocks/BlockPiston.cpp @@ -33,18 +33,18 @@ cBlockPistonHandler::cBlockPistonHandler(BLOCKTYPE a_BlockType) -void cBlockPistonHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockPistonHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE OldMeta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); int newX = a_BlockX; int newY = a_BlockY; int newZ = a_BlockZ; AddPistonDir(newX, newY, newZ, OldMeta & ~(8), 1); - if (a_ChunkInterface->GetBlock(newX, newY, newZ) == E_BLOCK_PISTON_EXTENSION) + if (a_ChunkInterface.GetBlock(newX, newY, newZ) == E_BLOCK_PISTON_EXTENSION) { - a_ChunkInterface->SetBlock(a_WorldInterface, newX, newY, newZ, E_BLOCK_AIR, 0); + a_ChunkInterface.SetBlock(a_WorldInterface, newX, newY, newZ, E_BLOCK_AIR, 0); } } @@ -53,7 +53,7 @@ void cBlockPistonHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorld bool cBlockPistonHandler::GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index 627b58244..e0ab182db 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -13,10 +13,10 @@ class cBlockPistonHandler : public: cBlockPistonHandler(BLOCKTYPE a_BlockType); - virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockPlanks.h b/src/Blocks/BlockPlanks.h index 9fd51e8e6..483761b5f 100644 --- a/src/Blocks/BlockPlanks.h +++ b/src/Blocks/BlockPlanks.h @@ -17,7 +17,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockPortal.h b/src/Blocks/BlockPortal.h index 2c63f96b2..dc916990e 100644 --- a/src/Blocks/BlockPortal.h +++ b/src/Blocks/BlockPortal.h @@ -17,7 +17,7 @@ public: } virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -39,7 +39,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if ((a_RelY - 1 < 0) || (a_RelY + 1 > cChunkDef::Height)) { diff --git a/src/Blocks/BlockPumpkin.h b/src/Blocks/BlockPumpkin.h index 0f6e365f4..4a33d1d16 100644 --- a/src/Blocks/BlockPumpkin.h +++ b/src/Blocks/BlockPumpkin.h @@ -14,7 +14,7 @@ public: { } - virtual void OnPlacedByPlayer(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override + virtual void OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override { // Check whether the pumpkin is a part of a golem or a snowman @@ -24,16 +24,16 @@ public: return; } - BLOCKTYPE BlockY1 = a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); - BLOCKTYPE BlockY2 = a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 2, a_BlockZ); + BLOCKTYPE BlockY1 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); + BLOCKTYPE BlockY2 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 2, a_BlockZ); // Check for a snow golem: if ((BlockY1 == E_BLOCK_SNOW_BLOCK) && (BlockY2 == E_BLOCK_SNOW_BLOCK)) { - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); - a_WorldInterface->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtSnowGolem); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); + a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtSnowGolem); return; } @@ -46,40 +46,40 @@ public: // Now check both orientations for hands: if ( - (a_ChunkInterface->GetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ) == E_BLOCK_IRON_BLOCK) && - (a_ChunkInterface->GetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ) == E_BLOCK_IRON_BLOCK) + (a_ChunkInterface.GetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ) == E_BLOCK_IRON_BLOCK) && + (a_ChunkInterface.GetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ) == E_BLOCK_IRON_BLOCK) ) { // Remove the iron blocks: - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); - a_ChunkInterface->FastSetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); - a_ChunkInterface->FastSetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); // Spawn the golem: - a_WorldInterface->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtIronGolem); + a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtIronGolem); } else if ( - (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1) == E_BLOCK_IRON_BLOCK) && - (a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1) == E_BLOCK_IRON_BLOCK) + (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1) == E_BLOCK_IRON_BLOCK) && + (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1) == E_BLOCK_IRON_BLOCK) ) { // Remove the iron blocks: - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1, E_BLOCK_AIR, 0); - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1, E_BLOCK_AIR, 0); - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); // Spawn the golem: - a_WorldInterface->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtIronGolem); + a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtIronGolem); } } virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 203ee297c..65c6889de 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -30,7 +30,7 @@ public: } virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -42,7 +42,7 @@ public: } - virtual void OnPlaced(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override + virtual void OnPlaced(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override { super::OnPlaced(a_ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); @@ -59,7 +59,7 @@ public: } - virtual void OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override + virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { super::OnDestroyed(a_ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); @@ -76,12 +76,12 @@ public: } - virtual void OnNeighborChanged(cChunkInterface *a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override + virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override { - NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); if (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ) && (Meta != FindMeta(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ))) { - a_ChunkInterface->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, FindMeta(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ)); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, FindMeta(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ)); } } @@ -92,7 +92,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if (a_RelY <= 0) { @@ -136,7 +136,7 @@ public: return true; } - NIBBLETYPE FindMeta(cChunkInterface *a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + NIBBLETYPE FindMeta(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { NIBBLETYPE Meta = 0; char RailsCnt = 0; @@ -211,13 +211,13 @@ public: } - bool IsUnstable(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + bool IsUnstable(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - if (!IsBlockRail(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ))) + if (!IsBlockRail(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))) { return false; } - NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); switch (Meta) { case E_META_RAIL_ZM_ZP: @@ -344,31 +344,31 @@ public: } - bool IsNotConnected(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Pure = 0) + bool IsNotConnected(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Pure = 0) { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, false); NIBBLETYPE Meta; - if (!IsBlockRail(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ))) + if (!IsBlockRail(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))) { - if (!IsBlockRail(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)) || (a_Pure != E_PURE_UPDOWN)) + if (!IsBlockRail(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)) || (a_Pure != E_PURE_UPDOWN)) { - if (!IsBlockRail(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ)) || (a_Pure == E_PURE_NONE)) + if (!IsBlockRail(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ)) || (a_Pure == E_PURE_NONE)) { return true; } else { - Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ); + Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ); } } else { - Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY + 1, a_BlockZ); + Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY + 1, a_BlockZ); } } else { - Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); } switch (a_BlockFace) diff --git a/src/Blocks/BlockRedstone.h b/src/Blocks/BlockRedstone.h index 45e668529..10de96197 100644 --- a/src/Blocks/BlockRedstone.h +++ b/src/Blocks/BlockRedstone.h @@ -18,7 +18,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && g_BlockFullyOccupiesVoxel[a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)]); } diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h index c995a6787..1e82108c4 100644 --- a/src/Blocks/BlockRedstoneRepeater.h +++ b/src/Blocks/BlockRedstoneRepeater.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -30,9 +30,9 @@ public: } - virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, ((a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f)); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, ((a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f)); } @@ -49,7 +49,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); } diff --git a/src/Blocks/BlockSapling.h b/src/Blocks/BlockSapling.h index 3fb67fe72..3d6e58438 100644 --- a/src/Blocks/BlockSapling.h +++ b/src/Blocks/BlockSapling.h @@ -25,7 +25,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return (a_RelY > 0) && IsBlockTypeOfDirt(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)); } diff --git a/src/Blocks/BlockSign.h b/src/Blocks/BlockSign.h index 68506e307..60895f69c 100644 --- a/src/Blocks/BlockSign.h +++ b/src/Blocks/BlockSign.h @@ -63,7 +63,7 @@ public: virtual void OnPlacedByPlayer( - cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index a1e73c94e..51e78393a 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -33,7 +33,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -47,7 +47,7 @@ public: cItemHandler * ItemHandler = cItemHandler::GetItemHandler(GetDoubleSlabType(Type)); // Check if the block at the coordinates is a slab. Eligibility for combining has already been processed in ClientHandle - if (IsAnySlabType(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ))) + if (IsAnySlabType(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))) { // Call the function in ClientHandle that places a block when the client sends the packet, // so that plugins may interfere with the placement. diff --git a/src/Blocks/BlockSnow.h b/src/Blocks/BlockSnow.h index 235ac3251..b79ef9f64 100644 --- a/src/Blocks/BlockSnow.h +++ b/src/Blocks/BlockSnow.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -28,7 +28,7 @@ public: BLOCKTYPE BlockBeforePlacement; NIBBLETYPE MetaBeforePlacement; - a_ChunkInterface->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockBeforePlacement, MetaBeforePlacement); + a_ChunkInterface.GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockBeforePlacement, MetaBeforePlacement); if ((BlockBeforePlacement == E_BLOCK_SNOW) && (MetaBeforePlacement < 7)) { @@ -65,7 +65,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if (a_RelY > 0) { diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index a43d81b4d..d50014dd1 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -19,7 +19,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockStems.h b/src/Blocks/BlockStems.h index 8f546029d..ed18817b2 100644 --- a/src/Blocks/BlockStems.h +++ b/src/Blocks/BlockStems.h @@ -42,7 +42,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_FARMLAND)); } diff --git a/src/Blocks/BlockSugarcane.h b/src/Blocks/BlockSugarcane.h index fbdd5a0a8..59314e37d 100644 --- a/src/Blocks/BlockSugarcane.h +++ b/src/Blocks/BlockSugarcane.h @@ -23,7 +23,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { if (a_RelY <= 0) { diff --git a/src/Blocks/BlockTallGrass.h b/src/Blocks/BlockTallGrass.h index 52aa039bc..b8af1f1da 100644 --- a/src/Blocks/BlockTallGrass.h +++ b/src/Blocks/BlockTallGrass.h @@ -34,7 +34,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); } diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index a9a3bd1f8..61f43ac76 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -39,7 +39,7 @@ public: { // Not top or bottom faces, try to preserve whatever face was clicked AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); - if (!CanBePlacedOn(a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ), a_BlockFace)) + if (!CanBePlacedOn(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ), a_BlockFace)) { // Torch couldn't be placed on whatever face was clicked, last ditch resort - find another face a_BlockFace = FindSuitableFace(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); @@ -110,12 +110,12 @@ public: /// Finds a suitable face to place the torch, returning BLOCK_FACE_NONE on failure - static char FindSuitableFace(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + static char FindSuitableFace(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { for (int i = BLOCK_FACE_YM; i <= BLOCK_FACE_XP; i++) // Loop through all directions { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, i, true); - BLOCKTYPE BlockInQuestion = a_ChunkInterface->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + BLOCKTYPE BlockInQuestion = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ); if ( // If on a block that can only hold a torch if torch is standing on it, return that face ((BlockInQuestion == E_BLOCK_GLASS) || @@ -142,7 +142,7 @@ public: } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { char Face = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 0fb48005d..f549b4183 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -32,16 +32,16 @@ public: return true; } - virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Flip the ON bit on/off using the XOR bitwise operation - NIBBLETYPE Meta = (a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x04); + NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x04); - a_ChunkInterface->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); } virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -89,7 +89,7 @@ public: } } - virtual bool CanBeAt(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { NIBBLETYPE Meta; a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta); diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index b6a88524b..aa29849b2 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta @@ -27,7 +27,7 @@ public: // TODO: Disallow placement where the vine doesn't attach to something properly BLOCKTYPE BlockType = 0; NIBBLETYPE BlockMeta; - a_ChunkInterface->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); + a_ChunkInterface.GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); if (BlockType == m_BlockType) { a_BlockMeta = BlockMeta | DirectionToMetaData(a_BlockFace); @@ -105,7 +105,7 @@ public: } - void Check(cChunkInterface * a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override + void Check(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override { NIBBLETYPE CurMeta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); NIBBLETYPE MaxMeta = GetMaxMeta(a_Chunk, a_RelX, a_RelY, a_RelZ); diff --git a/src/Blocks/BlockWood.h b/src/Blocks/BlockWood.h index f2fdbff6a..cf49d0745 100644 --- a/src/Blocks/BlockWood.h +++ b/src/Blocks/BlockWood.h @@ -17,7 +17,7 @@ public: virtual bool GetPlacementBlockTypeMeta( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta diff --git a/src/Blocks/BlockWorkbench.h b/src/Blocks/BlockWorkbench.h index 5c60f1ef1..1c08adb43 100644 --- a/src/Blocks/BlockWorkbench.h +++ b/src/Blocks/BlockWorkbench.h @@ -19,7 +19,7 @@ public: } - virtual void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { cWindow * Window = new cCraftingWindow(a_BlockX, a_BlockY, a_BlockZ); a_Player->OpenWindow(Window); diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h index b0faf5b05..cca5bf913 100644 --- a/src/Blocks/ChunkInterface.h +++ b/src/Blocks/ChunkInterface.h @@ -30,7 +30,7 @@ public: /** Sets the block at the specified coords to the specified value. Full processing, incl. updating neighbors, is performed. */ - void SetBlock(cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) + void SetBlock(cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { m_ChunkMap->SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); } @@ -39,9 +39,9 @@ public: m_ChunkMap->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_MetaData); } - void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay, BLOCKTYPE a_PreviousBlockType, cWorldInterface * a_WorldInterface) + void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay, BLOCKTYPE a_PreviousBlockType, cWorldInterface & a_WorldInterface) { - m_ChunkMap->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_WorldInterface->GetWorldAge() + a_TickDelay, a_PreviousBlockType); + m_ChunkMap->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_WorldInterface.GetWorldAge() + a_TickDelay, a_PreviousBlockType); } /** Sets the block at the specified coords to the specified value. diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index c50bd1ad7..f6b83942f 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -12,7 +12,7 @@ public: virtual eDimension GetDimension(void) const = 0; - virtual cBroadcastInterface * GetBroadcastManager() = 0; + virtual cBroadcastInterface & GetBroadcastManager() = 0; virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData) = 0; diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 4fdaf4b69..b29c97084 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -770,7 +770,7 @@ void cChunk::CheckBlocks() Vector3i BlockPos = IndexToCoordinate(index); cBlockHandler * Handler = BlockHandler(GetBlock(index)); - Handler->Check(&ChunkInterface, BlockPos.x, BlockPos.y, BlockPos.z, *this); + Handler->Check(ChunkInterface, BlockPos.x, BlockPos.y, BlockPos.z, *this); } // for itr - ToTickBlocks[] } diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index fb2495dd1..049bb5fb2 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1233,12 +1233,12 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP -void cChunkMap::SetBlock(cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta) +void cChunkMap::SetBlock(cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta) { cChunkInterface ChunkInterface(this); if (a_BlockType == E_BLOCK_AIR) { - BlockHandler(GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnDestroyed(&ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); + BlockHandler(GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnDestroyed(ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); } int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ; @@ -1251,7 +1251,7 @@ void cChunkMap::SetBlock(cWorldInterface * a_WorldInterface, int a_BlockX, int a Chunk->SetBlock(X, Y, Z, a_BlockType, a_BlockMeta ); m_World->GetSimulatorManager()->WakeUp(a_BlockX, a_BlockY, a_BlockZ, Chunk); } - BlockHandler(a_BlockType)->OnPlaced(&ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + BlockHandler(a_BlockType)->OnPlaced(ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 59a55dc17..62c74d81c 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -148,7 +148,7 @@ public: NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ); NIBBLETYPE GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_BlockZ); void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockMeta); - void SetBlock (cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta); + void SetBlock (cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta); void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR); bool GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); bool GetBlockInfo (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight); diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 3cad46adf..2ec9a87af 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -902,9 +902,8 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, c // A plugin doesn't agree with using the block, abort return; } - cChunkInterface *ChunkInterface = new cChunkInterface(World->GetChunkMap()); - BlockHandler->OnUse(ChunkInterface, World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ); - delete ChunkInterface; + cChunkInterface ChunkInterface(World->GetChunkMap()); + BlockHandler->OnUse(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ); PlgMgr->CallHookPlayerUsedBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta); return; } @@ -1065,7 +1064,7 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, c m_Player->GetInventory().RemoveOneEquippedItem(); } cChunkInterface ChunkInterface(World->GetChunkMap()); - NewBlock->OnPlacedByPlayer(&ChunkInterface,World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta); + NewBlock->OnPlacedByPlayer(ChunkInterface,*World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta); // Step sound with 0.8f pitch is used as block placement sound World->BroadcastSoundEffect(NewBlock->GetStepSound(), a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 1.0f, 0.8f); diff --git a/src/Items/ItemDoor.h b/src/Items/ItemDoor.h index d5c1d887a..531a0c6e4 100644 --- a/src/Items/ItemDoor.h +++ b/src/Items/ItemDoor.h @@ -33,7 +33,7 @@ public: a_BlockType = (m_ItemType == E_ITEM_WOODEN_DOOR) ? E_BLOCK_WOODEN_DOOR : E_BLOCK_IRON_DOOR; cChunkInterface ChunkInterface(a_World->GetChunkMap()); bool Meta = BlockHandler(a_BlockType)->GetPlacementBlockTypeMeta( - &ChunkInterface, a_Player, + ChunkInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 32f9cb3b9..2b8b9f794 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -467,7 +467,7 @@ bool cItemHandler::GetPlacementBlockTypeMeta( cBlockHandler * BlockH = BlockHandler(m_ItemType); cChunkInterface ChunkInterface(a_World->GetChunkMap()); return BlockH->GetPlacementBlockTypeMeta( - &ChunkInterface, a_Player, + ChunkInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index e672c2e49..5749f5035 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -748,7 +748,7 @@ void cRedstoneSimulator::HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ) if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) { cChunkInterface ChunkInterface(m_World.GetChunkMap()); - cBlockDoorHandler::ChangeDoor(&ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + cBlockDoorHandler::ChangeDoor(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); } } @@ -757,7 +757,7 @@ void cRedstoneSimulator::HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ) if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) { cChunkInterface ChunkInterface(m_World.GetChunkMap()); - cBlockDoorHandler::ChangeDoor(&ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + cBlockDoorHandler::ChangeDoor(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); } } diff --git a/src/World.cpp b/src/World.cpp index 7b4cb553a..78b42e810 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1486,7 +1486,7 @@ int cWorld::GetBiomeAt (int a_BlockX, int a_BlockZ) void cWorld::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { - m_ChunkMap->SetBlock(this, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + m_ChunkMap->SetBlock(*this, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); } @@ -1672,9 +1672,8 @@ bool cWorld::GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure) bool cWorld::DigBlock(int a_X, int a_Y, int a_Z) { cBlockHandler *Handler = cBlockHandler::GetBlockHandler(GetBlock(a_X, a_Y, a_Z)); - cChunkInterface *ChunkInterface = new cChunkInterface(GetChunkMap()); - Handler->OnDestroyed(ChunkInterface, this, a_X, a_Y, a_Z); - delete ChunkInterface; + cChunkInterface ChunkInterface(GetChunkMap()); + Handler->OnDestroyed(ChunkInterface, *this, a_X, a_Y, a_Z); return m_ChunkMap->DigBlock(a_X, a_Y, a_Z); } diff --git a/src/World.h b/src/World.h index cdfd1510a..bf6a4ba28 100644 --- a/src/World.h +++ b/src/World.h @@ -186,9 +186,9 @@ public: virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ); void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL); - virtual cBroadcastInterface * GetBroadcastManager() + virtual cBroadcastInterface & GetBroadcastManager() { - return this; + return *this; } /** If there is a block entity at the specified coords, sends it to the client specified */ -- cgit v1.2.3 From 4b5bd4dedf87eb7a2b164bd2dda66b52723c8db4 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Feb 2014 05:14:31 -0800 Subject: Removed register keyword from Messinne Twister Removed register as it is meaningless in c++ and causes a depreciated warning in clang 3.4 in c++ mode for va_copy --- src/MersenneTwister.h | 52 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h index dc7134a93..784ac605d 100644 --- a/src/MersenneTwister.h +++ b/src/MersenneTwister.h @@ -162,9 +162,9 @@ inline void MTRand::initialize( const uint32 seed ) // See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier. // In previous versions, most significant bits (MSBs) of the seed affect // only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto. - register uint32 *s = state; - register uint32 *r = state; - register int i = 1; + uint32 *s = state; + uint32 *r = state; + int i = 1; *s++ = seed & 0xffffffffUL; for( ; i < N; ++i ) { @@ -178,8 +178,8 @@ inline void MTRand::reload() // Generate N new values in state // Made clearer and faster by Matthew Bellew (matthew.bellew@home.com) static const int MmN = int(M) - int(N); // in case enums are unsigned - register uint32 *p = state; - register int i; + uint32 *p = state; + int i; for( i = N - M; i--; ++p ) *p = twist( p[M], p[0], p[1] ); for( i = M; --i; ++p ) @@ -205,9 +205,9 @@ inline void MTRand::seed( uint32 *const bigSeed, const uint32 seedLength ) // in each element are discarded. // Just call seed() if you want to get array from /dev/urandom initialize(19650218UL); - register int i = 1; - register uint32 j = 0; - register int k = ( N > seedLength ? N : seedLength ); + int i = 1; + uint32 j = 0; + int k = ( N > seedLength ? N : seedLength ); for( ; k; --k ) { state[i] = @@ -238,7 +238,7 @@ inline void MTRand::seed() // First try getting an array from /dev/urandom - /* // Commented out by FakeTruth because doing this 200 times a tick is SUUUUPEERRR SLOW!!~~!ÕNe + /* // Commented out by FakeTruth because doing this 200 times a tick is SUUUUPEERRR SLOW!!~~!\D5Ne FILE* urandom = fopen( "/dev/urandom", "rb" ); if( urandom ) { @@ -268,9 +268,9 @@ inline MTRand::MTRand() inline MTRand::MTRand( const MTRand& o ) { - register const uint32 *t = o.state; - register uint32 *s = state; - register int i = N; + const uint32 *t = o.state; + uint32 *s = state; + int i = N; for( ; i--; *s++ = *t++ ) {} left = o.left; pNext = &state[N-left]; @@ -284,7 +284,7 @@ inline MTRand::uint32 MTRand::randInt() if( left == 0 ) reload(); --left; - register uint32 s1; + uint32 s1; s1 = *pNext++; s1 ^= (s1 >> 11); s1 ^= (s1 << 7) & 0x9d2c5680UL; @@ -358,18 +358,18 @@ inline double MTRand::operator()() inline void MTRand::save( uint32* saveArray ) const { - register const uint32 *s = state; - register uint32 *sa = saveArray; - register int i = N; + const uint32 *s = state; + uint32 *sa = saveArray; + int i = N; for( ; i--; *sa++ = *s++ ) {} *sa = left; } inline void MTRand::load( uint32 *const loadArray ) { - register uint32 *s = state; - register uint32 *la = loadArray; - register int i = N; + uint32 *s = state; + uint32 *la = loadArray; + int i = N; for( ; i--; *s++ = *la++ ) {} left = *la; pNext = &state[N-left]; @@ -377,16 +377,16 @@ inline void MTRand::load( uint32 *const loadArray ) inline std::ostream& operator<<( std::ostream& os, const MTRand& mtrand ) { - register const MTRand::uint32 *s = mtrand.state; - register int i = mtrand.N; + const MTRand::uint32 *s = mtrand.state; + int i = mtrand.N; for( ; i--; os << *s++ << "\t" ) {} return os << mtrand.left; } inline std::istream& operator>>( std::istream& is, MTRand& mtrand ) { - register MTRand::uint32 *s = mtrand.state; - register int i = mtrand.N; + MTRand::uint32 *s = mtrand.state; + int i = mtrand.N; for( ; i--; is >> *s++ ) {} is >> mtrand.left; mtrand.pNext = &mtrand.state[mtrand.N-mtrand.left]; @@ -396,9 +396,9 @@ inline std::istream& operator>>( std::istream& is, MTRand& mtrand ) inline MTRand& MTRand::operator=( const MTRand& o ) { if( this == &o ) return (*this); - register const uint32 *t = o.state; - register uint32 *s = state; - register int i = N; + const uint32 *t = o.state; + uint32 *s = state; + int i = N; for( ; i--; *s++ = *t++ ) {} left = o.left; pNext = &state[N-left]; -- cgit v1.2.3 From cf3b4ec226034b006fd646b395f4e8a609f6f378 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Feb 2014 06:01:13 -0800 Subject: Changed Signiture of OnDestroyedByPlayer --- src/Blocks/BlockButton.h | 2 +- src/Blocks/BlockDoor.h | 2 +- src/Blocks/BlockHandler.cpp | 3 ++- src/Blocks/BlockHandler.h | 4 ++-- src/Blocks/BlockPiston.cpp | 10 +++++----- src/Blocks/BlockPiston.h | 2 +- src/Blocks/BlockRedstoneRepeater.h | 1 + src/Blocks/BlockSign.h | 2 +- src/Blocks/BlockTorch.h | 2 +- src/Blocks/ChunkInterface.h | 5 +++++ src/Blocks/WorldInterface.h | 3 +++ src/ClientHandle.cpp | 7 ++++--- 12 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 62fae6abc..f592b94a1 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -1,7 +1,7 @@ #pragma once #include "BlockHandler.h" - +#include "Chunk.h" diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 31d1bb797..2da561952 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -3,7 +3,7 @@ #include "BlockHandler.h" #include "../Entities/Player.h" - +#include "Chunk.h" diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 374c64fd8..d5ca9dcc1 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -5,6 +5,7 @@ #include "../World.h" #include "../Root.h" #include "../Bindings/PluginManager.h" +#include "../Chunk.h" #include "BlockBed.h" #include "BlockBrewingStand.h" #include "BlockButton.h" @@ -276,7 +277,7 @@ void cBlockHandler::OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldI -void cBlockHandler::OnDestroyedByPlayer(cWorld *a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockHandler::OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) { } diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 73a658b3f..a48a5a62b 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -3,7 +3,6 @@ #include "../Defines.h" #include "../Item.h" -#include "../Chunk.h" #include "WorldInterface.h" #include "ChunkInterface.h" @@ -13,6 +12,7 @@ // fwd: class cPlayer; +class cChunk; @@ -51,7 +51,7 @@ public: ); /// Called before the player has destroyed a block - virtual void OnDestroyedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ); + virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called before a block gets destroyed / replaced with air virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ); diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp index 43afda45a..e960d23e4 100644 --- a/src/Blocks/BlockPiston.cpp +++ b/src/Blocks/BlockPiston.cpp @@ -80,19 +80,19 @@ cBlockPistonHeadHandler::cBlockPistonHeadHandler(void) : -void cBlockPistonHeadHandler::OnDestroyedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockPistonHeadHandler::OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE OldMeta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); int newX = a_BlockX; int newY = a_BlockY; int newZ = a_BlockZ; AddPistonDir(newX, newY, newZ, OldMeta & ~(8), -1); - BLOCKTYPE Block = a_World->GetBlock(newX, newY, newZ); + BLOCKTYPE Block = a_ChunkInterface.GetBlock(newX, newY, newZ); if ((Block == E_BLOCK_STICKY_PISTON) || (Block == E_BLOCK_PISTON)) { - a_World->DigBlock(newX, newY, newZ); + a_ChunkInterface.DigBlock(a_WorldInterface, newX, newY, newZ); if (a_Player->IsGameModeCreative()) { return; // No pickups if creative @@ -100,7 +100,7 @@ void cBlockPistonHeadHandler::OnDestroyedByPlayer(cWorld * a_World, cPlayer * a_ cItems Pickups; Pickups.push_back(cItem(Block, 1)); - a_World->SpawnItemPickups(Pickups, a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5); + a_WorldInterface.SpawnItemPickups(Pickups, a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5); } } diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index e0ab182db..de40afdd6 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -35,7 +35,7 @@ class cBlockPistonHeadHandler : public: cBlockPistonHeadHandler(void); - virtual void OnDestroyedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h index 1e82108c4..a48fed8b6 100644 --- a/src/Blocks/BlockRedstoneRepeater.h +++ b/src/Blocks/BlockRedstoneRepeater.h @@ -2,6 +2,7 @@ #pragma once #include "BlockHandler.h" +#include "Chunk.h" diff --git a/src/Blocks/BlockSign.h b/src/Blocks/BlockSign.h index 60895f69c..dced0008c 100644 --- a/src/Blocks/BlockSign.h +++ b/src/Blocks/BlockSign.h @@ -2,8 +2,8 @@ #pragma once #include "BlockHandler.h" -#include "../World.h" #include "../Entities/Player.h" +#include "Chunk.h" diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 61f43ac76..33cafbddc 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -1,7 +1,7 @@ #pragma once #include "BlockHandler.h" -#include "../World.h" +#include "../Chunk.h" diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h index cca5bf913..b30eff1e4 100644 --- a/src/Blocks/ChunkInterface.h +++ b/src/Blocks/ChunkInterface.h @@ -3,6 +3,9 @@ #include "../ChunkMap.h" #include "../ForEachChunkProvider.h" +#include "WorldInterface.h" + +class cBlockHandler; class cChunkInterface : public cForEachChunkProvider { @@ -69,6 +72,8 @@ public: return m_ChunkMap->WriteBlockArea(a_Area, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes); } + bool DigBlock(cWorldInterface & a_WorldInterface, int a_X, int a_Y, int a_Z); + private: cChunkMap * m_ChunkMap; }; diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index f6b83942f..b6f2f55a7 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -2,6 +2,9 @@ #pragma once #include "BroadcastInterface.h" +#include "../Mobs/Monster.h" + +class cItems; class cWorldInterface { diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 2ec9a87af..1dd51ed82 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -832,8 +832,8 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo cWorld * World = m_Player->GetWorld(); ItemHandler->OnBlockDestroyed(World, m_Player, m_Player->GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ); // The ItemHandler is also responsible for spawning the pickups - - BlockHandler(a_OldBlock)->OnDestroyedByPlayer(World, m_Player, a_BlockX, a_BlockY, a_BlockZ); + cChunkInterface ChunkInterface(World->GetChunkMap()); + BlockHandler(a_OldBlock)->OnDestroyedByPlayer(ChunkInterface,*World, m_Player, a_BlockX, a_BlockY, a_BlockZ); World->BroadcastSoundParticleEffect(2001, a_BlockX, a_BlockY, a_BlockZ, a_OldBlock, this); World->DigBlock(a_BlockX, a_BlockY, a_BlockZ); @@ -1002,7 +1002,8 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, c BlockHandler(ClickedBlock)->DoesIgnoreBuildCollision(m_Player, ClickedBlockMeta) ) { - BlockHandler(ClickedBlock)->OnDestroyedByPlayer(World, m_Player, a_BlockX, a_BlockY, a_BlockZ); + cChunkInterface ChunkInterface(World->GetChunkMap()); + BlockHandler(ClickedBlock)->OnDestroyedByPlayer(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ); } else { -- cgit v1.2.3 From 0259aed8beba5a2a46d537617e122a5dacc373a3 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Sat, 1 Feb 2014 20:16:42 +0400 Subject: Added saving of collar's color. --- src/WorldStorage/NBTChunkSerializer.cpp | 3 ++- src/WorldStorage/WSSAnvil.cpp | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 9c454c028..7bba82ca8 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -455,7 +455,8 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) case cMonster::mtWolf: { m_Writer.AddString("Owner", ((const cWolf *)a_Monster)->GetOwner()); - m_Writer.AddByte("Sitting", ((const cWolf *)a_Monster)->IsSitting()); + m_Writer.AddByte("IsSitting", (((const cWolf *)a_Monster)->IsSitting() ? 1 : 0)); + m_Writer.AddInt("CollarColor", ((const cWolf *)a_Monster)->GetCollarColor()); break; } case cMonster::mtZombie: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 63999add3..a9c6a3475 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1886,12 +1886,18 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N Monster->SetIsTame(true); } } - int SittingIdx = a_NBT.FindChildByName(a_TagIdx, "Sitting"); - if (SittingIdx > 0) + int IsSittingIdx = a_NBT.FindChildByName(a_TagIdx, "IsSitting"); + if (IsSittingIdx > 0) { - bool IsSitting = (a_NBT.GetByte(SittingIdx) > 0); + bool IsSitting = ((a_NBT.GetByte(IsSittingIdx) == 1) ? true : false); Monster->SetIsSitting(IsSitting); } + int CollarColorIdx = a_NBT.FindChildByName(a_TagIdx, "CollarColor"); + if (CollarColorIdx > 0) + { + int CollarColor = a_NBT.GetInt(CollarColorIdx); + Monster->SetCollarColor(CollarColor); + } a_Entities.push_back(Monster.release()); } -- cgit v1.2.3 From 0d33f2d11d9f9836bfd840a0e83969bbe6e9c49c Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Sat, 1 Feb 2014 20:22:12 +0400 Subject: Fixed teleport to air, if owner is flying. --- src/Mobs/Wolf.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index c0c7892e3..ff324d073 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -204,6 +204,7 @@ void cWolf::TickFollowPlayer() { if (!IsSitting()) { + Callback.OwnerPos.y = FindFirstNonAirBlockPosition(Callback.OwnerPos.x, Callback.OwnerPos.z); TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z); } } -- cgit v1.2.3 From 6e39ed3868fa8feba676b0cda28194c249e549ce Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Feb 2014 08:35:48 -0800 Subject: Changed Signiture of OnDigging --- src/Blocks/BlockFire.h | 4 ++-- src/Blocks/BlockHandler.cpp | 2 +- src/Blocks/BlockHandler.h | 2 +- src/ClientHandle.cpp | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h index a85808c89..a25b87858 100644 --- a/src/Blocks/BlockFire.h +++ b/src/Blocks/BlockFire.h @@ -38,9 +38,9 @@ public: FindAndSetPortalFrame(a_BlockX, a_BlockY, a_BlockZ, a_ChunkInterface, a_WorldInterface); // Brought to you by Aperture Science } - virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override + virtual void OnDigging(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override { - a_World->DigBlock(a_BlockX, a_BlockY, a_BlockZ); + a_ChunkInterface.DigBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); } virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index d5ca9dcc1..8ce8ec1f7 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -335,7 +335,7 @@ void cBlockHandler::OnNeighborChanged(cChunkInterface & a_ChunkInterface, int a_ -void cBlockHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockHandler::OnDigging(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) { } diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index a48a5a62b..867c4c2c5 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -63,7 +63,7 @@ public: static void NeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called while the player diggs the block. - virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ); + virtual void OnDigging(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called if the user right clicks the block and the block is useable virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 1dd51ed82..6b61eaae8 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -767,9 +767,9 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc m_Player->GetWorld()->BroadcastBlockBreakAnimation(m_UniqueID, m_BlockDigAnimX, m_BlockDigAnimY, m_BlockDigAnimZ, 0, this); cWorld * World = m_Player->GetWorld(); - + cChunkInterface ChunkInterface(World->GetChunkMap()); cBlockHandler * Handler = cBlockHandler::GetBlockHandler(a_OldBlock); - Handler->OnDigging(World, m_Player, a_BlockX, a_BlockY, a_BlockZ); + Handler->OnDigging(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ); cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem()); ItemHandler->OnDiggingBlock(World, m_Player, m_Player->GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); @@ -786,7 +786,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc if (Handler->IsClickedThrough()) { - Handler->OnDigging(World, m_Player, pX, pY, pZ); + Handler->OnDigging(ChunkInterface, *World, m_Player, pX, pY, pZ); } } } -- cgit v1.2.3 From 2a52b390c001406540627293e6b425ff709e7250 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Sat, 1 Feb 2014 20:38:53 +0400 Subject: Monster's nominal speed was increased. --- CONTRIBUTORS | 1 + src/Mobs/Monster.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 2392d8523..8b10525da 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -23,6 +23,7 @@ Sxw1212 Taugeshtu tigerw (Tiger Wang) tonibm19 +UltraCoderRU worktycho xoft diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 42c7d2899..283ef36e6 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -276,7 +276,7 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) { Distance.y = 0; Distance.Normalize(); - Distance *= 3; + Distance *= 5; SetSpeedX(Distance.x); SetSpeedZ(Distance.z); -- cgit v1.2.3 From b0784d1931b4a6771321a0c3b33af537200bf084 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 1 Feb 2014 21:40:02 +0000 Subject: Split cCoord template into one and two data types --- src/ChunkDef.h | 42 ++++++++++++++++++++++++++++--------- src/Simulator/RedstoneSimulator.cpp | 4 ++-- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 13933e6f1..2c50755cf 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -498,15 +498,14 @@ public: -/// Generic template that can store any kind of data together with a triplet of 3 coords: -template class cCoordWithData +/** Generic template that can store any kind of data together with a triplet of 3 coords*/ +template class cCoordWithData { public: int x; int y; int z; X Data; - Y SecondData; cCoordWithData(int a_X, int a_Y, int a_Z) : x(a_X), y(a_Y), z(a_Z) @@ -517,18 +516,41 @@ public: x(a_X), y(a_Y), z(a_Z), Data(a_Data) { } - - cCoordWithData(int a_X, int a_Y, int a_Z, const X & a_Data, const Y & a_SecondData) : - x(a_X), y(a_Y), z(a_Z), Data(a_Data), SecondData(a_SecondData) - { - } } ; -typedef cCoordWithData cCoordWithInt; -typedef cCoordWithData cCoordWithBlockAndBool; +typedef cCoordWithData cCoordWithInt; +typedef cCoordWithData cCoordWithBlock; typedef std::list cCoordWithIntList; typedef std::vector cCoordWithIntVector; + + + + + +/** Generic template that can store two types of any kind of data together with a triplet of 3 coords */ +template class cCoordWithDoubleData +{ +public: + int x; + int y; + int z; + X Data; + Z DataTwo; + + cCoordWithDoubleData(int a_X, int a_Y, int a_Z) : + x(a_X), y(a_Y), z(a_Z) + { + } + + cCoordWithDoubleData(int a_X, int a_Y, int a_Z, const X & a_Data, const Z & a_DataTwo) : + x(a_X), y(a_Y), z(a_Z), Data(a_Data), DataTwo(a_DataTwo) + { + } +}; + +typedef cCoordWithDoubleData cCoordWithBlockAndBool; + typedef std::vector cCoordWithBlockAndBoolVector; diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 357643ecc..131380daa 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -169,7 +169,7 @@ void cRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChu { if (!IsAllowedBlock(Block)) { - itr->SecondData = true; // The new blocktype is not redstone; it must be queued to be removed from this list + itr->DataTwo = true; // The new blocktype is not redstone; it must be queued to be removed from this list } else { @@ -209,7 +209,7 @@ void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, c for (cRedstoneSimulatorChunkData::iterator dataitr = ChunkData.begin(); dataitr != ChunkData.end();) { - if (dataitr->SecondData) + if (dataitr->DataTwo) { dataitr = ChunkData.erase(dataitr); continue; -- cgit v1.2.3 From e26dc5cc0aaeb81ee7c6419ea91f8eef7d072ef3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 1 Feb 2014 21:40:50 +0000 Subject: Added checks for ice into IsBlockWater() * This fixes players spawning in vast oceans of ice, as opposed to the previous water --- src/Defines.h | 11 +++++++++-- src/World.cpp | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Defines.h b/src/Defines.h index 3a26f4be6..b3dbcc93e 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -254,9 +254,16 @@ inline bool IsValidItem(int a_ItemType) -inline bool IsBlockWater(BLOCKTYPE a_BlockType) +inline bool IsBlockWater(BLOCKTYPE a_BlockType, bool a_IncludeFrozenWater = false) { - return ((a_BlockType == E_BLOCK_WATER) || (a_BlockType == E_BLOCK_STATIONARY_WATER)); + if (a_IncludeFrozenWater) + { + return ((a_BlockType == E_BLOCK_WATER) || (a_BlockType == E_BLOCK_STATIONARY_WATER) || (a_BlockType == E_BLOCK_ICE)); + } + else + { + return ((a_BlockType == E_BLOCK_WATER) || (a_BlockType == E_BLOCK_STATIONARY_WATER)); + } } diff --git a/src/World.cpp b/src/World.cpp index f2981bf84..2571a6782 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -635,7 +635,7 @@ void cWorld::GenerateRandomSpawn(void) { LOGD("Generating random spawnpoint..."); - while (IsBlockWater(GetBlock((int)m_SpawnX, GetHeight((int)m_SpawnX, (int)m_SpawnZ), (int)m_SpawnZ))) + while (IsBlockWater(GetBlock((int)m_SpawnX, GetHeight((int)m_SpawnX, (int)m_SpawnZ), (int)m_SpawnZ), true)) { if ((GetTickRandomNumber(4) % 2) == 0) // Randomise whether to increment X or Z coords { -- cgit v1.2.3 From dd325d742db9db54a25460fcacd093e7cc6f44f0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 1 Feb 2014 21:44:23 +0000 Subject: Again improved LogReplaceLine * Fixed issues on Linux with cursor positioning * Made preprocessor blocks more readable * Improved reliability of line clearing on Windows - Removed an *unneeded* variable --- src/Log.cpp | 156 +++++++++++++++++++++++++++++++----------------------------- src/Log.h | 1 - 2 files changed, 80 insertions(+), 77 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index aa9f22f84..a1b4c784f 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -9,7 +9,7 @@ #ifdef __linux #include -#include +#include #endif // __linux @@ -24,8 +24,7 @@ cLog* cLog::s_Log = NULL; cLog::cLog(const AString & a_FileName ) - : m_File(NULL), - m_LastStringSize(0) + : m_File(NULL) { s_Log = this; @@ -115,20 +114,22 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) time(&rawtime); struct tm* timeinfo; -#ifdef _MSC_VER - struct tm timeinforeal; - timeinfo = &timeinforeal; - localtime_s(timeinfo, &rawtime); -#else - timeinfo = localtime(&rawtime); -#endif + + #ifdef _MSC_VER + struct tm timeinforeal; + timeinfo = &timeinforeal; + localtime_s(timeinfo, &rawtime); + #else + timeinfo = localtime(&rawtime); + #endif AString Line; -#ifdef _DEBUG - Printf(Line, "[%04x|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); -#else - Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); -#endif + #ifdef _DEBUG + Printf(Line, "[%04x|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); + #else + Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); + #endif + if (m_File) { fprintf(m_File, "%s\n", Line.c_str()); @@ -136,67 +137,68 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) } // Print to console: -#if defined(ANDROID_NDK) - //__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList); - __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str()); - //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); -#else -#ifdef _WIN32 - size_t LineLength = Line.length(); - - if (m_LastStringSize == 0) - m_LastStringSize = LineLength; // Initialise m_LastStringSize - - HANDLE Output = GetStdHandle(STD_OUTPUT_HANDLE); - - CONSOLE_SCREEN_BUFFER_INFO csbi; - GetConsoleScreenBufferInfo(Output, &csbi); - - if ((size_t)((csbi.srWindow.Right - csbi.srWindow.Left) + 1) < LineLength) - { - printf("\n%s", Line.c_str()); // We are at line to be replaced, but since we can't, add a new line - return false; - } - - if (LineLength < m_LastStringSize) // If last printed line was longer than current, clear this line - { - for (size_t X = 0; X != m_LastStringSize + 1; ++X) - { - fputs(" ", stdout); - } - } -#else // _WIN32 - struct ttysize ts; -#ifdef TIOCGSIZE - ioctl(STDIN_FILENO, TIOCGSIZE, &ts); - if (ts.ts_cols < LineLength) - { - return false; - } -#elif defined(TIOCGWINSZ) - ioctl(STDIN_FILENO, TIOCGWINSZ, &ts); - if (ts.ts_cols < LineLength) - { - return false; - } -#else /* TIOCGSIZE */ - return false; -#endif - fputs("\033[K", stdout); // Clear current line -#endif - printf("\r%s", Line.c_str()); -#ifdef __linux - fputs("\033[1B", stdout); // Move down one line -#endif // __linux - - m_LastStringSize = LineLength; - -#endif // ANDROID_NDK + #if defined(ANDROID_NDK) + //__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList); + __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str()); + //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); + #else + + size_t LineLength = Line.length(); + #ifdef _WIN32 + HANDLE Output = GetStdHandle(STD_OUTPUT_HANDLE); + + CONSOLE_SCREEN_BUFFER_INFO csbi; + GetConsoleScreenBufferInfo(Output, &csbi); // Obtain console window information + + if ((size_t)((csbi.srWindow.Right - csbi.srWindow.Left) + 1) < LineLength) // Will text overrun width? If so, do not do a replace operation + { + printf("\n%s", Line.c_str()); // We are at line to be replaced, but since we can't, print normally with a newline + return false; + } + + for (size_t X = 0; X != (size_t)(csbi.srWindow.Right - csbi.srWindow.Left); ++X) + { + fputs(" ", stdout); // Clear current line in preparation for new text + } + #else // _WIN32 + // Try to get console width; if text overruns, print normally with a newline + #ifdef TIOCGSIZE + struct ttysize ts; + ioctl(STDIN_FILENO, TIOCGSIZE, &ts); + + if (ts.ts_cols < LineLength) + { + printf("\n%s", Line.c_str()); + return false; + } + #elif defined(TIOCGWINSZ) + struct winsize ts; + ioctl(STDIN_FILENO, TIOCGWINSZ, &ts); + + if (ts.ws_col < LineLength) + { + printf("\n%s", Line.c_str()); + return false; + } + #else + printf("\n%s", Line.c_str()); + return false; + #endif + + fputs("\033[K", stdout); // Clear current line + #endif // Not _WIN32 + + printf("\r%s", Line.c_str()); + + #ifdef __linux + fputs("\033[1B", stdout); // Move down one line + #endif // __linux + #endif // ANDROID_NDK -#if defined (_WIN32) && defined(_DEBUG) - // In a Windows Debug build, output the log to debug console as well: - OutputDebugStringA((Line + "\n").c_str()); -#endif // _WIN32 + #if defined (_WIN32) && defined(_DEBUG) + // In a Windows Debug build, output the log to debug console as well: + OutputDebugStringA((Line + "\n").c_str()); + #endif // _WIN32 return true; } @@ -241,7 +243,9 @@ void cLog::Log(const char * a_Format, va_list argList) __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str() ); //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); #else - printf("%s", Line.c_str()); + // If something requests the current line to be rewritten (LogReplaceLine), on Linux it clears the current line, but that moves the cursor to the end of that line, so we reset it here (\r) + // Doesn't affect anything normally - cursor should already be at beginning of line + printf("\r%s", Line.c_str()); #endif #if defined (_WIN32) && defined(_DEBUG) diff --git a/src/Log.h b/src/Log.h index c9ca17864..6944edd88 100644 --- a/src/Log.h +++ b/src/Log.h @@ -11,7 +11,6 @@ private: FILE * m_File; static cLog * s_Log; - size_t m_LastStringSize; public: -- cgit v1.2.3 From a1c36c18e0d12516cabf5045807596d5555c54a2 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Sun, 2 Feb 2014 13:56:55 +0400 Subject: Fixed sitting tag. --- src/WorldStorage/NBTChunkSerializer.cpp | 2 +- src/WorldStorage/WSSAnvil.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 7bba82ca8..f3f187e66 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -455,7 +455,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) case cMonster::mtWolf: { m_Writer.AddString("Owner", ((const cWolf *)a_Monster)->GetOwner()); - m_Writer.AddByte("IsSitting", (((const cWolf *)a_Monster)->IsSitting() ? 1 : 0)); + m_Writer.AddByte("Sitting", (((const cWolf *)a_Monster)->IsSitting() ? 1 : 0)); m_Writer.AddInt("CollarColor", ((const cWolf *)a_Monster)->GetCollarColor()); break; } diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index a9c6a3475..ad15a093b 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1886,11 +1886,11 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N Monster->SetIsTame(true); } } - int IsSittingIdx = a_NBT.FindChildByName(a_TagIdx, "IsSitting"); - if (IsSittingIdx > 0) + int SittingIdx = a_NBT.FindChildByName(a_TagIdx, "Sitting"); + if (SittingIdx > 0) { - bool IsSitting = ((a_NBT.GetByte(IsSittingIdx) == 1) ? true : false); - Monster->SetIsSitting(IsSitting); + bool Sitting = ((a_NBT.GetByte(SittingIdx) == 1) ? true : false); + Monster->SetIsSitting(Sitting); } int CollarColorIdx = a_NBT.FindChildByName(a_TagIdx, "CollarColor"); if (CollarColorIdx > 0) -- cgit v1.2.3 From a134fd45cfd4314d0f51cd402ffd1ec01c5736b9 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Sun, 2 Feb 2014 14:28:42 +0400 Subject: Added saving of angry flag. --- src/WorldStorage/NBTChunkSerializer.cpp | 1 + src/WorldStorage/WSSAnvil.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index f3f187e66..c6250f393 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -456,6 +456,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) { m_Writer.AddString("Owner", ((const cWolf *)a_Monster)->GetOwner()); m_Writer.AddByte("Sitting", (((const cWolf *)a_Monster)->IsSitting() ? 1 : 0)); + m_Writer.AddByte("Angry", (((const cWolf *)a_Monster)->IsAngry() ? 1 : 0)); m_Writer.AddInt("CollarColor", ((const cWolf *)a_Monster)->GetCollarColor()); break; } diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index ad15a093b..d72165c46 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1892,6 +1892,12 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N bool Sitting = ((a_NBT.GetByte(SittingIdx) == 1) ? true : false); Monster->SetIsSitting(Sitting); } + int AngryIdx = a_NBT.FindChildByName(a_TagIdx, "Angry"); + if (AngryIdx > 0) + { + bool Angry = ((a_NBT.GetByte(AngryIdx) == 1) ? true : false); + Monster->SetIsAngry(Angry); + } int CollarColorIdx = a_NBT.FindChildByName(a_TagIdx, "CollarColor"); if (CollarColorIdx > 0) { -- cgit v1.2.3 From 275035eb70e7a39f408da8078bd5167758abedef Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 12:43:57 +0000 Subject: Fixed #620 --- src/Blocks/BlockTorch.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index faba9c4f5..437449820 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -38,9 +38,10 @@ public: else { // Not top or bottom faces, try to preserve whatever face was clicked - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); // Set to clicked block if (!CanBePlacedOn(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ), a_BlockFace)) { + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, false); // Reset to torch block // Torch couldn't be placed on whatever face was clicked, last ditch resort - find another face a_BlockFace = FindSuitableFace(a_World, a_BlockX, a_BlockY, a_BlockZ); if (a_BlockFace == BLOCK_FACE_NONE) -- cgit v1.2.3 From b89419f603126b9c8e01c607912b2976ba66ffda Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 12:47:17 +0000 Subject: Creative players take Plugin damage --- src/Entities/Entity.cpp | 3 ++- src/Entities/Player.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index e22f689d9..08780ca8b 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -397,6 +397,7 @@ int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_Dama case dtPotionOfHarming: case dtFalling: case dtLightning: + case dtPlugin: { return 0; } @@ -473,7 +474,7 @@ void cEntity::KilledBy(cEntity * a_Killer) return; } - // Drop loot: + // Drop loot: cItems Drops; GetDrops(Drops, a_Killer); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ()); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 82e31ae65..ca0f0e770 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -784,11 +784,11 @@ void cPlayer::SetFlying(bool a_IsFlying) void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { - if (a_TDI.DamageType != dtInVoid) + if ((a_TDI.DamageType != dtInVoid) && (a_TDI.DamageType != dtPlugin)) { if (IsGameModeCreative()) { - // No damage / health in creative mode if not void damage + // No damage / health in creative mode if not void or plugin damage return; } } -- cgit v1.2.3 From b82fc394dd2a40e12e3c13709fea26c2435792c9 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 2 Feb 2014 06:49:37 -0800 Subject: Changed Signiture of OnUpdate --- src/Blocks/BlockCactus.h | 2 +- src/Blocks/BlockCrops.h | 2 +- src/Blocks/BlockDirt.h | 2 +- src/Blocks/BlockFarmland.h | 2 +- src/Blocks/BlockFluid.h | 6 +++--- src/Blocks/BlockHandler.cpp | 14 +++++++------- src/Blocks/BlockHandler.h | 7 ++++--- src/Blocks/BlockLeaves.h | 6 +++--- src/Blocks/BlockNetherWart.h | 2 +- src/Blocks/BlockSapling.h | 2 +- src/Blocks/BlockStems.h | 2 +- src/Blocks/BlockSugarcane.h | 2 +- src/Blocks/BlockVine.h | 4 ++-- src/Chunk.cpp | 14 ++++++++++---- src/Items/ItemBucket.h | 5 ++++- src/Items/ItemHandler.cpp | 5 ++++- src/Items/ItemShovel.h | 7 +++++-- src/Mobs/Villager.cpp | 5 ++++- src/Piston.cpp | 5 ++++- src/Simulator/FloodyFluidSimulator.cpp | 8 +++++++- 20 files changed, 65 insertions(+), 37 deletions(-) diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h index 70c9c5257..83595d2b9 100644 --- a/src/Blocks/BlockCactus.h +++ b/src/Blocks/BlockCactus.h @@ -65,7 +65,7 @@ public: } - void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { a_Chunk.GetWorld()->GrowCactus(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width, 1); } diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index c86183ca4..4c4ac21be 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -74,7 +74,7 @@ public: } - void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { NIBBLETYPE Meta = a_Chunk.GetMeta (a_RelX, a_RelY, a_RelZ); NIBBLETYPE Light = a_Chunk.GetBlockLight(a_RelX, a_RelY, a_RelZ); diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index 1cc6bc0c3..91534c5e5 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -25,7 +25,7 @@ public: } - void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { if (m_BlockType != E_BLOCK_GRASS) { diff --git a/src/Blocks/BlockFarmland.h b/src/Blocks/BlockFarmland.h index a69d9b775..101ab8e34 100644 --- a/src/Blocks/BlockFarmland.h +++ b/src/Blocks/BlockFarmland.h @@ -28,7 +28,7 @@ public: } - void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { bool Found = false; diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index fbdbec26c..37885e4de 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -32,7 +32,7 @@ public: } - virtual void Check(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override + virtual void Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override { switch (m_BlockType) { @@ -47,7 +47,7 @@ public: break; } } - super::Check(a_ChunkInterface, a_RelX, a_RelY, a_RelZ, a_Chunk); + super::Check(a_ChunkInterface, a_PluginInterface, a_RelX, a_RelY, a_RelZ, a_Chunk); } } ; @@ -68,7 +68,7 @@ public: /// Called to tick the block - virtual void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { if (a_Chunk.GetWorld()->ShouldLavaSpawnFire()) { diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 8ce8ec1f7..3f69ba1c1 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -261,7 +261,7 @@ bool cBlockHandler::GetPlacementBlockTypeMeta( -void cBlockHandler::OnUpdate(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockHandler::OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ) { } @@ -361,14 +361,14 @@ void cBlockHandler::ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) -void cBlockHandler::DropBlock(cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ) { cItems Pickups; - NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); ConvertToPickups(Pickups, Meta); // Allow plugins to modify the pickups: - cRoot::Get()->GetPluginManager()->CallHookBlockToPickups(a_World, a_Digger, a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta, Pickups); + a_BlockPluginInterface.CallHookBlockToPickups(a_Digger, a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta, Pickups); if (!Pickups.empty()) { @@ -384,7 +384,7 @@ void cBlockHandler::DropBlock(cWorld * a_World, cEntity * a_Digger, int a_BlockX MicroX += r1.rand(1) - 0.5; MicroZ += r1.rand(1) - 0.5; - a_World->SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ); + a_WorldInterface.SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ); } } @@ -446,7 +446,7 @@ bool cBlockHandler::DoesDropOnUnsuitable(void) -void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) +void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) { if (!CanBeAt(a_ChunkInterface, a_RelX, a_RelY, a_RelZ, a_Chunk)) { @@ -454,7 +454,7 @@ void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, int a_RelX, int a_ { int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width; int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width; - DropBlock(a_Chunk.GetWorld(), NULL, BlockX, a_RelY, BlockZ); + DropBlock(a_ChunkInterface, *a_Chunk.GetWorld(), a_PluginInterface, NULL, BlockX, a_RelY, BlockZ); } a_Chunk.SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_AIR, 0); diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 867c4c2c5..44b15bce1 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -5,6 +5,7 @@ #include "../Item.h" #include "WorldInterface.h" #include "ChunkInterface.h" +#include "BlockPluginInterface.h" @@ -25,7 +26,7 @@ public: /// Called when the block gets ticked either by a random tick or by a queued tick. /// Note that the coords are chunk-relative! - virtual void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ); + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ); /** Called before a block is placed into a world. The handler should return true to allow placement, false to refuse. @@ -72,7 +73,7 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta); /// Handles the dropping of a block based on what ConvertToDrops() returns. This will not destroy the block. a_Digger is the entity causing the drop; it may be NULL - virtual void DropBlock(cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ); + virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ); /// Returns step sound name of block virtual const char * GetStepSound(void); @@ -113,7 +114,7 @@ public: By default drops if position no more suitable (CanBeAt(), DoesDropOnUnsuitable(), Drop()), and wakes up all simulators on the block. */ - virtual void Check(cChunkInterface & ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk); + virtual void Check(cChunkInterface & ChunkInterface, cBlockPluginInterface & a_PluginInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk); /// Rotates a given block meta counter-clockwise. Default: no change /// Block meta following rotation diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 069849361..ad6e440e2 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -77,7 +77,7 @@ public: } - void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + virtual void OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); if ((Meta & 0x04) != 0) @@ -116,8 +116,8 @@ public: } // Decay the leaves: - DropBlock(a_Chunk.GetWorld(), NULL, BlockX, a_RelY, BlockZ); - a_Chunk.GetWorld()->DigBlock(BlockX, a_RelY, BlockZ); + DropBlock(a_ChunkInterface, a_WorldInterface, a_PluginInterface, NULL, BlockX, a_RelY, BlockZ); + a_ChunkInterface.DigBlock(a_WorldInterface, BlockX, a_RelY, BlockZ); } diff --git a/src/Blocks/BlockNetherWart.h b/src/Blocks/BlockNetherWart.h index 937d2b4b5..923180e19 100644 --- a/src/Blocks/BlockNetherWart.h +++ b/src/Blocks/BlockNetherWart.h @@ -35,7 +35,7 @@ public: } } - void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { NIBBLETYPE Meta = a_Chunk.GetMeta (a_RelX, a_RelY, a_RelZ); diff --git a/src/Blocks/BlockSapling.h b/src/Blocks/BlockSapling.h index 3d6e58438..3d925029a 100644 --- a/src/Blocks/BlockSapling.h +++ b/src/Blocks/BlockSapling.h @@ -31,7 +31,7 @@ public: } - void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); diff --git a/src/Blocks/BlockStems.h b/src/Blocks/BlockStems.h index ed18817b2..705436345 100644 --- a/src/Blocks/BlockStems.h +++ b/src/Blocks/BlockStems.h @@ -24,7 +24,7 @@ public: } - void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); if (Meta >= 7) diff --git a/src/Blocks/BlockSugarcane.h b/src/Blocks/BlockSugarcane.h index 59314e37d..84d3b2e7d 100644 --- a/src/Blocks/BlockSugarcane.h +++ b/src/Blocks/BlockSugarcane.h @@ -73,7 +73,7 @@ public: } - void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { a_Chunk.GetWorld()->GrowSugarcane(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width, 1); } diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index aa29849b2..aa0d582b3 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -105,7 +105,7 @@ public: } - void Check(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override + void Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override { NIBBLETYPE CurMeta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); NIBBLETYPE MaxMeta = GetMaxMeta(a_Chunk, a_RelX, a_RelY, a_RelZ); @@ -128,7 +128,7 @@ public: { int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width; int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width; - DropBlock(a_Chunk.GetWorld(), NULL, BlockX, a_RelY, BlockZ); + DropBlock(a_ChunkInterface, *a_Chunk.GetWorld(), a_PluginInterface, NULL, BlockX, a_RelY, BlockZ); } a_Chunk.SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_AIR, 0); return; diff --git a/src/Chunk.cpp b/src/Chunk.cpp index b29c97084..b48bfe65e 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -31,7 +31,7 @@ #include "Simulator/FluidSimulator.h" #include "MobCensus.h" #include "MobSpawner.h" - +#include "BlockInServerPluginInterface.h" #include "json/json.h" @@ -638,7 +638,9 @@ void cChunk::TickBlock(int a_RelX, int a_RelY, int a_RelZ) unsigned Index = MakeIndex(a_RelX, a_RelY, a_RelZ); cBlockHandler * Handler = BlockHandler(m_BlockTypes[Index]); ASSERT(Handler != NULL); // Happenned on server restart, FS #243 - Handler->OnUpdate(*this, a_RelX, a_RelY, a_RelZ); + cChunkInterface ChunkInterface(this->GetWorld()->GetChunkMap()); + cBlockInServerPluginInterface PluginInterface(*this->GetWorld()); + Handler->OnUpdate(ChunkInterface, *this->GetWorld(), PluginInterface,*this, a_RelX, a_RelY, a_RelZ); } @@ -763,6 +765,7 @@ void cChunk::CheckBlocks() std::swap(m_ToTickBlocks, ToTickBlocks); cChunkInterface ChunkInterface(m_World->GetChunkMap()); + cBlockInServerPluginInterface PluginInterface(*m_World); for (std::vector::const_iterator itr = ToTickBlocks.begin(), end = ToTickBlocks.end(); itr != end; ++itr) { @@ -770,7 +773,7 @@ void cChunk::CheckBlocks() Vector3i BlockPos = IndexToCoordinate(index); cBlockHandler * Handler = BlockHandler(GetBlock(index)); - Handler->Check(ChunkInterface, BlockPos.x, BlockPos.y, BlockPos.z, *this); + Handler->Check(ChunkInterface, PluginInterface, BlockPos.x, BlockPos.y, BlockPos.z, *this); } // for itr - ToTickBlocks[] } @@ -788,6 +791,9 @@ void cChunk::TickBlocks(void) int TickX = m_BlockTickX; int TickY = m_BlockTickY; int TickZ = m_BlockTickZ; + + cChunkInterface ChunkInterface(this->GetWorld()->GetChunkMap()); + cBlockInServerPluginInterface PluginInterface(*this->GetWorld()); // This for loop looks disgusting, but it actually does a simple thing - first processes m_BlockTick, then adds random to it // This is so that SetNextBlockTick() works @@ -813,7 +819,7 @@ void cChunk::TickBlocks(void) unsigned int Index = MakeIndexNoCheck(m_BlockTickX, m_BlockTickY, m_BlockTickZ); cBlockHandler * Handler = BlockHandler(m_BlockTypes[Index]); ASSERT(Handler != NULL); // Happenned on server restart, FS #243 - Handler->OnUpdate(*this, m_BlockTickX, m_BlockTickY, m_BlockTickZ); + Handler->OnUpdate(ChunkInterface, *this->GetWorld(), PluginInterface, *this, m_BlockTickX, m_BlockTickY, m_BlockTickZ); } // for i - tickblocks } diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index c9a632580..f18a4d959 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -6,6 +6,7 @@ #include "../Simulator/FluidSimulator.h" #include "../Blocks/BlockHandler.h" #include "../LineBlockTracer.h" +#include "../BlockInServerPluginInterface.h" @@ -142,7 +143,9 @@ public: cBlockHandler * Handler = BlockHandler(CurrentBlock); if (Handler->DoesDropOnUnsuitable()) { - Handler->DropBlock(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ); + cChunkInterface ChunkInterface(a_World->GetChunkMap()); + cBlockInServerPluginInterface PluginInterface(*a_World); + Handler->DropBlock(ChunkInterface, *a_World, PluginInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ); } } diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 2b8b9f794..302796d1b 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -5,6 +5,7 @@ #include "../World.h" #include "../Entities/Player.h" #include "../FastRandom.h" +#include "../BlockInServerPluginInterface.h" // Handlers: #include "ItemBed.h" @@ -257,7 +258,9 @@ void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const { if (!BlockRequiresSpecialTool(Block) || CanHarvestBlock(Block)) { - Handler->DropBlock(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ); + cChunkInterface ChunkInterface(a_World->GetChunkMap()); + cBlockInServerPluginInterface PluginInterface(*a_World); + Handler->DropBlock(ChunkInterface, *a_World, PluginInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ); } } diff --git a/src/Items/ItemShovel.h b/src/Items/ItemShovel.h index d0625ef1c..4921b257a 100644 --- a/src/Items/ItemShovel.h +++ b/src/Items/ItemShovel.h @@ -6,6 +6,7 @@ #include "../Entities/Player.h" #include "../Blocks/BlockHandler.h" +#include "../BlockInServerPluginInterface.h" @@ -25,7 +26,9 @@ public: BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); if (Block == E_BLOCK_SNOW) { - BlockHandler(Block)->DropBlock(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ); + cChunkInterface ChunkInterface(a_World->GetChunkMap()); + cBlockInServerPluginInterface PluginInterface(*a_World); + BlockHandler(Block)->DropBlock(ChunkInterface,*a_World, PluginInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ); a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); a_Player->UseEquippedItem(); @@ -38,4 +41,4 @@ public: { return (a_BlockType == E_BLOCK_SNOW); } -}; \ No newline at end of file +}; diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 44ec14295..08e5e4315 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -5,6 +5,7 @@ #include "../World.h" #include "../BlockArea.h" #include "../Blocks/BlockHandler.h" +#include "../BlockInServerPluginInterface.h" @@ -150,7 +151,9 @@ void cVillager::HandleFarmerTryHarvestCrops() if (IsBlockFarmable(CropBlock) && m_World->GetBlockMeta(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z) == 0x7) { cBlockHandler * Handler = cBlockHandler::GetBlockHandler(CropBlock); - Handler->DropBlock(m_World, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); + cChunkInterface ChunkInterface(m_World->GetChunkMap()); + cBlockInServerPluginInterface PluginInterface(*m_World); + Handler->DropBlock(ChunkInterface, *m_World, PluginInterface, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_AIR, 0); m_ActionCountDown = 20; } diff --git a/src/Piston.cpp b/src/Piston.cpp index 75eeb5e98..5eb14451d 100644 --- a/src/Piston.cpp +++ b/src/Piston.cpp @@ -9,6 +9,7 @@ #include "World.h" #include "Server.h" #include "Blocks/BlockHandler.h" +#include "BlockInServerPluginInterface.h" @@ -90,7 +91,9 @@ void cPiston::ExtendPiston(int pistx, int pisty, int pistz) cBlockHandler * Handler = BlockHandler(currBlock); if (Handler->DoesDropOnUnsuitable()) { - Handler->DropBlock(m_World, NULL, pistx, pisty, pistz); + cChunkInterface ChunkInterface(m_World->GetChunkMap()); + cBlockInServerPluginInterface PluginInterface(*m_World); + Handler->DropBlock(ChunkInterface, *m_World, PluginInterface, NULL, pistx, pisty, pistz); } } diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp index fdc4643a8..95182345c 100644 --- a/src/Simulator/FloodyFluidSimulator.cpp +++ b/src/Simulator/FloodyFluidSimulator.cpp @@ -11,6 +11,7 @@ #include "../Chunk.h" #include "../BlockArea.h" #include "../Blocks/BlockHandler.h" +#include "../BlockInServerPluginInterface.h" @@ -273,8 +274,13 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i cBlockHandler * Handler = BlockHandler(BlockType); if (Handler->DoesDropOnUnsuitable()) { + cChunkInterface ChunkInterface(m_World.GetChunkMap()); + cBlockInServerPluginInterface PluginInterface(m_World); Handler->DropBlock( - &m_World, NULL, + ChunkInterface, + m_World, + PluginInterface, + NULL, a_NearChunk->GetPosX() * cChunkDef::Width + a_RelX, a_RelY, a_NearChunk->GetPosZ() * cChunkDef::Width + a_RelZ -- cgit v1.2.3 From 42497847acd65c34b67f4c6c2a16320ecbe19c65 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 2 Feb 2014 06:59:36 -0800 Subject: Added missing files --- src/BlockInServerPluginInterface.h | 19 +++++++++++++++++++ src/Blocks/BlockPluginInterface.h | 8 ++++++++ src/Blocks/ChunkInterface.cpp | 12 ++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/BlockInServerPluginInterface.h create mode 100644 src/Blocks/BlockPluginInterface.h create mode 100644 src/Blocks/ChunkInterface.cpp diff --git a/src/BlockInServerPluginInterface.h b/src/BlockInServerPluginInterface.h new file mode 100644 index 000000000..e82435364 --- /dev/null +++ b/src/BlockInServerPluginInterface.h @@ -0,0 +1,19 @@ + +#pragma once + +#include "Blocks/BlockPluginInterface.h" +#include "World.h" +#include "Root.h" +#include "Bindings/PluginManager.h" + +class cBlockInServerPluginInterface : public cBlockPluginInterface +{ +public: + cBlockInServerPluginInterface(cWorld & a_World) : m_World(a_World) {} + virtual bool CallHookBlockToPickups(cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) override + { + return cRoot::Get()->GetPluginManager()->CallHookBlockToPickups(&m_World, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_Pickups); + } +private: + cWorld & m_World; +}; diff --git a/src/Blocks/BlockPluginInterface.h b/src/Blocks/BlockPluginInterface.h new file mode 100644 index 000000000..7428c9a7a --- /dev/null +++ b/src/Blocks/BlockPluginInterface.h @@ -0,0 +1,8 @@ + +#pragma once + +class cBlockPluginInterface +{ +public: + virtual bool CallHookBlockToPickups(cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) = 0; +}; diff --git a/src/Blocks/ChunkInterface.cpp b/src/Blocks/ChunkInterface.cpp new file mode 100644 index 000000000..b2dda19f4 --- /dev/null +++ b/src/Blocks/ChunkInterface.cpp @@ -0,0 +1,12 @@ + +#include "Globals.h" + +#include "ChunkInterface.h" +#include "BlockHandler.h" + +bool cChunkInterface::DigBlock(cWorldInterface & a_WorldInterface, int a_X, int a_Y, int a_Z) +{ + cBlockHandler *Handler = cBlockHandler::GetBlockHandler(GetBlock(a_X, a_Y, a_Z)); + Handler->OnDestroyed(*this, a_WorldInterface, a_X, a_Y, a_Z); + return m_ChunkMap->DigBlock(a_X, a_Y, a_Z); +} -- cgit v1.2.3 From c3d4cc4f4f0dab5886e5bf5e0d127f4933cd55cb Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 2 Feb 2014 17:52:05 +0100 Subject: Fixed dark oak and acacia placement. Fixes #621. --- src/Blocks/BlockHandler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 3f69ba1c1..c16f255b8 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -165,6 +165,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_NETHER_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_NETHER_PORTAL: return new cBlockPortalHandler (a_BlockType); case E_BLOCK_NETHER_WART: return new cBlockNetherWartHandler (a_BlockType); + case E_BLOCK_NEW_LOG: return new cBlockWoodHandler (a_BlockType); case E_BLOCK_NOTE_BLOCK: return new cBlockNoteHandler (a_BlockType); case E_BLOCK_PISTON: return new cBlockPistonHandler (a_BlockType); case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler ( ); -- cgit v1.2.3 From 55cfb232db9d7bf15dfa0d2e0816b4651331e2fd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 19:10:22 +0000 Subject: Possibly fixed #618 --- src/World.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index 2571a6782..acfcf8e48 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1639,7 +1639,7 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_FlyAwaySpeed /= 100; // Pre-divide, so that we don't have to divide each time inside the loop for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) { - if (!IsValidItem(itr->m_ItemType)) + if (!IsValidItem(itr->m_ItemType) || itr->m_ItemType == E_BLOCK_AIR) { // Don't spawn pickup if item isn't even valid; should prevent client crashing too continue; @@ -1665,7 +1665,7 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double { for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) { - if (!IsValidItem(itr->m_ItemType)) + if (!IsValidItem(itr->m_ItemType) || itr->m_ItemType == E_BLOCK_AIR) { continue; } -- cgit v1.2.3 From e56d41175b7db000a87346bd1bb14f17ecc5a66a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 19:16:38 +0000 Subject: TNT improvements + Added entity damage + Added entity propulsion * Fixed #67 and fixed #230 --- src/BlockID.h | 1 + src/ChunkMap.cpp | 152 +++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 116 insertions(+), 37 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index b31c589b9..f53440ec8 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -801,6 +801,7 @@ enum eDamageType dtPotionOfHarming, dtEnderPearl, // Thrown an ender pearl, teleported by it dtAdmin, // Damage applied by an admin command + dtExplosion, // Damage applied by an explosion // Some common synonyms: dtPawnAttack = dtAttack, diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 5797eb453..e23a29a11 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -15,6 +15,9 @@ #include "Blocks/BlockHandler.h" #include "MobCensus.h" #include "MobSpawner.h" +#include "BoundingBox.h" + +#include "Entities/Pickup.h" #ifndef _WIN32 #include // abs @@ -1624,49 +1627,52 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ { return; } - + + bool ShouldDestroyBlocks = true; + // Don't explode if the explosion center is inside a liquid block: - switch (m_World->GetBlock((int)floor(a_BlockX), (int)floor(a_BlockY), (int)floor(a_BlockZ))) + if (IsBlockLiquid(m_World->GetBlock((int)floor(a_BlockX), (int)floor(a_BlockY), (int)floor(a_BlockZ)))) { - case E_BLOCK_WATER: - case E_BLOCK_STATIONARY_WATER: - case E_BLOCK_LAVA: - case E_BLOCK_STATIONARY_LAVA: - { - return; - } + ShouldDestroyBlocks = false; } - - cBlockArea area; + + int ExplosionSizeInt = (int)ceil(a_ExplosionSize); + int ExplosionSizeSq = ExplosionSizeInt * ExplosionSizeInt; + int bx = (int)floor(a_BlockX); int by = (int)floor(a_BlockY); int bz = (int)floor(a_BlockZ); - int ExplosionSizeInt = (int) ceil(a_ExplosionSize); - int ExplosionSizeSq = ExplosionSizeInt * ExplosionSizeInt; - a_BlocksAffected.reserve(8 * ExplosionSizeInt * ExplosionSizeInt * ExplosionSizeInt); + int MinY = std::max((int)floor(a_BlockY - ExplosionSizeInt), 0); int MaxY = std::min((int)ceil(a_BlockY + ExplosionSizeInt), cChunkDef::Height - 1); - area.Read(m_World, bx - ExplosionSizeInt, (int)ceil(a_BlockX + ExplosionSizeInt), MinY, MaxY, bz - ExplosionSizeInt, (int)ceil(a_BlockZ + ExplosionSizeInt)); - for (int x = -ExplosionSizeInt; x < ExplosionSizeInt; x++) + + if (ShouldDestroyBlocks) { - for (int y = -ExplosionSizeInt; y < ExplosionSizeInt; y++) + cBlockArea area; + + a_BlocksAffected.reserve(8 * ExplosionSizeInt * ExplosionSizeInt * ExplosionSizeInt); + + area.Read(m_World, bx - ExplosionSizeInt, (int)ceil(a_BlockX + ExplosionSizeInt), MinY, MaxY, bz - ExplosionSizeInt, (int)ceil(a_BlockZ + ExplosionSizeInt)); + for (int x = -ExplosionSizeInt; x < ExplosionSizeInt; x++) { - if ((by + y >= cChunkDef::Height) || (by + y < 0)) + for (int y = -ExplosionSizeInt; y < ExplosionSizeInt; y++) { - // Outside of the world - continue; - } - for (int z = -ExplosionSizeInt; z < ExplosionSizeInt; z++) - { - if ((x * x + y * y + z * z) > ExplosionSizeSq) + if ((by + y >= cChunkDef::Height) || (by + y < 0)) { - // Too far away + // Outside of the world continue; } - - BLOCKTYPE Block = area.GetBlockType(bx + x, by + y, bz + z); - switch (Block) + for (int z = -ExplosionSizeInt; z < ExplosionSizeInt; z++) { + if ((x * x + y * y + z * z) > ExplosionSizeSq) + { + // Too far away + continue; + } + + BLOCKTYPE Block = area.GetBlockType(bx + x, by + y, bz + z); + switch (Block) + { case E_BLOCK_TNT: { // Activate the TNT, with a random fuse between 10 to 30 game ticks @@ -1691,20 +1697,20 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_WATER); break; } - + case E_BLOCK_STATIONARY_LAVA: { // Turn into simulated lava: area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_LAVA); break; } - + case E_BLOCK_AIR: { // No pickups for air break; } - + default: { if (m_World->GetTickRandomNumber(100) <= 25) // 25% chance of pickups @@ -1713,16 +1719,88 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ cBlockHandler * Handler = BlockHandler(Block); Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc. - m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z); + //m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z); } area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR); a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z)); } - } // switch (BlockType) - } // for z - } // for y - } // for x - area.Write(m_World, bx - ExplosionSizeInt, MinY, bz - ExplosionSizeInt); + } // switch (BlockType) + } // for z + } // for y + } // for x + area.Write(m_World, bx - ExplosionSizeInt, MinY, bz - ExplosionSizeInt); + } + + class cTNTDamageCallback : + public cEntityCallback + { + public: + cTNTDamageCallback(cBoundingBox & a_bbTNT, Vector3d a_ExplosionPos, int a_ExplosionSize, int a_ExplosionSizeSq) : + m_bbTNT(a_bbTNT), + m_ExplosionPos(a_ExplosionPos), + m_ExplosionSize(a_ExplosionSize), + m_ExplosionSizeSq(a_ExplosionSizeSq) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + if (a_Entity->IsPickup()) + { + if (((cPickup *)a_Entity)->GetAge() < 20) // If pickup age is smaller than one second, it is invincible + { + return false; + } + } + + Vector3d EntityPos = a_Entity->GetPosition(); + cBoundingBox bbEntity(EntityPos, a_Entity->GetWidth() / 2, a_Entity->GetHeight()); + + if (m_bbTNT.IsInside(bbEntity)) // IsInside actually acts like DoesSurround + { + Vector3d AbsoluteEntityPos(abs(EntityPos.x), abs(EntityPos.y), abs(EntityPos.z)); + Vector3d MaxExplosionBoundary(m_ExplosionSizeSq, m_ExplosionSizeSq, m_ExplosionSizeSq); + + AbsoluteEntityPos -= m_ExplosionPos; + AbsoluteEntityPos = MaxExplosionBoundary - AbsoluteEntityPos; + + double FinalDamage = ((AbsoluteEntityPos.x + AbsoluteEntityPos.y + AbsoluteEntityPos.z) / 3) * m_ExplosionSize; + FinalDamage = a_Entity->GetMaxHealth() - abs(FinalDamage); + if (FinalDamage > a_Entity->GetMaxHealth()) + FinalDamage = a_Entity->GetMaxHealth(); + else if (FinalDamage < 0) + return false; + + if (!a_Entity->IsTNT()) + { + a_Entity->TakeDamage(dtExplosion, NULL, (int)FinalDamage, 0); + } + + Vector3d distance_explosion = a_Entity->GetPosition() - m_ExplosionPos; + if (distance_explosion.SqrLength() < 4096.0) + { + distance_explosion.Normalize(); + distance_explosion *= m_ExplosionSizeSq; + + a_Entity->AddSpeed(distance_explosion); + } + } + return false; + } + + protected: + cBoundingBox & m_bbTNT; + Vector3d m_ExplosionPos; + int m_ExplosionSize; + int m_ExplosionSizeSq; + }; + + cBoundingBox bbTNT(Vector3d(a_BlockX, a_BlockY, a_BlockZ), 0.5, 1); + bbTNT.Expand(ExplosionSizeInt * 2, ExplosionSizeInt * 2, ExplosionSizeInt * 2); + + + cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), a_ExplosionSize, ExplosionSizeSq); + ForEachEntity(TNTDamageCallback); // Wake up all simulators for the area, so that water and lava flows and sand falls into the blasted holes (FS #391): WakeUpSimulatorsInArea( -- cgit v1.2.3 From 5bf060f06c7ee2d7ffa6a86b2e15acc4d472a9da Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 20:09:15 +0000 Subject: Revert "Again improved LogReplaceLine" This reverts commit dd325d742db9db54a25460fcacd093e7cc6f44f0. --- src/Log.cpp | 156 +++++++++++++++++++++++++++++------------------------------- src/Log.h | 1 + 2 files changed, 77 insertions(+), 80 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index a1b4c784f..aa9f22f84 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -9,7 +9,7 @@ #ifdef __linux #include -#include +#include #endif // __linux @@ -24,7 +24,8 @@ cLog* cLog::s_Log = NULL; cLog::cLog(const AString & a_FileName ) - : m_File(NULL) + : m_File(NULL), + m_LastStringSize(0) { s_Log = this; @@ -114,22 +115,20 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) time(&rawtime); struct tm* timeinfo; - - #ifdef _MSC_VER - struct tm timeinforeal; - timeinfo = &timeinforeal; - localtime_s(timeinfo, &rawtime); - #else - timeinfo = localtime(&rawtime); - #endif +#ifdef _MSC_VER + struct tm timeinforeal; + timeinfo = &timeinforeal; + localtime_s(timeinfo, &rawtime); +#else + timeinfo = localtime(&rawtime); +#endif AString Line; - #ifdef _DEBUG - Printf(Line, "[%04x|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); - #else - Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); - #endif - +#ifdef _DEBUG + Printf(Line, "[%04x|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); +#else + Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); +#endif if (m_File) { fprintf(m_File, "%s\n", Line.c_str()); @@ -137,68 +136,67 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) } // Print to console: - #if defined(ANDROID_NDK) - //__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList); - __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str()); - //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); - #else - - size_t LineLength = Line.length(); - #ifdef _WIN32 - HANDLE Output = GetStdHandle(STD_OUTPUT_HANDLE); - - CONSOLE_SCREEN_BUFFER_INFO csbi; - GetConsoleScreenBufferInfo(Output, &csbi); // Obtain console window information - - if ((size_t)((csbi.srWindow.Right - csbi.srWindow.Left) + 1) < LineLength) // Will text overrun width? If so, do not do a replace operation - { - printf("\n%s", Line.c_str()); // We are at line to be replaced, but since we can't, print normally with a newline - return false; - } - - for (size_t X = 0; X != (size_t)(csbi.srWindow.Right - csbi.srWindow.Left); ++X) - { - fputs(" ", stdout); // Clear current line in preparation for new text - } - #else // _WIN32 - // Try to get console width; if text overruns, print normally with a newline - #ifdef TIOCGSIZE - struct ttysize ts; - ioctl(STDIN_FILENO, TIOCGSIZE, &ts); - - if (ts.ts_cols < LineLength) - { - printf("\n%s", Line.c_str()); - return false; - } - #elif defined(TIOCGWINSZ) - struct winsize ts; - ioctl(STDIN_FILENO, TIOCGWINSZ, &ts); - - if (ts.ws_col < LineLength) - { - printf("\n%s", Line.c_str()); - return false; - } - #else - printf("\n%s", Line.c_str()); - return false; - #endif - - fputs("\033[K", stdout); // Clear current line - #endif // Not _WIN32 - - printf("\r%s", Line.c_str()); - - #ifdef __linux - fputs("\033[1B", stdout); // Move down one line - #endif // __linux - #endif // ANDROID_NDK +#if defined(ANDROID_NDK) + //__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList); + __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str()); + //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); +#else +#ifdef _WIN32 + size_t LineLength = Line.length(); - #if defined (_WIN32) && defined(_DEBUG) - // In a Windows Debug build, output the log to debug console as well: - OutputDebugStringA((Line + "\n").c_str()); - #endif // _WIN32 + if (m_LastStringSize == 0) + m_LastStringSize = LineLength; // Initialise m_LastStringSize + + HANDLE Output = GetStdHandle(STD_OUTPUT_HANDLE); + + CONSOLE_SCREEN_BUFFER_INFO csbi; + GetConsoleScreenBufferInfo(Output, &csbi); + + if ((size_t)((csbi.srWindow.Right - csbi.srWindow.Left) + 1) < LineLength) + { + printf("\n%s", Line.c_str()); // We are at line to be replaced, but since we can't, add a new line + return false; + } + + if (LineLength < m_LastStringSize) // If last printed line was longer than current, clear this line + { + for (size_t X = 0; X != m_LastStringSize + 1; ++X) + { + fputs(" ", stdout); + } + } +#else // _WIN32 + struct ttysize ts; +#ifdef TIOCGSIZE + ioctl(STDIN_FILENO, TIOCGSIZE, &ts); + if (ts.ts_cols < LineLength) + { + return false; + } +#elif defined(TIOCGWINSZ) + ioctl(STDIN_FILENO, TIOCGWINSZ, &ts); + if (ts.ts_cols < LineLength) + { + return false; + } +#else /* TIOCGSIZE */ + return false; +#endif + fputs("\033[K", stdout); // Clear current line +#endif + printf("\r%s", Line.c_str()); +#ifdef __linux + fputs("\033[1B", stdout); // Move down one line +#endif // __linux + + m_LastStringSize = LineLength; + +#endif // ANDROID_NDK + +#if defined (_WIN32) && defined(_DEBUG) + // In a Windows Debug build, output the log to debug console as well: + OutputDebugStringA((Line + "\n").c_str()); +#endif // _WIN32 return true; } @@ -243,9 +241,7 @@ void cLog::Log(const char * a_Format, va_list argList) __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str() ); //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); #else - // If something requests the current line to be rewritten (LogReplaceLine), on Linux it clears the current line, but that moves the cursor to the end of that line, so we reset it here (\r) - // Doesn't affect anything normally - cursor should already be at beginning of line - printf("\r%s", Line.c_str()); + printf("%s", Line.c_str()); #endif #if defined (_WIN32) && defined(_DEBUG) diff --git a/src/Log.h b/src/Log.h index 6944edd88..c9ca17864 100644 --- a/src/Log.h +++ b/src/Log.h @@ -11,6 +11,7 @@ private: FILE * m_File; static cLog * s_Log; + size_t m_LastStringSize; public: -- cgit v1.2.3 From a0242afec23ed0f3328410e6d2d6336ec61a5d51 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 20:09:35 +0000 Subject: Revert "Another Linux fix" This reverts commit 6f660b379ecbc091b9bd92093e0dad01a4f6bf38. --- src/Log.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index aa9f22f84..44dab33c9 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -7,12 +7,6 @@ #include #include "OSSupport/IsThread.h" -#ifdef __linux -#include -#include -#endif // __linux - - #if defined(ANDROID_NDK) #include #include "ToJava.h" -- cgit v1.2.3 From 070962fb8a09e86a26fe6f1d517ff94787675489 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 20:09:40 +0000 Subject: Revert "Fixed Linux compile" This reverts commit 5becfe850a2b4827a21e8ede989545334efbbead. --- src/Log.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index 44dab33c9..b246e8196 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -135,7 +135,6 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str()); //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); #else -#ifdef _WIN32 size_t LineLength = Line.length(); if (m_LastStringSize == 0) @@ -151,7 +150,7 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) printf("\n%s", Line.c_str()); // We are at line to be replaced, but since we can't, add a new line return false; } - +#ifdef _WIN32 if (LineLength < m_LastStringSize) // If last printed line was longer than current, clear this line { for (size_t X = 0; X != m_LastStringSize + 1; ++X) -- cgit v1.2.3 From e4b666989d67b9ec824fe0ac9f7c4f880486d72b Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 20:09:47 +0000 Subject: Revert "A newline issue is resolved" This reverts commit 397208145ebe5c95ebf32f2985f6800634932230. --- src/Log.cpp | 2 +- src/MCLogger.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Log.cpp b/src/Log.cpp index b246e8196..e7d3e0629 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -147,7 +147,7 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) if ((size_t)((csbi.srWindow.Right - csbi.srWindow.Left) + 1) < LineLength) { - printf("\n%s", Line.c_str()); // We are at line to be replaced, but since we can't, add a new line + printf("\r%s", Line.c_str()); return false; } #ifdef _WIN32 diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index 11fd451a7..0828b7fe4 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -150,6 +150,7 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla if (!m_Log->LogReplaceLine(a_Format, a_ArgList)) { m_BeginLineUpdate = false; + puts(""); } ResetColor(); @@ -161,6 +162,7 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla if (!m_Log->LogReplaceLine(a_Format, a_ArgList)) { m_BeginLineUpdate = false; + puts(""); } ResetColor(); #endif -- cgit v1.2.3 From dd3cc733ae882d029eaab093113783fb1c91113a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 20:09:56 +0000 Subject: Revert "Fixed issues with insufficient console space" This reverts commit 6b18add09b5e9d6d6c2a61e90bdd7011f56f4c82. --- src/Log.cpp | 118 ++++++++++++------------------------------------------- src/Log.h | 11 +----- src/MCLogger.cpp | 14 ++----- 3 files changed, 29 insertions(+), 114 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index e7d3e0629..3938f2c24 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -100,29 +100,29 @@ void cLog::ClearLog() -bool cLog::LogReplaceLine(const char * a_Format, va_list argList) +void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine) { AString Message; AppendVPrintf(Message, a_Format, argList); time_t rawtime; - time(&rawtime); - + time ( &rawtime ); + struct tm* timeinfo; #ifdef _MSC_VER struct tm timeinforeal; timeinfo = &timeinforeal; - localtime_s(timeinfo, &rawtime); + localtime_s(timeinfo, &rawtime ); #else - timeinfo = localtime(&rawtime); + timeinfo = localtime( &rawtime ); #endif AString Line; -#ifdef _DEBUG + #ifdef _DEBUG Printf(Line, "[%04x|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); -#else + #else Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); -#endif + #endif if (m_File) { fprintf(m_File, "%s\n", Line.c_str()); @@ -132,7 +132,7 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) // Print to console: #if defined(ANDROID_NDK) //__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList); - __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str()); + __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str() ); //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); #else size_t LineLength = Line.length(); @@ -140,103 +140,35 @@ bool cLog::LogReplaceLine(const char * a_Format, va_list argList) if (m_LastStringSize == 0) m_LastStringSize = LineLength; // Initialise m_LastStringSize - HANDLE Output = GetStdHandle(STD_OUTPUT_HANDLE); - - CONSOLE_SCREEN_BUFFER_INFO csbi; - GetConsoleScreenBufferInfo(Output, &csbi); - - if ((size_t)((csbi.srWindow.Right - csbi.srWindow.Left) + 1) < LineLength) + if (a_ReplaceCurrentLine) { - printf("\r%s", Line.c_str()); - return false; - } #ifdef _WIN32 - if (LineLength < m_LastStringSize) // If last printed line was longer than current, clear this line - { - for (size_t X = 0; X != m_LastStringSize + 1; ++X) + if (LineLength < m_LastStringSize) // If last printed line was longer than current, clear this line { - fputs(" ", stdout); + for (size_t X = 0; X != m_LastStringSize; ++X) + { + fputs(" ", stdout); + } } - } #else // _WIN32 - struct ttysize ts; -#ifdef TIOCGSIZE - ioctl(STDIN_FILENO, TIOCGSIZE, &ts); - if (ts.ts_cols < LineLength) - { - return false; - } -#elif defined(TIOCGWINSZ) - ioctl(STDIN_FILENO, TIOCGWINSZ, &ts); - if (ts.ts_cols < LineLength) - { - return false; - } -#else /* TIOCGSIZE */ - return false; + fputs("\033[K", stdout); // Clear current line #endif - fputs("\033[K", stdout); // Clear current line -#endif - printf("\r%s", Line.c_str()); + + printf("\r%s", Line.c_str()); + #ifdef __linux - fputs("\033[1B", stdout); // Move down one line + fputs("\033[1B", stdout); // Move down one line #endif // __linux + } + else + { + printf("%s", Line.c_str()); + } m_LastStringSize = LineLength; -#endif // ANDROID_NDK - -#if defined (_WIN32) && defined(_DEBUG) - // In a Windows Debug build, output the log to debug console as well: - OutputDebugStringA((Line + "\n").c_str()); -#endif // _WIN32 - - return true; -} - - - - - -void cLog::Log(const char * a_Format, va_list argList) -{ - AString Message; - AppendVPrintf(Message, a_Format, argList); - - time_t rawtime; - time ( &rawtime ); - - struct tm* timeinfo; -#ifdef _MSC_VER - struct tm timeinforeal; - timeinfo = &timeinforeal; - localtime_s(timeinfo, &rawtime ); -#else - timeinfo = localtime( &rawtime ); #endif - AString Line; - #ifdef _DEBUG - Printf(Line, "[%04x|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); - #else - Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); - #endif - - if (m_File) - { - fprintf(m_File, "%s\n", Line.c_str()); - fflush(m_File); - } - - // Print to console: - #if defined(ANDROID_NDK) - //__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList); - __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str() ); - //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); - #else - printf("%s", Line.c_str()); - #endif - #if defined (_WIN32) && defined(_DEBUG) // In a Windows Debug build, output the log to debug console as well: OutputDebugStringA((Line + "\n").c_str()); diff --git a/src/Log.h b/src/Log.h index c9ca17864..8a0ee9fc7 100644 --- a/src/Log.h +++ b/src/Log.h @@ -8,29 +8,20 @@ class cLog { // tolua_export private: - FILE * m_File; static cLog * s_Log; size_t m_LastStringSize; - public: - cLog(const AString & a_FileName); ~cLog(); - - /** Replaces current line of console with given text. - Returns true if successful, false if not (screen too narrow etc.) */ - bool LogReplaceLine(const char * a_Format, va_list argList); - void Log(const char * a_Format, va_list argList); + void Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine = false); void Log(const char * a_Format, ...); - // tolua_begin void SimpleLog(const char * a_String); void OpenLog(const char * a_FileName); void CloseLog(); void ClearLog(); static cLog* GetInstance(); - }; // tolua_end diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index 0828b7fe4..b7b826374 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -147,11 +147,7 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla SetConsoleCursorPosition(Output, Position); SetColor(csRegular); - if (!m_Log->LogReplaceLine(a_Format, a_ArgList)) - { - m_BeginLineUpdate = false; - puts(""); - } + m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); ResetColor(); Position = { 0, csbi.dwCursorPosition.Y }; // Set cursor to original position @@ -159,18 +155,14 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla #else // _WIN32 fputs("\033[1A", stdout); // Move cursor up one line SetColor(csRegular); - if (!m_Log->LogReplaceLine(a_Format, a_ArgList)) - { - m_BeginLineUpdate = false; - puts(""); - } + m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); ResetColor(); #endif } else { SetColor(csRegular); - m_Log->Log(a_Format, a_ArgList); + m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); ResetColor(); puts(""); } -- cgit v1.2.3 From ecbb9134a5e4c631fc10cb9251d0d18de80d6b36 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 20:10:02 +0000 Subject: Revert "Properly initialised variables" This reverts commit 02e752789399ad1b65a0443534ea6a8721efd78c. --- src/Log.cpp | 3 +-- src/Log.h | 2 +- src/MCLogger.cpp | 14 ++++++++------ src/MCLogger.h | 4 ---- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index 3938f2c24..cbb83097c 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -18,8 +18,7 @@ cLog* cLog::s_Log = NULL; cLog::cLog(const AString & a_FileName ) - : m_File(NULL), - m_LastStringSize(0) + : m_File(NULL) { s_Log = this; diff --git a/src/Log.h b/src/Log.h index 8a0ee9fc7..c8c26913b 100644 --- a/src/Log.h +++ b/src/Log.h @@ -10,7 +10,7 @@ class cLog private: FILE * m_File; static cLog * s_Log; - size_t m_LastStringSize; + size_t m_LastStringSize = 0; public: cLog(const AString & a_FileName); ~cLog(); diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index b7b826374..aebe3e1c9 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -11,6 +11,10 @@ cMCLogger * cMCLogger::s_MCLogger = NULL; bool g_ShouldColorOutput = false; +/** Flag to show whether a 'replace line' log command has been issued +Used to decide when to put a newline */ +bool g_BeginLineUpdate = false; + #ifdef _WIN32 #include // Needed for _isatty(), not available on Linux @@ -34,7 +38,6 @@ cMCLogger * cMCLogger::GetInstance(void) cMCLogger::cMCLogger(void) - : m_BeginLineUpdate(false) { AString FileName; Printf(FileName, "LOG_%d.txt", (int)time(NULL)); @@ -46,7 +49,6 @@ cMCLogger::cMCLogger(void) cMCLogger::cMCLogger(const AString & a_FileName) - : m_BeginLineUpdate(false) { InitLog(a_FileName); } @@ -125,14 +127,14 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla { cCSLock Lock(m_CriticalSection); - if (!m_BeginLineUpdate && a_ShouldReplaceLine) + if (!g_BeginLineUpdate && a_ShouldReplaceLine) { a_ShouldReplaceLine = false; // Print a normal line first if this is the initial replace line - m_BeginLineUpdate = true; + g_BeginLineUpdate = true; } - else if (m_BeginLineUpdate && !a_ShouldReplaceLine) + else if (g_BeginLineUpdate && !a_ShouldReplaceLine) { - m_BeginLineUpdate = false; + g_BeginLineUpdate = false; } if (a_ShouldReplaceLine) diff --git a/src/MCLogger.h b/src/MCLogger.h index 4550cc55d..c105ab6e2 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -51,10 +51,6 @@ private: /// Common initialization for all constructors, creates a logfile with the specified name and assigns s_MCLogger to this void InitLog(const AString & a_FileName); - - /** Flag to show whether a 'replace line' log command has been issued - Used to decide when to put a newline */ - bool m_BeginLineUpdate; }; // tolua_export -- cgit v1.2.3 From f4c25ac445c95502ae95a0023fc67f3aa394d594 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 20:10:13 +0000 Subject: Revert "Added a comment" This reverts commit 7ae5631d89426df6f05b6c8ba656ba02b9d15f93. --- src/Log.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Log.cpp b/src/Log.cpp index cbb83097c..37f1376db 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -137,7 +137,7 @@ void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine size_t LineLength = Line.length(); if (m_LastStringSize == 0) - m_LastStringSize = LineLength; // Initialise m_LastStringSize + m_LastStringSize = LineLength; if (a_ReplaceCurrentLine) { -- cgit v1.2.3 From 6ef5c057aa2a36dbd54f56780e5700e753b37bcf Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 20:10:23 +0000 Subject: Revert "Improved code" This reverts commit d8aa0b0ec7a2ebea2fc157c623ae8cd7d0b6ba1c. --- src/Log.cpp | 14 +++++--------- src/MCLogger.cpp | 12 ++++-------- src/MCLogger.h | 4 ++++ src/World.cpp | 2 -- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index 37f1376db..a23a79ccc 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -134,15 +134,14 @@ void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str() ); //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); #else - size_t LineLength = Line.length(); - - if (m_LastStringSize == 0) - m_LastStringSize = LineLength; - if (a_ReplaceCurrentLine) { #ifdef _WIN32 - if (LineLength < m_LastStringSize) // If last printed line was longer than current, clear this line + if (m_LastStringSize == 0) + { + m_LastStringSize = Line.length(); + } + else if (Line.length() < m_LastStringSize) // If last printed line was longer than current, clear this line { for (size_t X = 0; X != m_LastStringSize; ++X) { @@ -163,9 +162,6 @@ void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine { printf("%s", Line.c_str()); } - - m_LastStringSize = LineLength; - #endif #if defined (_WIN32) && defined(_DEBUG) diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index aebe3e1c9..632ea2efe 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -11,10 +11,6 @@ cMCLogger * cMCLogger::s_MCLogger = NULL; bool g_ShouldColorOutput = false; -/** Flag to show whether a 'replace line' log command has been issued -Used to decide when to put a newline */ -bool g_BeginLineUpdate = false; - #ifdef _WIN32 #include // Needed for _isatty(), not available on Linux @@ -127,14 +123,14 @@ void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldRepla { cCSLock Lock(m_CriticalSection); - if (!g_BeginLineUpdate && a_ShouldReplaceLine) + if (!m_BeginLineUpdate && a_ShouldReplaceLine) { a_ShouldReplaceLine = false; // Print a normal line first if this is the initial replace line - g_BeginLineUpdate = true; + m_BeginLineUpdate = true; } - else if (g_BeginLineUpdate && !a_ShouldReplaceLine) + else if (m_BeginLineUpdate && !a_ShouldReplaceLine) { - g_BeginLineUpdate = false; + m_BeginLineUpdate = false; } if (a_ShouldReplaceLine) diff --git a/src/MCLogger.h b/src/MCLogger.h index c105ab6e2..7bcc195dd 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -51,6 +51,10 @@ private: /// Common initialization for all constructors, creates a logfile with the specified name and assigns s_MCLogger to this void InitLog(const AString & a_FileName); + + /** Flag to show whether a 'replace line' log command has been issued + Used to decide when to put a newline */ + bool m_BeginLineUpdate = false; }; // tolua_export diff --git a/src/World.cpp b/src/World.cpp index acfcf8e48..5cd3e1478 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -111,7 +111,6 @@ protected: cSleep::MilliSleep(100); if (m_ShouldTerminate) { - LOGREPLACELINE("World successfully loaded!"); return; } } @@ -162,7 +161,6 @@ protected: cSleep::MilliSleep(100); if (m_ShouldTerminate) { - LOGREPLACELINE("Lighting successful!"); return; } } -- cgit v1.2.3 From d9a9052de733d88e49a2df9f455632c64f2c5b5d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 20:10:31 +0000 Subject: Revert "Added LOGREPLACELINE for line replacement" This reverts commit 7d03876a3e11aedff0201a8330bfdb2b5523fc5e. --- src/Log.cpp | 31 ++---------------------------- src/Log.h | 4 ++-- src/MCLogger.cpp | 58 ++++++-------------------------------------------------- src/MCLogger.h | 7 +------ src/World.cpp | 10 +++++----- 5 files changed, 16 insertions(+), 94 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index a23a79ccc..2d6be0f59 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -99,7 +99,7 @@ void cLog::ClearLog() -void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine) +void cLog::Log(const char * a_Format, va_list argList) { AString Message; AppendVPrintf(Message, a_Format, argList); @@ -134,34 +134,7 @@ void cLog::Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str() ); //CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line ); #else - if (a_ReplaceCurrentLine) - { -#ifdef _WIN32 - if (m_LastStringSize == 0) - { - m_LastStringSize = Line.length(); - } - else if (Line.length() < m_LastStringSize) // If last printed line was longer than current, clear this line - { - for (size_t X = 0; X != m_LastStringSize; ++X) - { - fputs(" ", stdout); - } - } -#else // _WIN32 - fputs("\033[K", stdout); // Clear current line -#endif - - printf("\r%s", Line.c_str()); - -#ifdef __linux - fputs("\033[1B", stdout); // Move down one line -#endif // __linux - } - else - { - printf("%s", Line.c_str()); - } + printf("%s", Line.c_str()); #endif #if defined (_WIN32) && defined(_DEBUG) diff --git a/src/Log.h b/src/Log.h index c8c26913b..cba248dae 100644 --- a/src/Log.h +++ b/src/Log.h @@ -10,11 +10,11 @@ class cLog private: FILE * m_File; static cLog * s_Log; - size_t m_LastStringSize = 0; + public: cLog(const AString & a_FileName); ~cLog(); - void Log(const char * a_Format, va_list argList, bool a_ReplaceCurrentLine = false); + void Log(const char * a_Format, va_list argList); void Log(const char * a_Format, ...); // tolua_begin void SimpleLog(const char * a_String); diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index 632ea2efe..4f3e5dc0f 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -119,51 +119,13 @@ void cMCLogger::LogSimple(const char* a_Text, int a_LogType /* = 0 */ ) -void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldReplaceLine) +void cMCLogger::Log(const char * a_Format, va_list a_ArgList) { cCSLock Lock(m_CriticalSection); - - if (!m_BeginLineUpdate && a_ShouldReplaceLine) - { - a_ShouldReplaceLine = false; // Print a normal line first if this is the initial replace line - m_BeginLineUpdate = true; - } - else if (m_BeginLineUpdate && !a_ShouldReplaceLine) - { - m_BeginLineUpdate = false; - } - - if (a_ShouldReplaceLine) - { -#ifdef _WIN32 - HANDLE Output = GetStdHandle(STD_OUTPUT_HANDLE); - - CONSOLE_SCREEN_BUFFER_INFO csbi; - GetConsoleScreenBufferInfo(Output, &csbi); - - COORD Position = { 0, csbi.dwCursorPosition.Y - 1 }; // Move cursor up one line - SetConsoleCursorPosition(Output, Position); - - SetColor(csRegular); - m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); - ResetColor(); - - Position = { 0, csbi.dwCursorPosition.Y }; // Set cursor to original position - SetConsoleCursorPosition(Output, Position); -#else // _WIN32 - fputs("\033[1A", stdout); // Move cursor up one line - SetColor(csRegular); - m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); - ResetColor(); -#endif - } - else - { - SetColor(csRegular); - m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine); - ResetColor(); - puts(""); - } + SetColor(csRegular); + m_Log->Log(a_Format, a_ArgList); + ResetColor(); + puts(""); } @@ -226,7 +188,7 @@ void cMCLogger::SetColor(eColorScheme a_Scheme) default: ASSERT(!"Unhandled color scheme"); } SetConsoleTextAttribute(g_Console, Attrib); - #elif (defined(__linux) || defined(__apple)) && !defined(ANDROID_NDK) + #elif defined(__linux) && !defined(ANDROID_NDK) switch (a_Scheme) { case csRegular: printf("\x1b[0m"); break; // Whatever the console default is @@ -262,14 +224,6 @@ void cMCLogger::ResetColor(void) ////////////////////////////////////////////////////////////////////////// // Global functions -void LOGREPLACELINE(const char* a_Format, ...) -{ - va_list argList; - va_start(argList, a_Format); - cMCLogger::GetInstance()->Log(a_Format, argList, true); - va_end(argList); -} - void LOG(const char* a_Format, ...) { va_list argList; diff --git a/src/MCLogger.h b/src/MCLogger.h index 7bcc195dd..c949a4cdf 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -21,7 +21,7 @@ public: // tolua_export ~cMCLogger(); // tolua_export - void Log(const char* a_Format, va_list a_ArgList, bool a_ShouldReplaceLine = false); + void Log(const char* a_Format, va_list a_ArgList); void Info(const char* a_Format, va_list a_ArgList); void Warn(const char* a_Format, va_list a_ArgList); void Error(const char* a_Format, va_list a_ArgList); @@ -51,17 +51,12 @@ private: /// Common initialization for all constructors, creates a logfile with the specified name and assigns s_MCLogger to this void InitLog(const AString & a_FileName); - - /** Flag to show whether a 'replace line' log command has been issued - Used to decide when to put a newline */ - bool m_BeginLineUpdate = false; }; // tolua_export -extern void LOGREPLACELINE(const char* a_Format, ...); extern void LOG(const char* a_Format, ...); extern void LOGINFO(const char* a_Format, ...); extern void LOGWARN(const char* a_Format, ...); diff --git a/src/World.cpp b/src/World.cpp index 5cd3e1478..f598874ea 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -100,13 +100,13 @@ protected: { for (;;) { - LOGREPLACELINE("%d chunks to load, %d chunks to generate", + LOG("%d chunks to load, %d chunks to generate", m_World->GetStorage().GetLoadQueueLength(), m_World->GetGenerator().GetQueueLength() ); - // Wait for 0.5 sec, but be "reasonably wakeable" when the thread is to finish - for (int i = 0; i < 5; i++) + // Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish + for (int i = 0; i < 20; i++) { cSleep::MilliSleep(100); if (m_ShouldTerminate) @@ -152,10 +152,10 @@ protected: { for (;;) { - LOGREPLACELINE("%d chunks remaining to light", m_Lighting->GetQueueLength() + LOG("%d chunks remaining to light", m_Lighting->GetQueueLength() ); - // Wait for 0.5 sec, but be "reasonably wakeable" when the thread is to finish + // Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish for (int i = 0; i < 20; i++) { cSleep::MilliSleep(100); -- cgit v1.2.3 From ba398c06d78f6e11e7ac322e5ef46df4a91b5776 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 21:24:06 +0000 Subject: Uncommented pickup spawner code --- src/ChunkMap.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index e23a29a11..53e5b956b 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1719,7 +1719,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ cBlockHandler * Handler = BlockHandler(Block); Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc. - //m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z); + m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z); } area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR); a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z)); @@ -1747,7 +1747,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ { if (a_Entity->IsPickup()) { - if (((cPickup *)a_Entity)->GetAge() < 20) // If pickup age is smaller than one second, it is invincible + if (((cPickup *)a_Entity)->GetAge() < 20) // If pickup age is smaller than one second, it is invincible (so we don't kill pickups that were just spawned) { return false; } @@ -1761,21 +1761,25 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ Vector3d AbsoluteEntityPos(abs(EntityPos.x), abs(EntityPos.y), abs(EntityPos.z)); Vector3d MaxExplosionBoundary(m_ExplosionSizeSq, m_ExplosionSizeSq, m_ExplosionSizeSq); + // Work out how far we are from the edge of the TNT's explosive effect AbsoluteEntityPos -= m_ExplosionPos; AbsoluteEntityPos = MaxExplosionBoundary - AbsoluteEntityPos; double FinalDamage = ((AbsoluteEntityPos.x + AbsoluteEntityPos.y + AbsoluteEntityPos.z) / 3) * m_ExplosionSize; FinalDamage = a_Entity->GetMaxHealth() - abs(FinalDamage); + + // Clip damage values if (FinalDamage > a_Entity->GetMaxHealth()) FinalDamage = a_Entity->GetMaxHealth(); else if (FinalDamage < 0) return false; - if (!a_Entity->IsTNT()) + if (!a_Entity->IsTNT()) // Don't apply damage to other TNT entities, they should be invincible { a_Entity->TakeDamage(dtExplosion, NULL, (int)FinalDamage, 0); } + // Apply force to entities around the explosion - code modified from World.cpp DoExplosionAt() Vector3d distance_explosion = a_Entity->GetPosition() - m_ExplosionPos; if (distance_explosion.SqrLength() < 4096.0) { -- cgit v1.2.3 From 0f67f80c6e60b2696bf94ee91330cdc0cefde3fa Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 21:48:21 +0000 Subject: Added IsBlockWaterOrIce() --- src/Defines.h | 20 +++++++++++--------- src/World.cpp | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Defines.h b/src/Defines.h index b3dbcc93e..5b868b2e5 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -254,16 +254,18 @@ inline bool IsValidItem(int a_ItemType) -inline bool IsBlockWater(BLOCKTYPE a_BlockType, bool a_IncludeFrozenWater = false) +inline bool IsBlockWater(BLOCKTYPE a_BlockType) { - if (a_IncludeFrozenWater) - { - return ((a_BlockType == E_BLOCK_WATER) || (a_BlockType == E_BLOCK_STATIONARY_WATER) || (a_BlockType == E_BLOCK_ICE)); - } - else - { - return ((a_BlockType == E_BLOCK_WATER) || (a_BlockType == E_BLOCK_STATIONARY_WATER)); - } + return ((a_BlockType == E_BLOCK_WATER) || (a_BlockType == E_BLOCK_STATIONARY_WATER)); +} + + + + + +inline bool IsBlockWaterOrIce(BLOCKTYPE a_BlockType) +{ + return (IsBlockWater(a_BlockType) || (a_BlockType == E_BLOCK_ICE)); } diff --git a/src/World.cpp b/src/World.cpp index f598874ea..d8850e78a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -633,7 +633,7 @@ void cWorld::GenerateRandomSpawn(void) { LOGD("Generating random spawnpoint..."); - while (IsBlockWater(GetBlock((int)m_SpawnX, GetHeight((int)m_SpawnX, (int)m_SpawnZ), (int)m_SpawnZ), true)) + while (IsBlockWaterOrIce(GetBlock((int)m_SpawnX, GetHeight((int)m_SpawnX, (int)m_SpawnZ), (int)m_SpawnZ))) { if ((GetTickRandomNumber(4) % 2) == 0) // Randomise whether to increment X or Z coords { -- cgit v1.2.3 From ac03c5199749ef007d4ad4cb88467327225c5ff1 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 22:08:57 +0000 Subject: Fixed #624 --- src/BlockID.cpp | 1 + src/Blocks/BlockChest.h | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/BlockID.cpp b/src/BlockID.cpp index fbb5a0720..de56d4625 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -793,6 +793,7 @@ public: g_BlockIsSolid[E_BLOCK_WOODEN_SLAB] = false; // Torch placeable blocks: + g_BlockFullyOccupiesVoxel[E_BLOCK_NEW_LOG] = true; g_BlockFullyOccupiesVoxel[E_BLOCK_BEDROCK] = true; g_BlockFullyOccupiesVoxel[E_BLOCK_BLOCK_OF_COAL] = true; g_BlockFullyOccupiesVoxel[E_BLOCK_BLOCK_OF_REDSTONE] = true; diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 88f7c4b32..561e9bc8c 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -216,6 +216,12 @@ public: a_World->SetBlockMeta(a_Area.GetOriginX() + a_RelX, a_Area.GetOriginY(), a_Area.GetOriginZ() + a_RelZ, a_NewMeta); return true; } + + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + a_Pickups.push_back(cItem(E_BLOCK_CHEST, 1, 0)); + } } ; -- cgit v1.2.3 From c1c7936c6874adcba45d6e31eeafba9a92aaaedd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 22:55:41 +0000 Subject: Fixed multiple invalid permission nodes New players can build as default now --- src/GroupManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 792acc2c3..497f98c93 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -58,11 +58,11 @@ cGroupManager::cGroupManager() IniFile.SetValue("Moderator", "Color", "2", true); IniFile.SetValue("Moderator", "Inherits", "Player", true); - IniFile.SetValue("Player", "Permissions", "core.build", true); + IniFile.SetValue("Player", "Permissions", "core.portal", true); IniFile.SetValue("Player", "Color", "f", true); IniFile.SetValue("Player", "Inherits", "Default", true); - IniFile.SetValue("Default", "Permissions", "core.help,core.playerlist,core.pluginlist,core.spawn,core.listworlds,core.back,core.motd,core.gotoworld,core.coords,core.viewdistance", true); + IniFile.SetValue("Default", "Permissions", "core.help,core.plugins,core.spawn,core.worlds,core.back,core.motd,core.build,core.locate,core.viewdistance", true); IniFile.SetValue("Default", "Color", "f", true); IniFile.WriteFile("groups.ini"); -- cgit v1.2.3 From c2c1639af8f9db9bdd0f720c0e748c98d2835b5c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 2 Feb 2014 22:43:39 +0100 Subject: Groups.ini can contain spaces around commas in values. This includes Permissions, Inherits and Commands. Also fixed an unlikely but possible crash with group colors. --- src/GroupManager.cpp | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 497f98c93..d5567d91e 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -69,47 +69,51 @@ cGroupManager::cGroupManager() } unsigned int NumKeys = IniFile.GetNumKeys(); - for( unsigned int i = 0; i < NumKeys; i++ ) + for (size_t i = 0; i < NumKeys; i++) { std::string KeyName = IniFile.GetKeyName( i ); cGroup* Group = GetGroup( KeyName.c_str() ); LOGD("Loading group: %s", KeyName.c_str() ); - Group->SetName( KeyName ); - char Color = IniFile.GetValue( KeyName, "Color", "-" )[0]; - if( Color != '-' ) - Group->SetColor( cChatColor::Color + Color ); + Group->SetName(KeyName); + AString Color = IniFile.GetValue(KeyName, "Color", "-"); + if ((Color != "-") && (Color.length() >= 1)) + { + Group->SetColor(cChatColor::Color + Color[0]); + } else - Group->SetColor( cChatColor::White ); + { + Group->SetColor(cChatColor::White); + } - AString Commands = IniFile.GetValue( KeyName, "Commands", "" ); - if( Commands.size() > 0 ) + AString Commands = IniFile.GetValue(KeyName, "Commands", ""); + if (!Commands.empty()) { - AStringVector Split = StringSplit( Commands, "," ); - for( unsigned int i = 0; i < Split.size(); i++) + AStringVector Split = StringSplitAndTrim(Commands, ","); + for (size_t i = 0; i < Split.size(); i++) { - Group->AddCommand( Split[i] ); + Group->AddCommand(Split[i]); } } - AString Permissions = IniFile.GetValue( KeyName, "Permissions", "" ); - if( Permissions.size() > 0 ) + AString Permissions = IniFile.GetValue(KeyName, "Permissions", ""); + if (!Permissions.empty()) { - AStringVector Split = StringSplit( Permissions, "," ); - for( unsigned int i = 0; i < Split.size(); i++) + AStringVector Split = StringSplitAndTrim(Permissions, ","); + for (size_t i = 0; i < Split.size(); i++) { - Group->AddPermission( Split[i] ); + Group->AddPermission(Split[i]); } } - std::string Groups = IniFile.GetValue( KeyName, "Inherits", "" ); - if( Groups.size() > 0 ) + std::string Groups = IniFile.GetValue(KeyName, "Inherits", ""); + if (!Groups.empty()) { - AStringVector Split = StringSplit( Groups, "," ); - for( unsigned int i = 0; i < Split.size(); i++) + AStringVector Split = StringSplitAndTrim(Groups, ","); + for (size_t i = 0; i < Split.size(); i++) { - Group->InheritFrom( GetGroup( Split[i].c_str() ) ); + Group->InheritFrom(GetGroup(Split[i].c_str())); } } } -- cgit v1.2.3 From 0b384198e535470ac4aaa7d8f38b3da62b12ea34 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 3 Feb 2014 10:38:25 +0100 Subject: SocketThreads: Fixed sending to closed socket. --- src/OSSupport/SocketThreads.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp index 3e2631733..269f1d452 100644 --- a/src/OSSupport/SocketThreads.cpp +++ b/src/OSSupport/SocketThreads.cpp @@ -557,6 +557,11 @@ void cSocketThreads::cSocketThread::WriteToSockets(fd_set * a_Write) } } // if (outgoing data is empty) + if (m_Slots[i].m_State == sSlot::ssRemoteClosed) + { + continue; + } + if (!SendDataThroughSocket(m_Slots[i].m_Socket, m_Slots[i].m_Outgoing)) { int Err = cSocket::GetLastError(); @@ -566,7 +571,7 @@ void cSocketThreads::cSocketThread::WriteToSockets(fd_set * a_Write) { m_Slots[i].m_Client->SocketClosed(); } - return; + continue; } if (m_Slots[i].m_Outgoing.empty() && (m_Slots[i].m_State == sSlot::ssWritingRestOut)) -- cgit v1.2.3 From e3b9cdebc9c07a548c4aa219d53cf53c2c111b48 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 3 Feb 2014 14:01:47 +0000 Subject: Inversed condition --- src/ChunkMap.cpp | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 53e5b956b..4511391ff 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1756,39 +1756,42 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ Vector3d EntityPos = a_Entity->GetPosition(); cBoundingBox bbEntity(EntityPos, a_Entity->GetWidth() / 2, a_Entity->GetHeight()); - if (m_bbTNT.IsInside(bbEntity)) // IsInside actually acts like DoesSurround + if (!m_bbTNT.IsInside(bbEntity)) // IsInside actually acts like DoesSurround { - Vector3d AbsoluteEntityPos(abs(EntityPos.x), abs(EntityPos.y), abs(EntityPos.z)); - Vector3d MaxExplosionBoundary(m_ExplosionSizeSq, m_ExplosionSizeSq, m_ExplosionSizeSq); + return false; + } + + Vector3d AbsoluteEntityPos(abs(EntityPos.x), abs(EntityPos.y), abs(EntityPos.z)); + Vector3d MaxExplosionBoundary(m_ExplosionSizeSq, m_ExplosionSizeSq, m_ExplosionSizeSq); - // Work out how far we are from the edge of the TNT's explosive effect - AbsoluteEntityPos -= m_ExplosionPos; - AbsoluteEntityPos = MaxExplosionBoundary - AbsoluteEntityPos; + // Work out how far we are from the edge of the TNT's explosive effect + AbsoluteEntityPos -= m_ExplosionPos; + AbsoluteEntityPos = MaxExplosionBoundary - AbsoluteEntityPos; - double FinalDamage = ((AbsoluteEntityPos.x + AbsoluteEntityPos.y + AbsoluteEntityPos.z) / 3) * m_ExplosionSize; - FinalDamage = a_Entity->GetMaxHealth() - abs(FinalDamage); + double FinalDamage = ((AbsoluteEntityPos.x + AbsoluteEntityPos.y + AbsoluteEntityPos.z) / 3) * m_ExplosionSize; + FinalDamage = a_Entity->GetMaxHealth() - abs(FinalDamage); - // Clip damage values - if (FinalDamage > a_Entity->GetMaxHealth()) - FinalDamage = a_Entity->GetMaxHealth(); - else if (FinalDamage < 0) - return false; + // Clip damage values + if (FinalDamage > a_Entity->GetMaxHealth()) + FinalDamage = a_Entity->GetMaxHealth(); + else if (FinalDamage < 0) + return false; - if (!a_Entity->IsTNT()) // Don't apply damage to other TNT entities, they should be invincible - { - a_Entity->TakeDamage(dtExplosion, NULL, (int)FinalDamage, 0); - } + if (!a_Entity->IsTNT()) // Don't apply damage to other TNT entities, they should be invincible + { + a_Entity->TakeDamage(dtExplosion, NULL, (int)FinalDamage, 0); + } - // Apply force to entities around the explosion - code modified from World.cpp DoExplosionAt() - Vector3d distance_explosion = a_Entity->GetPosition() - m_ExplosionPos; - if (distance_explosion.SqrLength() < 4096.0) - { - distance_explosion.Normalize(); - distance_explosion *= m_ExplosionSizeSq; + // Apply force to entities around the explosion - code modified from World.cpp DoExplosionAt() + Vector3d distance_explosion = a_Entity->GetPosition() - m_ExplosionPos; + if (distance_explosion.SqrLength() < 4096.0) + { + distance_explosion.Normalize(); + distance_explosion *= m_ExplosionSizeSq; - a_Entity->AddSpeed(distance_explosion); - } + a_Entity->AddSpeed(distance_explosion); } + return false; } -- cgit v1.2.3 From c9916cd8c2332b6d6992ab38c0339ced6c91bc92 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 3 Feb 2014 17:07:46 +0100 Subject: Fixed socket leaking. --- src/OSSupport/SocketThreads.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp index 269f1d452..a02661d2c 100644 --- a/src/OSSupport/SocketThreads.cpp +++ b/src/OSSupport/SocketThreads.cpp @@ -209,6 +209,10 @@ bool cSocketThreads::cSocketThread::RemoveClient(const cCallback * a_Client) if (m_Slots[i].m_State == sSlot::ssRemoteClosed) { // The remote has already closed the socket, remove the slot altogether: + if (m_Slots[i].m_Socket.IsValid()) + { + m_Slots[i].m_Socket.CloseSocket(); + } m_Slots[i] = m_Slots[--m_NumSlots]; } else @@ -489,6 +493,7 @@ void cSocketThreads::cSocketThread::ReadFromSockets(fd_set * a_Read) // Notify the callback that the remote has closed the socket; keep the slot m_Slots[i].m_Client->SocketClosed(); m_Slots[i].m_State = sSlot::ssRemoteClosed; + m_Slots[i].m_Socket.CloseSocket(); break; } case sSlot::ssWritingRestOut: -- cgit v1.2.3 From 5ba46ebc21714c7398e7c1a14e81cb0f00c3f348 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 3 Feb 2014 20:08:38 +0100 Subject: This renames the cBlockWoodHandler to cBlockSidewaysHandler, and implements a new cBlockQuartzHandler to handle the quartz pillars. --- src/Blocks/BlockHandler.cpp | 9 ++++-- src/Blocks/BlockQuartz.h | 66 +++++++++++++++++++++++++++++++++++++++++ src/Blocks/BlockSideways.h | 72 +++++++++++++++++++++++++++++++++++++++++++++ src/Blocks/BlockWood.h | 72 --------------------------------------------- 4 files changed, 144 insertions(+), 75 deletions(-) create mode 100644 src/Blocks/BlockQuartz.h create mode 100644 src/Blocks/BlockSideways.h delete mode 100644 src/Blocks/BlockWood.h diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index c16f255b8..3ecf0d7e2 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -49,6 +49,7 @@ #include "BlockPlanks.h" #include "BlockPortal.h" #include "BlockPumpkin.h" +#include "BlockQuartz.h" #include "BlockRail.h" #include "BlockRedstone.h" #include "BlockRedstoneLamp.h" @@ -56,6 +57,7 @@ #include "BlockRedstoneTorch.h" #include "BlockSand.h" #include "BlockSapling.h" +#include "BlockSideways.h" #include "BlockSign.h" #include "BlockSlab.h" #include "BlockSnow.h" @@ -67,7 +69,6 @@ #include "BlockTorch.h" #include "BlockTrapdoor.h" #include "BlockVine.h" -#include "BlockWood.h" #include "BlockWorkbench.h" @@ -144,6 +145,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_GLASS: return new cBlockGlassHandler (a_BlockType); case E_BLOCK_GRASS: return new cBlockDirtHandler (a_BlockType); case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType); + case E_BLOCK_HAY_BALE: return new cBlockSidewaysHandler (a_BlockType); case E_BLOCK_HOPPER: return new cBlockHopperHandler (a_BlockType); case E_BLOCK_ICE: return new cBlockIceHandler (a_BlockType); case E_BLOCK_INACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); @@ -158,14 +160,14 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_LAVA: return new cBlockLavaHandler (a_BlockType); case E_BLOCK_LEAVES: return new cBlockLeavesHandler (a_BlockType); case E_BLOCK_LIT_FURNACE: return new cBlockFurnaceHandler (a_BlockType); - case E_BLOCK_LOG: return new cBlockWoodHandler (a_BlockType); + case E_BLOCK_LOG: return new cBlockSidewaysHandler (a_BlockType); case E_BLOCK_MELON: return new cBlockMelonHandler (a_BlockType); case E_BLOCK_MELON_STEM: return new cBlockStemsHandler (a_BlockType); case E_BLOCK_MYCELIUM: return new cBlockMyceliumHandler (a_BlockType); case E_BLOCK_NETHER_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_NETHER_PORTAL: return new cBlockPortalHandler (a_BlockType); case E_BLOCK_NETHER_WART: return new cBlockNetherWartHandler (a_BlockType); - case E_BLOCK_NEW_LOG: return new cBlockWoodHandler (a_BlockType); + case E_BLOCK_NEW_LOG: return new cBlockSidewaysHandler (a_BlockType); case E_BLOCK_NOTE_BLOCK: return new cBlockNoteHandler (a_BlockType); case E_BLOCK_PISTON: return new cBlockPistonHandler (a_BlockType); case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler ( ); @@ -174,6 +176,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_POWERED_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_PUMPKIN: return new cBlockPumpkinHandler (a_BlockType); case E_BLOCK_PUMPKIN_STEM: return new cBlockStemsHandler (a_BlockType); + case E_BLOCK_QUARTZ_BLOCK: return new cBlockQuartsHandler (a_BlockType); case E_BLOCK_QUARTZ_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_REDSTONE_LAMP_ON: return new cBlockRedstoneLampHandler (a_BlockType); // We need this to change pickups to an off lamp; else 1.7+ clients crash diff --git a/src/Blocks/BlockQuartz.h b/src/Blocks/BlockQuartz.h new file mode 100644 index 000000000..a01abac7b --- /dev/null +++ b/src/Blocks/BlockQuartz.h @@ -0,0 +1,66 @@ + +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockQuartsHandler : public cBlockHandler +{ +public: + cBlockQuartsHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + + virtual bool GetPlacementBlockTypeMeta( + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = m_BlockType; + NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage); + if (Meta != 0x2) // Check if the block is a pillar block. + { + return false; + } + + a_BlockMeta = BlockFaceToMetaData(a_BlockFace, Meta); + return true; + } + + inline static NIBBLETYPE BlockFaceToMetaData(char a_BlockFace, NIBBLETYPE a_QuartzMeta) + { + switch (a_BlockFace) + { + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + { + return a_QuartzMeta; // Top or bottom, just return original + } + + case BLOCK_FACE_ZP: + case BLOCK_FACE_ZM: + { + return 0x4; // North or south + } + + case BLOCK_FACE_XP: + case BLOCK_FACE_XM: + { + return 0x3; // East or west + } + + default: + { + ASSERT(!"Unhandled block face!"); + return a_QuartzMeta; // No idea, give a special meta (all sides the sa) + } + } + } +} ; \ No newline at end of file diff --git a/src/Blocks/BlockSideways.h b/src/Blocks/BlockSideways.h new file mode 100644 index 000000000..f11f0bee1 --- /dev/null +++ b/src/Blocks/BlockSideways.h @@ -0,0 +1,72 @@ + +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockSidewaysHandler : public cBlockHandler +{ +public: + cBlockSidewaysHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + + virtual bool GetPlacementBlockTypeMeta( + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = m_BlockType; + NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage); + a_BlockMeta = BlockFaceToMetaData(a_BlockFace, Meta); + return true; + } + + + inline static NIBBLETYPE BlockFaceToMetaData(char a_BlockFace, NIBBLETYPE a_WoodMeta) + { + switch (a_BlockFace) + { + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + { + return a_WoodMeta; // Top or bottom, just return original + } + + case BLOCK_FACE_ZP: + case BLOCK_FACE_ZM: + { + return a_WoodMeta | 0x8; // North or south + } + + case BLOCK_FACE_XP: + case BLOCK_FACE_XM: + { + return a_WoodMeta | 0x4; // East or west + } + + default: + { + ASSERT(!"Unhandled block face!"); + return a_WoodMeta | 0xC; // No idea, give a special meta (all sides bark) + } + } + } + + + virtual const char * GetStepSound(void) override + { + return "step.wood"; + } +} ; + + + + diff --git a/src/Blocks/BlockWood.h b/src/Blocks/BlockWood.h deleted file mode 100644 index cf49d0745..000000000 --- a/src/Blocks/BlockWood.h +++ /dev/null @@ -1,72 +0,0 @@ - -#pragma once - -#include "BlockHandler.h" - - - - - -class cBlockWoodHandler : public cBlockHandler -{ -public: - cBlockWoodHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) - { - } - - - virtual bool GetPlacementBlockTypeMeta( - cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, - int a_CursorX, int a_CursorY, int a_CursorZ, - BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta - ) override - { - a_BlockType = m_BlockType; - NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage); - a_BlockMeta = BlockFaceToMetaData(a_BlockFace, Meta); - return true; - } - - - inline static NIBBLETYPE BlockFaceToMetaData(char a_BlockFace, NIBBLETYPE a_WoodMeta) - { - switch (a_BlockFace) - { - case BLOCK_FACE_YM: - case BLOCK_FACE_YP: - { - return a_WoodMeta; // Top or bottom, just return original - } - - case BLOCK_FACE_ZP: - case BLOCK_FACE_ZM: - { - return a_WoodMeta | 0x8; // North or south - } - - case BLOCK_FACE_XP: - case BLOCK_FACE_XM: - { - return a_WoodMeta | 0x4; // East or west - } - - default: - { - ASSERT(!"Unhandled block face!"); - return a_WoodMeta | 0xC; // No idea, give a special meta (all sides bark) - } - } - } - - - virtual const char * GetStepSound(void) override - { - return "step.wood"; - } -} ; - - - - -- cgit v1.2.3 From 0c29c52ff3713047fe280bdc07d7a2f09e9a32e8 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 3 Feb 2014 20:22:45 +0100 Subject: Renamed cBlockQuartsHandler to cBlockQuartzHandler. Fixed not being able to place normal quartz blocks. --- src/Blocks/BlockHandler.cpp | 2 +- src/Blocks/BlockQuartz.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 3ecf0d7e2..657058e3e 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -176,7 +176,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_POWERED_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_PUMPKIN: return new cBlockPumpkinHandler (a_BlockType); case E_BLOCK_PUMPKIN_STEM: return new cBlockStemsHandler (a_BlockType); - case E_BLOCK_QUARTZ_BLOCK: return new cBlockQuartsHandler (a_BlockType); + case E_BLOCK_QUARTZ_BLOCK: return new cBlockQuartzHandler (a_BlockType); case E_BLOCK_QUARTZ_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_REDSTONE_LAMP_ON: return new cBlockRedstoneLampHandler (a_BlockType); // We need this to change pickups to an off lamp; else 1.7+ clients crash diff --git a/src/Blocks/BlockQuartz.h b/src/Blocks/BlockQuartz.h index a01abac7b..e5306ff6a 100644 --- a/src/Blocks/BlockQuartz.h +++ b/src/Blocks/BlockQuartz.h @@ -7,10 +7,10 @@ -class cBlockQuartsHandler : public cBlockHandler +class cBlockQuartzHandler : public cBlockHandler { public: - cBlockQuartsHandler(BLOCKTYPE a_BlockType) + cBlockQuartzHandler(BLOCKTYPE a_BlockType) : cBlockHandler(a_BlockType) { } @@ -27,7 +27,7 @@ public: NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage); if (Meta != 0x2) // Check if the block is a pillar block. { - return false; + return true; } a_BlockMeta = BlockFaceToMetaData(a_BlockFace, Meta); -- cgit v1.2.3 From 347488a9a23e43b59062a8f161bcc7f88628db56 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 3 Feb 2014 20:34:05 +0100 Subject: Fixed some issues. Meta wasn't set if the block wasn't a pillar. Fixed typo. --- src/Blocks/BlockQuartz.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Blocks/BlockQuartz.h b/src/Blocks/BlockQuartz.h index e5306ff6a..41f4e15a7 100644 --- a/src/Blocks/BlockQuartz.h +++ b/src/Blocks/BlockQuartz.h @@ -27,6 +27,7 @@ public: NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage); if (Meta != 0x2) // Check if the block is a pillar block. { + a_BlockMeta = Meta; return true; } @@ -59,7 +60,7 @@ public: default: { ASSERT(!"Unhandled block face!"); - return a_QuartzMeta; // No idea, give a special meta (all sides the sa) + return a_QuartzMeta; // No idea, give a special meta (all sides the same) } } } -- cgit v1.2.3 From c2e7dd34d98258bdfa5baa2f27f08999909996c5 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Mon, 3 Feb 2014 20:52:11 +0100 Subject: Exporded World:FindClosestPlayer, Item:IsEnchantable and Monster:MoveToPosition to Lua API --- src/Entities/Entity.h | 1 + src/Item.h | 2 +- src/Mobs/Monster.cpp | 8 ++++++++ src/Mobs/Monster.h | 1 + src/World.cpp | 2 +- src/World.h | 2 +- 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index b2edfc2b4..5287e3a6d 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -158,6 +158,7 @@ public: double GetHeight (void) const { return m_Height; } double GetMass (void) const { return m_Mass; } const Vector3d & GetPosition (void) const { return m_Pos; } + const Vector3d & GetPosition (void) const { return m_Pos; } double GetPosX (void) const { return m_Pos.x; } double GetPosY (void) const { return m_Pos.y; } double GetPosZ (void) const { return m_Pos.z; } diff --git a/src/Item.h b/src/Item.h index 727965112..7781db0cb 100644 --- a/src/Item.h +++ b/src/Item.h @@ -167,7 +167,7 @@ public: void FromJson(const Json::Value & a_Value); /// Returns true if the specified item type is enchantable (as per 1.2.5 protocol requirements) - static bool IsEnchantable(short a_ItemType); + static bool IsEnchantable(short a_ItemType); // tolua_export // tolua_begin diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 283ef36e6..35880bcff 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -188,6 +188,14 @@ void cMonster::MoveToPosition(const Vector3f & a_Position) TickPathFinding(); } +void cMonster::MoveToPosition(const Vector3d & a_Position) +{ + FinishPathFinding(); + + m_FinalDestination = a_Position; + m_bMovingToDestination = true; + TickPathFinding(); +} diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 1dd302cdc..714feddb9 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -91,6 +91,7 @@ public: virtual void KilledBy(cEntity * a_Killer) override; virtual void MoveToPosition(const Vector3f & a_Position); + virtual void MoveToPosition(const Vector3d & a_Position); // tolua_export virtual bool ReachedDestination(void); // tolua_begin diff --git a/src/World.cpp b/src/World.cpp index de2002b84..410326b2d 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2339,7 +2339,7 @@ bool cWorld::FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCa // TODO: This interface is dangerous! -cPlayer * cWorld::FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit, bool a_CheckLineOfSight) +cPlayer * cWorld::FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit, bool a_CheckLineOfSight) { cTracer LineOfSight(this); diff --git a/src/World.h b/src/World.h index bf6a4ba28..531154181 100644 --- a/src/World.h +++ b/src/World.h @@ -248,7 +248,7 @@ public: bool FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << // TODO: This interface is dangerous - rewrite to DoWithClosestPlayer(pos, sight, action) - cPlayer * FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit, bool a_CheckLineOfSight = true); + cPlayer * FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit, bool a_CheckLineOfSight = true); // tolua_export void SendPlayerList(cPlayer * a_DestPlayer); // Sends playerlist to the player -- cgit v1.2.3 From 0beae3a427bbaa1b4937fb4fa8e820a41bd02cbd Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Mon, 3 Feb 2014 21:02:32 +0100 Subject: Added documentation --- MCServer/Plugins/APIDump/APIDesc.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index cbdb7797b..fb82ac270 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1103,6 +1103,7 @@ These ItemGrids are available in the API and can be manipulated by the plugins, GetMaxStackSize = { Params = "", Return = "number", Notes = "Returns the maximum stack size for this item." }, IsDamageable = { Params = "", Return = "bool", Notes = "Returns true if this item does account for its damage" }, IsEmpty = { Params = "", Return = "bool", Notes = "Returns true if this object represents an empty item (zero count or invalid ID)" }, + IsEnchantable = { Params = "", Return = "bool", Notes = "Returns true if the item is enchantable" }, IsEqual = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is the same as the one stored in the object (type, damage and enchantments)" }, IsFullStack = { Params = "", Return = "bool", Notes = "Returns true if the item is stacked up to its maximum stacking" }, IsSameType = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is of the same ItemType as the one stored in the object. This is true even if the two items have different enchantments" }, @@ -1479,6 +1480,7 @@ a_Player:OpenWindow(Window); GetMobType = { Params = "", Return = "{{cMonster#MobType|MobType}}", Notes = "Returns the type of this mob ({{cMonster#MobType|mtXXX}} constant)" }, GetSpawnDelay = { Params = "{{cMonster#MobFamily|MobFamily}}", Return = "number", Notes = "(STATIC) Returns the spawn delay - the number of game ticks between spawn attempts - for the specified mob family." }, MobTypeToString = { Params = "{{cMonster#MobType|MobType}}", Return = "string", Notes = "(STATIC) Returns the string representing the given mob type ({{cMonster#MobType|mtXXX}} constant), or empty string if unknown type." }, + MoveToPosition = { Params = "Position", Return = "", Notes = "Moves mob to the specified position" }, StringToMobType = { Params = "string", Return = "{{cMonster#MobType|MobType}}", Notes = "(STATIC) Returns the mob type ({{cMonster#MobType|mtXXX}} constant) parsed from the string type (\"creeper\"), or mtInvalidType if unrecognized." }, }, Constants = @@ -2043,7 +2045,8 @@ end ForEachEntity = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the loaded world. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cEntity|Entity}}, [CallbackData])
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, ForEachEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the specified chunk. Returns true if all the entities have been processed (including when there are zero entities), or false if the chunk is not loaded or the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cEntity|Entity}}, [CallbackData])
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, ForEachFurnaceInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each furnace in the chunk. Returns true if all furnaces in the chunk have been processed (including when there are zero furnaces), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature:
function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])
The callback should return false or no value to continue with the next furnace, or true to abort the enumeration." }, - ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cPlayer|Player}}, [CallbackData])
The callback should return false or no value to continue with the next player, or true to abort the enumeration." }, + FindClosestPlayer = { Params = "Vector3d(Position), MaxPlayerDistance", Return = "cPlayer", Notes = "Returns nearest player cPlayer's object" }, + ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cPlayer|Player}}, [CallbackData])
The callback should return false or no value to continue with the next player, or true to abort the enumeration." }, GenerateChunk = { Params = "ChunkX, ChunkZ", Return = "", Notes = "Queues the specified chunk in the chunk generator. Ignored if the chunk is already generated (use RegenerateChunk() to force chunk re-generation)." }, GetBiomeAt = { Params = "BlockX, BlockZ", Return = "eBiome", Notes = "Returns the biome at the specified coords. Reads the biome from the chunk, if it is loaded, otherwise it uses the chunk generator to provide the biome value." }, GetBlock = -- cgit v1.2.3 From defb001ad7f242e524530770a02c65f1bf455c19 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Mon, 3 Feb 2014 21:05:10 +0100 Subject: Fixed compilation --- src/Entities/Entity.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 5287e3a6d..b2edfc2b4 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -158,7 +158,6 @@ public: double GetHeight (void) const { return m_Height; } double GetMass (void) const { return m_Mass; } const Vector3d & GetPosition (void) const { return m_Pos; } - const Vector3d & GetPosition (void) const { return m_Pos; } double GetPosX (void) const { return m_Pos.x; } double GetPosY (void) const { return m_Pos.y; } double GetPosZ (void) const { return m_Pos.z; } -- cgit v1.2.3 From df8b589b31af5a94c06ad042a1d2b01f723ab4ee Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Mon, 3 Feb 2014 21:06:43 +0100 Subject: Not exporting FindClosestPlayer --- src/World.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/World.h b/src/World.h index 531154181..33db16614 100644 --- a/src/World.h +++ b/src/World.h @@ -248,7 +248,7 @@ public: bool FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << // TODO: This interface is dangerous - rewrite to DoWithClosestPlayer(pos, sight, action) - cPlayer * FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit, bool a_CheckLineOfSight = true); // tolua_export + cPlayer * FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit, bool a_CheckLineOfSight = true); void SendPlayerList(cPlayer * a_DestPlayer); // Sends playerlist to the player -- cgit v1.2.3 From 80807eec2cc1c497c4766a0c7cddb9c3ddc29e45 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 3 Feb 2014 12:26:17 -0800 Subject: Increased Type safety of Biomes Changed a number of funcictions from using integers to store biomes to using EMCSBiome Note that switching from an int to an Enum is a non-breaking chang to the lua bindings --- Tools/BiomeVisualiser/BiomeRenderer.cpp | 2 +- src/BiomeDef.cpp | 14 +++++++++++--- src/BiomeDef.h | 9 ++++++++- src/Generating/BioGen.cpp | 10 +++++----- src/Generating/ChunkDesc.cpp | 4 ++-- src/Generating/ChunkDesc.h | 2 +- src/Mobs/SnowGolem.cpp | 2 +- src/World.cpp | 4 ++-- src/World.h | 2 +- 9 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Tools/BiomeVisualiser/BiomeRenderer.cpp b/Tools/BiomeVisualiser/BiomeRenderer.cpp index 569128a12..5c572d33e 100644 --- a/Tools/BiomeVisualiser/BiomeRenderer.cpp +++ b/Tools/BiomeVisualiser/BiomeRenderer.cpp @@ -78,7 +78,7 @@ bool cBiomeRenderer::Render(cPixmap & a_Pixmap) { for (int i = 0; i < ARRAYCOUNT(CurBiomes); i++) { - CurBiomes[i] = (EMCSBiome)-1; + CurBiomes[i] = EMCSBiome::biInvalidBiome; } break; } diff --git a/src/BiomeDef.cpp b/src/BiomeDef.cpp index 89a1cdefb..5c1156484 100644 --- a/src/BiomeDef.cpp +++ b/src/BiomeDef.cpp @@ -13,8 +13,16 @@ EMCSBiome StringToBiome(const AString & a_BiomeString) int res = atoi(a_BiomeString.c_str()); if ((res != 0) || (a_BiomeString.compare("0") == 0)) { - // It was a valid number - return (EMCSBiome)res; + if(res >= biFirstBiome && res < biNumBiomes) + { + return (EMCSBiome)res; + } + else if(res >= biFirstVarientBiome && res < biNumVarientBiomes) + { + return (EMCSBiome)res; + } + // It was an invalid number + return biInvalidBiome; } // Convert using the built-in map: @@ -100,7 +108,7 @@ EMCSBiome StringToBiome(const AString & a_BiomeString) return BiomeMap[i].m_Biome; } } // for i - BiomeMap[] - return (EMCSBiome)-1; + return biInvalidBiome; } diff --git a/src/BiomeDef.h b/src/BiomeDef.h index df1e387f0..f015dd836 100644 --- a/src/BiomeDef.h +++ b/src/BiomeDef.h @@ -20,6 +20,9 @@ BiomeIDs over 255 are used by MCServer internally and are translated to MC biome */ enum EMCSBiome { + biInvalidBiome = -1, + + biFirstBiome = 0, biOcean = 0, biPlains = 1, biDesert = 2, @@ -74,6 +77,7 @@ enum EMCSBiome biVariant = 128, // Release 1.7 biome variants: + biFirstVarientBiome = 129, biSunflowerPlains = 129, biDesertM = 130, biExtremeHillsM = 131, @@ -95,9 +99,12 @@ enum EMCSBiome biMesaBryce = 165, biMesaPlateauFM = 166, biMesaPlateauM = 167, + // Automatically capture the maximum consecutive biome value into biVarientMaxBiome: + biNumVarientBiomes, // True number of biomes, since they are zero-based + biMaxVarientBiome = biNumVarientBiomes - 1, // The maximum biome value } ; -/// Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns -1 on failure. +/// Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns biInvalidBiome on failure. extern EMCSBiome StringToBiome(const AString & a_BiomeString); /// Returns true if the biome has no downfall - deserts and savannas diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index f89b1800d..1a18f53f1 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -97,7 +97,7 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile) { AString Biome = a_IniFile.GetValueSet("Generator", "ConstantBiome", "Plains"); m_Biome = StringToBiome(Biome); - if (m_Biome == -1) + if (m_Biome == EMCSBiome::biInvalidBiome) { LOGWARN("[Generator]::ConstantBiome value \"%s\" not recognized, using \"Plains\".", Biome.c_str()); m_Biome = biPlains; @@ -233,7 +233,7 @@ void cBiomeGenList::InitializeBiomes(const AString & a_Biomes) } } EMCSBiome Biome = StringToBiome(Split2[0]); - if (Biome != -1) + if (Biome != EMCSBiome::biInvalidBiome) { for (int i = 0; i < Count; i++) { @@ -500,7 +500,7 @@ void cBioGenMultiStepMap::DecideOceanLandMushroom(int a_ChunkX, int a_ChunkZ, cC int OffsetZ = (m_Noise4.IntNoise3DInt(RealCellX, 32 * RealCellX - 16 * RealCellZ, RealCellZ) / 8) % m_OceanCellSize; SeedX[xc][zc] = CellBlockX + OffsetX; SeedZ[xc][zc] = CellBlockZ + OffsetZ; - SeedV[xc][zc] = (((m_Noise6.IntNoise3DInt(RealCellX, RealCellX - RealCellZ + 1000, RealCellZ) / 11) % 256) > 90) ? biOcean : ((EMCSBiome)(-1)); + SeedV[xc][zc] = (((m_Noise6.IntNoise3DInt(RealCellX, RealCellX - RealCellZ + 1000, RealCellZ) / 11) % 256) > 90) ? biOcean : (EMCSBiome::biInvalidBiome); } // for z } // for x @@ -573,7 +573,7 @@ void cBioGenMultiStepMap::AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::Biome float NoiseCoordZ = (float)(a_ChunkZ * cChunkDef::Width + z) / m_RiverCellSize; for (int x = 0; x < cChunkDef::Width; x++) { - if (cChunkDef::GetBiome(a_BiomeMap, x, z) != -1) + if (cChunkDef::GetBiome(a_BiomeMap, x, z) != EMCSBiome::biInvalidBiome) { // Biome already set, skip this column continue; @@ -693,7 +693,7 @@ void cBioGenMultiStepMap::DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, con int idxZ = 17 * z; for (int x = 0; x < cChunkDef::Width; x++) { - if (cChunkDef::GetBiome(a_BiomeMap, x, z) != -1) + if (cChunkDef::GetBiome(a_BiomeMap, x, z) != EMCSBiome::biInvalidBiome) { // Already set before continue; diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp index 87566aa78..d9529b4b0 100644 --- a/src/Generating/ChunkDesc.cpp +++ b/src/Generating/ChunkDesc.cpp @@ -118,9 +118,9 @@ void cChunkDesc::SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_B -void cChunkDesc::SetBiome(int a_RelX, int a_RelZ, int a_BiomeID) +void cChunkDesc::SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID) { - cChunkDef::SetBiome(m_BiomeMap, a_RelX, a_RelZ, (EMCSBiome)a_BiomeID); + cChunkDef::SetBiome(m_BiomeMap, a_RelX, a_RelZ, a_BiomeID); } diff --git a/src/Generating/ChunkDesc.h b/src/Generating/ChunkDesc.h index e258383d5..8edc2800b 100644 --- a/src/Generating/ChunkDesc.h +++ b/src/Generating/ChunkDesc.h @@ -53,7 +53,7 @@ public: void SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta); NIBBLETYPE GetBlockMeta(int a_RelX, int a_RelY, int a_RelZ); - void SetBiome(int a_RelX, int a_RelZ, int a_BiomeID); + void SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID); EMCSBiome GetBiome(int a_RelX, int a_RelZ); // These operate on the heightmap, so they could get out of sync with the data diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index 06021cca5..c60103055 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -29,7 +29,7 @@ void cSnowGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSnowGolem::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - if (IsBiomeNoDownfall((EMCSBiome) m_World->GetBiomeAt((int) floor(GetPosX()), (int) floor(GetPosZ())) )) + if (IsBiomeNoDownfall(m_World->GetBiomeAt((int) floor(GetPosX()), (int) floor(GetPosZ())) )) { TakeDamage(*this); } diff --git a/src/World.cpp b/src/World.cpp index de2002b84..f9a6e7776 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1222,7 +1222,7 @@ void cWorld::GrowTreeByBiome(int a_X, int a_Y, int a_Z) { cNoise Noise(m_Generator.GetSeed()); sSetBlockVector Logs, Other; - GetTreeImageByBiome(a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), (EMCSBiome)GetBiomeAt(a_X, a_Z), Logs, Other); + GetTreeImageByBiome(a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), GetBiomeAt(a_X, a_Z), Logs, Other); Other.insert(Other.begin(), Logs.begin(), Logs.end()); Logs.clear(); GrowTreeImage(Other); @@ -1475,7 +1475,7 @@ void cWorld::GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBl -int cWorld::GetBiomeAt (int a_BlockX, int a_BlockZ) +EMCSBiome cWorld::GetBiomeAt (int a_BlockX, int a_BlockZ) { return m_ChunkMap->GetBiomeAt(a_BlockX, a_BlockZ); } diff --git a/src/World.h b/src/World.h index bf6a4ba28..afdc09788 100644 --- a/src/World.h +++ b/src/World.h @@ -526,7 +526,7 @@ public: void GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow); /** Returns the biome at the specified coords. Reads the biome from the chunk, if loaded, otherwise uses the world generator to provide the biome value */ - int GetBiomeAt(int a_BlockX, int a_BlockZ); + EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ); /** Returns the name of the world */ const AString & GetName(void) const { return m_WorldName; } -- cgit v1.2.3 From f8881622a4000d769af700396f772bae21d1d117 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 3 Feb 2014 12:31:18 -0800 Subject: Removed unused lookups --- src/Simulator/FluidSimulator.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Simulator/FluidSimulator.cpp b/src/Simulator/FluidSimulator.cpp index 72b2eb628..61c93ed73 100644 --- a/src/Simulator/FluidSimulator.cpp +++ b/src/Simulator/FluidSimulator.cpp @@ -166,14 +166,12 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a { LowestPoint = Meta; X = Pos->x; - Pos->y; //Remove if no side effects Z = Pos->z; } }else if(BlockID == E_BLOCK_AIR) { LowestPoint = 9; //This always dominates X = Pos->x; - Pos->y; //Remove if no side effects Z = Pos->z; } -- cgit v1.2.3 From d9fb83300cf831ea31a74d509f9be9f2ed4f1189 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 3 Feb 2014 13:01:12 -0800 Subject: Fixed Compile errors c++11 introduces scoped enums, so the code didn't fail in clang --- Tools/BiomeVisualiser/BiomeRenderer.cpp | 2 +- src/BiomeDef.cpp | 4 ++-- src/BiomeDef.h | 6 +++--- src/Generating/BioGen.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Tools/BiomeVisualiser/BiomeRenderer.cpp b/Tools/BiomeVisualiser/BiomeRenderer.cpp index 5c572d33e..c0123c08a 100644 --- a/Tools/BiomeVisualiser/BiomeRenderer.cpp +++ b/Tools/BiomeVisualiser/BiomeRenderer.cpp @@ -78,7 +78,7 @@ bool cBiomeRenderer::Render(cPixmap & a_Pixmap) { for (int i = 0; i < ARRAYCOUNT(CurBiomes); i++) { - CurBiomes[i] = EMCSBiome::biInvalidBiome; + CurBiomes[i] = biInvalidBiome; } break; } diff --git a/src/BiomeDef.cpp b/src/BiomeDef.cpp index 5c1156484..3fba93e8a 100644 --- a/src/BiomeDef.cpp +++ b/src/BiomeDef.cpp @@ -13,11 +13,11 @@ EMCSBiome StringToBiome(const AString & a_BiomeString) int res = atoi(a_BiomeString.c_str()); if ((res != 0) || (a_BiomeString.compare("0") == 0)) { - if(res >= biFirstBiome && res < biNumBiomes) + if ((res >= biFirstBiome) && (res < biNumBiomes)) { return (EMCSBiome)res; } - else if(res >= biFirstVarientBiome && res < biNumVarientBiomes) + else if ((res >= biFirstVariantBiome) && (res < biNumVariantBiomes)) { return (EMCSBiome)res; } diff --git a/src/BiomeDef.h b/src/BiomeDef.h index f015dd836..474d4df76 100644 --- a/src/BiomeDef.h +++ b/src/BiomeDef.h @@ -77,7 +77,7 @@ enum EMCSBiome biVariant = 128, // Release 1.7 biome variants: - biFirstVarientBiome = 129, + biFirstVariantBiome = 129, biSunflowerPlains = 129, biDesertM = 130, biExtremeHillsM = 131, @@ -100,8 +100,8 @@ enum EMCSBiome biMesaPlateauFM = 166, biMesaPlateauM = 167, // Automatically capture the maximum consecutive biome value into biVarientMaxBiome: - biNumVarientBiomes, // True number of biomes, since they are zero-based - biMaxVarientBiome = biNumVarientBiomes - 1, // The maximum biome value + biNumVariantBiomes, // True number of biomes, since they are zero-based + biMaxVariantBiome = biNumVariantBiomes - 1, // The maximum biome value } ; /// Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns biInvalidBiome on failure. diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 1a18f53f1..20f269fc8 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -97,7 +97,7 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile) { AString Biome = a_IniFile.GetValueSet("Generator", "ConstantBiome", "Plains"); m_Biome = StringToBiome(Biome); - if (m_Biome == EMCSBiome::biInvalidBiome) + if (m_Biome == biInvalidBiome) { LOGWARN("[Generator]::ConstantBiome value \"%s\" not recognized, using \"Plains\".", Biome.c_str()); m_Biome = biPlains; -- cgit v1.2.3 From 4b1924730502c26519202c9fa8ea9e77976475e5 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 3 Feb 2014 13:07:38 -0800 Subject: Fogot to save Biogen --- src/Generating/BioGen.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 20f269fc8..967deba6a 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -233,7 +233,7 @@ void cBiomeGenList::InitializeBiomes(const AString & a_Biomes) } } EMCSBiome Biome = StringToBiome(Split2[0]); - if (Biome != EMCSBiome::biInvalidBiome) + if (Biome != biInvalidBiome) { for (int i = 0; i < Count; i++) { @@ -500,7 +500,7 @@ void cBioGenMultiStepMap::DecideOceanLandMushroom(int a_ChunkX, int a_ChunkZ, cC int OffsetZ = (m_Noise4.IntNoise3DInt(RealCellX, 32 * RealCellX - 16 * RealCellZ, RealCellZ) / 8) % m_OceanCellSize; SeedX[xc][zc] = CellBlockX + OffsetX; SeedZ[xc][zc] = CellBlockZ + OffsetZ; - SeedV[xc][zc] = (((m_Noise6.IntNoise3DInt(RealCellX, RealCellX - RealCellZ + 1000, RealCellZ) / 11) % 256) > 90) ? biOcean : (EMCSBiome::biInvalidBiome); + SeedV[xc][zc] = (((m_Noise6.IntNoise3DInt(RealCellX, RealCellX - RealCellZ + 1000, RealCellZ) / 11) % 256) > 90) ? biOcean : (biInvalidBiome); } // for z } // for x @@ -573,7 +573,7 @@ void cBioGenMultiStepMap::AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::Biome float NoiseCoordZ = (float)(a_ChunkZ * cChunkDef::Width + z) / m_RiverCellSize; for (int x = 0; x < cChunkDef::Width; x++) { - if (cChunkDef::GetBiome(a_BiomeMap, x, z) != EMCSBiome::biInvalidBiome) + if (cChunkDef::GetBiome(a_BiomeMap, x, z) != biInvalidBiome) { // Biome already set, skip this column continue; @@ -693,7 +693,7 @@ void cBioGenMultiStepMap::DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, con int idxZ = 17 * z; for (int x = 0; x < cChunkDef::Width; x++) { - if (cChunkDef::GetBiome(a_BiomeMap, x, z) != EMCSBiome::biInvalidBiome) + if (cChunkDef::GetBiome(a_BiomeMap, x, z) != biInvalidBiome) { // Already set before continue; -- cgit v1.2.3 From b5e898a608cfa0b872828db842e31ec2d624e598 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 3 Feb 2014 21:12:44 +0000 Subject: Server now handles join messages also * Revised as well hook documentation --- MCServer/Plugins/APIDump/Hooks/OnDisconnect.lua | 16 ++++++---------- MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua | 10 +++++++--- MCServer/Plugins/APIDump/Hooks/OnPlayerJoined.lua | 8 ++++---- src/ClientHandle.cpp | 20 +++++++++++--------- src/Entities/Player.cpp | 8 +++++++- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/MCServer/Plugins/APIDump/Hooks/OnDisconnect.lua b/MCServer/Plugins/APIDump/Hooks/OnDisconnect.lua index 496e0d751..a3301a8c6 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnDisconnect.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnDisconnect.lua @@ -5,13 +5,10 @@ return CalledWhen = "A player has explicitly disconnected.", DefaultFnName = "OnDisconnect", -- also used as pagename Desc = [[ - This hook is called when a client sends the disconnect packet and is about to be disconnected from - the server.

-

- Note that this callback is not called if the client drops the connection or is kicked by the - server.

-

- FIXME: There is no callback for "client destroying" that would be called in all circumstances.

+ This hook is called when a client is about to be disconnected from the server, for whatever reason. + +

Note that this hook will be removed after <1.7 protocol support is removed, as it was originally a hook for + the client sending the server a disconnect packet, which no longer happens.

]], Params = { @@ -19,9 +16,8 @@ return { Name = "Reason", Type = "string", Notes = "The reason that the client has sent in the disconnect packet" }, }, Returns = [[ - If the function returns false or no value, MCServer calls other plugins' callbacks for this event - and finally broadcasts a disconnect message to the player's world. If the function returns true, no - other plugins are called for this event and the disconnect message is not broadcast. In either case, + If the function returns false or no value, MCServer calls other plugins' callbacks for this event. + If the function returns true, no other plugins are called for this event. In either case, the player is disconnected. ]], }, -- HOOK_DISCONNECT diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua index 8e503658c..dc033197a 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua @@ -2,17 +2,21 @@ return { HOOK_PLAYER_DESTROYED = { - CalledWhen = "A player is about to get destroyed.", + CalledWhen = "A player object is about to be destroyed.", DefaultFnName = "OnPlayerDestroyed", -- also used as pagename Desc = [[ - This function is called when a {{cPlayer|player}} is about to get destroyed. But the player isn't already destroyed. + This function is called before a {{cPlayer|player}} is about to be destroyed. + The player has disconnected for whatever reason and is no longer in the server. + If a plugin returns true, a leave message is not broadcast, and vice versa. + However, whatever the return value, the player object is removed from memory. ]], Params = { { Name = "Player", Type = "{{cPlayer}}", Notes = "The destroyed player" }, }, Returns = [[ - It's only for notification. Can't be returned. + If the function returns false or no value, other plugins' callbacks are called and a leave message is broadcast. + If the function returns true, no other callbacks are called for this event and no leave message appears. Either way the player is removed internally. ]], }, -- HOOK_PLAYER_DESTROYED } diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerJoined.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerJoined.lua index 00805af7e..dcd16ed00 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnPlayerJoined.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerJoined.lua @@ -9,16 +9,16 @@ return enabled, this function is called after their name has been authenticated. It is called after {{OnLogin|HOOK_LOGIN}} and before {{OnPlayerSpawned|HOOK_PLAYER_SPAWNED}}, right after the player's entity is created, but not added to the world yet. The player is not yet visible to other players. - This is a notification-only event, plugins wishing to refuse player's entry should kick the player - using the {{cPlayer}}:Kick() function. + Returning true will block a join message from being broadcast, but otherwise, the player is still allowed to join. + Plugins wishing to refuse player's entry should kick the player using the {{cPlayer}}:Kick() function. ]], Params = { { Name = "Player", Type = "{{cPlayer}}", Notes = "The player who has joined the game" }, }, Returns = [[ - If the function returns false or no value, other plugins' callbacks are called. If the function - returns true, no other callbacks are called for this event. Either way the player is let in. + If the function returns false or no value, other plugins' callbacks are called and a join message is broadcast. If the function + returns true, no other callbacks are called for this event and a join message is not sent. Either way the player is let in. ]], }, -- HOOK_PLAYER_JOINED } diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 6b61eaae8..b0eb27089 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -227,7 +227,13 @@ void cClientHandle::Authenticate(void) m_Player->SetIP (m_IPString); - cRoot::Get()->GetPluginManager()->CallHookPlayerJoined(*m_Player); + if (!cRoot::Get()->GetPluginManager()->CallHookPlayerJoined(*m_Player)) + { + AString JoinMessage; + AppendPrintf(JoinMessage, "%s[JOIN] %s%s has joined the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), m_Username.c_str()); + cRoot::Get()->BroadcastChat(JoinMessage); + LOGINFO("Player %s has joined the game.", m_Username.c_str()); + } m_ConfirmPosition = m_Player->GetPosition(); @@ -910,7 +916,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, c cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Equipped.m_ItemType); - if (ItemHandler->IsPlaceable()) + if (ItemHandler->IsPlaceable() && (a_BlockFace > -1)) { HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); } @@ -1330,13 +1336,9 @@ void cClientHandle::HandleRespawn(void) void cClientHandle::HandleDisconnect(const AString & a_Reason) { LOGD("Received d/c packet from %s with reason \"%s\"", m_Username.c_str(), a_Reason.c_str()); - if (!cRoot::Get()->GetPluginManager()->CallHookDisconnect(m_Player, a_Reason)) - { - AString DisconnectMessage; - Printf(DisconnectMessage, "%s[LEAVE] %s%s has left the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), m_Username.c_str()); - cRoot::Get()->BroadcastChat(DisconnectMessage); - LOGINFO("Player %s has left the game.", m_Username.c_str()); - } + + cRoot::Get()->GetPluginManager()->CallHookDisconnect(m_Player, a_Reason); + m_HasSentDC = true; Destroy(); } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 8c37fdc8d..a1c942c20 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -130,7 +130,13 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) cPlayer::~cPlayer(void) { - cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this); + if (!cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this)) + { + AString DisconnectMessage; + AppendPrintf(DisconnectMessage, "%s[LEAVE] %s%s has left the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), GetClientHandle()->GetUsername().c_str()); + cRoot::Get()->BroadcastChat(DisconnectMessage); + LOGINFO("Player %s has left the game.", GetClientHandle()->GetUsername().c_str()); + } LOGD("Deleting cPlayer \"%s\" at %p, ID %d", m_PlayerName.c_str(), this, GetUniqueID()); -- cgit v1.2.3 From 6bbba2644d520204c50b48d67ca294fcd9b0a5c4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 3 Feb 2014 21:14:52 +0000 Subject: Fixed issues with farmland * Fixed farmland reversion checks not taking into account carrots and potatoes * Fixed #623 --- src/Blocks/BlockCrops.h | 2 +- src/Blocks/BlockFarmland.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index 4c4ac21be..ffc2b3f8b 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -87,7 +87,7 @@ public: if ((Meta < 7) && (Light > 8)) { - a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_CROPS, ++Meta); + a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, m_BlockType, ++Meta); } else if (Light < 9) { diff --git a/src/Blocks/BlockFarmland.h b/src/Blocks/BlockFarmland.h index 101ab8e34..b720ccd14 100644 --- a/src/Blocks/BlockFarmland.h +++ b/src/Blocks/BlockFarmland.h @@ -90,6 +90,8 @@ public: switch (a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ)) { case E_BLOCK_CROPS: + case E_BLOCK_POTATOES: + case E_BLOCK_CARROTS: case E_BLOCK_MELON_STEM: case E_BLOCK_PUMPKIN_STEM: { -- cgit v1.2.3 From 3fc848c95a7e16ac759dc74f32ea7e7b0f46de6e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 3 Feb 2014 21:16:26 +0000 Subject: Fixed #626 * Fixed consumption of carrots and potatoes --- src/Items/ItemFood.h | 6 +++--- src/Items/ItemHandler.cpp | 25 +++++++++++++++---------- src/Items/ItemSeeds.h | 20 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/Items/ItemFood.h b/src/Items/ItemFood.h index 2ae572331..961cf482d 100644 --- a/src/Items/ItemFood.h +++ b/src/Items/ItemFood.h @@ -31,7 +31,7 @@ public: // Please keep alpha-sorted. case E_ITEM_BAKED_POTATO: return FoodInfo(6, 7.2); case E_ITEM_BREAD: return FoodInfo(5, 6); - case E_ITEM_CARROT: return FoodInfo(4, 4.8); + // Carrots handled in ItemSeeds case E_ITEM_COOKED_CHICKEN: return FoodInfo(6, 7.2); case E_ITEM_COOKED_FISH: return FoodInfo(5, 6); case E_ITEM_COOKED_PORKCHOP: return FoodInfo(8, 12.8); @@ -39,8 +39,9 @@ public: case E_ITEM_GOLDEN_APPLE: return FoodInfo(4, 9.6); case E_ITEM_GOLDEN_CARROT: return FoodInfo(6, 14.4); case E_ITEM_MELON_SLICE: return FoodInfo(2, 1.2); + case E_ITEM_MUSHROOM_SOUP: return FoodInfo(6, 7.2); case E_ITEM_POISONOUS_POTATO: return FoodInfo(2, 1.2, 60); - case E_ITEM_POTATO: return FoodInfo(1, 0.6); + // Potatoes handled in ItemSeeds case E_ITEM_PUMPKIN_PIE: return FoodInfo(8, 4.8); case E_ITEM_RAW_BEEF: return FoodInfo(3, 1.8); case E_ITEM_RAW_CHICKEN: return FoodInfo(2, 1.2, 30); @@ -50,7 +51,6 @@ public: case E_ITEM_ROTTEN_FLESH: return FoodInfo(4, 0.8, 80); case E_ITEM_SPIDER_EYE: return FoodInfo(2, 3.2, 100); case E_ITEM_STEAK: return FoodInfo(8, 12.8); - case E_ITEM_MUSHROOM_SOUP: return FoodInfo(6, 7.2); } LOGWARNING("%s: Unknown food item (%d), returning zero nutrition", __FUNCTION__, m_ItemType); return FoodInfo(0, 0.f); diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 302796d1b..9024aafea 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -181,23 +181,28 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) return new cItemMinecartHandler(a_ItemType); } - // Food: + // Food (please keep alpha-sorted): + // (carrots and potatoes handled in SeedHandler as both seed and food + case E_ITEM_BAKED_POTATO: case E_ITEM_BREAD: + case E_ITEM_COOKED_CHICKEN: + case E_ITEM_COOKED_FISH: + case E_ITEM_COOKED_PORKCHOP: case E_ITEM_COOKIE: + case E_ITEM_GOLDEN_APPLE: + case E_ITEM_GOLDEN_CARROT: case E_ITEM_MELON_SLICE: - case E_ITEM_RAW_CHICKEN: - case E_ITEM_COOKED_CHICKEN: + case E_ITEM_MUSHROOM_SOUP: + case E_ITEM_POISONOUS_POTATO: + case E_ITEM_PUMPKIN_PIE: case E_ITEM_RAW_BEEF: - case E_ITEM_RAW_PORKCHOP: - case E_ITEM_STEAK: - case E_ITEM_COOKED_PORKCHOP: + case E_ITEM_RAW_CHICKEN: case E_ITEM_RAW_FISH: - case E_ITEM_COOKED_FISH: + case E_ITEM_RAW_PORKCHOP: case E_ITEM_RED_APPLE: - case E_ITEM_GOLDEN_APPLE: case E_ITEM_ROTTEN_FLESH: - case E_ITEM_MUSHROOM_SOUP: case E_ITEM_SPIDER_EYE: + case E_ITEM_STEAK: { return new cItemFoodHandler(a_ItemType); } @@ -511,7 +516,7 @@ bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item) cItemHandler::FoodInfo cItemHandler::GetFoodInfo() { - return FoodInfo(0, 0.f); + return FoodInfo(0, 0); } diff --git a/src/Items/ItemSeeds.h b/src/Items/ItemSeeds.h index 67f0d38bd..3e20e2d56 100644 --- a/src/Items/ItemSeeds.h +++ b/src/Items/ItemSeeds.h @@ -22,6 +22,26 @@ public: { return true; } + + virtual bool IsFood(void) override + { + switch (m_ItemType) // Special cases, both a seed and food + { + case E_ITEM_CARROT: + case E_ITEM_POTATO: return true; + default: return false; + } + } + + virtual FoodInfo GetFoodInfo(void) override + { + switch (m_ItemType) + { + case E_ITEM_CARROT: return FoodInfo(4, 4.8); + case E_ITEM_POTATO: return FoodInfo(1, 0.6); + default: return FoodInfo(0, 0); + } + } virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, -- cgit v1.2.3 From 70e48960acdbc09bedd4bbeb536e6aa46b50f82e Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 3 Feb 2014 22:30:32 +0100 Subject: Named the different quartz block. --- src/BlockID.h | 5 +++++ src/Blocks/BlockQuartz.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/BlockID.h b/src/BlockID.h index b31c589b9..612eee1fc 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -500,6 +500,11 @@ enum E_META_PLANKS_BIRCH = 2, E_META_PLANKS_JUNGLE = 3, + // E_BLOCK_QUARTZ_BLOCK metas: + E_META_QUARTZ_NORMAL = 0, + E_META_QUARTZ_CHISELLED = 1, + E_META_QUARTZ_PILLAR = 2, + // E_BLOCK_RAIL metas E_META_RAIL_ZM_ZP = 0, E_META_RAIL_XM_XP = 1, diff --git a/src/Blocks/BlockQuartz.h b/src/Blocks/BlockQuartz.h index 41f4e15a7..a9f8f9046 100644 --- a/src/Blocks/BlockQuartz.h +++ b/src/Blocks/BlockQuartz.h @@ -25,7 +25,7 @@ public: { a_BlockType = m_BlockType; NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage); - if (Meta != 0x2) // Check if the block is a pillar block. + if (Meta != E_META_QUARTZ_PILLAR) // Check if the block is a pillar block. { a_BlockMeta = Meta; return true; -- cgit v1.2.3 From 6de8c09fe0044f310397ef94457277f7426470e0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 3 Feb 2014 22:24:22 +0000 Subject: Fixed a crash bug --- src/ClientHandle.cpp | 10 ++-------- src/Entities/Player.cpp | 6 +++--- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index b0eb27089..3e9e03815 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -230,7 +230,7 @@ void cClientHandle::Authenticate(void) if (!cRoot::Get()->GetPluginManager()->CallHookPlayerJoined(*m_Player)) { AString JoinMessage; - AppendPrintf(JoinMessage, "%s[JOIN] %s%s has joined the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), m_Username.c_str()); + AppendPrintf(JoinMessage, "%s[JOIN] %s%s has joined the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), GetUsername().c_str()); cRoot::Get()->BroadcastChat(JoinMessage); LOGINFO("Player %s has joined the game.", m_Username.c_str()); } @@ -2461,13 +2461,7 @@ void cClientHandle::SocketClosed(void) if (m_Username != "") // Ignore client pings { - if (!cRoot::Get()->GetPluginManager()->CallHookDisconnect(m_Player, "Player disconnected")) - { - AString DisconnectMessage; - Printf(DisconnectMessage, "%s[LEAVE] %s%s has left the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), m_Username.c_str()); - cRoot::Get()->BroadcastChat(DisconnectMessage); - LOGINFO("Player %s has left the game.", m_Username.c_str()); - } + cRoot::Get()->GetPluginManager()->CallHookDisconnect(m_Player, "Player disconnected"); } Destroy(); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index d649cacf2..70c881091 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -133,12 +133,12 @@ cPlayer::~cPlayer(void) if (!cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this)) { AString DisconnectMessage; - AppendPrintf(DisconnectMessage, "%s[LEAVE] %s%s has left the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), GetClientHandle()->GetUsername().c_str()); + AppendPrintf(DisconnectMessage, "%s[LEAVE] %s%s has left the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), GetName().c_str()); cRoot::Get()->BroadcastChat(DisconnectMessage); - LOGINFO("Player %s has left the game.", GetClientHandle()->GetUsername().c_str()); + LOGINFO("Player %s has left the game.", GetName().c_str()); } - LOGD("Deleting cPlayer \"%s\" at %p, ID %d", m_PlayerName.c_str(), this, GetUniqueID()); + LOGD("Deleting cPlayer \"%s\" at %p, ID %d", GetName().c_str(), this, GetUniqueID()); // Notify the server that the player is being destroyed cRoot::Get()->GetServer()->PlayerDestroying(this); -- cgit v1.2.3 From fad90081d2c039a2c34badf16ba48e0ae80bc014 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 3 Feb 2014 22:25:16 +0000 Subject: Fixed #491 --- src/OSSupport/File.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 0ebd04915..17070030f 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -73,14 +73,26 @@ bool cFile::Open(const AString & iFileName, eMode iMode) return false; } } - m_File = fopen( (FILE_IO_PREFIX + iFileName).c_str(), Mode); + +#ifdef _WIN32 + fopen_s(&m_File, (FILE_IO_PREFIX + iFileName).c_str(), Mode); +#else + m_File = fopen((FILE_IO_PREFIX + iFileName).c_str(), Mode); +#endif // _WIN32 + if ((m_File == NULL) && (iMode == fmReadWrite)) { // Fix for MS not following C spec, opening "a" mode files for writing at the end only // The file open operation has been tried with "read update", fails if file not found // So now we know either the file doesn't exist or we don't have rights, no need to worry about file contents. // Simply re-open for read-writing, erasing existing contents: - m_File = fopen( (FILE_IO_PREFIX + iFileName).c_str(), "wb+"); + +#ifdef _WIN32 + fopen_s(&m_File, (FILE_IO_PREFIX + iFileName).c_str(), "wb+"); +#else + m_File = fopen((FILE_IO_PREFIX + iFileName).c_str(), "wb+"); +#endif // _WIN32 + } return (m_File != NULL); } -- cgit v1.2.3 From d82f3102e59bec9a0eb45b3731a82c92e2d11b59 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 3 Feb 2014 22:26:16 +0000 Subject: Partial fix for #130 --- src/WorldStorage/NBTChunkSerializer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index c6250f393..95b5e66d2 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -625,6 +625,7 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity) case cEntity::etMonster: AddMonsterEntity ((cMonster *) a_Entity); break; case cEntity::etPickup: AddPickupEntity ((cPickup *) a_Entity); break; case cEntity::etProjectile: AddProjectileEntity ((cProjectileEntity *)a_Entity); break; + case cEntity::etTNT: /* TODO */ break; case cEntity::etExpOrb: /* TODO */ break; case cEntity::etPlayer: return; // Players aren't saved into the world default: -- cgit v1.2.3 From 3583a58cf7bbeb867e568f4210f270cd5058e9f3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 3 Feb 2014 22:46:56 +0000 Subject: Added SendMessageXXX() to cPlayer As requested by @bearbin, one no longer needs to download a file that links to Core. The server does it! Hopefully this encourages standards compliance. --- src/Defines.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/Entities/Player.h | 3 +++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/Defines.h b/src/Defines.h index 5b868b2e5..17885394e 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -1,6 +1,8 @@ #pragma once +#include "ChatColor.h" + @@ -441,7 +443,73 @@ inline float GetSpecialSignf( float a_Val ) -// tolua_begin +enum ChatPrefixCodes +{ + // http://forum.mc-server.org/showthread.php?tid=1212 + // MessageType... + + mtCustom, // Plugin prints what it wants + mtFailure, // Something could not be done (i.e. command not executed due to insufficient privilege) + mtInformation, // Informational message (i.e. command usage) + mtSuccess, // Something executed successfully + mtWarning, // Something concerning (i.e. reload) is about to happen + mtFatal, // Something catastrophic occured (i.e. plugin crash) + mtDeath, // Denotes death of player + mtPrivateMessage // Player to player messaging identifier +}; + + + + +inline AString AppendChatEpithet(const AString & a_ChatMessage, ChatPrefixCodes a_ChatPrefix) +{ + switch (a_ChatPrefix) + { + case mtCustom: return a_ChatMessage; + case mtFailure: + { + AString Message(Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtInformation: + { + AString Message(Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtSuccess: + { + AString Message(Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtWarning: + { + AString Message(Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtFatal: + { + AString Message(Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtDeath: + { + AString Message(Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtPrivateMessage: + { + AString Message(Printf("%s[MSG] %s%s", cChatColor::LightBlue.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str())); + Message.append(a_ChatMessage); + return Message; + } + } +}// tolua_begin /// Normalizes an angle in degrees to the [-180, +180) range: inline double NormalizeAngleDegrees(const double a_Degrees) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 50f7560d6..764b47ae0 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -196,6 +196,9 @@ public: cClientHandle * GetClientHandle(void) const { return m_ClientHandle; } void SendMessage(const AString & a_Message); + void SendMessageInfo(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtInformation)); } + void SendMessageFailure(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtFailure)); } + void SendMessageSuccess(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtSuccess)); } const AString & GetName(void) const { return m_PlayerName; } void SetName(const AString & a_Name) { m_PlayerName = a_Name; } -- cgit v1.2.3 From 01c723e89eb364b9245386bcdd2902b287ee2982 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 3 Feb 2014 22:51:26 +0000 Subject: Pickup constructor no longer exported It didn't do anything without Initialize() exported, anyway, pickups are spawned with cWorld. --- src/Entities/ExpOrb.h | 1 + src/Entities/Floater.h | 4 +++- src/Entities/Pickup.h | 7 ++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Entities/ExpOrb.h b/src/Entities/ExpOrb.h index a062eedd3..47d86922c 100644 --- a/src/Entities/ExpOrb.h +++ b/src/Entities/ExpOrb.h @@ -13,6 +13,7 @@ class cExpOrb : typedef cExpOrb super; public: + CLASS_PROTODEF(cExpOrb); cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward); cExpOrb(const Vector3d & a_Pos, int a_Reward); diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h index 162b74e75..865d6dc50 100644 --- a/src/Entities/Floater.h +++ b/src/Entities/Floater.h @@ -14,8 +14,10 @@ class cFloater : typedef cFloater super; public: - //tolua_end + + CLASS_PROTODEF(cFloater); + cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID, int a_CountDownTime); virtual void SpawnOn(cClientHandle & a_Client) override; diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h index d39eda298..c273567d1 100644 --- a/src/Entities/Pickup.h +++ b/src/Entities/Pickup.h @@ -18,15 +18,16 @@ class cPlayer; class cPickup : public cEntity { - // tolua_end typedef cEntity super; public: + // tolua_end + CLASS_PROTODEF(cPickup); - cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); // tolua_export + cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); - cItem & GetItem(void) {return m_Item; } // tolua_export + cItem & GetItem(void) {return m_Item; } // tolua_export const cItem & GetItem(void) const {return m_Item; } virtual void SpawnOn(cClientHandle & a_ClientHandle) override; -- cgit v1.2.3 From d1b5f0859a4176a31f764b23cf0fce49743d245e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 3 Feb 2014 22:55:15 +0000 Subject: Greatly improved TNT propulsion chances --- src/ChunkMap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 1e2181f32..757396a20 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1808,7 +1808,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ if (FinalDamage > a_Entity->GetMaxHealth()) FinalDamage = a_Entity->GetMaxHealth(); else if (FinalDamage < 0) - return false; + FinalDamage = 0; if (!a_Entity->IsTNT()) // Don't apply damage to other TNT entities, they should be invincible { -- cgit v1.2.3 From 1bd939c4d4f27b5a04c65446d8119c132a2b64ab Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 00:16:13 +0100 Subject: InfoDump: Fixed export for undeclared command param combinations. --- MCServer/Plugins/InfoDump.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index 6b1da7a77..28a17c214 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -149,7 +149,7 @@ local function GetCommandRefForum(a_Command) if (type(a_Command) == "string") then return "[color=blue]" .. a_Command .. "[/color]"; end - return "[color=blue]" .. a_Command.Name .. "[/color] [color=green]" .. a_Command.Params .. "[/color]"; + return "[color=blue]" .. a_Command.Name .. "[/color] [color=green]" .. (a_Command.Params or "") .. "[/color]"; end @@ -169,7 +169,7 @@ local function WriteCommandParameterCombinationsForum(a_CmdString, a_ParameterCo f:write("The following parameter combinations are recognized:\n"); for idx, combination in ipairs(a_ParameterCombinations) do - f:write("[color=blue]", a_CmdString, "[/color] [color=green]", combination.Params, "[/color]"); + f:write("[color=blue]", a_CmdString, "[/color] [color=green]", combination.Params or "", "[/color]"); if (combination.Help ~= nil) then f:write(" - ", ForumizeString(combination.Help)); end -- cgit v1.2.3 From aa19f4fd042c7085d1b7f6d692ffee7bf5a7ff80 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 09:18:32 +0100 Subject: Improved error resistance in cPluginManager:CallPlugin(). Fixed: If the call failed, all the next plugin calls would fail as well. --- src/Bindings/LuaState.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index d49cd8ef3..6a02197e8 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1066,6 +1066,8 @@ int cLuaState::CallFunctionWithForeignParams( { // Something went wrong, fix the stack and exit lua_pop(m_LuaState, 2); + m_NumCurrentFunctionArgs = -1; + m_CurrentFunctionName.clear(); return -1; } @@ -1081,11 +1083,17 @@ int cLuaState::CallFunctionWithForeignParams( { lua_pop(m_LuaState, CurTop - OldTop); } + + // Reset the internal checking mechanisms: + m_NumCurrentFunctionArgs = -1; + m_CurrentFunctionName.clear(); + return -1; } // Reset the internal checking mechanisms: m_NumCurrentFunctionArgs = -1; + m_CurrentFunctionName.clear(); // Remove the error handler from the stack: lua_remove(m_LuaState, OldTop + 1); -- cgit v1.2.3 From 69c85e5169e5322857d2dfbfccd45281ca1be1c4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 10:29:10 +0100 Subject: Fixed error handling in cPluginManager:CallPlugin() API. Fixed: When the called function malfunctioned, the entire plugin's call was aborted. --- src/Bindings/LuaState.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 6a02197e8..0a3f6f5b7 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1072,7 +1072,8 @@ int cLuaState::CallFunctionWithForeignParams( } // Call the function, with an error handler: - int s = lua_pcall(m_LuaState, a_SrcParamEnd - a_SrcParamStart + 1, LUA_MULTRET, OldTop); + LogStack("Before pcall"); + int s = lua_pcall(m_LuaState, a_SrcParamEnd - a_SrcParamStart + 1, LUA_MULTRET, OldTop + 1); if (ReportErrors(s)) { LOGWARN("Error while calling function '%s' in '%s'", a_FunctionName.c_str(), m_SubsystemName.c_str()); @@ -1088,7 +1089,9 @@ int cLuaState::CallFunctionWithForeignParams( m_NumCurrentFunctionArgs = -1; m_CurrentFunctionName.clear(); - return -1; + // Make Lua think everything is okay and return 0 values, so that plugins continue executing. + // The failure is indicated by the zero return values. + return 0; } // Reset the internal checking mechanisms: -- cgit v1.2.3 From 1dbfd7eb764f1ad32351257de85925a256c2bc45 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 11:37:34 +0100 Subject: Removed a leftover debug message. --- src/Bindings/LuaState.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 0a3f6f5b7..1bec5e525 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1072,7 +1072,6 @@ int cLuaState::CallFunctionWithForeignParams( } // Call the function, with an error handler: - LogStack("Before pcall"); int s = lua_pcall(m_LuaState, a_SrcParamEnd - a_SrcParamStart + 1, LUA_MULTRET, OldTop + 1); if (ReportErrors(s)) { -- cgit v1.2.3 From 3dc1452790c1986daa0375da15b79cc3f8ae61a8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 14:26:36 +0100 Subject: Fixed calling plugins with userdata params. --- src/Bindings/LuaState.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 1bec5e525..8dd17c448 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1162,6 +1162,7 @@ int cLuaState::CopyStackFrom(cLuaState & a_SrcLuaState, int a_SrcStart, int a_Sr // Copy the value: void * ud = tolua_touserdata(a_SrcLuaState, i, NULL); tolua_pushusertype(m_LuaState, ud, type); + break; } default: { -- cgit v1.2.3 From a845b9abbb2531761b1ff25ba0e4d1958a4e9299 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Tue, 4 Feb 2014 17:29:36 +0100 Subject: Blank lines and indentation. Also removed GetClosestPlayer documentation --- MCServer/Plugins/APIDump/APIDesc.lua | 1 - src/Mobs/Monster.cpp | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index fb82ac270..e9f0e456f 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2045,7 +2045,6 @@ end ForEachEntity = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the loaded world. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cEntity|Entity}}, [CallbackData])
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, ForEachEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the specified chunk. Returns true if all the entities have been processed (including when there are zero entities), or false if the chunk is not loaded or the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cEntity|Entity}}, [CallbackData])
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, ForEachFurnaceInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each furnace in the chunk. Returns true if all furnaces in the chunk have been processed (including when there are zero furnaces), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature:
function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])
The callback should return false or no value to continue with the next furnace, or true to abort the enumeration." }, - FindClosestPlayer = { Params = "Vector3d(Position), MaxPlayerDistance", Return = "cPlayer", Notes = "Returns nearest player cPlayer's object" }, ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cPlayer|Player}}, [CallbackData])
The callback should return false or no value to continue with the next player, or true to abort the enumeration." }, GenerateChunk = { Params = "ChunkX, ChunkZ", Return = "", Notes = "Queues the specified chunk in the chunk generator. Ignored if the chunk is already generated (use RegenerateChunk() to force chunk re-generation)." }, GetBiomeAt = { Params = "BlockX, BlockZ", Return = "eBiome", Notes = "Returns the biome at the specified coords. Reads the biome from the chunk, if it is loaded, otherwise it uses the chunk generator to provide the biome value." }, diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 35880bcff..340761a7e 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -188,6 +188,10 @@ void cMonster::MoveToPosition(const Vector3f & a_Position) TickPathFinding(); } + + + + void cMonster::MoveToPosition(const Vector3d & a_Position) { FinishPathFinding(); -- cgit v1.2.3 From f3f4c5b110c23df2ee1aa8a45c9d7fdb923402e9 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Tue, 4 Feb 2014 17:31:17 +0100 Subject: Fixed indentation --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index e9f0e456f..e281830b8 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2045,7 +2045,7 @@ end ForEachEntity = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the loaded world. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cEntity|Entity}}, [CallbackData])
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, ForEachEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the specified chunk. Returns true if all the entities have been processed (including when there are zero entities), or false if the chunk is not loaded or the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cEntity|Entity}}, [CallbackData])
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, ForEachFurnaceInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each furnace in the chunk. Returns true if all furnaces in the chunk have been processed (including when there are zero furnaces), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature:
function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])
The callback should return false or no value to continue with the next furnace, or true to abort the enumeration." }, - ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cPlayer|Player}}, [CallbackData])
The callback should return false or no value to continue with the next player, or true to abort the enumeration." }, + ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cPlayer|Player}}, [CallbackData])
The callback should return false or no value to continue with the next player, or true to abort the enumeration." }, GenerateChunk = { Params = "ChunkX, ChunkZ", Return = "", Notes = "Queues the specified chunk in the chunk generator. Ignored if the chunk is already generated (use RegenerateChunk() to force chunk re-generation)." }, GetBiomeAt = { Params = "BlockX, BlockZ", Return = "eBiome", Notes = "Returns the biome at the specified coords. Reads the biome from the chunk, if it is loaded, otherwise it uses the chunk generator to provide the biome value." }, GetBlock = -- cgit v1.2.3 From dd1d85c8ad245390cf8f83f3af28662dd3cc5c07 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 18:27:05 +0100 Subject: Fixed indent from previous commits. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index e281830b8..948f55a22 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2045,7 +2045,7 @@ end ForEachEntity = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the loaded world. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cEntity|Entity}}, [CallbackData])
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, ForEachEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the specified chunk. Returns true if all the entities have been processed (including when there are zero entities), or false if the chunk is not loaded or the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cEntity|Entity}}, [CallbackData])
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, ForEachFurnaceInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each furnace in the chunk. Returns true if all furnaces in the chunk have been processed (including when there are zero furnaces), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature:
function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])
The callback should return false or no value to continue with the next furnace, or true to abort the enumeration." }, - ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cPlayer|Player}}, [CallbackData])
The callback should return false or no value to continue with the next player, or true to abort the enumeration." }, + ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cPlayer|Player}}, [CallbackData])
The callback should return false or no value to continue with the next player, or true to abort the enumeration." }, GenerateChunk = { Params = "ChunkX, ChunkZ", Return = "", Notes = "Queues the specified chunk in the chunk generator. Ignored if the chunk is already generated (use RegenerateChunk() to force chunk re-generation)." }, GetBiomeAt = { Params = "BlockX, BlockZ", Return = "eBiome", Notes = "Returns the biome at the specified coords. Reads the biome from the chunk, if it is loaded, otherwise it uses the chunk generator to provide the biome value." }, GetBlock = -- cgit v1.2.3 From 634331fd3b84c4099dfbfbbde3edebf2a1f221eb Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 18:38:10 +0100 Subject: Fixed chest placement. Fixes #624. --- src/Blocks/BlockChest.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 014b98063..280f2f288 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -110,9 +110,11 @@ public: return "step.wood"; } - virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { - return CanBeAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width; + int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width; + return CanBeAt(a_ChunkInterface, BlockX, a_RelY, BlockZ); } -- cgit v1.2.3 From 8464f689ea214d3c30105ae58539885cf1268317 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 4 Feb 2014 10:59:05 -0800 Subject: Improved Type safety of eBlockFace May Fix #640 --- src/Blocks/BlockBed.cpp | 4 ++-- src/Blocks/BlockBed.h | 4 ++-- src/Blocks/BlockButton.h | 8 ++++---- src/Blocks/BlockCarpet.h | 2 +- src/Blocks/BlockChest.h | 4 ++-- src/Blocks/BlockComparator.h | 4 ++-- src/Blocks/BlockDoor.cpp | 4 ++-- src/Blocks/BlockDoor.h | 6 +++--- src/Blocks/BlockDropSpenser.h | 2 +- src/Blocks/BlockEnderchest.h | 2 +- src/Blocks/BlockEntity.h | 2 +- src/Blocks/BlockFenceGate.h | 4 ++-- src/Blocks/BlockFurnace.h | 2 +- src/Blocks/BlockHandler.cpp | 6 +++--- src/Blocks/BlockHandler.h | 6 +++--- src/Blocks/BlockHopper.h | 2 +- src/Blocks/BlockLadder.h | 33 +++++++++++++++++---------------- src/Blocks/BlockLever.h | 8 ++++---- src/Blocks/BlockPiston.cpp | 2 +- src/Blocks/BlockPiston.h | 2 +- src/Blocks/BlockPlanks.h | 2 +- src/Blocks/BlockPortal.h | 2 +- src/Blocks/BlockPumpkin.h | 4 ++-- src/Blocks/BlockQuartz.h | 6 +++--- src/Blocks/BlockRail.h | 4 ++-- src/Blocks/BlockRedstoneRepeater.h | 4 ++-- src/Blocks/BlockSideways.h | 4 ++-- src/Blocks/BlockSign.h | 4 ++-- src/Blocks/BlockSlab.h | 2 +- src/Blocks/BlockSnow.h | 2 +- src/Blocks/BlockStairs.h | 2 +- src/Blocks/BlockTorch.h | 16 ++++++++-------- src/Blocks/BlockTrapdoor.h | 8 ++++---- src/Blocks/BlockVine.h | 2 +- src/Blocks/BlockWorkbench.h | 2 +- src/BoundingBox.cpp | 6 +++--- src/BoundingBox.h | 5 +++-- src/ClientHandle.cpp | 10 +++++----- src/ClientHandle.h | 10 +++++----- src/Defines.h | 6 ++---- src/Entities/Floater.cpp | 4 ++-- src/Entities/ProjectileEntity.cpp | 22 +++++++++++----------- src/Entities/ProjectileEntity.h | 18 +++++++++--------- src/Items/ItemBed.h | 2 +- src/Items/ItemBoat.h | 4 ++-- src/Items/ItemBow.h | 4 ++-- src/Items/ItemBrewingStand.h | 2 +- src/Items/ItemBucket.h | 4 ++-- src/Items/ItemCauldron.h | 2 +- src/Items/ItemComparator.h | 2 +- src/Items/ItemDoor.h | 2 +- src/Items/ItemDye.h | 2 +- src/Items/ItemFishingRod.h | 4 ++-- src/Items/ItemFlowerPot.h | 2 +- src/Items/ItemHandler.cpp | 6 +++--- src/Items/ItemHandler.h | 8 ++++---- src/Items/ItemHoe.h | 2 +- src/Items/ItemLeaves.h | 2 +- src/Items/ItemLighter.h | 2 +- src/Items/ItemMinecart.h | 2 +- src/Items/ItemNetherWart.h | 4 ++-- src/Items/ItemRedstoneDust.h | 2 +- src/Items/ItemRedstoneRepeater.h | 2 +- src/Items/ItemSapling.h | 2 +- src/Items/ItemSeeds.h | 2 +- src/Items/ItemShears.h | 2 +- src/Items/ItemShovel.h | 2 +- src/Items/ItemSign.h | 2 +- src/Items/ItemSpawnEgg.h | 2 +- src/Items/ItemSugarcane.h | 2 +- src/Items/ItemThrowable.h | 6 +++--- src/Piston.h | 21 ++++++++++++++++++++- src/Protocol/Protocol125.cpp | 4 ++-- src/Protocol/Protocol132.cpp | 2 +- src/Protocol/Protocol17x.cpp | 4 ++-- src/Simulator/RedstoneSimulator.cpp | 5 +++-- 76 files changed, 194 insertions(+), 174 deletions(-) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 65d397b36..2fd993817 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -7,7 +7,7 @@ void cBlockBedHandler::OnPlacedByPlayer( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) @@ -51,7 +51,7 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInt -void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { if (a_WorldInterface.GetDimension() != dimOverworld) { diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 0b86fe5e7..caec2b56f 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -20,9 +20,9 @@ public: } - virtual void OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; + virtual void OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; - virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; virtual bool IsUseable(void) override diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index f592b94a1..ca6850ced 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -16,7 +16,7 @@ public: } - virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Set p the ON bit to on NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); @@ -44,7 +44,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -61,7 +61,7 @@ public: } - inline static NIBBLETYPE BlockFaceToMetaData(char a_BlockFace) + inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace) { switch (a_BlockFace) { @@ -77,7 +77,7 @@ public: } } - inline static NIBBLETYPE BlockMetaDataToBlockFace(NIBBLETYPE a_Meta) + inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta) { switch (a_Meta & 0x7) { diff --git a/src/Blocks/BlockCarpet.h b/src/Blocks/BlockCarpet.h index 757d62c33..33dc1da6c 100644 --- a/src/Blocks/BlockCarpet.h +++ b/src/Blocks/BlockCarpet.h @@ -32,7 +32,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 014b98063..c2ac8ae27 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -21,7 +21,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -67,7 +67,7 @@ public: virtual void OnPlacedByPlayer( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) override diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index 3b32efd6b..aba390d9d 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -18,7 +18,7 @@ public: } - virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); Meta ^= 0x04; // Toggle 3rd (addition/subtraction) bit with XOR @@ -47,7 +47,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index 9d891f2b2..2ff5c1c37 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -43,7 +43,7 @@ void cBlockDoorHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldIn -void cBlockDoorHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockDoorHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { if (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_DOOR) { @@ -57,7 +57,7 @@ void cBlockDoorHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterfac void cBlockDoorHandler::OnPlacedByPlayer( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 2da561952..ef0dbb787 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -15,13 +15,13 @@ public: cBlockDoorHandler(BLOCKTYPE a_BlockType); virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; - virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; virtual const char * GetStepSound(void) override; virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -54,7 +54,7 @@ public: virtual void OnPlacedByPlayer( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) override; diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index 0c285612e..30d347ec9 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -23,7 +23,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index 7ea09cd4c..b4b0b995d 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -24,7 +24,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockEntity.h b/src/Blocks/BlockEntity.h index f05bf16b1..7f86a22b2 100644 --- a/src/Blocks/BlockEntity.h +++ b/src/Blocks/BlockEntity.h @@ -15,7 +15,7 @@ public: { } - virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { a_ChunkInterface.UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); } diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index 2d0cfb8fd..fb984f345 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -19,7 +19,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -30,7 +30,7 @@ public: } - virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { NIBBLETYPE OldMetaData = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); NIBBLETYPE NewMetaData = PlayerYawToMetaData(a_Player->GetYaw()); diff --git a/src/Blocks/BlockFurnace.h b/src/Blocks/BlockFurnace.h index bbc50de9f..27ef2689f 100644 --- a/src/Blocks/BlockFurnace.h +++ b/src/Blocks/BlockFurnace.h @@ -27,7 +27,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 657058e3e..6c9bbeb02 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -250,7 +250,7 @@ cBlockHandler::cBlockHandler(BLOCKTYPE a_BlockType) bool cBlockHandler::GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) @@ -273,7 +273,7 @@ void cBlockHandler::OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface -void cBlockHandler::OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +void cBlockHandler::OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { } @@ -347,7 +347,7 @@ void cBlockHandler::OnDigging(cChunkInterface & a_ChunkInterface, cWorldInterfac -void cBlockHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { } diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 44b15bce1..a2913d7f8 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -35,7 +35,7 @@ public: */ virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ); @@ -46,7 +46,7 @@ public: /// Called by cClientHandle::HandlePlaceBlock() after the player has placed a new block. Called after OnPlaced(). virtual void OnPlacedByPlayer( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ); @@ -67,7 +67,7 @@ public: virtual void OnDigging(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ); /// Called if the user right clicks the block and the block is useable - virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); /// Called when the item is mined to convert it into pickups. Pickups may specify multiple items. Appends items to a_Pickups, preserves its original contents virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta); diff --git a/src/Blocks/BlockHopper.h b/src/Blocks/BlockHopper.h index aa0317660..59b84aa0e 100644 --- a/src/Blocks/BlockHopper.h +++ b/src/Blocks/BlockHopper.h @@ -19,7 +19,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h index 5c2b542c0..6a105d5c9 100644 --- a/src/Blocks/BlockLadder.h +++ b/src/Blocks/BlockLadder.h @@ -20,7 +20,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -41,37 +41,38 @@ public: } - static NIBBLETYPE DirectionToMetaData(char a_Direction) // tolua_export + static NIBBLETYPE DirectionToMetaData(eBlockFace a_Direction) // tolua_export { // tolua_export switch (a_Direction) { - case 0x2: return 0x2; - case 0x3: return 0x3; - case 0x4: return 0x4; - case 0x5: return 0x5; + case BLOCK_FACE_ZM: return 0x2; + case BLOCK_FACE_ZP: return 0x3; + case BLOCK_FACE_XM: return 0x4; + case BLOCK_FACE_XP: return 0x5; default: return 0x2; } } // tolua_export - static char MetaDataToDirection(NIBBLETYPE a_MetaData) // tolua_export + static eBlockFace MetaDataToDirection(NIBBLETYPE a_MetaData) // tolua_export { // tolua_export switch (a_MetaData) { - case 0x2: return 0x2; - case 0x3: return 0x3; - case 0x4: return 0x4; - case 0x5: return 0x5; - default: return 0x2; + case 0x2: return BLOCK_FACE_ZM; + case 0x3: return BLOCK_FACE_ZP; + case 0x4: return BLOCK_FACE_XM; + case 0x5: return BLOCK_FACE_XP; + default: return BLOCK_FACE_ZM; } } // tolua_export /// Finds a suitable Direction for the Ladder. Returns BLOCK_FACE_BOTTOM on failure - static char FindSuitableBlockFace(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + static eBlockFace FindSuitableBlockFace(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - for (int Face = 2; Face <= 5; Face++) + for (int FaceInt = BLOCK_FACE_ZM; FaceInt <= BLOCK_FACE_XP; FaceInt++) { + eBlockFace Face = static_cast(FaceInt); if (LadderCanBePlacedAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, Face)) { return Face; @@ -81,7 +82,7 @@ public: } - static bool LadderCanBePlacedAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) + static bool LadderCanBePlacedAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) { if ((a_BlockFace == BLOCK_FACE_BOTTOM) || (a_BlockFace == BLOCK_FACE_TOP)) { @@ -97,7 +98,7 @@ public: virtual bool CanBeAt(cChunkInterface & a_ChunkInterface,int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { // TODO: Use AdjustCoordsByMeta(), then cChunk::UnboundedRelGetBlock() and finally some comparison - char BlockFace = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); + eBlockFace BlockFace = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width; int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width; return LadderCanBePlacedAt(a_ChunkInterface, BlockX, a_RelY, BlockZ, BlockFace); diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index 09b600759..48c7e774b 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -15,7 +15,7 @@ public: { } - virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Flip the ON bit on/off using the XOR bitwise operation NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08); @@ -40,7 +40,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -51,7 +51,7 @@ public: } - inline static NIBBLETYPE LeverDirectionToMetaData(char a_Dir) + inline static NIBBLETYPE LeverDirectionToMetaData(eBlockFace a_Dir) { // Determine lever direction: switch (a_Dir) @@ -73,7 +73,7 @@ public: } - inline static NIBBLETYPE BlockMetaDataToBlockFace(NIBBLETYPE a_Meta) + inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta) { switch (a_Meta & 0x7) { diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp index e960d23e4..542eb33b5 100644 --- a/src/Blocks/BlockPiston.cpp +++ b/src/Blocks/BlockPiston.cpp @@ -54,7 +54,7 @@ void cBlockPistonHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorld bool cBlockPistonHandler::GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index de40afdd6..7632b5e5a 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -17,7 +17,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override; diff --git a/src/Blocks/BlockPlanks.h b/src/Blocks/BlockPlanks.h index 483761b5f..2a99a455e 100644 --- a/src/Blocks/BlockPlanks.h +++ b/src/Blocks/BlockPlanks.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockPortal.h b/src/Blocks/BlockPortal.h index dc916990e..21bcbdeea 100644 --- a/src/Blocks/BlockPortal.h +++ b/src/Blocks/BlockPortal.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockPumpkin.h b/src/Blocks/BlockPumpkin.h index 4a33d1d16..349f52605 100644 --- a/src/Blocks/BlockPumpkin.h +++ b/src/Blocks/BlockPumpkin.h @@ -14,7 +14,7 @@ public: { } - virtual void OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override + virtual void OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override { // Check whether the pumpkin is a part of a golem or a snowman @@ -80,7 +80,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockQuartz.h b/src/Blocks/BlockQuartz.h index a9f8f9046..9cc51490f 100644 --- a/src/Blocks/BlockQuartz.h +++ b/src/Blocks/BlockQuartz.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -35,7 +35,7 @@ public: return true; } - inline static NIBBLETYPE BlockFaceToMetaData(char a_BlockFace, NIBBLETYPE a_QuartzMeta) + inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace, NIBBLETYPE a_QuartzMeta) { switch (a_BlockFace) { @@ -64,4 +64,4 @@ public: } } } -} ; \ No newline at end of file +} ; diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 65c6889de..52d6f60b3 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -31,7 +31,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -344,7 +344,7 @@ public: } - bool IsNotConnected(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Pure = 0) + bool IsNotConnected(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, char a_Pure = 0) { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, false); NIBBLETYPE Meta; diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h index a48fed8b6..eb0918acf 100644 --- a/src/Blocks/BlockRedstoneRepeater.h +++ b/src/Blocks/BlockRedstoneRepeater.h @@ -20,7 +20,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -31,7 +31,7 @@ public: } - virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, ((a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f)); } diff --git a/src/Blocks/BlockSideways.h b/src/Blocks/BlockSideways.h index f11f0bee1..69c0a7230 100644 --- a/src/Blocks/BlockSideways.h +++ b/src/Blocks/BlockSideways.h @@ -18,7 +18,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -30,7 +30,7 @@ public: } - inline static NIBBLETYPE BlockFaceToMetaData(char a_BlockFace, NIBBLETYPE a_WoodMeta) + inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace, NIBBLETYPE a_WoodMeta) { switch (a_BlockFace) { diff --git a/src/Blocks/BlockSign.h b/src/Blocks/BlockSign.h index dced0008c..cd0c02a40 100644 --- a/src/Blocks/BlockSign.h +++ b/src/Blocks/BlockSign.h @@ -45,7 +45,7 @@ public: } - static char DirectionToMetaData(char a_Direction) + static char DirectionToMetaData(eBlockFace a_Direction) { switch (a_Direction) { @@ -64,7 +64,7 @@ public: virtual void OnPlacedByPlayer( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) override diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index 51e78393a..3628303ce 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -34,7 +34,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockSnow.h b/src/Blocks/BlockSnow.h index b79ef9f64..a3daf0393 100644 --- a/src/Blocks/BlockSnow.h +++ b/src/Blocks/BlockSnow.h @@ -19,7 +19,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index d50014dd1..c1887bc46 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -20,7 +20,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index c3b25c899..13f961d21 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -19,7 +19,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -57,7 +57,7 @@ public: } - inline static NIBBLETYPE DirectionToMetaData(char a_Direction) + inline static NIBBLETYPE DirectionToMetaData(eBlockFace a_Direction) { switch (a_Direction) { @@ -77,7 +77,7 @@ public: } - inline static char MetaDataToDirection(NIBBLETYPE a_MetaData) + inline static eBlockFace MetaDataToDirection(NIBBLETYPE a_MetaData) { switch (a_MetaData) { @@ -93,11 +93,11 @@ public: break; } } - return 0; + return BLOCK_FACE_TOP; } - static bool CanBePlacedOn(BLOCKTYPE a_BlockType, char a_BlockFace) + static bool CanBePlacedOn(BLOCKTYPE a_BlockType, eBlockFace a_BlockFace) { if ( !g_BlockFullyOccupiesVoxel[a_BlockType] ) { @@ -111,9 +111,9 @@ public: /// Finds a suitable face to place the torch, returning BLOCK_FACE_NONE on failure - static char FindSuitableFace(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + static eBlockFace FindSuitableFace(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - for (int i = BLOCK_FACE_YM; i <= BLOCK_FACE_XP; i++) // Loop through all directions + for (eBlockFace i = BLOCK_FACE_YM; i <= BLOCK_FACE_XP; i++) // Loop through all directions { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, i, true); BLOCKTYPE BlockInQuestion = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ); @@ -145,7 +145,7 @@ public: virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { - char Face = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); + eBlockFace Face = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); AddFaceDirection(a_RelX, a_RelY, a_RelZ, Face, true); BLOCKTYPE BlockInQuestion; diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index f549b4183..37e79a1e1 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -32,7 +32,7 @@ public: return true; } - virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Flip the ON bit on/off using the XOR bitwise operation NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x04); @@ -42,7 +42,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -57,7 +57,7 @@ public: return true; } - inline static NIBBLETYPE BlockFaceToMetaData(char a_BlockFace) + inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace) { switch (a_BlockFace) { @@ -73,7 +73,7 @@ public: } } - inline static NIBBLETYPE BlockMetaDataToBlockFace(NIBBLETYPE a_Meta) + inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta) { switch (a_Meta & 0x3) { diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index aa0d582b3..ee7dcee8a 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -19,7 +19,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Blocks/BlockWorkbench.h b/src/Blocks/BlockWorkbench.h index 1c08adb43..70468369c 100644 --- a/src/Blocks/BlockWorkbench.h +++ b/src/Blocks/BlockWorkbench.h @@ -19,7 +19,7 @@ public: } - virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { cWindow * Window = new cCraftingWindow(a_BlockX, a_BlockY, a_BlockZ); a_Player->OpenWindow(Window); diff --git a/src/BoundingBox.cpp b/src/BoundingBox.cpp index d0943d42a..86d4546c7 100644 --- a/src/BoundingBox.cpp +++ b/src/BoundingBox.cpp @@ -228,7 +228,7 @@ bool cBoundingBox::IsInside(const Vector3d & a_Min, const Vector3d & a_Max, doub -bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, char & a_Face) +bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, eBlockFace & a_Face) { return CalcLineIntersection(m_Min, m_Max, a_Line1, a_Line2, a_LineCoeff, a_Face); } @@ -237,7 +237,7 @@ bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Line1, const Vector3d -bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d & a_Max, const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, char & a_Face) +bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d & a_Max, const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, eBlockFace & a_Face) { if (IsInside(a_Min, a_Max, a_Line1)) { @@ -247,7 +247,7 @@ bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d & return true; } - char Face = BLOCK_FACE_NONE; + eBlockFace Face = BLOCK_FACE_NONE; double Coeff = Vector3d::NO_INTERSECTION; // Check each individual bbox face for intersection with the line, remember the one with the lowest coeff diff --git a/src/BoundingBox.h b/src/BoundingBox.h index ff9963989..9ac5f11b8 100644 --- a/src/BoundingBox.h +++ b/src/BoundingBox.h @@ -9,6 +9,7 @@ #pragma once #include "Vector3d.h" +#include "Defines.h" @@ -66,13 +67,13 @@ public: Also calculates the distance along the line in which the intersection occurs (0 .. 1) Only forward collisions (a_LineCoeff >= 0) are returned. */ - bool CalcLineIntersection(const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, char & a_Face); + bool CalcLineIntersection(const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, eBlockFace & a_Face); /** Returns true if the specified bounding box is intersected by the line specified by its two points Also calculates the distance along the line in which the intersection occurs (0 .. 1) and the face hit (BLOCK_FACE_ constants) Only forward collisions (a_LineCoeff >= 0) are returned. */ - static bool CalcLineIntersection(const Vector3d & a_Min, const Vector3d & a_Max, const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, char & a_Face); + static bool CalcLineIntersection(const Vector3d & a_Min, const Vector3d & a_Max, const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, eBlockFace & a_Face); // tolua_end diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 6b61eaae8..aa43f192c 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -620,7 +620,7 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a -void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) +void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, char a_Status) { LOGD("HandleLeftClick: {%i, %i, %i}; Face: %i; Stat: %i", a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status @@ -721,7 +721,7 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, ch -void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta) +void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta) { if ( m_HasStartedDigging && @@ -795,7 +795,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc -void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta) +void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta) { if ( !m_HasStartedDigging || // Hasn't received the DIG_STARTED packet @@ -844,7 +844,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo -void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem) +void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem) { LOGD("HandleRightClick: {%d, %d, %d}, face %d, HeldItem: %s", a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, ItemToFullString(a_HeldItem).c_str() @@ -946,7 +946,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, c -void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler) +void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler) { if (a_BlockFace < 0) { diff --git a/src/ClientHandle.h b/src/ClientHandle.h index e1f326543..a4a22e4df 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -184,7 +184,7 @@ public: bool HandleHandshake (const AString & a_Username); void HandleKeepAlive (int a_KeepAliveID); - void HandleLeftClick (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status); + void HandleLeftClick (int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, char a_Status); void HandlePing (void); void HandlePlayerAbilities (bool a_CanFly, bool a_IsFlying, float FlyingSpeed, float WalkingSpeed); void HandlePlayerLook (float a_Rotation, float a_Pitch, bool a_IsOnGround); @@ -192,7 +192,7 @@ public: void HandlePlayerPos (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround); void HandlePluginMessage (const AString & a_Channel, const AString & a_Message); void HandleRespawn (void); - void HandleRightClick (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem); + void HandleRightClick (int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem); void HandleSlotSelected (short a_SlotNum); void HandleSteerVehicle (float Forward, float Sideways); void HandleTabCompletion (const AString & a_Text); @@ -217,7 +217,7 @@ public: void MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket); /// Handles the block placing packet when it is a real block placement (not block-using, item-using or eating) - void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler); + void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler); private: @@ -325,10 +325,10 @@ private: void StreamChunk(int a_ChunkX, int a_ChunkZ); /// Handles the DIG_STARTED dig packet: - void HandleBlockDigStarted (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta); + void HandleBlockDigStarted (int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta); /// Handles the DIG_FINISHED dig packet: - void HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta); + void HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta); /// Handles the "MC|AdvCdm" plugin message void HandleCommandBlockMessage(const char* a_Data, unsigned int a_Length); diff --git a/src/Defines.h b/src/Defines.h index 5b868b2e5..1a12a8743 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -325,7 +325,7 @@ inline bool IsBlockTypeOfDirt(BLOCKTYPE a_BlockType) -inline void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, char a_BlockFace, bool a_bInverse = false) // tolua_export +inline void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse = false) // tolua_export { // tolua_export if (!a_bInverse) { @@ -369,7 +369,7 @@ inline void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cha -inline void AddFaceDirection(int & a_BlockX, unsigned char & a_BlockY, int & a_BlockZ, char a_BlockFace, bool a_bInverse = false) +inline void AddFaceDirection(int & a_BlockX, unsigned char & a_BlockY, int & a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse = false) { int Y = a_BlockY; AddFaceDirection(a_BlockX, Y, a_BlockZ, a_BlockFace, a_bInverse); @@ -389,8 +389,6 @@ inline void AddFaceDirection(int & a_BlockX, unsigned char & a_BlockY, int & a_B - - #define PI 3.14159265358979323846264338327950288419716939937510582097494459072381640628620899862803482534211706798f inline void EulerToVector(double a_Pan, double a_Pitch, double & a_X, double & a_Y, double & a_Z) diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index dfe77f059..38160a30e 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -35,7 +35,7 @@ public: cBoundingBox EntBox(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight()); double LineCoeff; - char Face; + eBlockFace Face; EntBox.Expand(m_Floater->GetWidth() / 2, m_Floater->GetHeight() / 2, m_Floater->GetWidth() / 2); if (!EntBox.CalcLineIntersection(m_Pos, m_NextPos, LineCoeff, Face)) { @@ -215,4 +215,4 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) SetSpeedZ(GetSpeedZ() * 0.95); BroadcastMovementUpdate(); -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index bffa790a3..a3fa9d557 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -63,7 +63,7 @@ protected: Vector3d Line1 = m_Projectile->GetPosition(); Vector3d Line2 = Line1 + m_Projectile->GetSpeed(); double LineCoeff = 0; - char Face; + eBlockFace Face; if (bb.CalcLineIntersection(Line1, Line2, LineCoeff, Face)) { Vector3d Intersection = Line1 + m_Projectile->GetSpeed() * LineCoeff; @@ -138,7 +138,7 @@ public: // Instead of colliding the bounding box with another bounding box in motion, we collide an enlarged bounding box with a hairline. // The results should be good enough for our purposes double LineCoeff; - char Face; + eBlockFace Face; EntBox.Expand(m_Projectile->GetWidth() / 2, m_Projectile->GetHeight() / 2, m_Projectile->GetWidth() / 2); if (!EntBox.CalcLineIntersection(m_Pos, m_NextPos, LineCoeff, Face)) { @@ -243,7 +243,7 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, -void cProjectileEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) +void cProjectileEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { // Set the position based on what face was hit: SetPosition(a_HitPos); @@ -446,7 +446,7 @@ bool cArrowEntity::CanPickup(const cPlayer & a_Player) const -void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) +void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { if (a_HitFace == BLOCK_FACE_NONE) { return; } @@ -590,7 +590,7 @@ cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, -void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) +void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { if (m_World->GetTickRandomNumber(7) == 1) { @@ -623,7 +623,7 @@ cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X -void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) +void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { // Teleport the creator here, make them take 5 damage: if (m_Creator != NULL) @@ -653,7 +653,7 @@ cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, do -void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) +void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { // TODO: Apply damage to certain mobs (blaze etc.) and anger all mobs @@ -677,7 +677,7 @@ super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) +void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { // Spawn an experience orb with a reward between 3 and 11. m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); @@ -701,7 +701,7 @@ super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -void cFireworkEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) +void cFireworkEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { if ((a_HitFace != BLOCK_FACE_BOTTOM) && (a_HitFace != BLOCK_FACE_NONE)) { @@ -784,7 +784,7 @@ void cGhastFireballEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) -void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) +void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { Destroy(); Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); @@ -830,7 +830,7 @@ void cFireChargeEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) -void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) +void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { Destroy(); Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 4721409ee..e80592999 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -49,7 +49,7 @@ public: static cProjectileEntity * Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d * a_Speed = NULL); /// Called by the physics blocktracer when the entity hits a solid block, the hit position and the face hit (BLOCK_FACE_) is given - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace); + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace); /// Called by the physics blocktracer when the entity hits another entity virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) @@ -174,7 +174,7 @@ protected: Vector3i m_HitBlockPos; // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) override; + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; virtual void CollectedBy(cPlayer * a_Player) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; @@ -204,7 +204,7 @@ protected: // tolua_end // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) override; + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; // tolua_begin @@ -232,7 +232,7 @@ protected: // tolua_end // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) override; + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; // tolua_begin @@ -258,7 +258,7 @@ public: protected: // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) override; + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; // tolua_begin @@ -284,7 +284,7 @@ public: protected: // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) override; + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; // tolua_begin @@ -310,7 +310,7 @@ public: protected: // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) override; + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; // tolua_begin @@ -339,7 +339,7 @@ protected: void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) override; + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; // TODO: Deflecting the fireballs by arrow- or sword- hits @@ -370,7 +370,7 @@ protected: void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) override; + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; // tolua_begin diff --git a/src/Items/ItemBed.h b/src/Items/ItemBed.h index 9b7c8bff8..f23d69731 100644 --- a/src/Items/ItemBed.h +++ b/src/Items/ItemBed.h @@ -26,7 +26,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index 79c8e9589..31d1ca52e 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -29,9 +29,9 @@ public: - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { - if (a_Dir > 0) + if (a_Dir != BLOCK_FACE_YM || a_Dir != BLOCK_FACE_NONE) { return false; } diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index d533c21fd..410c5f512 100644 --- a/src/Items/ItemBow.h +++ b/src/Items/ItemBow.h @@ -27,7 +27,7 @@ public: } - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { ASSERT(a_Player != NULL); @@ -42,7 +42,7 @@ public: } - virtual void OnItemShoot(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override + virtual void OnItemShoot(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override { // Actual shot - produce the arrow with speed based on the ticks that the bow was charged ASSERT(a_Player != NULL); diff --git a/src/Items/ItemBrewingStand.h b/src/Items/ItemBrewingStand.h index 4ff14d4b4..d5eefb855 100644 --- a/src/Items/ItemBrewingStand.h +++ b/src/Items/ItemBrewingStand.h @@ -25,7 +25,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index f18a4d959..72cb8fa0a 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -22,7 +22,7 @@ public: } - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { switch (m_ItemType) { @@ -93,7 +93,7 @@ public: } - bool PlaceFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_FluidBlock) + bool PlaceFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_FluidBlock) { if (a_BlockFace < 0) { diff --git a/src/Items/ItemCauldron.h b/src/Items/ItemCauldron.h index 8b2ddc29f..07ae12660 100644 --- a/src/Items/ItemCauldron.h +++ b/src/Items/ItemCauldron.h @@ -25,7 +25,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemComparator.h b/src/Items/ItemComparator.h index 3a5d1d200..60d9c3648 100644 --- a/src/Items/ItemComparator.h +++ b/src/Items/ItemComparator.h @@ -24,7 +24,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemDoor.h b/src/Items/ItemDoor.h index 531a0c6e4..f3677c28c 100644 --- a/src/Items/ItemDoor.h +++ b/src/Items/ItemDoor.h @@ -25,7 +25,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemDye.h b/src/Items/ItemDye.h index 190cdc510..ccf4714f7 100644 --- a/src/Items/ItemDye.h +++ b/src/Items/ItemDye.h @@ -19,7 +19,7 @@ public: } - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { // Handle growing the plants: if (a_Item.m_ItemDamage == E_META_DYE_WHITE) diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h index b2eaee63a..15acbd9fe 100644 --- a/src/Items/ItemFishingRod.h +++ b/src/Items/ItemFishingRod.h @@ -84,7 +84,7 @@ public: { } - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { if (a_Dir != BLOCK_FACE_NONE) { @@ -230,4 +230,4 @@ public: } return true; } -} ; \ No newline at end of file +} ; diff --git a/src/Items/ItemFlowerPot.h b/src/Items/ItemFlowerPot.h index befa2ff21..60bf87985 100644 --- a/src/Items/ItemFlowerPot.h +++ b/src/Items/ItemFlowerPot.h @@ -25,7 +25,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 302796d1b..f7115c558 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -231,7 +231,7 @@ cItemHandler::cItemHandler(int a_ItemType) -bool cItemHandler::OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) +bool cItemHandler::OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) { return false; } @@ -240,7 +240,7 @@ bool cItemHandler::OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & -bool cItemHandler::OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) +bool cItemHandler::OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) { return false; } @@ -454,7 +454,7 @@ bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType) bool cItemHandler::GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index db0ffc9db..1a6bb044f 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -22,10 +22,10 @@ public: cItemHandler(int a_ItemType); /// Called when the player tries to use the item (right mouse button). Return false to make the item unusable. DEFAULT: False - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir); + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir); /// Called when the client sends the SHOOT status in the lclk packet - virtual void OnItemShoot(cPlayer *, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) + virtual void OnItemShoot(cPlayer *, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) { UNUSED(a_BlockX); UNUSED(a_BlockY); @@ -34,7 +34,7 @@ public: } /// Called while the player diggs a block using this item - virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace); + virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace); /// Called when the player destroys a block using this item. This also calls the drop function for the destroyed block virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_X, int a_Y, int a_Z); @@ -80,7 +80,7 @@ public: */ virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ); diff --git a/src/Items/ItemHoe.h b/src/Items/ItemHoe.h index 7b6b3e6ac..29f7c83d5 100644 --- a/src/Items/ItemHoe.h +++ b/src/Items/ItemHoe.h @@ -19,7 +19,7 @@ public: } - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); diff --git a/src/Items/ItemLeaves.h b/src/Items/ItemLeaves.h index 60222eaa9..12cb45d1c 100644 --- a/src/Items/ItemLeaves.h +++ b/src/Items/ItemLeaves.h @@ -20,7 +20,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemLighter.h b/src/Items/ItemLighter.h index 8f3389d95..6681a08d4 100644 --- a/src/Items/ItemLighter.h +++ b/src/Items/ItemLighter.h @@ -19,7 +19,7 @@ public: { } - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override { if (a_BlockFace < 0) { diff --git a/src/Items/ItemMinecart.h b/src/Items/ItemMinecart.h index 4071f8c60..bcaa5635a 100644 --- a/src/Items/ItemMinecart.h +++ b/src/Items/ItemMinecart.h @@ -28,7 +28,7 @@ public: - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { if (a_Dir < 0) { diff --git a/src/Items/ItemNetherWart.h b/src/Items/ItemNetherWart.h index aa4a44340..a6a9a286a 100644 --- a/src/Items/ItemNetherWart.h +++ b/src/Items/ItemNetherWart.h @@ -25,7 +25,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override @@ -51,4 +51,4 @@ public: return true; } -} ; \ No newline at end of file +} ; diff --git a/src/Items/ItemRedstoneDust.h b/src/Items/ItemRedstoneDust.h index de90c8075..18c6b8615 100644 --- a/src/Items/ItemRedstoneDust.h +++ b/src/Items/ItemRedstoneDust.h @@ -22,7 +22,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemRedstoneRepeater.h b/src/Items/ItemRedstoneRepeater.h index e71c8e672..c5fb5d566 100644 --- a/src/Items/ItemRedstoneRepeater.h +++ b/src/Items/ItemRedstoneRepeater.h @@ -24,7 +24,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemSapling.h b/src/Items/ItemSapling.h index dc0810a45..61b1a32be 100644 --- a/src/Items/ItemSapling.h +++ b/src/Items/ItemSapling.h @@ -20,7 +20,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemSeeds.h b/src/Items/ItemSeeds.h index 67f0d38bd..ba3b2538b 100644 --- a/src/Items/ItemSeeds.h +++ b/src/Items/ItemSeeds.h @@ -25,7 +25,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemShears.h b/src/Items/ItemShears.h index 6a17607ee..b8f75f5ba 100644 --- a/src/Items/ItemShears.h +++ b/src/Items/ItemShears.h @@ -25,7 +25,7 @@ public: } - virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); if (Block == E_BLOCK_LEAVES) diff --git a/src/Items/ItemShovel.h b/src/Items/ItemShovel.h index 4921b257a..873d5ae25 100644 --- a/src/Items/ItemShovel.h +++ b/src/Items/ItemShovel.h @@ -21,7 +21,7 @@ public: } - virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); if (Block == E_BLOCK_SNOW) diff --git a/src/Items/ItemSign.h b/src/Items/ItemSign.h index 8c134ab83..60cf0f5f8 100644 --- a/src/Items/ItemSign.h +++ b/src/Items/ItemSign.h @@ -27,7 +27,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemSpawnEgg.h b/src/Items/ItemSpawnEgg.h index 407d655de..0d6019398 100644 --- a/src/Items/ItemSpawnEgg.h +++ b/src/Items/ItemSpawnEgg.h @@ -19,7 +19,7 @@ public: } - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override { if (a_BlockFace < 0) { diff --git a/src/Items/ItemSugarcane.h b/src/Items/ItemSugarcane.h index ce93aa3e5..e891cc367 100644 --- a/src/Items/ItemSugarcane.h +++ b/src/Items/ItemSugarcane.h @@ -23,7 +23,7 @@ public: virtual bool GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h index fc24e775a..46049f961 100644 --- a/src/Items/ItemThrowable.h +++ b/src/Items/ItemThrowable.h @@ -26,7 +26,7 @@ public: } - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { if (!a_Player->IsGameModeCreative()) { @@ -120,7 +120,7 @@ public: { } - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) { @@ -137,4 +137,4 @@ public: return true; } -}; \ No newline at end of file +}; diff --git a/src/Piston.h b/src/Piston.h index 92ddf6938..9bbc8c6b9 100644 --- a/src/Piston.h +++ b/src/Piston.h @@ -2,7 +2,7 @@ #pragma once - +#include "Defines.h" // fwd: World.h @@ -54,6 +54,25 @@ public: } } } + + static eBlockFace MetaDataToDirection(NIBBLETYPE a_MetaData) + { + switch (a_MetaData) + { + //case -1: return BLOCK_FACE_NONE; //can never happen as metadata is unsigned + case 0x0: return BLOCK_FACE_YM; + case 0x1: return BLOCK_FACE_YP; + case 0x2: return BLOCK_FACE_ZM; + case 0x3: return BLOCK_FACE_ZP; + case 0x4: return BLOCK_FACE_XM; + case 0x5: return BLOCK_FACE_XP; + default: + { + ASSERT(!"Invalid Metadata"); + return BLOCK_FACE_NONE; + } + } + } void ExtendPiston( int, int, int ); void RetractPiston( int, int, int ); diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 323a13992..73d21161c 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1211,7 +1211,7 @@ int cProtocol125::ParseBlockDig(void) HANDLE_PACKET_READ(ReadByte, Byte, PosY); HANDLE_PACKET_READ(ReadBEInt, int, PosZ); HANDLE_PACKET_READ(ReadChar, char, BlockFace); - m_Client->HandleLeftClick(PosX, PosY, PosZ, BlockFace, Status); + m_Client->HandleLeftClick(PosX, PosY, PosZ, static_cast(BlockFace), Status); return PARSE_OK; } @@ -1234,7 +1234,7 @@ int cProtocol125::ParseBlockPlace(void) } // 1.2.5 didn't have any cursor position, so use 8, 8, 8, so that halfslabs and stairs work correctly and the special value is recognizable. - m_Client->HandleRightClick(PosX, PosY, PosZ, BlockFace, 8, 8, 8, HeldItem); + m_Client->HandleRightClick(PosX, PosY, PosZ, static_cast(BlockFace), 8, 8, 8, HeldItem); return PARSE_OK; } diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index f5fd95c7e..648e70151 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -476,7 +476,7 @@ int cProtocol132::ParseBlockPlace(void) HANDLE_PACKET_READ(ReadChar, char, CursorY); HANDLE_PACKET_READ(ReadChar, char, CursorZ); - m_Client->HandleRightClick(PosX, PosY, PosZ, BlockFace, CursorX, CursorY, CursorZ, HeldItem); + m_Client->HandleRightClick(PosX, PosY, PosZ, static_cast(BlockFace), CursorX, CursorY, CursorZ, HeldItem); return PARSE_OK; } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 04bade867..434055fe4 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1480,7 +1480,7 @@ void cProtocol172::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadByte, Byte, BlockY); HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Face); - m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, Face, Status); + m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, static_cast(Face), Status); } @@ -1499,7 +1499,7 @@ void cProtocol172::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorX); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorY); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorZ); - m_Client->HandleRightClick(BlockX, BlockY, BlockZ, Face, CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem()); + m_Client->HandleRightClick(BlockX, BlockY, BlockZ, static_cast(Face), CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem()); } diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 05badf0d4..6b7ae3196 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -1112,12 +1112,13 @@ bool cRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, int a_Block // Pistons cannot be powered through their front face; this function verifies that a source meets this requirement int OldX = a_BlockX, OldY = a_BlockY, OldZ = a_BlockZ; + eBlockFace Face = cPiston::MetaDataToDirection(a_Meta); for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Meta); // Piston meta is based on what direction they face, so we can do this + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, Face); if (!itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { @@ -1133,7 +1134,7 @@ bool cRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, int a_Block { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Meta); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, Face); if (!itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { -- cgit v1.2.3 From bee7de25f120a22e0a42b5a5a5347877ca167117 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 4 Feb 2014 11:15:41 -0800 Subject: Ensure -Wall is enabled --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f336e20f..c40767d20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,6 +208,7 @@ if (NOT MSVC) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + add_flags_cxx("-Wall") endif() if(${BUILD_TOOLS}) -- cgit v1.2.3 From 1f26c9f5ab478b072eac7e850e730d5f0095c7dd Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 4 Feb 2014 11:26:39 -0800 Subject: Fix gcc not having operator ++ on enums --- src/Blocks/BlockTorch.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 13f961d21..f2a4c8665 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -113,9 +113,10 @@ public: /// Finds a suitable face to place the torch, returning BLOCK_FACE_NONE on failure static eBlockFace FindSuitableFace(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - for (eBlockFace i = BLOCK_FACE_YM; i <= BLOCK_FACE_XP; i++) // Loop through all directions + for (int i = BLOCK_FACE_YM; i <= BLOCK_FACE_XP; i++) // Loop through all directions { - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, i, true); + eBlockFace Face = static_cast(i); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, Face, true); BLOCKTYPE BlockInQuestion = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ); if ( // If on a block that can only hold a torch if torch is standing on it, return that face @@ -123,20 +124,20 @@ public: (BlockInQuestion == E_BLOCK_FENCE) || (BlockInQuestion == E_BLOCK_NETHER_BRICK_FENCE) || (BlockInQuestion == E_BLOCK_COBBLESTONE_WALL)) && - (i == BLOCK_FACE_TOP) + (Face == BLOCK_FACE_TOP) ) { - return i; + return Face; } else if ((g_BlockFullyOccupiesVoxel[BlockInQuestion]) && (i != BLOCK_FACE_BOTTOM)) { // Otherwise, if block in that direction is torch placeable and we haven't gotten to it via the bottom face, return that face - return i; + return Face; } else { // Reset coords in preparation for next iteration - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, i, false); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, Face, false); } } return BLOCK_FACE_NONE; -- cgit v1.2.3 From 835a59b8fc4d005a6101546e2f2db33e205bc0e5 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 22:15:01 +0100 Subject: Protocol 1.7 uses char for blockface. That should fix #644 on RasPi. --- src/Protocol/Protocol17x.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 434055fe4..8168e8314 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1479,7 +1479,7 @@ void cProtocol172::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, BlockY); HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ); - HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Face); + HANDLE_READ(a_ByteBuffer, ReadChar, char, Face); m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, static_cast(Face), Status); } @@ -1492,7 +1492,7 @@ void cProtocol172::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, BlockY); HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ); - HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Face); + HANDLE_READ(a_ByteBuffer, ReadChar, char, Face); cItem Item; ReadItem(a_ByteBuffer, Item); -- cgit v1.2.3 From 5cdbb6683fa57814a3c83464de0178de0ce4ca9b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 22:18:59 +0100 Subject: Fixed a warning in cItem in gcc. Constructor member order... --- src/Item.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Item.h b/src/Item.h index 7781db0cb..ca9ec5a2b 100644 --- a/src/Item.h +++ b/src/Item.h @@ -174,9 +174,9 @@ public: short m_ItemType; char m_ItemCount; short m_ItemDamage; + cEnchantments m_Enchantments; AString m_CustomName; AString m_Lore; - cEnchantments m_Enchantments; }; // tolua_end -- cgit v1.2.3 From 010e64be1124caabeb692f2005db364efb6ac9a0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 22:24:03 +0100 Subject: Removed a useless check in cLuaState. --- src/Bindings/LuaState.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 8dd17c448..ac5ce47e1 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1018,9 +1018,7 @@ void cLuaState::LogStackTrace(lua_State * a_LuaState) int depth = 0; while (lua_getstack(a_LuaState, depth, &entry)) { - int status = lua_getinfo(a_LuaState, "Sln", &entry); - assert(status); - + lua_getinfo(a_LuaState, "Sln", &entry); LOGWARNING(" %s(%d): %s", entry.short_src, entry.currentline, entry.name ? entry.name : "(no name)"); depth++; } -- cgit v1.2.3 From 82173db9bf9c4f076062ca316c57bf6af9ea1a83 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 22:26:35 +0100 Subject: Fixed a gcc warning in ManualBindings. Constructor member order... --- src/Bindings/ManualBindings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index dbaf32756..9ebdc4b22 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1593,9 +1593,9 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S) int m_NumReturns; cCallback(const AString & a_FunctionName, cLuaState & a_SrcLuaState) : + m_NumReturns(0), m_FunctionName(a_FunctionName), - m_SrcLuaState(a_SrcLuaState), - m_NumReturns(0) + m_SrcLuaState(a_SrcLuaState) { } protected: -- cgit v1.2.3 From 91a8db0d7ef3187b52d6f7e7906b28ae8ce03ae0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 22:41:54 +0100 Subject: Protocol 1.7: Fixed a signed / unsigned comparison warning. --- src/Protocol/Protocol17x.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 8168e8314..52c0099ed 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -99,7 +99,7 @@ void cProtocol172::DataReceived(const char * a_Data, int a_Size) Byte Decrypted[512]; while (a_Size > 0) { - int NumBytes = (a_Size > sizeof(Decrypted)) ? sizeof(Decrypted) : a_Size; + int NumBytes = (a_Size > (int)sizeof(Decrypted)) ? (int)sizeof(Decrypted) : a_Size; m_Decryptor.ProcessData(Decrypted, (Byte *)a_Data, NumBytes); AddReceivedData((const char *)Decrypted, NumBytes); a_Size -= NumBytes; @@ -1836,7 +1836,7 @@ void cProtocol172::SendData(const char * a_Data, int a_Size) Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks) while (a_Size > 0) { - int NumBytes = (a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : a_Size; + int NumBytes = (a_Size > (int)sizeof(Encrypted)) ? (int)sizeof(Encrypted) : a_Size; m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes); m_Client->SendData((const char *)Encrypted, NumBytes); a_Size -= NumBytes; -- cgit v1.2.3 From a96ea33b64a87cff22814fb216f7bdd20613577d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 23:09:07 +0100 Subject: Added dtExplosion to damage<->string functions. --- src/BlockID.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/BlockID.cpp b/src/BlockID.cpp index de56d4625..c38db0bfe 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -380,7 +380,7 @@ AString DamageTypeToString(eDamageType a_DamageType) case dtRangedAttack: return "dtRangedAttack"; case dtStarving: return "dtStarving"; case dtSuffocating: return "dtSuffocation"; - + case dtExplosion: return "dtExplosion"; } // Unknown damage type: @@ -426,6 +426,7 @@ eDamageType StringToDamageType(const AString & a_DamageTypeString) { dtInVoid, "dtInVoid"}, { dtPotionOfHarming, "dtPotionOfHarming"}, { dtAdmin, "dtAdmin"}, + { dtExplosion, "dtExplosion"}, // Common synonyms: { dtAttack, "dtPawnAttack"}, -- cgit v1.2.3 From cc032995bde636913f7e6d5767e44896fcee7086 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 23:25:06 +0100 Subject: Crypto: Removed unused member, fixed gcc warning. --- src/Crypto.cpp | 8 ++++---- src/Crypto.h | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Crypto.cpp b/src/Crypto.cpp index 7a06d7fa3..26500f263 100644 --- a/src/Crypto.cpp +++ b/src/Crypto.cpp @@ -308,8 +308,8 @@ void cPublicKey::InitRnd(void) // cAESCFBDecryptor: cAESCFBDecryptor::cAESCFBDecryptor(void) : - m_IsValid(false), - m_IVOffset(0) + m_IVOffset(0), + m_IsValid(false) { } @@ -366,8 +366,8 @@ void cAESCFBDecryptor::ProcessData(Byte * a_DecryptedOut, const Byte * a_Encrypt // cAESCFBEncryptor: cAESCFBEncryptor::cAESCFBEncryptor(void) : - m_IsValid(false), - m_IVOffset(0) + m_IVOffset(0), + m_IsValid(false) { } diff --git a/src/Crypto.h b/src/Crypto.h index d68f7ec24..a9ec2c6d4 100644 --- a/src/Crypto.h +++ b/src/Crypto.h @@ -132,8 +132,6 @@ protected: class cAESCFBEncryptor { public: - Byte test; - cAESCFBEncryptor(void); ~cAESCFBEncryptor(); -- cgit v1.2.3 From 9eeeb91fa6e3df67aa1dc8aae54da8e6631d25be Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 4 Feb 2014 22:39:57 +0000 Subject: Added more SendMessageXXX() functions --- src/Defines.h | 91 ++++++++++++++++++++++++++------------------------- src/Entities/Player.h | 4 +++ src/Root.h | 14 ++++++-- 3 files changed, 62 insertions(+), 47 deletions(-) diff --git a/src/Defines.h b/src/Defines.h index 17885394e..f766d4d04 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -465,51 +465,54 @@ inline AString AppendChatEpithet(const AString & a_ChatMessage, ChatPrefixCodes { switch (a_ChatPrefix) { - case mtCustom: return a_ChatMessage; - case mtFailure: - { - AString Message(Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; - } - case mtInformation: - { - AString Message(Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; - } - case mtSuccess: - { - AString Message(Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; - } - case mtWarning: - { - AString Message(Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; - } - case mtFatal: - { - AString Message(Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; - } - case mtDeath: - { - AString Message(Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; - } - case mtPrivateMessage: - { - AString Message(Printf("%s[MSG] %s%s", cChatColor::LightBlue.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str())); - Message.append(a_ChatMessage); - return Message; - } + case mtCustom: return a_ChatMessage; + case mtFailure: + { + AString Message(Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtInformation: + { + AString Message(Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtSuccess: + { + AString Message(Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtWarning: + { + AString Message(Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtFatal: + { + AString Message(Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtDeath: + { + AString Message(Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str())); + Message.append(a_ChatMessage); + return Message; + } + case mtPrivateMessage: + { + AString Message(Printf("%s[MSG] %s%s", cChatColor::LightBlue.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str())); + Message.append(a_ChatMessage); + return Message; + } + default: ASSERT(!"Unhandled chat prefix type!"); return ""; } -}// tolua_begin +} + +// tolua_begin /// Normalizes an angle in degrees to the [-180, +180) range: inline double NormalizeAngleDegrees(const double a_Degrees) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 764b47ae0..784aac327 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -199,6 +199,10 @@ public: void SendMessageInfo(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtInformation)); } void SendMessageFailure(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtFailure)); } void SendMessageSuccess(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtSuccess)); } + void SendMessageWarning(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtWarning)); } + void SendMessageFatal(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtFailure)); } + void SendMessageDeath(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtDeath)); } + void SendMessagePrivateMsg(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtPrivateMessage)); } const AString & GetName(void) const { return m_PlayerName; } void SetName(const AString & a_Name) { m_PlayerName = a_Name; } diff --git a/src/Root.h b/src/Root.h index c59afc810..fa52c21a1 100644 --- a/src/Root.h +++ b/src/Root.h @@ -3,6 +3,7 @@ #include "Authenticator.h" #include "HTTPServer/HTTPServer.h" +#include "Defines.h" @@ -98,9 +99,6 @@ public: /// Saves all chunks in all worlds void SaveAllChunks(void); // tolua_export - /// Sends a chat message to all connected clients (in all worlds) - void BroadcastChat(const AString & a_Message); // tolua_export - /// Calls the callback for each player in all worlds bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << @@ -109,6 +107,16 @@ public: // tolua_begin + /// Sends a chat message to all connected clients (in all worlds) + void BroadcastChat(const AString & a_Message); + void BroadcastChatInfo(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtInformation)); } + void BroadcastChatFailure(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); } + void BroadcastChatSuccess(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtSuccess)); } + void BroadcastChatWarning(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtWarning)); } + void BroadcastChatFatal(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); } + void BroadcastChatDeath(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtDeath)); } + void BroadcastChatPrivateMsg(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtPrivateMessage)); } + /// Returns the textual description of the protocol version: 49 -> "1.4.4". Provided specifically for Lua API static AString GetProtocolVersionTextFromInt(int a_ProtocolVersionNum); -- cgit v1.2.3 From 45958cb835566b437c1152fcd11f678aef30db54 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 23:43:40 +0100 Subject: Explicitly make chars signed at the compiler-level. Should fix #640. --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c40767d20..1fee887e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,9 @@ else() set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11") endif() + + # We use a signed char (fixes #640 on RasPi) + add_flags_cxx("-fsigned-char") endif() -- cgit v1.2.3 From 630507fd5b8a7ac280ee75994f98b9ecfdcb7a70 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 4 Feb 2014 23:07:22 +0000 Subject: Fixed a bunch of MSVS warnings * Possibly also fixed some bugs with pathfinding and TNT, though unlikely --- src/Blocks/BlockButton.h | 2 +- src/Blocks/BlockLever.h | 2 +- src/Blocks/BlockTrapdoor.h | 4 ++-- src/ChunkMap.cpp | 2 +- src/Mobs/Monster.cpp | 2 +- src/Protocol/Protocol17x.cpp | 3 ++- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index f592b94a1..5567c1942 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -88,7 +88,7 @@ public: default: { ASSERT(!"Unhandled block meta!"); - return BLOCK_FACE_NONE; + return 0; } } } diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index 09b600759..cb65cd03c 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -88,7 +88,7 @@ public: default: { ASSERT(!"Unhandled block meta!"); - return BLOCK_FACE_NONE; + return 0; } } } diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index f549b4183..ee595d9c4 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -68,7 +68,7 @@ public: default: { ASSERT(!"Unhandled block face!"); - return 0x0; + return 0; } } } @@ -84,7 +84,7 @@ public: default: { ASSERT(!"Unhandled block meta!"); - return BLOCK_FACE_NONE; + return 0; } } } diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 1e2181f32..cb10e275d 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1839,7 +1839,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ bbTNT.Expand(ExplosionSizeInt * 2, ExplosionSizeInt * 2, ExplosionSizeInt * 2); - cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), a_ExplosionSize, ExplosionSizeSq); + cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), a_ExplosionSizeInt, ExplosionSizeSq); ForEachEntity(TNTDamageCallback); // Wake up all simulators for the area, so that water and lava flows and sand falls into the blasted holes (FS #391): diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 283ef36e6..b49a8661d 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -264,7 +264,7 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) { m_Destination.y = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z); - if (DoesPosYRequireJump(m_Destination.y)) + if (DoesPosYRequireJump((int)floor(m_Destination.y))) { m_bOnGround = false; AddPosY(1.5); // Jump!! diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 04bade867..eb42e9299 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2435,7 +2435,8 @@ void cProtocol172::cPacketizer::WriteEntityProperties(const cEntity & a_Entity) WriteInt(0); return; } - const cMonster & Mob = (const cMonster &)a_Entity; + + //const cMonster & Mob = (const cMonster &)a_Entity; // TODO: Send properties and modifiers based on the mob type -- cgit v1.2.3 From b63c206a5c4fee7b30ccdaba8d1af6b1e252debc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 5 Feb 2014 00:09:35 +0100 Subject: InfoDump: Git-Ignoring all generated files. --- MCServer/Plugins/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 MCServer/Plugins/.gitignore diff --git a/MCServer/Plugins/.gitignore b/MCServer/Plugins/.gitignore new file mode 100644 index 000000000..89eab800a --- /dev/null +++ b/MCServer/Plugins/.gitignore @@ -0,0 +1,2 @@ +*.txt +*.md -- cgit v1.2.3 From e5dce265aed40bd11ce91caae22db132b3486787 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 5 Feb 2014 00:16:33 +0100 Subject: Added cPluginManager:LogStackTrace() to the Lua API. Fixes #637. --- MCServer/Plugins/APIDump/APIDesc.lua | 3 ++- src/Bindings/ManualBindings.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 948f55a22..20a97be19 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1747,10 +1747,11 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); GetCommandPermission = { Params = "Command", Return = "Permission", Notes = "Returns the permission needed for executing the specified command" }, GetCurrentPlugin = { Params = "", Return = "{{cPlugin}}", Notes = "Returns the {{cPlugin}} object for the calling plugin. This is the same object that the Initialize function receives as the argument." }, GetNumPlugins = { Params = "", Return = "number", Notes = "Returns the number of plugins, including the disabled ones" }, - GetPlugin = { Params = "PluginName", Return = "{{cPlugin}}", Notes = "Returns a plugin handle of the specified plugin" }, + GetPlugin = { Params = "PluginName", Return = "{{cPlugin}}", Notes = "(DEPRECATED, UNSAFE) Returns a plugin handle of the specified plugin, or nil if such plugin is not loaded. Note thatdue to multithreading the handle is not guaranteed to be safe for use when stored - a single-plugin reload may have been triggered in the mean time for the requested plugin." }, IsCommandBound = { Params = "Command", Return = "bool", Notes = "Returns true if in-game Command is already bound (by any plugin)" }, IsConsoleCommandBound = { Params = "Command", Return = "bool", Notes = "Returns true if console Command is already bound (by any plugin)" }, LoadPlugin = { Params = "PluginFolder", Return = "", Notes = "(DEPRECATED) Loads a plugin from the specified folder. NOTE: Loading plugins may be an unsafe operation and may result in a deadlock or a crash. This API is deprecated and might be removed." }, + LogStackTrace = { Params = "", Return = "", Notes = "(STATIC) Logs a current stack trace of the Lua engine to the server console log. Same format as is used when the plugin fails." }, ReloadPlugins = { Params = "", Return = "", Notes = "Reloads all active plugins" }, }, Constants = diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 9ebdc4b22..d476a3156 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1106,6 +1106,16 @@ static int tolua_cPluginManager_GetCurrentPlugin(lua_State * S) +static int tolua_cPluginManager_LogStackTrace(lua_State * S) +{ + cLuaState::LogStackTrace(S); + return 0; +} + + + + + static int tolua_cPluginManager_AddHook_FnRef(cPluginManager * a_PluginManager, cLuaState & S, int a_ParamIdx) { // Helper function for cPluginmanager:AddHook() binding @@ -2386,6 +2396,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "ForEachConsoleCommand", tolua_cPluginManager_ForEachConsoleCommand); tolua_function(tolua_S, "GetAllPlugins", tolua_cPluginManager_GetAllPlugins); tolua_function(tolua_S, "GetCurrentPlugin", tolua_cPluginManager_GetCurrentPlugin); + tolua_function(tolua_S, "LogStackTrace", tolua_cPluginManager_LogStackTrace); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cPlayer"); -- cgit v1.2.3 From ea2ce1595f51c141342991378c372529f26434c6 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 4 Feb 2014 23:27:13 +0000 Subject: Fixed annoying creative on fire bug --- src/Entities/Player.cpp | 17 +++++++++++++++++ src/Entities/Player.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 70c881091..c0466fa66 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1760,6 +1760,23 @@ void cPlayer::UseEquippedItem(void) +void cPlayer::TickBurning(cChunk & a_Chunk) +{ + // Don't burn in creative and stop burning in creative if necessary + if (!IsGameModeCreative()) + { + super::TickBurning(a_Chunk); + } + else if (IsOnFire()) + { + m_TicksLeftBurning = 0; + OnFinishedBurning(); + } +} + + + + void cPlayer::HandleFood(void) { diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 784aac327..925011c9c 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -475,6 +475,9 @@ protected: /// Filters out damage for creative mode/friendly fire virtual void DoTakeDamage(TakeDamageInfo & TDI) override; + + /** Stops players from burning in creative mode */ + virtual void TickBurning(cChunk & a_Chunk) override; /// Called in each tick to handle food-related processing void HandleFood(void); -- cgit v1.2.3 From 94c343fe079346caf24be265234cce194bc3b450 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 4 Feb 2014 23:40:58 +0000 Subject: Fixed explosions bug * Fixed bug where explosions would sometimes never be sent --- src/ChunkMap.cpp | 2 +- src/ClientHandle.cpp | 30 ++++++++++-------------------- src/ClientHandle.h | 13 ++----------- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index cb10e275d..db2a1b1d9 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1839,7 +1839,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ bbTNT.Expand(ExplosionSizeInt * 2, ExplosionSizeInt * 2, ExplosionSizeInt * 2); - cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), a_ExplosionSizeInt, ExplosionSizeSq); + cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), ExplosionSizeInt, ExplosionSizeSq); ForEachEntity(TNTDamageCallback); // Wake up all simulators for the area, so that water and lava flows and sand falls into the blasted holes (FS #391): diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 3e9e03815..3059ae7b1 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -44,16 +44,13 @@ -/// If the number of queued outgoing packets reaches this, the client will be kicked +/** If the number of queued outgoing packets reaches this, the client will be kicked */ #define MAX_OUTGOING_PACKETS 2000 -/// How many explosions per single game tick are allowed -static const int MAX_EXPLOSIONS_PER_TICK = 100; +/** Maximum number of explosions to send this tick, server will start dropping if exceeded */ +#define MAX_EXPLOSIONS_PER_TICK 100 -/// How many explosions in the recent history are allowed -static const int MAX_RUNNING_SUM_EXPLOSIONS = cClientHandle::NUM_CHECK_EXPLOSIONS_TICKS * MAX_EXPLOSIONS_PER_TICK / 8; - -/// How many ticks before the socket is closed after the client is destroyed (#31) +/** How many ticks before the socket is closed after the client is destroyed (#31) */ static const int TICKS_BEFORE_CLOSE = 20; @@ -95,8 +92,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_TicksSinceDestruction(0), m_State(csConnected), m_ShouldCheckDownloaded(false), - m_CurrentExplosionTick(0), - m_RunningSumExplosions(0), + m_NumExplosionsThisTick(0), m_UniqueID(0), m_HasSentPlayerChunk(false) { @@ -1637,10 +1633,8 @@ void cClientHandle::Tick(float a_Dt) } } - // Update the explosion statistics: - m_CurrentExplosionTick = (m_CurrentExplosionTick + 1) % ARRAYCOUNT(m_NumExplosionsPerTick); - m_RunningSumExplosions -= m_NumExplosionsPerTick[m_CurrentExplosionTick]; - m_NumExplosionsPerTick[m_CurrentExplosionTick] = 0; + // Reset explosion counter: + m_NumExplosionsThisTick = 0; } @@ -1920,18 +1914,14 @@ void cClientHandle::SendEntityVelocity(const cEntity & a_Entity) void cClientHandle::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) { - if ( - (m_NumExplosionsPerTick[m_CurrentExplosionTick] > MAX_EXPLOSIONS_PER_TICK) || // Too many explosions in this tick - (m_RunningSumExplosions > MAX_RUNNING_SUM_EXPLOSIONS) // Too many explosions in the recent history - ) + if (m_NumExplosionsThisTick > MAX_EXPLOSIONS_PER_TICK) { - LOGD("Dropped %u explosions", a_BlocksAffected.size()); + LOGD("Dropped an explosion!"); return; } // Update the statistics: - m_NumExplosionsPerTick[m_CurrentExplosionTick] += a_BlocksAffected.size(); - m_RunningSumExplosions += a_BlocksAffected.size(); + m_NumExplosionsThisTick += 1; m_Protocol->SendExplosion(a_BlockX, a_BlockY, a_BlockZ, a_Radius, a_BlocksAffected, a_PlayerMotion); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index e1f326543..29a56f5a7 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -53,9 +53,6 @@ public: static const int MAX_VIEW_DISTANCE = 15; static const int MIN_VIEW_DISTANCE = 3; - /// How many ticks should be checked for a running average of explosions, for limiting purposes - static const int NUM_CHECK_EXPLOSIONS_TICKS = 20; - cClientHandle(const cSocket * a_Socket, int a_ViewDistance); virtual ~cClientHandle(); @@ -301,14 +298,8 @@ private: /// If set to true during csDownloadingWorld, the tick thread calls CheckIfWorldDownloaded() bool m_ShouldCheckDownloaded; - /// Stores the recent history of the number of explosions per tick - int m_NumExplosionsPerTick[NUM_CHECK_EXPLOSIONS_TICKS]; - - /// Points to the current tick in the m_NumExplosionsPerTick[] array - int m_CurrentExplosionTick; - - /// Running sum of m_NumExplosionsPerTick[] - int m_RunningSumExplosions; + /** Number of explosions sent this tick */ + int m_NumExplosionsThisTick; static int s_ClientCount; int m_UniqueID; -- cgit v1.2.3 From 7d151d54946fe3c82c053faf02a06b32b0be563f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 4 Feb 2014 23:53:10 +0000 Subject: Updated Core & PolarSSL --- MCServer/Plugins/Core | 2 +- lib/polarssl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 5fe3662a8..fbe438b61 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 5fe3662a8719f79cb2ca0a16150c716a3c5eb19c +Subproject commit fbe438b61bef3fc350f1ba1fa24a130506115bf0 diff --git a/lib/polarssl b/lib/polarssl index c78c8422c..2cb1a0c40 160000 --- a/lib/polarssl +++ b/lib/polarssl @@ -1 +1 @@ -Subproject commit c78c8422c25b9dc38f09eded3200d565375522e2 +Subproject commit 2cb1a0c4009ecf368ecc74eb428394e10f9e6d00 -- cgit v1.2.3 From 99fdadd58e459b70803fff5f9fd3cae1ab8df2d5 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 5 Feb 2014 00:45:08 +0000 Subject: Reduced max explosions per tick --- src/ClientHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 3059ae7b1..439f980ce 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -48,7 +48,7 @@ #define MAX_OUTGOING_PACKETS 2000 /** Maximum number of explosions to send this tick, server will start dropping if exceeded */ -#define MAX_EXPLOSIONS_PER_TICK 100 +#define MAX_EXPLOSIONS_PER_TICK 20 /** How many ticks before the socket is closed after the client is destroyed (#31) */ static const int TICKS_BEFORE_CLOSE = 20; -- cgit v1.2.3 From 9e98c9691d2ce48fa8b74b120db8a1bb991ceb71 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 5 Feb 2014 13:54:47 +0100 Subject: Improved the signedness conversion. --- src/Protocol/Protocol17x.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 52c0099ed..57da48e49 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -99,7 +99,7 @@ void cProtocol172::DataReceived(const char * a_Data, int a_Size) Byte Decrypted[512]; while (a_Size > 0) { - int NumBytes = (a_Size > (int)sizeof(Decrypted)) ? (int)sizeof(Decrypted) : a_Size; + size_t NumBytes = (a_Size > sizeof(Decrypted)) ? sizeof(Decrypted) : a_Size; m_Decryptor.ProcessData(Decrypted, (Byte *)a_Data, NumBytes); AddReceivedData((const char *)Decrypted, NumBytes); a_Size -= NumBytes; @@ -1836,7 +1836,7 @@ void cProtocol172::SendData(const char * a_Data, int a_Size) Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks) while (a_Size > 0) { - int NumBytes = (a_Size > (int)sizeof(Encrypted)) ? (int)sizeof(Encrypted) : a_Size; + size_t NumBytes = ((size_t)a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : (size_t)a_Size; m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes); m_Client->SendData((const char *)Encrypted, NumBytes); a_Size -= NumBytes; -- cgit v1.2.3 From 7c750914f0ddd0fec414e8690b10145ed61e7fa9 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 5 Feb 2014 18:10:08 +0100 Subject: Improvements: Adds a function in cRoot that allows you to reload all the groups permissions. Note: Players don't automatically load their new permissions. You can use cPlayer::LoadPermissionsFromDisk for that. --- src/Group.cpp | 31 +++++++++++++++++++++++++++---- src/Group.h | 24 +++++++++++++----------- src/GroupManager.cpp | 23 ++++++++++++++++------- src/GroupManager.h | 1 + src/Root.cpp | 9 +++++++++ src/Root.h | 3 +++ 6 files changed, 69 insertions(+), 22 deletions(-) diff --git a/src/Group.cpp b/src/Group.cpp index 448d29d87..cc42c55a1 100644 --- a/src/Group.cpp +++ b/src/Group.cpp @@ -3,19 +3,34 @@ #include "Group.h" -void cGroup::AddCommand( std::string a_Command ) + + + + +void cGroup::AddCommand( AString a_Command ) { m_Commands[ a_Command ] = true; } -void cGroup::AddPermission( std::string a_Permission ) + + + + +void cGroup::AddPermission( AString a_Permission ) { m_Permissions[ a_Permission ] = true; } -bool cGroup::HasCommand( std::string a_Command ) + + + + +bool cGroup::HasCommand( AString a_Command ) { - if( m_Commands.find("*") != m_Commands.end() ) return true; + if( m_Commands.find("*") != m_Commands.end() ) + { + return true; + } CommandMap::iterator itr = m_Commands.find( a_Command ); if( itr != m_Commands.end() ) @@ -34,4 +49,12 @@ void cGroup::InheritFrom( cGroup* a_Group ) { m_Inherits.remove( a_Group ); m_Inherits.push_back( a_Group ); +} + + + + +void cGroup::ClearPermission() +{ + m_Permissions.clear(); } \ No newline at end of file diff --git a/src/Group.h b/src/Group.h index 65ee1a60a..3299aecbc 100644 --- a/src/Group.h +++ b/src/Group.h @@ -11,19 +11,21 @@ public: // tolua_export cGroup() {} ~cGroup() {} - void SetName( std::string a_Name ) { m_Name = a_Name; } // tolua_export - const std::string & GetName() const { return m_Name; } // tolua_export - void SetColor( std::string a_Color ) { m_Color = a_Color; } // tolua_export - void AddCommand( std::string a_Command ); // tolua_export - void AddPermission( std::string a_Permission ); // tolua_export - void InheritFrom( cGroup* a_Group ); // tolua_export + void SetName( AString a_Name ) { m_Name = a_Name; } // tolua_export + const AString & GetName() const { return m_Name; } // tolua_export + void SetColor( AString a_Color ) { m_Color = a_Color; } // tolua_export + void AddCommand( AString a_Command ); // tolua_export + void AddPermission( AString a_Permission ); // tolua_export + void InheritFrom( cGroup* a_Group ); // tolua_export - bool HasCommand( std::string a_Command ); // tolua_export + bool HasCommand( AString a_Command ); // tolua_export - typedef std::map< std::string, bool > PermissionMap; + typedef std::map< AString, bool > PermissionMap; const PermissionMap & GetPermissions() const { return m_Permissions; } - typedef std::map< std::string, bool > CommandMap; + void ClearPermission(void); + + typedef std::map< AString, bool > CommandMap; const CommandMap & GetCommands() const { return m_Commands; } const AString & GetColor() const { return m_Color; } // tolua_export @@ -31,8 +33,8 @@ public: // tolua_export typedef std::list< cGroup* > GroupList; const GroupList & GetInherits() const { return m_Inherits; } private: - std::string m_Name; - std::string m_Color; + AString m_Name; + AString m_Color; PermissionMap m_Permissions; CommandMap m_Commands; diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index d5567d91e..99befa0ff 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -44,6 +44,18 @@ cGroupManager::cGroupManager() : m_pState( new sGroupManagerState ) { LOGD("-- Loading Groups --"); + + LoadGroups(); + + LOGD("-- Groups Successfully Loaded --"); +} + + + + + +void cGroupManager::LoadGroups() +{ cIniFile IniFile; if (!IniFile.ReadFile("groups.ini")) { @@ -71,8 +83,10 @@ cGroupManager::cGroupManager() unsigned int NumKeys = IniFile.GetNumKeys(); for (size_t i = 0; i < NumKeys; i++) { - std::string KeyName = IniFile.GetKeyName( i ); + AString KeyName = IniFile.GetKeyName( i ); cGroup* Group = GetGroup( KeyName.c_str() ); + + Group->ClearPermission(); // Needed in case the groups are reloaded. LOGD("Loading group: %s", KeyName.c_str() ); @@ -107,7 +121,7 @@ cGroupManager::cGroupManager() } } - std::string Groups = IniFile.GetValue(KeyName, "Inherits", ""); + AString Groups = IniFile.GetValue(KeyName, "Inherits", ""); if (!Groups.empty()) { AStringVector Split = StringSplitAndTrim(Groups, ","); @@ -117,13 +131,8 @@ cGroupManager::cGroupManager() } } } - LOGD("-- Groups Successfully Loaded --"); } - - - - cGroup* cGroupManager::GetGroup( const AString & a_Name ) { GroupMap::iterator itr = m_pState->Groups.find( a_Name ); diff --git a/src/GroupManager.h b/src/GroupManager.h index d911f976c..02a58fe4e 100644 --- a/src/GroupManager.h +++ b/src/GroupManager.h @@ -15,6 +15,7 @@ class cGroupManager { public: cGroup * GetGroup(const AString & a_Name); + void LoadGroups(void); private: friend class cRoot; diff --git a/src/Root.cpp b/src/Root.cpp index 883bfe76e..5d1b2ebe2 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -536,6 +536,15 @@ void cRoot::SaveAllChunks(void) +void cRoot::ReloadGroups(void) +{ + m_GroupManager->LoadGroups(); +} + + + + + void cRoot::BroadcastChat(const AString & a_Message) { for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr) diff --git a/src/Root.h b/src/Root.h index c59afc810..71ee2e671 100644 --- a/src/Root.h +++ b/src/Root.h @@ -98,6 +98,9 @@ public: /// Saves all chunks in all worlds void SaveAllChunks(void); // tolua_export + /// Reloads all the groups + void ReloadGroups(void); // tolua_export + /// Sends a chat message to all connected clients (in all worlds) void BroadcastChat(const AString & a_Message); // tolua_export -- cgit v1.2.3 From d6142b53f30dd212bea8f7daef3915e189791df5 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 5 Feb 2014 18:14:51 +0100 Subject: Forgot extra lines. --- src/GroupManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 99befa0ff..723b86f94 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -133,6 +133,10 @@ void cGroupManager::LoadGroups() } } + + + + cGroup* cGroupManager::GetGroup( const AString & a_Name ) { GroupMap::iterator itr = m_pState->Groups.find( a_Name ); -- cgit v1.2.3 From 8ba6f731699465aa13818e307af7b9f001d3767e Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 5 Feb 2014 09:43:49 -0800 Subject: Fixed most of the reordering warnings --- src/Bindings/ManualBindings.cpp | 4 ++-- src/Crypto.cpp | 8 ++++---- src/Entities/Entity.cpp | 4 ++-- src/Entities/Floater.cpp | 4 ++-- src/Entities/Minecart.cpp | 10 +++++----- src/Entities/Pickup.cpp | 4 ++-- src/Item.h | 8 ++++---- src/Mobs/Monster.cpp | 8 ++++---- src/Mobs/Villager.cpp | 4 ++-- src/Scoreboard.cpp | 2 +- src/Simulator/RedstoneSimulator.cpp | 6 +++--- src/World.cpp | 4 ++-- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index dbaf32756..9ebdc4b22 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1593,9 +1593,9 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S) int m_NumReturns; cCallback(const AString & a_FunctionName, cLuaState & a_SrcLuaState) : + m_NumReturns(0), m_FunctionName(a_FunctionName), - m_SrcLuaState(a_SrcLuaState), - m_NumReturns(0) + m_SrcLuaState(a_SrcLuaState) { } protected: diff --git a/src/Crypto.cpp b/src/Crypto.cpp index 7a06d7fa3..26500f263 100644 --- a/src/Crypto.cpp +++ b/src/Crypto.cpp @@ -308,8 +308,8 @@ void cPublicKey::InitRnd(void) // cAESCFBDecryptor: cAESCFBDecryptor::cAESCFBDecryptor(void) : - m_IsValid(false), - m_IVOffset(0) + m_IVOffset(0), + m_IsValid(false) { } @@ -366,8 +366,8 @@ void cAESCFBDecryptor::ProcessData(Byte * a_DecryptedOut, const Byte * a_Encrypt // cAESCFBEncryptor: cAESCFBEncryptor::cAESCFBEncryptor(void) : - m_IsValid(false), - m_IVOffset(0) + m_IVOffset(0), + m_IsValid(false) { } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 08780ca8b..8554ab2a5 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -50,6 +50,8 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_TicksSinceLastFireDamage(0) , m_TicksLeftBurning(0) , m_TicksSinceLastVoidDamage(0) + , m_IsSwimming(false) + , m_IsSubmerged(false) , m_HeadYaw( 0.0 ) , m_Rot(0.0, 0.0, 0.0) , m_Pos(a_X, a_Y, a_Z) @@ -57,8 +59,6 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_Mass (0.001) // Default 1g , m_Width(a_Width) , m_Height(a_Height) - , m_IsSubmerged(false) - , m_IsSwimming(false) { cCSLock Lock(m_CSCount); m_EntityCount++; diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index 38160a30e..b910c3769 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -103,10 +103,10 @@ protected: cFloater::cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID, int a_CountDownTime) : cEntity(etFloater, a_X, a_Y, a_Z, 0.2, 0.2), - m_PickupCountDown(0), - m_PlayerID(a_PlayerID), m_CanPickupItem(false), + m_PickupCountDown(0), m_CountDownTime(a_CountDownTime), + m_PlayerID(a_PlayerID), m_AttachedMobID(-1) { SetSpeed(a_Speed); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index a650927b1..d854906b7 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -24,11 +24,11 @@ class cMinecartCollisionCallback : { public: cMinecartCollisionCallback(Vector3d a_Pos, double a_Height, double a_Width, int a_UniqueID, int a_AttacheeUniqueID) : + m_DoesInteserct(false), + m_CollidedEntityPos(0, 0, 0), m_Pos(a_Pos), m_Height(a_Height), m_Width(a_Width), - m_DoesInteserct(false), - m_CollidedEntityPos(0, 0, 0), m_UniqueID(a_UniqueID), m_AttacheeUniqueID(a_AttacheeUniqueID) { @@ -1057,8 +1057,8 @@ void cMinecartWithChest::OnRightClicked(cPlayer & a_Player) cMinecartWithFurnace::cMinecartWithFurnace(double a_X, double a_Y, double a_Z) : super(mpFurnace, a_X, a_Y, a_Z), - m_IsFueled(false), - m_FueledTimeLeft(-1) + m_FueledTimeLeft(-1), + m_IsFueled(false) { } @@ -1137,4 +1137,4 @@ cMinecartWithHopper::cMinecartWithHopper(double a_X, double a_Y, double a_Z) : } // TODO: Make it suck up blocks and travel further than any other cart and physics and put and take blocks -// AND AVARYTHING!! \ No newline at end of file +// AND AVARYTHING!! diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index bfe162b69..c5503c16a 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -22,9 +22,9 @@ class cPickupCombiningCallback : { public: cPickupCombiningCallback(Vector3d a_Position, cPickup * a_Pickup) : + m_FoundMatchingPickup(false), m_Position(a_Position), - m_Pickup(a_Pickup), - m_FoundMatchingPickup(false) + m_Pickup(a_Pickup) { } diff --git a/src/Item.h b/src/Item.h index 727965112..1afb5938a 100644 --- a/src/Item.h +++ b/src/Item.h @@ -55,9 +55,9 @@ public: m_ItemType (a_ItemType), m_ItemCount (a_ItemCount), m_ItemDamage (a_ItemDamage), - m_Enchantments(a_Enchantments), m_CustomName (a_CustomName), - m_Lore (a_Lore) + m_Lore (a_Lore), + m_Enchantments(a_Enchantments) { if (!IsValidItem(m_ItemType)) { @@ -75,9 +75,9 @@ public: m_ItemType (a_CopyFrom.m_ItemType), m_ItemCount (a_CopyFrom.m_ItemCount), m_ItemDamage (a_CopyFrom.m_ItemDamage), - m_Enchantments(a_CopyFrom.m_Enchantments), m_CustomName (a_CopyFrom.m_CustomName), - m_Lore (a_CopyFrom.m_Lore) + m_Lore (a_CopyFrom.m_Lore), + m_Enchantments(a_CopyFrom.m_Enchantments) { } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 283ef36e6..1b9bfaa79 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -69,20 +69,20 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString : super(etMonster, a_Width, a_Height) , m_EMState(IDLE) , m_EMPersonality(AGGRESSIVE) - , m_SightDistance(25) , m_Target(NULL) - , m_AttackRate(3) - , m_IdleInterval(0) , m_bMovingToDestination(false) + , m_LastGroundHeight(POSY_TOINT) + , m_IdleInterval(0) , m_DestroyTimer(0) , m_MobType(a_MobType) , m_SoundHurt(a_SoundHurt) , m_SoundDeath(a_SoundDeath) + , m_AttackRate(3) , m_AttackDamage(1) , m_AttackRange(2) , m_AttackInterval(0) + , m_SightDistance(25) , m_BurnsInDaylight(false) - , m_LastGroundHeight(POSY_TOINT) { if (!a_ConfigName.empty()) { diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 08e5e4315..09a6e2d09 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -13,9 +13,9 @@ cVillager::cVillager(eVillagerType VillagerType) : super("Villager", mtVillager, "", "", 0.6, 1.8), + m_ActionCountDown(-1), m_Type(VillagerType), - m_VillagerAction(false), - m_ActionCountDown(-1) + m_VillagerAction(false) { } diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index b2edd613b..61ecac5b7 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -197,8 +197,8 @@ cTeam::cTeam(const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix) : m_AllowsFriendlyFire(true) , m_CanSeeFriendlyInvisible(false) - , m_Name(a_Name) , m_DisplayName(a_DisplayName) + , m_Name(a_Name) , m_Prefix(a_Prefix) , m_Suffix(a_Suffix) {} diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 6b7ae3196..298175ad7 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -946,11 +946,11 @@ void cRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_BlockY, int a_B { public: cWoodenPressurePlateCallback(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + m_Entity(NULL), + m_World(a_World), m_X(a_BlockX), m_Y(a_BlockY), - m_Z(a_BlockZ), - m_World(a_World), - m_Entity(NULL) + m_Z(a_BlockZ) { } diff --git a/src/World.cpp b/src/World.cpp index f9a6e7776..892e04d63 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -247,9 +247,9 @@ cWorld::cWorld(const AString & a_WorldName) : m_SkyDarkness(0), m_Weather(eWeather_Sunny), m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :) + m_Scoreboard(this), m_GeneratorCallbacks(*this), - m_TickThread(*this), - m_Scoreboard(this) + m_TickThread(*this) { LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str()); -- cgit v1.2.3 From 62c18868b2f01b5a7c2b4a4b5dc4c8ac6bc6d441 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 5 Feb 2014 09:57:53 -0800 Subject: Added Self Test Plugin At the moment It just shuts the server down again --- MCServer/Plugins/SelfTest/plugin.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 MCServer/Plugins/SelfTest/plugin.lua diff --git a/MCServer/Plugins/SelfTest/plugin.lua b/MCServer/Plugins/SelfTest/plugin.lua new file mode 100644 index 000000000..3822b9ba1 --- /dev/null +++ b/MCServer/Plugins/SelfTest/plugin.lua @@ -0,0 +1,20 @@ + +function Initialize(Plugin) + Plugin:SetName("SelfTest") + Plugin:SetVersion(1) + + cPluginManager.AddHook(cPluginManager.HOOK_WORLD_STARTED, OnWorldStarted) + + LOG("Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) + return true +end + + + + + +function OnWorldStarted(World) + LOG("Stopping") + cRoot:Get():QueueExecuteConsoleCommand("stop"); + return false +end -- cgit v1.2.3 From f25597540de890f48a0b4df6feeb7e4c3246efb8 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 5 Feb 2014 10:10:45 -0800 Subject: Added support to start up MCServer and then immediatly sut it down in travis --- .travis.yml | 2 +- CMakeLists.txt | 4 ++++ src/Bindings/PluginManager.cpp | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a41c10b84..c8a2faecb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ compiler: - gcc - clang # Build MCServer -script: cmake . -DCMAKE_BUILD_TYPE=RELEASE && make -j 2 +script: cmake . -DCMAKE_BUILD_TYPE=RELEASE -DSELF_TEST=1 && make -j 2 && cd MCServer/ && ./MCServer # Notification Settings notifications: diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fee887e7..57b200a2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,6 +124,10 @@ endif() # The Expat library is linked in statically, make the source files aware of that: add_definitions(-DXML_STATIC) +# Self Test Mode enables extra checks at startup +if(${SELF_TEST}) + add_definitions(-DSELF_TEST) +endif() # Declare the flags used for profiling builds: if (MSVC) diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index a20583550..f4bae0647 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -172,6 +172,10 @@ void cPluginManager::InsertDefaultPlugins(cIniFile & a_SettingsIni) a_SettingsIni.AddValue("Plugins", "Plugin", "Core"); a_SettingsIni.AddValue("Plugins", "Plugin", "TransAPI"); a_SettingsIni.AddValue("Plugins", "Plugin", "ChatLog"); + + #ifdef SELFTEST + a_SettingsIni.AddValue("Plugins", "Plugin", "SelfTest"); + #endif } -- cgit v1.2.3 From de7e84b45b4564edef674f6fb006b1968a52ac80 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 5 Feb 2014 10:38:24 -0800 Subject: Revert "Added Self Test Plugin" This reverts commit 62c18868b2f01b5a7c2b4a4b5dc4c8ac6bc6d441. --- MCServer/Plugins/SelfTest/plugin.lua | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 MCServer/Plugins/SelfTest/plugin.lua diff --git a/MCServer/Plugins/SelfTest/plugin.lua b/MCServer/Plugins/SelfTest/plugin.lua deleted file mode 100644 index 3822b9ba1..000000000 --- a/MCServer/Plugins/SelfTest/plugin.lua +++ /dev/null @@ -1,20 +0,0 @@ - -function Initialize(Plugin) - Plugin:SetName("SelfTest") - Plugin:SetVersion(1) - - cPluginManager.AddHook(cPluginManager.HOOK_WORLD_STARTED, OnWorldStarted) - - LOG("Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) - return true -end - - - - - -function OnWorldStarted(World) - LOG("Stopping") - cRoot:Get():QueueExecuteConsoleCommand("stop"); - return false -end -- cgit v1.2.3 From 670213b48d9b175d3c3167b17f03dc1c72b36b33 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 5 Feb 2014 10:39:33 -0800 Subject: Simplified shutdown --- .travis.yml | 2 +- src/Bindings/PluginManager.cpp | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c8a2faecb..38dd2f280 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ compiler: - gcc - clang # Build MCServer -script: cmake . -DCMAKE_BUILD_TYPE=RELEASE -DSELF_TEST=1 && make -j 2 && cd MCServer/ && ./MCServer +script: cmake . -DCMAKE_BUILD_TYPE=RELEASE -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | ./MCServer) # Notification Settings notifications: diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index f4bae0647..a20583550 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -172,10 +172,6 @@ void cPluginManager::InsertDefaultPlugins(cIniFile & a_SettingsIni) a_SettingsIni.AddValue("Plugins", "Plugin", "Core"); a_SettingsIni.AddValue("Plugins", "Plugin", "TransAPI"); a_SettingsIni.AddValue("Plugins", "Plugin", "ChatLog"); - - #ifdef SELFTEST - a_SettingsIni.AddValue("Plugins", "Plugin", "SelfTest"); - #endif } -- cgit v1.2.3 From aeb877f76a77d7f12b6aea5264a1b9b976e4f3ac Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 5 Feb 2014 11:06:57 -0800 Subject: Modified automatic test for boundingBox --- src/BoundingBox.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/BoundingBox.cpp b/src/BoundingBox.cpp index 86d4546c7..94a22465c 100644 --- a/src/BoundingBox.cpp +++ b/src/BoundingBox.cpp @@ -11,7 +11,7 @@ -#if 0 +#if SELF_TEST /// A simple self-test that is executed on program start, used to verify bbox functionality class SelfTest @@ -30,18 +30,37 @@ public: Vector3d(1.999, 0, 1.5), Vector3d(1.999, 4, 1.5), // Should intersect at 0.25, face 0 (YM) Vector3d(2.001, 0, 1.5), Vector3d(2.001, 4, 1.5), // Should not intersect } ; + bool Results[] = {true,true,true,false,true,false}; + double LineCoeffs[] = {2,0.25,0.5,0,0.25,0}; + for (size_t i = 0; i < ARRAYCOUNT(LineDefs) / 2; i++) { double LineCoeff; - char Face; + eBlockFace Face; Vector3d Line1 = LineDefs[2 * i]; Vector3d Line2 = LineDefs[2 * i + 1]; bool res = cBoundingBox::CalcLineIntersection(Min, Max, Line1, Line2, LineCoeff, Face); - printf("LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", - Line1.x, Line1.y, Line1.z, - Line2.x, Line2.y, Line2.z, - res ? 1 : 0, LineCoeff, Face - ); + if (res != Results[i]) + { + printf("LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", + Line1.x, Line1.y, Line1.z, + Line2.x, Line2.y, Line2.z, + res ? 1 : 0, LineCoeff, Face + ); + abort(); + } + if (res) + { + if (LineCoeff != LineCoeffs[i]) + { + printf("LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", + Line1.x, Line1.y, Line1.z, + Line2.x, Line2.y, Line2.z, + res ? 1 : 0, LineCoeff, Face + ); + abort(); + } + } } // for i - LineDefs[] printf("BoundingBox selftest complete."); } -- cgit v1.2.3 From 89ec774fd60630b167185fc2526655880a975752 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 5 Feb 2014 20:20:11 +0100 Subject: Removed deprecated HasCommand function --- src/Entities/Player.cpp | 13 ------------- src/Entities/Player.h | 1 - src/Group.cpp | 21 +-------------------- src/Group.h | 2 -- 4 files changed, 1 insertion(+), 36 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index bde623f1b..bea8def9e 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1267,19 +1267,6 @@ void cPlayer::RemoveFromGroup( const AString & a_GroupName ) -bool cPlayer::CanUseCommand( const AString & a_Command ) -{ - for( GroupList::iterator itr = m_Groups.begin(); itr != m_Groups.end(); ++itr ) - { - if( (*itr)->HasCommand( a_Command ) ) return true; - } - return false; -} - - - - - bool cPlayer::HasPermission(const AString & a_Permission) { if (a_Permission.empty()) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 50f7560d6..5c56c927a 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -211,7 +211,6 @@ public: /// Removes a player from the group, resolves permissions and group inheritance (case sensitive) void RemoveFromGroup( const AString & a_GroupName ); // tolua_export - bool CanUseCommand( const AString & a_Command ); // tolua_export bool HasPermission( const AString & a_Permission ); // tolua_export const GroupList & GetGroups() { return m_Groups; } // >> EXPORTED IN MANUALBINDINGS << StringList GetResolvedPermissions(); // >> EXPORTED IN MANUALBINDINGS << diff --git a/src/Group.cpp b/src/Group.cpp index cc42c55a1..5f1f25782 100644 --- a/src/Group.cpp +++ b/src/Group.cpp @@ -25,26 +25,6 @@ void cGroup::AddPermission( AString a_Permission ) -bool cGroup::HasCommand( AString a_Command ) -{ - if( m_Commands.find("*") != m_Commands.end() ) - { - return true; - } - - CommandMap::iterator itr = m_Commands.find( a_Command ); - if( itr != m_Commands.end() ) - { - if( itr->second ) return true; - } - - for( GroupList::iterator itr = m_Inherits.begin(); itr != m_Inherits.end(); ++itr ) - { - if( (*itr)->HasCommand( a_Command ) ) return true; - } - return false; -} - void cGroup::InheritFrom( cGroup* a_Group ) { m_Inherits.remove( a_Group ); @@ -54,6 +34,7 @@ void cGroup::InheritFrom( cGroup* a_Group ) + void cGroup::ClearPermission() { m_Permissions.clear(); diff --git a/src/Group.h b/src/Group.h index 3299aecbc..8bee6f7ed 100644 --- a/src/Group.h +++ b/src/Group.h @@ -18,8 +18,6 @@ public: // tolua_export void AddPermission( AString a_Permission ); // tolua_export void InheritFrom( cGroup* a_Group ); // tolua_export - bool HasCommand( AString a_Command ); // tolua_export - typedef std::map< AString, bool > PermissionMap; const PermissionMap & GetPermissions() const { return m_Permissions; } -- cgit v1.2.3 From 374fecf61f94e8df6bf60ea49df265dd19859bf7 Mon Sep 17 00:00:00 2001 From: worktycho Date: Wed, 5 Feb 2014 20:13:37 +0000 Subject: Change Output to stderr --- src/BoundingBox.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/BoundingBox.cpp b/src/BoundingBox.cpp index 94a22465c..47b135688 100644 --- a/src/BoundingBox.cpp +++ b/src/BoundingBox.cpp @@ -1,4 +1,3 @@ - // BoundingBox.cpp // Implements the cBoundingBox class representing an axis-aligned bounding box with floatingpoint coords @@ -42,7 +41,7 @@ public: bool res = cBoundingBox::CalcLineIntersection(Min, Max, Line1, Line2, LineCoeff, Face); if (res != Results[i]) { - printf("LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", + fprintf(stderr,"LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", Line1.x, Line1.y, Line1.z, Line2.x, Line2.y, Line2.z, res ? 1 : 0, LineCoeff, Face @@ -53,7 +52,7 @@ public: { if (LineCoeff != LineCoeffs[i]) { - printf("LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", + fprintf(stderr,"LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", Line1.x, Line1.y, Line1.z, Line2.x, Line2.y, Line2.z, res ? 1 : 0, LineCoeff, Face @@ -62,7 +61,7 @@ public: } } } // for i - LineDefs[] - printf("BoundingBox selftest complete."); + fprintf(stderr,"BoundingBox selftest complete."); } } Test; -- cgit v1.2.3 From aec7ffd3f69a07a8d207d2b00f54433affff8139 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 5 Feb 2014 21:50:35 +0100 Subject: InfoDump: Added github output. --- MCServer/Plugins/InfoDump.lua | 233 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 228 insertions(+), 5 deletions(-) diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index 28a17c214..8fac09d60 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -69,6 +69,47 @@ end +--- Replaces generic formatting with forum-specific formatting +-- Also removes the single line-ends +local function GithubizeString(a_Str) + assert(type(a_Str) == "string"); + + -- Remove the indentation, unless in the code tag: + -- Only one code or /code tag per line is supported! + local IsInCode = false; + local function RemoveIndentIfNotInCode(s) + if (IsInCode) then + -- we're in code section, check if this line terminates it + IsInCode = (s:find("{%%/code}") ~= nil); + return s .. "\n"; + else + -- we're not in code section, check if this line starts it + IsInCode = (s:find("{%%code}") ~= nil); + return s:gsub("^%s*", "") .. "\n"; + end + end + a_Str = a_Str:gsub("(.-)\n", RemoveIndentIfNotInCode); + + -- Replace multiple line ends with {%p} and single line ends with a space, + -- so that manual word-wrap in the Info.lua file doesn't wrap in the forum. + a_Str = a_Str:gsub("\n\n", "{%%p}"); + a_Str = a_Str:gsub("\n", " "); + + -- Replace the generic formatting: + a_Str = a_Str:gsub("{%%p}", "\n\n"); + a_Str = a_Str:gsub("{%%b}", "**"):gsub("{%%/b}", "**"); + a_Str = a_Str:gsub("{%%i}", "*"):gsub("{%%/i}", "*"); + a_Str = a_Str:gsub("{%%list}", ""):gsub("{%%/list}", ""); + a_Str = a_Str:gsub("{%%li}", " - "):gsub("{%%/li}", ""); + -- TODO: Other formatting + + return a_Str; +end + + + + + --- Builds an array of categories, each containing all the commands belonging to the category, -- and the category description, if available. -- Returns the array table, each item has the following format: @@ -156,6 +197,28 @@ end +--- Returns a string specifying the command. +-- If a_CommandParams is nil, returns a_CommandName apostrophed +-- If a_CommandParams is a string, apostrophes a_CommandName with a_CommandParams +local function GetCommandRefGithub(a_CommandName, a_CommandParams) + assert(type(a_CommandName) == "string"); + if (a_CommandParams == nil) then + return "`" .. a_CommandName .. "`"; + end + + assert(type(a_CommandParams) == "table"); + if ((a_CommandParams.Params == nil) or (a_CommandParams.Params == "")) then + return "`" .. a_CommandName .. "`"; + end + + assert(type(a_CommandParams.Params) == "string"); + return "`" .. a_CommandName .. " " .. a_CommandParams.Params .. "`"; +end + + + + + --- Writes the specified command detailed help array to the output file, in the forum dump format local function WriteCommandParameterCombinationsForum(a_CmdString, a_ParameterCombinations, f) assert(type(a_CmdString) == "string"); @@ -184,6 +247,34 @@ end +--- Writes the specified command detailed help array to the output file, in the forum dump format +local function WriteCommandParameterCombinationsGithub(a_CmdString, a_ParameterCombinations, f) + assert(type(a_CmdString) == "string"); + assert(type(a_ParameterCombinations) == "table"); + assert(f ~= nil); + + if (#a_ParameterCombinations == 0) then + -- No explicit parameter combinations to write + return; + end + + f:write("The following parameter combinations are recognized:\n\n"); + for idx, combination in ipairs(a_ParameterCombinations) do + f:write(GetCommandRefGithub(a_CmdString, combination)); + if (combination.Help ~= nil) then + f:write(" - ", GithubizeString(combination.Help)); + end + if (combination.Permission ~= nil) then + f:write(" (Requires permission '**", combination.Permission, "**')"); + end + f:write("\n"); + end +end + + + + + --- Writes all commands in the specified category to the output file, in the forum dump format local function WriteCommandsCategoryForum(a_Category, f) -- Write category name: @@ -206,7 +297,7 @@ local function WriteCommandsCategoryForum(a_Category, f) f:write("Permission required: [color=red]", cmd.Info.Permission, "[/color]\n"); end if (cmd.Info.DetailedDescription ~= nil) then - f:write(cmd.Info.DetailedDescription); + f:write(ForumizeString(cmd.Info.DetailedDescription)); end if (cmd.Info.ParameterCombinations ~= nil) then WriteCommandParameterCombinationsForum(cmd.CommandString, cmd.Info.ParameterCombinations, f); @@ -219,6 +310,41 @@ end +--- Writes all commands in the specified category to the output file, in the Github dump format +local function WriteCommandsCategoryGithub(a_Category, f) + -- Write category name: + local CategoryName = a_Category.Name; + if (CategoryName == "") then + CategoryName = "General"; + end + f:write("\n## ", GithubizeString(a_Category.DisplayName or CategoryName), "\n"); + + -- Write description: + if (a_Category.Description ~= "") then + f:write(GithubizeString(a_Category.Description), "\n"); + end + + -- Write commands: + f:write("\n"); + for idx2, cmd in ipairs(a_Category.Commands) do + f:write("\n### ", cmd.CommandString, "\n", GithubizeString(cmd.Info.HelpString or "UNDOCUMENTED"), "\n\n"); + if (cmd.Info.Permission ~= nil) then + f:write("Permission required: **", cmd.Info.Permission, "**\n\n"); + end + if (cmd.Info.DetailedDescription ~= nil) then + f:write(GithubizeString(cmd.Info.DetailedDescription)); + end + if (cmd.Info.ParameterCombinations ~= nil) then + WriteCommandParameterCombinationsGithub(cmd.CommandString, cmd.Info.ParameterCombinations, f); + end + end + f:write("\n\n") +end + + + + + local function DumpCommandsForum(a_PluginInfo, f) -- Copy all Categories from a dictionary into an array: local Categories = BuildCategories(a_PluginInfo); @@ -246,9 +372,36 @@ end +local function DumpCommandsGithub(a_PluginInfo, f) + -- Copy all Categories from a dictionary into an array: + local Categories = BuildCategories(a_PluginInfo); + + -- Sort the categories by name: + table.sort(Categories, + function(cat1, cat2) + return (string.lower(cat1.Name) < string.lower(cat2.Name)); + end + ); + + if (#Categories == 0) then + return; + end + + f:write("\n# Commands\n"); + + -- Dump per-category commands: + for idx, cat in ipairs(Categories) do + WriteCommandsCategoryGithub(cat, f); + end +end + + + + + local function DumpAdditionalInfoForum(a_PluginInfo, f) local AInfo = a_PluginInfo.AdditionalInfo; - if ((AInfo == nil) or (type(AInfo) ~= "table")) then + if (type(AInfo) ~= "table") then -- There is no AdditionalInfo in a_PluginInfo return; end @@ -265,6 +418,25 @@ end +local function DumpAdditionalInfoGithub(a_PluginInfo, f) + local AInfo = a_PluginInfo.AdditionalInfo; + if (type(AInfo) ~= "table") then + -- There is no AdditionalInfo in a_PluginInfo + return; + end + + for idx, info in ipairs(a_PluginInfo.AdditionalInfo) do + if ((info.Title ~= nil) and (info.Contents ~= nil)) then + f:write("\n# ", GithubizeString(info.Title), "\n"); + f:write(GithubizeString(info.Contents), "\n"); + end + end +end + + + + + --- Collects all permissions mentioned in the info, returns them as a sorted array -- Each array item is {Name = "PermissionName", Info = { PermissionInfo }} local function BuildPermissions(a_PluginInfo) @@ -333,7 +505,7 @@ local function DumpPermissionsForum(a_PluginInfo, f) f:write("\n[size=X-Large]Permissions[/size]\n[list]\n"); for idx, perm in ipairs(Permissions) do f:write(" - [color=red]", perm.Name, "[/color] - "); - f:write(perm.Info.Description or ""); + f:write(ForumizeString(perm.Info.Description or "")); local CommandsAffected = perm.Info.CommandsAffected or {}; if (#CommandsAffected > 0) then f:write("\n[list] Commands affected:\n- "); @@ -356,6 +528,43 @@ end +local function DumpPermissionsGithub(a_PluginInfo, f) + -- Get the processed sorted array of permissions: + local Permissions = BuildPermissions(a_PluginInfo); + if ((Permissions == nil) or (#Permissions <= 0)) then + return; + end + + -- Dump the permissions: + f:write("\n# Permissions\n"); + for idx, perm in ipairs(Permissions) do + f:write("### ", perm.Name, "\n"); + f:write(GithubizeString(perm.Info.Description or "")); + local CommandsAffected = perm.Info.CommandsAffected or {}; + if (#CommandsAffected > 0) then + f:write("\n\nCommands affected:\n - "); + local Affects = {}; + for idx2, cmd in ipairs(CommandsAffected) do + if (type(cmd) == "string") then + table.insert(Affects, GetCommandRefGithub(cmd)); + else + table.insert(Affects, GetCommandRefGithub(cmd.Name, cmd)); + end + end + f:write(table.concat(Affects, "\n - ")); + f:write("\n"); + end + if (perm.Info.RecommendedGroups ~= nil) then + f:write("\n\nRecommended groups: ", perm.Info.RecommendedGroups, "\n"); + end + f:write("\n"); + end +end + + + + + local function DumpPluginInfoForum(a_PluginFolder, a_PluginInfo) -- Open the output file: local f, msg = io.open(a_PluginInfo.Name .. "_forum.txt", "w"); @@ -377,8 +586,21 @@ end -local function DumpPluginInfoGitHub() - -- TODO +local function DumpPluginInfoGithub(a_PluginFolder, a_PluginInfo) + -- Open the output file: + local f, msg = io.open(a_PluginInfo.Name .. ".md", "w"); -- TODO: Save to a_PluginFolder .. "/Readme.md" instead + if (f == nil) then + print("\tCannot dump github info for plugin " .. a_PluginFolder .. ": " .. msg); + return; + end + + -- Write the description: + f:write(GithubizeString(a_PluginInfo.Description), "\n"); + DumpAdditionalInfoGithub(a_PluginInfo, f); + DumpCommandsGithub(a_PluginInfo, f); + DumpPermissionsGithub(a_PluginInfo, f); + + f:close(); end @@ -418,6 +640,7 @@ local function ProcessPluginFolder(a_FolderName) return; end DumpPluginInfoForum(a_FolderName, PluginInfo); + DumpPluginInfoGithub(a_FolderName, PluginInfo); end -- cgit v1.2.3 From 3450f0ca42c8f72920045709d0a57d5443b086a7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 5 Feb 2014 23:24:02 +0000 Subject: Added more chat functions --- src/Defines.h | 56 +++++++++++++++++++++++++++++---------------------- src/Entities/Player.h | 1 - src/Root.h | 4 +++- src/World.h | 12 ++++++++++- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/Defines.h b/src/Defines.h index f766d4d04..7fe93399d 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -448,14 +448,15 @@ enum ChatPrefixCodes // http://forum.mc-server.org/showthread.php?tid=1212 // MessageType... - mtCustom, // Plugin prints what it wants mtFailure, // Something could not be done (i.e. command not executed due to insufficient privilege) mtInformation, // Informational message (i.e. command usage) mtSuccess, // Something executed successfully mtWarning, // Something concerning (i.e. reload) is about to happen mtFatal, // Something catastrophic occured (i.e. plugin crash) mtDeath, // Denotes death of player - mtPrivateMessage // Player to player messaging identifier + mtPrivateMessage, // Player to player messaging identifier + mtJoin, // A player has joined the server + mtLeave, // A player has left the server }; @@ -463,53 +464,60 @@ enum ChatPrefixCodes inline AString AppendChatEpithet(const AString & a_ChatMessage, ChatPrefixCodes a_ChatPrefix) { + AString Message; + switch (a_ChatPrefix) { - case mtCustom: return a_ChatMessage; case mtFailure: { - AString Message(Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; + Message = Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); + break; } case mtInformation: { - AString Message(Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; + Message = Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + break; } case mtSuccess: { - AString Message(Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; + Message = Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str()); + break; } case mtWarning: { - AString Message(Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; + Message = Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); + break; } case mtFatal: { - AString Message(Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; + Message = Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str()); + break; } case mtDeath: { - AString Message(Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str())); - Message.append(a_ChatMessage); - return Message; + Message = Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str()); + break; } case mtPrivateMessage: { - AString Message(Printf("%s[MSG] %s%s", cChatColor::LightBlue.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str())); - Message.append(a_ChatMessage); - return Message; + Message = Printf("%s[MSG] %s%s", cChatColor::LightBlue.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()); + break; + } + case mtJoin: + { + Message = Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + break; + } + case mtLeave: + { + Message = Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + break; } default: ASSERT(!"Unhandled chat prefix type!"); return ""; } + + Message.append(a_ChatMessage); + return Message; } // tolua_begin diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 925011c9c..f2830a0c7 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -201,7 +201,6 @@ public: void SendMessageSuccess(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtSuccess)); } void SendMessageWarning(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtWarning)); } void SendMessageFatal(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtFailure)); } - void SendMessageDeath(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtDeath)); } void SendMessagePrivateMsg(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtPrivateMessage)); } const AString & GetName(void) const { return m_PlayerName; } diff --git a/src/Root.h b/src/Root.h index fa52c21a1..ba106b54e 100644 --- a/src/Root.h +++ b/src/Root.h @@ -104,6 +104,9 @@ public: /// Finds a player from a partial or complete player name and calls the callback - case-insensitive bool FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << + + void BroadcastChatJoin(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtJoin)); } + void BroadcastChatLeave(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtLeave)); } // tolua_begin @@ -115,7 +118,6 @@ public: void BroadcastChatWarning(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtWarning)); } void BroadcastChatFatal(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); } void BroadcastChatDeath(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtDeath)); } - void BroadcastChatPrivateMsg(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtPrivateMessage)); } /// Returns the textual description of the protocol version: 49 -> "1.4.4". Provided specifically for Lua API static AString GetProtocolVersionTextFromInt(int a_ProtocolVersionNum); diff --git a/src/World.h b/src/World.h index bf6a4ba28..01481c049 100644 --- a/src/World.h +++ b/src/World.h @@ -157,7 +157,17 @@ public: void BroadcastBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = NULL); // tolua_export void BroadcastBlockBreakAnimation(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = NULL); void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); ///< If there is a block entity at the specified coods, sends it to all clients except a_Exclude - void BroadcastChat (const AString & a_Message, const cClientHandle * a_Exclude = NULL); // tolua_export + + // tolua_start + void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL); + void BroadcastChatInfo(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtInformation)); } + void BroadcastChatFailure(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); } + void BroadcastChatSuccess(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtSuccess)); } + void BroadcastChatWarning(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtWarning)); } + void BroadcastChatFatal(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); } + void BroadcastChatDeath(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtDeath)); } + // tolua_end + void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL); void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); -- cgit v1.2.3 From aa8b46e94714f261bfe451897b7ef23934e764eb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 5 Feb 2014 23:24:16 +0000 Subject: Server internally uses new functions --- src/Bindings/PluginManager.cpp | 4 ++-- src/Blocks/BlockBed.cpp | 2 +- src/ClientHandle.cpp | 14 ++++++-------- src/Entities/Player.cpp | 10 ++++------ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index a20583550..c6c8c081e 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -248,7 +248,7 @@ bool cPluginManager::CallHookChat(cPlayer * a_Player, AString & a_Message) { AStringVector Split(StringSplit(a_Message, " ")); ASSERT(!Split.empty()); // This should not happen - we know there's at least one char in the message so the split needs to be at least one item long - a_Player->SendMessage(Printf("%s[INFO] %sUnknown command: \"%s\"", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), Split[0].c_str())); + a_Player->SendMessageInfo(Printf("Unknown command: \"%s\"", Split[0].c_str())); LOGINFO("Player %s issued an unknown command: \"%s\"", a_Player->GetName().c_str(), a_Message.c_str()); return true; // Cancel sending } @@ -1392,7 +1392,7 @@ bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command !a_Player->HasPermission(cmd->second.m_Permission) ) { - a_Player->SendMessage(Printf("%s[INFO] %sForbidden command; insufficient privileges: \"%s\"", cChatColor::Rose.c_str(), cChatColor::White.c_str(), Split[0].c_str())); + a_Player->SendMessageFailure(Printf("Forbidden command; insufficient privileges: \"%s\"", Split[0].c_str())); LOGINFO("Player %s tried to execute forbidden command: \"%s\"", a_Player->GetName().c_str(), Split[0].c_str()); a_WasCommandForbidden = true; return false; diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 65d397b36..8f291ad1f 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -78,7 +78,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface } } } else { - a_Player->SendMessage("You can only sleep at night"); + a_Player->SendMessageFailure("You can only sleep at night"); } } } diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 439f980ce..f7c6cb734 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -225,9 +225,7 @@ void cClientHandle::Authenticate(void) if (!cRoot::Get()->GetPluginManager()->CallHookPlayerJoined(*m_Player)) { - AString JoinMessage; - AppendPrintf(JoinMessage, "%s[JOIN] %s%s has joined the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), GetUsername().c_str()); - cRoot::Get()->BroadcastChat(JoinMessage); + cRoot::Get()->BroadcastChatJoin(Printf("%s has joined the game", GetUsername().c_str())); LOGINFO("Player %s has joined the game.", m_Username.c_str()); } @@ -568,7 +566,7 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a { if (a_Length < 14) { - SendChat(Printf("%s[INFO]%s Failure setting command block command; bad request", cChatColor::Red.c_str(), cChatColor::White.c_str())); + SendChat(AppendChatEpithet("Failure setting command block command; bad request", mtFailure)); LOGD("Malformed MC|AdvCdm packet."); return; } @@ -598,7 +596,7 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a default: { - SendChat(Printf("%s[INFO]%s Failure setting command block command; unhandled mode", cChatColor::Red.c_str(), cChatColor::White.c_str())); + SendChat(AppendChatEpithet("Failure setting command block command; unhandled mode", mtFailure)); LOGD("Unhandled MC|AdvCdm packet mode."); return; } @@ -609,12 +607,12 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a if (World->AreCommandBlocksEnabled()) { World->SetCommandBlockCommand(BlockX, BlockY, BlockZ, Command); - - SendChat(Printf("%s[INFO]%s Successfully set command block command", cChatColor::Green.c_str(), cChatColor::White.c_str())); + + SendChat(AppendChatEpithet("Successfully set command block command", mtSuccess)); } else { - SendChat(Printf("%s[INFO]%s Command blocks are not enabled on this server", cChatColor::Yellow.c_str(), cChatColor::White.c_str())); + SendChat(AppendChatEpithet("Command blocks are not enabled on this server", mtFailure)); } } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c0466fa66..385e28c28 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -132,9 +132,7 @@ cPlayer::~cPlayer(void) { if (!cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this)) { - AString DisconnectMessage; - AppendPrintf(DisconnectMessage, "%s[LEAVE] %s%s has left the game", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), GetName().c_str()); - cRoot::Get()->BroadcastChat(DisconnectMessage); + cRoot::Get()->BroadcastChatLeave(Printf("%s has left the game", GetName().c_str())); LOGINFO("Player %s has left the game.", GetName().c_str()); } @@ -847,18 +845,18 @@ void cPlayer::KilledBy(cEntity * a_Killer) if (a_Killer == NULL) { - GetWorld()->BroadcastChat(Printf("%s[DEATH] %s%s was killed by environmental damage", cChatColor::Red.c_str(), cChatColor::White.c_str(), GetName().c_str())); + GetWorld()->BroadcastChatDeath(Printf("%s was killed by environmental damage", GetName().c_str())); } else if (a_Killer->IsPlayer()) { - GetWorld()->BroadcastChat(Printf("%s[DEATH] %s%s was killed by %s", cChatColor::Red.c_str(), cChatColor::White.c_str(), GetName().c_str(), ((cPlayer *)a_Killer)->GetName().c_str())); + GetWorld()->BroadcastChatDeath(Printf("%s was killed by %s", GetName().c_str(), ((cPlayer *)a_Killer)->GetName().c_str())); } else { AString KillerClass = a_Killer->GetClass(); KillerClass.erase(KillerClass.begin()); // Erase the 'c' of the class (e.g. "cWitch" -> "Witch") - GetWorld()->BroadcastChat(Printf("%s[DEATH] %s%s was killed by a %s", cChatColor::Red.c_str(), cChatColor::White.c_str(), GetName().c_str(), KillerClass.c_str())); + GetWorld()->BroadcastChatDeath(Printf("%s was killed by a %s", GetName().c_str(), KillerClass.c_str())); } class cIncrementCounterCB -- cgit v1.2.3 From 916020d6c26419d2f979b823edd1ab76e2cbd442 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 7 Feb 2014 12:07:22 +0100 Subject: Fixed wiki link in auto-generated settings.ini. --- src/Root.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Root.cpp b/src/Root.cpp index 5d1b2ebe2..9462a3c91 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -132,7 +132,7 @@ void cRoot::Start(void) LOGWARN("Regenerating settings.ini, all settings will be reset"); IniFile.AddHeaderComment(" This is the main server configuration"); IniFile.AddHeaderComment(" Most of the settings here can be configured using the webadmin interface, if enabled in webadmin.ini"); - IniFile.AddHeaderComment(" See: http://www.mc-server.org/wiki/doku.php?id=configure:settings.ini for further configuration help"); + IniFile.AddHeaderComment(" See: http://wiki.mc-server.org/doku.php?id=configure:settings.ini for further configuration help"); } m_PrimaryServerVersion = IniFile.GetValueI("Server", "PrimaryServerVersion", 0); @@ -220,6 +220,7 @@ void cRoot::Start(void) #endif // Deallocate stuffs + if LOG("Shutting down server..."); m_Server->Shutdown(); -- cgit v1.2.3 From e165da946e8c1d836b11c33ba444e842472b2bfe Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 7 Feb 2014 12:26:41 +0100 Subject: WebAdmin is stopped properly on server shutdown / restart. Fixes #272. --- src/Root.cpp | 7 ++----- src/WebAdmin.cpp | 38 +++++++++++++++++++++++++++----------- src/WebAdmin.h | 46 ++++++++++++++++++++++++++-------------------- 3 files changed, 55 insertions(+), 36 deletions(-) diff --git a/src/Root.cpp b/src/Root.cpp index 9462a3c91..0bd2b58fe 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -219,17 +219,14 @@ void cRoot::Start(void) delete m_InputThread; m_InputThread = NULL; #endif - // Deallocate stuffs - if + // Stop the server: + m_WebAdmin->Stop(); LOG("Shutting down server..."); m_Server->Shutdown(); - LOGD("Shutting down deadlock detector..."); dd.Stop(); - LOGD("Stopping world threads..."); StopWorlds(); - LOGD("Stopping authenticator..."); m_Authenticator.Stop(); diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp index e6a5a01b3..e88de5947 100644 --- a/src/WebAdmin.cpp +++ b/src/WebAdmin.cpp @@ -42,6 +42,7 @@ public: cWebAdmin::cWebAdmin(void) : m_IsInitialized(false), + m_IsRunning(false), m_TemplateScript("") { } @@ -52,29 +53,26 @@ cWebAdmin::cWebAdmin(void) : cWebAdmin::~cWebAdmin() { - if (m_IsInitialized) - { - LOGD("Stopping WebAdmin..."); - } + ASSERT(!m_IsRunning); // Was the HTTP server stopped properly? } -void cWebAdmin::AddPlugin( cWebPlugin * a_Plugin ) +void cWebAdmin::AddPlugin(cWebPlugin * a_Plugin) { - m_Plugins.remove( a_Plugin ); - m_Plugins.push_back( a_Plugin ); + m_Plugins.remove(a_Plugin); + m_Plugins.push_back(a_Plugin); } -void cWebAdmin::RemovePlugin( cWebPlugin * a_Plugin ) +void cWebAdmin::RemovePlugin(cWebPlugin * a_Plugin) { - m_Plugins.remove( a_Plugin ); + m_Plugins.remove(a_Plugin); } @@ -87,7 +85,8 @@ bool cWebAdmin::Init(void) { LOGWARN("Regenerating webadmin.ini, all settings will be reset"); m_IniFile.AddHeaderComment(" This file controls the webadmin feature of MCServer"); - m_IniFile.AddHeaderComment(" Username format: [User:*username*] | Password format: Password=*password*; for example:"); + m_IniFile.AddHeaderComment(" Username format: [User:*username*]"); + m_IniFile.AddHeaderComment(" Password format: Password=*password*; for example:"); m_IniFile.AddHeaderComment(" [User:admin]"); m_IniFile.AddHeaderComment(" Password=admin"); } @@ -134,7 +133,24 @@ bool cWebAdmin::Start(void) m_TemplateScript.Close(); } - return m_HTTPServer.Start(*this); + m_IsRunning = m_HTTPServer.Start(*this); + return m_IsRunning; +} + + + + + +void cWebAdmin::Stop(void) +{ + if (!m_IsRunning) + { + return; + } + + LOGD("Stopping WebAdmin..."); + m_HTTPServer.Stop(); + m_IsRunning = false; } diff --git a/src/WebAdmin.h b/src/WebAdmin.h index 3eb807640..a2a07a543 100644 --- a/src/WebAdmin.h +++ b/src/WebAdmin.h @@ -56,13 +56,13 @@ struct HTTPRequest AString Username; // tolua_end - /// Parameters given in the URL, after the questionmark + /** Parameters given in the URL, after the questionmark */ StringStringMap Params; // >> EXPORTED IN MANUALBINDINGS << - /// Parameters posted as a part of a form - either in the URL (GET method) or in the body (POST method) + /** Parameters posted as a part of a form - either in the URL (GET method) or in the body (POST method) */ StringStringMap PostParams; // >> EXPORTED IN MANUALBINDINGS << - /// Same as PostParams + /** Same as PostParams */ FormDataMap FormData; // >> EXPORTED IN MANUALBINDINGS << } ; // tolua_export @@ -107,14 +107,17 @@ public: cWebAdmin(void); virtual ~cWebAdmin(); - /// Initializes the object. Returns true if successfully initialized and ready to start + /** Initializes the object. Returns true if successfully initialized and ready to start */ bool Init(void); - /// Starts the HTTP server taking care of the admin. Returns true if successful + /** Starts the HTTP server taking care of the admin. Returns true if successful */ bool Start(void); + + /** Stops the HTTP server, if it was started. */ + void Stop(void); - void AddPlugin( cWebPlugin* a_Plugin ); - void RemovePlugin( cWebPlugin* a_Plugin ); + void AddPlugin(cWebPlugin * a_Plugin); + void RemovePlugin(cWebPlugin * a_Plugin); // TODO: Convert this to the auto-locking callback mechanism used for looping players in worlds and such PluginList GetPlugins() const { return m_Plugins; } // >> EXPORTED IN MANUALBINDINGS << @@ -123,13 +126,13 @@ public: sWebAdminPage GetPage(const HTTPRequest & a_Request); - /// Returns the contents of the default page - the list of plugins and players + /** Returns the contents of the default page - the list of plugins and players */ AString GetDefaultPage(void); - /// Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) + /** Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) */ AString GetBaseURL(const AString & a_URL); - /// Escapes text passed into it, so it can be embedded into html. + /** Escapes text passed into it, so it can be embedded into html. */ static AString GetHTMLEscapedString(const AString & a_Input); AString GetIPv4Ports(void) const { return m_PortsIPv4; } @@ -137,21 +140,21 @@ public: // tolua_end - /// Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) + /** Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) */ AString GetBaseURL(const AStringVector& a_URLSplit); protected: - /// Common base class for request body data handlers + /** Common base class for request body data handlers */ class cRequestData { public: virtual ~cRequestData() {} // Force a virtual destructor in all descendants - /// Called when a new chunk of body data is received + /** Called when a new chunk of body data is received */ virtual void OnBody(const char * a_Data, int a_Size) = 0; } ; - /// The body handler for requests in the "/webadmin" and "/~webadmin" paths + /** The body handler for requests in the "/webadmin" and "/~webadmin" paths */ class cWebadminRequestData : public cRequestData, public cHTTPFormParser::cCallbacks @@ -182,10 +185,13 @@ protected: } ; - /// Set to true if Init() succeeds and the webadmin isn't to be disabled + /** Set to true if Init() succeeds and the webadmin isn't to be disabled */ bool m_IsInitialized; + + /** Set to true if Start() succeeds in starting the server, reset back to false in Stop(). */ + bool m_IsRunning; - /// The webadmin.ini file, used for the settings and allowed logins + /** The webadmin.ini file, used for the settings and allowed logins */ cIniFile m_IniFile; PluginList m_Plugins; @@ -193,19 +199,19 @@ protected: AString m_PortsIPv4; AString m_PortsIPv6; - /// The Lua template script to provide templates: + /** The Lua template script to provide templates: */ cLuaState m_TemplateScript; - /// The HTTP server which provides the underlying HTTP parsing, serialization and events + /** The HTTP server which provides the underlying HTTP parsing, serialization and events */ cHTTPServer m_HTTPServer; AString GetTemplate(void); - /// Handles requests coming to the "/webadmin" or "/~webadmin" URLs + /** Handles requests coming to the "/webadmin" or "/~webadmin" URLs */ void HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request); - /// Handles requests for the root page + /** Handles requests for the root page */ void HandleRootRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request); // cHTTPServer::cCallbacks overrides: -- cgit v1.2.3 From 88a64ec40df87f21a89de43fe8bb78f10ee7eeb7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 7 Feb 2014 18:58:52 +0000 Subject: Improved chat messaging functions * Moved string manipulation into cClientHandle and therefore... + Added configuration option for prefixes. * Cleaned up code. * Updated documentation for API. --- MCServer/Plugins/APIDump/APIDesc.lua | 27 ++++++++- src/ClientHandle.cpp | 114 +++++++++++++++++++++++++++++++++-- src/ClientHandle.h | 2 +- src/Defines.h | 64 +------------------- src/Entities/Player.cpp | 10 --- src/Entities/Player.h | 15 ++--- src/Root.cpp | 4 +- src/Root.h | 19 +++--- src/World.cpp | 11 ++-- src/World.h | 27 ++++++--- 10 files changed, 179 insertions(+), 114 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index cbdb7797b..69e1bdda9 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1644,7 +1644,13 @@ a_Player:OpenWindow(Window); OpenWindow = { Params = "{{cWindow|Window}}", Return = "", Notes = "Opens the specified UI window for the player." }, RemoveFromGroup = { Params = "GroupName", Return = "", Notes = "Temporarily removes the player from the specified group. This change is lost when the player disconnects." }, Respawn = { Params = "", Return = "", Notes = "Restores the health, extinguishes fire, makes visible and sends the Respawn packet." }, - SendMessage = { Params = "MessageString", Return = "", Notes = "Sends the specified message to the player." }, + SendMessage = { Params = "Message", Return = "", Notes = "Sends the specified message to the player." }, + SendMessageFailure = { Params = "Message", Return = "", Notes = "Prepends Rose [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. For a command that failed to run because of insufficient permissions, etc." }, + SendMessageFatal = { Params = "Message", Return = "", Notes = "Prepends Red [FATAL] / colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. For something serious, such as a plugin crash, etc." }, + SendMessageInfo = { Params = "Message", Return = "", Notes = "Prepends Yellow [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. Informational message, such as command usage, etc." }, + SendMessagePrivateMsg = { Params = "Message, SenderName", Return = "", Notes = "Prepends Light Blue [MSG: *SenderName*] / prepends SenderName and colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. For private messaging." }, + SendMessageSuccess = { Params = "Message", Return = "", Notes = "Prepends Green [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. Success notification." }, + SendMessageWarning = { Params = "Message, Sender", Return = "", Notes = "Prepends Rose [WARN] / colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. Denotes that something concerning, such as plugin reload, is about to happen." }, SetCanFly = { Params = "CanFly", Notes = "Sets if the player can fly or not." }, SetCrouch = { Params = "IsCrouched", Return = "", Notes = "Sets the crouch state, broadcasts the change to other players." }, SetCurrentExperience = { Params = "XPAmount", Return = "", Notes = "Sets the current amount of experience (and indirectly, the XP level)." }, @@ -1823,7 +1829,12 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); Functions = { Get = { Params = "", Return = "Root object", Notes = "(STATIC)This function returns the cRoot object." }, - BroadcastChat = { Params = "Message", Return = "", Notes = "Broadcasts a message to every player in the server." }, + BroadcastChat = { Params = "Message", Return = "", Notes = "Broadcasts a message to every player in the server. No formatting is done by the server." }, + BroadcastChatFailure = { Params = "Message", Return = "", Notes = "Prepends Rose [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a command that failed to run because of insufficient permissions, etc." }, + BroadcastChatFatal = { Params = "Message", Return = "", Notes = "Prepends Red [FATAL] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a plugin that crashed, or similar." }, + BroadcastChatInfo = { Params = "Message", Return = "", Notes = "Prepends Yellow [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For informational messages, such as command usage." }, + BroadcastChatSuccess = { Params = "Message", Return = "", Notes = "Prepends Green [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For success messages." }, + BroadcastChatWarning = { Params = "Message", Return = "", Notes = "Prepends Rose [WARN] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For concerning events, such as plugin reload etc." }, FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "", Notes = "Calls the given callback function for the given player." }, ForEachPlayer = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each player. The callback function has the following signature:
function Callback({{cPlayer|cPlayer}})
" }, ForEachWorld = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each world. The callback function has the following signature:
function Callback({{cWorld|cWorld}})
" }, @@ -2014,8 +2025,14 @@ end Functions = { + AreCommandBlocksEnabled = { Params = "", Return = "bool", Notes = "Returns whether command blocks are enabled on the (entire) server" }, BroadcastBlockAction = { Params = "BlockX, BlockY, BlockZ, ActionByte1, ActionByte2, BlockType, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Broadcasts the BlockAction packet to all clients who have the appropriate chunk loaded (except ExcludeClient). The contents of the packet are specified by the parameters for the call, the blocktype needn't match the actual block that is present in the world data at the specified location." }, - BroadcastChat = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the Message to all players in this world, except the optional ExceptClient" }, + BroadcastChat = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the Message to all players in this world, except the optional ExcludeClient. No formatting is done by the server." }, + BroadcastChatFailure = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Rose [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a command that failed to run because of insufficient permissions, etc." }, + BroadcastChatFatal = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Red [FATAL] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a plugin that crashed, or similar." }, + BroadcastChatInfo = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Yellow [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For informational messages, such as command usage." }, + BroadcastChatSuccess = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Green [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For success messages." }, + BroadcastChatWarning = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Rose [WARN] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For concerning events, such as plugin reload etc." }, BroadcastSoundEffect = { Params = "SoundName, X, Y, Z, Volume, Pitch, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the specified sound effect to all players in this world, except the optional ExceptClient" }, BroadcastSoundParticleEffect = { Params = "EffectID, X, Y, Z, EffectData, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the specified effect to all players in this world, except the optional ExceptClient" }, CastThunderbolt = { Params = "X, Y, Z", Return = "", Notes = "Creates a thunderbolt at the specified coords" }, @@ -2111,6 +2128,10 @@ end { Params = "{{Vector3i|BlockCoords}}, BlockMeta", Return = "", Notes = "Sets the meta for the block at the specified coords." }, }, SetNextBlockTick = { Params = "BlockX, BlockY, BlockZ", Return = "", Notes = "Sets the blockticking to start at the specified block in the next tick." }, + SetCommandBlockCommand = { Params = "BlockX, BlockY, BlockZ, Command", Return = "bool", Notes = "Sets the command to be executed in a command block at the specified coordinates. Returns if command was changed." }, + SetCommandBlocksEnabled = { Params = "IsEnabled (bool)", Return = "", Notes = "Sets whether command blocks should be enabled on the (entire) server." }, + SetShouldUseChatPrefixes = { Params = "", Return = "ShouldUse (bool)", Notes = "Sets whether coloured chat prefixes such as [INFO] is used with the SendMessageXXX() or BroadcastChatXXX(), or simply the entire message is coloured in the respective colour." }, + ShouldUseChatPrefixes = { Params = "", Return = "bool", Notes = "Returns whether coloured chat prefixes are prepended to chat messages or the entire message is simply coloured." }, SetSignLines = { Params = "X, Y, Z, Line1, Line2, Line3, Line4, [{{cPlayer|Player}}]", Return = "", Notes = "Sets the sign text at the specified coords. The sign-updating hooks are called for the change. The Player parameter is used to indicate the player from whom the change has come, it may be nil. Same as UpdateSign()." }, SetTicksUntilWeatherChange = { Params = "NumTicks", Return = "", Notes = "Sets the number of ticks after which the weather will be changed." }, SetTimeOfDay = { Params = "TimeOfDayTicks", Return = "", Notes = "Sets the time of day, expressed as number of ticks past sunrise, in the range 0 .. 24000." }, diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index f7c6cb734..911c0795f 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -566,7 +566,7 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a { if (a_Length < 14) { - SendChat(AppendChatEpithet("Failure setting command block command; bad request", mtFailure)); + SendChat("Failure setting command block command; bad request", mtFailure); LOGD("Malformed MC|AdvCdm packet."); return; } @@ -596,7 +596,7 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a default: { - SendChat(AppendChatEpithet("Failure setting command block command; unhandled mode", mtFailure)); + SendChat("Failure setting command block command; unhandled mode", mtFailure); LOGD("Unhandled MC|AdvCdm packet mode."); return; } @@ -608,11 +608,11 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a { World->SetCommandBlockCommand(BlockX, BlockY, BlockZ, Command); - SendChat(AppendChatEpithet("Successfully set command block command", mtSuccess)); + SendChat("Successfully set command block command", mtSuccess); } else { - SendChat(AppendChatEpithet("Command blocks are not enabled on this server", mtFailure)); + SendChat("Command blocks are not enabled on this server", mtFailure); } } @@ -1729,9 +1729,111 @@ void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlock -void cClientHandle::SendChat(const AString & a_Message) +void cClientHandle::SendChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const AString & a_AdditionalData) { - m_Protocol->SendChat(a_Message); + bool ShouldAppendChatPrefixes = true; + + if (GetPlayer()->GetWorld() == NULL) + { + cWorld * World = cRoot::Get()->GetWorld(GetPlayer()->GetLoadedWorldName()); + if (World == NULL) + { + World = cRoot::Get()->GetDefaultWorld(); + } + + if (!World->ShouldUseChatPrefixes()) + { + ShouldAppendChatPrefixes = false; + } + } + else if (!GetPlayer()->GetWorld()->ShouldUseChatPrefixes()) + { + ShouldAppendChatPrefixes = false; + } + + AString Message; + + switch (a_ChatPrefix) + { + case mtCustom: break; + case mtFailure: + { + if (ShouldAppendChatPrefixes) + Message = Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); + else + Message = Printf("%s", cChatColor::Rose.c_str()); + break; + } + case mtInformation: + { + if (ShouldAppendChatPrefixes) + Message = Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + Message = Printf("%s", cChatColor::Yellow.c_str()); + break; + } + case mtSuccess: + { + if (ShouldAppendChatPrefixes) + Message = Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str()); + else + Message = Printf("%s", cChatColor::Green.c_str()); + break; + } + case mtWarning: + { + if (ShouldAppendChatPrefixes) + Message = Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); + else + Message = Printf("%s", cChatColor::Rose.c_str()); + break; + } + case mtFatal: + { + if (ShouldAppendChatPrefixes) + Message = Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str()); + else + Message = Printf("%s", cChatColor::Red.c_str()); + break; + } + case mtDeath: + { + if (ShouldAppendChatPrefixes) + Message = Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str()); + else + Message = Printf("%s", cChatColor::Gray.c_str()); + break; + } + case mtPrivateMessage: + { + if (ShouldAppendChatPrefixes) + Message = Printf("%s[MSG: %s] %s%s", cChatColor::LightBlue.c_str(), a_AdditionalData.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()); + else + Message = Printf("%s", cChatColor::LightBlue.c_str()); + break; + } + case mtJoin: + { + if (ShouldAppendChatPrefixes) + Message = Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + Message = Printf("%s", cChatColor::Yellow.c_str()); + break; + } + case mtLeave: + { + if (ShouldAppendChatPrefixes) + Message = Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + Message = Printf("%s", cChatColor::Yellow.c_str()); + break; + } + default: ASSERT(!"Unhandled chat prefix type!"); return; + } + + Message.append(a_Message); + + m_Protocol->SendChat(Message); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 29a56f5a7..c35289340 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -89,7 +89,7 @@ public: void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage); void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // tolua_export void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes); - void SendChat (const AString & a_Message); + void SendChat (const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const AString & a_AdditionalData = ""); void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer); void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player); void SendDestroyEntity (const cEntity & a_Entity); diff --git a/src/Defines.h b/src/Defines.h index 7fe93399d..177acefdf 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -448,6 +448,7 @@ enum ChatPrefixCodes // http://forum.mc-server.org/showthread.php?tid=1212 // MessageType... + mtCustom, // Send raw data without any processing mtFailure, // Something could not be done (i.e. command not executed due to insufficient privilege) mtInformation, // Informational message (i.e. command usage) mtSuccess, // Something executed successfully @@ -459,70 +460,9 @@ enum ChatPrefixCodes mtLeave, // A player has left the server }; - - - -inline AString AppendChatEpithet(const AString & a_ChatMessage, ChatPrefixCodes a_ChatPrefix) -{ - AString Message; - - switch (a_ChatPrefix) - { - case mtFailure: - { - Message = Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); - break; - } - case mtInformation: - { - Message = Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - break; - } - case mtSuccess: - { - Message = Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str()); - break; - } - case mtWarning: - { - Message = Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); - break; - } - case mtFatal: - { - Message = Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str()); - break; - } - case mtDeath: - { - Message = Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str()); - break; - } - case mtPrivateMessage: - { - Message = Printf("%s[MSG] %s%s", cChatColor::LightBlue.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()); - break; - } - case mtJoin: - { - Message = Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - break; - } - case mtLeave: - { - Message = Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - break; - } - default: ASSERT(!"Unhandled chat prefix type!"); return ""; - } - - Message.append(a_ChatMessage); - return Message; -} - // tolua_begin -/// Normalizes an angle in degrees to the [-180, +180) range: +/** Normalizes an angle in degrees to the [-180, +180) range: */ inline double NormalizeAngleDegrees(const double a_Degrees) { double Norm = fmod(a_Degrees + 180, 360); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 385e28c28..eef6b8e69 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -3,7 +3,6 @@ #include "Player.h" #include "../Server.h" -#include "../ClientHandle.h" #include "../UI/Window.h" #include "../UI/WindowOwner.h" #include "../World.h" @@ -1121,15 +1120,6 @@ void cPlayer::SetIP(const AString & a_IP) -void cPlayer::SendMessage(const AString & a_Message) -{ - m_ClientHandle->SendChat(a_Message); -} - - - - - void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) { SetPosition( a_PosX, a_PosY, a_PosZ ); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index f2830a0c7..869e67775 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -5,6 +5,7 @@ #include "../Inventory.h" #include "../Defines.h" #include "../World.h" +#include "../ClientHandle.h" @@ -195,13 +196,13 @@ public: cClientHandle * GetClientHandle(void) const { return m_ClientHandle; } - void SendMessage(const AString & a_Message); - void SendMessageInfo(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtInformation)); } - void SendMessageFailure(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtFailure)); } - void SendMessageSuccess(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtSuccess)); } - void SendMessageWarning(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtWarning)); } - void SendMessageFatal(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtFailure)); } - void SendMessagePrivateMsg(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtPrivateMessage)); } + void SendMessage (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtCustom); } + void SendMessageInfo (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtInformation); } + void SendMessageFailure (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtFailure); } + void SendMessageSuccess (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtSuccess); } + void SendMessageWarning (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtWarning); } + void SendMessageFatal (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtFailure); } + void SendMessagePrivateMsg(const AString & a_Message, const AString & a_Sender) { m_ClientHandle->SendChat(a_Message, mtPrivateMessage, a_Sender); } const AString & GetName(void) const { return m_PlayerName; } void SetName(const AString & a_Name) { m_PlayerName = a_Name; } diff --git a/src/Root.cpp b/src/Root.cpp index 883bfe76e..3e1898c42 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -536,11 +536,11 @@ void cRoot::SaveAllChunks(void) -void cRoot::BroadcastChat(const AString & a_Message) +void cRoot::LoopWorldsAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix) { for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr) { - itr->second->BroadcastChat(a_Message); + itr->second->LoopPlayersAndBroadcastChat(a_Message, a_ChatPrefix); } // for itr - m_WorldsByName[] } diff --git a/src/Root.h b/src/Root.h index ba106b54e..4cb77a79d 100644 --- a/src/Root.h +++ b/src/Root.h @@ -105,19 +105,20 @@ public: /// Finds a player from a partial or complete player name and calls the callback - case-insensitive bool FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << - void BroadcastChatJoin(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtJoin)); } - void BroadcastChatLeave(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtLeave)); } + void LoopWorldsAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix); + void BroadcastChatJoin (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtJoin); } + void BroadcastChatLeave (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtLeave); } + void BroadcastChatDeath (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtDeath); } // tolua_begin /// Sends a chat message to all connected clients (in all worlds) - void BroadcastChat(const AString & a_Message); - void BroadcastChatInfo(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtInformation)); } - void BroadcastChatFailure(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); } - void BroadcastChatSuccess(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtSuccess)); } - void BroadcastChatWarning(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtWarning)); } - void BroadcastChatFatal(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); } - void BroadcastChatDeath(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtDeath)); } + void BroadcastChat (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtCustom); } + void BroadcastChatInfo (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtInformation); } + void BroadcastChatFailure(const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtFailure); } + void BroadcastChatSuccess(const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtSuccess); } + void BroadcastChatWarning(const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtWarning); } + void BroadcastChatFatal (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtFailure); } /// Returns the textual description of the protocol version: 49 -> "1.4.4". Provided specifically for Lua API static AString GetProtocolVersionTextFromInt(int a_ProtocolVersionNum); diff --git a/src/World.cpp b/src/World.cpp index de2002b84..e5c9f4398 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -249,7 +249,9 @@ cWorld::cWorld(const AString & a_WorldName) : m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :) m_GeneratorCallbacks(*this), m_TickThread(*this), - m_Scoreboard(this) + m_Scoreboard(this), + m_bCommandBlocksEnabled(false), + m_bUseChatPrefixes(true) { LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str()); @@ -543,9 +545,10 @@ void cWorld::Start(void) m_IsSaplingBonemealable = IniFile.GetValueSetB("Plants", "IsSaplingBonemealable", true); m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false); m_bEnabledPVP = IniFile.GetValueSetB("PVP", "Enabled", true); - m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", false); + m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true); m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true); m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false); + m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true); m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true); m_GameMode = (eGameMode)IniFile.GetValueSetI("GameMode", "GameMode", m_GameMode); @@ -1744,7 +1747,7 @@ void cWorld::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cons -void cWorld::BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude) +void cWorld::LoopPlayersAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) @@ -1754,7 +1757,7 @@ void cWorld::BroadcastChat(const AString & a_Message, const cClientHandle * a_Ex { continue; } - ch->SendChat(a_Message); + ch->SendChat(a_Message, a_ChatPrefix); } } diff --git a/src/World.h b/src/World.h index 01481c049..0527abbff 100644 --- a/src/World.h +++ b/src/World.h @@ -158,14 +158,16 @@ public: void BroadcastBlockBreakAnimation(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = NULL); void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); ///< If there is a block entity at the specified coods, sends it to all clients except a_Exclude - // tolua_start - void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL); - void BroadcastChatInfo(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtInformation)); } - void BroadcastChatFailure(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); } - void BroadcastChatSuccess(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtSuccess)); } - void BroadcastChatWarning(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtWarning)); } - void BroadcastChatFatal(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); } - void BroadcastChatDeath(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtDeath)); } + void LoopPlayersAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const cClientHandle * a_Exclude = NULL); + void BroadcastChatDeath (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtDeath, a_Exclude); } + + // tolua_begin + void BroadcastChat (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtCustom, a_Exclude); } + void BroadcastChatInfo (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtInformation, a_Exclude); } + void BroadcastChatFailure(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtFailure, a_Exclude); } + void BroadcastChatSuccess(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtSuccess, a_Exclude); } + void BroadcastChatWarning(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtWarning, a_Exclude); } + void BroadcastChatFatal (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtFailure, a_Exclude); } // tolua_end void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); @@ -544,12 +546,14 @@ public: /** Returns the name of the world.ini file used by this world */ const AString & GetIniFileName(void) const {return m_IniFileName; } - /// Returns the associated scoreboard instance + /** Returns the associated scoreboard instance */ cScoreboard & GetScoreBoard(void) { return m_Scoreboard; } bool AreCommandBlocksEnabled(void) const { return m_bCommandBlocksEnabled; } - void SetCommandBlocksEnabled(bool a_Flag) { m_bCommandBlocksEnabled = a_Flag; } + + bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; } + void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; } // tolua_end @@ -800,7 +804,10 @@ private: bool m_IsSaplingBonemealable; bool m_IsSugarcaneBonemealable; + /** Whether command blocks are enabled or not */ bool m_bCommandBlocksEnabled; + /** Whether prefixes such as [INFO] are prepended to SendMessageXXX() / BroadcastChatXXX() functions */ + bool m_bUseChatPrefixes; cChunkGenerator m_Generator; -- cgit v1.2.3 From 0a5c14bf68439d450bc94ec9da63f4e424a75d95 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 7 Feb 2014 19:56:22 +0000 Subject: Removed some unexported documentation. --- MCServer/Plugins/APIDump/APIDesc.lua | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 69e1bdda9..2f0feac7f 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -693,7 +693,6 @@ end GetRawDamageAgainst = { Params = "ReceiverEntity", Return = "number", Notes = "Returns the raw damage that this entity's equipment would cause when attacking the ReceiverEntity. This includes this entity's weapon {{cEnchantments|enchantments}}, but excludes the receiver's armor or potion effects. See {{TakeDamageInfo}} for more information on attack damage." }, GetRoll = { Params = "", Return = "number", Notes = "Returns the roll (sideways rotation) of the entity. Currently unused." }, GetRot = { Params = "", Return = "{{Vector3f}}", Notes = "Returns the entire rotation vector (Yaw, Pitch, Roll)" }, - GetRotation = { Params = "", Return = "number", Notes = "Returns the yaw (direction) of the entity. OBSOLETE, use GetYaw() instead." }, GetSpeed = { Params = "", Return = "{{Vector3d}}", Notes = "Returns the complete speed vector of the entity" }, GetSpeedX = { Params = "", Return = "number", Notes = "Returns the X-part of the speed vector" }, GetSpeedY = { Params = "", Return = "number", Notes = "Returns the Y-part of the speed vector" }, @@ -720,8 +719,11 @@ end IsRclking = { Params = "", Return = "bool", Notes = "Currently unimplemented" }, IsRiding = { Params = "", Return = "bool", Notes = "Returns true if the entity is attached to (riding) another entity." }, IsSprinting = { Params = "", Return = "bool", Notes = "Returns true if the entity is sprinting. Entities that cannot sprint return always false" }, + IsSubmerged = { Params = "", Return = "bool", Notes = "Returns true if the mob or player is submerged in water (head is in a water block). Note, this function is only updated with mobs or players." }, + IsSwimming = { Params = "", Return = "bool", Notes = "Returns true if the mob or player is swimming in water (feet are in a water block). Note, this function is only updated with mobs or players." }, IsTNT = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a {{cTNTEntity|TNT entity}}" }, KilledBy = { Notes = "FIXME: Remove this from API" }, + GetAirLevel = { Params = "", Return = "number", Notes = "Returns the air level (number of ticks of air left). Note, this function is only updated with mobs or players." }, SetGravity = { Params = "Gravity", Return = "", Notes = "Sets the number that is used as the gravity for physics simulation. 1G (9.78) by default." }, SetHeadYaw = { Params = "HeadPitch", Return = "", Notes = "Sets the head pitch (FIXME: Rename to SetHeadPitch() )." }, SetHealth = { Params = "Hitpoints", Return = "", Notes = "Sets the entity's health to the specified amount of hitpoints. Doesn't broadcast any hurt animation. Doesn't kill the entity if health drops below zero. Use the TakeDamage() function instead for taking damage." }, @@ -740,8 +742,7 @@ end SetPosZ = { Params = "number", Return = "", Notes = "Sets the Z-coord of the entity's pivot" }, SetRoll = { Params = "number", Return = "", Notes = "Sets the roll (sideways rotation) of the entity. Currently unused." }, SetRot = { Params = "{{Vector3f|Rotation}}", Return = "", Notes = "Sets the entire rotation vector (Yaw, Pitch, Roll)" }, - SetRotation = { Params = "number", Return = "", Notes = "Sets the yaw (direction) of the entity. OBSOLETE, use SetYaw() instead." }, - SetRotationFromSpeed = { Params = "", Return = "", Notes = "Sets the entity's yaw to match its current speed (entity looking forwards as it moves). (FIXME: Rename to SetYawFromSpeed)" }, + SetYawFromSpeed = { Params = "", Return = "", Notes = "Sets the entity's yaw to match its current speed (entity looking forwards as it moves). (FIXME: Rename to SetYawFromSpeed)" }, SetSpeed = { { Params = "SpeedX, SpeedY, SpeedZ", Return = "", Notes = "Sets the current speed of the entity" }, @@ -1103,10 +1104,9 @@ These ItemGrids are available in the API and can be manipulated by the plugins, GetMaxStackSize = { Params = "", Return = "number", Notes = "Returns the maximum stack size for this item." }, IsDamageable = { Params = "", Return = "bool", Notes = "Returns true if this item does account for its damage" }, IsEmpty = { Params = "", Return = "bool", Notes = "Returns true if this object represents an empty item (zero count or invalid ID)" }, - IsEqual = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is the same as the one stored in the object (type, damage and enchantments)" }, + IsEqual = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is the same as the one stored in the object (type, damage, lore, name and enchantments)" }, IsFullStack = { Params = "", Return = "bool", Notes = "Returns true if the item is stacked up to its maximum stacking" }, IsSameType = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is of the same ItemType as the one stored in the object. This is true even if the two items have different enchantments" }, - IsStackableWith = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is stackable with the one stored in the object. Two items with different enchantments cannot be stacked" }, }, Variables = { @@ -1564,7 +1564,6 @@ a_Player:OpenWindow(Window); ]], Functions = { - constructor = { Params = "PosX, PosY, PosZ, {{cItem|Item}}, IsPlayerCreated, [SpeedX, SpeedY, SpeedZ]", Return = "cPickup", Notes = "Creates a new pickup at the specified coords. If IsPlayerCreated is true, the pickup has a longer initial collection interval." }, CollectedBy = { Params = "{{cPlayer}}", Return = "bool", Notes = "Tries to make the player collect the pickup. Returns true if the pickup was collected, at least partially." }, GetAge = { Params = "", Return = "number", Notes = "Returns the number of ticks that the pickup has existed." }, GetItem = { Params = "", Return = "{{cItem|cItem}}", Notes = "Returns the item represented by this pickup" }, @@ -1594,7 +1593,6 @@ a_Player:OpenWindow(Window); Feed = { Params = "AddFood, AddSaturation", Return = "bool", Notes = "Tries to add the specified amounts to food level and food saturation level (only positive amounts expected). Returns true if player was hungry and the food was consumed, false if too satiated." }, FoodPoison = { Params = "NumTicks", Return = "", Notes = "Starts the food poisoning for the specified amount of ticks; if already foodpoisoned, sets FoodPoisonedTicksRemaining to the larger of the two" }, ForceSetSpeed = { Params = "{{Vector3d|Direction}}", Notes = "Forces the player to move to the given direction." }, - GetAirLevel = { Params = "", Return = "number", Notes = "Returns the air level (number of ticks of air left)." }, GetClientHandle = { Params = "", Return = "{{cClientHandle}}", Notes = "Returns the client handle representing the player's connection. May be nil (AI players)." }, GetColor = { Return = "string", Notes = "Returns the full color code to be used for this player (based on the first group). Prefix player messages with this code." }, GetCurrentXp = { Params = "", Return = "number", Notes = "Returns the current amount of XP" }, @@ -1635,8 +1633,6 @@ a_Player:OpenWindow(Window); IsInGroup = { Params = "GroupNameString", Return = "bool", Notes = "Returns true if the player is a member of the specified group." }, IsOnGround = { Params = "", Return = "bool", Notes = "Returns true if the player is on ground (not falling, not jumping, not flying)" }, IsSatiated = { Params = "", Return = "bool", Notes = "Returns true if the player is satiated (cannot eat)." }, - IsSubmerged = { Params = "", Return = "bool", Notes = "Returns true if the player is submerged in water (the player's head is in a water block)" }, - IsSwimming = { Params = "", Return = "bool", Notes = "Returns true if the player is swimming in water (the player's feet are in a water block)" }, IsVisible = { Params = "", Return = "bool", Notes = "Returns true if the player is visible to other players" }, LoadPermissionsFromDisk = { Params = "", Return = "", Notes = "Reloads the player's permissions from the disk. This loses any temporary changes made to the player's groups." }, MoveTo = { Params = "{{Vector3d|NewPosition}}", Return = "Tries to move the player into the specified position." }, @@ -1672,9 +1668,7 @@ a_Player:OpenWindow(Window); }, Constants = { - DROWNING_TICKS = { Notes = "Number of ticks per heart of damage when drowning (zero AirLevel)" }, EATING_TICKS = { Notes = "Number of ticks required for consuming an item." }, - MAX_AIR_LEVEL = { Notes = "The maximum air level value. AirLevel gets reset to this value when the player exits water." }, MAX_FOOD_LEVEL = { Notes = "The maximum food level value. When the food level is at this value, the player cannot eat." }, MAX_HEALTH = { Notes = "The maximum health value" }, }, -- cgit v1.2.3 From 0f36d1c122c78757c9106eb6afa5e3897a87e5fb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 7 Feb 2014 20:10:12 +0000 Subject: Added sender name to PM if prefixes disabled * Also moved the PVP setting into Mechanics --- src/ClientHandle.cpp | 2 +- src/World.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 911c0795f..15b614999 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1809,7 +1809,7 @@ void cClientHandle::SendChat(const AString & a_Message, ChatPrefixCodes a_ChatPr if (ShouldAppendChatPrefixes) Message = Printf("%s[MSG: %s] %s%s", cChatColor::LightBlue.c_str(), a_AdditionalData.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()); else - Message = Printf("%s", cChatColor::LightBlue.c_str()); + Message = Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue.c_str()); break; } case mtJoin: diff --git a/src/World.cpp b/src/World.cpp index e5c9f4398..bb6f5f29a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -544,10 +544,10 @@ void cWorld::Start(void) m_IsPumpkinBonemealable = IniFile.GetValueSetB("Plants", "IsPumpkinBonemealable", false); m_IsSaplingBonemealable = IniFile.GetValueSetB("Plants", "IsSaplingBonemealable", true); m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false); - m_bEnabledPVP = IniFile.GetValueSetB("PVP", "Enabled", true); m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true); m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true); m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false); + m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true); m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true); m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true); -- cgit v1.2.3 From fadf3c037ba02e18264dabbad5f1016fa53a995d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 7 Feb 2014 20:11:56 +0000 Subject: Moved Gamemode setting into General root tag --- src/World.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/World.cpp b/src/World.cpp index bb6f5f29a..ab77fa545 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -551,7 +551,7 @@ void cWorld::Start(void) m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true); m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true); - m_GameMode = (eGameMode)IniFile.GetValueSetI("GameMode", "GameMode", m_GameMode); + m_GameMode = (eGameMode)IniFile.GetValueSetI("General", "Gamemode", m_GameMode); // Load allowed mobs: const char * DefaultMonsters = ""; -- cgit v1.2.3 From 176664810b43a839d92418b2558359e61b700935 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Fri, 7 Feb 2014 22:13:55 +0100 Subject: Implemented an easy way of adding new redstone simulators. Also added a "noop" redstone simulator that does the same as the fluid version. --- src/Simulator/NoopRedstoneSimulator.h | 40 +++++++++++++++++++++++++++++++++++ src/Simulator/RedstoneManager.cpp | 19 +++++++++++++++++ src/Simulator/RedstoneManager.h | 17 +++++++++++++++ src/Simulator/RedstoneSimulator.h | 6 +++--- src/World.cpp | 40 ++++++++++++++++++++++++++++++++--- src/World.h | 9 +++++--- 6 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 src/Simulator/NoopRedstoneSimulator.h create mode 100644 src/Simulator/RedstoneManager.cpp create mode 100644 src/Simulator/RedstoneManager.h diff --git a/src/Simulator/NoopRedstoneSimulator.h b/src/Simulator/NoopRedstoneSimulator.h new file mode 100644 index 000000000..4dd473c64 --- /dev/null +++ b/src/Simulator/NoopRedstoneSimulator.h @@ -0,0 +1,40 @@ + +#pragma once + +#include "RedstoneManager.h" + + + + + +class cRedstoneNoopSimulator : + public cRedstoneManager +{ + typedef cRedstoneManager super; +public: + + cRedstoneNoopSimulator(cWorld & a_World) : + super(a_World) + { + } + + //~cRedstoneNoopSimulator(); + + virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} // not used + virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override + { + UNUSED(a_Dt); + UNUSED(a_ChunkX); + UNUSED(a_ChunkZ); + UNUSED(a_Chunk); + } + virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override { return false; } + virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override + { + UNUSED(a_BlockX); + UNUSED(a_BlockY); + UNUSED(a_BlockZ); + UNUSED(a_Chunk); + } + +} ; \ No newline at end of file diff --git a/src/Simulator/RedstoneManager.cpp b/src/Simulator/RedstoneManager.cpp new file mode 100644 index 000000000..58fb8fa4c --- /dev/null +++ b/src/Simulator/RedstoneManager.cpp @@ -0,0 +1,19 @@ + +#include "Globals.h" + +#include "RedstoneManager.h" +#include "../World.h" + + + + + +cRedstoneManager::cRedstoneManager(cWorld & a_World) : + super(a_World) +{ +} + + + + + diff --git a/src/Simulator/RedstoneManager.h b/src/Simulator/RedstoneManager.h new file mode 100644 index 000000000..846b7d8ab --- /dev/null +++ b/src/Simulator/RedstoneManager.h @@ -0,0 +1,17 @@ + +#pragma once + +#include "Simulator.h" + + + + +class cRedstoneManager : + public cSimulator +{ + typedef cSimulator super; + +public: + cRedstoneManager(cWorld & a_World); + +} ; \ No newline at end of file diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index c505b2a0f..c5ab1b9bb 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -1,7 +1,7 @@ #pragma once -#include "Simulator.h" +#include "RedstoneManager.h" /// Per-chunk data for the simulator, specified individual chunks to simulate; 'Data' is not used typedef cCoordWithBlockAndBoolVector cRedstoneSimulatorChunkData; @@ -11,9 +11,9 @@ typedef cCoordWithBlockAndBoolVector cRedstoneSimulatorChunkData; class cRedstoneSimulator : - public cSimulator + public cRedstoneManager { - typedef cSimulator super; + typedef cRedstoneManager super; public: cRedstoneSimulator(cWorld & a_World); diff --git a/src/World.cpp b/src/World.cpp index 5e08fd599..1343d5ad6 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -29,6 +29,7 @@ #include "Simulator/FluidSimulator.h" #include "Simulator/FireSimulator.h" #include "Simulator/NoopFluidSimulator.h" +#include "Simulator/NoopRedstoneSimulator.h" #include "Simulator/SandSimulator.h" #include "Simulator/RedstoneSimulator.h" #include "Simulator/VaporizeFluidSimulator.h" @@ -596,12 +597,11 @@ void cWorld::Start(void) m_LavaSimulator = InitializeFluidSimulator(IniFile, "Lava", E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA); m_SandSimulator = new cSandSimulator(*this, IniFile); m_FireSimulator = new cFireSimulator(*this, IniFile); - m_RedstoneSimulator = new cRedstoneSimulator(*this); + m_RedstoneSimulator = InitializeRedstoneSimulator(IniFile); - // Water and Lava simulators get registered in InitializeFluidSimulator() + // Water, Lava and Redstone simulators get registered in InitializeFluidSimulator() m_SimulatorManager->RegisterSimulator(m_SandSimulator, 1); m_SimulatorManager->RegisterSimulator(m_FireSimulator, 1); - m_SimulatorManager->RegisterSimulator(m_RedstoneSimulator, 1); m_Lighting.Start(this); m_Storage.Start(this, m_StorageSchema, m_StorageCompressionFactor ); @@ -2871,6 +2871,40 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul +cRedstoneManager * cWorld::InitializeRedstoneSimulator(cIniFile & a_IniFile) +{ + AString SimulatorName = a_IniFile.GetValueSet("Physics", "RedstoneSimulator", ""); + + if (SimulatorName.empty()) + { + LOGWARNING("[Physics] RedstoneSimulator not present or empty in %s, using the default of \"Floody\".", GetIniFileName().c_str()); + SimulatorName = "redstone"; + } + + cRedstoneManager * res = NULL; + + if ( + (NoCaseCompare(SimulatorName, "redstone") == 0) + ) + { + res = new cRedstoneSimulator(*this); + } + else if ( + (NoCaseCompare(SimulatorName, "noop") == 0) + ) + { + res = new cRedstoneNoopSimulator(*this); + } + + m_SimulatorManager->RegisterSimulator(res, 1); + + return res; +} + + + + + cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock) { AString SimulatorNameKey; diff --git a/src/World.h b/src/World.h index 8cf860ff5..bc4e411cc 100644 --- a/src/World.h +++ b/src/World.h @@ -33,7 +33,7 @@ class cFireSimulator; class cFluidSimulator; class cSandSimulator; -class cRedstoneSimulator; +class cRedstoneManager; class cItem; class cPlayer; class cClientHandle; @@ -432,7 +432,7 @@ public: inline cFluidSimulator * GetWaterSimulator(void) { return m_WaterSimulator; } inline cFluidSimulator * GetLavaSimulator (void) { return m_LavaSimulator; } - inline cRedstoneSimulator * GetRedstoneSimulator(void) { return m_RedstoneSimulator; } + inline cRedstoneManager * GetRedstoneSimulator(void) { return m_RedstoneSimulator; } /** Calls the callback for each block entity in the specified chunk; returns true if all block entities processed, false if the callback aborted by returning true */ bool ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback & a_Callback); // Exported in ManualBindings.cpp @@ -759,7 +759,7 @@ private: cFluidSimulator * m_WaterSimulator; cFluidSimulator * m_LavaSimulator; cFireSimulator * m_FireSimulator; - cRedstoneSimulator * m_RedstoneSimulator; + cRedstoneManager * m_RedstoneSimulator; cCriticalSection m_CSPlayers; cPlayerList m_Players; @@ -858,6 +858,9 @@ private: /** Creates a new fluid simulator, loads its settings from the inifile (a_FluidName section) */ cFluidSimulator * InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock); + + /** Creates a new redstone simulator.*/ + cRedstoneManager * InitializeRedstoneSimulator(cIniFile & a_IniFile); }; // tolua_export -- cgit v1.2.3 From 09a23fa11473d0cad74985d8cd8ecdcddef46b45 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Fri, 7 Feb 2014 22:25:15 +0100 Subject: Fixed some end of lines --- src/Simulator/NoopRedstoneSimulator.h | 2 +- src/Simulator/RedstoneManager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Simulator/NoopRedstoneSimulator.h b/src/Simulator/NoopRedstoneSimulator.h index 4dd473c64..d2e00d039 100644 --- a/src/Simulator/NoopRedstoneSimulator.h +++ b/src/Simulator/NoopRedstoneSimulator.h @@ -37,4 +37,4 @@ public: UNUSED(a_Chunk); } -} ; \ No newline at end of file +} ; diff --git a/src/Simulator/RedstoneManager.h b/src/Simulator/RedstoneManager.h index 846b7d8ab..18cfb0c1a 100644 --- a/src/Simulator/RedstoneManager.h +++ b/src/Simulator/RedstoneManager.h @@ -14,4 +14,4 @@ class cRedstoneManager : public: cRedstoneManager(cWorld & a_World); -} ; \ No newline at end of file +} ; -- cgit v1.2.3 From 3a897844a0796ce91e51e0154acbbce2d8e807e5 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Fri, 7 Feb 2014 22:59:08 +0100 Subject: Renamed cRedstoneManager to cRedstoneSimulator and renamed cRedstoneSimulator to cIncrementalRedstoneSimulator (Might change later). --- src/Chunk.h | 2 +- src/Simulator/IncrementalRedstoneSimulator.cpp | 1534 ++++++++++++++++++++++++ src/Simulator/IncrementalRedstoneSimulator.h | 263 ++++ src/Simulator/NoopRedstoneSimulator.h | 6 +- src/Simulator/RedstoneManager.cpp | 19 - src/Simulator/RedstoneManager.h | 17 - src/Simulator/RedstoneSimulator.cpp | 1523 +---------------------- src/Simulator/RedstoneSimulator.h | 256 +--- src/World.cpp | 20 +- src/World.h | 8 +- 10 files changed, 1822 insertions(+), 1826 deletions(-) create mode 100644 src/Simulator/IncrementalRedstoneSimulator.cpp create mode 100644 src/Simulator/IncrementalRedstoneSimulator.h delete mode 100644 src/Simulator/RedstoneManager.cpp delete mode 100644 src/Simulator/RedstoneManager.h diff --git a/src/Chunk.h b/src/Chunk.h index 83d69d12c..3dc83b157 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -6,7 +6,7 @@ #include "Simulator/FireSimulator.h" #include "Simulator/SandSimulator.h" -#include "Simulator/RedstoneSimulator.h" +#include "Simulator/IncrementalRedstoneSimulator.h" diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp new file mode 100644 index 000000000..5dba69455 --- /dev/null +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -0,0 +1,1534 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "IncrementalRedstoneSimulator.h" +#include "../BlockEntities/DropSpenserEntity.h" +#include "../BlockEntities/NoteEntity.h" +#include "../BlockEntities/CommandBlockEntity.h" +#include "../Entities/TNTEntity.h" +#include "../Blocks/BlockTorch.h" +#include "../Blocks/BlockDoor.h" +#include "../Piston.h" + + + + + +cIncrementalRedstoneSimulator::cIncrementalRedstoneSimulator(cWorld & a_World) + : super(a_World) +{ +} + + + + + +cIncrementalRedstoneSimulator::~cIncrementalRedstoneSimulator() +{ +} + + + + + +void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) +{ + if ((a_Chunk == NULL) || !a_Chunk->IsValid()) + { + return; + } + else if ((a_BlockY < 0) || (a_BlockY > cChunkDef::Height)) + { + return; + } + + int RelX = a_BlockX - a_Chunk->GetPosX() * cChunkDef::Width; + int RelZ = a_BlockZ - a_Chunk->GetPosZ() * cChunkDef::Width; + + BLOCKTYPE Block; + NIBBLETYPE Meta; + a_Chunk->GetBlockTypeMeta(RelX, a_BlockY, RelZ, Block, Meta); + + // Every time a block is changed (AddBlock called), we want to go through all lists and check to see if the coordiantes stored within are still valid + // Checking only when a block is changed, as opposed to every tick, also improves performance + + for (PoweredBlocksList::iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) + { + if (!itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + continue; + } + + if (!IsPotentialSource(Block)) + { + LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list as it no longer connected to a source", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); + m_PoweredBlocks.erase(itr); + break; + } + else if ( + // Changeable sources + ((Block == E_BLOCK_REDSTONE_WIRE) && (Meta == 0)) || + ((Block == E_BLOCK_LEVER) && !IsLeverOn(Meta)) || + ((Block == E_BLOCK_DETECTOR_RAIL) && (Meta & 0x08) == 0) || + (((Block == E_BLOCK_STONE_BUTTON) || (Block == E_BLOCK_WOODEN_BUTTON)) && (!IsButtonOn(Meta))) || + (((Block == E_BLOCK_STONE_PRESSURE_PLATE) || (Block == E_BLOCK_WOODEN_PRESSURE_PLATE)) && (Meta == 0)) + ) + { + LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); + m_PoweredBlocks.erase(itr); + break; + } + else if (Block == E_BLOCK_DAYLIGHT_SENSOR) + { + if (!a_Chunk->IsLightValid()) + { + m_World.QueueLightChunk(a_Chunk->GetPosX(), a_Chunk->GetPosZ()); + break; + } + else + { + NIBBLETYPE SkyLight; + a_Chunk->UnboundedRelGetBlockSkyLight(RelX, itr->a_SourcePos.y + 1, RelZ, SkyLight); + + if (a_Chunk->GetTimeAlteredLight(SkyLight) <= 8) // Could use SkyLight - m_World.GetSkyDarkness(); + { + LOGD("cIncrementalRedstoneSimulator: Erased daylight sensor from powered blocks list due to insufficient light level"); + m_PoweredBlocks.erase(itr); + break; + } + } + } + } + + for (LinkedBlocksList::iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) + { + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + if (!IsPotentialSource(Block)) + { + LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list as it is no longer connected to a source", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); + m_LinkedPoweredBlocks.erase(itr); + break; + } + else if ( + // Things that can send power through a block but which depends on meta + ((Block == E_BLOCK_REDSTONE_WIRE) && (Meta == 0)) || + ((Block == E_BLOCK_LEVER) && !IsLeverOn(Meta)) || + (((Block == E_BLOCK_STONE_BUTTON) || (Block == E_BLOCK_WOODEN_BUTTON)) && (!IsButtonOn(Meta))) + ) + { + LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); + m_LinkedPoweredBlocks.erase(itr); + break; + } + } + else if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + if (!IsViableMiddleBlock(Block)) + { + LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list as it is no longer powered through a valid middle block", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); + m_LinkedPoweredBlocks.erase(itr); + break; + } + } + } + + for (SimulatedPlayerToggleableList::iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + continue; + } + + if (!IsAllowedBlock(Block)) + { + LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from toggleable simulated list as it is no longer redstone", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); + m_SimulatedPlayerToggleableBlocks.erase(itr); + break; + } + } + + for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + continue; + } + + if ((Block != E_BLOCK_REDSTONE_REPEATER_ON) && (Block != E_BLOCK_REDSTONE_REPEATER_OFF)) + { + m_RepeatersDelayList.erase(itr); + break; + } + } + + cRedstoneSimulatorChunkData & ChunkData = a_Chunk->GetRedstoneSimulatorData(); + for (cRedstoneSimulatorChunkData::iterator itr = ChunkData.begin(); itr != ChunkData.end(); ++itr) + { + if ((itr->x == RelX) && (itr->y == a_BlockY) && (itr->z == RelZ)) // We are at an entry matching the current (changed) block + { + if (!IsAllowedBlock(Block)) + { + itr->DataTwo = true; // The new blocktype is not redstone; it must be queued to be removed from this list + } + else + { + itr->Data = Block; // Update block information + } + return; + } + } + + if (!IsAllowedBlock(Block)) + { + return; + } + + ChunkData.push_back(cCoordWithBlockAndBool(RelX, a_BlockY, RelZ, Block, false)); +} + + + + + +void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) +{ + // We still attempt to simulate all blocks in the chunk every tick, because of outside influence that needs to be taken into account + // For example, repeaters need to be ticked, pressure plates checked for entities, daylight sensor checked for light changes, etc. + // The easiest way to make this more efficient is probably just to reduce code within the handlers that put too much strain on server, like getting or setting blocks + // A marking dirty system might be a TODO for later on, perhaps + + cRedstoneSimulatorChunkData & ChunkData = a_Chunk->GetRedstoneSimulatorData(); + if (ChunkData.empty()) + { + return; + } + + int BaseX = a_Chunk->GetPosX() * cChunkDef::Width; + int BaseZ = a_Chunk->GetPosZ() * cChunkDef::Width; + + for (cRedstoneSimulatorChunkData::iterator dataitr = ChunkData.begin(); dataitr != ChunkData.end();) + { + if (dataitr->DataTwo) + { + dataitr = ChunkData.erase(dataitr); + continue; + } + + int a_X = BaseX + dataitr->x; + int a_Z = BaseZ + dataitr->z; + switch (dataitr->Data) + { + case E_BLOCK_BLOCK_OF_REDSTONE: HandleRedstoneBlock(a_X, dataitr->y, a_Z); break; + case E_BLOCK_LEVER: HandleRedstoneLever(a_X, dataitr->y, a_Z); break; + case E_BLOCK_TNT: HandleTNT(a_X, dataitr->y, a_Z); break; + case E_BLOCK_TRAPDOOR: HandleTrapdoor(a_X, dataitr->y, a_Z); break; + case E_BLOCK_REDSTONE_WIRE: HandleRedstoneWire(a_X, dataitr->y, a_Z); break; + case E_BLOCK_NOTE_BLOCK: HandleNoteBlock(a_X, dataitr->y, a_Z); break; + case E_BLOCK_DAYLIGHT_SENSOR: HandleDaylightSensor(a_X, dataitr->y, a_Z); break; + case E_BLOCK_COMMAND_BLOCK: HandleCommandBlock(a_X, dataitr->y, a_Z); break; + + case E_BLOCK_REDSTONE_TORCH_OFF: + case E_BLOCK_REDSTONE_TORCH_ON: + { + HandleRedstoneTorch(a_X, dataitr->y, a_Z, dataitr->Data); + break; + } + case E_BLOCK_STONE_BUTTON: + case E_BLOCK_WOODEN_BUTTON: + { + HandleRedstoneButton(a_X, dataitr->y, a_Z, dataitr->Data); + break; + } + case E_BLOCK_REDSTONE_REPEATER_OFF: + case E_BLOCK_REDSTONE_REPEATER_ON: + { + HandleRedstoneRepeater(a_X, dataitr->y, a_Z, dataitr->Data); + break; + } + case E_BLOCK_PISTON: + case E_BLOCK_STICKY_PISTON: + { + HandlePiston(a_X, dataitr->y, a_Z); + break; + } + case E_BLOCK_REDSTONE_LAMP_OFF: + case E_BLOCK_REDSTONE_LAMP_ON: + { + HandleRedstoneLamp(a_X, dataitr->y, a_Z, dataitr->Data); + break; + } + case E_BLOCK_DISPENSER: + case E_BLOCK_DROPPER: + { + HandleDropSpenser(a_X, dataitr->y, a_Z); + break; + } + case E_BLOCK_WOODEN_DOOR: + case E_BLOCK_IRON_DOOR: + { + HandleDoor(a_X, dataitr->y, a_Z); + break; + } + case E_BLOCK_ACTIVATOR_RAIL: + case E_BLOCK_DETECTOR_RAIL: + case E_BLOCK_POWERED_RAIL: + { + HandleRail(a_X, dataitr->y, a_Z, dataitr->Data); + break; + } + case E_BLOCK_WOODEN_PRESSURE_PLATE: + case E_BLOCK_STONE_PRESSURE_PLATE: + { + HandlePressurePlate(a_X, dataitr->y, a_Z, dataitr->Data); + break; + } + } + ++dataitr; + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) +{ + static const struct // Define which directions the torch can power + { + int x, y, z; + } gCrossCoords[] = + { + { 1, 0, 0}, + {-1, 0, 0}, + { 0, 0, 1}, + { 0, 0, -1}, + { 0, 1, 0}, + } ; + + if (a_MyState == E_BLOCK_REDSTONE_TORCH_ON) + { + // Check if the block the torch is on is powered + int X = a_BlockX; int Y = a_BlockY; int Z = a_BlockZ; + AddFaceDirection(X, Y, Z, cBlockTorchHandler::MetaDataToDirection(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)), true); // Inverse true to get the block torch is on + + if (AreCoordsDirectlyPowered(X, Y, Z)) + { + // There was a match, torch goes off + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_OFF, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); + return; + } + + // Torch still on, make all 4(X, Z) + 1(Y) sides powered + for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) + { + BLOCKTYPE Type = m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z); + if (i + 1 < ARRAYCOUNT(gCrossCoords)) // Sides of torch, not top (top is last) + { + if ( + ((IsMechanism(Type)) || (Type == E_BLOCK_REDSTONE_WIRE)) && // Is it a mechanism or wire? Not block/other torch etc. + (!Vector3i(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z).Equals(Vector3i(X, Y, Z))) // CAN'T power block is that it is on + ) + { + SetBlockPowered(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON); + } + } + else + { + // Top side, power whatever is there, including blocks + SetBlockPowered(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON); + // Power all blocks surrounding block above torch + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, E_BLOCK_REDSTONE_TORCH_ON); + } + } + + if (m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) != 0x5) // Is torch standing on ground? If NOT (i.e. on wall), power block beneath + { + BLOCKTYPE Type = m_World.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); + + if ((IsMechanism(Type)) || (Type == E_BLOCK_REDSTONE_WIRE)) // Still can't make a normal block powered though! + { + SetBlockPowered(a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON); + } + } + } + else + { + // Check if the block the torch is on is powered + int X = a_BlockX; int Y = a_BlockY; int Z = a_BlockZ; + AddFaceDirection(X, Y, Z, cBlockTorchHandler::MetaDataToDirection(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)), true); // Inverse true to get the block torch is on + + // See if off state torch can be turned on again + if (AreCoordsDirectlyPowered(X, Y, Z)) + { + return; // Something matches, torch still powered + } + + // Block torch on not powered, can be turned on again! + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleRedstoneBlock(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_BLOCK_OF_REDSTONE); + SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_BLOCK_OF_REDSTONE); // Set self as powered +} + + + + + +void cIncrementalRedstoneSimulator::HandleRedstoneLever(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + if (IsLeverOn(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ))) + { + SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LEVER); + + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_LEVER); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_LEVER); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, E_BLOCK_LEVER); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, E_BLOCK_LEVER); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_LEVER); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_LEVER); + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleRedstoneButton(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType) +{ + if (IsButtonOn(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ))) + { + SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, a_BlockType); + + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, a_BlockType); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, a_BlockType); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, a_BlockType); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, a_BlockType); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, a_BlockType); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, a_BlockType); + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + static const struct // Define which directions the wire can receive power from + { + int x, y, z; + } gCrossCoords[] = + { + { 1, 0, 0}, /* Wires on same level start */ + {-1, 0, 0}, + { 0, 0, 1}, + { 0, 0, -1}, /* Wires on same level stop */ + { 1, 1, 0}, /* Wires one higher, surrounding self start */ + {-1, 1, 0}, + { 0, 1, 1}, + { 0, 1, -1}, /* Wires one higher, surrounding self stop */ + { 1,-1, 0}, /* Wires one lower, surrounding self start */ + {-1,-1, 0}, + { 0,-1, 1}, + { 0,-1, -1}, /* Wires one lower, surrounding self stop */ + } ; + + static const struct // Define which directions the wire will check for repeater prescence + { + int x, y, z; + } gSideCoords[] = + { + { 1, 0, 0 }, + {-1, 0, 0 }, + { 0, 0, 1 }, + { 0, 0,-1 }, + { 0, 1, 0 }, + }; + + // Check to see if directly beside a power source + if (IsWirePowered(a_BlockX, a_BlockY, a_BlockZ)) + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 15); // Maximum power + } + else + { + NIBBLETYPE MetaToSet = 0; + NIBBLETYPE MyMeta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + int TimesMetaSmaller = 0, TimesFoundAWire = 0; + + for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) // Loop through all directions to transfer or receive power + { + if ((i >= 4) && (i <= 7)) // If we are currently checking for wire surrounding ourself one block above... + { + if (g_BlockIsSolid[m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)]) // If there is something solid above us (wire cut off)... + { + continue; // We don't receive power from that wire + } + } + else if ((i >= 8) && (i <= 11)) // See above, but this is for wire below us + { + if (g_BlockIsSolid[m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y + 1, a_BlockZ + gCrossCoords[i].z)]) + { + continue; + } + } + + BLOCKTYPE SurroundType; + NIBBLETYPE SurroundMeta; + m_World.GetBlockTypeMeta(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, SurroundType, SurroundMeta); + + if (SurroundType == E_BLOCK_REDSTONE_WIRE) + { + TimesFoundAWire++; + + if (SurroundMeta > 1) // Wires of power 1 or 0 cannot transfer power TO ME, don't bother checking + { + // Does surrounding wire have a higher power level than self? + // >= to fix a bug where wires bordering each other with the same power level will appear (in terms of meta) to power each other, when they aren't actually in the powered list + if (SurroundMeta >= MyMeta) + { + MetaToSet = SurroundMeta - 1; // To improve performance + } + } + + if (SurroundMeta < MyMeta) // Go through all surroundings to see if self power is larger than everyone else's + { + TimesMetaSmaller++; + } + } + } + + if (TimesMetaSmaller == TimesFoundAWire) + { + // All surrounding metas were smaller - self must have been a wire that was + // transferring power to other wires around. + // However, self not directly powered anymore, so source must have been removed, + // therefore, self must be set to meta zero + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE, 0); // SetMeta & WakeUpSims doesn't seem to work here, so SetBlock + return; // No need to process block power sets because self not powered + } + else + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaToSet); + } + } + + if (m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) != 0) // A powered wire + { + for (size_t i = 0; i < ARRAYCOUNT(gSideCoords); i++) // Look for repeaters immediately surrounding self and try to power them + { + if (m_World.GetBlock(a_BlockX + gSideCoords[i].x, a_BlockY + gSideCoords[i].y, a_BlockZ + gSideCoords[i].z) == E_BLOCK_REDSTONE_REPEATER_OFF) + { + SetBlockPowered(a_BlockX + gSideCoords[i].x, a_BlockY + gSideCoords[i].y, a_BlockZ + gSideCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + } + } + + // Wire still powered, power blocks beneath + SetBlockPowered(a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, E_BLOCK_REDSTONE_WIRE); + + switch (GetWireDirection(a_BlockX, a_BlockY, a_BlockZ)) + { + case REDSTONE_NONE: + { + SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_REDSTONE_WIRE); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_REDSTONE_WIRE); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, E_BLOCK_REDSTONE_WIRE); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, E_BLOCK_REDSTONE_WIRE); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_REDSTONE_WIRE); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_REDSTONE_WIRE); + break; + } + case REDSTONE_X_POS: + { + SetBlockPowered(a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_REDSTONE_WIRE); + break; + } + case REDSTONE_X_NEG: + { + SetBlockPowered(a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_REDSTONE_WIRE); + break; + } + case REDSTONE_Z_POS: + { + SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_REDSTONE_WIRE); + break; + } + case REDSTONE_Z_NEG: + { + SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_REDSTONE_WIRE); + break; + } + } + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) +{ + NIBBLETYPE a_Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + + bool IsOn = ((a_MyState == E_BLOCK_REDSTONE_REPEATER_ON) ? true : false); // Cache if repeater is on + bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); // Cache if repeater is pwoered + + if (IsSelfPowered && !IsOn) // Queue a power change if I am receiving power but not on + { + QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, 0, true); + } + else if (!IsSelfPowered && IsOn) // Queue a power change if I am not receiving power but on + { + QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, 0, false); + } + + for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + continue; + } + + if (itr->a_ElapsedTicks >= itr->a_DelayTicks) // Has the elapsed ticks reached the target ticks? + { + if (itr->ShouldPowerOn) + { + if (!IsOn) + { + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON, a_Meta); // For performance + } + + switch (a_Meta & 0x3) // We only want the direction (bottom) bits + { + case 0x0: + { + SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_REDSTONE_REPEATER_ON); + break; + } + case 0x1: + { + SetBlockPowered(a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_REDSTONE_REPEATER_ON); + break; + } + case 0x2: + { + SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_REDSTONE_REPEATER_ON); + break; + } + case 0x3: + { + SetBlockPowered(a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); + SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_REDSTONE_REPEATER_ON); + break; + } + } + + // Removal of the data entry will be handled in SimChunk - we still want to continue trying to power blocks, even if our delay time has reached + // Otherwise, the power state of blocks in front won't update after we have powered on + return; + } + else + { + if (IsOn) + { + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); + } + m_RepeatersDelayList.erase(itr); // We can remove off repeaters which don't need further updating + return; + } + } + else + { + // Apparently, incrementing ticks only works reliably here, and not in SimChunk; + // With a world with lots of redstone, the repeaters simply do not delay + // I am confounded to say why. Perhaps optimisation failure. + LOGD("Incremented a repeater @ {%i %i %i} | Elapsed ticks: %i | Target delay: %i", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z, itr->a_ElapsedTicks, itr->a_DelayTicks); + itr->a_ElapsedTicks++; + } + } +} + + + + + +void cIncrementalRedstoneSimulator::HandlePiston(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + cPiston Piston(&m_World); + if (IsPistonPowered(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x7)) // We only want the bottom three bits (4th controls extended-ness) + { + Piston.ExtendPiston(a_BlockX, a_BlockY, a_BlockZ); + } + else + { + Piston.RetractPiston(a_BlockX, a_BlockY, a_BlockZ); + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleDropSpenser(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + class cSetPowerToDropSpenser : + public cDropSpenserCallback + { + bool m_IsPowered; + public: + cSetPowerToDropSpenser(bool a_IsPowered) : m_IsPowered(a_IsPowered) {} + + virtual bool Item(cDropSpenserEntity * a_DropSpenser) override + { + a_DropSpenser->SetRedstonePower(m_IsPowered); + return false; + } + } DrSpSP (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)); + + m_World.DoWithDropSpenserAt(a_BlockX, a_BlockY, a_BlockZ, DrSpSP); +} + + + + + +void cIncrementalRedstoneSimulator::HandleRedstoneLamp(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) +{ + if (a_MyState == E_BLOCK_REDSTONE_LAMP_OFF) + { + if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + { + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_LAMP_ON, 0); + } + } + else + { + if (!AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + { + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_LAMP_OFF, 0); + } + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + { + m_World.BroadcastSoundEffect("random.fuse", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); + m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + { + if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) + { + cChunkInterface ChunkInterface(m_World.GetChunkMap()); + cBlockDoorHandler::ChangeDoor(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); + } + } + else + { + if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) + { + cChunkInterface ChunkInterface(m_World.GetChunkMap()); + cBlockDoorHandler::ChangeDoor(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); + } + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleCommandBlock(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + class cSetPowerToCommandBlock : + public cCommandBlockCallback + { + bool m_IsPowered; + public: + cSetPowerToCommandBlock(bool a_IsPowered) : m_IsPowered(a_IsPowered) {} + + virtual bool Item(cCommandBlockEntity * a_CommandBlock) override + { + a_CommandBlock->SetRedstonePower(m_IsPowered); + return false; + } + } CmdBlockSP (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)); + + m_World.DoWithCommandBlockAt(a_BlockX, a_BlockY, a_BlockZ, CmdBlockSP); +} + + + + + +void cIncrementalRedstoneSimulator::HandleRail(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType) +{ + switch (a_MyType) + { + case E_BLOCK_DETECTOR_RAIL: + { + if ((m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x08) == 0x08) + { + SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, a_MyType); + } + break; + } + case E_BLOCK_ACTIVATOR_RAIL: + case E_BLOCK_POWERED_RAIL: + { + if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); + } + else + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07); + } + break; + } + default: LOGD("Unhandled type of rail in %s", __FUNCTION__); + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleTrapdoor(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + { + if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x4); + SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); + } + } + else + { + if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0xB); // Take into account that the fourth bit is needed for trapdoors too + SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); + } + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleNoteBlock(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + bool m_bAreCoordsPowered = AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ); + + if (m_bAreCoordsPowered) + { + if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) + { + class cSetPowerToNoteBlock : + public cNoteBlockCallback + { + bool m_IsPowered; + public: + cSetPowerToNoteBlock(bool a_IsPowered) : m_IsPowered(a_IsPowered) {} + + virtual bool Item(cNoteEntity * a_NoteBlock) override + { + if (m_IsPowered) + { + a_NoteBlock->MakeSound(); + } + return false; + } + } NoteBlockSP(m_bAreCoordsPowered); + + m_World.DoWithNoteBlockAt(a_BlockX, a_BlockY, a_BlockZ, NoteBlockSP); + SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); + } + } + else + { + if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) + { + SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); + } + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleDaylightSensor(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + int a_ChunkX, a_ChunkZ; + cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, a_ChunkX, a_ChunkZ); + + if (!m_World.IsChunkLighted(a_ChunkX, a_ChunkZ)) + { + m_World.QueueLightChunk(a_ChunkX, a_ChunkZ); + } + else + { + NIBBLETYPE SkyLight = m_World.GetBlockSkyLight(a_BlockX, a_BlockY + 1, a_BlockZ) - m_World.GetSkyDarkness(); + if (SkyLight > 8) + { + SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_DAYLIGHT_SENSOR); + } + } +} + + + + + +void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType) +{ + switch (a_MyType) + { + case E_BLOCK_STONE_PRESSURE_PLATE: + { + // MCS feature - stone pressure plates can only be triggered by players :D + cPlayer * a_Player = m_World.FindClosestPlayer(Vector3f(a_BlockX + 0.5f, (float)a_BlockY, a_BlockZ + 0.5f), 0.5f, false); + + if (a_Player != NULL) + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x1); + SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_STONE_PRESSURE_PLATE); + } + else + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x0); + m_World.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); + } + break; + } + case E_BLOCK_WOODEN_PRESSURE_PLATE: + { + class cWoodenPressurePlateCallback : + public cEntityCallback + { + public: + cWoodenPressurePlateCallback(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + m_Entity(NULL), + m_World(a_World), + m_X(a_BlockX), + m_Y(a_BlockY), + m_Z(a_BlockZ) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + Vector3f EntityPos = a_Entity->GetPosition(); + Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f); + float Distance = (EntityPos - BlockPos).Length(); + + if (Distance < 0.5) + { + m_Entity = a_Entity; + return true; // Break out, we only need to know for wooden plates that at least one entity is on top + } + return false; + } + + bool FoundEntity(void) const + { + return m_Entity != NULL; + } + + protected: + cEntity * m_Entity; + cWorld * m_World; + + int m_X; + int m_Y; + int m_Z; + } ; + + cWoodenPressurePlateCallback WoodenPressurePlateCallback(a_BlockX, a_BlockY, a_BlockZ, &m_World); + m_World.ForEachEntity(WoodenPressurePlateCallback); + + if (WoodenPressurePlateCallback.FoundEntity()) + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x1); + SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_WOODEN_PRESSURE_PLATE); + } + else + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x0); + m_World.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); + } + break; + } + default: + LOGD("Unimplemented pressure plate type %s in cRedstoneSimulator", ItemToFullString(a_MyType).c_str()); + break; + } +} + + + + + +bool cIncrementalRedstoneSimulator::AreCoordsDirectlyPowered(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) // Check powered list + { + if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + return true; + } + } + return false; +} + + + + + +bool cIncrementalRedstoneSimulator::AreCoordsLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) // Check linked powered list + { + if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + return true; + } + } + return false; +} + + + + + +bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) +{ + // Repeaters cannot be powered by any face except their back; verify that this is true for a source + + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + + switch (a_Meta) + { + case 0x0: + { + // Flip the coords to check the back of the repeater + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } + break; + } + case 0x1: + { + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } + break; + } + case 0x2: + { + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } + break; + } + case 0x3: + { + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } + break; + } + } + } + + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + + switch (a_Meta) + { + case 0x0: + { + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } + break; + } + case 0x1: + { + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } + break; + } + case 0x2: + { + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } + break; + } + case 0x3: + { + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } + break; + } + } + } + return false; // Couldn't find power source behind repeater +} + + + + +bool cIncrementalRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) +{ + // Pistons cannot be powered through their front face; this function verifies that a source meets this requirement + + int OldX = a_BlockX, OldY = a_BlockY, OldZ = a_BlockZ; + eBlockFace Face = cPiston::MetaDataToDirection(a_Meta); + + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, Face); + + if (!itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + return true; + } + + a_BlockX = OldX; + a_BlockY = OldY; + a_BlockZ = OldZ; + } + + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, Face); + + if (!itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + return true; + } + + a_BlockX = OldX; + a_BlockY = OldY; + a_BlockZ = OldZ; + } + return false; // Source was in front of the piston's front face +} + + + + +bool cIncrementalRedstoneSimulator::IsWirePowered(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + + if (m_World.GetBlock(itr->a_SourcePos) != E_BLOCK_REDSTONE_WIRE) + { + return true; + } + } + + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + + if (m_World.GetBlock(itr->a_SourcePos) != E_BLOCK_REDSTONE_WIRE) + { + return true; + } + } + return false; // Source was in front of the piston's front face +} + + + + + +bool cIncrementalRedstoneSimulator::AreCoordsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool IsCurrentStatePowered) +{ + for (SimulatedPlayerToggleableList::const_iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end(); ++itr) + { + if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + if (itr->WasLastStatePowered != IsCurrentStatePowered) // Was the last power state different to the current? + { + return false; // It was, coordinates are no longer simulated + } + else + { + return true; // It wasn't, don't resimulate block, and allow players to toggle + } + } + } + return false; // Block wasn't even in the list, not simulated +} + + + + + +void cIncrementalRedstoneSimulator::SetDirectionLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Direction, BLOCKTYPE a_SourceType) +{ + switch (a_Direction) + { + case BLOCK_FACE_XM: + { + BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ); + + SetBlockLinkedPowered(a_BlockX - 2, a_BlockY, a_BlockZ, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX - 1, a_BlockY + 1, a_BlockZ, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX - 1, a_BlockY - 1, a_BlockZ, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ + 1, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ - 1, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + + break; + } + case BLOCK_FACE_XP: + { + BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ); + + SetBlockLinkedPowered(a_BlockX + 2, a_BlockY, a_BlockZ, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX + 1, a_BlockY + 1, a_BlockZ, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX + 1, a_BlockY - 1, a_BlockZ, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ + 1, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ - 1, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + + break; + } + case BLOCK_FACE_YM: + { + BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); + + SetBlockLinkedPowered(a_BlockX, a_BlockY - 2, a_BlockZ, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX + 1, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX - 1, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ + 1, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ - 1, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + + break; + } + case BLOCK_FACE_YP: + { + BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ); + + SetBlockLinkedPowered(a_BlockX, a_BlockY + 2, a_BlockZ, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX + 1, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX - 1, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ + 1, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ - 1, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + + break; + } + case BLOCK_FACE_ZM: + { + BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1); + + SetBlockLinkedPowered(a_BlockX, a_BlockY, a_BlockZ - 2, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + + break; + } + case BLOCK_FACE_ZP: + { + BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1); + + SetBlockLinkedPowered(a_BlockX, a_BlockY, a_BlockZ + 2, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + + break; + } + default: + { + ASSERT(!"Unhandled face direction when attempting to set blocks as linked powered!"); // Zombies, that wasn't supposed to happen... + break; + } + } +} + + + + + +void cIncrementalRedstoneSimulator::SetAllDirsAsPowered(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_SourceBlock) +{ + static const struct + { + int x, y, z; + } gCrossCoords[] = + { + { 1, 0, 0 }, + {-1, 0, 0 }, + { 0, 0, 1 }, + { 0, 0,-1 }, + { 0, 1, 0 }, + { 0,-1, 0 } + }; + + for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) // Loop through struct to power all directions + { + SetBlockPowered(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, a_SourceBlock); + } +} + + + + + +void cIncrementalRedstoneSimulator::SetBlockPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock) +{ + BLOCKTYPE Block = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ); + if (Block == E_BLOCK_AIR) + { + // Don't set air, fixes some bugs (wires powering themselves) + return; + } + + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) // Check powered list + { + if ( + itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)) && + itr->a_SourcePos.Equals(Vector3i(a_SourceX, a_SourceY, a_SourceZ)) + ) + { + // Check for duplicates + return; + } + } + + sPoweredBlocks RC; + RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + RC.a_SourcePos = Vector3i(a_SourceX, a_SourceY, a_SourceZ); + m_PoweredBlocks.push_back(RC); +} + + + + + +void cIncrementalRedstoneSimulator::SetBlockLinkedPowered( + int a_BlockX, int a_BlockY, int a_BlockZ, + int a_MiddleX, int a_MiddleY, int a_MiddleZ, + int a_SourceX, int a_SourceY, int a_SourceZ, + BLOCKTYPE a_SourceBlock, BLOCKTYPE a_MiddleBlock +) +{ + BLOCKTYPE DestBlock = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ); + if (DestBlock == E_BLOCK_AIR) + { + // Don't set air, fixes some bugs (wires powering themselves) + return; + } + if (!IsViableMiddleBlock(a_MiddleBlock)) + { + return; + } + + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) // Check linked powered list + { + if ( + itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)) && + itr->a_MiddlePos.Equals(Vector3i(a_MiddleX, a_MiddleY, a_MiddleZ)) && + itr->a_SourcePos.Equals(Vector3i(a_SourceX, a_SourceY, a_SourceZ)) + ) + { + // Check for duplicates + return; + } + } + + sLinkedPoweredBlocks RC; + RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + RC.a_MiddlePos = Vector3i(a_MiddleX, a_MiddleY, a_MiddleZ); + RC.a_SourcePos = Vector3i(a_SourceX, a_SourceY, a_SourceZ); + m_LinkedPoweredBlocks.push_back(RC); +} + + + + + +void cIncrementalRedstoneSimulator::SetPlayerToggleableBlockAsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool WasLastStatePowered) +{ + for (SimulatedPlayerToggleableList::iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + continue; + } + + if (itr->WasLastStatePowered != WasLastStatePowered) + { + // If power states different, update listing + itr->WasLastStatePowered = WasLastStatePowered; + return; + } + else + { + // If states the same, just ignore + return; + } + } + + // We have arrive here; no block must be in list - add one + sSimulatedPlayerToggleableList RC; + RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + RC.WasLastStatePowered = WasLastStatePowered; + m_SimulatedPlayerToggleableBlocks.push_back(RC); +} + + + + + +void cIncrementalRedstoneSimulator::QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta, short a_ElapsedTicks, bool ShouldPowerOn) +{ + for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); ++itr) + { + if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + if (ShouldPowerOn == itr->ShouldPowerOn) // We are queued already for the same thing, don't replace entry + { + return; + } + + // Already in here (normal to allow repeater to continue on powering and updating blocks in front) - just update info and quit + itr->a_DelayTicks = (((a_Meta & 0xC) >> 0x2) + (ShouldPowerOn ? 1 : 0)) * 2; // See below for description + itr->a_ElapsedTicks = 0; + itr->ShouldPowerOn = ShouldPowerOn; + return; + } + } + + // Self not in list, add self to list + sRepeatersDelayList RC; + RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + + // Gets the top two bits (delay time), shifts them into the lower two bits, and adds one (meta 0 = 1 tick; 1 = 2 etc.) + // * 2 because apparently, MCS ticks are way faster than vanilla ticks, so repeater aren't noticeably delayed + // We don't +1 when powering off because everything seems to already delay a tick when powering off, why? No idea :P + RC.a_DelayTicks = (((a_Meta & 0xC) >> 0x2) + (ShouldPowerOn ? 1 : 0)) * 2; + + + RC.a_ElapsedTicks = 0; + RC.ShouldPowerOn = ShouldPowerOn; + m_RepeatersDelayList.push_back(RC); + return; +} + + + + + +cIncrementalRedstoneSimulator::eRedstoneDirection cIncrementalRedstoneSimulator::GetWireDirection(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + int Dir = REDSTONE_NONE; + + BLOCKTYPE NegX = m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ); + if (IsPotentialSource(NegX)) + { + Dir |= (REDSTONE_X_POS); + } + + BLOCKTYPE PosX = m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ); + if (IsPotentialSource(PosX)) + { + Dir |= (REDSTONE_X_NEG); + } + + BLOCKTYPE NegZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1); + if (IsPotentialSource(NegZ)) + { + if ((Dir & REDSTONE_X_POS) && !(Dir & REDSTONE_X_NEG)) // corner + { + Dir ^= REDSTONE_X_POS; + Dir |= REDSTONE_X_NEG; + } + if ((Dir & REDSTONE_X_NEG) && !(Dir & REDSTONE_X_POS)) // corner + { + Dir ^= REDSTONE_X_NEG; + Dir |= REDSTONE_X_POS; + } + Dir |= REDSTONE_Z_POS; + } + + BLOCKTYPE PosZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1); + if (IsPotentialSource(PosZ)) + { + if ((Dir & REDSTONE_X_POS) && !(Dir & REDSTONE_X_NEG)) // corner + { + Dir ^= REDSTONE_X_POS; + Dir |= REDSTONE_X_NEG; + } + if ((Dir & REDSTONE_X_NEG) && !(Dir & REDSTONE_X_POS)) // corner + { + Dir ^= REDSTONE_X_NEG; + Dir |= REDSTONE_X_POS; + } + Dir |= REDSTONE_Z_NEG; + } + return (eRedstoneDirection)Dir; +} + + + + + +bool cIncrementalRedstoneSimulator::IsLeverOn(NIBBLETYPE a_BlockMeta) +{ + // Extract the ON bit from metadata and return if true if it is set: + return ((a_BlockMeta & 0x8) == 0x8); +} + + + + + +bool cIncrementalRedstoneSimulator::IsButtonOn(NIBBLETYPE a_BlockMeta) +{ + return IsLeverOn(a_BlockMeta); +} + + + + diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h new file mode 100644 index 000000000..3397e143c --- /dev/null +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -0,0 +1,263 @@ + +#pragma once + +#include "RedstoneSimulator.h" + +/// Per-chunk data for the simulator, specified individual chunks to simulate; 'Data' is not used +typedef cCoordWithBlockAndBoolVector cRedstoneSimulatorChunkData; + + + + + +class cIncrementalRedstoneSimulator : + public cRedstoneSimulator +{ + typedef cRedstoneSimulator super; +public: + + cIncrementalRedstoneSimulator(cWorld & a_World); + ~cIncrementalRedstoneSimulator(); + + virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} // not used + virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; + virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override { return IsRedstone(a_BlockType); } + + enum eRedstoneDirection + { + REDSTONE_NONE = 0, + REDSTONE_X_POS = 0x1, + REDSTONE_X_NEG = 0x2, + REDSTONE_Z_POS = 0x4, + REDSTONE_Z_NEG = 0x8, + }; + eRedstoneDirection GetWireDirection(int a_BlockX, int a_BlockY, int a_BlockZ); + +private: + + struct sPoweredBlocks // Define structure of the directly powered blocks list + { + Vector3i a_BlockPos; // Position of powered block + Vector3i a_SourcePos; // Position of source powering the block at a_BlockPos + }; + + struct sLinkedPoweredBlocks // Define structure of the indirectly powered blocks list (i.e. repeaters powering through a block to the block at the other side) + { + Vector3i a_BlockPos; + Vector3i a_MiddlePos; + Vector3i a_SourcePos; + }; + + struct sSimulatedPlayerToggleableList + { + Vector3i a_BlockPos; + bool WasLastStatePowered; + }; + + struct sRepeatersDelayList + { + Vector3i a_BlockPos; + short a_DelayTicks; + short a_ElapsedTicks; + bool ShouldPowerOn; + }; + + typedef std::vector PoweredBlocksList; + typedef std::vector LinkedBlocksList; + typedef std::vector SimulatedPlayerToggleableList; + typedef std::vector RepeatersDelayList; + + PoweredBlocksList m_PoweredBlocks; + LinkedBlocksList m_LinkedPoweredBlocks; + SimulatedPlayerToggleableList m_SimulatedPlayerToggleableBlocks; + RepeatersDelayList m_RepeatersDelayList; + + virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override; + + // We want a_MyState for devices needing a full FastSetBlock (as opposed to meta) because with our simulation model, we cannot keep setting the block if it is already set correctly + // In addition to being non-performant, it would stop the player from actually breaking said device + + /* ====== SOURCES ====== */ + /** Handles the redstone torch */ + void HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState); + /** Handles the redstone block */ + void HandleRedstoneBlock(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles levers */ + void HandleRedstoneLever(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles buttons */ + void HandleRedstoneButton(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType); + /** Handles daylight sensors */ + void HandleDaylightSensor(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles pressure plates */ + void HandlePressurePlate(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType); + /* ==================== */ + + /* ====== CARRIERS ====== */ + /** Handles redstone wire */ + void HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles repeaters */ + void HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState); + /* ====================== */ + + /* ====== DEVICES ====== */ + /** Handles pistons */ + void HandlePiston(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles dispensers and droppers */ + void HandleDropSpenser(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles TNT (exploding) */ + void HandleTNT(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles redstone lamps */ + void HandleRedstoneLamp(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState); + /** Handles doords */ + void HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles command blocks */ + void HandleCommandBlock(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles activator, detector, and powered rails */ + void HandleRail(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType); + /** Handles trapdoors */ + void HandleTrapdoor(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles noteblocks */ + void HandleNoteBlock(int a_BlockX, int a_BlockY, int a_BlockZ); + /* ===================== */ + + /* ====== Helper functions ====== */ + /** Marks a block as powered */ + void SetBlockPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock); + /** Marks a block as being powered through another block */ + void SetBlockLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_MiddleX, int a_MiddleY, int a_MiddleZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock, BLOCKTYPE a_MiddeBlock); + /** Marks a block as simulated, who should not be simulated further unless their power state changes, to accomodate a player manually toggling the block without triggering the simulator toggling it back */ + void SetPlayerToggleableBlockAsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool WasLastStatePowered); + /** Marks the second block in a direction as linked powered */ + void SetDirectionLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Direction, BLOCKTYPE a_SourceBlock); + /** Marks all blocks immediately surrounding a coordinate as powered */ + void SetAllDirsAsPowered(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_SourceBlock); + /** Queues a repeater to be powered or unpowered */ + void QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta, short a_ElapsedTicks, bool ShouldPowerOn); + + /** Returns if a coordinate is powered or linked powered */ + bool AreCoordsPowered(int a_BlockX, int a_BlockY, int a_BlockZ) { return AreCoordsDirectlyPowered(a_BlockX, a_BlockY, a_BlockZ) || AreCoordsLinkedPowered(a_BlockX, a_BlockY, a_BlockZ); } + /** Returns if a coordinate is in the directly powered blocks list */ + bool AreCoordsDirectlyPowered(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Returns if a coordinate is in the indirectly powered blocks list */ + bool AreCoordsLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Returns if a coordinate was marked as simulated (for blocks toggleable by players) */ + bool AreCoordsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool IsCurrentStatePowered); + /** Returns if a repeater is powered */ + bool IsRepeaterPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); + /** Returns if a piston is powered */ + bool IsPistonPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); + /** Returns if a wire is powered + The only diffence between this and a normal AreCoordsPowered is that this function checks for a wire powering another wire + */ + bool IsWirePowered(int a_BlockX, int a_BlockY, int a_BlockZ); + + + /** Returns if lever metadata marks it as emitting power */ + bool IsLeverOn(NIBBLETYPE a_BlockMeta); + /** Returns if button metadata marks it as emitting power */ + bool IsButtonOn(NIBBLETYPE a_BlockMeta); + /* ============================== */ + + /* ====== Misc Functions ====== */ + /** Returns if a block is viable to be the MiddleBlock of a SetLinkedPowered operation */ + inline static bool IsViableMiddleBlock(BLOCKTYPE Block) { return g_BlockFullyOccupiesVoxel[Block]; } + + /** Returns if a block is a mechanism (something that accepts power and does something) */ + inline static bool IsMechanism(BLOCKTYPE Block) + { + switch (Block) + { + case E_BLOCK_ACTIVATOR_RAIL: + case E_BLOCK_COMMAND_BLOCK: + case E_BLOCK_PISTON: + case E_BLOCK_STICKY_PISTON: + case E_BLOCK_DISPENSER: + case E_BLOCK_DROPPER: + case E_BLOCK_FENCE_GATE: + case E_BLOCK_HOPPER: + case E_BLOCK_NOTE_BLOCK: + case E_BLOCK_TNT: + case E_BLOCK_TRAPDOOR: + case E_BLOCK_REDSTONE_LAMP_OFF: + case E_BLOCK_REDSTONE_LAMP_ON: + case E_BLOCK_WOODEN_DOOR: + case E_BLOCK_IRON_DOOR: + case E_BLOCK_REDSTONE_REPEATER_OFF: + case E_BLOCK_REDSTONE_REPEATER_ON: + case E_BLOCK_POWERED_RAIL: + { + return true; + } + default: return false; + } + } + + /** Returns if a block has the potential to output power */ + inline static bool IsPotentialSource(BLOCKTYPE Block) + { + switch (Block) + { + case E_BLOCK_DETECTOR_RAIL: + case E_BLOCK_DAYLIGHT_SENSOR: + case E_BLOCK_WOODEN_BUTTON: + case E_BLOCK_STONE_BUTTON: + case E_BLOCK_REDSTONE_WIRE: + case E_BLOCK_REDSTONE_TORCH_ON: + case E_BLOCK_LEVER: + case E_BLOCK_REDSTONE_REPEATER_ON: + case E_BLOCK_BLOCK_OF_REDSTONE: + case E_BLOCK_ACTIVE_COMPARATOR: + { + return true; + } + default: return false; + } + } + + /** Returns if a block is any sort of redstone device */ + inline static bool IsRedstone(BLOCKTYPE Block) + { + switch (Block) + { + // All redstone devices, please alpha sort + case E_BLOCK_ACTIVATOR_RAIL: + case E_BLOCK_ACTIVE_COMPARATOR: + case E_BLOCK_BLOCK_OF_REDSTONE: + case E_BLOCK_COMMAND_BLOCK: + case E_BLOCK_DETECTOR_RAIL: + case E_BLOCK_DISPENSER: + case E_BLOCK_DAYLIGHT_SENSOR: + case E_BLOCK_DROPPER: + case E_BLOCK_FENCE_GATE: + case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: + case E_BLOCK_HOPPER: + case E_BLOCK_INACTIVE_COMPARATOR: + case E_BLOCK_IRON_DOOR: + case E_BLOCK_LEVER: + case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: + case E_BLOCK_NOTE_BLOCK: + case E_BLOCK_POWERED_RAIL: + case E_BLOCK_REDSTONE_LAMP_OFF: + case E_BLOCK_REDSTONE_LAMP_ON: + case E_BLOCK_REDSTONE_REPEATER_OFF: + case E_BLOCK_REDSTONE_REPEATER_ON: + case E_BLOCK_REDSTONE_TORCH_OFF: + case E_BLOCK_REDSTONE_TORCH_ON: + case E_BLOCK_REDSTONE_WIRE: + case E_BLOCK_STICKY_PISTON: + case E_BLOCK_STONE_BUTTON: + case E_BLOCK_STONE_PRESSURE_PLATE: + case E_BLOCK_TNT: + case E_BLOCK_TRAPDOOR: + case E_BLOCK_TRIPWIRE_HOOK: + case E_BLOCK_WOODEN_BUTTON: + case E_BLOCK_WOODEN_DOOR: + case E_BLOCK_WOODEN_PRESSURE_PLATE: + case E_BLOCK_PISTON: + { + return true; + } + default: return false; + } + } +}; diff --git a/src/Simulator/NoopRedstoneSimulator.h b/src/Simulator/NoopRedstoneSimulator.h index d2e00d039..fe3949198 100644 --- a/src/Simulator/NoopRedstoneSimulator.h +++ b/src/Simulator/NoopRedstoneSimulator.h @@ -1,16 +1,16 @@ #pragma once -#include "RedstoneManager.h" +#include "RedstoneSimulator.h" class cRedstoneNoopSimulator : - public cRedstoneManager + public cRedstoneSimulator { - typedef cRedstoneManager super; + typedef cRedstoneSimulator super; public: cRedstoneNoopSimulator(cWorld & a_World) : diff --git a/src/Simulator/RedstoneManager.cpp b/src/Simulator/RedstoneManager.cpp deleted file mode 100644 index 58fb8fa4c..000000000 --- a/src/Simulator/RedstoneManager.cpp +++ /dev/null @@ -1,19 +0,0 @@ - -#include "Globals.h" - -#include "RedstoneManager.h" -#include "../World.h" - - - - - -cRedstoneManager::cRedstoneManager(cWorld & a_World) : - super(a_World) -{ -} - - - - - diff --git a/src/Simulator/RedstoneManager.h b/src/Simulator/RedstoneManager.h deleted file mode 100644 index 18cfb0c1a..000000000 --- a/src/Simulator/RedstoneManager.h +++ /dev/null @@ -1,17 +0,0 @@ - -#pragma once - -#include "Simulator.h" - - - - -class cRedstoneManager : - public cSimulator -{ - typedef cSimulator super; - -public: - cRedstoneManager(cWorld & a_World); - -} ; diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 298175ad7..a83f21106 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -1,21 +1,15 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules +#include "Globals.h" #include "RedstoneSimulator.h" -#include "../BlockEntities/DropSpenserEntity.h" -#include "../BlockEntities/NoteEntity.h" -#include "../BlockEntities/CommandBlockEntity.h" -#include "../Entities/TNTEntity.h" -#include "../Blocks/BlockTorch.h" -#include "../Blocks/BlockDoor.h" -#include "../Piston.h" +#include "../World.h" -cRedstoneSimulator::cRedstoneSimulator(cWorld & a_World) - : super(a_World) +cRedstoneSimulator::cRedstoneSimulator(cWorld & a_World) : + super(a_World) { } @@ -23,1512 +17,3 @@ cRedstoneSimulator::cRedstoneSimulator(cWorld & a_World) -cRedstoneSimulator::~cRedstoneSimulator() -{ -} - - - - - -void cRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) -{ - if ((a_Chunk == NULL) || !a_Chunk->IsValid()) - { - return; - } - else if ((a_BlockY < 0) || (a_BlockY > cChunkDef::Height)) - { - return; - } - - int RelX = a_BlockX - a_Chunk->GetPosX() * cChunkDef::Width; - int RelZ = a_BlockZ - a_Chunk->GetPosZ() * cChunkDef::Width; - - BLOCKTYPE Block; - NIBBLETYPE Meta; - a_Chunk->GetBlockTypeMeta(RelX, a_BlockY, RelZ, Block, Meta); - - // Every time a block is changed (AddBlock called), we want to go through all lists and check to see if the coordiantes stored within are still valid - // Checking only when a block is changed, as opposed to every tick, also improves performance - - for (PoweredBlocksList::iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) - { - if (!itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - continue; - } - - if (!IsPotentialSource(Block)) - { - LOGD("cRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list as it no longer connected to a source", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_PoweredBlocks.erase(itr); - break; - } - else if ( - // Changeable sources - ((Block == E_BLOCK_REDSTONE_WIRE) && (Meta == 0)) || - ((Block == E_BLOCK_LEVER) && !IsLeverOn(Meta)) || - ((Block == E_BLOCK_DETECTOR_RAIL) && (Meta & 0x08) == 0) || - (((Block == E_BLOCK_STONE_BUTTON) || (Block == E_BLOCK_WOODEN_BUTTON)) && (!IsButtonOn(Meta))) || - (((Block == E_BLOCK_STONE_PRESSURE_PLATE) || (Block == E_BLOCK_WOODEN_PRESSURE_PLATE)) && (Meta == 0)) - ) - { - LOGD("cRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_PoweredBlocks.erase(itr); - break; - } - else if (Block == E_BLOCK_DAYLIGHT_SENSOR) - { - if (!a_Chunk->IsLightValid()) - { - m_World.QueueLightChunk(a_Chunk->GetPosX(), a_Chunk->GetPosZ()); - break; - } - else - { - NIBBLETYPE SkyLight; - a_Chunk->UnboundedRelGetBlockSkyLight(RelX, itr->a_SourcePos.y + 1, RelZ, SkyLight); - - if (a_Chunk->GetTimeAlteredLight(SkyLight) <= 8) // Could use SkyLight - m_World.GetSkyDarkness(); - { - LOGD("cRedstoneSimulator: Erased daylight sensor from powered blocks list due to insufficient light level"); - m_PoweredBlocks.erase(itr); - break; - } - } - } - } - - for (LinkedBlocksList::iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) - { - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - if (!IsPotentialSource(Block)) - { - LOGD("cRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list as it is no longer connected to a source", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_LinkedPoweredBlocks.erase(itr); - break; - } - else if ( - // Things that can send power through a block but which depends on meta - ((Block == E_BLOCK_REDSTONE_WIRE) && (Meta == 0)) || - ((Block == E_BLOCK_LEVER) && !IsLeverOn(Meta)) || - (((Block == E_BLOCK_STONE_BUTTON) || (Block == E_BLOCK_WOODEN_BUTTON)) && (!IsButtonOn(Meta))) - ) - { - LOGD("cRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_LinkedPoweredBlocks.erase(itr); - break; - } - } - else if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - if (!IsViableMiddleBlock(Block)) - { - LOGD("cRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list as it is no longer powered through a valid middle block", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_LinkedPoweredBlocks.erase(itr); - break; - } - } - } - - for (SimulatedPlayerToggleableList::iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - continue; - } - - if (!IsAllowedBlock(Block)) - { - LOGD("cRedstoneSimulator: Erased block @ {%i, %i, %i} from toggleable simulated list as it is no longer redstone", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_SimulatedPlayerToggleableBlocks.erase(itr); - break; - } - } - - for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - continue; - } - - if ((Block != E_BLOCK_REDSTONE_REPEATER_ON) && (Block != E_BLOCK_REDSTONE_REPEATER_OFF)) - { - m_RepeatersDelayList.erase(itr); - break; - } - } - - cRedstoneSimulatorChunkData & ChunkData = a_Chunk->GetRedstoneSimulatorData(); - for (cRedstoneSimulatorChunkData::iterator itr = ChunkData.begin(); itr != ChunkData.end(); ++itr) - { - if ((itr->x == RelX) && (itr->y == a_BlockY) && (itr->z == RelZ)) // We are at an entry matching the current (changed) block - { - if (!IsAllowedBlock(Block)) - { - itr->DataTwo = true; // The new blocktype is not redstone; it must be queued to be removed from this list - } - else - { - itr->Data = Block; // Update block information - } - return; - } - } - - if (!IsAllowedBlock(Block)) - { - return; - } - - ChunkData.push_back(cCoordWithBlockAndBool(RelX, a_BlockY, RelZ, Block, false)); -} - - - - - -void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) -{ - // We still attempt to simulate all blocks in the chunk every tick, because of outside influence that needs to be taken into account - // For example, repeaters need to be ticked, pressure plates checked for entities, daylight sensor checked for light changes, etc. - // The easiest way to make this more efficient is probably just to reduce code within the handlers that put too much strain on server, like getting or setting blocks - // A marking dirty system might be a TODO for later on, perhaps - - cRedstoneSimulatorChunkData & ChunkData = a_Chunk->GetRedstoneSimulatorData(); - if (ChunkData.empty()) - { - return; - } - - int BaseX = a_Chunk->GetPosX() * cChunkDef::Width; - int BaseZ = a_Chunk->GetPosZ() * cChunkDef::Width; - - for (cRedstoneSimulatorChunkData::iterator dataitr = ChunkData.begin(); dataitr != ChunkData.end();) - { - if (dataitr->DataTwo) - { - dataitr = ChunkData.erase(dataitr); - continue; - } - - int a_X = BaseX + dataitr->x; - int a_Z = BaseZ + dataitr->z; - switch (dataitr->Data) - { - case E_BLOCK_BLOCK_OF_REDSTONE: HandleRedstoneBlock(a_X, dataitr->y, a_Z); break; - case E_BLOCK_LEVER: HandleRedstoneLever(a_X, dataitr->y, a_Z); break; - case E_BLOCK_TNT: HandleTNT(a_X, dataitr->y, a_Z); break; - case E_BLOCK_TRAPDOOR: HandleTrapdoor(a_X, dataitr->y, a_Z); break; - case E_BLOCK_REDSTONE_WIRE: HandleRedstoneWire(a_X, dataitr->y, a_Z); break; - case E_BLOCK_NOTE_BLOCK: HandleNoteBlock(a_X, dataitr->y, a_Z); break; - case E_BLOCK_DAYLIGHT_SENSOR: HandleDaylightSensor(a_X, dataitr->y, a_Z); break; - case E_BLOCK_COMMAND_BLOCK: HandleCommandBlock(a_X, dataitr->y, a_Z); break; - - case E_BLOCK_REDSTONE_TORCH_OFF: - case E_BLOCK_REDSTONE_TORCH_ON: - { - HandleRedstoneTorch(a_X, dataitr->y, a_Z, dataitr->Data); - break; - } - case E_BLOCK_STONE_BUTTON: - case E_BLOCK_WOODEN_BUTTON: - { - HandleRedstoneButton(a_X, dataitr->y, a_Z, dataitr->Data); - break; - } - case E_BLOCK_REDSTONE_REPEATER_OFF: - case E_BLOCK_REDSTONE_REPEATER_ON: - { - HandleRedstoneRepeater(a_X, dataitr->y, a_Z, dataitr->Data); - break; - } - case E_BLOCK_PISTON: - case E_BLOCK_STICKY_PISTON: - { - HandlePiston(a_X, dataitr->y, a_Z); - break; - } - case E_BLOCK_REDSTONE_LAMP_OFF: - case E_BLOCK_REDSTONE_LAMP_ON: - { - HandleRedstoneLamp(a_X, dataitr->y, a_Z, dataitr->Data); - break; - } - case E_BLOCK_DISPENSER: - case E_BLOCK_DROPPER: - { - HandleDropSpenser(a_X, dataitr->y, a_Z); - break; - } - case E_BLOCK_WOODEN_DOOR: - case E_BLOCK_IRON_DOOR: - { - HandleDoor(a_X, dataitr->y, a_Z); - break; - } - case E_BLOCK_ACTIVATOR_RAIL: - case E_BLOCK_DETECTOR_RAIL: - case E_BLOCK_POWERED_RAIL: - { - HandleRail(a_X, dataitr->y, a_Z, dataitr->Data); - break; - } - case E_BLOCK_WOODEN_PRESSURE_PLATE: - case E_BLOCK_STONE_PRESSURE_PLATE: - { - HandlePressurePlate(a_X, dataitr->y, a_Z, dataitr->Data); - break; - } - } - ++dataitr; - } -} - - - - - -void cRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) -{ - static const struct // Define which directions the torch can power - { - int x, y, z; - } gCrossCoords[] = - { - { 1, 0, 0}, - {-1, 0, 0}, - { 0, 0, 1}, - { 0, 0, -1}, - { 0, 1, 0}, - } ; - - if (a_MyState == E_BLOCK_REDSTONE_TORCH_ON) - { - // Check if the block the torch is on is powered - int X = a_BlockX; int Y = a_BlockY; int Z = a_BlockZ; - AddFaceDirection(X, Y, Z, cBlockTorchHandler::MetaDataToDirection(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)), true); // Inverse true to get the block torch is on - - if (AreCoordsDirectlyPowered(X, Y, Z)) - { - // There was a match, torch goes off - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_OFF, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); - return; - } - - // Torch still on, make all 4(X, Z) + 1(Y) sides powered - for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) - { - BLOCKTYPE Type = m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z); - if (i + 1 < ARRAYCOUNT(gCrossCoords)) // Sides of torch, not top (top is last) - { - if ( - ((IsMechanism(Type)) || (Type == E_BLOCK_REDSTONE_WIRE)) && // Is it a mechanism or wire? Not block/other torch etc. - (!Vector3i(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z).Equals(Vector3i(X, Y, Z))) // CAN'T power block is that it is on - ) - { - SetBlockPowered(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON); - } - } - else - { - // Top side, power whatever is there, including blocks - SetBlockPowered(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON); - // Power all blocks surrounding block above torch - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, E_BLOCK_REDSTONE_TORCH_ON); - } - } - - if (m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) != 0x5) // Is torch standing on ground? If NOT (i.e. on wall), power block beneath - { - BLOCKTYPE Type = m_World.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); - - if ((IsMechanism(Type)) || (Type == E_BLOCK_REDSTONE_WIRE)) // Still can't make a normal block powered though! - { - SetBlockPowered(a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON); - } - } - } - else - { - // Check if the block the torch is on is powered - int X = a_BlockX; int Y = a_BlockY; int Z = a_BlockZ; - AddFaceDirection(X, Y, Z, cBlockTorchHandler::MetaDataToDirection(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)), true); // Inverse true to get the block torch is on - - // See if off state torch can be turned on again - if (AreCoordsDirectlyPowered(X, Y, Z)) - { - return; // Something matches, torch still powered - } - - // Block torch on not powered, can be turned on again! - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); - } -} - - - - - -void cRedstoneSimulator::HandleRedstoneBlock(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_BLOCK_OF_REDSTONE); - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_BLOCK_OF_REDSTONE); // Set self as powered -} - - - - - -void cRedstoneSimulator::HandleRedstoneLever(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - if (IsLeverOn(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ))) - { - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LEVER); - - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_LEVER); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_LEVER); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, E_BLOCK_LEVER); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, E_BLOCK_LEVER); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_LEVER); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_LEVER); - } -} - - - - - -void cRedstoneSimulator::HandleRedstoneButton(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType) -{ - if (IsButtonOn(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ))) - { - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, a_BlockType); - - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, a_BlockType); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, a_BlockType); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, a_BlockType); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, a_BlockType); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, a_BlockType); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, a_BlockType); - } -} - - - - - -void cRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - static const struct // Define which directions the wire can receive power from - { - int x, y, z; - } gCrossCoords[] = - { - { 1, 0, 0}, /* Wires on same level start */ - {-1, 0, 0}, - { 0, 0, 1}, - { 0, 0, -1}, /* Wires on same level stop */ - { 1, 1, 0}, /* Wires one higher, surrounding self start */ - {-1, 1, 0}, - { 0, 1, 1}, - { 0, 1, -1}, /* Wires one higher, surrounding self stop */ - { 1,-1, 0}, /* Wires one lower, surrounding self start */ - {-1,-1, 0}, - { 0,-1, 1}, - { 0,-1, -1}, /* Wires one lower, surrounding self stop */ - } ; - - static const struct // Define which directions the wire will check for repeater prescence - { - int x, y, z; - } gSideCoords[] = - { - { 1, 0, 0 }, - {-1, 0, 0 }, - { 0, 0, 1 }, - { 0, 0,-1 }, - { 0, 1, 0 }, - }; - - // Check to see if directly beside a power source - if (IsWirePowered(a_BlockX, a_BlockY, a_BlockZ)) - { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 15); // Maximum power - } - else - { - NIBBLETYPE MetaToSet = 0; - NIBBLETYPE MyMeta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - int TimesMetaSmaller = 0, TimesFoundAWire = 0; - - for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) // Loop through all directions to transfer or receive power - { - if ((i >= 4) && (i <= 7)) // If we are currently checking for wire surrounding ourself one block above... - { - if (g_BlockIsSolid[m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)]) // If there is something solid above us (wire cut off)... - { - continue; // We don't receive power from that wire - } - } - else if ((i >= 8) && (i <= 11)) // See above, but this is for wire below us - { - if (g_BlockIsSolid[m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y + 1, a_BlockZ + gCrossCoords[i].z)]) - { - continue; - } - } - - BLOCKTYPE SurroundType; - NIBBLETYPE SurroundMeta; - m_World.GetBlockTypeMeta(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, SurroundType, SurroundMeta); - - if (SurroundType == E_BLOCK_REDSTONE_WIRE) - { - TimesFoundAWire++; - - if (SurroundMeta > 1) // Wires of power 1 or 0 cannot transfer power TO ME, don't bother checking - { - // Does surrounding wire have a higher power level than self? - // >= to fix a bug where wires bordering each other with the same power level will appear (in terms of meta) to power each other, when they aren't actually in the powered list - if (SurroundMeta >= MyMeta) - { - MetaToSet = SurroundMeta - 1; // To improve performance - } - } - - if (SurroundMeta < MyMeta) // Go through all surroundings to see if self power is larger than everyone else's - { - TimesMetaSmaller++; - } - } - } - - if (TimesMetaSmaller == TimesFoundAWire) - { - // All surrounding metas were smaller - self must have been a wire that was - // transferring power to other wires around. - // However, self not directly powered anymore, so source must have been removed, - // therefore, self must be set to meta zero - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE, 0); // SetMeta & WakeUpSims doesn't seem to work here, so SetBlock - return; // No need to process block power sets because self not powered - } - else - { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaToSet); - } - } - - if (m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) != 0) // A powered wire - { - for (size_t i = 0; i < ARRAYCOUNT(gSideCoords); i++) // Look for repeaters immediately surrounding self and try to power them - { - if (m_World.GetBlock(a_BlockX + gSideCoords[i].x, a_BlockY + gSideCoords[i].y, a_BlockZ + gSideCoords[i].z) == E_BLOCK_REDSTONE_REPEATER_OFF) - { - SetBlockPowered(a_BlockX + gSideCoords[i].x, a_BlockY + gSideCoords[i].y, a_BlockZ + gSideCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - } - } - - // Wire still powered, power blocks beneath - SetBlockPowered(a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, E_BLOCK_REDSTONE_WIRE); - - switch (GetWireDirection(a_BlockX, a_BlockY, a_BlockZ)) - { - case REDSTONE_NONE: - { - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_REDSTONE_WIRE); - break; - } - case REDSTONE_X_POS: - { - SetBlockPowered(a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_REDSTONE_WIRE); - break; - } - case REDSTONE_X_NEG: - { - SetBlockPowered(a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_REDSTONE_WIRE); - break; - } - case REDSTONE_Z_POS: - { - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_REDSTONE_WIRE); - break; - } - case REDSTONE_Z_NEG: - { - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_REDSTONE_WIRE); - break; - } - } - } -} - - - - - -void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) -{ - NIBBLETYPE a_Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - - bool IsOn = ((a_MyState == E_BLOCK_REDSTONE_REPEATER_ON) ? true : false); // Cache if repeater is on - bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); // Cache if repeater is pwoered - - if (IsSelfPowered && !IsOn) // Queue a power change if I am receiving power but not on - { - QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, 0, true); - } - else if (!IsSelfPowered && IsOn) // Queue a power change if I am not receiving power but on - { - QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, 0, false); - } - - for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - continue; - } - - if (itr->a_ElapsedTicks >= itr->a_DelayTicks) // Has the elapsed ticks reached the target ticks? - { - if (itr->ShouldPowerOn) - { - if (!IsOn) - { - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON, a_Meta); // For performance - } - - switch (a_Meta & 0x3) // We only want the direction (bottom) bits - { - case 0x0: - { - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_REDSTONE_REPEATER_ON); - break; - } - case 0x1: - { - SetBlockPowered(a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_REDSTONE_REPEATER_ON); - break; - } - case 0x2: - { - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_REDSTONE_REPEATER_ON); - break; - } - case 0x3: - { - SetBlockPowered(a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_REDSTONE_REPEATER_ON); - break; - } - } - - // Removal of the data entry will be handled in SimChunk - we still want to continue trying to power blocks, even if our delay time has reached - // Otherwise, the power state of blocks in front won't update after we have powered on - return; - } - else - { - if (IsOn) - { - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); - } - m_RepeatersDelayList.erase(itr); // We can remove off repeaters which don't need further updating - return; - } - } - else - { - // Apparently, incrementing ticks only works reliably here, and not in SimChunk; - // With a world with lots of redstone, the repeaters simply do not delay - // I am confounded to say why. Perhaps optimisation failure. - LOGD("Incremented a repeater @ {%i %i %i} | Elapsed ticks: %i | Target delay: %i", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z, itr->a_ElapsedTicks, itr->a_DelayTicks); - itr->a_ElapsedTicks++; - } - } -} - - - - - -void cRedstoneSimulator::HandlePiston(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - cPiston Piston(&m_World); - if (IsPistonPowered(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x7)) // We only want the bottom three bits (4th controls extended-ness) - { - Piston.ExtendPiston(a_BlockX, a_BlockY, a_BlockZ); - } - else - { - Piston.RetractPiston(a_BlockX, a_BlockY, a_BlockZ); - } -} - - - - - -void cRedstoneSimulator::HandleDropSpenser(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - class cSetPowerToDropSpenser : - public cDropSpenserCallback - { - bool m_IsPowered; - public: - cSetPowerToDropSpenser(bool a_IsPowered) : m_IsPowered(a_IsPowered) {} - - virtual bool Item(cDropSpenserEntity * a_DropSpenser) override - { - a_DropSpenser->SetRedstonePower(m_IsPowered); - return false; - } - } DrSpSP (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)); - - m_World.DoWithDropSpenserAt(a_BlockX, a_BlockY, a_BlockZ, DrSpSP); -} - - - - - -void cRedstoneSimulator::HandleRedstoneLamp(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) -{ - if (a_MyState == E_BLOCK_REDSTONE_LAMP_OFF) - { - if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) - { - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_LAMP_ON, 0); - } - } - else - { - if (!AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) - { - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_LAMP_OFF, 0); - } - } -} - - - - - -void cRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) - { - m_World.BroadcastSoundEffect("random.fuse", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); - m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - } -} - - - - - -void cRedstoneSimulator::HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) - { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) - { - cChunkInterface ChunkInterface(m_World.GetChunkMap()); - cBlockDoorHandler::ChangeDoor(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); - } - } - else - { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) - { - cChunkInterface ChunkInterface(m_World.GetChunkMap()); - cBlockDoorHandler::ChangeDoor(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); - } - } -} - - - - - -void cRedstoneSimulator::HandleCommandBlock(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - class cSetPowerToCommandBlock : - public cCommandBlockCallback - { - bool m_IsPowered; - public: - cSetPowerToCommandBlock(bool a_IsPowered) : m_IsPowered(a_IsPowered) {} - - virtual bool Item(cCommandBlockEntity * a_CommandBlock) override - { - a_CommandBlock->SetRedstonePower(m_IsPowered); - return false; - } - } CmdBlockSP (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)); - - m_World.DoWithCommandBlockAt(a_BlockX, a_BlockY, a_BlockZ, CmdBlockSP); -} - - - - - -void cRedstoneSimulator::HandleRail(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType) -{ - switch (a_MyType) - { - case E_BLOCK_DETECTOR_RAIL: - { - if ((m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x08) == 0x08) - { - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, a_MyType); - } - break; - } - case E_BLOCK_ACTIVATOR_RAIL: - case E_BLOCK_POWERED_RAIL: - { - if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) - { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); - } - else - { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07); - } - break; - } - default: LOGD("Unhandled type of rail in %s", __FUNCTION__); - } -} - - - - - -void cRedstoneSimulator::HandleTrapdoor(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) - { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) - { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x4); - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); - } - } - else - { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) - { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0xB); // Take into account that the fourth bit is needed for trapdoors too - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); - } - } -} - - - - - -void cRedstoneSimulator::HandleNoteBlock(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - bool m_bAreCoordsPowered = AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ); - - if (m_bAreCoordsPowered) - { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) - { - class cSetPowerToNoteBlock : - public cNoteBlockCallback - { - bool m_IsPowered; - public: - cSetPowerToNoteBlock(bool a_IsPowered) : m_IsPowered(a_IsPowered) {} - - virtual bool Item(cNoteEntity * a_NoteBlock) override - { - if (m_IsPowered) - { - a_NoteBlock->MakeSound(); - } - return false; - } - } NoteBlockSP(m_bAreCoordsPowered); - - m_World.DoWithNoteBlockAt(a_BlockX, a_BlockY, a_BlockZ, NoteBlockSP); - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); - } - } - else - { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) - { - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); - } - } -} - - - - - -void cRedstoneSimulator::HandleDaylightSensor(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - int a_ChunkX, a_ChunkZ; - cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, a_ChunkX, a_ChunkZ); - - if (!m_World.IsChunkLighted(a_ChunkX, a_ChunkZ)) - { - m_World.QueueLightChunk(a_ChunkX, a_ChunkZ); - } - else - { - NIBBLETYPE SkyLight = m_World.GetBlockSkyLight(a_BlockX, a_BlockY + 1, a_BlockZ) - m_World.GetSkyDarkness(); - if (SkyLight > 8) - { - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_DAYLIGHT_SENSOR); - } - } -} - - - - - -void cRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType) -{ - switch (a_MyType) - { - case E_BLOCK_STONE_PRESSURE_PLATE: - { - // MCS feature - stone pressure plates can only be triggered by players :D - cPlayer * a_Player = m_World.FindClosestPlayer(Vector3f(a_BlockX + 0.5f, (float)a_BlockY, a_BlockZ + 0.5f), 0.5f, false); - - if (a_Player != NULL) - { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x1); - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_STONE_PRESSURE_PLATE); - } - else - { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x0); - m_World.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); - } - break; - } - case E_BLOCK_WOODEN_PRESSURE_PLATE: - { - class cWoodenPressurePlateCallback : - public cEntityCallback - { - public: - cWoodenPressurePlateCallback(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : - m_Entity(NULL), - m_World(a_World), - m_X(a_BlockX), - m_Y(a_BlockY), - m_Z(a_BlockZ) - { - } - - virtual bool Item(cEntity * a_Entity) override - { - Vector3f EntityPos = a_Entity->GetPosition(); - Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f); - float Distance = (EntityPos - BlockPos).Length(); - - if (Distance < 0.5) - { - m_Entity = a_Entity; - return true; // Break out, we only need to know for wooden plates that at least one entity is on top - } - return false; - } - - bool FoundEntity(void) const - { - return m_Entity != NULL; - } - - protected: - cEntity * m_Entity; - cWorld * m_World; - - int m_X; - int m_Y; - int m_Z; - } ; - - cWoodenPressurePlateCallback WoodenPressurePlateCallback(a_BlockX, a_BlockY, a_BlockZ, &m_World); - m_World.ForEachEntity(WoodenPressurePlateCallback); - - if (WoodenPressurePlateCallback.FoundEntity()) - { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x1); - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_WOODEN_PRESSURE_PLATE); - } - else - { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x0); - m_World.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); - } - break; - } - default: - LOGD("Unimplemented pressure plate type %s in cRedstoneSimulator", ItemToFullString(a_MyType).c_str()); - break; - } -} - - - - - -bool cRedstoneSimulator::AreCoordsDirectlyPowered(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) // Check powered list - { - if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - return true; - } - } - return false; -} - - - - - -bool cRedstoneSimulator::AreCoordsLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) // Check linked powered list - { - if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - return true; - } - } - return false; -} - - - - - -bool cRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) -{ - // Repeaters cannot be powered by any face except their back; verify that this is true for a source - - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - - switch (a_Meta) - { - case 0x0: - { - // Flip the coords to check the back of the repeater - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } - break; - } - case 0x1: - { - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } - break; - } - case 0x2: - { - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } - break; - } - case 0x3: - { - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } - break; - } - } - } - - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - - switch (a_Meta) - { - case 0x0: - { - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } - break; - } - case 0x1: - { - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } - break; - } - case 0x2: - { - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } - break; - } - case 0x3: - { - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } - break; - } - } - } - return false; // Couldn't find power source behind repeater -} - - - - -bool cRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) -{ - // Pistons cannot be powered through their front face; this function verifies that a source meets this requirement - - int OldX = a_BlockX, OldY = a_BlockY, OldZ = a_BlockZ; - eBlockFace Face = cPiston::MetaDataToDirection(a_Meta); - - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, Face); - - if (!itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - return true; - } - - a_BlockX = OldX; - a_BlockY = OldY; - a_BlockZ = OldZ; - } - - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, Face); - - if (!itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - return true; - } - - a_BlockX = OldX; - a_BlockY = OldY; - a_BlockZ = OldZ; - } - return false; // Source was in front of the piston's front face -} - - - - -bool cRedstoneSimulator::IsWirePowered(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - - if (m_World.GetBlock(itr->a_SourcePos) != E_BLOCK_REDSTONE_WIRE) - { - return true; - } - } - - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - - if (m_World.GetBlock(itr->a_SourcePos) != E_BLOCK_REDSTONE_WIRE) - { - return true; - } - } - return false; // Source was in front of the piston's front face -} - - - - - -bool cRedstoneSimulator::AreCoordsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool IsCurrentStatePowered) -{ - for (SimulatedPlayerToggleableList::const_iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end(); ++itr) - { - if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - if (itr->WasLastStatePowered != IsCurrentStatePowered) // Was the last power state different to the current? - { - return false; // It was, coordinates are no longer simulated - } - else - { - return true; // It wasn't, don't resimulate block, and allow players to toggle - } - } - } - return false; // Block wasn't even in the list, not simulated -} - - - - - -void cRedstoneSimulator::SetDirectionLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Direction, BLOCKTYPE a_SourceType) -{ - switch (a_Direction) - { - case BLOCK_FACE_XM: - { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ); - - SetBlockLinkedPowered(a_BlockX - 2, a_BlockY, a_BlockZ, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY + 1, a_BlockZ, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY - 1, a_BlockZ, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ + 1, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ - 1, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - - break; - } - case BLOCK_FACE_XP: - { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ); - - SetBlockLinkedPowered(a_BlockX + 2, a_BlockY, a_BlockZ, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY + 1, a_BlockZ, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY - 1, a_BlockZ, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ + 1, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ - 1, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - - break; - } - case BLOCK_FACE_YM: - { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); - - SetBlockLinkedPowered(a_BlockX, a_BlockY - 2, a_BlockZ, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ + 1, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ - 1, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - - break; - } - case BLOCK_FACE_YP: - { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ); - - SetBlockLinkedPowered(a_BlockX, a_BlockY + 2, a_BlockZ, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ + 1, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ - 1, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - - break; - } - case BLOCK_FACE_ZM: - { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1); - - SetBlockLinkedPowered(a_BlockX, a_BlockY, a_BlockZ - 2, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - - break; - } - case BLOCK_FACE_ZP: - { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1); - - SetBlockLinkedPowered(a_BlockX, a_BlockY, a_BlockZ + 2, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - - break; - } - default: - { - ASSERT(!"Unhandled face direction when attempting to set blocks as linked powered!"); // Zombies, that wasn't supposed to happen... - break; - } - } -} - - - - - -void cRedstoneSimulator::SetAllDirsAsPowered(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_SourceBlock) -{ - static const struct - { - int x, y, z; - } gCrossCoords[] = - { - { 1, 0, 0 }, - {-1, 0, 0 }, - { 0, 0, 1 }, - { 0, 0,-1 }, - { 0, 1, 0 }, - { 0,-1, 0 } - }; - - for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) // Loop through struct to power all directions - { - SetBlockPowered(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, a_SourceBlock); - } -} - - - - - -void cRedstoneSimulator::SetBlockPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock) -{ - BLOCKTYPE Block = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ); - if (Block == E_BLOCK_AIR) - { - // Don't set air, fixes some bugs (wires powering themselves) - return; - } - - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) // Check powered list - { - if ( - itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)) && - itr->a_SourcePos.Equals(Vector3i(a_SourceX, a_SourceY, a_SourceZ)) - ) - { - // Check for duplicates - return; - } - } - - sPoweredBlocks RC; - RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); - RC.a_SourcePos = Vector3i(a_SourceX, a_SourceY, a_SourceZ); - m_PoweredBlocks.push_back(RC); -} - - - - - -void cRedstoneSimulator::SetBlockLinkedPowered( - int a_BlockX, int a_BlockY, int a_BlockZ, - int a_MiddleX, int a_MiddleY, int a_MiddleZ, - int a_SourceX, int a_SourceY, int a_SourceZ, - BLOCKTYPE a_SourceBlock, BLOCKTYPE a_MiddleBlock -) -{ - BLOCKTYPE DestBlock = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ); - if (DestBlock == E_BLOCK_AIR) - { - // Don't set air, fixes some bugs (wires powering themselves) - return; - } - if (!IsViableMiddleBlock(a_MiddleBlock)) - { - return; - } - - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) // Check linked powered list - { - if ( - itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)) && - itr->a_MiddlePos.Equals(Vector3i(a_MiddleX, a_MiddleY, a_MiddleZ)) && - itr->a_SourcePos.Equals(Vector3i(a_SourceX, a_SourceY, a_SourceZ)) - ) - { - // Check for duplicates - return; - } - } - - sLinkedPoweredBlocks RC; - RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); - RC.a_MiddlePos = Vector3i(a_MiddleX, a_MiddleY, a_MiddleZ); - RC.a_SourcePos = Vector3i(a_SourceX, a_SourceY, a_SourceZ); - m_LinkedPoweredBlocks.push_back(RC); -} - - - - - -void cRedstoneSimulator::SetPlayerToggleableBlockAsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool WasLastStatePowered) -{ - for (SimulatedPlayerToggleableList::iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - continue; - } - - if (itr->WasLastStatePowered != WasLastStatePowered) - { - // If power states different, update listing - itr->WasLastStatePowered = WasLastStatePowered; - return; - } - else - { - // If states the same, just ignore - return; - } - } - - // We have arrive here; no block must be in list - add one - sSimulatedPlayerToggleableList RC; - RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); - RC.WasLastStatePowered = WasLastStatePowered; - m_SimulatedPlayerToggleableBlocks.push_back(RC); -} - - - - - -void cRedstoneSimulator::QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta, short a_ElapsedTicks, bool ShouldPowerOn) -{ - for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); ++itr) - { - if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) - { - if (ShouldPowerOn == itr->ShouldPowerOn) // We are queued already for the same thing, don't replace entry - { - return; - } - - // Already in here (normal to allow repeater to continue on powering and updating blocks in front) - just update info and quit - itr->a_DelayTicks = (((a_Meta & 0xC) >> 0x2) + (ShouldPowerOn ? 1 : 0)) * 2; // See below for description - itr->a_ElapsedTicks = 0; - itr->ShouldPowerOn = ShouldPowerOn; - return; - } - } - - // Self not in list, add self to list - sRepeatersDelayList RC; - RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); - - // Gets the top two bits (delay time), shifts them into the lower two bits, and adds one (meta 0 = 1 tick; 1 = 2 etc.) - // * 2 because apparently, MCS ticks are way faster than vanilla ticks, so repeater aren't noticeably delayed - // We don't +1 when powering off because everything seems to already delay a tick when powering off, why? No idea :P - RC.a_DelayTicks = (((a_Meta & 0xC) >> 0x2) + (ShouldPowerOn ? 1 : 0)) * 2; - - - RC.a_ElapsedTicks = 0; - RC.ShouldPowerOn = ShouldPowerOn; - m_RepeatersDelayList.push_back(RC); - return; -} - - - - - -cRedstoneSimulator::eRedstoneDirection cRedstoneSimulator::GetWireDirection(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - int Dir = REDSTONE_NONE; - - BLOCKTYPE NegX = m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ); - if (IsPotentialSource(NegX)) - { - Dir |= (REDSTONE_X_POS); - } - - BLOCKTYPE PosX = m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ); - if (IsPotentialSource(PosX)) - { - Dir |= (REDSTONE_X_NEG); - } - - BLOCKTYPE NegZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1); - if (IsPotentialSource(NegZ)) - { - if ((Dir & REDSTONE_X_POS) && !(Dir & REDSTONE_X_NEG)) // corner - { - Dir ^= REDSTONE_X_POS; - Dir |= REDSTONE_X_NEG; - } - if ((Dir & REDSTONE_X_NEG) && !(Dir & REDSTONE_X_POS)) // corner - { - Dir ^= REDSTONE_X_NEG; - Dir |= REDSTONE_X_POS; - } - Dir |= REDSTONE_Z_POS; - } - - BLOCKTYPE PosZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1); - if (IsPotentialSource(PosZ)) - { - if ((Dir & REDSTONE_X_POS) && !(Dir & REDSTONE_X_NEG)) // corner - { - Dir ^= REDSTONE_X_POS; - Dir |= REDSTONE_X_NEG; - } - if ((Dir & REDSTONE_X_NEG) && !(Dir & REDSTONE_X_POS)) // corner - { - Dir ^= REDSTONE_X_NEG; - Dir |= REDSTONE_X_POS; - } - Dir |= REDSTONE_Z_NEG; - } - return (eRedstoneDirection)Dir; -} - - - - - -bool cRedstoneSimulator::IsLeverOn(NIBBLETYPE a_BlockMeta) -{ - // Extract the ON bit from metadata and return if true if it is set: - return ((a_BlockMeta & 0x8) == 0x8); -} - - - - - -bool cRedstoneSimulator::IsButtonOn(NIBBLETYPE a_BlockMeta) -{ - return IsLeverOn(a_BlockMeta); -} - - - - diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index c5ab1b9bb..b3e20c9a5 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -1,263 +1,17 @@ #pragma once -#include "RedstoneManager.h" - -/// Per-chunk data for the simulator, specified individual chunks to simulate; 'Data' is not used -typedef cCoordWithBlockAndBoolVector cRedstoneSimulatorChunkData; - +#include "Simulator.h" class cRedstoneSimulator : - public cRedstoneManager + public cSimulator { - typedef cRedstoneManager super; + typedef cSimulator super; + public: - cRedstoneSimulator(cWorld & a_World); - ~cRedstoneSimulator(); - - virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} // not used - virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; - virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override { return IsRedstone(a_BlockType); } - - enum eRedstoneDirection - { - REDSTONE_NONE = 0, - REDSTONE_X_POS = 0x1, - REDSTONE_X_NEG = 0x2, - REDSTONE_Z_POS = 0x4, - REDSTONE_Z_NEG = 0x8, - }; - eRedstoneDirection GetWireDirection(int a_BlockX, int a_BlockY, int a_BlockZ); - -private: - - struct sPoweredBlocks // Define structure of the directly powered blocks list - { - Vector3i a_BlockPos; // Position of powered block - Vector3i a_SourcePos; // Position of source powering the block at a_BlockPos - }; - - struct sLinkedPoweredBlocks // Define structure of the indirectly powered blocks list (i.e. repeaters powering through a block to the block at the other side) - { - Vector3i a_BlockPos; - Vector3i a_MiddlePos; - Vector3i a_SourcePos; - }; - - struct sSimulatedPlayerToggleableList - { - Vector3i a_BlockPos; - bool WasLastStatePowered; - }; - - struct sRepeatersDelayList - { - Vector3i a_BlockPos; - short a_DelayTicks; - short a_ElapsedTicks; - bool ShouldPowerOn; - }; - - typedef std::vector PoweredBlocksList; - typedef std::vector LinkedBlocksList; - typedef std::vector SimulatedPlayerToggleableList; - typedef std::vector RepeatersDelayList; - - PoweredBlocksList m_PoweredBlocks; - LinkedBlocksList m_LinkedPoweredBlocks; - SimulatedPlayerToggleableList m_SimulatedPlayerToggleableBlocks; - RepeatersDelayList m_RepeatersDelayList; - - virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override; - - // We want a_MyState for devices needing a full FastSetBlock (as opposed to meta) because with our simulation model, we cannot keep setting the block if it is already set correctly - // In addition to being non-performant, it would stop the player from actually breaking said device - - /* ====== SOURCES ====== */ - /** Handles the redstone torch */ - void HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState); - /** Handles the redstone block */ - void HandleRedstoneBlock(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Handles levers */ - void HandleRedstoneLever(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Handles buttons */ - void HandleRedstoneButton(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType); - /** Handles daylight sensors */ - void HandleDaylightSensor(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Handles pressure plates */ - void HandlePressurePlate(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType); - /* ==================== */ - - /* ====== CARRIERS ====== */ - /** Handles redstone wire */ - void HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Handles repeaters */ - void HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState); - /* ====================== */ - - /* ====== DEVICES ====== */ - /** Handles pistons */ - void HandlePiston(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Handles dispensers and droppers */ - void HandleDropSpenser(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Handles TNT (exploding) */ - void HandleTNT(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Handles redstone lamps */ - void HandleRedstoneLamp(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState); - /** Handles doords */ - void HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Handles command blocks */ - void HandleCommandBlock(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Handles activator, detector, and powered rails */ - void HandleRail(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType); - /** Handles trapdoors */ - void HandleTrapdoor(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Handles noteblocks */ - void HandleNoteBlock(int a_BlockX, int a_BlockY, int a_BlockZ); - /* ===================== */ - - /* ====== Helper functions ====== */ - /** Marks a block as powered */ - void SetBlockPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock); - /** Marks a block as being powered through another block */ - void SetBlockLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_MiddleX, int a_MiddleY, int a_MiddleZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock, BLOCKTYPE a_MiddeBlock); - /** Marks a block as simulated, who should not be simulated further unless their power state changes, to accomodate a player manually toggling the block without triggering the simulator toggling it back */ - void SetPlayerToggleableBlockAsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool WasLastStatePowered); - /** Marks the second block in a direction as linked powered */ - void SetDirectionLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Direction, BLOCKTYPE a_SourceBlock); - /** Marks all blocks immediately surrounding a coordinate as powered */ - void SetAllDirsAsPowered(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_SourceBlock); - /** Queues a repeater to be powered or unpowered */ - void QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta, short a_ElapsedTicks, bool ShouldPowerOn); - - /** Returns if a coordinate is powered or linked powered */ - bool AreCoordsPowered(int a_BlockX, int a_BlockY, int a_BlockZ) { return AreCoordsDirectlyPowered(a_BlockX, a_BlockY, a_BlockZ) || AreCoordsLinkedPowered(a_BlockX, a_BlockY, a_BlockZ); } - /** Returns if a coordinate is in the directly powered blocks list */ - bool AreCoordsDirectlyPowered(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Returns if a coordinate is in the indirectly powered blocks list */ - bool AreCoordsLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Returns if a coordinate was marked as simulated (for blocks toggleable by players) */ - bool AreCoordsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool IsCurrentStatePowered); - /** Returns if a repeater is powered */ - bool IsRepeaterPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); - /** Returns if a piston is powered */ - bool IsPistonPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); - /** Returns if a wire is powered - The only diffence between this and a normal AreCoordsPowered is that this function checks for a wire powering another wire - */ - bool IsWirePowered(int a_BlockX, int a_BlockY, int a_BlockZ); - - - /** Returns if lever metadata marks it as emitting power */ - bool IsLeverOn(NIBBLETYPE a_BlockMeta); - /** Returns if button metadata marks it as emitting power */ - bool IsButtonOn(NIBBLETYPE a_BlockMeta); - /* ============================== */ - - /* ====== Misc Functions ====== */ - /** Returns if a block is viable to be the MiddleBlock of a SetLinkedPowered operation */ - inline static bool IsViableMiddleBlock(BLOCKTYPE Block) { return g_BlockFullyOccupiesVoxel[Block]; } - - /** Returns if a block is a mechanism (something that accepts power and does something) */ - inline static bool IsMechanism(BLOCKTYPE Block) - { - switch (Block) - { - case E_BLOCK_ACTIVATOR_RAIL: - case E_BLOCK_COMMAND_BLOCK: - case E_BLOCK_PISTON: - case E_BLOCK_STICKY_PISTON: - case E_BLOCK_DISPENSER: - case E_BLOCK_DROPPER: - case E_BLOCK_FENCE_GATE: - case E_BLOCK_HOPPER: - case E_BLOCK_NOTE_BLOCK: - case E_BLOCK_TNT: - case E_BLOCK_TRAPDOOR: - case E_BLOCK_REDSTONE_LAMP_OFF: - case E_BLOCK_REDSTONE_LAMP_ON: - case E_BLOCK_WOODEN_DOOR: - case E_BLOCK_IRON_DOOR: - case E_BLOCK_REDSTONE_REPEATER_OFF: - case E_BLOCK_REDSTONE_REPEATER_ON: - case E_BLOCK_POWERED_RAIL: - { - return true; - } - default: return false; - } - } - - /** Returns if a block has the potential to output power */ - inline static bool IsPotentialSource(BLOCKTYPE Block) - { - switch (Block) - { - case E_BLOCK_DETECTOR_RAIL: - case E_BLOCK_DAYLIGHT_SENSOR: - case E_BLOCK_WOODEN_BUTTON: - case E_BLOCK_STONE_BUTTON: - case E_BLOCK_REDSTONE_WIRE: - case E_BLOCK_REDSTONE_TORCH_ON: - case E_BLOCK_LEVER: - case E_BLOCK_REDSTONE_REPEATER_ON: - case E_BLOCK_BLOCK_OF_REDSTONE: - case E_BLOCK_ACTIVE_COMPARATOR: - { - return true; - } - default: return false; - } - } - /** Returns if a block is any sort of redstone device */ - inline static bool IsRedstone(BLOCKTYPE Block) - { - switch (Block) - { - // All redstone devices, please alpha sort - case E_BLOCK_ACTIVATOR_RAIL: - case E_BLOCK_ACTIVE_COMPARATOR: - case E_BLOCK_BLOCK_OF_REDSTONE: - case E_BLOCK_COMMAND_BLOCK: - case E_BLOCK_DETECTOR_RAIL: - case E_BLOCK_DISPENSER: - case E_BLOCK_DAYLIGHT_SENSOR: - case E_BLOCK_DROPPER: - case E_BLOCK_FENCE_GATE: - case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: - case E_BLOCK_HOPPER: - case E_BLOCK_INACTIVE_COMPARATOR: - case E_BLOCK_IRON_DOOR: - case E_BLOCK_LEVER: - case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: - case E_BLOCK_NOTE_BLOCK: - case E_BLOCK_POWERED_RAIL: - case E_BLOCK_REDSTONE_LAMP_OFF: - case E_BLOCK_REDSTONE_LAMP_ON: - case E_BLOCK_REDSTONE_REPEATER_OFF: - case E_BLOCK_REDSTONE_REPEATER_ON: - case E_BLOCK_REDSTONE_TORCH_OFF: - case E_BLOCK_REDSTONE_TORCH_ON: - case E_BLOCK_REDSTONE_WIRE: - case E_BLOCK_STICKY_PISTON: - case E_BLOCK_STONE_BUTTON: - case E_BLOCK_STONE_PRESSURE_PLATE: - case E_BLOCK_TNT: - case E_BLOCK_TRAPDOOR: - case E_BLOCK_TRIPWIRE_HOOK: - case E_BLOCK_WOODEN_BUTTON: - case E_BLOCK_WOODEN_DOOR: - case E_BLOCK_WOODEN_PRESSURE_PLATE: - case E_BLOCK_PISTON: - { - return true; - } - default: return false; - } - } -}; +} ; diff --git a/src/World.cpp b/src/World.cpp index 1343d5ad6..a02767575 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -31,7 +31,7 @@ #include "Simulator/NoopFluidSimulator.h" #include "Simulator/NoopRedstoneSimulator.h" #include "Simulator/SandSimulator.h" -#include "Simulator/RedstoneSimulator.h" +#include "Simulator/IncrementalRedstoneSimulator.h" #include "Simulator/VaporizeFluidSimulator.h" // Mobs: @@ -2871,27 +2871,23 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul -cRedstoneManager * cWorld::InitializeRedstoneSimulator(cIniFile & a_IniFile) +cRedstoneSimulator * cWorld::InitializeRedstoneSimulator(cIniFile & a_IniFile) { AString SimulatorName = a_IniFile.GetValueSet("Physics", "RedstoneSimulator", ""); if (SimulatorName.empty()) { - LOGWARNING("[Physics] RedstoneSimulator not present or empty in %s, using the default of \"Floody\".", GetIniFileName().c_str()); - SimulatorName = "redstone"; + LOGWARNING("[Physics] RedstoneSimulator not present or empty in %s, using the default of \"incremental\".", GetIniFileName().c_str()); + SimulatorName = "incremental"; } - cRedstoneManager * res = NULL; + cRedstoneSimulator * res = NULL; - if ( - (NoCaseCompare(SimulatorName, "redstone") == 0) - ) + if (NoCaseCompare(SimulatorName, "incremental") == 0) { - res = new cRedstoneSimulator(*this); + res = new cIncrementalRedstoneSimulator(*this); } - else if ( - (NoCaseCompare(SimulatorName, "noop") == 0) - ) + else if (NoCaseCompare(SimulatorName, "noop") == 0) { res = new cRedstoneNoopSimulator(*this); } diff --git a/src/World.h b/src/World.h index bc4e411cc..d436e7adf 100644 --- a/src/World.h +++ b/src/World.h @@ -33,7 +33,7 @@ class cFireSimulator; class cFluidSimulator; class cSandSimulator; -class cRedstoneManager; +class cRedstoneSimulator; class cItem; class cPlayer; class cClientHandle; @@ -432,7 +432,7 @@ public: inline cFluidSimulator * GetWaterSimulator(void) { return m_WaterSimulator; } inline cFluidSimulator * GetLavaSimulator (void) { return m_LavaSimulator; } - inline cRedstoneManager * GetRedstoneSimulator(void) { return m_RedstoneSimulator; } + inline cRedstoneSimulator * GetRedstoneSimulator(void) { return m_RedstoneSimulator; } /** Calls the callback for each block entity in the specified chunk; returns true if all block entities processed, false if the callback aborted by returning true */ bool ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback & a_Callback); // Exported in ManualBindings.cpp @@ -759,7 +759,7 @@ private: cFluidSimulator * m_WaterSimulator; cFluidSimulator * m_LavaSimulator; cFireSimulator * m_FireSimulator; - cRedstoneManager * m_RedstoneSimulator; + cRedstoneSimulator * m_RedstoneSimulator; cCriticalSection m_CSPlayers; cPlayerList m_Players; @@ -860,7 +860,7 @@ private: cFluidSimulator * InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock); /** Creates a new redstone simulator.*/ - cRedstoneManager * InitializeRedstoneSimulator(cIniFile & a_IniFile); + cRedstoneSimulator * InitializeRedstoneSimulator(cIniFile & a_IniFile); }; // tolua_export -- cgit v1.2.3 From 53475e36d593455ee46f0079f5f9661753d958b7 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 8 Feb 2014 11:20:00 +0100 Subject: Fixed comment. --- src/World.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/World.cpp b/src/World.cpp index a02767575..ebdd3fb06 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -599,7 +599,7 @@ void cWorld::Start(void) m_FireSimulator = new cFireSimulator(*this, IniFile); m_RedstoneSimulator = InitializeRedstoneSimulator(IniFile); - // Water, Lava and Redstone simulators get registered in InitializeFluidSimulator() + // Water, Lava and Redstone simulators get registered in their initialize function. m_SimulatorManager->RegisterSimulator(m_SandSimulator, 1); m_SimulatorManager->RegisterSimulator(m_FireSimulator, 1); -- cgit v1.2.3 From cfd6875c864570e85a8ac64f3abd8d65f2d47e05 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 8 Feb 2014 13:35:08 +0100 Subject: Fixed cWorld:TryGetHeight() API. --- src/Bindings/ManualBindings.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index d476a3156..841ec5cf2 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -906,8 +906,12 @@ static int tolua_cWorld_TryGetHeight(lua_State * tolua_S) { int Height = 0; bool res = self->TryGetHeight(BlockX, BlockZ, Height); - tolua_pushnumber(tolua_S, Height); tolua_pushboolean(tolua_S, res ? 1 : 0); + if (res) + { + tolua_pushnumber(tolua_S, Height); + return 2; + } } } return 1; -- cgit v1.2.3 From ea71bfa9b645cda80b7d4364c675ebaee8db8353 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 8 Feb 2014 21:55:21 +0100 Subject: Initial ChunkStay code. --- src/Chunk.cpp | 1 - src/Chunk.h | 110 +++++++++++++-------------- src/ChunkDef.h | 1 + src/ChunkMap.cpp | 185 ++++++++++++++++++--------------------------- src/ChunkMap.h | 199 ++++++++++++++++++++++--------------------------- src/ChunkStay.cpp | 136 +++++++++++++++++++++++++++++++++ src/ChunkStay.h | 92 +++++++++++++++++++++++ src/LightingThread.cpp | 151 ++++++++++++++++++------------------- src/LightingThread.h | 76 ++++++++++--------- src/World.cpp | 12 --- src/World.h | 3 - 11 files changed, 560 insertions(+), 406 deletions(-) create mode 100644 src/ChunkStay.cpp create mode 100644 src/ChunkStay.h diff --git a/src/Chunk.cpp b/src/Chunk.cpp index b48bfe65e..3028d24d0 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -422,7 +422,6 @@ bool cChunk::HasBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ) -/// Sets or resets the internal flag that prevents chunk from being unloaded void cChunk::Stay(bool a_Stay) { m_StayCount += (a_Stay ? 1 : -1); diff --git a/src/Chunk.h b/src/Chunk.h index 3dc83b157..93eba217e 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -85,10 +85,10 @@ public: void MarkLoaded(void); // Marks the chunk as freshly loaded. Fails if the chunk is already valid void MarkLoadFailed(void); // Marks the chunk as failed to load. Ignored is the chunk is already valid - /// Gets all chunk data, calls the a_Callback's methods for each data type + /** Gets all chunk data, calls the a_Callback's methods for each data type */ void GetAllData(cChunkDataCallback & a_Callback); - /// Sets all chunk data + /** Sets all chunk data */ void SetAllData( const BLOCKTYPE * a_BlockTypes, const NIBBLETYPE * a_BlockMeta, @@ -104,27 +104,29 @@ public: const cChunkDef::BlockNibbles & a_SkyLight ); - /// Copies m_BlockData into a_BlockTypes, only the block types + /** Copies m_BlockData into a_BlockTypes, only the block types */ void GetBlockTypes(BLOCKTYPE * a_BlockTypes); - /// Writes the specified cBlockArea at the coords specified. Note that the coords may extend beyond the chunk! + /** Writes the specified cBlockArea at the coords specified. Note that the coords may extend beyond the chunk! */ void WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes); - /// Returns true if there is a block entity at the coords specified + /** Returns true if there is a block entity at the coords specified */ bool HasBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ); - /// Sets or resets the internal flag that prevents chunk from being unloaded + /** Sets or resets the internal flag that prevents chunk from being unloaded. + The flag is cumulative - it can be set multiple times and then needs to be un-set that many times + before the chunk is unloadable again. */ void Stay(bool a_Stay = true); - /// Recence all mobs proximities to players in order to know what to do with them + /** Recence all mobs proximities to players in order to know what to do with them */ void CollectMobCensus(cMobCensus& toFill); - /// Try to Spawn Monsters inside chunk + /** Try to Spawn Monsters inside chunk */ void SpawnMobs(cMobSpawner& a_MobSpawner); void Tick(float a_Dt); - /// Ticks a single block. Used by cWorld::TickQueuedBlocks() to tick the queued blocks + /** Ticks a single block. Used by cWorld::TickQueuedBlocks() to tick the queued blocks */ void TickBlock(int a_RelX, int a_RelY, int a_RelZ); int GetPosX(void) const { return m_PosX; } @@ -137,13 +139,13 @@ public: // SetBlock() does a lot of work (heightmap, tickblocks, blockentities) so a BlockIdx version doesn't make sense void SetBlock( const Vector3i & a_RelBlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) { SetBlock( a_RelBlockPos.x, a_RelBlockPos.y, a_RelBlockPos.z, a_BlockType, a_BlockMeta ); } - /// Queues a block change till the specified world tick + /** Queues a block change till the specified world tick */ void QueueSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR); - /// Queues block for ticking (m_ToTickQueue) + /** Queues block for ticking (m_ToTickQueue) */ void QueueTickBlock(int a_RelX, int a_RelY, int a_RelZ); - /// Queues all 6 neighbors of the specified block for ticking (m_ToTickQueue). If any are outside the chunk, relays the checking to the proper neighboring chunk + /** Queues all 6 neighbors of the specified block for ticking (m_ToTickQueue). If any are outside the chunk, relays the checking to the proper neighboring chunk */ void QueueTickBlockNeighbors(int a_RelX, int a_RelY, int a_RelZ); void FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta ); // Doesn't force block updates on neighbors, use for simple changes such as grass growing etc. @@ -175,14 +177,14 @@ public: void CollectPickupsByPlayer(cPlayer * a_Player); - /// Sets the sign text. Returns true if successful. Also sends update packets to all clients in the chunk + /** Sets the sign text. Returns true if successful. Also sends update packets to all clients in the chunk */ bool SetSignLines(int a_RelX, int a_RelY, int a_RelZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4); int GetHeight( int a_X, int a_Z ); void SendBlockTo(int a_RelX, int a_RelY, int a_RelZ, cClientHandle * a_Client); - /// Adds a client to the chunk; returns true if added, false if already there + /** Adds a client to the chunk; returns true if added, false if already there */ bool AddClient (cClientHandle* a_Client ); void RemoveClient (cClientHandle* a_Client ); @@ -193,55 +195,55 @@ public: void RemoveEntity(cEntity * a_Entity); bool HasEntity(int a_EntityID); - /// Calls the callback for each entity; returns true if all entities processed, false if the callback aborted by returning true + /** Calls the callback for each entity; returns true if all entities processed, false if the callback aborted by returning true */ bool ForEachEntity(cEntityCallback & a_Callback); // Lua-accessible - /// Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found. + /** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found. */ bool DoWithEntityByID(int a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult); // Lua-accessible - /// Calls the callback for each block entity; returns true if all block entities processed, false if the callback aborted by returning true + /** Calls the callback for each block entity; returns true if all block entities processed, false if the callback aborted by returning true */ bool ForEachBlockEntity(cBlockEntityCallback & a_Callback); // Lua-accessible - /// Calls the callback for each chest; returns true if all chests processed, false if the callback aborted by returning true + /** Calls the callback for each chest; returns true if all chests processed, false if the callback aborted by returning true */ bool ForEachChest(cChestCallback & a_Callback); // Lua-accessible - /// Calls the callback for each dispenser; returns true if all dispensers processed, false if the callback aborted by returning true + /** Calls the callback for each dispenser; returns true if all dispensers processed, false if the callback aborted by returning true */ bool ForEachDispenser(cDispenserCallback & a_Callback); - /// Calls the callback for each dropper; returns true if all droppers processed, false if the callback aborted by returning true + /** Calls the callback for each dropper; returns true if all droppers processed, false if the callback aborted by returning true */ bool ForEachDropper(cDropperCallback & a_Callback); - /// Calls the callback for each dropspenser; returns true if all dropspensers processed, false if the callback aborted by returning true + /** Calls the callback for each dropspenser; returns true if all dropspensers processed, false if the callback aborted by returning true */ bool ForEachDropSpenser(cDropSpenserCallback & a_Callback); - /// Calls the callback for each furnace; returns true if all furnaces processed, false if the callback aborted by returning true + /** Calls the callback for each furnace; returns true if all furnaces processed, false if the callback aborted by returning true */ bool ForEachFurnace(cFurnaceCallback & a_Callback); // Lua-accessible - /// Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found + /** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */ bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible - /// Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found + /** Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found */ bool DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback); // Lua-acessible - /// Calls the callback for the dispenser at the specified coords; returns false if there's no dispenser at those coords or callback returns true, returns true if found + /** Calls the callback for the dispenser at the specified coords; returns false if there's no dispenser at those coords or callback returns true, returns true if found */ bool DoWithDispenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDispenserCallback & a_Callback); - /// Calls the callback for the dispenser at the specified coords; returns false if there's no dropper at those coords or callback returns true, returns true if found + /** Calls the callback for the dispenser at the specified coords; returns false if there's no dropper at those coords or callback returns true, returns true if found */ bool DoWithDropperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropperCallback & a_Callback); - /// Calls the callback for the dispenser at the specified coords; returns false if there's no dropspenser at those coords or callback returns true, returns true if found + /** Calls the callback for the dispenser at the specified coords; returns false if there's no dropspenser at those coords or callback returns true, returns true if found */ bool DoWithDropSpenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropSpenserCallback & a_Callback); - /// Calls the callback for the furnace at the specified coords; returns false if there's no furnace at those coords or callback returns true, returns true if found + /** Calls the callback for the furnace at the specified coords; returns false if there's no furnace at those coords or callback returns true, returns true if found */ bool DoWithFurnaceAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnaceCallback & a_Callback); // Lua-accessible - /// Calls the callback for the noteblock at the specified coords; returns false if there's no noteblock at those coords or callback returns true, returns true if found + /** Calls the callback for the noteblock at the specified coords; returns false if there's no noteblock at those coords or callback returns true, returns true if found */ bool DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNoteBlockCallback & a_Callback); - /// Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found + /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); - /// Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found + /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible void UseBlockEntity(cPlayer * a_Player, int a_X, int a_Y, int a_Z); // [x, y, z] in world block coords @@ -292,7 +294,7 @@ public: m_IsSaving = false; } - /// Sets the blockticking to start at the specified block. Only one blocktick may be set, second call overwrites the first call + /** Sets the blockticking to start at the specified block. Only one blocktick may be set, second call overwrites the first call */ inline void SetNextBlockTick(int a_RelX, int a_RelY, int a_RelZ) { m_BlockTickX = a_RelX; @@ -310,34 +312,34 @@ public: inline NIBBLETYPE GetBlockLight(int a_Idx) const {return cChunkDef::GetNibble(m_BlockLight, a_Idx); } inline NIBBLETYPE GetSkyLight (int a_Idx) const {return cChunkDef::GetNibble(m_BlockSkyLight, a_Idx); } - /// Same as GetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success + /** Same as GetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success */ bool UnboundedRelGetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; - /// Same as GetBlockType(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success + /** Same as GetBlockType(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success */ bool UnboundedRelGetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType) const; - /// Same as GetBlockMeta(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success + /** Same as GetBlockMeta(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success */ bool UnboundedRelGetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE & a_BlockMeta) const; - /// Same as GetBlockBlockLight(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success + /** Same as GetBlockBlockLight(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success */ bool UnboundedRelGetBlockBlockLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE & a_BlockLight) const; - /// Same as GetBlockSkyLight(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success + /** Same as GetBlockSkyLight(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success */ bool UnboundedRelGetBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE & a_SkyLight) const; - /// Queries both BlockLight and SkyLight, relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success + /** Queries both BlockLight and SkyLight, relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success */ bool UnboundedRelGetBlockLights(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE & a_BlockLight, NIBBLETYPE & a_SkyLight) const; - /// Same as SetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success + /** Same as SetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success */ bool UnboundedRelSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); - /// Same as FastSetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success + /** Same as FastSetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success */ bool UnboundedRelFastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); - /// Same as QueueTickBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s in such a case), ignores unsuccessful attempts + /** Same as QueueTickBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s in such a case), ignores unsuccessful attempts */ void UnboundedQueueTickBlock(int a_RelX, int a_RelY, int a_RelZ); - /// Light alterations based on time + /** Light alterations based on time */ NIBBLETYPE GetTimeAlteredLight(NIBBLETYPE a_Skylight) const; @@ -389,7 +391,7 @@ private: cEntityList m_Entities; cBlockEntityList m_BlockEntities; - /// Number of times the chunk has been requested to stay (by various cChunkStay objects); if zero, the chunk can be unloaded + /** Number of times the chunk has been requested to stay (by various cChunkStay objects); if zero, the chunk can be unloaded */ int m_StayCount; int m_PosX, m_PosY, m_PosZ; @@ -427,40 +429,40 @@ private: void RemoveBlockEntity(cBlockEntity * a_BlockEntity); void AddBlockEntity (cBlockEntity * a_BlockEntity); - /// Creates a block entity for each block that needs a block entity and doesn't have one in the list + /** Creates a block entity for each block that needs a block entity and doesn't have one in the list */ void CreateBlockEntities(void); - /// Wakes up each simulator for its specific blocks; through all the blocks in the chunk + /** Wakes up each simulator for its specific blocks; through all the blocks in the chunk */ void WakeUpSimulators(void); // Makes a copy of the list cClientHandleList GetAllClients(void) const {return m_LoadedByClient; } - /// Sends m_PendingSendBlocks to all clients + /** Sends m_PendingSendBlocks to all clients */ void BroadcastPendingBlockChanges(void); - /// Checks the block scheduled for checking in m_ToTickBlocks[] + /** Checks the block scheduled for checking in m_ToTickBlocks[] */ void CheckBlocks(); - /// Ticks several random blocks in the chunk + /** Ticks several random blocks in the chunk */ void TickBlocks(void); - /// Adds snow to the top of snowy biomes and hydrates farmland / fills cauldrons in rainy biomes + /** Adds snow to the top of snowy biomes and hydrates farmland / fills cauldrons in rainy biomes */ void ApplyWeatherToTop(void); - /// Grows sugarcane by the specified number of blocks, but no more than 3 blocks high (used by both bonemeal and ticking) + /** Grows sugarcane by the specified number of blocks, but no more than 3 blocks high (used by both bonemeal and ticking) */ void GrowSugarcane (int a_RelX, int a_RelY, int a_RelZ, int a_NumBlocks); - /// Grows cactus by the specified number of blocks, but no more than 3 blocks high (used by both bonemeal and ticking) + /** Grows cactus by the specified number of blocks, but no more than 3 blocks high (used by both bonemeal and ticking) */ void GrowCactus (int a_RelX, int a_RelY, int a_RelZ, int a_NumBlocks); - /// Grows a melon or a pumpkin next to the block specified (assumed to be the stem) + /** Grows a melon or a pumpkin next to the block specified (assumed to be the stem) */ void GrowMelonPumpkin(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, MTRand & a_Random); - /// Called by Tick() when an entity moves out of this chunk into a neighbor; moves the entity and sends spawn / despawn packet to clients + /** Called by Tick() when an entity moves out of this chunk into a neighbor; moves the entity and sends spawn / despawn packet to clients */ void MoveEntityToNewChunk(cEntity * a_Entity); - /// Processes all blocks that have been scheduled for replacement by the QueueSetBlock() function + /** Processes all blocks that have been scheduled for replacement by the QueueSetBlock() function */ void ProcessQueuedSetBlocks(void); }; diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 1c4aa6aca..f48dc4fd5 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -481,6 +481,7 @@ public: } ; typedef std::list cChunkCoordsList; +typedef std::vector cChunkCoordsVector; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 757396a20..a9f6bf00b 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -134,7 +134,7 @@ cChunkMap::cChunkLayer * cChunkMap::GetLayerForChunk(int a_ChunkX, int a_ChunkZ) -cChunkPtr cChunkMap::GetChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ ) +cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) { // No need to lock m_CSLayers, since it's already locked by the operation that called us ASSERT(m_CSLayers.IsLockedByCurrentThread()); @@ -897,17 +897,25 @@ void cChunkMap::SetChunkData( bool a_MarkDirty ) { - cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - if (Chunk == NULL) - { - return; - } - Chunk->SetAllData(a_BlockTypes, a_BlockMeta, a_BlockLight, a_BlockSkyLight, a_HeightMap, a_BiomeMap, a_BlockEntities); - - if (a_MarkDirty) { - Chunk->MarkDirty(); + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + if (Chunk == NULL) + { + return; + } + Chunk->SetAllData(a_BlockTypes, a_BlockMeta, a_BlockLight, a_BlockSkyLight, a_HeightMap, a_BiomeMap, a_BlockEntities); + + if (a_MarkDirty) + { + Chunk->MarkDirty(); + } + + // Notify relevant ChunkStays: + for (cChunkStays::iterator itr = m_ChunkStays.begin(), end = m_ChunkStays.end(); itr != end; ++itr) + { + (*itr)->ChunkAvailable(a_ChunkX, a_ChunkZ); + } // for itr - m_ChunkStays[] } // Notify plugins of the chunk becoming available @@ -2206,24 +2214,6 @@ bool cChunkMap::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const ASt -void cChunkMap::ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay) -{ - cCSLock Lock(m_CSLayers); - for (cChunkCoordsList::const_iterator itr = a_Chunks.begin(); itr != a_Chunks.end(); ++itr) - { - cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ); - if (Chunk == NULL) - { - continue; - } - Chunk->Stay(a_Stay); - } -} - - - - - void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSLayers); @@ -2810,12 +2800,16 @@ void cChunkMap::cChunkLayer::UnloadUnusedChunks(void) -void cChunkMap::FastSetBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +void cChunkMap::FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { cCSLock Lock(m_CSFastSetBlock); - m_FastSetBlockQueue.push_back(sSetBlock(a_X, a_Y, a_Z, a_BlockType, a_BlockMeta)); + m_FastSetBlockQueue.push_back(sSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta)); } + + + + void cChunkMap::FastSetQueuedBlocks() { // Asynchronously set blocks: @@ -2834,110 +2828,75 @@ void cChunkMap::FastSetQueuedBlocks() } -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cChunkStay: - -cChunkStay::cChunkStay(cWorld * a_World) : - m_World(a_World), - m_IsEnabled(false) -{ -} - - - - - -cChunkStay::~cChunkStay() -{ - Clear(); -} - - - - - -void cChunkStay::Clear(void) -{ - if (m_IsEnabled) - { - Disable(); - } - m_Chunks.clear(); -} - - -void cChunkStay::Add(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +void cChunkMap::AddChunkStay(cChunkStay & a_ChunkStay) { - ASSERT(!m_IsEnabled); - - for (cChunkCoordsList::const_iterator itr = m_Chunks.begin(); itr != m_Chunks.end(); ++itr) + cCSLock Lock(m_CSLayers); + + // Add it to the list: + ASSERT(std::find(m_ChunkStays.begin(), m_ChunkStays.end(), &a_ChunkStay) == m_ChunkStays.end()); // Has not yet been added + m_ChunkStays.push_back(&a_ChunkStay); + + // Schedule all chunks to be loaded / generated, and mark each as locked: + const cChunkCoordsVector & WantedChunks = a_ChunkStay.GetChunks(); + for (cChunkCoordsVector::const_iterator itr = WantedChunks.begin(); itr != WantedChunks.end(); ++itr) { - if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkY == a_ChunkY) && (itr->m_ChunkZ == a_ChunkZ)) + cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ); + if (Chunk == NULL) { - // Already present - return; + continue; } - } // for itr - Chunks[] - m_Chunks.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); + Chunk->Stay(true); + if (Chunk->IsValid()) + { + a_ChunkStay.ChunkAvailable(itr->m_ChunkX, itr->m_ChunkZ); + } + } // for itr - WantedChunks[] } -void cChunkStay::Remove(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +/** Removes the specified cChunkStay descendant from the internal list of ChunkStays. */ +void cChunkMap::DelChunkStay(cChunkStay & a_ChunkStay) { - ASSERT(!m_IsEnabled); - - for (cChunkCoordsList::iterator itr = m_Chunks.begin(); itr != m_Chunks.end(); ++itr) + cCSLock Lock(m_CSLayers); + + // Remove from the list of active chunkstays: + bool HasFound = false; + for (cChunkStays::iterator itr = m_ChunkStays.begin(), end = m_ChunkStays.end(); itr != end; ++itr) { - if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkY == a_ChunkY) && (itr->m_ChunkZ == a_ChunkZ)) + if (*itr == &a_ChunkStay) { - // Found, un-"stay" - m_Chunks.erase(itr); - return; + m_ChunkStays.erase(itr); + HasFound = true; + break; } - } // for itr - m_Chunks[] -} - - - - - -void cChunkStay::Enable(void) -{ - ASSERT(!m_IsEnabled); + } // for itr - m_ChunkStays[] - m_World->ChunksStay(*this, true); - m_IsEnabled = true; -} - - - - - -void cChunkStay::Load(void) -{ - for (cChunkCoordsList::iterator itr = m_Chunks.begin(); itr != m_Chunks.end(); ++itr) + if (!HasFound) + { + ASSERT(!"Removing a cChunkStay that hasn't been added!"); + return; + } + + // Unmark all contained chunks: + const cChunkCoordsVector & Chunks = a_ChunkStay.GetChunks(); + for (cChunkCoordsVector::const_iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr) { - m_World->TouchChunk(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ); - } // for itr - m_Chunks[] + cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ); + if (Chunk == NULL) + { + continue; + } + Chunk->Stay(false); + } // for itr - Chunks[] } -void cChunkStay::Disable(void) -{ - ASSERT(m_IsEnabled); - - m_World->ChunksStay(*this, false); - m_IsEnabled = false; -} - - - diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 62c74d81c..d713d0cf5 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -85,19 +85,19 @@ public: void BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); void BroadcastUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ); - /// Sends the block entity, if it is at the coords specified, to a_Client + /** Sends the block entity, if it is at the coords specified, to a_Client */ void SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle & a_Client); - /// a_Player rclked block entity at the coords specified, handle it + /** a_Player rclked block entity at the coords specified, handle it */ void UseBlockEntity(cPlayer * a_Player, int a_X, int a_Y, int a_Z); - /// Calls the callback for the chunk specified, with ChunkMapCS locked; returns false if the chunk doesn't exist, otherwise returns the same value as the callback + /** Calls the callback for the chunk specified, with ChunkMapCS locked; returns false if the chunk doesn't exist, otherwise returns the same value as the callback */ bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback & a_Callback); - /// Wakes up simulators for the specified block + /** Wakes up simulators for the specified block */ void WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ); - /// Wakes up the simulators for the specified area of blocks + /** Wakes up the simulators for the specified area of blocks */ void WakeUpSimulatorsInArea(int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ); void MarkChunkDirty (int a_ChunkX, int a_ChunkZ); @@ -130,7 +130,7 @@ public: bool GetChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataCallback & a_Callback); - /// Copies the chunk's blocktypes into a_Blocks; returns true if successful + /** Copies the chunk's blocktypes into a_Blocks; returns true if successful */ bool GetChunkBlockTypes (int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_Blocks); bool IsChunkValid (int a_ChunkX, int a_ChunkZ); @@ -153,154 +153,151 @@ public: bool GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); bool GetBlockInfo (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight); - /// Replaces world blocks with a_Blocks, if they are of type a_FilterBlockType + /** Replaces world blocks with a_Blocks, if they are of type a_FilterBlockType */ void ReplaceBlocks(const sSetBlockVector & a_Blocks, BLOCKTYPE a_FilterBlockType); - /// Special function used for growing trees, replaces only blocks that tree may overwrite + /** Special function used for growing trees, replaces only blocks that tree may overwrite */ void ReplaceTreeBlocks(const sSetBlockVector & a_Blocks); EMCSBiome GetBiomeAt (int a_BlockX, int a_BlockZ); - /// Retrieves block types of the specified blocks. If a chunk is not loaded, doesn't modify the block. Returns true if all blocks were read. + /** Retrieves block types of the specified blocks. If a chunk is not loaded, doesn't modify the block. Returns true if all blocks were read. */ bool GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure); bool DigBlock (int a_X, int a_Y, int a_Z); void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player); - /// Compares clients of two chunks, calls the callback accordingly + /** Compares clients of two chunks, calls the callback accordingly */ void CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback); - /// Compares clients of two chunks, calls the callback accordingly + /** Compares clients of two chunks, calls the callback accordingly */ void CompareChunkClients(cChunk * a_Chunk1, cChunk * a_Chunk2, cClientDiffCallback & a_Callback); - /// Adds client to a chunk, if not already present; returns true if added, false if present + /** Adds client to a chunk, if not already present; returns true if added, false if present */ bool AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client); - /// Removes the client from the chunk + /** Removes the client from the chunk */ void RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client); - /// Removes the client from all chunks it is present in + /** Removes the client from all chunks it is present in */ void RemoveClientFromChunks(cClientHandle * a_Client); - /// Adds the entity to its appropriate chunk, takes ownership of the entity pointer + /** Adds the entity to its appropriate chunk, takes ownership of the entity pointer */ void AddEntity(cEntity * a_Entity); - /// Returns true if the entity with specified ID is present in the chunks + /** Returns true if the entity with specified ID is present in the chunks */ bool HasEntity(int a_EntityID); - /// Removes the entity from its appropriate chunk + /** Removes the entity from its appropriate chunk */ void RemoveEntity(cEntity * a_Entity); - /// Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true + /** Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true */ bool ForEachEntity(cEntityCallback & a_Callback); // Lua-accessible - /// Calls the callback for each entity in the specified chunk; returns true if all entities processed, false if the callback aborted by returning true + /** Calls the callback for each entity in the specified chunk; returns true if all entities processed, false if the callback aborted by returning true */ bool ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & a_Callback); // Lua-accessible - /// Destroys and returns a list of blocks destroyed in the explosion at the specified coordinates + /** Destroys and returns a list of blocks destroyed in the explosion at the specified coordinates */ void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, cVector3iArray & a_BlockAffected); - /// Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found and callback returned false. + /** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found and callback returned false. */ bool DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback); // Lua-accessible - /// Calls the callback for each block entity in the specified chunk; returns true if all block entities processed, false if the callback aborted by returning true + /** Calls the callback for each block entity in the specified chunk; returns true if all block entities processed, false if the callback aborted by returning true */ bool ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback & a_Callback); // Lua-accessible - /// Calls the callback for each chest in the specified chunk; returns true if all chests processed, false if the callback aborted by returning true + /** Calls the callback for each chest in the specified chunk; returns true if all chests processed, false if the callback aborted by returning true */ bool ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback & a_Callback); // Lua-accessible - /// Calls the callback for each dispenser in the specified chunk; returns true if all dispensers processed, false if the callback aborted by returning true + /** Calls the callback for each dispenser in the specified chunk; returns true if all dispensers processed, false if the callback aborted by returning true */ bool ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCallback & a_Callback); - /// Calls the callback for each dropper in the specified chunk; returns true if all droppers processed, false if the callback aborted by returning true + /** Calls the callback for each dropper in the specified chunk; returns true if all droppers processed, false if the callback aborted by returning true */ bool ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallback & a_Callback); - /// Calls the callback for each dropspenser in the specified chunk; returns true if all dropspensers processed, false if the callback aborted by returning true + /** Calls the callback for each dropspenser in the specified chunk; returns true if all dropspensers processed, false if the callback aborted by returning true */ bool ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpenserCallback & a_Callback); - /// Calls the callback for each furnace in the specified chunk; returns true if all furnaces processed, false if the callback aborted by returning true + /** Calls the callback for each furnace in the specified chunk; returns true if all furnaces processed, false if the callback aborted by returning true */ bool ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback & a_Callback); // Lua-accessible - /// Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found + /** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */ bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible - /// Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found + /** Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found */ bool DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback); // Lua-acessible - /// Calls the callback for the dispenser at the specified coords; returns false if there's no dispenser at those coords or callback returns true, returns true if found + /** Calls the callback for the dispenser at the specified coords; returns false if there's no dispenser at those coords or callback returns true, returns true if found */ bool DoWithDispenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDispenserCallback & a_Callback); // Lua-accessible - /// Calls the callback for the dropper at the specified coords; returns false if there's no dropper at those coords or callback returns true, returns true if found + /** Calls the callback for the dropper at the specified coords; returns false if there's no dropper at those coords or callback returns true, returns true if found */ bool DoWithDropperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropperCallback & a_Callback); // Lua-accessible - /// Calls the callback for the dropspenser at the specified coords; returns false if there's no dropspenser at those coords or callback returns true, returns true if found + /** Calls the callback for the dropspenser at the specified coords; returns false if there's no dropspenser at those coords or callback returns true, returns true if found */ bool DoWithDropSpenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropSpenserCallback & a_Callback); // Lua-accessible - /// Calls the callback for the furnace at the specified coords; returns false if there's no furnace at those coords or callback returns true, returns true if found + /** Calls the callback for the furnace at the specified coords; returns false if there's no furnace at those coords or callback returns true, returns true if found */ bool DoWithFurnaceAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnaceCallback & a_Callback); // Lua-accessible - /// Calls the callback for the noteblock at the specified coords; returns false if there's no noteblock at those coords or callback returns true, returns true if found + /** Calls the callback for the noteblock at the specified coords; returns false if there's no noteblock at those coords or callback returns true, returns true if found */ bool DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNoteBlockCallback & a_Callback); // Lua-accessible - /// Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found + /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Lua-accessible - /// Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found + /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible - /// Touches the chunk, causing it to be loaded or generated + /** Touches the chunk, causing it to be loaded or generated */ void TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); - /// Loads the chunk, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) + /** Loads the chunk, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) */ bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); - /// Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid() + /** Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid() */ void LoadChunks(const cChunkCoordsList & a_Chunks); - /// Marks the chunk as failed-to-load + /** Marks the chunk as failed-to-load */ void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ); - /// Sets the sign text. Returns true if sign text changed. + /** Sets the sign text. Returns true if sign text changed. */ bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4); - /// Marks (a_Stay == true) or unmarks (a_Stay == false) chunks as non-unloadable; to be used only by cChunkStay! - void ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay = true); - - /// Marks the chunk as being regenerated - all its clients want that chunk again (used by cWorld::RegenerateChunk() ) + /** Marks the chunk as being regenerated - all its clients want that chunk again (used by cWorld::RegenerateChunk() ) */ void MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ); bool IsChunkLighted(int a_ChunkX, int a_ChunkZ); - /// Calls the callback for each chunk in the coords specified (all cords are inclusive). Returns true if all chunks have been processed successfully + /** Calls the callback for each chunk in the coords specified (all cords are inclusive). Returns true if all chunks have been processed successfully */ bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback); - /// Writes the block area into the specified coords. Returns true if all chunks have been processed. Prefer cBlockArea::Write() instead. + /** Writes the block area into the specified coords. Returns true if all chunks have been processed. Prefer cBlockArea::Write() instead. */ bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes); - /// Returns the number of valid chunks and the number of dirty chunks + /** Returns the number of valid chunks and the number of dirty chunks */ void GetChunkStats(int & a_NumChunksValid, int & a_NumChunksDirty); - /// Grows a melon or a pumpkin next to the block specified (assumed to be the stem) + /** Grows a melon or a pumpkin next to the block specified (assumed to be the stem) */ void GrowMelonPumpkin(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, MTRand & a_Rand); - /// Grows a sugarcane present at the block specified by the amount of blocks specified, up to the max height specified in the config + /** Grows a sugarcane present at the block specified by the amount of blocks specified, up to the max height specified in the config */ void GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow); - /// Grows a cactus present at the block specified by the amount of blocks specified, up to the max height specified in the config + /** Grows a cactus present at the block specified by the amount of blocks specified, up to the max height specified in the config */ void GrowCactus(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow); - /// Sets the blockticking to start at the specified block. Only one blocktick per chunk may be set, second call overwrites the first call + /** Sets the blockticking to start at the specified block. Only one blocktick per chunk may be set, second call overwrites the first call */ void SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ); - /// Make a Mob census, of all mobs, their family, their chunk and theyr distance to closest player + /** Make a Mob census, of all mobs, their family, their chunk and theyr distance to closest player */ void CollectMobCensus(cMobCensus& a_ToFill); - /// Try to Spawn Monsters inside all Chunks + /** Try to Spawn Monsters inside all Chunks */ void SpawnMobs(cMobSpawner& a_MobSpawner); void Tick(float a_Dt); - /// Ticks a single block. Used by cWorld::TickQueuedBlocks() to tick the queued blocks + /** Ticks a single block. Used by cWorld::TickQueuedBlocks() to tick the queued blocks */ void TickBlock(int a_BlockX, int a_BlockY, int a_BlockZ); void UnloadUnusedChunks(void); @@ -312,15 +309,20 @@ public: void ChunkValidated(void); // Called by chunks that have become valid - /// Queues the specified block for ticking (block update) + /** Queues the specified block for ticking (block update) */ void QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ); - /// Returns the CS for locking the chunkmap; only cWorld::cLock may use this function! + /** Returns the CS for locking the chunkmap; only cWorld::cLock may use this function! */ cCriticalSection & GetCS(void) { return m_CSLayers; } private: - friend class cChunk; // The chunks can manipulate neighbors while in their Tick() method, using LockedGetBlock() and LockedSetBlock() + // The chunks can manipulate neighbors while in their Tick() method, using LockedGetBlock() and LockedSetBlock() + friend class cChunk; + + // The chunkstay can (de-)register itself using AddChunkStay() and DelChunkStay() + friend class cChunkStay; + class cChunkLayer { @@ -328,10 +330,10 @@ private: cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent); ~cChunkLayer(); - /// Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check + /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ cChunkPtr GetChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ ); - /// Returns the specified chunk, or NULL if not created yet + /** Returns the specified chunk, or NULL if not created yet */ cChunk * FindChunk(int a_ChunkX, int a_ChunkZ); int GetX(void) const {return m_LayerX; } @@ -344,22 +346,22 @@ private: void Save(void); void UnloadUnusedChunks(void); - /// Collect a mob census, of all mobs, their megatype, their chunk and their distance o closest player + /** Collect a mob census, of all mobs, their megatype, their chunk and their distance o closest player */ void CollectMobCensus(cMobCensus& a_ToFill); - /// Try to Spawn Monsters inside all Chunks + /** Try to Spawn Monsters inside all Chunks */ void SpawnMobs(cMobSpawner& a_MobSpawner); void Tick(float a_Dt); void RemoveClient(cClientHandle * a_Client); - /// Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true + /** Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true */ bool ForEachEntity(cEntityCallback & a_Callback); // Lua-accessible - /// Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found. + /** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found. */ bool DoWithEntityByID(int a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackReturn); // Lua-accessible - /// Returns true if there is an entity with the specified ID within this layer's chunks + /** Returns true if there is an entity with the specified ID within this layer's chunks */ bool HasEntity(int a_EntityID); protected: @@ -372,17 +374,19 @@ private: }; typedef std::list cChunkLayerList; + + typedef std::list cChunkStays; - /// Finds the cChunkLayer object responsible for the specified chunk; returns NULL if not found. Assumes m_CSLayers is locked. + /** Finds the cChunkLayer object responsible for the specified chunk; returns NULL if not found. Assumes m_CSLayers is locked. */ cChunkLayer * FindLayerForChunk(int a_ChunkX, int a_ChunkZ); - /// Returns the specified cChunkLayer object; returns NULL if not found. Assumes m_CSLayers is locked. + /** Returns the specified cChunkLayer object; returns NULL if not found. Assumes m_CSLayers is locked. */ cChunkLayer * FindLayer(int a_LayerX, int a_LayerZ); - /// Returns the cChunkLayer object responsible for the specified chunk; creates it if not found. + /** Returns the cChunkLayer object responsible for the specified chunk; creates it if not found. */ cChunkLayer * GetLayerForChunk (int a_ChunkX, int a_ChunkZ); - /// Returns the specified cChunkLayer object; creates it if not found. + /** Returns the specified cChunkLayer object; creates it if not found. */ cChunkLayer * GetLayer(int a_LayerX, int a_LayerZ); void RemoveLayer(cChunkLayer * a_Layer); @@ -395,67 +399,42 @@ private: cCriticalSection m_CSFastSetBlock; sSetBlockList m_FastSetBlockQueue; + + /** The cChunkStay descendants that are currently enabled in this chunkmap */ + cChunkStays m_ChunkStays; cChunkPtr GetChunk (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate cChunkPtr GetChunkNoLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Doesn't load, doesn't generate - /// Gets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) + /** Gets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */ bool LockedGetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); - /// Gets a block type in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) + /** Gets a block type in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */ bool LockedGetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType); - /// Gets a block meta in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) + /** Gets a block meta in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */ bool LockedGetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE & a_BlockMeta); - /// Sets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) + /** Sets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */ bool LockedSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); - /// Fast-sets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) + /** Fast-sets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */ bool LockedFastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); - /// Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSLayers is locked. To be called only from cChunkMap. + /** Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSLayers is locked. To be called only from cChunkMap. */ cChunk * FindChunk(int a_ChunkX, int a_ChunkZ); -}; - - - - -/** Makes chunks stay loaded until this object is cleared or destroyed -Works by setting internal flags in the cChunk that it should not be unloaded. -To optimize for speed, cChunkStay has an Enabled flag, it will "stay" the chunks only when enabled and it will refuse manipulations when enabled -The object itself is not made thread-safe, it's supposed to be used from a single thread only. -*/ -class cChunkStay -{ -public: - cChunkStay(cWorld * a_World); - ~cChunkStay(); - - void Clear(void); - - void Add(int a_ChunkX, int a_ChunkY, int a_ChunkZ); - void Remove(int a_ChunkX, int a_ChunkY, int a_ChunkZ); - - void Enable(void); - void Disable(void); + /** Adds a new cChunkStay descendant to the internal list of ChunkStays; loads its chunks. + To be used only by cChunkStay; others should use cChunkStay::Enable() instead */ + void AddChunkStay(cChunkStay & a_ChunkStay); - /// Queues each chunk in m_Chunks[] for loading / generating - void Load(void); + /** Removes the specified cChunkStay descendant from the internal list of ChunkStays. + To be used only by cChunkStay; others should use cChunkStay::Disable() instead */ + void DelChunkStay(cChunkStay & a_ChunkStay); - // Allow cChunkStay be passed to functions expecting a const cChunkCoordsList & - operator const cChunkCoordsList(void) const {return m_Chunks; } - -protected: +}; - cWorld * m_World; - - bool m_IsEnabled; - - cChunkCoordsList m_Chunks; -} ; diff --git a/src/ChunkStay.cpp b/src/ChunkStay.cpp new file mode 100644 index 000000000..a64a2a3e4 --- /dev/null +++ b/src/ChunkStay.cpp @@ -0,0 +1,136 @@ + +// ChunkStay.cpp + +// Implements the cChunkStay class representing a base for classes that keep chunks loaded + +#include "Globals.h" +#include "ChunkStay.h" +#include "ChunkMap.h" + + + + + +cChunkStay::cChunkStay(void) : + m_ChunkMap(NULL) +{ +} + + + + + +cChunkStay::~cChunkStay() +{ + Clear(); +} + + + + + +void cChunkStay::Clear(void) +{ + if (m_ChunkMap != NULL) + { + Disable(); + } + m_Chunks.clear(); +} + + + + + +void cChunkStay::Add(int a_ChunkX, int a_ChunkZ) +{ + ASSERT(m_ChunkMap == NULL); + + for (cChunkCoordsVector::const_iterator itr = m_Chunks.begin(); itr != m_Chunks.end(); ++itr) + { + if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) + { + // Already present + return; + } + } // for itr - Chunks[] + m_Chunks.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)); +} + + + + + +void cChunkStay::Remove(int a_ChunkX, int a_ChunkZ) +{ + ASSERT(m_ChunkMap == NULL); + + for (cChunkCoordsVector::iterator itr = m_Chunks.begin(); itr != m_Chunks.end(); ++itr) + { + if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) + { + // Found, un-"stay" + m_Chunks.erase(itr); + return; + } + } // for itr - m_Chunks[] +} + + + + + +void cChunkStay::Enable(cChunkMap & a_ChunkMap) +{ + ASSERT(m_ChunkMap == NULL); + + m_ChunkMap = &a_ChunkMap; + a_ChunkMap.AddChunkStay(*this); + m_OutstandingChunks = m_Chunks; +} + + + + + +void cChunkStay::Disable(void) +{ + ASSERT(m_ChunkMap != NULL); + + m_ChunkMap->DelChunkStay(*this); + m_ChunkMap = NULL; +} + + + + + +void cChunkStay::ChunkAvailable(int a_ChunkX, int a_ChunkZ) +{ + // Check if this is a chunk that we want: + bool IsMine = false; + for (cChunkCoordsVector::const_iterator itr = m_OutstandingChunks.begin(), end = m_OutstandingChunks.end(); itr != end; ++itr) + { + if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) + { + m_OutstandingChunks.erase(itr); + IsMine = true; + break; + } + } // for itr - m_OutstandingChunks[] + if (!IsMine) + { + return; + } + + // Call the appropriate callbacks: + OnChunkAvailable(a_ChunkX, a_ChunkZ); + if (m_OutstandingChunks.empty()) + { + OnAllChunksAvailable(); + } +} + + + + diff --git a/src/ChunkStay.h b/src/ChunkStay.h new file mode 100644 index 000000000..6eb8e1669 --- /dev/null +++ b/src/ChunkStay.h @@ -0,0 +1,92 @@ + +// ChunkStay.h + +/* Declares the cChunkStay class representing a base for classes that want to wait for certain chunks to load, +then do some action on them. While the object is enabled, the chunks contained within are locked and will +not unload +*/ + + + + + +#pragma once + + + + + +// fwd +class cChunkMap; + + + + + +/** Makes chunks stay loaded until this object is cleared or destroyed +Works by setting internal flags in the cChunk that it should not be unloaded. +To optimize for speed, cChunkStay has an Enabled flag, it will "stay" the chunks only when enabled +and it will refuse chunk-list manipulations when enabled. +The object itself is not made thread-safe, it's supposed to be used from a single thread only. +This class is abstract, the descendants are expected to provide the OnChunkAvailable() and +the OnAllChunksAvailable() callback implementations. Note that those are called from the contexts of +different threads' - the caller, the Loader or the Generator thread. +*/ +class cChunkStay +{ +public: + cChunkStay(void); + ~cChunkStay(); + + void Clear(void); + + /** Adds a chunk to be locked from unloading. + To be used only while the ChunkStay object is not enabled. */ + void Add (int a_ChunkX, int a_ChunkZ); + + /** Releases the chunk so that it's no longer locked from unloading. + To be used only while the ChunkStay object is not enabled. */ + void Remove(int a_ChunkX, int a_ChunkZ); + + /** Enables the ChunkStay on the specified chunkmap, causing it to load and generate chunks. + All the contained chunks are queued for loading / generating. */ + void Enable (cChunkMap & a_ChunkMap); + + /** Disables the ChunkStay, the chunks are released and the ChunkStay + object can be edited with Add() and Remove() again*/ + void Disable(void); + + /** Returns all the chunks that should be kept */ + const cChunkCoordsVector & GetChunks(void) const { return m_Chunks; } + + /** Called when a specific chunk become available. */ + virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) = 0; + + /** Caled once all of the contained chunks are available. */ + virtual void OnAllChunksAvailable(void) = 0; + +protected: + + friend class cChunkMap; + + + /** The chunkmap where the object is enabled. + Valid only after call to Enable() and before Disable(). */ + cChunkMap * m_ChunkMap; + + /** The list of chunks to lock from unloading. */ + cChunkCoordsVector m_Chunks; + + /** The chunks that still need loading */ + cChunkCoordsVector m_OutstandingChunks; + + + /** Called by cChunkMap when a chunk is available, checks m_NumLoaded and triggers the appropriate callbacks. + May be called for chunks outside this ChunkStay. */ + void ChunkAvailable(int a_ChunkX, int a_ChunkZ); +} ; + + + + + diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index a823c08cc..b665066ee 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -6,6 +6,7 @@ #include "Globals.h" #include "LightingThread.h" #include "ChunkMap.h" +#include "ChunkStay.h" #include "World.h" @@ -109,9 +110,14 @@ void cLightingThread::Stop(void) { { cCSLock Lock(m_CS); - for (sItems::iterator itr = m_Queue.begin(), end = m_Queue.end(); itr != end; ++itr) + for (cChunkStays::iterator itr = m_PendingQueue.begin(), end = m_PendingQueue.end(); itr != end; ++itr) { - delete itr->m_ChunkStay; + delete *itr; + } + m_PendingQueue.clear(); + for (cChunkStays::iterator itr = m_Queue.begin(), end = m_Queue.end(); itr != end; ++itr) + { + delete *itr; } m_Queue.clear(); } @@ -129,25 +135,12 @@ void cLightingThread::QueueChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback { ASSERT(m_World != NULL); // Did you call Start() properly? - cChunkStay * ChunkStay = new cChunkStay(m_World); - ChunkStay->Add(a_ChunkX + 1, ZERO_CHUNK_Y, a_ChunkZ + 1); - ChunkStay->Add(a_ChunkX + 1, ZERO_CHUNK_Y, a_ChunkZ); - ChunkStay->Add(a_ChunkX + 1, ZERO_CHUNK_Y, a_ChunkZ - 1); - ChunkStay->Add(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ + 1); - ChunkStay->Add(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - ChunkStay->Add(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ - 1); - ChunkStay->Add(a_ChunkX - 1, ZERO_CHUNK_Y, a_ChunkZ + 1); - ChunkStay->Add(a_ChunkX - 1, ZERO_CHUNK_Y, a_ChunkZ); - ChunkStay->Add(a_ChunkX - 1, ZERO_CHUNK_Y, a_ChunkZ - 1); - ChunkStay->Enable(); - ChunkStay->Load(); + cChunkStay * ChunkStay = new cLightingChunkStay(*this, a_ChunkX, a_ChunkZ, a_CallbackAfter); + ChunkStay->Enable(*m_World->GetChunkMap()); + // The ChunkStay will enqueue itself using the QueueChunkStay() once it is fully loaded + // In the meantime, put it into the PendingQueue so that it can be removed when stopping the thread cCSLock Lock(m_CS); - m_Queue.push_back(sItem(a_ChunkX, a_ChunkZ, ChunkStay, a_CallbackAfter)); - if (m_Queue.size() > WARN_ON_QUEUE_SIZE) - { - LOGINFO("Lighting thread overloaded, %d items in queue", m_Queue.size()); - } - m_evtItemAdded.Set(); + m_PendingQueue.push_back(ChunkStay); } @@ -157,7 +150,7 @@ void cLightingThread::QueueChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback void cLightingThread::WaitForQueueEmpty(void) { cCSLock Lock(m_CS); - while (!m_ShouldTerminate && (!m_Queue.empty() || !m_PostponedQueue.empty())) + while (!m_ShouldTerminate && (!m_Queue.empty() || !m_PendingQueue.empty())) { cCSUnlock Unlock(Lock); m_evtQueueEmpty.Wait(); @@ -171,43 +164,7 @@ void cLightingThread::WaitForQueueEmpty(void) size_t cLightingThread::GetQueueLength(void) { cCSLock Lock(m_CS); - return m_Queue.size() + m_PostponedQueue.size(); -} - - - - - -void cLightingThread::ChunkReady(int a_ChunkX, int a_ChunkZ) -{ - // Check all the items in the m_PostponedQueue, if the chunk is their neighbor, move the item to m_Queue - - bool NewlyAdded = false; - { - cCSLock Lock(m_CS); - for (sItems::iterator itr = m_PostponedQueue.begin(); itr != m_PostponedQueue.end(); ) - { - if ( - (itr->x - a_ChunkX >= -1) && (itr->x - a_ChunkX <= 1) && - (itr->z - a_ChunkZ >= -1) && (itr->z - a_ChunkZ <= 1) - ) - { - // It is a neighbor - m_Queue.push_back(*itr); - itr = m_PostponedQueue.erase(itr); - NewlyAdded = true; - } - else - { - ++itr; - } - } // for itr - m_PostponedQueue[] - } // Lock(m_CS) - - if (NewlyAdded) - { - m_evtItemAdded.Set(); // Notify the thread it has some work to do - } + return m_Queue.size() + m_PendingQueue.size(); } @@ -233,14 +190,14 @@ void cLightingThread::Execute(void) } // Process one items from the queue: - sItem Item; + cLightingChunkStay * Item; { cCSLock Lock(m_CS); if (m_Queue.empty()) { continue; } - Item = m_Queue.front(); + Item = (cLightingChunkStay *)m_Queue.front(); m_Queue.pop_front(); if (m_Queue.empty()) { @@ -248,7 +205,7 @@ void cLightingThread::Execute(void) } } // CSLock(m_CS) - LightChunk(Item); + LightChunk(*Item); } } @@ -257,23 +214,11 @@ void cLightingThread::Execute(void) -void cLightingThread::LightChunk(cLightingThread::sItem & a_Item) +void cLightingThread::LightChunk(cLightingChunkStay & a_Item) { cChunkDef::BlockNibbles BlockLight, SkyLight; - if (!ReadChunks(a_Item.x, a_Item.z)) - { - // Neighbors not available. Re-queue in the postponed queue - cCSLock Lock(m_CS); - m_PostponedQueue.push_back(a_Item); - return; - } - - /* - // DEBUG: torch somewhere: - m_BlockTypes[19 + 24 * cChunkDef::Width * 3 + (m_HeightMap[24 + 24 * cChunkDef::Width * 3] / 2) * BlocksPerYLayer] = E_BLOCK_TORCH; - // m_HeightMap[24 + 24 * cChunkDef::Width * 3]++; - */ + ReadChunks(a_Item.m_ChunkX, a_Item.m_ChunkZ); PrepareBlockLight(); CalcLight(m_BlockLight); @@ -339,13 +284,13 @@ void cLightingThread::LightChunk(cLightingThread::sItem & a_Item) CompressLight(m_BlockLight, BlockLight); CompressLight(m_SkyLight, SkyLight); - m_World->ChunkLighted(a_Item.x, a_Item.z, BlockLight, SkyLight); + m_World->ChunkLighted(a_Item.m_ChunkX, a_Item.m_ChunkZ, BlockLight, SkyLight); - if (a_Item.m_Callback != NULL) + if (a_Item.m_CallbackAfter != NULL) { - a_Item.m_Callback->Call(a_Item.x, a_Item.z); + a_Item.m_CallbackAfter->Call(a_Item.m_ChunkX, a_Item.m_ChunkZ); } - delete a_Item.m_ChunkStay; + delete &a_Item; } @@ -561,3 +506,51 @@ void cLightingThread::CompressLight(NIBBLETYPE * a_LightArray, NIBBLETYPE * a_Ch + +void cLightingThread::QueueChunkStay(cLightingChunkStay & a_ChunkStay) +{ + // Move the ChunkStay from the Pending queue to the lighting queue. + { + cCSLock Lock(m_CS); + m_PendingQueue.remove(&a_ChunkStay); + m_Queue.push_back(&a_ChunkStay); + } + m_evtItemAdded.Set(); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cLightingThread::cLightingChunkStay: + +cLightingThread::cLightingChunkStay::cLightingChunkStay(cLightingThread & a_LightingThread, int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallbackAfter) : + m_LightingThread(a_LightingThread), + m_ChunkX(a_ChunkX), + m_ChunkZ(a_ChunkZ), + m_CallbackAfter(a_CallbackAfter) +{ + Add(a_ChunkX + 1, a_ChunkZ + 1); + Add(a_ChunkX + 1, a_ChunkZ); + Add(a_ChunkX + 1, a_ChunkZ - 1); + Add(a_ChunkX, a_ChunkZ + 1); + Add(a_ChunkX, a_ChunkZ); + Add(a_ChunkX, a_ChunkZ - 1); + Add(a_ChunkX - 1, a_ChunkZ + 1); + Add(a_ChunkX - 1, a_ChunkZ); + Add(a_ChunkX - 1, a_ChunkZ - 1); +} + + + + + +void cLightingThread::cLightingChunkStay::OnAllChunksAvailable(void) +{ + m_LightingThread.QueueChunkStay(*this); +} + + + + diff --git a/src/LightingThread.h b/src/LightingThread.h index d8ce59f01..0e17c485f 100644 --- a/src/LightingThread.h +++ b/src/LightingThread.h @@ -33,6 +33,7 @@ Chunks from m_PostponedQueue are moved back into m_Queue when their neighbors ge #include "OSSupport/IsThread.h" #include "ChunkDef.h" +#include "ChunkStay.h" @@ -41,9 +42,6 @@ Chunks from m_PostponedQueue are moved back into m_Queue when their neighbors ge // fwd: "cWorld.h" class cWorld; -// fwd: "cChunkMap.h" -class cChunkStay; - @@ -62,43 +60,49 @@ public: void Stop(void); - /// Queues the entire chunk for lighting + /** Queues the entire chunk for lighting */ void QueueChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallbackAfter = NULL); - /// Blocks until the queue is empty or the thread is terminated + /** Blocks until the queue is empty or the thread is terminated */ void WaitForQueueEmpty(void); size_t GetQueueLength(void); - /// Called from cWorld when a chunk gets valid. Chunks in m_PostponedQueue may need moving into m_Queue - void ChunkReady(int a_ChunkX, int a_ChunkZ); - protected: - struct sItem + class cLightingChunkStay : + public cChunkStay { - int x, z; - cChunkStay * m_ChunkStay; - cChunkCoordCallback * m_Callback; + public: + cLightingThread & m_LightingThread; + int m_ChunkX; + int m_ChunkZ; + cChunkCoordCallback * m_CallbackAfter; - sItem(void) {} // empty default constructor needed - sItem(int a_X, int a_Z, cChunkStay * a_ChunkStay, cChunkCoordCallback * a_Callback) : - x(a_X), - z(a_Z), - m_ChunkStay(a_ChunkStay), - m_Callback(a_Callback) - { - } + cLightingChunkStay(cLightingThread & a_LightingThread, int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallbackAfter); + + protected: + virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override {} + virtual void OnAllChunksAvailable(void) override; } ; - typedef std::list sItems; + typedef std::list cChunkStays; + - cWorld * m_World; + cWorld * m_World; + + /** The mutex to protect m_Queue and m_PendingQueue */ cCriticalSection m_CS; - sItems m_Queue; - sItems m_PostponedQueue; // Chunks that have been postponed due to missing neighbors - cEvent m_evtItemAdded; // Set when queue is appended, or to stop the thread - cEvent m_evtQueueEmpty; // Set when the queue gets empty + + /** The ChunkStays that are loaded and are waiting to be lit. */ + cChunkStays m_Queue; + + /** The ChunkStays that are waiting for load. Used for stopping the thread. */ + cChunkStays m_PendingQueue; + + cEvent m_evtItemAdded; // Set when queue is appended, or to stop the thread + cEvent m_evtQueueEmpty; // Set when the queue gets empty + // Buffers for the 3x3 chunk data // These buffers alone are 1.7 MiB in size, therefore they cannot be located on the stack safely - some architectures may have only 1 MiB for stack, or even less @@ -124,29 +128,29 @@ protected: virtual void Execute(void) override; - /// Lights the entire chunk. If neighbor chunks don't exist, touches them and re-queues the chunk - void LightChunk(sItem & a_Item); + /** Lights the entire chunk. If neighbor chunks don't exist, touches them and re-queues the chunk */ + void LightChunk(cLightingChunkStay & a_Item); - /// Prepares m_BlockTypes and m_HeightMap data; returns false if any of the chunks fail. Zeroes out the light arrays + /** Prepares m_BlockTypes and m_HeightMap data; returns false if any of the chunks fail. Zeroes out the light arrays */ bool ReadChunks(int a_ChunkX, int a_ChunkZ); - /// Uses m_HeightMap to initialize the m_SkyLight[] data; fills in seeds for the skylight + /** Uses m_HeightMap to initialize the m_SkyLight[] data; fills in seeds for the skylight */ void PrepareSkyLight(void); - /// Uses m_BlockTypes to initialize the m_BlockLight[] data; fills in seeds for the blocklight + /** Uses m_BlockTypes to initialize the m_BlockLight[] data; fills in seeds for the blocklight */ void PrepareBlockLight(void); - /// Calculates light in the light array specified, using stored seeds + /** Calculates light in the light array specified, using stored seeds */ void CalcLight(NIBBLETYPE * a_Light); - /// Does one step in the light calculation - one seed propagation and seed recalculation + /** Does one step in the light calculation - one seed propagation and seed recalculation */ void CalcLightStep( NIBBLETYPE * a_Light, int a_NumSeedsIn, unsigned char * a_IsSeedIn, unsigned int * a_SeedIdxIn, int & a_NumSeedsOut, unsigned char * a_IsSeedOut, unsigned int * a_SeedIdxOut ); - /// Compresses from 1-block-per-byte (faster calc) into 2-blocks-per-byte (MC storage): + /** Compresses from 1-block-per-byte (faster calc) into 2-blocks-per-byte (MC storage): */ void CompressLight(NIBBLETYPE * a_LightArray, NIBBLETYPE * a_ChunkLight); inline void PropagateLight( @@ -174,6 +178,10 @@ protected: } } + /** Queues a chunkstay that has all of its chunks loaded. + Called by cLightingChunkStay when all of its chunks are loaded. */ + void QueueChunkStay(cLightingChunkStay & a_ChunkStay); + } ; diff --git a/src/World.cpp b/src/World.cpp index ebdd3fb06..dfc186639 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2145,9 +2145,6 @@ void cWorld::SetChunkData( { m_ChunkSender.ChunkReady(a_ChunkX, a_ChunkZ); } - - // Notify the lighting thread that the chunk has become valid (in case it is a neighbor of a postponed chunk): - m_Lighting.ChunkReady(a_ChunkX, a_ChunkZ); } @@ -2561,15 +2558,6 @@ bool cWorld::SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, co -void cWorld::ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay) -{ - m_ChunkMap->ChunksStay(a_Chunks, a_Stay); -} - - - - - void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) { m_ChunkMap->MarkChunkRegenerating(a_ChunkX, a_ChunkZ); diff --git a/src/World.h b/src/World.h index d436e7adf..b82bdc67c 100644 --- a/src/World.h +++ b/src/World.h @@ -308,9 +308,6 @@ public: /** Sets the command block command. Returns true if command changed. */ bool SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command); // tolua_export - /** Marks (a_Stay == true) or unmarks (a_Stay == false) chunks as non-unloadable. To be used only by cChunkStay! */ - void ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay = true); - /** Regenerate the given chunk: */ void RegenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export -- cgit v1.2.3 From a4bf44858dd1dc0c986cc1ed18cf8c37487207ff Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 8 Feb 2014 22:01:04 +0100 Subject: Fixed gcc compilation. --- src/ChunkStay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChunkStay.cpp b/src/ChunkStay.cpp index a64a2a3e4..e86501c4e 100644 --- a/src/ChunkStay.cpp +++ b/src/ChunkStay.cpp @@ -109,7 +109,7 @@ void cChunkStay::ChunkAvailable(int a_ChunkX, int a_ChunkZ) { // Check if this is a chunk that we want: bool IsMine = false; - for (cChunkCoordsVector::const_iterator itr = m_OutstandingChunks.begin(), end = m_OutstandingChunks.end(); itr != end; ++itr) + for (cChunkCoordsVector::iterator itr = m_OutstandingChunks.begin(), end = m_OutstandingChunks.end(); itr != end; ++itr) { if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) { -- cgit v1.2.3 From 7432d2f74d8d2cc5a002b9c414b006ecb9cdfcfd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 8 Feb 2014 22:23:38 +0100 Subject: Fixed ChunkStay initialization. --- src/ChunkStay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChunkStay.cpp b/src/ChunkStay.cpp index e86501c4e..cce8d5f4d 100644 --- a/src/ChunkStay.cpp +++ b/src/ChunkStay.cpp @@ -84,9 +84,9 @@ void cChunkStay::Enable(cChunkMap & a_ChunkMap) { ASSERT(m_ChunkMap == NULL); + m_OutstandingChunks = m_Chunks; m_ChunkMap = &a_ChunkMap; a_ChunkMap.AddChunkStay(*this); - m_OutstandingChunks = m_Chunks; } -- cgit v1.2.3 From df0ecc6c078cf06c5aba025bb8d77569ca91c748 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 8 Feb 2014 22:33:42 +0100 Subject: Fixed lighting thread queueing. --- src/LightingThread.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index b665066ee..8fbfb29db 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -136,11 +136,13 @@ void cLightingThread::QueueChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback ASSERT(m_World != NULL); // Did you call Start() properly? cChunkStay * ChunkStay = new cLightingChunkStay(*this, a_ChunkX, a_ChunkZ, a_CallbackAfter); + { + cCSLock Lock(m_CS); + m_PendingQueue.push_back(ChunkStay); + } ChunkStay->Enable(*m_World->GetChunkMap()); // The ChunkStay will enqueue itself using the QueueChunkStay() once it is fully loaded // In the meantime, put it into the PendingQueue so that it can be removed when stopping the thread - cCSLock Lock(m_CS); - m_PendingQueue.push_back(ChunkStay); } -- cgit v1.2.3 From cf48968835195f2b66e7e4a04187c51e5211d40f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 8 Feb 2014 22:35:45 +0100 Subject: Moved a forgotten comment back to its place. --- src/LightingThread.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index 8fbfb29db..688f119ff 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -137,12 +137,12 @@ void cLightingThread::QueueChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback cChunkStay * ChunkStay = new cLightingChunkStay(*this, a_ChunkX, a_ChunkZ, a_CallbackAfter); { + // The ChunkStay will enqueue itself using the QueueChunkStay() once it is fully loaded + // In the meantime, put it into the PendingQueue so that it can be removed when stopping the thread cCSLock Lock(m_CS); m_PendingQueue.push_back(ChunkStay); } ChunkStay->Enable(*m_World->GetChunkMap()); - // The ChunkStay will enqueue itself using the QueueChunkStay() once it is fully loaded - // In the meantime, put it into the PendingQueue so that it can be removed when stopping the thread } -- cgit v1.2.3 From 645c096e2b76c6a42a2b0c679553475d63054f75 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 9 Feb 2014 00:02:16 +0100 Subject: The console reload command also reloads the groups. --- src/Server.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Server.cpp b/src/Server.cpp index ba2b46d55..62b4442d2 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -459,6 +459,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac if (split[0] == "reload") { cPluginManager::Get()->ReloadPlugins(); + cRoot::Get()->ReloadGroups(); return; } -- cgit v1.2.3 From 14b5054c95bc294a62792b4d82331c970809f07f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 8 Feb 2014 23:02:50 +0000 Subject: Fixed a boat ASSERT --- src/Entities/Boat.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 184aeeeeb..67df201ce 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -89,8 +89,14 @@ void cBoat::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); BroadcastMovementUpdate(); - SetSpeed(GetSpeed() * 0.97); // Slowly decrease the speed. - if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ()))) + SetSpeed(GetSpeed() * 0.97); // Slowly decrease the speed + + if ((POSY_TOINT < 0) || (POSY_TOINT > cChunkDef::Height)) + { + return; + } + + if (IsBlockWater(m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT))) { SetSpeedY(1); } -- cgit v1.2.3 From 011a334a8a1bf7a7efcfbbbe895ebae9432ce118 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 9 Feb 2014 00:06:37 +0100 Subject: Split "reload" in "reloadplugins" and "reloadgroups". --- src/Server.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index 62b4442d2..671d251cd 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -456,12 +456,15 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac PrintHelp(split, a_Output); return; } - if (split[0] == "reload") + if (split[0] == "reloadplugins") { cPluginManager::Get()->ReloadPlugins(); - cRoot::Get()->ReloadGroups(); return; } + if (split[0] == "reloadgroups") + { + cRoot::Get()->ReloadGroups(); + } // There is currently no way a plugin can do these (and probably won't ever be): if (split[0].compare("chunkstats") == 0) -- cgit v1.2.3 From 2a741e719cd827344bc441a04b27f3e3c8493d33 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 9 Feb 2014 00:13:25 +0100 Subject: "reload" is back. --- src/Server.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Server.cpp b/src/Server.cpp index 671d251cd..ab1458da4 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -456,6 +456,12 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac PrintHelp(split, a_Output); return; } + if (split[0] == "reload") + { + cPluginManager::Get()->ReloadPlugins(); + cRoot::Get()->ReloadGroups(); + return; + } if (split[0] == "reloadplugins") { cPluginManager::Get()->ReloadPlugins(); @@ -464,6 +470,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac if (split[0] == "reloadgroups") { cRoot::Get()->ReloadGroups(); + return; } // There is currently no way a plugin can do these (and probably won't ever be): -- cgit v1.2.3 From c68bdaf34beee368100e6697fc3d87a711dba6b7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Feb 2014 00:57:22 +0000 Subject: Fixed compile and some warnings in MSVS --- src/Blocks/BlockButton.h | 2 +- src/Blocks/BlockLever.h | 2 +- src/Blocks/BlockTrapdoor.h | 2 +- src/Generating/StructGen.cpp | 9 --------- src/MobSpawner.cpp | 2 +- src/World.cpp | 2 -- src/WorldStorage/ScoreboardSerializer.cpp | 4 ++-- 7 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index f2a2885be..ca6850ced 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -88,7 +88,7 @@ public: default: { ASSERT(!"Unhandled block meta!"); - return 0; + return BLOCK_FACE_NONE; } } } diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index 8b4126873..48c7e774b 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -88,7 +88,7 @@ public: default: { ASSERT(!"Unhandled block meta!"); - return 0; + return BLOCK_FACE_NONE; } } } diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 47b51db16..08fc28327 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -84,7 +84,7 @@ public: default: { ASSERT(!"Unhandled block meta!"); - return 0; + return BLOCK_FACE_NONE; } } } diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index da6227801..4efcf92f0 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -60,15 +60,6 @@ template T Clamp(T a_Value, T a_Min, T a_Max) -static bool SortTreeBlocks(const sSetBlock & a_First, const sSetBlock & a_Second) -{ - return (a_First.BlockType == E_BLOCK_LOG) && (a_Second.BlockType != E_BLOCK_LOG); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cStructGenTrees: diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index 4d0b2777b..c86268e63 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -126,7 +126,7 @@ cMonster::eType cMobSpawner::ChooseMobType(EMCSBiome a_Biome) bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, cMonster::eType a_MobType, EMCSBiome a_Biome) { - BLOCKTYPE TargetBlock; + BLOCKTYPE TargetBlock = E_BLOCK_AIR; if (m_AllowedTypes.find(a_MobType) != m_AllowedTypes.end() && a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, TargetBlock)) { NIBBLETYPE BlockLight = a_Chunk->GetBlockLight(a_RelX, a_RelY, a_RelZ); diff --git a/src/World.cpp b/src/World.cpp index d2523b0a5..662a9a4b8 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -251,10 +251,8 @@ cWorld::cWorld(const AString & a_WorldName) : m_Scoreboard(this), m_GeneratorCallbacks(*this), m_TickThread(*this), - m_Scoreboard(this), m_bCommandBlocksEnabled(false), m_bUseChatPrefixes(true) - m_TickThread(*this) { LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str()); diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp index c65e13f98..9b8b661c4 100644 --- a/src/WorldStorage/ScoreboardSerializer.cpp +++ b/src/WorldStorage/ScoreboardSerializer.cpp @@ -242,7 +242,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT) { AString Name, ObjectiveName; - cObjective::Score Score; + cObjective::Score Score = 0; int CurrLine = a_NBT.FindChildByName(Child, "Score"); if (CurrLine >= 0) @@ -280,7 +280,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT) { AString Name, DisplayName, Prefix, Suffix; - bool AllowsFriendlyFire, CanSeeFriendlyInvisible; + bool AllowsFriendlyFire = false, CanSeeFriendlyInvisible = false; int CurrLine = a_NBT.FindChildByName(Child, "Name"); if (CurrLine >= 0) -- cgit v1.2.3 From 373e450518ea17e2615fadaafd1d5d52e8d60f1a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Feb 2014 01:04:16 +0000 Subject: Updated Core --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 5fe3662a8..7f97e93ef 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 5fe3662a8719f79cb2ca0a16150c716a3c5eb19c +Subproject commit 7f97e93ef25616673e8342b7919d9b5914e1327e -- cgit v1.2.3 From 9795bfcbe354dfd2974e014a925d3be10599e7c2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Feb 2014 16:19:38 +0100 Subject: Added air, farmland and tilleddirt to items.ini. Air hasn't been present at all, the others are usual synonyms. --- MCServer/items.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MCServer/items.ini b/MCServer/items.ini index c09b32f17..7b8fcf4ee 100644 --- a/MCServer/items.ini +++ b/MCServer/items.ini @@ -1,4 +1,5 @@ [Items] +air=0 rock=1 stone=1 grass=2 @@ -177,6 +178,8 @@ workbench=58 crop=59 crops=59 soil=60 +farmland=60 +tilleddirt=60 furnace=61 litfurnace=62 signblock=63 -- cgit v1.2.3 From 4bcaf302b9d269ace566e4dfa02aa1f26545333c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Feb 2014 16:22:49 +0100 Subject: Added AllToLua.pkg to MSVC project files. MSVC ignores the file when compiling and it makes it easier to open it up for editing. --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 944150a44..50caf5f4f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -143,6 +143,7 @@ else () "${PATH}/*.cpp" "${PATH}/*.h" "${PATH}/*.rc" + "${PATH}/*.pkg" ) source_group("${PATH}" FILES ${FOLDER_FILES}) endfunction(includefolder) @@ -154,6 +155,7 @@ else () file(GLOB_RECURSE SOURCE "*.cpp" "*.h" + "*.pkg" ) include_directories("${PROJECT_SOURCE_DIR}") -- cgit v1.2.3 From 310a25c45697dbf3b1de6b0363f529691c422bf1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Feb 2014 18:39:22 +0100 Subject: cLuaState::cRef can be unbound and re-bound. This will allow us to store Lua references as member variables in classes and initialize those later than in the constructor. --- src/Bindings/LuaState.cpp | 52 ++++++++++++++++++++++++++++++++++++++++------- src/Bindings/LuaState.h | 17 ++++++++++++++-- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index ac5ce47e1..22f342467 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1240,13 +1240,21 @@ int cLuaState::ReportFnCallErrors(lua_State * a_LuaState) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cLuaState::cRef: +cLuaState::cRef::cRef(void) : + m_LuaState(NULL), + m_Ref(LUA_REFNIL) +{ +} + + + + + cLuaState::cRef::cRef(cLuaState & a_LuaState, int a_StackPos) : - m_LuaState(a_LuaState) + m_LuaState(NULL), + m_Ref(LUA_REFNIL) { - ASSERT(m_LuaState.IsValid()); - - lua_pushvalue(m_LuaState, a_StackPos); // Push a copy of the value at a_StackPos onto the stack - m_Ref = luaL_ref(m_LuaState, LUA_REGISTRYINDEX); + RefStack(a_LuaState, a_StackPos); } @@ -1255,12 +1263,42 @@ cLuaState::cRef::cRef(cLuaState & a_LuaState, int a_StackPos) : cLuaState::cRef::~cRef() { - ASSERT(m_LuaState.IsValid()); + if (m_LuaState != NULL) + { + UnRef(); + } +} + + + + + +void cLuaState::cRef::RefStack(cLuaState & a_LuaState, int a_StackPos) +{ + ASSERT(a_LuaState.IsValid()); + if (m_LuaState != NULL) + { + UnRef(); + } + m_LuaState = &a_LuaState; + lua_pushvalue(a_LuaState, a_StackPos); // Push a copy of the value at a_StackPos onto the stack + m_Ref = luaL_ref(a_LuaState, LUA_REGISTRYINDEX); +} + + + + + +void cLuaState::cRef::UnRef(void) +{ + ASSERT(m_LuaState->IsValid()); // The reference should be destroyed before destroying the LuaState if (IsValid()) { - luaL_unref(m_LuaState, LUA_REGISTRYINDEX, m_Ref); + luaL_unref(*m_LuaState, LUA_REGISTRYINDEX, m_Ref); } + m_LuaState = NULL; + m_Ref = LUA_REFNIL; } diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index dda45bb28..1c9c99e69 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -65,14 +65,27 @@ class cLuaState { public: - /** Used for storing references to object in the global registry */ + /** Used for storing references to object in the global registry. + Can be bound (contains a reference) or unbound (doesn't contain reference). + The reference can also be reset by calling RefStack(). */ class cRef { public: + /** Creates an unbound reference object. */ + cRef(void); + /** Creates a reference in the specified LuaState for object at the specified StackPos */ cRef(cLuaState & a_LuaState, int a_StackPos); + ~cRef(); + /** Creates a reference to Lua object at the specified stack pos, binds this object to it. + Calls UnRef() first if previously bound to another reference. */ + void RefStack(cLuaState & a_LuaState, int a_StackPos); + + /** Removes the bound reference, resets the object to Unbound state. */ + void UnRef(void); + /** Returns true if the reference is valid */ bool IsValid(void) const {return (m_Ref != LUA_REFNIL); } @@ -80,7 +93,7 @@ public: operator int(void) const { return m_Ref; } protected: - cLuaState & m_LuaState; + cLuaState * m_LuaState; int m_Ref; } ; -- cgit v1.2.3 From 9455f59b1100f3db2c5b1e88bb9d1f6a01664721 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Feb 2014 18:56:16 +0100 Subject: Initial Lua cChunkStay export. --- src/Bindings/AllToLua.pkg | 2 ++ src/Bindings/LuaChunkStay.cpp | 52 ++++++++++++++++++++++++++++++++++++++ src/Bindings/LuaChunkStay.h | 58 +++++++++++++++++++++++++++++++++++++++++++ src/ChunkStay.h | 12 ++++++++- 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 src/Bindings/LuaChunkStay.cpp create mode 100644 src/Bindings/LuaChunkStay.h diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index f65aed9bb..a78ee7d56 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -24,6 +24,7 @@ $cfile "Plugin.h" $cfile "PluginLua.h" $cfile "WebPlugin.h" $cfile "LuaWindow.h" +$cfile "LuaChunkStay.h" $cfile "../BlockID.h" $cfile "../StringUtils.h" @@ -70,6 +71,7 @@ $cfile "../Generating/ChunkDesc.h" $cfile "../CraftingRecipes.h" $cfile "../UI/Window.h" $cfile "../Mobs/Monster.h" +$cfile "../ChunkStay.h" diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp new file mode 100644 index 000000000..606f7694f --- /dev/null +++ b/src/Bindings/LuaChunkStay.cpp @@ -0,0 +1,52 @@ + +// LuaChunkStay.cpp + +// Implements the cLuaChunkStay class representing a cChunkStay binding for plugins + +#include "Globals.h" +#include "LuaChunkStay.h" +#include "../World.h" + + + + + +void cLuaChunkStay::Enable( + cWorld & a_World, cLuaState & a_LuaState, + const cLuaState::cRef & a_OnChunkAvailable, const cLuaState::cRef & a_OnAllChunksAvailable +) +{ + if (m_LuaState != NULL) + { + LOGWARNING("LuaChunkStay: Already enabled. Ignoring this call."); + a_LuaState.LogStackTrace(); + return; + } + m_LuaState = &a_LuaState; + m_OnChunkAvailable = a_OnAllChunksAvailable; + m_OnAllChunksAvailable = a_OnAllChunksAvailable; + super::Enable(*a_World.GetChunkMap()); +} + + + + + +void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ) +{ + m_LuaState->Call(m_OnChunkAvailable, a_ChunkX, a_ChunkZ); +} + + + + + +void cLuaChunkStay::OnAllChunksAvailable(void) +{ + m_LuaState->Call(m_OnAllChunksAvailable); +} + + + + + diff --git a/src/Bindings/LuaChunkStay.h b/src/Bindings/LuaChunkStay.h new file mode 100644 index 000000000..e9d87d7f6 --- /dev/null +++ b/src/Bindings/LuaChunkStay.h @@ -0,0 +1,58 @@ + +// LuaChunkStay.h + +// Declares the cLuaChunkStay class representing a cChunkStay binding for plugins + + + + + +#pragma once + +#include "LuaState.h" +#include "../ChunkStay.h" + + + + + +// tolua_begin +class cLuaChunkStay + : public cChunkStay +{ + typedef cChunkStay super; + +public: + // Allow Lua to construct objects of this class: + cLuaChunkStay(void) {} + + // Allow Lua to garbage-collect objects of this class: + ~cLuaChunkStay() {} + + // tolua_end + + /** Enabled the ChunkStay for the specified world, with the specified Lua callbacks. + Exported in ManualBindings. */ + void Enable( + cWorld & a_World, cLuaState & a_LuaState, + const cLuaState::cRef & a_OnChunkAvailable, const cLuaState::cRef & a_OnAllChunksAvailable + ); + +protected: + /** The Lua state associated with the callbacks. Only valid when enabled. */ + cLuaState * m_LuaState; + + /** The Lua function to call in OnChunkAvailable. Only valid when enabled. */ + cLuaState::cRef m_OnChunkAvailable; + + /** The Lua function to call in OnAllChunksAvailable. Only valid when enabled. */ + cLuaState::cRef m_OnAllChunksAvailable; + + // cChunkStay overrides: + virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override; + virtual void OnAllChunksAvailable(void) override; +} ; // tolua_export + + + + diff --git a/src/ChunkStay.h b/src/ChunkStay.h index 6eb8e1669..a6274812e 100644 --- a/src/ChunkStay.h +++ b/src/ChunkStay.h @@ -32,12 +32,16 @@ This class is abstract, the descendants are expected to provide the OnChunkAvail the OnAllChunksAvailable() callback implementations. Note that those are called from the contexts of different threads' - the caller, the Loader or the Generator thread. */ +// tolua_begin class cChunkStay { public: + // tolua_end cChunkStay(void); ~cChunkStay(); + // tolua_begin + void Clear(void); /** Adds a chunk to be locked from unloading. @@ -48,14 +52,20 @@ public: To be used only while the ChunkStay object is not enabled. */ void Remove(int a_ChunkX, int a_ChunkZ); + // tolua_end + /** Enables the ChunkStay on the specified chunkmap, causing it to load and generate chunks. All the contained chunks are queued for loading / generating. */ void Enable (cChunkMap & a_ChunkMap); + // tolua_begin + /** Disables the ChunkStay, the chunks are released and the ChunkStay object can be edited with Add() and Remove() again*/ void Disable(void); + // tolua_end + /** Returns all the chunks that should be kept */ const cChunkCoordsVector & GetChunks(void) const { return m_Chunks; } @@ -84,7 +94,7 @@ protected: /** Called by cChunkMap when a chunk is available, checks m_NumLoaded and triggers the appropriate callbacks. May be called for chunks outside this ChunkStay. */ void ChunkAvailable(int a_ChunkX, int a_ChunkZ); -} ; +} ; // tolua_export -- cgit v1.2.3 From 4ef6c56f32d73ad9cb29c7958871ba3034f27d9d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Feb 2014 18:56:43 +0100 Subject: Debuggers: Disabled testing plugin calls. --- MCServer/Plugins/Debuggers/Debuggers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 624261cbf..521032239 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -64,7 +64,7 @@ function Initialize(Plugin) -- TestBlockAreas(); -- TestSQLiteBindings(); -- TestExpatBindings(); - TestPluginCalls(); + -- TestPluginCalls(); return true end; -- cgit v1.2.3 From 47a497fa895fa5f353ba593d4bb232ea514e66c9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Feb 2014 20:39:45 +0100 Subject: First working version of cLuaChunkStay. It works, but has random failures, probably due to threading issues. --- src/Bindings/LuaChunkStay.cpp | 45 ++++++++++++++++++++++++++++++++--------- src/Bindings/LuaChunkStay.h | 21 ++++++++++++------- src/Bindings/ManualBindings.cpp | 41 +++++++++++++++++++++++++++++++++++++ src/ChunkStay.h | 2 +- 4 files changed, 92 insertions(+), 17 deletions(-) diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp index 606f7694f..f84964f56 100644 --- a/src/Bindings/LuaChunkStay.cpp +++ b/src/Bindings/LuaChunkStay.cpp @@ -11,20 +11,29 @@ +cLuaChunkStay::cLuaChunkStay(void) : + m_LuaState((lua_State *)NULL) // Want a detached Lua state by default +{ +} + + + + + void cLuaChunkStay::Enable( - cWorld & a_World, cLuaState & a_LuaState, - const cLuaState::cRef & a_OnChunkAvailable, const cLuaState::cRef & a_OnAllChunksAvailable + cWorld & a_World, lua_State * a_LuaState, + int a_OnChunkAvailableStackPos, int a_OnAllChunksAvailableStackPos ) { - if (m_LuaState != NULL) + if (m_LuaState.IsValid()) { LOGWARNING("LuaChunkStay: Already enabled. Ignoring this call."); - a_LuaState.LogStackTrace(); + cLuaState::LogStackTrace(a_LuaState); return; } - m_LuaState = &a_LuaState; - m_OnChunkAvailable = a_OnAllChunksAvailable; - m_OnAllChunksAvailable = a_OnAllChunksAvailable; + m_LuaState.Attach(a_LuaState); + m_OnChunkAvailable.RefStack(m_LuaState, a_OnChunkAvailableStackPos); + m_OnAllChunksAvailable.RefStack(m_LuaState, a_OnAllChunksAvailableStackPos); super::Enable(*a_World.GetChunkMap()); } @@ -32,9 +41,27 @@ void cLuaChunkStay::Enable( +void cLuaChunkStay::Disable(void) +{ + super::Disable(); + + // If the state was valid (bound to Lua functions), unbind those functions: + if (!m_LuaState.IsValid()) + { + return; + } + m_OnAllChunksAvailable.UnRef(); + m_OnChunkAvailable.UnRef(); + m_LuaState.Detach(); +} + + + + + void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ) { - m_LuaState->Call(m_OnChunkAvailable, a_ChunkX, a_ChunkZ); + m_LuaState.Call(m_OnChunkAvailable, a_ChunkX, a_ChunkZ); } @@ -43,7 +70,7 @@ void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ) void cLuaChunkStay::OnAllChunksAvailable(void) { - m_LuaState->Call(m_OnAllChunksAvailable); + m_LuaState.Call(m_OnAllChunksAvailable); } diff --git a/src/Bindings/LuaChunkStay.h b/src/Bindings/LuaChunkStay.h index e9d87d7f6..0ab73f669 100644 --- a/src/Bindings/LuaChunkStay.h +++ b/src/Bindings/LuaChunkStay.h @@ -24,23 +24,28 @@ class cLuaChunkStay public: // Allow Lua to construct objects of this class: - cLuaChunkStay(void) {} + cLuaChunkStay(void); // Allow Lua to garbage-collect objects of this class: - ~cLuaChunkStay() {} + ~cLuaChunkStay() { } // tolua_end - /** Enabled the ChunkStay for the specified world, with the specified Lua callbacks. + /** Enables the ChunkStay for the specified world, with the specified Lua callbacks. Exported in ManualBindings. */ void Enable( - cWorld & a_World, cLuaState & a_LuaState, - const cLuaState::cRef & a_OnChunkAvailable, const cLuaState::cRef & a_OnAllChunksAvailable + cWorld & a_World, lua_State * a_LuaState, + int a_OnChunkAvailableStackPos, int a_OnAllChunksAvailableStackPos ); + // tolua_begin + + /** Disables the ChunkStay. Cleans up the bound Lua state and callbacks */ + virtual void Disable(void); + protected: /** The Lua state associated with the callbacks. Only valid when enabled. */ - cLuaState * m_LuaState; + cLuaState m_LuaState; /** The Lua function to call in OnChunkAvailable. Only valid when enabled. */ cLuaState::cRef m_OnChunkAvailable; @@ -51,7 +56,9 @@ protected: // cChunkStay overrides: virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override; virtual void OnAllChunksAvailable(void) override; -} ; // tolua_export +} ; + +// tolua_end diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 841ec5cf2..3571fd7ea 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -8,6 +8,7 @@ #include "PluginLua.h" #include "PluginManager.h" #include "LuaWindow.h" +#include "LuaChunkStay.h" #include "../Root.h" #include "../World.h" #include "../Entities/Player.h" @@ -1638,6 +1639,42 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S) +static int tolua_cLuaChunkStay_Enable(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cLuaChunkStay") || + !L.CheckParamUserType(2, "cWorld") || + !L.CheckParamFunction(3, 4) + ) + { + return 0; + } + + // Read the params: + cLuaChunkStay * ChunkStay = (cLuaChunkStay *)tolua_tousertype(tolua_S, 1, NULL); + if (ChunkStay == NULL) + { + LOGWARNING("cLuaChunkStay:Enable(): invalid self"); + L.LogStackTrace(); + return 0; + } + cWorld * World = (cWorld *)tolua_tousertype(tolua_S, 2, NULL); + if (World == NULL) + { + LOGWARNING("cLuaChunkStay:Enable(): invalid world parameter"); + L.LogStackTrace(); + return 0; + } + + ChunkStay->Enable(*World, tolua_S, 3, 4); + return 0; +} + + + + + static int tolua_cPlayer_GetGroups(lua_State* tolua_S) { cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); @@ -2403,6 +2440,10 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "LogStackTrace", tolua_cPluginManager_LogStackTrace); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cLuaChunkStay"); + tolua_function(tolua_S, "Enable", tolua_cLuaChunkStay_Enable); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cPlayer"); tolua_function(tolua_S, "GetGroups", tolua_cPlayer_GetGroups); tolua_function(tolua_S, "GetResolvedPermissions", tolua_cPlayer_GetResolvedPermissions); diff --git a/src/ChunkStay.h b/src/ChunkStay.h index a6274812e..1e9cd69e8 100644 --- a/src/ChunkStay.h +++ b/src/ChunkStay.h @@ -62,7 +62,7 @@ public: /** Disables the ChunkStay, the chunks are released and the ChunkStay object can be edited with Add() and Remove() again*/ - void Disable(void); + virtual void Disable(void); // tolua_end -- cgit v1.2.3 From 1447d6d0dc0cca5b3362c6775c57d8483f8d8d17 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Feb 2014 20:40:20 +0100 Subject: Debuggers: Added a cLuaChunkStay test code. --- MCServer/Plugins/Debuggers/Debuggers.lua | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 521032239..fca993065 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -53,6 +53,7 @@ function Initialize(Plugin) PM:BindCommand("/fr", "debuggers", HandleFurnaceRecipe, "- Shows the furnace recipe for the currently held item"); PM:BindCommand("/ff", "debuggers", HandleFurnaceFuel, "- Shows how long the currently held item would burn in a furnace"); PM:BindCommand("/sched", "debuggers", HandleSched, "- Schedules a simple countdown using cWorld:ScheduleTask()"); + PM:BindCommand("/cs", "debuggers", HandleChunkStay, "- Tests the ChunkStay Lua integration for the specified chunk coords"); Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers); @@ -1061,3 +1062,74 @@ end + +function HandleChunkStay(a_Split, a_Player) + if (#a_Split ~= 3) then + a_Player:SendMessage("Usage: /cs ") + return true + end + + local ChunkX = tonumber(a_Split[2]) + local ChunkZ = tonumber(a_Split[3]) + if ((ChunkX == nil) or (ChunkZ == nil)) then + a_Player:SendMessage("Invalid chunk coords.") + return true + end + + local World = a_Player:GetWorld() + local PlayerID = a_Player:GetUniqueID() + + -- Create the ChunkStay object: + local ChunkStay = cLuaChunkStay() + + -- Add the wanted chunks: + for z = -1, 1 do for x = -1, 1 do + ChunkStay:Add(ChunkX + x, ChunkZ + z) + end end + + -- The function that is called when all chunks are available + -- Will perform the action and finally get rid of the ChunkStay object + -- Note that the player needs to be referenced using their EntityID - in case they disconnect before this completes + local OnAllChunksAvailable = function() + -- Build something on the neighboring chunks, to verify: + for z = -1, 1 do for x = -1, 1 do + local BlockX = (ChunkX + x) * 16 + 8 + local BlockZ = (ChunkZ + z) * 16 + 8 + for y = 20, 80 do + World:SetBlock(BlockX, y, BlockZ, E_BLOCK_OBSIDIAN, 0) + end + end end + + -- Teleport the player there for visual inspection: + World:DoWithEntityByID(PlayerID, + function (a_CallbackPlayer) + a_CallbackPlayer:TeleportToCoords(ChunkX * 16 + 8, 85, ChunkZ * 16 + 8) + a_CallbackPlayer:SendMessage("ChunkStay fully available") + end + ) + + -- Deactivate and remove the ChunkStay object (so that MCS can unload the chunks): + -- Forgetting this might crash the server when it stops! + ChunkStay:Disable() + ChunkStay = nil + end + + -- This function will be called for each chunk that is made available + -- Note that the player needs to be referenced using their EntityID - in case they disconnect before this completes + local OnChunkAvailable = function(a_ChunkX, a_ChunkZ) + LOGINFO("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") + World:DoWithEntityByID(PlayerID, + function (a_CallbackPlayer) + a_CallbackPlayer:SendMessage("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") + end + ) + end + + -- Activate the ChunkStay: + ChunkStay:Enable(World, OnChunkAvailable, OnAllChunksAvailable) + return true +end + + + + -- cgit v1.2.3 From 8028a8bbc6b625da265791dc6a0628e215f2b643 Mon Sep 17 00:00:00 2001 From: narroo Date: Mon, 10 Feb 2014 11:22:15 -0500 Subject: Typo Fix in console.lua --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 7f97e93ef..5fe3662a8 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 7f97e93ef25616673e8342b7919d9b5914e1327e +Subproject commit 5fe3662a8719f79cb2ca0a16150c716a3c5eb19c -- cgit v1.2.3 From 75e0b38d835d5707494218748a404bc284f37852 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Mon, 10 Feb 2014 18:17:44 +0100 Subject: Maybe fixed boat placing --- src/Items/ItemBoat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index 31d1ca52e..dd6eaaf14 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -31,7 +31,7 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { - if (a_Dir != BLOCK_FACE_YM || a_Dir != BLOCK_FACE_NONE) + if (a_Dir > 0) { return false; } -- cgit v1.2.3 From 23f69bc0931a6b2f5b9575283abb6c63d306655a Mon Sep 17 00:00:00 2001 From: worktycho Date: Mon, 10 Feb 2014 17:59:17 +0000 Subject: Fixed stupid mistax in conditional boats can't be placed if the face is not block_face_none and not block_face_YM, not if it is only not one. --- src/Items/ItemBoat.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index 31d1ca52e..929533c9c 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -1,4 +1,3 @@ - // ItemBoat.h // Declares the various boat ItemHandlers @@ -31,7 +30,7 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { - if (a_Dir != BLOCK_FACE_YM || a_Dir != BLOCK_FACE_NONE) + if (a_Dir != BLOCK_FACE_YM && a_Dir != BLOCK_FACE_NONE) { return false; } -- cgit v1.2.3 From 7ad4a86c4947a619951db9fdad4f37bbb4252236 Mon Sep 17 00:00:00 2001 From: worktycho Date: Mon, 10 Feb 2014 18:06:49 +0000 Subject: Added additional parenthasies --- src/Items/ItemBoat.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index b45485251..a28ec8e22 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -1,4 +1,3 @@ - // ItemBoat.h // Declares the various boat ItemHandlers @@ -31,7 +30,7 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { - if (a_Dir != BLOCK_FACE_YM && a_Dir != BLOCK_FACE_NONE) + if ((a_Dir != BLOCK_FACE_YM) && (a_Dir != BLOCK_FACE_NONE)) { return false; } -- cgit v1.2.3 From 5aa1123f70303316b13b4a1377b4e970cd2bc707 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 10 Feb 2014 20:38:02 +0100 Subject: Added cPluginLua::cOperation. This class should be used to lock-and-access the plugin's LuaState. cPluginLua::GetLuaState() is unsafe and by this commit obsolete. --- src/Bindings/PluginLua.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index ad0cfbe5a..a177f5288 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -35,7 +35,33 @@ class cPluginLua : public: // tolua_end - cPluginLua( const AString & a_PluginDirectory ); + /** A RAII-style mutex lock for accessing the internal LuaState. + This will be the only way to retrieve the plugin's LuaState; + therefore it directly supports accessing the LuaState of the locked plugin. + Usage: + cPluginLua::cOperation Op(SomePlugin); + Op().Call(...) // Call a function in the plugin's LuaState + */ + class cOperation + { + public: + cOperation(cPluginLua & a_Plugin) : + m_Plugin(a_Plugin), + m_Lock(a_Plugin.m_CriticalSection) + { + } + + cLuaState & operator ()(void) { return m_Plugin.m_LuaState; } + + protected: + cPluginLua & m_Plugin; + + /** RAII lock for m_Plugin.m_CriticalSection */ + cCSLock m_Lock; + } ; + + + cPluginLua(const AString & a_PluginDirectory); ~cPluginLua(); virtual void OnDisable(void) override; -- cgit v1.2.3 From 0cf1c1d91d97efeb968382bc95b3a8e9a836496f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 10 Feb 2014 20:13:22 +0000 Subject: Updated MagicCarpet and Core --- MCServer/Plugins/Core | 2 +- MCServer/Plugins/MagicCarpet/coremessaging.lua | 19 ------------------- MCServer/Plugins/MagicCarpet/plugin.lua | 8 ++++---- 3 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 MCServer/Plugins/MagicCarpet/coremessaging.lua diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 7f97e93ef..8ddc8a9d0 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 7f97e93ef25616673e8342b7919d9b5914e1327e +Subproject commit 8ddc8a9d027a9471c72270ec82cc618069710faa diff --git a/MCServer/Plugins/MagicCarpet/coremessaging.lua b/MCServer/Plugins/MagicCarpet/coremessaging.lua deleted file mode 100644 index 9fb2c0db1..000000000 --- a/MCServer/Plugins/MagicCarpet/coremessaging.lua +++ /dev/null @@ -1,19 +0,0 @@ -Core = cPluginManager:Get():GetPlugin("Core") - -function SendMessage(a_Player, a_Message) - if (Core ~= nil) then - Core:Call("SendMessage", a_Player, a_Message) - end -end - -function SendMessageSuccess(a_Player, a_Message) - if (Core ~= nil) then - Core:Call("SendMessageSuccess", a_Player, a_Message) - end -end - -function SendMessageFailure(a_Player, a_Message) - if (Core ~= nil) then - Core:Call("SendMessageFailure", a_Player, a_Message) - end -end diff --git a/MCServer/Plugins/MagicCarpet/plugin.lua b/MCServer/Plugins/MagicCarpet/plugin.lua index b05816e48..417ea0e02 100644 --- a/MCServer/Plugins/MagicCarpet/plugin.lua +++ b/MCServer/Plugins/MagicCarpet/plugin.lua @@ -6,7 +6,7 @@ function Initialize( Plugin ) Plugin:SetVersion( 2 ) cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_MOVING, OnPlayerMoving) - cPluginManager.AddHook(cPluginManager.HOOK_DISCONNECT, OnDisconnect) + cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_DESTROYED, OnDisconnect) local PluginManager = cPluginManager:Get() PluginManager:BindCommand("/mc", "magiccarpet", HandleCarpetCommand, " - Spawns a magical carpet"); @@ -37,12 +37,12 @@ function HandleCarpetCommand( Split, Player ) if( Carpet == nil ) then Carpets[ Player ] = cCarpet:new() - SendMessageSuccess(Player, "You're on a magic carpet!") - SendMessage(Player, "Look straight down to descend. Jump to ascend.") + Player:SendMessageSuccess("You're on a magic carpet!") + Player:SendMessageInfo("Look straight down to descend. Jump to ascend.") else Carpet:remove() Carpets[ Player ] = nil - SendMessageSuccess(Player, "The carpet vanished!") + Player:SendMessageSuccess("The carpet vanished!") end return true -- cgit v1.2.3 From 589a4839dfe05810235a16f430e72f5e622b09ee Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 10 Feb 2014 22:44:56 +0100 Subject: cLuaState: Stack traces don't include ghost 0-th element. --- src/Bindings/LuaState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 22f342467..8f2a70a60 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1206,7 +1206,7 @@ void cLuaState::LogStack(const char * a_Header) void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header) { LOGD((a_Header != NULL) ? a_Header : "Lua C API Stack contents:"); - for (int i = lua_gettop(a_LuaState); i >= 0; i--) + for (int i = lua_gettop(a_LuaState); i > 0; i--) { AString Value; int Type = lua_type(a_LuaState, i); -- cgit v1.2.3 From 9cebc9157cf43ba639227b9d79b980b3613dda1e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 10 Feb 2014 22:47:10 +0100 Subject: Rewritten Lua ChunkStay API into a single function, cWorld:ChunkStay(). This fixes problems with indeterminate class object lifespan (Lua-GC) and forgetting to disable it or keep it until ready. --- src/Bindings/AllToLua.pkg | 2 - src/Bindings/LuaChunkStay.cpp | 146 +++++++++++++++++++++++++++++++++------- src/Bindings/LuaChunkStay.h | 48 +++++++------ src/Bindings/ManualBindings.cpp | 40 ++++++----- src/ChunkMap.cpp | 13 +++- src/ChunkStay.cpp | 7 +- src/ChunkStay.h | 27 +++----- src/LightingThread.cpp | 14 +++- src/LightingThread.h | 3 +- 9 files changed, 213 insertions(+), 87 deletions(-) diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index a78ee7d56..f65aed9bb 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -24,7 +24,6 @@ $cfile "Plugin.h" $cfile "PluginLua.h" $cfile "WebPlugin.h" $cfile "LuaWindow.h" -$cfile "LuaChunkStay.h" $cfile "../BlockID.h" $cfile "../StringUtils.h" @@ -71,7 +70,6 @@ $cfile "../Generating/ChunkDesc.h" $cfile "../CraftingRecipes.h" $cfile "../UI/Window.h" $cfile "../Mobs/Monster.h" -$cfile "../ChunkStay.h" diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp index f84964f56..0e982637f 100644 --- a/src/Bindings/LuaChunkStay.cpp +++ b/src/Bindings/LuaChunkStay.cpp @@ -1,18 +1,20 @@ // LuaChunkStay.cpp -// Implements the cLuaChunkStay class representing a cChunkStay binding for plugins +// Implements the cLuaChunkStay class representing a cChunkStay binding for plugins, used by cWorld:ChunkStay() Lua API #include "Globals.h" #include "LuaChunkStay.h" +#include "PluginLua.h" #include "../World.h" -cLuaChunkStay::cLuaChunkStay(void) : - m_LuaState((lua_State *)NULL) // Want a detached Lua state by default +cLuaChunkStay::cLuaChunkStay(cPluginLua & a_Plugin) : + m_Plugin(a_Plugin), + m_LuaState(NULL) { } @@ -20,39 +22,107 @@ cLuaChunkStay::cLuaChunkStay(void) : -void cLuaChunkStay::Enable( - cWorld & a_World, lua_State * a_LuaState, - int a_OnChunkAvailableStackPos, int a_OnAllChunksAvailableStackPos -) +bool cLuaChunkStay::AddChunks(int a_ChunkCoordTableStackPos) { - if (m_LuaState.IsValid()) + // This function is expected to be called just once, with all the coords in a table + ASSERT(m_Chunks.empty()); + + cPluginLua::cOperation Op(m_Plugin); + cLuaState & L = Op(); + + // Check that we got a table: + if (!lua_istable(L, a_ChunkCoordTableStackPos)) { - LOGWARNING("LuaChunkStay: Already enabled. Ignoring this call."); - cLuaState::LogStackTrace(a_LuaState); - return; + LOGWARNING("%s: The parameter is not a table of coords (got %s). Ignoring the call.", + __FUNCTION__, lua_typename(L, lua_type(L, a_ChunkCoordTableStackPos)) + ); + L.LogStackTrace(); + return false; + } + + // Add each set of coords: + int NumChunks = luaL_getn(L, a_ChunkCoordTableStackPos); + m_Chunks.reserve(NumChunks); + for (int idx = 1; idx <= NumChunks; idx++) + { + // Push the idx-th element of the array onto stack top, check that it's a table: + lua_rawgeti(L, a_ChunkCoordTableStackPos, idx); + if (!lua_istable(L, -1)) + { + LOGWARNING("%s: Element #%d is not a table (got %s). Ignoring the element.", + __FUNCTION__, idx, lua_typename(L, -1) + ); + L.LogStackTrace(); + lua_pop(L, 1); + continue; + } + AddChunkCoord(L, idx); + lua_pop(L, 1); } - m_LuaState.Attach(a_LuaState); - m_OnChunkAvailable.RefStack(m_LuaState, a_OnChunkAvailableStackPos); - m_OnAllChunksAvailable.RefStack(m_LuaState, a_OnAllChunksAvailableStackPos); - super::Enable(*a_World.GetChunkMap()); + + // If there are no chunks, log a warning and return failure: + if (m_Chunks.empty()) + { + LOGWARNING("%s: Zero chunks to stay.", __FUNCTION__); + L.LogStackTrace(); + return false; + } + + // All ok + return true; } -void cLuaChunkStay::Disable(void) +void cLuaChunkStay::AddChunkCoord(cLuaState & L, int a_Index) { - super::Disable(); - - // If the state was valid (bound to Lua functions), unbind those functions: - if (!m_LuaState.IsValid()) + // Check that the element has 2 coords: + int NumCoords = luaL_getn(L, -1); + if (NumCoords != 2) { + LOGWARNING("%s: Element #%d doesn't contain 2 coords (got %d). Ignoring the element.", + __FUNCTION__, a_Index, NumCoords + ); return; } - m_OnAllChunksAvailable.UnRef(); - m_OnChunkAvailable.UnRef(); - m_LuaState.Detach(); + + // Read the two coords from the element: + lua_rawgeti(L, -1, 1); + lua_rawgeti(L, -2, 2); + int ChunkX = luaL_checkint(L, -2); + int ChunkZ = luaL_checkint(L, -1); + lua_pop(L, 2); + + // Check that a coord is not yet present: + for (cChunkCoordsVector::iterator itr = m_Chunks.begin(), end = m_Chunks.end(); itr != end; ++itr) + { + if ((itr->m_ChunkX == ChunkX) && (itr->m_ChunkZ == ChunkZ)) + { + LOGWARNING("%s: Element #%d is a duplicate, ignoring it.", + __FUNCTION__, a_Index + ); + return; + } + } // for itr - m_Chunks[] + + m_Chunks.push_back(cChunkCoords(ChunkX, ZERO_CHUNK_Y, ChunkZ)); +} + + + + + +void cLuaChunkStay::Enable(cChunkMap & a_ChunkMap, int a_OnChunkAvailableStackPos, int a_OnAllChunksAvailableStackPos) +{ + // Get the references to the callback functions: + m_LuaState = &m_Plugin.GetLuaState(); + m_OnChunkAvailable.RefStack(*m_LuaState, a_OnChunkAvailableStackPos); + m_OnAllChunksAvailable.RefStack(*m_LuaState, a_OnAllChunksAvailableStackPos); + + // Enable the ChunkStay: + super::Enable(a_ChunkMap); } @@ -61,19 +131,43 @@ void cLuaChunkStay::Disable(void) void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ) { - m_LuaState.Call(m_OnChunkAvailable, a_ChunkX, a_ChunkZ); + // DEBUG: + LOGD("LuaChunkStay: Chunk [%d, %d] is now available, calling the callback...", a_ChunkX, a_ChunkZ); + + cPluginLua::cOperation Op(m_Plugin); + Op().Call((int)m_OnChunkAvailable, a_ChunkX, a_ChunkZ); } -void cLuaChunkStay::OnAllChunksAvailable(void) +bool cLuaChunkStay::OnAllChunksAvailable(void) { - m_LuaState.Call(m_OnAllChunksAvailable); + { + // Call the callback: + cPluginLua::cOperation Op(m_Plugin); + Op().Call((int)m_OnAllChunksAvailable); + + // Remove the callback references - they won't be needed anymore + m_OnChunkAvailable.UnRef(); + m_OnAllChunksAvailable.UnRef(); + } + + // Disable the ChunkStay by returning true + return true; } +void cLuaChunkStay::OnDisabled(void) +{ + // This object is no longer needed, delete it + delete this; +} + + + + diff --git a/src/Bindings/LuaChunkStay.h b/src/Bindings/LuaChunkStay.h index 0ab73f669..49ab9a0ad 100644 --- a/src/Bindings/LuaChunkStay.h +++ b/src/Bindings/LuaChunkStay.h @@ -1,7 +1,7 @@ // LuaChunkStay.h -// Declares the cLuaChunkStay class representing a cChunkStay binding for plugins +// Declares the cLuaChunkStay class representing a cChunkStay binding for plugins, used by cWorld:ChunkStay() Lua API @@ -16,36 +16,36 @@ -// tolua_begin +// fwd: +class cPluginLua; + + + + + class cLuaChunkStay : public cChunkStay { typedef cChunkStay super; public: - // Allow Lua to construct objects of this class: - cLuaChunkStay(void); + cLuaChunkStay(cPluginLua & a_Plugin); - // Allow Lua to garbage-collect objects of this class: ~cLuaChunkStay() { } - // tolua_end + /** Adds chunks in the specified on-stack Lua table. + Returns true if any chunk added, false (plus log warning) if none. */ + bool AddChunks(int a_ChunkCoordTableStackPos); - /** Enables the ChunkStay for the specified world, with the specified Lua callbacks. - Exported in ManualBindings. */ - void Enable( - cWorld & a_World, lua_State * a_LuaState, - int a_OnChunkAvailableStackPos, int a_OnAllChunksAvailableStackPos - ); - - // tolua_begin - - /** Disables the ChunkStay. Cleans up the bound Lua state and callbacks */ - virtual void Disable(void); + /** Enables the ChunkStay for the specified chunkmap, with the specified Lua callbacks. */ + void Enable(cChunkMap & a_ChunkMap, int a_OnChunkAvailableStackPos, int a_OnAllChunksAvailableStackPos); protected: + /** The plugin which has created the ChunkStay, via cWorld:ChunkStay() binding method. */ + cPluginLua & m_Plugin; + /** The Lua state associated with the callbacks. Only valid when enabled. */ - cLuaState m_LuaState; + cLuaState * m_LuaState; /** The Lua function to call in OnChunkAvailable. Only valid when enabled. */ cLuaState::cRef m_OnChunkAvailable; @@ -53,12 +53,20 @@ protected: /** The Lua function to call in OnAllChunksAvailable. Only valid when enabled. */ cLuaState::cRef m_OnAllChunksAvailable; + // cChunkStay overrides: virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override; - virtual void OnAllChunksAvailable(void) override; + virtual bool OnAllChunksAvailable(void) override; + virtual void OnDisabled(void) override; + + /** Adds a single chunk coord from the table at the top of the Lua stack. + Expects the top element to be a table, checks that it contains two numbers. + Uses those two numbers as chunk coords appended to m_Chunks. + If the coords are already present, gives a warning and ignores the pair. + The a_Index parameter is only for the error messages. */ + void AddChunkCoord(cLuaState & a_LuaState, int a_Index); } ; -// tolua_end diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 3571fd7ea..f0bad92e8 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1639,35 +1639,46 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S) -static int tolua_cLuaChunkStay_Enable(lua_State * tolua_S) +static int tolua_cWorld_ChunkStay(lua_State * tolua_S) { + /* Function signature: + World:ChunkStay(ChunkCoordTable, OnChunkAvailable, OnAllChunksAvailable) + ChunkCoordTable == { {Chunk1x, Chunk1z}, {Chunk2x, Chunk2z}, ... } + */ + cLuaState L(tolua_S); if ( - !L.CheckParamUserType(1, "cLuaChunkStay") || - !L.CheckParamUserType(2, "cWorld") || + !L.CheckParamUserType(1, "cWorld") || + !L.CheckParamTable (2) || !L.CheckParamFunction(3, 4) ) { return 0; } - // Read the params: - cLuaChunkStay * ChunkStay = (cLuaChunkStay *)tolua_tousertype(tolua_S, 1, NULL); - if (ChunkStay == NULL) + cPluginLua * Plugin = GetLuaPlugin(tolua_S); + if (Plugin == NULL) { - LOGWARNING("cLuaChunkStay:Enable(): invalid self"); - L.LogStackTrace(); return 0; } - cWorld * World = (cWorld *)tolua_tousertype(tolua_S, 2, NULL); + cLuaChunkStay * ChunkStay = new cLuaChunkStay(*Plugin); + + // Read the params: + cWorld * World = (cWorld *)tolua_tousertype(tolua_S, 1, NULL); if (World == NULL) { - LOGWARNING("cLuaChunkStay:Enable(): invalid world parameter"); + LOGWARNING("World:ChunkStay(): invalid world parameter"); L.LogStackTrace(); return 0; } - - ChunkStay->Enable(*World, tolua_S, 3, 4); + L.LogStack("Before AddChunks()"); + if (!ChunkStay->AddChunks(2)) + { + return 0; + } + L.LogStack("After params read"); + + ChunkStay->Enable(*World->GetChunkMap(), 3, 4); return 0; } @@ -2397,6 +2408,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cWorld"); + tolua_function(tolua_S, "ChunkStay", tolua_cWorld_ChunkStay); tolua_function(tolua_S, "DoWithBlockEntityAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithChestAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithDispenserAt", tolua_DoWithXYZ); @@ -2440,10 +2452,6 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "LogStackTrace", tolua_cPluginManager_LogStackTrace); tolua_endmodule(tolua_S); - tolua_beginmodule(tolua_S, "cLuaChunkStay"); - tolua_function(tolua_S, "Enable", tolua_cLuaChunkStay_Enable); - tolua_endmodule(tolua_S); - tolua_beginmodule(tolua_S, "cPlayer"); tolua_function(tolua_S, "GetGroups", tolua_cPlayer_GetGroups); tolua_function(tolua_S, "GetResolvedPermissions", tolua_cPlayer_GetResolvedPermissions); diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 7726a0b7e..0c5a8d9b9 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -912,9 +912,18 @@ void cChunkMap::SetChunkData( } // Notify relevant ChunkStays: - for (cChunkStays::iterator itr = m_ChunkStays.begin(), end = m_ChunkStays.end(); itr != end; ++itr) + for (cChunkStays::iterator itr = m_ChunkStays.begin(); itr != m_ChunkStays.end(); ) { - (*itr)->ChunkAvailable(a_ChunkX, a_ChunkZ); + if ((*itr)->ChunkAvailable(a_ChunkX, a_ChunkZ)) + { + cChunkStays::iterator cur = itr; + ++itr; + m_ChunkStays.erase(cur); + } + else + { + ++itr; + } } // for itr - m_ChunkStays[] } diff --git a/src/ChunkStay.cpp b/src/ChunkStay.cpp index cce8d5f4d..6b1d5ee34 100644 --- a/src/ChunkStay.cpp +++ b/src/ChunkStay.cpp @@ -105,7 +105,7 @@ void cChunkStay::Disable(void) -void cChunkStay::ChunkAvailable(int a_ChunkX, int a_ChunkZ) +bool cChunkStay::ChunkAvailable(int a_ChunkX, int a_ChunkZ) { // Check if this is a chunk that we want: bool IsMine = false; @@ -120,15 +120,16 @@ void cChunkStay::ChunkAvailable(int a_ChunkX, int a_ChunkZ) } // for itr - m_OutstandingChunks[] if (!IsMine) { - return; + return false; } // Call the appropriate callbacks: OnChunkAvailable(a_ChunkX, a_ChunkZ); if (m_OutstandingChunks.empty()) { - OnAllChunksAvailable(); + return OnAllChunksAvailable(); } + return false; } diff --git a/src/ChunkStay.h b/src/ChunkStay.h index 1e9cd69e8..80b084aee 100644 --- a/src/ChunkStay.h +++ b/src/ChunkStay.h @@ -32,48 +32,42 @@ This class is abstract, the descendants are expected to provide the OnChunkAvail the OnAllChunksAvailable() callback implementations. Note that those are called from the contexts of different threads' - the caller, the Loader or the Generator thread. */ -// tolua_begin class cChunkStay { public: - // tolua_end cChunkStay(void); ~cChunkStay(); - // tolua_begin - void Clear(void); /** Adds a chunk to be locked from unloading. To be used only while the ChunkStay object is not enabled. */ - void Add (int a_ChunkX, int a_ChunkZ); + void Add(int a_ChunkX, int a_ChunkZ); /** Releases the chunk so that it's no longer locked from unloading. To be used only while the ChunkStay object is not enabled. */ void Remove(int a_ChunkX, int a_ChunkZ); - // tolua_end - /** Enables the ChunkStay on the specified chunkmap, causing it to load and generate chunks. All the contained chunks are queued for loading / generating. */ void Enable (cChunkMap & a_ChunkMap); - // tolua_begin - /** Disables the ChunkStay, the chunks are released and the ChunkStay object can be edited with Add() and Remove() again*/ virtual void Disable(void); - // tolua_end - /** Returns all the chunks that should be kept */ const cChunkCoordsVector & GetChunks(void) const { return m_Chunks; } /** Called when a specific chunk become available. */ virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) = 0; - /** Caled once all of the contained chunks are available. */ - virtual void OnAllChunksAvailable(void) = 0; + /** Caled once all of the contained chunks are available. + If returns true, the ChunkStay is automatically disabled by the ChunkMap; if it returns false, the ChunkStay is kept. */ + virtual bool OnAllChunksAvailable(void) = 0; + + /** Called by the ChunkMap when the ChunkStay is disabled. The object may choose to delete itself. */ + virtual void OnDisabled(void) = 0; protected: @@ -92,9 +86,10 @@ protected: /** Called by cChunkMap when a chunk is available, checks m_NumLoaded and triggers the appropriate callbacks. - May be called for chunks outside this ChunkStay. */ - void ChunkAvailable(int a_ChunkX, int a_ChunkZ); -} ; // tolua_export + May be called for chunks outside this ChunkStay. + Returns true if the ChunkStay is to be automatically disabled by the ChunkMap; returns false to keep the ChunkStay. */ + bool ChunkAvailable(int a_ChunkX, int a_ChunkZ); +} ; diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index 688f119ff..9c81d004d 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -548,9 +548,21 @@ cLightingThread::cLightingChunkStay::cLightingChunkStay(cLightingThread & a_Ligh -void cLightingThread::cLightingChunkStay::OnAllChunksAvailable(void) +bool cLightingThread::cLightingChunkStay::OnAllChunksAvailable(void) { m_LightingThread.QueueChunkStay(*this); + + // Keep the ChunkStay alive: + return false; +} + + + + + +void cLightingThread::cLightingChunkStay::OnDisabled(void) +{ + // Nothing needed in this callback } diff --git a/src/LightingThread.h b/src/LightingThread.h index 0e17c485f..81dd9d61f 100644 --- a/src/LightingThread.h +++ b/src/LightingThread.h @@ -83,7 +83,8 @@ protected: protected: virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override {} - virtual void OnAllChunksAvailable(void) override; + virtual bool OnAllChunksAvailable(void) override; + virtual void OnDisabled(void) override; } ; typedef std::list cChunkStays; -- cgit v1.2.3 From 2b1506de9c92539bfe7ffaceef87b5dd610bd04c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 10 Feb 2014 22:47:32 +0100 Subject: Debuggers: Updated to reflect the new API. --- MCServer/Plugins/Debuggers/Debuggers.lua | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index fca993065..853b0a1dc 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -1079,18 +1079,17 @@ function HandleChunkStay(a_Split, a_Player) local World = a_Player:GetWorld() local PlayerID = a_Player:GetUniqueID() - -- Create the ChunkStay object: - local ChunkStay = cLuaChunkStay() - - -- Add the wanted chunks: + -- Set the wanted chunks: + local Chunks = {} for z = -1, 1 do for x = -1, 1 do - ChunkStay:Add(ChunkX + x, ChunkZ + z) + table.insert(Chunks, {ChunkX + x, ChunkZ + z}) end end -- The function that is called when all chunks are available - -- Will perform the action and finally get rid of the ChunkStay object - -- Note that the player needs to be referenced using their EntityID - in case they disconnect before this completes + -- Will perform the actual action with all those chunks + -- Note that the player needs to be referenced using their EntityID - in case they disconnect before the chunks load local OnAllChunksAvailable = function() + LOGINFO("ChunkStay all chunks now available") -- Build something on the neighboring chunks, to verify: for z = -1, 1 do for x = -1, 1 do local BlockX = (ChunkX + x) * 16 + 8 @@ -1107,15 +1106,10 @@ function HandleChunkStay(a_Split, a_Player) a_CallbackPlayer:SendMessage("ChunkStay fully available") end ) - - -- Deactivate and remove the ChunkStay object (so that MCS can unload the chunks): - -- Forgetting this might crash the server when it stops! - ChunkStay:Disable() - ChunkStay = nil end -- This function will be called for each chunk that is made available - -- Note that the player needs to be referenced using their EntityID - in case they disconnect before this completes + -- Note that the player needs to be referenced using their EntityID - in case they disconnect before the chunks load local OnChunkAvailable = function(a_ChunkX, a_ChunkZ) LOGINFO("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") World:DoWithEntityByID(PlayerID, @@ -1125,8 +1119,8 @@ function HandleChunkStay(a_Split, a_Player) ) end - -- Activate the ChunkStay: - ChunkStay:Enable(World, OnChunkAvailable, OnAllChunksAvailable) + -- Process the ChunkStay: + World:ChunkStay(Chunks, OnChunkAvailable, OnAllChunksAvailable) return true end -- cgit v1.2.3 From de7bf126dbd6601272eac725955394691631a527 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 10 Feb 2014 23:23:04 +0100 Subject: Added LuaChunkStay to Bindings sources. This should fix *nix compilation. Also alpha-sorted the lists. --- src/CMakeLists.txt | 83 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50caf5f4f..6ba952f92 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,60 +20,60 @@ if (NOT MSVC) set(BINDING_DEPENDECIES ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/virtual_method_hooks.lua ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/AllToLua.pkg - ChunkDef.h - BiomeDef.h - OSSupport/File.h Bindings/LuaFunctions.h - Bindings/PluginManager.h + Bindings/LuaWindow.h Bindings/Plugin.h Bindings/PluginLua.h + Bindings/PluginManager.h Bindings/WebPlugin.h - Bindings/LuaWindow.h + BiomeDef.h + BlockArea.h + BlockEntities/BlockEntity.h + BlockEntities/BlockEntityWithItems.h + BlockEntities/ChestEntity.h + BlockEntities/DispenserEntity.h + BlockEntities/DropSpenserEntity.h + BlockEntities/DropperEntity.h + BlockEntities/FurnaceEntity.h + BlockEntities/HopperEntity.h + BlockEntities/JukeboxEntity.h + BlockEntities/NoteEntity.h + BlockEntities/SignEntity.h BlockID.h - StringUtils.h - Defines.h + BoundingBox.h ChatColor.h + ChunkDef.h ClientHandle.h + CraftingRecipes.h + Cuboid.h + Defines.h + Enchantments.h + Entities/Effects.h Entities/Entity.h Entities/Floater.h Entities/Pawn.h - Entities/Player.h Entities/Pickup.h + Entities/Player.h Entities/ProjectileEntity.h Entities/TNTEntity.h - Entities/Effects.h - Server.h - World.h + Generating/ChunkDesc.h + Group.h Inventory.h - Enchantments.h Item.h ItemGrid.h - BlockEntities/BlockEntity.h - BlockEntities/BlockEntityWithItems.h - BlockEntities/ChestEntity.h - BlockEntities/DropSpenserEntity.h - BlockEntities/DispenserEntity.h - BlockEntities/DropperEntity.h - BlockEntities/FurnaceEntity.h - BlockEntities/HopperEntity.h - BlockEntities/JukeboxEntity.h - BlockEntities/NoteEntity.h - BlockEntities/SignEntity.h - WebAdmin.h - Root.h - Vector3f.h - Vector3d.h - Vector3i.h Matrix4f.h - Cuboid.h - BoundingBox.h + Mobs/Monster.h + OSSupport/File.h + Root.h + Server.h + StringUtils.h Tracer.h - Group.h - BlockArea.h - Generating/ChunkDesc.h - CraftingRecipes.h UI/Window.h - Mobs/Monster.h + Vector3d.h + Vector3f.h + Vector3i.h + WebAdmin.h + World.h ) include_directories(Bindings) @@ -91,7 +91,18 @@ if (NOT MSVC) DEPENDS ${BINDING_DEPENDECIES} ) #add cpp files here - add_library(Bindings Bindings/PluginManager Bindings/LuaState Bindings/WebPlugin Bindings/Bindings Bindings/ManualBindings Bindings/LuaWindow Bindings/Plugin Bindings/PluginLua Bindings/WebPlugin) + add_library(Bindings + Bindings/Bindings + Bindings/LuaChunkStay + Bindings/LuaState + Bindings/LuaWindow + Bindings/ManualBindings + Bindings/Plugin + Bindings/PluginLua + Bindings/PluginManager + Bindings/WebPlugin + Bindings/WebPlugin + ) target_link_libraries(Bindings lua sqlite tolualib) -- cgit v1.2.3 From e8e76a6058988cb0cff222579049fb6aa3cdb9c1 Mon Sep 17 00:00:00 2001 From: narroo Date: Mon, 10 Feb 2014 20:00:07 -0500 Subject: Fixed bug #385. UnloadUnusedChunks now has the same interface as SaveAllChunks. Meaning, QueueUnloadUnusedChunks and the supporting cTaskUnloadUnusedChunks has been added. Use QueueUnloadUnusedChunks from now on to prevent deadlocking. --- lib/polarssl | 2 +- src/World.cpp | 10 ++++++++++ src/World.h | 16 +++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/polarssl b/lib/polarssl index 2cb1a0c40..2ceda5798 160000 --- a/lib/polarssl +++ b/lib/polarssl @@ -1 +1 @@ -Subproject commit 2cb1a0c4009ecf368ecc74eb428394e10f9e6d00 +Subproject commit 2ceda579893ceb23c5eb0d56df47dc235644e0f4 diff --git a/src/World.cpp b/src/World.cpp index 662a9a4b8..9120f8d7d 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2213,6 +2213,10 @@ void cWorld::UnloadUnusedChunks(void) } +void cWorld::QueueUnloadUnusedChunks(void) +{ + QueueTask(new cWorld::cTaskUnloadUnusedChunks); +} @@ -2966,7 +2970,13 @@ void cWorld::cTaskSaveAllChunks::Run(cWorld & a_World) } +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cWorld::cTaskUnloadUnusedChunks +void cWorld::cTaskUnloadUnusedChunks::Run(cWorld & a_World) +{ + a_World.UnloadUnusedChunks(); +} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/World.h b/src/World.h index 0174be03b..e4036d8df 100644 --- a/src/World.h +++ b/src/World.h @@ -99,6 +99,15 @@ public: } ; + class cTaskUnloadUnusedChunks : + public cTask + { + protected: + // cTask overrides: + virtual void Run(cWorld & a_World) override; + }; + + static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates { return "cWorld"; @@ -243,7 +252,12 @@ public: bool IsChunkValid (int a_ChunkX, int a_ChunkZ) const; bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const; - void UnloadUnusedChunks(void); // tolua_export + + /*Unloads all chunks immediately. Dangerous interface, may deadlock, use QueueUnloadUnusedChunks() instead*/ + void UnloadUnusedChunks(void); + + /*Queues a task to unload unused chunks onto the tick thread. The prefferred way of unloading*/ + void QueueUnloadUnusedChunks(void); // tolua_export void CollectPickupsByPlayer(cPlayer * a_Player); -- cgit v1.2.3 From a25fcd25d6638027a9ea2cf874d2580ba7105f3f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 11 Feb 2014 07:51:32 +0100 Subject: APIDump: Documented cWorld:ChunkStay(). --- MCServer/Plugins/APIDump/APIDesc.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index c0056ac4a..01554d99c 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2035,6 +2035,7 @@ end BroadcastSoundParticleEffect = { Params = "EffectID, X, Y, Z, EffectData, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the specified effect to all players in this world, except the optional ExceptClient" }, CastThunderbolt = { Params = "X, Y, Z", Return = "", Notes = "Creates a thunderbolt at the specified coords" }, ChangeWeather = { Params = "", Return = "", Notes = "Forces the weather to change in the next game tick. Weather is changed according to the normal rules: wSunny <-> wRain <-> wStorm" }, + ChunkStay = { Params = "ChunkCoordTable, OnChunkAvailable, OnAllChunksAvailable", Return = "", Notes = "Queues the specified chunks to be loaded or generated and calls the specified callbacks once they are loaded. ChunkCoordTable is an arra-table of chunk coords, each coord being a table of 2 numbers: { {Chunk1x, Chunk1z}, {Chunk2x, Chunk2z}, ...}. When any of those chunks are made available (including being available at the start of this call), the OnChunkAvailable() callback is called. When all the chunks are available, the OnAllChunksAvailable() callback is called. The function signatures are:
function OnChunkAvailable(ChunkX, ChunkZ)\nfunction OnAllChunksAvailable()
All return values from the callbacks are ignored." }, CreateProjectile = { Params = "X, Y, Z, {{cProjectileEntity|ProjectileKind}}, {{cEntity|Creator}}, [{{Vector3d|Speed}}]", Return = "", Notes = "Creates a new projectile of the specified kind at the specified coords. The projectile's creator is set to Creator (may be nil). Optional speed indicates the initial speed for the projectile." }, DigBlock = { Params = "X, Y, Z", Return = "", Notes = "Replaces the specified block with air, without dropping the usual pickups for the block. Wakes up the simulators for the block and its neighbors." }, DoExplosionAt = { Params = "Force, X, Y, Z, CanCauseFire, Source, SourceData", Return = "", Notes = "Creates an explosion of the specified relative force in the specified position. If CanCauseFire is set, the explosion will set blocks on fire, too. The Source parameter specifies the source of the explosion, one of the esXXX constants. The SourceData parameter is specific to each source type, usually it provides more info about the source." }, -- cgit v1.2.3 From b41bb3bb44bbc098622e45e17ed3adf34eadf2aa Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 11 Feb 2014 08:52:14 +0100 Subject: Fixed nested plugin function calls. --- src/Bindings/LuaState.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 8f2a70a60..24e64d9b2 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -735,17 +735,20 @@ bool cLuaState::CallFunction(int a_NumResults) ASSERT(lua_isfunction(m_LuaState, -m_NumCurrentFunctionArgs - 1)); // The function to call ASSERT(lua_isfunction(m_LuaState, -m_NumCurrentFunctionArgs - 2)); // The error handler - int s = lua_pcall(m_LuaState, m_NumCurrentFunctionArgs, a_NumResults, -m_NumCurrentFunctionArgs - 2); + // Save the current "stack" state and reset, in case the callback calls another function: + AString CurrentFunctionName; + std::swap(m_CurrentFunctionName, CurrentFunctionName); + int NumArgs = m_NumCurrentFunctionArgs; + m_NumCurrentFunctionArgs = -1; + + // Call the function: + int s = lua_pcall(m_LuaState, NumArgs, a_NumResults, -NumArgs - 2); if (s != 0) { // The error has already been printed together with the stacktrace - LOGWARNING("Error in %s calling function %s()", m_SubsystemName.c_str(), m_CurrentFunctionName.c_str()); - m_NumCurrentFunctionArgs = -1; - m_CurrentFunctionName.clear(); + LOGWARNING("Error in %s calling function %s()", m_SubsystemName.c_str(), CurrentFunctionName.c_str()); return false; } - m_NumCurrentFunctionArgs = -1; - m_CurrentFunctionName.clear(); // Remove the error handler from the stack: lua_remove(m_LuaState, -a_NumResults - 1); -- cgit v1.2.3 From 90d68c57e43773587fb8b2cd9f073806e2828f78 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 11 Feb 2014 08:54:29 +0100 Subject: Debuggers: Updated messaging functions --- MCServer/Plugins/Debuggers/Debuggers.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 853b0a1dc..8345e2169 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -1064,20 +1064,25 @@ end function HandleChunkStay(a_Split, a_Player) + -- As an example of using ChunkStay, this call will load 3x3 chunks around the specified chunk coords, + -- then build an obsidian pillar in the middle of each one. + -- Once complete, the player will be teleported to the middle pillar + if (#a_Split ~= 3) then - a_Player:SendMessage("Usage: /cs ") + a_Player:SendMessageInfo("Usage: /cs ") return true end local ChunkX = tonumber(a_Split[2]) local ChunkZ = tonumber(a_Split[3]) if ((ChunkX == nil) or (ChunkZ == nil)) then - a_Player:SendMessage("Invalid chunk coords.") + a_Player:SendMessageFailure("Invalid chunk coords.") return true end local World = a_Player:GetWorld() local PlayerID = a_Player:GetUniqueID() + a_Player:SendMessageInfo("Loading chunks, stand by..."); -- Set the wanted chunks: local Chunks = {} @@ -1103,7 +1108,7 @@ function HandleChunkStay(a_Split, a_Player) World:DoWithEntityByID(PlayerID, function (a_CallbackPlayer) a_CallbackPlayer:TeleportToCoords(ChunkX * 16 + 8, 85, ChunkZ * 16 + 8) - a_CallbackPlayer:SendMessage("ChunkStay fully available") + a_CallbackPlayer:SendMessageSuccess("ChunkStay fully available") end ) end @@ -1114,7 +1119,7 @@ function HandleChunkStay(a_Split, a_Player) LOGINFO("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") World:DoWithEntityByID(PlayerID, function (a_CallbackPlayer) - a_CallbackPlayer:SendMessage("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") + a_CallbackPlayer:SendMessageInfo("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") end ) end -- cgit v1.2.3 From 7e80b04114958f4062c8868c7b8bb1ef57fbc4b0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 11 Feb 2014 11:30:11 +0100 Subject: Fixed gcc warnings in Item.h. --- src/Item.h | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Item.h b/src/Item.h index 4782f31c1..cc3b3c961 100644 --- a/src/Item.h +++ b/src/Item.h @@ -32,7 +32,7 @@ namespace Json class cItem { public: - /// Creates an empty item + /** Creates an empty item */ cItem(void) : m_ItemType(E_ITEM_EMPTY), m_ItemCount(0), @@ -43,7 +43,7 @@ public: } - /// Creates an item of the specified type, by default 1 piece with no damage and no enchantments + /** Creates an item of the specified type, by default 1 piece with no damage and no enchantments */ cItem( short a_ItemType, char a_ItemCount = 1, @@ -55,9 +55,9 @@ public: m_ItemType (a_ItemType), m_ItemCount (a_ItemCount), m_ItemDamage (a_ItemDamage), + m_Enchantments(a_Enchantments), m_CustomName (a_CustomName), - m_Lore (a_Lore), - m_Enchantments(a_Enchantments) + m_Lore (a_Lore) { if (!IsValidItem(m_ItemType)) { @@ -70,14 +70,14 @@ public: } - /// Creates an exact copy of the item + /** Creates an exact copy of the item */ cItem(const cItem & a_CopyFrom) : m_ItemType (a_CopyFrom.m_ItemType), m_ItemCount (a_CopyFrom.m_ItemCount), m_ItemDamage (a_CopyFrom.m_ItemDamage), + m_Enchantments(a_CopyFrom.m_Enchantments), m_CustomName (a_CopyFrom.m_CustomName), - m_Lore (a_CopyFrom.m_Lore), - m_Enchantments(a_CopyFrom.m_Enchantments) + m_Lore (a_CopyFrom.m_Lore) { } @@ -106,8 +106,8 @@ public: return ((m_ItemType <= 0) || (m_ItemCount <= 0)); } - /* Returns true if this itemstack can stack with the specified stack (types match, enchantments etc.) ItemCounts are ignored! - */ + /* Returns true if this itemstack can stack with the specified stack (types match, enchantments etc.) + ItemCounts are ignored. */ bool IsEqual(const cItem & a_Item) const { return ( @@ -135,38 +135,38 @@ public: bool IsCustomNameEmpty(void) const { return (m_CustomName.empty()); } bool IsLoreEmpty(void) const { return (m_Lore.empty()); } - /// Returns a copy of this item with m_ItemCount set to 1. Useful to preserve enchantments etc. on stacked items + /** Returns a copy of this item with m_ItemCount set to 1. Useful to preserve enchantments etc. on stacked items */ cItem CopyOne(void) const; - /// Adds the specified count to this object and returns the reference to self (useful for chaining) + /** Adds the specified count to this object and returns the reference to self (useful for chaining) */ cItem & AddCount(char a_AmountToAdd); - /// Returns the maximum damage value that this item can have; zero if damage is not applied + /** Returns the maximum damage value that this item can have; zero if damage is not applied */ short GetMaxDamage(void) const; - /// Damages a weapon / tool. Returns true when damage reaches max value and the item should be destroyed + /** Damages a weapon / tool. Returns true when damage reaches max value and the item should be destroyed */ bool DamageItem(short a_Amount = 1); inline bool IsDamageable(void) const { return (GetMaxDamage() > 0); } - /// Returns true if the item is stacked up to its maximum stacking. + /** Returns true if the item is stacked up to its maximum stacking. */ bool IsFullStack(void) const; - /// Returns the maximum amount of stacked items of this type. + /** Returns the maximum amount of stacked items of this type. */ char GetMaxStackSize(void) const; // tolua_end - /// Returns the cItemHandler responsible for this item type + /** Returns the cItemHandler responsible for this item type */ cItemHandler * GetHandler(void) const; - /// Saves the item data into JSON representation + /** Saves the item data into JSON representation */ void GetJson(Json::Value & a_OutValue) const; - /// Loads the item data from JSON representation + /** Loads the item data from JSON representation */ void FromJson(const Json::Value & a_Value); - /// Returns true if the specified item type is enchantable (as per 1.2.5 protocol requirements) + /** Returns true if the specified item type is enchantable (as per 1.2.5 protocol requirements) */ static bool IsEnchantable(short a_ItemType); // tolua_export // tolua_begin @@ -193,7 +193,7 @@ class cItems // tolua_export public: // tolua_begin - /// Need a Lua-accessible constructor + /** Need a Lua-accessible constructor */ cItems(void) {} cItem * Get (int a_Idx); @@ -216,7 +216,7 @@ public: -/// Used to store loot probability tables +/** Used to store loot probability tables */ class cLootProbab { public: -- cgit v1.2.3 From c969794511cb3b0c7097bdcad0a31f837ee926d2 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 11 Feb 2014 11:33:23 +0100 Subject: Fixed *nix attribs. --- MCServer/hg | 0 MCServer/vg | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 MCServer/hg mode change 100644 => 100755 MCServer/vg diff --git a/MCServer/hg b/MCServer/hg old mode 100644 new mode 100755 diff --git a/MCServer/vg b/MCServer/vg old mode 100644 new mode 100755 -- cgit v1.2.3 From 2559aa58f46494d9d574d877bfab8258d3501924 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 11 Feb 2014 11:46:06 +0100 Subject: Made cChunkStay's destructor virtual. --- src/ChunkStay.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChunkStay.h b/src/ChunkStay.h index 80b084aee..2510cb490 100644 --- a/src/ChunkStay.h +++ b/src/ChunkStay.h @@ -36,7 +36,7 @@ class cChunkStay { public: cChunkStay(void); - ~cChunkStay(); + virtual ~cChunkStay(); void Clear(void); -- cgit v1.2.3 From 892c7eb57f4edce3a95e1248d9ef1dc8eac5b3b6 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 11 Feb 2014 11:56:29 +0100 Subject: More gcc warnings fixed. --- src/World.cpp | 6 +++--- src/World.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index c2149e4c0..f8c1091f0 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -248,11 +248,11 @@ cWorld::cWorld(const AString & a_WorldName) : m_SkyDarkness(0), m_Weather(eWeather_Sunny), m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :) + m_bCommandBlocksEnabled(false), + m_bUseChatPrefixes(true), m_Scoreboard(this), m_GeneratorCallbacks(*this), - m_TickThread(*this), - m_bCommandBlocksEnabled(false), - m_bUseChatPrefixes(true) + m_TickThread(*this) { LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str()); diff --git a/src/World.h b/src/World.h index 26f3993e0..fa83fe73e 100644 --- a/src/World.h +++ b/src/World.h @@ -803,6 +803,7 @@ private: /** Whether command blocks are enabled or not */ bool m_bCommandBlocksEnabled; + /** Whether prefixes such as [INFO] are prepended to SendMessageXXX() / BroadcastChatXXX() functions */ bool m_bUseChatPrefixes; @@ -846,7 +847,7 @@ private: cWorld(const AString & a_WorldName); - ~cWorld(); + virtual ~cWorld(); void Tick(float a_Dt, int a_LastTickDurationMSec); -- cgit v1.2.3 From d7f32ed682b19cded6c54f14e4e46792695399a7 Mon Sep 17 00:00:00 2001 From: narroo Date: Tue, 11 Feb 2014 08:01:25 -0500 Subject: Fixed formatting of previous commit. --- src/World.cpp | 5 +++++ src/World.h | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index 9120f8d7d..ad2a58e01 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2213,6 +2213,9 @@ void cWorld::UnloadUnusedChunks(void) } + + + void cWorld::QueueUnloadUnusedChunks(void) { QueueTask(new cWorld::cTaskUnloadUnusedChunks); @@ -2220,6 +2223,8 @@ void cWorld::QueueUnloadUnusedChunks(void) + + void cWorld::CollectPickupsByPlayer(cPlayer * a_Player) { m_ChunkMap->CollectPickupsByPlayer(a_Player); diff --git a/src/World.h b/src/World.h index e4036d8df..5161c7fd6 100644 --- a/src/World.h +++ b/src/World.h @@ -253,10 +253,10 @@ public: bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const; - /*Unloads all chunks immediately. Dangerous interface, may deadlock, use QueueUnloadUnusedChunks() instead*/ + /** Unloads all chunks immediately. Dangerous interface, may deadlock, use QueueUnloadUnusedChunks() instead*/ void UnloadUnusedChunks(void); - /*Queues a task to unload unused chunks onto the tick thread. The prefferred way of unloading*/ + /** Queues a task to unload unused chunks onto the tick thread. The prefferred way of unloading*/ void QueueUnloadUnusedChunks(void); // tolua_export void CollectPickupsByPlayer(cPlayer * a_Player); -- cgit v1.2.3 From 33c84aaa4d9d5d5255439948d318a1894db4cba4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 11 Feb 2014 15:03:35 +0100 Subject: Added cLuaState::CheckParamFunctionOrNil(). Also fixed error reporting for the two function-checking functions. --- src/Bindings/LuaState.cpp | 36 ++++++++++++++++++++++++++++++++++-- src/Bindings/LuaState.h | 3 +++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 24e64d9b2..c6be7be3c 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -944,10 +944,42 @@ bool cLuaState::CheckParamFunction(int a_StartParam, int a_EndParam) lua_Debug entry; VERIFY(lua_getstack(m_LuaState, 0, &entry)); VERIFY(lua_getinfo (m_LuaState, "n", &entry)); - AString ErrMsg = Printf("Error in function '%s' parameter #%d. Function expected, got %s", + luaL_error(m_LuaState, "Error in function '%s' parameter #%d. Function expected, got %s", + (entry.name != NULL) ? entry.name : "?", i, GetTypeText(i).c_str() + ); + return false; + } // for i - Param + + // All params checked ok + return true; +} + + + + + +bool cLuaState::CheckParamFunctionOrNil(int a_StartParam, int a_EndParam) +{ + ASSERT(IsValid()); + + if (a_EndParam < 0) + { + a_EndParam = a_StartParam; + } + + for (int i = a_StartParam; i <= a_EndParam; i++) + { + if (lua_isfunction(m_LuaState, i) || lua_isnil(m_LuaState, i)) + { + continue; + } + // Not the correct parameter + lua_Debug entry; + VERIFY(lua_getstack(m_LuaState, 0, &entry)); + VERIFY(lua_getinfo (m_LuaState, "n", &entry)); + luaL_error(m_LuaState, "Error in function '%s' parameter #%d. Function expected, got %s", (entry.name != NULL) ? entry.name : "?", i, GetTypeText(i).c_str() ); - LogStackTrace(); return false; } // for i - Param diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 1c9c99e69..b9bf10142 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -833,6 +833,9 @@ public: /** Returns true if the specified parameters on the stack are functions; also logs warning if not */ bool CheckParamFunction(int a_StartParam, int a_EndParam = -1); + /** Returns true if the specified parameters on the stack are functions or nils; also logs warning if not */ + bool CheckParamFunctionOrNil(int a_StartParam, int a_EndParam = -1); + /** Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) */ bool CheckParamEnd(int a_Param); -- cgit v1.2.3 From a1e01ff725c5f9261043df34564c770adb7cc937 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 11 Feb 2014 15:04:35 +0100 Subject: cWorld:ChunkStay() accepts nils as callbacks. Also removed leftover debug logging. --- src/Bindings/ManualBindings.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index f0bad92e8..2a7631120 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1648,9 +1648,9 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S) cLuaState L(tolua_S); if ( - !L.CheckParamUserType(1, "cWorld") || - !L.CheckParamTable (2) || - !L.CheckParamFunction(3, 4) + !L.CheckParamUserType (1, "cWorld") || + !L.CheckParamTable (2) || + !L.CheckParamFunctionOrNil(3, 4) ) { return 0; @@ -1671,12 +1671,10 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S) L.LogStackTrace(); return 0; } - L.LogStack("Before AddChunks()"); if (!ChunkStay->AddChunks(2)) { return 0; } - L.LogStack("After params read"); ChunkStay->Enable(*World->GetChunkMap(), 3, 4); return 0; -- cgit v1.2.3 From 803314b9407c41106b06f59f16a83bf2484d3793 Mon Sep 17 00:00:00 2001 From: narroo Date: Tue, 11 Feb 2014 10:19:18 -0500 Subject: Updated APIDesc.lua to replace 'UnloadUnusedChunks' with 'QueueUnloadUnusedChunks'. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index c0056ac4a..3b34ec6b9 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2145,7 +2145,7 @@ end SpawnExperienceOrb = { Params = "X, Y, Z, Reward", Return = "EntityID", Notes = "Spawns an {{cExpOrb|experience orb}} at the specified coords, with the given reward" }, SpawnPrimedTNT = { Params = "X, Y, Z, FuseTimeSecs, InitialVelocityCoeff", Return = "", Notes = "Spawns a {{cTNTEntity|primed TNT entity}} at the specified coords, with the given fuse time. The entity gets a random speed multiplied by the InitialVelocityCoeff, 1 being the default value." }, TryGetHeight = { Params = "BlockX, BlockZ", Return = "IsValid, Height", Notes = "Returns true and height of the highest non-air block if the chunk is loaded, or false otherwise." }, - UnloadUnusedChunks = { Params = "", Return = "", Notes = "Unloads chunks that are no longer needed, and are saved. NOTE: This API is deprecated and will be removed soon." }, + QueueUnloadUnusedChunks = { Params = "", Return = "", Notes = "Queues a cTask that unloads chunks that are no longer needed and are saved." }, UpdateSign = { Params = "X, Y, Z, Line1, Line2, Line3, Line4, [{{cPlayer|Player}}]", Return = "", Notes = "Sets the sign text at the specified coords. The sign-updating hooks are called for the change. The Player parameter is used to indicate the player from whom the change has come, it may be nil. Same as SetSignLiens()" }, UseBlockEntity = { Params = "{{cPlayer|Player}}, BlockX, BlockY, BlockZ", Return = "", Notes = "Makes the specified Player use the block entity at the specified coords (open chest UI, etc.) If the cords are in an unloaded chunk or there's no block entity, ignores the call." }, WakeUpSimulators = { Params = "BlockX, BlockY, BlockZ", Return = "", Notes = "Wakes up the simulators for the specified block." }, -- cgit v1.2.3 From 619c3438ef2e70b4e116ab8ecd1edde8fb9b4896 Mon Sep 17 00:00:00 2001 From: narroo Date: Tue, 11 Feb 2014 10:35:25 -0500 Subject: Changed console.lua in core plugin. --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 5fe3662a8..51aa4290d 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 5fe3662a8719f79cb2ca0a16150c716a3c5eb19c +Subproject commit 51aa4290d7cef2aff68a35c66339535d9068f79b -- cgit v1.2.3 From 03dbfce10e3bc6f6e5d093fd6591f0a650636848 Mon Sep 17 00:00:00 2001 From: narroo Date: Tue, 11 Feb 2014 14:11:20 -0500 Subject: Alpha-Sorted List. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 3b34ec6b9..c9ef02a96 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1851,6 +1851,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); GetWebAdmin = { Params = "", Return = "{{cWebAdmin|cWebAdmin}}", Notes = "Returns the cWebAdmin object." }, GetWorld = { Params = "WorldName", Return = "{{cWorld|cWorld}}", Notes = "Returns the cWorld object of the given world. It returns nil if there is no world with the given name." }, QueueExecuteConsoleCommand = { Params = "Message", Return = "", Notes = "Queues a console command for execution through the cServer class. The command will be executed in the tick thread. The command's output will be sent to console." }, + QueueUnloadUnusedChunks = { Params = "", Return = "", Notes = "Queues a cTask that unloads chunks that are no longer needed and are saved." }, SaveAllChunks = { Params = "", Return = "", Notes = "Saves all the chunks in all the worlds. Note that the saving is queued on each world's tick thread and this functions returns before the chunks are actually saved." }, SetPrimaryServerVersion = { Params = "Protocol Version", Return = "", Notes = "Sets the servers PrimaryServerVersion to the given protocol number." } }, @@ -2145,7 +2146,6 @@ end SpawnExperienceOrb = { Params = "X, Y, Z, Reward", Return = "EntityID", Notes = "Spawns an {{cExpOrb|experience orb}} at the specified coords, with the given reward" }, SpawnPrimedTNT = { Params = "X, Y, Z, FuseTimeSecs, InitialVelocityCoeff", Return = "", Notes = "Spawns a {{cTNTEntity|primed TNT entity}} at the specified coords, with the given fuse time. The entity gets a random speed multiplied by the InitialVelocityCoeff, 1 being the default value." }, TryGetHeight = { Params = "BlockX, BlockZ", Return = "IsValid, Height", Notes = "Returns true and height of the highest non-air block if the chunk is loaded, or false otherwise." }, - QueueUnloadUnusedChunks = { Params = "", Return = "", Notes = "Queues a cTask that unloads chunks that are no longer needed and are saved." }, UpdateSign = { Params = "X, Y, Z, Line1, Line2, Line3, Line4, [{{cPlayer|Player}}]", Return = "", Notes = "Sets the sign text at the specified coords. The sign-updating hooks are called for the change. The Player parameter is used to indicate the player from whom the change has come, it may be nil. Same as SetSignLiens()" }, UseBlockEntity = { Params = "{{cPlayer|Player}}, BlockX, BlockY, BlockZ", Return = "", Notes = "Makes the specified Player use the block entity at the specified coords (open chest UI, etc.) If the cords are in an unloaded chunk or there's no block entity, ignores the call." }, WakeUpSimulators = { Params = "BlockX, BlockY, BlockZ", Return = "", Notes = "Wakes up the simulators for the specified block." }, -- cgit v1.2.3 From e53b331b4a17234c89f0ac54e724a5f48de4c4be Mon Sep 17 00:00:00 2001 From: narroo Date: Tue, 11 Feb 2014 14:38:28 -0500 Subject: Fixed formatting. Moved UnloadUnusedChunks from public to private. --- src/World.cpp | 7 +++++++ src/World.h | 7 +++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index ad2a58e01..6090443a8 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2966,6 +2966,7 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cWorld::cTaskSaveAllChunks: @@ -2975,6 +2976,9 @@ void cWorld::cTaskSaveAllChunks::Run(cWorld & a_World) } + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cWorld::cTaskUnloadUnusedChunks @@ -2984,6 +2988,9 @@ void cWorld::cTaskUnloadUnusedChunks::Run(cWorld & a_World) } + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cWorld::cChunkGeneratorCallbacks: diff --git a/src/World.h b/src/World.h index 5161c7fd6..f22a8f49c 100644 --- a/src/World.h +++ b/src/World.h @@ -252,10 +252,6 @@ public: bool IsChunkValid (int a_ChunkX, int a_ChunkZ) const; bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const; - - /** Unloads all chunks immediately. Dangerous interface, may deadlock, use QueueUnloadUnusedChunks() instead*/ - void UnloadUnusedChunks(void); - /** Queues a task to unload unused chunks onto the tick thread. The prefferred way of unloading*/ void QueueUnloadUnusedChunks(void); // tolua_export @@ -882,6 +878,9 @@ private: /** Ticks all clients that are in this world */ void TickClients(float a_Dt); + /** Unloads all chunks immediately.*/ + void UnloadUnusedChunks(void); + void UpdateSkyDarkness(void); /** Generates a random spawnpoint on solid land by walking chunks and finding their biomes */ -- cgit v1.2.3 From c53406f0d4d83f795e2a445059952b61abb12f34 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 11 Feb 2014 22:04:11 +0000 Subject: Fixed #612 * Chests send contents updates to client --- src/BlockEntities/ChestEntity.cpp | 15 +++++++++++++++ src/BlockEntities/ChestEntity.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index dfbe6ae87..9282da7fd 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -170,3 +170,18 @@ void cChestEntity::OpenNewWindow(void) + +void cChestEntity::OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) +{ + super::OnSlotChanged(a_Grid, a_SlotNum); + + cWindow * Window = GetWindow(); + if (Window != NULL) + { + Window->BroadcastWholeWindow(); + } +} + + + + diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h index 4110de1f3..1f5668f78 100644 --- a/src/BlockEntities/ChestEntity.h +++ b/src/BlockEntities/ChestEntity.h @@ -49,6 +49,7 @@ public: virtual void SaveToJson(Json::Value & a_Value) override; virtual void SendTo(cClientHandle & a_Client) override; virtual void UsedBy(cPlayer * a_Player) override; + virtual void OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) override; /// Opens a new chest window for this chest. Scans for neighbors to open a double chest window, if appropriate. void OpenNewWindow(void); -- cgit v1.2.3 From 06239c8336a340459a62b45b6d633a55058e4677 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 11 Feb 2014 22:09:56 +0000 Subject: Fixed #627 - Attack() is now called from cAggressive instead of cMonster * Monsters can no longer attack through walls * Should fix last remnants of player damage after teleporting (that both STR and bearbin contributed fixes to :P) --- src/Entities/Player.cpp | 4 ++-- src/Mobs/AggressiveMonster.cpp | 11 +++++++++-- src/Mobs/AggressiveMonster.h | 2 +- src/Mobs/Monster.cpp | 14 -------------- src/Mobs/Monster.h | 2 -- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 286d43cf6..5f2379ba2 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1122,8 +1122,8 @@ void cPlayer::SetIP(const AString & a_IP) void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) { - SetPosition( a_PosX, a_PosY, a_PosZ ); - m_LastGroundHeight = (float)a_PosY; + SetPosition(a_PosX, a_PosY, a_PosZ); + m_LastGroundHeight, m_LastJumpHeight = (float)a_PosY; m_World->BroadcastTeleportEntity(*this, GetClientHandle()); m_ClientHandle->SendPlayerMoveLook(); diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index f2f0c404c..7da9f4fc2 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -5,7 +5,7 @@ #include "../World.h" #include "../Entities/Player.h" -#include "../MersenneTwister.h" +#include "../Tracer.h" @@ -73,6 +73,13 @@ void cAggressiveMonster::Tick(float a_Dt, cChunk & a_Chunk) { CheckEventSeePlayer(); } + + cTracer LineOfSight(GetWorld()); + if (ReachedFinalDestination() && (m_Target != NULL) && !LineOfSight.Trace(GetPosition(), (m_Target->GetPosition() - GetPosition()), (int)(m_Target->GetPosition() - GetPosition()).Length())) + { + // Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls) + Attack(a_Dt / 1000); + } } @@ -81,7 +88,7 @@ void cAggressiveMonster::Tick(float a_Dt, cChunk & a_Chunk) void cAggressiveMonster::Attack(float a_Dt) { - super::Attack(a_Dt); + m_AttackInterval += a_Dt * m_AttackRate; if ((m_Target != NULL) && (m_AttackInterval > 3.0)) { diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h index 9cee4e7a7..152260f95 100644 --- a/src/Mobs/AggressiveMonster.h +++ b/src/Mobs/AggressiveMonster.h @@ -20,7 +20,7 @@ public: virtual void InStateChasing(float a_Dt) override; virtual void EventSeePlayer(cEntity *) override; - virtual void Attack(float a_Dt) override; + virtual void Attack(float a_Dt); } ; diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index ad3a87725..9817901c9 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -311,9 +311,6 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) } } - if (ReachedFinalDestination() && (m_Target != NULL)) - Attack(a_Dt); - SetPitchAndYawFromDestination(); HandleFalling(); @@ -657,17 +654,6 @@ void cMonster::InStateEscaping(float a_Dt) -// Do attack here -// a_Dt is passed so we can set attack rate -void cMonster::Attack(float a_Dt) -{ - m_AttackInterval += a_Dt * m_AttackRate; -} - - - - - void cMonster::GetMonsterConfig(const AString & a_Name) { cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, a_Name); diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 714feddb9..4d2e099c5 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -112,8 +112,6 @@ public: virtual void InStateChasing (float a_Dt); virtual void InStateEscaping(float a_Dt); - virtual void Attack(float a_Dt); - int GetAttackRate() { return (int)m_AttackRate; } void SetAttackRate(float a_AttackRate) { m_AttackRate = a_AttackRate; } void SetAttackRange(int a_AttackRange) { m_AttackRange = a_AttackRange; } -- cgit v1.2.3 From 9d54f2b761370afb04ebb49e0920de460f269efd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 11 Feb 2014 22:54:01 +0000 Subject: Fixed #190 + Hoppers now collect pickups above them --- src/BlockEntities/HopperEntity.cpp | 69 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 2255cad64..2d07ce6c7 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -7,10 +7,12 @@ #include "HopperEntity.h" #include "../Chunk.h" #include "../Entities/Player.h" +#include "../Entities/Pickup.h" #include "../Bindings/PluginManager.h" #include "ChestEntity.h" #include "DropSpenserEntity.h" #include "FurnaceEntity.h" +#include "../BoundingBox.h" @@ -190,8 +192,71 @@ bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick) /// Moves pickups from above this hopper into it. Returns true if the contents have changed. bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) { - // TODO - return false; + UNUSED(a_CurrentTick); + + class cHopperPickupSearchCallback : + public cEntityCallback + { + public: + cHopperPickupSearchCallback(Vector3i a_Pos, cItemGrid & a_Contents) : + m_Pos(a_Pos), + m_Contents(a_Contents), + m_bFoundPickupsAbove(false) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + ASSERT(a_Entity != NULL); + + if (!a_Entity->IsPickup() || a_Entity->IsDestroyed()) + { + return false; + } + + Vector3f EntityPos = a_Entity->GetPosition(); + Vector3f BlockPos(m_Pos.x + 0.5f, (float)m_Pos.y + 1, m_Pos.z + 0.5f); // One block above hopper, and search from center outwards + float Distance = (EntityPos - BlockPos).Length(); + + if (Distance < 0.5) + { + for (int i = 0; i < ContentsWidth * ContentsHeight; i++) + { + if (m_Contents.IsSlotEmpty(i)) + { + m_bFoundPickupsAbove = true; + m_Contents.SetSlot(i, ((cPickup *)a_Entity)->GetItem()); + a_Entity->Destroy(); // Kill pickup + return false; // Don't break enumeration + } + else if (m_Contents.GetSlot(i).IsEqual(((cPickup *)a_Entity)->GetItem())) + { + m_bFoundPickupsAbove = true; + m_Contents.ChangeSlotCount(i, ((cPickup *)a_Entity)->GetItem().m_ItemCount); + a_Entity->Destroy(); + return false; + } + } + } + + return false; + } + + bool FoundPickupsAbove(void) const + { + return m_bFoundPickupsAbove; + } + + protected: + Vector3i m_Pos; + bool m_bFoundPickupsAbove; + cItemGrid & m_Contents; + }; + + cHopperPickupSearchCallback HopperPickupSearchCallback(Vector3i(GetPosX(), GetPosY(), GetPosZ()), m_Contents); + a_Chunk.ForEachEntity(HopperPickupSearchCallback); + + return HopperPickupSearchCallback.FoundPickupsAbove(); } -- cgit v1.2.3 From a0a44b969ece88d32bcc89fea51b25d819424a06 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 11 Feb 2014 23:13:49 +0000 Subject: Improved pressure plates + Two (or more) pressure plates can be triggered at the same time * Fixed issues caused by pressure plates not being in the sources list --- src/Simulator/IncrementalRedstoneSimulator.cpp | 2 +- src/Simulator/IncrementalRedstoneSimulator.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 5dba69455..a875c9e4d 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -960,7 +960,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_Bloc Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f); float Distance = (EntityPos - BlockPos).Length(); - if (Distance < 0.5) + if (Distance <= 0.7) { m_Entity = a_Entity; return true; // Break out, we only need to know for wooden plates that at least one entity is on top diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index 3397e143c..a3da13584 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -207,6 +207,10 @@ private: case E_BLOCK_REDSTONE_REPEATER_ON: case E_BLOCK_BLOCK_OF_REDSTONE: case E_BLOCK_ACTIVE_COMPARATOR: + case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: + case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: + case E_BLOCK_STONE_PRESSURE_PLATE: + case E_BLOCK_WOODEN_PRESSURE_PLATE: { return true; } -- cgit v1.2.3 From 2f11e145e55dcde0c8bde19b9c324764b81f4d2e Mon Sep 17 00:00:00 2001 From: narroo Date: Tue, 11 Feb 2014 19:58:40 -0500 Subject: Fixed location of QueueUnloadUnusedChunks entry in APIDesc dump. Now is lexographically listed in cWorld, not cRoot. --- MCServer/Plugins/APIDump/APIDesc.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index c9ef02a96..565b32b1b 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1851,7 +1851,6 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); GetWebAdmin = { Params = "", Return = "{{cWebAdmin|cWebAdmin}}", Notes = "Returns the cWebAdmin object." }, GetWorld = { Params = "WorldName", Return = "{{cWorld|cWorld}}", Notes = "Returns the cWorld object of the given world. It returns nil if there is no world with the given name." }, QueueExecuteConsoleCommand = { Params = "Message", Return = "", Notes = "Queues a console command for execution through the cServer class. The command will be executed in the tick thread. The command's output will be sent to console." }, - QueueUnloadUnusedChunks = { Params = "", Return = "", Notes = "Queues a cTask that unloads chunks that are no longer needed and are saved." }, SaveAllChunks = { Params = "", Return = "", Notes = "Saves all the chunks in all the worlds. Note that the saving is queued on each world's tick thread and this functions returns before the chunks are actually saved." }, SetPrimaryServerVersion = { Params = "Protocol Version", Return = "", Notes = "Sets the servers PrimaryServerVersion to the given protocol number." } }, @@ -2117,7 +2116,8 @@ end QueueSaveAllChunks = { Params = "", Return = "", Notes = "Queues all chunks to be saved in the world storage thread" }, QueueSetBlock = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta, TickDelay", Return = "", Notes = "Queues the block to be set to the specified blocktype and meta after the specified amount of game ticks. Uses SetBlock() for the actual setting, so simulators are woken up and block entities are handled correctly." }, QueueTask = { Params = "TaskFunction", Return = "", Notes = "Queues the specified function to be executed in the tick thread. This is the primary means of interaction with a cWorld from the WebAdmin page handlers (see {{WebWorldThreads}}). The function signature is
function()
All return values from the function are ignored. Note that this function is actually called *after* the QueueTask() function returns. Note that it is unsafe to store references to MCServer objects, such as entities, across from the caller to the task handler function; store the EntityID instead." }, - RegenerateChunk = { Params = "ChunkX, ChunkZ", Return = "", Notes = "Queues the specified chunk to be re-generated, overwriting the current data. To queue a chunk for generating only if it doesn't exist, use the GenerateChunk() instead." }, + QueueUnloadUnusedChunks = { Params = "", Return = "", Notes = "Queues a cTask that unloads chunks that are no longer needed and are saved." }, + RegenerateChunk = { Params = "ChunkX, ChunkZ", Return = "", Notes = "Queues the specified chunk to be re-generated, overwriting the current data. To queue a chunk for generating only if it doesn't exist, use the GenerateChunk() instead." }, ScheduleTask = { Params = "DelayTicks, TaskFunction", Return = "", Notes = "Queues the specified function to be executed in the world's tick thread after a the specified number of ticks. This enables operations to be queued for execution in the future. The function signature is
function({{cWorld|World}})
All return values from the function are ignored. Note that it is unsafe to store references to MCServer objects, such as entities, across from the caller to the task handler function; store the EntityID instead." }, SendBlockTo = { Params = "BlockX, BlockY, BlockZ, {{cPlayer|Player}}", Return = "", Notes = "Sends the block at the specified coords to the specified player's client, as an UpdateBlock packet." }, SetBlock = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block at the specified coords, replaces the block entities for the previous block type, creates a new block entity for the new block, if appropriate, and wakes up the simulators. This is the preferred way to set blocks, as opposed to FastSetBlock(), which is only to be used under special circumstances." }, -- cgit v1.2.3 From b0018da61504f26a383ca00cc3cd73c8cbdfcdd6 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Feb 2014 10:36:13 +0100 Subject: Updated Core. --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 8ddc8a9d0..d6ed20414 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 8ddc8a9d027a9471c72270ec82cc618069710faa +Subproject commit d6ed2041469ab959bbf3842db41c0e25fd249dc1 -- cgit v1.2.3 From 8470841f84a04301ef45c2ec9f1f3aabecb83582 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 12 Feb 2014 19:07:17 +0100 Subject: Fixed #573 --- src/WorldStorage/WSSAnvil.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index d72165c46..e95813a3c 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1083,6 +1083,10 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a { LoadHorseFromNBT(a_Entities, a_NBT, a_EntityTagIdx); } + else if (strncmp(a_IDTag, "Villager", a_IDTagLength) == 0) + { + LoadVillagerFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + } else if (strncmp(a_IDTag, "VillagerGolem", a_IDTagLength) == 0) { LoadIronGolemFromNBT(a_Entities, a_NBT, a_EntityTagIdx); @@ -1131,10 +1135,6 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a { LoadSquidFromNBT(a_Entities, a_NBT, a_EntityTagIdx); } - else if (strncmp(a_IDTag, "Villager", a_IDTagLength) == 0) - { - LoadVillagerFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - } else if (strncmp(a_IDTag, "Witch", a_IDTagLength) == 0) { LoadWitchFromNBT(a_Entities, a_NBT, a_EntityTagIdx); -- cgit v1.2.3 From fecf40d95b12c6c2382762824b6302bd3a064f48 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Wed, 12 Feb 2014 19:34:45 +0100 Subject: Decreased mobs attack range Mobs attack from too far and throught walls, this will reduce the bug. --- MCServer/monsters.ini | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/MCServer/monsters.ini b/MCServer/monsters.ini index a1b63423e..8cd956157 100644 --- a/MCServer/monsters.ini +++ b/MCServer/monsters.ini @@ -1,61 +1,61 @@ [Spider] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=2.0 SightDistance=25.0 MaxHealth=16 [Chicken] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=1.0 SightDistance=25.0 MaxHealth=4 [Cow] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=1.0 SightDistance=25.0 MaxHealth=10 [Pig] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=1.0 SightDistance=25.0 MaxHealth=10 [Sheep] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=1.0 SightDistance=25.0 MaxHealth=8 [Squid] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=1.0 SightDistance=25.0 MaxHealth=10 [Enderman] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=4.0 SightDistance=25.0 MaxHealth=40 [Zombiepigman] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=7.0 SightDistance=25.0 MaxHealth=20 [Cavespider] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=2.0 SightDistance=25.0 @@ -76,7 +76,7 @@ SightDistance=50.0 MaxHealth=10 [Silverfish] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=1.0 SightDistance=25.0 @@ -89,21 +89,21 @@ SightDistance=40.0 MaxHealth=20 [Slime] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=4.0 SightDistance=25.0 MaxHealth=16 [Zombie] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=4.0 SightDistance=25.0 MaxHealth=20 [Wolf] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=4.0 SightDistance=25.0 @@ -117,14 +117,14 @@ SightDistance=25.0 MaxHealth=20 [Villager] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=0.0 SightDistance=25.0 MaxHealth=20 [Witch] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=0.0 SightDistance=25.0 @@ -132,49 +132,49 @@ MaxHealth=26 [Ocelot] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=0.0 SightDistance=25.0 MaxHealth=10 [Mooshroom] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=0.0 SightDistance=25.0 MaxHealth=10 [Magmacube] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=6.0 SightDistance=25.0 MaxHealth=16 [Horse] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=6.0 SightDistance=25.0 MaxHealth=30 [EnderDragon] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=6.0 SightDistance=25.0 MaxHealth=200 [Giant] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=6.0 SightDistance=25.0 MaxHealth=100 [IronGolem] -AttackRange=5.0 +AttackRange=2.0 AttackRate=1 AttackDamage=6.0 SightDistance=25.0 -- cgit v1.2.3 From 7ced2f290fc2018d93e324d384d87cfd826312a5 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 12 Feb 2014 21:53:21 +0000 Subject: Simplified Attack() tracing --- src/Mobs/AggressiveMonster.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 7da9f4fc2..0901f85a9 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -74,8 +74,13 @@ void cAggressiveMonster::Tick(float a_Dt, cChunk & a_Chunk) CheckEventSeePlayer(); } + if (m_Target == NULL) + return; + cTracer LineOfSight(GetWorld()); - if (ReachedFinalDestination() && (m_Target != NULL) && !LineOfSight.Trace(GetPosition(), (m_Target->GetPosition() - GetPosition()), (int)(m_Target->GetPosition() - GetPosition()).Length())) + Vector3d AttackDirection(m_Target->GetPosition() - GetPosition()); + + if (ReachedFinalDestination() && !LineOfSight.Trace(GetPosition(), AttackDirection, (int)AttackDirection.Length())) { // Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls) Attack(a_Dt / 1000); -- cgit v1.2.3 From 91ebb6cef09ff8437beaa0c17ca2a1c094741200 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 12 Feb 2014 21:53:46 +0000 Subject: Made player jump reset less ambiguous --- src/Entities/Player.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 5f2379ba2..838bbd06c 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1123,7 +1123,8 @@ void cPlayer::SetIP(const AString & a_IP) void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) { SetPosition(a_PosX, a_PosY, a_PosZ); - m_LastGroundHeight, m_LastJumpHeight = (float)a_PosY; + m_LastGroundHeight = (float)a_PosY; + m_LastJumpHeight = (float)a_PosY; m_World->BroadcastTeleportEntity(*this, GetClientHandle()); m_ClientHandle->SendPlayerMoveLook(); -- cgit v1.2.3 From f97ce3015171fcc6f6c5316810d19eb37c89c5f7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 12 Feb 2014 22:01:22 +0000 Subject: Changed inheritance a bit * cBlockEntityWithItems now inherits from cBlockEntityWindowOwner --- src/BlockEntities/BlockEntityWithItems.h | 7 +++++ src/BlockEntities/ChestEntity.h | 4 +-- src/BlockEntities/DropSpenserEntity.h | 4 +-- src/BlockEntities/EnderChestEntity.h | 4 +-- src/BlockEntities/FurnaceEntity.h | 4 +-- src/BlockEntities/HopperEntity.cpp | 53 +++++++++++++++++++++----------- src/BlockEntities/HopperEntity.h | 4 +-- src/ItemGrid.cpp | 7 +++++ 8 files changed, 54 insertions(+), 33 deletions(-) diff --git a/src/BlockEntities/BlockEntityWithItems.h b/src/BlockEntities/BlockEntityWithItems.h index bf6289a2f..918781a00 100644 --- a/src/BlockEntities/BlockEntityWithItems.h +++ b/src/BlockEntities/BlockEntityWithItems.h @@ -11,6 +11,7 @@ #include "BlockEntity.h" #include "../ItemGrid.h" +#include "../UI/WindowOwner.h" @@ -22,6 +23,7 @@ class cBlockEntityWithItems : // tolua_end // tolua doesn't seem to support multiple inheritance? , public cItemGrid::cListener + , public cBlockEntityWindowOwner // tolua_begin { typedef cBlockEntity super; @@ -77,6 +79,11 @@ protected: ASSERT(a_Grid == &m_Contents); if (m_World != NULL) { + if (GetWindow() != NULL) + { + GetWindow()->BroadcastWholeWindow(); + } + m_World->MarkChunkDirty(GetChunkX(), GetChunkZ()); } } diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h index 1f5668f78..3167d64a0 100644 --- a/src/BlockEntities/ChestEntity.h +++ b/src/BlockEntities/ChestEntity.h @@ -2,7 +2,6 @@ #pragma once #include "BlockEntityWithItems.h" -#include "../UI/WindowOwner.h" @@ -23,8 +22,7 @@ class cNBTData; // tolua_begin class cChestEntity : - public cBlockEntityWithItems, - public cBlockEntityWindowOwner + public cBlockEntityWithItems { typedef cBlockEntityWithItems super; diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h index f2f1eba36..47d3bd492 100644 --- a/src/BlockEntities/DropSpenserEntity.h +++ b/src/BlockEntities/DropSpenserEntity.h @@ -11,7 +11,6 @@ #pragma once #include "BlockEntityWithItems.h" -#include "../UI/WindowOwner.h" @@ -31,8 +30,7 @@ class cServer; // tolua_begin class cDropSpenserEntity : - public cBlockEntityWithItems, - public cBlockEntityWindowOwner + public cBlockEntityWithItems { typedef cBlockEntityWithItems super; diff --git a/src/BlockEntities/EnderChestEntity.h b/src/BlockEntities/EnderChestEntity.h index 0ee3cab3b..45beee45f 100644 --- a/src/BlockEntities/EnderChestEntity.h +++ b/src/BlockEntities/EnderChestEntity.h @@ -2,7 +2,6 @@ #pragma once #include "BlockEntityWithItems.h" -#include "../UI/WindowOwner.h" @@ -23,8 +22,7 @@ class cNBTData; // tolua_begin class cEnderChestEntity : - public cBlockEntityWithItems, - public cBlockEntityWindowOwner + public cBlockEntityWithItems { typedef cBlockEntityWithItems super; diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h index b08187300..5e08ae37a 100644 --- a/src/BlockEntities/FurnaceEntity.h +++ b/src/BlockEntities/FurnaceEntity.h @@ -2,7 +2,6 @@ #pragma once #include "BlockEntityWithItems.h" -#include "../UI/WindowOwner.h" #include "../FurnaceRecipe.h" @@ -23,8 +22,7 @@ class cServer; // tolua_begin class cFurnaceEntity : - public cBlockEntityWithItems, - public cBlockEntityWindowOwner + public cBlockEntityWithItems { typedef cBlockEntityWithItems super; diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 2d07ce6c7..b2fe7ee99 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -198,10 +198,10 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) public cEntityCallback { public: - cHopperPickupSearchCallback(Vector3i a_Pos, cItemGrid & a_Contents) : + cHopperPickupSearchCallback(const Vector3i a_Pos, cItemGrid & a_Contents) : m_Pos(a_Pos), - m_Contents(a_Contents), - m_bFoundPickupsAbove(false) + m_bFoundPickupsAbove(false), + m_Contents(a_Contents) { } @@ -220,25 +220,42 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) if (Distance < 0.5) { - for (int i = 0; i < ContentsWidth * ContentsHeight; i++) + if (TrySuckPickupIn((cPickup *)a_Entity)) { - if (m_Contents.IsSlotEmpty(i)) - { - m_bFoundPickupsAbove = true; - m_Contents.SetSlot(i, ((cPickup *)a_Entity)->GetItem()); - a_Entity->Destroy(); // Kill pickup - return false; // Don't break enumeration - } - else if (m_Contents.GetSlot(i).IsEqual(((cPickup *)a_Entity)->GetItem())) + return false; + } + } + + return false; + } + + bool TrySuckPickupIn(cPickup * a_Pickup) + { + for (int i = 0; i < ContentsWidth * ContentsHeight; i++) + { + if (m_Contents.IsSlotEmpty(i)) + { + m_bFoundPickupsAbove = true; + m_Contents.SetSlot(i, a_Pickup->GetItem()); + a_Pickup->Destroy(); // Kill pickup + return true; + } + else if (m_Contents.GetSlot(i).IsEqual(a_Pickup->GetItem()) && !m_Contents.GetSlot(i).IsFullStack()) + { + m_bFoundPickupsAbove = true; + LOGINFO("Previous counts, pickup: %i, hopper: %i", (int)a_Pickup->GetItem().m_ItemCount, (int)m_Contents.GetSlot(i).m_ItemCount); + int PreviousCount = m_Contents.GetSlot(i).m_ItemCount; + a_Pickup->GetItem().m_ItemCount -= m_Contents.ChangeSlotCount(i, a_Pickup->GetItem().m_ItemCount) - PreviousCount; // Set count to however many items were added + LOGINFO("After counts, pickup: %i, hopper: %i", (int)a_Pickup->GetItem().m_ItemCount, (int)m_Contents.GetSlot(i).m_ItemCount); + + if (a_Pickup->GetItem().IsEmpty()) { - m_bFoundPickupsAbove = true; - m_Contents.ChangeSlotCount(i, ((cPickup *)a_Entity)->GetItem().m_ItemCount); - a_Entity->Destroy(); - return false; + //LOGINFO("Pickup was empty!"); + a_Pickup->Destroy(); // Kill pickup if all items were added } + return true; } } - return false; } @@ -248,7 +265,7 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) } protected: - Vector3i m_Pos; + const Vector3i m_Pos; bool m_bFoundPickupsAbove; cItemGrid & m_Contents; }; diff --git a/src/BlockEntities/HopperEntity.h b/src/BlockEntities/HopperEntity.h index 2c8b301fe..6ef98f43a 100644 --- a/src/BlockEntities/HopperEntity.h +++ b/src/BlockEntities/HopperEntity.h @@ -10,7 +10,6 @@ #pragma once #include "BlockEntityWithItems.h" -#include "../UI/WindowOwner.h" @@ -18,8 +17,7 @@ // tolua_begin class cHopperEntity : - public cBlockEntityWithItems, - public cBlockEntityWindowOwner + public cBlockEntityWithItems { typedef cBlockEntityWithItems super; diff --git a/src/ItemGrid.cpp b/src/ItemGrid.cpp index e8b58695f..34a267bab 100644 --- a/src/ItemGrid.cpp +++ b/src/ItemGrid.cpp @@ -369,6 +369,13 @@ int cItemGrid::ChangeSlotCount(int a_SlotNum, int a_AddToCount) } m_Slots[a_SlotNum].m_ItemCount += a_AddToCount; + + cItemHandler * Handler = cItemHandler::GetItemHandler(m_Slots[a_SlotNum].m_ItemType); + if (m_Slots[a_SlotNum].m_ItemCount > Handler->GetMaxStackSize()) + { + m_Slots[a_SlotNum].m_ItemCount = Handler->GetMaxStackSize(); + } + TriggerListeners(a_SlotNum); return m_Slots[a_SlotNum].m_ItemCount; } -- cgit v1.2.3 From e915a0df4cf78f41a200f0a06aabf069aec1bb07 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 12 Feb 2014 22:06:13 +0000 Subject: Removed some unneeded BroadcastWholeWindow()s --- src/BlockEntities/ChestEntity.cpp | 15 --------------- src/BlockEntities/ChestEntity.h | 1 - src/BlockEntities/DropSpenserEntity.cpp | 7 ------- src/BlockEntities/SignEntity.h | 2 ++ 4 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index 9282da7fd..dfbe6ae87 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -170,18 +170,3 @@ void cChestEntity::OpenNewWindow(void) - -void cChestEntity::OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) -{ - super::OnSlotChanged(a_Grid, a_SlotNum); - - cWindow * Window = GetWindow(); - if (Window != NULL) - { - Window->BroadcastWholeWindow(); - } -} - - - - diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h index 3167d64a0..ce16f84d7 100644 --- a/src/BlockEntities/ChestEntity.h +++ b/src/BlockEntities/ChestEntity.h @@ -47,7 +47,6 @@ public: virtual void SaveToJson(Json::Value & a_Value) override; virtual void SendTo(cClientHandle & a_Client) override; virtual void UsedBy(cPlayer * a_Player) override; - virtual void OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) override; /// Opens a new chest window for this chest. Scans for neighbors to open a double chest window, if appropriate. void OpenNewWindow(void); diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp index 7c9a40ce6..81df0fc8c 100644 --- a/src/BlockEntities/DropSpenserEntity.cpp +++ b/src/BlockEntities/DropSpenserEntity.cpp @@ -99,13 +99,6 @@ void cDropSpenserEntity::DropSpense(cChunk & a_Chunk) } m_World->BroadcastSoundParticleEffect(2000, m_PosX, m_PosY, m_PosZ, SmokeDir); m_World->BroadcastSoundEffect("random.click", m_PosX * 8, m_PosY * 8, m_PosZ * 8, 1.0f, 1.0f); - - // Update the UI window, if open: - cWindow * Window = GetWindow(); - if (Window != NULL) - { - Window->BroadcastWholeWindow(); - } } diff --git a/src/BlockEntities/SignEntity.h b/src/BlockEntities/SignEntity.h index d998ff1e8..2b965747c 100644 --- a/src/BlockEntities/SignEntity.h +++ b/src/BlockEntities/SignEntity.h @@ -56,6 +56,8 @@ public: virtual void UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle & a_Client) override; + + static const char * GetClassStatic(void) { return "cSignrEntity"; } private: -- cgit v1.2.3 From 6ed4f476ce1365c5878c2726de331c892d00c256 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 12 Feb 2014 22:06:59 +0000 Subject: Added more missing GetClassStatic()s --- src/BlockEntities/JukeboxEntity.h | 2 ++ src/BlockEntities/NoteEntity.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index 996de965b..734d7bb66 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -43,6 +43,8 @@ public: void EjectRecord(void); // tolua_end + + static const char * GetClassStatic(void) { return "cJukeboxEntity"; } virtual void UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle &) override { }; diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h index cf78aeac6..b698899c0 100644 --- a/src/BlockEntities/NoteEntity.h +++ b/src/BlockEntities/NoteEntity.h @@ -54,6 +54,8 @@ public: virtual void UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle &) override { }; + static const char * GetClassStatic(void) { return "cNoteEntity"; } + private: char m_Pitch; } ; // tolua_export -- cgit v1.2.3 From cc72b656c97d82eca0900c19280cdd031cfa7ff4 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 13 Feb 2014 06:59:07 +0100 Subject: Updated COMPILING instructions for out-of-source build. Also made the 32-bit mode a bit more clear as to what architectures it affects. --- COMPILING.md | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/COMPILING.md b/COMPILING.md index eceeefee7..d3c896bdd 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -49,7 +49,7 @@ There's a script file, `MCServer/profile_run.cmd` that encapsulates most of the Install git, cmake and gcc or clang, using your platform's package manager: ``` -sudo apt-get install git cmake gcc +sudo apt-get install git cmake gcc g++ ``` ### Getting the sources ### @@ -65,17 +65,29 @@ git submodule update Release mode is preferred for almost all cases, it has much better speed and less console spam. However, if you are developing MCServer actively, debug mode might be better. - cmake . -DCMAKE_BUILD_TYPE=RELEASE && make - +Assuming you are in the MCServer folder created in the initial setup step, you need to run these commands: +``` +mkdir Release +cd Release +cmake . -DCMAKE_BUILD_TYPE=RELEASE .. && make +``` +The executable will be built in the `MCServer/MCServer` folder and will be named `MCServer`. + ### Debug Mode ### -Debug mode is useful if you want more debugging information about MCServer as it's running or if you want to use a debugger like GDB to debug issues and crashes. +Debug mode is useful if you want more debugging information about MCServer while it's running or if you want to use a debugger like GDB to debug issues and crashes. - cmake . -DCMAKE_BUILD_TYPE=DEBUG && make +Assuming you are in the MCServer folder created in the Getting the sources step, you need to run these commands: +``` +mkdir Debug +cd Debug +cmake . -DCMAKE_BUILD_TYPE=DEBUG && make` +``` +The executable will be built in the `MCServer/MCServer` folder and will be named `MCServer_debug`. -### 32 Bit Mode ### +### 32 Bit Mode switch ### -This is useful if you want to compile MCServer to use on another 32-bit machine. It can be used with debug or release mode. To use 32 bit mode, simply add: +This is useful if you want to compile MCServer on an x64 (64-bit Intel) machine but want to use on an x86 (32-bit Intel) machine. This switch can be used with debug or release mode. Simply add: -DFORCE_32=1 @@ -84,8 +96,10 @@ to your cmake command and 32 bit will be forced. ### Compiling for another computer ### -When compiling for another computer it is important to set cross compiling mode. This tells the compiler not to optimise for your machine. It can be used with debug or release mode. To enable simply add: +When cross-compiling for another computer it is important to set cross compiling mode. This tells the compiler not to optimise for your machine. This switch can be used with debug or release mode. To enable, simply add: -DCROSSCOMPILE=1 to your cmake command. + +Note that cross-compilation is probably broken at this moment, since the build requires running an executable that it has built, as part of the build process. -- cgit v1.2.3 From 972919589bfe77e21fad99a52e5ed401127c37a0 Mon Sep 17 00:00:00 2001 From: narroo Date: Thu, 13 Feb 2014 07:51:17 -0600 Subject: Fixed formatting issue in APIDesc.lua --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 565b32b1b..19553ea80 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2117,7 +2117,7 @@ end QueueSetBlock = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta, TickDelay", Return = "", Notes = "Queues the block to be set to the specified blocktype and meta after the specified amount of game ticks. Uses SetBlock() for the actual setting, so simulators are woken up and block entities are handled correctly." }, QueueTask = { Params = "TaskFunction", Return = "", Notes = "Queues the specified function to be executed in the tick thread. This is the primary means of interaction with a cWorld from the WebAdmin page handlers (see {{WebWorldThreads}}). The function signature is
function()
All return values from the function are ignored. Note that this function is actually called *after* the QueueTask() function returns. Note that it is unsafe to store references to MCServer objects, such as entities, across from the caller to the task handler function; store the EntityID instead." }, QueueUnloadUnusedChunks = { Params = "", Return = "", Notes = "Queues a cTask that unloads chunks that are no longer needed and are saved." }, - RegenerateChunk = { Params = "ChunkX, ChunkZ", Return = "", Notes = "Queues the specified chunk to be re-generated, overwriting the current data. To queue a chunk for generating only if it doesn't exist, use the GenerateChunk() instead." }, + RegenerateChunk = { Params = "ChunkX, ChunkZ", Return = "", Notes = "Queues the specified chunk to be re-generated, overwriting the current data. To queue a chunk for generating only if it doesn't exist, use the GenerateChunk() instead." }, ScheduleTask = { Params = "DelayTicks, TaskFunction", Return = "", Notes = "Queues the specified function to be executed in the world's tick thread after a the specified number of ticks. This enables operations to be queued for execution in the future. The function signature is
function({{cWorld|World}})
All return values from the function are ignored. Note that it is unsafe to store references to MCServer objects, such as entities, across from the caller to the task handler function; store the EntityID instead." }, SendBlockTo = { Params = "BlockX, BlockY, BlockZ, {{cPlayer|Player}}", Return = "", Notes = "Sends the block at the specified coords to the specified player's client, as an UpdateBlock packet." }, SetBlock = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block at the specified coords, replaces the block entities for the previous block type, creates a new block entity for the new block, if appropriate, and wakes up the simulators. This is the preferred way to set blocks, as opposed to FastSetBlock(), which is only to be used under special circumstances." }, -- cgit v1.2.3 From 92e85cc96030285bba74837759925866c1be7235 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 13 Feb 2014 17:13:09 +0200 Subject: Implementation of in-game maps --- src/ClientHandle.cpp | 18 ++++ src/ClientHandle.h | 2 + src/Map.cpp | 149 ++++++++++++++++++++++++++++ src/Map.h | 95 ++++++++++++++++++ src/Protocol/Protocol.h | 3 + src/Protocol/Protocol125.cpp | 27 ++++++ src/Protocol/Protocol125.h | 2 + src/Protocol/Protocol17x.cpp | 35 +++++++ src/Protocol/Protocol17x.h | 2 + src/Protocol/ProtocolRecognizer.cpp | 20 ++++ src/Protocol/ProtocolRecognizer.h | 2 + src/WorldStorage/MapSerializer.cpp | 189 ++++++++++++++++++++++++++++++++++++ src/WorldStorage/MapSerializer.h | 52 ++++++++++ 13 files changed, 596 insertions(+) create mode 100644 src/Map.cpp create mode 100644 src/Map.h create mode 100644 src/WorldStorage/MapSerializer.cpp create mode 100644 src/WorldStorage/MapSerializer.h diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 1b3ebc3d4..8e44a61fd 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2057,6 +2057,24 @@ void cClientHandle::SendInventorySlot(char a_WindowID, short a_SlotNum, const cI +void cClientHandle::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) +{ + m_Protocol->SendMapColumn(a_ID, a_X, a_Y, a_Colors, a_Length); +} + + + + + +void cClientHandle::SendMapInfo(int a_ID, unsigned int a_Scale) +{ + m_Protocol->SendMapInfo(a_ID, a_Scale); +} + + + + + void cClientHandle::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) { m_Protocol->SendParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmmount); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index d9a86d983..b1f13954b 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -109,6 +109,8 @@ public: void SendGameMode (eGameMode a_GameMode); void SendHealth (void); void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item); + void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; + void SendMapInfo (int a_ID, unsigned int a_Scale) override; void SendPickupSpawn (const cPickup & a_Pickup); void SendEntityAnimation (const cEntity & a_Entity, char a_Animation); void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount); diff --git a/src/Map.cpp b/src/Map.cpp new file mode 100644 index 000000000..f1b690698 --- /dev/null +++ b/src/Map.cpp @@ -0,0 +1,149 @@ + +// Map.cpp + +#include "Globals.h" + +#include "Map.h" + +#include "ClientHandle.h" +#include "World.h" + + + + + +cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale) + : m_ID(a_ID) + , m_Width(128) + , m_Height(128) + , m_Scale(a_Scale) + , m_CenterX(a_CenterX) + , m_CenterZ(a_CenterZ) + , m_World(a_World) +{ + m_Data.assign(m_Width * m_Height, 0); + + UpdateMap(); +} + + + + + +void cMap::UpdateMap(void) +{ + // ASSERT(m_World != NULL); + + // TODO + + for (unsigned int X = 0; X < m_Width; ++X) + { + for (unsigned int Y = 0; Y < m_Height; ++Y) + { + // Debug + m_Data[Y + X * m_Height] = rand() % 100; + } + } +} + + + + + +eDimension cMap::GetDimension(void) const +{ + ASSERT(m_World != NULL); + return m_World->GetDimension(); +} + + + + + + +void cMap::Resize(unsigned int a_Width, unsigned int a_Height) +{ + if ((m_Width == a_Width) && (m_Height == a_Height)) + { + return; + } + + m_Width = a_Width; + m_Height = a_Height; + + m_Data.assign(m_Width * m_Height, 0); + + UpdateMap(); +} + + + + + +void cMap::SetPosition(int a_CenterX, int a_CenterZ) +{ + if ((m_CenterX == a_CenterX) && (m_CenterZ == a_CenterZ)) + { + return; + } + + m_CenterX = a_CenterX; + m_CenterZ = a_CenterZ; + + UpdateMap(); +} + + + + + +void cMap::SetScale(unsigned int a_Scale) +{ + if (m_Scale == a_Scale) + { + return; + } + + m_Scale = a_Scale; + + UpdateMap(); +} + + + + + +void cMap::SendTo(cClientHandle & a_Client) +{ + a_Client.SendMapInfo(m_ID, m_Scale); + + for (unsigned int i = 0; i < m_Width; ++i) + { + const Byte* Colors = &m_Data[i * m_Height]; + + a_Client.SendMapColumn(m_ID, i, 0, Colors, m_Height); + } +} + + + + + +unsigned int cMap::GetNumPixels(void) const +{ + return m_Width * m_Height; +} + + + + + +unsigned int cMap::GetNumBlocksPerPixel(void) const +{ + return pow(2, m_Scale); +} + + + + + diff --git a/src/Map.h b/src/Map.h new file mode 100644 index 000000000..80bbd4ab4 --- /dev/null +++ b/src/Map.h @@ -0,0 +1,95 @@ + +// Map.h + +// Implementation of in-game coloured maps + + + + + +#pragma once + + + + + +#include "BlockID.h" + + + + + +class cClientHandle; +class cWorld; + + + + + +class cMap +{ +public: + + typedef Byte ColorID; + + typedef std::vector cColorList; + + +public: + + cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale = 3); + + /** Update the map (Query the world) */ + void UpdateMap(void); + + /** Send this map to the specified client. */ + void SendTo(cClientHandle & a_Client); + + void Resize(unsigned int a_Width, unsigned int a_Height); + + void SetPosition(int a_CenterX, int a_CenterZ); + + void SetScale(unsigned int a_Scale); + + unsigned int GetWidth (void) const { return m_Width; } + unsigned int GetHeight(void) const { return m_Height; } + + unsigned int GetScale(void) const { return m_Scale; } + + int GetCenterX(void) const { return m_CenterX; } + int GetCenterZ(void) const { return m_CenterZ; } + + unsigned int GetID(void) const { return m_ID; } + + cWorld * GetWorld(void) { return m_World; } + + eDimension GetDimension(void) const; + + const cColorList & GetData(void) const { return m_Data; } + + unsigned int GetNumPixels(void) const; + + unsigned int GetNumBlocksPerPixel(void) const; + + +private: + + unsigned int m_ID; + + unsigned int m_Width; + unsigned int m_Height; + + /** The zoom level, 2^scale square blocks per pixel */ + unsigned int m_Scale; + + int m_CenterX; + int m_CenterZ; + + /** Column-major array of colours */ + cColorList m_Data; + + cWorld * m_World; + + friend class cMapSerializer; + +}; diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 791082537..5f89799e1 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -28,6 +28,7 @@ class cWorld; class cMonster; class cChunkDataSerializer; class cFallingBlock; +class cMap; @@ -79,6 +80,8 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0; virtual void SendKeepAlive (int a_PingID) = 0; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0; + virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) = 0; + virtual void SendMapInfo (int a_ID, unsigned int a_Scale) = 0; virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0; virtual void SendPlayerAbilities (void) = 0; virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) = 0; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 73d21161c..edb22fae6 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -95,6 +95,7 @@ enum PACKET_WINDOW_PROPERTY = 0x69, PACKET_CREATIVE_INVENTORY_ACTION = 0x6B, PACKET_UPDATE_SIGN = 0x82, + PACKET_ITEM_DATA = 0x83, PACKET_PLAYER_LIST_ITEM = 0xC9, PACKET_PLAYER_ABILITIES = 0xca, PACKET_PLUGIN_MESSAGE = 0xfa, @@ -576,6 +577,32 @@ void cProtocol125::SendLogin(const cPlayer & a_Player, const cWorld & a_World) +void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) +{ + cCSLock Lock(m_CSPacket); + + WriteByte (PACKET_ITEM_DATA); + WriteShort(E_ITEM_MAP); + WriteShort(a_ID); + WriteShort(3 + a_Length); + + WriteByte(0); + WriteByte(a_X); + WriteByte(a_Y); + + for (unsigned int i = 0; i < a_Length; ++i) + { + WriteByte(a_Colors[i]); + } + + Flush(); +} + + + + + + void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) { cCSLock Lock(m_CSPacket); diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index cd15ab518..467aee002 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -54,6 +54,8 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; + virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; + virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override {} // This protocol doesn't support such message virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override {} // This protocol doesn't support such message diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 7eaf106cf..4acc61586 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -496,6 +496,41 @@ void cProtocol172::SendLogin(const cPlayer & a_Player, const cWorld & a_World) +void cProtocol172::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) +{ + cPacketizer Pkt(*this, 0x34); + Pkt.WriteVarInt(a_ID); + Pkt.WriteShort (3 + a_Length); + + Pkt.WriteByte(0); + Pkt.WriteByte(a_X); + Pkt.WriteByte(a_Y); + + for (unsigned int i = 0; i < a_Length; ++i) + { + Pkt.WriteByte(a_Colors[i]); + } +} + + + + + +void cProtocol172::SendMapInfo(int a_ID, unsigned int a_Scale) +{ + cPacketizer Pkt(*this, 0x34); + Pkt.WriteVarInt(a_ID); + Pkt.WriteShort (2); + + Pkt.WriteByte(2); + Pkt.WriteByte(a_Scale); +} + + + + + + void cProtocol172::SendPickupSpawn(const cPickup & a_Pickup) { { diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 6a75e41c8..0e50db45d 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -76,6 +76,8 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; + virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; + virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override; virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 32409c2aa..447fa516b 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -386,6 +386,26 @@ void cProtocolRecognizer::SendLogin(const cPlayer & a_Player, const cWorld & a_W +void cProtocolRecognizer::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendMapColumn(a_ID, a_X, a_Y, a_Colors, a_Length); +} + + + + + +void cProtocolRecognizer::SendMapInfo(int a_ID, unsigned int a_Scale) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendMapInfo(a_ID, a_Scale); +} + + + + + void cProtocolRecognizer::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) { ASSERT(m_Protocol != NULL); diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index f58c66d10..3c37d5138 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -89,6 +89,8 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; + virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; + virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override; diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp new file mode 100644 index 000000000..ea0d3ec47 --- /dev/null +++ b/src/WorldStorage/MapSerializer.cpp @@ -0,0 +1,189 @@ + +// MapSerializer.cpp + + +#include "Globals.h" +#include "MapSerializer.h" +#include "../StringCompression.h" +#include "zlib/zlib.h" +#include "FastNBT.h" + +#include "../Map.h" + + + + + +cMapSerializer::cMapSerializer(const AString& a_WorldName, cMap * a_Map) + : m_Map(a_Map) +{ + AString DataPath; + Printf(DataPath, "%s/data", a_WorldName.c_str()); + + Printf(m_Path, "%s/map_%i.dat", DataPath.c_str(), a_Map->GetID()); + + cFile::CreateFolder(FILE_IO_PREFIX + DataPath); +} + + + + + +bool cMapSerializer::Load(void) +{ + AString Data = cFile::ReadWholeFile(FILE_IO_PREFIX + m_Path); + if (Data.empty()) + { + return false; + } + + AString Uncompressed; + int res = UncompressStringGZIP(Data.data(), Data.size(), Uncompressed); + + if (res != Z_OK) + { + return false; + } + + // Parse the NBT data: + cParsedNBT NBT(Uncompressed.data(), Uncompressed.size()); + if (!NBT.IsValid()) + { + // NBT Parsing failed + return false; + } + + return LoadMapFromNBT(NBT); +} + + + + + +bool cMapSerializer::Save(void) +{ + cFastNBTWriter Writer; + + SaveMapToNBT(Writer); + + Writer.Finish(); + + #ifdef _DEBUG + cParsedNBT TestParse(Writer.GetResult().data(), Writer.GetResult().size()); + ASSERT(TestParse.IsValid()); + #endif // _DEBUG + + cFile File; + if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmWrite)) + { + return false; + } + + AString Compressed; + int res = CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed); + + if (res != Z_OK) + { + return false; + } + + File.Write(Compressed.data(), Compressed.size()); + File.Close(); + + return true; +} + + + + + +void cMapSerializer::SaveMapToNBT(cFastNBTWriter & a_Writer) +{ + a_Writer.BeginCompound("data"); + + a_Writer.AddByte("scale", m_Map->GetScale()); + a_Writer.AddByte("dimension", (int) m_Map->GetDimension()); + + a_Writer.AddShort("width", m_Map->GetWidth()); + a_Writer.AddShort("height", m_Map->GetHeight()); + + a_Writer.AddInt("xCenter", m_Map->GetCenterX()); + a_Writer.AddInt("zCenter", m_Map->GetCenterZ()); + + // Potential bug - The internal representation may change + const cMap::cColorList & Data = m_Map->GetData(); + a_Writer.AddByteArray("colors", (char *) Data.data(), Data.size()); + + a_Writer.EndCompound(); +} + + + + + +bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT) +{ + int Data = a_NBT.FindChildByName(0, "data"); + if (Data < 0) + { + return false; + } + + int CurrLine = a_NBT.FindChildByName(Data, "scale"); + if (CurrLine >= 0) + { + unsigned int Scale = a_NBT.GetByte(CurrLine); + m_Map->m_Scale = Scale; + } + + CurrLine = a_NBT.FindChildByName(Data, "dimension"); + if (CurrLine >= 0) + { + eDimension Dimension = (eDimension) a_NBT.GetByte(CurrLine); + + // ASSERT(Dimension == m_World.GetDimension()); + } + + CurrLine = a_NBT.FindChildByName(Data, "width"); + if (CurrLine >= 0) + { + unsigned int Width = a_NBT.GetShort(CurrLine); + m_Map->m_Width = Width; + } + + CurrLine = a_NBT.FindChildByName(Data, "height"); + if (CurrLine >= 0) + { + unsigned int Height = a_NBT.GetShort(CurrLine); + m_Map->m_Height = Height; + } + + CurrLine = a_NBT.FindChildByName(Data, "xCenter"); + if (CurrLine >= 0) + { + int CenterX = a_NBT.GetInt(CurrLine); + m_Map->m_CenterX = CenterX; + } + + CurrLine = a_NBT.FindChildByName(Data, "zCenter"); + if (CurrLine >= 0) + { + int CenterZ = a_NBT.GetInt(CurrLine); + m_Map->m_CenterZ = CenterZ; + } + + unsigned int NumPixels = m_Map->GetNumPixels(); + m_Map->m_Data.resize(NumPixels); + + // TODO xdot: Parse the byte array. + + return true; +} + + + + + + + + diff --git a/src/WorldStorage/MapSerializer.h b/src/WorldStorage/MapSerializer.h new file mode 100644 index 000000000..71791a2fb --- /dev/null +++ b/src/WorldStorage/MapSerializer.h @@ -0,0 +1,52 @@ + +// MapSerializer.h + +// Declares the cMapSerializer class that is used for saving maps into NBT format used by Anvil + + + + + +#pragma once + + + + + +// fwd: +class cFastNBTWriter; +class cParsedNBT; +class cMap; + + + + +class cMapSerializer +{ +public: + + cMapSerializer(const AString& a_WorldName, cMap * a_Map); + + /// Try to load the scoreboard + bool Load(void); + + /// Try to save the scoreboard + bool Save(void); + + +private: + + void SaveMapToNBT(cFastNBTWriter & a_Writer); + + bool LoadMapFromNBT(const cParsedNBT & a_NBT); + + cMap * m_Map; + + AString m_Path; + + +} ; + + + + -- cgit v1.2.3 From 05590fb91d7f4bd2178847cc56ae31699f09ddd2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 13 Feb 2014 11:47:20 +0100 Subject: MCADefrag: Initial implementation. Partially implements #639. This only defragments the chunks, without recompressing them. --- Tools/MCADefrag/.gitignore | 1 + Tools/MCADefrag/CMakeLists.txt | 144 ++++++++++++++++++++ Tools/MCADefrag/Globals.cpp | 10 ++ Tools/MCADefrag/Globals.h | 229 +++++++++++++++++++++++++++++++ Tools/MCADefrag/MCADefrag.cpp | 303 +++++++++++++++++++++++++++++++++++++++++ Tools/MCADefrag/MCADefrag.h | 112 +++++++++++++++ 6 files changed, 799 insertions(+) create mode 100644 Tools/MCADefrag/.gitignore create mode 100644 Tools/MCADefrag/CMakeLists.txt create mode 100644 Tools/MCADefrag/Globals.cpp create mode 100644 Tools/MCADefrag/Globals.h create mode 100644 Tools/MCADefrag/MCADefrag.cpp create mode 100644 Tools/MCADefrag/MCADefrag.h diff --git a/Tools/MCADefrag/.gitignore b/Tools/MCADefrag/.gitignore new file mode 100644 index 000000000..44a3e1f48 --- /dev/null +++ b/Tools/MCADefrag/.gitignore @@ -0,0 +1 @@ +*.mca diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt new file mode 100644 index 000000000..7296b8ddc --- /dev/null +++ b/Tools/MCADefrag/CMakeLists.txt @@ -0,0 +1,144 @@ + +cmake_minimum_required (VERSION 2.6) + +project (MCADefrag) + + + +macro(add_flags_cxx FLAGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAGS}") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAGS}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${FLAGS}") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${FLAGS}") +endmacro() + + + + +# Add the preprocessor macros used for distinguishing between debug and release builds (CMake does this automatically for MSVC): +if (NOT MSVC) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG") +endif() + + + +if(MSVC) + # Make build use multiple threads under MSVC: + add_flags_cxx("/MP") + + # Make release builds use link-time code generation: + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") + set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG") +elseif(APPLE) + #on os x clang adds pthread for us but we need to add it for gcc + if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_flags_cxx("-pthread") + endif() +else() + # Let gcc / clang know that we're compiling a multi-threaded app: + add_flags_cxx("-pthread") +endif() + + + + +# Use static CRT in MSVC builds: +if (MSVC) + string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") +endif() + + + + +# Set include paths to the used libraries: +include_directories("../../lib") +include_directories("../../src") + + + +function(flatten_files arg1) + set(res "") + foreach(f ${${arg1}}) + get_filename_component(f ${f} ABSOLUTE) + list(APPEND res ${f}) + endforeach() + set(${arg1} "${res}" PARENT_SCOPE) +endfunction() + + +# Include the libraries: +file(GLOB ZLIB_SRC "../../lib/zlib/*.c") +file(GLOB ZLIB_HDR "../../lib/zlib/*.h") +flatten_files(ZLIB_SRC) +flatten_files(ZLIB_HDR) +source_group("ZLib" FILES ${ZLIB_SRC} ${ZLIB_HDR}) + + +# Include the shared files: +set(SHARED_SRC + ../../src/StringCompression.cpp + ../../src/StringUtils.cpp + ../../src/Log.cpp + ../../src/MCLogger.cpp +) +set(SHARED_HDR + ../../src/ByteBuffer.h + ../../src/StringUtils.h + ../../src/Log.h + ../../src/MCLogger.h +) +set(SHARED_OSS_SRC + ../../src/OSSupport/CriticalSection.cpp + ../../src/OSSupport/File.cpp + ../../src/OSSupport/IsThread.cpp + ../../src/OSSupport/Timer.cpp +) +set(SHARED_OSS_HDR + ../../src/OSSupport/CriticalSection.h + ../../src/OSSupport/File.h + ../../src/OSSupport/IsThread.h + ../../src/OSSupport/Timer.h +) +flatten_files(SHARED_SRC) +flatten_files(SHARED_HDR) +flatten_files(SHARED_OSS_SRC) +flatten_files(SHARED_OSS_HDR) +source_group("Shared" FILES ${SHARED_SRC} ${SHARED_HDR}) +source_group("Shared\\OSSupport" FILES ${SHARED_OSS_SRC} ${SHARED_OSS_HDR}) + + + +# Include the main source files: +set(SOURCES + MCADefrag.cpp + Globals.cpp +) +set(HEADERS + MCADefrag.h + Globals.h +) + +source_group("" FILES ${SOURCES} ${HEADERS}) + +add_executable(MCADefrag + ${SOURCES} + ${HEADERS} + ${SHARED_SRC} + ${SHARED_HDR} + ${SHARED_OSS_SRC} + ${SHARED_OSS_HDR} + ${ZLIB_SRC} + ${ZLIB_HDR} +) + diff --git a/Tools/MCADefrag/Globals.cpp b/Tools/MCADefrag/Globals.cpp new file mode 100644 index 000000000..13c6ae709 --- /dev/null +++ b/Tools/MCADefrag/Globals.cpp @@ -0,0 +1,10 @@ + +// Globals.cpp + +// This file is used for precompiled header generation in MSVC environments + +#include "Globals.h" + + + + diff --git a/Tools/MCADefrag/Globals.h b/Tools/MCADefrag/Globals.h new file mode 100644 index 000000000..6f4bbdc76 --- /dev/null +++ b/Tools/MCADefrag/Globals.h @@ -0,0 +1,229 @@ + +// Globals.h + +// This file gets included from every module in the project, so that global symbols may be introduced easily +// Also used for precompiled header generation in MSVC environments + + + + + +// Compiler-dependent stuff: +#if defined(_MSC_VER) + // MSVC produces warning C4481 on the override keyword usage, so disable the warning altogether + #pragma warning(disable:4481) + + // Disable some warnings that we don't care about: + #pragma warning(disable:4100) + + #define OBSOLETE __declspec(deprecated) + + // No alignment needed in MSVC + #define ALIGN_8 + #define ALIGN_16 + +#elif defined(__GNUC__) + + // TODO: Can GCC explicitly mark classes as abstract (no instances can be created)? + #define abstract + + // TODO: Can GCC mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class) + #define override + + #define OBSOLETE __attribute__((deprecated)) + + #define ALIGN_8 __attribute__((aligned(8))) + #define ALIGN_16 __attribute__((aligned(16))) + + // Some portability macros :) + #define stricmp strcasecmp + +#else + + #error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler" + + /* + // Copy and uncomment this into another #elif section based on your compiler identification + + // Explicitly mark classes as abstract (no instances can be created) + #define abstract + + // Mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class) + #define override + + // Mark functions as obsolete, so that their usage results in a compile-time warning + #define OBSOLETE + + // Mark types / variables for alignment. Do the platforms need it? + #define ALIGN_8 + #define ALIGN_16 + */ + +#endif + + + + + +// Integral types with predefined sizes: +typedef long long Int64; +typedef int Int32; +typedef short Int16; + +typedef unsigned long long UInt64; +typedef unsigned int UInt32; +typedef unsigned short UInt16; + +typedef unsigned char Byte; + + + + + +// A macro to disallow the copy constructor and operator= functions +// This should be used in the private: declarations for any class that shouldn't allow copying itself +#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName &); \ + void operator=(const TypeName &) + +// A macro that is used to mark unused function parameters, to avoid pedantic warnings in gcc +#define UNUSED(X) (void)(X) + + + + +// OS-dependent stuff: +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN + #include + #include + #include + + // Windows SDK defines min and max macros, messing up with our std::min and std::max usage + #undef min + #undef max + + // Windows SDK defines GetFreeSpace as a constant, probably a Win16 API remnant + #ifdef GetFreeSpace + #undef GetFreeSpace + #endif // GetFreeSpace + + #define SocketError WSAGetLastError() +#else + #include + #include // for mkdir + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #include + #include + #include + #include + #include + #include + + typedef int SOCKET; + enum + { + INVALID_SOCKET = -1, + }; + #define closesocket close + #define SocketError errno +#if !defined(ANDROID_NDK) + #include +#endif +#endif + +#if !defined(ANDROID_NDK) + #define USE_SQUIRREL +#endif + +#if defined(ANDROID_NDK) + #define FILE_IO_PREFIX "/sdcard/mcserver/" +#else + #define FILE_IO_PREFIX "" +#endif + + + + + +// CRT stuff: +#include +#include +#include +#include +#include + + + + + +// STL stuff: +#include +#include +#include +#include +#include +#include +#include + + + + + +// Common headers (without macros): +#include "StringUtils.h" +#include "OSSupport/CriticalSection.h" +#include "OSSupport/IsThread.h" +#include "OSSupport/File.h" + + + + + +// Common definitions: + +/// Evaluates to the number of elements in an array (compile-time!) +#define ARRAYCOUNT(X) (sizeof(X) / sizeof(*(X))) + +/// Allows arithmetic expressions like "32 KiB" (but consider using parenthesis around it, "(32 KiB)" ) +#define KiB * 1024 +#define MiB * 1024 * 1024 + +/// Faster than (int)floorf((float)x / (float)div) +#define FAST_FLOOR_DIV( x, div ) ( (x) < 0 ? (((int)x / div) - 1) : ((int)x / div) ) + +// Own version of assert() that writes failed assertions to the log for review +#ifdef NDEBUG + #define ASSERT(x) ((void)0) +#else + #define ASSERT assert +#endif + +// Pretty much the same as ASSERT() but stays in Release builds +#define VERIFY( x ) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), exit(1), 0 ) ) + + + + + +/// A generic interface used mainly in ForEach() functions +template class cItemCallback +{ +public: + /// Called for each item in the internal list; return true to stop the loop, or false to continue enumerating + virtual bool Item(Type * a_Type) = 0; +} ; + + + + diff --git a/Tools/MCADefrag/MCADefrag.cpp b/Tools/MCADefrag/MCADefrag.cpp new file mode 100644 index 000000000..2f24469c9 --- /dev/null +++ b/Tools/MCADefrag/MCADefrag.cpp @@ -0,0 +1,303 @@ + +// MCADefrag.cpp + +// Implements the main app entrypoint and the cMCADefrag class representing the entire app + +#include "Globals.h" +#include "MCADefrag.h" +#include "MCLogger.h" + + + + + +int main(int argc, char ** argv) +{ + new cMCLogger(Printf("Defrag_%08x.log", time(NULL))); + cMCADefrag Defrag; + if (!Defrag.Init(argc, argv)) + { + return 1; + } + + Defrag.Run(); + + return 0; +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cMCADefrag: + +cMCADefrag::cMCADefrag(void) : + m_NumThreads(1) +{ +} + + + + + +bool cMCADefrag::Init(int argc, char ** argv) +{ + // Nothing needed yet + return true; +} + + + + + +void cMCADefrag::Run(void) +{ + // Fill the queue with MCA files + m_Queue = cFile::GetFolderContents("."); + + // Start the processing threads: + for (int i = 0; i < m_NumThreads; i++) + { + StartThread(); + } + + // Wait for all the threads to finish: + while (!m_Threads.empty()) + { + m_Threads.front()->Wait(); + delete m_Threads.front(); + m_Threads.pop_front(); + } +} + + + + +void cMCADefrag::StartThread(void) +{ + cThread * Thread = new cThread(*this); + m_Threads.push_back(Thread); + Thread->Start(); +} + + + + + +AString cMCADefrag::GetNextFileName(void) +{ + cCSLock Lock(m_CS); + if (m_Queue.empty()) + { + return AString(); + } + AString res = m_Queue.back(); + m_Queue.pop_back(); + return res; +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cMCADefrag::cThread: + +cMCADefrag::cThread::cThread(cMCADefrag & a_Parent) : + super("MCADefrag thread"), + m_Parent(a_Parent) +{ +} + + + + + +void cMCADefrag::cThread::Execute(void) +{ + for (;;) + { + AString FileName = m_Parent.GetNextFileName(); + if (FileName.empty()) + { + return; + } + ProcessFile(FileName); + } +} + + + + + +void cMCADefrag::cThread::ProcessFile(const AString & a_FileName) +{ + // Filter out non-MCA files: + if ((a_FileName.length() < 4) || (a_FileName.substr(a_FileName.length() - 4, 4) != ".mca")) + { + return; + } + LOGINFO("%s", a_FileName.c_str()); + + // Open input and output files: + AString OutFileName = a_FileName + ".new"; + cFile In, Out; + if (!In.Open(a_FileName, cFile::fmRead)) + { + LOGWARNING("Cannot open file %s for reading, skipping file.", a_FileName.c_str()); + return; + } + if (!Out.Open(OutFileName.c_str(), cFile::fmWrite)) + { + LOGWARNING("Cannot open file %s for writing, skipping file.", OutFileName.c_str()); + return; + } + + // Read the Locations and Timestamps from the input file: + Byte Locations[4096]; + UInt32 Timestamps[1024]; + if (In.Read(Locations, sizeof(Locations)) != sizeof(Locations)) + { + LOGWARNING("Cannot read Locations in file %s, skipping file.", a_FileName.c_str()); + return; + } + if (In.Read(Timestamps, sizeof(Timestamps)) != sizeof(Timestamps)) + { + LOGWARNING("Cannot read Timestamps in file %s, skipping file.", a_FileName.c_str()); + return; + } + + // Write dummy Locations to the Out file (will be overwritten once the correct ones are known) + if (Out.Write(Locations, sizeof(Locations)) != sizeof(Locations)) + { + LOGWARNING("Cannot write Locations to file %s, skipping file.", OutFileName.c_str()); + return; + } + m_CurrentSectorOut = 2; + + // Write a copy of the Timestamps into the Out file: + if (Out.Write(Timestamps, sizeof(Timestamps)) != sizeof(Timestamps)) + { + LOGWARNING("Cannot write Timestamps to file %s, skipping file.", OutFileName.c_str()); + return; + } + + // Process each chunk: + for (size_t i = 0; i < 1024; i++) + { + size_t idx = i * 4; + if ( + (Locations[idx] == 0) && + (Locations[idx + 1] == 0) && + (Locations[idx + 2] == 0) && + (Locations[idx + 3] == 0) + ) + { + // Chunk not present + continue; + } + if (!ReadChunk(In, Locations + idx)) + { + LOGWARNING("Cannot read chunk #%d from file %s. Skipping file.", i, a_FileName.c_str()); + return; + } + if (!WriteChunk(Out, Locations + idx)) + { + LOGWARNING("Cannot write chunk #%d to file %s. Skipping file.", i, OutFileName.c_str()); + return; + } + } + + // Write the new Locations into the MCA header: + Out.Seek(0); + if (Out.Write(Locations, sizeof(Locations)) != sizeof(Locations)) + { + LOGWARNING("Cannot write updated Locations to file %s, skipping file.", OutFileName.c_str()); + return; + } + + // Close the files, delete orig, rename new: + In.Close(); + Out.Close(); + cFile::Delete(a_FileName); + cFile::Rename(OutFileName, a_FileName); +} + + + + + +bool cMCADefrag::cThread::ReadChunk(cFile & a_File, const Byte * a_LocationRaw) +{ + int SectorNum = (a_LocationRaw[0] << 16) | (a_LocationRaw[1] << 8) | a_LocationRaw[2]; + int SizeInSectors = a_LocationRaw[3] * (4 KiB); + if (a_File.Seek(SectorNum * (4 KiB)) < 0) + { + LOGWARNING("Failed to seek to chunk data - file pos %llu (%d KiB, %.02f MiB)!", (Int64)SectorNum * (4 KiB), SectorNum * 4, ((double)SectorNum) / 256); + return false; + } + + // Read the exact size: + Byte Buf[4]; + if (a_File.Read(Buf, 4) != 4) + { + LOGWARNING("Failed to read chunk data length"); + return false; + } + m_CompressedChunkDataSize = (Buf[0] << 24) | (Buf[1] << 16) | (Buf[2] << 8) | Buf[3]; + if (m_CompressedChunkDataSize > SizeInSectors) + { + LOGWARNING("Invalid chunk data - SizeInSectors (%d) smaller that RealSize (%d)", SizeInSectors, m_CompressedChunkDataSize); + return false; + } + + // Read the data: + if (a_File.Read(m_CompressedChunkData, m_CompressedChunkDataSize) != m_CompressedChunkDataSize) + { + LOGWARNING("Failed to read chunk data!"); + return false; + } + + // TODO: Uncompress the data if recompression is active + + return true; +} + + + + + +bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw) +{ + // TODO: Recompress the data if recompression is active + + a_LocationRaw[0] = m_CurrentSectorOut >> 16; + a_LocationRaw[1] = (m_CurrentSectorOut >> 8) & 0xff; + a_LocationRaw[2] = m_CurrentSectorOut & 0xff; + a_LocationRaw[3] = (m_CompressedChunkDataSize + (4 KiB) - 1) / (4 KiB); + + // Write the data length: + Byte Buf[4]; + Buf[0] = m_CompressedChunkDataSize >> 24; + Buf[1] = (m_CompressedChunkDataSize >> 16) & 0xff; + Buf[2] = (m_CompressedChunkDataSize >> 8) & 0xff; + Buf[3] = m_CompressedChunkDataSize & 0xff; + if (a_File.Write(Buf, 4) != 4) + { + LOGWARNING("Failed to write chunk length!"); + return false; + } + + // Write the data: + if (a_File.Write(m_CompressedChunkData, m_CompressedChunkDataSize) != m_CompressedChunkDataSize) + { + LOGWARNING("Failed to write chunk data!"); + return false; + } + return true; +} + + + + diff --git a/Tools/MCADefrag/MCADefrag.h b/Tools/MCADefrag/MCADefrag.h new file mode 100644 index 000000000..0801d1b5d --- /dev/null +++ b/Tools/MCADefrag/MCADefrag.h @@ -0,0 +1,112 @@ + +// MCADefrag.h + +// Interfaces to the cMCADefrag class encapsulating the entire app + + + + + +#pragma once + + + + + + +class cMCADefrag +{ +public: + enum + { + MAX_COMPRESSED_CHUNK_DATA_SIZE = (1 MiB), + MAX_RAW_CHUNK_DATA_SIZE = (100 MiB), + } ; + + cMCADefrag(void); + + /** Reads the cmdline params and initializes the app. + Returns true if the app should continue, false if not. */ + bool Init(int argc, char ** argv); + + /** Runs the entire app. */ + void Run(void); + +protected: + /** A single thread processing MCA files from the queue */ + class cThread : + public cIsThread + { + typedef cIsThread super; + + public: + cThread(cMCADefrag & a_Parent); + + protected: + cMCADefrag & m_Parent; + + /** The current compressed chunk data. Valid after a successful ReadChunk(). + This contains only the compression method byte and the compressed data, + but not the length preceding the data in the MCA file. */ + unsigned char m_CompressedChunkData[MAX_COMPRESSED_CHUNK_DATA_SIZE]; + + /** Size of the actual current compressed chunk data. */ + int m_CompressedChunkDataSize; + + /** The current raw chunk data. Valid after a successful ReadChunk(), if recompression is active. */ + unsigned char m_RawChunkData[MAX_RAW_CHUNK_DATA_SIZE]; + + /** Size of the actual current raw chunk data. */ + int m_RawChunkDataSize; + + /** Number of the sector where the next chunk will be written by WriteChunk(). */ + int m_CurrentSectorOut; + + + /** Processes the specified file. */ + void ProcessFile(const AString & a_FileName); + + /** Reads the chunk data into m_CompressedChunkData. + Calls DecompressChunkData() if recompression is active. + a_LocationRaw is the pointer to the first byte of the Location data in the MCA header. + Returns true if successful. */ + bool ReadChunk(cFile & a_File, const Byte * a_LocationRaw); + + /** Writes the chunk data from m_CompressedData or m_RawChunkData (performing recompression) into file. + Calls CompressChunkData() for the actual compression, if recompression is active. + a_LocationRaw is the pointer to the first byte of the Location data to be put into the MCA header, + the chunk's location is stored in that memory area. Updates m_CurrentSectorOut. + Returns true if successful. */ + bool WriteChunk(cFile & a_File, Byte * a_LocationRaw); + + // cIsThread overrides: + virtual void Execute(void) override; + } ; + + typedef std::list cThreads; + + + /** The mutex protecting m_Files agains multithreaded access. */ + cCriticalSection m_CS; + + /** The queue of MCA files to be processed by the threads. Protected by m_CS. */ + AStringVector m_Queue; + + /** List of threads that the server has running. */ + cThreads m_Threads; + + /** The number of threads that should be started. Configurable on the command line. */ + int m_NumThreads; + + + /** Starts a new processing thread and adds it to cThreads. */ + void StartThread(void); + + /** Retrieves one file from the queue (and removes it from the queue). + Returns an empty string when queue empty. */ + AString GetNextFileName(void); +} ; + + + + -- cgit v1.2.3 From cd658e02e8dcb7503d8aa5d75c314dcddb1ca11a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 13 Feb 2014 12:48:22 +0100 Subject: MCADefrag: Fixed bugs, now produces valid MCA files. --- Tools/MCADefrag/MCADefrag.cpp | 20 +++++++++++++++++++- Tools/MCADefrag/MCADefrag.h | 5 +++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Tools/MCADefrag/MCADefrag.cpp b/Tools/MCADefrag/MCADefrag.cpp index 2f24469c9..59a67e45d 100644 --- a/Tools/MCADefrag/MCADefrag.cpp +++ b/Tools/MCADefrag/MCADefrag.cpp @@ -11,6 +11,13 @@ +// An array of 4096 zero bytes, used for writing the padding +static const Byte g_Zeroes[4096] = {0}; + + + + + int main(int argc, char ** argv) { new cMCLogger(Printf("Defrag_%08x.log", time(NULL))); @@ -275,7 +282,7 @@ bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw) a_LocationRaw[0] = m_CurrentSectorOut >> 16; a_LocationRaw[1] = (m_CurrentSectorOut >> 8) & 0xff; a_LocationRaw[2] = m_CurrentSectorOut & 0xff; - a_LocationRaw[3] = (m_CompressedChunkDataSize + (4 KiB) - 1) / (4 KiB); + a_LocationRaw[3] = (m_CompressedChunkDataSize + (4 KiB) + 3) / (4 KiB); // +3 because the m_CompressedChunkDataSize doesn't include the exact-length // Write the data length: Byte Buf[4]; @@ -295,6 +302,17 @@ bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw) LOGWARNING("Failed to write chunk data!"); return false; } + + // Pad onto the next sector: + int NumPadding = a_LocationRaw[3] * 4096 - (m_CompressedChunkDataSize + 4); + ASSERT(NumPadding >= 0); + if ((NumPadding > 0) && (a_File.Write(g_Zeroes, NumPadding) != NumPadding)) + { + LOGWARNING("Failed to write padding"); + return false; + } + + m_CurrentSectorOut += a_LocationRaw[3]; return true; } diff --git a/Tools/MCADefrag/MCADefrag.h b/Tools/MCADefrag/MCADefrag.h index 0801d1b5d..ef527863d 100644 --- a/Tools/MCADefrag/MCADefrag.h +++ b/Tools/MCADefrag/MCADefrag.h @@ -47,10 +47,11 @@ protected: /** The current compressed chunk data. Valid after a successful ReadChunk(). This contains only the compression method byte and the compressed data, - but not the length preceding the data in the MCA file. */ + but not the exact-length preceding the data in the MCA file. */ unsigned char m_CompressedChunkData[MAX_COMPRESSED_CHUNK_DATA_SIZE]; - /** Size of the actual current compressed chunk data. */ + /** Size of the actual current compressed chunk data, excluding the 4 exact-length bytes. + This is the amount of bytes in m_CompressedChunkData[] that are valid. */ int m_CompressedChunkDataSize; /** The current raw chunk data. Valid after a successful ReadChunk(), if recompression is active. */ -- cgit v1.2.3 From 41ab8260f7b50bedbf06ea0effcb6147cb648685 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 13 Feb 2014 16:54:29 +0100 Subject: MCADefrag: Implemented recompression. This finalizes #639. --- Tools/MCADefrag/MCADefrag.cpp | 110 ++++++++++++++++++++++++++++++++++++++++-- Tools/MCADefrag/MCADefrag.h | 31 ++++++++++++ 2 files changed, 136 insertions(+), 5 deletions(-) diff --git a/Tools/MCADefrag/MCADefrag.cpp b/Tools/MCADefrag/MCADefrag.cpp index 59a67e45d..a2de7f957 100644 --- a/Tools/MCADefrag/MCADefrag.cpp +++ b/Tools/MCADefrag/MCADefrag.cpp @@ -6,6 +6,7 @@ #include "Globals.h" #include "MCADefrag.h" #include "MCLogger.h" +#include "zlib/zlib.h" @@ -40,7 +41,8 @@ int main(int argc, char ** argv) // cMCADefrag: cMCADefrag::cMCADefrag(void) : - m_NumThreads(1) + m_NumThreads(4), + m_ShouldRecompress(true) { } @@ -113,7 +115,8 @@ AString cMCADefrag::GetNextFileName(void) cMCADefrag::cThread::cThread(cMCADefrag & a_Parent) : super("MCADefrag thread"), - m_Parent(a_Parent) + m_Parent(a_Parent), + m_IsChunkUncompressed(false) { } @@ -204,6 +207,7 @@ void cMCADefrag::cThread::ProcessFile(const AString & a_FileName) // Chunk not present continue; } + m_IsChunkUncompressed = false; if (!ReadChunk(In, Locations + idx)) { LOGWARNING("Cannot read chunk #%d from file %s. Skipping file.", i, a_FileName.c_str()); @@ -266,7 +270,15 @@ bool cMCADefrag::cThread::ReadChunk(cFile & a_File, const Byte * a_LocationRaw) return false; } - // TODO: Uncompress the data if recompression is active + // Uncompress the data if recompression is active + if (m_Parent.m_ShouldRecompress) + { + m_IsChunkUncompressed = UncompressChunk(); + if (!m_IsChunkUncompressed) + { + LOGINFO("Chunk failed to uncompress, will be copied verbatim instead."); + } + } return true; } @@ -277,12 +289,21 @@ bool cMCADefrag::cThread::ReadChunk(cFile & a_File, const Byte * a_LocationRaw) bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw) { - // TODO: Recompress the data if recompression is active + // Recompress the data if recompression is active: + if (m_Parent.m_ShouldRecompress) + { + if (!CompressChunk()) + { + LOGINFO("Chunk failed to recompress, will be coped verbatim instead."); + } + } + // Update the Location: a_LocationRaw[0] = m_CurrentSectorOut >> 16; a_LocationRaw[1] = (m_CurrentSectorOut >> 8) & 0xff; a_LocationRaw[2] = m_CurrentSectorOut & 0xff; a_LocationRaw[3] = (m_CompressedChunkDataSize + (4 KiB) + 3) / (4 KiB); // +3 because the m_CompressedChunkDataSize doesn't include the exact-length + m_CurrentSectorOut += a_LocationRaw[3]; // Write the data length: Byte Buf[4]; @@ -312,7 +333,86 @@ bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw) return false; } - m_CurrentSectorOut += a_LocationRaw[3]; + return true; +} + + + + + +bool cMCADefrag::cThread::UncompressChunk(void) +{ + switch (m_CompressedChunkData[0]) + { + case COMPRESSION_GZIP: return UncompressChunkGzip(); + case COMPRESSION_ZLIB: return UncompressChunkZlib(); + } + LOGINFO("Chunk is compressed with in an unknown algorithm"); + return false; +} + + + + + +bool cMCADefrag::cThread::UncompressChunkGzip(void) +{ + // TODO + // This format is not used in practice + return false; +} + + + + + +bool cMCADefrag::cThread::UncompressChunkZlib(void) +{ + // Uncompress the data: + z_stream strm; + strm.zalloc = (alloc_func)NULL; + strm.zfree = (free_func)NULL; + strm.opaque = NULL; + inflateInit(&strm); + strm.next_out = m_RawChunkData; + strm.avail_out = sizeof(m_RawChunkData); + strm.next_in = m_CompressedChunkData + 1; // The first byte is the compression method, skip it + strm.avail_in = m_CompressedChunkDataSize; + int res = inflate(&strm, Z_FINISH); + inflateEnd(&strm); + if (res != Z_STREAM_END) + { + LOGWARNING("Failed to uncompress chunk data: %s", strm.msg); + return false; + } + m_RawChunkDataSize = strm.total_out; + + return true; +} + + + + + +bool cMCADefrag::cThread::CompressChunk(void) +{ + // Check that the compressed data can fit: + uLongf CompressedSize = compressBound(m_RawChunkDataSize); + if (CompressedSize > sizeof(m_CompressedChunkData)) + { + LOGINFO("Too much data for the internal compression buffer!"); + return false; + } + + // Compress the data using the highest compression factor: + int errorcode = compress2(m_CompressedChunkData + 1, &CompressedSize, m_RawChunkData, m_RawChunkDataSize, Z_BEST_COMPRESSION); + if (errorcode != Z_OK) + { + LOGINFO("Recompression failed: %d", errorcode); + return false; + } + m_CompressedChunkData[0] = COMPRESSION_ZLIB; + m_CompressedChunkDataSize = CompressedSize + 1; return true; } diff --git a/Tools/MCADefrag/MCADefrag.h b/Tools/MCADefrag/MCADefrag.h index ef527863d..d7fa1fc6e 100644 --- a/Tools/MCADefrag/MCADefrag.h +++ b/Tools/MCADefrag/MCADefrag.h @@ -43,6 +43,14 @@ protected: cThread(cMCADefrag & a_Parent); protected: + /** The compression methods, as specified by the MCA compression method byte. */ + enum + { + COMPRESSION_GZIP = 1, + COMPRESSION_ZLIB = 2, + } ; + + cMCADefrag & m_Parent; /** The current compressed chunk data. Valid after a successful ReadChunk(). @@ -63,6 +71,10 @@ protected: /** Number of the sector where the next chunk will be written by WriteChunk(). */ int m_CurrentSectorOut; + /** Set to true when the chunk has been successfully uncompressed. Only used if recompression is active. + WriteChunk() tests this flag to decide whether to call Compress(). */ + bool m_IsChunkUncompressed; + /** Processes the specified file. */ void ProcessFile(const AString & a_FileName); @@ -80,6 +92,22 @@ protected: Returns true if successful. */ bool WriteChunk(cFile & a_File, Byte * a_LocationRaw); + /** Uncompresses the chunk data from m_CompressedChunkData into m_RawChunkData. + Returns true if successful, false on failure. */ + bool UncompressChunk(void); + + /** Uncompresses the chunk data from m_CompressedChunkData into m_RawChunkData, using Gzip. + Returns true if successful, false on failure. */ + bool UncompressChunkGzip(void); + + /** Uncompresses the chunk data from m_CompressedChunkData into m_RawChunkData, using Zlib. + Returns true if successful, false on failure. */ + bool UncompressChunkZlib(void); + + /** Compresses the chunk data from m_RawChunkData into m_CompressedChunkData. + Returns true if successful, false on failure. */ + bool CompressChunk(void); + // cIsThread overrides: virtual void Execute(void) override; } ; @@ -99,6 +127,9 @@ protected: /** The number of threads that should be started. Configurable on the command line. */ int m_NumThreads; + /** If set to true, the chunk data is recompressed while saving each MCA file. */ + bool m_ShouldRecompress; + /** Starts a new processing thread and adds it to cThreads. */ void StartThread(void); -- cgit v1.2.3 From 6103589e8c13aca159f34eff5d0bc7bb40e3e76a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 13 Feb 2014 17:05:31 +0100 Subject: Updated Core. --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 0e5358871..5c8557d4f 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 0e53588713215f0a9557ef55295e8aa22f265cba +Subproject commit 5c8557d4fdfa580c100510cde07a1a778ea2e244 -- cgit v1.2.3 From 32b465b8e1e1a6fa9e966a1376209f292331d4ae Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 13 Feb 2014 21:36:24 +0200 Subject: IDCount Serialization --- src/ClientHandle.h | 4 +- src/Map.cpp | 18 +++++++++ src/Map.h | 3 ++ src/World.cpp | 54 ++++++++++++++++++++++++++ src/World.h | 11 ++++++ src/WorldStorage/MapSerializer.cpp | 79 +++++++++++++++++++++++++++++++++++++- src/WorldStorage/MapSerializer.h | 25 ++++++++++++ 7 files changed, 191 insertions(+), 3 deletions(-) diff --git a/src/ClientHandle.h b/src/ClientHandle.h index b1f13954b..a714cf8b9 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -109,8 +109,8 @@ public: void SendGameMode (eGameMode a_GameMode); void SendHealth (void); void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item); - void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; - void SendMapInfo (int a_ID, unsigned int a_Scale) override; + void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length); + void SendMapInfo (int a_ID, unsigned int a_Scale); void SendPickupSpawn (const cPickup & a_Pickup); void SendEntityAnimation (const cEntity & a_Entity, char a_Animation); void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount); diff --git a/src/Map.cpp b/src/Map.cpp index f1b690698..f99b01752 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -12,6 +12,24 @@ +cMap::cMap(unsigned int a_ID, cWorld * a_World) + : m_ID(a_ID) + , m_Width(128) + , m_Height(128) + , m_Scale(3) + , m_CenterX(0) + , m_CenterZ(0) + , m_World(a_World) +{ + m_Data.assign(m_Width * m_Height, 0); + + // Do not update map +} + + + + + cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale) : m_ID(a_ID) , m_Width(128) diff --git a/src/Map.h b/src/Map.h index 80bbd4ab4..dbb15afdd 100644 --- a/src/Map.h +++ b/src/Map.h @@ -37,6 +37,9 @@ public: public: + /// Construct an empty map + cMap(unsigned int a_ID, cWorld * a_World); + cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale = 3); /** Update the map (Query the world) */ diff --git a/src/World.cpp b/src/World.cpp index f8c1091f0..a308778df 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -11,7 +11,9 @@ #include "ChunkMap.h" #include "Generating/ChunkDesc.h" #include "OSSupport/Timer.h" + #include "WorldStorage/ScoreboardSerializer.h" +#include "WorldStorage/MapSerializer.h" // Entities (except mobs): #include "Entities/ExpOrb.h" @@ -261,6 +263,8 @@ cWorld::cWorld(const AString & a_WorldName) : // Load the scoreboard cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard); Serializer.Load(); + + LoadMapData(); } @@ -284,6 +288,8 @@ cWorld::~cWorld() cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard); Serializer.Save(); + SaveMapData(); + delete m_ChunkMap; } @@ -2945,6 +2951,54 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c + +void cWorld::LoadMapData(void) +{ + cIDCountSerializer IDSerializer(GetName()); + + IDSerializer.Load(); + + unsigned int MapCount = IDSerializer.GetMapCount(); + + m_MapData.clear(); + + for (unsigned int i = 0; i < MapCount; ++i) + { + cMap Map(i, this); + + cMapSerializer Serializer(GetName(), &Map); + + Serializer.Load(); + + m_MapData.push_back(Map); + } +} + + + + + +void cWorld::SaveMapData(void) +{ + cIDCountSerializer IDSerializer(GetName()); + + IDSerializer.SetMapCount(m_MapData.size()); + + IDSerializer.Save(); + + for (cMapList::iterator it = m_MapData.begin(); it != m_MapData.end(); ++it) + { + cMap & Map = *it; + + cMapSerializer Serializer(GetName(), &Map); + + Serializer.Save(); + } +} + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cWorld::cTaskSaveAllChunks: diff --git a/src/World.h b/src/World.h index fa83fe73e..02e56a247 100644 --- a/src/World.h +++ b/src/World.h @@ -24,6 +24,7 @@ #include "Entities/ProjectileEntity.h" #include "ForEachChunkProvider.h" #include "Scoreboard.h" +#include "Map.h" #include "Blocks/WorldInterface.h" #include "Blocks/BroadcastInterface.h" @@ -811,6 +812,10 @@ private: cChunkGenerator m_Generator; cScoreboard m_Scoreboard; + + typedef std::vector cMapList; + + cMapList m_MapData; /** The callbacks that the ChunkGenerator uses to store new chunks and interface to plugins */ cChunkGeneratorCallbacks m_GeneratorCallbacks; @@ -876,6 +881,12 @@ private: /** Creates a new redstone simulator.*/ cRedstoneSimulator * InitializeRedstoneSimulator(cIniFile & a_IniFile); + + /** Loads the map data from the disk */ + void LoadMapData(void); + + /** Saves the map data to the disk */ + void SaveMapData(void); }; // tolua_export diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp index ea0d3ec47..aab4c7816 100644 --- a/src/WorldStorage/MapSerializer.cpp +++ b/src/WorldStorage/MapSerializer.cpp @@ -9,6 +9,7 @@ #include "FastNBT.h" #include "../Map.h" +#include "../World.h" @@ -141,7 +142,7 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT) { eDimension Dimension = (eDimension) a_NBT.GetByte(CurrLine); - // ASSERT(Dimension == m_World.GetDimension()); + ASSERT(Dimension == m_Map->m_World->GetDimension()); } CurrLine = a_NBT.FindChildByName(Data, "width"); @@ -184,6 +185,82 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT) +cIDCountSerializer::cIDCountSerializer(const AString & a_WorldName) : m_MapCount(0) +{ + AString DataPath; + Printf(DataPath, "%s/data", a_WorldName.c_str()); + + Printf(m_Path, "%s/idcounts.dat", DataPath.c_str()); + + cFile::CreateFolder(FILE_IO_PREFIX + DataPath); +} + + + + + +bool cIDCountSerializer::Load(void) +{ + AString Data = cFile::ReadWholeFile(FILE_IO_PREFIX + m_Path); + if (Data.empty()) + { + return false; + } + + // NOTE: idcounts.dat is not compressed (raw format) + + // Parse the NBT data: + cParsedNBT NBT(Data.data(), Data.size()); + if (!NBT.IsValid()) + { + // NBT Parsing failed + return false; + } + + int CurrLine = NBT.FindChildByName(0, "map"); + if (CurrLine >= 0) + { + m_MapCount = (int)NBT.GetShort(CurrLine); + } + + return true; +} + + + + + +bool cIDCountSerializer::Save(void) +{ + cFastNBTWriter Writer; + + Writer.AddShort("map", m_MapCount); + + Writer.Finish(); + + #ifdef _DEBUG + cParsedNBT TestParse(Writer.GetResult().data(), Writer.GetResult().size()); + ASSERT(TestParse.IsValid()); + #endif // _DEBUG + + cFile File; + if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmWrite)) + { + return false; + } + + // NOTE: idcounts.dat is not compressed (raw format) + + File.Write(Writer.GetResult().data(), Writer.GetResult().size()); + File.Close(); + + return true; +} + + + + + diff --git a/src/WorldStorage/MapSerializer.h b/src/WorldStorage/MapSerializer.h index 71791a2fb..d9da107bc 100644 --- a/src/WorldStorage/MapSerializer.h +++ b/src/WorldStorage/MapSerializer.h @@ -50,3 +50,28 @@ private: +class cIDCountSerializer +{ +public: + + cIDCountSerializer(const AString & a_WorldName); + + bool Load(void); + + bool Save(void); + + inline unsigned int GetMapCount(void) const { return m_MapCount; } + + inline void SetMapCount(unsigned int a_MapCount) { m_MapCount = a_MapCount; } + + +private: + + AString m_Path; + + unsigned int m_MapCount; +}; + + + + -- cgit v1.2.3 From c0e7d6fec9c8349321849b933183ef3f49ff87d2 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 13 Feb 2014 19:57:23 +0000 Subject: Fancy stuff with constant references --- src/BlockEntities/HopperEntity.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index b2fe7ee99..b4ee36607 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -198,7 +198,7 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) public cEntityCallback { public: - cHopperPickupSearchCallback(const Vector3i a_Pos, cItemGrid & a_Contents) : + cHopperPickupSearchCallback(const Vector3i & a_Pos, cItemGrid & a_Contents) : m_Pos(a_Pos), m_bFoundPickupsAbove(false), m_Contents(a_Contents) @@ -265,7 +265,7 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) } protected: - const Vector3i m_Pos; + Vector3i m_Pos; bool m_bFoundPickupsAbove; cItemGrid & m_Contents; }; -- cgit v1.2.3 From f4f0099947a017085574bff681d76aa1d4d53058 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 13 Feb 2014 20:20:37 +0000 Subject: Added proper debug messages --- src/BlockEntities/HopperEntity.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index b4ee36607..386dc2d32 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -238,19 +238,24 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) m_bFoundPickupsAbove = true; m_Contents.SetSlot(i, a_Pickup->GetItem()); a_Pickup->Destroy(); // Kill pickup + + LOGD("Hopper sucking pickup into an empty slot"); + return true; } else if (m_Contents.GetSlot(i).IsEqual(a_Pickup->GetItem()) && !m_Contents.GetSlot(i).IsFullStack()) { m_bFoundPickupsAbove = true; - LOGINFO("Previous counts, pickup: %i, hopper: %i", (int)a_Pickup->GetItem().m_ItemCount, (int)m_Contents.GetSlot(i).m_ItemCount); + + LOGD("Hopper sucking pickup; previous counts, pickup: %i, hopper: %i", (int)a_Pickup->GetItem().m_ItemCount, (int)m_Contents.GetSlot(i).m_ItemCount); + int PreviousCount = m_Contents.GetSlot(i).m_ItemCount; a_Pickup->GetItem().m_ItemCount -= m_Contents.ChangeSlotCount(i, a_Pickup->GetItem().m_ItemCount) - PreviousCount; // Set count to however many items were added - LOGINFO("After counts, pickup: %i, hopper: %i", (int)a_Pickup->GetItem().m_ItemCount, (int)m_Contents.GetSlot(i).m_ItemCount); + + LOGD("Hopper sucking pickup; after counts, pickup: %i, hopper: %i", (int)a_Pickup->GetItem().m_ItemCount, (int)m_Contents.GetSlot(i).m_ItemCount); if (a_Pickup->GetItem().IsEmpty()) { - //LOGINFO("Pickup was empty!"); a_Pickup->Destroy(); // Kill pickup if all items were added } return true; -- cgit v1.2.3 From 5b92b877bcc0c5072dbea98b6c54106f954aa758 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 14 Feb 2014 16:21:16 +0200 Subject: Send map when selected --- src/Bindings/AllToLua.pkg | 1 + src/ClientHandle.cpp | 13 +++++++++++ src/Map.cpp | 47 +++++++++++++++++++++++--------------- src/Map.h | 20 ++++++++++++---- src/World.cpp | 45 ++++++++++++++++++++++++++++++++++-- src/World.h | 6 +++++ src/WorldStorage/MapSerializer.cpp | 9 +++++--- 7 files changed, 114 insertions(+), 27 deletions(-) diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index f65aed9bb..335acff95 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -47,6 +47,7 @@ $cfile "../ItemGrid.h" $cfile "../BlockEntities/BlockEntity.h" $cfile "../BlockEntities/BlockEntityWithItems.h" $cfile "../BlockEntities/ChestEntity.h" +$cfile "../BlockEntities/CommandBlockEntity.h" $cfile "../BlockEntities/DropSpenserEntity.h" $cfile "../BlockEntities/DispenserEntity.h" $cfile "../BlockEntities/DropperEntity.h" diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 8e44a61fd..a2cbaefff 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1190,6 +1190,19 @@ void cClientHandle::HandleSlotSelected(short a_SlotNum) { m_Player->GetInventory().SetEquippedSlotNum(a_SlotNum); m_Player->GetWorld()->BroadcastEntityEquipment(*m_Player, 0, m_Player->GetInventory().GetEquippedItem(), this); + + const cItem & Item = m_Player->GetInventory().GetEquippedItem(); + if (Item.m_ItemType == E_ITEM_MAP) + { + // TODO 2014-02-14 xdot: Do not hardcode this. + cMap * Map = m_Player->GetWorld()->GetMapData(Item.m_ItemDamage); + + if (Map != NULL) + { + // TODO 2014-02-14 xdot: Optimization - Do not send the whole map. + Map->SendTo(*this); + } + } } diff --git a/src/Map.cpp b/src/Map.cpp index f99b01752..4acd9512c 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -7,6 +7,7 @@ #include "ClientHandle.h" #include "World.h" +#include "Chunk.h" @@ -22,8 +23,6 @@ cMap::cMap(unsigned int a_ID, cWorld * a_World) , m_World(a_World) { m_Data.assign(m_Width * m_Height, 0); - - // Do not update map } @@ -41,27 +40,45 @@ cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, un { m_Data.assign(m_Width * m_Height, 0); - UpdateMap(); + for (unsigned int X = 0; X < m_Width; ++X) + { + for (unsigned int Y = 0; Y < m_Height; ++Y) + { + // Debug + m_Data[Y + X * m_Height] = rand() % 100; + } + } } -void cMap::UpdateMap(void) +bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y) { - // ASSERT(m_World != NULL); + ASSERT(m_World != NULL); - // TODO + cChunk * Chunk = NULL; - for (unsigned int X = 0; X < m_Width; ++X) + if (Chunk == NULL) { - for (unsigned int Y = 0; Y < m_Height; ++Y) - { - // Debug - m_Data[Y + X * m_Height] = rand() % 100; - } + return false; } + + int Height = Chunk->GetHeight(a_X, a_Y); + + // TODO + + return true; +} + + + + + +void cMap::EraseData(void) +{ + m_Data.assign(m_Width * m_Height, 0); } @@ -90,8 +107,6 @@ void cMap::Resize(unsigned int a_Width, unsigned int a_Height) m_Height = a_Height; m_Data.assign(m_Width * m_Height, 0); - - UpdateMap(); } @@ -107,8 +122,6 @@ void cMap::SetPosition(int a_CenterX, int a_CenterZ) m_CenterX = a_CenterX; m_CenterZ = a_CenterZ; - - UpdateMap(); } @@ -123,8 +136,6 @@ void cMap::SetScale(unsigned int a_Scale) } m_Scale = a_Scale; - - UpdateMap(); } diff --git a/src/Map.h b/src/Map.h index dbb15afdd..c443445de 100644 --- a/src/Map.h +++ b/src/Map.h @@ -26,28 +26,33 @@ class cWorld; +// tolua_begin class cMap { public: typedef Byte ColorID; + // tolua_end + typedef std::vector cColorList; public: - /// Construct an empty map + /** Construct an empty map. */ cMap(unsigned int a_ID, cWorld * a_World); cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale = 3); - /** Update the map (Query the world) */ - void UpdateMap(void); - /** Send this map to the specified client. */ void SendTo(cClientHandle & a_Client); + // tolua_begin + + /** Erase pixel data */ + void EraseData(void); + void Resize(unsigned int a_Width, unsigned int a_Height); void SetPosition(int a_CenterX, int a_CenterZ); @@ -74,9 +79,16 @@ public: unsigned int GetNumBlocksPerPixel(void) const; + // tolua_end + private: + /** Update the specified pixel. */ + bool UpdatePixel(unsigned int a_X, unsigned int a_Y); + + void PixelToWorldCoords(unsigned int a_X, unsigned int a_Y, int & a_WorldX, int & a_WorldY); + unsigned int m_ID; unsigned int m_Width; diff --git a/src/World.cpp b/src/World.cpp index a308778df..2a3e53332 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1554,6 +1554,42 @@ bool cWorld::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlock +cMap * cWorld::GetMapData(unsigned int a_ID) +{ + if (a_ID < m_MapData.size()) + { + return &m_MapData[a_ID]; + } + else + { + return NULL; + } +} + + + + + +cMap * cWorld::CreateMap(int a_CenterX, int a_CenterY, int a_Scale) +{ + if (m_MapData.size() >= 65536) + { + LOGD("cWorld::CreateMap - Too many maps in use"); + + return NULL; + } + + cMap Map(m_MapData.size(), a_CenterX, a_CenterY, this, a_Scale); + + m_MapData.push_back(Map); + + return &m_MapData[Map.GetID()]; +} + + + + + void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed, bool IsPlayerCreated) { MTRand r1; @@ -2958,7 +2994,7 @@ void cWorld::LoadMapData(void) IDSerializer.Load(); - unsigned int MapCount = IDSerializer.GetMapCount(); + unsigned int MapCount = IDSerializer.GetMapCount() + 1; m_MapData.clear(); @@ -2980,9 +3016,14 @@ void cWorld::LoadMapData(void) void cWorld::SaveMapData(void) { + if (m_MapData.empty()) + { + return; + } + cIDCountSerializer IDSerializer(GetName()); - IDSerializer.SetMapCount(m_MapData.size()); + IDSerializer.SetMapCount(m_MapData.size() - 1); IDSerializer.Save(); diff --git a/src/World.h b/src/World.h index 02e56a247..a9b1ca2cb 100644 --- a/src/World.h +++ b/src/World.h @@ -552,6 +552,12 @@ public: bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; } void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; } + + /** Returns the map with the specified ID, NULL if out of range. */ + cMap * GetMapData(unsigned int a_ID); + + /** Creates a new map. Returns NULL on error */ + cMap * CreateMap(int a_CenterX, int a_CenterY, int a_Scale = 3); // tolua_end diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp index aab4c7816..6dab19d4f 100644 --- a/src/WorldStorage/MapSerializer.cpp +++ b/src/WorldStorage/MapSerializer.cpp @@ -111,7 +111,6 @@ void cMapSerializer::SaveMapToNBT(cFastNBTWriter & a_Writer) a_Writer.AddInt("xCenter", m_Map->GetCenterX()); a_Writer.AddInt("zCenter", m_Map->GetCenterZ()); - // Potential bug - The internal representation may change const cMap::cColorList & Data = m_Map->GetData(); a_Writer.AddByteArray("colors", (char *) Data.data(), Data.size()); @@ -134,7 +133,7 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT) if (CurrLine >= 0) { unsigned int Scale = a_NBT.GetByte(CurrLine); - m_Map->m_Scale = Scale; + m_Map->SetScale(Scale); } CurrLine = a_NBT.FindChildByName(Data, "dimension"); @@ -176,7 +175,11 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT) unsigned int NumPixels = m_Map->GetNumPixels(); m_Map->m_Data.resize(NumPixels); - // TODO xdot: Parse the byte array. + CurrLine = a_NBT.FindChildByName(Data, "colors"); + if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_ByteArray)) + { + memcpy(m_Map->m_Data.data(), a_NBT.GetData(CurrLine), NumPixels); + } return true; } -- cgit v1.2.3 From c7fb00085854ed76b8b8945968de0505b8fbe8a2 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 14 Feb 2014 17:38:22 +0200 Subject: EmptyMap item handler --- MCServer/crafting.txt | 2 +- src/Items/ItemEmptyMap.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/Items/ItemHandler.cpp | 2 ++ src/Map.cpp | 8 ++++---- 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 src/Items/ItemEmptyMap.h diff --git a/MCServer/crafting.txt b/MCServer/crafting.txt index fe9a465d0..92abe24cb 100644 --- a/MCServer/crafting.txt +++ b/MCServer/crafting.txt @@ -156,7 +156,7 @@ Lighter = IronIngot, 1:1 | Flint, 2:2 Lighter = IronIngot, 2:1 | Flint, 1:2 Bucket = IronIngot, 1:1, 2:2, 3:1 Compass = IronIngot, 2:1, 1:2, 3:2, 2:3 | RedstoneDust, 2:2 -Map = Paper, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 | Compass, 2:2 +EmptyMap = Paper, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 | Compass, 2:2 Watch = GoldIngot, 2:1, 1:2, 3:2, 2:3 | RedstoneDust, 2:2 FishingRod = Stick, 1:3, 2:2, 3:1 | String, 3:2, 3:3 FishingRod = Stick, 3:3, 2:2, 1:1 | String, 1:2, 1:3 diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h new file mode 100644 index 000000000..5516033a0 --- /dev/null +++ b/src/Items/ItemEmptyMap.h @@ -0,0 +1,46 @@ + +// ItemEmptyMap.h + + + + + +#pragma once + +#include "../Entities/Entity.h" +#include "../Item.h" + + + + + +class cItemEmptyMapHandler : + public cItemHandler +{ + typedef cItemHandler super; + +public: + cItemEmptyMapHandler() : + super(E_ITEM_EMPTY_MAP) + { + } + + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override + { + UNUSED(a_Item); + UNUSED(a_BlockX); + UNUSED(a_BlockZ); + UNUSED(a_Dir); + + // The map center is fixed at the central point of the 8x8 block of chunks you are standing in when you right-click it. + + const int RegionWidth = cChunkDef::Width * 8; + + int CenterX = round(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth; + int CenterZ = round(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth; + + a_World->CreateMap(CenterX, CenterZ, 0); + + return true; + } +} ; diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 19913ab24..755766d64 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -18,6 +18,7 @@ #include "ItemComparator.h" #include "ItemDoor.h" #include "ItemDye.h" +#include "ItemEmptyMap.h" #include "ItemFishingRod.h" #include "ItemFlowerPot.h" #include "ItemFood.h" @@ -100,6 +101,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_COMPARATOR: return new cItemComparatorHandler(a_ItemType); case E_ITEM_DYE: return new cItemDyeHandler(a_ItemType); case E_ITEM_EGG: return new cItemEggHandler(); + case E_ITEM_EMPTY_MAP: return new cItemEmptyMapHandler(); case E_ITEM_ENDER_PEARL: return new cItemEnderPearlHandler(); case E_ITEM_FIREWORK_ROCKET: return new cItemFireworkHandler(); case E_ITEM_FISHING_ROD: return new cItemFishingRodHandler(a_ItemType); diff --git a/src/Map.cpp b/src/Map.cpp index 4acd9512c..497cc9659 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -15,8 +15,8 @@ cMap::cMap(unsigned int a_ID, cWorld * a_World) : m_ID(a_ID) - , m_Width(128) - , m_Height(128) + , m_Width(cChunkDef::Width * 8) + , m_Height(cChunkDef::Width * 8) , m_Scale(3) , m_CenterX(0) , m_CenterZ(0) @@ -31,8 +31,8 @@ cMap::cMap(unsigned int a_ID, cWorld * a_World) cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale) : m_ID(a_ID) - , m_Width(128) - , m_Height(128) + , m_Width(cChunkDef::Width * 8) + , m_Height(cChunkDef::Width * 8) , m_Scale(a_Scale) , m_CenterX(a_CenterX) , m_CenterZ(a_CenterZ) -- cgit v1.2.3 From ceb16ea2f714cc1b9f52750446e3842e2b6a5820 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 15 Feb 2014 11:38:20 +0100 Subject: Exported cWorld::BroadcastParticleEffect. --- src/World.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/World.h b/src/World.h index fa83fe73e..9049971be 100644 --- a/src/World.h +++ b/src/World.h @@ -183,7 +183,7 @@ public: void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL); void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastEntityAnimation (const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL); - void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); + void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); // tolua_export void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL); void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL); void BroadcastScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode); -- cgit v1.2.3 From 34207a606a129c888eb77d9765214a351144f0f5 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 15 Feb 2014 11:45:20 +0100 Subject: Documented BroadcastParticleEffect --- MCServer/Plugins/APIDump/APIDesc.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 01554d99c..54e1d097d 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2031,6 +2031,7 @@ end BroadcastChatInfo = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Yellow [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For informational messages, such as command usage." }, BroadcastChatSuccess = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Green [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For success messages." }, BroadcastChatWarning = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Rose [WARN] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For concerning events, such as plugin reload etc." }, + BroadcastParticleEffect = { Params = "ParticleName, X, Y, Z, OffSetX, OffSetY, OffSetZ, ParticleData, ParticleAmmount, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Spawns the specified particles to all players in the world exept the optional ExeptClient. A list of available particles by thinkofdeath can be found {{https://gist.github.com/thinkofdeath/5110835|Here}}" }, BroadcastSoundEffect = { Params = "SoundName, X, Y, Z, Volume, Pitch, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the specified sound effect to all players in this world, except the optional ExceptClient" }, BroadcastSoundParticleEffect = { Params = "EffectID, X, Y, Z, EffectData, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the specified effect to all players in this world, except the optional ExceptClient" }, CastThunderbolt = { Params = "X, Y, Z", Return = "", Notes = "Creates a thunderbolt at the specified coords" }, -- cgit v1.2.3 From c6a2e8c6889aca8aa422ac704b79bf7fc43856ec Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 15 Feb 2014 12:58:17 +0000 Subject: Removed debug messages again --- src/BlockEntities/HopperEntity.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 386dc2d32..31b23ac99 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -239,20 +239,14 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) m_Contents.SetSlot(i, a_Pickup->GetItem()); a_Pickup->Destroy(); // Kill pickup - LOGD("Hopper sucking pickup into an empty slot"); - return true; } else if (m_Contents.GetSlot(i).IsEqual(a_Pickup->GetItem()) && !m_Contents.GetSlot(i).IsFullStack()) { m_bFoundPickupsAbove = true; - LOGD("Hopper sucking pickup; previous counts, pickup: %i, hopper: %i", (int)a_Pickup->GetItem().m_ItemCount, (int)m_Contents.GetSlot(i).m_ItemCount); - int PreviousCount = m_Contents.GetSlot(i).m_ItemCount; a_Pickup->GetItem().m_ItemCount -= m_Contents.ChangeSlotCount(i, a_Pickup->GetItem().m_ItemCount) - PreviousCount; // Set count to however many items were added - - LOGD("Hopper sucking pickup; after counts, pickup: %i, hopper: %i", (int)a_Pickup->GetItem().m_ItemCount, (int)m_Contents.GetSlot(i).m_ItemCount); if (a_Pickup->GetItem().IsEmpty()) { -- cgit v1.2.3 From b0fd5511eab236b69fb0805789917e91f8bb6b6e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 15 Feb 2014 13:55:58 +0000 Subject: Fixed typographical error --- src/BlockEntities/SignEntity.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/BlockEntities/SignEntity.h b/src/BlockEntities/SignEntity.h index 2b965747c..80c7bbfdf 100644 --- a/src/BlockEntities/SignEntity.h +++ b/src/BlockEntities/SignEntity.h @@ -1,4 +1,3 @@ - // SignEntity.h // Declares the cSignEntity class representing a single sign in the world @@ -57,7 +56,7 @@ public: virtual void UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle & a_Client) override; - static const char * GetClassStatic(void) { return "cSignrEntity"; } + static const char * GetClassStatic(void) { return "cSignEntity"; } private: -- cgit v1.2.3 From 87e79de4b7d435366862c3b70ccdad559bb2e286 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 11 Feb 2014 15:01:24 +0100 Subject: Add Fence Gate to Redstone Simulator --- src/Simulator/IncrementalRedstoneSimulator.cpp | 29 ++++++++++++++++++++++++++ src/Simulator/IncrementalRedstoneSimulator.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index a875c9e4d..a6e2cb2e9 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -8,6 +8,7 @@ #include "../Entities/TNTEntity.h" #include "../Blocks/BlockTorch.h" #include "../Blocks/BlockDoor.h" +#include "../Blocks/BlockFenceGate.h" #include "../Piston.h" @@ -221,6 +222,7 @@ void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int { case E_BLOCK_BLOCK_OF_REDSTONE: HandleRedstoneBlock(a_X, dataitr->y, a_Z); break; case E_BLOCK_LEVER: HandleRedstoneLever(a_X, dataitr->y, a_Z); break; + case E_BLOCK_FENCE_GATE: HandleFenceGate(a_X, dataitr->y, a_Z); break; case E_BLOCK_TNT: HandleTNT(a_X, dataitr->y, a_Z); break; case E_BLOCK_TRAPDOOR: HandleTrapdoor(a_X, dataitr->y, a_Z); break; case E_BLOCK_REDSTONE_WIRE: HandleRedstoneWire(a_X, dataitr->y, a_Z); break; @@ -402,6 +404,33 @@ void cIncrementalRedstoneSimulator::HandleRedstoneLever(int a_BlockX, int a_Bloc +void cIncrementalRedstoneSimulator::HandleFenceGate(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + cChunkInterface ChunkInterface(m_World.GetChunkMap()); + NIBBLETYPE MetaData = ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + + if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + { + if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaData | 0x4); + SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); + } + } + else + { + if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaData & 0xFFFFFFFB); + SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); + } + } +} + + + + + void cIncrementalRedstoneSimulator::HandleRedstoneButton(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType) { if (IsButtonOn(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ))) diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index a3da13584..bcf89bb82 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -84,6 +84,8 @@ private: void HandleRedstoneBlock(int a_BlockX, int a_BlockY, int a_BlockZ); /** Handles levers */ void HandleRedstoneLever(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles Fence Gates */ + void HandleFenceGate(int a_BlockX, int a_BlockY, int a_BlockZ); /** Handles buttons */ void HandleRedstoneButton(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType); /** Handles daylight sensors */ -- cgit v1.2.3 From 70a0dcb1ebf8c79dce3a2c3bad553b9ee4606540 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 11 Feb 2014 15:08:17 +0100 Subject: Add more Sounds to Redstone Simulator --- src/Simulator/IncrementalRedstoneSimulator.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index a6e2cb2e9..985fdee27 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -318,6 +318,22 @@ void cIncrementalRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_Bloc { // There was a match, torch goes off m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_OFF, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); + + float Pitch = (((1.0F-0.0F)*((float)rand()/RAND_MAX)) - ((1.0F-0.0F)*((float)rand()/RAND_MAX))) * 0.8F; + m_World.BroadcastSoundEffect("random.fizz", + ((int) (a_BlockX + 0.5F) * 8.0), + ((int) (a_BlockY + 0.5F) * 8.0), + ((int) (a_BlockZ + 0.5F) * 8.0), + 0.5F, + 2.6F + Pitch); + + for (int l = 0; l < 5; ++l) { + float d0 = a_BlockX + (double(rand())/RAND_MAX) * 0.6F + 0.2F; + float d1 = a_BlockY + (double(rand())/RAND_MAX) * 0.6F + 0.2F; + float d2 = a_BlockZ + (double(rand())/RAND_MAX) * 0.6F + 0.2F; + m_World.BroadcastParticleEffect("smoke", d0, d1, d2, 0.0F, 0.0F, 0.0F, 0.01F, 1); + } + return; } @@ -414,6 +430,7 @@ void cIncrementalRedstoneSimulator::HandleFenceGate(int a_BlockX, int a_BlockY, if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) { m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaData | 0x4); + m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); } } @@ -422,6 +439,7 @@ void cIncrementalRedstoneSimulator::HandleFenceGate(int a_BlockX, int a_BlockY, if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) { m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaData & 0xFFFFFFFB); + m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); } } @@ -766,7 +784,7 @@ void cIncrementalRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_ { if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) { - m_World.BroadcastSoundEffect("random.fuse", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); + m_World.BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); } @@ -784,6 +802,7 @@ void cIncrementalRedstoneSimulator::HandleDoor(int a_BlockX, int a_BlockY, int a { cChunkInterface ChunkInterface(m_World.GetChunkMap()); cBlockDoorHandler::ChangeDoor(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); } } @@ -793,6 +812,7 @@ void cIncrementalRedstoneSimulator::HandleDoor(int a_BlockX, int a_BlockY, int a { cChunkInterface ChunkInterface(m_World.GetChunkMap()); cBlockDoorHandler::ChangeDoor(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); } } @@ -865,6 +885,7 @@ void cIncrementalRedstoneSimulator::HandleTrapdoor(int a_BlockX, int a_BlockY, i if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) { m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x4); + m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); } } @@ -873,6 +894,7 @@ void cIncrementalRedstoneSimulator::HandleTrapdoor(int a_BlockX, int a_BlockY, i if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) { m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0xB); // Take into account that the fourth bit is needed for trapdoors too + m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); } } -- cgit v1.2.3 From 147b9ed69456bd38d7f9167ad0b3aa249e5ede45 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 15 Feb 2014 16:27:40 +0100 Subject: Debuggers: Added a WebAdmin StressTest page. This page reloads content from the WebAdmin as fast as possible. --- MCServer/Plugins/Debuggers/Debuggers.lua | 89 +++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 13 deletions(-) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 8345e2169..51b3a3a87 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -19,18 +19,18 @@ function Initialize(Plugin) cPluginManager.AddHook(cPluginManager.HOOK_TICK, OnTick2); --]] - cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_USING_BLOCK, OnPlayerUsingBlock); - cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_USING_ITEM, OnPlayerUsingItem); - cPluginManager:AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage); - cPluginManager:AddHook(cPluginManager.HOOK_TICK, OnTick); - cPluginManager:AddHook(cPluginManager.HOOK_CHAT, OnChat); - cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY, OnPlayerRightClickingEntity); - cPluginManager:AddHook(cPluginManager.HOOK_WORLD_TICK, OnWorldTick); - cPluginManager:AddHook(cPluginManager.HOOK_CHUNK_GENERATED, OnChunkGenerated); - cPluginManager:AddHook(cPluginManager.HOOK_PLUGINS_LOADED, OnPluginsLoaded); - cPluginManager:AddHook(cPluginManager.HOOK_PLUGIN_MESSAGE, OnPluginMessage); - - PM = cRoot:Get():GetPluginManager(); + local PM = cPluginManager; + PM:AddHook(cPluginManager.HOOK_PLAYER_USING_BLOCK, OnPlayerUsingBlock); + PM:AddHook(cPluginManager.HOOK_PLAYER_USING_ITEM, OnPlayerUsingItem); + PM:AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage); + PM:AddHook(cPluginManager.HOOK_TICK, OnTick); + PM:AddHook(cPluginManager.HOOK_CHAT, OnChat); + PM:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY, OnPlayerRightClickingEntity); + PM:AddHook(cPluginManager.HOOK_WORLD_TICK, OnWorldTick); + PM:AddHook(cPluginManager.HOOK_CHUNK_GENERATED, OnChunkGenerated); + PM:AddHook(cPluginManager.HOOK_PLUGINS_LOADED, OnPluginsLoaded); + PM:AddHook(cPluginManager.HOOK_PLUGIN_MESSAGE, OnPluginMessage); + PM:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "- Shows a list of all the loaded entities"); PM:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "- Kills all the loaded entities"); PM:BindCommand("/wool", "debuggers", HandleWoolCmd, "- Sets all your armor to blue wool"); @@ -55,7 +55,8 @@ function Initialize(Plugin) PM:BindCommand("/sched", "debuggers", HandleSched, "- Schedules a simple countdown using cWorld:ScheduleTask()"); PM:BindCommand("/cs", "debuggers", HandleChunkStay, "- Tests the ChunkStay Lua integration for the specified chunk coords"); - Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers); + Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers) + Plugin:AddWebTab("StressTest", HandleRequest_StressTest) -- Enable the following line for BlockArea / Generator interface testing: -- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED); @@ -1038,6 +1039,68 @@ end +local g_Counter = 0 +local g_JavaScript = +[[ + +]] + +function HandleRequest_StressTest(a_Request) + if (a_Request.PostParams["counter"]) then + g_Counter = g_Counter + 1 + return tostring(g_Counter) + end + return g_JavaScript .. "

The counter below should be reloading as fast as possible

0
" +end + + + + + function OnPluginMessage(a_Client, a_Channel, a_Message) LOGINFO("Received a plugin message from client " .. a_Client:GetUsername() .. ": channel '" .. a_Channel .. "', message '" .. a_Message .. "'"); -- cgit v1.2.3 From a5b8d358450aa8208319f37226ef0b34687c0e37 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 15 Feb 2014 15:37:10 +0000 Subject: Updated Plugin article + Adds reference to new SendMessage() functions --- .../Plugins/APIDump/Writing-a-MCServer-plugin.html | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html b/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html index 1eec4842a..35c880b00 100644 --- a/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html +++ b/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html @@ -20,13 +20,7 @@

Let us begin. In order to begin development, we must firstly obtain a compiled copy of MCServer, and make sure that the Core plugin is within the Plugins folder, and activated. - Core handles much of the MCServer end-user experience and is a necessary component of - plugin development, as necessary plugin components depend on sone of its functions. -

-

- Next, we must obtain a copy of CoreMessaging.lua. This can be found - here. - This is used to provide messaging support that is compliant with MCServer standards. + Core handles much of the MCServer end-user experience and gameplay will be very bland without it.

Creating the basic template

@@ -41,7 +35,11 @@ function Initialize(Plugin) Plugin:SetName("NewPlugin") Plugin:SetVersion(1) - PLUGIN = Plugin + -- Hooks + + PLUGIN = Plugin -- NOTE: only needed if you want OnDisable() to use GetName() or something like that + + -- Command Bindings LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) return true @@ -58,7 +56,8 @@ end

  • Plugin:SetName sets the name of the plugin.
  • Plugin:SetVersion sets the revision number of the plugin. This must be an integer.
  • LOG logs to console a message, in this case, it prints that the plugin was initialised.
  • -
  • The PLUGIN variable just stores this plugin's object, so GetName() can be called in OnDisable (as no Plugin parameter is passed there, contrary to Initialize).
  • +
  • The PLUGIN variable just stores this plugin's object, so GetName() can be called in OnDisable (as no Plugin parameter is passed there, contrary to Initialize). + This global variable is only needed if you want to know the plugin details (name, etc.) when shutting down.
  • function OnDisable is called when the plugin is disabled, commonly when the server is shutting down. Perform cleanup and logging here.
  • Be sure to return true for this function, else MCS thinks you plugin had failed to initialise and prints a stacktrace with an error message. @@ -159,21 +158,23 @@ cPluginManager.BindCommand("/commandname", "permissionnode", FunctionToCall, " ~ a message. Again, see the API documentation for fuller details. But, you ask, how do we send a message to the client?

    - Remember that copy of CoreMessaging.lua that we downloaded earlier? Make sure that file is in your plugin folder, along with the main.lua file you are typing - your code in. Since MCS brings all the files together on JIT compile, we don't need to worry about requiring any files or such. Simply follow the below examples: + There are dedicated functions used for sending a player formatted messages. By format, I refer to coloured prefixes/coloured text (depending on configuration) + that clearly categorise what type of message a player is being sent. For example, an informational message has a yellow coloured [INFO] prefix, and a warning message + has a rose coloured [WARNING] prefix. A few of the most used functions are listed here, but see the API docs for more details. Look in the cRoot, cWorld, and cPlayer sections + for functions that broadcast to the entire server, the whole world, and a single player, respectively.

     -- Format: §yellow[INFO] §white%text% (yellow [INFO], white text following it)
     -- Use: Informational message, such as instructions for usage of a command
    -SendMessage(Player, "Usage: /explode [player]")
    +Player:SendMessageInfo("Usage: /explode [player]")
     
     -- Format: §green[INFO] §white%text% (green [INFO] etc.)
     -- Use: Success message, like when a command executes successfully
    -SendMessageSuccess(Player, "Notch was blown up!")
    +Player:SendMessageSuccess("Notch was blown up!")
     
     -- Format: §rose[INFO] §white%text% (rose coloured [INFO] etc.)
     -- Use: Failure message, like when a command was entered correctly but failed to run, such as when the destination player wasn't found in a /tp command
    -SendMessageFailure(Player, "Player Salted was not found")
    +Player:SendMessageFailure("Player Salted was not found")
     			

    Those are the basics. If you want to output text to the player for a reason other than the three listed above, and you want to colour the text, simply concatenate -- cgit v1.2.3 From 6eeeb2aa0129ee9664b6cf21a68517bd4b9c7348 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 15 Feb 2014 15:51:49 +0000 Subject: Sizeable speed improvements to redstone + Moved all simulator data into individual chunks * Cleaned up parameters for functions and some code * Fixed repeaters powering off faster than they power on The main issue before was that, although the redstone simulator stored blocks to be simulated in individual cChunks, other data, such as powered lists, and etcetera, were global regardless of which chunk was being simulated. Therefore, with worlds with lots of redstone, each tick saw the ticking of chunks, which themselves iterated through the entire dataset needlessly, creating LOTS of lag. Should be better now :) --- src/Chunk.h | 14 ++- src/Simulator/IncrementalRedstoneSimulator.cpp | 161 ++++++++++++++----------- src/Simulator/IncrementalRedstoneSimulator.h | 35 ++++-- 3 files changed, 127 insertions(+), 83 deletions(-) diff --git a/src/Chunk.h b/src/Chunk.h index 93eba217e..696690068 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -343,12 +343,17 @@ public: NIBBLETYPE GetTimeAlteredLight(NIBBLETYPE a_Skylight) const; - // Simulator data: + // Per-chunk simulator data: cFireSimulatorChunkData & GetFireSimulatorData (void) { return m_FireSimulatorData; } cFluidSimulatorData * GetWaterSimulatorData(void) { return m_WaterSimulatorData; } cFluidSimulatorData * GetLavaSimulatorData (void) { return m_LavaSimulatorData; } cSandSimulatorChunkData & GetSandSimulatorData (void) { return m_SandSimulatorData; } - cRedstoneSimulatorChunkData & GetRedstoneSimulatorData(void) { return m_RedstoneSimulatorData; } + + cRedstoneSimulatorChunkData * GetRedstoneSimulatorData(void) { return &m_RedstoneSimulatorData; } + cIncrementalRedstoneSimulator::PoweredBlocksList * GetRedstoneSimulatorPoweredBlocksList(void) { return &m_RedstoneSimulatorPoweredBlocksList; } + cIncrementalRedstoneSimulator::LinkedBlocksList * GetRedstoneSimulatorLinkedBlocksList(void) { return &m_RedstoneSimulatorLinkedBlocksList; }; + cIncrementalRedstoneSimulator::SimulatedPlayerToggleableList * GetRedstoneSimulatorSimulatedPlayerToggleableList(void) { return &m_RedstoneSimulatorSimulatedPlayerToggleableList; }; + cIncrementalRedstoneSimulator::RepeatersDelayList * GetRedstoneSimulatorRepeatersDelayList(void) { return &m_RedstoneSimulatorRepeatersDelayList; }; cBlockEntity * GetBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ); cBlockEntity * GetBlockEntity(const Vector3i & a_BlockPos) { return GetBlockEntity(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z); } @@ -419,7 +424,12 @@ private: cFluidSimulatorData * m_WaterSimulatorData; cFluidSimulatorData * m_LavaSimulatorData; cSandSimulatorChunkData m_SandSimulatorData; + cRedstoneSimulatorChunkData m_RedstoneSimulatorData; + cIncrementalRedstoneSimulator::PoweredBlocksList m_RedstoneSimulatorPoweredBlocksList; + cIncrementalRedstoneSimulator::LinkedBlocksList m_RedstoneSimulatorLinkedBlocksList; + cIncrementalRedstoneSimulator::SimulatedPlayerToggleableList m_RedstoneSimulatorSimulatedPlayerToggleableList; + cIncrementalRedstoneSimulator::RepeatersDelayList m_RedstoneSimulatorRepeatersDelayList; // pick up a random block of this chunk diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 985fdee27..e6398a9eb 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -8,7 +8,6 @@ #include "../Entities/TNTEntity.h" #include "../Blocks/BlockTorch.h" #include "../Blocks/BlockDoor.h" -#include "../Blocks/BlockFenceGate.h" #include "../Piston.h" @@ -53,7 +52,8 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B // Every time a block is changed (AddBlock called), we want to go through all lists and check to see if the coordiantes stored within are still valid // Checking only when a block is changed, as opposed to every tick, also improves performance - for (PoweredBlocksList::iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) + PoweredBlocksList * PoweredBlocks = a_Chunk->GetRedstoneSimulatorPoweredBlocksList(); + for (PoweredBlocksList::iterator itr = PoweredBlocks->begin(); itr != PoweredBlocks->end(); ++itr) { if (!itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { @@ -63,7 +63,7 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B if (!IsPotentialSource(Block)) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list as it no longer connected to a source", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_PoweredBlocks.erase(itr); + &(*PoweredBlocks).erase(itr); break; } else if ( @@ -76,7 +76,7 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B ) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_PoweredBlocks.erase(itr); + &(*PoweredBlocks).erase(itr); break; } else if (Block == E_BLOCK_DAYLIGHT_SENSOR) @@ -94,21 +94,22 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B if (a_Chunk->GetTimeAlteredLight(SkyLight) <= 8) // Could use SkyLight - m_World.GetSkyDarkness(); { LOGD("cIncrementalRedstoneSimulator: Erased daylight sensor from powered blocks list due to insufficient light level"); - m_PoweredBlocks.erase(itr); + &(*PoweredBlocks).erase(itr); break; } } } } - for (LinkedBlocksList::iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) + LinkedBlocksList * LinkedPoweredBlocks = a_Chunk->GetRedstoneSimulatorLinkedBlocksList(); + for (LinkedBlocksList::iterator itr = LinkedPoweredBlocks->begin(); itr != LinkedPoweredBlocks->end(); ++itr) { if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { if (!IsPotentialSource(Block)) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list as it is no longer connected to a source", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_LinkedPoweredBlocks.erase(itr); + &(*LinkedPoweredBlocks).erase(itr); break; } else if ( @@ -119,7 +120,7 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B ) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_LinkedPoweredBlocks.erase(itr); + &(*LinkedPoweredBlocks).erase(itr); break; } } @@ -128,13 +129,14 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B if (!IsViableMiddleBlock(Block)) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list as it is no longer powered through a valid middle block", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_LinkedPoweredBlocks.erase(itr); + &(*LinkedPoweredBlocks).erase(itr); break; } } } - for (SimulatedPlayerToggleableList::iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end(); ++itr) + SimulatedPlayerToggleableList * SimulatedPlayerToggleableBlocks = a_Chunk->GetRedstoneSimulatorSimulatedPlayerToggleableList(); + for (SimulatedPlayerToggleableList::iterator itr = SimulatedPlayerToggleableBlocks->begin(); itr != SimulatedPlayerToggleableBlocks->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { @@ -144,12 +146,13 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B if (!IsAllowedBlock(Block)) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from toggleable simulated list as it is no longer redstone", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - m_SimulatedPlayerToggleableBlocks.erase(itr); + &(*SimulatedPlayerToggleableBlocks).erase(itr); break; } } - for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); ++itr) + RepeatersDelayList * RepeatersDelayList = a_Chunk->GetRedstoneSimulatorRepeatersDelayList(); + for (RepeatersDelayList::iterator itr = RepeatersDelayList->begin(); itr != RepeatersDelayList->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { @@ -158,13 +161,13 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B if ((Block != E_BLOCK_REDSTONE_REPEATER_ON) && (Block != E_BLOCK_REDSTONE_REPEATER_OFF)) { - m_RepeatersDelayList.erase(itr); + &(*RepeatersDelayList).erase(itr); break; } } - cRedstoneSimulatorChunkData & ChunkData = a_Chunk->GetRedstoneSimulatorData(); - for (cRedstoneSimulatorChunkData::iterator itr = ChunkData.begin(); itr != ChunkData.end(); ++itr) + cRedstoneSimulatorChunkData * RedstoneSimulatorChunkData = a_Chunk->GetRedstoneSimulatorData(); + for (cRedstoneSimulatorChunkData::iterator itr = RedstoneSimulatorChunkData->begin(); itr != RedstoneSimulatorChunkData->end(); ++itr) { if ((itr->x == RelX) && (itr->y == a_BlockY) && (itr->z == RelZ)) // We are at an entry matching the current (changed) block { @@ -185,7 +188,7 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B return; } - ChunkData.push_back(cCoordWithBlockAndBool(RelX, a_BlockY, RelZ, Block, false)); + RedstoneSimulatorChunkData->push_back(cCoordWithBlockAndBool(RelX, a_BlockY, RelZ, Block, false)); } @@ -199,20 +202,26 @@ void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int // The easiest way to make this more efficient is probably just to reduce code within the handlers that put too much strain on server, like getting or setting blocks // A marking dirty system might be a TODO for later on, perhaps - cRedstoneSimulatorChunkData & ChunkData = a_Chunk->GetRedstoneSimulatorData(); - if (ChunkData.empty()) + m_RedstoneSimulatorChunkData = a_Chunk->GetRedstoneSimulatorData(); + if (m_RedstoneSimulatorChunkData->empty()) { return; } + m_PoweredBlocks = a_Chunk->GetRedstoneSimulatorPoweredBlocksList(); + m_RepeatersDelayList = a_Chunk->GetRedstoneSimulatorRepeatersDelayList(); + m_SimulatedPlayerToggleableBlocks = a_Chunk->GetRedstoneSimulatorSimulatedPlayerToggleableList(); + m_LinkedPoweredBlocks = a_Chunk->GetRedstoneSimulatorLinkedBlocksList(); + m_Chunk = a_Chunk; + int BaseX = a_Chunk->GetPosX() * cChunkDef::Width; int BaseZ = a_Chunk->GetPosZ() * cChunkDef::Width; - for (cRedstoneSimulatorChunkData::iterator dataitr = ChunkData.begin(); dataitr != ChunkData.end();) + for (cRedstoneSimulatorChunkData::iterator dataitr = m_RedstoneSimulatorChunkData->begin(); dataitr != m_RedstoneSimulatorChunkData->end();) { if (dataitr->DataTwo) { - dataitr = ChunkData.erase(dataitr); + dataitr = m_RedstoneSimulatorChunkData->erase(dataitr); continue; } @@ -293,6 +302,31 @@ void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int +void cIncrementalRedstoneSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) +{ + if ( + ((a_BlockX % cChunkDef::Width) >= cChunkDef::Width - 2) || + ((a_BlockX % cChunkDef::Width) <= cChunkDef::Width + 2) || + ((a_BlockZ % cChunkDef::Width) >= cChunkDef::Width - 2) || + ((a_BlockZ % cChunkDef::Width) <= cChunkDef::Width + 2) + ) // Are we on a chunk boundary? ± 2 because of LinkedPowered blocks + { + // On a chunk boundary, alert all four sides (i.e. at least one neighbouring chunk) + AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk); + AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 1, a_BlockZ)); + AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 1, a_BlockZ)); + AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ - 1)); + AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ + 1)); + return; + } + + // Not on boundary, just alert this chunk for speed + AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk); +} + + + + void cIncrementalRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) { @@ -318,22 +352,6 @@ void cIncrementalRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_Bloc { // There was a match, torch goes off m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_OFF, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); - - float Pitch = (((1.0F-0.0F)*((float)rand()/RAND_MAX)) - ((1.0F-0.0F)*((float)rand()/RAND_MAX))) * 0.8F; - m_World.BroadcastSoundEffect("random.fizz", - ((int) (a_BlockX + 0.5F) * 8.0), - ((int) (a_BlockY + 0.5F) * 8.0), - ((int) (a_BlockZ + 0.5F) * 8.0), - 0.5F, - 2.6F + Pitch); - - for (int l = 0; l < 5; ++l) { - float d0 = a_BlockX + (double(rand())/RAND_MAX) * 0.6F + 0.2F; - float d1 = a_BlockY + (double(rand())/RAND_MAX) * 0.6F + 0.2F; - float d2 = a_BlockZ + (double(rand())/RAND_MAX) * 0.6F + 0.2F; - m_World.BroadcastParticleEffect("smoke", d0, d1, d2, 0.0F, 0.0F, 0.0F, 0.01F, 1); - } - return; } @@ -424,7 +442,7 @@ void cIncrementalRedstoneSimulator::HandleFenceGate(int a_BlockX, int a_BlockY, { cChunkInterface ChunkInterface(m_World.GetChunkMap()); NIBBLETYPE MetaData = ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - + if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) { if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) @@ -432,7 +450,7 @@ void cIncrementalRedstoneSimulator::HandleFenceGate(int a_BlockX, int a_BlockY, m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaData | 0x4); m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); - } + } } else { @@ -554,7 +572,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block } } - if (TimesMetaSmaller == TimesFoundAWire) + if ((TimesMetaSmaller == TimesFoundAWire) && (MyMeta != 0)) { // All surrounding metas were smaller - self must have been a wire that was // transferring power to other wires around. @@ -563,7 +581,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE, 0); // SetMeta & WakeUpSims doesn't seem to work here, so SetBlock return; // No need to process block power sets because self not powered } - else + else if (MyMeta != MetaToSet) { m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaToSet); } @@ -587,12 +605,15 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block { case REDSTONE_NONE: { - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + SetBlockPowered(a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + SetBlockPowered(a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + SetBlockPowered(a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_REDSTONE_WIRE); SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_REDSTONE_WIRE); SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, E_BLOCK_REDSTONE_WIRE); SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_REDSTONE_WIRE); SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_REDSTONE_WIRE); break; @@ -638,14 +659,14 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B if (IsSelfPowered && !IsOn) // Queue a power change if I am receiving power but not on { - QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, 0, true); + QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, true); } else if (!IsSelfPowered && IsOn) // Queue a power change if I am not receiving power but on { - QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, 0, false); + QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, false); } - for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); ++itr) + for (RepeatersDelayList::iterator itr = m_RepeatersDelayList->begin(); itr != m_RepeatersDelayList->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { @@ -699,7 +720,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B { m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); } - m_RepeatersDelayList.erase(itr); // We can remove off repeaters which don't need further updating + m_RepeatersDelayList->erase(itr); // We can remove off repeaters which don't need further updating return; } } @@ -1060,7 +1081,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_Bloc bool cIncrementalRedstoneSimulator::AreCoordsDirectlyPowered(int a_BlockX, int a_BlockY, int a_BlockZ) { - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) // Check powered list + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) // Check powered list { if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { @@ -1076,7 +1097,7 @@ bool cIncrementalRedstoneSimulator::AreCoordsDirectlyPowered(int a_BlockX, int a bool cIncrementalRedstoneSimulator::AreCoordsLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ) { - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) // Check linked powered list + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) // Check linked powered list { if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { @@ -1094,7 +1115,7 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY { // Repeaters cannot be powered by any face except their back; verify that this is true for a source - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } @@ -1124,7 +1145,7 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY } } - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } @@ -1165,7 +1186,7 @@ bool cIncrementalRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, int OldX = a_BlockX, OldY = a_BlockY, OldZ = a_BlockZ; eBlockFace Face = cPiston::MetaDataToDirection(a_Meta); - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } @@ -1181,7 +1202,7 @@ bool cIncrementalRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, a_BlockZ = OldZ; } - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } @@ -1204,7 +1225,7 @@ bool cIncrementalRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, bool cIncrementalRedstoneSimulator::IsWirePowered(int a_BlockX, int a_BlockY, int a_BlockZ) { - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } @@ -1214,7 +1235,7 @@ bool cIncrementalRedstoneSimulator::IsWirePowered(int a_BlockX, int a_BlockY, in } } - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } @@ -1232,7 +1253,7 @@ bool cIncrementalRedstoneSimulator::IsWirePowered(int a_BlockX, int a_BlockY, in bool cIncrementalRedstoneSimulator::AreCoordsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool IsCurrentStatePowered) { - for (SimulatedPlayerToggleableList::const_iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end(); ++itr) + for (SimulatedPlayerToggleableList::const_iterator itr = m_SimulatedPlayerToggleableBlocks->begin(); itr != m_SimulatedPlayerToggleableBlocks->end(); ++itr) { if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { @@ -1375,7 +1396,9 @@ void cIncrementalRedstoneSimulator::SetBlockPowered(int a_BlockX, int a_BlockY, return; } - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) // Check powered list + PoweredBlocksList * Powered = m_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ)->GetRedstoneSimulatorPoweredBlocksList(); + + for (PoweredBlocksList::const_iterator itr = Powered->begin(); itr != Powered->end(); ++itr) // Check powered list { if ( itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)) && @@ -1390,7 +1413,7 @@ void cIncrementalRedstoneSimulator::SetBlockPowered(int a_BlockX, int a_BlockY, sPoweredBlocks RC; RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); RC.a_SourcePos = Vector3i(a_SourceX, a_SourceY, a_SourceZ); - m_PoweredBlocks.push_back(RC); + Powered->push_back(RC); } @@ -1415,7 +1438,9 @@ void cIncrementalRedstoneSimulator::SetBlockLinkedPowered( return; } - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) // Check linked powered list + LinkedBlocksList * Linked = m_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ)->GetRedstoneSimulatorLinkedBlocksList(); + + for (LinkedBlocksList::const_iterator itr = Linked->begin(); itr != Linked->end(); ++itr) // Check linked powered list { if ( itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)) && @@ -1432,7 +1457,7 @@ void cIncrementalRedstoneSimulator::SetBlockLinkedPowered( RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); RC.a_MiddlePos = Vector3i(a_MiddleX, a_MiddleY, a_MiddleZ); RC.a_SourcePos = Vector3i(a_SourceX, a_SourceY, a_SourceZ); - m_LinkedPoweredBlocks.push_back(RC); + Linked->push_back(RC); } @@ -1441,7 +1466,7 @@ void cIncrementalRedstoneSimulator::SetBlockLinkedPowered( void cIncrementalRedstoneSimulator::SetPlayerToggleableBlockAsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool WasLastStatePowered) { - for (SimulatedPlayerToggleableList::iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end(); ++itr) + for (SimulatedPlayerToggleableList::iterator itr = m_SimulatedPlayerToggleableBlocks->begin(); itr != m_SimulatedPlayerToggleableBlocks->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { @@ -1465,16 +1490,16 @@ void cIncrementalRedstoneSimulator::SetPlayerToggleableBlockAsSimulated(int a_Bl sSimulatedPlayerToggleableList RC; RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); RC.WasLastStatePowered = WasLastStatePowered; - m_SimulatedPlayerToggleableBlocks.push_back(RC); + m_SimulatedPlayerToggleableBlocks->push_back(RC); } -void cIncrementalRedstoneSimulator::QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta, short a_ElapsedTicks, bool ShouldPowerOn) +void cIncrementalRedstoneSimulator::QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta, bool ShouldPowerOn) { - for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); ++itr) + for (RepeatersDelayList::iterator itr = m_RepeatersDelayList->begin(); itr != m_RepeatersDelayList->end(); ++itr) { if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { @@ -1484,7 +1509,7 @@ void cIncrementalRedstoneSimulator::QueueRepeaterPowerChange(int a_BlockX, int a } // Already in here (normal to allow repeater to continue on powering and updating blocks in front) - just update info and quit - itr->a_DelayTicks = (((a_Meta & 0xC) >> 0x2) + (ShouldPowerOn ? 1 : 0)) * 2; // See below for description + itr->a_DelayTicks = (((a_Meta & 0xC) >> 0x2) + 1) * 2; // See below for description itr->a_ElapsedTicks = 0; itr->ShouldPowerOn = ShouldPowerOn; return; @@ -1492,18 +1517,16 @@ void cIncrementalRedstoneSimulator::QueueRepeaterPowerChange(int a_BlockX, int a } // Self not in list, add self to list - sRepeatersDelayList RC; + sRepeatersDelayList RC; RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); // Gets the top two bits (delay time), shifts them into the lower two bits, and adds one (meta 0 = 1 tick; 1 = 2 etc.) // * 2 because apparently, MCS ticks are way faster than vanilla ticks, so repeater aren't noticeably delayed - // We don't +1 when powering off because everything seems to already delay a tick when powering off, why? No idea :P - RC.a_DelayTicks = (((a_Meta & 0xC) >> 0x2) + (ShouldPowerOn ? 1 : 0)) * 2; - + RC.a_DelayTicks = (((a_Meta & 0xC) >> 0x2) + 1) * 2; RC.a_ElapsedTicks = 0; RC.ShouldPowerOn = ShouldPowerOn; - m_RepeatersDelayList.push_back(RC); + m_RepeatersDelayList->push_back(RC); return; } diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index bcf89bb82..aea668996 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -3,7 +3,7 @@ #include "RedstoneSimulator.h" -/// Per-chunk data for the simulator, specified individual chunks to simulate; 'Data' is not used +/// Per-chunk data for the simulator, specified individual chunks to simulate typedef cCoordWithBlockAndBoolVector cRedstoneSimulatorChunkData; @@ -21,7 +21,8 @@ public: virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} // not used virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; - virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override { return IsRedstone(a_BlockType); } + virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override { return IsRedstone(a_BlockType); } + virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override; enum eRedstoneDirection { @@ -57,22 +58,28 @@ private: struct sRepeatersDelayList { Vector3i a_BlockPos; - short a_DelayTicks; - short a_ElapsedTicks; + unsigned char a_DelayTicks; + unsigned char a_ElapsedTicks; bool ShouldPowerOn; }; - + +public: + typedef std::vector PoweredBlocksList; typedef std::vector LinkedBlocksList; typedef std::vector SimulatedPlayerToggleableList; typedef std::vector RepeatersDelayList; - PoweredBlocksList m_PoweredBlocks; - LinkedBlocksList m_LinkedPoweredBlocks; - SimulatedPlayerToggleableList m_SimulatedPlayerToggleableBlocks; - RepeatersDelayList m_RepeatersDelayList; +private: + + cRedstoneSimulatorChunkData * m_RedstoneSimulatorChunkData; + PoweredBlocksList * m_PoweredBlocks; + LinkedBlocksList * m_LinkedPoweredBlocks; + SimulatedPlayerToggleableList * m_SimulatedPlayerToggleableBlocks; + RepeatersDelayList * m_RepeatersDelayList; virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override; + cChunk * m_Chunk; // We want a_MyState for devices needing a full FastSetBlock (as opposed to meta) because with our simulation model, we cannot keep setting the block if it is already set correctly // In addition to being non-performant, it would stop the player from actually breaking said device @@ -84,8 +91,6 @@ private: void HandleRedstoneBlock(int a_BlockX, int a_BlockY, int a_BlockZ); /** Handles levers */ void HandleRedstoneLever(int a_BlockX, int a_BlockY, int a_BlockZ); - /** Handles Fence Gates */ - void HandleFenceGate(int a_BlockX, int a_BlockY, int a_BlockZ); /** Handles buttons */ void HandleRedstoneButton(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType); /** Handles daylight sensors */ @@ -118,6 +123,8 @@ private: void HandleRail(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType); /** Handles trapdoors */ void HandleTrapdoor(int a_BlockX, int a_BlockY, int a_BlockZ); + /** Handles fence gates */ + void HandleFenceGate(int a_BlockX, int a_BlockY, int a_BlockZ); /** Handles noteblocks */ void HandleNoteBlock(int a_BlockX, int a_BlockY, int a_BlockZ); /* ===================== */ @@ -134,7 +141,7 @@ private: /** Marks all blocks immediately surrounding a coordinate as powered */ void SetAllDirsAsPowered(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_SourceBlock); /** Queues a repeater to be powered or unpowered */ - void QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta, short a_ElapsedTicks, bool ShouldPowerOn); + void QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta, bool ShouldPowerOn); /** Returns if a coordinate is powered or linked powered */ bool AreCoordsPowered(int a_BlockX, int a_BlockY, int a_BlockZ) { return AreCoordsDirectlyPowered(a_BlockX, a_BlockY, a_BlockZ) || AreCoordsLinkedPowered(a_BlockX, a_BlockY, a_BlockZ); } @@ -267,3 +274,7 @@ private: } } }; + + + + -- cgit v1.2.3 From 8fbb936b6326b46fb3f4b85d654288a6b2ccc240 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 15 Feb 2014 15:53:02 +0000 Subject: Fixed TNT fizzing everywhere --- src/Items/ItemLighter.h | 2 +- src/Mobs/Creeper.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Items/ItemLighter.h b/src/Items/ItemLighter.h index 6681a08d4..cc7daeb08 100644 --- a/src/Items/ItemLighter.h +++ b/src/Items/ItemLighter.h @@ -33,7 +33,7 @@ public: case E_BLOCK_TNT: { // Activate the TNT: - a_World->BroadcastSoundEffect("random.fuse", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); + a_World->BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); a_World->SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom a_World->SetBlock(a_BlockX,a_BlockY,a_BlockZ, E_BLOCK_AIR, 0); break; diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 2e1ece865..ff0abfdca 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -79,7 +79,7 @@ void cCreeper::Attack(float a_Dt) if (!m_bIsBlowing) { - m_World->BroadcastSoundEffect("random.fuse", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 1.f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_World->BroadcastSoundEffect("game.tnt.primed", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 1.f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); m_bIsBlowing = true; m_World->BroadcastEntityMetadata(*this); } -- cgit v1.2.3 From cf96e69716e0ccd0657cf275720bb11b915361c4 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 15 Feb 2014 20:06:47 +0200 Subject: cMap::UpdateRadius --- src/ClientHandle.cpp | 2 + src/Items/ItemEmptyMap.h | 6 ++- src/Map.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++----- src/Map.h | 17 +++++-- 4 files changed, 121 insertions(+), 16 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index a2cbaefff..ff8775771 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1199,6 +1199,8 @@ void cClientHandle::HandleSlotSelected(short a_SlotNum) if (Map != NULL) { + Map->UpdateRadius(*m_Player, 128); // Temporary + // TODO 2014-02-14 xdot: Optimization - Do not send the whole map. Map->SendTo(*this); } diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index 5516033a0..24d31151b 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -18,6 +18,8 @@ class cItemEmptyMapHandler : public cItemHandler { typedef cItemHandler super; + + static const unsigned int DEFAULT_SCALE = 0; public: cItemEmptyMapHandler() : @@ -34,12 +36,12 @@ public: // The map center is fixed at the central point of the 8x8 block of chunks you are standing in when you right-click it. - const int RegionWidth = cChunkDef::Width * 8; + const int RegionWidth = cChunkDef::Width * 8 * pow(2, DEFAULT_SCALE); int CenterX = round(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth; int CenterZ = round(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth; - a_World->CreateMap(CenterX, CenterZ, 0); + a_World->CreateMap(CenterX, CenterZ, DEFAULT_SCALE); return true; } diff --git a/src/Map.cpp b/src/Map.cpp index 497cc9659..e0f991693 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -8,6 +8,7 @@ #include "ClientHandle.h" #include "World.h" #include "Chunk.h" +#include "Entities/Player.h" @@ -23,6 +24,8 @@ cMap::cMap(unsigned int a_ID, cWorld * a_World) , m_World(a_World) { m_Data.assign(m_Width * m_Height, 0); + + Printf(m_Name, "map_%i", m_ID); } @@ -40,12 +43,34 @@ cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, un { m_Data.assign(m_Width * m_Height, 0); - for (unsigned int X = 0; X < m_Width; ++X) + Printf(m_Name, "map_%i", m_ID); +} + + + + + +void cMap::UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius) +{ + int PixelRadius = a_Radius / GetPixelWidth(); + + unsigned int StartX = std::max(a_PixelX - PixelRadius, 0); + unsigned int StartZ = std::max(a_PixelZ - PixelRadius, 0); + + unsigned int EndX = std::min(a_PixelX + PixelRadius, (int)m_Width); + unsigned int EndZ = std::min(a_PixelZ + PixelRadius, (int)m_Height); + + for (unsigned int X = StartX; X < EndX; ++X) { - for (unsigned int Y = 0; Y < m_Height; ++Y) + for (unsigned int Z = StartZ; Z < EndZ; ++Z) { - // Debug - m_Data[Y + X * m_Height] = rand() % 100; + int dX = X - a_PixelX; + int dZ = Z - a_PixelZ; + + if ((dX * dX) + (dZ * dZ) < (PixelRadius * PixelRadius)) + { + UpdatePixel(X, Z); + } } } } @@ -54,20 +79,85 @@ cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, un +void cMap::UpdateRadius(cPlayer & a_Player, unsigned int a_Radius) +{ + unsigned int PixelWidth = GetPixelWidth(); + + int PixelX = (a_Player.GetPosX() - m_CenterX) / PixelWidth + (m_Width / 2); + int PixelZ = (a_Player.GetPosZ() - m_CenterZ) / PixelWidth + (m_Height / 2); + + UpdateRadius(PixelX, PixelZ, a_Radius); +} + + + + + bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y) { ASSERT(m_World != NULL); - cChunk * Chunk = NULL; + unsigned int PixelWidth = GetPixelWidth(); + + int BlockX = m_CenterX + ((a_X - m_Width) * PixelWidth); + int BlockZ = m_CenterZ + ((a_Y - m_Height) * PixelWidth); + + int ChunkX, ChunkY, ChunkZ; + m_World->BlockToChunk(BlockX, 0, BlockZ, ChunkX, ChunkY, ChunkZ); - if (Chunk == NULL) + int RelX = BlockX - (ChunkX * cChunkDef::Width); + int RelZ = BlockZ - (ChunkZ * cChunkDef::Width); + + class cCalculatePixelCb : + public cChunkCallback { - return false; - } + cMap * m_Map; + + int m_RelX, m_RelZ; + + ColorID m_PixelData; + + public: + cCalculatePixelCb(cMap * a_Map, int a_RelX, int a_RelZ) + : m_Map(a_Map), m_RelX(a_RelX), m_RelZ(a_RelZ), m_PixelData(0) {} + + virtual bool Item(cChunk * a_Chunk) override + { + if (a_Chunk == NULL) + { + return false; + } - int Height = Chunk->GetHeight(a_X, a_Y); + unsigned int PixelWidth = m_Map->GetPixelWidth(); + + for (unsigned int X = m_RelX; X < m_RelX + PixelWidth; ++X) + { + for (unsigned int Z = m_RelZ; Z < m_RelZ + PixelWidth; ++Z) + { + int Height = a_Chunk->GetHeight(X, Z); + + if (Height > 0) + { + // TODO + } + } + } + + m_PixelData = 8; // Debug + + return false; + } + + ColorID GetPixelData(void) const + { + return m_PixelData; + } + } CalculatePixelCb(this, RelX, RelZ); + + ASSERT(m_World != NULL); + m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb); - // TODO + m_Data[a_Y + (a_X * m_Height)] = CalculatePixelCb.GetPixelData(); return true; } @@ -167,7 +257,7 @@ unsigned int cMap::GetNumPixels(void) const -unsigned int cMap::GetNumBlocksPerPixel(void) const +unsigned int cMap::GetPixelWidth(void) const { return pow(2, m_Scale); } diff --git a/src/Map.h b/src/Map.h index c443445de..4134d53a1 100644 --- a/src/Map.h +++ b/src/Map.h @@ -21,6 +21,7 @@ class cClientHandle; class cWorld; +class cPlayer; @@ -48,6 +49,11 @@ public: /** Send this map to the specified client. */ void SendTo(cClientHandle & a_Client); + /** Update a circular region with the specified radius and center (in pixels). */ + void UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius); + + void UpdateRadius(cPlayer & a_Player, unsigned int a_Radius); + // tolua_begin /** Erase pixel data */ @@ -71,13 +77,15 @@ public: cWorld * GetWorld(void) { return m_World; } + AString GetName(void) { return m_Name; } + eDimension GetDimension(void) const; const cColorList & GetData(void) const { return m_Data; } unsigned int GetNumPixels(void) const; - unsigned int GetNumBlocksPerPixel(void) const; + unsigned int GetPixelWidth(void) const; // tolua_end @@ -87,8 +95,6 @@ private: /** Update the specified pixel. */ bool UpdatePixel(unsigned int a_X, unsigned int a_Y); - void PixelToWorldCoords(unsigned int a_X, unsigned int a_Y, int & a_WorldX, int & a_WorldY); - unsigned int m_ID; unsigned int m_Width; @@ -105,6 +111,11 @@ private: cWorld * m_World; + //typedef std::vector cPlayerList; + //cPlayerList m_TrackedPlayers; + + AString m_Name; + friend class cMapSerializer; }; -- cgit v1.2.3 From 0040a88b9b40817c04e54259fcb61e31dc4f4213 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 15 Feb 2014 19:51:05 +0100 Subject: If a player is called "Notch" he drops an apple. http://minecraft.gamepedia.com/Notch --- src/Entities/Player.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 286d43cf6..cf5a8edfe 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -839,6 +839,12 @@ void cPlayer::KilledBy(cEntity * a_Killer) cItems Pickups; m_Inventory.CopyToItems(Pickups); m_Inventory.Clear(); + + if (GetName() == "Notch") + { + Pickups.Add(cItem(E_ITEM_RED_APPLE)); + } + m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10); SaveToDisk(); // Save it, yeah the world is a tough place ! -- cgit v1.2.3 From c494d0f6f2645baa4fd356ef2250dbc3202f883a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 15 Feb 2014 19:56:45 +0000 Subject: A fix and an improvement * Fixed a special case with the wrong ChunkX/Z values being used to calculate a relative position * Simplified data structure adding and removing operations (no more pointers!) - Removed one character of whitespace :D --- src/Simulator/IncrementalRedstoneSimulator.cpp | 63 +++++++++++++++++--------- src/Simulator/IncrementalRedstoneSimulator.h | 3 +- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index e6398a9eb..4e165bd36 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -31,7 +31,7 @@ cIncrementalRedstoneSimulator::~cIncrementalRedstoneSimulator() -void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) +void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk, cChunk * a_OtherChunk) { if ((a_Chunk == NULL) || !a_Chunk->IsValid()) { @@ -42,12 +42,27 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B return; } - int RelX = a_BlockX - a_Chunk->GetPosX() * cChunkDef::Width; - int RelZ = a_BlockZ - a_Chunk->GetPosZ() * cChunkDef::Width; - + // We may be called with coordinates in a chunk that is not the first chunk parameter + // In that case, the actual chunk (which the coordinates are in), will be passed as the second parameter + // Use that Chunk pointer to get a relative position + + int RelX = 0; + int RelZ = 0; BLOCKTYPE Block; NIBBLETYPE Meta; - a_Chunk->GetBlockTypeMeta(RelX, a_BlockY, RelZ, Block, Meta); + + if (a_OtherChunk != NULL) + { + RelX = a_BlockX - a_OtherChunk->GetPosX() * cChunkDef::Width; + RelZ = a_BlockZ - a_OtherChunk->GetPosZ() * cChunkDef::Width; + a_OtherChunk->GetBlockTypeMeta(RelX, a_BlockY, RelZ, Block, Meta); + } + else + { + RelX = a_BlockX - a_Chunk->GetPosX() * cChunkDef::Width; + RelZ = a_BlockZ - a_Chunk->GetPosZ() * cChunkDef::Width; + a_Chunk->GetBlockTypeMeta(RelX, a_BlockY, RelZ, Block, Meta); + } // Every time a block is changed (AddBlock called), we want to go through all lists and check to see if the coordiantes stored within are still valid // Checking only when a block is changed, as opposed to every tick, also improves performance @@ -63,7 +78,7 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B if (!IsPotentialSource(Block)) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list as it no longer connected to a source", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - &(*PoweredBlocks).erase(itr); + PoweredBlocks->erase(itr); break; } else if ( @@ -76,7 +91,7 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B ) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - &(*PoweredBlocks).erase(itr); + PoweredBlocks->erase(itr); break; } else if (Block == E_BLOCK_DAYLIGHT_SENSOR) @@ -94,7 +109,7 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B if (a_Chunk->GetTimeAlteredLight(SkyLight) <= 8) // Could use SkyLight - m_World.GetSkyDarkness(); { LOGD("cIncrementalRedstoneSimulator: Erased daylight sensor from powered blocks list due to insufficient light level"); - &(*PoweredBlocks).erase(itr); + PoweredBlocks->erase(itr); break; } } @@ -102,15 +117,16 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B } LinkedBlocksList * LinkedPoweredBlocks = a_Chunk->GetRedstoneSimulatorLinkedBlocksList(); - for (LinkedBlocksList::iterator itr = LinkedPoweredBlocks->begin(); itr != LinkedPoweredBlocks->end(); ++itr) + // We loop through all values (insteading of breaking out at the first) to make sure everything is gone, as there can be multiple SourceBlock entries for one AddBlock coordinate + for (LinkedBlocksList::iterator itr = LinkedPoweredBlocks->begin(); itr != LinkedPoweredBlocks->end();) { if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { if (!IsPotentialSource(Block)) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list as it is no longer connected to a source", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - &(*LinkedPoweredBlocks).erase(itr); - break; + itr = LinkedPoweredBlocks->erase(itr); + continue; } else if ( // Things that can send power through a block but which depends on meta @@ -120,8 +136,8 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B ) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - &(*LinkedPoweredBlocks).erase(itr); - break; + itr = LinkedPoweredBlocks->erase(itr); + continue; } } else if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) @@ -129,13 +145,14 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B if (!IsViableMiddleBlock(Block)) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list as it is no longer powered through a valid middle block", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - &(*LinkedPoweredBlocks).erase(itr); - break; + itr = LinkedPoweredBlocks->erase(itr); + continue; } } + ++itr; } - SimulatedPlayerToggleableList * SimulatedPlayerToggleableBlocks = a_Chunk->GetRedstoneSimulatorSimulatedPlayerToggleableList(); + SimulatedPlayerToggleableList * SimulatedPlayerToggleableBlocks = a_Chunk->GetRedstoneSimulatorSimulatedPlayerToggleableList(); for (SimulatedPlayerToggleableList::iterator itr = SimulatedPlayerToggleableBlocks->begin(); itr != SimulatedPlayerToggleableBlocks->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) @@ -146,7 +163,7 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B if (!IsAllowedBlock(Block)) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from toggleable simulated list as it is no longer redstone", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - &(*SimulatedPlayerToggleableBlocks).erase(itr); + SimulatedPlayerToggleableBlocks->erase(itr); break; } } @@ -161,7 +178,7 @@ void cIncrementalRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_B if ((Block != E_BLOCK_REDSTONE_REPEATER_ON) && (Block != E_BLOCK_REDSTONE_REPEATER_OFF)) { - &(*RepeatersDelayList).erase(itr); + RepeatersDelayList->erase(itr); break; } } @@ -313,10 +330,12 @@ void cIncrementalRedstoneSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_Blo { // On a chunk boundary, alert all four sides (i.e. at least one neighbouring chunk) AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk); - AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 1, a_BlockZ)); - AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 1, a_BlockZ)); - AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ - 1)); - AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ + 1)); + // Pass the original coordinates, because when adding things to our simulator lists, we get the chunk that they are in, and therefore any updates need to preseve their position + // RedstoneAddBlock to pass both the neighbouring chunk and the chunk which the coordiantes are in + RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 1, a_BlockZ), a_Chunk); + RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 1, a_BlockZ), a_Chunk); + RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ - 1), a_Chunk); + RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ + 1), a_Chunk); return; } diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index aea668996..e6bc28621 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -78,7 +78,8 @@ private: SimulatedPlayerToggleableList * m_SimulatedPlayerToggleableBlocks; RepeatersDelayList * m_RepeatersDelayList; - virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override; + virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override { RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk); } + void RedstoneAddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk, cChunk * a_OtherChunk = NULL); cChunk * m_Chunk; // We want a_MyState for devices needing a full FastSetBlock (as opposed to meta) because with our simulation model, we cannot keep setting the block if it is already set correctly -- cgit v1.2.3 From d273cc414241e11d56d336535501955d413cec89 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 15 Feb 2014 20:22:51 +0000 Subject: Added a 'default:' for SimChunk()'s switch --- src/Simulator/IncrementalRedstoneSimulator.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 4e165bd36..4f592d253 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -311,6 +311,7 @@ void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int HandlePressurePlate(a_X, dataitr->y, a_Z, dataitr->Data); break; } + default: LOGD("Unhandled block (!) or unimplemented redstone block: %s", ItemToString(dataitr->Data).c_str()); break; } ++dataitr; } -- cgit v1.2.3 From 0f1f7583aeea65335b2ee051585a857b1142a927 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 15 Feb 2014 23:16:44 +0100 Subject: Implemented cCompositeChat. This allows plugins to send composite chat messages, containing URLs, commands to run and cmdline suggestions. Fixes #678. --- src/Bindings/AllToLua.pkg | 1 + src/ClientHandle.cpp | 12 ++- src/ClientHandle.h | 4 +- src/CompositeChat.cpp | 206 ++++++++++++++++++++++++++++++++++++ src/CompositeChat.h | 172 ++++++++++++++++++++++++++++++ src/Defines.h | 9 +- src/Entities/Player.h | 1 + src/Protocol/Protocol.h | 2 + src/Protocol/Protocol125.cpp | 38 +++++++ src/Protocol/Protocol125.h | 1 + src/Protocol/Protocol17x.cpp | 153 ++++++++++++++++++++++++++ src/Protocol/Protocol17x.h | 38 ++++--- src/Protocol/ProtocolRecognizer.cpp | 10 ++ src/Protocol/ProtocolRecognizer.h | 1 + src/Root.cpp | 14 ++- src/Root.h | 6 +- src/World.cpp | 20 +++- src/World.h | 4 +- 18 files changed, 671 insertions(+), 21 deletions(-) create mode 100644 src/CompositeChat.cpp create mode 100644 src/CompositeChat.h diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index f65aed9bb..6c295102f 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -70,6 +70,7 @@ $cfile "../Generating/ChunkDesc.h" $cfile "../CraftingRecipes.h" $cfile "../UI/Window.h" $cfile "../Mobs/Monster.h" +$cfile "../CompositeChat.h" diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 1b3ebc3d4..f8a707324 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -31,6 +31,7 @@ #include "MersenneTwister.h" #include "Protocol/ProtocolRecognizer.h" +#include "CompositeChat.h" @@ -1729,7 +1730,7 @@ void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlock -void cClientHandle::SendChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const AString & a_AdditionalData) +void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData) { bool ShouldAppendChatPrefixes = true; @@ -1840,6 +1841,15 @@ void cClientHandle::SendChat(const AString & a_Message, ChatPrefixCodes a_ChatPr +void cClientHandle::SendChat(const cCompositeChat & a_Message) +{ + m_Protocol->SendChat(a_Message); +} + + + + + void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { ASSERT(m_Player != NULL); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index d9a86d983..034fe07c2 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -34,6 +34,7 @@ class cWindow; class cFallingBlock; class cItemHandler; class cWorld; +class cCompositeChat; @@ -89,7 +90,8 @@ public: void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage); void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // tolua_export void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes); - void SendChat (const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const AString & a_AdditionalData = ""); + void SendChat (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = ""); + void SendChat (const cCompositeChat & a_Message); void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer); void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player); void SendDestroyEntity (const cEntity & a_Entity); diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp new file mode 100644 index 000000000..16ae58f56 --- /dev/null +++ b/src/CompositeChat.cpp @@ -0,0 +1,206 @@ + +// CompositeChat.cpp + +// Implements the cCompositeChat class used to wrap a chat message with multiple parts (text, url, cmd) + +#include "Globals.h" +#include "CompositeChat.h" + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCompositeChat: + +cCompositeChat::cCompositeChat(void) : + m_MessageType(mtCustom) +{ +} + + + + + +cCompositeChat::cCompositeChat(const AString & a_ParseText) : + m_MessageType(mtCustom) +{ + ParseText(a_ParseText); +} + + + + + +cCompositeChat::~cCompositeChat() +{ + Clear(); +} + + + + + +void cCompositeChat::Clear(void) +{ + for (cParts::iterator itr = m_Parts.begin(), end = m_Parts.end(); itr != end; ++itr) + { + delete *itr; + } // for itr - m_Parts[] + m_Parts.clear(); +} + + + + + +void cCompositeChat::AddTextPart(const AString & a_Message, const AString & a_Style) +{ + m_Parts.push_back(new cTextPart(a_Message, a_Style)); +} + + + + + +void cCompositeChat::AddClientTranslatedPart(const AString & a_TranslationID, const AStringVector & a_Parameters, const AString & a_Style) +{ + m_Parts.push_back(new cClientTranslatedPart(a_TranslationID, a_Parameters, a_Style)); +} + + + + + +void cCompositeChat::AddUrlPart(const AString & a_Text, const AString & a_Url, const AString & a_Style) +{ + m_Parts.push_back(new cUrlPart(a_Text, a_Url, a_Style)); +} + + + + + +void cCompositeChat::AddRunCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style) +{ + m_Parts.push_back(new cRunCommandPart(a_Text, a_Command, a_Style)); +} + + + + + +void cCompositeChat::AddSuggestCommandPart(const AString & a_Text, const AString & a_SuggestedCommand, const AString & a_Style) +{ + m_Parts.push_back(new cSuggestCommandPart(a_Text, a_SuggestedCommand, a_Style)); +} + + + + + +void cCompositeChat::ParseText(const AString & a_ParseText) +{ + // TODO +} + + + + + +void cCompositeChat::SetMessageType(eMessageType a_MessageType) +{ + m_MessageType = a_MessageType; +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCompositeChat::cBasePart: + +cCompositeChat::cBasePart::cBasePart(cCompositeChat::ePartType a_PartType, const AString & a_Text, const AString & a_Style) : + m_PartType(a_PartType), + m_Text(a_Text), + m_Style(a_Style) +{ +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCompositeChat::cTextPart: + +cCompositeChat::cTextPart::cTextPart(const AString & a_Text, const AString &a_Style) : + super(ptText, a_Text, a_Style) +{ +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCompositeChat::cClientTranslatedPart: + +cCompositeChat::cClientTranslatedPart::cClientTranslatedPart(const AString & a_TranslationID, const AStringVector & a_Parameters, const AString & a_Style) : + super(ptClientTranslated, a_TranslationID, a_Style), + m_Parameters(a_Parameters) +{ +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCompositeChat::cUrlPart: + +cCompositeChat::cUrlPart::cUrlPart(const AString & a_Text, const AString & a_Url, const AString & a_Style) : + super(ptUrl, a_Text, a_Style), + m_Url(a_Url) +{ +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCompositeChat::cCommandPart: + +cCompositeChat::cCommandPart::cCommandPart(ePartType a_PartType, const AString & a_Text, const AString & a_Command, const AString & a_Style) : + super(a_PartType, a_Text, a_Style), + m_Command(a_Command) +{ +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCompositeChat::cRunCommandPart: + +cCompositeChat::cRunCommandPart::cRunCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style) : + super(ptRunCommand, a_Text, a_Command, a_Style) +{ +} + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCompositeChat::cSuggestCommandPart: + +cCompositeChat::cSuggestCommandPart::cSuggestCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style) : + super(ptSuggestCommand, a_Text, a_Command, a_Style) +{ +} + + + + diff --git a/src/CompositeChat.h b/src/CompositeChat.h new file mode 100644 index 000000000..e220f6345 --- /dev/null +++ b/src/CompositeChat.h @@ -0,0 +1,172 @@ + +// CompositeChat.h + +// Declares the cCompositeChat class used to wrap a chat message with multiple parts (text, url, cmd) + +#include "Defines.h" + + + + + +// tolua_begin +/** Container for a single chat message composed of multiple functional parts. +Each part corresponds roughly to the behavior supported by the client messaging: + - plain text, optionaly colorized / styled + - clickable URLs + - clickable commands (run) + - clickable commands (suggest) +Each part has a text assigned to it that can be styled. The style is specified using a string, +each character / character combination in the string specifies the style to use: + - b = bold + - i = italic + - u = underlined + - s = strikethrough + - o = obfuscated + - @X = color X (X is 0 - 9 or a - f, same as dye meta +If the protocol version doesn't support all the features, it degrades gracefully. +*/ +class cCompositeChat +{ +public: + // tolua_end + + enum ePartType + { + ptText, + ptClientTranslated, + ptUrl, + ptRunCommand, + ptSuggestCommand, + } ; + + class cBasePart + { + public: + ePartType m_PartType; + AString m_Text; + AString m_Style; + + cBasePart(ePartType a_PartType, const AString & a_Text, const AString & a_Style = ""); + } ; + + class cTextPart : + public cBasePart + { + typedef cBasePart super; + public: + cTextPart(const AString & a_Text, const AString & a_Style = ""); + } ; + + class cClientTranslatedPart : + public cBasePart + { + typedef cBasePart super; + public: + AStringVector m_Parameters; + + cClientTranslatedPart(const AString & a_TranslationID, const AStringVector & a_Parameters, const AString & a_Style = ""); + } ; + + class cUrlPart : + public cBasePart + { + typedef cBasePart super; + public: + AString m_Url; + + cUrlPart(const AString & a_Text, const AString & a_Url, const AString & a_Style = ""); + } ; + + class cCommandPart : + public cBasePart + { + typedef cBasePart super; + public: + AString m_Command; + + cCommandPart(ePartType a_PartType, const AString & a_Text, const AString & a_Command, const AString & a_Style = ""); + } ; + + class cRunCommandPart : + public cCommandPart + { + typedef cCommandPart super; + public: + cRunCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style = ""); + } ; + + class cSuggestCommandPart : + public cCommandPart + { + typedef cCommandPart super; + public: + cSuggestCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style = ""); + } ; + + typedef std::vector cParts; + + // tolua_begin + + /** Creates a new empty chat message */ + cCompositeChat(void); + + /** Creates a new chat message and parses the text into parts. + Recognizes "http:" and "https:" links and @color-codes. + Uses ParseText() for the actual parsing. */ + cCompositeChat(const AString & a_ParseText); + + ~cCompositeChat(); + + /** Removes all parts from the object. */ + void Clear(void); + + /** Adds a plain text part, with optional style. + The default style is plain white text. */ + void AddTextPart(const AString & a_Message, const AString & a_Style = ""); + + // tolua_end + + /** Adds a part that is translated client-side, with the formatting parameters and optional style. + Exported in ManualBindings due to AStringVector usage - Lua uses an array-table of strings. */ + void AddClientTranslatedPart(const AString & a_TranslationID, const AStringVector & a_Parameters, const AString & a_Style = ""); + + // tolua_begin + + /** Adds a part that opens an URL when clicked. + The default style is underlined light blue text. */ + void AddUrlPart(const AString & a_Text, const AString & a_Url, const AString & a_Style = "u@c"); + + /** Adds a part that runs a command when clicked. + The default style is underlined light green text. */ + void AddRunCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style = "u@a"); + + /** Adds a part that suggests a command (enters it into the chat message area, but doesn't send) when clicked. + The default style is underlined yellow text. */ + void AddSuggestCommandPart(const AString & a_Text, const AString & a_SuggestedCommand, const AString & a_Style = "u@b"); + + /** Parses text into various parts, adds those. + Recognizes "http:" and "https:" URLs and @color-codes. */ + void ParseText(const AString & a_ParseText); + + /** Sets the message type, which is indicated by prefixes added to the message when serializing. */ + void SetMessageType(eMessageType a_MessageType); + + /** Returns the message type set previously by SetMessageType(). */ + eMessageType GetMessageType(void) const { return m_MessageType; } + + // tolua_end + + const cParts & GetParts(void) const { return m_Parts; } + +protected: + /** All the parts that */ + cParts m_Parts; + + /** The message type, as indicated by prefixes. */ + eMessageType m_MessageType; +} ; // tolua_export + + + + diff --git a/src/Defines.h b/src/Defines.h index 290f862ef..f33d1ae56 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -441,7 +441,10 @@ inline float GetSpecialSignf( float a_Val ) -enum ChatPrefixCodes + +// tolua_begin + +enum eMessageType { // http://forum.mc-server.org/showthread.php?tid=1212 // MessageType... @@ -458,7 +461,9 @@ enum ChatPrefixCodes mtLeave, // A player has left the server }; -// tolua_begin + + + /** Normalizes an angle in degrees to the [-180, +180) range: */ inline double NormalizeAngleDegrees(const double a_Degrees) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 7db9544cb..53e4b56db 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -203,6 +203,7 @@ public: void SendMessageWarning (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtWarning); } void SendMessageFatal (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtFailure); } void SendMessagePrivateMsg(const AString & a_Message, const AString & a_Sender) { m_ClientHandle->SendChat(a_Message, mtPrivateMessage, a_Sender); } + void SendMessage (const cCompositeChat & a_Message) { m_ClientHandle->SendChat(a_Message); } const AString & GetName(void) const { return m_PlayerName; } void SetName(const AString & a_Name) { m_PlayerName = a_Name; } diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 791082537..f5b9fd403 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -28,6 +28,7 @@ class cWorld; class cMonster; class cChunkDataSerializer; class cFallingBlock; +class cCompositeChat; @@ -58,6 +59,7 @@ public: virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) = 0; virtual void SendChat (const AString & a_Message) = 0; + virtual void SendChat (const cCompositeChat & a_Message) = 0; virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) = 0; virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) = 0; virtual void SendDestroyEntity (const cEntity & a_Entity) = 0; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 73d21161c..7020699d1 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -32,6 +32,8 @@ Documentation: #include "../Mobs/IncludeAllMonsters.h" +#include "../CompositeChat.h" + @@ -233,6 +235,42 @@ void cProtocol125::SendChat(const AString & a_Message) +void cProtocol125::SendChat(const cCompositeChat & a_Message) +{ + // This version doesn't support composite messages, just extract each part's text and use it: + AString Msg; + const cCompositeChat::cParts & Parts = a_Message.GetParts(); + for (cCompositeChat::cParts::const_iterator itr = Parts.begin(), end = Parts.end(); itr != end; ++itr) + { + switch ((*itr)->m_PartType) + { + case cCompositeChat::ptText: + case cCompositeChat::ptClientTranslated: + case cCompositeChat::ptRunCommand: + case cCompositeChat::ptSuggestCommand: + { + Msg.append((*itr)->m_Text); + break; + } + case cCompositeChat::ptUrl: + { + Msg.append(((cCompositeChat::cUrlPart *)(*itr))->m_Url); + break; + } + } // switch (PartType) + } // for itr - Parts[] + + // Send the message: + cCSLock Lock(m_CSPacket); + WriteByte (PACKET_CHAT); + WriteString(Msg); + Flush(); +} + + + + + void cProtocol125::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { cCSLock Lock(m_CSPacket); diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index cd15ab518..1a3209333 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -33,6 +33,7 @@ public: virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override; virtual void SendChat (const AString & a_Message) override; + virtual void SendChat (const cCompositeChat & a_Message) override; virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override; virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) override; virtual void SendDestroyEntity (const cEntity & a_Entity) override; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 7eaf106cf..5aa18300c 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -8,6 +8,7 @@ Implements the 1.7.x protocol classes: */ #include "Globals.h" +#include "json/json.h" #include "Protocol17x.h" #include "ChunkDataSerializer.h" #include "../ClientHandle.h" @@ -25,6 +26,7 @@ Implements the 1.7.x protocol classes: #include "../Mobs/IncludeAllMonsters.h" #include "../UI/Window.h" #include "../BlockEntities/CommandBlockEntity.h" +#include "../CompositeChat.h" @@ -200,6 +202,78 @@ void cProtocol172::SendChat(const AString & a_Message) +void cProtocol172::SendChat(const cCompositeChat & a_Message) +{ + // Compose the complete Json string to send: + Json::Value msg; + msg["text"] = ""; // The client crashes without this + const cCompositeChat::cParts & Parts = a_Message.GetParts(); + for (cCompositeChat::cParts::const_iterator itr = Parts.begin(), end = Parts.end(); itr != end; ++itr) + { + Json::Value Part; + switch ((*itr)->m_PartType) + { + case cCompositeChat::ptText: + { + Part["text"] = (*itr)->m_Text; + AddChatPartStyle(Part, (*itr)->m_Style); + break; + } + + case cCompositeChat::ptClientTranslated: + { + const cCompositeChat::cClientTranslatedPart & p = (const cCompositeChat::cClientTranslatedPart &)**itr; + Part["translate"] = p.m_Text; + Json::Value With; + for (AStringVector::const_iterator itrW = p.m_Parameters.begin(), endW = p.m_Parameters.end(); itrW != endW; ++itr) + { + With.append(*itrW); + } + if (!p.m_Parameters.empty()) + { + Part["with"] = With; + } + AddChatPartStyle(Part, p.m_Style); + break; + } + + case cCompositeChat::ptUrl: + { + const cCompositeChat::cUrlPart & p = (const cCompositeChat::cUrlPart &)**itr; + Part["text"] = p.m_Text; + Json::Value Url; + Url["action"] = "open_url"; + Url["value"] = p.m_Url; + Part["clickEvent"] = Url; + AddChatPartStyle(Part, p.m_Style); + break; + } + + case cCompositeChat::ptSuggestCommand: + case cCompositeChat::ptRunCommand: + { + const cCompositeChat::cCommandPart & p = (const cCompositeChat::cCommandPart &)**itr; + Part["text"] = p.m_Text; + Json::Value Cmd; + Cmd["action"] = (p.m_PartType == cCompositeChat::ptRunCommand) ? "run_command" : "suggest_command"; + Cmd["value"] = p.m_Command; + Part["clickEvent"] = Cmd; + AddChatPartStyle(Part, p.m_Style); + break; + } + } + msg["extra"].append(Part); + } // for itr - Parts[] + + // Send the message to the client: + cPacketizer Pkt(*this, 0x02); + Pkt.WriteString(msg.toStyledString()); +} + + + + + void cProtocol172::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { // Serialize first, before creating the Packetizer (the packetizer locks a CS) @@ -1979,6 +2053,85 @@ void cProtocol172::StartEncryption(const Byte * a_Key) +void cProtocol172::AddChatPartStyle(Json::Value & a_Value, const AString & a_PartStyle) +{ + size_t len = a_PartStyle.length(); + for (size_t i = 0; i < len; i++) + { + switch (a_PartStyle[i]) + { + case 'b': + { + // bold + a_Value["bold"] = Json::Value(true); + break; + } + + case 'i': + { + // italic + a_Value["italic"] = Json::Value(true); + break; + } + + case 'u': + { + // Underlined + a_Value["underlined"] = Json::Value(true); + break; + } + + case 's': + { + // strikethrough + a_Value["strikethrough"] = Json::Value(true); + break; + } + + case 'o': + { + // obfuscated + a_Value["obfuscated"] = Json::Value(true); + break; + } + + case '@': + { + // Color, specified by the next char: + i++; + if (i >= len) + { + // String too short, didn't contain a color + break; + } + switch (a_PartStyle[i]) + { + case '0': a_Value["color"] = Json::Value("black"); break; + case '1': a_Value["color"] = Json::Value("dark_blue"); break; + case '2': a_Value["color"] = Json::Value("dark_green"); break; + case '3': a_Value["color"] = Json::Value("dark_aqua"); break; + case '4': a_Value["color"] = Json::Value("dark_red"); break; + case '5': a_Value["color"] = Json::Value("dark_purple"); break; + case '6': a_Value["color"] = Json::Value("gold"); break; + case '7': a_Value["color"] = Json::Value("gray"); break; + case '8': a_Value["color"] = Json::Value("dark_gray"); break; + case '9': a_Value["color"] = Json::Value("blue"); break; + case 'a': a_Value["color"] = Json::Value("green"); break; + case 'b': a_Value["color"] = Json::Value("aqua"); break; + case 'c': a_Value["color"] = Json::Value("red"); break; + case 'd': a_Value["color"] = Json::Value("light_purple"); break; + case 'e': a_Value["color"] = Json::Value("yellow"); break; + case 'f': a_Value["color"] = Json::Value("white"); break; + } // switch (color) + } // case '@' + } // switch (Style[i]) + } // for i - a_PartStyle[] +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cProtocol172::cPacketizer: diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 6a75e41c8..d19be0f05 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -36,6 +36,16 @@ Declares the 1.7.x protocol classes: +// fwd: +namespace Json +{ + class Value; +} + + + + + class cProtocol172 : public cProtocol { @@ -45,16 +55,17 @@ public: cProtocol172(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); - /// Called when client sends some data: + /** Called when client sends some data: */ virtual void DataReceived(const char * a_Data, int a_Size) override; - /// Sending stuff to clients (alphabetically sorted): + /** Sending stuff to clients (alphabetically sorted): */ virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override; virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override; virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override; virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override; virtual void SendChat (const AString & a_Message) override; + virtual void SendChat (const cCompositeChat & a_Message) override; virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override; virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) override; virtual void SendDestroyEntity (const cEntity & a_Entity) override; @@ -117,7 +128,7 @@ public: protected: - /// Composes individual packets in the protocol's m_OutPacketBuffer; sends them upon being destructed + /** Composes individual packets in the protocol's m_OutPacketBuffer; sends them upon being destructed */ class cPacketizer { public: @@ -206,16 +217,16 @@ protected: AString m_AuthServerID; - /// State of the protocol. 1 = status, 2 = login, 3 = game + /** State of the protocol. 1 = status, 2 = login, 3 = game */ UInt32 m_State; - /// Buffer for the received data + /** Buffer for the received data */ cByteBuffer m_ReceivedData; - /// Buffer for composing the outgoing packets, through cPacketizer + /** Buffer for composing the outgoing packets, through cPacketizer */ cByteBuffer m_OutPacketBuffer; - /// Buffer for composing packet length (so that each cPacketizer instance doesn't allocate a new cPacketBuffer) + /** Buffer for composing packet length (so that each cPacketizer instance doesn't allocate a new cPacketBuffer) */ cByteBuffer m_OutPacketLenBuffer; bool m_IsEncrypted; @@ -227,7 +238,7 @@ protected: cFile m_CommLogFile; - /// Adds the received (unencrypted) data to m_ReceivedData, parses complete packets + /** Adds the received (unencrypted) data to m_ReceivedData, parses complete packets */ void AddReceivedData(const char * a_Data, int a_Size); /** Reads and handles the packet. The packet length and type have already been read. @@ -268,21 +279,24 @@ protected: void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer); - /// Writes an entire packet into the output stream. a_Packet is expected to start with the packet type; data length is prepended here. + /** Writes an entire packet into the output stream. a_Packet is expected to start with the packet type; data length is prepended here. */ void WritePacket(cByteBuffer & a_Packet); - /// Sends the data to the client, encrypting them if needed. + /** Sends the data to the client, encrypting them if needed. */ virtual void SendData(const char * a_Data, int a_Size) override; void SendCompass(const cWorld & a_World); - /// Reads an item out of the received data, sets a_Item to the values read. Returns false if not enough received data + /** Reads an item out of the received data, sets a_Item to the values read. Returns false if not enough received data */ bool ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item); - /// Parses item metadata as read by ReadItem(), into the item enchantments. + /** Parses item metadata as read by ReadItem(), into the item enchantments. */ void ParseItemMetadata(cItem & a_Item, const AString & a_Metadata); void StartEncryption(const Byte * a_Key); + + /** Adds the chat part's style (represented by the part's stylestring) into the Json object. */ + void AddChatPartStyle(Json::Value & a_Value, const AString & a_PartStyle); } ; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 32409c2aa..6e51ee9cd 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -159,6 +159,16 @@ void cProtocolRecognizer::SendChat(const AString & a_Message) +void cProtocolRecognizer::SendChat(const cCompositeChat & a_Message) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendChat(a_Message); +} + + + + + void cProtocolRecognizer::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { ASSERT(m_Protocol != NULL); diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index f58c66d10..800163be6 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -68,6 +68,7 @@ public: virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override; virtual void SendChat (const AString & a_Message) override; + virtual void SendChat (const cCompositeChat & a_Message) override; virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override; virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) override; virtual void SendDestroyEntity (const cEntity & a_Entity) override; diff --git a/src/Root.cpp b/src/Root.cpp index 749fbd288..415a26dd3 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -543,7 +543,7 @@ void cRoot::ReloadGroups(void) -void cRoot::LoopWorldsAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix) +void cRoot::LoopWorldsAndBroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix) { for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr) { @@ -555,6 +555,18 @@ void cRoot::LoopWorldsAndBroadcastChat(const AString & a_Message, ChatPrefixCode +void cRoot::BroadcastChat(const cCompositeChat & a_Message) +{ + for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr) + { + itr->second->BroadcastChat(a_Message); + } // for itr - m_WorldsByName[] +} + + + + + bool cRoot::ForEachPlayer(cPlayerListCallback & a_Callback) { for (WorldMap::iterator itr = m_WorldsByName.begin(), itr2 = itr; itr != m_WorldsByName.end(); itr = itr2) diff --git a/src/Root.h b/src/Root.h index 13e208b8d..a1a3ca6a2 100644 --- a/src/Root.h +++ b/src/Root.h @@ -20,7 +20,8 @@ class cPluginManager; class cServer; class cWorld; class cPlayer; -class cCommandOutputCallback ; +class cCommandOutputCallback; +class cCompositeChat; typedef cItemCallback cPlayerListCallback; typedef cItemCallback cWorldListCallback; @@ -108,7 +109,7 @@ public: /// Finds a player from a partial or complete player name and calls the callback - case-insensitive bool FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << - void LoopWorldsAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix); + void LoopWorldsAndBroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix); void BroadcastChatJoin (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtJoin); } void BroadcastChatLeave (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtLeave); } void BroadcastChatDeath (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtDeath); } @@ -122,6 +123,7 @@ public: void BroadcastChatSuccess(const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtSuccess); } void BroadcastChatWarning(const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtWarning); } void BroadcastChatFatal (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtFailure); } + void BroadcastChat (const cCompositeChat & a_Message); /// Returns the textual description of the protocol version: 49 -> "1.4.4". Provided specifically for Lua API static AString GetProtocolVersionTextFromInt(int a_ProtocolVersionNum); diff --git a/src/World.cpp b/src/World.cpp index cb07caa5d..d1a13794c 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1747,7 +1747,7 @@ void cWorld::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cons -void cWorld::LoopPlayersAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const cClientHandle * a_Exclude) +void cWorld::LoopPlayersAndBroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) @@ -1765,6 +1765,24 @@ void cWorld::LoopPlayersAndBroadcastChat(const AString & a_Message, ChatPrefixCo +void cWorld::BroadcastChat(const cCompositeChat & a_Message, const cClientHandle * a_Exclude) +{ + cCSLock Lock(m_CSPlayers); + for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) + { + cClientHandle * ch = (*itr)->GetClientHandle(); + if ((ch == a_Exclude) || (ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed()) + { + continue; + } + ch->SendChat(a_Message); + } +} + + + + + void cWorld::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude) { m_ChunkMap->BroadcastChunkData(a_ChunkX, a_ChunkZ, a_Serializer, a_Exclude); diff --git a/src/World.h b/src/World.h index ca1b7dcc5..2fbc51038 100644 --- a/src/World.h +++ b/src/World.h @@ -46,6 +46,7 @@ class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; class cMobCensus; +class cCompositeChat; typedef std::list< cPlayer * > cPlayerList; @@ -167,7 +168,7 @@ public: void BroadcastBlockBreakAnimation(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = NULL); void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); ///< If there is a block entity at the specified coods, sends it to all clients except a_Exclude - void LoopPlayersAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const cClientHandle * a_Exclude = NULL); + void LoopPlayersAndBroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix, const cClientHandle * a_Exclude = NULL); void BroadcastChatDeath (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtDeath, a_Exclude); } // tolua_begin @@ -177,6 +178,7 @@ public: void BroadcastChatSuccess(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtSuccess, a_Exclude); } void BroadcastChatWarning(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtWarning, a_Exclude); } void BroadcastChatFatal (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtFailure, a_Exclude); } + void BroadcastChat (const cCompositeChat & a_Message, const cClientHandle * a_Exclude = NULL); // tolua_end void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); -- cgit v1.2.3 From 3582c4bc60beb1f8a093c435131d9d93e337a659 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 15 Feb 2014 23:17:42 +0100 Subject: Debuggers: Added code to test cCompositeChat functionality. Ref.: #678 --- MCServer/Plugins/Debuggers/Debuggers.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 51b3a3a87..60e84c947 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -54,6 +54,7 @@ function Initialize(Plugin) PM:BindCommand("/ff", "debuggers", HandleFurnaceFuel, "- Shows how long the currently held item would burn in a furnace"); PM:BindCommand("/sched", "debuggers", HandleSched, "- Schedules a simple countdown using cWorld:ScheduleTask()"); PM:BindCommand("/cs", "debuggers", HandleChunkStay, "- Tests the ChunkStay Lua integration for the specified chunk coords"); + PM:BindCommand("/compo", "debuggers", HandleCompo, "- Tests the cCompositeChat bindings") Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers) Plugin:AddWebTab("StressTest", HandleRequest_StressTest) @@ -1195,3 +1196,25 @@ end + +function HandleCompo(a_Split, a_Player) + -- Send one composite message to self: + local msg = cCompositeChat() + msg:AddTextPart("Hello! ", "b@e") -- bold yellow + msg:AddUrlPart("MCServer", "http://mc-server.org") + msg:AddTextPart(" rules! ") + msg:AddRunCommandPart("Set morning", "/time set 0") + a_Player:SendMessage(msg) + + -- Broadcast another one to the world: + local msg2 = cCompositeChat() + msg2:AddSuggestCommandPart(a_Player:GetName(), "/tell " .. a_Player:GetName() .. " ") + msg2:AddTextPart(" knows how to use cCompositeChat!"); + a_Player:GetWorld():BroadcastChat(msg2) + + return true +end + + + + -- cgit v1.2.3 From 52cd9dfe9f7cfc7c229049d98993f13b6b8ddd5d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 15 Feb 2014 23:26:19 +0100 Subject: Removed the unnecessary LoopPlayersAndBroadcastChat() functions. --- src/Root.cpp | 4 ++-- src/Root.h | 20 +++++++++----------- src/World.cpp | 2 +- src/World.h | 16 +++++++--------- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/Root.cpp b/src/Root.cpp index 415a26dd3..206255916 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -543,11 +543,11 @@ void cRoot::ReloadGroups(void) -void cRoot::LoopWorldsAndBroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix) +void cRoot::BroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix) { for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr) { - itr->second->LoopPlayersAndBroadcastChat(a_Message, a_ChatPrefix); + itr->second->BroadcastChat(a_Message, NULL, a_ChatPrefix); } // for itr - m_WorldsByName[] } diff --git a/src/Root.h b/src/Root.h index a1a3ca6a2..4bbd7586f 100644 --- a/src/Root.h +++ b/src/Root.h @@ -109,20 +109,18 @@ public: /// Finds a player from a partial or complete player name and calls the callback - case-insensitive bool FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << - void LoopWorldsAndBroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix); - void BroadcastChatJoin (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtJoin); } - void BroadcastChatLeave (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtLeave); } - void BroadcastChatDeath (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtDeath); } - // tolua_begin /// Sends a chat message to all connected clients (in all worlds) - void BroadcastChat (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtCustom); } - void BroadcastChatInfo (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtInformation); } - void BroadcastChatFailure(const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtFailure); } - void BroadcastChatSuccess(const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtSuccess); } - void BroadcastChatWarning(const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtWarning); } - void BroadcastChatFatal (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtFailure); } + void BroadcastChat (const AString & a_Message, eMessageType a_ChatPrefix = mtCustom); + void BroadcastChatInfo (const AString & a_Message) { BroadcastChat(a_Message, mtInformation); } + void BroadcastChatFailure(const AString & a_Message) { BroadcastChat(a_Message, mtFailure); } + void BroadcastChatSuccess(const AString & a_Message) { BroadcastChat(a_Message, mtSuccess); } + void BroadcastChatWarning(const AString & a_Message) { BroadcastChat(a_Message, mtWarning); } + void BroadcastChatFatal (const AString & a_Message) { BroadcastChat(a_Message, mtFailure); } + void BroadcastChatJoin (const AString & a_Message) { BroadcastChat(a_Message, mtJoin); } + void BroadcastChatLeave (const AString & a_Message) { BroadcastChat(a_Message, mtLeave); } + void BroadcastChatDeath (const AString & a_Message) { BroadcastChat(a_Message, mtDeath); } void BroadcastChat (const cCompositeChat & a_Message); /// Returns the textual description of the protocol version: 49 -> "1.4.4". Provided specifically for Lua API diff --git a/src/World.cpp b/src/World.cpp index d1a13794c..d67ad36d1 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1747,7 +1747,7 @@ void cWorld::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cons -void cWorld::LoopPlayersAndBroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix, const cClientHandle * a_Exclude) +void cWorld::BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude, eMessageType a_ChatPrefix) { cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) diff --git a/src/World.h b/src/World.h index 2fbc51038..97358b88a 100644 --- a/src/World.h +++ b/src/World.h @@ -168,16 +168,14 @@ public: void BroadcastBlockBreakAnimation(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = NULL); void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); ///< If there is a block entity at the specified coods, sends it to all clients except a_Exclude - void LoopPlayersAndBroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix, const cClientHandle * a_Exclude = NULL); - void BroadcastChatDeath (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtDeath, a_Exclude); } - // tolua_begin - void BroadcastChat (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtCustom, a_Exclude); } - void BroadcastChatInfo (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtInformation, a_Exclude); } - void BroadcastChatFailure(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtFailure, a_Exclude); } - void BroadcastChatSuccess(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtSuccess, a_Exclude); } - void BroadcastChatWarning(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtWarning, a_Exclude); } - void BroadcastChatFatal (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtFailure, a_Exclude); } + void BroadcastChat (const AString & a_Message, const cClientHandle * a_Exclude = NULL, eMessageType a_ChatPrefix = mtCustom); + void BroadcastChatInfo (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(a_Message, a_Exclude, mtInformation); } + void BroadcastChatFailure(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(a_Message, a_Exclude, mtFailure); } + void BroadcastChatSuccess(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(a_Message, a_Exclude, mtSuccess); } + void BroadcastChatWarning(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(a_Message, a_Exclude, mtWarning); } + void BroadcastChatFatal (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(a_Message, a_Exclude, mtFailure); } + void BroadcastChatDeath (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(a_Message, a_Exclude, mtDeath); } void BroadcastChat (const cCompositeChat & a_Message, const cClientHandle * a_Exclude = NULL); // tolua_end -- cgit v1.2.3 From faa64563440ac8d331f09152214f66b575eb7b0f Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 15 Feb 2014 15:17:58 -0800 Subject: Added a seperate module for Setting flags --- CMakeLists.txt | 186 ++-------------------------------------- SetFlags.cmake | 208 +++++++++++++++++++++++++++++++++++++++++++++ lib/tolua++/CMakeLists.txt | 2 +- 3 files changed, 216 insertions(+), 180 deletions(-) create mode 100644 SetFlags.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 57b200a2a..a42d8c599 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,105 +3,10 @@ cmake_minimum_required (VERSION 2.6) # Without this, the MSVC variable isn't defined for MSVC builds ( http://www.cmake.org/pipermail/cmake/2011-November/047130.html ) enable_language(CXX C) -macro (add_flags_lnk FLAGS) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAGS}") - set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FLAGS}") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${FLAGS}") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${FLAGS}") - set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${FLAGS}") - set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${FLAGS}") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FLAGS}") - set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${FLAGS}") - set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${FLAGS}") -endmacro() - -macro(add_flags_cxx FLAGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAGS}") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAGS}") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${FLAGS}") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${FLAGS}") -endmacro() - -# Add the preprocessor macros used for distinguishing between debug and release builds (CMake does this automatically for MSVC): -if (NOT MSVC) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG") -endif() - -if(MSVC) - # Make build use multiple threads under MSVC: - add_flags_cxx("/MP") - - # Make release builds use link-time code generation: - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") - set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") - set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG") -elseif(APPLE) - #on os x clang adds pthread for us but we need to add it for gcc - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11") - else() - add_flags_cxx("-pthread") - endif() - -else() - # Let gcc / clang know that we're compiling a multi-threaded app: - add_flags_cxx("-pthread") - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11") - endif() - - # We use a signed char (fixes #640 on RasPi) - add_flags_cxx("-fsigned-char") -endif() - - -# Allow for a forced 32-bit build under 64-bit OS: -if (FORCE_32) - add_flags_cxx("-m32") - add_flags_lnk("-m32") -endif() - - -# Have the compiler generate code specifically targeted at the current machine on Linux -if(LINUX AND NOT CROSSCOMPILE) - add_flags_cxx("-march=native") -endif() - - -# Use static CRT in MSVC builds: -if (MSVC) - string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") -endif() - - -# Set lower warnings-level for the libraries: -if (MSVC) - # Remove /W3 from command line -- cannot just cancel it later with /w like in unix, MSVC produces a D9025 warning (option1 overriden by option2) - string(REPLACE "/W3" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/W3" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - string(REPLACE "/W3" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - string(REPLACE "/W3" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") -else() - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -w") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -w") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -w") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -w") -endif() - +include(SetFlags.cmake) +set_flags() +set_lib_flags() +enable_profile() # Under Windows, we need Lua as DLL; on *nix we need it linked statically: if (WIN32) @@ -109,18 +14,6 @@ if (WIN32) endif() -# On Unix we use two dynamic loading libraries dl and ltdl. -# Preference is for dl on unknown systems as it is specified in POSIX -# the dynamic loader is used by lua and sqllite. -if (UNIX) - if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") - set(DYNAMIC_LOADER ltdl) - else() - set(DYNAMIC_LOADER dl) - endif() -endif() - - # The Expat library is linked in statically, make the source files aware of that: add_definitions(-DXML_STATIC) @@ -129,64 +22,10 @@ if(${SELF_TEST}) add_definitions(-DSELF_TEST) endif() -# Declare the flags used for profiling builds: -if (MSVC) - set (CXX_PROFILING "") - set (LNK_PROFILING "/PROFILE") -else() - set (CXX_PROFILING "-pg") - set (LNK_PROFILING "-pg") -endif() -# Declare the profiling configurations: -SET(CMAKE_CXX_FLAGS_DEBUGPROFILE - "${CMAKE_CXX_FLAGS_DEBUG} ${PCXX_ROFILING}" - CACHE STRING "Flags used by the C++ compiler during profile builds." - FORCE ) -SET(CMAKE_C_FLAGS_DEBUGPROFILE - "${CMAKE_C_FLAGS_DEBUG} ${CXX_PROFILING}" - CACHE STRING "Flags used by the C compiler during profile builds." - FORCE ) -SET(CMAKE_EXE_LINKER_FLAGS_DEBUGPROFILE - "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${LNK_PROFILING}" - CACHE STRING "Flags used for linking binaries during profile builds." - FORCE ) -SET(CMAKE_SHARED_LINKER_FLAGS_DEBUGPROFILE - "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${LNK_PROFILING}" - CACHE STRING "Flags used by the shared libraries linker during profile builds." - FORCE ) -MARK_AS_ADVANCED( - CMAKE_CXX_FLAGS_DEBUGPROFILE - CMAKE_C_FLAGS_DEBUGPROFILE - CMAKE_EXE_LINKER_FLAGS_DEBUGPROFILE - CMAKE_SHARED_LINKER_FLAGS_DEBUGPROFILE ) - -SET(CMAKE_CXX_FLAGS_RELEASEPROFILE - "${CMAKE_CXX_FLAGS_RELEASE} ${CXX_PROFILING}" - CACHE STRING "Flags used by the C++ compiler during profile builds." - FORCE ) -SET(CMAKE_C_FLAGS_RELEASEPROFILE - "${CMAKE_C_FLAGS_RELEASE} ${CXX_PROFILING}" - CACHE STRING "Flags used by the C compiler during profile builds." - FORCE ) -SET(CMAKE_EXE_LINKER_FLAGS_RELEASEPROFILE - "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${LNK_PROFILING}" - CACHE STRING "Flags used for linking binaries during profile builds." - FORCE ) -SET(CMAKE_SHARED_LINKER_FLAGS_RELEASEPROFILE - "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${LNK_PROFILING}" - CACHE STRING "Flags used by the shared libraries linker during profile builds." - FORCE ) -MARK_AS_ADVANCED( - CMAKE_CXX_FLAGS_RELEASEPROFILE - CMAKE_C_FLAGS_RELEASEPROFILE - CMAKE_EXE_LINKER_FLAGS_RELEASEPROFILE - CMAKE_SHARED_LINKER_FLAGS_RELEASEPROFILE ) - - -# The configuration types need to be set after their respective c/cxx/linker flags and before the project directive -set(CMAKE_CONFIGURATION_TYPES "Debug;Release;DebugProfile;ReleaseProfile" CACHE STRING "" FORCE) + + project (MCServer) # Include all the libraries: @@ -205,18 +44,7 @@ add_subdirectory(lib/md5/) # (PolarSSL also has test and example programs in their CMakeLists.txt, we don't want those) add_subdirectory(lib/polarssl/ EXCLUDE_FROM_ALL) - -# Remove disabling the maximum warning level: -# clang does not like a command line that reads -Wall -Wextra -w -Wall -Wextra and does not output any warnings -# We do not do that for MSVC since MSVC produces an awful lot of warnings for its own STL headers; -# the important warnings are turned on using #pragma in Globals.h -if (NOT MSVC) - string(REPLACE "-w" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall") -endif() +set_exe_flags() if(${BUILD_TOOLS}) add_subdirectory(Tools/GeneratorPerformanceTest/) diff --git a/SetFlags.cmake b/SetFlags.cmake new file mode 100644 index 000000000..a2f13384a --- /dev/null +++ b/SetFlags.cmake @@ -0,0 +1,208 @@ + + +macro (add_flags_lnk FLAGS) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${FLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${FLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${FLAGS}") +endmacro() + +macro(add_flags_cxx FLAGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAGS}") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAGS}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${FLAGS}") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${FLAGS}") +endmacro() + + +macro(set_flags) + if(NOT DEFINED ${FLAGS_SET}) + set(FLAGS_SET 1) + + # Add the preprocessor macros used for distinguishing between debug and release builds (CMake does this automatically for MSVC): + if (NOT MSVC) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG") + endif() + + if(MSVC) + # Make build use multiple threads under MSVC: + add_flags_cxx("/MP") + + # Make release builds use link-time code generation: + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") + set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG") + elseif(APPLE) + #on os x clang adds pthread for us but we need to add it for gcc + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11") + else() + add_flags_cxx("-pthread") + endif() + + else() + # Let gcc / clang know that we're compiling a multi-threaded app: + add_flags_cxx("-pthread") + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11") + endif() + + # We use a signed char (fixes #640 on RasPi) + add_flags_cxx("-fsigned-char") + endif() + + + # Allow for a forced 32-bit build under 64-bit OS: + if (FORCE_32) + add_flags_cxx("-m32") + add_flags_lnk("-m32") + endif() + + + # Have the compiler generate code specifically targeted at the current machine on Linux + if(LINUX AND NOT CROSSCOMPILE) + add_flags_cxx("-march=native") + endif() + + + # Use static CRT in MSVC builds: + if (MSVC) + string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + endif() + + endif() +endmacro() + +macro(set_lib_flags) + if(NOT DEFINED ${LIB_FLAGS_SET}) + set(LIB_FLAGS_SET 1) + # Set lower warnings-level for the libraries: + if (MSVC) + # Remove /W3 from command line -- cannot just cancel it later with /w like in unix, MSVC produces a D9025 warning (option1 overriden by option2) + string(REPLACE "/W3" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "/W3" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REPLACE "/W3" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "/W3" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + else() + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -w") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -w") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -w") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -w") + endif() + + # On Unix we use two dynamic loading libraries dl and ltdl. + # Preference is for dl on unknown systems as it is specified in POSIX + # the dynamic loader is used by lua and sqllite. + if (UNIX) + if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + set(DYNAMIC_LOADER ltdl) + else() + set(DYNAMIC_LOADER dl) + endif() + endif() + + + endif() +endmacro() + +macro(enable_profile) + if(NOT DEFINED ${PROFILE_ENABLED}) + set(PROFILE_ENABLED 1) + + # Declare the flags used for profiling builds: + if (MSVC) + set (CXX_PROFILING "") + set (LNK_PROFILING "/PROFILE") + else() + set (CXX_PROFILING "-pg") + set (LNK_PROFILING "-pg") + endif() + + + # Declare the profiling configurations: + SET(CMAKE_CXX_FLAGS_DEBUGPROFILE + "${CMAKE_CXX_FLAGS_DEBUG} ${PCXX_ROFILING}" + CACHE STRING "Flags used by the C++ compiler during profile builds." + FORCE ) + SET(CMAKE_C_FLAGS_DEBUGPROFILE + "${CMAKE_C_FLAGS_DEBUG} ${CXX_PROFILING}" + CACHE STRING "Flags used by the C compiler during profile builds." + FORCE ) + SET(CMAKE_EXE_LINKER_FLAGS_DEBUGPROFILE + "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${LNK_PROFILING}" + CACHE STRING "Flags used for linking binaries during profile builds." + FORCE ) + SET(CMAKE_SHARED_LINKER_FLAGS_DEBUGPROFILE + "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${LNK_PROFILING}" + CACHE STRING "Flags used by the shared libraries linker during profile builds." + FORCE ) + MARK_AS_ADVANCED( + CMAKE_CXX_FLAGS_DEBUGPROFILE + CMAKE_C_FLAGS_DEBUGPROFILE + CMAKE_EXE_LINKER_FLAGS_DEBUGPROFILE + CMAKE_SHARED_LINKER_FLAGS_DEBUGPROFILE ) + + SET(CMAKE_CXX_FLAGS_RELEASEPROFILE + "${CMAKE_CXX_FLAGS_RELEASE} ${CXX_PROFILING}" + CACHE STRING "Flags used by the C++ compiler during profile builds." + FORCE ) + SET(CMAKE_C_FLAGS_RELEASEPROFILE + "${CMAKE_C_FLAGS_RELEASE} ${CXX_PROFILING}" + CACHE STRING "Flags used by the C compiler during profile builds." + FORCE ) + SET(CMAKE_EXE_LINKER_FLAGS_RELEASEPROFILE + "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${LNK_PROFILING}" + CACHE STRING "Flags used for linking binaries during profile builds." + FORCE ) + SET(CMAKE_SHARED_LINKER_FLAGS_RELEASEPROFILE + "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${LNK_PROFILING}" + CACHE STRING "Flags used by the shared libraries linker during profile builds." + FORCE ) + MARK_AS_ADVANCED( + CMAKE_CXX_FLAGS_RELEASEPROFILE + CMAKE_C_FLAGS_RELEASEPROFILE + CMAKE_EXE_LINKER_FLAGS_RELEASEPROFILE + CMAKE_SHARED_LINKER_FLAGS_RELEASEPROFILE ) + # The configuration types need to be set after their respective c/cxx/linker flags and before the project directive + set(CMAKE_CONFIGURATION_TYPES "Debug;Release;DebugProfile;ReleaseProfile" CACHE STRING "" FORCE) + endif() +endmacro() + +macro(set_exe_flags) + if(NOT DEFINED ${EXE_FLAGS_SET}) + set(EXE_FLAGS_SET 1) + + # Remove disabling the maximum warning level: + # clang does not like a command line that reads -Wall -Wextra -w -Wall -Wextra and does not output any warnings + # We do not do that for MSVC since MSVC produces an awful lot of warnings for its own STL headers; + # the important warnings are turned on using #pragma in Globals.h + if (NOT MSVC) + string(REPLACE "-w" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + add_flags_cxx("-Wall") + endif() + + + endif() +endmacro() diff --git a/lib/tolua++/CMakeLists.txt b/lib/tolua++/CMakeLists.txt index 239232c38..5ec8ee822 100644 --- a/lib/tolua++/CMakeLists.txt +++ b/lib/tolua++/CMakeLists.txt @@ -19,7 +19,7 @@ add_library(tolualib ${LIB_SOURCE}) #m is the standard math librarys if(UNIX) -target_link_libraries(tolua m) +target_link_libraries(tolua m ${DYNAMIC_LOADER}) endif() target_link_libraries(tolua lua tolualib) -- cgit v1.2.3 From 9ba0b6ecf220346017c831293ffb69d535382480 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 15 Feb 2014 15:24:34 -0800 Subject: rewrote MCADefrag CMakelist to use Setflags --- Tools/MCADefrag/CMakeLists.txt | 72 ++++++++++-------------------------------- 1 file changed, 16 insertions(+), 56 deletions(-) diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt index 7296b8ddc..f3256f275 100644 --- a/Tools/MCADefrag/CMakeLists.txt +++ b/Tools/MCADefrag/CMakeLists.txt @@ -3,60 +3,13 @@ cmake_minimum_required (VERSION 2.6) project (MCADefrag) +# Without this, the MSVC variable isn't defined for MSVC builds ( http://www.cmake.org/pipermail/cmake/2011-November/047130.html ) +enable_language(CXX C) - -macro(add_flags_cxx FLAGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAGS}") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAGS}") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${FLAGS}") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${FLAGS}") -endmacro() - - - - -# Add the preprocessor macros used for distinguishing between debug and release builds (CMake does this automatically for MSVC): -if (NOT MSVC) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG") -endif() - - - -if(MSVC) - # Make build use multiple threads under MSVC: - add_flags_cxx("/MP") - - # Make release builds use link-time code generation: - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") - set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") - set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG") -elseif(APPLE) - #on os x clang adds pthread for us but we need to add it for gcc - if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-pthread") - endif() -else() - # Let gcc / clang know that we're compiling a multi-threaded app: - add_flags_cxx("-pthread") -endif() - - - - -# Use static CRT in MSVC builds: -if (MSVC) - string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") -endif() +include(../../SetFlags.cmake) +set_flags() +set_lib_flags() +enable_profile() @@ -78,12 +31,16 @@ endfunction() # Include the libraries: +if(NOT DEFINED ${ZLIB}) file(GLOB ZLIB_SRC "../../lib/zlib/*.c") file(GLOB ZLIB_HDR "../../lib/zlib/*.h") flatten_files(ZLIB_SRC) flatten_files(ZLIB_HDR) source_group("ZLib" FILES ${ZLIB_SRC} ${ZLIB_HDR}) +set(ZLIB 1) +endif() +set_exe_flags() # Include the shared files: set(SHARED_SRC @@ -98,6 +55,10 @@ set(SHARED_HDR ../../src/Log.h ../../src/MCLogger.h ) +flatten_files(SHARED_SRC) +flatten_files(SHARED_HDR) +source_group("Shared" FILES ${SHARED_SRC} ${SHARED_HDR}) + set(SHARED_OSS_SRC ../../src/OSSupport/CriticalSection.cpp ../../src/OSSupport/File.cpp @@ -110,11 +71,10 @@ set(SHARED_OSS_HDR ../../src/OSSupport/IsThread.h ../../src/OSSupport/Timer.h ) -flatten_files(SHARED_SRC) -flatten_files(SHARED_HDR) + flatten_files(SHARED_OSS_SRC) flatten_files(SHARED_OSS_HDR) -source_group("Shared" FILES ${SHARED_SRC} ${SHARED_HDR}) + source_group("Shared\\OSSupport" FILES ${SHARED_OSS_SRC} ${SHARED_OSS_HDR}) -- cgit v1.2.3 From 42e9b21fb25426cd6f4e42c7cede4294e00e9e6b Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 15 Feb 2014 15:27:10 -0800 Subject: CHange MCADefrag CMakelist to use zlib CMakeList --- Tools/MCADefrag/CMakeLists.txt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt index f3256f275..174da4fab 100644 --- a/Tools/MCADefrag/CMakeLists.txt +++ b/Tools/MCADefrag/CMakeLists.txt @@ -19,7 +19,6 @@ include_directories("../../lib") include_directories("../../src") - function(flatten_files arg1) set(res "") foreach(f ${${arg1}}) @@ -32,12 +31,8 @@ endfunction() # Include the libraries: if(NOT DEFINED ${ZLIB}) -file(GLOB ZLIB_SRC "../../lib/zlib/*.c") -file(GLOB ZLIB_HDR "../../lib/zlib/*.h") -flatten_files(ZLIB_SRC) -flatten_files(ZLIB_HDR) -source_group("ZLib" FILES ${ZLIB_SRC} ${ZLIB_HDR}) -set(ZLIB 1) + add_subdirectory(../../lib/zlib lib/zlib) + set(ZLIB 1) endif() set_exe_flags() @@ -98,7 +93,7 @@ add_executable(MCADefrag ${SHARED_HDR} ${SHARED_OSS_SRC} ${SHARED_OSS_HDR} - ${ZLIB_SRC} - ${ZLIB_HDR} ) +target_link_libraries(MCADefrag zlib) + -- cgit v1.2.3 From d15d6acc5837b0f2aa6814b2d9c9a2e440a952e6 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 11 Feb 2014 15:34:18 +0100 Subject: Disable Hunger Death --- src/Entities/Player.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index d568e068d..6e3db5194 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1764,6 +1764,12 @@ void cPlayer::HandleFood(void) { // Ref.: http://www.minecraftwiki.net/wiki/Hunger + if (IsGameModeCreative()) + { + // Hunger is disabled for Creative + return; + } + // Remember the food level before processing, for later comparison int LastFoodLevel = m_FoodLevel; @@ -1781,7 +1787,7 @@ void cPlayer::HandleFood(void) Heal(1); m_FoodExhaustionLevel += 3; } - else if (m_FoodLevel <= 0) + else if (m_FoodLevel <= 0 && m_Health > 1) { // Damage from starving TakeDamage(dtStarving, NULL, 1, 1, 0); -- cgit v1.2.3 From 507a8a4b844f1c0a36bfc7063804ddca1012948d Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 14 Feb 2014 21:33:16 +0100 Subject: Set max. Players in the Tablist to 60 --- src/Protocol/Protocol17x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 5aa18300c..1dfa5ec90 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -550,7 +550,7 @@ void cProtocol172::SendLogin(const cPlayer & a_Player, const cWorld & a_World) Pkt.WriteByte((Byte)a_Player.GetEffectiveGameMode() | (cRoot::Get()->GetServer()->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 Pkt.WriteChar((char)a_World.GetDimension()); Pkt.WriteByte(2); // TODO: Difficulty (set to Normal) - Pkt.WriteByte(cRoot::Get()->GetServer()->GetMaxPlayers()); + Pkt.WriteByte(std::min(cRoot::Get()->GetServer()->GetMaxPlayers(), 60)); Pkt.WriteString("default"); // Level type - wtf? } -- cgit v1.2.3 From f3bd288f020a8f004179513c0e260ac0f2855767 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 14 Feb 2014 22:49:23 +0100 Subject: Add Exp Bottle Effects --- src/Entities/ExpOrb.cpp | 10 +++++++++- src/Entities/Player.cpp | 9 +++++++++ src/Entities/Player.h | 2 ++ src/Entities/ProjectileEntity.cpp | 3 +++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 04ee85823..8b0838d27 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -4,6 +4,8 @@ #include "Player.h" #include "../ClientHandle.h" +#include + cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) : cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98), @@ -51,6 +53,12 @@ void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk) { LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward); a_ClosestPlayer->DeltaExperience(m_Reward); + + srand (static_cast (time(0))); + float r1 = static_cast (rand()) / static_cast (RAND_MAX); // Random Float Value (Java: random.nextFloat()) + float r2 = static_cast (rand()) / static_cast (RAND_MAX); // Random Float Value (Java: random.nextFloat()) + a_ClosestPlayer->PlaySoundEffect("random.orb", 0.1F, 0.5F * ((r1 - r2) * 0.7F + 1.8F)); + Destroy(true); } a_Distance.Normalize(); @@ -61,4 +69,4 @@ void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk) BroadcastMovementUpdate(); } HandlePhysics(a_Dt, a_Chunk); -} \ No newline at end of file +} diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 6e3db5194..be26e4f6e 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1059,6 +1059,15 @@ void cPlayer::CloseWindowIfID(char a_WindowID, bool a_CanRefuse) +void cPlayer::PlaySoundEffect(const AString & a_SoundName, float a_Volume, float a_Pitch) +{ + m_ClientHandle->SendSoundEffect(a_SoundName, (int) (GetPosX() * 8.0), (int) (GetPosY() * 8.0), (int) (GetPosZ() * 8.0), a_Volume, a_Pitch); +} + + + + + void cPlayer::SetLastBlockActionTime() { if (m_World != NULL) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 53e4b56db..838f0301d 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -208,6 +208,8 @@ public: const AString & GetName(void) const { return m_PlayerName; } void SetName(const AString & a_Name) { m_PlayerName = a_Name; } + void PlaySoundEffect(const AString & a_SoundName, float a_Volume, float a_Pitch); + // tolua_end typedef std::list< cGroup* > GroupList; diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index a3fa9d557..718a04baf 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -12,6 +12,8 @@ #include "../ChunkMap.h" #include "../Chunk.h" +#include + @@ -680,6 +682,7 @@ super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { // Spawn an experience orb with a reward between 3 and 11. + m_World->BroadcastSoundParticleEffect(2002, (int) round(GetPosX()), (int) round(GetPosY()), (int) round(GetPosZ()), 0); m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); Destroy(); -- cgit v1.2.3 From 707916b404e8ba16b8f39b43cb9e91af9d4b37b4 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 15 Feb 2014 19:52:15 +0100 Subject: Replace random Float Generation and broadcast the Exp Pickup Sound --- src/Entities/ExpOrb.cpp | 9 +++------ src/Entities/ProjectileEntity.cpp | 4 +--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 8b0838d27..41b60cc3b 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -4,8 +4,6 @@ #include "Player.h" #include "../ClientHandle.h" -#include - cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) : cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98), @@ -54,10 +52,9 @@ void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk) LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward); a_ClosestPlayer->DeltaExperience(m_Reward); - srand (static_cast (time(0))); - float r1 = static_cast (rand()) / static_cast (RAND_MAX); // Random Float Value (Java: random.nextFloat()) - float r2 = static_cast (rand()) / static_cast (RAND_MAX); // Random Float Value (Java: random.nextFloat()) - a_ClosestPlayer->PlaySoundEffect("random.orb", 0.1F, 0.5F * ((r1 - r2) * 0.7F + 1.8F)); + float r1 = (float) (0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64); // Random Float Value + float r2 = (float) (0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64); // Random Float Value + m_World->BroadcastSoundEffect("random.orb", (int) (GetPosX() * 8.0F), (int) (GetPosY() * 8.0F), (int) (GetPosZ() * 8.0F), 0.1F, 0.5F * ((r1 - r2) * 0.7F + 1.8F)); Destroy(true); } diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 718a04baf..ef82c6e94 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -12,8 +12,6 @@ #include "../ChunkMap.h" #include "../Chunk.h" -#include - @@ -682,7 +680,7 @@ super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { // Spawn an experience orb with a reward between 3 and 11. - m_World->BroadcastSoundParticleEffect(2002, (int) round(GetPosX()), (int) round(GetPosY()), (int) round(GetPosZ()), 0); + m_World->BroadcastSoundParticleEffect(2002, POSX_TOINT, POSY_TOINT, POSZ_TOINT, 0); m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); Destroy(); -- cgit v1.2.3 From 55a6306e2bfa1b8ddf87ee2287fe1217904ac547 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 16 Feb 2014 00:45:14 +0000 Subject: Fixed a glaring bug with chunk cross-simulating * A chunk's redstone blocks list is no longer touched if AddBlock was being called with another chunk's coordinates * Fixed chunk boundary checks --- src/Simulator/IncrementalRedstoneSimulator.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 4f592d253..60dabaf84 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -183,6 +183,12 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, } } + if (a_OtherChunk != NULL) + { + // DO NOT touch our chunk's data structure if we are being called with coordinates from another chunk - this one caused me massive grief :P + return; + } + cRedstoneSimulatorChunkData * RedstoneSimulatorChunkData = a_Chunk->GetRedstoneSimulatorData(); for (cRedstoneSimulatorChunkData::iterator itr = RedstoneSimulatorChunkData->begin(); itr != RedstoneSimulatorChunkData->end(); ++itr) { @@ -323,20 +329,22 @@ void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int void cIncrementalRedstoneSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) { if ( - ((a_BlockX % cChunkDef::Width) >= cChunkDef::Width - 2) || - ((a_BlockX % cChunkDef::Width) <= cChunkDef::Width + 2) || - ((a_BlockZ % cChunkDef::Width) >= cChunkDef::Width - 2) || - ((a_BlockZ % cChunkDef::Width) <= cChunkDef::Width + 2) + ((a_BlockX % cChunkDef::Width) <= 1) || + ((a_BlockX % cChunkDef::Width) >= 14) || + ((a_BlockZ % cChunkDef::Width) <= 1) || + ((a_BlockZ % cChunkDef::Width) >= 14) ) // Are we on a chunk boundary? ± 2 because of LinkedPowered blocks { // On a chunk boundary, alert all four sides (i.e. at least one neighbouring chunk) AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk); + // Pass the original coordinates, because when adding things to our simulator lists, we get the chunk that they are in, and therefore any updates need to preseve their position - // RedstoneAddBlock to pass both the neighbouring chunk and the chunk which the coordiantes are in - RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 1, a_BlockZ), a_Chunk); - RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 1, a_BlockZ), a_Chunk); - RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ - 1), a_Chunk); - RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ + 1), a_Chunk); + // RedstoneAddBlock to pass both the neighbouring chunk and the chunk which the coordiantes are in and ± 2 in GetNeighbour() to accomodate for LinkedPowered blocks being 2 away from chunk boundaries + RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 2, a_BlockZ), a_Chunk); + RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 2, a_BlockZ), a_Chunk); + RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ - 2), a_Chunk); + RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ + 2), a_Chunk); + return; } -- cgit v1.2.3 From 8c34b2d9748311840a93f64494f56a5b1e81015f Mon Sep 17 00:00:00 2001 From: narroo Date: Sat, 15 Feb 2014 19:56:36 -0500 Subject: Addressed Issue #402. cIniFile can now process UTF-8 files that have a Byte Order Marker, BOM. --- lib/inifile/iniFile.cpp | 156 +++++++++++++++++++++++++++--------------------- lib/inifile/iniFile.h | 2 + 2 files changed, 91 insertions(+), 67 deletions(-) diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp index afa1c110d..7b0df3d68 100644 --- a/lib/inifile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp @@ -83,91 +83,97 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) } } - while (getline(f, line)) - { - // To be compatible with Win32, check for existence of '\r'. - // Win32 files have the '\r' and Unix files don't at the end of a line. - // Note that the '\r' will be written to INI files from - // Unix so that the created INI file can be read under Win32 - // without change. - size_t lineLength = line.length(); - if (lineLength == 0) - { - continue; - } - if (line[lineLength - 1] == '\r') - { - line = line.substr(0, lineLength - 1); - } + if (getline(f, line)) + { + // Removes UTF-8 Byte Order Markers (BOM) if, present. + RemoveBom(line); - if (line.length() == 0) + do { - continue; - } + // To be compatible with Win32, check for existence of '\r'. + // Win32 files have the '\r' and Unix files don't at the end of a line. + // Note that the '\r' will be written to INI files from + // Unix so that the created INI file can be read under Win32 + // without change. + size_t lineLength = line.length(); + if (lineLength == 0) + { + continue; + } + if (line[lineLength - 1] == '\r') + { + line = line.substr(0, lineLength - 1); + } - // Check that the user hasn't opened a binary file by checking the first - // character of each line! - if (!isprint(line[0])) - { - printf("%s: Binary-check failed on char %d\n", __FUNCTION__, line[0]); - f.close(); - return false; - } - if ((pLeft = line.find_first_of(";#[=")) == AString::npos) - { - continue; - } + if (line.length() == 0) + { + continue; + } - switch (line[pLeft]) - { + // Check that the user hasn't opened a binary file by checking the first + // character of each line! + if (!isprint(line[0])) + { + printf("%s: Binary-check failed on char %d\n", __FUNCTION__, line[0]); + f.close(); + return false; + } + if ((pLeft = line.find_first_of(";#[=")) == AString::npos) + { + continue; + } + + switch (line[pLeft]) + { case '[': { - if ( - ((pRight = line.find_last_of("]")) != AString::npos) && - (pRight > pLeft) - ) - { - keyname = line.substr(pLeft + 1, pRight - pLeft - 1); - AddKeyName(keyname); - } - break; + if ( + ((pRight = line.find_last_of("]")) != AString::npos) && + (pRight > pLeft) + ) + { + keyname = line.substr(pLeft + 1, pRight - pLeft - 1); + AddKeyName(keyname); + } + break; } case '=': { - valuename = line.substr(0, pLeft); - value = line.substr(pLeft + 1); - AddValue(keyname, valuename, value); - break; + valuename = line.substr(0, pLeft); + value = line.substr(pLeft + 1); + AddValue(keyname, valuename, value); + break; } case ';': case '#': { - if (names.size() == 0) - { - AddHeaderComment(line.substr(pLeft + 1)); - } - else - { - AddKeyComment(keyname, line.substr(pLeft + 1)); - } - break; + if (names.size() == 0) + { + AddHeaderComment(line.substr(pLeft + 1)); + } + else + { + AddKeyComment(keyname, line.substr(pLeft + 1)); + } + break; } - } // switch (line[pLeft]) - } // while (getline()) + } // switch (line[pLeft]) + } while (getline(f, line)); // do - f.close(); - if (names.size() == 0) - { - return false; - } - - if (IsFromExampleRedirect) - { - WriteFile(FILE_IO_PREFIX + a_FileName); + f.close(); + if (names.size() == 0) + { + return false; + } + + if (IsFromExampleRedirect) + { + WriteFile(FILE_IO_PREFIX + a_FileName); + } + return true; } - return true; } @@ -824,3 +830,19 @@ AString cIniFile::CheckCase(const AString & s) const + +void cIniFile::RemoveBom(AString & a_line) const +{ + // The BOM sequence for UTF-8 is 0xEF,0xBB,0xBF ( In Unicode Latin I:  ) + static char BOM[] = { 0xEF, 0xBB, 0xBF }; + + // The BOM sequence, if present, is always the first three characters of the input. + if (a_line.compare(0, 3, BOM) == 0) + { + a_line.erase(0, 3); + } +} + + + + diff --git a/lib/inifile/iniFile.h b/lib/inifile/iniFile.h index 40af618dc..0bf1d917e 100644 --- a/lib/inifile/iniFile.h +++ b/lib/inifile/iniFile.h @@ -51,6 +51,8 @@ private: /// If the object is case-insensitive, returns s as lowercase; otherwise returns s as-is AString CheckCase(const AString & s) const; + /// Removes the UTF-8 BOMs (Byte order makers), if present. + void RemoveBom(AString & a_line) const; public: enum errors { -- cgit v1.2.3 From 0f7d90b7d18a1ccc59b2e47184bf8de1a21ec5a6 Mon Sep 17 00:00:00 2001 From: Muhammad Wang Date: Sun, 16 Feb 2014 12:15:24 +0800 Subject: Fixed a minor error --- COMPILING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/COMPILING.md b/COMPILING.md index d3c896bdd..94220f9c6 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -69,7 +69,7 @@ Assuming you are in the MCServer folder created in the initial setup step, you n ``` mkdir Release cd Release -cmake . -DCMAKE_BUILD_TYPE=RELEASE .. && make +cmake .. -DCMAKE_BUILD_TYPE=RELEASE && make ``` The executable will be built in the `MCServer/MCServer` folder and will be named `MCServer`. @@ -81,7 +81,7 @@ Assuming you are in the MCServer folder created in the Getting the sources step, ``` mkdir Debug cd Debug -cmake . -DCMAKE_BUILD_TYPE=DEBUG && make` +cmake .. -DCMAKE_BUILD_TYPE=DEBUG && make ``` The executable will be built in the `MCServer/MCServer` folder and will be named `MCServer_debug`. -- cgit v1.2.3 From 2acf218700a6ae6d5cb441d1e4138b98519f6dfe Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 16 Feb 2014 03:37:31 -0800 Subject: Allow building MCADefrag at the same time as MCServer --- CMakeLists.txt | 13 ++- SetFlags.cmake | 191 +++++++++++++++++++---------------------- Tools/MCADefrag/CMakeLists.txt | 6 +- lib/zlib/CMakeLists.txt | 14 +-- 4 files changed, 105 insertions(+), 119 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a42d8c599..8c8daf915 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,15 @@ cmake_minimum_required (VERSION 2.6) # Without this, the MSVC variable isn't defined for MSVC builds ( http://www.cmake.org/pipermail/cmake/2011-November/047130.html ) enable_language(CXX C) +#THis has to be done before any flags have been set up. +if(${BUILD_TOOLS}) + add_subdirectory(Tools/MCADefrag/) +endif() + +if(${BUILD_UNSTABLE_TOOLS}) + add_subdirectory(Tools/GeneratorPerformanceTest/) +endif() + include(SetFlags.cmake) set_flags() set_lib_flags() @@ -46,9 +55,5 @@ add_subdirectory(lib/polarssl/ EXCLUDE_FROM_ALL) set_exe_flags() -if(${BUILD_TOOLS}) -add_subdirectory(Tools/GeneratorPerformanceTest/) -endif() - add_subdirectory (src) diff --git a/SetFlags.cmake b/SetFlags.cmake index a2f13384a..162560c90 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -23,9 +23,6 @@ endmacro() macro(set_flags) - if(NOT DEFINED ${FLAGS_SET}) - set(FLAGS_SET 1) - # Add the preprocessor macros used for distinguishing between debug and release builds (CMake does this automatically for MSVC): if (NOT MSVC) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") @@ -88,121 +85,105 @@ macro(set_flags) string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") endif() - - endif() endmacro() macro(set_lib_flags) - if(NOT DEFINED ${LIB_FLAGS_SET}) - set(LIB_FLAGS_SET 1) - # Set lower warnings-level for the libraries: - if (MSVC) - # Remove /W3 from command line -- cannot just cancel it later with /w like in unix, MSVC produces a D9025 warning (option1 overriden by option2) - string(REPLACE "/W3" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/W3" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - string(REPLACE "/W3" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - string(REPLACE "/W3" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - else() - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -w") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -w") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -w") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -w") - endif() + # Set lower warnings-level for the libraries: + if (MSVC) + # Remove /W3 from command line -- cannot just cancel it later with /w like in unix, MSVC produces a D9025 warning (option1 overriden by option2) + string(REPLACE "/W3" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "/W3" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REPLACE "/W3" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "/W3" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + else() + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -w") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -w") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -w") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -w") + endif() - # On Unix we use two dynamic loading libraries dl and ltdl. - # Preference is for dl on unknown systems as it is specified in POSIX - # the dynamic loader is used by lua and sqllite. - if (UNIX) - if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") - set(DYNAMIC_LOADER ltdl) - else() - set(DYNAMIC_LOADER dl) - endif() + # On Unix we use two dynamic loading libraries dl and ltdl. + # Preference is for dl on unknown systems as it is specified in POSIX + # the dynamic loader is used by lua and sqllite. + if (UNIX) + if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + set(DYNAMIC_LOADER ltdl) + else() + set(DYNAMIC_LOADER dl) endif() - - endif() endmacro() macro(enable_profile) - if(NOT DEFINED ${PROFILE_ENABLED}) - set(PROFILE_ENABLED 1) - - # Declare the flags used for profiling builds: - if (MSVC) - set (CXX_PROFILING "") - set (LNK_PROFILING "/PROFILE") - else() - set (CXX_PROFILING "-pg") - set (LNK_PROFILING "-pg") - endif() + # Declare the flags used for profiling builds: + if (MSVC) + set (CXX_PROFILING "") + set (LNK_PROFILING "/PROFILE") + else() + set (CXX_PROFILING "-pg") + set (LNK_PROFILING "-pg") + endif() - # Declare the profiling configurations: - SET(CMAKE_CXX_FLAGS_DEBUGPROFILE - "${CMAKE_CXX_FLAGS_DEBUG} ${PCXX_ROFILING}" - CACHE STRING "Flags used by the C++ compiler during profile builds." - FORCE ) - SET(CMAKE_C_FLAGS_DEBUGPROFILE - "${CMAKE_C_FLAGS_DEBUG} ${CXX_PROFILING}" - CACHE STRING "Flags used by the C compiler during profile builds." - FORCE ) - SET(CMAKE_EXE_LINKER_FLAGS_DEBUGPROFILE - "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${LNK_PROFILING}" - CACHE STRING "Flags used for linking binaries during profile builds." - FORCE ) - SET(CMAKE_SHARED_LINKER_FLAGS_DEBUGPROFILE - "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${LNK_PROFILING}" - CACHE STRING "Flags used by the shared libraries linker during profile builds." - FORCE ) - MARK_AS_ADVANCED( - CMAKE_CXX_FLAGS_DEBUGPROFILE - CMAKE_C_FLAGS_DEBUGPROFILE - CMAKE_EXE_LINKER_FLAGS_DEBUGPROFILE - CMAKE_SHARED_LINKER_FLAGS_DEBUGPROFILE ) - - SET(CMAKE_CXX_FLAGS_RELEASEPROFILE - "${CMAKE_CXX_FLAGS_RELEASE} ${CXX_PROFILING}" - CACHE STRING "Flags used by the C++ compiler during profile builds." - FORCE ) - SET(CMAKE_C_FLAGS_RELEASEPROFILE - "${CMAKE_C_FLAGS_RELEASE} ${CXX_PROFILING}" - CACHE STRING "Flags used by the C compiler during profile builds." - FORCE ) - SET(CMAKE_EXE_LINKER_FLAGS_RELEASEPROFILE - "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${LNK_PROFILING}" - CACHE STRING "Flags used for linking binaries during profile builds." - FORCE ) - SET(CMAKE_SHARED_LINKER_FLAGS_RELEASEPROFILE - "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${LNK_PROFILING}" - CACHE STRING "Flags used by the shared libraries linker during profile builds." - FORCE ) - MARK_AS_ADVANCED( - CMAKE_CXX_FLAGS_RELEASEPROFILE - CMAKE_C_FLAGS_RELEASEPROFILE - CMAKE_EXE_LINKER_FLAGS_RELEASEPROFILE - CMAKE_SHARED_LINKER_FLAGS_RELEASEPROFILE ) - # The configuration types need to be set after their respective c/cxx/linker flags and before the project directive - set(CMAKE_CONFIGURATION_TYPES "Debug;Release;DebugProfile;ReleaseProfile" CACHE STRING "" FORCE) - endif() + # Declare the profiling configurations: + SET(CMAKE_CXX_FLAGS_DEBUGPROFILE + "${CMAKE_CXX_FLAGS_DEBUG} ${PCXX_ROFILING}" + CACHE STRING "Flags used by the C++ compiler during profile builds." + FORCE ) + SET(CMAKE_C_FLAGS_DEBUGPROFILE + "${CMAKE_C_FLAGS_DEBUG} ${CXX_PROFILING}" + CACHE STRING "Flags used by the C compiler during profile builds." + FORCE ) + SET(CMAKE_EXE_LINKER_FLAGS_DEBUGPROFILE + "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${LNK_PROFILING}" + CACHE STRING "Flags used for linking binaries during profile builds." + FORCE ) + SET(CMAKE_SHARED_LINKER_FLAGS_DEBUGPROFILE + "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${LNK_PROFILING}" + CACHE STRING "Flags used by the shared libraries linker during profile builds." + FORCE ) + MARK_AS_ADVANCED( + CMAKE_CXX_FLAGS_DEBUGPROFILE + CMAKE_C_FLAGS_DEBUGPROFILE + CMAKE_EXE_LINKER_FLAGS_DEBUGPROFILE + CMAKE_SHARED_LINKER_FLAGS_DEBUGPROFILE ) + + SET(CMAKE_CXX_FLAGS_RELEASEPROFILE + "${CMAKE_CXX_FLAGS_RELEASE} ${CXX_PROFILING}" + CACHE STRING "Flags used by the C++ compiler during profile builds." + FORCE ) + SET(CMAKE_C_FLAGS_RELEASEPROFILE + "${CMAKE_C_FLAGS_RELEASE} ${CXX_PROFILING}" + CACHE STRING "Flags used by the C compiler during profile builds." + FORCE ) + SET(CMAKE_EXE_LINKER_FLAGS_RELEASEPROFILE + "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${LNK_PROFILING}" + CACHE STRING "Flags used for linking binaries during profile builds." + FORCE ) + SET(CMAKE_SHARED_LINKER_FLAGS_RELEASEPROFILE + "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${LNK_PROFILING}" + CACHE STRING "Flags used by the shared libraries linker during profile builds." + FORCE ) + MARK_AS_ADVANCED( + CMAKE_CXX_FLAGS_RELEASEPROFILE + CMAKE_C_FLAGS_RELEASEPROFILE + CMAKE_EXE_LINKER_FLAGS_RELEASEPROFILE + CMAKE_SHARED_LINKER_FLAGS_RELEASEPROFILE ) + # The configuration types need to be set after their respective c/cxx/linker flags and before the project directive + set(CMAKE_CONFIGURATION_TYPES "Debug;Release;DebugProfile;ReleaseProfile" CACHE STRING "" FORCE) endmacro() macro(set_exe_flags) - if(NOT DEFINED ${EXE_FLAGS_SET}) - set(EXE_FLAGS_SET 1) - - # Remove disabling the maximum warning level: - # clang does not like a command line that reads -Wall -Wextra -w -Wall -Wextra and does not output any warnings - # We do not do that for MSVC since MSVC produces an awful lot of warnings for its own STL headers; - # the important warnings are turned on using #pragma in Globals.h - if (NOT MSVC) - string(REPLACE "-w" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall") - endif() - - + # Remove disabling the maximum warning level: + # clang does not like a command line that reads -Wall -Wextra -w -Wall -Wextra and does not output any warnings + # We do not do that for MSVC since MSVC produces an awful lot of warnings for its own STL headers; + # the important warnings are turned on using #pragma in Globals.h + if (NOT MSVC) + string(REPLACE "-w" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + add_flags_cxx("-Wall") endif() + endmacro() diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt index 174da4fab..c11c8c772 100644 --- a/Tools/MCADefrag/CMakeLists.txt +++ b/Tools/MCADefrag/CMakeLists.txt @@ -30,10 +30,8 @@ endfunction() # Include the libraries: -if(NOT DEFINED ${ZLIB}) - add_subdirectory(../../lib/zlib lib/zlib) - set(ZLIB 1) -endif() + +add_subdirectory(../../lib/zlib lib/zlib) set_exe_flags() diff --git a/lib/zlib/CMakeLists.txt b/lib/zlib/CMakeLists.txt index b1b74031d..6c52578ee 100644 --- a/lib/zlib/CMakeLists.txt +++ b/lib/zlib/CMakeLists.txt @@ -8,12 +8,14 @@ file(GLOB SOURCE "*.c" ) -add_library(zlib ${SOURCE}) +if(NOT TARGET zlib) + add_library(zlib ${SOURCE}) -if (MSVC) - # Remove SCL warnings, we expect this library to have been tested safe - SET_TARGET_PROPERTIES( - zlib PROPERTIES COMPILE_FLAGS "-D_CRT_SECURE_NO_WARNINGS" - ) + if (MSVC) + # Remove SCL warnings, we expect this library to have been tested safe + SET_TARGET_PROPERTIES( + zlib PROPERTIES COMPILE_FLAGS "-D_CRT_SECURE_NO_WARNINGS" + ) + endif() endif() -- cgit v1.2.3 From 83f0438e21676a0b97850c9c974d3b1a57fc573c Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 16 Feb 2014 04:09:00 -0800 Subject: COnverted ProtoProxy to use library CMakeLists --- Tools/MCADefrag/CMakeLists.txt | 2 +- Tools/ProtoProxy/CMakeLists.txt | 21 ++++----------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt index c11c8c772..2a021049f 100644 --- a/Tools/MCADefrag/CMakeLists.txt +++ b/Tools/MCADefrag/CMakeLists.txt @@ -31,7 +31,7 @@ endfunction() # Include the libraries: -add_subdirectory(../../lib/zlib lib/zlib) +add_subdirectory(../../lib/zlib ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/lib/zlib) set_exe_flags() diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt index 9e233a688..30630b04b 100644 --- a/Tools/ProtoProxy/CMakeLists.txt +++ b/Tools/ProtoProxy/CMakeLists.txt @@ -77,19 +77,8 @@ function(flatten_files arg1) set(${arg1} "${res}" PARENT_SCOPE) endfunction() - -# Include the libraries: -file(GLOB POLARSSL_SRC "../../lib/polarssl/library/*.c") -file(GLOB POLARSSL_HDR "../../lib/polarssl/include/polarssl/*.h") -flatten_files(POLARSSL_SRC) -flatten_files(POLARSSL_HDR) -source_group("PolarSSL" FILES ${POLARSSL_SRC} ${POLARSSL_HDR}) - -file(GLOB ZLIB_SRC "../../lib/zlib/*.c") -file(GLOB ZLIB_HDR "../../lib/zlib/*.h") -flatten_files(ZLIB_SRC) -flatten_files(ZLIB_HDR) -source_group("ZLib" FILES ${ZLIB_SRC} ${ZLIB_HDR}) +include(../../lib/polarssl.cmake) +add_subdirectory(../../lib/zlib ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/lib/zlib) # Include the shared files: @@ -149,9 +138,7 @@ add_executable(ProtoProxy ${SHARED_HDR} ${SHARED_OSS_SRC} ${SHARED_OSS_HDR} - ${POLARSSL_SRC} - ${POLARSSL_HDR} - ${ZLIB_SRC} - ${ZLIB_HDR} ) +target_link_libraries(ProtoProxy zlib polarssl) + -- cgit v1.2.3 From 994904f6c585accf1fad67f68dde33ca445cc657 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 16 Feb 2014 04:15:12 -0800 Subject: Now uses setflags for flags --- Tools/ProtoProxy/CMakeLists.txt | 59 +++-------------------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt index 30630b04b..01f1e88ad 100644 --- a/Tools/ProtoProxy/CMakeLists.txt +++ b/Tools/ProtoProxy/CMakeLists.txt @@ -3,62 +3,10 @@ cmake_minimum_required (VERSION 2.6) project (ProtoProxy) +include(../../SetFlags.cmake) - -macro(add_flags_cxx FLAGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAGS}") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAGS}") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${FLAGS}") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${FLAGS}") -endmacro() - - - - -# Add the preprocessor macros used for distinguishing between debug and release builds (CMake does this automatically for MSVC): -if (NOT MSVC) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG") -endif() - - - -if(MSVC) - # Make build use multiple threads under MSVC: - add_flags_cxx("/MP") - - # Make release builds use link-time code generation: - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") - set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") - set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG") -elseif(APPLE) - #on os x clang adds pthread for us but we need to add it for gcc - if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-pthread") - endif() -else() - # Let gcc / clang know that we're compiling a multi-threaded app: - add_flags_cxx("-pthread") -endif() - - - - -# Use static CRT in MSVC builds: -if (MSVC) - string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") -endif() - - +set_flags() +set_lib_flags() # Set include paths to the used libraries: @@ -80,6 +28,7 @@ endfunction() include(../../lib/polarssl.cmake) add_subdirectory(../../lib/zlib ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/lib/zlib) +set_exe_flags() # Include the shared files: set(SHARED_SRC -- cgit v1.2.3 From 48d28a0f94ab168b7cb022107f6a62e3250043bc Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Feb 2014 13:26:07 +0100 Subject: Add Locale to ClientHandle --- src/ClientHandle.cpp | 1 + src/ClientHandle.h | 7 ++++++- src/Protocol/Protocol132.cpp | 2 +- src/Protocol/Protocol14x.cpp | 2 +- src/Protocol/Protocol17x.cpp | 2 ++ 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index f8a707324..b46bcfd47 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -95,6 +95,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_ShouldCheckDownloaded(false), m_NumExplosionsThisTick(0), m_UniqueID(0), + m_Locale("en_GB"), m_HasSentPlayerChunk(false) { m_Protocol = new cProtocolRecognizer(this); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 034fe07c2..5faa94004 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -155,6 +155,9 @@ public: void SetViewDistance(int a_ViewDistance); // tolua_export int GetViewDistance(void) const { return m_ViewDistance; } // tolua_export + + void SetLocale(AString & a_Locale) { m_Locale = a_Locale; } // tolua_export + AString GetLocale(void) const { return m_Locale; } // tolua_export int GetUniqueID() const { return m_UniqueID; } // tolua_export @@ -308,7 +311,9 @@ private: /// Set to true when the chunk where the player is is sent to the client. Used for spawning the player bool m_HasSentPlayerChunk; - + + /// Client Settings + AString m_Locale; /// Returns true if the rate block interactions is within a reasonable limit (bot protection) diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index 648e70151..1f9222a69 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -560,7 +560,7 @@ int cProtocol132::ParseLocaleViewDistance(void) HANDLE_PACKET_READ(ReadChar, char, ViewDistance); HANDLE_PACKET_READ(ReadChar, char, ChatFlags); HANDLE_PACKET_READ(ReadChar, char, ClientDifficulty); - // TODO: m_Client->HandleLocale(Locale); + m_Client->SetLocale(Locale); // TODO: m_Client->HandleViewDistance(ViewDistance); // TODO: m_Client->HandleChatFlags(ChatFlags); // Ignoring client difficulty diff --git a/src/Protocol/Protocol14x.cpp b/src/Protocol/Protocol14x.cpp index f82e6de45..232b2718e 100644 --- a/src/Protocol/Protocol14x.cpp +++ b/src/Protocol/Protocol14x.cpp @@ -85,7 +85,7 @@ int cProtocol142::ParseLocaleViewDistance(void) HANDLE_PACKET_READ(ReadChar, char, ChatFlags); HANDLE_PACKET_READ(ReadChar, char, ClientDifficulty); HANDLE_PACKET_READ(ReadChar, char, ShouldShowCape); // <-- new in 1.4.2 - // TODO: m_Client->HandleLocale(Locale); + m_Client->SetLocale(Locale); // TODO: m_Client->HandleViewDistance(ViewDistance); // TODO: m_Client->HandleChatFlags(ChatFlags); // Ignoring client difficulty diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 1dfa5ec90..f7d13774d 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1598,6 +1598,8 @@ void cProtocol172::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ChatColors); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Difficulty); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ShowCape); + + m_Client->SetLocale(Locale); // TODO: handle in m_Client } -- cgit v1.2.3 From f42ad4e9f7e06a95ce1f5a9b3f7ae0246f81e6d5 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 16 Feb 2014 04:30:45 -0800 Subject: can Now build ProtoProxy alongside MCServer --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c8daf915..18d1fc1c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ enable_language(CXX C) #THis has to be done before any flags have been set up. if(${BUILD_TOOLS}) add_subdirectory(Tools/MCADefrag/) + add_subdirectory(Tools/ProtoProxy/) endif() if(${BUILD_UNSTABLE_TOOLS}) @@ -51,7 +52,7 @@ add_subdirectory(lib/md5/) # We use EXCLUDE_FROM_ALL so that only the explicit dependencies are used # (PolarSSL also has test and example programs in their CMakeLists.txt, we don't want those) -add_subdirectory(lib/polarssl/ EXCLUDE_FROM_ALL) +include(lib/polarssl.cmake) set_exe_flags() -- cgit v1.2.3 From e3dd931be21b234eaf17ab816f25854d5a3fdd34 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 16 Feb 2014 04:39:41 -0800 Subject: Fogot --- lib/polarssl.cmake | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 lib/polarssl.cmake diff --git a/lib/polarssl.cmake b/lib/polarssl.cmake new file mode 100644 index 000000000..d57cc9220 --- /dev/null +++ b/lib/polarssl.cmake @@ -0,0 +1,5 @@ + +if(NOT TARGET polarssl) + message("including polarssl") + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/polarssl/ ${CMAKE_CURRENT_BINARY_DIR}/lib/polarssl EXCLUDE_FROM_ALL ) +endif() -- cgit v1.2.3 From d4f2788008d413f2b2031d55759e54b952d0a964 Mon Sep 17 00:00:00 2001 From: narroo Date: Sun, 16 Feb 2014 07:49:09 -0500 Subject: Changed char[] to unsigned char[] in cIniFile::RemoveBom --- lib/inifile/iniFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp index 7b0df3d68..e2a91c4c2 100644 --- a/lib/inifile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp @@ -834,7 +834,7 @@ AString cIniFile::CheckCase(const AString & s) const void cIniFile::RemoveBom(AString & a_line) const { // The BOM sequence for UTF-8 is 0xEF,0xBB,0xBF ( In Unicode Latin I:  ) - static char BOM[] = { 0xEF, 0xBB, 0xBF }; + static unsigned char BOM[] = { 0xEF, 0xBB, 0xBF }; // The BOM sequence, if present, is always the first three characters of the input. if (a_line.compare(0, 3, BOM) == 0) -- cgit v1.2.3 From 2b0b2b7425c75ddb6d7cc6ea73860698d2b362be Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 16 Feb 2014 04:49:50 -0800 Subject: Build cmake built tools in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 38dd2f280..c6537cf47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ compiler: - gcc - clang # Build MCServer -script: cmake . -DCMAKE_BUILD_TYPE=RELEASE -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | ./MCServer) +script: cmake . -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_TOOLS=1 -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | ./MCServer) # Notification Settings notifications: -- cgit v1.2.3 From 03fd3b556a3842da5e359f5c2317d1b62c8e14fd Mon Sep 17 00:00:00 2001 From: narroo Date: Sun, 16 Feb 2014 08:22:10 -0500 Subject: Changed unsigned char[] back to char[]. --- lib/inifile/iniFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp index e2a91c4c2..db48ad25d 100644 --- a/lib/inifile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp @@ -834,7 +834,7 @@ AString cIniFile::CheckCase(const AString & s) const void cIniFile::RemoveBom(AString & a_line) const { // The BOM sequence for UTF-8 is 0xEF,0xBB,0xBF ( In Unicode Latin I:  ) - static unsigned char BOM[] = { 0xEF, 0xBB, 0xBF }; + static const AString BOM = "" + 0xEF + 0xBB + 0xBF; // The BOM sequence, if present, is always the first three characters of the input. if (a_line.compare(0, 3, BOM) == 0) -- cgit v1.2.3 From 6b64a722b85d2f1ab6ddba7b874fd2ad43443ef2 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 16 Feb 2014 14:34:20 +0100 Subject: Fixed cmake invocation text The docs say: cmake --- COMPILING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/COMPILING.md b/COMPILING.md index 94220f9c6..139f1a0ee 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -69,7 +69,7 @@ Assuming you are in the MCServer folder created in the initial setup step, you n ``` mkdir Release cd Release -cmake .. -DCMAKE_BUILD_TYPE=RELEASE && make +cmake -DCMAKE_BUILD_TYPE=RELEASE .. && make ``` The executable will be built in the `MCServer/MCServer` folder and will be named `MCServer`. @@ -81,7 +81,7 @@ Assuming you are in the MCServer folder created in the Getting the sources step, ``` mkdir Debug cd Debug -cmake .. -DCMAKE_BUILD_TYPE=DEBUG && make +cmake -DCMAKE_BUILD_TYPE=DEBUG .. && make ``` The executable will be built in the `MCServer/MCServer` folder and will be named `MCServer_debug`. -- cgit v1.2.3 From 4908b6f500aa31ca550536c7e5a49e660ff72b65 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 16 Feb 2014 13:37:36 +0000 Subject: Fixed minor formatting issues from #682 - Removed unused PlaySoundEffect * Simplified and parenthesised code --- src/Entities/ExpOrb.cpp | 6 ++---- src/Entities/Player.cpp | 11 +---------- src/Entities/Player.h | 2 -- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 41b60cc3b..3398f1c7b 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -52,11 +52,9 @@ void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk) LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward); a_ClosestPlayer->DeltaExperience(m_Reward); - float r1 = (float) (0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64); // Random Float Value - float r2 = (float) (0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64); // Random Float Value - m_World->BroadcastSoundEffect("random.orb", (int) (GetPosX() * 8.0F), (int) (GetPosY() * 8.0F), (int) (GetPosZ() * 8.0F), 0.1F, 0.5F * ((r1 - r2) * 0.7F + 1.8F)); + m_World->BroadcastSoundEffect("random.orb", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - Destroy(true); + Destroy(); } a_Distance.Normalize(); a_Distance *= ((float) (5.5 - Distance)); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index be26e4f6e..70ddb3c98 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1059,15 +1059,6 @@ void cPlayer::CloseWindowIfID(char a_WindowID, bool a_CanRefuse) -void cPlayer::PlaySoundEffect(const AString & a_SoundName, float a_Volume, float a_Pitch) -{ - m_ClientHandle->SendSoundEffect(a_SoundName, (int) (GetPosX() * 8.0), (int) (GetPosY() * 8.0), (int) (GetPosZ() * 8.0), a_Volume, a_Pitch); -} - - - - - void cPlayer::SetLastBlockActionTime() { if (m_World != NULL) @@ -1796,7 +1787,7 @@ void cPlayer::HandleFood(void) Heal(1); m_FoodExhaustionLevel += 3; } - else if (m_FoodLevel <= 0 && m_Health > 1) + else if ((m_FoodLevel <= 0) && (m_Health > 1)) { // Damage from starving TakeDamage(dtStarving, NULL, 1, 1, 0); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 838f0301d..53e4b56db 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -208,8 +208,6 @@ public: const AString & GetName(void) const { return m_PlayerName; } void SetName(const AString & a_Name) { m_PlayerName = a_Name; } - void PlaySoundEffect(const AString & a_SoundName, float a_Volume, float a_Pitch); - // tolua_end typedef std::list< cGroup* > GroupList; -- cgit v1.2.3 From 1a84102b102304945ea1e2c5ecf13075946b3a4a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 16 Feb 2014 13:47:55 +0000 Subject: Slight cleanup of wolf code --- src/Mobs/Wolf.cpp | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index ff324d073..43949d4ce 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -124,12 +124,6 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); } - - // The wolf is sitting so don't move him at all. - if (IsSitting()) - { - m_bMovingToDestination = false; - } cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); if (a_Closest_Player != NULL) @@ -148,18 +142,15 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) SetIsBegging(true); m_World->BroadcastEntityMetadata(*this); } + // Don't move to the player if the wolf is sitting. if (IsSitting()) { m_bMovingToDestination = false; + return; } - else - { - m_bMovingToDestination = true; - } - Vector3d PlayerPos = a_Closest_Player->GetPosition(); - PlayerPos.y++; - m_FinalDestination = PlayerPos; + + MoveToPosition(a_Closest_Player->GetPosition()); break; } default: @@ -173,7 +164,7 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) } } - if (IsTame()) + if (IsTame() && !IsSitting()) { TickFollowPlayer(); } @@ -196,6 +187,7 @@ void cWolf::TickFollowPlayer() public: Vector3d OwnerPos; } Callback; + if (m_World->DoWithPlayer(m_OwnerName, Callback)) { // The player is present in the world, follow him: @@ -210,15 +202,7 @@ void cWolf::TickFollowPlayer() } else { - m_FinalDestination = Callback.OwnerPos; - if (IsSitting()) - { - m_bMovingToDestination = false; - } - else - { - m_bMovingToDestination = true; - } + MoveToPosition(Callback.OwnerPos); } } } -- cgit v1.2.3 From 761857bd01e7eb42b87504c400d636a0b82a4cf0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 16 Feb 2014 05:55:37 -0800 Subject: Fixed comment --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18d1fc1c8..05b6d879b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required (VERSION 2.6) # Without this, the MSVC variable isn't defined for MSVC builds ( http://www.cmake.org/pipermail/cmake/2011-November/047130.html ) enable_language(CXX C) -#THis has to be done before any flags have been set up. +# This has to be done before any flags have been set up. if(${BUILD_TOOLS}) add_subdirectory(Tools/MCADefrag/) add_subdirectory(Tools/ProtoProxy/) -- cgit v1.2.3 From 6eefd54d455d172f7b77819bf9975ed933477c1c Mon Sep 17 00:00:00 2001 From: narroo Date: Sun, 16 Feb 2014 09:25:32 -0500 Subject: Reworked RemoveBom to use unsigned chars and reverted the logic changes in WriteFile. Should work fine now. --- lib/inifile/iniFile.cpp | 178 ++++++++++++++++++++++++++---------------------- 1 file changed, 96 insertions(+), 82 deletions(-) diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp index db48ad25d..fbbf5c197 100644 --- a/lib/inifile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp @@ -83,97 +83,102 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) } } - if (getline(f, line)) + bool IsFirstLine = true; + + while (getline(f, line)) { - // Removes UTF-8 Byte Order Markers (BOM) if, present. - RemoveBom(line); + // To be compatible with Win32, check for existence of '\r'. + // Win32 files have the '\r' and Unix files don't at the end of a line. + // Note that the '\r' will be written to INI files from + // Unix so that the created INI file can be read under Win32 + // without change. - do + // Removes UTF-8 Byte Order Markers (BOM) if, present. + if (IsFirstLine) { - // To be compatible with Win32, check for existence of '\r'. - // Win32 files have the '\r' and Unix files don't at the end of a line. - // Note that the '\r' will be written to INI files from - // Unix so that the created INI file can be read under Win32 - // without change. - size_t lineLength = line.length(); - if (lineLength == 0) - { - continue; - } - if (line[lineLength - 1] == '\r') - { - line = line.substr(0, lineLength - 1); - } - - if (line.length() == 0) - { - continue; - } + RemoveBom(line); + IsFirstLine = false; + } - // Check that the user hasn't opened a binary file by checking the first - // character of each line! - if (!isprint(line[0])) - { - printf("%s: Binary-check failed on char %d\n", __FUNCTION__, line[0]); - f.close(); - return false; - } - if ((pLeft = line.find_first_of(";#[=")) == AString::npos) - { - continue; - } + size_t lineLength = line.length(); + if (lineLength == 0) + { + continue; + } + if (line[lineLength - 1] == '\r') + { + line = line.substr(0, lineLength - 1); + } - switch (line[pLeft]) - { - case '[': - { - if ( - ((pRight = line.find_last_of("]")) != AString::npos) && - (pRight > pLeft) - ) - { - keyname = line.substr(pLeft + 1, pRight - pLeft - 1); - AddKeyName(keyname); - } - break; - } + if (line.length() == 0) + { + continue; + } - case '=': - { - valuename = line.substr(0, pLeft); - value = line.substr(pLeft + 1); - AddValue(keyname, valuename, value); - break; - } + // Check that the user hasn't opened a binary file by checking the first + // character of each line! + if (!isprint(line[0])) + { + printf("%s: Binary-check failed on char %d\n", __FUNCTION__, line[0]); + f.close(); + return false; + } + if ((pLeft = line.find_first_of(";#[=")) == AString::npos) + { + continue; + } - case ';': - case '#': - { - if (names.size() == 0) - { - AddHeaderComment(line.substr(pLeft + 1)); - } - else - { - AddKeyComment(keyname, line.substr(pLeft + 1)); - } - break; - } - } // switch (line[pLeft]) - } while (getline(f, line)); // do + switch (line[pLeft]) + { + case '[': + { + if ( + ((pRight = line.find_last_of("]")) != AString::npos) && + (pRight > pLeft) + ) + { + keyname = line.substr(pLeft + 1, pRight - pLeft - 1); + AddKeyName(keyname); + } + break; + } - f.close(); - if (names.size() == 0) + case '=': { - return false; + valuename = line.substr(0, pLeft); + value = line.substr(pLeft + 1); + AddValue(keyname, valuename, value); + break; } - if (IsFromExampleRedirect) + case ';': + case '#': { - WriteFile(FILE_IO_PREFIX + a_FileName); + if (names.size() == 0) + { + AddHeaderComment(line.substr(pLeft + 1)); + } + else + { + AddKeyComment(keyname, line.substr(pLeft + 1)); + } + break; } - return true; + } // switch (line[pLeft]) + } // while(getline(f, line)) + + f.close(); + if (names.size() == 0) + { + return false; + } + + if (IsFromExampleRedirect) + { + WriteFile(FILE_IO_PREFIX + a_FileName); } + + return true; } @@ -833,14 +838,23 @@ AString cIniFile::CheckCase(const AString & s) const void cIniFile::RemoveBom(AString & a_line) const { - // The BOM sequence for UTF-8 is 0xEF,0xBB,0xBF ( In Unicode Latin I:  ) - static const AString BOM = "" + 0xEF + 0xBB + 0xBF; + // The BOM sequence for UTF-8 is 0xEF,0xBB,0xBF + static unsigned const char BOM[] = { 0xEF, 0xBB, 0xBF }; + + // The BOM sequence, if present, is always th e first three characters of the input. + const AString ref = a_line.substr(0, 3); - // The BOM sequence, if present, is always the first three characters of the input. - if (a_line.compare(0, 3, BOM) == 0) + // If any of the first three chars do not match, return and do nothing. + for (int i = 0; i < 3; ++i) { - a_line.erase(0, 3); + if (static_cast(ref[i]) != BOM[i]) + { + return; + } } + + // First three characters match; erase them. + a_line.erase(0, 3); } -- cgit v1.2.3 From 6da2d2bb21000bf15f745c171e7a6d9d0e584084 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 16 Feb 2014 07:04:44 -0800 Subject: Added -Wextra --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 162560c90..ded57e6d7 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -183,7 +183,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall") + add_flags_cxx("-Wall -Wextra") endif() endmacro() -- cgit v1.2.3 From 2350b77bb5fa2de05a619a3646662c9fc00ace28 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 16 Feb 2014 17:08:49 +0000 Subject: Fixes to previous commit --- src/Mobs/Wolf.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 43949d4ce..2736c3dd1 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -143,14 +143,14 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) m_World->BroadcastEntityMetadata(*this); } + m_FinalDestination = a_Closest_Player->GetPosition(); // So that we will look at a player holding food + // Don't move to the player if the wolf is sitting. - if (IsSitting()) + if (!IsSitting()) { - m_bMovingToDestination = false; - return; + MoveToPosition(a_Closest_Player->GetPosition()); } - MoveToPosition(a_Closest_Player->GetPosition()); break; } default: @@ -168,6 +168,10 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) { TickFollowPlayer(); } + else if (IsSitting()) + { + m_bMovingToDestination = false; + } } @@ -194,11 +198,8 @@ void cWolf::TickFollowPlayer() double Distance = (Callback.OwnerPos - GetPosition()).Length(); if (Distance > 30) { - if (!IsSitting()) - { - Callback.OwnerPos.y = FindFirstNonAirBlockPosition(Callback.OwnerPos.x, Callback.OwnerPos.z); - TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z); - } + Callback.OwnerPos.y = FindFirstNonAirBlockPosition(Callback.OwnerPos.x, Callback.OwnerPos.z); + TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z); } else { -- cgit v1.2.3 From 60bcf2807a293dcf0a6fcc604a7e36c824a02110 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Sun, 16 Feb 2014 18:18:07 +0100 Subject: Now mobs can't escape from fences. --- src/Mobs/Monster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 9817901c9..1690d3a31 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -142,11 +142,11 @@ void cMonster::TickPathFinding() BLOCKTYPE BlockAtYPP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 2, gCrossCoords[i].z + PosZ); BLOCKTYPE BlockAtYM = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY - 1, gCrossCoords[i].z + PosZ); - if (!g_BlockIsSolid[BlockAtY] && !g_BlockIsSolid[BlockAtYP] && !IsBlockLava(BlockAtYM)) + if (!g_BlockIsSolid[BlockAtY] && !g_BlockIsSolid[BlockAtYP] && !IsBlockLava(BlockAtYM) && BlockAtY!=E_BLOCK_FENCE && BlockAtY!=E_BLOCK_FENCE_GATE) { m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY, gCrossCoords[i].z + PosZ)); } - else if (g_BlockIsSolid[BlockAtY] && !g_BlockIsSolid[BlockAtYP] && !g_BlockIsSolid[BlockAtYPP] && !IsBlockLava(BlockAtYM)) + else if (g_BlockIsSolid[BlockAtY] && !g_BlockIsSolid[BlockAtYP] && !g_BlockIsSolid[BlockAtYPP] && !IsBlockLava(BlockAtYM) && BlockAtY!=E_BLOCK_FENCE && BlockAtY!=E_BLOCK_FENCE_GATE) { m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY + 1, gCrossCoords[i].z + PosZ)); } -- cgit v1.2.3 From e0868c5c062ec81ec268942657517cc8119034c0 Mon Sep 17 00:00:00 2001 From: MuhammadWang Date: Mon, 17 Feb 2014 01:16:00 +0800 Subject: Added files for eclipse and debug, fix a mistake src/Bindings/BindingsDependecies.txt is a mistake made in 45bc1ff033271bc0c6a9e5931a00c554e065c375 --- .gitignore | 5 ++++- MCServer/.gitignore | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 007b21519..c8ad93a80 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ cloc.xsl *.*~ *~ *.orig +## Eclipse +.cproject +.project # world inside source ChunkWorx.ini @@ -57,7 +60,7 @@ install_mainfest.txt src/MCServer lib/tolua++/tolua src/Bindings/Bindings.* -src/Bindings/BindingsDependecies.txt +src/Bindings/BindingDependecies.txt MCServer.dir/ #win32 cmake stuff diff --git a/MCServer/.gitignore b/MCServer/.gitignore index e3aebbf92..0fd04ef59 100644 --- a/MCServer/.gitignore +++ b/MCServer/.gitignore @@ -4,6 +4,7 @@ *.lib *.ini MCServer +MCServer_debug CommLogs/ logs players -- cgit v1.2.3 From b0dbe512100dd2ce506d78065e415a648faf7f0d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 16 Feb 2014 23:30:50 +0100 Subject: Fixed cBoundingBox self-test code-style. Also made the class name unique and the global variable static, to avoid linkage problems with other self-tests --- src/BoundingBox.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/BoundingBox.cpp b/src/BoundingBox.cpp index 47b135688..aab51c539 100644 --- a/src/BoundingBox.cpp +++ b/src/BoundingBox.cpp @@ -12,25 +12,25 @@ #if SELF_TEST -/// A simple self-test that is executed on program start, used to verify bbox functionality -class SelfTest +/** A simple self-test that is executed on program start, used to verify bbox functionality */ +static class SelfTest_BoundingBox { public: - SelfTest(void) + SelfTest_BoundingBox(void) { Vector3d Min(1, 1, 1); Vector3d Max(2, 2, 2); Vector3d LineDefs[] = { - Vector3d(1.5, 4, 1.5), Vector3d(1.5, 3, 1.5), // Should intersect at 2, face 1 (YP) + Vector3d(1.5, 4, 1.5), Vector3d(1.5, 3, 1.5), // Should intersect at 2, face 1 (YP) Vector3d(1.5, 0, 1.5), Vector3d(1.5, 4, 1.5), // Should intersect at 0.25, face 0 (YM) Vector3d(0, 0, 0), Vector3d(2, 2, 2), // Should intersect at 0.5, face 0, 3 or 5 (anyM) Vector3d(0.999, 0, 1.5), Vector3d(0.999, 4, 1.5), // Should not intersect Vector3d(1.999, 0, 1.5), Vector3d(1.999, 4, 1.5), // Should intersect at 0.25, face 0 (YM) Vector3d(2.001, 0, 1.5), Vector3d(2.001, 4, 1.5), // Should not intersect } ; - bool Results[] = {true,true,true,false,true,false}; - double LineCoeffs[] = {2,0.25,0.5,0,0.25,0}; + bool Results[] = {true, true, true, false, true, false}; + double LineCoeffs[] = {2, 0.25, 0.5, 0, 0.25, 0}; for (size_t i = 0; i < ARRAYCOUNT(LineDefs) / 2; i++) { @@ -41,7 +41,7 @@ public: bool res = cBoundingBox::CalcLineIntersection(Min, Max, Line1, Line2, LineCoeff, Face); if (res != Results[i]) { - fprintf(stderr,"LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", + fprintf(stderr, "LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", Line1.x, Line1.y, Line1.z, Line2.x, Line2.y, Line2.z, res ? 1 : 0, LineCoeff, Face @@ -52,7 +52,7 @@ public: { if (LineCoeff != LineCoeffs[i]) { - fprintf(stderr,"LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", + fprintf(stderr, "LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", Line1.x, Line1.y, Line1.z, Line2.x, Line2.y, Line2.z, res ? 1 : 0, LineCoeff, Face @@ -61,9 +61,9 @@ public: } } } // for i - LineDefs[] - fprintf(stderr,"BoundingBox selftest complete."); + fprintf(stderr, "BoundingBox selftest complete.\n"); } -} Test; +} gTest; #endif -- cgit v1.2.3 From 4a24e39ac10de4389bcbda29f51ae09f93e794ca Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 16 Feb 2014 23:31:47 +0100 Subject: Implemented cCompositeChat::ParseText(), incl. self-test. --- src/CompositeChat.cpp | 207 +++++++++++++++++++++++++++++++++++++++++++++++++- src/CompositeChat.h | 5 ++ 2 files changed, 211 insertions(+), 1 deletion(-) diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index 16ae58f56..1893585f6 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -10,6 +10,96 @@ +#if SELF_TEST + +/** A simple self-test that verifies that the composite chat parser is working properly. */ +class SelfTest_CompositeChat +{ +public: + SelfTest_CompositeChat(void) + { + fprintf(stderr, "cCompositeChat self test...\n"); + TestParser1(); + TestParser2(); + TestParser3(); + TestParser4(); + TestParser5(); + fprintf(stderr, "cCompositeChat self test finished.\n"); + } + + void TestParser1(void) + { + cCompositeChat Msg; + Msg.ParseText("Testing @2color codes and http://links parser"); + const cCompositeChat::cParts & Parts = Msg.GetParts(); + assert(Parts.size() == 4); + assert(Parts[0]->m_PartType == cCompositeChat::ptText); + assert(Parts[1]->m_PartType == cCompositeChat::ptText); + assert(Parts[2]->m_PartType == cCompositeChat::ptUrl); + assert(Parts[3]->m_PartType == cCompositeChat::ptText); + assert(Parts[0]->m_Style == ""); + assert(Parts[1]->m_Style == "@2"); + assert(Parts[2]->m_Style == "@2"); + assert(Parts[3]->m_Style == "@2"); + } + + void TestParser2(void) + { + cCompositeChat Msg; + Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling"); + const cCompositeChat::cParts & Parts = Msg.GetParts(); + assert(Parts.size() == 4); + assert(Parts[0]->m_PartType == cCompositeChat::ptText); + assert(Parts[1]->m_PartType == cCompositeChat::ptText); + assert(Parts[2]->m_PartType == cCompositeChat::ptUrl); + assert(Parts[3]->m_PartType == cCompositeChat::ptText); + assert(Parts[0]->m_Style == "@3"); + assert(Parts[1]->m_Style == "@5"); + assert(Parts[2]->m_Style == "@5"); + assert(Parts[3]->m_Style == "@5"); + } + + void TestParser3(void) + { + cCompositeChat Msg; + Msg.ParseText("http://links.starting the text"); + const cCompositeChat::cParts & Parts = Msg.GetParts(); + assert(Parts.size() == 2); + assert(Parts[0]->m_PartType == cCompositeChat::ptUrl); + assert(Parts[1]->m_PartType == cCompositeChat::ptText); + assert(Parts[0]->m_Style == ""); + assert(Parts[1]->m_Style == ""); + } + + void TestParser4(void) + { + cCompositeChat Msg; + Msg.ParseText("links finishing the text: http://some.server"); + const cCompositeChat::cParts & Parts = Msg.GetParts(); + assert(Parts.size() == 2); + assert(Parts[0]->m_PartType == cCompositeChat::ptText); + assert(Parts[1]->m_PartType == cCompositeChat::ptUrl); + assert(Parts[0]->m_Style == ""); + assert(Parts[1]->m_Style == ""); + } + + void TestParser5(void) + { + cCompositeChat Msg; + Msg.ParseText("http://only.links"); + const cCompositeChat::cParts & Parts = Msg.GetParts(); + assert(Parts.size() == 1); + assert(Parts[0]->m_PartType == cCompositeChat::ptUrl); + assert(Parts[0]->m_Style == ""); + } + +} gTest; +#endif // SELF_TEST + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cCompositeChat: @@ -101,7 +191,99 @@ void cCompositeChat::AddSuggestCommandPart(const AString & a_Text, const AString void cCompositeChat::ParseText(const AString & a_ParseText) { - // TODO + size_t len = a_ParseText.length(); + size_t first = 0; // First character of the currently parsed block + AString CurrentStyle; + AString CurrentText; + for (size_t i = 0; i < len; i++) + { + switch (a_ParseText[i]) + { + case '@': + { + // Color code + i++; + if (i >= len) + { + // Not enough following text + break; + } + if (a_ParseText[i] == '@') + { + // "@@" escape, just put a "@" into the current text and keep parsing as text + if (i > first + 1) + { + CurrentText.append(a_ParseText.c_str() + first, i - first - 1); + } + first = i + 1; + continue; + } + else + { + // True color code. Create a part for the CurrentText and start parsing anew: + if (i >= first) + { + CurrentText.append(a_ParseText.c_str() + first, i - first - 1); + first = i + 1; + } + if (!CurrentText.empty()) + { + m_Parts.push_back(new cTextPart(CurrentText, CurrentStyle)); + CurrentText.clear(); + } + AddStyle(CurrentStyle, a_ParseText.substr(i - 1, 2)); + } + break; + } + + case ':': + { + const char * LinkPrefixes[] = + { + "http", + "https" + }; + for (size_t Prefix = 0; Prefix < ARRAYCOUNT(LinkPrefixes); Prefix++) + { + size_t PrefixLen = strlen(LinkPrefixes[Prefix]); + if ( + (i >= first + PrefixLen) && // There is enough space in front of the colon for the prefix + (strncmp(a_ParseText.c_str() + i - PrefixLen, LinkPrefixes[Prefix], PrefixLen) == 0) // the prefix matches + ) + { + // Add everything before this as a text part: + if (i > first + PrefixLen) + { + CurrentText.append(a_ParseText.c_str() + first, i - first - PrefixLen); + first = i - PrefixLen; + } + if (!CurrentText.empty()) + { + AddTextPart(CurrentText, CurrentStyle); + CurrentText.clear(); + } + + // Go till the last non-whitespace char in the text: + for (; i < len; i++) + { + if (isspace(a_ParseText[i])) + { + break; + } + } + AddUrlPart(a_ParseText.substr(first, i - first), a_ParseText.substr(first, i - first), CurrentStyle); + first = i; + break; + } + } // for Prefix - LinkPrefix[] + break; + } // case ':' + } // switch (a_ParseText[i]) + } // for i - a_ParseText[] + if (first < len) + { + AddTextPart(a_ParseText.substr(first, len - first), CurrentStyle); + } } @@ -117,6 +299,29 @@ void cCompositeChat::SetMessageType(eMessageType a_MessageType) +void cCompositeChat::AddStyle(AString & a_Style, const AString & a_AddStyle) +{ + if (a_AddStyle.empty()) + { + return; + } + if (a_AddStyle[0] == '@') + { + size_t idx = a_Style.find('@'); + if ((idx != AString::npos) && (idx != a_Style.length())) + { + a_Style.erase(idx, 2); + } + a_Style.append(a_AddStyle); + return; + } + a_Style.append(a_AddStyle); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cCompositeChat::cBasePart: diff --git a/src/CompositeChat.h b/src/CompositeChat.h index e220f6345..4b3523b08 100644 --- a/src/CompositeChat.h +++ b/src/CompositeChat.h @@ -165,6 +165,11 @@ protected: /** The message type, as indicated by prefixes. */ eMessageType m_MessageType; + + + /** Adds a_AddStyle to a_Style; overwrites the existing style if appropriate. + If the style already contains something that a_AddStyle overrides, it is erased first. */ + void AddStyle(AString & a_Style, const AString & a_AddStyle); } ; // tolua_export -- cgit v1.2.3 From ea55a22a71a6fd46877bc4b6b56d6205dd20608f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 16 Feb 2014 23:51:32 +0100 Subject: Links sent via chat messages are clickable. Fixes #658. --- src/ClientHandle.cpp | 22 ++++++++++++++-------- src/CompositeChat.cpp | 15 +++++++++++++++ src/CompositeChat.h | 3 +++ src/Entities/Player.h | 3 ++- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index b46bcfd47..c91a0c01b 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1089,14 +1089,20 @@ void cClientHandle::HandleChat(const AString & a_Message) return; } - // Not a command, broadcast as a simple message: - AString Msg; - Printf(Msg, "%s<%s>%s %s", - m_Player->GetColor().c_str(), - m_Player->GetName().c_str(), - cChatColor::White.c_str(), - Message.c_str() - ); + // Not a command, broadcast as a message: + cCompositeChat Msg; + AString Color = m_Player->GetColor(); + if (Color.length() == 3) + { + Color = AString("@") + Color[2]; + } + else + { + Color.empty(); + } + Msg.AddTextPart(AString("<") + m_Player->GetName() + "> ", Color); + Msg.ParseText(a_Message); + Msg.UnderlineUrls(); m_Player->GetWorld()->BroadcastChat(Msg); } diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index 1893585f6..3eec35657 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -299,6 +299,21 @@ void cCompositeChat::SetMessageType(eMessageType a_MessageType) +void cCompositeChat::UnderlineUrls(void) +{ + for (cParts::iterator itr = m_Parts.begin(), end = m_Parts.end(); itr != end; ++itr) + { + if ((*itr)->m_PartType == ptUrl) + { + (*itr)->m_Style.append("u"); + } + } // for itr - m_Parts[] +} + + + + + void cCompositeChat::AddStyle(AString & a_Style, const AString & a_AddStyle) { if (a_AddStyle.empty()) diff --git a/src/CompositeChat.h b/src/CompositeChat.h index 4b3523b08..8963bb520 100644 --- a/src/CompositeChat.h +++ b/src/CompositeChat.h @@ -155,6 +155,9 @@ public: /** Returns the message type set previously by SetMessageType(). */ eMessageType GetMessageType(void) const { return m_MessageType; } + /** Adds the "underline" style to each part that is an URL. */ + void UnderlineUrls(void); + // tolua_end const cParts & GetParts(void) const { return m_Parts; } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 53e4b56db..a795bb9eb 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -226,7 +226,8 @@ public: // tolua_begin - /// Returns the full color code to use for this player, based on their primary group or set in m_Color + /** Returns the full color code to use for this player, based on their primary group or set in m_Color. + The returned value includes the cChatColor::Delimiter. */ AString GetColor(void) const; /** tosses the item in the selected hotbar slot */ -- cgit v1.2.3 From a4ff63f223d5a9b20e71286975d7a6d5f0c00f17 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 17 Feb 2014 10:15:18 +0100 Subject: Fixed a memory leak in CompositeChat. --- src/CompositeChat.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CompositeChat.h b/src/CompositeChat.h index 8963bb520..51600da4f 100644 --- a/src/CompositeChat.h +++ b/src/CompositeChat.h @@ -48,6 +48,9 @@ public: AString m_Style; cBasePart(ePartType a_PartType, const AString & a_Text, const AString & a_Style = ""); + + // Force a virtual destructor in descendants + virtual ~cBasePart() {} } ; class cTextPart : -- cgit v1.2.3 From 3ce8bf9712f09bf670e3cb11138c7be9bb26b211 Mon Sep 17 00:00:00 2001 From: narroo Date: Mon, 17 Feb 2014 08:45:31 -0500 Subject: Fixed Tab spacing of cases. --- lib/inifile/iniFile.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp index fbbf5c197..212c1d14d 100644 --- a/lib/inifile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp @@ -130,8 +130,8 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) switch (line[pLeft]) { - case '[': - { + case '[': + { if ( ((pRight = line.find_last_of("]")) != AString::npos) && (pRight > pLeft) @@ -141,19 +141,19 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) AddKeyName(keyname); } break; - } + } - case '=': - { + case '=': + { valuename = line.substr(0, pLeft); value = line.substr(pLeft + 1); AddValue(keyname, valuename, value); break; - } + } - case ';': - case '#': - { + case ';': + case '#': + { if (names.size() == 0) { AddHeaderComment(line.substr(pLeft + 1)); @@ -163,7 +163,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) AddKeyComment(keyname, line.substr(pLeft + 1)); } break; - } + } } // switch (line[pLeft]) } // while(getline(f, line)) -- cgit v1.2.3 From ecabb2b34f8dea427868f76019a1dd7f2b031bf9 Mon Sep 17 00:00:00 2001 From: narroo Date: Mon, 17 Feb 2014 08:46:41 -0500 Subject: Fixed the tab spacing. --- lib/inifile/iniFile.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp index 212c1d14d..9c5300cdf 100644 --- a/lib/inifile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp @@ -132,37 +132,37 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) { case '[': { - if ( - ((pRight = line.find_last_of("]")) != AString::npos) && - (pRight > pLeft) - ) - { - keyname = line.substr(pLeft + 1, pRight - pLeft - 1); - AddKeyName(keyname); - } - break; + if ( + ((pRight = line.find_last_of("]")) != AString::npos) && + (pRight > pLeft) + ) + { + keyname = line.substr(pLeft + 1, pRight - pLeft - 1); + AddKeyName(keyname); + } + break; } case '=': { - valuename = line.substr(0, pLeft); - value = line.substr(pLeft + 1); - AddValue(keyname, valuename, value); - break; + valuename = line.substr(0, pLeft); + value = line.substr(pLeft + 1); + AddValue(keyname, valuename, value); + break; } case ';': case '#': { - if (names.size() == 0) - { - AddHeaderComment(line.substr(pLeft + 1)); - } - else - { - AddKeyComment(keyname, line.substr(pLeft + 1)); - } - break; + if (names.size() == 0) + { + AddHeaderComment(line.substr(pLeft + 1)); + } + else + { + AddKeyComment(keyname, line.substr(pLeft + 1)); + } + break; } } // switch (line[pLeft]) } // while(getline(f, line)) -- cgit v1.2.3 From 952a338c7f5518bacd5b733ecbcc62c02cfc60b2 Mon Sep 17 00:00:00 2001 From: narroo Date: Mon, 17 Feb 2014 08:50:22 -0500 Subject: Fixed Comment Typo. --- lib/inifile/iniFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp index 9c5300cdf..c56292059 100644 --- a/lib/inifile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp @@ -165,7 +165,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) break; } } // switch (line[pLeft]) - } // while(getline(f, line)) + } // while(getline()) f.close(); if (names.size() == 0) -- cgit v1.2.3 From 794be05f229009ae9e00150b50ccff908b71b1fd Mon Sep 17 00:00:00 2001 From: narroo Date: Mon, 17 Feb 2014 08:51:36 -0500 Subject: Fixed comment typo --- lib/inifile/iniFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp index c56292059..cf8b63987 100644 --- a/lib/inifile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp @@ -165,7 +165,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) break; } } // switch (line[pLeft]) - } // while(getline()) + } // while (getline()) f.close(); if (names.size() == 0) -- cgit v1.2.3 From 3b24bc870bb39a8b8812ed307250e1188b9ff788 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 17 Feb 2014 16:27:12 +0200 Subject: Map item handler; Fixed several bugs --- src/ClientHandle.cpp | 2 -- src/Entities/Player.cpp | 3 ++ src/Inventory.cpp | 25 +++++++++++++++ src/Inventory.h | 3 ++ src/Items/ItemEmptyMap.h | 16 +++++++++- src/Items/ItemHandler.cpp | 2 ++ src/Items/ItemHandler.h | 8 +++++ src/Items/ItemMap.h | 43 ++++++++++++++++++++++++++ src/Map.cpp | 63 +++++++++++++++++++++++++++++++------- src/Map.h | 13 ++++++-- src/World.cpp | 28 ++++++++++++----- src/WorldStorage/MapSerializer.cpp | 11 +++++-- src/WorldStorage/MapSerializer.h | 7 +++-- 13 files changed, 195 insertions(+), 29 deletions(-) create mode 100644 src/Items/ItemMap.h diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index ff8775771..a2cbaefff 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1199,8 +1199,6 @@ void cClientHandle::HandleSlotSelected(short a_SlotNum) if (Map != NULL) { - Map->UpdateRadius(*m_Player, 128); // Temporary - // TODO 2014-02-14 xdot: Optimization - Do not send the whole map. Map->SendTo(*this); } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 286d43cf6..fdf8d4303 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -254,6 +254,9 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) HandleFloater(); } + // Update items (e.g. Maps) + m_Inventory.UpdateItems(); + // Send Player List (Once per m_LastPlayerListTime/1000 ms) cTimer t1; if (m_LastPlayerListTime + cPlayer::PLAYER_LIST_TIME_MS <= t1.GetNowTime()) diff --git a/src/Inventory.cpp b/src/Inventory.cpp index 0e1cedc85..7f434adfd 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -515,6 +515,31 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, +void cInventory::UpdateItems(void) +{ + const cItem & Slot = GetEquippedItem(); + + if (Slot.IsEmpty()) + { + return; + } + + switch (Slot.m_ItemType) + { + case E_ITEM_MAP: + { + ItemHandler(Slot.m_ItemType)->OnUpdate(m_Owner.GetWorld(), &m_Owner, Slot); + break; + } + + default: break; + } +} + + + + + void cInventory::SaveToJson(Json::Value & a_Value) { // The JSON originally included the 4 crafting slots and the result, so we have to put empty items there, too: diff --git a/src/Inventory.h b/src/Inventory.h index 3c6a19de8..fd2089a13 100644 --- a/src/Inventory.h +++ b/src/Inventory.h @@ -150,6 +150,9 @@ public: /// Sends the slot contents to the owner void SendSlot(int a_SlotNum); + /// Update items (e.g. Maps) + void UpdateItems(void); + /// Converts an armor slot number into the ID for the EntityEquipment packet static int ArmorSlotNumToEntityEquipmentID(short a_ArmorSlotNum); diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index 24d31151b..b06cf9d13 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -41,7 +41,21 @@ public: int CenterX = round(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth; int CenterZ = round(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth; - a_World->CreateMap(CenterX, CenterZ, DEFAULT_SCALE); + cMap * NewMap = a_World->CreateMap(CenterX, CenterZ, DEFAULT_SCALE); + + // Remove empty map from inventory + if (!a_Player->GetInventory().RemoveOneEquippedItem()) + { + ASSERT(!"Inventory mismatch"); + return true; + } + + if (NewMap == NULL) + { + return true; + } + + a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, NewMap->GetID()), true, true); return true; } diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 755766d64..cab8dec97 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -25,6 +25,7 @@ #include "ItemHoe.h" #include "ItemLeaves.h" #include "ItemLighter.h" +#include "ItemMap.h" #include "ItemMinecart.h" #include "ItemNetherWart.h" #include "ItemPickaxe.h" @@ -107,6 +108,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_FISHING_ROD: return new cItemFishingRodHandler(a_ItemType); case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType); case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType); + case E_ITEM_MAP: return new cItemMapHandler(); case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType); case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemType); case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index 1a6bb044f..ef3f37a7a 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -32,6 +32,14 @@ public: UNUSED(a_BlockZ); UNUSED(a_BlockFace); } + + /// Called every tick while the item is on the player's inventory (Used by maps) - For now, called only for equipped items + virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item) + { + UNUSED(a_World); + UNUSED(a_Player); + UNUSED(a_Item); + } /// Called while the player diggs a block using this item virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace); diff --git a/src/Items/ItemMap.h b/src/Items/ItemMap.h new file mode 100644 index 000000000..c3e605547 --- /dev/null +++ b/src/Items/ItemMap.h @@ -0,0 +1,43 @@ + +// ItemMap.h + + + + + +#pragma once + +#include "../Entities/Entity.h" +#include "../Item.h" + + + + + +class cItemMapHandler : + public cItemHandler +{ + typedef cItemHandler super; + + static const unsigned int DEFAULT_RADIUS = 128; + +public: + cItemMapHandler() : + super(E_ITEM_MAP) + { + } + + virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item) + { + cMap * Map = a_World->GetMapData(a_Item.m_ItemDamage); + + if (Map == NULL) + { + return; + } + + // Map->AddTrackedPlayer(a_Player); + + Map->UpdateRadius(*a_Player, DEFAULT_RADIUS); + } +} ; diff --git a/src/Map.cpp b/src/Map.cpp index e0f991693..e85c23d3a 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -50,15 +50,25 @@ cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, un +template +T Clamp(T a_X, T a_Min, T a_Max) +{ + return std::min(std::max(a_X, a_Min), a_Max); +} + + + + + void cMap::UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius) { int PixelRadius = a_Radius / GetPixelWidth(); - unsigned int StartX = std::max(a_PixelX - PixelRadius, 0); - unsigned int StartZ = std::max(a_PixelZ - PixelRadius, 0); + unsigned int StartX = Clamp(a_PixelX - PixelRadius, 0, (int)m_Width); + unsigned int StartZ = Clamp(a_PixelZ - PixelRadius, 0, (int)m_Height); - unsigned int EndX = std::min(a_PixelX + PixelRadius, (int)m_Width); - unsigned int EndZ = std::min(a_PixelZ + PixelRadius, (int)m_Height); + unsigned int EndX = Clamp(a_PixelX + PixelRadius, 0, (int)m_Width); + unsigned int EndZ = Clamp(a_PixelZ + PixelRadius, 0, (int)m_Height); for (unsigned int X = StartX; X < EndX; ++X) { @@ -93,11 +103,9 @@ void cMap::UpdateRadius(cPlayer & a_Player, unsigned int a_Radius) -bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y) +bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) { - ASSERT(m_World != NULL); - - unsigned int PixelWidth = GetPixelWidth(); + /*unsigned int PixelWidth = GetPixelWidth(); int BlockX = m_CenterX + ((a_X - m_Width) * PixelWidth); int BlockZ = m_CenterZ + ((a_Y - m_Height) * PixelWidth); @@ -119,7 +127,7 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y) public: cCalculatePixelCb(cMap * a_Map, int a_RelX, int a_RelZ) - : m_Map(a_Map), m_RelX(a_RelX), m_RelZ(a_RelZ), m_PixelData(0) {} + : m_Map(a_Map), m_RelX(a_RelX), m_RelZ(a_RelZ), m_PixelData(4) {} virtual bool Item(cChunk * a_Chunk) override { @@ -155,9 +163,9 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y) } CalculatePixelCb(this, RelX, RelZ); ASSERT(m_World != NULL); - m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb); + m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb);*/ - m_Data[a_Y + (a_X * m_Height)] = CalculatePixelCb.GetPixelData(); + m_Data[a_Z + (a_X * m_Height)] = 4; return true; } @@ -166,6 +174,39 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y) +void cMap::UpdateTrackedPlayers(void) +{ + cTrackedPlayerList NewList; + + for (cTrackedPlayerList::iterator it = m_TrackedPlayers.begin(); it != m_TrackedPlayers.end(); ++it) + { + cPlayer * Player = *it; + + UpdateRadius(*Player, DEFAULT_RADIUS); + + if (true) + { + NewList.insert(Player); + } + } + + std::swap(m_TrackedPlayers, NewList); +} + + + + + +void cMap::AddTrackedPlayer(cPlayer * a_Player) +{ + ASSERT(a_Player != NULL); + m_TrackedPlayers.insert(a_Player); +} + + + + + void cMap::EraseData(void) { m_Data.assign(m_Width * m_Height, 0); diff --git a/src/Map.h b/src/Map.h index 4134d53a1..805dfb845 100644 --- a/src/Map.h +++ b/src/Map.h @@ -38,6 +38,8 @@ public: typedef std::vector cColorList; + static const unsigned int DEFAULT_RADIUS = 128; + public: @@ -54,6 +56,10 @@ public: void UpdateRadius(cPlayer & a_Player, unsigned int a_Radius); + void UpdateTrackedPlayers(void); + + void AddTrackedPlayer(cPlayer * a_Player); + // tolua_begin /** Erase pixel data */ @@ -93,7 +99,7 @@ public: private: /** Update the specified pixel. */ - bool UpdatePixel(unsigned int a_X, unsigned int a_Y); + bool UpdatePixel(unsigned int a_X, unsigned int a_Z); unsigned int m_ID; @@ -111,8 +117,9 @@ private: cWorld * m_World; - //typedef std::vector cPlayerList; - //cPlayerList m_TrackedPlayers; + typedef std::set cTrackedPlayerList; + + cTrackedPlayerList m_TrackedPlayers; AString m_Name; diff --git a/src/World.cpp b/src/World.cpp index 2a3e53332..55c6fbb7a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1574,8 +1574,7 @@ cMap * cWorld::CreateMap(int a_CenterX, int a_CenterY, int a_Scale) { if (m_MapData.size() >= 65536) { - LOGD("cWorld::CreateMap - Too many maps in use"); - + LOGWARN("Could not craft map - Too many maps in use"); return NULL; } @@ -2992,9 +2991,12 @@ void cWorld::LoadMapData(void) { cIDCountSerializer IDSerializer(GetName()); - IDSerializer.Load(); + if (!IDSerializer.Load()) + { + return; + } - unsigned int MapCount = IDSerializer.GetMapCount() + 1; + unsigned int MapCount = IDSerializer.GetMapCount(); m_MapData.clear(); @@ -3004,7 +3006,10 @@ void cWorld::LoadMapData(void) cMapSerializer Serializer(GetName(), &Map); - Serializer.Load(); + if (!Serializer.Load()) + { + LOGWARN("Could not load map #%i", Map.GetID()); + } m_MapData.push_back(Map); } @@ -3023,9 +3028,13 @@ void cWorld::SaveMapData(void) cIDCountSerializer IDSerializer(GetName()); - IDSerializer.SetMapCount(m_MapData.size() - 1); + IDSerializer.SetMapCount(m_MapData.size()); - IDSerializer.Save(); + if (!IDSerializer.Save()) + { + LOGERROR("Could not save idcounts.dat"); + return; + } for (cMapList::iterator it = m_MapData.begin(); it != m_MapData.end(); ++it) { @@ -3033,7 +3042,10 @@ void cWorld::SaveMapData(void) cMapSerializer Serializer(GetName(), &Map); - Serializer.Save(); + if (!Serializer.Save()) + { + LOGWARN("Could not save map #%i", Map.GetID()); + } } } diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp index 6dab19d4f..0bbe71a60 100644 --- a/src/WorldStorage/MapSerializer.cpp +++ b/src/WorldStorage/MapSerializer.cpp @@ -223,7 +223,11 @@ bool cIDCountSerializer::Load(void) int CurrLine = NBT.FindChildByName(0, "map"); if (CurrLine >= 0) { - m_MapCount = (int)NBT.GetShort(CurrLine); + m_MapCount = (int)NBT.GetShort(CurrLine) + 1; + } + else + { + m_MapCount = 0; } return true; @@ -237,7 +241,10 @@ bool cIDCountSerializer::Save(void) { cFastNBTWriter Writer; - Writer.AddShort("map", m_MapCount); + if (m_MapCount > 0) + { + Writer.AddShort("map", m_MapCount - 1); + } Writer.Finish(); diff --git a/src/WorldStorage/MapSerializer.h b/src/WorldStorage/MapSerializer.h index d9da107bc..296cc92c8 100644 --- a/src/WorldStorage/MapSerializer.h +++ b/src/WorldStorage/MapSerializer.h @@ -27,10 +27,10 @@ public: cMapSerializer(const AString& a_WorldName, cMap * a_Map); - /// Try to load the scoreboard + /** Try to load the scoreboard */ bool Load(void); - /// Try to save the scoreboard + /** Try to save the scoreboard */ bool Save(void); @@ -56,8 +56,10 @@ public: cIDCountSerializer(const AString & a_WorldName); + /** Try to load the ID counts */ bool Load(void); + /** Try to save the ID counts */ bool Save(void); inline unsigned int GetMapCount(void) const { return m_MapCount; } @@ -70,6 +72,7 @@ private: AString m_Path; unsigned int m_MapCount; + }; -- cgit v1.2.3 From 8707f7ddc812037f022e46fa7d0d6a56a9c55728 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Mon, 17 Feb 2014 17:01:22 +0100 Subject: Improved formatting --- src/Mobs/Monster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 1690d3a31..b5cf693cb 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -142,11 +142,11 @@ void cMonster::TickPathFinding() BLOCKTYPE BlockAtYPP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 2, gCrossCoords[i].z + PosZ); BLOCKTYPE BlockAtYM = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY - 1, gCrossCoords[i].z + PosZ); - if (!g_BlockIsSolid[BlockAtY] && !g_BlockIsSolid[BlockAtYP] && !IsBlockLava(BlockAtYM) && BlockAtY!=E_BLOCK_FENCE && BlockAtY!=E_BLOCK_FENCE_GATE) + if ((!g_BlockIsSolid[BlockAtY]) && (!g_BlockIsSolid[BlockAtYP]) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) { m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY, gCrossCoords[i].z + PosZ)); } - else if (g_BlockIsSolid[BlockAtY] && !g_BlockIsSolid[BlockAtYP] && !g_BlockIsSolid[BlockAtYPP] && !IsBlockLava(BlockAtYM) && BlockAtY!=E_BLOCK_FENCE && BlockAtY!=E_BLOCK_FENCE_GATE) + else if ((g_BlockIsSolid[BlockAtY]) && (!g_BlockIsSolid[BlockAtYP]) && (!g_BlockIsSolid[BlockAtYPP]) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) { m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY + 1, gCrossCoords[i].z + PosZ)); } -- cgit v1.2.3 From 777041806fb5085e94838fa9bb0b1c3fe0b61696 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 17 Feb 2014 20:14:08 +0100 Subject: Add Skulls/Heads --- src/BlockEntities/BlockEntity.cpp | 2 + src/BlockEntities/SkullEntity.cpp | 110 ++++++++++++++++++++++++++++++++ src/BlockEntities/SkullEntity.h | 79 +++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/Chunk.cpp | 2 + src/Defines.h | 37 +++++++++++ src/Items/ItemHandler.cpp | 2 + src/Items/ItemSkull.h | 43 +++++++++++++ src/Protocol/Protocol17x.cpp | 14 ++++ src/WorldStorage/NBTChunkSerializer.cpp | 26 ++++++-- src/WorldStorage/NBTChunkSerializer.h | 2 + src/WorldStorage/WSSAnvil.cpp | 40 ++++++++++++ src/WorldStorage/WSSAnvil.h | 1 + 13 files changed, 354 insertions(+), 5 deletions(-) create mode 100644 src/BlockEntities/SkullEntity.cpp create mode 100644 src/BlockEntities/SkullEntity.h create mode 100644 src/Items/ItemSkull.h diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 97b5c1a66..441f54a26 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -15,6 +15,7 @@ #include "JukeboxEntity.h" #include "NoteEntity.h" #include "SignEntity.h" +#include "SkullEntity.h" @@ -31,6 +32,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/SkullEntity.cpp b/src/BlockEntities/SkullEntity.cpp new file mode 100644 index 000000000..3f3bc00ed --- /dev/null +++ b/src/BlockEntities/SkullEntity.cpp @@ -0,0 +1,110 @@ + +// SkullEntity.cpp + +// Implements the cSkullEntity class representing a single skull/head in the world + +#include "Globals.h" +#include "json/json.h" +#include "SkullEntity.h" +#include "../Entities/Player.h" + + + + + +cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World) : + super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), + //m_SkullType(static_cast(a_BlockMeta)), + m_Owner("") +{ + +} + + + + + +void cSkullEntity::UsedBy(cPlayer * a_Player) +{ + UNUSED(a_Player); +} + + + + + +void cSkullEntity::SetSkullType(const eSkullType & a_SkullType) +{ + if ((!m_Owner.empty()) && (a_SkullType != SKULL_TYPE_PLAYER)) + { + m_Owner = ""; + } + m_SkullType = a_SkullType; +} + + + + + +void cSkullEntity::SetRotation(eSkullRotation a_Rotation) +{ + m_Rotation = a_Rotation; +} + + + + + +void cSkullEntity::SetOwner(const AString & a_Owner) +{ + if ((a_Owner.length() > 16) || (m_SkullType != SKULL_TYPE_PLAYER)) + { + return; + } + m_Owner = a_Owner; +} + + + + + +void cSkullEntity::SendTo(cClientHandle & a_Client) +{ + a_Client.SendUpdateBlockEntity(*this); +} + + + + + +bool cSkullEntity::LoadFromJson(const Json::Value & a_Value) +{ + m_PosX = a_Value.get("x", 0).asInt(); + m_PosY = a_Value.get("y", 0).asInt(); + m_PosZ = a_Value.get("z", 0).asInt(); + + m_SkullType = static_cast(a_Value.get("SkullType", 0).asInt()); + m_Rotation = static_cast(a_Value.get("Rotation", 0).asInt()); + m_Owner = a_Value.get("Owner", "").asString(); + + return true; +} + + + + + +void cSkullEntity::SaveToJson(Json::Value & a_Value) +{ + a_Value["x"] = m_PosX; + a_Value["y"] = m_PosY; + a_Value["z"] = m_PosZ; + + a_Value["SkullType"] = m_SkullType; + a_Value["Rotation"] = m_Rotation; + a_Value["Owner"] = m_Owner; +} + + + + diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h new file mode 100644 index 000000000..6f47c7d30 --- /dev/null +++ b/src/BlockEntities/SkullEntity.h @@ -0,0 +1,79 @@ +// SkullEntity.h + +// Declares the cSkullEntity class representing a single skull/head in the world + + + + + +#pragma once + +#include "BlockEntity.h" + + + + + +namespace Json +{ + class Value; +} + + + + + +// tolua_begin + +class cSkullEntity : + public cBlockEntity +{ + typedef cBlockEntity super; + +public: + + // tolua_end + + /// Creates a new skull entity at the specified block coords. a_World may be NULL + cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World); + + bool LoadFromJson( const Json::Value& a_Value ); + virtual void SaveToJson(Json::Value& a_Value ) override; + + // tolua_begin + + /// Set the Skull Type + void SetSkullType(const eSkullType & a_SkullType); + + /// Set the Rotation + void SetRotation(eSkullRotation a_Rotation); + + // Set the Player Name for Player Skulls + void SetOwner(const AString & a_Owner); + + /// Get the Skull Type + eSkullType GetSkullType(void) const { return m_SkullType; } + + /// Get the Rotation + eSkullRotation GetRotation(void) const { return m_Rotation; } + + /// Get the setted Player Name + AString GetOwner(void) const { return m_Owner; } + + // tolua_end + + virtual void UsedBy(cPlayer * a_Player) override; + virtual void SendTo(cClientHandle & a_Client) override; + + static const char * GetClassStatic(void) { return "cSkullEntity"; } + +private: + + eSkullType m_SkullType; + eSkullRotation m_Rotation; + AString m_Owner; +} ; // tolua_export + + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6ba952f92..e46aa3ee5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,7 @@ if (NOT MSVC) BlockEntities/JukeboxEntity.h BlockEntities/NoteEntity.h BlockEntities/SignEntity.h + BlockEntities/SkullEntity.h BlockID.h BoundingBox.h ChatColor.h diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 3028d24d0..c66dae7b4 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1314,6 +1314,7 @@ void cChunk::CreateBlockEntities(void) case E_BLOCK_HOPPER: case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: + case E_BLOCK_HEAD: case E_BLOCK_NOTE_BLOCK: case E_BLOCK_JUKEBOX: { @@ -1442,6 +1443,7 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, case E_BLOCK_HOPPER: case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: + case E_BLOCK_HEAD: case E_BLOCK_NOTE_BLOCK: case E_BLOCK_JUKEBOX: { diff --git a/src/Defines.h b/src/Defines.h index f33d1ae56..7e22cbdc5 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -174,6 +174,43 @@ enum eWeather +enum eSkullType +{ + SKULL_TYPE_SKELETON = 0, + SKULL_TYPE_WITHER = 1, + SKULL_TYPE_ZOMBIE = 2, + SKULL_TYPE_PLAYER = 3, + SKULL_TYPE_CREEPER = 4, +} ; + + + + + +enum eSkullRotation +{ + SKULL_ROTATION_NORTH = 0, + SKULL_ROTATION_NORTH_NORTH_EAST = 1, + SKULL_ROTATION_NORTH_EAST = 2, + SKULL_ROTATION_EAST_NORTH_EAST = 3, + SKULL_ROTATION_EAST = 4, + SKULL_ROTATION_EAST_SOUTH_EAST = 5, + SKULL_ROTATION_SOUTH_EAST = 6, + SKULL_ROTATION_SOUTH_SOUTH_EAST = 7, + SKULL_ROTATION_SOUTH = 8, + SKULL_ROTATION_SOUTH_SOUTH_WEST = 9, + SKULL_ROTATION_SOUTH_WEST = 10, + SKULL_ROTATION_WEST_SOUTH_WEST = 11, + SKULL_ROTATION_WEST = 12, + SKULL_ROTATION_WEST_NORTH_WEST = 13, + SKULL_ROTATION_NORTH_WEST = 14, + SKULL_ROTATION_NORTH_NORTH_WEST = 15, +} ; + + + + + inline const char * ClickActionToString(eClickAction a_ClickAction) { switch (a_ClickAction) diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 19913ab24..4ede75cf1 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -35,6 +35,7 @@ #include "ItemShears.h" #include "ItemShovel.h" #include "ItemSign.h" +#include "ItemSkull.h" #include "ItemSpawnEgg.h" #include "ItemSugarcane.h" #include "ItemSword.h" @@ -110,6 +111,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType); case E_ITEM_SIGN: return new cItemSignHandler(a_ItemType); + case E_ITEM_HEAD: return new cItemSkullHandler(a_ItemType); case E_ITEM_SNOWBALL: return new cItemSnowballHandler(); case E_ITEM_SPAWN_EGG: return new cItemSpawnEggHandler(a_ItemType); case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemType); diff --git a/src/Items/ItemSkull.h b/src/Items/ItemSkull.h new file mode 100644 index 000000000..f511c8c4a --- /dev/null +++ b/src/Items/ItemSkull.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemSkullHandler : + public cItemHandler +{ +public: + cItemSkullHandler(int a_ItemType) : + cItemHandler(a_ItemType) + { + } + + + virtual bool IsPlaceable(void) override + { + return true; + } + + + virtual bool GetPlacementBlockTypeMeta( + cWorld * a_World, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = E_BLOCK_HEAD; + a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); + + return true; + } +} ; + + + + diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index f7d13774d..4d55822fb 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -26,6 +26,7 @@ Implements the 1.7.x protocol classes: #include "../Mobs/IncludeAllMonsters.h" #include "../UI/Window.h" #include "../BlockEntities/CommandBlockEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "../CompositeChat.h" @@ -1042,6 +1043,7 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text + case E_BLOCK_HEAD: Action = 4; break; // Update Skull entity default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break; } Pkt.WriteByte(Action); @@ -2269,6 +2271,18 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt } break; } + case E_BLOCK_HEAD: + { + cSkullEntity & SkullEntity = (cSkullEntity &)a_BlockEntity; + + Writer.AddInt("x", SkullEntity.GetPosX()); + Writer.AddInt("y", SkullEntity.GetPosY()); + Writer.AddInt("z", SkullEntity.GetPosZ()); + Writer.AddByte("SkullType", SkullEntity.GetSkullType() & 0xFF); + Writer.AddByte("Rot", SkullEntity.GetRotation() & 0xFF); + Writer.AddString("ExtraType", SkullEntity.GetOwner().c_str()); + Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though + } default: break; } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 95b5e66d2..6da141728 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -19,6 +19,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "../Entities/Entity.h" #include "../Entities/FallingBlock.h" @@ -248,11 +249,25 @@ void cNBTChunkSerializer::AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock void cNBTChunkSerializer::AddSignEntity(cSignEntity * a_Sign) { m_Writer.BeginCompound(""); - AddBasicTileEntity(a_Sign, "Sign"); - m_Writer.AddString("Text1", a_Sign->GetLine(0)); - m_Writer.AddString("Text2", a_Sign->GetLine(1)); - m_Writer.AddString("Text3", a_Sign->GetLine(2)); - m_Writer.AddString("Text4", a_Sign->GetLine(3)); + AddBasicTileEntity(a_Sign, "Sign"); + m_Writer.AddString("Text1", a_Sign->GetLine(0)); + m_Writer.AddString("Text2", a_Sign->GetLine(1)); + m_Writer.AddString("Text3", a_Sign->GetLine(2)); + m_Writer.AddString("Text4", a_Sign->GetLine(3)); + m_Writer.EndCompound(); +} + + + + + +void cNBTChunkSerializer::AddSkullEntity(cSkullEntity * a_Skull) +{ + m_Writer.BeginCompound(""); + AddBasicTileEntity(a_Skull, "Skull"); + m_Writer.AddByte ("SkullType", a_Skull->GetSkullType() & 0xFF); + m_Writer.AddByte ("Rot", a_Skull->GetRotation() & 0xFF); + m_Writer.AddString("ExtraType", a_Skull->GetOwner()); m_Writer.EndCompound(); } @@ -666,6 +681,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: AddSignEntity ((cSignEntity *) a_Entity); break; + case E_BLOCK_HEAD: AddSkullEntity ((cSkullEntity *) a_Entity); break; case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break; case E_BLOCK_JUKEBOX: AddJukeboxEntity ((cJukeboxEntity *) a_Entity); break; case E_BLOCK_COMMAND_BLOCK: AddCommandBlockEntity((cCommandBlockEntity *) a_Entity); break; diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index 245b68063..fd5601e47 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -29,6 +29,7 @@ class cHopperEntity; class cJukeboxEntity; class cNoteEntity; class cSignEntity; +class cSkullEntity; class cFallingBlock; class cMinecart; class cMinecartWithChest; @@ -93,6 +94,7 @@ protected: void AddJukeboxEntity (cJukeboxEntity * a_Jukebox); void AddNoteEntity (cNoteEntity * a_Note); void AddSignEntity (cSignEntity * a_Sign); + void AddSkullEntity (cSkullEntity * a_Skull); void AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock); // Entities: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index e95813a3c..89a236f07 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -24,6 +24,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "../Mobs/Monster.h" @@ -597,6 +598,10 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con { LoadSignFromNBT(a_BlockEntities, a_NBT, Child); } + else if (strncmp(a_NBT.GetData(sID), "Skull", a_NBT.GetDataLength(sID)) == 0) + { + LoadSkullFromNBT(a_BlockEntities, a_NBT, Child); + } else if (strncmp(a_NBT.GetData(sID), "Trap", a_NBT.GetDataLength(sID)) == 0) { LoadDispenserFromNBT(a_BlockEntities, a_NBT, Child); @@ -927,6 +932,41 @@ void cWSSAnvil::LoadSignFromNBT(cBlockEntityList & a_BlockEntities, const cParse +void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); + int x, y, z; + if (!GetBlockEntityNBTPos(a_NBT, a_TagIdx, x, y, z)) + { + return; + } + std::auto_ptr Skull(new cSkullEntity(E_BLOCK_HEAD, x, y, z, m_World)); + + int currentLine = a_NBT.FindChildByName(a_TagIdx, "SkullType"); + if (currentLine >= 0) + { + Skull->SetSkullType(static_cast(a_NBT.GetByte(currentLine))); + } + + currentLine = a_NBT.FindChildByName(a_TagIdx, "Rot"); + if (currentLine >= 0) + { + Skull->SetRotation(static_cast(a_NBT.GetByte(currentLine))); + } + + currentLine = a_NBT.FindChildByName(a_TagIdx, "ExtraType"); + if (currentLine >= 0) + { + Skull->SetOwner(a_NBT.GetString(currentLine)); + } + + a_BlockEntities.push_back(Skull.release()); +} + + + + + void cWSSAnvil::LoadCommandBlockFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) { ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 5093ad083..9c9e17258 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -139,6 +139,7 @@ protected: void LoadJukeboxFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadNoteFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadSignFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadSkullFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadCommandBlockFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength); -- cgit v1.2.3 From 865ae82114c7c567f3d2580f648979ad5101e0db Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 17 Feb 2014 23:12:46 +0100 Subject: Add Lua plugin path to package.path and .cpath. Fixes #693. --- src/Bindings/LuaState.cpp | 26 ++++++++++++++++++++++++++ src/Bindings/LuaState.h | 3 +++ src/Bindings/PluginLua.cpp | 8 ++++++++ 3 files changed, 37 insertions(+) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index c6be7be3c..ca7f6b255 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -173,6 +173,31 @@ void cLuaState::Detach(void) +void cLuaState::AddPackagePath(const AString & a_PathVariable, const AString & a_Path) +{ + // Get the current path: + lua_getfield(m_LuaState, LUA_GLOBALSINDEX, "package"); // Stk: + lua_getfield(m_LuaState, -1, a_PathVariable.c_str()); // Stk: + size_t len = 0; + const char * PackagePath = lua_tolstring(m_LuaState, -1, &len); + + // Append the new path: + AString NewPackagePath(PackagePath, len); + NewPackagePath.append(LUA_PATHSEP); + NewPackagePath.append(a_Path); + + // Set the new path to the environment: + lua_pop(m_LuaState, 1); // Stk: + lua_pushlstring(m_LuaState, NewPackagePath.c_str(), NewPackagePath.length()); // Stk: + lua_setfield(m_LuaState, -2, a_PathVariable.c_str()); // Stk: + lua_pop(m_LuaState, 1); + lua_pop(m_LuaState, 1); // Stk: - +} + + + + + bool cLuaState::LoadFile(const AString & a_FileName) { ASSERT(IsValid()); @@ -1251,6 +1276,7 @@ void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header) case LUA_TLIGHTUSERDATA: Printf(Value, "%p", lua_touserdata(a_LuaState, i)); break; case LUA_TNUMBER: Printf(Value, "%f", (double)lua_tonumber(a_LuaState, i)); break; case LUA_TSTRING: Printf(Value, "%s", lua_tostring(a_LuaState, i)); break; + case LUA_TTABLE: Printf(Value, "%p", lua_topointer(a_LuaState, i)); break; default: break; } LOGD(" Idx %d: type %d (%s) %s", i, Type, lua_typename(a_LuaState, Type), Value.c_str()); diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index b9bf10142..dcb660c3f 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -154,6 +154,9 @@ public: /** Returns true if the m_LuaState is valid */ bool IsValid(void) const { return (m_LuaState != NULL); } + /** Adds the specified path to package. */ + void AddPackagePath(const AString & a_PathVariable, const AString & a_Path); + /** Loads the specified file Returns false and logs a warning to the console if not successful (but the LuaState is kept open). m_SubsystemName is displayed in the warning log message. diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 773d522c4..45c8216be 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -82,6 +82,14 @@ bool cPluginLua::Initialize(void) lua_pushstring(m_LuaState, GetName().c_str()); lua_setglobal(m_LuaState, LUA_PLUGIN_NAME_VAR_NAME); + // Add the plugin's folder to the package.path and package.cpath variables (#693): + m_LuaState.AddPackagePath("path", FILE_IO_PREFIX + GetLocalFolder() + "/?.lua"); + #ifdef _WIN32 + m_LuaState.AddPackagePath("cpath", GetLocalFolder() + "\\?.dll"); + #else + m_LuaState.AddPackagePath("cpath", FILE_IO_PREFIX + GetLocalFolder() + "/?.so"); + #endif + tolua_pushusertype(m_LuaState, this, "cPluginLua"); lua_setglobal(m_LuaState, "g_Plugin"); } -- cgit v1.2.3 From 1a26f05ed0e81cb0c2cbd17ee4eb6022f094438e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 17 Feb 2014 23:36:39 +0100 Subject: Added cPluginManager:GetPluginsPath() to the Lua API. --- src/Bindings/PluginManager.cpp | 2 +- src/Bindings/PluginManager.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index c6c8c081e..c7df6357e 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -56,7 +56,7 @@ void cPluginManager::ReloadPlugins(void) void cPluginManager::FindPlugins(void) { - AString PluginsPath = FILE_IO_PREFIX + AString( "Plugins/" ); + AString PluginsPath = GetPluginsPath() + "/"; // First get a clean list of only the currently running plugins, we don't want to mess those up for (PluginMap::iterator itr = m_Plugins.begin(); itr != m_Plugins.end();) diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index c78bceda1..44bc5a8d7 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -266,6 +266,10 @@ public: // tolua_export Returns false if plugin not found, and the value that the callback has returned otherwise. */ bool DoWithPlugin(const AString & a_PluginName, cPluginCallback & a_Callback); + /** Returns the path where individual plugins' folders are expected. + The path doesn't end in a slash. */ + static AString GetPluginsPath(void) { return FILE_IO_PREFIX + AString("Plugins"); } // tolua_export + private: friend class cRoot; -- cgit v1.2.3 From 89ef81b5e887d5abdace921974f2863926778824 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 17 Feb 2014 23:39:53 +0100 Subject: Documented the cPluginManager:GetPluginsPath() API function. --- MCServer/Plugins/APIDump/APIDesc.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 34aff5ddb..b0d31e7a8 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1749,6 +1749,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); GetCurrentPlugin = { Params = "", Return = "{{cPlugin}}", Notes = "Returns the {{cPlugin}} object for the calling plugin. This is the same object that the Initialize function receives as the argument." }, GetNumPlugins = { Params = "", Return = "number", Notes = "Returns the number of plugins, including the disabled ones" }, GetPlugin = { Params = "PluginName", Return = "{{cPlugin}}", Notes = "(DEPRECATED, UNSAFE) Returns a plugin handle of the specified plugin, or nil if such plugin is not loaded. Note thatdue to multithreading the handle is not guaranteed to be safe for use when stored - a single-plugin reload may have been triggered in the mean time for the requested plugin." }, + GetPluginsPath = { Params = "", Return = "string", Notes = "Returns the path where the individual plugin folders are located. Doesn't include the path separator at the end of the returned string." }, IsCommandBound = { Params = "Command", Return = "bool", Notes = "Returns true if in-game Command is already bound (by any plugin)" }, IsConsoleCommandBound = { Params = "Command", Return = "bool", Notes = "Returns true if console Command is already bound (by any plugin)" }, LoadPlugin = { Params = "PluginFolder", Return = "", Notes = "(DEPRECATED) Loads a plugin from the specified folder. NOTE: Loading plugins may be an unsafe operation and may result in a deadlock or a crash. This API is deprecated and might be removed." }, -- cgit v1.2.3 From e924d102e1a03cf148dde57cd35655faeda437e3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 17 Feb 2014 23:41:48 +0100 Subject: Added the InfoReg plugin library file. This file should be used by all plugins that use Info.lua to register their commands. It defines the functions that register the commands and provide handling for the subcommands. --- MCServer/Plugins/InfoReg.lua | 157 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 MCServer/Plugins/InfoReg.lua diff --git a/MCServer/Plugins/InfoReg.lua b/MCServer/Plugins/InfoReg.lua new file mode 100644 index 000000000..3afb57488 --- /dev/null +++ b/MCServer/Plugins/InfoReg.lua @@ -0,0 +1,157 @@ + +-- InfoReg.lua + +-- Implements registration functions that process g_PluginInfo + + + + + +--- Lists all the subcommands that the player has permissions for +local function ListSubcommands(a_Player, a_Subcommands, a_CmdString) + a_Player:SendMessage("The " .. a_CmdString .. " command requires another verb:"); + local Verbs = {}; + for cmd, info in pairs(a_Subcommands) do + if (a_Player:HasPermission(info.Permission or "")) then + table.insert(Verbs, a_CmdString .. " " .. cmd); + end + end + table.sort(Verbs); + for idx, verb in ipairs(Verbs) do + a_Player:SendMessage(verb); + end +end + + + + + +--- This is a generic command callback used for handling multicommands' parent commands +-- For example, if there are "/gal save" and "/gal load" commands, this callback handles the "/gal" command +local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_Level) + local Verb = a_Split[a_Level + 1]; + if (Verb == nil) then + -- No verb was specified. If there is a handler for the upper level command, call it: + if (a_CmdInfo.Handler ~= nil) then + return a_CmdInfo.Handler(a_Split, a_Player); + end + -- Let the player know they need to give a subcommand: + ListSubcommands(a_Player, a_CmdInfo.Subcommands, a_CmdString); + return true; + end + + -- A verb was specified, look it up in the subcommands table: + local Subcommand = a_CmdInfo.Subcommands[Verb]; + if (Subcommand == nil) then + if (a_Level > 1) then + -- This is a true subcommand, display the message and make MCS think the command was handled + -- Otherwise we get weird behavior: for "/cmd verb" we get "unknown command /cmd" although "/cmd" is valid + a_Player:SendMessage("The " .. a_CmdString .. " command doesn't support verb " .. Verb); + return true; + end + -- This is a top-level command, let MCS handle the unknown message + return false; + end + + -- Check the permission: + if not(a_Player:HasPermission(Subcommand.Permission or "")) then + a_Player:SendMessage("You don't have permission to execute this command"); + return true; + end + + -- Check if the handler is valid: + if (Subcommand.Handler == nil) then + if (Subcommand.Subcommands == nil) then + LOG("Cannot find handler for command " .. a_CmdString .. " " .. Verb); + return false; + end + ListSubcommands(a_Player, Subcommand.Subcommands, a_CmdString .. " " .. Verb); + return true; + end + + -- Execute: + return Subcommand.Handler(a_Split, a_Player); +end + + + + + +--- Registers all commands specified in the g_PluginInfo.Commands +function RegisterPluginInfoCommands() + -- A sub-function that registers all subcommands of a single command, using the command's Subcommands table + -- The a_Prefix param already contains the space after the previous command + -- a_Level is the depth of the subcommands being registered, with 1 being the top level command + local function RegisterSubcommands(a_Prefix, a_Subcommands, a_Level) + assert(a_Subcommands ~= nil); + + for cmd, info in pairs(a_Subcommands) do + local CmdName = a_Prefix .. cmd; + local Handler = info.Handler; + -- Provide a special handler for multicommands: + if (info.Subcommands ~= nil) then + Handler = function(a_Split, a_Player) + return MultiCommandHandler(a_Split, a_Player, CmdName, info, a_Level); + end + end + + if (Handler == nil) then + LOGWARNING(g_PluginInfo.Name .. ": Invalid handler for command " .. CmdName .. ", command will not be registered."); + else + local HelpString; + if (info.HelpString ~= nil) then + HelpString = " - " .. info.HelpString; + else + HelpString = ""; + end + cPluginManager.BindCommand(CmdName, info.Permission or "", Handler, HelpString); + -- Register all aliases for the command: + if (info.Alias ~= nil) then + if (type(info.Alias) == "string") then + info.Alias = {info.Alias}; + end + for idx, alias in ipairs(info.Alias) do + cPluginManager.BindCommand(a_Prefix .. alias, info.Permission or "", Handler, HelpString); + end + end + end + + -- Recursively register any subcommands: + if (info.Subcommands ~= nil) then + RegisterSubcommands(a_Prefix .. cmd .. " ", info.Subcommands, a_Level + 1); + end + end + end + + -- Loop through all commands in the plugin info, register each: + RegisterSubcommands("", g_PluginInfo.Commands, 1); +end + + + + + +--- Registers all console commands specified in the g_PluginInfo.ConsoleCommands +function RegisterPluginInfoConsoleCommands() + -- A sub-function that registers all subcommands of a single command, using the command's Subcommands table + -- The a_Prefix param already contains the space after the previous command + local function RegisterSubcommands(a_Prefix, a_Subcommands) + assert(a_Subcommands ~= nil); + + for cmd, info in pairs(a_Subcommands) do + local CmdName = a_Prefix .. cmd; + cPluginManager.BindConsoleCommand(cmd, info.Handler, info.HelpString or ""); + -- Recursively register any subcommands: + if (info.Subcommands ~= nil) then + RegisterSubcommands(a_Prefix .. cmd .. " ", info.Subcommands); + end + end + end + + -- Loop through all commands in the plugin info, register each: + RegisterSubcommands("", g_PluginInfo.ConsoleCommands); +end + + + + -- cgit v1.2.3 From 464ec47eb7bf61ca1e9c2af6559ad2225038d06e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 17 Feb 2014 23:00:03 +0000 Subject: Implemented item frames, a part of #689 + Implemented Item Frames * Fixed Pitch and Yaw being wrongly flipped in the protocol (XOFT!) --- src/Entities/Entity.h | 2 + src/Entities/ItemFrame.cpp | 109 ++++++++++++++++++++++++++++++++ src/Entities/ItemFrame.h | 42 ++++++++++++ src/Items/ItemHandler.cpp | 3 + src/Items/ItemItemFrame.h | 62 ++++++++++++++++++ src/Protocol/Protocol17x.cpp | 16 ++++- src/WorldStorage/NBTChunkSerializer.cpp | 1 + 7 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 src/Entities/ItemFrame.cpp create mode 100644 src/Entities/ItemFrame.h create mode 100644 src/Items/ItemItemFrame.h diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index b2edfc2b4..79150ee51 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -81,6 +81,7 @@ public: etProjectile, etExpOrb, etFloater, + etItemFrame, // Common variations etMob = etMonster, // DEPRECATED, use etMonster instead! @@ -139,6 +140,7 @@ public: bool IsProjectile (void) const { return (m_EntityType == etProjectile); } bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); } bool IsFloater (void) const { return (m_EntityType == etFloater); } + bool IsItemFrame (void) const { return (m_EntityType == etItemFrame); } /// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true) virtual bool IsA(const char * a_ClassName) const; diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp new file mode 100644 index 000000000..e4e50bd8d --- /dev/null +++ b/src/Entities/ItemFrame.cpp @@ -0,0 +1,109 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ItemFrame.h" +#include "ClientHandle.h" +#include "Player.h" + + + + + +cItemFrame::cItemFrame(int a_BlockFace, double a_X, double a_Y, double a_Z) + : cEntity(etItemFrame, a_X, a_Y, a_Z, 0.8, 0.8), + m_BlockFace(a_BlockFace), + m_Item(E_BLOCK_AIR), + m_Rotation(0) +{ + SetMaxHealth(1); + SetHealth(1); + + if ((a_BlockFace == 0) || (a_BlockFace == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180 + { + SetYaw((a_BlockFace * 90) - 180); + } + else + { + SetYaw(a_BlockFace * 90); + } +} + + + + + +void cItemFrame::SpawnOn(cClientHandle & a_ClientHandle) +{ + a_ClientHandle.SendSpawnObject(*this, 71, m_BlockFace, (Byte)GetYaw(), (Byte)GetPitch()); +} + + + + + +void cItemFrame::OnRightClicked(cPlayer & a_Player) +{ + if (!m_Item.IsEmpty()) + { + // Item not empty, rotate, clipping values to zero to three inclusive + m_Rotation++; + if (m_Rotation >= 4) + m_Rotation = 0; + } + else if (!a_Player.GetEquippedItem().IsEmpty()) + { + // Item empty, and player held item not empty - add this item to self + m_Item = a_Player.GetEquippedItem(); + m_Item.m_ItemCount = 1; + + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + } + } + + GetWorld()->BroadcastEntityMetadata(*this); // Update clients +} + + + + + + +void cItemFrame::KilledBy(cEntity * a_Killer) +{ + if (m_Item.IsEmpty()) + { + super::KilledBy(a_Killer); + Destroy(); + return; + } + + if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative()) + { + cItems Item; + Item.push_back(m_Item); + + GetWorld()->SpawnItemPickups(Item, GetPosX(), GetPosY(), GetPosZ()); + } + + SetHealth(GetMaxHealth()); + m_Item.Clear(); + GetWorld()->BroadcastEntityMetadata(*this); +} + + + + + +void cItemFrame::GetDrops(cItems & a_Items, cEntity * a_Killer) +{ + if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative()) + { + a_Items.push_back(cItem(E_ITEM_ITEM_FRAME)); + } +} + + + + diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h new file mode 100644 index 000000000..15a03e54a --- /dev/null +++ b/src/Entities/ItemFrame.h @@ -0,0 +1,42 @@ + +#pragma once + +#include "Entity.h" + + + + + +// tolua_begin +class cItemFrame : + public cEntity +{ + // tolua_end + typedef cEntity super; + +public: + + CLASS_PROTODEF(cItemFrame); + + cItemFrame(int a_BlockFace, double a_X, double a_Y, double a_Z); + + const cItem & GetItem(void) { return m_Item; } + Byte GetRotation(void) const { return m_Rotation; } + +private: + + virtual void SpawnOn(cClientHandle & a_ClientHandle) override; + virtual void OnRightClicked(cPlayer & a_Player) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override {}; + virtual void KilledBy(cEntity * a_Killer) override; + virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override; + + int m_BlockFace; + cItem m_Item; + Byte m_Rotation; + +}; // tolua_export + + + + diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 19913ab24..da1cd768d 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -21,6 +21,7 @@ #include "ItemFishingRod.h" #include "ItemFlowerPot.h" #include "ItemFood.h" +#include "ItemItemFrame.h" #include "ItemHoe.h" #include "ItemLeaves.h" #include "ItemLighter.h" @@ -105,6 +106,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_FISHING_ROD: return new cItemFishingRodHandler(a_ItemType); case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType); case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType); + case E_ITEM_ITEM_FRAME: return new cItemItemFrameHandler(a_ItemType); case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType); case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemType); case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); @@ -342,6 +344,7 @@ char cItemHandler::GetMaxStackSize(void) case E_ITEM_GUNPOWDER: return 64; case E_ITEM_HEAD: return 64; case E_ITEM_IRON: return 64; + case E_ITEM_ITEM_FRAME: return 64; case E_ITEM_LEATHER: return 64; case E_ITEM_MAGMA_CREAM: return 64; case E_ITEM_MAP: return 64; diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h new file mode 100644 index 000000000..39be48b54 --- /dev/null +++ b/src/Items/ItemItemFrame.h @@ -0,0 +1,62 @@ + +#pragma once + +#include "ItemHandler.h" +#include "Entities/ItemFrame.h" +#include "../Entities/Player.h" + + + + + +class cItemItemFrameHandler : + public cItemHandler +{ +public: + cItemItemFrameHandler(int a_ItemType) + : cItemHandler(a_ItemType) + { + + } + + virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override + { + if (a_Dir == BLOCK_FACE_NONE) + { + return false; + } + + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir); + BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir, true); + + if (Block == E_BLOCK_AIR) + { + int Dir = 0; + switch (a_Dir) + { + case BLOCK_FACE_SOUTH: break; + case BLOCK_FACE_NORTH: Dir = 2; break; + case BLOCK_FACE_WEST: Dir = 1; break; + case BLOCK_FACE_EAST: Dir = 3; break; + default: return false; + } + + cItemFrame * ItemFrame = new cItemFrame(Dir, a_BlockX, a_BlockY, a_BlockZ); + ItemFrame->Initialize(a_World); + + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); + } + + return true; + + } + return false; + } +}; + + + + diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index f7d13774d..57a56d1a4 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -23,6 +23,7 @@ Implements the 1.7.x protocol classes: #include "../Entities/FallingBlock.h" #include "../Entities/Pickup.h" #include "../Entities/Player.h" +#include "../Entities/ItemFrame.h" #include "../Mobs/IncludeAllMonsters.h" #include "../UI/Window.h" #include "../BlockEntities/CommandBlockEntity.h" @@ -923,8 +924,8 @@ void cProtocol172::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, Pkt.WriteFPInt(a_Entity.GetPosX()); Pkt.WriteFPInt(a_Entity.GetPosY()); Pkt.WriteFPInt(a_Entity.GetPosZ()); - Pkt.WriteByteAngle(a_Entity.GetYaw()); Pkt.WriteByteAngle(a_Entity.GetPitch()); + Pkt.WriteByteAngle(a_Entity.GetYaw()); Pkt.WriteInt(a_ObjectData); if (a_ObjectData != 0) { @@ -946,8 +947,8 @@ void cProtocol172::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp Pkt.WriteFPInt(a_Vehicle.GetPosX()); Pkt.WriteFPInt(a_Vehicle.GetPosY()); Pkt.WriteFPInt(a_Vehicle.GetPosZ()); - Pkt.WriteByteAngle(a_Vehicle.GetYaw()); Pkt.WriteByteAngle(a_Vehicle.GetPitch()); + Pkt.WriteByteAngle(a_Vehicle.GetYaw()); Pkt.WriteInt(a_VehicleSubType); if (a_VehicleSubType != 0) { @@ -2391,6 +2392,16 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity) WriteMobMetadata((const cMonster &)a_Entity); break; } + case cEntity::etItemFrame: + { + cItemFrame & Frame = (cItemFrame &)a_Entity; + WriteByte(0xA2); + WriteItem(Frame.GetItem()); + WriteByte(0x3); + WriteByte(Frame.GetRotation()); + break; + } + default: break; } } @@ -2575,6 +2586,7 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob) WriteInt(Horse.GetHorseArmour()); break; } + default: break; } // switch (a_Mob.GetType()) } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 95b5e66d2..4f1e88b21 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -627,6 +627,7 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity) case cEntity::etProjectile: AddProjectileEntity ((cProjectileEntity *)a_Entity); break; case cEntity::etTNT: /* TODO */ break; case cEntity::etExpOrb: /* TODO */ break; + case cEntity::etItemFrame: /* TODO */ break; case cEntity::etPlayer: return; // Players aren't saved into the world default: { -- cgit v1.2.3 From 7c0d11fbb28730a328d0cb422760cb252eb8d73f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 17 Feb 2014 23:38:25 +0000 Subject: Used new BLOCK_FACE constants Also added more comments --- src/Items/ItemItemFrame.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h index 39be48b54..a403778ad 100644 --- a/src/Items/ItemItemFrame.h +++ b/src/Items/ItemItemFrame.h @@ -23,23 +23,24 @@ public: { if (a_Dir == BLOCK_FACE_NONE) { + // Client sends this if clicked on top or bottom face return false; } - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir); // Make sure block that will be occupied is free BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir, true); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir, true); // We want the clicked block, so go back again if (Block == E_BLOCK_AIR) { int Dir = 0; switch (a_Dir) { - case BLOCK_FACE_SOUTH: break; - case BLOCK_FACE_NORTH: Dir = 2; break; - case BLOCK_FACE_WEST: Dir = 1; break; - case BLOCK_FACE_EAST: Dir = 3; break; - default: return false; + case BLOCK_FACE_ZP: break; // Initialised to zero + case BLOCK_FACE_ZM: Dir = 2; break; + case BLOCK_FACE_XM: Dir = 1; break; + case BLOCK_FACE_XP: Dir = 3; break; + default: ASSERT(!"Unhandled block face when trying spawn item frame!"); return false; } cItemFrame * ItemFrame = new cItemFrame(Dir, a_BlockX, a_BlockY, a_BlockZ); -- cgit v1.2.3 From fb963b6393b1af693a62315e2440dc503ec3648a Mon Sep 17 00:00:00 2001 From: narroo Date: Mon, 17 Feb 2014 19:05:11 -0500 Subject: Issue #673 Fix, Chunkworx now uses QueueUnloadUnusedChunks instead of UnloadUnusedChunks. --- MCServer/Plugins/ChunkWorx/chunkworx_main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/ChunkWorx/chunkworx_main.lua b/MCServer/Plugins/ChunkWorx/chunkworx_main.lua index f74c4ea2d..88ecb3979 100644 --- a/MCServer/Plugins/ChunkWorx/chunkworx_main.lua +++ b/MCServer/Plugins/ChunkWorx/chunkworx_main.lua @@ -122,7 +122,7 @@ function OnTick( DeltaTime ) end end WW_instance:QueueSaveAllChunks() - WW_instance:UnloadUnusedChunks() + WW_instance:QueueUnloadUnusedChunks() end end end \ No newline at end of file -- cgit v1.2.3 From 66cfd29ddca3c61047403422c42fa53682a605a0 Mon Sep 17 00:00:00 2001 From: narroo Date: Mon, 17 Feb 2014 19:12:31 -0500 Subject: Fixed Chunkworx, Issue 673. --- MCServer/Plugins/ChunkWorx/chunkworx_web.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/ChunkWorx/chunkworx_web.lua b/MCServer/Plugins/ChunkWorx/chunkworx_web.lua index 44993f81c..6c5eab676 100644 --- a/MCServer/Plugins/ChunkWorx/chunkworx_web.lua +++ b/MCServer/Plugins/ChunkWorx/chunkworx_web.lua @@ -44,7 +44,7 @@ function HandleRequest_Generation( Request ) if (Request.PostParams["AGHRRRR"] ~= nil) then GENERATION_STATE = 0 WW_instance:SaveAllChunks() - WW_instance:UnloadUnusedChunks() + WW_instance:QueueUnloadUnusedChunks() LOGERROR("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": works ABORTED by admin") end --Content = Content .. "" -- cgit v1.2.3 From 320cc74f0a1a8439f8f80a1fb45a19c950f42377 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 00:16:03 +0000 Subject: Implemented paintings, fixes #689 + Implemented paintings --- src/BlockID.h | 2 +- src/ClientHandle.cpp | 8 +++ src/ClientHandle.h | 2 + src/Entities/Entity.h | 2 + src/Entities/Painting.cpp | 43 +++++++++++++++ src/Entities/Painting.h | 42 +++++++++++++++ src/Items/ItemHandler.cpp | 6 ++- src/Items/ItemPainting.h | 95 +++++++++++++++++++++++++++++++++ src/Protocol/Protocol.h | 2 + src/Protocol/Protocol125.h | 1 + src/Protocol/Protocol17x.cpp | 15 ++++++ src/Protocol/Protocol17x.h | 1 + src/Protocol/ProtocolRecognizer.cpp | 8 +++ src/Protocol/ProtocolRecognizer.h | 1 + src/WorldStorage/NBTChunkSerializer.cpp | 1 + 15 files changed, 226 insertions(+), 3 deletions(-) create mode 100644 src/Entities/Painting.cpp create mode 100644 src/Entities/Painting.h create mode 100644 src/Items/ItemPainting.h diff --git a/src/BlockID.h b/src/BlockID.h index d5b3da672..740c5fc90 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -266,7 +266,7 @@ enum ENUM_ITEM_ID E_ITEM_FLINT = 318, E_ITEM_RAW_PORKCHOP = 319, E_ITEM_COOKED_PORKCHOP = 320, - E_ITEM_PAINTINGS = 321, + E_ITEM_PAINTING = 321, E_ITEM_GOLDEN_APPLE = 322, E_ITEM_SIGN = 323, E_ITEM_WOODEN_DOOR = 324, diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index c91a0c01b..84286fc41 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2091,6 +2091,14 @@ void cClientHandle::SendPickupSpawn(const cPickup & a_Pickup) +void cClientHandle::SendPaintingSpawn(const cPainting & a_Painting) +{ + m_Protocol->SendPaintingSpawn(a_Painting); +} + + + + void cClientHandle::SendEntityAnimation(const cEntity & a_Entity, char a_Animation) { diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 5faa94004..aefca7233 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -27,6 +27,7 @@ class cInventory; class cMonster; class cPawn; class cExpOrb; +class cPainting; class cPickup; class cPlayer; class cProtocol; @@ -111,6 +112,7 @@ public: void SendGameMode (eGameMode a_GameMode); void SendHealth (void); void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item); + void SendPaintingSpawn (const cPainting & a_Painting); void SendPickupSpawn (const cPickup & a_Pickup); void SendEntityAnimation (const cEntity & a_Entity, char a_Animation); void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount); diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index b2edfc2b4..29ffd949d 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -81,6 +81,7 @@ public: etProjectile, etExpOrb, etFloater, + etPainting, // Common variations etMob = etMonster, // DEPRECATED, use etMonster instead! @@ -139,6 +140,7 @@ public: bool IsProjectile (void) const { return (m_EntityType == etProjectile); } bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); } bool IsFloater (void) const { return (m_EntityType == etFloater); } + bool IsPainting (void) const { return (m_EntityType == etPainting); } /// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true) virtual bool IsA(const char * a_ClassName) const; diff --git a/src/Entities/Painting.cpp b/src/Entities/Painting.cpp new file mode 100644 index 000000000..b98c1e67a --- /dev/null +++ b/src/Entities/Painting.cpp @@ -0,0 +1,43 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Painting.h" +#include "ClientHandle.h" +#include "Player.h" + + + + + +cPainting::cPainting(const AString & a_Name, int a_Direction, double a_X, double a_Y, double a_Z) + : cEntity(etPainting, a_X, a_Y, a_Z, 1, 1), + m_Name(a_Name), + m_Direction(a_Direction) +{ +} + + + + + + +void cPainting::SpawnOn(cClientHandle & a_Client) +{ + a_Client.SendPaintingSpawn(*this); +} + + + + + +void cPainting::GetDrops(cItems & a_Items, cEntity * a_Killer) +{ + if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative()) + { + a_Items.push_back(cItem(E_ITEM_PAINTING)); + } +} + + + + diff --git a/src/Entities/Painting.h b/src/Entities/Painting.h new file mode 100644 index 000000000..f401dac79 --- /dev/null +++ b/src/Entities/Painting.h @@ -0,0 +1,42 @@ + +#pragma once + +#include "Entity.h" + + + + + +// tolua_begin +class cPainting : + public cEntity +{ + // tolua_end + typedef cEntity super; + +public: + CLASS_PROTODEF(cPainting); + + cPainting(const AString & a_Name, int a_Direction, double a_X, double a_Y, double a_Z); + const AString & GetName(void) const { return m_Name; } + int GetDirection(void) const { return m_Direction; } + +private: + + virtual void SpawnOn(cClientHandle & a_Client) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override {}; + virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override; + virtual void KilledBy(cEntity * a_Killer) override + { + super::KilledBy(a_Killer); + Destroy(); + } + + AString m_Name; + int m_Direction; + +}; // tolua_export + + + + diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 19913ab24..5ff74fc2c 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -26,6 +26,7 @@ #include "ItemLighter.h" #include "ItemMinecart.h" #include "ItemNetherWart.h" +#include "ItemPainting.h" #include "ItemPickaxe.h" #include "ItemThrowable.h" #include "ItemRedstoneDust.h" @@ -106,6 +107,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType); case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType); case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType); + case E_ITEM_PAINTING: return new cItemPaintingHandler(a_ItemType); case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemType); case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType); @@ -305,7 +307,7 @@ char cItemHandler::GetMaxStackSize(void) case E_ITEM_BOWL: return 64; case E_ITEM_BREAD: return 64; case E_ITEM_BREWING_STAND: return 64; - case E_ITEM_BUCKET: return 1; // TODO: change this to 16 when turning compatibility to 1.3 + case E_ITEM_BUCKET: return 16; case E_ITEM_CARROT: return 64; case E_ITEM_CAULDRON: return 64; case E_ITEM_CLAY: return 64; @@ -349,7 +351,7 @@ char cItemHandler::GetMaxStackSize(void) case E_ITEM_MELON_SLICE: return 64; case E_ITEM_NETHER_BRICK: return 64; case E_ITEM_NETHER_WART: return 64; - case E_ITEM_PAINTINGS: return 64; + case E_ITEM_PAINTING: return 64; case E_ITEM_PAPER: return 64; case E_ITEM_POISONOUS_POTATO: return 64; case E_ITEM_POTATO: return 64; diff --git a/src/Items/ItemPainting.h b/src/Items/ItemPainting.h new file mode 100644 index 000000000..53fc3809b --- /dev/null +++ b/src/Items/ItemPainting.h @@ -0,0 +1,95 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" +#include "../Entities/Player.h" +#include "../Entities/Painting.h" + + + + + +class cItemPaintingHandler : + public cItemHandler +{ +public: + cItemPaintingHandler(int a_ItemType) + : cItemHandler(a_ItemType) + { + } + + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override + { + if (a_Dir == BLOCK_FACE_NONE) + { + return false; + } + + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir); + BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir, true); + + if (Block == E_BLOCK_AIR) + { + int Dir = 0; + switch (a_Dir) + { + case BLOCK_FACE_SOUTH: break; + case BLOCK_FACE_NORTH: Dir = 2; break; + case BLOCK_FACE_WEST: Dir = 1; break; + case BLOCK_FACE_EAST: Dir = 3; break; + default: return false; + } + + static const struct // Define all the possible painting titles + { + AString Title; + } gPaintingTitlesList[] = + { + { "Kebab" }, + { "Aztec" }, + { "Alban" }, + { "Aztec2" }, + { "Bomb" }, + { "Plant" }, + { "Wasteland" }, + { "Wanderer" }, + { "Graham" }, + { "Pool" }, + { "Courbet" }, + { "Sunset" }, + { "Sea" }, + { "Creebet" }, + { "Match" }, + { "Bust" }, + { "Stage" }, + { "Void" }, + { "SkullAndRoses" }, + { "Wither" }, + { "Fighters" }, + { "Skeleton" }, + { "DonkeyKong" }, + { "Pointer" }, + { "Pigscene" }, + { "BurningSkull" } + }; + + cPainting * Painting = new cPainting(gPaintingTitlesList[a_World->GetTickRandomNumber(ARRAYCOUNT(gPaintingTitlesList) - 1)].Title, Dir, a_BlockX, a_BlockY, a_BlockZ); + Painting->Initialize(a_World); + + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); + } + + return true; + + } + return false; + } +}; + + + + diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index f5b9fd403..46b627254 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -24,6 +24,7 @@ class cWindow; class cInventory; class cPawn; class cPickup; +class cPainting; class cWorld; class cMonster; class cChunkDataSerializer; @@ -81,6 +82,7 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0; virtual void SendKeepAlive (int a_PingID) = 0; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0; + virtual void SendPaintingSpawn (const cPainting & a_Painting) = 0; virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0; virtual void SendPlayerAbilities (void) = 0; virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) = 0; diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 1a3209333..54551ea5f 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -56,6 +56,7 @@ public: virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override; + virtual void SendPaintingSpawn (const cPainting & a_Painting) override {}; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override {} // This protocol doesn't support such message virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index f7d13774d..7da19a14b 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -21,6 +21,7 @@ Implements the 1.7.x protocol classes: #include "../Entities/ExpOrb.h" #include "../Entities/Minecart.h" #include "../Entities/FallingBlock.h" +#include "../Entities/Painting.h" #include "../Entities/Pickup.h" #include "../Entities/Player.h" #include "../Mobs/IncludeAllMonsters.h" @@ -569,6 +570,20 @@ void cProtocol172::SendLogin(const cPlayer & a_Player, const cWorld & a_World) +void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting) +{ + cPacketizer Pkt(*this, 0x10); // Spawn Painting packet + Pkt.WriteVarInt(a_Painting.GetUniqueID()); + Pkt.WriteString(a_Painting.GetName().c_str()); + Pkt.WriteInt((int)a_Painting.GetPosX()); + Pkt.WriteInt((int)a_Painting.GetPosY()); + Pkt.WriteInt((int)a_Painting.GetPosZ()); + Pkt.WriteInt(a_Painting.GetDirection()); +} + + + + void cProtocol172::SendPickupSpawn(const cPickup & a_Pickup) { diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index d19be0f05..ae3577867 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -87,6 +87,7 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; + virtual void SendPaintingSpawn (const cPainting & a_Painting) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override; virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 6e51ee9cd..b658dc9db 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -405,6 +405,14 @@ void cProtocolRecognizer::SendParticleEffect(const AString & a_ParticleName, flo +void cProtocolRecognizer::SendPaintingSpawn(const cPainting & a_Painting) +{ + m_Protocol->SendPaintingSpawn(a_Painting); +} + + + + void cProtocolRecognizer::SendPickupSpawn(const cPickup & a_Pickup) { diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index 800163be6..abbb22827 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -91,6 +91,7 @@ public: virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override; + virtual void SendPaintingSpawn (const cPainting & a_Painting) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override; virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 95b5e66d2..8419bd646 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -627,6 +627,7 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity) case cEntity::etProjectile: AddProjectileEntity ((cProjectileEntity *)a_Entity); break; case cEntity::etTNT: /* TODO */ break; case cEntity::etExpOrb: /* TODO */ break; + case cEntity::etPainting: /* TODO */ break; case cEntity::etPlayer: return; // Players aren't saved into the world default: { -- cgit v1.2.3 From ced6eb971d1705330b5a47458a986efb87a8106b Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 00:28:31 +0000 Subject: Comments & new BLOCK_FACE constants --- src/Items/ItemPainting.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Items/ItemPainting.h b/src/Items/ItemPainting.h index 53fc3809b..b85098221 100644 --- a/src/Items/ItemPainting.h +++ b/src/Items/ItemPainting.h @@ -23,23 +23,26 @@ public: { if (a_Dir == BLOCK_FACE_NONE) { + // Client sends this if clicked on top or bottom face return false; } - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir); // Make sure block that will be occupied is free BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir, true); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir, true); // We want the clicked block, so go back again if (Block == E_BLOCK_AIR) { int Dir = 0; + + // The client uses different values for painting directions and block faces. Our constants are for the block faces, so we convert them here to painting faces switch (a_Dir) { - case BLOCK_FACE_SOUTH: break; - case BLOCK_FACE_NORTH: Dir = 2; break; - case BLOCK_FACE_WEST: Dir = 1; break; - case BLOCK_FACE_EAST: Dir = 3; break; - default: return false; + case BLOCK_FACE_ZP: break; // Initialised to zero + case BLOCK_FACE_ZM: Dir = 2; break; + case BLOCK_FACE_XM: Dir = 1; break; + case BLOCK_FACE_XP: Dir = 3; break; + default: ASSERT(!"Unhandled block face when trying spawn painting!"); return false; } static const struct // Define all the possible painting titles -- cgit v1.2.3 From 7a23e27fc532bdfed0038804b0060a6f7f5c0f54 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 00:29:10 +0000 Subject: Added an explanatory comment --- src/Items/ItemItemFrame.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h index a403778ad..f286fffd0 100644 --- a/src/Items/ItemItemFrame.h +++ b/src/Items/ItemItemFrame.h @@ -34,6 +34,8 @@ public: if (Block == E_BLOCK_AIR) { int Dir = 0; + + // The client uses different values for painting directions and block faces. Our constants are for the block faces, so we convert them here to painting faces switch (a_Dir) { case BLOCK_FACE_ZP: break; // Initialised to zero -- cgit v1.2.3 From 6788dbe7f21b3c46b1156e232041accf3d8ba200 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 11:37:45 +0000 Subject: Properly exported and documented paintings --- MCServer/Plugins/APIDump/APIDesc.lua | 18 ++++++++++++++++++ src/Bindings/AllToLua.pkg | 1 + src/CMakeLists.txt | 1 + src/Entities/Painting.h | 4 ++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index b0d31e7a8..33e98df69 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -713,6 +713,7 @@ end IsMinecart = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a {{cMinecart|minecart}}" }, IsMob = { Params = "", Return = "bool", Notes = "Returns true if the entity represents any {{cMonster|mob}}." }, IsOnFire = { Params = "", Return = "bool", Notes = "Returns true if the entity is on fire" }, + IsPainting = { Params = "", Return = "bool", Notes = "Returns if this entity is a painting." }, IsPickup = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a {{cPickup|pickup}}." }, IsPlayer = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a {{cPlayer|player}}" }, IsProjectile = { Params = "", Return = "bool", Notes = "Returns true if the entity is a {{cProjectileEntity}} descendant." }, @@ -779,6 +780,7 @@ end etPickup = { Notes = "The entity is a {{cPickup}}" }, etProjectile = { Notes = "The entity is a {{cProjectileEntity}} descendant" }, etTNT = { Notes = "The entity is a {{cTNTEntity}}" }, + etPainting = { Notes = "The entity is a {{cPainting}}" }, }, ConstantGroups = { @@ -1109,6 +1111,9 @@ These ItemGrids are available in the API and can be manipulated by the plugins, IsFullStack = { Params = "", Return = "bool", Notes = "Returns true if the item is stacked up to its maximum stacking" }, IsSameType = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is of the same ItemType as the one stored in the object. This is true even if the two items have different enchantments" }, IsStackableWith = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is stackable with the one stored in the object. Two items with different enchantments cannot be stacked" }, + IsBothNameAndLoreEmpty = { Params = "", Return = "bool", Notes = "Returns if both the custom name and lore are not set." }, + IsCustomNameEmpty = { Params = "", Return = "bool", Notes = "Returns if the custom name of the cItem is empty." }, + IsLoreEmpty = { Params = "", Return = "", Notes = "Returns if the lore of the cItem is empty." }, }, Variables = { @@ -1116,6 +1121,8 @@ These ItemGrids are available in the API and can be manipulated by the plugins, m_ItemCount = { Type = "number", Notes = "Number of items in this stack" }, m_ItemDamage = { Type = "number", Notes = "The damage of the item. Zero means no damage. Maximum damage can be queried with GetMaxDamage()" }, m_ItemType = { Type = "number", Notes = "The item type. One of E_ITEM_ or E_BLOCK_ constants" }, + m_CustomName = { Type = "string", Notes = "The custom name for an item." }, + m_Lore = { Type = "string", Notes = "The lore for an item. Line breaks are represented by the ` character." }, }, AdditionalInfo = { @@ -1160,6 +1167,17 @@ local Item5 = cItem(E_ITEM_DIAMOND_CHESTPLATE, 1, 0, "thorns=1;unbreaking=3"); }, }, -- cItem + cPainting = + { + Desc = "This class represents a painting in the world. These paintings are special and different from Vanilla in that they can be critical-hit.", + Functions = + { + GetDirection = { Params = "", Return = "number", Notes = "Returns the direction the painting faces. Directions: ZP - 0, ZM - 2, XM - 1, XP - 3. Note that these are not the BLOCK_FACE constants." }, + GetName = { Params = "", Return = "string", Notes = "Returns the name of the painting" }, + }, + + }, -- cPainting + cItemGrid = { Desc = [[This class represents a 2D array of items. It is used as the underlying storage and API for all cases that use a grid of items: diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 6c295102f..1f08c66dc 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -34,6 +34,7 @@ $cfile "../Entities/Entity.h" $cfile "../Entities/Floater.h" $cfile "../Entities/Pawn.h" $cfile "../Entities/Player.h" +$cfile "../Entities/Painting.h" $cfile "../Entities/Pickup.h" $cfile "../Entities/ProjectileEntity.h" $cfile "../Entities/TNTEntity.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6ba952f92..16bdad14e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,6 +52,7 @@ if (NOT MSVC) Entities/Entity.h Entities/Floater.h Entities/Pawn.h + Entities/Painting.h Entities/Pickup.h Entities/Player.h Entities/ProjectileEntity.h diff --git a/src/Entities/Painting.h b/src/Entities/Painting.h index f401dac79..95afbed1e 100644 --- a/src/Entities/Painting.h +++ b/src/Entities/Painting.h @@ -18,8 +18,8 @@ public: CLASS_PROTODEF(cPainting); cPainting(const AString & a_Name, int a_Direction, double a_X, double a_Y, double a_Z); - const AString & GetName(void) const { return m_Name; } - int GetDirection(void) const { return m_Direction; } + const AString & GetName(void) const { return m_Name; } // tolua_export + int GetDirection(void) const { return m_Direction; } // tolua_export private: -- cgit v1.2.3 From d5ee899d0e3039ace71077b5fe3d7e4a5c3601ad Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 11:44:09 +0000 Subject: Added a brace ==== { } { __ } { | | } ==== REMOVE ALL THE BRACES!! --- src/Entities/ItemFrame.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index e4e50bd8d..65b0edb25 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -48,7 +48,9 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player) // Item not empty, rotate, clipping values to zero to three inclusive m_Rotation++; if (m_Rotation >= 4) + { m_Rotation = 0; + } } else if (!a_Player.GetEquippedItem().IsEmpty()) { -- cgit v1.2.3 From 8ad4ab5bc103427a6ec993b48dbe211c2fc40da4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 12:48:25 +0000 Subject: Updated Core --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 5c8557d4f..3b416b07a 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 5c8557d4fdfa580c100510cde07a1a778ea2e244 +Subproject commit 3b416b07a339b3abcbc127070d56eea05b05373d -- cgit v1.2.3 From fc8743df9671172158d9d491843b8e208d3e25f3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 18 Feb 2014 08:25:29 +0100 Subject: Added a bit more documentation to cForEachChunkProvider. --- src/ForEachChunkProvider.h | 27 ++++++++++++++++++++++++++- src/World.h | 11 +++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/ForEachChunkProvider.h b/src/ForEachChunkProvider.h index 70cd2196a..6017173ee 100644 --- a/src/ForEachChunkProvider.h +++ b/src/ForEachChunkProvider.h @@ -1,14 +1,39 @@ +// ForEachChunkProvider.h + +// Declares the cForEachChunkProvider class which acts as an interface for classes that provide a ForEachChunkInRect() function +// Primarily serves as a decoupling between cBlockArea and cWorld + + + + + #pragma once -class cChunkDataCallback; + + +// fwd: +class cChunkDataCallback; class cBlockArea; + + + + class cForEachChunkProvider { public: + /** Calls the callback for each chunk in the specified range. */ virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) = 0; + /** Writes the block area into the specified coords. + Returns true if all chunks have been processed. + a_DataTypes is a bitmask of cBlockArea::baXXX constants ORed together. + */ virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) = 0; }; + + + + diff --git a/src/World.h b/src/World.h index 97358b88a..f885040ba 100644 --- a/src/World.h +++ b/src/World.h @@ -64,7 +64,10 @@ typedef cItemCallback cCommandBlockCallback; // tolua_begin -class cWorld : public cForEachChunkProvider, public cWorldInterface, public cBroadcastInterface +class cWorld : + public cForEachChunkProvider, + public cWorldInterface, + public cBroadcastInterface { public: @@ -401,15 +404,15 @@ public: Prefer cBlockArea::Write() instead, this is the internal implementation; cBlockArea does error checking, too. a_DataTypes is a bitmask of cBlockArea::baXXX constants ORed together. */ - virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes); + virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) override; // tolua_begin /** Spawns item pickups for each item in the list. May compress pickups if too many entities: */ - virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false); + virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false); // override; cannot specify it here due to tolua /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified: */ - virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false); + virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false); // override; cannot specify it here due to tolua /** Spawns an falling block entity at the given position. It returns the UniqueID of the spawned falling block. */ int SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta); -- cgit v1.2.3 From 803ea412361ee2f4b1d74a811ddbee05f50c9345 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 18 Feb 2014 13:06:18 +0100 Subject: Added cWorld:SetAreaBiome() API function. Fixes #675. --- src/Chunk.cpp | 32 +++++++++++++++++++++++++++++ src/Chunk.h | 8 ++++++++ src/ChunkMap.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/ChunkMap.h | 9 +++++++++ src/World.cpp | 37 ++++++++++++++++++++++++++++++++++ src/World.h | 20 ++++++++++++++++++- 6 files changed, 164 insertions(+), 3 deletions(-) diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 3028d24d0..0587beb9c 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1652,6 +1652,38 @@ void cChunk::UseBlockEntity(cPlayer * a_Player, int a_X, int a_Y, int a_Z) +void cChunk::SetBiomeAt(int a_RelX, int a_RelZ, EMCSBiome a_Biome) +{ + cChunkDef::SetBiome(m_BiomeMap, a_RelX, a_RelZ, a_Biome); + MarkDirty(); +} + + + + + +void cChunk::SetAreaBiome(int a_MinRelX, int a_MaxRelX, int a_MinRelZ, int a_MaxRelZ, EMCSBiome a_Biome) +{ + for (int z = a_MinRelZ; z <= a_MaxRelZ; z++) + { + for (int x = a_MinRelX; x <= a_MaxRelX; x++) + { + cChunkDef::SetBiome(m_BiomeMap, x, z, a_Biome); + } + } + MarkDirty(); + + // Re-send the chunk to all clients: + for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr) + { + m_World->ForceSendChunkTo(m_PosX, m_PosZ, (*itr)); + } // for itr - m_LoadedByClient[] +} + + + + + void cChunk::CollectPickupsByPlayer(cPlayer * a_Player) { double PosX = a_Player->GetPosX(); diff --git a/src/Chunk.h b/src/Chunk.h index 696690068..682ec6170 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -175,6 +175,14 @@ public: EMCSBiome GetBiomeAt(int a_RelX, int a_RelZ) const {return cChunkDef::GetBiome(m_BiomeMap, a_RelX, a_RelZ); } + /** Sets the biome at the specified relative coords. + Doesn't resend the chunk to clients. */ + void SetBiomeAt(int a_RelX, int a_RelZ, EMCSBiome a_Biome); + + /** Sets the biome in the specified relative coords area. All the coords are inclusive. + Sends the chunk to all relevant clients. */ + void SetAreaBiome(int a_MinRelX, int a_MaxRelX, int a_MinRelZ, int a_MaxRelZ, EMCSBiome a_Biome); + void CollectPickupsByPlayer(cPlayer * a_Player); /** Sets the sign text. Returns true if successful. Also sends update packets to all clients in the chunk */ diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 0c5a8d9b9..01195e8bc 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1390,10 +1390,10 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks) EMCSBiome cChunkMap::GetBiomeAt (int a_BlockX, int a_BlockZ) { int ChunkX, ChunkZ, X = a_BlockX, Y = 0, Z = a_BlockZ; - cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ ); + cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ ); + cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { return Chunk->GetBiomeAt(X, Z); @@ -1408,6 +1408,63 @@ EMCSBiome cChunkMap::GetBiomeAt (int a_BlockX, int a_BlockZ) +bool cChunkMap::SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome) +{ + int ChunkX, ChunkZ, X = a_BlockX, Y = 0, Z = a_BlockZ; + cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); + + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); + if ((Chunk != NULL) && Chunk->IsValid()) + { + Chunk->SetBiomeAt(X, Z, a_Biome); + return true; + } + return false; +} + + + + + +bool cChunkMap::SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome) +{ + // Translate coords to relative: + int Y = 0; + int MinChunkX, MinChunkZ, MinX = a_MinX, MinZ = a_MinZ; + int MaxChunkX, MaxChunkZ, MaxX = a_MaxX, MaxZ = a_MaxZ; + cChunkDef::AbsoluteToRelative(MinX, Y, MinZ, MinChunkX, MinChunkZ); + cChunkDef::AbsoluteToRelative(MaxX, Y, MaxZ, MaxChunkX, MaxChunkZ); + + // Go through all chunks, set: + bool res = true; + cCSLock Lock(m_CSLayers); + for (int x = MinChunkX; x <= MaxChunkX; x++) + { + int MinRelX = (x == MinChunkX) ? MinX : 0; + int MaxRelX = (x == MaxChunkX) ? MaxX : cChunkDef::Width - 1; + for (int z = MinChunkZ; z <= MaxChunkZ; z++) + { + int MinRelZ = (z == MinChunkZ) ? MinZ : 0; + int MaxRelZ = (z == MaxChunkZ) ? MaxZ : cChunkDef::Width - 1; + cChunkPtr Chunk = GetChunkNoLoad(x, ZERO_CHUNK_Y, z); + if ((Chunk != NULL) && Chunk->IsValid()) + { + Chunk->SetAreaBiome(MinRelX, MaxRelX, MinRelZ, MaxRelZ, a_Biome); + } + else + { + res = false; + } + } // for z + } // for x + return res; +} + + + + + bool cChunkMap::GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure) { bool res = true; diff --git a/src/ChunkMap.h b/src/ChunkMap.h index d713d0cf5..9f0dd087e 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -159,8 +159,17 @@ public: /** Special function used for growing trees, replaces only blocks that tree may overwrite */ void ReplaceTreeBlocks(const sSetBlockVector & a_Blocks); + /** Returns the biome at the specified coords. Reads the biome from the chunk, if loaded, otherwise uses the world generator to provide the biome value */ EMCSBiome GetBiomeAt (int a_BlockX, int a_BlockZ); + /** Sets the biome at the specified coords. Returns true if successful, false if not (chunk not loaded). + Doesn't resend the chunk to clients. */ + bool SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome); + + /** Sets the biome at the area. Returns true if successful, false if any subarea failed (chunk not loaded). + (Re)sends the chunks to their relevant clients if successful. */ + bool SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome); + /** Retrieves block types of the specified blocks. If a chunk is not loaded, doesn't modify the block. Returns true if all blocks were read. */ bool GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure); diff --git a/src/World.cpp b/src/World.cpp index d67ad36d1..c9d7f42be 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1487,6 +1487,33 @@ EMCSBiome cWorld::GetBiomeAt (int a_BlockX, int a_BlockZ) +bool cWorld::SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome) +{ + return m_ChunkMap->SetBiomeAt(a_BlockX, a_BlockZ, a_Biome); +} + + + + + +bool cWorld::SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome) +{ + return m_ChunkMap->SetAreaBiome(a_MinX, a_MaxX, a_MinZ, a_MaxZ, a_Biome); +} + + + + + +bool cWorld::SetAreaBiome(const cCuboid & a_Area, EMCSBiome a_Biome) +{ + return SetAreaBiome(a_Area.p1.x, a_Area.p2.x, a_Area.p1.z, a_Area.p2.z, a_Biome); +} + + + + + void cWorld::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { m_ChunkMap->SetBlock(*this, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); @@ -2490,6 +2517,16 @@ void cWorld::SendChunkTo(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) +void cWorld::ForceSendChunkTo(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) +{ + a_Client->AddWantedChunk(a_ChunkX, a_ChunkZ); + m_ChunkSender.QueueSendChunkTo(a_ChunkX, a_ChunkZ, a_Client); +} + + + + + void cWorld::RemoveClientFromChunkSender(cClientHandle * a_Client) { m_ChunkSender.RemoveClient(a_Client); diff --git a/src/World.h b/src/World.h index f885040ba..dc286598c 100644 --- a/src/World.h +++ b/src/World.h @@ -47,6 +47,7 @@ class cFurnaceEntity; class cNoteEntity; class cMobCensus; class cCompositeChat; +class cCuboid; typedef std::list< cPlayer * > cPlayerList; @@ -306,9 +307,14 @@ public: /** Removes the client from all chunks it is present in */ void RemoveClientFromChunks(cClientHandle * a_Client); - /** Sends the chunk to the client specified, if the chunk is valid. If not valid, the request is postponed (ChunkSender will send that chunk when it becomes valid+lighted) */ + /** Sends the chunk to the client specified, if the client doesn't have the chunk yet. + If chunk not valid, the request is postponed (ChunkSender will send that chunk when it becomes valid + lighted). */ void SendChunkTo(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client); + /** Sends the chunk to the client specified, even if the client already has the chunk. + If the chunk's not valid, the request is postponed (ChunkSender will send that chunk when it becomes valid + lighted). */ + void ForceSendChunkTo(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client); + /** Removes client from ChunkSender's queue of chunks to be sent */ void RemoveClientFromChunkSender(cClientHandle * a_Client); @@ -549,6 +555,18 @@ public: /** Returns the biome at the specified coords. Reads the biome from the chunk, if loaded, otherwise uses the world generator to provide the biome value */ EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ); + + /** Sets the biome at the specified coords. Returns true if successful, false if not (chunk not loaded). + Doesn't resend the chunk to clients, use ForceSendChunkTo() for that. */ + bool SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome); + + /** Sets the biome at the area. Returns true if successful, false if any subarea failed (chunk not loaded). + (Re)sends the chunks to their relevant clients if successful. */ + bool SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome); + + /** Sets the biome at the area. Returns true if successful, false if any subarea failed (chunk not loaded). + (Re)sends the chunks to their relevant clients if successful. */ + bool SetAreaBiome(const cCuboid & a_Area, EMCSBiome a_Biome); /** Returns the name of the world */ const AString & GetName(void) const { return m_WorldName; } -- cgit v1.2.3 From 71b6fd3da92f5d0956a67e9185b823b6d9e207ef Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 18 Feb 2014 13:06:38 +0100 Subject: Debuggers: Added a test for the cWorld:SetAreaBiome() function. --- MCServer/Plugins/Debuggers/Debuggers.lua | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 60e84c947..66894d835 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -55,6 +55,7 @@ function Initialize(Plugin) PM:BindCommand("/sched", "debuggers", HandleSched, "- Schedules a simple countdown using cWorld:ScheduleTask()"); PM:BindCommand("/cs", "debuggers", HandleChunkStay, "- Tests the ChunkStay Lua integration for the specified chunk coords"); PM:BindCommand("/compo", "debuggers", HandleCompo, "- Tests the cCompositeChat bindings") + PM:BindCommand("/sb", "debuggers", HandleSetBiome, "- Sets the biome around you to the specified one"); Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers) Plugin:AddWebTab("StressTest", HandleRequest_StressTest) @@ -1218,3 +1219,42 @@ end + +function HandleSetBiome(a_Split, a_Player) + local Biome = biJungle + local Size = 20 + local SplitSize = #a_Split + if (SplitSize > 3) then + a_Player:SendMessage("Too many parameters. Usage: " .. a_Split[1] .. " ") + return true + end + + if (SplitSize >= 2) then + Biome = StringToBiome(a_Split[2]) + if (Biome == biInvalidBiome) then + a_Player:SendMessage("Unknown biome: '" .. a_Split[2] .. "'. Command ignored.") + return true + end + end + if (SplitSize >= 3) then + Size = tostring(a_Split[3]) + if (Size == nil) then + a_Player:SendMessage("Unknown size: '" .. a_Split[3] .. "'. Command ignored.") + return true + end + end + + local BlockX = math.floor(a_Player:GetPosX()) + local BlockZ = math.floor(a_Player:GetPosZ()) + a_Player:GetWorld():SetAreaBiome(BlockX - Size, BlockX + Size, BlockZ - Size, BlockZ + Size, Biome) + a_Player:SendMessage( + "Blocks {" .. (BlockX - Size) .. ", " .. (BlockZ - Size) .. + "} - {" .. (BlockX + Size) .. ", " .. (BlockZ + Size) .. + "} set to biome #" .. tostring(Biome) .. "." + ) + return true +end + + + + -- cgit v1.2.3 From b1c6b4f5843d1f466cd12dd159bc717ae46059b5 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 18 Feb 2014 13:44:40 +0100 Subject: The cuboid for cWorld::SetAreaBiome() doesn't need sorting. --- src/World.cpp | 6 +++++- src/World.h | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index c9d7f42be..e57675c44 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1507,7 +1507,11 @@ bool cWorld::SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBi bool cWorld::SetAreaBiome(const cCuboid & a_Area, EMCSBiome a_Biome) { - return SetAreaBiome(a_Area.p1.x, a_Area.p2.x, a_Area.p1.z, a_Area.p2.z, a_Biome); + return SetAreaBiome( + std::min(a_Area.p1.x, a_Area.p2.x), std::max(a_Area.p1.x, a_Area.p2.x), + std::min(a_Area.p1.z, a_Area.p2.z), std::max(a_Area.p1.z, a_Area.p2.z), + a_Biome + ); } diff --git a/src/World.h b/src/World.h index dc286598c..d79de3b87 100644 --- a/src/World.h +++ b/src/World.h @@ -565,7 +565,8 @@ public: bool SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome); /** Sets the biome at the area. Returns true if successful, false if any subarea failed (chunk not loaded). - (Re)sends the chunks to their relevant clients if successful. */ + (Re)sends the chunks to their relevant clients if successful. + The cuboid needn't be sorted. */ bool SetAreaBiome(const cCuboid & a_Area, EMCSBiome a_Biome); /** Returns the name of the world */ -- cgit v1.2.3 From 600861988e40e442534c89e461fdb9b7c460d5b2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 18 Feb 2014 13:45:10 +0100 Subject: APIDump: Documented missing cWorld functions. --- MCServer/Plugins/APIDump/APIDesc.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index b0d31e7a8..61b42a1a1 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2027,6 +2027,7 @@ end AreCommandBlocksEnabled = { Params = "", Return = "bool", Notes = "Returns whether command blocks are enabled on the (entire) server" }, BroadcastBlockAction = { Params = "BlockX, BlockY, BlockZ, ActionByte1, ActionByte2, BlockType, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Broadcasts the BlockAction packet to all clients who have the appropriate chunk loaded (except ExcludeClient). The contents of the packet are specified by the parameters for the call, the blocktype needn't match the actual block that is present in the world data at the specified location." }, BroadcastChat = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the Message to all players in this world, except the optional ExcludeClient. No formatting is done by the server." }, + BroadcastChatDeath = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Gray [DEATH] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For when a player dies." }, BroadcastChatFailure = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Rose [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a command that failed to run because of insufficient permissions, etc." }, BroadcastChatFatal = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Red [FATAL] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a plugin that crashed, or similar." }, BroadcastChatInfo = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Yellow [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For informational messages, such as command usage." }, @@ -2043,6 +2044,7 @@ end DoExplosionAt = { Params = "Force, X, Y, Z, CanCauseFire, Source, SourceData", Return = "", Notes = "Creates an explosion of the specified relative force in the specified position. If CanCauseFire is set, the explosion will set blocks on fire, too. The Source parameter specifies the source of the explosion, one of the esXXX constants. The SourceData parameter is specific to each source type, usually it provides more info about the source." }, DoWithBlockEntityAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a block entity at the specified coords, calls the CallbackFunction with the {{cBlockEntity}} parameter representing the block entity. The CallbackFunction has the following signature:

    function Callback({{cBlockEntity|BlockEntity}}, [CallbackData])
    The function returns false if there is no block entity, or if there is, it returns the bool value that the callback has returned. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." }, DoWithChestAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a chest at the specified coords, calls the CallbackFunction with the {{cChestEntity}} parameter representing the chest. The CallbackFunction has the following signature:
    function Callback({{cChestEntity|ChestEntity}}, [CallbackData])
    The function returns false if there is no chest, or if there is, it returns the bool value that the callback has returned." }, + DoWithCommandBlockAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a command block at the specified coords, calls the CallbackFunction with the {{cCommandBlockEntity}} parameter representing the command block. The CallbackFunction has the following signature:
    function Callback({{cCommandBlockEntity|CommandBlockEntity}}, [CallbackData])
    The function returns false if there is no command block, or if there is, it returns the bool value that the callback has returned." }, DoWithDispenserAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dispenser at the specified coords, calls the CallbackFunction with the {{cDispenserEntity}} parameter representing the dispenser. The CallbackFunction has the following signature:
    function Callback({{cDispenserEntity|DispenserEntity}}, [CallbackData])
    The function returns false if there is no dispenser, or if there is, it returns the bool value that the callback has returned." }, DoWithDropSpenserAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper or a dispenser at the specified coords, calls the CallbackFunction with the {{cDropSpenserEntity}} parameter representing the dropper or dispenser. The CallbackFunction has the following signature:
    function Callback({{cDropSpenserEntity|DropSpenserEntity}}, [CallbackData])
    Note that this can be used to access both dispensers and droppers in a similar way. The function returns false if there is neither dispenser nor dropper, or if there is, it returns the bool value that the callback has returned." }, DoWithDropperAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper at the specified coords, calls the CallbackFunction with the {{cDropperEntity}} parameter representing the dropper. The CallbackFunction has the following signature:
    function Callback({{cDropperEntity|DropperEntity}}, [CallbackData])
    The function returns false if there is no dropper, or if there is, it returns the bool value that the callback has returned." }, @@ -2088,6 +2090,7 @@ end GetMaxSugarcaneHeight = { Params = "", Return = "number", Notes = "Returns the configured maximum height to which sugarcane will grow naturally." }, GetName = { Params = "", Return = "string", Notes = "Returns the name of the world, as specified in the settings.ini file." }, GetNumChunks = { Params = "", Return = "number", Notes = "Returns the number of chunks currently loaded." }, + GetScoreBoard = { Params = "", Return = "{{cScoreBoard}}", Notes = "Returns the {{cScoreBoard|ScoreBoard}} object used by this world. " }, GetSignLines = { Params = "BlockX, BlockY, BlockZ", Return = "IsValid, [Line1, Line2, Line3, Line4]", Notes = "Returns true and the lines of a sign at the specified coords, or false if there is no sign at the coords." }, GetSpawnX = { Params = "", Return = "number", Notes = "Returns the X coord of the default spawn" }, GetSpawnY = { Params = "", Return = "number", Notes = "Returns the Y coord of the default spawn" }, @@ -2123,6 +2126,11 @@ end RegenerateChunk = { Params = "ChunkX, ChunkZ", Return = "", Notes = "Queues the specified chunk to be re-generated, overwriting the current data. To queue a chunk for generating only if it doesn't exist, use the GenerateChunk() instead." }, ScheduleTask = { Params = "DelayTicks, TaskFunction", Return = "", Notes = "Queues the specified function to be executed in the world's tick thread after a the specified number of ticks. This enables operations to be queued for execution in the future. The function signature is
    function({{cWorld|World}})
    All return values from the function are ignored. Note that it is unsafe to store references to MCServer objects, such as entities, across from the caller to the task handler function; store the EntityID instead." }, SendBlockTo = { Params = "BlockX, BlockY, BlockZ, {{cPlayer|Player}}", Return = "", Notes = "Sends the block at the specified coords to the specified player's client, as an UpdateBlock packet." }, + SetAreaBiome = { + { Params = "MinX, MaxX, MinZ, MaxZ, EMCSBiome", Return = "bool", Notes = "Sets the biome in the rectangular area specified. Returns true if successful, false if any of the chunks were unloaded." }, + { Params = "{{cCuboid|Cuboid}}, EMCSBiome", Return = "bool", Notes = "Sets the biome in the cuboid specified. Returns true if successful, false if any of the chunks were unloaded. The cuboid needn't be sorted." }, + }, + SetBiomeAt = { Params = "BlockX, BlockZ, EMCSBiome", Return = "bool", Notes = "Sets the biome at the specified block coords. Returns true if successful, false otherwise." }, SetBlock = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block at the specified coords, replaces the block entities for the previous block type, creates a new block entity for the new block, if appropriate, and wakes up the simulators. This is the preferred way to set blocks, as opposed to FastSetBlock(), which is only to be used under special circumstances." }, SetBlockMeta = { -- cgit v1.2.3 From 29269a6ef82ec71e226f60f986f039d931e367e6 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 18 Feb 2014 13:51:45 +0100 Subject: ProtoProxy: ignoring PolarSSL build files. --- Tools/ProtoProxy/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/Tools/ProtoProxy/.gitignore b/Tools/ProtoProxy/.gitignore index 8def77d0b..158a30080 100644 --- a/Tools/ProtoProxy/.gitignore +++ b/Tools/ProtoProxy/.gitignore @@ -1,6 +1,7 @@ Debug Release Logs/ +lib/ *.log *.nbt *.sln -- cgit v1.2.3 From 393ca0221dfdb6dabadcf293fea86a830453c938 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 18 Feb 2014 20:50:08 +0200 Subject: Map decorators; Map clients --- src/ClientHandle.cpp | 22 ++-- src/ClientHandle.h | 2 + src/Items/ItemMap.h | 4 +- src/Map.cpp | 232 ++++++++++++++++++++++++++++++++---- src/Map.h | 75 +++++++++++- src/Protocol/Protocol.h | 3 +- src/Protocol/Protocol125.cpp | 25 ++++ src/Protocol/Protocol125.h | 1 + src/Protocol/Protocol17x.cpp | 20 ++++ src/Protocol/Protocol17x.h | 1 + src/Protocol/ProtocolRecognizer.cpp | 10 ++ src/Protocol/ProtocolRecognizer.h | 1 + 12 files changed, 351 insertions(+), 45 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index a2cbaefff..efc5a9f64 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1190,19 +1190,6 @@ void cClientHandle::HandleSlotSelected(short a_SlotNum) { m_Player->GetInventory().SetEquippedSlotNum(a_SlotNum); m_Player->GetWorld()->BroadcastEntityEquipment(*m_Player, 0, m_Player->GetInventory().GetEquippedItem(), this); - - const cItem & Item = m_Player->GetInventory().GetEquippedItem(); - if (Item.m_ItemType == E_ITEM_MAP) - { - // TODO 2014-02-14 xdot: Do not hardcode this. - cMap * Map = m_Player->GetWorld()->GetMapData(Item.m_ItemDamage); - - if (Map != NULL) - { - // TODO 2014-02-14 xdot: Optimization - Do not send the whole map. - Map->SendTo(*this); - } - } } @@ -2079,6 +2066,15 @@ void cClientHandle::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Col +void cClientHandle::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators) +{ + m_Protocol->SendMapDecorators(a_ID, a_Decorators); +} + + + + + void cClientHandle::SendMapInfo(int a_ID, unsigned int a_Scale) { m_Protocol->SendMapInfo(a_ID, a_Scale); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index a714cf8b9..a613a76e8 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -17,6 +17,7 @@ #include "ChunkDef.h" #include "ByteBuffer.h" #include "Scoreboard.h" +#include "Map.h" @@ -110,6 +111,7 @@ public: void SendHealth (void); void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item); void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length); + void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators); void SendMapInfo (int a_ID, unsigned int a_Scale); void SendPickupSpawn (const cPickup & a_Pickup); void SendEntityAnimation (const cEntity & a_Entity, char a_Animation); diff --git a/src/Items/ItemMap.h b/src/Items/ItemMap.h index c3e605547..9bb16b189 100644 --- a/src/Items/ItemMap.h +++ b/src/Items/ItemMap.h @@ -36,8 +36,8 @@ public: return; } - // Map->AddTrackedPlayer(a_Player); - Map->UpdateRadius(*a_Player, DEFAULT_RADIUS); + + Map->UpdateClient(a_Player); } } ; diff --git a/src/Map.cpp b/src/Map.cpp index e85c23d3a..f32d232fa 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -14,6 +14,111 @@ +cMapDecorator::cMapDecorator(cMap * a_Map, eType a_Type, int a_X, int a_Z, unsigned int a_Rot) + : m_Map(a_Map) + , m_Type(a_Type) + , m_PixelX(a_X) + , m_PixelZ(a_Z) + , m_Rot(a_Rot) + , m_Player(NULL) +{ +} + + + + + +cMapDecorator::cMapDecorator(cMap * a_Map, cPlayer * a_Player) + : m_Map(a_Map) + , m_Type(E_TYPE_PLAYER) + , m_Player(a_Player) +{ + Update(); +} + + + + + +template +T Clamp(T a_X, T a_Min, T a_Max) +{ + return std::min(std::max(a_X, a_Min), a_Max); +} + + + + + +void cMapDecorator::Update(void) +{ + ASSERT(m_Map != NULL); + unsigned int PixelWidth = m_Map->GetPixelWidth(); + + int InsideWidth = (m_Map->GetWidth() / 2) - 1; + int InsideHeight = (m_Map->GetHeight() / 2) - 1; + + if (m_Player) + { + int PixelX = (m_Player->GetPosX() - m_Map->GetCenterX()) / PixelWidth; + int PixelZ = (m_Player->GetPosZ() - m_Map->GetCenterZ()) / PixelWidth; + + // Center of pixel + m_PixelX = (2 * PixelX) + 1; + m_PixelZ = (2 * PixelZ) + 1; + + // 1px border + if ((PixelX > -InsideWidth) && (PixelX <= InsideWidth) && (PixelZ > -InsideHeight) && (PixelZ <= InsideHeight)) + { + double Yaw = m_Player->GetYaw(); + + m_Rot = (Yaw * 16) / 360; + + if (m_Map->GetDimension() == dimNether) + { + Int64 WorldAge = m_Player->GetWorld()->GetWorldAge(); + + // TODO 2014-02-18 xdot: Random rotations + } + + m_Type = E_TYPE_PLAYER; + } + else + { + if ((abs(PixelX) > 320.0) || (abs(PixelZ) > 320.0)) + { + // TODO 2014-02-18 xdot: Remove decorator + } + + m_Rot = 0; + + m_Type = E_TYPE_PLAYER_OUTSIDE; + + // Move to border + if (PixelX <= -InsideWidth) + { + m_PixelX = (2 * -InsideWidth) + 1; + } + if (PixelZ <= -InsideHeight) + { + m_PixelZ = (2 * -InsideHeight) + 1; + } + if (PixelX > InsideWidth) + { + m_PixelX = (2 * InsideWidth) + 1; + } + if (PixelZ > InsideHeight) + { + m_PixelZ = (2 * InsideHeight) + 1; + } + } + } +} + + + + + cMap::cMap(unsigned int a_ID, cWorld * a_World) : m_ID(a_ID) , m_Width(cChunkDef::Width * 8) @@ -50,16 +155,6 @@ cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, un -template -T Clamp(T a_X, T a_Min, T a_Max) -{ - return std::min(std::max(a_X, a_Min), a_Max); -} - - - - - void cMap::UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius) { int PixelRadius = a_Radius / GetPixelWidth(); @@ -174,33 +269,117 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) -void cMap::UpdateTrackedPlayers(void) +void cMap::UpdateDecorators(void) +{ + for (cMapDecoratorList::iterator it = m_Decorators.begin(); it != m_Decorators.end(); ++it) + { + it->Update(); + } +} + + + + + +void cMap::UpdateClient(cPlayer * a_Player) { - cTrackedPlayerList NewList; + ASSERT(a_Player != NULL); + cClientHandle * Handle = a_Player->GetClientHandle(); - for (cTrackedPlayerList::iterator it = m_TrackedPlayers.begin(); it != m_TrackedPlayers.end(); ++it) + if (Handle == NULL) { - cPlayer * Player = *it; + return; + } + + Int64 WorldAge = a_Player->GetWorld()->GetWorldAge(); - UpdateRadius(*Player, DEFAULT_RADIUS); + // Remove invalid clients + for (cMapClientList::iterator it = m_Clients.begin(); it != m_Clients.end();) + { + // Check if client is active + if (it->m_LastUpdate < WorldAge - 5) + { + // Remove associated decorators + for (cMapDecoratorList::iterator it2 = m_Decorators.begin(); it2 != m_Decorators.end();) + { + if (it2->GetPlayer()->GetClientHandle() == Handle) + { + // Erase decorator + cMapDecoratorList::iterator temp = it2; + ++it2; + m_Decorators.erase(temp); + } + else + { + ++it2; + } + } - if (true) + // Erase client + cMapClientList::iterator temp = it; + ++it; + m_Clients.erase(temp); + } + else { - NewList.insert(Player); + ++it; } } - std::swap(m_TrackedPlayers, NewList); -} + // Linear search for client state + for (cMapClientList::iterator it = m_Clients.begin(); it != m_Clients.end(); ++it) + { + if (it->m_Handle == Handle) + { + it->m_LastUpdate = WorldAge; + if (it->m_SendInfo) + { + Handle->SendMapInfo(m_ID, m_Scale); + it->m_SendInfo = false; + return; + } + ++it->m_NextDecoratorUpdate; -void cMap::AddTrackedPlayer(cPlayer * a_Player) -{ - ASSERT(a_Player != NULL); - m_TrackedPlayers.insert(a_Player); + if (it->m_NextDecoratorUpdate >= 4) + { + UpdateDecorators(); + + Handle->SendMapDecorators(m_ID, m_Decorators); + + it->m_NextDecoratorUpdate = 0; + } + else + { + ++it->m_DataUpdate; + + unsigned int Y = (it->m_DataUpdate * 11) % m_Width; + + const Byte * Colors = &m_Data[Y * m_Height]; + + Handle->SendMapColumn(m_ID, Y, 0, Colors, m_Height); + } + + return; + } + } + + // New player, construct a new client state + cMapClient MapClient; + + MapClient.m_LastUpdate = WorldAge; + MapClient.m_SendInfo = true; + MapClient.m_Handle = a_Player->GetClientHandle(); + + m_Clients.push_back(MapClient); + + // Insert new decorator + cMapDecorator PlayerDecorator(this, a_Player); + + m_Decorators.push_back(PlayerDecorator); } @@ -267,6 +446,11 @@ void cMap::SetScale(unsigned int a_Scale) } m_Scale = a_Scale; + + for (cMapClientList::iterator it = m_Clients.begin(); it != m_Clients.end(); ++it) + { + it->m_SendInfo = true; + } } @@ -283,6 +467,8 @@ void cMap::SendTo(cClientHandle & a_Client) a_Client.SendMapColumn(m_ID, i, 0, Colors, m_Height); } + + a_Client.SendMapDecorators(m_ID, m_Decorators); } diff --git a/src/Map.h b/src/Map.h index 805dfb845..76e459621 100644 --- a/src/Map.h +++ b/src/Map.h @@ -22,6 +22,55 @@ class cClientHandle; class cWorld; class cPlayer; +class cMap; + + + + + +class cMapDecorator +{ +public: + enum eType + { + E_TYPE_PLAYER = 0x00, + E_TYPE_ITEM_FRAME = 0x01, + E_TYPE_PLAYER_OUTSIDE = 0x06 + }; + + +public: + + cMapDecorator(cMap * a_Map, eType a_Type, int a_X, int a_Z, unsigned int a_Rot); + + cMapDecorator(cMap * a_Map, cPlayer * a_Player); + + void Update(void); + + unsigned int GetPixelX(void) const { return m_PixelX; } + unsigned int GetPixelZ(void) const { return m_PixelZ; } + unsigned int GetRot(void) const { return m_Rot; } + + eType GetType(void) const { return m_Type; } + + cPlayer * GetPlayer(void) { return m_Player; } + + +protected: + + cMap * m_Map; + + eType m_Type; + + unsigned int m_PixelX; + unsigned int m_PixelZ; + + unsigned int m_Rot; + + cPlayer * m_Player; +}; + +typedef std::list cMapDecoratorList; @@ -38,7 +87,19 @@ public: typedef std::vector cColorList; - static const unsigned int DEFAULT_RADIUS = 128; + struct cMapClient + { + cClientHandle * m_Handle; + + bool m_SendInfo; + + unsigned int m_NextDecoratorUpdate; + + Int64 m_DataUpdate; + Int64 m_LastUpdate; + }; + + typedef std::list cMapClientList; public: @@ -56,9 +117,8 @@ public: void UpdateRadius(cPlayer & a_Player, unsigned int a_Radius); - void UpdateTrackedPlayers(void); - - void AddTrackedPlayer(cPlayer * a_Player); + /** Send next update packet and remove invalid decorators */ + void UpdateClient(cPlayer * a_Player); // tolua_begin @@ -98,6 +158,9 @@ public: private: + /** Update the associated decorators. */ + void UpdateDecorators(void); + /** Update the specified pixel. */ bool UpdatePixel(unsigned int a_X, unsigned int a_Z); @@ -117,9 +180,9 @@ private: cWorld * m_World; - typedef std::set cTrackedPlayerList; + cMapDecoratorList m_Decorators; - cTrackedPlayerList m_TrackedPlayers; + cMapClientList m_Clients; AString m_Name; diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 5f89799e1..4a1601487 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -13,6 +13,7 @@ #include "../Defines.h" #include "../Endianness.h" #include "../Scoreboard.h" +#include "../Map.h" @@ -28,7 +29,6 @@ class cWorld; class cMonster; class cChunkDataSerializer; class cFallingBlock; -class cMap; @@ -81,6 +81,7 @@ public: virtual void SendKeepAlive (int a_PingID) = 0; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) = 0; + virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) = 0; virtual void SendMapInfo (int a_ID, unsigned int a_Scale) = 0; virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0; virtual void SendPlayerAbilities (void) = 0; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index edb22fae6..220fa18cf 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -602,6 +602,31 @@ void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colo +void cProtocol125::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators) +{ + cCSLock Lock(m_CSPacket); + + WriteByte (PACKET_ITEM_DATA); + WriteShort(E_ITEM_MAP); + WriteShort(a_ID); + WriteShort(1 + (3 * a_Decorators.size())); + + WriteByte(1); + + for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it) + { + WriteByte((it->GetType() << 4) | (it->GetRot() & 0xf)); + WriteByte(it->GetPixelX()); + WriteByte(it->GetPixelZ()); + } + + Flush(); +} + + + + + void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) { diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 467aee002..1eeb15120 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -55,6 +55,7 @@ public: virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; + virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override; virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override {} // This protocol doesn't support such message virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 4acc61586..38b4ed786 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -516,6 +516,26 @@ void cProtocol172::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colo +void cProtocol172::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators) +{ + cPacketizer Pkt(*this, 0x34); + Pkt.WriteVarInt(a_ID); + Pkt.WriteShort (1 + (3 * a_Decorators.size())); + + Pkt.WriteByte(1); + + for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it) + { + Pkt.WriteByte((it->GetType() << 4) | (it->GetRot() & 0xf)); + Pkt.WriteByte(it->GetPixelX()); + Pkt.WriteByte(it->GetPixelZ()); + } +} + + + + + void cProtocol172::SendMapInfo(int a_ID, unsigned int a_Scale) { cPacketizer Pkt(*this, 0x34); diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 0e50db45d..4edf51d2f 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -77,6 +77,7 @@ public: virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; + virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override; virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 447fa516b..0a9369c0d 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -396,6 +396,16 @@ void cProtocolRecognizer::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * +void cProtocolRecognizer::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendMapDecorators(a_ID, a_Decorators); +} + + + + + void cProtocolRecognizer::SendMapInfo(int a_ID, unsigned int a_Scale) { ASSERT(m_Protocol != NULL); diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index 3c37d5138..ff4549ff5 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -90,6 +90,7 @@ public: virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; + virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override; virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; -- cgit v1.2.3 From 52c41f886927cf62ed592ba7fec974eee6b16844 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 18 Feb 2014 21:40:02 +0100 Subject: Add Heads completely --- src/Bindings/ManualBindings.cpp | 2 ++ src/BlockEntities/BlockEntity.cpp | 2 +- src/BlockEntities/SkullEntity.cpp | 4 +-- src/BlockEntities/SkullEntity.h | 2 +- src/Blocks/BlockHandler.cpp | 2 ++ src/Blocks/BlockSkull.h | 69 +++++++++++++++++++++++++++++++++++++++ src/Chunk.cpp | 33 +++++++++++++++++++ src/Chunk.h | 7 +++- src/ChunkMap.cpp | 18 ++++++++++ src/ChunkMap.h | 5 +++ src/Items/ItemSkull.h | 1 + src/World.cpp | 9 +++++ src/World.h | 5 +++ src/WorldStorage/WSSAnvil.cpp | 2 +- 14 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 src/Blocks/BlockSkull.h diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 2a7631120..70f3fbcf2 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -22,6 +22,7 @@ #include "../BlockEntities/FurnaceEntity.h" #include "../BlockEntities/HopperEntity.h" #include "../BlockEntities/NoteEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "md5/md5.h" #include "../LineBlockTracer.h" #include "../WorldStorage/SchematicFileSerializer.h" @@ -2416,6 +2417,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "DoWithFurnaceAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithSkullBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk); diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 441f54a26..f01a139d2 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -30,9 +30,9 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); - case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/SkullEntity.cpp b/src/BlockEntities/SkullEntity.cpp index 3f3bc00ed..43b97b93e 100644 --- a/src/BlockEntities/SkullEntity.cpp +++ b/src/BlockEntities/SkullEntity.cpp @@ -12,12 +12,10 @@ -cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World) : +cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), - //m_SkullType(static_cast(a_BlockMeta)), m_Owner("") { - } diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h index 6f47c7d30..ffd84465f 100644 --- a/src/BlockEntities/SkullEntity.h +++ b/src/BlockEntities/SkullEntity.h @@ -35,7 +35,7 @@ public: // tolua_end /// Creates a new skull entity at the specified block coords. a_World may be NULL - cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World); + cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); bool LoadFromJson( const Json::Value& a_Value ); virtual void SaveToJson(Json::Value& a_Value ) override; diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 6c9bbeb02..870de7a7d 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -34,6 +34,7 @@ #include "BlockGlass.h" #include "BlockGlowstone.h" #include "BlockGravel.h" +#include "BlockSkull.h" #include "BlockHopper.h" #include "BlockIce.h" #include "BlockLadder.h" @@ -146,6 +147,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_GRASS: return new cBlockDirtHandler (a_BlockType); case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType); case E_BLOCK_HAY_BALE: return new cBlockSidewaysHandler (a_BlockType); + case E_BLOCK_HEAD: return new cBlockSkullHandler (a_BlockType); case E_BLOCK_HOPPER: return new cBlockHopperHandler (a_BlockType); case E_BLOCK_ICE: return new cBlockIceHandler (a_BlockType); case E_BLOCK_INACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); diff --git a/src/Blocks/BlockSkull.h b/src/Blocks/BlockSkull.h new file mode 100644 index 000000000..eea5ac922 --- /dev/null +++ b/src/Blocks/BlockSkull.h @@ -0,0 +1,69 @@ + +#pragma once + +#include "BlockEntity.h" +#include "../BlockEntities/SkullEntity.h" + + + + + +class cBlockSkullHandler : + public cBlockEntityHandler +{ +public: + cBlockSkullHandler(BLOCKTYPE a_BlockType) + : cBlockEntityHandler(a_BlockType) + { + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + a_Pickups.push_back(cItem(E_ITEM_HEAD, 1, 0)); + } + + virtual void OnPlacedByPlayer( + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta + ) override + { + class cCallback : public cSkullBlockCallback + { + cPlayer * m_Player; + NIBBLETYPE m_OldBlockMeta; + NIBBLETYPE m_NewBlockMeta; + + virtual bool Item (cSkullEntity * a_SkullEntity) + { + int Rotation = 0; + if (m_NewBlockMeta == 1) + { + Rotation = (int) floor(m_Player->GetYaw() * 16.0F / 360.0F + 0.5) & 0xF; + } + + a_SkullEntity->SetSkullType(static_cast(m_OldBlockMeta)); + a_SkullEntity->SetRotation(static_cast(Rotation)); + return false; + } + + public: + cCallback (cPlayer * a_Player, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) : + m_Player(a_Player), + m_OldBlockMeta(a_OldBlockMeta), + m_NewBlockMeta(a_NewBlockMeta) + {} + }; + cCallback Callback(a_Player, a_BlockMeta, static_cast(a_BlockFace)); + + a_BlockMeta = a_BlockFace; + cWorld * World = (cWorld *) &a_WorldInterface; + World->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, Callback); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); + } +} ; + + + + diff --git a/src/Chunk.cpp b/src/Chunk.cpp index c66dae7b4..8b03732f3 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -19,6 +19,7 @@ #include "BlockEntities/JukeboxEntity.h" #include "BlockEntities/NoteEntity.h" #include "BlockEntities/SignEntity.h" +#include "BlockEntities/SkullEntity.h" #include "Entities/Pickup.h" #include "Item.h" #include "Noise.h" @@ -2311,6 +2312,38 @@ bool cChunk::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom +bool cChunk::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +{ + // The blockentity list is locked by the parent chunkmap's CS + for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2) + { + ++itr2; + if (((*itr)->GetPosX() != a_BlockX) || ((*itr)->GetPosY() != a_BlockY) || ((*itr)->GetPosZ() != a_BlockZ)) + { + continue; + } + if ((*itr)->GetBlockType() != E_BLOCK_HEAD) + { + // There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out + return false; + } + + // The correct block entity is here, + if (a_Callback.Item((cSkullEntity *)*itr)) + { + return false; + } + return true; + } // for itr - m_BlockEntitites[] + + // Not found: + return false; +} + + + + + bool cChunk::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { // The blockentity list is locked by the parent chunkmap's CS diff --git a/src/Chunk.h b/src/Chunk.h index 696690068..27388deb4 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -31,6 +31,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; +class cSkullEntity; class cBlockArea; class cPawn; class cPickup; @@ -47,6 +48,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; +typedef cItemCallback cSkullBlockCallback; @@ -241,7 +243,10 @@ public: bool DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNoteBlockCallback & a_Callback); /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ - bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); + bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); + + /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ + bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 0c5a8d9b9..5f1674c03 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2121,6 +2121,24 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c +bool cChunkMap::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +{ + int ChunkX, ChunkZ; + int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; + cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + if ((Chunk == NULL) && !Chunk->IsValid()) + { + return false; + } + return Chunk->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); +} + + + + + bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { int ChunkX, ChunkZ; diff --git a/src/ChunkMap.h b/src/ChunkMap.h index d713d0cf5..02c245dc9 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -25,6 +25,7 @@ class cDropSpenserEntity; class cFurnaceEntity; class cNoteEntity; class cCommandBlockEntity; +class cSkullEntity; class cPawn; class cPickup; class cChunkDataSerializer; @@ -43,6 +44,7 @@ typedef cItemCallback cDropSpenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; +typedef cItemCallback cSkullBlockCallback; typedef cItemCallback cChunkCallback; @@ -245,6 +247,9 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Lua-accessible + /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ + bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Lua-accessible + /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/Items/ItemSkull.h b/src/Items/ItemSkull.h index f511c8c4a..3648f1436 100644 --- a/src/Items/ItemSkull.h +++ b/src/Items/ItemSkull.h @@ -31,6 +31,7 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override { + a_BlockType = E_BLOCK_HEAD; a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); diff --git a/src/World.cpp b/src/World.cpp index d67ad36d1..14d904d72 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1165,6 +1165,15 @@ bool cWorld::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom +bool cWorld::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +{ + return m_ChunkMap->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); +} + + + + + bool cWorld::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { return m_ChunkMap->GetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4); diff --git a/src/World.h b/src/World.h index 97358b88a..4e83833ed 100644 --- a/src/World.h +++ b/src/World.h @@ -45,6 +45,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; +class cSkullEntity; class cMobCensus; class cCompositeChat; @@ -57,6 +58,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; +typedef cItemCallback cSkullBlockCallback; @@ -510,6 +512,9 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Exported in ManualBindings.cpp + /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ + bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Exported in ManualBindings.cpp + /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Exported in ManualBindings.cpp diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 89a236f07..58dc2e9e4 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -940,7 +940,7 @@ void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cPars { return; } - std::auto_ptr Skull(new cSkullEntity(E_BLOCK_HEAD, x, y, z, m_World)); + std::auto_ptr Skull(new cSkullEntity(x, y, z, m_World)); int currentLine = a_NBT.FindChildByName(a_TagIdx, "SkullType"); if (currentLine >= 0) -- cgit v1.2.3 From 05789f9e66abd9ad211fb27fb36bb45915c6d19e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 21:33:33 +0000 Subject: Changed BlockFace type to eBlockFace --- src/Entities/ItemFrame.cpp | 35 ++++++++++++++++++++++++----------- src/Entities/ItemFrame.h | 4 ++-- src/Items/ItemItemFrame.h | 14 +------------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index 65b0edb25..8cfa5e18d 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -9,7 +9,7 @@ -cItemFrame::cItemFrame(int a_BlockFace, double a_X, double a_Y, double a_Z) +cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z) : cEntity(etItemFrame, a_X, a_Y, a_Z, 0.8, 0.8), m_BlockFace(a_BlockFace), m_Item(E_BLOCK_AIR), @@ -17,15 +17,6 @@ cItemFrame::cItemFrame(int a_BlockFace, double a_X, double a_Y, double a_Z) { SetMaxHealth(1); SetHealth(1); - - if ((a_BlockFace == 0) || (a_BlockFace == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180 - { - SetYaw((a_BlockFace * 90) - 180); - } - else - { - SetYaw(a_BlockFace * 90); - } } @@ -34,7 +25,28 @@ cItemFrame::cItemFrame(int a_BlockFace, double a_X, double a_Y, double a_Z) void cItemFrame::SpawnOn(cClientHandle & a_ClientHandle) { - a_ClientHandle.SendSpawnObject(*this, 71, m_BlockFace, (Byte)GetYaw(), (Byte)GetPitch()); + int Dir = 0; + + // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces + switch (m_BlockFace) + { + case BLOCK_FACE_ZP: break; // Initialised to zero + case BLOCK_FACE_ZM: Dir = 2; break; + case BLOCK_FACE_XM: Dir = 1; break; + case BLOCK_FACE_XP: Dir = 3; break; + default: ASSERT(!"Unhandled block face when trying to spawn item frame!"); return; + } + + if ((Dir == 0) || (Dir == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180 + { + SetYaw((Dir * 90) - 180); + } + else + { + SetYaw(Dir * 90); + } + + a_ClientHandle.SendSpawnObject(*this, 71, Dir, (Byte)GetYaw(), (Byte)GetPitch()); } @@ -91,6 +103,7 @@ void cItemFrame::KilledBy(cEntity * a_Killer) SetHealth(GetMaxHealth()); m_Item.Clear(); + m_Rotation = 0; GetWorld()->BroadcastEntityMetadata(*this); } diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h index 15a03e54a..43915e3f9 100644 --- a/src/Entities/ItemFrame.h +++ b/src/Entities/ItemFrame.h @@ -18,7 +18,7 @@ public: CLASS_PROTODEF(cItemFrame); - cItemFrame(int a_BlockFace, double a_X, double a_Y, double a_Z); + cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z); const cItem & GetItem(void) { return m_Item; } Byte GetRotation(void) const { return m_Rotation; } @@ -31,7 +31,7 @@ private: virtual void KilledBy(cEntity * a_Killer) override; virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override; - int m_BlockFace; + eBlockFace m_BlockFace; cItem m_Item; Byte m_Rotation; diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h index f286fffd0..4875e09dc 100644 --- a/src/Items/ItemItemFrame.h +++ b/src/Items/ItemItemFrame.h @@ -33,19 +33,7 @@ public: if (Block == E_BLOCK_AIR) { - int Dir = 0; - - // The client uses different values for painting directions and block faces. Our constants are for the block faces, so we convert them here to painting faces - switch (a_Dir) - { - case BLOCK_FACE_ZP: break; // Initialised to zero - case BLOCK_FACE_ZM: Dir = 2; break; - case BLOCK_FACE_XM: Dir = 1; break; - case BLOCK_FACE_XP: Dir = 3; break; - default: ASSERT(!"Unhandled block face when trying spawn item frame!"); return false; - } - - cItemFrame * ItemFrame = new cItemFrame(Dir, a_BlockX, a_BlockY, a_BlockZ); + cItemFrame * ItemFrame = new cItemFrame(a_Dir, a_BlockX, a_BlockY, a_BlockZ); ItemFrame->Initialize(a_World); if (!a_Player->IsGameModeCreative()) -- cgit v1.2.3 From 5b961453d12d78a8901910d2f419093b82feb533 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 21:54:53 +0000 Subject: Fixed possible ASSERT failure --- src/Items/ItemItemFrame.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h index 4875e09dc..74e987445 100644 --- a/src/Items/ItemItemFrame.h +++ b/src/Items/ItemItemFrame.h @@ -21,7 +21,7 @@ public: virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { - if (a_Dir == BLOCK_FACE_NONE) + if ((a_Dir == BLOCK_FACE_NONE) || (a_Dir == BLOCK_FACE_YP) || (a_Dir == BLOCK_FACE_YM)) { // Client sends this if clicked on top or bottom face return false; -- cgit v1.2.3 From 8b2153ba97cfb5ec545ff84b1329a200b7cbc2a0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 22:07:21 +0000 Subject: De-breaked stuff --- src/Protocol/Protocol17x.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 57a56d1a4..3d6a8f807 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2401,7 +2401,6 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity) WriteByte(Frame.GetRotation()); break; } - default: break; } } @@ -2586,7 +2585,6 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob) WriteInt(Horse.GetHorseArmour()); break; } - default: break; } // switch (a_Mob.GetType()) } -- cgit v1.2.3 From 823ee3a125d1b57880eaa050d25e5bc71180506d Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 19 Feb 2014 14:12:34 +0100 Subject: Add break to Protocol17x.cpp and use new comment delimiter --- src/BlockEntities/SkullEntity.h | 14 +++++++------- src/Protocol/Protocol17x.cpp | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h index ffd84465f..3dc355623 100644 --- a/src/BlockEntities/SkullEntity.h +++ b/src/BlockEntities/SkullEntity.h @@ -34,7 +34,7 @@ public: // tolua_end - /// Creates a new skull entity at the specified block coords. a_World may be NULL + /** Creates a new skull entity at the specified block coords. a_World may be NULL */ cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); bool LoadFromJson( const Json::Value& a_Value ); @@ -42,22 +42,22 @@ public: // tolua_begin - /// Set the Skull Type + /** Set the Skull Type */ void SetSkullType(const eSkullType & a_SkullType); - /// Set the Rotation + /** Set the Rotation */ void SetRotation(eSkullRotation a_Rotation); - // Set the Player Name for Player Skulls + /** Set the Player Name for Player Skull */ void SetOwner(const AString & a_Owner); - /// Get the Skull Type + /** Get the Skull Type */ eSkullType GetSkullType(void) const { return m_SkullType; } - /// Get the Rotation + /** Get the Rotation */ eSkullRotation GetRotation(void) const { return m_Rotation; } - /// Get the setted Player Name + /** Get the setted Player Name */ AString GetOwner(void) const { return m_Owner; } // tolua_end diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 4d55822fb..07b23e0ac 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2282,6 +2282,7 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt Writer.AddByte("Rot", SkullEntity.GetRotation() & 0xFF); Writer.AddString("ExtraType", SkullEntity.GetOwner().c_str()); Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though + break; } default: break; } -- cgit v1.2.3 From 4a1ac5740869356880523dde83ec0b7804689d42 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 19 Feb 2014 15:28:48 +0200 Subject: Documented cMap --- src/Map.cpp | 12 ++++++++---- src/Map.h | 24 +++++++++++++++++++++--- src/WorldStorage/MapSerializer.h | 2 ++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Map.cpp b/src/Map.cpp index f32d232fa..4f8924af2 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -14,7 +14,7 @@ -cMapDecorator::cMapDecorator(cMap * a_Map, eType a_Type, int a_X, int a_Z, unsigned int a_Rot) +cMapDecorator::cMapDecorator(cMap * a_Map, eType a_Type, int a_X, int a_Z, int a_Rot) : m_Map(a_Map) , m_Type(a_Type) , m_PixelX(a_X) @@ -58,7 +58,7 @@ void cMapDecorator::Update(void) int InsideWidth = (m_Map->GetWidth() / 2) - 1; int InsideHeight = (m_Map->GetHeight() / 2) - 1; - if (m_Player) + if (m_Player != NULL) { int PixelX = (m_Player->GetPosX() - m_Map->GetCenterX()) / PixelWidth; int PixelZ = (m_Player->GetPosZ() - m_Map->GetCenterZ()) / PixelWidth; @@ -200,7 +200,8 @@ void cMap::UpdateRadius(cPlayer & a_Player, unsigned int a_Radius) bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) { - /*unsigned int PixelWidth = GetPixelWidth(); + /* + unsigned int PixelWidth = GetPixelWidth(); int BlockX = m_CenterX + ((a_X - m_Width) * PixelWidth); int BlockZ = m_CenterZ + ((a_Y - m_Height) * PixelWidth); @@ -258,7 +259,8 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) } CalculatePixelCb(this, RelX, RelZ); ASSERT(m_World != NULL); - m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb);*/ + m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb); + */ m_Data[a_Z + (a_X * m_Height)] = 4; @@ -346,6 +348,8 @@ void cMap::UpdateClient(cPlayer * a_Player) if (it->m_NextDecoratorUpdate >= 4) { + // TODO 2014-02-19 xdot + // This is dangerous as the player object may have been destroyed before the decorator is erased from the list UpdateDecorators(); Handle->SendMapDecorators(m_ID, m_Decorators); diff --git a/src/Map.h b/src/Map.h index 76e459621..1a330e1c2 100644 --- a/src/Map.h +++ b/src/Map.h @@ -28,28 +28,36 @@ class cMap; +/** Encapsulates a map decorator. */ class cMapDecorator { public: + enum eType { E_TYPE_PLAYER = 0x00, E_TYPE_ITEM_FRAME = 0x01, + + /** Player outside of the boundaries of the map. */ E_TYPE_PLAYER_OUTSIDE = 0x06 }; public: - cMapDecorator(cMap * a_Map, eType a_Type, int a_X, int a_Z, unsigned int a_Rot); + /** Constructs a map decorator fixed at the specified pixel coordinates. (DEBUG) */ + cMapDecorator(cMap * a_Map, eType a_Type, int a_X, int a_Z, int a_Rot); + /** Constructs a map decorator that tracks a player. */ cMapDecorator(cMap * a_Map, cPlayer * a_Player); + /** Updates the pixel coordinates of the decorator. */ void Update(void); unsigned int GetPixelX(void) const { return m_PixelX; } unsigned int GetPixelZ(void) const { return m_PixelZ; } - unsigned int GetRot(void) const { return m_Rot; } + + int GetRot(void) const { return m_Rot; } eType GetType(void) const { return m_Type; } @@ -68,6 +76,7 @@ protected: unsigned int m_Rot; cPlayer * m_Player; + }; typedef std::list cMapDecoratorList; @@ -77,6 +86,8 @@ typedef std::list cMapDecoratorList; // tolua_begin + +/** Encapsulates an in-game world map. */ class cMap { public: @@ -87,15 +98,20 @@ public: typedef std::vector cColorList; + /** Encapsulates the state of a map client. */ struct cMapClient { cClientHandle * m_Handle; + /** Whether the map scale was modified and needs to be resent. */ bool m_SendInfo; + /** Ticks since last decorator update. */ unsigned int m_NextDecoratorUpdate; + /** Number of pixel data updates. */ Int64 m_DataUpdate; + Int64 m_LastUpdate; }; @@ -107,14 +123,16 @@ public: /** Construct an empty map. */ cMap(unsigned int a_ID, cWorld * a_World); + /** Constructs an empty map at the specified coordinates. */ cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale = 3); - /** Send this map to the specified client. */ + /** Send this map to the specified client. WARNING: Slow */ void SendTo(cClientHandle & a_Client); /** Update a circular region with the specified radius and center (in pixels). */ void UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius); + /** Update a circular region around the specified player. */ void UpdateRadius(cPlayer & a_Player, unsigned int a_Radius); /** Send next update packet and remove invalid decorators */ diff --git a/src/WorldStorage/MapSerializer.h b/src/WorldStorage/MapSerializer.h index 296cc92c8..85fe917f5 100644 --- a/src/WorldStorage/MapSerializer.h +++ b/src/WorldStorage/MapSerializer.h @@ -21,6 +21,7 @@ class cMap; +/** Utility class used to serialize maps. */ class cMapSerializer { public: @@ -50,6 +51,7 @@ private: +/** Utility class used to serialize item ID counts. */ class cIDCountSerializer { public: -- cgit v1.2.3 From d63ce62f3bbe4b8e89b8c54af4b71d77bcc7e052 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 19 Feb 2014 14:45:09 +0100 Subject: Rename SkullEntity to MobHeadEntity --- src/Bindings/ManualBindings.cpp | 4 +- src/BlockEntities/BlockEntity.cpp | 4 +- src/BlockEntities/MobHeadEntity.cpp | 108 ++++++++++++++++++++++++++++++++ src/BlockEntities/MobHeadEntity.h | 79 +++++++++++++++++++++++ src/BlockEntities/SkullEntity.cpp | 108 -------------------------------- src/BlockEntities/SkullEntity.h | 79 ----------------------- src/Blocks/BlockHandler.cpp | 4 +- src/Blocks/BlockMobHead.h | 69 ++++++++++++++++++++ src/Blocks/BlockSkull.h | 69 -------------------- src/CMakeLists.txt | 2 +- src/Chunk.cpp | 6 +- src/Chunk.h | 8 +-- src/ChunkMap.cpp | 4 +- src/ChunkMap.h | 8 +-- src/Defines.h | 4 +- src/Items/ItemHandler.cpp | 4 +- src/Items/ItemMobHead.h | 42 +++++++++++++ src/Items/ItemSkull.h | 44 ------------- src/Protocol/Protocol17x.cpp | 18 +++--- src/World.cpp | 4 +- src/World.h | 8 +-- src/WorldStorage/NBTChunkSerializer.cpp | 14 ++--- src/WorldStorage/NBTChunkSerializer.h | 4 +- src/WorldStorage/WSSAnvil.cpp | 16 ++--- src/WorldStorage/WSSAnvil.h | 2 +- 25 files changed, 355 insertions(+), 357 deletions(-) create mode 100644 src/BlockEntities/MobHeadEntity.cpp create mode 100644 src/BlockEntities/MobHeadEntity.h delete mode 100644 src/BlockEntities/SkullEntity.cpp delete mode 100644 src/BlockEntities/SkullEntity.h create mode 100644 src/Blocks/BlockMobHead.h delete mode 100644 src/Blocks/BlockSkull.h create mode 100644 src/Items/ItemMobHead.h delete mode 100644 src/Items/ItemSkull.h diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 70f3fbcf2..41b4cc0f4 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -22,7 +22,7 @@ #include "../BlockEntities/FurnaceEntity.h" #include "../BlockEntities/HopperEntity.h" #include "../BlockEntities/NoteEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "md5/md5.h" #include "../LineBlockTracer.h" #include "../WorldStorage/SchematicFileSerializer.h" @@ -2417,7 +2417,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "DoWithFurnaceAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ); - tolua_function(tolua_S, "DoWithSkullBlockAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithMobHeadBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk); diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index f01a139d2..57ad83de9 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -15,7 +15,7 @@ #include "JukeboxEntity.h" #include "NoteEntity.h" #include "SignEntity.h" -#include "SkullEntity.h" +#include "MobHeadEntity.h" @@ -30,7 +30,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp new file mode 100644 index 000000000..c0a1781f6 --- /dev/null +++ b/src/BlockEntities/MobHeadEntity.cpp @@ -0,0 +1,108 @@ + +// MobHeadEntity.cpp + +// Implements the cMobHeadEntity class representing a single skull/head in the world + +#include "Globals.h" +#include "json/json.h" +#include "MobHeadEntity.h" +#include "../Entities/Player.h" + + + + + +cMobHeadEntity::cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), + m_Owner("") +{ +} + + + + + +void cMobHeadEntity::UsedBy(cPlayer * a_Player) +{ + UNUSED(a_Player); +} + + + + + +void cMobHeadEntity::SetType(const eMobHeadType & a_Type) +{ + if ((!m_Owner.empty()) && (a_Type != SKULL_TYPE_PLAYER)) + { + m_Owner = ""; + } + m_Type = a_Type; +} + + + + + +void cMobHeadEntity::SetRotation(eMobHeadRotation a_Rotation) +{ + m_Rotation = a_Rotation; +} + + + + + +void cMobHeadEntity::SetOwner(const AString & a_Owner) +{ + if ((a_Owner.length() > 16) || (m_Type != SKULL_TYPE_PLAYER)) + { + return; + } + m_Owner = a_Owner; +} + + + + + +void cMobHeadEntity::SendTo(cClientHandle & a_Client) +{ + a_Client.SendUpdateBlockEntity(*this); +} + + + + + +bool cMobHeadEntity::LoadFromJson(const Json::Value & a_Value) +{ + m_PosX = a_Value.get("x", 0).asInt(); + m_PosY = a_Value.get("y", 0).asInt(); + m_PosZ = a_Value.get("z", 0).asInt(); + + m_Type = static_cast(a_Value.get("Type", 0).asInt()); + m_Rotation = static_cast(a_Value.get("Rotation", 0).asInt()); + m_Owner = a_Value.get("Owner", "").asString(); + + return true; +} + + + + + +void cMobHeadEntity::SaveToJson(Json::Value & a_Value) +{ + a_Value["x"] = m_PosX; + a_Value["y"] = m_PosY; + a_Value["z"] = m_PosZ; + + a_Value["Type"] = m_Type; + a_Value["Rotation"] = m_Rotation; + a_Value["Owner"] = m_Owner; +} + + + + diff --git a/src/BlockEntities/MobHeadEntity.h b/src/BlockEntities/MobHeadEntity.h new file mode 100644 index 000000000..367eb15e7 --- /dev/null +++ b/src/BlockEntities/MobHeadEntity.h @@ -0,0 +1,79 @@ +// MobHeadEntity.h + +// Declares the cMobHeadEntity class representing a single skull/head in the world + + + + + +#pragma once + +#include "BlockEntity.h" + + + + + +namespace Json +{ + class Value; +} + + + + + +// tolua_begin + +class cMobHeadEntity : + public cBlockEntity +{ + typedef cBlockEntity super; + +public: + + // tolua_end + + /** Creates a new mob head entity at the specified block coords. a_World may be NULL */ + cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); + + bool LoadFromJson( const Json::Value& a_Value ); + virtual void SaveToJson(Json::Value& a_Value ) override; + + // tolua_begin + + /** Set the Type */ + void SetType(const eMobHeadType & a_SkullType); + + /** Set the Rotation */ + void SetRotation(eMobHeadRotation a_Rotation); + + /** Set the Player Name for Mobheads with Player type */ + void SetOwner(const AString & a_Owner); + + /** Get the Type */ + eMobHeadType GetType(void) const { return m_Type; } + + /** Get the Rotation */ + eMobHeadRotation GetRotation(void) const { return m_Rotation; } + + /** Get the setted Player Name */ + AString GetOwner(void) const { return m_Owner; } + + // tolua_end + + virtual void UsedBy(cPlayer * a_Player) override; + virtual void SendTo(cClientHandle & a_Client) override; + + static const char * GetClassStatic(void) { return "cMobHeadEntity"; } + +private: + + eMobHeadType m_Type; + eMobHeadRotation m_Rotation; + AString m_Owner; +} ; // tolua_export + + + + diff --git a/src/BlockEntities/SkullEntity.cpp b/src/BlockEntities/SkullEntity.cpp deleted file mode 100644 index 43b97b93e..000000000 --- a/src/BlockEntities/SkullEntity.cpp +++ /dev/null @@ -1,108 +0,0 @@ - -// SkullEntity.cpp - -// Implements the cSkullEntity class representing a single skull/head in the world - -#include "Globals.h" -#include "json/json.h" -#include "SkullEntity.h" -#include "../Entities/Player.h" - - - - - -cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : - super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), - m_Owner("") -{ -} - - - - - -void cSkullEntity::UsedBy(cPlayer * a_Player) -{ - UNUSED(a_Player); -} - - - - - -void cSkullEntity::SetSkullType(const eSkullType & a_SkullType) -{ - if ((!m_Owner.empty()) && (a_SkullType != SKULL_TYPE_PLAYER)) - { - m_Owner = ""; - } - m_SkullType = a_SkullType; -} - - - - - -void cSkullEntity::SetRotation(eSkullRotation a_Rotation) -{ - m_Rotation = a_Rotation; -} - - - - - -void cSkullEntity::SetOwner(const AString & a_Owner) -{ - if ((a_Owner.length() > 16) || (m_SkullType != SKULL_TYPE_PLAYER)) - { - return; - } - m_Owner = a_Owner; -} - - - - - -void cSkullEntity::SendTo(cClientHandle & a_Client) -{ - a_Client.SendUpdateBlockEntity(*this); -} - - - - - -bool cSkullEntity::LoadFromJson(const Json::Value & a_Value) -{ - m_PosX = a_Value.get("x", 0).asInt(); - m_PosY = a_Value.get("y", 0).asInt(); - m_PosZ = a_Value.get("z", 0).asInt(); - - m_SkullType = static_cast(a_Value.get("SkullType", 0).asInt()); - m_Rotation = static_cast(a_Value.get("Rotation", 0).asInt()); - m_Owner = a_Value.get("Owner", "").asString(); - - return true; -} - - - - - -void cSkullEntity::SaveToJson(Json::Value & a_Value) -{ - a_Value["x"] = m_PosX; - a_Value["y"] = m_PosY; - a_Value["z"] = m_PosZ; - - a_Value["SkullType"] = m_SkullType; - a_Value["Rotation"] = m_Rotation; - a_Value["Owner"] = m_Owner; -} - - - - diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h deleted file mode 100644 index 3dc355623..000000000 --- a/src/BlockEntities/SkullEntity.h +++ /dev/null @@ -1,79 +0,0 @@ -// SkullEntity.h - -// Declares the cSkullEntity class representing a single skull/head in the world - - - - - -#pragma once - -#include "BlockEntity.h" - - - - - -namespace Json -{ - class Value; -} - - - - - -// tolua_begin - -class cSkullEntity : - public cBlockEntity -{ - typedef cBlockEntity super; - -public: - - // tolua_end - - /** Creates a new skull entity at the specified block coords. a_World may be NULL */ - cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); - - bool LoadFromJson( const Json::Value& a_Value ); - virtual void SaveToJson(Json::Value& a_Value ) override; - - // tolua_begin - - /** Set the Skull Type */ - void SetSkullType(const eSkullType & a_SkullType); - - /** Set the Rotation */ - void SetRotation(eSkullRotation a_Rotation); - - /** Set the Player Name for Player Skull */ - void SetOwner(const AString & a_Owner); - - /** Get the Skull Type */ - eSkullType GetSkullType(void) const { return m_SkullType; } - - /** Get the Rotation */ - eSkullRotation GetRotation(void) const { return m_Rotation; } - - /** Get the setted Player Name */ - AString GetOwner(void) const { return m_Owner; } - - // tolua_end - - virtual void UsedBy(cPlayer * a_Player) override; - virtual void SendTo(cClientHandle & a_Client) override; - - static const char * GetClassStatic(void) { return "cSkullEntity"; } - -private: - - eSkullType m_SkullType; - eSkullRotation m_Rotation; - AString m_Owner; -} ; // tolua_export - - - - diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 870de7a7d..09a1244ea 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -34,7 +34,7 @@ #include "BlockGlass.h" #include "BlockGlowstone.h" #include "BlockGravel.h" -#include "BlockSkull.h" +#include "BlockMobHead.h" #include "BlockHopper.h" #include "BlockIce.h" #include "BlockLadder.h" @@ -147,7 +147,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_GRASS: return new cBlockDirtHandler (a_BlockType); case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType); case E_BLOCK_HAY_BALE: return new cBlockSidewaysHandler (a_BlockType); - case E_BLOCK_HEAD: return new cBlockSkullHandler (a_BlockType); + case E_BLOCK_HEAD: return new cBlockMobHeadHandler (a_BlockType); case E_BLOCK_HOPPER: return new cBlockHopperHandler (a_BlockType); case E_BLOCK_ICE: return new cBlockIceHandler (a_BlockType); case E_BLOCK_INACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h new file mode 100644 index 000000000..6a00c3acd --- /dev/null +++ b/src/Blocks/BlockMobHead.h @@ -0,0 +1,69 @@ + +#pragma once + +#include "BlockEntity.h" +#include "../BlockEntities/MobHeadEntity.h" + + + + + +class cBlockMobHeadHandler : + public cBlockEntityHandler +{ +public: + cBlockMobHeadHandler(BLOCKTYPE a_BlockType) + : cBlockEntityHandler(a_BlockType) + { + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + a_Pickups.push_back(cItem(E_ITEM_HEAD, 1, 0)); + } + + virtual void OnPlacedByPlayer( + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta + ) override + { + class cCallback : public cMobHeadBlockCallback + { + cPlayer * m_Player; + NIBBLETYPE m_OldBlockMeta; + NIBBLETYPE m_NewBlockMeta; + + virtual bool Item (cMobHeadEntity * a_MobHeadEntity) + { + int Rotation = 0; + if (m_NewBlockMeta == 1) + { + Rotation = (int) floor(m_Player->GetYaw() * 16.0F / 360.0F + 0.5) & 0xF; + } + + a_MobHeadEntity->SetType(static_cast(m_OldBlockMeta)); + a_MobHeadEntity->SetRotation(static_cast(Rotation)); + return false; + } + + public: + cCallback (cPlayer * a_Player, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) : + m_Player(a_Player), + m_OldBlockMeta(a_OldBlockMeta), + m_NewBlockMeta(a_NewBlockMeta) + {} + }; + cCallback Callback(a_Player, a_BlockMeta, static_cast(a_BlockFace)); + + a_BlockMeta = a_BlockFace; + cWorld * World = (cWorld *) &a_WorldInterface; + World->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, Callback); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); + } +} ; + + + + diff --git a/src/Blocks/BlockSkull.h b/src/Blocks/BlockSkull.h deleted file mode 100644 index eea5ac922..000000000 --- a/src/Blocks/BlockSkull.h +++ /dev/null @@ -1,69 +0,0 @@ - -#pragma once - -#include "BlockEntity.h" -#include "../BlockEntities/SkullEntity.h" - - - - - -class cBlockSkullHandler : - public cBlockEntityHandler -{ -public: - cBlockSkullHandler(BLOCKTYPE a_BlockType) - : cBlockEntityHandler(a_BlockType) - { - } - - virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override - { - a_Pickups.push_back(cItem(E_ITEM_HEAD, 1, 0)); - } - - virtual void OnPlacedByPlayer( - cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, - int a_CursorX, int a_CursorY, int a_CursorZ, - BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta - ) override - { - class cCallback : public cSkullBlockCallback - { - cPlayer * m_Player; - NIBBLETYPE m_OldBlockMeta; - NIBBLETYPE m_NewBlockMeta; - - virtual bool Item (cSkullEntity * a_SkullEntity) - { - int Rotation = 0; - if (m_NewBlockMeta == 1) - { - Rotation = (int) floor(m_Player->GetYaw() * 16.0F / 360.0F + 0.5) & 0xF; - } - - a_SkullEntity->SetSkullType(static_cast(m_OldBlockMeta)); - a_SkullEntity->SetRotation(static_cast(Rotation)); - return false; - } - - public: - cCallback (cPlayer * a_Player, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) : - m_Player(a_Player), - m_OldBlockMeta(a_OldBlockMeta), - m_NewBlockMeta(a_NewBlockMeta) - {} - }; - cCallback Callback(a_Player, a_BlockMeta, static_cast(a_BlockFace)); - - a_BlockMeta = a_BlockFace; - cWorld * World = (cWorld *) &a_WorldInterface; - World->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, Callback); - a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); - } -} ; - - - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e46aa3ee5..bfece3312 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,7 +39,7 @@ if (NOT MSVC) BlockEntities/JukeboxEntity.h BlockEntities/NoteEntity.h BlockEntities/SignEntity.h - BlockEntities/SkullEntity.h + BlockEntities/MobHeadEntity.h BlockID.h BoundingBox.h ChatColor.h diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 8b03732f3..0e757be6e 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -19,7 +19,7 @@ #include "BlockEntities/JukeboxEntity.h" #include "BlockEntities/NoteEntity.h" #include "BlockEntities/SignEntity.h" -#include "BlockEntities/SkullEntity.h" +#include "BlockEntities/MobHeadEntity.h" #include "Entities/Pickup.h" #include "Item.h" #include "Noise.h" @@ -2312,7 +2312,7 @@ bool cChunk::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom -bool cChunk::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +bool cChunk::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) { // The blockentity list is locked by the parent chunkmap's CS for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2) @@ -2329,7 +2329,7 @@ bool cChunk::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkull } // The correct block entity is here, - if (a_Callback.Item((cSkullEntity *)*itr)) + if (a_Callback.Item((cMobHeadEntity *)*itr)) { return false; } diff --git a/src/Chunk.h b/src/Chunk.h index 27388deb4..6bec60813 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -31,7 +31,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; -class cSkullEntity; +class cMobHeadEntity; class cBlockArea; class cPawn; class cPickup; @@ -48,7 +48,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cSkullBlockCallback; +typedef cItemCallback cMobHeadBlockCallback; @@ -245,8 +245,8 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); - /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ - bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); + /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob header block at those coords or callback returns true, returns true if found */ + bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 5f1674c03..0d19ecd28 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2121,7 +2121,7 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c -bool cChunkMap::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +bool cChunkMap::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) { int ChunkX, ChunkZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; @@ -2132,7 +2132,7 @@ bool cChunkMap::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSk { return false; } - return Chunk->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return Chunk->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 02c245dc9..fb587a52e 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -25,7 +25,7 @@ class cDropSpenserEntity; class cFurnaceEntity; class cNoteEntity; class cCommandBlockEntity; -class cSkullEntity; +class cMobHeadEntity; class cPawn; class cPickup; class cChunkDataSerializer; @@ -44,7 +44,7 @@ typedef cItemCallback cDropSpenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cSkullBlockCallback; +typedef cItemCallback cMobHeadBlockCallback; typedef cItemCallback cChunkCallback; @@ -247,8 +247,8 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Lua-accessible - /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ - bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Lua-accessible + /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ + bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Lua-accessible /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/Defines.h b/src/Defines.h index 7e22cbdc5..ba2866f83 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -174,7 +174,7 @@ enum eWeather -enum eSkullType +enum eMobHeadType { SKULL_TYPE_SKELETON = 0, SKULL_TYPE_WITHER = 1, @@ -187,7 +187,7 @@ enum eSkullType -enum eSkullRotation +enum eMobHeadRotation { SKULL_ROTATION_NORTH = 0, SKULL_ROTATION_NORTH_NORTH_EAST = 1, diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 4ede75cf1..3c3d98858 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -35,7 +35,7 @@ #include "ItemShears.h" #include "ItemShovel.h" #include "ItemSign.h" -#include "ItemSkull.h" +#include "ItemMobHead.h" #include "ItemSpawnEgg.h" #include "ItemSugarcane.h" #include "ItemSword.h" @@ -111,7 +111,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType); case E_ITEM_SIGN: return new cItemSignHandler(a_ItemType); - case E_ITEM_HEAD: return new cItemSkullHandler(a_ItemType); + case E_ITEM_HEAD: return new cItemMobHeadHandler(a_ItemType); case E_ITEM_SNOWBALL: return new cItemSnowballHandler(); case E_ITEM_SPAWN_EGG: return new cItemSpawnEggHandler(a_ItemType); case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemType); diff --git a/src/Items/ItemMobHead.h b/src/Items/ItemMobHead.h new file mode 100644 index 000000000..5ae040282 --- /dev/null +++ b/src/Items/ItemMobHead.h @@ -0,0 +1,42 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemMobHeadHandler : + public cItemHandler +{ +public: + cItemMobHeadHandler(int a_ItemType) : + cItemHandler(a_ItemType) + { + } + + + virtual bool IsPlaceable(void) override + { + return true; + } + + + virtual bool GetPlacementBlockTypeMeta( + cWorld * a_World, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = E_BLOCK_HEAD; + a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); + return true; + } +} ; + + + + diff --git a/src/Items/ItemSkull.h b/src/Items/ItemSkull.h deleted file mode 100644 index 3648f1436..000000000 --- a/src/Items/ItemSkull.h +++ /dev/null @@ -1,44 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - - - - - -class cItemSkullHandler : - public cItemHandler -{ -public: - cItemSkullHandler(int a_ItemType) : - cItemHandler(a_ItemType) - { - } - - - virtual bool IsPlaceable(void) override - { - return true; - } - - - virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, - int a_CursorX, int a_CursorY, int a_CursorZ, - BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta - ) override - { - - a_BlockType = E_BLOCK_HEAD; - a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); - - return true; - } -} ; - - - - diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 07b23e0ac..344dcc676 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -26,7 +26,7 @@ Implements the 1.7.x protocol classes: #include "../Mobs/IncludeAllMonsters.h" #include "../UI/Window.h" #include "../BlockEntities/CommandBlockEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "../CompositeChat.h" @@ -1043,7 +1043,7 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text - case E_BLOCK_HEAD: Action = 4; break; // Update Skull entity + case E_BLOCK_HEAD: Action = 4; break; // Update Mobhead entity default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break; } Pkt.WriteByte(Action); @@ -2273,14 +2273,14 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt } case E_BLOCK_HEAD: { - cSkullEntity & SkullEntity = (cSkullEntity &)a_BlockEntity; + cMobHeadEntity & MobHeadEntity = (cMobHeadEntity &)a_BlockEntity; - Writer.AddInt("x", SkullEntity.GetPosX()); - Writer.AddInt("y", SkullEntity.GetPosY()); - Writer.AddInt("z", SkullEntity.GetPosZ()); - Writer.AddByte("SkullType", SkullEntity.GetSkullType() & 0xFF); - Writer.AddByte("Rot", SkullEntity.GetRotation() & 0xFF); - Writer.AddString("ExtraType", SkullEntity.GetOwner().c_str()); + Writer.AddInt("x", MobHeadEntity.GetPosX()); + Writer.AddInt("y", MobHeadEntity.GetPosY()); + Writer.AddInt("z", MobHeadEntity.GetPosZ()); + Writer.AddByte("SkullType", MobHeadEntity.GetType() & 0xFF); + Writer.AddByte("Rot", MobHeadEntity.GetRotation() & 0xFF); + Writer.AddString("ExtraType", MobHeadEntity.GetOwner().c_str()); Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though break; } diff --git a/src/World.cpp b/src/World.cpp index 14d904d72..c0a621a2c 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1165,9 +1165,9 @@ bool cWorld::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom -bool cWorld::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +bool cWorld::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) { - return m_ChunkMap->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } diff --git a/src/World.h b/src/World.h index 4e83833ed..9c7079a92 100644 --- a/src/World.h +++ b/src/World.h @@ -45,7 +45,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; -class cSkullEntity; +class cMobHeadEntity; class cMobCensus; class cCompositeChat; @@ -58,7 +58,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cSkullBlockCallback; +typedef cItemCallback cMobHeadBlockCallback; @@ -512,8 +512,8 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Exported in ManualBindings.cpp - /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ - bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Exported in ManualBindings.cpp + /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ + bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Exported in ManualBindings.cpp /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Exported in ManualBindings.cpp diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 6da141728..cf6df114e 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -19,7 +19,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "../Entities/Entity.h" #include "../Entities/FallingBlock.h" @@ -261,13 +261,13 @@ void cNBTChunkSerializer::AddSignEntity(cSignEntity * a_Sign) -void cNBTChunkSerializer::AddSkullEntity(cSkullEntity * a_Skull) +void cNBTChunkSerializer::AddMobHeadEntity(cMobHeadEntity * a_MobHead) { m_Writer.BeginCompound(""); - AddBasicTileEntity(a_Skull, "Skull"); - m_Writer.AddByte ("SkullType", a_Skull->GetSkullType() & 0xFF); - m_Writer.AddByte ("Rot", a_Skull->GetRotation() & 0xFF); - m_Writer.AddString("ExtraType", a_Skull->GetOwner()); + AddBasicTileEntity(a_MobHead, "Skull"); + m_Writer.AddByte ("SkullType", a_MobHead->GetType() & 0xFF); + m_Writer.AddByte ("Rot", a_MobHead->GetRotation() & 0xFF); + m_Writer.AddString("ExtraType", a_MobHead->GetOwner()); m_Writer.EndCompound(); } @@ -681,7 +681,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: AddSignEntity ((cSignEntity *) a_Entity); break; - case E_BLOCK_HEAD: AddSkullEntity ((cSkullEntity *) a_Entity); break; + case E_BLOCK_HEAD: AddMobHeadEntity ((cMobHeadEntity *) a_Entity); break; case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break; case E_BLOCK_JUKEBOX: AddJukeboxEntity ((cJukeboxEntity *) a_Entity); break; case E_BLOCK_COMMAND_BLOCK: AddCommandBlockEntity((cCommandBlockEntity *) a_Entity); break; diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index fd5601e47..5f9e16ed1 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -29,7 +29,7 @@ class cHopperEntity; class cJukeboxEntity; class cNoteEntity; class cSignEntity; -class cSkullEntity; +class cMobHeadEntity; class cFallingBlock; class cMinecart; class cMinecartWithChest; @@ -94,7 +94,7 @@ protected: void AddJukeboxEntity (cJukeboxEntity * a_Jukebox); void AddNoteEntity (cNoteEntity * a_Note); void AddSignEntity (cSignEntity * a_Sign); - void AddSkullEntity (cSkullEntity * a_Skull); + void AddMobHeadEntity (cMobHeadEntity * a_MobHead); void AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock); // Entities: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 58dc2e9e4..d4490c7fe 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -24,7 +24,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "../Mobs/Monster.h" @@ -600,7 +600,7 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con } else if (strncmp(a_NBT.GetData(sID), "Skull", a_NBT.GetDataLength(sID)) == 0) { - LoadSkullFromNBT(a_BlockEntities, a_NBT, Child); + LoadMobHeadFromNBT(a_BlockEntities, a_NBT, Child); } else if (strncmp(a_NBT.GetData(sID), "Trap", a_NBT.GetDataLength(sID)) == 0) { @@ -932,7 +932,7 @@ void cWSSAnvil::LoadSignFromNBT(cBlockEntityList & a_BlockEntities, const cParse -void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) +void cWSSAnvil::LoadMobHeadFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) { ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); int x, y, z; @@ -940,27 +940,27 @@ void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cPars { return; } - std::auto_ptr Skull(new cSkullEntity(x, y, z, m_World)); + std::auto_ptr MobHead(new cMobHeadEntity(x, y, z, m_World)); int currentLine = a_NBT.FindChildByName(a_TagIdx, "SkullType"); if (currentLine >= 0) { - Skull->SetSkullType(static_cast(a_NBT.GetByte(currentLine))); + MobHead->SetType(static_cast(a_NBT.GetByte(currentLine))); } currentLine = a_NBT.FindChildByName(a_TagIdx, "Rot"); if (currentLine >= 0) { - Skull->SetRotation(static_cast(a_NBT.GetByte(currentLine))); + MobHead->SetRotation(static_cast(a_NBT.GetByte(currentLine))); } currentLine = a_NBT.FindChildByName(a_TagIdx, "ExtraType"); if (currentLine >= 0) { - Skull->SetOwner(a_NBT.GetString(currentLine)); + MobHead->SetOwner(a_NBT.GetString(currentLine)); } - a_BlockEntities.push_back(Skull.release()); + a_BlockEntities.push_back(MobHead.release()); } diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 9c9e17258..541371560 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -139,7 +139,7 @@ protected: void LoadJukeboxFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadNoteFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadSignFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); - void LoadSkullFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadMobHeadFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadCommandBlockFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength); -- cgit v1.2.3 From a5a52fe1605c33e2c3687c6de9f7925cbe9a9a47 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 19 Feb 2014 16:58:31 +0100 Subject: Add new Trees (without Generator) --- src/BlockID.h | 2 ++ src/Blocks/BlockHandler.cpp | 4 ++++ src/Blocks/BlockLeaves.h | 2 ++ src/Generating/Trees.cpp | 18 ++++++++++++++++++ src/Generating/Trees.h | 6 ++++++ src/World.cpp | 2 ++ 6 files changed, 34 insertions(+) diff --git a/src/BlockID.h b/src/BlockID.h index 740c5fc90..e1716b8b3 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -531,6 +531,8 @@ enum E_META_SAPLING_CONIFER = 1, E_META_SAPLING_BIRCH = 2, E_META_SAPLING_JUNGLE = 3, + E_META_SAPLING_ACACIA = 4, + E_META_SAPLING_DARKOAC = 5, // E_BLOCK_SILVERFISH_EGG metas: E_META_SILVERFISH_EGG_STONE = 0, diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 6c9bbeb02..fa9e797a2 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -38,6 +38,7 @@ #include "BlockIce.h" #include "BlockLadder.h" #include "BlockLeaves.h" +#include "BlockNewLeaves.h" #include "BlockLever.h" #include "BlockMelon.h" #include "BlockMushroom.h" @@ -107,6 +108,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) switch(a_BlockType) { // Block handlers, alphabetically sorted: + case E_BLOCK_ACACIA_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_ACTIVATOR_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_BED: return new cBlockBedHandler (a_BlockType); case E_BLOCK_BIRCH_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); @@ -125,6 +127,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_COBBLESTONE_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_COBWEB: return new cBlockCobWebHandler (a_BlockType); case E_BLOCK_CROPS: return new cBlockCropsHandler (a_BlockType); + case E_BLOCK_DARK_OAK_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_DEAD_BUSH: return new cBlockDeadBushHandler (a_BlockType); case E_BLOCK_DETECTOR_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_DIAMOND_ORE: return new cBlockOreHandler (a_BlockType); @@ -167,6 +170,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_NETHER_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_NETHER_PORTAL: return new cBlockPortalHandler (a_BlockType); case E_BLOCK_NETHER_WART: return new cBlockNetherWartHandler (a_BlockType); + case E_BLOCK_NEW_LEAVES: return new cBlockNewLeavesHandler (a_BlockType); case E_BLOCK_NEW_LOG: return new cBlockSidewaysHandler (a_BlockType); case E_BLOCK_NOTE_BLOCK: return new cBlockNoteHandler (a_BlockType); case E_BLOCK_PISTON: return new cBlockPistonHandler (a_BlockType); diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index ad6e440e2..7b8f0b378 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -139,6 +139,8 @@ bool HasNearLog(cBlockArea & a_Area, int a_BlockX, int a_BlockY, int a_BlockZ) { switch (Types[i]) { + case E_BLOCK_NEW_LEAVES: + case E_BLOCK_NEW_LOG: case E_BLOCK_LEAVES: case E_BLOCK_LOG: { diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp index 7e8a3c75f..ada20954a 100644 --- a/src/Generating/Trees.cpp +++ b/src/Generating/Trees.cpp @@ -382,6 +382,24 @@ void GetBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Nois +void GetAcaciaTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +{ + // TODO +} + + + + + +void GetDarkoacTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +{ + // TODO +} + + + + + void GetTallBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) { int Height = 9 + (a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) % 3); diff --git a/src/Generating/Trees.h b/src/Generating/Trees.h index 514158eb7..7619f4458 100644 --- a/src/Generating/Trees.h +++ b/src/Generating/Trees.h @@ -63,6 +63,12 @@ void GetLargeAppleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a /// Generates an image of a random birch tree void GetBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +/// Generates an image of a random acacia tree +void GetAcaciaTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); + +/// Generates an image of a random darkoac tree +void GetDarkoacTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); + /// Generates an image of a random large birch tree void GetTallBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks,sSetBlockVector & a_OtherBlocks); diff --git a/src/World.cpp b/src/World.cpp index e57675c44..369a854d2 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1211,6 +1211,8 @@ void cWorld::GrowTreeFromSapling(int a_X, int a_Y, int a_Z, NIBBLETYPE a_Sapling case E_META_SAPLING_BIRCH: GetBirchTreeImage (a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; case E_META_SAPLING_CONIFER: GetConiferTreeImage(a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; case E_META_SAPLING_JUNGLE: GetJungleTreeImage (a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; + case E_META_SAPLING_ACACIA: GetAcaciaTreeImage (a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; + case E_META_SAPLING_DARKOAC: GetDarkoacTreeImage(a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; } Other.insert(Other.begin(), Logs.begin(), Logs.end()); Logs.clear(); -- cgit v1.2.3 From 16f3809ded538611c6c26a41316cf35bb8b1f5a5 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 19 Feb 2014 19:18:40 +0100 Subject: Add BlockNewLeaves.h and rename Darkoac to Darkoak --- src/BlockID.h | 12 ++++++------ src/Blocks/BlockNewLeaves.h | 42 ++++++++++++++++++++++++++++++++++++++++++ src/Generating/Trees.cpp | 2 +- src/Generating/Trees.h | 4 ++-- src/World.cpp | 12 ++++++------ 5 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 src/Blocks/BlockNewLeaves.h diff --git a/src/BlockID.h b/src/BlockID.h index e1716b8b3..3413555f4 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -527,12 +527,12 @@ enum E_META_SANDSTONE_SMOOTH = 2, // E_BLOCK_SAPLING metas (lowest 3 bits): - E_META_SAPLING_APPLE = 0, - E_META_SAPLING_CONIFER = 1, - E_META_SAPLING_BIRCH = 2, - E_META_SAPLING_JUNGLE = 3, - E_META_SAPLING_ACACIA = 4, - E_META_SAPLING_DARKOAC = 5, + E_META_SAPLING_APPLE = 0, + E_META_SAPLING_CONIFER = 1, + E_META_SAPLING_BIRCH = 2, + E_META_SAPLING_JUNGLE = 3, + E_META_SAPLING_ACACIA = 4, + E_META_SAPLING_DARK_OAK = 5, // E_BLOCK_SILVERFISH_EGG metas: E_META_SILVERFISH_EGG_STONE = 0, diff --git a/src/Blocks/BlockNewLeaves.h b/src/Blocks/BlockNewLeaves.h new file mode 100644 index 000000000..5a267e8c6 --- /dev/null +++ b/src/Blocks/BlockNewLeaves.h @@ -0,0 +1,42 @@ +#pragma once +#include "BlockHandler.h" +#include "BlockLeaves.h" +#include "../World.h" + + + + + + +class cBlockNewLeavesHandler : + public cBlockLeavesHandler +{ +public: + cBlockNewLeavesHandler(BLOCKTYPE a_BlockType) + : cBlockLeavesHandler(a_BlockType) + { + } + + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + MTRand rand; + + // Only the first 2 bits contain the display information, the others are for growing + if (rand.randInt(5) == 0) + { + a_Pickups.push_back(cItem(E_BLOCK_SAPLING, 1, (a_BlockMeta & 3) + 4)); + } + } + + + void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override + { + cBlockHandler::OnDestroyed(a_ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); + } +} ; + + + + + diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp index ada20954a..a660285d1 100644 --- a/src/Generating/Trees.cpp +++ b/src/Generating/Trees.cpp @@ -391,7 +391,7 @@ void GetAcaciaTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noi -void GetDarkoacTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetDarkoakTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) { // TODO } diff --git a/src/Generating/Trees.h b/src/Generating/Trees.h index 7619f4458..00f343a3d 100644 --- a/src/Generating/Trees.h +++ b/src/Generating/Trees.h @@ -66,8 +66,8 @@ void GetBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Nois /// Generates an image of a random acacia tree void GetAcaciaTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); -/// Generates an image of a random darkoac tree -void GetDarkoacTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +/// Generates an image of a random darkoak tree +void GetDarkoakTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); /// Generates an image of a random large birch tree void GetTallBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks,sSetBlockVector & a_OtherBlocks); diff --git a/src/World.cpp b/src/World.cpp index 369a854d2..313a8d7fa 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1207,12 +1207,12 @@ void cWorld::GrowTreeFromSapling(int a_X, int a_Y, int a_Z, NIBBLETYPE a_Sapling sSetBlockVector Logs, Other; switch (a_SaplingMeta & 0x07) { - case E_META_SAPLING_APPLE: GetAppleTreeImage (a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; - case E_META_SAPLING_BIRCH: GetBirchTreeImage (a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; - case E_META_SAPLING_CONIFER: GetConiferTreeImage(a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; - case E_META_SAPLING_JUNGLE: GetJungleTreeImage (a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; - case E_META_SAPLING_ACACIA: GetAcaciaTreeImage (a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; - case E_META_SAPLING_DARKOAC: GetDarkoacTreeImage(a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; + case E_META_SAPLING_APPLE: GetAppleTreeImage (a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; + case E_META_SAPLING_BIRCH: GetBirchTreeImage (a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; + case E_META_SAPLING_CONIFER: GetConiferTreeImage(a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; + case E_META_SAPLING_JUNGLE: GetJungleTreeImage (a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; + case E_META_SAPLING_ACACIA: GetAcaciaTreeImage (a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; + case E_META_SAPLING_DARK_OAK: GetDarkoakTreeImage(a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), Logs, Other); break; } Other.insert(Other.begin(), Logs.begin(), Logs.end()); Logs.clear(); -- cgit v1.2.3 From 58a708825fa7e79c9dcbe6ad1bbbb2c0c3247edc Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 19 Feb 2014 20:57:14 +0200 Subject: cMapDecorator: Implemented random rotations --- src/Map.cpp | 25 +++++++++++++++---------- src/Map.h | 6 +++--- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Map.cpp b/src/Map.cpp index 4f8924af2..a194dbd96 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -9,6 +9,7 @@ #include "World.h" #include "Chunk.h" #include "Entities/Player.h" +#include "FastRandom.h" @@ -52,14 +53,14 @@ T Clamp(T a_X, T a_Min, T a_Max) void cMapDecorator::Update(void) { - ASSERT(m_Map != NULL); - unsigned int PixelWidth = m_Map->GetPixelWidth(); - - int InsideWidth = (m_Map->GetWidth() / 2) - 1; - int InsideHeight = (m_Map->GetHeight() / 2) - 1; - if (m_Player != NULL) { + ASSERT(m_Map != NULL); + unsigned int PixelWidth = m_Map->GetPixelWidth(); + + int InsideWidth = (m_Map->GetWidth() / 2) - 1; + int InsideHeight = (m_Map->GetHeight() / 2) - 1; + int PixelX = (m_Player->GetPosX() - m_Map->GetCenterX()) / PixelWidth; int PixelZ = (m_Player->GetPosZ() - m_Map->GetCenterZ()) / PixelWidth; @@ -67,18 +68,22 @@ void cMapDecorator::Update(void) m_PixelX = (2 * PixelX) + 1; m_PixelZ = (2 * PixelZ) + 1; - // 1px border if ((PixelX > -InsideWidth) && (PixelX <= InsideWidth) && (PixelZ > -InsideHeight) && (PixelZ <= InsideHeight)) { double Yaw = m_Player->GetYaw(); - m_Rot = (Yaw * 16) / 360; - if (m_Map->GetDimension() == dimNether) { + cFastRandom Random; + Int64 WorldAge = m_Player->GetWorld()->GetWorldAge(); - // TODO 2014-02-18 xdot: Random rotations + // TODO 2014-02-19 xdot: Refine + m_Rot = Random.NextInt(16, WorldAge); + } + else + { + m_Rot = (Yaw * 16) / 360; } m_Type = E_TYPE_PLAYER; diff --git a/src/Map.h b/src/Map.h index 1a330e1c2..3cf9977ab 100644 --- a/src/Map.h +++ b/src/Map.h @@ -51,7 +51,7 @@ public: /** Constructs a map decorator that tracks a player. */ cMapDecorator(cMap * a_Map, cPlayer * a_Player); - /** Updates the pixel coordinates of the decorator. */ + /** Updates the decorator. */ void Update(void); unsigned int GetPixelX(void) const { return m_PixelX; } @@ -123,7 +123,7 @@ public: /** Construct an empty map. */ cMap(unsigned int a_ID, cWorld * a_World); - /** Constructs an empty map at the specified coordinates. */ + /** Construct an empty map at the specified coordinates. */ cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale = 3); /** Send this map to the specified client. WARNING: Slow */ @@ -135,7 +135,7 @@ public: /** Update a circular region around the specified player. */ void UpdateRadius(cPlayer & a_Player, unsigned int a_Radius); - /** Send next update packet and remove invalid decorators */ + /** Send next update packet to the specified player and remove invalid decorators/clients. */ void UpdateClient(cPlayer * a_Player); // tolua_begin -- cgit v1.2.3 From a3fa52ec739d6640f7dc4d481de77d633111cf46 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Feb 2014 10:48:29 +0100 Subject: Fixed bindings for cBlockArea:Get(Rel)BlockTypeMeta(). They no longer require the ghost output params. --- src/Bindings/ManualBindings.cpp | 133 +++++++++++++++++++++++++++++++--------- src/BlockArea.h | 6 ++ 2 files changed, 110 insertions(+), 29 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 41b4cc0f4..c220e5e0a 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -213,7 +213,7 @@ static int tolua_DoWith(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 2 or 3 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); const char * ItemName = tolua_tocppstring(tolua_S, 2, ""); if ((ItemName == NULL) || (ItemName[0] == 0)) @@ -307,7 +307,7 @@ static int tolua_DoWithID(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 2 or 3 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *)tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *)tolua_tousertype(tolua_S, 1, NULL); int ItemID = (int)tolua_tonumber(tolua_S, 2, 0); if (!lua_isfunction(tolua_S, 3)) @@ -397,7 +397,7 @@ static int tolua_DoWithXYZ(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 4 or 5 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3) || !lua_isnumber(tolua_S, 4)) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3"); @@ -491,7 +491,7 @@ static int tolua_ForEachInChunk(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 3 or 4 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3)) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1 and #2"); @@ -585,7 +585,7 @@ static int tolua_ForEach(lua_State * tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 1 or 2 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance"); @@ -682,7 +682,7 @@ static int tolua_cWorld_GetBlockInfo(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -737,7 +737,7 @@ static int tolua_cWorld_GetBlockTypeMeta(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -789,7 +789,7 @@ static int tolua_cWorld_GetSignLines(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -847,7 +847,7 @@ static int tolua_cWorld_SetSignLines(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -896,7 +896,7 @@ static int tolua_cWorld_TryGetHeight(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 3, 0); #ifndef TOLUA_RELEASE @@ -968,7 +968,7 @@ static int tolua_cWorld_QueueTask(lua_State * tolua_S) } // Retrieve the args: - cWorld * self = (cWorld *)tolua_tousertype(tolua_S, 1, 0); + cWorld * self = (cWorld *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance"); @@ -1066,7 +1066,7 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S) static int tolua_cPluginManager_GetAllPlugins(lua_State * tolua_S) { - cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, 0); + cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, NULL); const cPluginManager::PluginMap & AllPlugins = self->GetAllPlugins(); @@ -1290,7 +1290,7 @@ static int tolua_cPluginManager_ForEachCommand(lua_State * tolua_S) return 0; } - cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, 0); + cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { LOGWARN("Error in function call 'ForEachCommand': Not called on an object instance"); @@ -1365,7 +1365,7 @@ static int tolua_cPluginManager_ForEachConsoleCommand(lua_State * tolua_S) return 0; } - cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, 0); + cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { LOGWARN("Error in function call 'ForEachConsoleCommand': Not called on an object instance"); @@ -1687,7 +1687,7 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S) static int tolua_cPlayer_GetGroups(lua_State* tolua_S) { - cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); + cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S, 1, NULL); const cPlayer::GroupList & AllGroups = self->GetGroups(); @@ -1712,7 +1712,7 @@ static int tolua_cPlayer_GetGroups(lua_State* tolua_S) static int tolua_cPlayer_GetResolvedPermissions(lua_State* tolua_S) { - cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); + cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S, 1, NULL); cPlayer::StringList AllPermissions = self->GetResolvedPermissions(); @@ -1825,7 +1825,7 @@ static int tolua_SetObjectCallback(lua_State * tolua_S) static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S) { - cPluginLua * self = (cPluginLua *)tolua_tousertype(tolua_S,1,0); + cPluginLua * self = (cPluginLua *)tolua_tousertype(tolua_S, 1, NULL); tolua_Error tolua_err; tolua_err.array = 0; @@ -1869,7 +1869,7 @@ static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S) static int tolua_cPluginLua_AddTab(lua_State* tolua_S) { - cPluginLua * self = (cPluginLua *) tolua_tousertype(tolua_S, 1, 0); + cPluginLua * self = (cPluginLua *) tolua_tousertype(tolua_S, 1, NULL); LOGWARN("WARNING: Using deprecated function AddTab()! Use AddWebTab() instead. (plugin \"%s\" in folder \"%s\")", self->GetName().c_str(), self->GetDirectory().c_str() ); @@ -1889,7 +1889,7 @@ static int tolua_cPlugin_Call(lua_State * tolua_S) L.LogStackTrace(); // Retrieve the params: plugin and the function name to call - cPluginLua * TargetPlugin = (cPluginLua *) tolua_tousertype(tolua_S, 1, 0); + cPluginLua * TargetPlugin = (cPluginLua *) tolua_tousertype(tolua_S, 1, NULL); AString FunctionName = tolua_tostring(tolua_S, 2, ""); // Call the function: @@ -1942,7 +1942,7 @@ static int tolua_push_StringStringMap(lua_State* tolua_S, std::map< std::string, static int tolua_get_HTTPRequest_Params(lua_State* tolua_S) { - HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0); + HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, NULL); return tolua_push_StringStringMap(tolua_S, self->Params); } @@ -1952,7 +1952,7 @@ static int tolua_get_HTTPRequest_Params(lua_State* tolua_S) static int tolua_get_HTTPRequest_PostParams(lua_State* tolua_S) { - HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0); + HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, NULL); return tolua_push_StringStringMap(tolua_S, self->PostParams); } @@ -1962,7 +1962,7 @@ static int tolua_get_HTTPRequest_PostParams(lua_State* tolua_S) static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S) { - HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0); + HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, NULL); std::map< std::string, HTTPFormData >& FormData = self->FormData; lua_newtable(tolua_S); @@ -1985,7 +1985,7 @@ static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S) static int tolua_cWebAdmin_GetPlugins(lua_State * tolua_S) { - cWebAdmin* self = (cWebAdmin*) tolua_tousertype(tolua_S,1,0); + cWebAdmin* self = (cWebAdmin*) tolua_tousertype(tolua_S, 1, NULL); const cWebAdmin::PluginList & AllPlugins = self->GetPlugins(); @@ -2010,7 +2010,7 @@ static int tolua_cWebAdmin_GetPlugins(lua_State * tolua_S) static int tolua_cWebPlugin_GetTabNames(lua_State * tolua_S) { - cWebPlugin* self = (cWebPlugin*) tolua_tousertype(tolua_S,1,0); + cWebPlugin* self = (cWebPlugin*) tolua_tousertype(tolua_S, 1, NULL); const cWebPlugin::TabNameList & TabNames = self->GetTabNames(); @@ -2077,7 +2077,7 @@ static int Lua_ItemGrid_GetSlotCoords(lua_State * L) } { - const cItemGrid * self = (const cItemGrid *)tolua_tousertype(L, 1, 0); + const cItemGrid * self = (const cItemGrid *)tolua_tousertype(L, 1, NULL); int SlotNum = (int)tolua_tonumber(L, 2, 0); if (self == NULL) { @@ -2289,7 +2289,7 @@ static int tolua_cHopperEntity_GetOutputBlockPos(lua_State * tolua_S) { return 0; } - cHopperEntity * self = (cHopperEntity *)tolua_tousertype(tolua_S, 1, 0); + cHopperEntity * self = (cHopperEntity *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { tolua_error(tolua_S, "invalid 'self' in function 'cHopperEntity::GetOutputBlockPos()'", NULL); @@ -2315,6 +2315,76 @@ static int tolua_cHopperEntity_GetOutputBlockPos(lua_State * tolua_S) +static int tolua_cBlockArea_GetBlockTypeMeta(lua_State * tolua_S) +{ + // function cBlockArea::GetBlockTypeMeta() + // Exported manually because tolua generates extra input params for the outputs + + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cBlockArea") || + !L.CheckParamNumber (2, 4) + ) + { + return 0; + } + + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetRelBlockTypeMeta'", NULL); + return 0; + } + int BlockX = (int)tolua_tonumber(tolua_S, 2, 0); + int BlockY = (int)tolua_tonumber(tolua_S, 3, 0); + int BlockZ = (int)tolua_tonumber(tolua_S, 4, 0); + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + self->GetBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta); + tolua_pushnumber(tolua_S, BlockType); + tolua_pushnumber(tolua_S, BlockMeta); + return 2; +} + + + + + +static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * tolua_S) +{ + // function cBlockArea::GetRelBlockTypeMeta() + // Exported manually because tolua generates extra input params for the outputs + + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cBlockArea") || + !L.CheckParamNumber (2, 4) + ) + { + return 0; + } + + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetRelBlockTypeMeta'", NULL); + return 0; + } + int BlockX = (int)tolua_tonumber(tolua_S, 2, 0); + int BlockY = (int)tolua_tonumber(tolua_S, 3, 0); + int BlockZ = (int)tolua_tonumber(tolua_S, 4, 0); + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + self->GetRelBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta); + tolua_pushnumber(tolua_S, BlockType); + tolua_pushnumber(tolua_S, BlockMeta); + return 2; +} + + + + + static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) { // function cBlockArea::LoadFromSchematicFile @@ -2328,7 +2398,7 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) { return 0; } - cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, 0); + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::LoadFromSchematicFile'", NULL); @@ -2344,6 +2414,7 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) + static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) { // function cBlockArea::SaveToSchematicFile @@ -2357,7 +2428,7 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) { return 0; } - cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, 0); + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::SaveToSchematicFile'", NULL); @@ -2371,6 +2442,8 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) + + void ManualBindings::Bind(lua_State * tolua_S) { tolua_beginmodule(tolua_S, NULL); @@ -2387,8 +2460,10 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cBlockArea"); + tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cBlockArea_GetBlockTypeMeta); + tolua_function(tolua_S, "GetRelBlockTypeMeta", tolua_cBlockArea_GetRelBlockTypeMeta); tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile); - tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); + tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cHopperEntity"); diff --git a/src/BlockArea.h b/src/BlockArea.h index 59bc0f241..b4a161f32 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -184,9 +184,15 @@ public: void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + + // tolua_end + + // These need manual exporting, tolua generates the binding as requiring 2 extra input params void GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; + // tolua_begin + int GetSizeX(void) const { return m_SizeX; } int GetSizeY(void) const { return m_SizeY; } int GetSizeZ(void) const { return m_SizeZ; } -- cgit v1.2.3 From 7b8ff7c9868e574f53d4740046db7c686bd978fb Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Feb 2014 11:05:45 +0100 Subject: APIDump: Fixed cBlockArea:GetRelBlockType() return types. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index fd4b1d947..73bb5c7fb 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -118,7 +118,7 @@ g_APIDesc = GetRelBlockMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "NIBBLETYPE", Notes = "Returns the block meta at the specified relative coords" }, GetRelBlockSkyLight = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "NIBBLETYPE", Notes = "Returns the skylight at the specified relative coords" }, GetRelBlockType = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "BLOCKTYPE", Notes = "Returns the block type at the specified relative coords" }, - GetRelBlockTypeMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "NIBBLETYPE", Notes = "Returns the block type and meta at the specified relative coords" }, + GetRelBlockTypeMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "BLOCKTYPE, NIBBLETYPE", Notes = "Returns the block type and meta at the specified relative coords" }, GetSizeX = { Params = "", Return = "number", Notes = "Returns the size of the held data in the x-axis" }, GetSizeY = { Params = "", Return = "number", Notes = "Returns the size of the held data in the y-axis" }, GetSizeZ = { Params = "", Return = "number", Notes = "Returns the size of the held data in the z-axis" }, -- cgit v1.2.3 From f201f4f176fc908e9ddebfed86d4c8ef5582556c Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 20 Feb 2014 16:38:37 +0200 Subject: Thread safe cMap manager --- src/Generating/StructGen.cpp | 9 --- src/Globals.h | 6 +- src/Map.h | 15 +++- src/MapManager.cpp | 178 +++++++++++++++++++++++++++++++++++++++++++ src/MapManager.h | 76 ++++++++++++++++++ src/World.cpp | 3 +- src/World.h | 5 +- 7 files changed, 275 insertions(+), 17 deletions(-) create mode 100644 src/MapManager.cpp create mode 100644 src/MapManager.h diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index 4efcf92f0..47945cc2b 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -51,15 +51,6 @@ const int NEST_SIZE_GRAVEL = 32; -template T Clamp(T a_Value, T a_Min, T a_Max) -{ - return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cStructGenTrees: diff --git a/src/Globals.h b/src/Globals.h index 7ee045130..e4737a98a 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -235,11 +235,11 @@ public: -/** Clamp a_X to the specified range. */ +/** Clamp X to the specified range. */ template -T Clamp(T a_X, T a_Min, T a_Max) +T Clamp(T a_Value, T a_Min, T a_Max) { - return std::min(std::max(a_X, a_Min), a_Max); + return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value); } diff --git a/src/Map.h b/src/Map.h index 3cf9977ab..ce19c8d2e 100644 --- a/src/Map.h +++ b/src/Map.h @@ -28,7 +28,14 @@ class cMap; -/** Encapsulates a map decorator. */ +/** Encapsulates a map decorator. + * + * A map decorator represents an object drawn on the map that can move freely. + * (e.g. player trackers and item frame pointers) + * + * Excluding manually placed decorators, + * decorators are automatically managed (allocated and freed) by their parent cMap instance. + */ class cMapDecorator { public: @@ -98,7 +105,11 @@ public: typedef std::vector cColorList; - /** Encapsulates the state of a map client. */ + /** Encapsulates the state of a map client. + * + * In order to enhance performace, maps are streamed column-by-column to each client. + * This structure stores the state of the stream. + */ struct cMapClient { cClientHandle * m_Handle; diff --git a/src/MapManager.cpp b/src/MapManager.cpp new file mode 100644 index 000000000..2fc44ccc8 --- /dev/null +++ b/src/MapManager.cpp @@ -0,0 +1,178 @@ + +// MapManager.cpp + +#include "Globals.h" + +#include "MapManager.h" + +#include "World.h" +#include "WorldStorage/MapSerializer.h" + + + + + +cMapManager::cMapManager(cWorld * a_World) + : m_World(a_World) +{ + ASSERT(m_World != NULL); +} + + + + + +bool cMapManager::DoWithMap(unsigned int a_ID, cMapCallback & a_Callback) +{ + cCSLock Lock(m_CS); + cMap * Map = GetMapData(a_ID); + + if (Map == NULL) + { + return false; + } + else + { + a_Callback.Item(Map); + return true; + } +} + + + + + +bool cMapManager::ForEachMap(cMapCallback & a_Callback) +{ + cCSLock Lock(m_CS); + for (cMapList::iterator itr = m_MapData.begin(); itr != m_MapData.end(); ++itr) + { + cMap * Map = &(*itr); + if (a_Callback.Item(Map)) + { + return false; + } + } // for itr - m_MapData[] + return true; +} + + + + + +cMap * cMapManager::GetMapData(unsigned int a_ID) +{ + if (a_ID < m_MapData.size()) + { + return &m_MapData[a_ID]; + } + else + { + return NULL; + } +} + + + + + +cMap * cMapManager::CreateMap(int a_CenterX, int a_CenterY, int a_Scale) +{ + cCSLock Lock(m_CS); + + if (m_MapData.size() >= 65536) + { + LOGWARN("Could not craft map - Too many maps in use"); + return NULL; + } + + cMap Map(m_MapData.size(), a_CenterX, a_CenterY, m_World, a_Scale); + + m_MapData.push_back(Map); + + return &m_MapData[Map.GetID()]; +} + + + + + +unsigned int cMapManager::GetNumMaps(void) const +{ + return m_MapData.size(); +} + + + + + +void cMapManager::LoadMapData(void) +{ + cCSLock Lock(m_CS); + + cIDCountSerializer IDSerializer(m_World->GetName()); + + if (!IDSerializer.Load()) + { + return; + } + + unsigned int MapCount = IDSerializer.GetMapCount(); + + m_MapData.clear(); + + for (unsigned int i = 0; i < MapCount; ++i) + { + cMap Map(i, m_World); + + cMapSerializer Serializer(m_World->GetName(), &Map); + + if (!Serializer.Load()) + { + LOGWARN("Could not load map #%i", Map.GetID()); + } + + m_MapData.push_back(Map); + } +} + + + + + +void cMapManager::SaveMapData(void) +{ + cCSLock Lock(m_CS); + + if (m_MapData.empty()) + { + return; + } + + cIDCountSerializer IDSerializer(m_World->GetName()); + + IDSerializer.SetMapCount(m_MapData.size()); + + if (!IDSerializer.Save()) + { + LOGERROR("Could not save idcounts.dat"); + return; + } + + for (cMapList::iterator it = m_MapData.begin(); it != m_MapData.end(); ++it) + { + cMap & Map = *it; + + cMapSerializer Serializer(m_World->GetName(), &Map); + + if (!Serializer.Save()) + { + LOGWARN("Could not save map #%i", Map.GetID()); + } + } +} + + + + + diff --git a/src/MapManager.h b/src/MapManager.h new file mode 100644 index 000000000..05673c694 --- /dev/null +++ b/src/MapManager.h @@ -0,0 +1,76 @@ + +// MapManager.h + + + + + +#pragma once + + + + + +#include "Map.h" + + + + +typedef cItemCallback cMapCallback; + + + + + +/** Manages the in-game maps of a single world - Thread safe. */ +class cMapManager +{ +public: + + cMapManager(cWorld * a_World); + + /** Returns the map with the specified ID, NULL if out of range. + * + * WARNING: The returned map object is not thread safe. + */ + cMap * GetMapData(unsigned int a_ID); + + /** Creates a new map. Returns NULL on error */ + cMap * CreateMap(int a_CenterX, int a_CenterY, int a_Scale = 3); + + /** Calls the callback for the map with the specified ID. + * + * Returns true if the map was found and the callback called, false if map not found. + * Callback return ignored. + */ + bool DoWithMap(unsigned int a_ID, cMapCallback & a_Callback); + + /** Calls the callback for each map. + * + * Returns true if all maps processed, false if the callback aborted by returning true. + */ + bool ForEachMap(cMapCallback & a_Callback); + + unsigned int GetNumMaps(void) const; + + /** Loads the map data from the disk */ + void LoadMapData(void); + + /** Saves the map data to the disk */ + void SaveMapData(void); + + +private: + + typedef std::vector cMapList; + + cCriticalSection m_CS; + + cMapList m_MapData; + + cWorld * m_World; + +}; + + + diff --git a/src/World.cpp b/src/World.cpp index c1e0731c1..01fdae697 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -12,8 +12,8 @@ #include "Generating/ChunkDesc.h" #include "OSSupport/Timer.h" +// Serializers #include "WorldStorage/ScoreboardSerializer.h" -#include "WorldStorage/MapSerializer.h" // Entities (except mobs): #include "Entities/ExpOrb.h" @@ -233,6 +233,7 @@ void cWorld::cTickThread::Execute(void) // cWorld: cWorld::cWorld(const AString & a_WorldName) : + cMapManager(this), m_WorldName(a_WorldName), m_IniFileName(m_WorldName + "/world.ini"), m_StorageSchema("Default"), diff --git a/src/World.h b/src/World.h index 92fc66c8c..f05ea9b2a 100644 --- a/src/World.h +++ b/src/World.h @@ -24,7 +24,7 @@ #include "Entities/ProjectileEntity.h" #include "ForEachChunkProvider.h" #include "Scoreboard.h" -#include "Map.h" +#include "MapManager.h" #include "Blocks/WorldInterface.h" #include "Blocks/BroadcastInterface.h" @@ -71,7 +71,8 @@ typedef cItemCallback cMobHeadBlockCallback; class cWorld : public cForEachChunkProvider, public cWorldInterface, - public cBroadcastInterface + public cBroadcastInterface, + public cMapManager { public: -- cgit v1.2.3 From c2277c6feeae4551c511588e6da8b05e1bc0c22e Mon Sep 17 00:00:00 2001 From: TheJumper Date: Thu, 20 Feb 2014 16:26:50 +0100 Subject: BlockBed.cpp: Fixed Multiple people in one bed. OnUse in BlockBed.cpp now checks whether bit flag 0x4 in the Data values of the bed is set before somebody can try to sleep in the bed. --- src/Blocks/BlockBed.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index a6f3c36b6..2fa3a7264 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -63,20 +63,29 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface if (a_WorldInterface.GetTimeOfDay() > 13000) { NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if (Meta & 0x8) + if(Meta & 0x4) { - // Is pillow - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_Player->SendMessageFailure("This bed is occupied."); } else { - // Is foot end - Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); - if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + if (Meta & 0x8) { - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + // Is pillow + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); } + else + { + // Is foot end + Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); + if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + { + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + } + } + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (Meta | (1 << 2))); } + } else { a_Player->SendMessageFailure("You can only sleep at night"); } @@ -86,3 +95,5 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface + + -- cgit v1.2.3 From 1b081a0fbbc217ed48830368c6e40b24a7af5358 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Thu, 20 Feb 2014 17:31:38 +0100 Subject: BlockBed.cpp: Fixed space at if statement Added a space after an if statement and before the first bracket to keep up code conventions. --- src/Blocks/BlockBed.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 2fa3a7264..3dad4feba 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -63,7 +63,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface if (a_WorldInterface.GetTimeOfDay() > 13000) { NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if(Meta & 0x4) + if (Meta & 0x4) { a_Player->SendMessageFailure("This bed is occupied."); } -- cgit v1.2.3 From 01c01bac37a56bf0d6301eee91483250bf76391d Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 20 Feb 2014 17:45:18 +0100 Subject: Add 'Meta < 3' to Cauldron --- src/Blocks/BlockCauldron.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Blocks/BlockCauldron.h b/src/Blocks/BlockCauldron.h index 09d5c3cbb..3e8abf4c9 100644 --- a/src/Blocks/BlockCauldron.h +++ b/src/Blocks/BlockCauldron.h @@ -28,15 +28,18 @@ public: { case E_ITEM_WATER_BUCKET: { - a_ChunkInterface->SetBlockMeta( a_BlockX, a_BlockY, a_BlockZ, 3 ); - a_Player->GetInventory().RemoveOneEquippedItem(); - cItem NewItem(E_ITEM_BUCKET, 1); - a_Player->GetInventory().AddItem(NewItem); + if (Meta < 3) + { + a_ChunkInterface->SetBlockMeta( a_BlockX, a_BlockY, a_BlockZ, 3 ); + a_Player->GetInventory().RemoveOneEquippedItem(); + cItem NewItem(E_ITEM_BUCKET, 1); + a_Player->GetInventory().AddItem(NewItem); + } break; } case E_ITEM_GLASS_BOTTLE: { - if( Meta > 0 ) + if (Meta > 0) { a_ChunkInterface->SetBlockMeta( a_BlockX, a_BlockY, a_BlockZ, --Meta); a_Player->GetInventory().RemoveOneEquippedItem(); -- cgit v1.2.3 From 4b7891f2903998892287b4a98d5f69e0bb4ce58c Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 20 Feb 2014 17:56:35 +0100 Subject: Add Hay Bale to Burnable --- src/Simulator/FireSimulator.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index d7c5ab3b4..b77fa1658 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -169,6 +169,7 @@ bool cFireSimulator::IsFuel(BLOCKTYPE a_BlockType) case E_BLOCK_FENCE: case E_BLOCK_TNT: case E_BLOCK_VINES: + case E_BLOCK_HAY_BALE: { return true; } -- cgit v1.2.3 From 69961fc4df08efe3689a643814e8bf0edb325eba Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 20 Feb 2014 19:07:32 +0100 Subject: Add Light weighted pressure plates --- src/BlockID.cpp | 4 ++++ src/Simulator/IncrementalRedstoneSimulator.cpp | 28 +++++++++++++++++--------- src/Simulator/SandSimulator.cpp | 2 ++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/BlockID.cpp b/src/BlockID.cpp index c38db0bfe..ff1c54e3f 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -644,9 +644,11 @@ public: g_BlockPistonBreakable[E_BLOCK_DEAD_BUSH] = true; g_BlockPistonBreakable[E_BLOCK_FIRE] = true; g_BlockPistonBreakable[E_BLOCK_FLOWER] = true; + g_BlockPistonBreakable[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE] = true; g_BlockPistonBreakable[E_BLOCK_INACTIVE_COMPARATOR] = true; g_BlockPistonBreakable[E_BLOCK_IRON_DOOR] = true; g_BlockPistonBreakable[E_BLOCK_JACK_O_LANTERN] = true; + g_BlockPistonBreakable[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE] = true; g_BlockPistonBreakable[E_BLOCK_LADDER] = true; g_BlockPistonBreakable[E_BLOCK_LAVA] = true; g_BlockPistonBreakable[E_BLOCK_LEVER] = true; @@ -727,10 +729,12 @@ public: g_BlockRequiresSpecialTool[E_BLOCK_END_STONE] = true; g_BlockRequiresSpecialTool[E_BLOCK_GOLD_BLOCK] = true; g_BlockRequiresSpecialTool[E_BLOCK_GOLD_ORE] = true; + g_BlockRequiresSpecialTool[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE] = true; g_BlockRequiresSpecialTool[E_BLOCK_IRON_BLOCK] = true; g_BlockRequiresSpecialTool[E_BLOCK_IRON_ORE] = true; g_BlockRequiresSpecialTool[E_BLOCK_LAPIS_BLOCK] = true; g_BlockRequiresSpecialTool[E_BLOCK_LAPIS_ORE] = true; + g_BlockRequiresSpecialTool[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE] = true; g_BlockRequiresSpecialTool[E_BLOCK_MOSSY_COBBLESTONE] = true; g_BlockRequiresSpecialTool[E_BLOCK_NETHERRACK] = true; g_BlockRequiresSpecialTool[E_BLOCK_NETHER_BRICK] = true; diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 60dabaf84..ca4bcca04 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -6,10 +6,13 @@ #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/CommandBlockEntity.h" #include "../Entities/TNTEntity.h" +#include "../Entities/Pickup.h" #include "../Blocks/BlockTorch.h" #include "../Blocks/BlockDoor.h" #include "../Piston.h" +#include + @@ -87,7 +90,8 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, ((Block == E_BLOCK_LEVER) && !IsLeverOn(Meta)) || ((Block == E_BLOCK_DETECTOR_RAIL) && (Meta & 0x08) == 0) || (((Block == E_BLOCK_STONE_BUTTON) || (Block == E_BLOCK_WOODEN_BUTTON)) && (!IsButtonOn(Meta))) || - (((Block == E_BLOCK_STONE_PRESSURE_PLATE) || (Block == E_BLOCK_WOODEN_PRESSURE_PLATE)) && (Meta == 0)) + (((Block == E_BLOCK_STONE_PRESSURE_PLATE) || (Block == E_BLOCK_WOODEN_PRESSURE_PLATE)) && (Meta == 0)) || + (((Block == E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE) || (Block == E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE)) && (Meta == 0)) ) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); @@ -313,6 +317,8 @@ void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int } case E_BLOCK_WOODEN_PRESSURE_PLATE: case E_BLOCK_STONE_PRESSURE_PLATE: + case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: + case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: { HandlePressurePlate(a_X, dataitr->y, a_Z, dataitr->Data); break; @@ -333,13 +339,13 @@ void cIncrementalRedstoneSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_Blo ((a_BlockX % cChunkDef::Width) >= 14) || ((a_BlockZ % cChunkDef::Width) <= 1) || ((a_BlockZ % cChunkDef::Width) >= 14) - ) // Are we on a chunk boundary? ± 2 because of LinkedPowered blocks + ) // Are we on a chunk boundary? \B1 2 because of LinkedPowered blocks { // On a chunk boundary, alert all four sides (i.e. at least one neighbouring chunk) AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk); // Pass the original coordinates, because when adding things to our simulator lists, we get the chunk that they are in, and therefore any updates need to preseve their position - // RedstoneAddBlock to pass both the neighbouring chunk and the chunk which the coordiantes are in and ± 2 in GetNeighbour() to accomodate for LinkedPowered blocks being 2 away from chunk boundaries + // RedstoneAddBlock to pass both the neighbouring chunk and the chunk which the coordiantes are in and \B1 2 in GetNeighbour() to accomodate for LinkedPowered blocks being 2 away from chunk boundaries RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 2, a_BlockZ), a_Chunk); RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 2, a_BlockZ), a_Chunk); RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ - 2), a_Chunk); @@ -1039,13 +1045,15 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_Bloc } break; } + case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: + case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: case E_BLOCK_WOODEN_PRESSURE_PLATE: { - class cWoodenPressurePlateCallback : + class cPressurePlateCallback : public cEntityCallback { public: - cWoodenPressurePlateCallback(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + cPressurePlateCallback(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : m_Entity(NULL), m_World(a_World), m_X(a_BlockX), @@ -1063,7 +1071,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_Bloc if (Distance <= 0.7) { m_Entity = a_Entity; - return true; // Break out, we only need to know for wooden plates that at least one entity is on top + return true; // Break out, we only need to know for plates that at least one entity is on top } return false; } @@ -1082,13 +1090,13 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_Bloc int m_Z; } ; - cWoodenPressurePlateCallback WoodenPressurePlateCallback(a_BlockX, a_BlockY, a_BlockZ, &m_World); - m_World.ForEachEntity(WoodenPressurePlateCallback); + cPressurePlateCallback PressurePlateCallback(a_BlockX, a_BlockY, a_BlockZ, &m_World); + m_World.ForEachEntity(PressurePlateCallback); - if (WoodenPressurePlateCallback.FoundEntity()) + if (PressurePlateCallback.FoundEntity()) { m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x1); - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_WOODEN_PRESSURE_PLATE); + SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, a_MyType); } else { diff --git a/src/Simulator/SandSimulator.cpp b/src/Simulator/SandSimulator.cpp index 87fb83357..f305ba61a 100644 --- a/src/Simulator/SandSimulator.cpp +++ b/src/Simulator/SandSimulator.cpp @@ -158,8 +158,10 @@ bool cSandSimulator::CanContinueFallThrough(BLOCKTYPE a_BlockType) case E_BLOCK_DETECTOR_RAIL: case E_BLOCK_FIRE: case E_BLOCK_FLOWER_POT: + case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: case E_BLOCK_LAVA: case E_BLOCK_LEVER: + case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: case E_BLOCK_MINECART_TRACKS: case E_BLOCK_MELON_STEM: case E_BLOCK_POWERED_RAIL: -- cgit v1.2.3 From 4dd39f8cd6e8f0894989e4270e0501dab7ae8f4d Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 20 Feb 2014 19:21:04 +0100 Subject: Add Pressure Plate Sound --- src/Simulator/IncrementalRedstoneSimulator.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index ca4bcca04..b6c573a62 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -1093,13 +1093,22 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_Bloc cPressurePlateCallback PressurePlateCallback(a_BlockX, a_BlockY, a_BlockZ, &m_World); m_World.ForEachEntity(PressurePlateCallback); + NIBBLETYPE Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); if (PressurePlateCallback.FoundEntity()) { + if (Meta == 0x0) + { + m_World.BroadcastSoundEffect("random.click", (int) ((a_BlockX + 0.5) * 8.0), (int) ((a_BlockY + 0.1) * 8.0), (int) ((a_BlockZ + 0.5) * 8.0), 0.3F, 0.5F); + } m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x1); SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, a_MyType); } else { + if (Meta == 0x1) + { + m_World.BroadcastSoundEffect("random.click", (int) ((a_BlockX + 0.5) * 8.0), (int) ((a_BlockY + 0.1) * 8.0), (int) ((a_BlockZ + 0.5) * 8.0), 0.3F, 0.6F); + } m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x0); m_World.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); } -- cgit v1.2.3 From 50bebd2dbdb26a48ce1637bf515770d1bfc50d99 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Feb 2014 20:11:17 +0100 Subject: Disabled the leak finder. --- src/Server.cpp | 4 +++- src/main.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index ab1458da4..c60418b41 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -39,7 +39,9 @@ extern "C" { // For the "dumpmem" server command: /// Synchronize this with main.cpp - the leak finder needs initialization before it can be used to dump memory -#define ENABLE_LEAK_FINDER +// _X 2014_02_20: Disabled for canon repo, it makes the debug version too slow in MSVC2013 +// and we haven't had a memory leak for over a year anyway. +// #define ENABLE_LEAK_FINDER #if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER) #pragma warning(push) diff --git a/src/main.cpp b/src/main.cpp index c8cd2d4fe..4d2801926 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,9 @@ bool g_ShouldLogCommOut; /// If defined, a thorough leak finder will be used (debug MSVC only); leaks will be output to the Output window -#define ENABLE_LEAK_FINDER +// _X 2014_02_20: Disabled for canon repo, it makes the debug version too slow in MSVC2013 +// and we haven't had a memory leak for over a year anyway. +// #define ENABLE_LEAK_FINDER -- cgit v1.2.3 From 5e7f2ba6d6dba6b931bd54389cddd3077b3a9d93 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 20 Feb 2014 20:41:53 +0100 Subject: Add Wolf Heal with Food --- src/Mobs/Wolf.cpp | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 2736c3dd1..0d3619166 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -4,6 +4,7 @@ #include "Wolf.h" #include "../World.h" #include "../Entities/Player.h" +#include "../Items/ItemHandler.h" @@ -86,23 +87,44 @@ void cWolf::OnRightClicked(cPlayer & a_Player) } else if (IsTame()) { - if (a_Player.GetName() == m_OwnerName) // Is the player the owner of the dog? + switch (a_Player.GetEquippedItem().m_ItemType) { - if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_DYE) + case E_ITEM_RAW_BEEF: + case E_ITEM_STEAK: + case E_ITEM_RAW_PORKCHOP: + case E_ITEM_COOKED_PORKCHOP: + case E_ITEM_RAW_CHICKEN: + case E_ITEM_COOKED_CHICKEN: + case E_ITEM_ROTTEN_FLESH: { - SetCollarColor(15 - a_Player.GetEquippedItem().m_ItemDamage); - if (!a_Player.IsGameModeCreative()) + if (m_Health < m_MaxHealth) { - a_Player.GetInventory().RemoveOneEquippedItem(); + Heal(ItemHandler(a_Player.GetEquippedItem().m_ItemType)->GetFoodInfo().FoodLevel); + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + } } - } - else if (IsSitting()) + break; + } + case E_ITEM_DYE: { - SetIsSitting(false); + if (a_Player.GetName() == m_OwnerName) // Is the player the owner of the dog? + { + SetCollarColor(15 - a_Player.GetEquippedItem().m_ItemDamage); + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + } + } + break; } - else + default: { - SetIsSitting(true); + if (a_Player.GetName() == m_OwnerName) // Is the player the owner of the dog? + { + SetIsSitting(!IsSitting()); + } } } } @@ -136,6 +158,8 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) case E_ITEM_RAW_CHICKEN: case E_ITEM_COOKED_CHICKEN: case E_ITEM_ROTTEN_FLESH: + case E_ITEM_RAW_PORKCHOP: + case E_ITEM_COOKED_PORKCHOP: { if (!IsBegging()) { -- cgit v1.2.3 From 10169220123b19f0ebcfd7330bb52adaf06f4ec0 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 20 Feb 2014 20:58:23 +0100 Subject: Fix Cauldron --- src/Blocks/BlockCauldron.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Blocks/BlockCauldron.h b/src/Blocks/BlockCauldron.h index 3e8abf4c9..2e1032d2b 100644 --- a/src/Blocks/BlockCauldron.h +++ b/src/Blocks/BlockCauldron.h @@ -21,19 +21,22 @@ public: a_Pickups.push_back(cItem(E_ITEM_CAULDRON, 1, 0)); } - void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - char Meta = a_ChunkInterface->GetBlockMeta( a_BlockX, a_BlockY, a_BlockZ ); - switch( a_Player->GetEquippedItem().m_ItemType ) + char Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + switch (a_Player->GetEquippedItem().m_ItemType) { case E_ITEM_WATER_BUCKET: { if (Meta < 3) { - a_ChunkInterface->SetBlockMeta( a_BlockX, a_BlockY, a_BlockZ, 3 ); - a_Player->GetInventory().RemoveOneEquippedItem(); - cItem NewItem(E_ITEM_BUCKET, 1); - a_Player->GetInventory().AddItem(NewItem); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 3); + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); + cItem NewItem(E_ITEM_BUCKET, 1); + a_Player->GetInventory().AddItem(NewItem); + } } break; } @@ -41,7 +44,7 @@ public: { if (Meta > 0) { - a_ChunkInterface->SetBlockMeta( a_BlockX, a_BlockY, a_BlockZ, --Meta); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, --Meta); a_Player->GetInventory().RemoveOneEquippedItem(); cItem NewItem(E_ITEM_POTIONS, 1, 0); a_Player->GetInventory().AddItem(NewItem); -- cgit v1.2.3 From d47f421e2db330ce431167843c84dbc61f04ea19 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 20 Feb 2014 21:00:16 +0100 Subject: Remove typeinfo import in IncrementalRedstoneSimulator --- src/Simulator/IncrementalRedstoneSimulator.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index b6c573a62..4459f9c89 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -11,8 +11,6 @@ #include "../Blocks/BlockDoor.h" #include "../Piston.h" -#include - -- cgit v1.2.3 From 337c4e5cd4e666c34efeb6767fdf1357aa6d3bca Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 20 Feb 2014 22:02:14 +0100 Subject: Bad UTF-8 o.O --- src/Simulator/IncrementalRedstoneSimulator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 4459f9c89..1637ac02a 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -337,13 +337,13 @@ void cIncrementalRedstoneSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_Blo ((a_BlockX % cChunkDef::Width) >= 14) || ((a_BlockZ % cChunkDef::Width) <= 1) || ((a_BlockZ % cChunkDef::Width) >= 14) - ) // Are we on a chunk boundary? \B1 2 because of LinkedPowered blocks + ) // Are we on a chunk boundary? ± 2 because of LinkedPowered blocks { // On a chunk boundary, alert all four sides (i.e. at least one neighbouring chunk) AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk); // Pass the original coordinates, because when adding things to our simulator lists, we get the chunk that they are in, and therefore any updates need to preseve their position - // RedstoneAddBlock to pass both the neighbouring chunk and the chunk which the coordiantes are in and \B1 2 in GetNeighbour() to accomodate for LinkedPowered blocks being 2 away from chunk boundaries + // RedstoneAddBlock to pass both the neighbouring chunk and the chunk which the coordiantes are in and ± 2 in GetNeighbour() to accomodate for LinkedPowered blocks being 2 away from chunk boundaries RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 2, a_BlockZ), a_Chunk); RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 2, a_BlockZ), a_Chunk); RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ - 2), a_Chunk); -- cgit v1.2.3 From ffc4691f48a275141b69e3c9f2a62efc1a596d7f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Feb 2014 22:17:01 +0100 Subject: Removed problematic utf8. --- src/Simulator/IncrementalRedstoneSimulator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 1637ac02a..91de9e0cc 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -337,13 +337,13 @@ void cIncrementalRedstoneSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_Blo ((a_BlockX % cChunkDef::Width) >= 14) || ((a_BlockZ % cChunkDef::Width) <= 1) || ((a_BlockZ % cChunkDef::Width) >= 14) - ) // Are we on a chunk boundary? ± 2 because of LinkedPowered blocks + ) // Are we on a chunk boundary? +- 2 because of LinkedPowered blocks { // On a chunk boundary, alert all four sides (i.e. at least one neighbouring chunk) AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk); // Pass the original coordinates, because when adding things to our simulator lists, we get the chunk that they are in, and therefore any updates need to preseve their position - // RedstoneAddBlock to pass both the neighbouring chunk and the chunk which the coordiantes are in and ± 2 in GetNeighbour() to accomodate for LinkedPowered blocks being 2 away from chunk boundaries + // RedstoneAddBlock to pass both the neighbouring chunk and the chunk which the coordiantes are in and +- 2 in GetNeighbour() to accomodate for LinkedPowered blocks being 2 away from chunk boundaries RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 2, a_BlockZ), a_Chunk); RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 2, a_BlockZ), a_Chunk); RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ - 2), a_Chunk); -- cgit v1.2.3 From 27e77a28fa434805905dc49f49800f8987d0957d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Feb 2014 23:24:39 +0100 Subject: cClientHandle manages the client-registered plugin channels. Fixes #706. --- src/ClientHandle.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++------ src/ClientHandle.h | 72 +++++++++++++++++++++++++++---------------- 2 files changed, 123 insertions(+), 36 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 84286fc41..3711262b6 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -542,19 +542,23 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString & a_Message) { - if (a_Channel == "MC|AdvCdm") // Command block, set text, Client -> Server + if (a_Channel == "MC|AdvCdm") { - const char* Data = a_Message.c_str(); - HandleCommandBlockMessage(Data, a_Message.size()); - return; + // Command block, set text, Client -> Server + HandleCommandBlockMessage(a_Message.c_str(), a_Message.size()); } - else if (a_Channel == "MC|Brand") // Client <-> Server branding exchange + else if (a_Channel == "MC|Brand") { - // We are custom, - // We are awesome, - // We are MCServer. + // Client <-> Server branding exchange SendPluginMessage("MC|Brand", "MCServer"); - return; + } + else if (a_Channel == "REGISTER") + { + RegisterPluginChannels(BreakApartPluginChannels(a_Message)); + } + else if (a_Channel == "UNREGISTER") + { + UnregisterPluginChannels(BreakApartPluginChannels(a_Message)); } cPluginManager::Get()->CallHookPluginMessage(*this, a_Channel, a_Message); @@ -564,7 +568,61 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString -void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a_Length) +AStringVector cClientHandle::BreakApartPluginChannels(const AString & a_PluginChannels) +{ + // Break the string on each NUL character. + // Note that StringSplit() doesn't work on this because NUL is a special char - string terminator + size_t len = a_PluginChannels.size(); + size_t first = 0; + AStringVector res; + for (size_t i = 0; i < len; i++) + { + if (a_PluginChannels[i] != 0) + { + continue; + } + if (i > first) + { + res.push_back(a_PluginChannels.substr(first, i - first)); + } + first = i + 1; + } // for i - a_PluginChannels[] + if (first < len) + { + res.push_back(a_PluginChannels.substr(first, len - first)); + } + return res; +} + + + + + +void cClientHandle::RegisterPluginChannels(const AStringVector & a_ChannelList) +{ + for (AStringVector::const_iterator itr = a_ChannelList.begin(), end = a_ChannelList.end(); itr != end; ++itr) + { + m_PluginChannels.insert(*itr); + } // for itr - a_ChannelList[] +} + + + + + +void cClientHandle::UnregisterPluginChannels(const AStringVector & a_ChannelList) +{ + for (AStringVector::const_iterator itr = a_ChannelList.begin(), end = a_ChannelList.end(); itr != end; ++itr) + { + m_PluginChannels.erase(*itr); + } // for itr - a_ChannelList[] +} + + + + + +void cClientHandle::HandleCommandBlockMessage(const char * a_Data, unsigned int a_Length) { if (a_Length < 14) { @@ -2463,6 +2521,15 @@ void cClientHandle::SetViewDistance(int a_ViewDistance) +bool cClientHandle::HasPluginChannel(const AString & a_PluginChannel) +{ + return (m_PluginChannels.find(a_PluginChannel) != m_PluginChannels.end()); +} + + + + + bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) { if (m_State >= csDestroying) diff --git a/src/ClientHandle.h b/src/ClientHandle.h index aefca7233..e0447d3f7 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -72,10 +72,10 @@ public: inline bool IsLoggedIn(void) const { return (m_State >= csAuthenticating); } - /// Called while the client is being ticked from the world via its cPlayer object + /** Called while the client is being ticked from the world via its cPlayer object */ void Tick(float a_Dt); - /// Called while the client is being ticked from the cServer object + /** Called while the client is being ticked from the cServer object */ void ServerTick(float a_Dt); void Destroy(void); @@ -150,23 +150,28 @@ public: void SendWindowOpen (const cWindow & a_Window); void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value); - const AString & GetUsername(void) const; // tolua_export - void SetUsername( const AString & a_Username ); // tolua_export + // tolua_begin + const AString & GetUsername(void) const; + void SetUsername( const AString & a_Username ); - inline short GetPing(void) const { return m_Ping; } // tolua_export + inline short GetPing(void) const { return m_Ping; } - void SetViewDistance(int a_ViewDistance); // tolua_export - int GetViewDistance(void) const { return m_ViewDistance; } // tolua_export + void SetViewDistance(int a_ViewDistance); + int GetViewDistance(void) const { return m_ViewDistance; } - void SetLocale(AString & a_Locale) { m_Locale = a_Locale; } // tolua_export - AString GetLocale(void) const { return m_Locale; } // tolua_export + void SetLocale(AString & a_Locale) { m_Locale = a_Locale; } + AString GetLocale(void) const { return m_Locale; } - int GetUniqueID() const { return m_UniqueID; } // tolua_export + int GetUniqueID(void) const { return m_UniqueID; } - /// Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend) + bool HasPluginChannel(const AString & a_PluginChannel); + + // tolua_end + + /** Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend) */ bool WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); - /// Adds the chunk specified to the list of chunks wanted for sending (m_ChunksToSend) + /** Adds the chunk specified to the list of chunks wanted for sending (m_ChunksToSend) */ void AddWantedChunk(int a_ChunkX, int a_ChunkZ); // Calls that cProtocol descendants use to report state: @@ -217,14 +222,17 @@ public: void SendData(const char * a_Data, int a_Size); - /// Called when the player moves into a different world; queues sreaming the new chunks + /** Called when the player moves into a different world; queues sreaming the new chunks */ void MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket); - /// Handles the block placing packet when it is a real block placement (not block-using, item-using or eating) + /** Handles the block placing packet when it is a real block placement (not block-using, item-using or eating) */ void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler); private: + /** The type used for storing the names of registered plugin channels. */ + typedef std::set cChannels; + int m_ViewDistance; // Number of chunks the player can see in each direction; 4 is the minimum ( http://wiki.vg/Protocol_FAQ#.E2.80.A6all_connecting_clients_spasm_and_jerk_uncontrollably.21 ) static const int GENERATEDISTANCE = 2; // Server generates this many chunks AHEAD of player sight. 2 is the minimum, since foliage is generated 1 step behind chunk terrain generation @@ -257,7 +265,7 @@ private: int m_LastStreamedChunkX; int m_LastStreamedChunkZ; - /// Seconds since the last packet data was received (updated in Tick(), reset in DataReceived()) + /** Seconds since the last packet data was received (updated in Tick(), reset in DataReceived()) */ float m_TimeSinceLastPacket; short m_Ping; @@ -279,7 +287,7 @@ private: int m_LastDigBlockY; int m_LastDigBlockZ; - /// Used while csDestroyedWaiting for counting the ticks until the connection is closed + /** Used while csDestroyedWaiting for counting the ticks until the connection is closed */ int m_TicksSinceDestruction; enum eState @@ -299,10 +307,10 @@ private: eState m_State; - /// m_State needs to be locked in the Destroy() function so that the destruction code doesn't run twice on two different threads + /** m_State needs to be locked in the Destroy() function so that the destruction code doesn't run twice on two different threads */ cCriticalSection m_CSDestroyingState; - /// If set to true during csDownloadingWorld, the tick thread calls CheckIfWorldDownloaded() + /** If set to true during csDownloadingWorld, the tick thread calls CheckIfWorldDownloaded() */ bool m_ShouldCheckDownloaded; /** Number of explosions sent this tick */ @@ -311,27 +319,39 @@ private: static int s_ClientCount; int m_UniqueID; - /// Set to true when the chunk where the player is is sent to the client. Used for spawning the player + /** Set to true when the chunk where the player is is sent to the client. Used for spawning the player */ bool m_HasSentPlayerChunk; - /// Client Settings + /** Client Settings */ AString m_Locale; + + /** The plugin channels that the client has registered. */ + cChannels m_PluginChannels; - /// Returns true if the rate block interactions is within a reasonable limit (bot protection) + /** Returns true if the rate block interactions is within a reasonable limit (bot protection) */ bool CheckBlockInteractionsRate(void); - /// Adds a single chunk to be streamed to the client; used by StreamChunks() + /** Adds a single chunk to be streamed to the client; used by StreamChunks() */ void StreamChunk(int a_ChunkX, int a_ChunkZ); - /// Handles the DIG_STARTED dig packet: + /** Handles the DIG_STARTED dig packet: */ void HandleBlockDigStarted (int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta); - /// Handles the DIG_FINISHED dig packet: + /** Handles the DIG_FINISHED dig packet: */ void HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta); - /// Handles the "MC|AdvCdm" plugin message - void HandleCommandBlockMessage(const char* a_Data, unsigned int a_Length); + /** Converts the protocol-formatted channel list (NUL-separated) into a proper string vector. */ + AStringVector BreakApartPluginChannels(const AString & a_PluginChannels); + + /** Adds all of the channels to the list of current plugin channels. Handles duplicates gracefully. */ + void RegisterPluginChannels(const AStringVector & a_ChannelList); + + /** Removes all of the channels from the list of current plugin channels. Ignores channels that are not found. */ + void UnregisterPluginChannels(const AStringVector & a_ChannelList); + + /** Handles the "MC|AdvCdm" plugin message */ + void HandleCommandBlockMessage(const char * a_Data, unsigned int a_Length); // cSocketThreads::cCallback overrides: virtual void DataReceived (const char * a_Data, int a_Size) override; // Data is received from the client -- cgit v1.2.3 From 1b9840b3286f73eb1aefee44b5ab1768756c8bf3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Feb 2014 23:32:08 +0100 Subject: APIDump: Documented cClientHandle:HasPluginChannel. --- MCServer/Plugins/APIDump/APIDesc.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 73bb5c7fb..a2f741a01 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -448,6 +448,7 @@ end GetUniqueID = { Params = "", Return = "number", Notes = "Returns the UniqueID of the client used to identify the client in the server" }, GetUsername = { Params = "", Return = "string", Notes = "Returns the username that the client has provided" }, GetViewDistance = { Params = "", Return = "number", Notes = "Returns the viewdistance (number of chunks loaded for the player in each direction)" }, + HasPluginChannel = { Params = "ChannelName", Return = "bool", Notes = "Returns true if the client has registered to receive messages on the specified plugin channel." }, Kick = { Params = "Reason", Return = "", Notes = "Kicks the user with the specified reason" }, SendPluginMessage = { Params = "Channel, Message", Return = "", Notes = "Sends the plugin message on the specified channel." }, SetUsername = { Params = "Name", Return = "", Notes = "Sets the username" }, -- cgit v1.2.3 From 8bf5d116fe4c7b2addeba2dac9a8b1fc93486444 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 21 Feb 2014 15:26:33 +0200 Subject: Split cMap::UpdateClient --- src/Map.cpp | 126 ++++++++++++++++++++++++++++++++++++------------------------ src/Map.h | 61 ++++++++++++++++++----------- 2 files changed, 114 insertions(+), 73 deletions(-) diff --git a/src/Map.cpp b/src/Map.cpp index cb5472a22..0028a1e94 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -278,28 +278,35 @@ void cMap::UpdateDecorators(void) -void cMap::UpdateClient(cPlayer * a_Player) +void cMap::AddPlayer(cPlayer * a_Player, cClientHandle * a_Handle, Int64 a_WorldAge) { - ASSERT(a_Player != NULL); - cClientHandle * Handle = a_Player->GetClientHandle(); + cMapClient MapClient; + + MapClient.m_LastUpdate = a_WorldAge; + MapClient.m_SendInfo = true; + MapClient.m_Handle = a_Handle; + + m_Clients.push_back(MapClient); + + cMapDecorator PlayerDecorator(this, a_Player); + + m_Decorators.push_back(PlayerDecorator); +} + + - if (Handle == NULL) - { - return; - } - Int64 WorldAge = a_Player->GetWorld()->GetWorldAge(); - // Remove invalid clients +void cMap::RemoveInactiveClients(Int64 a_WorldAge) +{ for (cMapClientList::iterator it = m_Clients.begin(); it != m_Clients.end();) { - // Check if client is active - if (it->m_LastUpdate < WorldAge - 5) + if (it->m_LastUpdate < a_WorldAge) { // Remove associated decorators for (cMapDecoratorList::iterator it2 = m_Decorators.begin(); it2 != m_Decorators.end();) { - if (it2->GetPlayer()->GetClientHandle() == Handle) + if (it2->GetPlayer()->GetClientHandle() == it->m_Handle) { // Erase decorator cMapDecoratorList::iterator temp = it2; @@ -322,63 +329,82 @@ void cMap::UpdateClient(cPlayer * a_Player) ++it; } } +} - // Linear search for client state - for (cMapClientList::iterator it = m_Clients.begin(); it != m_Clients.end(); ++it) + + + + +void cMap::StreamNext(cMapClient & a_Client) +{ + cClientHandle * Handle = a_Client.m_Handle; + + if (a_Client.m_SendInfo) { - if (it->m_Handle == Handle) - { - it->m_LastUpdate = WorldAge; + Handle->SendMapInfo(m_ID, m_Scale); - if (it->m_SendInfo) - { - Handle->SendMapInfo(m_ID, m_Scale); + a_Client.m_SendInfo = false; - it->m_SendInfo = false; + return; + } - return; - } + ++a_Client.m_NextDecoratorUpdate; - ++it->m_NextDecoratorUpdate; + if (a_Client.m_NextDecoratorUpdate >= 4) + { + // TODO 2014-02-19 xdot + // This is dangerous as the player object may have been destroyed before the decorator is erased from the list + UpdateDecorators(); - if (it->m_NextDecoratorUpdate >= 4) - { - // TODO 2014-02-19 xdot - // This is dangerous as the player object may have been destroyed before the decorator is erased from the list - UpdateDecorators(); + Handle->SendMapDecorators(m_ID, m_Decorators); - Handle->SendMapDecorators(m_ID, m_Decorators); + a_Client.m_NextDecoratorUpdate = 0; + } + else + { + ++a_Client.m_DataUpdate; - it->m_NextDecoratorUpdate = 0; - } - else - { - ++it->m_DataUpdate; + unsigned int Y = (a_Client.m_DataUpdate * 11) % m_Width; - unsigned int Y = (it->m_DataUpdate * 11) % m_Width; + const Byte * Colors = &m_Data[Y * m_Height]; - const Byte * Colors = &m_Data[Y * m_Height]; + Handle->SendMapColumn(m_ID, Y, 0, Colors, m_Height); + } +} - Handle->SendMapColumn(m_ID, Y, 0, Colors, m_Height); - } - return; - } + + + +void cMap::UpdateClient(cPlayer * a_Player) +{ + ASSERT(a_Player != NULL); + cClientHandle * Handle = a_Player->GetClientHandle(); + + if (Handle == NULL) + { + return; } - // New player, construct a new client state - cMapClient MapClient; + Int64 WorldAge = a_Player->GetWorld()->GetWorldAge(); - MapClient.m_LastUpdate = WorldAge; - MapClient.m_SendInfo = true; - MapClient.m_Handle = a_Player->GetClientHandle(); + RemoveInactiveClients(WorldAge - 5); - m_Clients.push_back(MapClient); + // Linear search for client state + for (cMapClientList::iterator it = m_Clients.begin(); it != m_Clients.end(); ++it) + { + if (it->m_Handle == Handle) + { + it->m_LastUpdate = WorldAge; - // Insert new decorator - cMapDecorator PlayerDecorator(this, a_Player); + StreamNext(*it); - m_Decorators.push_back(PlayerDecorator); + return; + } + } + + // New player, construct a new client state + AddPlayer(a_Player, Handle, WorldAge); } diff --git a/src/Map.h b/src/Map.h index ce19c8d2e..01ffd19f5 100644 --- a/src/Map.h +++ b/src/Map.h @@ -105,29 +105,6 @@ public: typedef std::vector cColorList; - /** Encapsulates the state of a map client. - * - * In order to enhance performace, maps are streamed column-by-column to each client. - * This structure stores the state of the stream. - */ - struct cMapClient - { - cClientHandle * m_Handle; - - /** Whether the map scale was modified and needs to be resent. */ - bool m_SendInfo; - - /** Ticks since last decorator update. */ - unsigned int m_NextDecoratorUpdate; - - /** Number of pixel data updates. */ - Int64 m_DataUpdate; - - Int64 m_LastUpdate; - }; - - typedef std::list cMapClientList; - public: @@ -185,6 +162,32 @@ public: // tolua_end +protected: + + /** Encapsulates the state of a map client. + * + * In order to enhance performace, maps are streamed column-by-column to each client. + * This structure stores the state of the stream. + */ + struct cMapClient + { + cClientHandle * m_Handle; + + /** Whether the map scale was modified and needs to be resent. */ + bool m_SendInfo; + + /** Ticks since last decorator update. */ + unsigned int m_NextDecoratorUpdate; + + /** Number of pixel data updates. */ + Int64 m_DataUpdate; + + Int64 m_LastUpdate; + }; + + typedef std::list cMapClientList; + + private: /** Update the associated decorators. */ @@ -193,6 +196,15 @@ private: /** Update the specified pixel. */ bool UpdatePixel(unsigned int a_X, unsigned int a_Z); + /** Add a new map client. */ + void AddPlayer(cPlayer * a_Player, cClientHandle * a_Handle, Int64 a_WorldAge); + + /** Remove inactive or invalid clients. */ + void RemoveInactiveClients(Int64 a_WorldAge); + + /** Send next update packet to the specified client. */ + void StreamNext(cMapClient & a_Client); + unsigned int m_ID; unsigned int m_Width; @@ -218,3 +230,6 @@ private: friend class cMapSerializer; }; + + + -- cgit v1.2.3 From 21febaf4b342aecd5d797b1e2017591fde208388 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 21 Feb 2014 14:53:46 +0100 Subject: Add 'Group not found', when the Server load the users.ini and add auto generate from users.ini --- src/Entities/Player.cpp | 6 +++++- src/GroupManager.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/GroupManager.h | 2 ++ src/Root.cpp | 4 +++- src/Server.cpp | 4 ++++ 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 70ddb3c98..7a3aaf568 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1529,7 +1529,11 @@ void cPlayer::LoadPermissionsFromDisk() AStringVector Split = StringSplit( Groups, "," ); for( unsigned int i = 0; i < Split.size(); i++ ) { - AddToGroup( Split[i].c_str() ); + if (!cRoot::Get()->GetGroupManager()->ExistsGroup(Split[i])) + { + LOGWARNING("The group %s for player %s was not found!", Split[i].c_str(), m_PlayerName.c_str()); + } + AddToGroup(Split[i].c_str()); } } else diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 723b86f94..5125e7586 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -46,6 +46,7 @@ cGroupManager::cGroupManager() LOGD("-- Loading Groups --"); LoadGroups(); + CheckUsers(); LOGD("-- Groups Successfully Loaded --"); } @@ -54,6 +55,42 @@ cGroupManager::cGroupManager() +void cGroupManager::CheckUsers(void) +{ + cIniFile IniFile; + if (!IniFile.ReadFile("users.ini")) + { + LOGWARN("Regenerating users.ini, all users will be reset"); + IniFile.AddHeaderComment(" This is the file in which the group the player belongs to is stored"); + IniFile.AddHeaderComment(" The format is: [PlayerName] | Groups=GroupName"); + + IniFile.WriteFile("users.ini"); + return; + } + + unsigned int NumKeys = IniFile.GetNumKeys(); + for (size_t i = 0; i < NumKeys; i++) + { + AString Player = IniFile.GetKeyName( i ); + AString Groups = IniFile.GetValue(Player, "Groups", ""); + if (!Groups.empty()) + { + AStringVector Split = StringSplit( Groups, "," ); + for( unsigned int i = 0; i < Split.size(); i++ ) + { + if (!ExistsGroup(Split[i])) + { + LOGWARNING("The group %s for player %s was not found!", Split[i].c_str(), Player.c_str()); + } + } + } + } +} + + + + + void cGroupManager::LoadGroups() { cIniFile IniFile; @@ -137,6 +174,16 @@ void cGroupManager::LoadGroups() +bool cGroupManager::ExistsGroup( const AString & a_Name ) +{ + GroupMap::iterator itr = m_pState->Groups.find( a_Name ); + return ( itr != m_pState->Groups.end() ); +} + + + + + cGroup* cGroupManager::GetGroup( const AString & a_Name ) { GroupMap::iterator itr = m_pState->Groups.find( a_Name ); diff --git a/src/GroupManager.h b/src/GroupManager.h index 02a58fe4e..377a54c98 100644 --- a/src/GroupManager.h +++ b/src/GroupManager.h @@ -14,8 +14,10 @@ class cGroup; class cGroupManager { public: + bool ExistsGroup(const AString & a_Name); cGroup * GetGroup(const AString & a_Name); void LoadGroups(void); + void CheckUsers(void); private: friend class cRoot; diff --git a/src/Root.cpp b/src/Root.cpp index 206255916..8680c0082 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -194,7 +194,7 @@ void cRoot::Start(void) #if !defined(ANDROID_NDK) LOGD("Starting InputThread..."); m_InputThread = new cThread( InputThread, this, "cRoot::InputThread" ); - m_InputThread->Start( false ); // We should NOT wait? Otherwise we can´t stop the server from other threads than the input thread + m_InputThread->Start( false ); // We should NOT wait? Otherwise we can�t stop the server from other threads than the input thread #endif long long finishmseconds = Time.GetNowTime(); @@ -536,7 +536,9 @@ void cRoot::SaveAllChunks(void) void cRoot::ReloadGroups(void) { + LOG("Reload groups ..."); m_GroupManager->LoadGroups(); + m_GroupManager->CheckUsers(); } diff --git a/src/Server.cpp b/src/Server.cpp index ab1458da4..4842c1782 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -460,16 +460,20 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac { cPluginManager::Get()->ReloadPlugins(); cRoot::Get()->ReloadGroups(); + a_Output.Finished(); return; } if (split[0] == "reloadplugins") { cPluginManager::Get()->ReloadPlugins(); + a_Output.Finished(); return; } if (split[0] == "reloadgroups") { cRoot::Get()->ReloadGroups(); + a_Output.Out("Groups reloaded!"); + a_Output.Finished(); return; } -- cgit v1.2.3 From a75575855323c59496d26d89c271641a828e223e Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 21 Feb 2014 14:55:28 +0100 Subject: Unicode :-( --- src/Root.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Root.cpp b/src/Root.cpp index 8680c0082..af2cb9e4b 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -194,7 +194,7 @@ void cRoot::Start(void) #if !defined(ANDROID_NDK) LOGD("Starting InputThread..."); m_InputThread = new cThread( InputThread, this, "cRoot::InputThread" ); - m_InputThread->Start( false ); // We should NOT wait? Otherwise we can�t stop the server from other threads than the input thread + m_InputThread->Start( false ); // We should NOT wait? Otherwise we can't stop the server from other threads than the input thread #endif long long finishmseconds = Time.GetNowTime(); -- cgit v1.2.3 From 5b3957233402c36f3262b7246047131e65c5eeb3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 21 Feb 2014 14:56:33 +0100 Subject: Remove old Output Finish --- src/Server.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index 4842c1782..c80348872 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -460,13 +460,11 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac { cPluginManager::Get()->ReloadPlugins(); cRoot::Get()->ReloadGroups(); - a_Output.Finished(); return; } if (split[0] == "reloadplugins") { cPluginManager::Get()->ReloadPlugins(); - a_Output.Finished(); return; } if (split[0] == "reloadgroups") -- cgit v1.2.3 From 3777873f22b8a19ed282be076357d5b3c2eb43ee Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 21 Feb 2014 15:10:31 +0100 Subject: Remove users.ini generation in Player.cpp and use the CheckUsers() Function --- src/Entities/Player.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 7a3aaf568..19173592e 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1545,12 +1545,7 @@ void cPlayer::LoadPermissionsFromDisk() } else { - LOGWARN("Regenerating users.ini, player %s will be added to the \"Default\" group", m_PlayerName.c_str()); - IniFile.AddHeaderComment(" This is the file in which the group the player belongs to is stored"); - IniFile.AddHeaderComment(" The format is: [PlayerName] | Groups=GroupName"); - - IniFile.SetValue(m_PlayerName, "Groups", "Default"); - IniFile.WriteFile("users.ini"); + cRoot::Get()->GetGroupManager()->CheckUsers(); AddToGroup("Default"); } ResolvePermissions(); -- cgit v1.2.3 From 1b32b005626e7dd7e466358910d461bf5fb11a64 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Fri, 21 Feb 2014 18:45:00 +0100 Subject: Fixed Mob Drops, Add Rare and Uncommon Drops, Looting inflicts Drops --- src/Mobs/Blaze.cpp | 6 +++++- src/Mobs/Cavespider.cpp | 8 ++++++-- src/Mobs/Chicken.cpp | 5 +++-- src/Mobs/Cow.cpp | 5 +++-- src/Mobs/Creeper.cpp | 3 ++- src/Mobs/Enderman.cpp | 3 ++- src/Mobs/Ghast.cpp | 5 +++-- src/Mobs/Horse.cpp | 3 ++- src/Mobs/IronGolem.cpp | 1 + src/Mobs/Magmacube.cpp | 5 ++++- src/Mobs/Monster.cpp | 29 +++++++++++++++++++++++++++++ src/Mobs/Monster.h | 3 +++ src/Mobs/Mooshroom.cpp | 5 +++-- src/Mobs/Pig.cpp | 3 ++- src/Mobs/Skeleton.cpp | 24 ++++++++++++++++++++++-- src/Mobs/Slime.cpp | 7 +++++-- src/Mobs/SnowGolem.cpp | 2 +- src/Mobs/Spider.cpp | 8 ++++++-- src/Mobs/Squid.cpp | 3 ++- src/Mobs/Witch.cpp | 27 ++++++++++++++++++++------- src/Mobs/Witch.h | 1 + src/Mobs/Zombie.cpp | 15 ++++++++++++--- src/Mobs/Zombiepigman.cpp | 10 +++++++--- 23 files changed, 144 insertions(+), 37 deletions(-) diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index f9c05b17a..084567708 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,7 +19,11 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_BLAZE_ROD); + if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + { + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); + } } diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index aba1ff9f5..0554f5c2a 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -31,8 +31,12 @@ void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_STRING); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_SPIDER_EYE); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); + if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + { + AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); + } } diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index fab92ce49..4ca016883 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -48,8 +48,9 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk) void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_FEATHER); - a_Drops.push_back(cItem(IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN, 1)); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); + AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); } diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index d8e905217..2740e4e72 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -21,8 +21,9 @@ cCow::cCow(void) : void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_LEATHER); - AddRandomDropItem(a_Drops, 1, 3, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); + AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index ff0abfdca..594878e52 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -39,7 +39,8 @@ void cCreeper::Tick(float a_Dt, cChunk & a_Chunk) void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_GUNPOWDER); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); if ((a_Killer != NULL) && (a_Killer->IsProjectile())) { diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index a784131e4..b79bf20fc 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -21,7 +21,8 @@ cEnderman::cEnderman(void) : void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_ENDER_PEARL); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL); } diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index 96a29b2d8..b62069d63 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -18,8 +18,9 @@ cGhast::cGhast(void) : void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_GUNPOWDER); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_GHAST_TEAR); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); } diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index bb9a4e3f6..4220585a1 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -140,7 +140,8 @@ void cHorse::OnRightClicked(cPlayer & a_Player) void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_LEATHER); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); if (m_bIsSaddled) { a_Drops.push_back(cItem(E_ITEM_SADDLE, 1)); diff --git a/src/Mobs/IronGolem.cpp b/src/Mobs/IronGolem.cpp index 47c961098..057834afd 100644 --- a/src/Mobs/IronGolem.cpp +++ b/src/Mobs/IronGolem.cpp @@ -19,6 +19,7 @@ cIronGolem::cIronGolem(void) : void cIronGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) { AddRandomDropItem(a_Drops, 0, 5, E_ITEM_IRON); + AddRandomDropItem(a_Drops, 0, 2, E_BLOCK_FLOWER); } diff --git a/src/Mobs/Magmacube.cpp b/src/Mobs/Magmacube.cpp index 86447ff6b..ec6137ca6 100644 --- a/src/Mobs/Magmacube.cpp +++ b/src/Mobs/Magmacube.cpp @@ -19,7 +19,10 @@ cMagmaCube::cMagmaCube(int a_Size) : void cMagmaCube::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_MAGMA_CREAM); + if (GetSize() > 1) + { + AddRandomUncommonDropItem(a_Drops, 25.0f, E_ITEM_MAGMA_CREAM); + } } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index b5cf693cb..66629474b 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -880,6 +880,35 @@ void cMonster::AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned +void cMonster::AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth) +{ + MTRand r1; + int Count = r1.randInt() % 1000; + if (Count < (a_Chance*10)) + { + a_Drops.push_back(cItem(a_Item, 1, a_ItemHealth)); + } +} + + + + + +void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel) +{ + MTRand r1; + int Count = r1.randInt() % 200; + if (Count < (5 + a_LootingLevel)) + { + int Rare = r1.randInt() % a_Items.Size(); + a_Drops.push_back(a_Items.at(Rare)); + } +} + + + + + void cMonster::HandleDaylightBurning(cChunk & a_Chunk) { if (!m_BurnsInDaylight) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 4d2e099c5..909504213 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -224,6 +224,9 @@ protected: bool m_BurnsInDaylight; void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); + void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); + void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); + } ; // tolua_export diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 88101cd83..4c245ea2d 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -23,8 +23,9 @@ cMooshroom::cMooshroom(void) : void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_LEATHER); - AddRandomDropItem(a_Drops, 1, 3, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); + AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index d8f3dda37..063e2a5b4 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -21,7 +21,8 @@ cPig::cPig(void) : void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 1, 3, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); if (m_bIsSaddled) { a_Drops.push_back(cItem(E_ITEM_SADDLE, 1)); diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 4c8e78988..b0a5670cf 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -20,8 +20,28 @@ cSkeleton::cSkeleton(bool IsWither) : void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_ARROW); - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_BONE); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + if (IsWither()) + { + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); + AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_COAL); + cItems RareDrops; + RareDrops.Add(cItem(E_ITEM_HEAD, 1, 1)); + if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + } + else + { + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ARROW); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); + cItems RareDrops; + if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); + if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); + if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); + if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); + if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + } } diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 19f376c21..f5b2cabc2 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -20,8 +20,11 @@ cSlime::cSlime(int a_Size) : void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - // TODO: only when tiny - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_SLIMEBALL); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + if (GetSize() == 1) + { + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL); + } } diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index c60103055..b68d18575 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -19,7 +19,7 @@ cSnowGolem::cSnowGolem(void) : void cSnowGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 5, E_ITEM_SNOWBALL); + AddRandomDropItem(a_Drops, 0, 15, E_ITEM_SNOWBALL); } diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index b19a5dcef..1f41328a2 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -18,8 +18,12 @@ cSpider::cSpider(void) : void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_STRING); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_SPIDER_EYE); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); + if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + { + AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); + } } diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 5a27762ff..9dee69cbb 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -21,7 +21,8 @@ cSquid::cSquid(void) : void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // Drops 0-3 Ink Sacs - AddRandomDropItem(a_Drops, 0, 3, E_ITEM_DYE, E_META_DYE_BLACK); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index 25d27041f..88e8f4e50 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -18,13 +18,26 @@ cWitch::cWitch(void) : void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_GLASS_BOTTLE); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_GLOWSTONE_DUST); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_GUNPOWDER); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_REDSTONE_DUST); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_SPIDER_EYE); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_STICK); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_SUGAR); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + MTRand r1; + int DropTypeCount = (r1.randInt() % 3) + 1; + for (int i = 0; i < DropTypeCount; i++) + { + int DropType = r1.randInt() % 7; + switch (DropType) + { + case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); + case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); + case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); + case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); + case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); + case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); + case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); + } + } + cItems RareDrops; + if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); } diff --git a/src/Mobs/Witch.h b/src/Mobs/Witch.h index 4e637beea..51c63322a 100644 --- a/src/Mobs/Witch.h +++ b/src/Mobs/Witch.h @@ -2,6 +2,7 @@ #pragma once #include "AggressiveMonster.h" +#include "../MersenneTwister.h" diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 27e8ed5fb..72373266a 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -23,9 +23,18 @@ cZombie::cZombie(bool a_IsVillagerZombie) : void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_ROTTEN_FLESH); - - // TODO: Rare drops + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); + cItems RareDrops; + RareDrops.Add(cItem(E_ITEM_IRON)); + RareDrops.Add(cItem(E_ITEM_CARROT)); + RareDrops.Add(cItem(E_ITEM_POTATO)); + if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); + if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); + if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); + if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); + if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); } diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index 6ac89ed4c..d1eadc2ae 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -19,10 +19,14 @@ cZombiePigman::cZombiePigman(void) : void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_ROTTEN_FLESH); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_GOLD_NUGGET); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); - // TODO: Rare drops + cItems RareDrops; + RareDrops.Add(cItem(E_ITEM_GOLD)); + if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); } -- cgit v1.2.3 From b3339a6617ffd7b8358c83348e6ccfa8eba2eb92 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 21 Feb 2014 22:26:04 +0100 Subject: Better Jukebox API --- src/BlockEntities/JukeboxEntity.cpp | 48 +++++++++++++++++++++++++++---------- src/BlockEntities/JukeboxEntity.h | 16 ++++++++++--- src/BlockID.h | 4 ++++ 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/BlockEntities/JukeboxEntity.cpp b/src/BlockEntities/JukeboxEntity.cpp index 33042179d..c96253b11 100644 --- a/src/BlockEntities/JukeboxEntity.cpp +++ b/src/BlockEntities/JukeboxEntity.cpp @@ -30,48 +30,70 @@ cJukeboxEntity::~cJukeboxEntity() void cJukeboxEntity::UsedBy(cPlayer * a_Player) { - if (m_Record == 0) + if (IsPlayingRecord()) + { + EjectRecord(); + } + else { const cItem & HeldItem = a_Player->GetEquippedItem(); - if (HeldItem.m_ItemType >= 2256 && HeldItem.m_ItemType <= 2267) + if (PlayRecord(HeldItem.m_ItemType)) { - m_Record = HeldItem.m_ItemType; a_Player->GetInventory().RemoveOneEquippedItem(); - PlayRecord(); } } - else - { - EjectRecord(); - } } -void cJukeboxEntity::PlayRecord(void) +bool cJukeboxEntity::PlayRecord(int a_Record) { + if (!IsRecordItem(a_Record)) + { + // This isn't a Record Item + return false; + } + if (IsPlayingRecord()) + { + // A Record is already in the Jukebox. + EjectRecord(); + } + m_Record = a_Record; m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, m_Record); + m_World->SetBlockMeta(m_PosX, m_PosY, m_PosZ, E_META_JUKEBOX_ON); + return true; } -void cJukeboxEntity::EjectRecord(void) +bool cJukeboxEntity::EjectRecord(void) { - if ((m_Record < E_ITEM_FIRST_DISC) || (m_Record > E_ITEM_LAST_DISC)) + if (!IsPlayingRecord()) { // There's no record here - return; + return false; } cItems Drops; Drops.push_back(cItem(m_Record, 1, 0)); + m_Record = 0; m_World->SpawnItemPickups(Drops, m_PosX + 0.5, m_PosY + 1, m_PosZ + 0.5, 8); m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, 0); - m_Record = 0; + m_World->SetBlockMeta(m_PosX, m_PosY, m_PosZ, E_META_JUKEBOX_OFF); + return true; +} + + + + + +bool cJukeboxEntity::IsPlayingRecord(void) +{ + return (m_Record != 0); } diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index 734d7bb66..01ce52494 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -37,10 +37,20 @@ public: int GetRecord(void); void SetRecord(int a_Record); - void PlayRecord(void); - /// Ejects the currently held record as a pickup. Does nothing when no record inserted. - void EjectRecord(void); + /** Play a Record. Return false, when a_Record isn't a Record */ + bool PlayRecord(int a_Record); + + /** Ejects the currently held record as a pickup. Return false when no record inserted. */ + bool EjectRecord(void); + + /** Is in the Jukebox a Record? */ + bool IsPlayingRecord(void); + + static bool IsRecordItem(int a_Item) + { + return ((a_Item >= E_ITEM_FIRST_DISC) && (a_Item <= E_ITEM_LAST_DISC)); + } // tolua_end diff --git a/src/BlockID.h b/src/BlockID.h index 3413555f4..861bb8dae 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -466,6 +466,10 @@ enum E_META_FLOWER_PINK_TULIP = 7, E_META_FLOWER_OXEYE_DAISY = 8, + // E_BLOCK_JUKEBOX metas + E_META_JUKEBOX_OFF = 0, + E_META_JUKEBOX_ON = 1, + // E_BLOCK_HOPPER metas: E_META_HOPPER_FACING_YM = 0, E_META_HOPPER_UNATTACHED = 1, // Hopper doesn't move items up, there's no YP -- cgit v1.2.3 From 7a7b9e88b295bd5e151f84cb4ae78d1749367d4e Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 01:21:49 +0100 Subject: Added static Enchantment Constants, Replaced cryptic Looting ID --- src/BlockID.h | 32 ++++++++++++++++++++++++++++++++ src/Mobs/Blaze.cpp | 2 +- src/Mobs/Cavespider.cpp | 2 +- src/Mobs/Chicken.cpp | 2 +- src/Mobs/Cow.cpp | 2 +- src/Mobs/Creeper.cpp | 2 +- src/Mobs/Enderman.cpp | 2 +- src/Mobs/Ghast.cpp | 2 +- src/Mobs/Horse.cpp | 2 +- src/Mobs/Mooshroom.cpp | 2 +- src/Mobs/Pig.cpp | 2 +- src/Mobs/Skeleton.cpp | 2 +- src/Mobs/Slime.cpp | 2 +- src/Mobs/Spider.cpp | 2 +- src/Mobs/Squid.cpp | 2 +- src/Mobs/Witch.cpp | 2 +- src/Mobs/Zombie.cpp | 2 +- src/Mobs/Zombiepigman.cpp | 2 +- 18 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index 740c5fc90..e23a0f82a 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -392,6 +392,38 @@ enum ENUM_ITEM_ID +// ENCHANTMENT IDS +enum +{ + E_ENCHANTMENT_PROTECTION = 0, + E_ENCHANTMENT_FIRE_PROTECTION = 1, + E_ENCHANTMENT_FEATHER_FALLING = 2, + E_ENCHANTMENT_BLAST_PROTECTION = 3, + E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, + E_ENCHANTMENT_RESPIRATION = 5, + E_ENCHANTMENT_AQUA_AFFINITY = 6, + E_ENCHANTMENT_THORNS = 7, + E_ENCHANTMENT_SHARPNESS = 16, + E_ENCHANTMENT_SMITE = 17, + E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, + E_ENCHANTMENT_KNOCKBACK = 19, + E_ENCHANTMENT_FIREASPECT = 20, + E_ENCHANTMENT_LOOTING = 21, + E_ENCHANTMENT_EFFICIENCY = 32, + E_ENCHANTMENT_SILKTOUCH = 33, + E_ENCHANTMENT_UNBREAKING = 34, + E_ENCHANTMENT_FORTUNE = 35, + E_ENCHANTMENT_POWER = 48, + E_ENCHANTMENT_PUNCH = 49, + E_ENCHANTMENT_FLAME = 50, + E_ENCHANTMENT_INFINITY = 51, + E_ENCHANTMENT_LUCKOFTHESEA = 61, + E_ENCHANTMENT_LURE = 62, +}; + + + + enum { diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index 084567708..bd16a36e2 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -21,7 +21,7 @@ void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); } } diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index 0554f5c2a..7274820b7 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -31,7 +31,7 @@ void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) { diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index 4ca016883..9388e1097 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -48,7 +48,7 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk) void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); } diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index 2740e4e72..cda067fac 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -21,7 +21,7 @@ cCow::cCow(void) : void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 594878e52..0ae78eee3 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -39,7 +39,7 @@ void cCreeper::Tick(float a_Dt, cChunk & a_Chunk) void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); if ((a_Killer != NULL) && (a_Killer->IsProjectile())) diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index b79bf20fc..4a5ad25be 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -21,7 +21,7 @@ cEnderman::cEnderman(void) : void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL); } diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index b62069d63..a73ed0944 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -18,7 +18,7 @@ cGhast::cGhast(void) : void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); } diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index 4220585a1..3c29e3682 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -140,7 +140,7 @@ void cHorse::OnRightClicked(cPlayer & a_Player) void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); if (m_bIsSaddled) { diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 4c245ea2d..17995ce91 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -23,7 +23,7 @@ cMooshroom::cMooshroom(void) : void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index 063e2a5b4..e4e46dfec 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -21,7 +21,7 @@ cPig::cPig(void) : void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); if (m_bIsSaddled) { diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index b0a5670cf..622cb5ceb 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -20,7 +20,7 @@ cSkeleton::cSkeleton(bool IsWither) : void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); if (IsWither()) { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index f5b2cabc2..7941e2452 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -20,7 +20,7 @@ cSlime::cSlime(int a_Size) : void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); if (GetSize() == 1) { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL); diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index 1f41328a2..aeb6e1bcc 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -18,7 +18,7 @@ cSpider::cSpider(void) : void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) { diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 9dee69cbb..4f2abf574 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -21,7 +21,7 @@ cSquid::cSquid(void) : void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // Drops 0-3 Ink Sacs - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index 88e8f4e50..6cb103645 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -18,7 +18,7 @@ cWitch::cWitch(void) : void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); MTRand r1; int DropTypeCount = (r1.randInt() % 3) + 1; for (int i = 0; i < DropTypeCount; i++) diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 72373266a..6a007683b 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -23,7 +23,7 @@ cZombie::cZombie(bool a_IsVillagerZombie) : void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_IRON)); diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index d1eadc2ae..ca222f9fe 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -19,7 +19,7 @@ cZombiePigman::cZombiePigman(void) : void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); -- cgit v1.2.3 From 764de9c39939e2184671e52ebab599c4e1c6b47d Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 01:27:32 +0100 Subject: Changed killer detection by using cEntity methods --- src/Mobs/Blaze.cpp | 2 +- src/Mobs/Cavespider.cpp | 2 +- src/Mobs/Spider.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index bd16a36e2..005bb23a1 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,7 +19,7 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) { int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index 7274820b7..9c88ac5d7 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -33,7 +33,7 @@ void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index aeb6e1bcc..1eb340075 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -20,7 +20,7 @@ void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } -- cgit v1.2.3 From c4bfe670c602ec498cc9ee9f6f7f430a353cdda0 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 01:29:50 +0100 Subject: Monster.cpp: Fixed Formatting in AddRandomUncommonDropItem --- src/Mobs/Monster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 66629474b..777b78c63 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -884,7 +884,7 @@ void cMonster::AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short { MTRand r1; int Count = r1.randInt() % 1000; - if (Count < (a_Chance*10)) + if (Count < (a_Chance * 10)) { a_Drops.push_back(cItem(a_Item, 1, a_ItemHealth)); } -- cgit v1.2.3 From f45d7d9769782b5e9a11348c4ef261a2da51091a Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 01:42:49 +0100 Subject: Monster.h: Added doxy-comments for drop methods --- src/Mobs/Monster.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 909504213..670e899c5 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -223,8 +223,11 @@ protected: void HandleDaylightBurning(cChunk & a_Chunk); bool m_BurnsInDaylight; + /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/ void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); + /** Adds a item a_Item with the chance of a_Chance to itemdrops a_Drops*/ void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); + /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/ void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); -- cgit v1.2.3 From 748a9c60b336f5ffabed9d5f2d86fc757bd3a253 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 02:11:54 +0100 Subject: Mooshroom.cpp: Added right click interaction --- src/Mobs/Mooshroom.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/Mobs/Mooshroom.h | 1 + 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 17995ce91..4787c6096 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -2,11 +2,12 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Mooshroom.h" +#include "../Entities/Player.h" + -// TODO: Milk Cow @@ -30,3 +31,38 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) + + +void cMooshroom::OnRightClicked(cPlayer & a_Player) +{ + if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BUCKET)) + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MILK); + } + } + + if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BOWL)) + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP); + } + } + + if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SHEARS) + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.UseEquippedItem(); + } + + cItems Drops; + Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + } +} + diff --git a/src/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h index c94301098..16f6c8248 100644 --- a/src/Mobs/Mooshroom.h +++ b/src/Mobs/Mooshroom.h @@ -18,6 +18,7 @@ public: CLASS_PROTODEF(cMooshroom); virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + virtual void OnRightClicked(cPlayer & a_Player) override; virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } } ; -- cgit v1.2.3 From a96eea5e66191ee02c21e3ce3f33277c516142bc Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 22 Feb 2014 12:50:30 +0200 Subject: Semi-working implementation of cMap::UpdatePixel --- src/Map.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/Map.h | 18 +++++++++++++ 2 files changed, 95 insertions(+), 11 deletions(-) diff --git a/src/Map.cpp b/src/Map.cpp index 0028a1e94..87fe9555f 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -123,7 +123,7 @@ cMap::cMap(unsigned int a_ID, cWorld * a_World) , m_CenterZ(0) , m_World(a_World) { - m_Data.assign(m_Width * m_Height, 0); + m_Data.assign(m_Width * m_Height, E_BASE_COLOR_TRANSPARENT); Printf(m_Name, "map_%i", m_ID); } @@ -141,7 +141,7 @@ cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, un , m_CenterZ(a_CenterZ) , m_World(a_World) { - m_Data.assign(m_Width * m_Height, 0); + m_Data.assign(m_Width * m_Height, E_BASE_COLOR_TRANSPARENT); Printf(m_Name, "map_%i", m_ID); } @@ -195,11 +195,10 @@ void cMap::UpdateRadius(cPlayer & a_Player, unsigned int a_Radius) bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) { - /* unsigned int PixelWidth = GetPixelWidth(); - int BlockX = m_CenterX + ((a_X - m_Width) * PixelWidth); - int BlockZ = m_CenterZ + ((a_Y - m_Height) * PixelWidth); + int BlockX = m_CenterX + ((a_X - (m_Width / 2)) * PixelWidth); + int BlockZ = m_CenterZ + ((a_Z - (m_Height / 2)) * PixelWidth); int ChunkX, ChunkY, ChunkZ; m_World->BlockToChunk(BlockX, 0, BlockZ, ChunkX, ChunkY, ChunkZ); @@ -218,7 +217,7 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) public: cCalculatePixelCb(cMap * a_Map, int a_RelX, int a_RelZ) - : m_Map(a_Map), m_RelX(a_RelX), m_RelZ(a_RelZ), m_PixelData(4) {} + : m_Map(a_Map), m_RelX(a_RelX), m_RelZ(a_RelZ), m_PixelData(E_BASE_COLOR_TRANSPARENT) {} virtual bool Item(cChunk * a_Chunk) override { @@ -229,20 +228,88 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) unsigned int PixelWidth = m_Map->GetPixelWidth(); + if (m_Map->GetDimension() == dimNether) + { + // TODO 2014-02-22 xdot: Nether maps + + return false; + } + + typedef std::map ColorCountMap; + ColorCountMap ColorCounts; + + // Count surface blocks for (unsigned int X = m_RelX; X < m_RelX + PixelWidth; ++X) { for (unsigned int Z = m_RelZ; Z < m_RelZ + PixelWidth; ++Z) { + unsigned int WaterDepth = 0; + + BLOCKTYPE TargetBlock = E_BLOCK_AIR; + NIBBLETYPE TargetMeta = 0; + int Height = a_Chunk->GetHeight(X, Z); - if (Height > 0) + while (Height > 0) + { + a_Chunk->GetBlockTypeMeta(X, Height, Z, TargetBlock, TargetMeta); + + // TODO 2014-02-22 xdot: Check if block color is transparent + if (TargetBlock == E_BLOCK_AIR) + { + --Height; + continue; + } + // TODO 2014-02-22 xdot: Check if block is liquid + else if (false) + { + --Height; + ++WaterDepth; + continue; + } + + break; + } + + // TODO 2014-02-22 xdot: Query block color + ColorID Color = E_BASE_COLOR_BROWN; + + // Debug - Temporary + switch (TargetBlock) { - // TODO + case E_BLOCK_GRASS: + { + Color = E_BASE_COLOR_LIGHT_GREEN; break; + } + case E_BLOCK_STATIONARY_WATER: + case E_BLOCK_WATER: + { + Color = E_BASE_COLOR_BLUE; break; + } } + + ++ColorCounts[Color]; + } + } + + // Find dominant color + ColorID PixelColor = E_BASE_COLOR_TRANSPARENT; + + unsigned int MaxCount = 0; + + for (ColorCountMap::iterator it = ColorCounts.begin(); it != ColorCounts.end(); ++it) + { + if (it->second > MaxCount) + { + PixelColor = it->first; + MaxCount = it->second; } } - m_PixelData = 8; // Debug + // TODO 2014-02-22 xdot: Adjust brightness + unsigned int dColor = 1; + + m_PixelData = PixelColor + dColor; return false; } @@ -255,9 +322,8 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) ASSERT(m_World != NULL); m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb); - */ - m_Data[a_Z + (a_X * m_Height)] = 4; + m_Data[a_Z + (a_X * m_Height)] = CalculatePixelCb.GetPixelData(); return true; } diff --git a/src/Map.h b/src/Map.h index 01ffd19f5..a86de3dd3 100644 --- a/src/Map.h +++ b/src/Map.h @@ -99,6 +99,24 @@ class cMap { public: + enum eBaseColor + { + E_BASE_COLOR_TRANSPARENT = 0, /* Air */ + E_BASE_COLOR_LIGHT_GREEN = 4, /* Grass */ + E_BASE_COLOR_LIGHT_BROWN = 8, /* Sand */ + E_BASE_COLOR_GRAY_1 = 12, /* Cloth */ + E_BASE_COLOR_RED = 16, /* TNT */ + E_BASE_COLOR_PALE_BLUE = 20, /* Ice */ + E_BASE_COLOR_GRAY_2 = 24, /* Iron */ + E_BASE_COLOR_DARK_GREEN = 28, /* Foliage */ + E_BASE_COLOR_WHITE = 32, /* Snow */ + E_BASE_COLOR_LIGHT_GRAY = 36, /* Clay */ + E_BASE_COLOR_BROWN = 40, /* Dirt */ + E_BASE_COLOR_DARK_GRAY = 44, /* Stone */ + E_BASE_COLOR_BLUE = 48, /* Water */ + E_BASE_COLOR_DARK_BROWN = 52 /* Wood */ + }; + typedef Byte ColorID; // tolua_end -- cgit v1.2.3 From b15ca0055b922f39b968b051efd921897d61276c Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 12:58:32 +0100 Subject: Fixed Looting segment fault - a_Killer can be NULL --- src/Mobs/Blaze.cpp | 2 +- src/Mobs/Cavespider.cpp | 8 ++++++-- src/Mobs/Chicken.cpp | 6 +++++- src/Mobs/Cow.cpp | 6 +++++- src/Mobs/Creeper.cpp | 6 +++++- src/Mobs/Enderman.cpp | 6 +++++- src/Mobs/Ghast.cpp | 6 +++++- src/Mobs/Horse.cpp | 6 +++++- src/Mobs/Mooshroom.cpp | 6 +++++- src/Mobs/Pig.cpp | 6 +++++- src/Mobs/Skeleton.cpp | 6 +++++- src/Mobs/Slime.cpp | 6 +++++- src/Mobs/Spider.cpp | 8 ++++++-- src/Mobs/Squid.cpp | 6 +++++- src/Mobs/Witch.cpp | 6 +++++- src/Mobs/Zombie.cpp | 6 +++++- src/Mobs/Zombiepigman.cpp | 6 +++++- 17 files changed, 83 insertions(+), 19 deletions(-) diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index 005bb23a1..fb97ea3c4 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,7 +19,7 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) + if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index 9c88ac5d7..a2678744b 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -31,9 +31,13 @@ void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) + if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index 9388e1097..b58eedbf7 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -48,7 +48,11 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk) void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); } diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index cda067fac..49eac5cf5 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -21,7 +21,11 @@ cCow::cCow(void) : void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 0ae78eee3..3dd978088 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -39,7 +39,11 @@ void cCreeper::Tick(float a_Dt, cChunk & a_Chunk) void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); if ((a_Killer != NULL) && (a_Killer->IsProjectile())) diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index 4a5ad25be..f0a3b5f5d 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -21,7 +21,11 @@ cEnderman::cEnderman(void) : void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL); } diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index a73ed0944..300435557 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -18,7 +18,11 @@ cGhast::cGhast(void) : void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); } diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index 3c29e3682..73cc532bf 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -140,7 +140,11 @@ void cHorse::OnRightClicked(cPlayer & a_Player) void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); if (m_bIsSaddled) { diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 4787c6096..bc1b9cac7 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -24,7 +24,11 @@ cMooshroom::cMooshroom(void) : void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index e4e46dfec..aa127a590 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -21,7 +21,11 @@ cPig::cPig(void) : void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); if (m_bIsSaddled) { diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 622cb5ceb..7c62de9cf 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -20,7 +20,11 @@ cSkeleton::cSkeleton(bool IsWither) : void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } if (IsWither()) { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 7941e2452..2001fdcb4 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -20,7 +20,11 @@ cSlime::cSlime(int a_Size) : void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } if (GetSize() == 1) { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL); diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index 1eb340075..d20f4997c 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -18,9 +18,13 @@ cSpider::cSpider(void) : void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) + if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 4f2abf574..24818222b 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -21,7 +21,11 @@ cSquid::cSquid(void) : void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // Drops 0-3 Ink Sacs - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index 6cb103645..f9025afe3 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -18,7 +18,11 @@ cWitch::cWitch(void) : void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } MTRand r1; int DropTypeCount = (r1.randInt() % 3) + 1; for (int i = 0; i < DropTypeCount; i++) diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 6a007683b..61cf49c14 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -23,7 +23,11 @@ cZombie::cZombie(bool a_IsVillagerZombie) : void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_IRON)); diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index ca222f9fe..5492068c9 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -19,7 +19,11 @@ cZombiePigman::cZombiePigman(void) : void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); -- cgit v1.2.3 From 866fde81ca50f223c88af77d0092a2f4e60f7ce9 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 22 Feb 2014 13:59:49 +0200 Subject: Documented and exported cMap --- MCServer/Plugins/APIDump/APIDesc.lua | 49 ++++++++++++++++++++++++++++++++++++ src/Bindings/AllToLua.pkg | 1 + src/Map.cpp | 49 +++++++++++++++++++++++++++++++----- src/Map.h | 12 ++++++--- 4 files changed, 102 insertions(+), 9 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 73bb5c7fb..296a60640 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1485,6 +1485,55 @@ a_Player:OpenWindow(Window); Inherits = "cWindow", }, -- cLuaWindow + cMap = + { + Desc = [[ + This class encapsulates a single in-game colored map.

    +

    + The contents (i.e. pixel data) of a cMap are dynamically updated by each + tracked {{cPlayer}} instance. Furthermore, a cMap maintains and periodically + updates a list of map decorators, which are objects drawn on the map that + can freely move (e.g. Player and item frame pointers). + ]], + Functions = + { + EraseData = { Params = "", Return = "", Notes = "Erases all pixel data." }, + GetCenterX = { Params = "", Return = "number", Notes = "Returns the X coord of the map's center." }, + GetCenterZ = { Params = "", Return = "number", Notes = "Returns the Y coord of the map's center." }, + GetDimension = { Params = "", Return = "eDimension", Notes = "Returns the dimension of the associated world." }, + GetHeight = { Params = "", Return = "number", Notes = "Returns the height of the map." }, + GetID = { Params = "", Return = "number", Notes = "Returns the numerical ID of the map. (The item damage value)" }, + GetName = { Params = "", Return = "string", Notes = "Returns the name of the map." }, + GetNumPixels = { Params = "", Return = "number", Notes = "Returns the number of pixels in this map." }, + GetPixel = { Params = "PixelX, PixelZ", Return = "ColorID", Notes = "Returns the color of the specified pixel." }, + GetPixelWidth = { Params = "", Return = "number", Notes = "Returns the width of a single pixel in blocks." }, + GetScale = { Params = "", Return = "number", Notes = "Returns the scale of the map. Range: [0,4]" }, + GetWidth = { Params = "", Return = "number", Notes = "Returns the width of the map." }, + GetWorld = { Params = "", Return = "cWorld", Notes = "Returns the associated world." }, + Resize = { Params = "Width, Height", Return = "", Notes = "Resizes the map. WARNING: This will erase the pixel data." }, + SetPixel = { Params = "PixelX, PixelZ, ColorID", Return = "bool", Notes = "Sets the color of the specified pixel. Returns false on error (Out of range)." }, + SetPosition = { Params = "CenterX, CenterZ", Return = "", Notes = "Relocates the map. The pixel data will not be modified." }, + SetScale = { Params = "number", Return = "", Notes = "Rescales the map. The pixel data will not be modified." }, + }, + Constants = + { + E_BASE_COLOR_BLUE = { Notes = "" }, + E_BASE_COLOR_BROWN = { Notes = "" }, + E_BASE_COLOR_DARK_BROWN = { Notes = "" }, + E_BASE_COLOR_DARK_GRAY = { Notes = "" }, + E_BASE_COLOR_DARK_GREEN = { Notes = "" }, + E_BASE_COLOR_GRAY_1 = { Notes = "" }, + E_BASE_COLOR_GRAY_2 = { Notes = "" }, + E_BASE_COLOR_LIGHT_BROWN = { Notes = "" }, + E_BASE_COLOR_LIGHT_GRAY = { Notes = "" }, + E_BASE_COLOR_LIGHT_GREEN = { Notes = "" }, + E_BASE_COLOR_PALE_BLUE = { Notes = "" }, + E_BASE_COLOR_RED = { Notes = "" }, + E_BASE_COLOR_TRANSPARENT = { Notes = "" }, + E_BASE_COLOR_WHITE = { Notes = "" }, + }, + }, -- cMap + cMonster = { Desc = [[ diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index ef61f55f0..dd45a2aab 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -73,6 +73,7 @@ $cfile "../CraftingRecipes.h" $cfile "../UI/Window.h" $cfile "../Mobs/Monster.h" $cfile "../CompositeChat.h" +$cfile "../Map.h" diff --git a/src/Map.cpp b/src/Map.cpp index 87fe9555f..e89fad8b0 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -323,7 +323,7 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) ASSERT(m_World != NULL); m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb); - m_Data[a_Z + (a_X * m_Height)] = CalculatePixelCb.GetPixelData(); + SetPixel(a_X, a_Z, CalculatePixelCb.GetPixelData()); return true; } @@ -516,11 +516,6 @@ void cMap::Resize(unsigned int a_Width, unsigned int a_Height) void cMap::SetPosition(int a_CenterX, int a_CenterZ) { - if ((m_CenterX == a_CenterX) && (m_CenterZ == a_CenterZ)) - { - return; - } - m_CenterX = a_CenterX; m_CenterZ = a_CenterZ; } @@ -548,6 +543,40 @@ void cMap::SetScale(unsigned int a_Scale) +bool cMap::SetPixel(unsigned int a_X, unsigned int a_Z, cMap::ColorID a_Data) +{ + if ((a_X < m_Width) && (a_Z < m_Height)) + { + m_Data[a_Z + (a_X * m_Height)] = a_Data; + + return true; + } + else + { + return false; + } +} + + + + + +cMap::ColorID cMap::GetPixel(unsigned int a_X, unsigned int a_Z) +{ + if ((a_X < m_Width) && (a_Z < m_Height)) + { + return m_Data[a_Z + (a_X * m_Height)]; + } + else + { + return E_BASE_COLOR_TRANSPARENT; + } +} + + + + + void cMap::SendTo(cClientHandle & a_Client) { a_Client.SendMapInfo(m_ID, m_Scale); @@ -575,6 +604,14 @@ unsigned int cMap::GetNumPixels(void) const +unsigned int cMap::GetNumDecorators(void) const +{ + return m_Decorators.size(); +} + + + + unsigned int cMap::GetPixelWidth(void) const { return pow(2, m_Scale); diff --git a/src/Map.h b/src/Map.h index a86de3dd3..fc754e6eb 100644 --- a/src/Map.h +++ b/src/Map.h @@ -155,6 +155,10 @@ public: void SetScale(unsigned int a_Scale); + bool SetPixel(unsigned int a_X, unsigned int a_Z, ColorID a_Data); + + ColorID GetPixel(unsigned int a_X, unsigned int a_Z); + unsigned int GetWidth (void) const { return m_Width; } unsigned int GetHeight(void) const { return m_Height; } @@ -171,14 +175,16 @@ public: eDimension GetDimension(void) const; - const cColorList & GetData(void) const { return m_Data; } - unsigned int GetNumPixels(void) const; unsigned int GetPixelWidth(void) const; // tolua_end + unsigned int GetNumDecorators(void) const; + + const cColorList & GetData(void) const { return m_Data; } + protected: @@ -247,7 +253,7 @@ private: friend class cMapSerializer; -}; +}; // tolua_export -- cgit v1.2.3 From 90574d083da08ccd6699bdad403601e282d73b89 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 22:57:40 +0100 Subject: Changed formatting, encapsuled armor drop, introduced better static Enchantment IDs --- src/BlockID.h | 32 -------------------------------- src/Enchantments.h | 32 ++++++++++++++++++++++++++++++++ src/Mobs/Blaze.cpp | 2 +- src/Mobs/Cavespider.cpp | 2 +- src/Mobs/Monster.cpp | 28 ++++++++++++++++++++++++++++ src/Mobs/Monster.h | 8 +++++++- src/Mobs/Skeleton.cpp | 10 ++-------- src/Mobs/Witch.cpp | 14 +++++++------- src/Mobs/Zombie.cpp | 6 +----- src/Mobs/Zombiepigman.cpp | 2 +- 10 files changed, 80 insertions(+), 56 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index e23a0f82a..740c5fc90 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -392,38 +392,6 @@ enum ENUM_ITEM_ID -// ENCHANTMENT IDS -enum -{ - E_ENCHANTMENT_PROTECTION = 0, - E_ENCHANTMENT_FIRE_PROTECTION = 1, - E_ENCHANTMENT_FEATHER_FALLING = 2, - E_ENCHANTMENT_BLAST_PROTECTION = 3, - E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, - E_ENCHANTMENT_RESPIRATION = 5, - E_ENCHANTMENT_AQUA_AFFINITY = 6, - E_ENCHANTMENT_THORNS = 7, - E_ENCHANTMENT_SHARPNESS = 16, - E_ENCHANTMENT_SMITE = 17, - E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, - E_ENCHANTMENT_KNOCKBACK = 19, - E_ENCHANTMENT_FIREASPECT = 20, - E_ENCHANTMENT_LOOTING = 21, - E_ENCHANTMENT_EFFICIENCY = 32, - E_ENCHANTMENT_SILKTOUCH = 33, - E_ENCHANTMENT_UNBREAKING = 34, - E_ENCHANTMENT_FORTUNE = 35, - E_ENCHANTMENT_POWER = 48, - E_ENCHANTMENT_PUNCH = 49, - E_ENCHANTMENT_FLAME = 50, - E_ENCHANTMENT_INFINITY = 51, - E_ENCHANTMENT_LUCKOFTHESEA = 61, - E_ENCHANTMENT_LURE = 62, -}; - - - - enum { diff --git a/src/Enchantments.h b/src/Enchantments.h index e984df92e..14a900e19 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -21,6 +21,38 @@ class cParsedNBT; +// ENCHANTMENT IDS +enum +{ + E_ENCHANTMENT_PROTECTION = 0, + E_ENCHANTMENT_FIRE_PROTECTION = 1, + E_ENCHANTMENT_FEATHER_FALLING = 2, + E_ENCHANTMENT_BLAST_PROTECTION = 3, + E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, + E_ENCHANTMENT_RESPIRATION = 5, + E_ENCHANTMENT_AQUA_AFFINITY = 6, + E_ENCHANTMENT_THORNS = 7, + E_ENCHANTMENT_SHARPNESS = 16, + E_ENCHANTMENT_SMITE = 17, + E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, + E_ENCHANTMENT_KNOCKBACK = 19, + E_ENCHANTMENT_FIREASPECT = 20, + E_ENCHANTMENT_LOOTING = 21, + E_ENCHANTMENT_EFFICIENCY = 32, + E_ENCHANTMENT_SILKTOUCH = 33, + E_ENCHANTMENT_UNBREAKING = 34, + E_ENCHANTMENT_FORTUNE = 35, + E_ENCHANTMENT_POWER = 48, + E_ENCHANTMENT_PUNCH = 49, + E_ENCHANTMENT_FLAME = 50, + E_ENCHANTMENT_INFINITY = 51, + E_ENCHANTMENT_LUCKOFTHESEA = 61, + E_ENCHANTMENT_LURE = 62, +}; + + + + /** Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a stringspec and read back from such stringspec. diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index fb97ea3c4..cd5437d97 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,7 +19,7 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index a2678744b..4ef80e5f0 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -37,7 +37,7 @@ void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 777b78c63..c81f46d6a 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -909,6 +909,34 @@ void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a +void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) +{ + MTRand r1; + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedHelmet().IsEmpty()) a_Drops.push_back(GetEquippedHelmet()); + } + + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedChestplate().IsEmpty()) a_Drops.push_back(GetEquippedChestplate()); + } + + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedLeggings().IsEmpty()) a_Drops.push_back(GetEquippedLeggings()); + } + + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedBoots().IsEmpty()) a_Drops.push_back(GetEquippedBoots()); + } +} + + + + + void cMonster::HandleDaylightBurning(cChunk & a_Chunk) { if (!m_BurnsInDaylight) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 670e899c5..6f7352b52 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -5,6 +5,7 @@ #include "../Defines.h" #include "../BlockID.h" #include "../Item.h" +#include "../Enchantments.h" @@ -225,11 +226,16 @@ protected: /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/ void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); - /** Adds a item a_Item with the chance of a_Chance to itemdrops a_Drops*/ + + /** Adds a item a_Item with the chance of a_Chance (in percent) to itemdrops a_Drops*/ void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); + /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/ void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); + /** Adds armor that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + void AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel); + } ; // tolua_export diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 7c62de9cf..c941ae521 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -31,20 +31,14 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_COAL); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_HEAD, 1, 1)); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } else { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ARROW); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); - cItems RareDrops; - if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); - if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); - if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); - if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); - AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index f9025afe3..a278a1964 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -30,13 +30,13 @@ void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) int DropType = r1.randInt() % 7; switch (DropType) { - case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); - case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); - case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); - case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); - case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); - case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); - case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); + case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); break; + case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); break; + case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); break; + case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); break; + case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); break; + case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); break; + case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); break; } } cItems RareDrops; diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 61cf49c14..5facf085e 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -33,12 +33,8 @@ void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) RareDrops.Add(cItem(E_ITEM_IRON)); RareDrops.Add(cItem(E_ITEM_CARROT)); RareDrops.Add(cItem(E_ITEM_POTATO)); - if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); - if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); - if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); - if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index 5492068c9..3ecc65fed 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -29,8 +29,8 @@ void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) cItems RareDrops; RareDrops.Add(cItem(E_ITEM_GOLD)); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } -- cgit v1.2.3 From 43b2370bac14578247f87fff7eec50f574b588e0 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 22:59:12 +0100 Subject: Changed formatting again --- src/Mobs/Spider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index d20f4997c..4a6f09aa4 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -24,7 +24,7 @@ void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } -- cgit v1.2.3 From 9fa4fa1cc737a0cf9a078956def206c31a4ebd02 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 23 Feb 2014 12:55:55 +0200 Subject: Documented and exported cMapManager --- MCServer/Plugins/APIDump/APIDesc.lua | 14 ++++++++++++++ src/Bindings/AllToLua.pkg | 1 + src/MapManager.h | 8 +++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 296a60640..8265b4e19 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1534,6 +1534,19 @@ a_Player:OpenWindow(Window); }, }, -- cMap + cMapManager = + { + Desc = [[ + This class is associated with a single {{cWorld}} instance and manages a list of maps. + ]], + Functions = + { + DoWithMap = { Params = "ID, Callback", Return = "bool", Notes = "Calls the callback for the map with the specified ID. Returns true if the map was found and the callback called, false if map not found." }, + GetNumMaps = { Params = "", Return = "number", Notes = "Returns the number of registered maps." }, + }, + + }, -- cMapManager + cMonster = { Desc = [[ @@ -2289,6 +2302,7 @@ World:ForEachEntity( ]], }, }, -- AdditionalInfo + Inherits = "cMapManager" }, -- cWorld HTTPFormData = diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index dd45a2aab..4fd5a68b8 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -74,6 +74,7 @@ $cfile "../UI/Window.h" $cfile "../Mobs/Monster.h" $cfile "../CompositeChat.h" $cfile "../Map.h" +$cfile "../MapManager.h" diff --git a/src/MapManager.h b/src/MapManager.h index 05673c694..5da8be035 100644 --- a/src/MapManager.h +++ b/src/MapManager.h @@ -21,11 +21,13 @@ typedef cItemCallback cMapCallback; +// tolua_begin /** Manages the in-game maps of a single world - Thread safe. */ class cMapManager { public: + // tolua_end cMapManager(cWorld * a_World); @@ -43,7 +45,7 @@ public: * Returns true if the map was found and the callback called, false if map not found. * Callback return ignored. */ - bool DoWithMap(unsigned int a_ID, cMapCallback & a_Callback); + bool DoWithMap(unsigned int a_ID, cMapCallback & a_Callback); // tolua_export /** Calls the callback for each map. * @@ -51,7 +53,7 @@ public: */ bool ForEachMap(cMapCallback & a_Callback); - unsigned int GetNumMaps(void) const; + unsigned int GetNumMaps(void) const; // tolua_export /** Loads the map data from the disk */ void LoadMapData(void); @@ -70,7 +72,7 @@ private: cWorld * m_World; -}; +}; // tolua_export -- cgit v1.2.3 From 30b22e9f59e0873be84e80c83d274dbe5353b835 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 23 Feb 2014 13:25:02 +0200 Subject: Manually exported DoWithMap --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- src/Bindings/ManualBindings.cpp | 4 ++++ src/Map.h | 5 +++++ src/MapManager.cpp | 2 +- src/MapManager.h | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 8265b4e19..c8811df66 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1541,7 +1541,7 @@ a_Player:OpenWindow(Window); ]], Functions = { - DoWithMap = { Params = "ID, Callback", Return = "bool", Notes = "Calls the callback for the map with the specified ID. Returns true if the map was found and the callback called, false if map not found." }, + DoWithMap = { Params = "ID, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If a map with the specified ID exists, calls the CallbackFunction for that map. The CallbackFunction has the following signature:

    function Callback({{cMap|Map}}, [CallbackData])
    Returns true if the map was found and the callback called, false if map not found." }, GetNumMaps = { Params = "", Return = "number", Notes = "Returns the number of registered maps." }, }, diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index c220e5e0a..f2d21a682 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2511,6 +2511,10 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "UpdateSign", tolua_cWorld_SetSignLines); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cMapManager"); + tolua_function(tolua_S, "DoWithMap", tolua_DoWithID); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cPlugin"); tolua_function(tolua_S, "Call", tolua_cPlugin_Call); tolua_endmodule(tolua_S); diff --git a/src/Map.h b/src/Map.h index fc754e6eb..a6df7e5f2 100644 --- a/src/Map.h +++ b/src/Map.h @@ -185,6 +185,11 @@ public: const cColorList & GetData(void) const { return m_Data; } + static const char * GetClassStatic(void) // Needed for ManualBindings's DoWith templates + { + return "cMap"; + } + protected: diff --git a/src/MapManager.cpp b/src/MapManager.cpp index 2fc44ccc8..9d02eafb4 100644 --- a/src/MapManager.cpp +++ b/src/MapManager.cpp @@ -22,7 +22,7 @@ cMapManager::cMapManager(cWorld * a_World) -bool cMapManager::DoWithMap(unsigned int a_ID, cMapCallback & a_Callback) +bool cMapManager::DoWithMap(int a_ID, cMapCallback & a_Callback) { cCSLock Lock(m_CS); cMap * Map = GetMapData(a_ID); diff --git a/src/MapManager.h b/src/MapManager.h index 5da8be035..80e6d16d1 100644 --- a/src/MapManager.h +++ b/src/MapManager.h @@ -45,7 +45,7 @@ public: * Returns true if the map was found and the callback called, false if map not found. * Callback return ignored. */ - bool DoWithMap(unsigned int a_ID, cMapCallback & a_Callback); // tolua_export + bool DoWithMap(int a_ID, cMapCallback & a_Callback); // Exported in ManualBindings.cpp /** Calls the callback for each map. * -- cgit v1.2.3 From beba3e55d73280cb7edfe315f1beaf20dd21e556 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sun, 23 Feb 2014 14:03:01 +0100 Subject: Finally corrected the Enchantment constants. --- src/Enchantments.h | 33 --------------------------------- src/Mobs/Blaze.cpp | 2 +- src/Mobs/Cavespider.cpp | 2 +- src/Mobs/Chicken.cpp | 2 +- src/Mobs/Cow.cpp | 2 +- src/Mobs/Creeper.cpp | 2 +- src/Mobs/Enderman.cpp | 2 +- src/Mobs/Ghast.cpp | 2 +- src/Mobs/Horse.cpp | 2 +- src/Mobs/Mooshroom.cpp | 2 +- src/Mobs/Pig.cpp | 2 +- src/Mobs/Skeleton.cpp | 2 +- src/Mobs/Slime.cpp | 2 +- src/Mobs/Spider.cpp | 2 +- src/Mobs/Squid.cpp | 2 +- src/Mobs/Witch.cpp | 2 +- src/Mobs/Zombie.cpp | 2 +- src/Mobs/Zombiepigman.cpp | 2 +- 18 files changed, 17 insertions(+), 50 deletions(-) diff --git a/src/Enchantments.h b/src/Enchantments.h index 14a900e19..f77b535d8 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -21,39 +21,6 @@ class cParsedNBT; -// ENCHANTMENT IDS -enum -{ - E_ENCHANTMENT_PROTECTION = 0, - E_ENCHANTMENT_FIRE_PROTECTION = 1, - E_ENCHANTMENT_FEATHER_FALLING = 2, - E_ENCHANTMENT_BLAST_PROTECTION = 3, - E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, - E_ENCHANTMENT_RESPIRATION = 5, - E_ENCHANTMENT_AQUA_AFFINITY = 6, - E_ENCHANTMENT_THORNS = 7, - E_ENCHANTMENT_SHARPNESS = 16, - E_ENCHANTMENT_SMITE = 17, - E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, - E_ENCHANTMENT_KNOCKBACK = 19, - E_ENCHANTMENT_FIREASPECT = 20, - E_ENCHANTMENT_LOOTING = 21, - E_ENCHANTMENT_EFFICIENCY = 32, - E_ENCHANTMENT_SILKTOUCH = 33, - E_ENCHANTMENT_UNBREAKING = 34, - E_ENCHANTMENT_FORTUNE = 35, - E_ENCHANTMENT_POWER = 48, - E_ENCHANTMENT_PUNCH = 49, - E_ENCHANTMENT_FLAME = 50, - E_ENCHANTMENT_INFINITY = 51, - E_ENCHANTMENT_LUCKOFTHESEA = 61, - E_ENCHANTMENT_LURE = 62, -}; - - - - - /** Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a stringspec and read back from such stringspec. The format for the stringspec is "id=lvl;id=lvl;id=lvl...", with an optional semicolon at the end, diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index cd5437d97..ac42cf40b 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -21,7 +21,7 @@ void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); } } diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index 4ef80e5f0..94e93283d 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -34,7 +34,7 @@ void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index b58eedbf7..f7e44238f 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -51,7 +51,7 @@ void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index 49eac5cf5..9914df6b5 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -24,7 +24,7 @@ void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 3dd978088..40ee20e44 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -42,7 +42,7 @@ void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index f0a3b5f5d..becc99a86 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -24,7 +24,7 @@ void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL); } diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index 300435557..fe18f5e76 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -21,7 +21,7 @@ void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index 73cc532bf..9d130301f 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -143,7 +143,7 @@ void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); if (m_bIsSaddled) diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index bc1b9cac7..5873ec63f 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -27,7 +27,7 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index aa127a590..e862f5aaa 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -24,7 +24,7 @@ void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); if (m_bIsSaddled) diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index c941ae521..661f0712c 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -23,7 +23,7 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } if (IsWither()) { diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 2001fdcb4..52a52bb39 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -23,7 +23,7 @@ void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } if (GetSize() == 1) { diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index 4a6f09aa4..8b978ff6b 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -21,7 +21,7 @@ void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 24818222b..ba9171b39 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -24,7 +24,7 @@ void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index a278a1964..bdc9e11de 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -21,7 +21,7 @@ void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } MTRand r1; int DropTypeCount = (r1.randInt() % 3) + 1; diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 5facf085e..999cd4a35 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -26,7 +26,7 @@ void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); cItems RareDrops; diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index 3ecc65fed..a967d5066 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -22,7 +22,7 @@ void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); -- cgit v1.2.3 From 3af235b9bbf180140a8055f302e16c7804d9ca2f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 23 Feb 2014 14:03:24 +0100 Subject: Added cBlockArea:GetSize() and :GetOrigin() to Lua API. These don't have a direct C++ equivalent, but are rather useful for the plugins. --- src/Bindings/ManualBindings.cpp | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index c220e5e0a..475913ea2 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2350,6 +2350,37 @@ static int tolua_cBlockArea_GetBlockTypeMeta(lua_State * tolua_S) +static int tolua_cBlockArea_GetOrigin(lua_State * tolua_S) +{ + // function cBlockArea::GetOrigin() + // Returns all three coords of the origin point + // Exported manually because there's no direct C++ equivalent, + // plus tolua would generate extra input params for the outputs + + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cBlockArea")) + { + return 0; + } + + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetOrigin'", NULL); + return 0; + } + + // Push the three origin coords: + lua_pushnumber(tolua_S, self->GetOriginX()); + lua_pushnumber(tolua_S, self->GetOriginY()); + lua_pushnumber(tolua_S, self->GetOriginZ()); + return 3; +} + + + + + static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * tolua_S) { // function cBlockArea::GetRelBlockTypeMeta() @@ -2385,6 +2416,37 @@ static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * tolua_S) +static int tolua_cBlockArea_GetSize(lua_State * tolua_S) +{ + // function cBlockArea::GetSize() + // Returns all three sizes of the area + // Exported manually because there's no direct C++ equivalent, + // plus tolua would generate extra input params for the outputs + + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cBlockArea")) + { + return 0; + } + + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetSize'", NULL); + return 0; + } + + // Push the three origin coords: + lua_pushnumber(tolua_S, self->GetSizeX()); + lua_pushnumber(tolua_S, self->GetSizeY()); + lua_pushnumber(tolua_S, self->GetSizeZ()); + return 3; +} + + + + + static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) { // function cBlockArea::LoadFromSchematicFile @@ -2461,7 +2523,9 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_beginmodule(tolua_S, "cBlockArea"); tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cBlockArea_GetBlockTypeMeta); + tolua_function(tolua_S, "GetOrigin", tolua_cBlockArea_GetOrigin); tolua_function(tolua_S, "GetRelBlockTypeMeta", tolua_cBlockArea_GetRelBlockTypeMeta); + tolua_function(tolua_S, "GetSize", tolua_cBlockArea_GetSize); tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile); tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); tolua_endmodule(tolua_S); -- cgit v1.2.3 From f47187394572027cbfa07884cba2f54eaa6972ec Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 23 Feb 2014 15:03:40 +0200 Subject: Maps: Improvements --- MCServer/Plugins/APIDump/APIDesc.lua | 4 ++-- src/Items/ItemEmptyMap.h | 2 +- src/Items/ItemMap.h | 2 +- src/Map.cpp | 12 +++++++++--- src/Map.h | 2 +- src/World.cpp | 6 +++--- src/World.h | 9 ++++++--- src/WorldStorage/MapSerializer.h | 6 +++++- 8 files changed, 28 insertions(+), 15 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index c8811df66..8e9d239fa 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2165,7 +2165,8 @@ end GetGeneratorQueueLength = { Params = "", Return = "number", Notes = "Returns the number of chunks that are queued in the chunk generator." }, GetHeight = { Params = "BlockX, BlockZ", Return = "number", Notes = "Returns the maximum height of the particula block column in the world. If the chunk is not loaded, it waits for it to load / generate. WARNING: Do not use, Use TryGetHeight() instead for a non-waiting version, otherwise you run the risk of a deadlock!" }, GetIniFileName = { Params = "", Return = "string", Notes = "Returns the name of the world.ini file that the world uses to store the information." }, - GetLightingQueueLength = { Params = "", Return = "number", Notes = "Returns the number of chunks in the lighting thread's queue." }, + GetLightingQueueLength = { Params = "", Return = "number", Notes = "Returns the number of chunks in the lighting thread's queue." }, + GetMapManager = { Params = "", Return = "{{cMapManager}}", Notes = "Returns the {{cMapManager|MapManager}} object used by this world." }, GetMaxCactusHeight = { Params = "", Return = "number", Notes = "Returns the configured maximum height to which cacti will grow naturally." }, GetMaxSugarcaneHeight = { Params = "", Return = "number", Notes = "Returns the configured maximum height to which sugarcane will grow naturally." }, GetName = { Params = "", Return = "string", Notes = "Returns the name of the world, as specified in the settings.ini file." }, @@ -2302,7 +2303,6 @@ World:ForEachEntity( ]], }, }, -- AdditionalInfo - Inherits = "cMapManager" }, -- cWorld HTTPFormData = diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index b06cf9d13..db28511f3 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -41,7 +41,7 @@ public: int CenterX = round(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth; int CenterZ = round(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth; - cMap * NewMap = a_World->CreateMap(CenterX, CenterZ, DEFAULT_SCALE); + cMap * NewMap = a_World->GetMapManager().CreateMap(CenterX, CenterZ, DEFAULT_SCALE); // Remove empty map from inventory if (!a_Player->GetInventory().RemoveOneEquippedItem()) diff --git a/src/Items/ItemMap.h b/src/Items/ItemMap.h index 9bb16b189..e8ff9da88 100644 --- a/src/Items/ItemMap.h +++ b/src/Items/ItemMap.h @@ -29,7 +29,7 @@ public: virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item) { - cMap * Map = a_World->GetMapData(a_Item.m_ItemDamage); + cMap * Map = a_World->GetMapManager().GetMapData(a_Item.m_ItemDamage); if (Map == NULL) { diff --git a/src/Map.cpp b/src/Map.cpp index e89fad8b0..2b8c4c74c 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -344,13 +344,19 @@ void cMap::UpdateDecorators(void) -void cMap::AddPlayer(cPlayer * a_Player, cClientHandle * a_Handle, Int64 a_WorldAge) +void cMap::AddPlayer(cPlayer * a_Player, Int64 a_WorldAge) { + cClientHandle * Handle = a_Player->GetClientHandle(); + if (Handle == NULL) + { + return; + } + cMapClient MapClient; MapClient.m_LastUpdate = a_WorldAge; MapClient.m_SendInfo = true; - MapClient.m_Handle = a_Handle; + MapClient.m_Handle = Handle; m_Clients.push_back(MapClient); @@ -470,7 +476,7 @@ void cMap::UpdateClient(cPlayer * a_Player) } // New player, construct a new client state - AddPlayer(a_Player, Handle, WorldAge); + AddPlayer(a_Player, WorldAge); } diff --git a/src/Map.h b/src/Map.h index a6df7e5f2..a313d5431 100644 --- a/src/Map.h +++ b/src/Map.h @@ -226,7 +226,7 @@ private: bool UpdatePixel(unsigned int a_X, unsigned int a_Z); /** Add a new map client. */ - void AddPlayer(cPlayer * a_Player, cClientHandle * a_Handle, Int64 a_WorldAge); + void AddPlayer(cPlayer * a_Player, Int64 a_WorldAge); /** Remove inactive or invalid clients. */ void RemoveInactiveClients(Int64 a_WorldAge); diff --git a/src/World.cpp b/src/World.cpp index 01fdae697..4870e7d6e 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -233,7 +233,6 @@ void cWorld::cTickThread::Execute(void) // cWorld: cWorld::cWorld(const AString & a_WorldName) : - cMapManager(this), m_WorldName(a_WorldName), m_IniFileName(m_WorldName + "/world.ini"), m_StorageSchema("Default"), @@ -254,6 +253,7 @@ cWorld::cWorld(const AString & a_WorldName) : m_bCommandBlocksEnabled(false), m_bUseChatPrefixes(true), m_Scoreboard(this), + m_MapManager(this), m_GeneratorCallbacks(*this), m_TickThread(*this) { @@ -265,7 +265,7 @@ cWorld::cWorld(const AString & a_WorldName) : cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard); Serializer.Load(); - LoadMapData(); + m_MapManager.LoadMapData(); } @@ -289,7 +289,7 @@ cWorld::~cWorld() cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard); Serializer.Save(); - SaveMapData(); + m_MapManager.SaveMapData(); delete m_ChunkMap; } diff --git a/src/World.h b/src/World.h index f05ea9b2a..4b74f7aba 100644 --- a/src/World.h +++ b/src/World.h @@ -71,8 +71,7 @@ typedef cItemCallback cMobHeadBlockCallback; class cWorld : public cForEachChunkProvider, public cWorldInterface, - public cBroadcastInterface, - public cMapManager + public cBroadcastInterface { public: @@ -582,9 +581,12 @@ public: /** Returns the name of the world.ini file used by this world */ const AString & GetIniFileName(void) const {return m_IniFileName; } - /** Returns the associated scoreboard instance */ + /** Returns the associated scoreboard instance. */ cScoreboard & GetScoreBoard(void) { return m_Scoreboard; } + /** Returns the associated map manager instance. */ + cMapManager & GetMapManager(void) { return m_MapManager; } + bool AreCommandBlocksEnabled(void) const { return m_bCommandBlocksEnabled; } void SetCommandBlocksEnabled(bool a_Flag) { m_bCommandBlocksEnabled = a_Flag; } @@ -850,6 +852,7 @@ private: cChunkGenerator m_Generator; cScoreboard m_Scoreboard; + cMapManager m_MapManager; /** The callbacks that the ChunkGenerator uses to store new chunks and interface to plugins */ cChunkGeneratorCallbacks m_GeneratorCallbacks; diff --git a/src/WorldStorage/MapSerializer.h b/src/WorldStorage/MapSerializer.h index 85fe917f5..eb7678a08 100644 --- a/src/WorldStorage/MapSerializer.h +++ b/src/WorldStorage/MapSerializer.h @@ -51,7 +51,11 @@ private: -/** Utility class used to serialize item ID counts. */ +/** Utility class used to serialize item ID counts. + * + * In order to perform bounds checking (while loading), + * the last registered ID of each item is serialized to an NBT file. + */ class cIDCountSerializer { public: -- cgit v1.2.3 From ea84f8cf89b36b97ae410dcd4fe65d309884cad1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 23 Feb 2014 14:08:05 +0100 Subject: Added cBlockArea::GetVolume, exported to Lua API. --- src/BlockArea.h | 57 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/BlockArea.h b/src/BlockArea.h index b4a161f32..5ef814d0e 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -24,7 +24,7 @@ class cBlockArea public: - /// What data is to be queried (bit-mask) + /** What data is to be queried (bit-mask) */ enum { baTypes = 1, @@ -44,7 +44,7 @@ public: cBlockArea(void); ~cBlockArea(); - /// Clears the data stored to reclaim memory + /** Clears the data stored to reclaim memory */ void Clear(void); /** Creates a new area of the specified size and contents. @@ -53,31 +53,31 @@ public: */ void Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes = baTypes | baMetas); - /// Resets the origin. No other changes are made, contents are untouched. + /** Resets the origin. No other changes are made, contents are untouched. */ void SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ); - /// Reads an area of blocks specified. Returns true if successful. All coords are inclusive. + /** Reads an area of blocks specified. Returns true if successful. All coords are inclusive. */ bool Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes = baTypes | baMetas); // TODO: Write() is not too good an interface: if it fails, there's no way to repeat only for the parts that didn't write // A better way may be to return a list of cBlockAreas for each part that didn't succeed writing, so that the caller may try again - /// Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all + /** Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all */ bool Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes = baTypes | baMetas); - /// Copies this object's contents into the specified BlockArea. + /** Copies this object's contents into the specified BlockArea. */ void CopyTo(cBlockArea & a_Into) const; - /// Copies the contents from the specified BlockArea into this object. + /** Copies the contents from the specified BlockArea into this object. */ void CopyFrom(const cBlockArea & a_From); - /// For testing purposes only, dumps the area into a file. + /** For testing purposes only, dumps the area into a file. */ void DumpToRawFile(const AString & a_FileName); - /// Crops the internal contents by the specified amount of blocks from each border. + /** Crops the internal contents by the specified amount of blocks from each border. */ void Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ); - /// Expands the internal contents by the specified amount of blocks from each border + /** Expands the internal contents by the specified amount of blocks from each border */ void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ); /** Merges another block area into this one, using the specified block combinating strategy @@ -117,49 +117,49 @@ public: */ void Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy); - /// Fills the entire block area with the specified data + /** Fills the entire block area with the specified data */ void Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f); - /// Fills a cuboid inside the block area with the specified data + /** Fills a cuboid inside the block area with the specified data */ void FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f ); - /// Draws a line from between two points with the specified data + /** Draws a line from between two points with the specified data */ void RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int a_RelY2, int a_RelZ2, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f ); - /// Rotates the entire area counter-clockwise around the Y axis + /** Rotates the entire area counter-clockwise around the Y axis */ void RotateCCW(void); - /// Rotates the entire area clockwise around the Y axis + /** Rotates the entire area clockwise around the Y axis */ void RotateCW(void); - /// Mirrors the entire area around the XY plane + /** Mirrors the entire area around the XY plane */ void MirrorXY(void); - /// Mirrors the entire area around the XZ plane + /** Mirrors the entire area around the XZ plane */ void MirrorXZ(void); - /// Mirrors the entire area around the YZ plane + /** Mirrors the entire area around the YZ plane */ void MirrorYZ(void); - /// Rotates the entire area counter-clockwise around the Y axis, doesn't use blockhandlers for block meta + /** Rotates the entire area counter-clockwise around the Y axis, doesn't use blockhandlers for block meta */ void RotateCCWNoMeta(void); - /// Rotates the entire area clockwise around the Y axis, doesn't use blockhandlers for block meta + /** Rotates the entire area clockwise around the Y axis, doesn't use blockhandlers for block meta */ void RotateCWNoMeta(void); - /// Mirrors the entire area around the XY plane, doesn't use blockhandlers for block meta + /** Mirrors the entire area around the XY plane, doesn't use blockhandlers for block meta */ void MirrorXYNoMeta(void); - /// Mirrors the entire area around the XZ plane, doesn't use blockhandlers for block meta + /** Mirrors the entire area around the XZ plane, doesn't use blockhandlers for block meta */ void MirrorXZNoMeta(void); - /// Mirrors the entire area around the YZ plane, doesn't use blockhandlers for block meta + /** Mirrors the entire area around the YZ plane, doesn't use blockhandlers for block meta */ void MirrorYZNoMeta(void); // Setters: @@ -197,11 +197,14 @@ public: int GetSizeY(void) const { return m_SizeY; } int GetSizeZ(void) const { return m_SizeZ; } + /** Returns the volume of the area, as number of blocks */ + int GetVolume(void) const { return m_SizeX * m_SizeY * m_SizeZ; } + int GetOriginX(void) const { return m_OriginX; } int GetOriginY(void) const { return m_OriginY; } int GetOriginZ(void) const { return m_OriginZ; } - /// Returns the datatypes that are stored in the object (bitmask of baXXX values) + /** Returns the datatypes that are stored in the object (bitmask of baXXX values) */ int GetDataTypes(void) const; bool HasBlockTypes (void) const { return (m_BlockTypes != NULL); } @@ -212,7 +215,7 @@ public: // tolua_end // Clients can use these for faster access to all blocktypes. Be careful though! - /// Returns the internal pointer to the block types + /** Returns the internal pointer to the block types */ BLOCKTYPE * GetBlockTypes (void) const { return m_BlockTypes; } NIBBLETYPE * GetBlockMetas (void) const { return m_BlockMetas; } // NOTE: one byte per block! NIBBLETYPE * GetBlockLight (void) const { return m_BlockLight; } // NOTE: one byte per block! @@ -263,7 +266,7 @@ protected: NIBBLETYPE * m_BlockLight; // Each light value is stored as a separate byte for faster access NIBBLETYPE * m_BlockSkyLight; // Each light value is stored as a separate byte for faster access - /// Clears the data stored and prepares a fresh new block area with the specified dimensions + /** Clears the data stored and prepares a fresh new block area with the specified dimensions */ bool SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes); // Basic Setters: @@ -282,7 +285,7 @@ protected: void ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ); void ExpandNibbles (NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ); - /// Sets the specified datatypes at the specified location. + /** Sets the specified datatypes at the specified location. */ void RelSetData( int a_RelX, int a_RelY, int a_RelZ, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, -- cgit v1.2.3 From 6da013c538c874370fb946af7a8957b7c5be775b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 23 Feb 2014 14:28:03 +0100 Subject: Documented cBlockArea:GetOrigin(), :GetSize() and :GetVolume(). --- MCServer/Plugins/APIDump/APIDesc.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index a2f741a01..516aa2e61 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -111,6 +111,7 @@ g_APIDesc = GetBlockType = { Params = "BlockX, BlockY, BlockZ", Return = "BLOCKTYPE", Notes = "Returns the block type at the specified absolute coords" }, GetBlockTypeMeta = { Params = "BlockX, BlockY, BlockZ", Return = "BLOCKTYPE, NIBBLETYPE", Notes = "Returns the block type and meta at the specified absolute coords" }, GetDataTypes = { Params = "", Return = "number", Notes = "Returns the mask of datatypes that the objectis currently holding" }, + GetOrigin = { Params = "", Return = "OriginX, OriginY, OriginZ", Notes = "Returns the origin coords of where the area was read from." }, GetOriginX = { Params = "", Return = "number", Notes = "Returns the origin x-coord" }, GetOriginY = { Params = "", Return = "number", Notes = "Returns the origin y-coord" }, GetOriginZ = { Params = "", Return = "number", Notes = "Returns the origin z-coord" }, @@ -119,9 +120,11 @@ g_APIDesc = GetRelBlockSkyLight = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "NIBBLETYPE", Notes = "Returns the skylight at the specified relative coords" }, GetRelBlockType = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "BLOCKTYPE", Notes = "Returns the block type at the specified relative coords" }, GetRelBlockTypeMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "BLOCKTYPE, NIBBLETYPE", Notes = "Returns the block type and meta at the specified relative coords" }, + GetSize = { Params = "", Return = "SizeX, SizeY, SizeZ", Notes = "Returns the size of the area in all 3 axes." }, GetSizeX = { Params = "", Return = "number", Notes = "Returns the size of the held data in the x-axis" }, GetSizeY = { Params = "", Return = "number", Notes = "Returns the size of the held data in the y-axis" }, GetSizeZ = { Params = "", Return = "number", Notes = "Returns the size of the held data in the z-axis" }, + GetVolume = { Params = "", Return = "number", Notes = "Returns the volume of the area - the total number of blocks stored within." }, HasBlockLights = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include blocklight" }, HasBlockMetas = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include block metas" }, HasBlockSkyLights = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include skylight" }, -- cgit v1.2.3 From b432f57608cc261824d59f2570ddea1c0f1f6791 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 23 Feb 2014 14:57:59 +0100 Subject: Updated CONTRIBUTING file with formatting and essential rules. --- CONTRIBUTING.md | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 83173a6af..a0a332f30 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,35 +1,39 @@ Code Stuff ---------- - * Because some devs use MSVC2008, we use C++03 - no C++11 magic for now at least :( + * We use C++03 * Use the provided wrappers for OS stuff: - - Threading is done by inheriting from cIsThread, thread synchronization through cCriticalSection, cSemaphore and cEvent, file access and filesystem operations through the cFile class, high-precision timers through cTimer, high-precision sleep through cSleep + - Threading is done by inheriting from `cIsThread`, thread synchronization through `cCriticalSection`, `cSemaphore` and `cEvent`, file access and filesystem operations through the `cFile` class, high-precision timers through `cTimer`, high-precision sleep through `cSleep` * No magic numbers, use named constants: - - E_ITEM_XXX, E_BLOCK_XXX and E_META_XXX for items and blocks - - E_ENTITY_TYPE_XXX for mob types - - dimNether, dimOverworld and dimEnd for world dimension - - gmSurvival, gmCreative, gmAdventure for game modes - - wSunny, wRain, wThunderstorm for weather - - cChunkDef::Width, cChunkDef::Height for chunk dimensions (C++) + - `E_ITEM_XXX`, `E_BLOCK_XXX` and `E_META_XXX` for items and blocks + - `cEntity::etXXX` for entity types, `cMonster::mtXXX` for mob types + - `dimNether`, `dimOverworld` and `dimEnd` for world dimension + - `gmSurvival`, `gmCreative`, `gmAdventure` for game modes + - `wSunny`, `wRain`, `wThunderstorm` for weather + - `cChunkDef::Width`, `cChunkDef::Height` for chunk dimensions (C++) - etc. - * Instead of checking for specific value, use Is functions, if available: - - cPlayer:IsGameModeCreative() instead of (cPlayer:GetGameMode() == gmCreative) - * Please use tabs for indentation and spaces for alignment. This means that if it's at line start, it's a tab; if it's in the middle of a line, it's a space + * Instead of checking for a specific value, use an `IsXXX` function, if available: + - `cPlayer:IsGameModeCreative()` instead of` (cPlayer:GetGameMode() == gmCreative)` (the player can also inherit the gamemode from the world, which the value-d condition doesn't catch) + * Please use **tabs for indentation and spaces for alignment**. This means that if it's at line start, it's a tab; if it's in the middle of a line, it's a space * Alpha-sort stuff that makes sense alpha-sorting - long lists of similar items etc. * Keep individual functions spaced out by 5 empty lines, this enhances readability and makes navigation in the source file easier. * Add those extra parentheses to conditions, especially in C++ - - "if ((a == 1) && ((b == 2) || (c == 3)))" instead of ambiguous "if (a == 1 && b == 2 || c == 3)" - - This helps prevent mistakes such as "if (a & 1 == 0)" + - `if ((a == 1) && ((b == 2) || (c == 3)))` instead of ambiguous `if (a == 1 && b == 2 || c == 3)` + - This helps prevent mistakes such as `if (a & 1 == 0)` * White space is free, so use it freely - "freely" as in "plentifully", not "arbitrarily" * Each and every control statement deserves its braces. This helps maintainability later on when the file is edited, lines added or removed - the control logic doesn't break so easily. - * Please leave the first line of all source files blank, to get around an IDE bug. - * Also leave the last line of all source files blank (GCC and GIT can complain otherwise) + - The only exception: a `switch` statement with all `case` statements being a single short statement is allowed to use the short brace-less form. + * Add an empty last line in all source files (GCC and GIT can complain otherwise) + * Use doxy-comments for functions in the header file, format as `/** Description */` + * Use spaces after the comment markers: `// Comment` instead of `//Comment` Copyright --------- -Your work should be licensed under the Apache license, and you should add yourself to the CONTRIBUTORS file. +Your work must be licensed at least under the Apache license. -If your work is not licensed under the Apache license, then it must be compatible and marked as such. Note that only plugins may choose a different license; MC-server's internals need to be single-license. +You can add yourself to the CONTRIBUTORS file if you wish. + +**PLUGINS ONLY**: If your plugin is not licensed under the Apache license, then it must be compatible and marked as such. This is only valid for the plugins included within the MCServer source; plugins developed on separate repositories can use whatever license they want. -- cgit v1.2.3 From 1afcc255bfe7153dc397970e0ece41d6d48e63be Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sun, 23 Feb 2014 18:13:49 +0100 Subject: Fixed Formatting, Added DropChance attributes to Monsters --- src/Mobs/Monster.cpp | 26 ++++- src/Mobs/Monster.h | 20 ++++ src/Mobs/Mooshroom.cpp | 49 +++++----- src/Mobs/Skeleton.cpp | 8 +- src/Mobs/Witch.cpp | 4 +- src/Mobs/Zombie.cpp | 1 + src/Mobs/Zombiepigman.cpp | 1 + src/WorldStorage/NBTChunkSerializer.cpp | 8 ++ src/WorldStorage/WSSAnvil.cpp | 163 ++++++++++++++++++++++++++++++++ src/WorldStorage/WSSAnvil.h | 3 + 10 files changed, 248 insertions(+), 35 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index c81f46d6a..23e4219e8 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -81,6 +81,11 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_AttackDamage(1) , m_AttackRange(2) , m_AttackInterval(0) + , m_DropChanceWeapon(0.085) + , m_DropChanceHelmet(0.085) + , m_DropChanceChestplate(0.085) + , m_DropChanceLeggings(0.085) + , m_DropChanceBoots(0.085) , m_SightDistance(25) , m_BurnsInDaylight(false) { @@ -912,22 +917,22 @@ void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) { MTRand r1; - if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + if (r1.randInt() % 200 < ((m_DropChanceHelmet * 200) + (a_LootingLevel * 2))) { if (!GetEquippedHelmet().IsEmpty()) a_Drops.push_back(GetEquippedHelmet()); } - if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + if (r1.randInt() % 200 < ((m_DropChanceChestplate * 200) + (a_LootingLevel * 2))) { if (!GetEquippedChestplate().IsEmpty()) a_Drops.push_back(GetEquippedChestplate()); } - if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + if (r1.randInt() % 200 < ((m_DropChanceLeggings * 200) + (a_LootingLevel * 2))) { if (!GetEquippedLeggings().IsEmpty()) a_Drops.push_back(GetEquippedLeggings()); } - if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + if (r1.randInt() % 200 < ((m_DropChanceBoots * 200) + (a_LootingLevel * 2))) { if (!GetEquippedBoots().IsEmpty()) a_Drops.push_back(GetEquippedBoots()); } @@ -937,6 +942,19 @@ void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) +void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel) +{ + MTRand r1; + if (r1.randInt() % 200 < ((m_DropChanceWeapon * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedWeapon().IsEmpty()) a_Drops.push_back(GetEquippedWeapon()); + } +} + + + + + void cMonster::HandleDaylightBurning(cChunk & a_Chunk) { if (!m_BurnsInDaylight) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 6f7352b52..b75ac444f 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -119,6 +119,17 @@ public: void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; } void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; } + float GetDropChanceWeapon() { return m_DropChanceWeapon; }; + float GetDropChanceHelmet() { return m_DropChanceHelmet; }; + float GetDropChanceChestplate() { return m_DropChanceChestplate; }; + float GetDropChanceLeggings() { return m_DropChanceLeggings; }; + float GetDropChanceBoots() { return m_DropChanceBoots; }; + void SetDropChanceWeapon(float a_DropChanceWeapon) { m_DropChanceWeapon = a_DropChanceWeapon; }; + void SetDropChanceHelmet(float a_DropChanceHelmet) { m_DropChanceHelmet = a_DropChanceHelmet; }; + void SetDropChanceChestplate(float a_DropChanceChestplate) { m_DropChanceChestplate = a_DropChanceChestplate; }; + void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; }; + void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; }; + /// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; } @@ -221,6 +232,12 @@ protected: float m_AttackInterval; int m_SightDistance; + float m_DropChanceWeapon; + float m_DropChanceHelmet; + float m_DropChanceChestplate; + float m_DropChanceLeggings; + float m_DropChanceBoots; + void HandleDaylightBurning(cChunk & a_Chunk); bool m_BurnsInDaylight; @@ -236,6 +253,9 @@ protected: /** Adds armor that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ void AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel); + /** Adds weapon that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + void AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel); + } ; // tolua_export diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 5873ec63f..8e4c52ae6 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -39,34 +39,35 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cMooshroom::OnRightClicked(cPlayer & a_Player) { - if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BUCKET)) + switch (a_Player.GetEquippedItem().m_ItemType) { - if (!a_Player.IsGameModeCreative()) + case E_ITEM_BUCKET: { - a_Player.GetInventory().RemoveOneEquippedItem(); - a_Player.GetInventory().AddItem(E_ITEM_MILK); - } - } - - if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BOWL)) - { - if (!a_Player.IsGameModeCreative()) + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MILK); + } + } break; + case E_ITEM_BOWL: { - a_Player.GetInventory().RemoveOneEquippedItem(); - a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP); - } - } - - if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SHEARS) - { - if (!a_Player.IsGameModeCreative()) + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP); + } + } break; + case E_ITEM_SHEARS: { - a_Player.UseEquippedItem(); - } - - cItems Drops; - Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + if (!a_Player.IsGameModeCreative()) + { + a_Player.UseEquippedItem(); + } + + cItems Drops; + Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + } break; } } diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 661f0712c..47fcdbb26 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -27,19 +27,19 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) } if (IsWither()) { - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_COAL); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_HEAD, 1, 1)); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); - AddRandomArmorDropItem(a_Drops, LootingLevel); } else { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ARROW); - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); - AddRandomArmorDropItem(a_Drops, LootingLevel); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index bdc9e11de..6956f7b7a 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -39,9 +39,7 @@ void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); break; } } - cItems RareDrops; - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); - AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 999cd4a35..f19e096ee 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -35,6 +35,7 @@ void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) RareDrops.Add(cItem(E_ITEM_POTATO)); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index a967d5066..a0142b566 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -31,6 +31,7 @@ void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) RareDrops.Add(cItem(E_ITEM_GOLD)); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 2a1eda523..5bcaf06bd 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -407,6 +407,14 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) } } // switch (payload) + m_Writer.BeginList("DropChances", TAG_Float); + m_Writer.AddFloat("", a_Monster->GetDropChanceWeapon()); + m_Writer.AddFloat("", a_Monster->GetDropChanceHelmet()); + m_Writer.AddFloat("", a_Monster->GetDropChanceChestplate()); + m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings()); + m_Writer.AddFloat("", a_Monster->GetDropChanceBoots()); + m_Writer.EndList(); + m_Writer.BeginCompound(""); AddBasicEntity(a_Monster, EntityClass); switch (a_Monster->GetMobType()) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index d4490c7fe..a5f4e1b25 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1485,6 +1485,11 @@ void cWSSAnvil::LoadBatFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1500,6 +1505,11 @@ void cWSSAnvil::LoadBlazeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1515,6 +1525,11 @@ void cWSSAnvil::LoadCaveSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1530,6 +1545,11 @@ void cWSSAnvil::LoadChickenFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1545,6 +1565,11 @@ void cWSSAnvil::LoadCowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1560,6 +1585,11 @@ void cWSSAnvil::LoadCreeperFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1575,6 +1605,11 @@ void cWSSAnvil::LoadEnderDragonFromNBT(cEntityList & a_Entities, const cParsedNB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1591,6 +1626,11 @@ void cWSSAnvil::LoadEndermanFromNBT(cEntityList & a_Entities, const cParsedNBT & return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -1606,6 +1646,11 @@ void cWSSAnvil::LoadGhastFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -1620,6 +1665,11 @@ void cWSSAnvil::LoadGiantFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1646,6 +1696,11 @@ void cWSSAnvil::LoadHorseFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1661,6 +1716,11 @@ void cWSSAnvil::LoadIronGolemFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1682,6 +1742,11 @@ void cWSSAnvil::LoadMagmaCubeFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1697,6 +1762,11 @@ void cWSSAnvil::LoadMooshroomFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1712,6 +1782,11 @@ void cWSSAnvil::LoadOcelotFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1727,6 +1802,11 @@ void cWSSAnvil::LoadPigFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1748,6 +1828,11 @@ void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1763,6 +1848,11 @@ void cWSSAnvil::LoadSilverfishFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1784,6 +1874,11 @@ void cWSSAnvil::LoadSkeletonFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1805,6 +1900,11 @@ void cWSSAnvil::LoadSlimeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1820,6 +1920,11 @@ void cWSSAnvil::LoadSnowGolemFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1835,6 +1940,11 @@ void cWSSAnvil::LoadSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1850,6 +1960,11 @@ void cWSSAnvil::LoadSquidFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1871,6 +1986,11 @@ void cWSSAnvil::LoadVillagerFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1886,6 +2006,11 @@ void cWSSAnvil::LoadWitchFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1901,6 +2026,11 @@ void cWSSAnvil::LoadWitherFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1916,6 +2046,10 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N { return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner"); if (OwnerIdx > 0) { @@ -1964,6 +2098,11 @@ void cWSSAnvil::LoadZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1980,6 +2119,11 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -2023,6 +2167,25 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N +bool LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx) +{ + float DropChance[5]; + if (!LoadDoublesListFromNBT(DropChance, 5, a_NBT, a_NBT.FindChildByName(a_TagIdx, "DropChance"))) + { + return false; + } + a_Monster.SetDropChanceWeapon(DropChance[0]); + a_Monster.SetDropChanceHelmet(DropChance[1]); + a_Monster.SetDropChanceChestplate(DropChance[2]); + a_Monster.SetDropChanceLeggings(DropChance[3]); + a_Monster.SetDropChanceBoots(DropChance[4]); + return true; +} + + + + + bool cWSSAnvil::LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx) { if (!LoadEntityBaseFromNBT(a_Entity, a_NBT, a_TagIdx)) diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 541371560..6c6444dae 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -194,6 +194,9 @@ protected: /// Loads entity common data from the NBT compound; returns true if successful bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads monster common data from the NBT compound; returns true if successful + bool LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads projectile common data from the NBT compound; returns true if successful bool LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIx); -- cgit v1.2.3 From 72dd48f7e741217077f82d9c8ec7e55618102bd6 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sun, 23 Feb 2014 18:43:47 +0100 Subject: Fixed Compiling Issues --- src/WorldStorage/NBTChunkSerializer.cpp | 15 +++++++-------- src/WorldStorage/WSSAnvil.cpp | 22 ++++++++++++++++++++-- src/WorldStorage/WSSAnvil.h | 4 ++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 5bcaf06bd..b9d92d2df 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -407,16 +407,15 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) } } // switch (payload) - m_Writer.BeginList("DropChances", TAG_Float); - m_Writer.AddFloat("", a_Monster->GetDropChanceWeapon()); - m_Writer.AddFloat("", a_Monster->GetDropChanceHelmet()); - m_Writer.AddFloat("", a_Monster->GetDropChanceChestplate()); - m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings()); - m_Writer.AddFloat("", a_Monster->GetDropChanceBoots()); - m_Writer.EndList(); - m_Writer.BeginCompound(""); AddBasicEntity(a_Monster, EntityClass); + m_Writer.BeginList("DropChances", TAG_Float); + m_Writer.AddFloat("", a_Monster->GetDropChanceWeapon()); + m_Writer.AddFloat("", a_Monster->GetDropChanceHelmet()); + m_Writer.AddFloat("", a_Monster->GetDropChanceChestplate()); + m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings()); + m_Writer.AddFloat("", a_Monster->GetDropChanceBoots()); + m_Writer.EndList(); switch (a_Monster->GetMobType()) { case cMonster::mtBat: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index a5f4e1b25..10c8d1f51 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2167,10 +2167,10 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N -bool LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx) +bool cWSSAnvil::LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx) { float DropChance[5]; - if (!LoadDoublesListFromNBT(DropChance, 5, a_NBT, a_NBT.FindChildByName(a_TagIdx, "DropChance"))) + if (!LoadFloatsListFromNBT(DropChance, 5, a_NBT, a_NBT.FindChildByName(a_TagIdx, "DropChance"))) { return false; } @@ -2228,6 +2228,24 @@ bool cWSSAnvil::LoadDoublesListFromNBT(double * a_Doubles, int a_NumDoubles, con +bool cWSSAnvil::LoadFloatsListFromNBT(float * a_Floats, int a_NumFloats, const cParsedNBT & a_NBT, int a_TagIdx) +{ + if ((a_TagIdx < 0) || (a_NBT.GetType(a_TagIdx) != TAG_List) || (a_NBT.GetChildrenType(a_TagIdx) != TAG_Float)) + { + return false; + } + int idx = 0; + for (int Tag = a_NBT.GetFirstChild(a_TagIdx); (Tag > 0) && (idx < a_NumFloats); Tag = a_NBT.GetNextSibling(Tag), ++idx) + { + a_Floats[idx] = a_NBT.GetFloat(Tag); + } // for Tag - PosTag[] + return (idx == a_NumFloats); // Did we read enough doubles? +} + + + + + bool cWSSAnvil::GetBlockEntityNBTPos(const cParsedNBT & a_NBT, int a_TagIdx, int & a_X, int & a_Y, int & a_Z) { int x = a_NBT.FindChildByName(a_TagIdx, "x"); diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 6c6444dae..4acf3f2a1 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -10,6 +10,7 @@ #include "WorldStorage.h" #include "FastNBT.h" +#include "../Mobs/Monster.h" @@ -203,6 +204,9 @@ protected: /// Loads an array of doubles of the specified length from the specified NBT list tag a_TagIdx; returns true if successful bool LoadDoublesListFromNBT(double * a_Doubles, int a_NumDoubles, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads an array of floats of the specified length from the specified NBT list tag a_TagIdx; returns true if successful + bool LoadFloatsListFromNBT(float * a_Floats, int a_NumFloats, const cParsedNBT & a_NBT, int a_TagIdx); + /// Helper function for extracting the X, Y, and Z int subtags of a NBT compound; returns true if successful bool GetBlockEntityNBTPos(const cParsedNBT & a_NBT, int a_TagIdx, int & a_X, int & a_Y, int & a_Z); -- cgit v1.2.3 From 847aef898de868dd88354adfb763e48fad22d6b2 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sun, 23 Feb 2014 19:12:34 +0100 Subject: Fixed Formatting, Added DropChances and CanPickUpLoot attributes to Monsters --- src/Mobs/Monster.cpp | 1 + src/Mobs/Monster.h | 23 +++++++++++++---------- src/WorldStorage/NBTChunkSerializer.cpp | 1 + src/WorldStorage/WSSAnvil.cpp | 2 ++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 23e4219e8..4ab485321 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -86,6 +86,7 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_DropChanceChestplate(0.085) , m_DropChanceLeggings(0.085) , m_DropChanceBoots(0.085) + , m_CanPickUpLoot(true) , m_SightDistance(25) , m_BurnsInDaylight(false) { diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index b75ac444f..49d0cf9ef 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -119,16 +119,18 @@ public: void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; } void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; } - float GetDropChanceWeapon() { return m_DropChanceWeapon; }; - float GetDropChanceHelmet() { return m_DropChanceHelmet; }; - float GetDropChanceChestplate() { return m_DropChanceChestplate; }; - float GetDropChanceLeggings() { return m_DropChanceLeggings; }; - float GetDropChanceBoots() { return m_DropChanceBoots; }; - void SetDropChanceWeapon(float a_DropChanceWeapon) { m_DropChanceWeapon = a_DropChanceWeapon; }; - void SetDropChanceHelmet(float a_DropChanceHelmet) { m_DropChanceHelmet = a_DropChanceHelmet; }; - void SetDropChanceChestplate(float a_DropChanceChestplate) { m_DropChanceChestplate = a_DropChanceChestplate; }; - void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; }; - void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; }; + float GetDropChanceWeapon() { return m_DropChanceWeapon; } + float GetDropChanceHelmet() { return m_DropChanceHelmet; } + float GetDropChanceChestplate() { return m_DropChanceChestplate; } + float GetDropChanceLeggings() { return m_DropChanceLeggings; } + float GetDropChanceBoots() { return m_DropChanceBoots; } + bool CanPickUpLoot() { return m_CanPickUpLoot; } + void SetDropChanceWeapon(float a_DropChanceWeapon) { m_DropChanceWeapon = a_DropChanceWeapon; } + void SetDropChanceHelmet(float a_DropChanceHelmet) { m_DropChanceHelmet = a_DropChanceHelmet; } + void SetDropChanceChestplate(float a_DropChanceChestplate) { m_DropChanceChestplate = a_DropChanceChestplate; } + void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; } + void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; } + void SetCanPickUpLoot(bool a_CanPickUpLoot) { m_CanPickUpLoot = a_CanPickUpLoot; } /// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; } @@ -237,6 +239,7 @@ protected: float m_DropChanceChestplate; float m_DropChanceLeggings; float m_DropChanceBoots; + bool m_CanPickUpLoot; void HandleDaylightBurning(cChunk & a_Chunk); bool m_BurnsInDaylight; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index b9d92d2df..c1c659b36 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -416,6 +416,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings()); m_Writer.AddFloat("", a_Monster->GetDropChanceBoots()); m_Writer.EndList(); + m_Writer.AddByte("CanPickUpLoot", (char)a_Monster->CanPickUpLoot()); switch (a_Monster->GetMobType()) { case cMonster::mtBat: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 10c8d1f51..05332d23d 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2179,6 +2179,8 @@ bool cWSSAnvil::LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_Monster.SetDropChanceChestplate(DropChance[2]); a_Monster.SetDropChanceLeggings(DropChance[3]); a_Monster.SetDropChanceBoots(DropChance[4]); + bool CanPickUpLoot = (a_NBT.GetByte(a_NBT.FindChildByName(a_TagIdx, "CanPickUpLoot")) == 1); + a_Monster.SetCanPickUpLoot(CanPickUpLoot); return true; } -- cgit v1.2.3 From 2f59517023765e8f5d5555adacafd146729ab071 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sun, 23 Feb 2014 19:35:56 +0100 Subject: Fixed Formatting, Added DropChances and CanPickUpLoot attributes to Monsters --- src/BlockID.h | 32 ------ src/Enchantments.h | 1 - src/Mobs/Blaze.cpp | 4 +- src/Mobs/Cavespider.cpp | 8 +- src/Mobs/Chicken.cpp | 6 +- src/Mobs/Cow.cpp | 6 +- src/Mobs/Creeper.cpp | 6 +- src/Mobs/Enderman.cpp | 6 +- src/Mobs/Ghast.cpp | 6 +- src/Mobs/Horse.cpp | 6 +- src/Mobs/Monster.cpp | 49 ++++++++- src/Mobs/Monster.h | 32 ++++++ src/Mobs/Mooshroom.cpp | 45 +++++++- src/Mobs/Mooshroom.h | 1 + src/Mobs/Pig.cpp | 6 +- src/Mobs/Skeleton.cpp | 20 ++-- src/Mobs/Slime.cpp | 6 +- src/Mobs/Spider.cpp | 8 +- src/Mobs/Squid.cpp | 6 +- src/Mobs/Witch.cpp | 24 +++-- src/Mobs/Zombie.cpp | 13 +-- src/Mobs/Zombiepigman.cpp | 9 +- src/WorldStorage/NBTChunkSerializer.cpp | 8 ++ src/WorldStorage/WSSAnvil.cpp | 183 ++++++++++++++++++++++++++++++++ src/WorldStorage/WSSAnvil.h | 7 ++ 25 files changed, 417 insertions(+), 81 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index e23a0f82a..740c5fc90 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -392,38 +392,6 @@ enum ENUM_ITEM_ID -// ENCHANTMENT IDS -enum -{ - E_ENCHANTMENT_PROTECTION = 0, - E_ENCHANTMENT_FIRE_PROTECTION = 1, - E_ENCHANTMENT_FEATHER_FALLING = 2, - E_ENCHANTMENT_BLAST_PROTECTION = 3, - E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, - E_ENCHANTMENT_RESPIRATION = 5, - E_ENCHANTMENT_AQUA_AFFINITY = 6, - E_ENCHANTMENT_THORNS = 7, - E_ENCHANTMENT_SHARPNESS = 16, - E_ENCHANTMENT_SMITE = 17, - E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, - E_ENCHANTMENT_KNOCKBACK = 19, - E_ENCHANTMENT_FIREASPECT = 20, - E_ENCHANTMENT_LOOTING = 21, - E_ENCHANTMENT_EFFICIENCY = 32, - E_ENCHANTMENT_SILKTOUCH = 33, - E_ENCHANTMENT_UNBREAKING = 34, - E_ENCHANTMENT_FORTUNE = 35, - E_ENCHANTMENT_POWER = 48, - E_ENCHANTMENT_PUNCH = 49, - E_ENCHANTMENT_FLAME = 50, - E_ENCHANTMENT_INFINITY = 51, - E_ENCHANTMENT_LUCKOFTHESEA = 61, - E_ENCHANTMENT_LURE = 62, -}; - - - - enum { diff --git a/src/Enchantments.h b/src/Enchantments.h index e984df92e..f77b535d8 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -21,7 +21,6 @@ class cParsedNBT; - /** Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a stringspec and read back from such stringspec. The format for the stringspec is "id=lvl;id=lvl;id=lvl...", with an optional semicolon at the end, diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index bd16a36e2..ac42cf40b 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,9 +19,9 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); } } diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index 7274820b7..94e93283d 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -31,9 +31,13 @@ void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index 9388e1097..f7e44238f 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -48,7 +48,11 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk) void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); } diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index cda067fac..9914df6b5 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -21,7 +21,11 @@ cCow::cCow(void) : void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 0ae78eee3..40ee20e44 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -39,7 +39,11 @@ void cCreeper::Tick(float a_Dt, cChunk & a_Chunk) void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); if ((a_Killer != NULL) && (a_Killer->IsProjectile())) diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index 4a5ad25be..becc99a86 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -21,7 +21,11 @@ cEnderman::cEnderman(void) : void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL); } diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index a73ed0944..fe18f5e76 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -18,7 +18,11 @@ cGhast::cGhast(void) : void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); } diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index 3c29e3682..9d130301f 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -140,7 +140,11 @@ void cHorse::OnRightClicked(cPlayer & a_Player) void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); if (m_bIsSaddled) { diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 66629474b..4ab485321 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -81,6 +81,12 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_AttackDamage(1) , m_AttackRange(2) , m_AttackInterval(0) + , m_DropChanceWeapon(0.085) + , m_DropChanceHelmet(0.085) + , m_DropChanceChestplate(0.085) + , m_DropChanceLeggings(0.085) + , m_DropChanceBoots(0.085) + , m_CanPickUpLoot(true) , m_SightDistance(25) , m_BurnsInDaylight(false) { @@ -884,7 +890,7 @@ void cMonster::AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short { MTRand r1; int Count = r1.randInt() % 1000; - if (Count < (a_Chance*10)) + if (Count < (a_Chance * 10)) { a_Drops.push_back(cItem(a_Item, 1, a_ItemHealth)); } @@ -909,6 +915,47 @@ void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a +void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) +{ + MTRand r1; + if (r1.randInt() % 200 < ((m_DropChanceHelmet * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedHelmet().IsEmpty()) a_Drops.push_back(GetEquippedHelmet()); + } + + if (r1.randInt() % 200 < ((m_DropChanceChestplate * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedChestplate().IsEmpty()) a_Drops.push_back(GetEquippedChestplate()); + } + + if (r1.randInt() % 200 < ((m_DropChanceLeggings * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedLeggings().IsEmpty()) a_Drops.push_back(GetEquippedLeggings()); + } + + if (r1.randInt() % 200 < ((m_DropChanceBoots * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedBoots().IsEmpty()) a_Drops.push_back(GetEquippedBoots()); + } +} + + + + + +void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel) +{ + MTRand r1; + if (r1.randInt() % 200 < ((m_DropChanceWeapon * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedWeapon().IsEmpty()) a_Drops.push_back(GetEquippedWeapon()); + } +} + + + + + void cMonster::HandleDaylightBurning(cChunk & a_Chunk) { if (!m_BurnsInDaylight) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 909504213..49d0cf9ef 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -5,6 +5,7 @@ #include "../Defines.h" #include "../BlockID.h" #include "../Item.h" +#include "../Enchantments.h" @@ -118,6 +119,19 @@ public: void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; } void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; } + float GetDropChanceWeapon() { return m_DropChanceWeapon; } + float GetDropChanceHelmet() { return m_DropChanceHelmet; } + float GetDropChanceChestplate() { return m_DropChanceChestplate; } + float GetDropChanceLeggings() { return m_DropChanceLeggings; } + float GetDropChanceBoots() { return m_DropChanceBoots; } + bool CanPickUpLoot() { return m_CanPickUpLoot; } + void SetDropChanceWeapon(float a_DropChanceWeapon) { m_DropChanceWeapon = a_DropChanceWeapon; } + void SetDropChanceHelmet(float a_DropChanceHelmet) { m_DropChanceHelmet = a_DropChanceHelmet; } + void SetDropChanceChestplate(float a_DropChanceChestplate) { m_DropChanceChestplate = a_DropChanceChestplate; } + void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; } + void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; } + void SetCanPickUpLoot(bool a_CanPickUpLoot) { m_CanPickUpLoot = a_CanPickUpLoot; } + /// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; } @@ -220,13 +234,31 @@ protected: float m_AttackInterval; int m_SightDistance; + float m_DropChanceWeapon; + float m_DropChanceHelmet; + float m_DropChanceChestplate; + float m_DropChanceLeggings; + float m_DropChanceBoots; + bool m_CanPickUpLoot; + void HandleDaylightBurning(cChunk & a_Chunk); bool m_BurnsInDaylight; + /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/ void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); + + /** Adds a item a_Item with the chance of a_Chance (in percent) to itemdrops a_Drops*/ void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); + + /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/ void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); + /** Adds armor that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + void AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel); + + /** Adds weapon that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + void AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel); + } ; // tolua_export diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 17995ce91..8e4c52ae6 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -2,11 +2,12 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Mooshroom.h" +#include "../Entities/Player.h" + -// TODO: Milk Cow @@ -23,10 +24,50 @@ cMooshroom::cMooshroom(void) : void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } + + +void cMooshroom::OnRightClicked(cPlayer & a_Player) +{ + switch (a_Player.GetEquippedItem().m_ItemType) + { + case E_ITEM_BUCKET: + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MILK); + } + } break; + case E_ITEM_BOWL: + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP); + } + } break; + case E_ITEM_SHEARS: + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.UseEquippedItem(); + } + + cItems Drops; + Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + } break; + } +} + diff --git a/src/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h index c94301098..16f6c8248 100644 --- a/src/Mobs/Mooshroom.h +++ b/src/Mobs/Mooshroom.h @@ -18,6 +18,7 @@ public: CLASS_PROTODEF(cMooshroom); virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + virtual void OnRightClicked(cPlayer & a_Player) override; virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } } ; diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index e4e46dfec..e862f5aaa 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -21,7 +21,11 @@ cPig::cPig(void) : void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); if (m_bIsSaddled) { diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 622cb5ceb..47fcdbb26 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -20,28 +20,26 @@ cSkeleton::cSkeleton(bool IsWither) : void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } if (IsWither()) { - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_COAL); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_HEAD, 1, 1)); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); } else { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ARROW); - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); - cItems RareDrops; - if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); - if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); - if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); - if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); - AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 7941e2452..52a52bb39 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -20,7 +20,11 @@ cSlime::cSlime(int a_Size) : void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } if (GetSize() == 1) { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL); diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index aeb6e1bcc..8b978ff6b 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -18,9 +18,13 @@ cSpider::cSpider(void) : void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 4f2abf574..ba9171b39 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -21,7 +21,11 @@ cSquid::cSquid(void) : void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // Drops 0-3 Ink Sacs - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index 6cb103645..6956f7b7a 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -18,7 +18,11 @@ cWitch::cWitch(void) : void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } MTRand r1; int DropTypeCount = (r1.randInt() % 3) + 1; for (int i = 0; i < DropTypeCount; i++) @@ -26,18 +30,16 @@ void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) int DropType = r1.randInt() % 7; switch (DropType) { - case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); - case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); - case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); - case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); - case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); - case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); - case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); + case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); break; + case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); break; + case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); break; + case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); break; + case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); break; + case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); break; + case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); break; } } - cItems RareDrops; - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); - AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 6a007683b..f19e096ee 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -23,18 +23,19 @@ cZombie::cZombie(bool a_IsVillagerZombie) : void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_IRON)); RareDrops.Add(cItem(E_ITEM_CARROT)); RareDrops.Add(cItem(E_ITEM_POTATO)); - if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); - if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); - if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); - if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index ca222f9fe..a0142b566 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -19,14 +19,19 @@ cZombiePigman::cZombiePigman(void) : void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_GOLD)); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 2a1eda523..c1c659b36 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -409,6 +409,14 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) m_Writer.BeginCompound(""); AddBasicEntity(a_Monster, EntityClass); + m_Writer.BeginList("DropChances", TAG_Float); + m_Writer.AddFloat("", a_Monster->GetDropChanceWeapon()); + m_Writer.AddFloat("", a_Monster->GetDropChanceHelmet()); + m_Writer.AddFloat("", a_Monster->GetDropChanceChestplate()); + m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings()); + m_Writer.AddFloat("", a_Monster->GetDropChanceBoots()); + m_Writer.EndList(); + m_Writer.AddByte("CanPickUpLoot", (char)a_Monster->CanPickUpLoot()); switch (a_Monster->GetMobType()) { case cMonster::mtBat: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index d4490c7fe..05332d23d 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1485,6 +1485,11 @@ void cWSSAnvil::LoadBatFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1500,6 +1505,11 @@ void cWSSAnvil::LoadBlazeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1515,6 +1525,11 @@ void cWSSAnvil::LoadCaveSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1530,6 +1545,11 @@ void cWSSAnvil::LoadChickenFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1545,6 +1565,11 @@ void cWSSAnvil::LoadCowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1560,6 +1585,11 @@ void cWSSAnvil::LoadCreeperFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1575,6 +1605,11 @@ void cWSSAnvil::LoadEnderDragonFromNBT(cEntityList & a_Entities, const cParsedNB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1591,6 +1626,11 @@ void cWSSAnvil::LoadEndermanFromNBT(cEntityList & a_Entities, const cParsedNBT & return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -1606,6 +1646,11 @@ void cWSSAnvil::LoadGhastFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -1620,6 +1665,11 @@ void cWSSAnvil::LoadGiantFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1646,6 +1696,11 @@ void cWSSAnvil::LoadHorseFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1661,6 +1716,11 @@ void cWSSAnvil::LoadIronGolemFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1682,6 +1742,11 @@ void cWSSAnvil::LoadMagmaCubeFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1697,6 +1762,11 @@ void cWSSAnvil::LoadMooshroomFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1712,6 +1782,11 @@ void cWSSAnvil::LoadOcelotFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1727,6 +1802,11 @@ void cWSSAnvil::LoadPigFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1748,6 +1828,11 @@ void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1763,6 +1848,11 @@ void cWSSAnvil::LoadSilverfishFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1784,6 +1874,11 @@ void cWSSAnvil::LoadSkeletonFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1805,6 +1900,11 @@ void cWSSAnvil::LoadSlimeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1820,6 +1920,11 @@ void cWSSAnvil::LoadSnowGolemFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1835,6 +1940,11 @@ void cWSSAnvil::LoadSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1850,6 +1960,11 @@ void cWSSAnvil::LoadSquidFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1871,6 +1986,11 @@ void cWSSAnvil::LoadVillagerFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1886,6 +2006,11 @@ void cWSSAnvil::LoadWitchFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1901,6 +2026,11 @@ void cWSSAnvil::LoadWitherFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1916,6 +2046,10 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N { return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner"); if (OwnerIdx > 0) { @@ -1964,6 +2098,11 @@ void cWSSAnvil::LoadZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1980,6 +2119,11 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -2023,6 +2167,27 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N +bool cWSSAnvil::LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx) +{ + float DropChance[5]; + if (!LoadFloatsListFromNBT(DropChance, 5, a_NBT, a_NBT.FindChildByName(a_TagIdx, "DropChance"))) + { + return false; + } + a_Monster.SetDropChanceWeapon(DropChance[0]); + a_Monster.SetDropChanceHelmet(DropChance[1]); + a_Monster.SetDropChanceChestplate(DropChance[2]); + a_Monster.SetDropChanceLeggings(DropChance[3]); + a_Monster.SetDropChanceBoots(DropChance[4]); + bool CanPickUpLoot = (a_NBT.GetByte(a_NBT.FindChildByName(a_TagIdx, "CanPickUpLoot")) == 1); + a_Monster.SetCanPickUpLoot(CanPickUpLoot); + return true; +} + + + + + bool cWSSAnvil::LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx) { if (!LoadEntityBaseFromNBT(a_Entity, a_NBT, a_TagIdx)) @@ -2065,6 +2230,24 @@ bool cWSSAnvil::LoadDoublesListFromNBT(double * a_Doubles, int a_NumDoubles, con +bool cWSSAnvil::LoadFloatsListFromNBT(float * a_Floats, int a_NumFloats, const cParsedNBT & a_NBT, int a_TagIdx) +{ + if ((a_TagIdx < 0) || (a_NBT.GetType(a_TagIdx) != TAG_List) || (a_NBT.GetChildrenType(a_TagIdx) != TAG_Float)) + { + return false; + } + int idx = 0; + for (int Tag = a_NBT.GetFirstChild(a_TagIdx); (Tag > 0) && (idx < a_NumFloats); Tag = a_NBT.GetNextSibling(Tag), ++idx) + { + a_Floats[idx] = a_NBT.GetFloat(Tag); + } // for Tag - PosTag[] + return (idx == a_NumFloats); // Did we read enough doubles? +} + + + + + bool cWSSAnvil::GetBlockEntityNBTPos(const cParsedNBT & a_NBT, int a_TagIdx, int & a_X, int & a_Y, int & a_Z) { int x = a_NBT.FindChildByName(a_TagIdx, "x"); diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 541371560..4acf3f2a1 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -10,6 +10,7 @@ #include "WorldStorage.h" #include "FastNBT.h" +#include "../Mobs/Monster.h" @@ -194,12 +195,18 @@ protected: /// Loads entity common data from the NBT compound; returns true if successful bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads monster common data from the NBT compound; returns true if successful + bool LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads projectile common data from the NBT compound; returns true if successful bool LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIx); /// Loads an array of doubles of the specified length from the specified NBT list tag a_TagIdx; returns true if successful bool LoadDoublesListFromNBT(double * a_Doubles, int a_NumDoubles, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads an array of floats of the specified length from the specified NBT list tag a_TagIdx; returns true if successful + bool LoadFloatsListFromNBT(float * a_Floats, int a_NumFloats, const cParsedNBT & a_NBT, int a_TagIdx); + /// Helper function for extracting the X, Y, and Z int subtags of a NBT compound; returns true if successful bool GetBlockEntityNBTPos(const cParsedNBT & a_NBT, int a_TagIdx, int & a_X, int & a_Y, int & a_Z); -- cgit v1.2.3 From ab2eba17ec36e5d906d0a45e33b8c7d59e19d4e2 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 17 Feb 2014 20:14:08 +0100 Subject: Add Skulls/Heads --- src/BlockEntities/BlockEntity.cpp | 2 + src/BlockEntities/SkullEntity.cpp | 110 ++++++++++++++++++++++++++++++++ src/BlockEntities/SkullEntity.h | 79 +++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/Chunk.cpp | 2 + src/Defines.h | 37 +++++++++++ src/Items/ItemHandler.cpp | 2 + src/Items/ItemSkull.h | 43 +++++++++++++ src/Protocol/Protocol17x.cpp | 14 ++++ src/WorldStorage/NBTChunkSerializer.cpp | 26 ++++++-- src/WorldStorage/NBTChunkSerializer.h | 2 + src/WorldStorage/WSSAnvil.cpp | 40 ++++++++++++ src/WorldStorage/WSSAnvil.h | 1 + 13 files changed, 354 insertions(+), 5 deletions(-) create mode 100644 src/BlockEntities/SkullEntity.cpp create mode 100644 src/BlockEntities/SkullEntity.h create mode 100644 src/Items/ItemSkull.h diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 97b5c1a66..441f54a26 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -15,6 +15,7 @@ #include "JukeboxEntity.h" #include "NoteEntity.h" #include "SignEntity.h" +#include "SkullEntity.h" @@ -31,6 +32,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/SkullEntity.cpp b/src/BlockEntities/SkullEntity.cpp new file mode 100644 index 000000000..3f3bc00ed --- /dev/null +++ b/src/BlockEntities/SkullEntity.cpp @@ -0,0 +1,110 @@ + +// SkullEntity.cpp + +// Implements the cSkullEntity class representing a single skull/head in the world + +#include "Globals.h" +#include "json/json.h" +#include "SkullEntity.h" +#include "../Entities/Player.h" + + + + + +cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World) : + super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), + //m_SkullType(static_cast(a_BlockMeta)), + m_Owner("") +{ + +} + + + + + +void cSkullEntity::UsedBy(cPlayer * a_Player) +{ + UNUSED(a_Player); +} + + + + + +void cSkullEntity::SetSkullType(const eSkullType & a_SkullType) +{ + if ((!m_Owner.empty()) && (a_SkullType != SKULL_TYPE_PLAYER)) + { + m_Owner = ""; + } + m_SkullType = a_SkullType; +} + + + + + +void cSkullEntity::SetRotation(eSkullRotation a_Rotation) +{ + m_Rotation = a_Rotation; +} + + + + + +void cSkullEntity::SetOwner(const AString & a_Owner) +{ + if ((a_Owner.length() > 16) || (m_SkullType != SKULL_TYPE_PLAYER)) + { + return; + } + m_Owner = a_Owner; +} + + + + + +void cSkullEntity::SendTo(cClientHandle & a_Client) +{ + a_Client.SendUpdateBlockEntity(*this); +} + + + + + +bool cSkullEntity::LoadFromJson(const Json::Value & a_Value) +{ + m_PosX = a_Value.get("x", 0).asInt(); + m_PosY = a_Value.get("y", 0).asInt(); + m_PosZ = a_Value.get("z", 0).asInt(); + + m_SkullType = static_cast(a_Value.get("SkullType", 0).asInt()); + m_Rotation = static_cast(a_Value.get("Rotation", 0).asInt()); + m_Owner = a_Value.get("Owner", "").asString(); + + return true; +} + + + + + +void cSkullEntity::SaveToJson(Json::Value & a_Value) +{ + a_Value["x"] = m_PosX; + a_Value["y"] = m_PosY; + a_Value["z"] = m_PosZ; + + a_Value["SkullType"] = m_SkullType; + a_Value["Rotation"] = m_Rotation; + a_Value["Owner"] = m_Owner; +} + + + + diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h new file mode 100644 index 000000000..6f47c7d30 --- /dev/null +++ b/src/BlockEntities/SkullEntity.h @@ -0,0 +1,79 @@ +// SkullEntity.h + +// Declares the cSkullEntity class representing a single skull/head in the world + + + + + +#pragma once + +#include "BlockEntity.h" + + + + + +namespace Json +{ + class Value; +} + + + + + +// tolua_begin + +class cSkullEntity : + public cBlockEntity +{ + typedef cBlockEntity super; + +public: + + // tolua_end + + /// Creates a new skull entity at the specified block coords. a_World may be NULL + cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World); + + bool LoadFromJson( const Json::Value& a_Value ); + virtual void SaveToJson(Json::Value& a_Value ) override; + + // tolua_begin + + /// Set the Skull Type + void SetSkullType(const eSkullType & a_SkullType); + + /// Set the Rotation + void SetRotation(eSkullRotation a_Rotation); + + // Set the Player Name for Player Skulls + void SetOwner(const AString & a_Owner); + + /// Get the Skull Type + eSkullType GetSkullType(void) const { return m_SkullType; } + + /// Get the Rotation + eSkullRotation GetRotation(void) const { return m_Rotation; } + + /// Get the setted Player Name + AString GetOwner(void) const { return m_Owner; } + + // tolua_end + + virtual void UsedBy(cPlayer * a_Player) override; + virtual void SendTo(cClientHandle & a_Client) override; + + static const char * GetClassStatic(void) { return "cSkullEntity"; } + +private: + + eSkullType m_SkullType; + eSkullRotation m_Rotation; + AString m_Owner; +} ; // tolua_export + + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 16bdad14e..13707b6a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,7 @@ if (NOT MSVC) BlockEntities/JukeboxEntity.h BlockEntities/NoteEntity.h BlockEntities/SignEntity.h + BlockEntities/SkullEntity.h BlockID.h BoundingBox.h ChatColor.h diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 0587beb9c..dc683baa5 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1314,6 +1314,7 @@ void cChunk::CreateBlockEntities(void) case E_BLOCK_HOPPER: case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: + case E_BLOCK_HEAD: case E_BLOCK_NOTE_BLOCK: case E_BLOCK_JUKEBOX: { @@ -1442,6 +1443,7 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, case E_BLOCK_HOPPER: case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: + case E_BLOCK_HEAD: case E_BLOCK_NOTE_BLOCK: case E_BLOCK_JUKEBOX: { diff --git a/src/Defines.h b/src/Defines.h index f33d1ae56..7e22cbdc5 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -174,6 +174,43 @@ enum eWeather +enum eSkullType +{ + SKULL_TYPE_SKELETON = 0, + SKULL_TYPE_WITHER = 1, + SKULL_TYPE_ZOMBIE = 2, + SKULL_TYPE_PLAYER = 3, + SKULL_TYPE_CREEPER = 4, +} ; + + + + + +enum eSkullRotation +{ + SKULL_ROTATION_NORTH = 0, + SKULL_ROTATION_NORTH_NORTH_EAST = 1, + SKULL_ROTATION_NORTH_EAST = 2, + SKULL_ROTATION_EAST_NORTH_EAST = 3, + SKULL_ROTATION_EAST = 4, + SKULL_ROTATION_EAST_SOUTH_EAST = 5, + SKULL_ROTATION_SOUTH_EAST = 6, + SKULL_ROTATION_SOUTH_SOUTH_EAST = 7, + SKULL_ROTATION_SOUTH = 8, + SKULL_ROTATION_SOUTH_SOUTH_WEST = 9, + SKULL_ROTATION_SOUTH_WEST = 10, + SKULL_ROTATION_WEST_SOUTH_WEST = 11, + SKULL_ROTATION_WEST = 12, + SKULL_ROTATION_WEST_NORTH_WEST = 13, + SKULL_ROTATION_NORTH_WEST = 14, + SKULL_ROTATION_NORTH_NORTH_WEST = 15, +} ; + + + + + inline const char * ClickActionToString(eClickAction a_ClickAction) { switch (a_ClickAction) diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 945f84b9c..7a92ad64c 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -37,6 +37,7 @@ #include "ItemShears.h" #include "ItemShovel.h" #include "ItemSign.h" +#include "ItemSkull.h" #include "ItemSpawnEgg.h" #include "ItemSugarcane.h" #include "ItemSword.h" @@ -114,6 +115,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType); case E_ITEM_SIGN: return new cItemSignHandler(a_ItemType); + case E_ITEM_HEAD: return new cItemSkullHandler(a_ItemType); case E_ITEM_SNOWBALL: return new cItemSnowballHandler(); case E_ITEM_SPAWN_EGG: return new cItemSpawnEggHandler(a_ItemType); case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemType); diff --git a/src/Items/ItemSkull.h b/src/Items/ItemSkull.h new file mode 100644 index 000000000..f511c8c4a --- /dev/null +++ b/src/Items/ItemSkull.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemSkullHandler : + public cItemHandler +{ +public: + cItemSkullHandler(int a_ItemType) : + cItemHandler(a_ItemType) + { + } + + + virtual bool IsPlaceable(void) override + { + return true; + } + + + virtual bool GetPlacementBlockTypeMeta( + cWorld * a_World, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = E_BLOCK_HEAD; + a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); + + return true; + } +} ; + + + + diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 0c569c07c..213e6a1f8 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -28,6 +28,7 @@ Implements the 1.7.x protocol classes: #include "../Mobs/IncludeAllMonsters.h" #include "../UI/Window.h" #include "../BlockEntities/CommandBlockEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "../CompositeChat.h" @@ -1058,6 +1059,7 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text + case E_BLOCK_HEAD: Action = 4; break; // Update Skull entity default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break; } Pkt.WriteByte(Action); @@ -2285,6 +2287,18 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt } break; } + case E_BLOCK_HEAD: + { + cSkullEntity & SkullEntity = (cSkullEntity &)a_BlockEntity; + + Writer.AddInt("x", SkullEntity.GetPosX()); + Writer.AddInt("y", SkullEntity.GetPosY()); + Writer.AddInt("z", SkullEntity.GetPosZ()); + Writer.AddByte("SkullType", SkullEntity.GetSkullType() & 0xFF); + Writer.AddByte("Rot", SkullEntity.GetRotation() & 0xFF); + Writer.AddString("ExtraType", SkullEntity.GetOwner().c_str()); + Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though + } default: break; } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index c7aaa2633..e1a986d04 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -19,6 +19,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "../Entities/Entity.h" #include "../Entities/FallingBlock.h" @@ -248,11 +249,25 @@ void cNBTChunkSerializer::AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock void cNBTChunkSerializer::AddSignEntity(cSignEntity * a_Sign) { m_Writer.BeginCompound(""); - AddBasicTileEntity(a_Sign, "Sign"); - m_Writer.AddString("Text1", a_Sign->GetLine(0)); - m_Writer.AddString("Text2", a_Sign->GetLine(1)); - m_Writer.AddString("Text3", a_Sign->GetLine(2)); - m_Writer.AddString("Text4", a_Sign->GetLine(3)); + AddBasicTileEntity(a_Sign, "Sign"); + m_Writer.AddString("Text1", a_Sign->GetLine(0)); + m_Writer.AddString("Text2", a_Sign->GetLine(1)); + m_Writer.AddString("Text3", a_Sign->GetLine(2)); + m_Writer.AddString("Text4", a_Sign->GetLine(3)); + m_Writer.EndCompound(); +} + + + + + +void cNBTChunkSerializer::AddSkullEntity(cSkullEntity * a_Skull) +{ + m_Writer.BeginCompound(""); + AddBasicTileEntity(a_Skull, "Skull"); + m_Writer.AddByte ("SkullType", a_Skull->GetSkullType() & 0xFF); + m_Writer.AddByte ("Rot", a_Skull->GetRotation() & 0xFF); + m_Writer.AddString("ExtraType", a_Skull->GetOwner()); m_Writer.EndCompound(); } @@ -668,6 +683,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: AddSignEntity ((cSignEntity *) a_Entity); break; + case E_BLOCK_HEAD: AddSkullEntity ((cSkullEntity *) a_Entity); break; case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break; case E_BLOCK_JUKEBOX: AddJukeboxEntity ((cJukeboxEntity *) a_Entity); break; case E_BLOCK_COMMAND_BLOCK: AddCommandBlockEntity((cCommandBlockEntity *) a_Entity); break; diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index 245b68063..fd5601e47 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -29,6 +29,7 @@ class cHopperEntity; class cJukeboxEntity; class cNoteEntity; class cSignEntity; +class cSkullEntity; class cFallingBlock; class cMinecart; class cMinecartWithChest; @@ -93,6 +94,7 @@ protected: void AddJukeboxEntity (cJukeboxEntity * a_Jukebox); void AddNoteEntity (cNoteEntity * a_Note); void AddSignEntity (cSignEntity * a_Sign); + void AddSkullEntity (cSkullEntity * a_Skull); void AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock); // Entities: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index e95813a3c..89a236f07 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -24,6 +24,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "../Mobs/Monster.h" @@ -597,6 +598,10 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con { LoadSignFromNBT(a_BlockEntities, a_NBT, Child); } + else if (strncmp(a_NBT.GetData(sID), "Skull", a_NBT.GetDataLength(sID)) == 0) + { + LoadSkullFromNBT(a_BlockEntities, a_NBT, Child); + } else if (strncmp(a_NBT.GetData(sID), "Trap", a_NBT.GetDataLength(sID)) == 0) { LoadDispenserFromNBT(a_BlockEntities, a_NBT, Child); @@ -927,6 +932,41 @@ void cWSSAnvil::LoadSignFromNBT(cBlockEntityList & a_BlockEntities, const cParse +void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); + int x, y, z; + if (!GetBlockEntityNBTPos(a_NBT, a_TagIdx, x, y, z)) + { + return; + } + std::auto_ptr Skull(new cSkullEntity(E_BLOCK_HEAD, x, y, z, m_World)); + + int currentLine = a_NBT.FindChildByName(a_TagIdx, "SkullType"); + if (currentLine >= 0) + { + Skull->SetSkullType(static_cast(a_NBT.GetByte(currentLine))); + } + + currentLine = a_NBT.FindChildByName(a_TagIdx, "Rot"); + if (currentLine >= 0) + { + Skull->SetRotation(static_cast(a_NBT.GetByte(currentLine))); + } + + currentLine = a_NBT.FindChildByName(a_TagIdx, "ExtraType"); + if (currentLine >= 0) + { + Skull->SetOwner(a_NBT.GetString(currentLine)); + } + + a_BlockEntities.push_back(Skull.release()); +} + + + + + void cWSSAnvil::LoadCommandBlockFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) { ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 5093ad083..9c9e17258 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -139,6 +139,7 @@ protected: void LoadJukeboxFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadNoteFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadSignFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadSkullFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadCommandBlockFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength); -- cgit v1.2.3 From 7bc59468832f2eb25f64194ba29da4a821a33866 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 18 Feb 2014 21:40:02 +0100 Subject: Add Heads completely --- src/Bindings/ManualBindings.cpp | 2 ++ src/BlockEntities/BlockEntity.cpp | 2 +- src/BlockEntities/SkullEntity.cpp | 4 +-- src/BlockEntities/SkullEntity.h | 2 +- src/Blocks/BlockHandler.cpp | 2 ++ src/Blocks/BlockSkull.h | 69 +++++++++++++++++++++++++++++++++++++++ src/Chunk.cpp | 33 +++++++++++++++++++ src/Chunk.h | 7 +++- src/ChunkMap.cpp | 18 ++++++++++ src/ChunkMap.h | 5 +++ src/Items/ItemSkull.h | 1 + src/World.cpp | 9 +++++ src/World.h | 5 +++ src/WorldStorage/WSSAnvil.cpp | 2 +- 14 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 src/Blocks/BlockSkull.h diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 2a7631120..70f3fbcf2 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -22,6 +22,7 @@ #include "../BlockEntities/FurnaceEntity.h" #include "../BlockEntities/HopperEntity.h" #include "../BlockEntities/NoteEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "md5/md5.h" #include "../LineBlockTracer.h" #include "../WorldStorage/SchematicFileSerializer.h" @@ -2416,6 +2417,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "DoWithFurnaceAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithSkullBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk); diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 441f54a26..f01a139d2 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -30,9 +30,9 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); - case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/SkullEntity.cpp b/src/BlockEntities/SkullEntity.cpp index 3f3bc00ed..43b97b93e 100644 --- a/src/BlockEntities/SkullEntity.cpp +++ b/src/BlockEntities/SkullEntity.cpp @@ -12,12 +12,10 @@ -cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World) : +cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), - //m_SkullType(static_cast(a_BlockMeta)), m_Owner("") { - } diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h index 6f47c7d30..ffd84465f 100644 --- a/src/BlockEntities/SkullEntity.h +++ b/src/BlockEntities/SkullEntity.h @@ -35,7 +35,7 @@ public: // tolua_end /// Creates a new skull entity at the specified block coords. a_World may be NULL - cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World); + cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); bool LoadFromJson( const Json::Value& a_Value ); virtual void SaveToJson(Json::Value& a_Value ) override; diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 6c9bbeb02..870de7a7d 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -34,6 +34,7 @@ #include "BlockGlass.h" #include "BlockGlowstone.h" #include "BlockGravel.h" +#include "BlockSkull.h" #include "BlockHopper.h" #include "BlockIce.h" #include "BlockLadder.h" @@ -146,6 +147,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_GRASS: return new cBlockDirtHandler (a_BlockType); case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType); case E_BLOCK_HAY_BALE: return new cBlockSidewaysHandler (a_BlockType); + case E_BLOCK_HEAD: return new cBlockSkullHandler (a_BlockType); case E_BLOCK_HOPPER: return new cBlockHopperHandler (a_BlockType); case E_BLOCK_ICE: return new cBlockIceHandler (a_BlockType); case E_BLOCK_INACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); diff --git a/src/Blocks/BlockSkull.h b/src/Blocks/BlockSkull.h new file mode 100644 index 000000000..eea5ac922 --- /dev/null +++ b/src/Blocks/BlockSkull.h @@ -0,0 +1,69 @@ + +#pragma once + +#include "BlockEntity.h" +#include "../BlockEntities/SkullEntity.h" + + + + + +class cBlockSkullHandler : + public cBlockEntityHandler +{ +public: + cBlockSkullHandler(BLOCKTYPE a_BlockType) + : cBlockEntityHandler(a_BlockType) + { + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + a_Pickups.push_back(cItem(E_ITEM_HEAD, 1, 0)); + } + + virtual void OnPlacedByPlayer( + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta + ) override + { + class cCallback : public cSkullBlockCallback + { + cPlayer * m_Player; + NIBBLETYPE m_OldBlockMeta; + NIBBLETYPE m_NewBlockMeta; + + virtual bool Item (cSkullEntity * a_SkullEntity) + { + int Rotation = 0; + if (m_NewBlockMeta == 1) + { + Rotation = (int) floor(m_Player->GetYaw() * 16.0F / 360.0F + 0.5) & 0xF; + } + + a_SkullEntity->SetSkullType(static_cast(m_OldBlockMeta)); + a_SkullEntity->SetRotation(static_cast(Rotation)); + return false; + } + + public: + cCallback (cPlayer * a_Player, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) : + m_Player(a_Player), + m_OldBlockMeta(a_OldBlockMeta), + m_NewBlockMeta(a_NewBlockMeta) + {} + }; + cCallback Callback(a_Player, a_BlockMeta, static_cast(a_BlockFace)); + + a_BlockMeta = a_BlockFace; + cWorld * World = (cWorld *) &a_WorldInterface; + World->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, Callback); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); + } +} ; + + + + diff --git a/src/Chunk.cpp b/src/Chunk.cpp index dc683baa5..d386b85f8 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -19,6 +19,7 @@ #include "BlockEntities/JukeboxEntity.h" #include "BlockEntities/NoteEntity.h" #include "BlockEntities/SignEntity.h" +#include "BlockEntities/SkullEntity.h" #include "Entities/Pickup.h" #include "Item.h" #include "Noise.h" @@ -2343,6 +2344,38 @@ bool cChunk::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom +bool cChunk::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +{ + // The blockentity list is locked by the parent chunkmap's CS + for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2) + { + ++itr2; + if (((*itr)->GetPosX() != a_BlockX) || ((*itr)->GetPosY() != a_BlockY) || ((*itr)->GetPosZ() != a_BlockZ)) + { + continue; + } + if ((*itr)->GetBlockType() != E_BLOCK_HEAD) + { + // There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out + return false; + } + + // The correct block entity is here, + if (a_Callback.Item((cSkullEntity *)*itr)) + { + return false; + } + return true; + } // for itr - m_BlockEntitites[] + + // Not found: + return false; +} + + + + + bool cChunk::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { // The blockentity list is locked by the parent chunkmap's CS diff --git a/src/Chunk.h b/src/Chunk.h index 682ec6170..3ef4d3a36 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -31,6 +31,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; +class cSkullEntity; class cBlockArea; class cPawn; class cPickup; @@ -47,6 +48,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; +typedef cItemCallback cSkullBlockCallback; @@ -249,7 +251,10 @@ public: bool DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNoteBlockCallback & a_Callback); /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ - bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); + bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); + + /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ + bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 01195e8bc..006ccfb29 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2178,6 +2178,24 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c +bool cChunkMap::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +{ + int ChunkX, ChunkZ; + int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; + cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + if ((Chunk == NULL) && !Chunk->IsValid()) + { + return false; + } + return Chunk->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); +} + + + + + bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { int ChunkX, ChunkZ; diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 9f0dd087e..d6036d828 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -25,6 +25,7 @@ class cDropSpenserEntity; class cFurnaceEntity; class cNoteEntity; class cCommandBlockEntity; +class cSkullEntity; class cPawn; class cPickup; class cChunkDataSerializer; @@ -43,6 +44,7 @@ typedef cItemCallback cDropSpenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; +typedef cItemCallback cSkullBlockCallback; typedef cItemCallback cChunkCallback; @@ -254,6 +256,9 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Lua-accessible + /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ + bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Lua-accessible + /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/Items/ItemSkull.h b/src/Items/ItemSkull.h index f511c8c4a..3648f1436 100644 --- a/src/Items/ItemSkull.h +++ b/src/Items/ItemSkull.h @@ -31,6 +31,7 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override { + a_BlockType = E_BLOCK_HEAD; a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); diff --git a/src/World.cpp b/src/World.cpp index e57675c44..24544752b 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1165,6 +1165,15 @@ bool cWorld::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom +bool cWorld::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +{ + return m_ChunkMap->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); +} + + + + + bool cWorld::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { return m_ChunkMap->GetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4); diff --git a/src/World.h b/src/World.h index d79de3b87..936ebc8fc 100644 --- a/src/World.h +++ b/src/World.h @@ -45,6 +45,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; +class cSkullEntity; class cMobCensus; class cCompositeChat; class cCuboid; @@ -58,6 +59,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; +typedef cItemCallback cSkullBlockCallback; @@ -519,6 +521,9 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Exported in ManualBindings.cpp + /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ + bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Exported in ManualBindings.cpp + /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Exported in ManualBindings.cpp diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 89a236f07..58dc2e9e4 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -940,7 +940,7 @@ void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cPars { return; } - std::auto_ptr Skull(new cSkullEntity(E_BLOCK_HEAD, x, y, z, m_World)); + std::auto_ptr Skull(new cSkullEntity(x, y, z, m_World)); int currentLine = a_NBT.FindChildByName(a_TagIdx, "SkullType"); if (currentLine >= 0) -- cgit v1.2.3 From a71e8be4d2d58df4e3c5b4688d2ca13338cb0657 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 19 Feb 2014 14:12:34 +0100 Subject: Add break to Protocol17x.cpp and use new comment delimiter --- src/BlockEntities/SkullEntity.h | 14 +++++++------- src/Protocol/Protocol17x.cpp | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h index ffd84465f..3dc355623 100644 --- a/src/BlockEntities/SkullEntity.h +++ b/src/BlockEntities/SkullEntity.h @@ -34,7 +34,7 @@ public: // tolua_end - /// Creates a new skull entity at the specified block coords. a_World may be NULL + /** Creates a new skull entity at the specified block coords. a_World may be NULL */ cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); bool LoadFromJson( const Json::Value& a_Value ); @@ -42,22 +42,22 @@ public: // tolua_begin - /// Set the Skull Type + /** Set the Skull Type */ void SetSkullType(const eSkullType & a_SkullType); - /// Set the Rotation + /** Set the Rotation */ void SetRotation(eSkullRotation a_Rotation); - // Set the Player Name for Player Skulls + /** Set the Player Name for Player Skull */ void SetOwner(const AString & a_Owner); - /// Get the Skull Type + /** Get the Skull Type */ eSkullType GetSkullType(void) const { return m_SkullType; } - /// Get the Rotation + /** Get the Rotation */ eSkullRotation GetRotation(void) const { return m_Rotation; } - /// Get the setted Player Name + /** Get the setted Player Name */ AString GetOwner(void) const { return m_Owner; } // tolua_end diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 213e6a1f8..5508c2cfe 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2298,6 +2298,7 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt Writer.AddByte("Rot", SkullEntity.GetRotation() & 0xFF); Writer.AddString("ExtraType", SkullEntity.GetOwner().c_str()); Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though + break; } default: break; } -- cgit v1.2.3 From 1f726b7d9dade75d8f7a3e105f3c9689a1ef0e0b Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 19 Feb 2014 14:45:09 +0100 Subject: Rename SkullEntity to MobHeadEntity --- src/Bindings/ManualBindings.cpp | 4 +- src/BlockEntities/BlockEntity.cpp | 4 +- src/BlockEntities/MobHeadEntity.cpp | 108 ++++++++++++++++++++++++++++++++ src/BlockEntities/MobHeadEntity.h | 79 +++++++++++++++++++++++ src/BlockEntities/SkullEntity.cpp | 108 -------------------------------- src/BlockEntities/SkullEntity.h | 79 ----------------------- src/Blocks/BlockHandler.cpp | 4 +- src/Blocks/BlockMobHead.h | 69 ++++++++++++++++++++ src/Blocks/BlockSkull.h | 69 -------------------- src/CMakeLists.txt | 2 +- src/Chunk.cpp | 6 +- src/Chunk.h | 8 +-- src/ChunkMap.cpp | 4 +- src/ChunkMap.h | 8 +-- src/Defines.h | 4 +- src/Items/ItemHandler.cpp | 4 +- src/Items/ItemMobHead.h | 42 +++++++++++++ src/Items/ItemSkull.h | 44 ------------- src/Protocol/Protocol17x.cpp | 18 +++--- src/World.cpp | 4 +- src/World.h | 8 +-- src/WorldStorage/NBTChunkSerializer.cpp | 14 ++--- src/WorldStorage/NBTChunkSerializer.h | 4 +- src/WorldStorage/WSSAnvil.cpp | 16 ++--- src/WorldStorage/WSSAnvil.h | 2 +- 25 files changed, 355 insertions(+), 357 deletions(-) create mode 100644 src/BlockEntities/MobHeadEntity.cpp create mode 100644 src/BlockEntities/MobHeadEntity.h delete mode 100644 src/BlockEntities/SkullEntity.cpp delete mode 100644 src/BlockEntities/SkullEntity.h create mode 100644 src/Blocks/BlockMobHead.h delete mode 100644 src/Blocks/BlockSkull.h create mode 100644 src/Items/ItemMobHead.h delete mode 100644 src/Items/ItemSkull.h diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 70f3fbcf2..41b4cc0f4 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -22,7 +22,7 @@ #include "../BlockEntities/FurnaceEntity.h" #include "../BlockEntities/HopperEntity.h" #include "../BlockEntities/NoteEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "md5/md5.h" #include "../LineBlockTracer.h" #include "../WorldStorage/SchematicFileSerializer.h" @@ -2417,7 +2417,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "DoWithFurnaceAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ); - tolua_function(tolua_S, "DoWithSkullBlockAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithMobHeadBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk); diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index f01a139d2..57ad83de9 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -15,7 +15,7 @@ #include "JukeboxEntity.h" #include "NoteEntity.h" #include "SignEntity.h" -#include "SkullEntity.h" +#include "MobHeadEntity.h" @@ -30,7 +30,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp new file mode 100644 index 000000000..c0a1781f6 --- /dev/null +++ b/src/BlockEntities/MobHeadEntity.cpp @@ -0,0 +1,108 @@ + +// MobHeadEntity.cpp + +// Implements the cMobHeadEntity class representing a single skull/head in the world + +#include "Globals.h" +#include "json/json.h" +#include "MobHeadEntity.h" +#include "../Entities/Player.h" + + + + + +cMobHeadEntity::cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), + m_Owner("") +{ +} + + + + + +void cMobHeadEntity::UsedBy(cPlayer * a_Player) +{ + UNUSED(a_Player); +} + + + + + +void cMobHeadEntity::SetType(const eMobHeadType & a_Type) +{ + if ((!m_Owner.empty()) && (a_Type != SKULL_TYPE_PLAYER)) + { + m_Owner = ""; + } + m_Type = a_Type; +} + + + + + +void cMobHeadEntity::SetRotation(eMobHeadRotation a_Rotation) +{ + m_Rotation = a_Rotation; +} + + + + + +void cMobHeadEntity::SetOwner(const AString & a_Owner) +{ + if ((a_Owner.length() > 16) || (m_Type != SKULL_TYPE_PLAYER)) + { + return; + } + m_Owner = a_Owner; +} + + + + + +void cMobHeadEntity::SendTo(cClientHandle & a_Client) +{ + a_Client.SendUpdateBlockEntity(*this); +} + + + + + +bool cMobHeadEntity::LoadFromJson(const Json::Value & a_Value) +{ + m_PosX = a_Value.get("x", 0).asInt(); + m_PosY = a_Value.get("y", 0).asInt(); + m_PosZ = a_Value.get("z", 0).asInt(); + + m_Type = static_cast(a_Value.get("Type", 0).asInt()); + m_Rotation = static_cast(a_Value.get("Rotation", 0).asInt()); + m_Owner = a_Value.get("Owner", "").asString(); + + return true; +} + + + + + +void cMobHeadEntity::SaveToJson(Json::Value & a_Value) +{ + a_Value["x"] = m_PosX; + a_Value["y"] = m_PosY; + a_Value["z"] = m_PosZ; + + a_Value["Type"] = m_Type; + a_Value["Rotation"] = m_Rotation; + a_Value["Owner"] = m_Owner; +} + + + + diff --git a/src/BlockEntities/MobHeadEntity.h b/src/BlockEntities/MobHeadEntity.h new file mode 100644 index 000000000..367eb15e7 --- /dev/null +++ b/src/BlockEntities/MobHeadEntity.h @@ -0,0 +1,79 @@ +// MobHeadEntity.h + +// Declares the cMobHeadEntity class representing a single skull/head in the world + + + + + +#pragma once + +#include "BlockEntity.h" + + + + + +namespace Json +{ + class Value; +} + + + + + +// tolua_begin + +class cMobHeadEntity : + public cBlockEntity +{ + typedef cBlockEntity super; + +public: + + // tolua_end + + /** Creates a new mob head entity at the specified block coords. a_World may be NULL */ + cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); + + bool LoadFromJson( const Json::Value& a_Value ); + virtual void SaveToJson(Json::Value& a_Value ) override; + + // tolua_begin + + /** Set the Type */ + void SetType(const eMobHeadType & a_SkullType); + + /** Set the Rotation */ + void SetRotation(eMobHeadRotation a_Rotation); + + /** Set the Player Name for Mobheads with Player type */ + void SetOwner(const AString & a_Owner); + + /** Get the Type */ + eMobHeadType GetType(void) const { return m_Type; } + + /** Get the Rotation */ + eMobHeadRotation GetRotation(void) const { return m_Rotation; } + + /** Get the setted Player Name */ + AString GetOwner(void) const { return m_Owner; } + + // tolua_end + + virtual void UsedBy(cPlayer * a_Player) override; + virtual void SendTo(cClientHandle & a_Client) override; + + static const char * GetClassStatic(void) { return "cMobHeadEntity"; } + +private: + + eMobHeadType m_Type; + eMobHeadRotation m_Rotation; + AString m_Owner; +} ; // tolua_export + + + + diff --git a/src/BlockEntities/SkullEntity.cpp b/src/BlockEntities/SkullEntity.cpp deleted file mode 100644 index 43b97b93e..000000000 --- a/src/BlockEntities/SkullEntity.cpp +++ /dev/null @@ -1,108 +0,0 @@ - -// SkullEntity.cpp - -// Implements the cSkullEntity class representing a single skull/head in the world - -#include "Globals.h" -#include "json/json.h" -#include "SkullEntity.h" -#include "../Entities/Player.h" - - - - - -cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : - super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), - m_Owner("") -{ -} - - - - - -void cSkullEntity::UsedBy(cPlayer * a_Player) -{ - UNUSED(a_Player); -} - - - - - -void cSkullEntity::SetSkullType(const eSkullType & a_SkullType) -{ - if ((!m_Owner.empty()) && (a_SkullType != SKULL_TYPE_PLAYER)) - { - m_Owner = ""; - } - m_SkullType = a_SkullType; -} - - - - - -void cSkullEntity::SetRotation(eSkullRotation a_Rotation) -{ - m_Rotation = a_Rotation; -} - - - - - -void cSkullEntity::SetOwner(const AString & a_Owner) -{ - if ((a_Owner.length() > 16) || (m_SkullType != SKULL_TYPE_PLAYER)) - { - return; - } - m_Owner = a_Owner; -} - - - - - -void cSkullEntity::SendTo(cClientHandle & a_Client) -{ - a_Client.SendUpdateBlockEntity(*this); -} - - - - - -bool cSkullEntity::LoadFromJson(const Json::Value & a_Value) -{ - m_PosX = a_Value.get("x", 0).asInt(); - m_PosY = a_Value.get("y", 0).asInt(); - m_PosZ = a_Value.get("z", 0).asInt(); - - m_SkullType = static_cast(a_Value.get("SkullType", 0).asInt()); - m_Rotation = static_cast(a_Value.get("Rotation", 0).asInt()); - m_Owner = a_Value.get("Owner", "").asString(); - - return true; -} - - - - - -void cSkullEntity::SaveToJson(Json::Value & a_Value) -{ - a_Value["x"] = m_PosX; - a_Value["y"] = m_PosY; - a_Value["z"] = m_PosZ; - - a_Value["SkullType"] = m_SkullType; - a_Value["Rotation"] = m_Rotation; - a_Value["Owner"] = m_Owner; -} - - - - diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h deleted file mode 100644 index 3dc355623..000000000 --- a/src/BlockEntities/SkullEntity.h +++ /dev/null @@ -1,79 +0,0 @@ -// SkullEntity.h - -// Declares the cSkullEntity class representing a single skull/head in the world - - - - - -#pragma once - -#include "BlockEntity.h" - - - - - -namespace Json -{ - class Value; -} - - - - - -// tolua_begin - -class cSkullEntity : - public cBlockEntity -{ - typedef cBlockEntity super; - -public: - - // tolua_end - - /** Creates a new skull entity at the specified block coords. a_World may be NULL */ - cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); - - bool LoadFromJson( const Json::Value& a_Value ); - virtual void SaveToJson(Json::Value& a_Value ) override; - - // tolua_begin - - /** Set the Skull Type */ - void SetSkullType(const eSkullType & a_SkullType); - - /** Set the Rotation */ - void SetRotation(eSkullRotation a_Rotation); - - /** Set the Player Name for Player Skull */ - void SetOwner(const AString & a_Owner); - - /** Get the Skull Type */ - eSkullType GetSkullType(void) const { return m_SkullType; } - - /** Get the Rotation */ - eSkullRotation GetRotation(void) const { return m_Rotation; } - - /** Get the setted Player Name */ - AString GetOwner(void) const { return m_Owner; } - - // tolua_end - - virtual void UsedBy(cPlayer * a_Player) override; - virtual void SendTo(cClientHandle & a_Client) override; - - static const char * GetClassStatic(void) { return "cSkullEntity"; } - -private: - - eSkullType m_SkullType; - eSkullRotation m_Rotation; - AString m_Owner; -} ; // tolua_export - - - - diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 870de7a7d..09a1244ea 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -34,7 +34,7 @@ #include "BlockGlass.h" #include "BlockGlowstone.h" #include "BlockGravel.h" -#include "BlockSkull.h" +#include "BlockMobHead.h" #include "BlockHopper.h" #include "BlockIce.h" #include "BlockLadder.h" @@ -147,7 +147,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_GRASS: return new cBlockDirtHandler (a_BlockType); case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType); case E_BLOCK_HAY_BALE: return new cBlockSidewaysHandler (a_BlockType); - case E_BLOCK_HEAD: return new cBlockSkullHandler (a_BlockType); + case E_BLOCK_HEAD: return new cBlockMobHeadHandler (a_BlockType); case E_BLOCK_HOPPER: return new cBlockHopperHandler (a_BlockType); case E_BLOCK_ICE: return new cBlockIceHandler (a_BlockType); case E_BLOCK_INACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h new file mode 100644 index 000000000..6a00c3acd --- /dev/null +++ b/src/Blocks/BlockMobHead.h @@ -0,0 +1,69 @@ + +#pragma once + +#include "BlockEntity.h" +#include "../BlockEntities/MobHeadEntity.h" + + + + + +class cBlockMobHeadHandler : + public cBlockEntityHandler +{ +public: + cBlockMobHeadHandler(BLOCKTYPE a_BlockType) + : cBlockEntityHandler(a_BlockType) + { + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + a_Pickups.push_back(cItem(E_ITEM_HEAD, 1, 0)); + } + + virtual void OnPlacedByPlayer( + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta + ) override + { + class cCallback : public cMobHeadBlockCallback + { + cPlayer * m_Player; + NIBBLETYPE m_OldBlockMeta; + NIBBLETYPE m_NewBlockMeta; + + virtual bool Item (cMobHeadEntity * a_MobHeadEntity) + { + int Rotation = 0; + if (m_NewBlockMeta == 1) + { + Rotation = (int) floor(m_Player->GetYaw() * 16.0F / 360.0F + 0.5) & 0xF; + } + + a_MobHeadEntity->SetType(static_cast(m_OldBlockMeta)); + a_MobHeadEntity->SetRotation(static_cast(Rotation)); + return false; + } + + public: + cCallback (cPlayer * a_Player, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) : + m_Player(a_Player), + m_OldBlockMeta(a_OldBlockMeta), + m_NewBlockMeta(a_NewBlockMeta) + {} + }; + cCallback Callback(a_Player, a_BlockMeta, static_cast(a_BlockFace)); + + a_BlockMeta = a_BlockFace; + cWorld * World = (cWorld *) &a_WorldInterface; + World->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, Callback); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); + } +} ; + + + + diff --git a/src/Blocks/BlockSkull.h b/src/Blocks/BlockSkull.h deleted file mode 100644 index eea5ac922..000000000 --- a/src/Blocks/BlockSkull.h +++ /dev/null @@ -1,69 +0,0 @@ - -#pragma once - -#include "BlockEntity.h" -#include "../BlockEntities/SkullEntity.h" - - - - - -class cBlockSkullHandler : - public cBlockEntityHandler -{ -public: - cBlockSkullHandler(BLOCKTYPE a_BlockType) - : cBlockEntityHandler(a_BlockType) - { - } - - virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override - { - a_Pickups.push_back(cItem(E_ITEM_HEAD, 1, 0)); - } - - virtual void OnPlacedByPlayer( - cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, - int a_CursorX, int a_CursorY, int a_CursorZ, - BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta - ) override - { - class cCallback : public cSkullBlockCallback - { - cPlayer * m_Player; - NIBBLETYPE m_OldBlockMeta; - NIBBLETYPE m_NewBlockMeta; - - virtual bool Item (cSkullEntity * a_SkullEntity) - { - int Rotation = 0; - if (m_NewBlockMeta == 1) - { - Rotation = (int) floor(m_Player->GetYaw() * 16.0F / 360.0F + 0.5) & 0xF; - } - - a_SkullEntity->SetSkullType(static_cast(m_OldBlockMeta)); - a_SkullEntity->SetRotation(static_cast(Rotation)); - return false; - } - - public: - cCallback (cPlayer * a_Player, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) : - m_Player(a_Player), - m_OldBlockMeta(a_OldBlockMeta), - m_NewBlockMeta(a_NewBlockMeta) - {} - }; - cCallback Callback(a_Player, a_BlockMeta, static_cast(a_BlockFace)); - - a_BlockMeta = a_BlockFace; - cWorld * World = (cWorld *) &a_WorldInterface; - World->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, Callback); - a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); - } -} ; - - - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 13707b6a6..387556775 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,7 +39,7 @@ if (NOT MSVC) BlockEntities/JukeboxEntity.h BlockEntities/NoteEntity.h BlockEntities/SignEntity.h - BlockEntities/SkullEntity.h + BlockEntities/MobHeadEntity.h BlockID.h BoundingBox.h ChatColor.h diff --git a/src/Chunk.cpp b/src/Chunk.cpp index d386b85f8..4f301c209 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -19,7 +19,7 @@ #include "BlockEntities/JukeboxEntity.h" #include "BlockEntities/NoteEntity.h" #include "BlockEntities/SignEntity.h" -#include "BlockEntities/SkullEntity.h" +#include "BlockEntities/MobHeadEntity.h" #include "Entities/Pickup.h" #include "Item.h" #include "Noise.h" @@ -2344,7 +2344,7 @@ bool cChunk::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom -bool cChunk::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +bool cChunk::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) { // The blockentity list is locked by the parent chunkmap's CS for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2) @@ -2361,7 +2361,7 @@ bool cChunk::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkull } // The correct block entity is here, - if (a_Callback.Item((cSkullEntity *)*itr)) + if (a_Callback.Item((cMobHeadEntity *)*itr)) { return false; } diff --git a/src/Chunk.h b/src/Chunk.h index 3ef4d3a36..1b7a6fa07 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -31,7 +31,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; -class cSkullEntity; +class cMobHeadEntity; class cBlockArea; class cPawn; class cPickup; @@ -48,7 +48,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cSkullBlockCallback; +typedef cItemCallback cMobHeadBlockCallback; @@ -253,8 +253,8 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); - /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ - bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); + /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob header block at those coords or callback returns true, returns true if found */ + bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 006ccfb29..fbb8706e0 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2178,7 +2178,7 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c -bool cChunkMap::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +bool cChunkMap::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) { int ChunkX, ChunkZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; @@ -2189,7 +2189,7 @@ bool cChunkMap::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSk { return false; } - return Chunk->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return Chunk->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index d6036d828..9df68c403 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -25,7 +25,7 @@ class cDropSpenserEntity; class cFurnaceEntity; class cNoteEntity; class cCommandBlockEntity; -class cSkullEntity; +class cMobHeadEntity; class cPawn; class cPickup; class cChunkDataSerializer; @@ -44,7 +44,7 @@ typedef cItemCallback cDropSpenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cSkullBlockCallback; +typedef cItemCallback cMobHeadBlockCallback; typedef cItemCallback cChunkCallback; @@ -256,8 +256,8 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Lua-accessible - /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ - bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Lua-accessible + /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ + bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Lua-accessible /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/Defines.h b/src/Defines.h index 7e22cbdc5..ba2866f83 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -174,7 +174,7 @@ enum eWeather -enum eSkullType +enum eMobHeadType { SKULL_TYPE_SKELETON = 0, SKULL_TYPE_WITHER = 1, @@ -187,7 +187,7 @@ enum eSkullType -enum eSkullRotation +enum eMobHeadRotation { SKULL_ROTATION_NORTH = 0, SKULL_ROTATION_NORTH_NORTH_EAST = 1, diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 7a92ad64c..e9bb616a6 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -37,7 +37,7 @@ #include "ItemShears.h" #include "ItemShovel.h" #include "ItemSign.h" -#include "ItemSkull.h" +#include "ItemMobHead.h" #include "ItemSpawnEgg.h" #include "ItemSugarcane.h" #include "ItemSword.h" @@ -115,7 +115,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType); case E_ITEM_SIGN: return new cItemSignHandler(a_ItemType); - case E_ITEM_HEAD: return new cItemSkullHandler(a_ItemType); + case E_ITEM_HEAD: return new cItemMobHeadHandler(a_ItemType); case E_ITEM_SNOWBALL: return new cItemSnowballHandler(); case E_ITEM_SPAWN_EGG: return new cItemSpawnEggHandler(a_ItemType); case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemType); diff --git a/src/Items/ItemMobHead.h b/src/Items/ItemMobHead.h new file mode 100644 index 000000000..5ae040282 --- /dev/null +++ b/src/Items/ItemMobHead.h @@ -0,0 +1,42 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemMobHeadHandler : + public cItemHandler +{ +public: + cItemMobHeadHandler(int a_ItemType) : + cItemHandler(a_ItemType) + { + } + + + virtual bool IsPlaceable(void) override + { + return true; + } + + + virtual bool GetPlacementBlockTypeMeta( + cWorld * a_World, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = E_BLOCK_HEAD; + a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); + return true; + } +} ; + + + + diff --git a/src/Items/ItemSkull.h b/src/Items/ItemSkull.h deleted file mode 100644 index 3648f1436..000000000 --- a/src/Items/ItemSkull.h +++ /dev/null @@ -1,44 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - - - - - -class cItemSkullHandler : - public cItemHandler -{ -public: - cItemSkullHandler(int a_ItemType) : - cItemHandler(a_ItemType) - { - } - - - virtual bool IsPlaceable(void) override - { - return true; - } - - - virtual bool GetPlacementBlockTypeMeta( - cWorld * a_World, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, - int a_CursorX, int a_CursorY, int a_CursorZ, - BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta - ) override - { - - a_BlockType = E_BLOCK_HEAD; - a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); - - return true; - } -} ; - - - - diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 5508c2cfe..aaf8830cd 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -28,7 +28,7 @@ Implements the 1.7.x protocol classes: #include "../Mobs/IncludeAllMonsters.h" #include "../UI/Window.h" #include "../BlockEntities/CommandBlockEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "../CompositeChat.h" @@ -1059,7 +1059,7 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text - case E_BLOCK_HEAD: Action = 4; break; // Update Skull entity + case E_BLOCK_HEAD: Action = 4; break; // Update Mobhead entity default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break; } Pkt.WriteByte(Action); @@ -2289,14 +2289,14 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt } case E_BLOCK_HEAD: { - cSkullEntity & SkullEntity = (cSkullEntity &)a_BlockEntity; + cMobHeadEntity & MobHeadEntity = (cMobHeadEntity &)a_BlockEntity; - Writer.AddInt("x", SkullEntity.GetPosX()); - Writer.AddInt("y", SkullEntity.GetPosY()); - Writer.AddInt("z", SkullEntity.GetPosZ()); - Writer.AddByte("SkullType", SkullEntity.GetSkullType() & 0xFF); - Writer.AddByte("Rot", SkullEntity.GetRotation() & 0xFF); - Writer.AddString("ExtraType", SkullEntity.GetOwner().c_str()); + Writer.AddInt("x", MobHeadEntity.GetPosX()); + Writer.AddInt("y", MobHeadEntity.GetPosY()); + Writer.AddInt("z", MobHeadEntity.GetPosZ()); + Writer.AddByte("SkullType", MobHeadEntity.GetType() & 0xFF); + Writer.AddByte("Rot", MobHeadEntity.GetRotation() & 0xFF); + Writer.AddString("ExtraType", MobHeadEntity.GetOwner().c_str()); Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though break; } diff --git a/src/World.cpp b/src/World.cpp index 24544752b..7d8bdd95f 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1165,9 +1165,9 @@ bool cWorld::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom -bool cWorld::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +bool cWorld::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) { - return m_ChunkMap->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } diff --git a/src/World.h b/src/World.h index 936ebc8fc..5c18c5d23 100644 --- a/src/World.h +++ b/src/World.h @@ -45,7 +45,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; -class cSkullEntity; +class cMobHeadEntity; class cMobCensus; class cCompositeChat; class cCuboid; @@ -59,7 +59,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cSkullBlockCallback; +typedef cItemCallback cMobHeadBlockCallback; @@ -521,8 +521,8 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Exported in ManualBindings.cpp - /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ - bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Exported in ManualBindings.cpp + /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ + bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Exported in ManualBindings.cpp /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Exported in ManualBindings.cpp diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index e1a986d04..2a1eda523 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -19,7 +19,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "../Entities/Entity.h" #include "../Entities/FallingBlock.h" @@ -261,13 +261,13 @@ void cNBTChunkSerializer::AddSignEntity(cSignEntity * a_Sign) -void cNBTChunkSerializer::AddSkullEntity(cSkullEntity * a_Skull) +void cNBTChunkSerializer::AddMobHeadEntity(cMobHeadEntity * a_MobHead) { m_Writer.BeginCompound(""); - AddBasicTileEntity(a_Skull, "Skull"); - m_Writer.AddByte ("SkullType", a_Skull->GetSkullType() & 0xFF); - m_Writer.AddByte ("Rot", a_Skull->GetRotation() & 0xFF); - m_Writer.AddString("ExtraType", a_Skull->GetOwner()); + AddBasicTileEntity(a_MobHead, "Skull"); + m_Writer.AddByte ("SkullType", a_MobHead->GetType() & 0xFF); + m_Writer.AddByte ("Rot", a_MobHead->GetRotation() & 0xFF); + m_Writer.AddString("ExtraType", a_MobHead->GetOwner()); m_Writer.EndCompound(); } @@ -683,7 +683,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: AddSignEntity ((cSignEntity *) a_Entity); break; - case E_BLOCK_HEAD: AddSkullEntity ((cSkullEntity *) a_Entity); break; + case E_BLOCK_HEAD: AddMobHeadEntity ((cMobHeadEntity *) a_Entity); break; case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break; case E_BLOCK_JUKEBOX: AddJukeboxEntity ((cJukeboxEntity *) a_Entity); break; case E_BLOCK_COMMAND_BLOCK: AddCommandBlockEntity((cCommandBlockEntity *) a_Entity); break; diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index fd5601e47..5f9e16ed1 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -29,7 +29,7 @@ class cHopperEntity; class cJukeboxEntity; class cNoteEntity; class cSignEntity; -class cSkullEntity; +class cMobHeadEntity; class cFallingBlock; class cMinecart; class cMinecartWithChest; @@ -94,7 +94,7 @@ protected: void AddJukeboxEntity (cJukeboxEntity * a_Jukebox); void AddNoteEntity (cNoteEntity * a_Note); void AddSignEntity (cSignEntity * a_Sign); - void AddSkullEntity (cSkullEntity * a_Skull); + void AddMobHeadEntity (cMobHeadEntity * a_MobHead); void AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock); // Entities: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 58dc2e9e4..d4490c7fe 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -24,7 +24,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "../Mobs/Monster.h" @@ -600,7 +600,7 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con } else if (strncmp(a_NBT.GetData(sID), "Skull", a_NBT.GetDataLength(sID)) == 0) { - LoadSkullFromNBT(a_BlockEntities, a_NBT, Child); + LoadMobHeadFromNBT(a_BlockEntities, a_NBT, Child); } else if (strncmp(a_NBT.GetData(sID), "Trap", a_NBT.GetDataLength(sID)) == 0) { @@ -932,7 +932,7 @@ void cWSSAnvil::LoadSignFromNBT(cBlockEntityList & a_BlockEntities, const cParse -void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) +void cWSSAnvil::LoadMobHeadFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) { ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); int x, y, z; @@ -940,27 +940,27 @@ void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cPars { return; } - std::auto_ptr Skull(new cSkullEntity(x, y, z, m_World)); + std::auto_ptr MobHead(new cMobHeadEntity(x, y, z, m_World)); int currentLine = a_NBT.FindChildByName(a_TagIdx, "SkullType"); if (currentLine >= 0) { - Skull->SetSkullType(static_cast(a_NBT.GetByte(currentLine))); + MobHead->SetType(static_cast(a_NBT.GetByte(currentLine))); } currentLine = a_NBT.FindChildByName(a_TagIdx, "Rot"); if (currentLine >= 0) { - Skull->SetRotation(static_cast(a_NBT.GetByte(currentLine))); + MobHead->SetRotation(static_cast(a_NBT.GetByte(currentLine))); } currentLine = a_NBT.FindChildByName(a_TagIdx, "ExtraType"); if (currentLine >= 0) { - Skull->SetOwner(a_NBT.GetString(currentLine)); + MobHead->SetOwner(a_NBT.GetString(currentLine)); } - a_BlockEntities.push_back(Skull.release()); + a_BlockEntities.push_back(MobHead.release()); } diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 9c9e17258..541371560 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -139,7 +139,7 @@ protected: void LoadJukeboxFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadNoteFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadSignFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); - void LoadSkullFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadMobHeadFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadCommandBlockFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength); -- cgit v1.2.3 From fd4af0f99287a48b969ffd0a6314e4beb7368e2f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Feb 2014 10:48:29 +0100 Subject: Fixed bindings for cBlockArea:Get(Rel)BlockTypeMeta(). They no longer require the ghost output params. --- src/Bindings/ManualBindings.cpp | 133 +++++++++++++++++++++++++++++++--------- src/BlockArea.h | 6 ++ 2 files changed, 110 insertions(+), 29 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 41b4cc0f4..c220e5e0a 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -213,7 +213,7 @@ static int tolua_DoWith(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 2 or 3 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); const char * ItemName = tolua_tocppstring(tolua_S, 2, ""); if ((ItemName == NULL) || (ItemName[0] == 0)) @@ -307,7 +307,7 @@ static int tolua_DoWithID(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 2 or 3 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *)tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *)tolua_tousertype(tolua_S, 1, NULL); int ItemID = (int)tolua_tonumber(tolua_S, 2, 0); if (!lua_isfunction(tolua_S, 3)) @@ -397,7 +397,7 @@ static int tolua_DoWithXYZ(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 4 or 5 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3) || !lua_isnumber(tolua_S, 4)) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3"); @@ -491,7 +491,7 @@ static int tolua_ForEachInChunk(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 3 or 4 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3)) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1 and #2"); @@ -585,7 +585,7 @@ static int tolua_ForEach(lua_State * tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 1 or 2 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance"); @@ -682,7 +682,7 @@ static int tolua_cWorld_GetBlockInfo(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -737,7 +737,7 @@ static int tolua_cWorld_GetBlockTypeMeta(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -789,7 +789,7 @@ static int tolua_cWorld_GetSignLines(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -847,7 +847,7 @@ static int tolua_cWorld_SetSignLines(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -896,7 +896,7 @@ static int tolua_cWorld_TryGetHeight(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 3, 0); #ifndef TOLUA_RELEASE @@ -968,7 +968,7 @@ static int tolua_cWorld_QueueTask(lua_State * tolua_S) } // Retrieve the args: - cWorld * self = (cWorld *)tolua_tousertype(tolua_S, 1, 0); + cWorld * self = (cWorld *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance"); @@ -1066,7 +1066,7 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S) static int tolua_cPluginManager_GetAllPlugins(lua_State * tolua_S) { - cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, 0); + cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, NULL); const cPluginManager::PluginMap & AllPlugins = self->GetAllPlugins(); @@ -1290,7 +1290,7 @@ static int tolua_cPluginManager_ForEachCommand(lua_State * tolua_S) return 0; } - cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, 0); + cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { LOGWARN("Error in function call 'ForEachCommand': Not called on an object instance"); @@ -1365,7 +1365,7 @@ static int tolua_cPluginManager_ForEachConsoleCommand(lua_State * tolua_S) return 0; } - cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, 0); + cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { LOGWARN("Error in function call 'ForEachConsoleCommand': Not called on an object instance"); @@ -1687,7 +1687,7 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S) static int tolua_cPlayer_GetGroups(lua_State* tolua_S) { - cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); + cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S, 1, NULL); const cPlayer::GroupList & AllGroups = self->GetGroups(); @@ -1712,7 +1712,7 @@ static int tolua_cPlayer_GetGroups(lua_State* tolua_S) static int tolua_cPlayer_GetResolvedPermissions(lua_State* tolua_S) { - cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); + cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S, 1, NULL); cPlayer::StringList AllPermissions = self->GetResolvedPermissions(); @@ -1825,7 +1825,7 @@ static int tolua_SetObjectCallback(lua_State * tolua_S) static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S) { - cPluginLua * self = (cPluginLua *)tolua_tousertype(tolua_S,1,0); + cPluginLua * self = (cPluginLua *)tolua_tousertype(tolua_S, 1, NULL); tolua_Error tolua_err; tolua_err.array = 0; @@ -1869,7 +1869,7 @@ static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S) static int tolua_cPluginLua_AddTab(lua_State* tolua_S) { - cPluginLua * self = (cPluginLua *) tolua_tousertype(tolua_S, 1, 0); + cPluginLua * self = (cPluginLua *) tolua_tousertype(tolua_S, 1, NULL); LOGWARN("WARNING: Using deprecated function AddTab()! Use AddWebTab() instead. (plugin \"%s\" in folder \"%s\")", self->GetName().c_str(), self->GetDirectory().c_str() ); @@ -1889,7 +1889,7 @@ static int tolua_cPlugin_Call(lua_State * tolua_S) L.LogStackTrace(); // Retrieve the params: plugin and the function name to call - cPluginLua * TargetPlugin = (cPluginLua *) tolua_tousertype(tolua_S, 1, 0); + cPluginLua * TargetPlugin = (cPluginLua *) tolua_tousertype(tolua_S, 1, NULL); AString FunctionName = tolua_tostring(tolua_S, 2, ""); // Call the function: @@ -1942,7 +1942,7 @@ static int tolua_push_StringStringMap(lua_State* tolua_S, std::map< std::string, static int tolua_get_HTTPRequest_Params(lua_State* tolua_S) { - HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0); + HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, NULL); return tolua_push_StringStringMap(tolua_S, self->Params); } @@ -1952,7 +1952,7 @@ static int tolua_get_HTTPRequest_Params(lua_State* tolua_S) static int tolua_get_HTTPRequest_PostParams(lua_State* tolua_S) { - HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0); + HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, NULL); return tolua_push_StringStringMap(tolua_S, self->PostParams); } @@ -1962,7 +1962,7 @@ static int tolua_get_HTTPRequest_PostParams(lua_State* tolua_S) static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S) { - HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0); + HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, NULL); std::map< std::string, HTTPFormData >& FormData = self->FormData; lua_newtable(tolua_S); @@ -1985,7 +1985,7 @@ static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S) static int tolua_cWebAdmin_GetPlugins(lua_State * tolua_S) { - cWebAdmin* self = (cWebAdmin*) tolua_tousertype(tolua_S,1,0); + cWebAdmin* self = (cWebAdmin*) tolua_tousertype(tolua_S, 1, NULL); const cWebAdmin::PluginList & AllPlugins = self->GetPlugins(); @@ -2010,7 +2010,7 @@ static int tolua_cWebAdmin_GetPlugins(lua_State * tolua_S) static int tolua_cWebPlugin_GetTabNames(lua_State * tolua_S) { - cWebPlugin* self = (cWebPlugin*) tolua_tousertype(tolua_S,1,0); + cWebPlugin* self = (cWebPlugin*) tolua_tousertype(tolua_S, 1, NULL); const cWebPlugin::TabNameList & TabNames = self->GetTabNames(); @@ -2077,7 +2077,7 @@ static int Lua_ItemGrid_GetSlotCoords(lua_State * L) } { - const cItemGrid * self = (const cItemGrid *)tolua_tousertype(L, 1, 0); + const cItemGrid * self = (const cItemGrid *)tolua_tousertype(L, 1, NULL); int SlotNum = (int)tolua_tonumber(L, 2, 0); if (self == NULL) { @@ -2289,7 +2289,7 @@ static int tolua_cHopperEntity_GetOutputBlockPos(lua_State * tolua_S) { return 0; } - cHopperEntity * self = (cHopperEntity *)tolua_tousertype(tolua_S, 1, 0); + cHopperEntity * self = (cHopperEntity *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { tolua_error(tolua_S, "invalid 'self' in function 'cHopperEntity::GetOutputBlockPos()'", NULL); @@ -2315,6 +2315,76 @@ static int tolua_cHopperEntity_GetOutputBlockPos(lua_State * tolua_S) +static int tolua_cBlockArea_GetBlockTypeMeta(lua_State * tolua_S) +{ + // function cBlockArea::GetBlockTypeMeta() + // Exported manually because tolua generates extra input params for the outputs + + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cBlockArea") || + !L.CheckParamNumber (2, 4) + ) + { + return 0; + } + + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetRelBlockTypeMeta'", NULL); + return 0; + } + int BlockX = (int)tolua_tonumber(tolua_S, 2, 0); + int BlockY = (int)tolua_tonumber(tolua_S, 3, 0); + int BlockZ = (int)tolua_tonumber(tolua_S, 4, 0); + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + self->GetBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta); + tolua_pushnumber(tolua_S, BlockType); + tolua_pushnumber(tolua_S, BlockMeta); + return 2; +} + + + + + +static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * tolua_S) +{ + // function cBlockArea::GetRelBlockTypeMeta() + // Exported manually because tolua generates extra input params for the outputs + + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cBlockArea") || + !L.CheckParamNumber (2, 4) + ) + { + return 0; + } + + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetRelBlockTypeMeta'", NULL); + return 0; + } + int BlockX = (int)tolua_tonumber(tolua_S, 2, 0); + int BlockY = (int)tolua_tonumber(tolua_S, 3, 0); + int BlockZ = (int)tolua_tonumber(tolua_S, 4, 0); + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + self->GetRelBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta); + tolua_pushnumber(tolua_S, BlockType); + tolua_pushnumber(tolua_S, BlockMeta); + return 2; +} + + + + + static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) { // function cBlockArea::LoadFromSchematicFile @@ -2328,7 +2398,7 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) { return 0; } - cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, 0); + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::LoadFromSchematicFile'", NULL); @@ -2344,6 +2414,7 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) + static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) { // function cBlockArea::SaveToSchematicFile @@ -2357,7 +2428,7 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) { return 0; } - cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, 0); + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::SaveToSchematicFile'", NULL); @@ -2371,6 +2442,8 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) + + void ManualBindings::Bind(lua_State * tolua_S) { tolua_beginmodule(tolua_S, NULL); @@ -2387,8 +2460,10 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cBlockArea"); + tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cBlockArea_GetBlockTypeMeta); + tolua_function(tolua_S, "GetRelBlockTypeMeta", tolua_cBlockArea_GetRelBlockTypeMeta); tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile); - tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); + tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cHopperEntity"); diff --git a/src/BlockArea.h b/src/BlockArea.h index 59bc0f241..b4a161f32 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -184,9 +184,15 @@ public: void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + + // tolua_end + + // These need manual exporting, tolua generates the binding as requiring 2 extra input params void GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; + // tolua_begin + int GetSizeX(void) const { return m_SizeX; } int GetSizeY(void) const { return m_SizeY; } int GetSizeZ(void) const { return m_SizeZ; } -- cgit v1.2.3 From ea2420e8b4a4b176f96303d82d779844da6e9fb5 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Feb 2014 11:05:45 +0100 Subject: APIDump: Fixed cBlockArea:GetRelBlockType() return types. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index fd4b1d947..73bb5c7fb 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -118,7 +118,7 @@ g_APIDesc = GetRelBlockMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "NIBBLETYPE", Notes = "Returns the block meta at the specified relative coords" }, GetRelBlockSkyLight = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "NIBBLETYPE", Notes = "Returns the skylight at the specified relative coords" }, GetRelBlockType = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "BLOCKTYPE", Notes = "Returns the block type at the specified relative coords" }, - GetRelBlockTypeMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "NIBBLETYPE", Notes = "Returns the block type and meta at the specified relative coords" }, + GetRelBlockTypeMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "BLOCKTYPE, NIBBLETYPE", Notes = "Returns the block type and meta at the specified relative coords" }, GetSizeX = { Params = "", Return = "number", Notes = "Returns the size of the held data in the x-axis" }, GetSizeY = { Params = "", Return = "number", Notes = "Returns the size of the held data in the y-axis" }, GetSizeZ = { Params = "", Return = "number", Notes = "Returns the size of the held data in the z-axis" }, -- cgit v1.2.3 From 8716263238e2a79273c123661295906ddfe74490 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Thu, 20 Feb 2014 16:26:50 +0100 Subject: BlockBed.cpp: Fixed Multiple people in one bed. OnUse in BlockBed.cpp now checks whether bit flag 0x4 in the Data values of the bed is set before somebody can try to sleep in the bed. --- src/Blocks/BlockBed.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index a6f3c36b6..2fa3a7264 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -63,20 +63,29 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface if (a_WorldInterface.GetTimeOfDay() > 13000) { NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if (Meta & 0x8) + if(Meta & 0x4) { - // Is pillow - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_Player->SendMessageFailure("This bed is occupied."); } else { - // Is foot end - Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); - if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + if (Meta & 0x8) { - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + // Is pillow + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); } + else + { + // Is foot end + Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); + if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + { + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + } + } + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (Meta | (1 << 2))); } + } else { a_Player->SendMessageFailure("You can only sleep at night"); } @@ -86,3 +95,5 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface + + -- cgit v1.2.3 From 2cc597372afddbd798c2a8c2e754b3f9c7a36038 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sun, 23 Feb 2014 19:44:58 +0100 Subject: Fixed Formatting, Added DropChances and CanPickUpLoot attributes to Monsters --- src/Blocks/BlockBed.cpp | 2 +- src/Enchantments.h | 1 - src/Mobs/Blaze.cpp | 6 +- src/Mobs/Cavespider.cpp | 12 ++- src/Mobs/Chicken.cpp | 9 +- src/Mobs/Cow.cpp | 9 +- src/Mobs/Creeper.cpp | 7 +- src/Mobs/Enderman.cpp | 7 +- src/Mobs/Ghast.cpp | 9 +- src/Mobs/Horse.cpp | 7 +- src/Mobs/IronGolem.cpp | 1 + src/Mobs/Magmacube.cpp | 5 +- src/Mobs/Monster.cpp | 76 +++++++++++++ src/Mobs/Monster.h | 35 ++++++ src/Mobs/Mooshroom.cpp | 48 ++++++++- src/Mobs/Mooshroom.h | 1 + src/Mobs/Pig.cpp | 7 +- src/Mobs/Skeleton.cpp | 22 +++- src/Mobs/Slime.cpp | 11 +- src/Mobs/SnowGolem.cpp | 2 +- src/Mobs/Spider.cpp | 12 ++- src/Mobs/Squid.cpp | 7 +- src/Mobs/Witch.cpp | 29 +++-- src/Mobs/Witch.h | 1 + src/Mobs/Zombie.cpp | 16 ++- src/Mobs/Zombiepigman.cpp | 15 ++- src/WorldStorage/NBTChunkSerializer.cpp | 8 ++ src/WorldStorage/WSSAnvil.cpp | 183 ++++++++++++++++++++++++++++++++ src/WorldStorage/WSSAnvil.h | 7 ++ 29 files changed, 515 insertions(+), 40 deletions(-) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 2fa3a7264..3dad4feba 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -63,7 +63,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface if (a_WorldInterface.GetTimeOfDay() > 13000) { NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if(Meta & 0x4) + if (Meta & 0x4) { a_Player->SendMessageFailure("This bed is occupied."); } diff --git a/src/Enchantments.h b/src/Enchantments.h index e984df92e..f77b535d8 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -21,7 +21,6 @@ class cParsedNBT; - /** Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a stringspec and read back from such stringspec. The format for the stringspec is "id=lvl;id=lvl;id=lvl...", with an optional semicolon at the end, diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index f9c05b17a..ac42cf40b 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,7 +19,11 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_BLAZE_ROD); + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + { + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); + } } diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index aba1ff9f5..94e93283d 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -31,8 +31,16 @@ void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_STRING); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_SPIDER_EYE); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + { + AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); + } } diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index fab92ce49..f7e44238f 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -48,8 +48,13 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk) void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_FEATHER); - a_Drops.push_back(cItem(IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN, 1)); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); + AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); } diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index d8e905217..9914df6b5 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -21,8 +21,13 @@ cCow::cCow(void) : void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_LEATHER); - AddRandomDropItem(a_Drops, 1, 3, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); + AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index ff0abfdca..40ee20e44 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -39,7 +39,12 @@ void cCreeper::Tick(float a_Dt, cChunk & a_Chunk) void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_GUNPOWDER); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); if ((a_Killer != NULL) && (a_Killer->IsProjectile())) { diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index a784131e4..becc99a86 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -21,7 +21,12 @@ cEnderman::cEnderman(void) : void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_ENDER_PEARL); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL); } diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index 96a29b2d8..fe18f5e76 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -18,8 +18,13 @@ cGhast::cGhast(void) : void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_GUNPOWDER); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_GHAST_TEAR); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); } diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index bb9a4e3f6..9d130301f 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -140,7 +140,12 @@ void cHorse::OnRightClicked(cPlayer & a_Player) void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_LEATHER); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); if (m_bIsSaddled) { a_Drops.push_back(cItem(E_ITEM_SADDLE, 1)); diff --git a/src/Mobs/IronGolem.cpp b/src/Mobs/IronGolem.cpp index 47c961098..057834afd 100644 --- a/src/Mobs/IronGolem.cpp +++ b/src/Mobs/IronGolem.cpp @@ -19,6 +19,7 @@ cIronGolem::cIronGolem(void) : void cIronGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) { AddRandomDropItem(a_Drops, 0, 5, E_ITEM_IRON); + AddRandomDropItem(a_Drops, 0, 2, E_BLOCK_FLOWER); } diff --git a/src/Mobs/Magmacube.cpp b/src/Mobs/Magmacube.cpp index 86447ff6b..ec6137ca6 100644 --- a/src/Mobs/Magmacube.cpp +++ b/src/Mobs/Magmacube.cpp @@ -19,7 +19,10 @@ cMagmaCube::cMagmaCube(int a_Size) : void cMagmaCube::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_MAGMA_CREAM); + if (GetSize() > 1) + { + AddRandomUncommonDropItem(a_Drops, 25.0f, E_ITEM_MAGMA_CREAM); + } } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index b5cf693cb..4ab485321 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -81,6 +81,12 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_AttackDamage(1) , m_AttackRange(2) , m_AttackInterval(0) + , m_DropChanceWeapon(0.085) + , m_DropChanceHelmet(0.085) + , m_DropChanceChestplate(0.085) + , m_DropChanceLeggings(0.085) + , m_DropChanceBoots(0.085) + , m_CanPickUpLoot(true) , m_SightDistance(25) , m_BurnsInDaylight(false) { @@ -880,6 +886,76 @@ void cMonster::AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned +void cMonster::AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth) +{ + MTRand r1; + int Count = r1.randInt() % 1000; + if (Count < (a_Chance * 10)) + { + a_Drops.push_back(cItem(a_Item, 1, a_ItemHealth)); + } +} + + + + + +void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel) +{ + MTRand r1; + int Count = r1.randInt() % 200; + if (Count < (5 + a_LootingLevel)) + { + int Rare = r1.randInt() % a_Items.Size(); + a_Drops.push_back(a_Items.at(Rare)); + } +} + + + + + +void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) +{ + MTRand r1; + if (r1.randInt() % 200 < ((m_DropChanceHelmet * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedHelmet().IsEmpty()) a_Drops.push_back(GetEquippedHelmet()); + } + + if (r1.randInt() % 200 < ((m_DropChanceChestplate * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedChestplate().IsEmpty()) a_Drops.push_back(GetEquippedChestplate()); + } + + if (r1.randInt() % 200 < ((m_DropChanceLeggings * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedLeggings().IsEmpty()) a_Drops.push_back(GetEquippedLeggings()); + } + + if (r1.randInt() % 200 < ((m_DropChanceBoots * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedBoots().IsEmpty()) a_Drops.push_back(GetEquippedBoots()); + } +} + + + + + +void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel) +{ + MTRand r1; + if (r1.randInt() % 200 < ((m_DropChanceWeapon * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedWeapon().IsEmpty()) a_Drops.push_back(GetEquippedWeapon()); + } +} + + + + + void cMonster::HandleDaylightBurning(cChunk & a_Chunk) { if (!m_BurnsInDaylight) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 4d2e099c5..49d0cf9ef 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -5,6 +5,7 @@ #include "../Defines.h" #include "../BlockID.h" #include "../Item.h" +#include "../Enchantments.h" @@ -118,6 +119,19 @@ public: void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; } void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; } + float GetDropChanceWeapon() { return m_DropChanceWeapon; } + float GetDropChanceHelmet() { return m_DropChanceHelmet; } + float GetDropChanceChestplate() { return m_DropChanceChestplate; } + float GetDropChanceLeggings() { return m_DropChanceLeggings; } + float GetDropChanceBoots() { return m_DropChanceBoots; } + bool CanPickUpLoot() { return m_CanPickUpLoot; } + void SetDropChanceWeapon(float a_DropChanceWeapon) { m_DropChanceWeapon = a_DropChanceWeapon; } + void SetDropChanceHelmet(float a_DropChanceHelmet) { m_DropChanceHelmet = a_DropChanceHelmet; } + void SetDropChanceChestplate(float a_DropChanceChestplate) { m_DropChanceChestplate = a_DropChanceChestplate; } + void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; } + void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; } + void SetCanPickUpLoot(bool a_CanPickUpLoot) { m_CanPickUpLoot = a_CanPickUpLoot; } + /// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; } @@ -220,10 +234,31 @@ protected: float m_AttackInterval; int m_SightDistance; + float m_DropChanceWeapon; + float m_DropChanceHelmet; + float m_DropChanceChestplate; + float m_DropChanceLeggings; + float m_DropChanceBoots; + bool m_CanPickUpLoot; + void HandleDaylightBurning(cChunk & a_Chunk); bool m_BurnsInDaylight; + /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/ void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); + + /** Adds a item a_Item with the chance of a_Chance (in percent) to itemdrops a_Drops*/ + void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); + + /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/ + void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); + + /** Adds armor that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + void AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel); + + /** Adds weapon that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + void AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel); + } ; // tolua_export diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 88101cd83..8e4c52ae6 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -2,11 +2,12 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Mooshroom.h" +#include "../Entities/Player.h" + -// TODO: Milk Cow @@ -23,9 +24,50 @@ cMooshroom::cMooshroom(void) : void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_LEATHER); - AddRandomDropItem(a_Drops, 1, 3, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); + AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } + + +void cMooshroom::OnRightClicked(cPlayer & a_Player) +{ + switch (a_Player.GetEquippedItem().m_ItemType) + { + case E_ITEM_BUCKET: + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MILK); + } + } break; + case E_ITEM_BOWL: + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP); + } + } break; + case E_ITEM_SHEARS: + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.UseEquippedItem(); + } + + cItems Drops; + Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + } break; + } +} + diff --git a/src/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h index c94301098..16f6c8248 100644 --- a/src/Mobs/Mooshroom.h +++ b/src/Mobs/Mooshroom.h @@ -18,6 +18,7 @@ public: CLASS_PROTODEF(cMooshroom); virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + virtual void OnRightClicked(cPlayer & a_Player) override; virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } } ; diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index d8f3dda37..e862f5aaa 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -21,7 +21,12 @@ cPig::cPig(void) : void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 1, 3, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); if (m_bIsSaddled) { a_Drops.push_back(cItem(E_ITEM_SADDLE, 1)); diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 4c8e78988..47fcdbb26 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -20,8 +20,26 @@ cSkeleton::cSkeleton(bool IsWither) : void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_ARROW); - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_BONE); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + if (IsWither()) + { + AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_COAL); + cItems RareDrops; + RareDrops.Add(cItem(E_ITEM_HEAD, 1, 1)); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + } + else + { + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ARROW); + + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 19f376c21..52a52bb39 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -20,8 +20,15 @@ cSlime::cSlime(int a_Size) : void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - // TODO: only when tiny - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_SLIMEBALL); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + if (GetSize() == 1) + { + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL); + } } diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index c60103055..b68d18575 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -19,7 +19,7 @@ cSnowGolem::cSnowGolem(void) : void cSnowGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 5, E_ITEM_SNOWBALL); + AddRandomDropItem(a_Drops, 0, 15, E_ITEM_SNOWBALL); } diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index b19a5dcef..8b978ff6b 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -18,8 +18,16 @@ cSpider::cSpider(void) : void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_STRING); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_SPIDER_EYE); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + { + AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); + } } diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 5a27762ff..ba9171b39 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -21,7 +21,12 @@ cSquid::cSquid(void) : void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // Drops 0-3 Ink Sacs - AddRandomDropItem(a_Drops, 0, 3, E_ITEM_DYE, E_META_DYE_BLACK); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index 25d27041f..6956f7b7a 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -18,13 +18,28 @@ cWitch::cWitch(void) : void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_GLASS_BOTTLE); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_GLOWSTONE_DUST); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_GUNPOWDER); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_REDSTONE_DUST); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_SPIDER_EYE); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_STICK); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_SUGAR); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + MTRand r1; + int DropTypeCount = (r1.randInt() % 3) + 1; + for (int i = 0; i < DropTypeCount; i++) + { + int DropType = r1.randInt() % 7; + switch (DropType) + { + case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); break; + case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); break; + case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); break; + case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); break; + case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); break; + case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); break; + case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); break; + } + } + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Witch.h b/src/Mobs/Witch.h index 4e637beea..51c63322a 100644 --- a/src/Mobs/Witch.h +++ b/src/Mobs/Witch.h @@ -2,6 +2,7 @@ #pragma once #include "AggressiveMonster.h" +#include "../MersenneTwister.h" diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 27e8ed5fb..f19e096ee 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -23,9 +23,19 @@ cZombie::cZombie(bool a_IsVillagerZombie) : void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_ROTTEN_FLESH); - - // TODO: Rare drops + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); + cItems RareDrops; + RareDrops.Add(cItem(E_ITEM_IRON)); + RareDrops.Add(cItem(E_ITEM_CARROT)); + RareDrops.Add(cItem(E_ITEM_POTATO)); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index 6ac89ed4c..a0142b566 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -19,10 +19,19 @@ cZombiePigman::cZombiePigman(void) : void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_ROTTEN_FLESH); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_GOLD_NUGGET); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); - // TODO: Rare drops + cItems RareDrops; + RareDrops.Add(cItem(E_ITEM_GOLD)); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 2a1eda523..c1c659b36 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -409,6 +409,14 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) m_Writer.BeginCompound(""); AddBasicEntity(a_Monster, EntityClass); + m_Writer.BeginList("DropChances", TAG_Float); + m_Writer.AddFloat("", a_Monster->GetDropChanceWeapon()); + m_Writer.AddFloat("", a_Monster->GetDropChanceHelmet()); + m_Writer.AddFloat("", a_Monster->GetDropChanceChestplate()); + m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings()); + m_Writer.AddFloat("", a_Monster->GetDropChanceBoots()); + m_Writer.EndList(); + m_Writer.AddByte("CanPickUpLoot", (char)a_Monster->CanPickUpLoot()); switch (a_Monster->GetMobType()) { case cMonster::mtBat: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index d4490c7fe..05332d23d 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1485,6 +1485,11 @@ void cWSSAnvil::LoadBatFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1500,6 +1505,11 @@ void cWSSAnvil::LoadBlazeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1515,6 +1525,11 @@ void cWSSAnvil::LoadCaveSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1530,6 +1545,11 @@ void cWSSAnvil::LoadChickenFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1545,6 +1565,11 @@ void cWSSAnvil::LoadCowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1560,6 +1585,11 @@ void cWSSAnvil::LoadCreeperFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1575,6 +1605,11 @@ void cWSSAnvil::LoadEnderDragonFromNBT(cEntityList & a_Entities, const cParsedNB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1591,6 +1626,11 @@ void cWSSAnvil::LoadEndermanFromNBT(cEntityList & a_Entities, const cParsedNBT & return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -1606,6 +1646,11 @@ void cWSSAnvil::LoadGhastFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -1620,6 +1665,11 @@ void cWSSAnvil::LoadGiantFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1646,6 +1696,11 @@ void cWSSAnvil::LoadHorseFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1661,6 +1716,11 @@ void cWSSAnvil::LoadIronGolemFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1682,6 +1742,11 @@ void cWSSAnvil::LoadMagmaCubeFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1697,6 +1762,11 @@ void cWSSAnvil::LoadMooshroomFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1712,6 +1782,11 @@ void cWSSAnvil::LoadOcelotFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1727,6 +1802,11 @@ void cWSSAnvil::LoadPigFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1748,6 +1828,11 @@ void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1763,6 +1848,11 @@ void cWSSAnvil::LoadSilverfishFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1784,6 +1874,11 @@ void cWSSAnvil::LoadSkeletonFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1805,6 +1900,11 @@ void cWSSAnvil::LoadSlimeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1820,6 +1920,11 @@ void cWSSAnvil::LoadSnowGolemFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1835,6 +1940,11 @@ void cWSSAnvil::LoadSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1850,6 +1960,11 @@ void cWSSAnvil::LoadSquidFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1871,6 +1986,11 @@ void cWSSAnvil::LoadVillagerFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1886,6 +2006,11 @@ void cWSSAnvil::LoadWitchFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1901,6 +2026,11 @@ void cWSSAnvil::LoadWitherFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1916,6 +2046,10 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N { return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner"); if (OwnerIdx > 0) { @@ -1964,6 +2098,11 @@ void cWSSAnvil::LoadZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1980,6 +2119,11 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -2023,6 +2167,27 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N +bool cWSSAnvil::LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx) +{ + float DropChance[5]; + if (!LoadFloatsListFromNBT(DropChance, 5, a_NBT, a_NBT.FindChildByName(a_TagIdx, "DropChance"))) + { + return false; + } + a_Monster.SetDropChanceWeapon(DropChance[0]); + a_Monster.SetDropChanceHelmet(DropChance[1]); + a_Monster.SetDropChanceChestplate(DropChance[2]); + a_Monster.SetDropChanceLeggings(DropChance[3]); + a_Monster.SetDropChanceBoots(DropChance[4]); + bool CanPickUpLoot = (a_NBT.GetByte(a_NBT.FindChildByName(a_TagIdx, "CanPickUpLoot")) == 1); + a_Monster.SetCanPickUpLoot(CanPickUpLoot); + return true; +} + + + + + bool cWSSAnvil::LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx) { if (!LoadEntityBaseFromNBT(a_Entity, a_NBT, a_TagIdx)) @@ -2065,6 +2230,24 @@ bool cWSSAnvil::LoadDoublesListFromNBT(double * a_Doubles, int a_NumDoubles, con +bool cWSSAnvil::LoadFloatsListFromNBT(float * a_Floats, int a_NumFloats, const cParsedNBT & a_NBT, int a_TagIdx) +{ + if ((a_TagIdx < 0) || (a_NBT.GetType(a_TagIdx) != TAG_List) || (a_NBT.GetChildrenType(a_TagIdx) != TAG_Float)) + { + return false; + } + int idx = 0; + for (int Tag = a_NBT.GetFirstChild(a_TagIdx); (Tag > 0) && (idx < a_NumFloats); Tag = a_NBT.GetNextSibling(Tag), ++idx) + { + a_Floats[idx] = a_NBT.GetFloat(Tag); + } // for Tag - PosTag[] + return (idx == a_NumFloats); // Did we read enough doubles? +} + + + + + bool cWSSAnvil::GetBlockEntityNBTPos(const cParsedNBT & a_NBT, int a_TagIdx, int & a_X, int & a_Y, int & a_Z) { int x = a_NBT.FindChildByName(a_TagIdx, "x"); diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 541371560..4acf3f2a1 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -10,6 +10,7 @@ #include "WorldStorage.h" #include "FastNBT.h" +#include "../Mobs/Monster.h" @@ -194,12 +195,18 @@ protected: /// Loads entity common data from the NBT compound; returns true if successful bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads monster common data from the NBT compound; returns true if successful + bool LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads projectile common data from the NBT compound; returns true if successful bool LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIx); /// Loads an array of doubles of the specified length from the specified NBT list tag a_TagIdx; returns true if successful bool LoadDoublesListFromNBT(double * a_Doubles, int a_NumDoubles, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads an array of floats of the specified length from the specified NBT list tag a_TagIdx; returns true if successful + bool LoadFloatsListFromNBT(float * a_Floats, int a_NumFloats, const cParsedNBT & a_NBT, int a_TagIdx); + /// Helper function for extracting the X, Y, and Z int subtags of a NBT compound; returns true if successful bool GetBlockEntityNBTPos(const cParsedNBT & a_NBT, int a_TagIdx, int & a_X, int & a_Y, int & a_Z); -- cgit v1.2.3 From cc34898e45113df8ad7ae4b58debd2fe000f9622 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 23 Feb 2014 20:02:44 +0100 Subject: No Sword Block Destroying in Creative Mode --- src/ClientHandle.cpp | 10 ++++++++++ src/Items/ItemSword.h | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 3711262b6..38301b86f 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -32,6 +32,7 @@ #include "Protocol/ProtocolRecognizer.h" #include "CompositeChat.h" +#include "Items/ItemSword.h" @@ -794,6 +795,15 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc return; } + if ( + m_Player->IsGameModeCreative() && + cItemSwordHandler::IsSword(m_Player->GetInventory().GetEquippedItem().m_ItemType) + ) + { + // Players can't destroy blocks with a Sword in the hand. + return; + } + if (cRoot::Get()->GetPluginManager()->CallHookPlayerBreakingBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta)) { // A plugin doesn't agree with the breaking. Bail out. Send the block back to the client, so that it knows: diff --git a/src/Items/ItemSword.h b/src/Items/ItemSword.h index a7c1d2432..07d121d5c 100644 --- a/src/Items/ItemSword.h +++ b/src/Items/ItemSword.h @@ -23,6 +23,25 @@ public: { return (a_BlockType == E_BLOCK_COBWEB); } + + inline static bool IsSword(int id) + { + switch (id) + { + case E_ITEM_WOODEN_SWORD: + case E_ITEM_STONE_SWORD: + case E_ITEM_IRON_SWORD: + case E_ITEM_GOLD_SWORD: + case E_ITEM_DIAMOND_SWORD: + { + return true; + } + default: + { + return false; + } + } + } } ; -- cgit v1.2.3 From 084971424fcc258e6958c464ada3263f5b85a870 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 23 Feb 2014 20:31:58 +0100 Subject: Use the ItemCategorie::IsSword() Method. --- src/ClientHandle.cpp | 2 +- src/Items/ItemSword.h | 19 ------------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 38301b86f..4715eb100 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -797,7 +797,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc if ( m_Player->IsGameModeCreative() && - cItemSwordHandler::IsSword(m_Player->GetInventory().GetEquippedItem().m_ItemType) + ItemCategory::IsSword(m_Player->GetInventory().GetEquippedItem().m_ItemType) ) { // Players can't destroy blocks with a Sword in the hand. diff --git a/src/Items/ItemSword.h b/src/Items/ItemSword.h index 07d121d5c..a7c1d2432 100644 --- a/src/Items/ItemSword.h +++ b/src/Items/ItemSword.h @@ -23,25 +23,6 @@ public: { return (a_BlockType == E_BLOCK_COBWEB); } - - inline static bool IsSword(int id) - { - switch (id) - { - case E_ITEM_WOODEN_SWORD: - case E_ITEM_STONE_SWORD: - case E_ITEM_IRON_SWORD: - case E_ITEM_GOLD_SWORD: - case E_ITEM_DIAMOND_SWORD: - { - return true; - } - default: - { - return false; - } - } - } } ; -- cgit v1.2.3 From 462e0bcf46ce8e7c29e9f00ace58c2fcebffb8d1 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 23 Feb 2014 12:23:35 -0800 Subject: fixed globals.h warnings --- MCServer/Plugins/Core | 2 +- src/ChunkDef.h | 1 + src/LightingThread.h | 6 +++++- src/OSSupport/Queue.h | 6 +++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 3b416b07a..5c8557d4f 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 3b416b07a339b3abcbc127070d56eea05b05373d +Subproject commit 5c8557d4fdfa580c100510cde07a1a778ea2e244 diff --git a/src/ChunkDef.h b/src/ChunkDef.h index f48dc4fd5..7be2fa2df 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -92,6 +92,7 @@ public: /// Converts absolute block coords into relative (chunk + block) coords: inline static void AbsoluteToRelative(/* in-out */ int & a_X, int & a_Y, int & a_Z, /* out */ int & a_ChunkX, int & a_ChunkZ ) { + UNUSED(a_Y); BlockToChunk(a_X, a_Z, a_ChunkX, a_ChunkZ); a_X = a_X - a_ChunkX * Width; diff --git a/src/LightingThread.h b/src/LightingThread.h index 81dd9d61f..72d561348 100644 --- a/src/LightingThread.h +++ b/src/LightingThread.h @@ -82,7 +82,11 @@ protected: cLightingChunkStay(cLightingThread & a_LightingThread, int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallbackAfter); protected: - virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override {} + virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override + { + UNUSED(a_ChunkX); + UNUSED(a_ChunkZ); + } virtual bool OnAllChunksAvailable(void) override; virtual void OnDisabled(void) override; } ; diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index 6c3d58295..beb6a63f1 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -29,7 +29,11 @@ public: static void Delete(T) {}; /// Called when an Item is inserted with EnqueueItemIfNotPresent and there is another equal value already inserted - static void Combine(T & a_existing, const T & a_new) {}; + static void Combine(T & a_existing, const T & a_new) + { + UNUSED(a_existing); + UNUSED(a_new); + }; }; -- cgit v1.2.3 From e3f38b04fd77ce40ae476531766527cee75158c5 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 23 Feb 2014 12:25:48 -0800 Subject: Undid changing core --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 5c8557d4f..3b416b07a 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 5c8557d4fdfa580c100510cde07a1a778ea2e244 +Subproject commit 3b416b07a339b3abcbc127070d56eea05b05373d -- cgit v1.2.3 From 728e3c68b61e68d4cb73071cf04b44d268742aca Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 23 Feb 2014 16:30:49 +0100 Subject: Fixed a possible crash in cWorld::WakeUpSimulatorsInArea(). The Y coords weren't checked. --- src/ChunkMap.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index fbb8706e0..b5795fbaf 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -805,6 +805,10 @@ void cChunkMap::WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ) /// Wakes up the simulators for the specified area of blocks void cChunkMap::WakeUpSimulatorsInArea(int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ) { + // Limit the Y coords: + a_MinBlockY = std::max(a_MinBlockY, 0); + a_MaxBlockY = std::min(a_MaxBlockY, cChunkDef::Height - 1); + cSimulatorManager * SimMgr = m_World->GetSimulatorManager(); int MinChunkX, MinChunkZ, MaxChunkX, MaxChunkZ; cChunkDef::BlockToChunk(a_MinBlockX, a_MinBlockZ, MinChunkX, MinChunkZ); -- cgit v1.2.3 From 0aa8f765f99f14f6f1cc8260784213da60a3b946 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 24 Feb 2014 09:34:00 +0100 Subject: Fixed crash in cBlockArea rotation. Fixes #720. --- src/BlockArea.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 194e2d68a..df154d3af 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -878,7 +878,7 @@ void cBlockArea::RotateCCW(void) int NewX = z; for (int y = 0; y < m_SizeY; y++) { - int NewIdx = NewX + NewZ * m_SizeX + y * m_SizeX * m_SizeZ; + int NewIdx = NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ; int OldIdx = MakeIndex(x, y, z); NewTypes[NewIdx] = m_BlockTypes[OldIdx]; NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCCW(m_BlockMetas[OldIdx]); @@ -923,7 +923,7 @@ void cBlockArea::RotateCW(void) int NewX = m_SizeZ - z - 1; for (int y = 0; y < m_SizeY; y++) { - int NewIdx = NewX + NewZ * m_SizeX + y * m_SizeX * m_SizeZ; + int NewIdx = NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ; int OldIdx = MakeIndex(x, y, z); NewTypes[NewIdx] = m_BlockTypes[OldIdx]; NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCW(m_BlockMetas[OldIdx]); @@ -1075,7 +1075,7 @@ void cBlockArea::RotateCCWNoMeta(void) int NewX = z; for (int y = 0; y < m_SizeY; y++) { - NewTypes[NewX + NewZ * m_SizeX + y * m_SizeX * m_SizeZ] = m_BlockTypes[MakeIndex(x, y, z)]; + NewTypes[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockTypes[MakeIndex(x, y, z)]; } // for y } // for z } // for x @@ -1093,7 +1093,7 @@ void cBlockArea::RotateCCWNoMeta(void) int NewX = z; for (int y = 0; y < m_SizeY; y++) { - NewMetas[NewX + NewZ * m_SizeX + y * m_SizeX * m_SizeZ] = m_BlockMetas[MakeIndex(x, y, z)]; + NewMetas[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockMetas[MakeIndex(x, y, z)]; } // for y } // for z } // for x @@ -1120,7 +1120,7 @@ void cBlockArea::RotateCWNoMeta(void) int NewZ = x; for (int y = 0; y < m_SizeY; y++) { - NewTypes[NewX + NewZ * m_SizeX + y * m_SizeX * m_SizeZ] = m_BlockTypes[MakeIndex(x, y, z)]; + NewTypes[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockTypes[MakeIndex(x, y, z)]; } // for y } // for x } // for z @@ -1138,7 +1138,7 @@ void cBlockArea::RotateCWNoMeta(void) int NewZ = x; for (int y = 0; y < m_SizeY; y++) { - NewMetas[NewX + NewZ * m_SizeX + y * m_SizeX * m_SizeZ] = m_BlockMetas[MakeIndex(x, y, z)]; + NewMetas[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockMetas[MakeIndex(x, y, z)]; } // for y } // for x } // for z -- cgit v1.2.3 From 31d15f865456dd0419e5c765498344fdd99cf179 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 24 Feb 2014 09:34:20 +0100 Subject: Removed an unused member variable from cChunk. --- src/Chunk.cpp | 7 ------- src/Chunk.h | 1 - 2 files changed, 8 deletions(-) diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 4f301c209..8dfbbeef5 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -562,13 +562,6 @@ void cChunk::Tick(float a_Dt) { BroadcastPendingBlockChanges(); - // Unload the chunk from all clients that have queued unloading: - for (cClientHandleList::iterator itr = m_UnloadQuery.begin(), end = m_UnloadQuery.end(); itr != end; ++itr) - { - (*itr)->SendUnloadChunk(m_PosX, m_PosZ); - } - m_UnloadQuery.clear(); - // Set all blocks that have been queued for setting later: ProcessQueuedSetBlocks(); diff --git a/src/Chunk.h b/src/Chunk.h index 1b7a6fa07..c9e9697ca 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -405,7 +405,6 @@ private: // A critical section is not needed, because all chunk access is protected by its parent ChunkMap's csLayers cClientHandleList m_LoadedByClient; - cClientHandleList m_UnloadQuery; cEntityList m_Entities; cBlockEntityList m_BlockEntities; -- cgit v1.2.3 From 145b3492e7b27abb5a5a8aca1b37cb98ba03a772 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 24 Feb 2014 12:58:57 +0100 Subject: Small improvements to boats. --- src/Entities/Boat.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 67df201ce..94b24c5af 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -89,6 +89,7 @@ void cBoat::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); BroadcastMovementUpdate(); + SetSpeed(GetSpeed() * 0.97); // Slowly decrease the speed if ((POSY_TOINT < 0) || (POSY_TOINT > cChunkDef::Height)) @@ -98,7 +99,10 @@ void cBoat::Tick(float a_Dt, cChunk & a_Chunk) if (IsBlockWater(m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT))) { - SetSpeedY(1); + if (GetSpeedY() < 2) + { + AddSpeedY(0.2); + } } } @@ -108,12 +112,12 @@ void cBoat::Tick(float a_Dt, cChunk & a_Chunk) void cBoat::HandleSpeedFromAttachee(float a_Forward, float a_Sideways) { - if (GetSpeed().Length() > 7) + if (GetSpeed().Length() > 7.5) { return; } - Vector3d ToAddSpeed(m_Attachee->GetLookVector() * (a_Sideways * 1.5)); + Vector3d ToAddSpeed = m_Attachee->GetLookVector() * (a_Sideways * 0.4) ; ToAddSpeed.y = 0; AddSpeed(ToAddSpeed); -- cgit v1.2.3 From 9440b61c8c84dcc5b1348505f5e86d59be8a391d Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 24 Feb 2014 14:43:46 +0100 Subject: Fixed MCServer not compiling with C++03 compilers --- src/Items/ItemEmptyMap.h | 6 +++--- src/Map.cpp | 14 +++++++------- src/WorldStorage/MapSerializer.cpp | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index db28511f3..6618bfce2 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -36,10 +36,10 @@ public: // The map center is fixed at the central point of the 8x8 block of chunks you are standing in when you right-click it. - const int RegionWidth = cChunkDef::Width * 8 * pow(2, DEFAULT_SCALE); + const int RegionWidth = cChunkDef::Width * 8 * pow(2.0, (double) DEFAULT_SCALE); - int CenterX = round(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth; - int CenterZ = round(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth; + int CenterX = floor(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth; + int CenterZ = floor(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth; cMap * NewMap = a_World->GetMapManager().CreateMap(CenterX, CenterZ, DEFAULT_SCALE); diff --git a/src/Map.cpp b/src/Map.cpp index 2b8c4c74c..337c9cd31 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -51,8 +51,8 @@ void cMapDecorator::Update(void) int InsideWidth = (m_Map->GetWidth() / 2) - 1; int InsideHeight = (m_Map->GetHeight() / 2) - 1; - int PixelX = (m_Player->GetPosX() - m_Map->GetCenterX()) / PixelWidth; - int PixelZ = (m_Player->GetPosZ() - m_Map->GetCenterZ()) / PixelWidth; + int PixelX = (int) (m_Player->GetPosX() - m_Map->GetCenterX()) / PixelWidth; + int PixelZ = (int) (m_Player->GetPosZ() - m_Map->GetCenterZ()) / PixelWidth; // Center of pixel m_PixelX = (2 * PixelX) + 1; @@ -69,11 +69,11 @@ void cMapDecorator::Update(void) Int64 WorldAge = m_Player->GetWorld()->GetWorldAge(); // TODO 2014-02-19 xdot: Refine - m_Rot = Random.NextInt(16, WorldAge); + m_Rot = Random.NextInt(16, (int) WorldAge); } else { - m_Rot = (Yaw * 16) / 360; + m_Rot = (int) (Yaw * 16) / 360; } m_Type = E_TYPE_PLAYER; @@ -183,8 +183,8 @@ void cMap::UpdateRadius(cPlayer & a_Player, unsigned int a_Radius) { unsigned int PixelWidth = GetPixelWidth(); - int PixelX = (a_Player.GetPosX() - m_CenterX) / PixelWidth + (m_Width / 2); - int PixelZ = (a_Player.GetPosZ() - m_CenterZ) / PixelWidth + (m_Height / 2); + int PixelX = (int) (a_Player.GetPosX() - m_CenterX) / PixelWidth + (m_Width / 2); + int PixelZ = (int) (a_Player.GetPosZ() - m_CenterZ) / PixelWidth + (m_Height / 2); UpdateRadius(PixelX, PixelZ, a_Radius); } @@ -620,7 +620,7 @@ unsigned int cMap::GetNumDecorators(void) const unsigned int cMap::GetPixelWidth(void) const { - return pow(2, m_Scale); + return (int) pow(2.0, (double) m_Scale); } diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp index 0bbe71a60..a4a0aab57 100644 --- a/src/WorldStorage/MapSerializer.cpp +++ b/src/WorldStorage/MapSerializer.cpp @@ -112,7 +112,7 @@ void cMapSerializer::SaveMapToNBT(cFastNBTWriter & a_Writer) a_Writer.AddInt("zCenter", m_Map->GetCenterZ()); const cMap::cColorList & Data = m_Map->GetData(); - a_Writer.AddByteArray("colors", (char *) Data.data(), Data.size()); + a_Writer.AddByteArray("colors", (char *) &Data[0], Data.size()); a_Writer.EndCompound(); } @@ -178,7 +178,7 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT) CurrLine = a_NBT.FindChildByName(Data, "colors"); if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_ByteArray)) { - memcpy(m_Map->m_Data.data(), a_NBT.GetData(CurrLine), NumPixels); + memcpy(&m_Map->m_Data[0], a_NBT.GetData(CurrLine), NumPixels); } return true; -- cgit v1.2.3 From 0b6aa7b3708b4651ecea5c2bdd58fb0ccb430cbc Mon Sep 17 00:00:00 2001 From: TheJumper Date: Mon, 24 Feb 2014 15:38:38 +0100 Subject: Fixed Formatting, added compiler warning suppressing methods, fixed comments --- src/Mobs/IronGolem.cpp | 1 + src/Mobs/Magmacube.cpp | 1 + src/Mobs/Monster.cpp | 2 +- src/Mobs/Monster.h | 4 ++-- src/Mobs/SnowGolem.cpp | 1 + 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Mobs/IronGolem.cpp b/src/Mobs/IronGolem.cpp index 057834afd..dae4615e4 100644 --- a/src/Mobs/IronGolem.cpp +++ b/src/Mobs/IronGolem.cpp @@ -18,6 +18,7 @@ cIronGolem::cIronGolem(void) : void cIronGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) { + UNUSED(a_Killer); AddRandomDropItem(a_Drops, 0, 5, E_ITEM_IRON); AddRandomDropItem(a_Drops, 0, 2, E_BLOCK_FLOWER); } diff --git a/src/Mobs/Magmacube.cpp b/src/Mobs/Magmacube.cpp index ec6137ca6..05405f082 100644 --- a/src/Mobs/Magmacube.cpp +++ b/src/Mobs/Magmacube.cpp @@ -19,6 +19,7 @@ cMagmaCube::cMagmaCube(int a_Size) : void cMagmaCube::GetDrops(cItems & a_Drops, cEntity * a_Killer) { + UNUSED(a_Killer); if (GetSize() > 1) { AddRandomUncommonDropItem(a_Drops, 25.0f, E_ITEM_MAGMA_CREAM); diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 4ab485321..ac9137ccd 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -81,13 +81,13 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_AttackDamage(1) , m_AttackRange(2) , m_AttackInterval(0) + , m_SightDistance(25) , m_DropChanceWeapon(0.085) , m_DropChanceHelmet(0.085) , m_DropChanceChestplate(0.085) , m_DropChanceLeggings(0.085) , m_DropChanceBoots(0.085) , m_CanPickUpLoot(true) - , m_SightDistance(25) , m_BurnsInDaylight(false) { if (!a_ConfigName.empty()) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 49d0cf9ef..776426a0d 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -253,10 +253,10 @@ protected: /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/ void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); - /** Adds armor that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + /** Adds armor that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if piccked up or 0.085 + (0.01 per LootingLevel) if born with) to the drop*/ void AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel); - /** Adds weapon that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + /** Adds weapon that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if piccked up or 0.085 + (0.01 per LootingLevel) if born with) to the drop*/ void AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel); diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index b68d18575..67e3a3bb8 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -19,6 +19,7 @@ cSnowGolem::cSnowGolem(void) : void cSnowGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) { + UNUSED(a_Killer); AddRandomDropItem(a_Drops, 0, 15, E_ITEM_SNOWBALL); } -- cgit v1.2.3 From df193c8f6f414525850092b2705343605cb74137 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 24 Feb 2014 11:29:59 -0800 Subject: BlockEntities is warnings free --- src/BlockEntities/CommandBlockEntity.cpp | 2 ++ src/BlockEntities/DropSpenserEntity.cpp | 1 + src/BlockEntities/FurnaceEntity.cpp | 6 ++++-- src/BlockEntities/FurnaceEntity.h | 2 +- src/BlockEntities/HopperEntity.cpp | 2 ++ src/BlockEntities/NoteEntity.cpp | 1 + 6 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp index 0bc6ca359..687f75c95 100644 --- a/src/BlockEntities/CommandBlockEntity.cpp +++ b/src/BlockEntities/CommandBlockEntity.cpp @@ -126,6 +126,8 @@ void cCommandBlockEntity::SetRedstonePower(bool a_IsPowered) bool cCommandBlockEntity::Tick(float a_Dt, cChunk & a_Chunk) { + UNUSED(a_Dt); + UNUSED(a_Chunk); if (!m_ShouldExecute) { return false; diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp index 81df0fc8c..0012742fb 100644 --- a/src/BlockEntities/DropSpenserEntity.cpp +++ b/src/BlockEntities/DropSpenserEntity.cpp @@ -129,6 +129,7 @@ void cDropSpenserEntity::SetRedstonePower(bool a_IsPowered) bool cDropSpenserEntity::Tick(float a_Dt, cChunk & a_Chunk) { + UNUSED(a_Dt); if (!m_ShouldDropSpense) { return false; diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp index c6643bcff..7d6d1f89e 100644 --- a/src/BlockEntities/FurnaceEntity.cpp +++ b/src/BlockEntities/FurnaceEntity.cpp @@ -94,6 +94,8 @@ bool cFurnaceEntity::ContinueCooking(void) bool cFurnaceEntity::Tick(float a_Dt, cChunk & a_Chunk) { + UNUSED(a_Dt); + UNUSED(a_Chunk); if (m_FuelBurnTime <= 0) { // No fuel is burning, reset progressbars and bail out @@ -110,7 +112,7 @@ bool cFurnaceEntity::Tick(float a_Dt, cChunk & a_Chunk) if (m_TimeCooked >= m_NeedCookTime) { // Finished smelting one item - FinishOne(a_Chunk); + FinishOne(); } } @@ -208,7 +210,7 @@ void cFurnaceEntity::BroadcastProgress(int a_ProgressbarID, short a_Value) /// One item finished cooking -void cFurnaceEntity::FinishOne(cChunk & a_Chunk) +void cFurnaceEntity::FinishOne() { m_TimeCooked = 0; diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h index 5e08ae37a..4f935a74b 100644 --- a/src/BlockEntities/FurnaceEntity.h +++ b/src/BlockEntities/FurnaceEntity.h @@ -126,7 +126,7 @@ protected: void BroadcastProgress(int a_ProgressbarID, short a_Value); /// One item finished cooking - void FinishOne(cChunk & a_Chunk); + void FinishOne(); /// Starts burning a new fuel, if possible void BurnNewFuel(void); diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 31b23ac99..729d3a2cc 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -58,6 +58,7 @@ bool cHopperEntity::GetOutputBlockPos(NIBBLETYPE a_BlockMeta, int & a_OutputX, i bool cHopperEntity::Tick(float a_Dt, cChunk & a_Chunk) { + UNUSED(a_Dt); Int64 CurrentTick = a_Chunk.GetWorld()->GetWorldAge(); bool res = false; @@ -73,6 +74,7 @@ bool cHopperEntity::Tick(float a_Dt, cChunk & a_Chunk) void cHopperEntity::SaveToJson(Json::Value & a_Value) { + UNUSED(a_Value); // TODO LOGWARNING("%s: Not implemented yet", __FUNCTION__); } diff --git a/src/BlockEntities/NoteEntity.cpp b/src/BlockEntities/NoteEntity.cpp index 9a33ead62..58b05a324 100644 --- a/src/BlockEntities/NoteEntity.cpp +++ b/src/BlockEntities/NoteEntity.cpp @@ -21,6 +21,7 @@ cNoteEntity::cNoteEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_Wo void cNoteEntity::UsedBy(cPlayer * a_Player) { + UNUSED(a_Player); IncrementPitch(); MakeSound(); } -- cgit v1.2.3 From 46f6cef99fdfbca1f713b15ac9ef1e958f9c4d41 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 24 Feb 2014 22:47:58 +0100 Subject: Fixed compilation in MSVC (forward class definitions). --- src/BlockEntities/CommandBlockEntity.cpp | 1 + src/BlockEntities/HopperEntity.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp index 687f75c95..d395997a6 100644 --- a/src/BlockEntities/CommandBlockEntity.cpp +++ b/src/BlockEntities/CommandBlockEntity.cpp @@ -12,6 +12,7 @@ #include "../CommandOutput.h" #include "../Root.h" #include "../Server.h" // ExecuteConsoleCommand() +#include "../Chunk.h" diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 729d3a2cc..af7043767 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -13,6 +13,7 @@ #include "DropSpenserEntity.h" #include "FurnaceEntity.h" #include "../BoundingBox.h" +#include "json/json.h" -- cgit v1.2.3 From f96801290ed658997d8388e825a52e9cb195045b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 24 Feb 2014 22:52:55 +0100 Subject: Fixed tolua export for Byte. No longer treated as an unknown class. --- src/Bindings/AllToLua.pkg | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 4fd5a68b8..6537437cd 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -87,3 +87,10 @@ class cLineBlockTracer; + +// To avoid tolua treating Byte as a class, and avoid the need to $cfile entire Globals.h: +typedef unsigned char Byte; + + + + -- cgit v1.2.3 From 9ab766189d6330988db190ddecd386d7c58d47b6 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 24 Feb 2014 23:17:12 +0100 Subject: Added useful parameter overloads to cBlockArea Lua API. --- MCServer/Plugins/APIDump/APIDesc.lua | 37 +++++++++++--- src/BlockArea.cpp | 95 ++++++++++++++++++++++++++++++++++++ src/BlockArea.h | 38 +++++++++++++++ 3 files changed, 164 insertions(+), 6 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 1fffbfcd0..47686e1e8 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -104,7 +104,11 @@ g_APIDesc = DumpToRawFile = { Params = "FileName", Return = "", Notes = "Dumps the raw data into a file. For debugging purposes only." }, Expand = { Params = "SubMinX, AddMaxX, SubMinY, AddMaxY, SubMinZ, AddMaxZ", Return = "", Notes = "Expands the specified number of blocks from each border. Modifies the size of this blockarea object. New blocks created with this operation are filled with zeroes." }, Fill = { Params = "DataTypes, BlockType, [BlockMeta], [BlockLight], [BlockSkyLight]", Return = "", Notes = "Fills the entire block area with the same values, specified. Uses the DataTypes param to determine which content types are modified." }, - FillRelCuboid = { Params = "MinRelX, MaxRelX, MinRelY, MaxRelY, MinRelZ, MaxRelZ, DataTypes, BlockType, [BlockMeta], [BlockLight], [BlockSkyLight]", Return = "", Notes = "Fills the specified cuboid with the same values (like Fill() )." }, + FillRelCuboid = + { + { Params = "{{cCuboid|RelCuboid}}, DataTypes, BlockType, [BlockMeta], [BlockLight], [BlockSkyLight]", Return = "", Notes = "Fills the specified cuboid (in relative coords) with the same values (like Fill() )." }, + { Params = "MinRelX, MaxRelX, MinRelY, MaxRelY, MinRelZ, MaxRelZ, DataTypes, BlockType, [BlockMeta], [BlockLight], [BlockSkyLight]", Return = "", Notes = "Fills the specified cuboid with the same values (like Fill() )." }, + }, GetBlockLight = { Params = "BlockX, BlockY, BlockZ", Return = "NIBBLETYPE", Notes = "Returns the blocklight at the specified absolute coords" }, GetBlockMeta = { Params = "BlockX, BlockY, BlockZ", Return = "NIBBLETYPE", Notes = "Returns the block meta at the specified absolute coords" }, GetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ", Return = "NIBBLETYPE", Notes = "Returns the skylight at the specified absolute coords" }, @@ -130,15 +134,28 @@ g_APIDesc = HasBlockSkyLights = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include skylight" }, HasBlockTypes = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include block types" }, LoadFromSchematicFile = { Params = "FileName", Return = "", Notes = "Clears current content and loads new content from the specified schematic file. Returns true if successful. Returns false and logs error if unsuccessful, old content is preserved in such a case." }, - Merge = { Params = "BlockAreaSrc, RelX, RelY, RelZ, Strategy", Return = "", Notes = "Merges BlockAreaSrc into this object at the specified relative coords, using the specified strategy" }, + Merge = + { + { Params = "BlockAreaSrc, {{Vector3i|RelMinCoords}}, Strategy", Return = "", Notes = "Merges BlockAreaSrc into this object at the specified relative coords, using the specified strategy" }, + { Params = "BlockAreaSrc, RelX, RelY, RelZ, Strategy", Return = "", Notes = "Merges BlockAreaSrc into this object at the specified relative coords, using the specified strategy" }, + }, MirrorXY = { Params = "", Return = "", Notes = "Mirrors this block area around the XY plane. Modifies blocks' metas (if present) to match (i. e. furnaces facing the opposite direction)." }, MirrorXYNoMeta = { Params = "", Return = "", Notes = "Mirrors this block area around the XY plane. Doesn't modify blocks' metas." }, MirrorXZ = { Params = "", Return = "", Notes = "Mirrors this block area around the XZ plane. Modifies blocks' metas (if present)" }, MirrorXZNoMeta = { Params = "", Return = "", Notes = "Mirrors this block area around the XZ plane. Doesn't modify blocks' metas." }, MirrorYZ = { Params = "", Return = "", Notes = "Mirrors this block area around the YZ plane. Modifies blocks' metas (if present)" }, MirrorYZNoMeta = { Params = "", Return = "", Notes = "Mirrors this block area around the YZ plane. Doesn't modify blocks' metas." }, - Read = { Params = "World, MinX, MaxX, MinY, MaxY, MinZ, MaxZ, DataTypes", Return = "bool", Notes = "Reads the area from World, returns true if successful" }, - RelLine = { Params = "RelX1, RelY1, RelZ1, RelX2, RelY2, RelZ2, DataTypes, BlockType, [BlockMeta], [BlockLight], [BlockSkyLight]", Return = "", Notes = "Draws a line between the two specified points. Sets only datatypes specified by DataTypes." }, + Read = + { + { Params = "World, {{cCuboid|Cuboid}}, DataTypes", Return = "bool", Notes = "Reads the area from World, returns true if successful" }, + { Params = "World, {{Vector3i|Point1}}, {{Vector3i|Point2}}, DataTypes", Return = "bool", Notes = "Reads the area from World, returns true if successful" }, + { Params = "World, X1, X2, Y1, Y2, Z1, Z2, DataTypes", Return = "bool", Notes = "Reads the area from World, returns true if successful" }, + }, + RelLine = + { + { Params = "{{Vector3i|RelPoint1}}, {{Vector3i|RelPoint2}}, DataTypes, BlockType, [BlockMeta], [BlockLight], [BlockSkyLight]", Return = "", Notes = "Draws a line between the two specified points. Sets only datatypes specified by DataTypes (baXXX constants)." }, + { Params = "RelX1, RelY1, RelZ1, RelX2, RelY2, RelZ2, DataTypes, BlockType, [BlockMeta], [BlockLight], [BlockSkyLight]", Return = "", Notes = "Draws a line between the two specified points. Sets only datatypes specified by DataTypes (baXXX constants)." }, + }, RotateCCW = { Params = "", Return = "", Notes = "Rotates the block area around the Y axis, counter-clockwise (east -> north). Modifies blocks' metas (if present) to match." }, RotateCCWNoMeta = { Params = "", Return = "", Notes = "Rotates the block area around the Y axis, counter-clockwise (east -> north). Doesn't modify blocks' metas." }, RotateCW = { Params = "", Return = "", Notes = "Rotates the block area around the Y axis, clockwise (north -> east). Modifies blocks' metas (if present) to match." }, @@ -149,13 +166,21 @@ g_APIDesc = SetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified absolute coords" }, SetBlockType = { Params = "BlockX, BlockY, BlockZ, BlockType", Return = "", Notes = "Sets the block type at the specified absolute coords" }, SetBlockTypeMeta = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block type and meta at the specified absolute coords" }, - SetOrigin = { Params = "OriginX, OriginY, OriginZ", Return = "", Notes = "Resets the origin for the absolute coords. Only affects how absolute coords are translated into relative coords." }, + SetOrigin = + { + { Params = "{{Vector3i|Origin}}", Return = "", Notes = "Resets the origin for the absolute coords. Only affects how absolute coords are translated into relative coords." }, + { Params = "OriginX, OriginY, OriginZ", Return = "", Notes = "Resets the origin for the absolute coords. Only affects how absolute coords are translated into relative coords." }, + }, SetRelBlockLight = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockLight", Return = "", Notes = "Sets the blocklight at the specified relative coords" }, SetRelBlockMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockMeta", Return = "", Notes = "Sets the block meta at the specified relative coords" }, SetRelBlockSkyLight = { Params = "RelBlockX, RelBlockY, RelBlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified relative coords" }, SetRelBlockType = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockType", Return = "", Notes = "Sets the block type at the specified relative coords" }, SetRelBlockTypeMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block type and meta at the specified relative coords" }, - Write = { Params = "World, MinX, MinY, MinZ, DataTypes", Return = "bool", Notes = "Writes the area into World at the specified coords, returns true if successful" }, + Write = + { + { Params = "World, {{Vector3i|MinPoint}}, DataTypes", Return = "bool", Notes = "Writes the area into World at the specified coords, returns true if successful" }, + { Params = "World, MinX, MinY, MinZ, DataTypes", Return = "bool", Notes = "Writes the area into World at the specified coords, returns true if successful" }, + }, }, Constants = { diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index df154d3af..d07ef747a 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -8,6 +8,7 @@ #include "BlockArea.h" #include "OSSupport/GZipFile.h" #include "Blocks/BlockHandler.h" +#include "Cuboid.h" @@ -264,6 +265,15 @@ void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ) +void cBlockArea::SetOrigin(const Vector3i & a_Origin) +{ + SetOrigin(a_Origin.x, a_Origin.y, a_Origin.z); +} + + + + + bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes) { // Normalize the coords: @@ -338,6 +348,36 @@ bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinB +bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, const cCuboid & a_Bounds, int a_DataTypes) +{ + return Read( + a_ForEachChunkProvider, + a_Bounds.p1.x, a_Bounds.p2.x, + a_Bounds.p1.y, a_Bounds.p2.y, + a_Bounds.p1.z, a_Bounds.p2.z, + a_DataTypes + ); +} + + + + + +bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, const Vector3i & a_Point1, const Vector3i & a_Point2, int a_DataTypes) +{ + return Read( + a_ForEachChunkProvider, + a_Point1.x, a_Point2.x, + a_Point1.y, a_Point2.y, + a_Point1.z, a_Point2.z, + a_DataTypes + ); +} + + + + + bool cBlockArea::Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) { ASSERT((a_DataTypes & GetDataTypes()) == a_DataTypes); // Are you requesting only the data that I have? @@ -362,6 +402,19 @@ bool cBlockArea::Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_Min +bool cBlockArea::Write(cForEachChunkProvider * a_ForEachChunkProvider, const Vector3i & a_MinCoords, int a_DataTypes) +{ + return Write( + a_ForEachChunkProvider, + a_MinCoords.x, a_MinCoords.y, a_MinCoords.z, + a_DataTypes + ); +} + + + + + void cBlockArea::CopyTo(cBlockArea & a_Into) const { if (&a_Into == this) @@ -643,6 +696,15 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R +void cBlockArea::Merge(const cBlockArea & a_Src, const Vector3i & a_RelMinCoords, eMergeStrategy a_Strategy) +{ + Merge(a_Src, a_RelMinCoords.x, a_RelMinCoords.y, a_RelMinCoords.z, a_Strategy); +} + + + + + void cBlockArea::Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight) { if ((a_DataTypes & GetDataTypes()) != a_DataTypes) @@ -735,6 +797,23 @@ void cBlockArea::FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int +void cBlockArea::FillRelCuboid(const cCuboid & a_RelCuboid, + int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, + NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight +) +{ + FillRelCuboid( + a_RelCuboid.p1.x, a_RelCuboid.p2.x, + a_RelCuboid.p1.y, a_RelCuboid.p2.y, + a_RelCuboid.p1.z, a_RelCuboid.p2.z, + a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight + ); +} + + + + + void cBlockArea::RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int a_RelY2, int a_RelZ2, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight @@ -852,6 +931,22 @@ void cBlockArea::RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int +void cBlockArea::RelLine(const Vector3i & a_Point1, const Vector3i & a_Point2, + int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, + NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight +) +{ + RelLine( + a_Point1.x, a_Point1.y, a_Point1.z, + a_Point2.x, a_Point2.y, a_Point2.z, + a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight + ); +} + + + + + void cBlockArea::RotateCCW(void) { if (!HasBlockTypes()) diff --git a/src/BlockArea.h b/src/BlockArea.h index 5ef814d0e..0703f195e 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -15,6 +15,16 @@ #include "ForEachChunkProvider.h" + + +// fwd: +class cCuboid; +class Vector3i; + + + + + // tolua_begin class cBlockArea { @@ -56,15 +66,27 @@ public: /** Resets the origin. No other changes are made, contents are untouched. */ void SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ); + /** Resets the origin. No other changes are made, contents are untouched. */ + void SetOrigin(const Vector3i & a_Origin); + /** Reads an area of blocks specified. Returns true if successful. All coords are inclusive. */ bool Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes = baTypes | baMetas); + /** Reads an area of blocks specified. Returns true if successful. The bounds are included in the read area. */ + bool Read(cForEachChunkProvider * a_ForEachChunkProvider, const cCuboid & a_Bounds, int a_DataTypes = baTypes | baMetas); + + /** Reads an area of blocks specified. Returns true if successful. The bounds are included in the read area. */ + bool Read(cForEachChunkProvider * a_ForEachChunkProvider, const Vector3i & a_Point1, const Vector3i & a_Point2, int a_DataTypes = baTypes | baMetas); + // TODO: Write() is not too good an interface: if it fails, there's no way to repeat only for the parts that didn't write // A better way may be to return a list of cBlockAreas for each part that didn't succeed writing, so that the caller may try again /** Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all */ bool Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes = baTypes | baMetas); + /** Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all */ + bool Write(cForEachChunkProvider * a_ForEachChunkProvider, const Vector3i & a_MinCoords, int a_DataTypes = baTypes | baMetas); + /** Copies this object's contents into the specified BlockArea. */ void CopyTo(cBlockArea & a_Into) const; @@ -117,6 +139,10 @@ public: */ void Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy); + /** Merges another block area into this one, using the specified block combinating strategy. + See Merge() above for details. */ + void Merge(const cBlockArea & a_Src, const Vector3i & a_RelMinCoords, eMergeStrategy a_Strategy); + /** Fills the entire block area with the specified data */ void Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f); @@ -126,12 +152,24 @@ public: NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f ); + /** Fills a cuboid inside the block area with the specified data. a_Cuboid must be sorted. */ + void FillRelCuboid(const cCuboid & a_RelCuboid, + int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, + NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f + ); + /** Draws a line from between two points with the specified data */ void RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int a_RelY2, int a_RelZ2, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f ); + /** Draws a line from between two points with the specified data */ + void RelLine(const Vector3i & a_Point1, const Vector3i & a_Point2, + int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, + NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f + ); + /** Rotates the entire area counter-clockwise around the Y axis */ void RotateCCW(void); -- cgit v1.2.3 From 0d8ab184e0d52fe75cac31ae6fc403e28af685ba Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 25 Feb 2014 18:15:09 +0100 Subject: InfoReg: Subcommand aliases are handled properly. --- MCServer/Plugins/InfoReg.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/InfoReg.lua b/MCServer/Plugins/InfoReg.lua index 3afb57488..1cf68dbed 100644 --- a/MCServer/Plugins/InfoReg.lua +++ b/MCServer/Plugins/InfoReg.lua @@ -85,6 +85,10 @@ function RegisterPluginInfoCommands() local function RegisterSubcommands(a_Prefix, a_Subcommands, a_Level) assert(a_Subcommands ~= nil); + -- A table that will hold aliases to subcommands temporarily, during subcommand iteration + local AliasTable = {} + + -- Iterate through the subcommands, register them, and accumulate aliases: for cmd, info in pairs(a_Subcommands) do local CmdName = a_Prefix .. cmd; local Handler = info.Handler; @@ -112,15 +116,25 @@ function RegisterPluginInfoCommands() end for idx, alias in ipairs(info.Alias) do cPluginManager.BindCommand(a_Prefix .. alias, info.Permission or "", Handler, HelpString); + -- Also copy the alias's info table as a separate subcommand, + -- so that MultiCommandHandler() handles it properly. Need to off-load into a separate table + -- than the one we're currently iterating and join after the iterating. + AliasTable[alias] = info end end - end + end -- else (if Handler == nil) -- Recursively register any subcommands: if (info.Subcommands ~= nil) then RegisterSubcommands(a_Prefix .. cmd .. " ", info.Subcommands, a_Level + 1); end + end -- for cmd, info - a_Subcommands[] + + -- Add the subcommand aliases that were off-loaded during registration: + for alias, info in pairs(AliasTable) do + a_Subcommands[alias] = info end + AliasTable = {} end -- Loop through all commands in the plugin info, register each: -- cgit v1.2.3 From 5cceca7fbcda49fd803d8b31728a926a6b29e49c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 26 Feb 2014 20:22:34 +0100 Subject: Added more utility functions to cCuboid. GetVolume(), Expand(), ClampX(), ClampY(), ClampZ() --- src/Cuboid.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Cuboid.h | 27 ++++++++++++++++--- 2 files changed, 105 insertions(+), 4 deletions(-) diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp index ea6f7c453..782837b23 100644 --- a/src/Cuboid.cpp +++ b/src/Cuboid.cpp @@ -58,6 +58,18 @@ void cCuboid::Sort(void) +int cCuboid::GetVolume(void) const +{ + int DifX = abs(p2.x - p1.x) + 1; + int DifY = abs(p2.y - p1.y) + 1; + int DifZ = abs(p2.z - p1.z) + 1; + return DifX * DifY * DifZ; +} + + + + + bool cCuboid::DoesIntersect(const cCuboid & a_Other) const { // In order for cuboids to intersect, each of their coord intervals need to intersect @@ -103,6 +115,76 @@ void cCuboid::Move(int a_OfsX, int a_OfsY, int a_OfsZ) +void cCuboid::Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ) +{ + if (p1.x < p2.x) + { + p1.x -= a_SubMinX; + p2.x += a_AddMaxX; + } + else + { + p2.x -= a_SubMinX; + p1.x += a_AddMaxX; + } + + if (p1.y < p2.y) + { + p1.y -= a_SubMinY; + p2.y += a_AddMaxY; + } + else + { + p2.y -= a_SubMinY; + p1.y += a_AddMaxY; + } + + if (p1.z < p2.z) + { + p1.z -= a_SubMinZ; + p2.z += a_AddMaxZ; + } + else + { + p2.z -= a_SubMinZ; + p1.z += a_AddMaxZ; + } +} + + + + + +void cCuboid::ClampX(int a_MinX, int a_MaxX) +{ + p1.x = Clamp(p1.x, a_MinX, a_MaxX); + p2.x = Clamp(p2.x, a_MinX, a_MaxX); +} + + + + + +void cCuboid::ClampY(int a_MinY, int a_MaxY) +{ + p1.y = Clamp(p1.y, a_MinY, a_MaxY); + p2.y = Clamp(p2.y, a_MinY, a_MaxY); +} + + + + + +void cCuboid::ClampZ(int a_MinZ, int a_MaxZ) +{ + p1.z = Clamp(p1.z, a_MinZ, a_MaxZ); + p2.z = Clamp(p2.z, a_MinZ, a_MaxZ); +} + + + + + bool cCuboid::IsSorted(void) const { return ( diff --git a/src/Cuboid.h b/src/Cuboid.h index 44db7b98e..51ccf799b 100644 --- a/src/Cuboid.h +++ b/src/Cuboid.h @@ -29,7 +29,12 @@ public: int DifY(void) const { return p2.y - p1.y; } int DifZ(void) const { return p2.z - p1.z; } - /// Returns true if the cuboids have at least one voxel in common. Both coords are considered inclusive. + /** Returns the volume of the cuboid, in blocks. + Note that the volume considers both coords inclusive. + Works on unsorted cuboids, too. */ + int GetVolume(void) const; + + /** Returns true if the cuboids have at least one voxel in common. Both coords are considered inclusive. */ bool DoesIntersect(const cCuboid & a_Other) const; bool IsInside(const Vector3i & v) const @@ -59,13 +64,27 @@ public: ); } - /// Returns true if this cuboid is completely inside the specifie cuboid (in all 6 coords) + /** Returns true if this cuboid is completely inside the specifie cuboid (in all 6 coords) */ bool IsCompletelyInside(const cCuboid & a_Outer) const; - /// Moves the cuboid by the specified offsets in each direction + /** Moves the cuboid by the specified offsets in each direction */ void Move(int a_OfsX, int a_OfsY, int a_OfsZ); + + /** Expands the cuboid by the specified amount in each direction. + Works on unsorted cuboids as well. + Note that this function doesn't check for underflows. */ + void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ); + + /** Clamps both X coords to the specified range. Works on unsorted cuboids, too. */ + void ClampX(int a_MinX, int a_MaxX); + + /** Clamps both Y coords to the specified range. Works on unsorted cuboids, too. */ + void ClampY(int a_MinY, int a_MaxY); + + /** Clamps both Z coords to the specified range. Works on unsorted cuboids, too. */ + void ClampZ(int a_MinZ, int a_MaxZ); - /// Returns true if the coords are properly sorted (lesser in p1, greater in p2) + /** Returns true if the coords are properly sorted (lesser in p1, greater in p2) */ bool IsSorted(void) const; } ; // tolua_end -- cgit v1.2.3 From 50b664fd0c5655827cc16e12f1ad6e9e796a8e3d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 26 Feb 2014 20:38:51 +0100 Subject: APIDump: Separated out Geometry-related classes to their own file. --- MCServer/Plugins/APIDump/APIDesc.lua | 301 ------------------------ MCServer/Plugins/APIDump/Classes/Geometry.lua | 320 ++++++++++++++++++++++++++ 2 files changed, 320 insertions(+), 301 deletions(-) create mode 100644 MCServer/Plugins/APIDump/Classes/Geometry.lua diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 47686e1e8..c6221f30d 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -290,45 +290,6 @@ g_APIDesc = }, -- AdditionalInfo }, -- cBlockArea - cBoundingBox = - { - Desc = [[ - Represents two sets of coordinates, minimum and maximum for each direction; thus defining an - axis-aligned cuboid with floating-point boundaries. It supports operations changing the size and - position of the box, as well as querying whether a point or another BoundingBox is inside the box.

    -

    - All the points within the coordinate limits (inclusive the edges) are considered "inside" the box. - However, for intersection purposes, if the intersection is "sharp" in any coord (min1 == max2, i. e. - zero volume), the boxes are considered non-intersecting.

    - ]], - Functions = - { - constructor = - { - { Params = "MinX, MaxX, MinY, MaxY, MinZ, MaxZ", Return = "cBoundingBox", Notes = "Creates a new bounding box with the specified edges" }, - { Params = "{{Vector3d|Min}}, {{Vector3d|Max}}", Return = "cBoundingBox", Notes = "Creates a new bounding box with the coords specified as two vectors" }, - { Params = "{{Vector3d|Pos}}, Radius, Height", Return = "cBoundingBox", Notes = "Creates a new bounding box from the position given and radius (X/Z) and height. Radius is added from X/Z to calculate the maximum coords and subtracted from X/Z to get the minimum; minimum Y is set to Pos.y and maxumim Y to Pos.y plus Height. This corresponds with how {{cEntity|entities}} are represented in Minecraft." }, - { Params = "OtherBoundingBox", Return = "cBoundingBox", Notes = "Creates a new copy of the given bounding box. Same result can be achieved by using a simple assignment." }, - }, - CalcLineIntersection = { Params = "{{Vector3d|LineStart}}, {{Vector3d|LinePt2}}", Return = "DoesIntersect, LineCoeff, Face", Notes = "Calculates the intersection of a ray (half-line), given by two of its points, with the bounding box. Returns false if the line doesn't intersect the bounding box, or true, together with coefficient of the intersection (how much of the difference between the two ray points is needed to reach the intersection), and the face of the box which is intersected.
    TODO: Lua binding for this function is wrong atm." }, - DoesIntersect = { Params = "OtherBoundingBox", Return = "bool", Notes = "Returns true if the two bounding boxes have an intersection of nonzero volume." }, - Expand = { Params = "ExpandX, ExpandY, ExpandZ", Return = "", Notes = "Expands this bounding box by the specified amount in each direction (so the box becomes larger by 2 * Expand in each axis)." }, - IsInside = - { - { Params = "{{Vector3d|Point}}", Return = "bool", Notes = "Returns true if the specified point is inside (including on the edge) of the box." }, - { Params = "PointX, PointY, PointZ", Return = "bool", Notes = "Returns true if the specified point is inside (including on the edge) of the box." }, - { Params = "OtherBoundingBox", Return = "bool", Notes = "Returns true if OtherBoundingBox is inside of this box." }, - { Params = "{{Vector3d|OtherBoxMin}}, {{Vector3d|OtherBoxMax}}", Return = "bool", Notes = "Returns true if the other bounding box, specified by its 2 corners, is inside of this box." }, - }, - Move = - { - { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Moves the bounding box by the specified offset in each axis" }, - { Params = "{{Vector3d|Offset}}", Return = "", Notes = "Moves the bounding box by the specified offset in each axis" }, - }, - Union = { Params = "OtherBoundingBox", Return = "cBoundingBox", Notes = "Returns the smallest bounding box that contains both OtherBoundingBox and this bounding box. Note that unlike the strict geometrical meaning of \"union\", this operation actually returns a cBoundingBox." }, - }, - }, - cChatColor = { Desc = [[ @@ -549,48 +510,6 @@ end }, }, -- cCraftingRecipe - cCuboid = - { - Desc = [[ - cCuboid offers some native support for integral-boundary cuboids. A cuboid internally consists of - two {{Vector3i}}s. By default the cuboid doesn't make any assumptions about the defining points, - but for most of the operations in the cCuboid class, the p1 member variable is expected to be the - minima and the p2 variable the maxima. The Sort() function guarantees this condition.

    -

    - The Cuboid considers both its edges inclusive.

    - ]], - Functions = - { - constructor = - { - { Params = "OtheCuboid", Return = "cCuboid", Notes = "Creates a new Cuboid object as a copy of OtherCuboid" }, - { Params = "{{Vector3i|Point1}}, {{Vector3i|Point2}}", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified points as its corners." }, - { Params = "X, Y, Z", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified point as both its corners (the cuboid has a size of 1 in each direction)." }, - { Params = "X1, Y1, Z1, X2, Y2, Z2", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified points as its corners." }, - }, - Assign = { Params = "X1, Y1, Z1, X2, Y2, Z2", Return = "", Notes = "Assigns all the coords stored in the cuboid. Sort-state is ignored." }, - DifX = { Params = "", Return = "number", Notes = "Returns the difference between the two X coords (X-size minus 1). Assumes sorted." }, - DifY = { Params = "", Return = "number", Notes = "Returns the difference between the two Y coords (Y-size minus 1). Assumes sorted." }, - DifZ = { Params = "", Return = "number", Notes = "Returns the difference between the two Z coords (Z-size minus 1). Assumes sorted." }, - DoesIntersect = { Params = "OtherCuboid", Return = "bool", Notes = "Returns true if this cuboid has at least one voxel in common with OtherCuboid. Note that edges are considered inclusive. Assumes both sorted." }, - IsCompletelyInside = { Params = "OuterCuboid", Return = "bool", Notes = "Returns true if this cuboid is completely inside (in all directions) in OuterCuboid. Assumes both sorted." }, - IsInside = - { - { Params = "X, Y, Z", Return = "bool", Notes = "Returns true if the specified point (integral coords) is inside this cuboid. Assumes sorted." }, - { Params = "{{Vector3i|Point}}", Return = "bool", Notes = "Returns true if the specified point (integral coords) is inside this cuboid. Assumes sorted." }, - { Params = "{{Vector3d|Point}}", Return = "bool", Notes = "Returns true if the specified point (floating-point coords) is inside this cuboid. Assumes sorted." }, - }, - IsSorted = { Params = "", Return = "bool", Notes = "Returns true if this cuboid is sorted" }, - Move = { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Adds the specified offsets to each respective coord, effectively moving the Cuboid. Sort-state is ignored." }, - Sort = { Params = "", Return = "" , Notes = "Sorts the internal representation so that p1 contains the lesser coords and p2 contains the greater coords." }, - }, - Variables = - { - p1 = { Type = "{{Vector3i}}", Notes = "The first corner. Usually the lesser of the two coords in each set" }, - p2 = { Type = "{{Vector3i}}", Notes = "The second corner. Usually the larger of the two coords in each set" }, - }, - }, -- cCuboid - cEnchantments = { Desc = [[ @@ -1341,95 +1260,6 @@ end }, }, -- cItems - cLineBlockTracer = - { - Desc = [[Objects of this class provide an easy-to-use interface to tracing lines through individual -blocks in the world. It will call the provided callbacks according to what events it encounters along the -way.

    -

    -For the Lua API, there's only one function exported that takes all the parameters necessary to do the -tracing. The Callbacks parameter is a table containing all the functions that will be called upon the -various events. See below for further information. - ]], - Functions = - { - Trace = { Params = "{{cWorld}}, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ", Return = "bool", Notes = "(STATIC) Performs the trace on the specified line. Returns true if the entire trace was processed (no callback returned true)" }, - }, - - AdditionalInfo = - { - { - Header = "Callbacks", - Contents = [[ -The Callbacks in the Trace() function is a table that contains named functions. MCServer will call -individual functions from that table for the events that occur on the line - hitting a block, going out of -valid world data etc. The following table lists all the available callbacks. If the callback function is -not defined, MCServer skips it. Each function can return a bool value, if it returns true, the tracing is -aborted and Trace() returns false.

    -

    - - - - - - - - - - - - - -
    NameParametersNotes
    OnNextBlockBlockX, BlockY, BlockZ, BlockType, BlockMeta, EntryFaceCalled when the ray hits a new valid block. The block type and meta is given. EntryFace is one of the - BLOCK_FACE_ constants indicating which "side" of the block got hit by the ray.
    OnNextBlockNoDataBlockX, BlockY, BlockZ, EntryFaceCalled when the ray hits a new block, but the block is in an unloaded chunk - no valid data is - available. Only the coords and the entry face are given.
    OnOutOfWorldX, Y, ZCalled when the ray goes outside of the world (Y-wise); the coords specify the exact exit point. Note - that for other paths than lines (considered for future implementations) the path may leave the world and - go back in again later, in such a case this callback is followed by OnIntoWorld() and further - OnNextBlock() calls.
    OnIntoWorldX, Y, ZCalled when the ray enters the world (Y-wise); the coords specify the exact entry point.
    OnNoMoreHits Called when the path is sure not to hit any more blocks. This is the final callback, no more - callbacks are called after this function. Unlike the other callbacks, this function doesn't have a return - value.
    OnNoChunk Called when the ray enters a chunk that is not loaded. This usually means that the tracing is aborted. - Unlike the other callbacks, this function doesn't have a return value.
    - ]], - }, - { - Header = "Example", - Contents = [[ -

    The following example is taken from the Debuggers plugin. It is a command handler function for the -"/spidey" command that creates a line of cobweb blocks from the player's eyes up to 50 blocks away in -the direction they're looking, but only through the air. -

    -function HandleSpideyCmd(a_Split, a_Player)
    -	local World = a_Player:GetWorld();
    -
    -	local Callbacks = {
    -		OnNextBlock = function(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta)
    -			if (a_BlockType ~= E_BLOCK_AIR) then
    -				-- abort the trace
    -				return true;
    -			end
    -			World:SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_COBWEB, 0);
    -		end
    -	};
    -
    -	local EyePos = a_Player:GetEyePosition();
    -	local LookVector = a_Player:GetLookVector();
    -	LookVector:Normalize();  -- Make the vector 1 m long
    -
    -	-- Start cca 2 blocks away from the eyes
    -	local Start = EyePos + LookVector + LookVector;
    -	local End = EyePos + LookVector * 50;
    -
    -	cLineBlockTracer.Trace(World, Callbacks, Start.x, Start.y, Start.z, End.x, End.y, End.z);
    -
    -	return true;
    -end
    -
    -

    - ]], - }, - }, -- AdditionalInfo - }, -- cLineBlockTracer - cLuaWindow = { Desc = [[This class is used by plugins wishing to display a custom window to the player, unrelated to block entities or entities near the player. The window can be of any type and have any contents that the plugin defines. Callbacks for when the player modifies the window contents and when the player closes the window can be set. @@ -2022,21 +1852,6 @@ end Inherits = "cEntity", }, - cTracer = - { - Desc = [[ - A cTracer object is used to trace lines in the world. One thing you can use the cTracer for, is - tracing what block a player is looking at, but you can do more with it if you want.

    -

    - The cTracer is still a work in progress.

    -

    - See also the {{cLineBlockTracer}} class for an alternative approach using callbacks. - ]], - Functions = - { - }, - }, -- cTracer - cWebAdmin = { Desc = "", @@ -2619,122 +2434,6 @@ end } -- AdditionalInfo }, -- tolua - Vector3d = - { - Desc = [[ - A Vector3d object uses double precision floating point values to describe a point in 3D space.

    -

    - See also {{Vector3f}} for single-precision floating point 3D coords and {{Vector3i}} for integer - 3D coords. - ]], - Functions = - { - constructor = - { - { Params = "{{Vector3f}}", Return = "Vector3d", Notes = "Creates a new Vector3d object by copying the coords from the given Vector3f." }, - { Params = "", Return = "Vector3d", Notes = "Creates a new Vector3d object with all its coords set to 0." }, - { Params = "X, Y, Z", Return = "Vector3d", Notes = "Creates a new Vector3d object with its coords set to the specified values." }, - }, - operator_div = { Params = "number", Return = "Vector3d", Notes = "Returns a new Vector3d with each coord divided by the specified number." }, - operator_mul = { Params = "number", Return = "Vector3d", Notes = "Returns a new Vector3d with each coord multiplied." }, - operator_sub = { Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d containing the difference between this object and the specified vector." }, - operator_plus = {Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d containing the sum of this vector and the specified vector" }, - Cross = { Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d that is a {{http://en.wikipedia.org/wiki/Cross_product|cross product}} of this vector and the specified vector." }, - Dot = { Params = "Vector3d", Return = "number", Notes = "Returns the dot product of this vector and the specified vector." }, - Equals = { Params = "Vector3d", Return = "bool", Notes = "Returns true if this vector is exactly equal to the specified vector." }, - Length = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of the vector." }, - LineCoeffToXYPlane = { Params = "Vector3d, Z", Return = "number", Notes = "Returns the coefficient for the line from the specified vector through this vector to reach the specified Z coord. The result satisfies the following equation: (this + Result * (Param - this)).z = Z. Returns the NO_INTERSECTION constant if there's no intersection." }, - LineCoeffToXZPlane = { Params = "Vector3d, Y", Return = "number", Notes = "Returns the coefficient for the line from the specified vector through this vector to reach the specified Y coord. The result satisfies the following equation: (this + Result * (Param - this)).y = Y. Returns the NO_INTERSECTION constant if there's no intersection." }, - LineCoeffToYZPlane = { Params = "Vector3d, X", Return = "number", Notes = "Returns the coefficient for the line from the specified vector through this vector to reach the specified X coord. The result satisfies the following equation: (this + Result * (Param - this)).x = X. Returns the NO_INTERSECTION constant if there's no intersection." }, - Normalize = { Params = "", Return = "", Notes = "Changes this vector so that it keeps current direction but is exactly 1 unit long. FIXME: Fails for a zero vector." }, - NormalizeCopy = { Params = "", Return = "Vector3d", Notes = "Returns a new vector that has the same directino as this but is exactly 1 unit long. FIXME: Fails for a zero vector." }, - Set = { Params = "X, Y, Z", Return = "", Notes = "Sets all the coords in this object." }, - SqrLength = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector, squared. This operation is slightly less computationally expensive than Length(), while it conserves some properties of Length(), such as comparison. " }, - }, - Constants = - { - EPS = { Notes = "The max difference between two coords for which the coords are assumed equal (in LineCoeffToXYPlane() et al)." }, - NO_INTERSECTION = { Notes = "Special return value for the LineCoeffToXYPlane() et al meaning that there's no intersectino with the plane." }, - }, - Variables = - { - x = { Type = "number", Notes = "The X coord of the vector." }, - y = { Type = "number", Notes = "The Y coord of the vector." }, - z = { Type = "number", Notes = "The Z coord of the vector." }, - }, - }, -- Vector3d - - Vector3f = - { - Desc = [[ - A Vector3f object uses floating point values to describe a point in space.

    -

    - See also {{Vector3d}} for double-precision floating point 3D coords and {{Vector3i}} for integer - 3D coords. - ]], - Functions = - { - constructor = - { - { Params = "", Return = "Vector3f", Notes = "Creates a new Vector3f object with zero coords" }, - { Params = "x, y, z", Return = "Vector3f", Notes = "Creates a new Vector3f object with the specified coords" }, - { Params = "Vector3f", Return = "Vector3f", Notes = "Creates a new Vector3f object as a copy of the specified vector" }, - { Params = "{{Vector3d}}", Return = "Vector3f", Notes = "Creates a new Vector3f object as a copy of the specified {{Vector3d}}" }, - { Params = "{{Vector3i}}", Return = "Vector3f", Notes = "Creates a new Vector3f object as a copy of the specified {{Vector3i}}" }, - }, - operator_mul = - { - { Params = "number", Return = "Vector3f", Notes = "Returns a new Vector3f object that has each of its coords multiplied by the specified number" }, - { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that has each of its coords multiplied by the respective coord of the specified vector." }, - }, - operator_plus = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the vector sum of this vector and the specified vector." }, - operator_sub = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the vector differrence between this vector and the specified vector." }, - Cross = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the cross product of this vector and the specified vector." }, - Dot = { Params = "Vector3f", Return = "number", Notes = "Returns the dot product of this vector and the specified vector." }, - Equals = { Params = "Vector3f", Return = "bool", Notes = "Returns true if the specified vector is exactly equal to this vector." }, - Length = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector" }, - Normalize = { Params = "", Return = "", Notes = "Normalizes this vector (makes it 1 unit long while keeping the direction). FIXME: Fails for zero vectors." }, - NormalizeCopy = { Params = "", Return = "Vector3f", Notes = "Returns a copy of this vector that is normalized (1 unit long while keeping the same direction). FIXME: Fails for zero vectors." }, - Set = { Params = "x, y, z", Return = "", Notes = "Sets all the coords of the vector at once." }, - SqrLength = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector, squared. This operation is slightly less computationally expensive than Length(), while it conserves some properties of Length(), such as comparison." }, - }, - Variables = - { - x = { Type = "number", Notes = "The X coord of the vector." }, - y = { Type = "number", Notes = "The Y coord of the vector." }, - z = { Type = "number", Notes = "The Z coord of the vector." }, - }, - }, -- Vector3f - - Vector3i = - { - Desc = [[ - A Vector3i object uses integer values to describe a point in space.

    -

    - See also {{Vector3d}} for double-precision floating point 3D coords and {{Vector3f}} for - single-precision floating point 3D coords. - ]], - Functions = - { - constructor = - { - { Params = "", Return = "Vector3i", Notes = "Creates a new Vector3i object with zero coords." }, - { Params = "x, y, z", Return = "Vector3i", Notes = "Creates a new Vector3i object with the specified coords." }, - { Params = "{{Vector3d}}", Return = "Vector3i", Notes = "Creates a new Vector3i object with coords copied and floor()-ed from the specified {{Vector3d}}." }, - }, - Equals = { Params = "Vector3i", Return = "bool", Notes = "Returns true if this vector is exactly the same as the specified vector." }, - Length = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector." }, - Set = { Params = "x, y, z", Return = "", Notes = "Sets all the coords of the vector at once" }, - SqrLength = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector, squared. This operation is slightly less computationally expensive than Length(), while it conserves some properties of Length(), such as comparison." }, - }, - Variables = - { - x = { Type = "number", Notes = "The X coord of the vector." }, - y = { Type = "number", Notes = "The Y coord of the vector." }, - z = { Type = "number", Notes = "The Z coord of the vector." }, - }, - }, -- Vector3i - Globals = { Desc = [[ diff --git a/MCServer/Plugins/APIDump/Classes/Geometry.lua b/MCServer/Plugins/APIDump/Classes/Geometry.lua new file mode 100644 index 000000000..22ee1ef44 --- /dev/null +++ b/MCServer/Plugins/APIDump/Classes/Geometry.lua @@ -0,0 +1,320 @@ + +-- Geometry.lua + +-- Defines the documentation for geometry-related classes: +-- cBoundingBox, cCuboid, cLineBlockTracer, cTracer, Vector3X + + + + +return +{ + cBoundingBox = + { + Desc = [[ + Represents two sets of coordinates, minimum and maximum for each direction; thus defining an + axis-aligned cuboid with floating-point boundaries. It supports operations changing the size and + position of the box, as well as querying whether a point or another BoundingBox is inside the box.

    +

    + All the points within the coordinate limits (inclusive the edges) are considered "inside" the box. + However, for intersection purposes, if the intersection is "sharp" in any coord (min1 == max2, i. e. + zero volume), the boxes are considered non-intersecting.

    + ]], + Functions = + { + constructor = + { + { Params = "MinX, MaxX, MinY, MaxY, MinZ, MaxZ", Return = "cBoundingBox", Notes = "Creates a new bounding box with the specified edges" }, + { Params = "{{Vector3d|Min}}, {{Vector3d|Max}}", Return = "cBoundingBox", Notes = "Creates a new bounding box with the coords specified as two vectors" }, + { Params = "{{Vector3d|Pos}}, Radius, Height", Return = "cBoundingBox", Notes = "Creates a new bounding box from the position given and radius (X/Z) and height. Radius is added from X/Z to calculate the maximum coords and subtracted from X/Z to get the minimum; minimum Y is set to Pos.y and maxumim Y to Pos.y plus Height. This corresponds with how {{cEntity|entities}} are represented in Minecraft." }, + { Params = "OtherBoundingBox", Return = "cBoundingBox", Notes = "Creates a new copy of the given bounding box. Same result can be achieved by using a simple assignment." }, + }, + CalcLineIntersection = { Params = "{{Vector3d|LineStart}}, {{Vector3d|LinePt2}}", Return = "DoesIntersect, LineCoeff, Face", Notes = "Calculates the intersection of a ray (half-line), given by two of its points, with the bounding box. Returns false if the line doesn't intersect the bounding box, or true, together with coefficient of the intersection (how much of the difference between the two ray points is needed to reach the intersection), and the face of the box which is intersected.
    TODO: Lua binding for this function is wrong atm." }, + DoesIntersect = { Params = "OtherBoundingBox", Return = "bool", Notes = "Returns true if the two bounding boxes have an intersection of nonzero volume." }, + Expand = { Params = "ExpandX, ExpandY, ExpandZ", Return = "", Notes = "Expands this bounding box by the specified amount in each direction (so the box becomes larger by 2 * Expand in each axis)." }, + IsInside = + { + { Params = "{{Vector3d|Point}}", Return = "bool", Notes = "Returns true if the specified point is inside (including on the edge) of the box." }, + { Params = "PointX, PointY, PointZ", Return = "bool", Notes = "Returns true if the specified point is inside (including on the edge) of the box." }, + { Params = "OtherBoundingBox", Return = "bool", Notes = "Returns true if OtherBoundingBox is inside of this box." }, + { Params = "{{Vector3d|OtherBoxMin}}, {{Vector3d|OtherBoxMax}}", Return = "bool", Notes = "Returns true if the other bounding box, specified by its 2 corners, is inside of this box." }, + }, + Move = + { + { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Moves the bounding box by the specified offset in each axis" }, + { Params = "{{Vector3d|Offset}}", Return = "", Notes = "Moves the bounding box by the specified offset in each axis" }, + }, + Union = { Params = "OtherBoundingBox", Return = "cBoundingBox", Notes = "Returns the smallest bounding box that contains both OtherBoundingBox and this bounding box. Note that unlike the strict geometrical meaning of \"union\", this operation actually returns a cBoundingBox." }, + }, + }, -- cBoundingBox + + + cCuboid = + { + Desc = [[ + cCuboid offers some native support for integral-boundary cuboids. A cuboid internally consists of + two {{Vector3i}}s. By default the cuboid doesn't make any assumptions about the defining points, + but for most of the operations in the cCuboid class, the p1 member variable is expected to be the + minima and the p2 variable the maxima. The Sort() function guarantees this condition.

    +

    + The Cuboid considers both its edges inclusive.

    + ]], + Functions = + { + constructor = + { + { Params = "OtheCuboid", Return = "cCuboid", Notes = "Creates a new Cuboid object as a copy of OtherCuboid" }, + { Params = "{{Vector3i|Point1}}, {{Vector3i|Point2}}", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified points as its corners." }, + { Params = "X, Y, Z", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified point as both its corners (the cuboid has a size of 1 in each direction)." }, + { Params = "X1, Y1, Z1, X2, Y2, Z2", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified points as its corners." }, + }, + Assign = { Params = "X1, Y1, Z1, X2, Y2, Z2", Return = "", Notes = "Assigns all the coords stored in the cuboid. Sort-state is ignored." }, + DifX = { Params = "", Return = "number", Notes = "Returns the difference between the two X coords (X-size minus 1). Assumes sorted." }, + DifY = { Params = "", Return = "number", Notes = "Returns the difference between the two Y coords (Y-size minus 1). Assumes sorted." }, + DifZ = { Params = "", Return = "number", Notes = "Returns the difference between the two Z coords (Z-size minus 1). Assumes sorted." }, + DoesIntersect = { Params = "OtherCuboid", Return = "bool", Notes = "Returns true if this cuboid has at least one voxel in common with OtherCuboid. Note that edges are considered inclusive. Assumes both sorted." }, + IsCompletelyInside = { Params = "OuterCuboid", Return = "bool", Notes = "Returns true if this cuboid is completely inside (in all directions) in OuterCuboid. Assumes both sorted." }, + IsInside = + { + { Params = "X, Y, Z", Return = "bool", Notes = "Returns true if the specified point (integral coords) is inside this cuboid. Assumes sorted." }, + { Params = "{{Vector3i|Point}}", Return = "bool", Notes = "Returns true if the specified point (integral coords) is inside this cuboid. Assumes sorted." }, + { Params = "{{Vector3d|Point}}", Return = "bool", Notes = "Returns true if the specified point (floating-point coords) is inside this cuboid. Assumes sorted." }, + }, + IsSorted = { Params = "", Return = "bool", Notes = "Returns true if this cuboid is sorted" }, + Move = { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Adds the specified offsets to each respective coord, effectively moving the Cuboid. Sort-state is ignored." }, + Sort = { Params = "", Return = "" , Notes = "Sorts the internal representation so that p1 contains the lesser coords and p2 contains the greater coords." }, + }, + Variables = + { + p1 = { Type = "{{Vector3i}}", Notes = "The first corner. Usually the lesser of the two coords in each set" }, + p2 = { Type = "{{Vector3i}}", Notes = "The second corner. Usually the larger of the two coords in each set" }, + }, + }, -- cCuboid + + + cLineBlockTracer = + { + Desc = [[This class provides an easy-to-use interface for tracing lines through individual +blocks in the world. It will call the provided callbacks according to what events it encounters along the +way.

    +

    +For the Lua API, there's only one static function exported that takes all the parameters necessary to do +the tracing. The Callbacks parameter is a table containing all the functions that will be called upon the +various events. See below for further information. + ]], + Functions = + { + Trace = { Params = "{{cWorld}}, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ", Return = "bool", Notes = "(STATIC) Performs the trace on the specified line. Returns true if the entire trace was processed (no callback returned true)" }, + }, + + AdditionalInfo = + { + { + Header = "Callbacks", + Contents = [[ +The Callbacks in the Trace() function is a table that contains named functions. MCServer will call +individual functions from that table for the events that occur on the line - hitting a block, going out of +valid world data etc. The following table lists all the available callbacks. If the callback function is +not defined, MCServer skips it. Each function can return a bool value, if it returns true, the tracing is +aborted and Trace() returns false.

    +

    + + + + + + + + + + + + + +
    NameParametersNotes
    OnNextBlockBlockX, BlockY, BlockZ, BlockType, BlockMeta, EntryFaceCalled when the ray hits a new valid block. The block type and meta is given. EntryFace is one of the + BLOCK_FACE_ constants indicating which "side" of the block got hit by the ray.
    OnNextBlockNoDataBlockX, BlockY, BlockZ, EntryFaceCalled when the ray hits a new block, but the block is in an unloaded chunk - no valid data is + available. Only the coords and the entry face are given.
    OnOutOfWorldX, Y, ZCalled when the ray goes outside of the world (Y-wise); the coords specify the exact exit point. Note + that for other paths than lines (considered for future implementations) the path may leave the world and + go back in again later, in such a case this callback is followed by OnIntoWorld() and further + OnNextBlock() calls.
    OnIntoWorldX, Y, ZCalled when the ray enters the world (Y-wise); the coords specify the exact entry point.
    OnNoMoreHits Called when the path is sure not to hit any more blocks. This is the final callback, no more + callbacks are called after this function. Unlike the other callbacks, this function doesn't have a return + value.
    OnNoChunk Called when the ray enters a chunk that is not loaded. This usually means that the tracing is aborted. + Unlike the other callbacks, this function doesn't have a return value.
    + ]], + }, + { + Header = "Example", + Contents = [[ +

    The following example is taken from the Debuggers plugin. It is a command handler function for the +"/spidey" command that creates a line of cobweb blocks from the player's eyes up to 50 blocks away in +the direction they're looking, but only through the air. +

    +function HandleSpideyCmd(a_Split, a_Player)
    +	local World = a_Player:GetWorld();
    +
    +	local Callbacks = {
    +		OnNextBlock = function(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta)
    +			if (a_BlockType ~= E_BLOCK_AIR) then
    +				-- abort the trace
    +				return true;
    +			end
    +			World:SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_COBWEB, 0);
    +		end
    +	};
    +
    +	local EyePos = a_Player:GetEyePosition();
    +	local LookVector = a_Player:GetLookVector();
    +	LookVector:Normalize();  -- Make the vector 1 m long
    +
    +	-- Start cca 2 blocks away from the eyes
    +	local Start = EyePos + LookVector + LookVector;
    +	local End = EyePos + LookVector * 50;
    +
    +	cLineBlockTracer.Trace(World, Callbacks, Start.x, Start.y, Start.z, End.x, End.y, End.z);
    +
    +	return true;
    +end
    +
    +

    + ]], + }, + }, -- AdditionalInfo + }, -- cLineBlockTracer + + + cTracer = + { + Desc = [[ + A cTracer object is used to trace lines in the world. One thing you can use the cTracer for, is + tracing what block a player is looking at, but you can do more with it if you want.

    +

    + The cTracer is still a work in progress.

    +

    + See also the {{cLineBlockTracer}} class for an alternative approach using callbacks. + ]], + Functions = + { + }, + }, -- cTracer + + + Vector3d = + { + Desc = [[ + A Vector3d object uses double precision floating point values to describe a point in 3D space.

    +

    + See also {{Vector3f}} for single-precision floating point 3D coords and {{Vector3i}} for integer + 3D coords. + ]], + Functions = + { + constructor = + { + { Params = "{{Vector3f}}", Return = "Vector3d", Notes = "Creates a new Vector3d object by copying the coords from the given Vector3f." }, + { Params = "", Return = "Vector3d", Notes = "Creates a new Vector3d object with all its coords set to 0." }, + { Params = "X, Y, Z", Return = "Vector3d", Notes = "Creates a new Vector3d object with its coords set to the specified values." }, + }, + operator_div = { Params = "number", Return = "Vector3d", Notes = "Returns a new Vector3d with each coord divided by the specified number." }, + operator_mul = { Params = "number", Return = "Vector3d", Notes = "Returns a new Vector3d with each coord multiplied." }, + operator_sub = { Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d containing the difference between this object and the specified vector." }, + operator_plus = {Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d containing the sum of this vector and the specified vector" }, + Cross = { Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d that is a {{http://en.wikipedia.org/wiki/Cross_product|cross product}} of this vector and the specified vector." }, + Dot = { Params = "Vector3d", Return = "number", Notes = "Returns the dot product of this vector and the specified vector." }, + Equals = { Params = "Vector3d", Return = "bool", Notes = "Returns true if this vector is exactly equal to the specified vector." }, + Length = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of the vector." }, + LineCoeffToXYPlane = { Params = "Vector3d, Z", Return = "number", Notes = "Returns the coefficient for the line from the specified vector through this vector to reach the specified Z coord. The result satisfies the following equation: (this + Result * (Param - this)).z = Z. Returns the NO_INTERSECTION constant if there's no intersection." }, + LineCoeffToXZPlane = { Params = "Vector3d, Y", Return = "number", Notes = "Returns the coefficient for the line from the specified vector through this vector to reach the specified Y coord. The result satisfies the following equation: (this + Result * (Param - this)).y = Y. Returns the NO_INTERSECTION constant if there's no intersection." }, + LineCoeffToYZPlane = { Params = "Vector3d, X", Return = "number", Notes = "Returns the coefficient for the line from the specified vector through this vector to reach the specified X coord. The result satisfies the following equation: (this + Result * (Param - this)).x = X. Returns the NO_INTERSECTION constant if there's no intersection." }, + Normalize = { Params = "", Return = "", Notes = "Changes this vector so that it keeps current direction but is exactly 1 unit long. FIXME: Fails for a zero vector." }, + NormalizeCopy = { Params = "", Return = "Vector3d", Notes = "Returns a new vector that has the same directino as this but is exactly 1 unit long. FIXME: Fails for a zero vector." }, + Set = { Params = "X, Y, Z", Return = "", Notes = "Sets all the coords in this object." }, + SqrLength = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector, squared. This operation is slightly less computationally expensive than Length(), while it conserves some properties of Length(), such as comparison. " }, + }, + Constants = + { + EPS = { Notes = "The max difference between two coords for which the coords are assumed equal (in LineCoeffToXYPlane() et al)." }, + NO_INTERSECTION = { Notes = "Special return value for the LineCoeffToXYPlane() et al meaning that there's no intersectino with the plane." }, + }, + Variables = + { + x = { Type = "number", Notes = "The X coord of the vector." }, + y = { Type = "number", Notes = "The Y coord of the vector." }, + z = { Type = "number", Notes = "The Z coord of the vector." }, + }, + }, -- Vector3d + + Vector3f = + { + Desc = [[ + A Vector3f object uses floating point values to describe a point in space.

    +

    + See also {{Vector3d}} for double-precision floating point 3D coords and {{Vector3i}} for integer + 3D coords. + ]], + Functions = + { + constructor = + { + { Params = "", Return = "Vector3f", Notes = "Creates a new Vector3f object with zero coords" }, + { Params = "x, y, z", Return = "Vector3f", Notes = "Creates a new Vector3f object with the specified coords" }, + { Params = "Vector3f", Return = "Vector3f", Notes = "Creates a new Vector3f object as a copy of the specified vector" }, + { Params = "{{Vector3d}}", Return = "Vector3f", Notes = "Creates a new Vector3f object as a copy of the specified {{Vector3d}}" }, + { Params = "{{Vector3i}}", Return = "Vector3f", Notes = "Creates a new Vector3f object as a copy of the specified {{Vector3i}}" }, + }, + operator_mul = + { + { Params = "number", Return = "Vector3f", Notes = "Returns a new Vector3f object that has each of its coords multiplied by the specified number" }, + { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that has each of its coords multiplied by the respective coord of the specified vector." }, + }, + operator_plus = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the vector sum of this vector and the specified vector." }, + operator_sub = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the vector differrence between this vector and the specified vector." }, + Cross = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the cross product of this vector and the specified vector." }, + Dot = { Params = "Vector3f", Return = "number", Notes = "Returns the dot product of this vector and the specified vector." }, + Equals = { Params = "Vector3f", Return = "bool", Notes = "Returns true if the specified vector is exactly equal to this vector." }, + Length = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector" }, + Normalize = { Params = "", Return = "", Notes = "Normalizes this vector (makes it 1 unit long while keeping the direction). FIXME: Fails for zero vectors." }, + NormalizeCopy = { Params = "", Return = "Vector3f", Notes = "Returns a copy of this vector that is normalized (1 unit long while keeping the same direction). FIXME: Fails for zero vectors." }, + Set = { Params = "x, y, z", Return = "", Notes = "Sets all the coords of the vector at once." }, + SqrLength = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector, squared. This operation is slightly less computationally expensive than Length(), while it conserves some properties of Length(), such as comparison." }, + }, + Variables = + { + x = { Type = "number", Notes = "The X coord of the vector." }, + y = { Type = "number", Notes = "The Y coord of the vector." }, + z = { Type = "number", Notes = "The Z coord of the vector." }, + }, + }, -- Vector3f + + Vector3i = + { + Desc = [[ + A Vector3i object uses integer values to describe a point in space.

    +

    + See also {{Vector3d}} for double-precision floating point 3D coords and {{Vector3f}} for + single-precision floating point 3D coords. + ]], + Functions = + { + constructor = + { + { Params = "", Return = "Vector3i", Notes = "Creates a new Vector3i object with zero coords." }, + { Params = "x, y, z", Return = "Vector3i", Notes = "Creates a new Vector3i object with the specified coords." }, + { Params = "{{Vector3d}}", Return = "Vector3i", Notes = "Creates a new Vector3i object with coords copied and floor()-ed from the specified {{Vector3d}}." }, + }, + Equals = { Params = "Vector3i", Return = "bool", Notes = "Returns true if this vector is exactly the same as the specified vector." }, + Length = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector." }, + Set = { Params = "x, y, z", Return = "", Notes = "Sets all the coords of the vector at once" }, + SqrLength = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector, squared. This operation is slightly less computationally expensive than Length(), while it conserves some properties of Length(), such as comparison." }, + }, + Variables = + { + x = { Type = "number", Notes = "The X coord of the vector." }, + y = { Type = "number", Notes = "The Y coord of the vector." }, + z = { Type = "number", Notes = "The Z coord of the vector." }, + }, + }, -- Vector3i +} + + + + -- cgit v1.2.3 From b7b027c0f68c69e8aae2f46a9d488a9d081a2420 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 26 Feb 2014 20:44:52 +0100 Subject: APIDump: Documented new cCuboid functions. --- MCServer/Plugins/APIDump/Classes/Geometry.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/Classes/Geometry.lua b/MCServer/Plugins/APIDump/Classes/Geometry.lua index 22ee1ef44..e83d6e4b1 100644 --- a/MCServer/Plugins/APIDump/Classes/Geometry.lua +++ b/MCServer/Plugins/APIDump/Classes/Geometry.lua @@ -69,10 +69,15 @@ return { Params = "X1, Y1, Z1, X2, Y2, Z2", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified points as its corners." }, }, Assign = { Params = "X1, Y1, Z1, X2, Y2, Z2", Return = "", Notes = "Assigns all the coords stored in the cuboid. Sort-state is ignored." }, + ClampX = { Params = "MinX, MaxX", Return = "", Notes = "Clamps both X coords into the range provided. Sortedness-agnostic." }, + ClampY = { Params = "MinY, MaxY", Return = "", Notes = "Clamps both Y coords into the range provided. Sortedness-agnostic." }, + ClampZ = { Params = "MinZ, MaxZ", Return = "", Notes = "Clamps both Z coords into the range provided. Sortedness-agnostic." }, DifX = { Params = "", Return = "number", Notes = "Returns the difference between the two X coords (X-size minus 1). Assumes sorted." }, DifY = { Params = "", Return = "number", Notes = "Returns the difference between the two Y coords (Y-size minus 1). Assumes sorted." }, DifZ = { Params = "", Return = "number", Notes = "Returns the difference between the two Z coords (Z-size minus 1). Assumes sorted." }, DoesIntersect = { Params = "OtherCuboid", Return = "bool", Notes = "Returns true if this cuboid has at least one voxel in common with OtherCuboid. Note that edges are considered inclusive. Assumes both sorted." }, + Expand = { Params = "SubMinX, AddMaxX, SubMinY, AddMaxY, SubMinZ, AddMaxZ", Return = "", Notes = "Expands the cuboid by the specified amount in each direction. Works on unsorted cuboids as well. NOTE: this function doesn't check for underflows." }, + GetVolume = { Params = "", Return = "number", Notes = "Returns the volume of the cuboid, in blocks. Note that the volume considers both coords inclusive. Works on unsorted cuboids, too." }, IsCompletelyInside = { Params = "OuterCuboid", Return = "bool", Notes = "Returns true if this cuboid is completely inside (in all directions) in OuterCuboid. Assumes both sorted." }, IsInside = { @@ -81,7 +86,7 @@ return { Params = "{{Vector3d|Point}}", Return = "bool", Notes = "Returns true if the specified point (floating-point coords) is inside this cuboid. Assumes sorted." }, }, IsSorted = { Params = "", Return = "bool", Notes = "Returns true if this cuboid is sorted" }, - Move = { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Adds the specified offsets to each respective coord, effectively moving the Cuboid. Sort-state is ignored." }, + Move = { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Adds the specified offsets to each respective coord, effectively moving the Cuboid. Sort-state is ignored and preserved." }, Sort = { Params = "", Return = "" , Notes = "Sorts the internal representation so that p1 contains the lesser coords and p2 contains the greater coords." }, }, Variables = -- cgit v1.2.3 From da75907942a5d0df0e3437ab525c8f67fc8f4196 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 26 Feb 2014 20:49:01 +0100 Subject: APIDump: Added Geometry file to project. --- MCServer/Plugins/APIDump/APIDump.deproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MCServer/Plugins/APIDump/APIDump.deproj b/MCServer/Plugins/APIDump/APIDump.deproj index e78974901..0e6fcd325 100644 --- a/MCServer/Plugins/APIDump/APIDump.deproj +++ b/MCServer/Plugins/APIDump/APIDump.deproj @@ -6,6 +6,9 @@ Classes\BlockEntities.lua + + Classes\Geometry.lua + Hooks\OnBlockToPickups.lua -- cgit v1.2.3 From aaddc98b46c2b918e908287f53a137d2fb5cf697 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 26 Feb 2014 21:37:38 +0100 Subject: Attempted fix for several GCC warnings. --- src/Bindings/LuaState.cpp | 7 +++++++ src/Bindings/ManualBindings.cpp | 9 +++++++-- src/MersenneTwister.h | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index ca7f6b255..45a066efe 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -677,6 +677,11 @@ void cLuaState::Push(void * a_Ptr) { ASSERT(IsValid()); + // Investigate the cause of this - what is the callstack? + LOGWARNING("Lua engine encountered an error - attempting to push a plain pointer"); + LogStackTrace(); + ASSERT(!"A plain pointer should never be pushed on Lua stack"); + lua_pushnil(m_LuaState); m_NumCurrentFunctionArgs += 1; } @@ -1265,6 +1270,8 @@ void cLuaState::LogStack(const char * a_Header) void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header) { + UNUSED(a_Header); // The param seems unused when compiling for release, so the compiler warns + LOGD((a_Header != NULL) ? a_Header : "Lua C API Stack contents:"); for (int i = lua_gettop(a_LuaState); i > 0; i--) { diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 2f3f3ee91..461186d3b 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1321,7 +1321,9 @@ static int tolua_cPluginManager_ForEachCommand(lua_State * tolua_S) private: virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) override { - lua_rawgeti( LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */ + UNUSED(a_Plugin); + + lua_rawgeti(LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */ tolua_pushcppstring(LuaState, a_Command); tolua_pushcppstring(LuaState, a_Permission); tolua_pushcppstring(LuaState, a_HelpString); @@ -1396,7 +1398,10 @@ static int tolua_cPluginManager_ForEachConsoleCommand(lua_State * tolua_S) private: virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) override { - lua_rawgeti( LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */ + UNUSED(a_Plugin); + UNUSED(a_Permission); + + lua_rawgeti(LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */ tolua_pushcppstring(LuaState, a_Command); tolua_pushcppstring(LuaState, a_HelpString); diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h index 784ac605d..f4c7b0699 100644 --- a/src/MersenneTwister.h +++ b/src/MersenneTwister.h @@ -207,7 +207,7 @@ inline void MTRand::seed( uint32 *const bigSeed, const uint32 seedLength ) initialize(19650218UL); int i = 1; uint32 j = 0; - int k = ( N > seedLength ? N : seedLength ); + int k = ( (uint32)N > seedLength ? (uint32)N : seedLength ); for( ; k; --k ) { state[i] = -- cgit v1.2.3 From cb40d114abe8a41ed5193e9cc99b06727f497452 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 26 Feb 2014 22:17:28 +0100 Subject: Fixed a gcc warning in FastNBT.h. --- src/WorldStorage/FastNBT.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h index b84eda1a1..a78b610cb 100644 --- a/src/WorldStorage/FastNBT.h +++ b/src/WorldStorage/FastNBT.h @@ -172,8 +172,17 @@ public: inline float GetFloat(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type == TAG_Float); - Int32 tmp = GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); - return *((float *)&tmp); + + // Cause a compile-time error if sizeof(int) != sizeof(float) + char Check1[sizeof(int) - sizeof(float) + 1]; // sizeof(int) >= sizeof(float) + char Check2[sizeof(float) - sizeof(int) + 1]; // sizeof(float) >= sizeof(int) + UNUSED(Check1); + UNUSED(Check2); + + int i = GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); + float f; + memcpy(&f, &i, sizeof(f)); + return f; } inline double GetDouble(int a_Tag) const -- cgit v1.2.3 From baf2d8892127cd6da9d2f6f2f8d991d617c87800 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 26 Feb 2014 23:29:14 +0000 Subject: Implemented ballistic missiles (fireworks) + Added fireworks --- MCServer/crafting.txt | 49 +++++- src/CraftingRecipes.cpp | 89 ++++++++++- src/Entities/ProjectileEntity.cpp | 87 ++++++----- src/Entities/ProjectileEntity.h | 12 +- src/Item.cpp | 22 ++- src/Item.h | 16 +- src/Items/ItemThrowable.h | 6 +- src/Protocol/Protocol17x.cpp | 77 ++++++---- src/World.cpp | 4 +- src/World.h | 2 +- src/WorldStorage/FastNBT.h | 2 +- src/WorldStorage/FireworksSerializer.cpp | 250 +++++++++++++++++++++++++++++++ src/WorldStorage/FireworksSerializer.h | 88 +++++++++++ src/WorldStorage/NBTChunkSerializer.cpp | 14 +- src/WorldStorage/WSSAnvil.cpp | 6 + 15 files changed, 637 insertions(+), 87 deletions(-) create mode 100644 src/WorldStorage/FireworksSerializer.cpp create mode 100644 src/WorldStorage/FireworksSerializer.h diff --git a/MCServer/crafting.txt b/MCServer/crafting.txt index 92abe24cb..bce0c5e9e 100644 --- a/MCServer/crafting.txt +++ b/MCServer/crafting.txt @@ -39,6 +39,7 @@ # # Need to list each of the four log types, otherwise all logs would get converted into apple planks (^0) + ApplePlanks, 4 = AppleLog, * ConiferPlanks, 4 = ConiferLog, * BirchPlanks, 4 = BirchLog, * @@ -434,6 +435,48 @@ GoldNugget, 9 = GoldIngot, * EnchantmentTable = Obsidian, 1:3, 2:3, 3:3, 2:2 | Diamond, 1:2, 3:2 | Book, 2:1 - - - +#******************************************************# +# Fireworks & Co. +# (Best not to add non-vanilla items to this as it will cause internal firework data handling code to log warnings) + +# Ballistic firework rockets - plain and with firework star, all with 1 - 3 gunpowder +FireworkRocket = Paper, * | Gunpowder, * +FireworkRocket = Paper, * | Gunpowder, * | Gunpowder, * +FireworkRocket = Paper, * | Gunpowder, * | Gunpowder, * | Gunpowder, * +FireworkRocket = FireworkStar, * | Paper, * | Gunpowder, * +FireworkRocket = FireworkStar, * | Paper, * | Gunpowder, * | Gunpowder, * +FireworkRocket = FireworkStar, * | Paper, * | Gunpowder, * | Gunpowder, * | Gunpowder, * + +# Radioactive firework stars +# Plain powder and dye +FireworkStar = Gunpowder, * | Dye ^-1, * + +# Powder and effect, with effect combining +FireworkStar = Gunpowder, * | Dye ^-1, * | Diamond, * +FireworkStar = Gunpowder, * | Dye ^-1, * | Glowdust, * +FireworkStar = Gunpowder, * | Dye ^-1, * | Glowdust, * | Diamond, * + +# Powder and shape (no shape combining possible) +FireworkStar = Gunpowder, * | Dye ^-1, * | Firecharge, * +FireworkStar = Gunpowder, * | Dye ^-1, * | Goldnugget, * +FireworkStar = Gunpowder, * | Dye ^-1, * | Feather, * +FireworkStar = Gunpowder, * | Dye ^-1, * | SkeletonHead ^-1, * + +# Power and shape (no shape combining possible), combined with effect +FireworkStar = Gunpowder, * | Dye ^-1, * | Firecharge, * | Diamond, * +FireworkStar = Gunpowder, * | Dye ^-1, * | Firecharge, * | Glowdust, * +FireworkStar = Gunpowder, * | Dye ^-1, * | Goldnugget, * | Diamond, * +FireworkStar = Gunpowder, * | Dye ^-1, * | Goldnugget, * | Glowdust, * +FireworkStar = Gunpowder, * | Dye ^-1, * | Feather, * | Diamond, * +FireworkStar = Gunpowder, * | Dye ^-1, * | Feather, * | Glowdust, * +FireworkStar = Gunpowder, * | Dye ^-1, * | SkeletonHead ^-1, * | Diamond, * +FireworkStar = Gunpowder, * | Dye ^-1, * | SkeletonHead ^-1, * | Glowdust, * + +# Power and shape (no shape combining possible), combined with effect (with effect combining) +FireworkStar = Gunpowder, * | Dye ^-1, * | Firecharge, * | Glowdust, * | Diamond, * +FireworkStar = Gunpowder, * | Dye ^-1, * | Goldnugget, * | Glowdust, * | Diamond, * +FireworkStar = Gunpowder, * | Dye ^-1, * | Feather, * | Glowdust, * | Diamond, * +FireworkStar = Gunpowder, * | Dye ^-1, * | SkeletonHead ^-1, * | Glowdust, * | Diamond, * + +# Star colour-change +FireworkStar = FireworkStar, * | Dye ^-1, * diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index fb1a10cca..41de0da8c 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -1,4 +1,4 @@ - + // CraftingRecipes.cpp // Interfaces to the cCraftingRecipes class representing the storage of crafting recipes @@ -762,6 +762,93 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti Recipe->m_Ingredients.push_back(*itrS); } Recipe->m_Ingredients.insert(Recipe->m_Ingredients.end(), MatchedSlots.begin(), MatchedSlots.end()); + + + // Henceforth is code to handle fireworks + // We use Recipe instead of a_Recipe because we want the wildcard ingredients' slot numbers as well, which was just added previously + + if (Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_ROCKET) + { + for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr) + { + switch (itr->m_Item.m_ItemType) + { + case E_ITEM_FIREWORK_STAR: + { + // Result was a rocket, found a star - copy star data to rocket data + int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY); + Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem); + break; + } + case E_ITEM_GUNPOWDER: + { + // Gunpowder - increase flight time + Recipe->m_Result.m_FireworkItem.m_FlightTimeInTicks += 20; + break; + } + case E_ITEM_PAPER: break; + default: LOG("Unexpected item in firework rocket recipe, was the crafting file fireworks section changed?"); break; + } + } + } + else if (Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_STAR) + { + for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr) + { + switch (itr->m_Item.m_ItemType) + { + case E_ITEM_FIREWORK_STAR: + { + // Result was star, found another star - probably adding fade colours, but copy data over anyhow + int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY); + Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem); + break; + } + case E_ITEM_DYE: + { + // Found a dye in ingredients... + for (cRecipeSlots::const_iterator itrnumerodos = Recipe->m_Ingredients.begin(); itrnumerodos != Recipe->m_Ingredients.end(); ++itrnumerodos) + { + // Loop through ingredients. Can we find a star? + if (itrnumerodos->m_Item.m_ItemType == E_ITEM_FIREWORK_STAR) + { + // Yes, this is definately adding fade colours, unless crafting.txt was changed :/ + for (cRecipeSlots::const_iterator itrnumerotres = Recipe->m_Ingredients.begin(); itrnumerotres != Recipe->m_Ingredients.end(); ++itrnumerotres) + { + // Loop again, can we find dye? + if (itrnumerotres->m_Item.m_ItemType == E_ITEM_DYE) + { + // Yep, push back fade colour and exit the loop + // There is a potential for flexibility here - we can move the goto out of the loop, so we can add multiple dyes (∴ multiple fade colours) + // That will require lots of dye-adding to crafting.txt though - TODO, perchance? + int GridID = (itrnumerotres->x + a_OffsetX) + a_GridStride * (itrnumerotres->y + a_OffsetY); + Recipe->m_Result.m_FireworkItem.m_FadeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage)); + goto next; + } + } + } + } + + // Just normal crafting of star, push back normal colours + int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY); + Recipe->m_Result.m_FireworkItem.m_Colours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage)); + + next: + break; + } + case E_ITEM_GUNPOWDER: break; + case E_ITEM_DIAMOND: Recipe->m_Result.m_FireworkItem.m_HasTrail = true; break; + case E_ITEM_GLOWSTONE_DUST: Recipe->m_Result.m_FireworkItem.m_HasFlicker = true; break; + + case E_ITEM_FIRE_CHARGE: Recipe->m_Result.m_FireworkItem.m_Type = 1; break; + case E_ITEM_GOLD_NUGGET: Recipe->m_Result.m_FireworkItem.m_Type = 2; break; + case E_ITEM_FEATHER: Recipe->m_Result.m_FireworkItem.m_Type = 4; break; + case E_ITEM_HEAD: Recipe->m_Result.m_FireworkItem.m_Type = 3; break; + default: LOG("Unexpected item in firework star recipe, was the crafting file fireworks section changed?"); break; // ermahgerd BARD ardmins + } + } + } + return Recipe.release(); } diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index ef82c6e94..be8e24540 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -214,7 +214,7 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Ve -cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d * a_Speed) +cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item, const Vector3d * a_Speed) { Vector3d Speed; if (a_Speed != NULL) @@ -231,8 +231,15 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, case pkGhastFireball: return new cGhastFireballEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkFireCharge: return new cFireChargeEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkExpBottle: return new cExpBottleEntity (a_Creator, a_X, a_Y, a_Z, Speed); - case pkFirework: return new cFireworkEntity (a_Creator, a_X, a_Y, a_Z ); - // TODO: the rest + case pkFirework: + { + if (a_Item.m_FireworkItem.m_Colours.empty()) + { + return NULL; + } + + return new cFireworkEntity(a_Creator, a_X, a_Y, a_Z, a_Item); + } } LOGWARNING("%s: Unknown projectile kind: %d", __FUNCTION__, a_Kind); @@ -276,6 +283,7 @@ AString cProjectileEntity::GetMCAClassName(void) const case pkExpBottle: return "ThrownExpBottle"; case pkSplashPotion: return "ThrownPotion"; case pkWitherSkull: return "WitherSkull"; + case pkFirework: return "Firework"; case pkFishingFloat: return ""; // Unknown, perhaps MC doesn't save this? } ASSERT(!"Unhandled projectile entity kind!"); @@ -693,8 +701,10 @@ void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_H /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cFireworkEntity : -cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z) : -super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) : +super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), + m_ExplodeTimer(0), + m_FireworkItem(a_Item) { } @@ -702,30 +712,20 @@ super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -void cFireworkEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { - if ((a_HitFace != BLOCK_FACE_BOTTOM) && (a_HitFace != BLOCK_FACE_NONE)) + int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; + int PosY = POSY_TOINT; + + if ((PosY < 0) || (PosY >= cChunkDef::Height)) { - return; + goto setspeed; } - SetSpeed(0, 0, 0); - SetPosition(GetPosX(), GetPosY() - 0.5, GetPosZ()); - - m_IsInGround = true; - - BroadcastMovementUpdate(); -} - - - - - -void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) -{ if (m_IsInGround) { - if (a_Chunk.GetBlock((int)GetPosX(), (int)GetPosY() + 1, (int)GetPosZ()) == E_BLOCK_AIR) + if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR) { m_IsInGround = false; } @@ -734,28 +734,35 @@ void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) return; } } + else + { + if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR) + { + OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM); + return; + } + } - Vector3d PerTickSpeed = GetSpeed() / 20; - Vector3d Pos = GetPosition(); +setspeed: + AddSpeedY(1); + AddPosition(GetSpeed() * (a_Dt / 1000)); +} - // Trace the tick's worth of movement as a line: - Vector3d NextPos = Pos + PerTickSpeed; - cProjectileTracerCallback TracerCallback(this); - if (!cLineBlockTracer::Trace(*m_World, TracerCallback, Pos, NextPos)) + + + + +void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + + if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks) { - // Something has been hit, abort all other processing - return; + m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_FIREWORK_EXPLODE); + Destroy(); } - // The tracer also checks the blocks for slowdown blocks - water and lava - and stores it for later in its SlowdownCoeff - - // Update the position: - SetPosition(NextPos); - // Add slowdown and gravity effect to the speed: - Vector3d NewSpeed(GetSpeed()); - NewSpeed.y += 2; - NewSpeed *= TracerCallback.GetSlowdownCoeff(); - SetSpeed(NewSpeed); + m_ExplodeTimer++; } diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index e80592999..fac592d16 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -46,7 +46,7 @@ public: cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, double a_Width, double a_Height); cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Vector3d & a_Pos, const Vector3d & a_Speed, double a_Width, double a_Height); - static cProjectileEntity * Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d * a_Speed = NULL); + static cProjectileEntity * Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item, const Vector3d * a_Speed = NULL); /// Called by the physics blocktracer when the entity hits a solid block, the hit position and the face hit (BLOCK_FACE_) is given virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace); @@ -305,13 +305,19 @@ public: CLASS_PROTODEF(cFireworkEntity); - cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z); + cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item); + const cItem & GetItem(void) const { return m_FireworkItem; } protected: // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + +private: + + int m_ExplodeTimer; + cItem m_FireworkItem; // tolua_begin diff --git a/src/Item.cpp b/src/Item.cpp index 9170006b6..61d57e763 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -1,4 +1,4 @@ - + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Item.h" @@ -139,6 +139,16 @@ void cItem::GetJson(Json::Value & a_OutValue) const { a_OutValue["Lore"] = m_Lore; } + + if ((m_ItemType == E_ITEM_FIREWORK_ROCKET) || (m_ItemType == E_ITEM_FIREWORK_STAR)) + { + a_OutValue["Flicker"] = m_FireworkItem.m_HasFlicker; + a_OutValue["Trail"] = m_FireworkItem.m_HasTrail; + a_OutValue["Type"] = m_FireworkItem.m_Type; + a_OutValue["FlightTimeInTicks"] = m_FireworkItem.m_FlightTimeInTicks; + a_OutValue["Colours"] = m_FireworkItem.ColoursToString(m_FireworkItem); + a_OutValue["FadeColours"] = m_FireworkItem.FadeColoursToString(m_FireworkItem); + } } } @@ -157,6 +167,16 @@ void cItem::FromJson(const Json::Value & a_Value) m_Enchantments.AddFromString(a_Value.get("ench", "").asString()); m_CustomName = a_Value.get("Name", "").asString(); m_Lore = a_Value.get("Lore", "").asString(); + + if ((m_ItemType == E_ITEM_FIREWORK_ROCKET) || (m_ItemType == E_ITEM_FIREWORK_STAR)) + { + m_FireworkItem.m_HasFlicker = a_Value.get("Flicker", false).asBool(); + m_FireworkItem.m_HasTrail = a_Value.get("Trail", false).asBool(); + m_FireworkItem.m_Type = (NIBBLETYPE)a_Value.get("Type", 0).asInt(); + m_FireworkItem.m_FlightTimeInTicks = (short)a_Value.get("FlightTimeInTicks", 0).asInt(); + m_FireworkItem.ColoursFromString(a_Value.get("Colours", "").asString(), m_FireworkItem); + m_FireworkItem.FadeColoursFromString(a_Value.get("FadeColours", "").asString(), m_FireworkItem); + } } } diff --git a/src/Item.h b/src/Item.h index cc3b3c961..4bdfb12dd 100644 --- a/src/Item.h +++ b/src/Item.h @@ -11,6 +11,7 @@ #include "Defines.h" #include "Enchantments.h" +#include "WorldStorage/FireworksSerializer.h" @@ -38,7 +39,8 @@ public: m_ItemCount(0), m_ItemDamage(0), m_CustomName(""), - m_Lore("") + m_Lore(""), + m_FireworkItem() { } @@ -57,7 +59,8 @@ public: m_ItemDamage (a_ItemDamage), m_Enchantments(a_Enchantments), m_CustomName (a_CustomName), - m_Lore (a_Lore) + m_Lore (a_Lore), + m_FireworkItem() { if (!IsValidItem(m_ItemType)) { @@ -77,7 +80,8 @@ public: m_ItemDamage (a_CopyFrom.m_ItemDamage), m_Enchantments(a_CopyFrom.m_Enchantments), m_CustomName (a_CopyFrom.m_CustomName), - m_Lore (a_CopyFrom.m_Lore) + m_Lore (a_CopyFrom.m_Lore), + m_FireworkItem(a_CopyFrom.m_FireworkItem) { } @@ -90,6 +94,7 @@ public: m_Enchantments.Clear(); m_CustomName = ""; m_Lore = ""; + m_FireworkItem.EmptyData(); } @@ -115,7 +120,8 @@ public: (m_ItemDamage == a_Item.m_ItemDamage) && (m_Enchantments == a_Item.m_Enchantments) && (m_CustomName == a_Item.m_CustomName) && - (m_Lore == a_Item.m_Lore) + (m_Lore == a_Item.m_Lore) && + m_FireworkItem.IsEqualTo(a_Item.m_FireworkItem) ); } @@ -177,6 +183,8 @@ public: cEnchantments m_Enchantments; AString m_CustomName; AString m_Lore; + + cFireworkItem m_FireworkItem; }; // tolua_end diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h index 46049f961..c6a4e714e 100644 --- a/src/Items/ItemThrowable.h +++ b/src/Items/ItemThrowable.h @@ -35,7 +35,7 @@ public: Vector3d Pos = a_Player->GetThrowStartPos(); Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff; - a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, &Speed); + a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, a_Player->GetEquippedItem(), &Speed); return true; } @@ -127,13 +127,13 @@ public: return false; } + a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, a_Player->GetEquippedItem()); + if (!a_Player->IsGameModeCreative()) { a_Player->GetInventory().RemoveOneEquippedItem(); } - a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, 0); - return true; } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 992023464..e0f02930c 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2069,36 +2069,47 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) // Load enchantments and custom display names from the NBT data: for (int tag = NBT.GetFirstChild(NBT.GetRoot()); tag >= 0; tag = NBT.GetNextSibling(tag)) { - if ( - (NBT.GetType(tag) == TAG_List) && - ( - (NBT.GetName(tag) == "ench") || - (NBT.GetName(tag) == "StoredEnchantments") - ) - ) + AString TagName = NBT.GetName(tag); + switch (NBT.GetType(tag)) { - EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, NBT, tag); - } - else if ((NBT.GetType(tag) == TAG_Compound) && (NBT.GetName(tag) == "display")) // Custom name and lore tag - { - for (int displaytag = NBT.GetFirstChild(tag); displaytag >= 0; displaytag = NBT.GetNextSibling(displaytag)) + case TAG_List: { - if ((NBT.GetType(displaytag) == TAG_String) && (NBT.GetName(displaytag) == "Name")) // Custon name tag + if ((TagName == "ench") || (TagName == "StoredEnchantments")) // Enchantments tags { - a_Item.m_CustomName = NBT.GetString(displaytag); + EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, NBT, tag); } - else if ((NBT.GetType(displaytag) == TAG_List) && (NBT.GetName(displaytag) == "Lore")) // Lore tag + break; + } + case TAG_Compound: + { + if (TagName == "display") // Custom name and lore tag { - AString Lore; - - for (int loretag = NBT.GetFirstChild(displaytag); loretag >= 0; loretag = NBT.GetNextSibling(loretag)) // Loop through array of strings + for (int displaytag = NBT.GetFirstChild(tag); displaytag >= 0; displaytag = NBT.GetNextSibling(displaytag)) { - AppendPrintf(Lore, "%s`", NBT.GetString(loretag).c_str()); // Append the lore with a newline, used internally by MCS to display a new line in the client; don't forget to c_str ;) + if ((NBT.GetType(displaytag) == TAG_String) && (NBT.GetName(displaytag) == "Name")) // Custon name tag + { + a_Item.m_CustomName = NBT.GetString(displaytag); + } + else if ((NBT.GetType(displaytag) == TAG_List) && (NBT.GetName(displaytag) == "Lore")) // Lore tag + { + AString Lore; + + for (int loretag = NBT.GetFirstChild(displaytag); loretag >= 0; loretag = NBT.GetNextSibling(loretag)) // Loop through array of strings + { + AppendPrintf(Lore, "%s`", NBT.GetString(loretag).c_str()); // Append the lore with a newline, used internally by MCS to display a new line in the client; don't forget to c_str ;) + } + + a_Item.m_Lore = Lore; + } } - - a_Item.m_Lore = Lore; } + else if ((TagName == "Fireworks") || (TagName == "Explosion")) + { + cFireworkItem::ParseFromNBT(a_Item.m_FireworkItem, NBT, tag, (ENUM_ITEM_ID)a_Item.m_ItemType); + } + break; } + default: LOGD("Unimplemented NBT data when parsing!"); break; } } } @@ -2262,7 +2273,7 @@ void cProtocol172::cPacketizer::WriteItem(const cItem & a_Item) WriteByte (a_Item.m_ItemCount); WriteShort(a_Item.m_ItemDamage); - if (a_Item.m_Enchantments.IsEmpty() && a_Item.IsBothNameAndLoreEmpty()) + if (a_Item.m_Enchantments.IsEmpty() && a_Item.IsBothNameAndLoreEmpty() && (a_Item.m_ItemType != E_ITEM_FIREWORK_ROCKET) && (a_Item.m_ItemType != E_ITEM_FIREWORK_STAR)) { WriteShort(-1); return; @@ -2301,6 +2312,10 @@ void cProtocol172::cPacketizer::WriteItem(const cItem & a_Item) } Writer.EndCompound(); } + if ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR)) + { + cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, Writer, (ENUM_ITEM_ID)a_Item.m_ItemType); + } Writer.Finish(); AString Compressed; CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed); @@ -2465,10 +2480,22 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity) } case cEntity::etProjectile: { - if (((cProjectileEntity &)a_Entity).GetProjectileKind() == cProjectileEntity::pkArrow) + cProjectileEntity & Projectile = (cProjectileEntity &)a_Entity; + switch (Projectile.GetProjectileKind()) { - WriteByte(0x10); - WriteByte(((const cArrowEntity &)a_Entity).IsCritical() ? 1 : 0); + case cProjectileEntity::pkArrow: + { + WriteByte(0x10); + WriteByte(((const cArrowEntity &)a_Entity).IsCritical() ? 1 : 0); + break; + } + case cProjectileEntity::pkFirework: + { + WriteByte(0xA8); + WriteItem(((const cFireworkEntity &)a_Entity).GetItem()); + break; + } + default: break; } break; } diff --git a/src/World.cpp b/src/World.cpp index ffdae2a37..ffb463169 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2904,9 +2904,9 @@ int cWorld::SpawnMobFinalize(cMonster * a_Monster) -int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const Vector3d * a_Speed) +int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem a_Item, const Vector3d * a_Speed) { - cProjectileEntity * Projectile = cProjectileEntity::Create(a_Kind, a_Creator, a_PosX, a_PosY, a_PosZ, a_Speed); + cProjectileEntity * Projectile = cProjectileEntity::Create(a_Kind, a_Creator, a_PosX, a_PosY, a_PosZ, a_Item, a_Speed); if (Projectile == NULL) { return -1; diff --git a/src/World.h b/src/World.h index 4b74f7aba..4fdbd8c0d 100644 --- a/src/World.h +++ b/src/World.h @@ -693,7 +693,7 @@ public: int SpawnMobFinalize(cMonster* a_Monster); /** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise */ - int CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const Vector3d * a_Speed = NULL); // tolua_export + int CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem a_Item, const Vector3d * a_Speed = NULL); // tolua_export /** Returns a random number from the m_TickRand in range [0 .. a_Range]. To be used only in the tick thread! */ int GetTickRandomNumber(unsigned a_Range) { return (int)(m_TickRand.randInt(a_Range)); } diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h index a78b610cb..e7e56282f 100644 --- a/src/WorldStorage/FastNBT.h +++ b/src/WorldStorage/FastNBT.h @@ -266,7 +266,7 @@ protected: eTagType m_ItemType; // for TAG_List, the element type } ; - static const int MAX_STACK = 50; // Highliy doubtful that an NBT would be constructed this many levels deep + static const int MAX_STACK = 50; // Highly doubtful that an NBT would be constructed this many levels deep // These two fields emulate a stack. A raw array is used due to speed issues - no reallocations are allowed. sParent m_Stack[MAX_STACK]; diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp new file mode 100644 index 000000000..eeb4e39ee --- /dev/null +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -0,0 +1,250 @@ + +#include "Globals.h" +#include "FireworksSerializer.h" +#include "WorldStorage/FastNBT.h" +#include + + + + + +void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFastNBTWriter & a_Writer, const ENUM_ITEM_ID a_Type) +{ + switch (a_Type) + { + case E_ITEM_FIREWORK_ROCKET: + { + a_Writer.BeginCompound("Fireworks"); + a_Writer.AddByte("Flight", a_FireworkItem.m_FlightTimeInTicks / 20); + a_Writer.BeginList("Explosions", TAG_Compound); + a_Writer.BeginCompound(""); + a_Writer.AddByte("Flicker", a_FireworkItem.m_HasFlicker); + a_Writer.AddByte("Trail", a_FireworkItem.m_HasTrail); + a_Writer.AddByte("Type", a_FireworkItem.m_Type); + a_Writer.AddIntArray("Colors", a_FireworkItem.m_Colours.data(), a_FireworkItem.m_Colours.size()); + a_Writer.AddIntArray("FadeColors", a_FireworkItem.m_FadeColours.data(), a_FireworkItem.m_FadeColours.size()); + a_Writer.EndCompound(); + a_Writer.EndList(); + a_Writer.EndCompound(); + break; + } + case E_ITEM_FIREWORK_STAR: + { + a_Writer.BeginCompound("Explosion"); + a_Writer.AddByte("Flicker", a_FireworkItem.m_HasFlicker); + a_Writer.AddByte("Trail", a_FireworkItem.m_HasTrail); + a_Writer.AddByte("Type", a_FireworkItem.m_Type); + if (!a_FireworkItem.m_Colours.empty()) + { + a_Writer.AddIntArray("Colors", a_FireworkItem.m_Colours.data(), a_FireworkItem.m_Colours.size()); + } + if (!a_FireworkItem.m_FadeColours.empty()) + { + a_Writer.AddIntArray("FadeColors", a_FireworkItem.m_FadeColours.data(), a_FireworkItem.m_FadeColours.size()); + } + a_Writer.EndCompound(); + break; + } + default: ASSERT(!"Unhandled firework item!"); break; + } +} + + + + + +void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNBT & a_NBT, int a_TagIdx, const ENUM_ITEM_ID a_Type) +{ + if (a_TagIdx < 0) + { + return; + } + + switch (a_Type) + { + case E_ITEM_FIREWORK_STAR: + { + for (int explosiontag = a_NBT.GetFirstChild(a_TagIdx); explosiontag >= 0; explosiontag = a_NBT.GetNextSibling(explosiontag)) + { + eTagType TagType = a_NBT.GetType(explosiontag); + if (TagType == TAG_Byte) // Custon name tag + { + AString ExplosionName = a_NBT.GetName(explosiontag); + + if (ExplosionName == "Flicker") + { + a_FireworkItem.m_HasFlicker = (a_NBT.GetByte(explosiontag) == 1); + } + else if (ExplosionName == "Trail") + { + a_FireworkItem.m_HasTrail = (a_NBT.GetByte(explosiontag) == 1); + } + else if (ExplosionName == "Type") + { + a_FireworkItem.m_Type = a_NBT.GetByte(explosiontag); + } + } + else if (TagType == TAG_IntArray) + { + AString ExplosionName = a_NBT.GetName(explosiontag); + + if (ExplosionName == "Colors") + { + if (a_NBT.GetDataLength(explosiontag) == 0) + { + continue; + } + + const int * ColourData = (const int *)(a_NBT.GetData(explosiontag)); + for (int i = 0; i < ARRAYCOUNT(ColourData); i++) + { + a_FireworkItem.m_Colours.push_back(ntohl(ColourData[i])); + } + } + else if (ExplosionName == "FadeColors") + { + if (a_NBT.GetDataLength(explosiontag) == 0) + { + continue; + } + + const int * FadeColourData = (const int *)(a_NBT.GetData(explosiontag)); + for (int i = 0; i < ARRAYCOUNT(FadeColourData); i++) + { + a_FireworkItem.m_FadeColours.push_back(ntohl(FadeColourData[i])); + } + } + } + } + break; + } + case E_ITEM_FIREWORK_ROCKET: + { + for (int fireworkstag = a_NBT.GetFirstChild(a_TagIdx); fireworkstag >= 0; fireworkstag = a_NBT.GetNextSibling(fireworkstag)) + { + eTagType TagType = a_NBT.GetType(fireworkstag); + if (TagType == TAG_Byte) // Custon name tag + { + if (a_NBT.GetName(fireworkstag) == "Flight") + { + a_FireworkItem.m_FlightTimeInTicks = a_NBT.GetByte(fireworkstag) * 20; + } + } + else if ((TagType == TAG_List) && (a_NBT.GetName(fireworkstag) == "Explosions")) + { + int ExplosionsChild = a_NBT.GetFirstChild(fireworkstag); + if ((a_NBT.GetType(ExplosionsChild) == TAG_Compound) && (a_NBT.GetName(ExplosionsChild).empty())) + { + ParseFromNBT(a_FireworkItem, a_NBT, ExplosionsChild, E_ITEM_FIREWORK_STAR); + } + } + } + break; + } + default: ASSERT(!"Unhandled firework item!"); break; + } +} + + + + + +AString cFireworkItem::ColoursToString(const cFireworkItem & a_FireworkItem) +{ + AString Result; + + for (std::vector::const_iterator itr = a_FireworkItem.m_Colours.begin(); itr != a_FireworkItem.m_Colours.end(); ++itr) + { + AppendPrintf(Result, "%i;", *itr); + } + + return Result; +} + + + + + +void cFireworkItem::ColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem) +{ + AStringVector Split = StringSplit(a_String, ";"); + + for (size_t itr = 0; itr < Split.size(); ++itr) + { + if (Split[itr].empty()) + { + continue; + } + + a_FireworkItem.m_Colours.push_back(atoi(Split[itr].c_str())); + } +} + + + + + +AString cFireworkItem::FadeColoursToString(const cFireworkItem & a_FireworkItem) +{ + AString Result; + + for (std::vector::const_iterator itr = a_FireworkItem.m_FadeColours.begin(); itr != a_FireworkItem.m_FadeColours.end(); ++itr) + { + AppendPrintf(Result, "%i;", *itr); + } + + return Result; +} + + + + + +void cFireworkItem::FadeColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem) +{ + AStringVector Split = StringSplit(a_String, ";"); + + for (size_t itr = 0; itr < Split.size(); ++itr) + { + if (Split[itr].empty()) + { + continue; + } + + a_FireworkItem.m_FadeColours.push_back(atoi(Split[itr].c_str())); + } +} + + + + + +int GetVanillaColourCodeFromDye(short a_DyeMeta) +{ + /* + Colours are supposed to be calculated via: R << 16 + G << 8 + B + However, the RGB values fireworks use aren't the same as the ones for dyes (the ones listed in the MC Wiki) + Therefore, here is a list of numbers gotten via the Protocol Proxy + */ + + switch (a_DyeMeta) + { + case E_META_DYE_BLACK: return 1973019; + case E_META_DYE_RED: return 11743532; + case E_META_DYE_GREEN: return 3887386; + case E_META_DYE_BROWN: return 5320730; + case E_META_DYE_BLUE: return 2437522; + case E_META_DYE_PURPLE: return 8073150; + case E_META_DYE_CYAN: return 2651799; + case E_META_DYE_LIGHTGRAY: return 11250603; + case E_META_DYE_GRAY: return 4408131; + case E_META_DYE_PINK: return 14188952; + case E_META_DYE_LIGHTGREEN: return 4312372; + case E_META_DYE_YELLOW: return 14602026; + case E_META_DYE_LIGHTBLUE: return 6719955; + case E_META_DYE_MAGENTA: return 12801229; + case E_META_DYE_ORANGE: return 15435844; + case E_META_DYE_WHITE: return 15790320; + default: ASSERT(!"Unhandled dye meta whilst trying to get colour code for fireworks!"); break; + } +} diff --git a/src/WorldStorage/FireworksSerializer.h b/src/WorldStorage/FireworksSerializer.h new file mode 100644 index 000000000..475d80bda --- /dev/null +++ b/src/WorldStorage/FireworksSerializer.h @@ -0,0 +1,88 @@ + +// FireworksSerializer.h + +// Declares the cFireworkItem class representing a firework or firework star + + + + + +#pragma once + +#include "Defines.h" + +class cFastNBTWriter; +class cParsedNBT; + + + + + +class cFireworkItem +{ +public: + cFireworkItem(void) : + m_HasFlicker(false), + m_HasTrail(false), + m_Type(0), + m_FlightTimeInTicks(0) + { + } + + inline void CopyFrom(const cFireworkItem & a_Item) + { + m_FlightTimeInTicks = a_Item.m_FlightTimeInTicks; + m_HasFlicker = a_Item.m_HasFlicker; + m_HasTrail = a_Item.m_HasTrail; + m_Type = a_Item.m_Type; + m_Colours = a_Item.m_Colours; + m_FadeColours = a_Item.m_FadeColours; + } + + inline void EmptyData(void) + { + m_FlightTimeInTicks = 0; + m_HasFlicker = false; + m_Type = 0; + m_HasTrail = false; + m_Colours.clear(); + m_FadeColours.clear(); + } + + inline bool IsEqualTo(const cFireworkItem & a_Item) const + { + return + ( + (m_FlightTimeInTicks == a_Item.m_FlightTimeInTicks) && + (m_HasFlicker == a_Item.m_HasFlicker) && + (m_HasTrail == a_Item.m_HasTrail) && + (m_Type == a_Item.m_Type) && + (m_Colours == a_Item.m_Colours) && + (m_FadeColours == a_Item.m_FadeColours) + ); + } + + /** Writes firework NBT data to a Writer object */ + static void WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFastNBTWriter & a_Writer, const ENUM_ITEM_ID a_Type); + /** Reads NBT data from a NBT object and populates a FireworkItem with it */ + static void ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNBT & a_NBT, int a_TagIdx, const ENUM_ITEM_ID a_Type); + + /** Converts the firework's vector of colours into a string of values separated by a semicolon */ + static AString ColoursToString(const cFireworkItem & a_FireworkItem); + /** Parses a string containing encoded firework colours and populates a FireworkItem with it */ + static void ColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem); + /** Converts the firework's vector of fade colours into a string of values separated by a semicolon */ + static AString FadeColoursToString(const cFireworkItem & a_FireworkItem); + /** Parses a string containing encoded firework fade colours and populates a FireworkItem with it */ + static void FadeColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem); + + /** Returns a colour code for fireworks used by the network code */ + static const inline int GetVanillaColourCodeFromDye(short a_DyeMeta); + + bool m_HasFlicker; + bool m_HasTrail; + NIBBLETYPE m_Type; + short m_FlightTimeInTicks; + std::vector m_Colours; + std::vector m_FadeColours; +}; \ No newline at end of file diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index c1c659b36..6d82cba86 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -90,11 +90,19 @@ void cNBTChunkSerializer::AddItem(const cItem & a_Item, int a_Slot, const AStrin } // Write the enchantments: - if (!a_Item.m_Enchantments.IsEmpty()) + if (!a_Item.m_Enchantments.IsEmpty() || ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR))) { - const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench"; m_Writer.BeginCompound("tag"); - EnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, m_Writer, TagName); + if ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR)) + { + cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, m_Writer, (ENUM_ITEM_ID)a_Item.m_ItemType); + } + + if (!a_Item.m_Enchantments.IsEmpty()) + { + const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench"; + EnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, m_Writer, TagName); + } m_Writer.EndCompound(); } diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 05332d23d..0658d5029 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -658,6 +658,12 @@ bool cWSSAnvil::LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_ { EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, a_NBT, EnchTag); } + + int FireworksTag = a_NBT.FindChildByName(TagTag, ((a_Item.m_ItemType == E_ITEM_FIREWORK_STAR) ? "Fireworks" : "Explosion")); + if (EnchTag > 0) + { + cFireworkItem::ParseFromNBT(a_Item.m_FireworkItem, a_NBT, FireworksTag, (ENUM_ITEM_ID)a_Item.m_ItemType); + } return true; } -- cgit v1.2.3 From a97f28939fb706cbe26bc0de400c7bf2f14f19f4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 26 Feb 2014 23:30:10 +0000 Subject: Fixed sheep ASSERTing sometimes --- src/Mobs/Sheep.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index 4761103e5..c64360153 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -68,17 +68,28 @@ void cSheep::OnRightClicked(cPlayer & a_Player) void cSheep::Tick(float a_Dt, cChunk & a_Chunk) { - // The sheep should not move when he's eating so only handle the physics. + super::Tick(a_Dt, a_Chunk); + int PosX = POSX_TOINT; + int PosY = POSY_TOINT - 1; + int PosZ = POSZ_TOINT; + + if ((PosY <= 0) || (PosY > cChunkDef::Height)) + { + return; + } + if (m_TimeToStopEating > 0) { - HandlePhysics(a_Dt, a_Chunk); + m_bMovingToDestination = false; // The sheep should not move when he's eating m_TimeToStopEating--; + if (m_TimeToStopEating == 0) { - if (m_World->GetBlock((int) GetPosX(), (int) GetPosY() - 1, (int) GetPosZ()) == E_BLOCK_GRASS) + if (m_World->GetBlock(PosX, PosY, PosZ) == E_BLOCK_GRASS) // Make sure grass hasn't been destroyed in the meantime { - // The sheep ate the grass so we change it to dirt. - m_World->SetBlock((int) GetPosX(), (int) GetPosY() - 1, (int) GetPosZ(), E_BLOCK_DIRT, 0); + // The sheep ate the grass so we change it to dirt + m_World->SetBlock(PosX, PosY, PosZ, E_BLOCK_DIRT, 0); + GetWorld()->BroadcastSoundParticleEffect(2001, PosX, PosY, PosX, E_BLOCK_GRASS); m_IsSheared = false; m_World->BroadcastEntityMetadata(*this); } @@ -86,12 +97,11 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk) } else { - super::Tick(a_Dt, a_Chunk); if (m_World->GetTickRandomNumber(600) == 1) { - if (m_World->GetBlock((int) GetPosX(), (int) GetPosY() - 1, (int) GetPosZ()) == E_BLOCK_GRASS) + if (m_World->GetBlock(PosX, PosY, PosZ) == E_BLOCK_GRASS) { - m_World->BroadcastEntityStatus(*this, 10); + m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_SHEEP_EATING); m_TimeToStopEating = 40; } } -- cgit v1.2.3 From 9c6d72a023807fca238361d636a52166f952fa59 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 27 Feb 2014 09:06:25 +0100 Subject: Fixed crash and some warnings in map handling. Fixes #728. --- src/Items/ItemEmptyMap.h | 6 +++--- src/Map.cpp | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index 6618bfce2..f0b1e1424 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -36,10 +36,10 @@ public: // The map center is fixed at the central point of the 8x8 block of chunks you are standing in when you right-click it. - const int RegionWidth = cChunkDef::Width * 8 * pow(2.0, (double) DEFAULT_SCALE); + const int RegionWidth = cChunkDef::Width * 8; - int CenterX = floor(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth; - int CenterZ = floor(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth; + int CenterX = (int)(floor(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth); + int CenterZ = (int)(floor(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth); cMap * NewMap = a_World->GetMapManager().CreateMap(CenterX, CenterZ, DEFAULT_SCALE); diff --git a/src/Map.cpp b/src/Map.cpp index 337c9cd31..2d8f57168 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -357,6 +357,8 @@ void cMap::AddPlayer(cPlayer * a_Player, Int64 a_WorldAge) MapClient.m_LastUpdate = a_WorldAge; MapClient.m_SendInfo = true; MapClient.m_Handle = Handle; + MapClient.m_DataUpdate = 0; + MapClient.m_NextDecoratorUpdate = 0; m_Clients.push_back(MapClient); -- cgit v1.2.3 From a23b5d13bde0742e6208bcc75807a97c1c12f7e1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 27 Feb 2014 15:17:42 +0100 Subject: Added a "nooutbuf" cmdline param. This forces that the stdout stream uses no buffer, even when not a TTY. Used for running MCServer under ZeroBraneStudio. --- src/Log.cpp | 4 ++-- src/main.cpp | 27 ++++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index 2d6be0f59..1ea327d5d 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -42,7 +42,7 @@ cLog::~cLog() -cLog* cLog::GetInstance() +cLog * cLog::GetInstance() { if (s_Log != NULL) { @@ -92,7 +92,7 @@ void cLog::ClearLog() if( m_File ) fclose (m_File); #endif - m_File = 0; + m_File = NULL; } diff --git a/src/main.cpp b/src/main.cpp index 4d2801926..2ae8a413b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -243,31 +243,36 @@ int main( int argc, char **argv ) // Check if comm logging is to be enabled: for (int i = 0; i < argc; i++) { + AString Arg(argv[i]); if ( - (NoCaseCompare(argv[i], "/commlog") == 0) || - (NoCaseCompare(argv[i], "/logcomm") == 0) + (NoCaseCompare(Arg, "/commlog") == 0) || + (NoCaseCompare(Arg, "/logcomm") == 0) ) { g_ShouldLogCommIn = true; g_ShouldLogCommOut = true; } - if ( - (NoCaseCompare(argv[i], "/commlogin") == 0) || - (NoCaseCompare(argv[i], "/comminlog") == 0) || - (NoCaseCompare(argv[i], "/logcommin") == 0) + else if ( + (NoCaseCompare(Arg, "/commlogin") == 0) || + (NoCaseCompare(Arg, "/comminlog") == 0) || + (NoCaseCompare(Arg, "/logcommin") == 0) ) { g_ShouldLogCommIn = true; } - if ( - (NoCaseCompare(argv[i], "/commlogout") == 0) || - (NoCaseCompare(argv[i], "/commoutlog") == 0) || - (NoCaseCompare(argv[i], "/logcommout") == 0) + else if ( + (NoCaseCompare(Arg, "/commlogout") == 0) || + (NoCaseCompare(Arg, "/commoutlog") == 0) || + (NoCaseCompare(Arg, "/logcommout") == 0) ) { g_ShouldLogCommOut = true; } - } + else if (NoCaseCompare(Arg, "nooutbuf") == 0) + { + setvbuf(stdout, NULL, _IONBF, 0); + } + } // for i - argv[] #if !defined(ANDROID_NDK) try -- cgit v1.2.3 From 84913299f45a28d3bd6146b3decbf14764449030 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 27 Feb 2014 11:33:35 -0800 Subject: Added some Metadate rotaters using templated Mixin --- src/Blocks/BlockBed.h | 5 +-- src/Blocks/BlockButton.h | 4 +-- src/Blocks/BlockChest.h | 4 +-- src/Blocks/BlockComparator.h | 4 +-- src/Blocks/BlockDoor.cpp | 2 +- src/Blocks/BlockDoor.h | 57 +++++++++++++++++++++++++++++- src/Blocks/BlockDropSpenser.h | 18 ++++++++-- src/Blocks/BlockEnderchest.h | 4 +-- src/Blocks/BlockFenceGate.h | 4 +-- src/Blocks/MetaRotater.h | 82 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 168 insertions(+), 16 deletions(-) create mode 100644 src/Blocks/MetaRotater.h diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index caec2b56f..6e8884114 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -4,6 +4,7 @@ #include "BlockHandler.h" #include "ChunkInterface.h" #include "WorldInterface.h" +#include "MetaRotater.h" #include "../Entities/Player.h" @@ -11,11 +12,11 @@ class cBlockBedHandler : - public cBlockHandler + public cMetaRotater { public: cBlockBedHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index ca6850ced..5a4bf7c96 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -7,11 +7,11 @@ class cBlockButtonHandler : - public cBlockHandler + public cMetaRotater { public: cBlockButtonHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 02ecc4346..4ab23bced 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -10,11 +10,11 @@ class cBlockChestHandler : - public cBlockEntityHandler + public cMetaRotater { public: cBlockChestHandler(BLOCKTYPE a_BlockType) - : cBlockEntityHandler(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index aba390d9d..7e672eece 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -9,11 +9,11 @@ class cBlockComparatorHandler : - public cBlockHandler + public cMetaRotater { public: cBlockComparatorHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index 2ff5c1c37..f0d0b4b7f 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -9,7 +9,7 @@ cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : super(a_BlockType) { } diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index ef0dbb787..c3647b203 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -9,8 +9,9 @@ class cBlockDoorHandler : - public cBlockHandler + public cMetaRotater { + typedef super cMetaRotater; public: cBlockDoorHandler(BLOCKTYPE a_BlockType); @@ -167,6 +168,60 @@ public: } + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override + { + if (a_Meta & 0x08) + { + return a_Meta; + } + else + { + return super::MetaRotateCCW(a_Meta); + } + } + + + + virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override + { + if (a_Meta & 0x08) + { + return a_Meta; + } + else + { + return super::MetaRotateCW(a_Meta); + } + } + + + + virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override + { + if (a_Meta & 0x08) + { + return a_Meta; + } + else + { + return super::MetaMirrorXY(a_Meta); + } + } + + + + virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override + { + if (a_Meta & 0x08) + { + return a_Meta; + } + else + { + return super::MetaMirrorYZ(a_Meta); + } + } + } ; diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index 30d347ec9..2253fcd1b 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -12,11 +12,11 @@ class cBlockDropSpenserHandler : - public cBlockEntityHandler + public cMetaRotater { public: cBlockDropSpenserHandler(BLOCKTYPE a_BlockType) : - cBlockEntityHandler(a_BlockType) + cMetaRotater(a_BlockType) { } @@ -34,6 +34,20 @@ public: a_BlockMeta = cPiston::RotationPitchToMetaData(a_Player->GetYaw(), a_Player->GetPitch()); return true; } + + virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override + { + // Bit 0x08 is a flag. Lowest three bits are position. 0x08 == 1000 + NIBBLETYPE OtherMeta = a_Meta & 0x08; + // Mirrors defined by by a table. (Source, mincraft.gamepedia.com) 0x07 == 0111 + switch (a_Meta & 0x07) + { + case 0x00: return 0x01 + OtherMeta; // Down -> Up + case 0x01: return 0x00 + OtherMeta; // Up -> Down + } + // Not Facing Up or Down; No change. + return a_Meta; + } } ; diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index b4b0b995d..ed3f37013 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -8,11 +8,11 @@ class cBlockEnderchestHandler : - public cBlockEntityHandler + public cMetaRotater { public: cBlockEnderchestHandler(BLOCKTYPE a_BlockType) - : cBlockEntityHandler(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index fb984f345..035579e8e 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -8,11 +8,11 @@ class cBlockFenceGateHandler : - public cBlockHandler + public cMetaRotater { public: cBlockFenceGateHandler(BLOCKTYPE a_BlockType) : - cBlockHandler(a_BlockType) + cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h new file mode 100644 index 000000000..f1656f1bd --- /dev/null +++ b/src/Blocks/MetaRotater.h @@ -0,0 +1,82 @@ + +#pragma once + +template +class cMetaRotater : public Base +{ +public: + + cMetaRotater(BLOCKTYPE a_BlockType) : + Base(a_BlockType) + {} + + virtual ~cMetaRotater() {} + + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override; + virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override; + virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override; + virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override; +}; + + +template +NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) +{ +NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); +switch (a_Meta & BitFilter) +{ +case South: return West | OtherMeta; +case West: return North | OtherMeta; +case North: return East | OtherMeta; +case East: return South | OtherMeta; +} +ASSERT(!"Invalid Meta value"); +return a_Meta; +} + + +template +NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) +{ +NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); +switch (a_Meta & BitFilter) +{ +case South: return East | OtherMeta; +case East: return North | OtherMeta; +case North: return West | OtherMeta; +case West: return South | OtherMeta; +} +ASSERT(!"Invalid Meta value"); +return a_Meta; +} + + + +template +NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) +{ +NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); +switch (a_Meta & BitFilter) +{ +case South: return North | OtherMeta; +case North: return South | OtherMeta; +} +// Not Facing North or South; No change. +return a_Meta; +} + + + + +template +NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) +{ +NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); +switch (a_Meta & BitFilter) +{ +case West: return East | OtherMeta; +case East: return West | OtherMeta; +} +// Not Facing East or West; No change. +return a_Meta; +} -- cgit v1.2.3 From 1de2c23d648af46a2e00402d0e231678c80311aa Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Thu, 27 Feb 2014 22:04:48 +0100 Subject: added mooshroom to cow conversion --- src/Mobs/Mooshroom.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 8e4c52ae6..81bd3e3b4 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -67,6 +67,8 @@ void cMooshroom::OnRightClicked(cPlayer & a_Player) cItems Drops; Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + m_World->SpawnMob(GetPosX(), GetPosY(), GetPosZ(), cMonster::mtCow); + Destroy(); } break; } } -- cgit v1.2.3 From 528467bc5c514d8ef193c4e9dd06fb5aeb9f0dd9 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 27 Feb 2014 21:48:49 +0000 Subject: Fixed compile --- src/WorldStorage/FireworksSerializer.cpp | 3 +-- src/WorldStorage/FireworksSerializer.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index eeb4e39ee..7f5077912 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -2,7 +2,6 @@ #include "Globals.h" #include "FireworksSerializer.h" #include "WorldStorage/FastNBT.h" -#include @@ -219,7 +218,7 @@ void cFireworkItem::FadeColoursFromString(const AString & a_String, cFireworkIte -int GetVanillaColourCodeFromDye(short a_DyeMeta) +int cFireworkItem::GetVanillaColourCodeFromDye(short a_DyeMeta) { /* Colours are supposed to be calculated via: R << 16 + G << 8 + B diff --git a/src/WorldStorage/FireworksSerializer.h b/src/WorldStorage/FireworksSerializer.h index 475d80bda..37fb6c883 100644 --- a/src/WorldStorage/FireworksSerializer.h +++ b/src/WorldStorage/FireworksSerializer.h @@ -77,7 +77,7 @@ public: static void FadeColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem); /** Returns a colour code for fireworks used by the network code */ - static const inline int GetVanillaColourCodeFromDye(short a_DyeMeta); + static int GetVanillaColourCodeFromDye(short a_DyeMeta); bool m_HasFlicker; bool m_HasTrail; -- cgit v1.2.3 From 9ac9249acaf21d01af41b4cdfc862961b1f9e286 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 27 Feb 2014 21:49:10 +0000 Subject: Removed unneeded includes in Player.cpp --- src/Entities/Player.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 0152bfc5b..f4039e548 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -10,18 +10,11 @@ #include "../BlockEntities/BlockEntity.h" #include "../GroupManager.h" #include "../Group.h" -#include "../ChatColor.h" -#include "../Item.h" -#include "../Tracer.h" #include "../Root.h" #include "../OSSupport/Timer.h" -#include "../MersenneTwister.h" #include "../Chunk.h" #include "../Items/ItemHandler.h" -#include "../Vector3d.h" -#include "../Vector3f.h" - #include "inifile/iniFile.h" #include "json/json.h" -- cgit v1.2.3 From 6a191cce0af0056ecde69efe1679a084aadd810c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Feb 2014 08:26:39 +0100 Subject: Fixed compatibility with ZeroBraneStudio and LuaRocks. Lua now compiles into lua51.dll and there's a lua5.1.dll that acts as a export-forwarding proxy to lua51.dll. --- MCServer/lua5.1.dll | Bin 0 -> 6722 bytes lib/lua/CMakeLists.txt | 6 +++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 MCServer/lua5.1.dll diff --git a/MCServer/lua5.1.dll b/MCServer/lua5.1.dll new file mode 100644 index 000000000..cca0bcb25 Binary files /dev/null and b/MCServer/lua5.1.dll differ diff --git a/lib/lua/CMakeLists.txt b/lib/lua/CMakeLists.txt index 4babae9b2..db112d557 100644 --- a/lib/lua/CMakeLists.txt +++ b/lib/lua/CMakeLists.txt @@ -47,8 +47,12 @@ if (WIN32) ) endif() + set_target_properties(lua PROPERTIES OUTPUT_NAME "lua51") + # NOTE: The DLL for each configuration is stored at the same place, thus overwriting each other. - # This is known, however such behavior is needed for LuaRocks - they always load "lua.dll" + # This is known, however such behavior is needed for LuaRocks - they always load "lua5.1.dll" or "lua51.dll" + # We make it work by compiling to "lua51.dll" and providing a proxy-DLL "lua5.1.dll" + # See http://lua-users.org/wiki/LuaProxyDllFour for details else() add_library(lua ${SOURCE}) endif() -- cgit v1.2.3 From 0aac17874c25a2c1be36a8b5d691331852cec49f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Feb 2014 08:31:35 +0100 Subject: Better fix for the 32-bit float reading. --- src/WorldStorage/FastNBT.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h index a78b610cb..49f97c458 100644 --- a/src/WorldStorage/FastNBT.h +++ b/src/WorldStorage/FastNBT.h @@ -173,13 +173,14 @@ public: { ASSERT(m_Tags[a_Tag].m_Type == TAG_Float); - // Cause a compile-time error if sizeof(int) != sizeof(float) - char Check1[sizeof(int) - sizeof(float) + 1]; // sizeof(int) >= sizeof(float) - char Check2[sizeof(float) - sizeof(int) + 1]; // sizeof(float) >= sizeof(int) + // Cause a compile-time error if sizeof(float) != 4 + // If your platform produces a compiler error here, you'll need to add code that manually decodes 32-bit floats + char Check1[5 - sizeof(float)]; // sizeof(float) <= 4 + char Check2[sizeof(float) - 3]; // sizeof(float) >= 4 UNUSED(Check1); UNUSED(Check2); - int i = GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); + Int32 i = GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); float f; memcpy(&f, &i, sizeof(f)); return f; -- cgit v1.2.3 From e4c3d3eb6decddddc986f1020f3fb30af48bbe4b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Feb 2014 10:37:09 +0100 Subject: Added a MobDebug enabler script. This file is to be copied to a plugin's folder in order to debug that plugin with MobDebug. --- MCServer/Plugins/@EnableMobDebug.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 MCServer/Plugins/@EnableMobDebug.lua diff --git a/MCServer/Plugins/@EnableMobDebug.lua b/MCServer/Plugins/@EnableMobDebug.lua new file mode 100644 index 000000000..48d4c36b7 --- /dev/null +++ b/MCServer/Plugins/@EnableMobDebug.lua @@ -0,0 +1,29 @@ + +-- @EnableMobDebug.lua + +-- Enables the MobDebug debugger, used by ZeroBrane Studio, for a plugin +-- Needs to be named with a @ at the start so that it's loaded as the first file of the plugin + +--[[ +Usage: +Copy this file to your plugin's folder when you want to debug that plugin +You should neither check this file into the plugin's version control system, +nor distribute it in the final release. +--]] + + + + + +-- Try to load the debugger, be silent about failures: +local IsSuccess, MobDebug = pcall(require, "mobdebug") +if (IsSuccess) then + MobDebug.start() + + -- The debugger will automatically put a breakpoint on this line, use this opportunity to set more breakpoints in your code + LOG(cPluginManager:GetCurrentPlugin():GetName() .. ": MobDebug enabled") +end + + + + -- cgit v1.2.3 From 66c84250410bf24bc689436c570c284bc47e3638 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 28 Feb 2014 15:26:32 +0100 Subject: Fix Double Slabs, fix Slab Meta and add more things to burnable --- src/Blocks/BlockSlab.h | 35 +++++++++++++++++++++++------------ src/ClientHandle.cpp | 2 +- src/Simulator/FireSimulator.cpp | 13 +++++++++++++ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index 3628303ce..8a3c998ec 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -28,7 +28,7 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { - a_Pickups.push_back(cItem(m_BlockType, 1, a_BlockMeta)); + a_Pickups.push_back(cItem(m_BlockType, 1, a_BlockMeta & 0x7)); } @@ -41,7 +41,7 @@ public: { a_BlockType = m_BlockType; BLOCKTYPE Type = (BLOCKTYPE) (a_Player->GetEquippedItem().m_ItemType); - NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x07); + NIBBLETYPE Meta = (NIBBLETYPE) a_Player->GetEquippedItem().m_ItemDamage; // HandlePlaceBlock wants a cItemHandler pointer thing, so let's give it one cItemHandler * ItemHandler = cItemHandler::GetItemHandler(GetDoubleSlabType(Type)); @@ -159,21 +159,32 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { - if (m_BlockType == E_BLOCK_DOUBLE_STONE_SLAB) - { - m_BlockType = E_BLOCK_STONE_SLAB; - } - else + BLOCKTYPE Block = GetSingleSlabType(m_BlockType); + a_Pickups.push_back(cItem(Block, 2, a_BlockMeta & 0x7)); + } + + inline static BLOCKTYPE GetSingleSlabType(BLOCKTYPE a_BlockType) + { + switch (a_BlockType) { - m_BlockType = E_BLOCK_WOODEN_SLAB; + case E_BLOCK_DOUBLE_STONE_SLAB: return E_BLOCK_STONE_SLAB; + case E_BLOCK_DOUBLE_WOODEN_SLAB: return E_BLOCK_WOODEN_SLAB; } - a_Pickups.push_back(cItem(m_BlockType, 2, a_BlockMeta)); + ASSERT(!"Unhandled double slab type!"); + return a_BlockType; } - virtual const char * GetStepSound(void) override - { - return ((m_BlockType == E_BLOCK_DOUBLE_WOODEN_SLAB) || (m_BlockType == E_BLOCK_DOUBLE_WOODEN_SLAB)) ? "step.wood" : "step.stone"; + { + BLOCKTYPE Block = GetSingleSlabType(m_BlockType); + if (Block != m_BlockType) + { + return cBlockHandler::GetBlockHandler(Block)->GetStepSound(); + } + else + { + return "step.stone"; + } } } ; diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index b08ceb5f6..ce549b0b1 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1043,7 +1043,7 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e if ( cBlockSlabHandler::IsAnySlabType(ClickedBlock) && // Is there a slab already? cBlockSlabHandler::IsAnySlabType(EquippedBlock) && // Is the player placing another slab? - ((ClickedBlockMeta & 0x07) == (EquippedBlockDamage & 0x07)) && // Is it the same slab type? + ((ClickedBlockMeta & 0x07) == EquippedBlockDamage) && // Is it the same slab type? ( (a_BlockFace == BLOCK_FACE_TOP) || // Clicking the top of a bottom slab (a_BlockFace == BLOCK_FACE_BOTTOM) // Clicking the bottom of a top slab diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index b77fa1658..85190c82b 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -162,14 +162,27 @@ bool cFireSimulator::IsFuel(BLOCKTYPE a_BlockType) switch (a_BlockType) { case E_BLOCK_PLANKS: + case E_BLOCK_DOUBLE_WOODEN_SLAB: + case E_BLOCK_WOODEN_SLAB: + case E_BLOCK_WOODEN_STAIRS: + case E_BLOCK_SPRUCE_WOOD_STAIRS: + case E_BLOCK_BIRCH_WOOD_STAIRS: + case E_BLOCK_JUNGLE_WOOD_STAIRS: case E_BLOCK_LEAVES: + case E_BLOCK_NEW_LEAVES: case E_BLOCK_LOG: + case E_BLOCK_NEW_LOG: case E_BLOCK_WOOL: case E_BLOCK_BOOKCASE: case E_BLOCK_FENCE: case E_BLOCK_TNT: case E_BLOCK_VINES: case E_BLOCK_HAY_BALE: + case E_BLOCK_TALL_GRASS: + case E_BLOCK_BIG_FLOWER: + case E_BLOCK_DANDELION: + case E_BLOCK_FLOWER: + case E_BLOCK_CARPET: { return true; } -- cgit v1.2.3 From 35def963f06dd46823300aebf09af0009189328b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Feb 2014 15:31:20 +0100 Subject: Moved common cGroupManager code to a separate function. This fixes my concerns in PR #709. --- src/Entities/Player.cpp | 18 +++++++++++------- src/GroupManager.cpp | 21 ++++++++++++++++----- src/GroupManager.h | 3 +++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index e0f0b9222..f419ee09c 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1529,14 +1529,14 @@ void cPlayer::LoadPermissionsFromDisk() std::string Groups = IniFile.GetValue(m_PlayerName, "Groups", ""); if (!Groups.empty()) { - AStringVector Split = StringSplit( Groups, "," ); - for( unsigned int i = 0; i < Split.size(); i++ ) + AStringVector Split = StringSplitAndTrim(Groups, ","); + for (AStringVector::const_iterator itr = Split.begin(), end = Split.end(); itr != end; ++itr) { - if (!cRoot::Get()->GetGroupManager()->ExistsGroup(Split[i])) + if (!cRoot::Get()->GetGroupManager()->ExistsGroup(*itr)) { - LOGWARNING("The group %s for player %s was not found!", Split[i].c_str(), m_PlayerName.c_str()); + LOGWARNING("The group %s for player %s was not found!", itr->c_str(), m_PlayerName.c_str()); } - AddToGroup(Split[i].c_str()); + AddToGroup(*itr); } } else @@ -1544,11 +1544,15 @@ void cPlayer::LoadPermissionsFromDisk() AddToGroup("Default"); } - m_Color = IniFile.GetValue(m_PlayerName, "Color", "-")[0]; + AString Color = IniFile.GetValue(m_PlayerName, "Color", "-"); + if (!Color.empty()) + { + m_Color = Color[0]; + } } else { - cRoot::Get()->GetGroupManager()->CheckUsers(); + cGroupManager::GenerateDefaultUsersIni(IniFile); AddToGroup("Default"); } ResolvePermissions(); diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 5125e7586..33b601e82 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -55,16 +55,27 @@ cGroupManager::cGroupManager() +void cGroupManager::GenerateDefaultUsersIni(cIniFile & a_IniFile) +{ + LOGWARN("Regenerating users.ini, all users will be reset"); + a_IniFile.AddHeaderComment(" This file stores the players' groups."); + a_IniFile.AddHeaderComment(" The format is:"); + a_IniFile.AddHeaderComment(" [PlayerName]"); + a_IniFile.AddHeaderComment(" Groups = GroupName1, GroupName2, ..."); + + a_IniFile.WriteFile("users.ini"); +} + + + + + void cGroupManager::CheckUsers(void) { cIniFile IniFile; if (!IniFile.ReadFile("users.ini")) { - LOGWARN("Regenerating users.ini, all users will be reset"); - IniFile.AddHeaderComment(" This is the file in which the group the player belongs to is stored"); - IniFile.AddHeaderComment(" The format is: [PlayerName] | Groups=GroupName"); - - IniFile.WriteFile("users.ini"); + GenerateDefaultUsersIni(IniFile); return; } diff --git a/src/GroupManager.h b/src/GroupManager.h index 377a54c98..9e1689a76 100644 --- a/src/GroupManager.h +++ b/src/GroupManager.h @@ -19,6 +19,9 @@ public: void LoadGroups(void); void CheckUsers(void); + /** Writes the default header to the specified ini file, and saves it as "users.ini". */ + static void GenerateDefaultUsersIni(cIniFile & a_IniFile); + private: friend class cRoot; cGroupManager(); -- cgit v1.2.3 From d97363a1b39fd94a77bb84a4d9732ab4f46b08b7 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Feb 2014 15:41:46 +0100 Subject: Documented the changes in cJukeboxEntity. --- MCServer/Plugins/APIDump/Classes/BlockEntities.lua | 6 ++++-- src/BlockEntities/JukeboxEntity.h | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua index cf258160c..61a8e8d22 100644 --- a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua +++ b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua @@ -196,9 +196,11 @@ World:ForEachChestInChunk(Player:GetChunkX(), Player:GetChunkZ(), Inherits = "cBlockEntity", Functions = { - EjectRecord = { Params = "", Return = "", Notes = "Ejects the current record as a {{cPickup|pickup}}. No action if there's no current record. To remove record without generating the pickup, use SetRecord(0)" }, + EjectRecord = { Params = "", Return = "bool", Notes = "Ejects the current record as a {{cPickup|pickup}}. No action if there's no current record. To remove record without generating the pickup, use SetRecord(0). Returns true if pickup ejected." }, GetRecord = { Params = "", Return = "number", Notes = "Returns the record currently present. Zero for no record, E_ITEM_*_DISC for records." }, - PlayRecord = { Params = "", Return = "", Notes = "Plays the currently present record. No action if there's no current record." }, + IsPlayingRecord = { Params = "", Return = "bool", Notes = "Returns true if the jukebox is playing a record." }, + IsRecordItem = { Params = "ItemType", Return = "bool", Notes = "Returns true if the specified item is a record that can be played." }, + PlayRecord = { Params = "RecordItemType", Return = "bool", Notes = "Plays the specified Record. Return false if the parameter isn't a playable Record (E_ITEM_XXX_DISC). If there is a record already playing, ejects it first." }, SetRecord = { Params = "number", Return = "", Notes = "Sets the currently present record. Use zero for no record, or E_ITEM_*_DISC for records." }, }, }, -- cJukeboxEntity diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index 01ce52494..3d1d604f7 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -38,10 +38,11 @@ public: int GetRecord(void); void SetRecord(int a_Record); - /** Play a Record. Return false, when a_Record isn't a Record */ + /** Plays the specified Record. Return false if a_Record isn't a playable Record (E_ITEM_XXX_DISC). + If there is a record already playing, ejects it first. */ bool PlayRecord(int a_Record); - /** Ejects the currently held record as a pickup. Return false when no record inserted. */ + /** Ejects the currently held record as a pickup. Return false when no record had been inserted. */ bool EjectRecord(void); /** Is in the Jukebox a Record? */ -- cgit v1.2.3 From 182646188448f9fd8df0b4c0391a2db04575c49d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Feb 2014 16:26:23 +0100 Subject: Fixed multiple gcc warnings about unused params. --- src/Entities/Painting.cpp | 11 +++++++++++ src/Entities/Painting.h | 2 +- src/HTTPServer/HTTPServer.cpp | 4 ++++ src/Items/ItemHandler.cpp | 26 +++++++++++++++++++++++++- src/OSSupport/BlockingTCPLink.cpp | 4 ++++ src/UI/SlotArea.cpp | 30 ++++++++++++++++++++++++++++++ src/UI/SlotArea.h | 6 +++--- 7 files changed, 78 insertions(+), 5 deletions(-) diff --git a/src/Entities/Painting.cpp b/src/Entities/Painting.cpp index b98c1e67a..e217556c7 100644 --- a/src/Entities/Painting.cpp +++ b/src/Entities/Painting.cpp @@ -4,6 +4,7 @@ #include "Painting.h" #include "ClientHandle.h" #include "Player.h" +#include "../Chunk.h" @@ -30,6 +31,16 @@ void cPainting::SpawnOn(cClientHandle & a_Client) +void cPainting::Tick(float a_Dt, cChunk & a_Chunk) +{ + UNUSED(a_Dt); + UNUSED(a_Chunk); +} + + + + + void cPainting::GetDrops(cItems & a_Items, cEntity * a_Killer) { if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative()) diff --git a/src/Entities/Painting.h b/src/Entities/Painting.h index 95afbed1e..c1024bd1b 100644 --- a/src/Entities/Painting.h +++ b/src/Entities/Painting.h @@ -24,7 +24,7 @@ public: private: virtual void SpawnOn(cClientHandle & a_Client) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override {}; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override; virtual void KilledBy(cEntity * a_Killer) override { diff --git a/src/HTTPServer/HTTPServer.cpp b/src/HTTPServer/HTTPServer.cpp index f6f5b0f8b..4e9195a00 100644 --- a/src/HTTPServer/HTTPServer.cpp +++ b/src/HTTPServer/HTTPServer.cpp @@ -29,6 +29,8 @@ class cDebugCallbacks : { virtual void OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override { + UNUSED(a_Connection); + if (cHTTPFormParser::HasFormData(a_Request)) { a_Request.SetUserData(new cHTTPFormParser(a_Request, *this)); @@ -38,6 +40,8 @@ class cDebugCallbacks : virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) override { + UNUSED(a_Connection); + cHTTPFormParser * FormParser = (cHTTPFormParser *)(a_Request.GetUserData()); if (FormParser != NULL) { diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index c10d13edc..507f7fa86 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -248,6 +248,14 @@ cItemHandler::cItemHandler(int a_ItemType) bool cItemHandler::OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) { + UNUSED(a_World); + UNUSED(a_Player); + UNUSED(a_Item); + UNUSED(a_BlockX); + UNUSED(a_BlockY); + UNUSED(a_BlockZ); + UNUSED(a_Dir); + return false; } @@ -257,6 +265,14 @@ bool cItemHandler::OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & bool cItemHandler::OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) { + UNUSED(a_World); + UNUSED(a_Player); + UNUSED(a_Item); + UNUSED(a_BlockX); + UNUSED(a_BlockY); + UNUSED(a_BlockZ); + UNUSED(a_Dir); + return false; } @@ -266,6 +282,8 @@ bool cItemHandler::OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cI void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ) { + UNUSED(a_Item); + BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); cBlockHandler * Handler = cBlockHandler::GetBlockHandler(Block); @@ -288,7 +306,9 @@ void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const void cItemHandler::OnFoodEaten(cWorld * a_World, cPlayer * a_Player, cItem * a_Item) { - + UNUSED(a_World); + UNUSED(a_Player); + UNUSED(a_Item); } @@ -461,6 +481,8 @@ bool cItemHandler::IsPlaceable(void) bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType) { + UNUSED(a_BlockType); + return false; } @@ -499,6 +521,8 @@ bool cItemHandler::GetPlacementBlockTypeMeta( bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item) { + UNUSED(a_Item); + FoodInfo Info = GetFoodInfo(); if ((Info.FoodLevel > 0) || (Info.Saturation > 0.f)) diff --git a/src/OSSupport/BlockingTCPLink.cpp b/src/OSSupport/BlockingTCPLink.cpp index af50eda5d..e9c00d6d4 100644 --- a/src/OSSupport/BlockingTCPLink.cpp +++ b/src/OSSupport/BlockingTCPLink.cpp @@ -89,6 +89,8 @@ bool cBlockingTCPLink::Connect(const char * iAddress, unsigned int iPort) int cBlockingTCPLink::Send(char * a_Data, unsigned int a_Size, int a_Flags /* = 0 */ ) { + UNUSED(a_Flags); + ASSERT(m_Socket.IsValid()); if (!m_Socket.IsValid()) { @@ -104,6 +106,8 @@ int cBlockingTCPLink::Send(char * a_Data, unsigned int a_Size, int a_Flags /* = int cBlockingTCPLink::SendMessage( const char* a_Message, int a_Flags /* = 0 */ ) { + UNUSED(a_Flags); + ASSERT(m_Socket.IsValid()); if (!m_Socket.IsValid()) { diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index bfcad3d92..88977e005 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -224,6 +224,24 @@ void cSlotArea::DblClicked(cPlayer & a_Player, int a_SlotNum) +void cSlotArea::OnPlayerAdded(cPlayer & a_Player) +{ + UNUSED(a_Player); +} + + + + + +void cSlotArea::OnPlayerRemoved(cPlayer & a_Player) +{ + UNUSED(a_Player); +} + + + + + void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_Apply, bool a_KeepEmptySlots) { for (int i = 0; i < m_NumSlots; i++) @@ -447,6 +465,18 @@ void cSlotAreaCrafting::OnPlayerRemoved(cPlayer & a_Player) + +void cSlotAreaCrafting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) +{ + UNUSED(a_ItemStack); + UNUSED(a_Player); + UNUSED(a_ShouldApply); + UNUSED(a_KeepEmptySlots); +} + + + + void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player) { cItem & DraggingItem = a_Player.GetDraggingItem(); diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index d31c87e0c..25b367cff 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -48,10 +48,10 @@ public: virtual void DblClicked(cPlayer & a_Player, int a_SlotNum); /// Called when a new player opens the same parent window. The window already tracks the player. CS-locked. - virtual void OnPlayerAdded(cPlayer & a_Player) {} ; + virtual void OnPlayerAdded(cPlayer & a_Player); /// Called when one of the players closes the parent window. The window already doesn't track the player. CS-locked. - virtual void OnPlayerRemoved(cPlayer & a_Player) {} ; + virtual void OnPlayerRemoved(cPlayer & a_Player); /** Called to store as much of a_ItemStack in the area as possible. a_ItemStack is modified to reflect the change. The default implementation searches each slot for available space and distributes the stack there. @@ -226,7 +226,7 @@ public: virtual void OnPlayerRemoved(cPlayer & a_Player) override; // Distributing items into this area is completely disabled - virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override {} + virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override; protected: /// Maps player's EntityID -> current recipe; not a std::map because cCraftingGrid needs proper constructor params -- cgit v1.2.3 From 0274db0e14adc269303380f41a54ffa07422317b Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 28 Feb 2014 22:32:10 +0100 Subject: Use switch in GetStepSound --- src/Blocks/BlockSlab.h | 12 +++++------- src/ClientHandle.cpp | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index 8a3c998ec..7cd2c97b2 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -176,15 +176,13 @@ public: virtual const char * GetStepSound(void) override { - BLOCKTYPE Block = GetSingleSlabType(m_BlockType); - if (Block != m_BlockType) - { - return cBlockHandler::GetBlockHandler(Block)->GetStepSound(); - } - else + switch (m_BlockType) { - return "step.stone"; + case E_BLOCK_DOUBLE_STONE_SLAB: return "step.stone"; + case E_BLOCK_DOUBLE_WOODEN_SLAB: return "step.wood"; } + ASSERT(!"Unhandled double slab type!"); + return ""; } } ; diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index ce549b0b1..dd2116dbf 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1043,7 +1043,7 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e if ( cBlockSlabHandler::IsAnySlabType(ClickedBlock) && // Is there a slab already? cBlockSlabHandler::IsAnySlabType(EquippedBlock) && // Is the player placing another slab? - ((ClickedBlockMeta & 0x07) == EquippedBlockDamage) && // Is it the same slab type? + ((ClickedBlockMeta & 0x07) == EquippedBlockDamage) && // Is it the same slab type? ( (a_BlockFace == BLOCK_FACE_TOP) || // Clicking the top of a bottom slab (a_BlockFace == BLOCK_FACE_BOTTOM) // Clicking the bottom of a top slab -- cgit v1.2.3 From 3991c04d478b0e929faff4ce95fdb53eae67b888 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 1 Mar 2014 02:43:35 +0100 Subject: Improved comments in float size check. --- src/WorldStorage/FastNBT.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h index 49f97c458..d68ebd54c 100644 --- a/src/WorldStorage/FastNBT.h +++ b/src/WorldStorage/FastNBT.h @@ -175,8 +175,8 @@ public: // Cause a compile-time error if sizeof(float) != 4 // If your platform produces a compiler error here, you'll need to add code that manually decodes 32-bit floats - char Check1[5 - sizeof(float)]; // sizeof(float) <= 4 - char Check2[sizeof(float) - 3]; // sizeof(float) >= 4 + char Check1[5 - sizeof(float)]; // Fails if sizeof(float) > 4 + char Check2[sizeof(float) - 3]; // Fails if sizeof(float) < 4 UNUSED(Check1); UNUSED(Check2); -- cgit v1.2.3 From aecbf772932792d122d191f8a45b75ddb2756d6f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 1 Mar 2014 02:46:50 +0100 Subject: Removed cBlockHandler forward declaration from cChunkInterface. Wasn't needed. Also reformatted the code. --- src/Blocks/ChunkInterface.h | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h index b30eff1e4..b58c0c086 100644 --- a/src/Blocks/ChunkInterface.h +++ b/src/Blocks/ChunkInterface.h @@ -5,31 +5,35 @@ #include "../ForEachChunkProvider.h" #include "WorldInterface.h" -class cBlockHandler; -class cChunkInterface : public cForEachChunkProvider + + + +class cChunkInterface: + public cForEachChunkProvider { public: cChunkInterface(cChunkMap * a_ChunkMap) : m_ChunkMap(a_ChunkMap) {} - BLOCKTYPE GetBlock (int a_BlockX, int a_BlockY, int a_BlockZ) + BLOCKTYPE GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ) { return m_ChunkMap->GetBlock(a_BlockX,a_BlockY,a_BlockZ); } - BLOCKTYPE GetBlock (const Vector3i & a_Pos ) + BLOCKTYPE GetBlock(const Vector3i & a_Pos ) { - return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z ); + return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z ); } - NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ) + NIBBLETYPE GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ) { return m_ChunkMap->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); } - bool GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) + bool GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) { return m_ChunkMap->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); } + /** Sets the block at the specified coords to the specified value. Full processing, incl. updating neighbors, is performed. */ @@ -37,7 +41,8 @@ public: { m_ChunkMap->SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); } - void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData) + + void SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData) { m_ChunkMap->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_MetaData); } @@ -55,7 +60,11 @@ public: { m_ChunkMap->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); } - void FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) { FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta ); } + + void FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) + { + FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta ); + } void UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) { @@ -77,3 +86,7 @@ public: private: cChunkMap * m_ChunkMap; }; + + + + -- cgit v1.2.3 From c18748648d791911e5e2df81ae600859c8522e9a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 1 Mar 2014 02:54:46 +0100 Subject: Forgotten changes to cChunkInterface. --- src/Blocks/ChunkInterface.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h index b58c0c086..be7c2e0e5 100644 --- a/src/Blocks/ChunkInterface.h +++ b/src/Blocks/ChunkInterface.h @@ -20,9 +20,9 @@ public: { return m_ChunkMap->GetBlock(a_BlockX,a_BlockY,a_BlockZ); } - BLOCKTYPE GetBlock(const Vector3i & a_Pos ) + BLOCKTYPE GetBlock(const Vector3i & a_Pos) { - return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z ); + return GetBlock(a_Pos.x, a_Pos.y, a_Pos.z); } NIBBLETYPE GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ) { -- cgit v1.2.3 From ce07a22fe6f210cd6461d54cd7fd8eaaaa47be4f Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 1 Mar 2014 10:44:34 +0100 Subject: APIDump: Documented cRoot:CreateAndInitializeWorld. --- MCServer/Plugins/APIDump/APIDesc.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index c6221f30d..241aa05ad 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1773,6 +1773,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); BroadcastChatInfo = { Params = "Message", Return = "", Notes = "Prepends Yellow [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For informational messages, such as command usage." }, BroadcastChatSuccess = { Params = "Message", Return = "", Notes = "Prepends Green [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For success messages." }, BroadcastChatWarning = { Params = "Message", Return = "", Notes = "Prepends Rose [WARN] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For concerning events, such as plugin reload etc." }, + CreateAndInitializeWorld = { Params = "WorldName", Return = "{{cWorld|cWorld}}", Notes = "Creates a new world and initializes it. If there is a world whith the same name it returns nil." }, FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "", Notes = "Calls the given callback function for the given player." }, ForEachPlayer = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each player. The callback function has the following signature:

    function Callback({{cPlayer|cPlayer}})
    " }, ForEachWorld = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each world. The callback function has the following signature:
    function Callback({{cWorld|cWorld}})
    " }, -- cgit v1.2.3 From 5c449452871340eeae9df8f34c5e145fda991d92 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 1 Mar 2014 12:06:19 +0200 Subject: Exported and documented cScoreboard --- MCServer/Plugins/APIDump/APIDesc.lua | 90 ++++++++++++++++++++++++++++++++++++ src/Bindings/AllToLua.pkg | 1 + src/Entities/Player.cpp | 21 ++------- src/Scoreboard.cpp | 30 ++++++++++++ src/Scoreboard.h | 67 ++++++++++++++------------- 5 files changed, 160 insertions(+), 49 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index c6221f30d..c2dd6ba99 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1115,6 +1115,42 @@ local Item5 = cItem(E_ITEM_DIAMOND_CHESTPLATE, 1, 0, "thorns=1;unbreaking=3"); }, }, -- cItem + cObjective = + { + Desc = [[ + This class represents a single scoreboard objective. + ]], + Functions = + { + AddScore = { Params = "string, number", Return = "Score", Notes = "Adds a value to the score of the specified player and returns the new value." }, + GetDisplayName = { Params = "", Return = "string", Notes = "Returns the display name of the objective. This name will be shown to the connected players." }, + GetName = { Params = "", Return = "string", Notes = "Returns the internal name of the objective." }, + GetScore = { Params = "string", Return = "Score", Notes = "Returns the score of the specified player." }, + GetType = { Params = "", Return = "eType", Notes = "Returns the type of the objective. (i.e what is being tracked)" }, + Reset = { Params = "", Return = "", Notes = "Resets the scores of the tracked players." }, + ResetScore = { Params = "string", Return = "", Notes = "Reset the score of the specified player." }, + SetDisplayName = { Params = "string", Return = "", Notes = "Sets the display name of the objective." }, + SetScore = { Params = "string, Score", Return = "", Notes = "Sets the score of the specified player." }, + SubScore = { Params = "string, number", Return = "Score", Notes = "Subtracts a value from the score of the specified player and returns the new value." }, + }, + Constants = + { + E_TYPE_ACHIEVEMENT = { Notes = "" }, + E_TYPE_DEATH_COUNT = { Notes = "" }, + E_TYPE_DUMMY = { Notes = "" }, + E_TYPE_HEALTH = { Notes = "" }, + E_TYPE_PLAYER_KILL_COUNT = { Notes = "" }, + E_TYPE_STAT = { Notes = "" }, + E_TYPE_STAT_BLOCK_MINE = { Notes = "" }, + E_TYPE_STAT_ENTITY_KILL = { Notes = "" }, + E_TYPE_STAT_ENTITY_KILLED_BY = { Notes = "" }, + E_TYPE_STAT_ITEM_BREAK = { Notes = "" }, + E_TYPE_STAT_ITEM_CRAFT = { Notes = "" }, + E_TYPE_STAT_ITEM_USE = { Notes = "" }, + E_TYPE_TOTAL_KILL_COUNT = { Notes = "" }, + }, + }, -- cObjective + cPainting = { Desc = "This class represents a painting in the world. These paintings are special and different from Vanilla in that they can be critical-hit.", @@ -1821,6 +1857,34 @@ end }, }, -- cRoot + cScoreboard = + { + Desc = [[ + This class manages the objectives and teams of a single world. + ]], + Functions = + { + AddPlayerScore = { Params = "Name, Type, Value", Return = "", Notes = "Adds a value to all player scores of the specified objective type." }, + GetNumObjectives = { Params = "", Return = "number", Notes = "Returns the nuber of registered objectives." }, + GetNumTeams = { Params = "", Return = "number", Notes = "Returns the number of registered teams." }, + GetObjective = { Params = "string", Return = "{{cObjective}}", Notes = "Returns the objective with the specified name." }, + GetObjectiveIn = { Params = "DisplaySlot", Return = "{{cObjective}}", Notes = "Returns the objective in the specified display slot. Can be nil." }, + GetTeam = { Params = "string", Return = "{{cTeam}}", Notes = "Returns the team with the specified name." }, + RegisterObjective = { Params = "Name, DisplayName, Type", Return = "{{cObjective}}", Notes = "Registers a new scoreboard objective. Returns the {{cObjective}} instance, nil on error." }, + RegisterTeam = { Params = "Name, DisplayName, Prefix, Suffix", Return = "{{cTeam}}", Notes = "Registers a new team. Returns the {{cTeam}} instance, nil on error." }, + RemoveObjective = { Params = "string", Return = "bool", Notes = "Removes the objective with the specified name. Returns true if operation was successful." }, + RemoveTeam = { Params = "string", Return = "bool", Notes = "Removes the team with the specified name. Returns true if operation was successful." }, + SetDisplay = { Params = "Name, DisplaySlot", Return = "", Notes = "Updates the currently displayed objective." }, + }, + Constants = + { + E_DISPLAY_SLOT_COUNT = { Notes = "" }, + E_DISPLAY_SLOT_LIST = { Notes = "" }, + E_DISPLAY_SLOT_NAME = { Notes = "" }, + E_DISPLAY_SLOT_SIDEBAR = { Notes = "" }, + }, + }, -- cScoreboard + cServer = { Desc = [[ @@ -1841,6 +1905,32 @@ end }, }, -- cServer + cTeam = + { + Desc = [[ + This class manages a single player team. + ]], + Functions = + { + AddPlayer = { Params = "string", Returns = "bool", Notes = "Adds a player to this team. Returns true if the operation was successful." }, + AllowsFriendlyFire = { Params = "", Return = "bool", Notes = "Returns whether team friendly fire is allowed." }, + CanSeeFriendlyInvisible = { Params = "", Return = "bool", Notes = "Returns whether players can see invisible teammates." }, + HasPlayer = { Params = "string", Returns = "bool", Notes = "Returns whether the specified player is a member of this team." }, + GetDisplayName = { Params = "", Return = "string", Notes = "Returns the display name of the team." }, + GetName = { Params = "", Return = "string", Notes = "Returns the internal name of the team." }, + GetNumPlayers = { Params = "", Return = "number", Notes = "Returns the number of registered players." }, + GetPrefix = { Params = "", Return = "string", Notes = "Returns the prefix prepended to the names of the members of this team." }, + RemovePlayer = { Params = "string", Returns = "bool", Notes = "Removes the player with the specified name from this team. Returns true if the operation was successful." }, + Reset = { Params = "", Returns = "", Notes = "Removes all players from this team." }, + GetSuffix = { Params = "", Return = "string", Notes = "Returns the suffix appended to the names of the members of this team." }, + SetCanSeeFriendlyInvisible = { Params = "bool", Return = "", Notes = "Set whether players can see invisible teammates." }, + SetDisplayName = { Params = "string", Return = "", Notes = "Sets the display name of this team. (i.e. what will be shown to the players)" }, + SetFriendlyFire = { Params = "bool", Return = "", Notes = "Sets whether team friendly fire is allowed." }, + SetPrefix = { Params = "string", Return = "", Notes = "Sets the prefix prepended to the names of the members of this team." }, + SetSuffix = { Params = "string", Return = "", Notes = "Sets the suffix appended to the names of the members of this team." }, + }, + }, -- cTeam + cTNTEntity = { Desc = "This class manages a TNT entity.", diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 6537437cd..1a2140771 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -75,6 +75,7 @@ $cfile "../Mobs/Monster.h" $cfile "../CompositeChat.h" $cfile "../Map.h" $cfile "../MapManager.h" +$cfile "../Scoreboard.h" diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index f419ee09c..416bda2ec 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -858,6 +858,8 @@ void cPlayer::KilledBy(cEntity * a_Killer) else if (a_Killer->IsPlayer()) { GetWorld()->BroadcastChatDeath(Printf("%s was killed by %s", GetName().c_str(), ((cPlayer *)a_Killer)->GetName().c_str())); + + m_World->GetScoreBoard().AddPlayerScore(((cPlayer *)a_Killer)->GetName(), cObjective::E_TYPE_PLAYER_KILL_COUNT, 1); } else { @@ -867,24 +869,7 @@ void cPlayer::KilledBy(cEntity * a_Killer) GetWorld()->BroadcastChatDeath(Printf("%s was killed by a %s", GetName().c_str(), KillerClass.c_str())); } - class cIncrementCounterCB - : public cObjectiveCallback - { - AString m_Name; - public: - cIncrementCounterCB(const AString & a_Name) : m_Name(a_Name) {} - - virtual bool Item(cObjective * a_Objective) override - { - a_Objective->AddScore(m_Name, 1); - return true; - } - } IncrementCounter (GetName()); - - cScoreboard & Scoreboard = m_World->GetScoreBoard(); - - // Update scoreboard objectives - Scoreboard.ForEachObjectiveWith(cObjective::E_TYPE_DEATH_COUNT, IncrementCounter); + m_World->GetScoreBoard().AddPlayerScore(GetName(), cObjective::E_TYPE_DEATH_COUNT, 1); } diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 61ecac5b7..1c5a22eff 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -246,6 +246,17 @@ void cTeam::Reset(void) +void cTeam::SetDisplayName(const AString & a_Name) +{ + m_DisplayName = a_Name; + + // TODO 2014-03-01 xdot: Update clients +} + + + + + unsigned int cTeam::GetNumPlayers(void) const { return m_Players.size(); @@ -306,6 +317,8 @@ bool cScoreboard::RemoveObjective(const AString & a_Name) ASSERT(m_World != NULL); m_World->BroadcastScoreboardObjective(it->second.GetName(), it->second.GetDisplayName(), 1); + // TODO 2014-03-01 xdot: Remove objective from display slot + return true; } @@ -465,6 +478,23 @@ void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallb +void cScoreboard::AddPlayerScore(const AString & a_Name, cObjective::eType a_Type, cObjective::Score a_Value) +{ + cCSLock Lock(m_CSObjectives); + + for (cObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it) + { + if (it->second.GetType() == a_Type) + { + it->second.AddScore(a_Name, a_Value); + } + } +} + + + + + void cScoreboard::SendTo(cClientHandle & a_Client) { cCSLock Lock(m_CSObjectives); diff --git a/src/Scoreboard.h b/src/Scoreboard.h index f64ba2bce..f9a8665da 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -67,29 +67,29 @@ public: const AString & GetName(void) const { return m_Name; } const AString & GetDisplayName(void) const { return m_DisplayName; } - /// Resets the objective + /** Resets the objective */ void Reset(void); - /// Returns the score of the specified player + /** Returns the score of the specified player */ Score GetScore(const AString & a_Name) const; - /// Sets the score of the specified player + /** Sets the score of the specified player */ void SetScore(const AString & a_Name, Score a_Score); - /// Resets the score of the specified player + /** Resets the score of the specified player */ void ResetScore(const AString & a_Name); - /// Adds a_Delta and returns the new score + /** Adds a_Delta and returns the new score */ Score AddScore(const AString & a_Name, Score a_Delta); - /// Subtracts a_Delta and returns the new score + /** Subtracts a_Delta and returns the new score */ Score SubScore(const AString & a_Name, Score a_Delta); void SetDisplayName(const AString & a_Name); // tolua_end - /// Send this objective to the specified client + /** Send this objective to the specified client */ void SendTo(cClientHandle & a_Client); private: @@ -109,7 +109,8 @@ private: friend class cScoreboardSerializer; -}; + +}; // tolua_export @@ -127,21 +128,21 @@ public: const AString & a_Prefix, const AString & a_Suffix ); - /// Adds a new player to the team + // tolua_begin + + /** Adds a new player to the team */ bool AddPlayer(const AString & a_Name); - /// Removes a player from the team + /** Removes a player from the team */ bool RemovePlayer(const AString & a_Name); - /// Returns whether the specified player is in this team + /** Returns whether the specified player is in this team */ bool HasPlayer(const AString & a_Name) const; - /// Removes all registered players + /** Removes all registered players */ void Reset(void); - // tolua_begin - - /// Returns the number of registered players + /** Returns the number of registered players */ unsigned int GetNumPlayers(void) const; bool AllowsFriendlyFire(void) const { return m_AllowsFriendlyFire; } @@ -180,7 +181,8 @@ private: friend class cScoreboardSerializer; -}; + +}; // tolua_export @@ -209,44 +211,46 @@ public: // tolua_begin - /// Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision + /** Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision */ cObjective * RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type); - /// Removes a registered objective, returns true if operation was successful + /** Removes a registered objective, returns true if operation was successful */ bool RemoveObjective(const AString & a_Name); - /// Retrieves the objective with the specified name, NULL if not found + /** Retrieves the objective with the specified name, NULL if not found */ cObjective * GetObjective(const AString & a_Name); - /// Registers a new team, returns the cTeam instance, NULL on name collision + /** Registers a new team, returns the cTeam instance, NULL on name collision */ cTeam * RegisterTeam(const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix); - /// Removes a registered team, returns true if operation was successful + /** Removes a registered team, returns true if operation was successful */ bool RemoveTeam(const AString & a_Name); - /// Retrieves the team with the specified name, NULL if not found + /** Retrieves the team with the specified name, NULL if not found */ cTeam * GetTeam(const AString & a_Name); - cTeam * QueryPlayerTeam(const AString & a_Name); // WARNING: O(n logn) - void SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot); - void SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot); - cObjective * GetObjectiveIn(eDisplaySlot a_Slot); - /// Execute callback for each objective with the specified type - void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback); - unsigned int GetNumObjectives(void) const; unsigned int GetNumTeams(void) const; + void AddPlayerScore(const AString & a_Name, cObjective::eType a_Type, cObjective::Score a_Value = 1); + // tolua_end - /// Send this scoreboard to the specified client + /** Send this scoreboard to the specified client */ void SendTo(cClientHandle & a_Client); + cTeam * QueryPlayerTeam(const AString & a_Name); // WARNING: O(n logn) + + /** Execute callback for each objective with the specified type */ + void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback); + + void SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot); + private: @@ -269,7 +273,8 @@ private: friend class cScoreboardSerializer; -} ; + +}; // tolua_export -- cgit v1.2.3 From a28e5eca1835e1be868c3bcd22d87e3cfae2f547 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 1 Mar 2014 14:03:16 +0200 Subject: Exported cScoreboard::ForEachObjective --- MCServer/Plugins/APIDump/APIDesc.lua | 1 + src/Bindings/ManualBindings.cpp | 4 ++++ src/Scoreboard.cpp | 24 ++++++++++++++++++++++-- src/Scoreboard.h | 19 +++++++++++++++++-- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index c2dd6ba99..5bc69eb24 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1865,6 +1865,7 @@ end Functions = { AddPlayerScore = { Params = "Name, Type, Value", Return = "", Notes = "Adds a value to all player scores of the specified objective type." }, + ForEachObjective = { Params = "CallBackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each objective in the scoreboard. Returns true if all objectives have been processed (including when there are zero objectives), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
    function Callback({{cObjective|Objective}}, [CallbackData])
    The callback should return false or no value to continue with the next objective, or true to abort the enumeration." }, GetNumObjectives = { Params = "", Return = "number", Notes = "Returns the nuber of registered objectives." }, GetNumTeams = { Params = "", Return = "number", Notes = "Returns the number of registered teams." }, GetObjective = { Params = "string", Return = "{{cObjective}}", Notes = "Returns the objective with the specified name." }, diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 461186d3b..3c3e78d25 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2583,6 +2583,10 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_beginmodule(tolua_S, "cMapManager"); tolua_function(tolua_S, "DoWithMap", tolua_DoWithID); tolua_endmodule(tolua_S); + + tolua_beginmodule(tolua_S, "cScoreboard"); + tolua_function(tolua_S, "ForEachObjective", tolua_ForEach); + tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cPlugin"); tolua_function(tolua_S, "Call", tolua_cPlugin_Call); diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 1c5a22eff..43b8ba1ad 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -457,7 +457,7 @@ cObjective * cScoreboard::GetObjectiveIn(eDisplaySlot a_Slot) -void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback) +bool cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback) { cCSLock Lock(m_CSObjectives); @@ -468,10 +468,30 @@ void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallb // Call callback if (a_Callback.Item(&it->second)) { - return; + return false; } } } + return true; +} + + + + + +bool cScoreboard::ForEachObjective(cObjectiveCallback& a_Callback) +{ + cCSLock Lock(m_CSObjectives); + + for (cObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it) + { + // Call callback + if (a_Callback.Item(&it->second)) + { + return false; + } + } + return true; } diff --git a/src/Scoreboard.h b/src/Scoreboard.h index f9a8665da..8e268516d 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -92,6 +92,12 @@ public: /** Send this objective to the specified client */ void SendTo(cClientHandle & a_Client); + static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates + { + return "cObjective"; + } + + private: typedef std::pair cTrackedPlayer; @@ -246,8 +252,17 @@ public: cTeam * QueryPlayerTeam(const AString & a_Name); // WARNING: O(n logn) - /** Execute callback for each objective with the specified type */ - void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback); + /** Execute callback for each objective with the specified type + * + * Returns true if all objectives processed, false if the callback aborted by returning true. + */ + bool ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback); + + /** Execute callback for each objective. + * + * Returns true if all objectives processed, false if the callback aborted by returning true. + */ + bool ForEachObjective(cObjectiveCallback& a_Callback); // Exported in ManualBindings.cpp void SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot); -- cgit v1.2.3 From 692a84af31889af7a83b780009b1fcc81bfa3d99 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 1 Mar 2014 14:20:29 +0200 Subject: Shortened enums --- src/Entities/Player.cpp | 4 +- src/Scoreboard.cpp | 62 +++++++++++++++---------------- src/Scoreboard.h | 36 +++++++++--------- src/WorldStorage/ScoreboardSerializer.cpp | 14 +++---- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 416bda2ec..8f94f1feb 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -859,7 +859,7 @@ void cPlayer::KilledBy(cEntity * a_Killer) { GetWorld()->BroadcastChatDeath(Printf("%s was killed by %s", GetName().c_str(), ((cPlayer *)a_Killer)->GetName().c_str())); - m_World->GetScoreBoard().AddPlayerScore(((cPlayer *)a_Killer)->GetName(), cObjective::E_TYPE_PLAYER_KILL_COUNT, 1); + m_World->GetScoreBoard().AddPlayerScore(((cPlayer *)a_Killer)->GetName(), cObjective::otPlayerKillCount, 1); } else { @@ -869,7 +869,7 @@ void cPlayer::KilledBy(cEntity * a_Killer) GetWorld()->BroadcastChatDeath(Printf("%s was killed by a %s", GetName().c_str(), KillerClass.c_str())); } - m_World->GetScoreBoard().AddPlayerScore(GetName(), cObjective::E_TYPE_DEATH_COUNT, 1); + m_World->GetScoreBoard().AddPlayerScore(GetName(), cObjective::otDeathCount, 1); } diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 43b8ba1ad..ee56a1145 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -17,19 +17,19 @@ AString cObjective::TypeToString(eType a_Type) { switch (a_Type) { - case E_TYPE_DUMMY: return "dummy"; - case E_TYPE_DEATH_COUNT: return "deathCount"; - case E_TYPE_PLAYER_KILL_COUNT: return "playerKillCount"; - case E_TYPE_TOTAL_KILL_COUNT: return "totalKillCount"; - case E_TYPE_HEALTH: return "health"; - case E_TYPE_ACHIEVEMENT: return "achievement"; - case E_TYPE_STAT: return "stat"; - case E_TYPE_STAT_ITEM_CRAFT: return "stat.craftItem"; - case E_TYPE_STAT_ITEM_USE: return "stat.useItem"; - case E_TYPE_STAT_ITEM_BREAK: return "stat.breakItem"; - case E_TYPE_STAT_BLOCK_MINE: return "stat.mineBlock"; - case E_TYPE_STAT_ENTITY_KILL: return "stat.killEntity"; - case E_TYPE_STAT_ENTITY_KILLED_BY: return "stat.entityKilledBy"; + case otDummy: return "dummy"; + case otDeathCount: return "deathCount"; + case otPlayerKillCount: return "playerKillCount"; + case otTotalKillCount: return "totalKillCount"; + case otHealth: return "health"; + case otAchievement: return "achievement"; + case otStat: return "stat"; + case otStatItemCraft: return "stat.craftItem"; + case otStatItemUse: return "stat.useItem"; + case otStatItemBreak: return "stat.breakItem"; + case otStatBlockMine: return "stat.mineBlock"; + case otStatEntityKill: return "stat.killEntity"; + case otStatEntityKilledBy: return "stat.entityKilledBy"; default: return ""; } @@ -46,19 +46,19 @@ cObjective::eType cObjective::StringToType(const AString & a_Name) const char * m_String; } TypeMap [] = { - {E_TYPE_DUMMY, "dummy"}, - {E_TYPE_DEATH_COUNT, "deathCount"}, - {E_TYPE_PLAYER_KILL_COUNT, "playerKillCount"}, - {E_TYPE_TOTAL_KILL_COUNT, "totalKillCount"}, - {E_TYPE_HEALTH, "health"}, - {E_TYPE_ACHIEVEMENT, "achievement"}, - {E_TYPE_STAT, "stat"}, - {E_TYPE_STAT_ITEM_CRAFT, "stat.craftItem"}, - {E_TYPE_STAT_ITEM_USE, "stat.useItem"}, - {E_TYPE_STAT_ITEM_BREAK, "stat.breakItem"}, - {E_TYPE_STAT_BLOCK_MINE, "stat.mineBlock"}, - {E_TYPE_STAT_ENTITY_KILL, "stat.killEntity"}, - {E_TYPE_STAT_ENTITY_KILLED_BY, "stat.entityKilledBy"} + {otDummy, "dummy" }, + {otDeathCount, "deathCount" }, + {otPlayerKillCount, "playerKillCount" }, + {otTotalKillCount, "totalKillCount" }, + {otHealth, "health" }, + {otAchievement, "achievement" }, + {otStat, "stat" }, + {otStatItemCraft, "stat.craftItem" }, + {otStatItemUse, "stat.useItem" }, + {otStatItemBreak, "stat.breakItem" }, + {otStatBlockMine, "stat.mineBlock" }, + {otStatEntityKill, "stat.killEntity" }, + {otStatEntityKilledBy, "stat.entityKilledBy"} }; for (size_t i = 0; i < ARRAYCOUNT(TypeMap); i++) { @@ -67,7 +67,7 @@ cObjective::eType cObjective::StringToType(const AString & a_Name) return TypeMap[i].m_Type; } } // for i - TypeMap[] - return E_TYPE_DUMMY; + return otDummy; } @@ -268,7 +268,7 @@ unsigned int cTeam::GetNumPlayers(void) const cScoreboard::cScoreboard(cWorld * a_World) : m_World(a_World) { - for (int i = 0; i < (int) E_DISPLAY_SLOT_COUNT; ++i) + for (int i = 0; i < (int) dsCount; ++i) { m_Display[i] = NULL; } @@ -423,7 +423,7 @@ cTeam * cScoreboard::QueryPlayerTeam(const AString & a_Name) void cScoreboard::SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot) { - ASSERT(a_Slot < E_DISPLAY_SLOT_COUNT); + ASSERT(a_Slot < dsCount); cObjective * Objective = GetObjective(a_Objective); @@ -448,7 +448,7 @@ void cScoreboard::SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot) cObjective * cScoreboard::GetObjectiveIn(eDisplaySlot a_Slot) { - ASSERT(a_Slot < E_DISPLAY_SLOT_COUNT); + ASSERT(a_Slot < dsCount); return m_Display[a_Slot]; } @@ -524,7 +524,7 @@ void cScoreboard::SendTo(cClientHandle & a_Client) it->second.SendTo(a_Client); } - for (int i = 0; i < (int) E_DISPLAY_SLOT_COUNT; ++i) + for (int i = 0; i < (int) dsCount; ++i) { // Avoid race conditions cObjective * Objective = m_Display[i]; diff --git a/src/Scoreboard.h b/src/Scoreboard.h index 8e268516d..2abd1564b 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -31,23 +31,23 @@ public: enum eType { - E_TYPE_DUMMY, + otDummy, - E_TYPE_DEATH_COUNT, - E_TYPE_PLAYER_KILL_COUNT, - E_TYPE_TOTAL_KILL_COUNT, - E_TYPE_HEALTH, + otDeathCount, + otPlayerKillCount, + otTotalKillCount, + otHealth, - E_TYPE_ACHIEVEMENT, + otAchievement, - E_TYPE_STAT, - E_TYPE_STAT_ITEM_CRAFT, - E_TYPE_STAT_ITEM_USE, - E_TYPE_STAT_ITEM_BREAK, + otStat, + otStatItemCraft, + otStatItemUse, + otStatItemBreak, - E_TYPE_STAT_BLOCK_MINE, - E_TYPE_STAT_ENTITY_KILL, - E_TYPE_STAT_ENTITY_KILLED_BY + otStatBlockMine, + otStatEntityKill, + otStatEntityKilledBy }; // tolua_end @@ -201,11 +201,11 @@ public: enum eDisplaySlot { - E_DISPLAY_SLOT_LIST = 0, - E_DISPLAY_SLOT_SIDEBAR, - E_DISPLAY_SLOT_NAME, + dsList = 0, + dsSidebar, + dsName, - E_DISPLAY_SLOT_COUNT + dsCount }; // tolua_end @@ -284,7 +284,7 @@ private: cWorld * m_World; - cObjective* m_Display[E_DISPLAY_SLOT_COUNT]; + cObjective * m_Display[dsCount]; friend class cScoreboardSerializer; diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp index 9b8b661c4..6c885bb45 100644 --- a/src/WorldStorage/ScoreboardSerializer.cpp +++ b/src/WorldStorage/ScoreboardSerializer.cpp @@ -173,13 +173,13 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer) a_Writer.BeginCompound("DisplaySlots"); - cObjective * Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_LIST); + cObjective * Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::dsList); a_Writer.AddString("slot_0", (Objective == NULL) ? "" : Objective->GetName()); - Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_SIDEBAR); + Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::dsSidebar); a_Writer.AddString("slot_1", (Objective == NULL) ? "" : Objective->GetName()); - Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_NAME); + Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::dsName); a_Writer.AddString("slot_2", (Objective == NULL) ? "" : Objective->GetName()); a_Writer.EndCompound(); // DisplaySlots @@ -280,7 +280,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT) { AString Name, DisplayName, Prefix, Suffix; - bool AllowsFriendlyFire = false, CanSeeFriendlyInvisible = false; + bool AllowsFriendlyFire = true, CanSeeFriendlyInvisible = false; int CurrLine = a_NBT.FindChildByName(Child, "Name"); if (CurrLine >= 0) @@ -346,7 +346,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT) { AString Name = a_NBT.GetString(CurrLine); - m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_LIST); + m_ScoreBoard->SetDisplay(Name, cScoreboard::dsList); } CurrLine = a_NBT.FindChildByName(DisplaySlots, "slot_1"); @@ -354,7 +354,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT) { AString Name = a_NBT.GetString(CurrLine); - m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_SIDEBAR); + m_ScoreBoard->SetDisplay(Name, cScoreboard::dsSidebar); } CurrLine = a_NBT.FindChildByName(DisplaySlots, "slot_2"); @@ -362,7 +362,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT) { AString Name = a_NBT.GetString(CurrLine); - m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_NAME); + m_ScoreBoard->SetDisplay(Name, cScoreboard::dsName); } return true; -- cgit v1.2.3 From 39c8e68ef030b70f1f50165e74d26100bc1988cc Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 1 Mar 2014 14:27:55 +0200 Subject: Exported cScoreboard::ForEachTeam --- MCServer/Plugins/APIDump/APIDesc.lua | 1 + src/Bindings/ManualBindings.cpp | 1 + src/Scoreboard.cpp | 19 +++++++++++++++++++ src/Scoreboard.h | 15 ++++++++++++++- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 5bc69eb24..e45c5c475 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1866,6 +1866,7 @@ end { AddPlayerScore = { Params = "Name, Type, Value", Return = "", Notes = "Adds a value to all player scores of the specified objective type." }, ForEachObjective = { Params = "CallBackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each objective in the scoreboard. Returns true if all objectives have been processed (including when there are zero objectives), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
    function Callback({{cObjective|Objective}}, [CallbackData])
    The callback should return false or no value to continue with the next objective, or true to abort the enumeration." }, + ForEachTeam = { Params = "CallBackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each team in the scoreboard. Returns true if all teams have been processed (including when there are zero teams), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
    function Callback({{cObjective|Objective}}, [CallbackData])
    The callback should return false or no value to continue with the next team, or true to abort the enumeration." }, GetNumObjectives = { Params = "", Return = "number", Notes = "Returns the nuber of registered objectives." }, GetNumTeams = { Params = "", Return = "number", Notes = "Returns the number of registered teams." }, GetObjective = { Params = "string", Return = "{{cObjective}}", Notes = "Returns the objective with the specified name." }, diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 3c3e78d25..fcdd728be 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2586,6 +2586,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_beginmodule(tolua_S, "cScoreboard"); tolua_function(tolua_S, "ForEachObjective", tolua_ForEach); + tolua_function(tolua_S, "ForEachTeam", tolua_ForEach); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cPlugin"); diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index ee56a1145..05fd0314d 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -498,6 +498,25 @@ bool cScoreboard::ForEachObjective(cObjectiveCallback& a_Callback) +bool cScoreboard::ForEachTeam(cTeamCallback& a_Callback) +{ + cCSLock Lock(m_CSObjectives); + + for (cTeamMap::iterator it = m_Teams.begin(); it != m_Teams.end(); ++it) + { + // Call callback + if (a_Callback.Item(&it->second)) + { + return false; + } + } + return true; +} + + + + + void cScoreboard::AddPlayerScore(const AString & a_Name, cObjective::eType a_Type, cObjective::Score a_Value) { cCSLock Lock(m_CSObjectives); diff --git a/src/Scoreboard.h b/src/Scoreboard.h index 2abd1564b..e22ecaeb1 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -14,9 +14,11 @@ class cObjective; +class cTeam; class cWorld; typedef cItemCallback cObjectiveCallback; +typedef cItemCallback cTeamCallback; @@ -170,6 +172,11 @@ public: // tolua_end + static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates + { + return "cTeam"; + } + private: typedef std::set cPlayerNameSet; @@ -260,10 +267,16 @@ public: /** Execute callback for each objective. * - * Returns true if all objectives processed, false if the callback aborted by returning true. + * Returns true if all objectives have been processed, false if the callback aborted by returning true. */ bool ForEachObjective(cObjectiveCallback& a_Callback); // Exported in ManualBindings.cpp + /** Execute callback for each team. + * + * Returns true if all teams have been processed, false if the callback aborted by returning true. + */ + bool ForEachTeam(cTeamCallback& a_Callback); // Exported in ManualBindings.cpp + void SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot); -- cgit v1.2.3 From add9955255ffc3dba012d4adfa743b244b240ea5 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 1 Mar 2014 15:03:27 +0200 Subject: APIDump: Fixed cScoreboard enums --- MCServer/Plugins/APIDump/APIDesc.lua | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index e45c5c475..ea89d04af 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1135,19 +1135,19 @@ local Item5 = cItem(E_ITEM_DIAMOND_CHESTPLATE, 1, 0, "thorns=1;unbreaking=3"); }, Constants = { - E_TYPE_ACHIEVEMENT = { Notes = "" }, - E_TYPE_DEATH_COUNT = { Notes = "" }, - E_TYPE_DUMMY = { Notes = "" }, - E_TYPE_HEALTH = { Notes = "" }, - E_TYPE_PLAYER_KILL_COUNT = { Notes = "" }, - E_TYPE_STAT = { Notes = "" }, - E_TYPE_STAT_BLOCK_MINE = { Notes = "" }, - E_TYPE_STAT_ENTITY_KILL = { Notes = "" }, - E_TYPE_STAT_ENTITY_KILLED_BY = { Notes = "" }, - E_TYPE_STAT_ITEM_BREAK = { Notes = "" }, - E_TYPE_STAT_ITEM_CRAFT = { Notes = "" }, - E_TYPE_STAT_ITEM_USE = { Notes = "" }, - E_TYPE_TOTAL_KILL_COUNT = { Notes = "" }, + otAchievement = { Notes = "" }, + otDeathCount = { Notes = "" }, + otDummy = { Notes = "" }, + otHealth = { Notes = "" }, + otPlayerKillCount = { Notes = "" }, + otStat = { Notes = "" }, + otStatBlockMine = { Notes = "" }, + otStatEntityKill = { Notes = "" }, + otStatEntityKilledBy = { Notes = "" }, + otStatItemBreak = { Notes = "" }, + otStatItemCraft = { Notes = "" }, + otStatItemUse = { Notes = "" }, + otTotalKillCount = { Notes = "" }, }, }, -- cObjective @@ -1880,10 +1880,10 @@ end }, Constants = { - E_DISPLAY_SLOT_COUNT = { Notes = "" }, - E_DISPLAY_SLOT_LIST = { Notes = "" }, - E_DISPLAY_SLOT_NAME = { Notes = "" }, - E_DISPLAY_SLOT_SIDEBAR = { Notes = "" }, + dsCount = { Notes = "" }, + dsList = { Notes = "" }, + dsName = { Notes = "" }, + dsSidebar = { Notes = "" }, }, }, -- cScoreboard -- cgit v1.2.3 From 48288992041eb89eb0d21380b9e1326426c3a61b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 1 Mar 2014 14:23:53 +0100 Subject: DoxyFile: Updated after all the folder renaming. --- Doxyfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Doxyfile b/Doxyfile index 33f15c4b1..d4dae6ec5 100644 --- a/Doxyfile +++ b/Doxyfile @@ -665,9 +665,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = source \ - iniFile \ - WebServer +INPUT = src # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is -- cgit v1.2.3 From 6129b6edf161c61db91d91145e9b1f23db688529 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 1 Mar 2014 14:29:40 +0100 Subject: If there is a SourceLocation available the InfoDump will note it in the forum version. --- MCServer/Plugins/InfoDump.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index 8fac09d60..03ce46d99 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -578,7 +578,10 @@ local function DumpPluginInfoForum(a_PluginFolder, a_PluginInfo) DumpAdditionalInfoForum(a_PluginInfo, f); DumpCommandsForum(a_PluginInfo, f); DumpPermissionsForum(a_PluginInfo, f); - + if (a_PluginInfo.SourceLocation ~= nil) then + f:write("[b][color=blue]Source:[/color] [url=" .. a_PluginInfo.SourceLocation .. "]Link[/url][/b]"); + end + f:close(); end -- cgit v1.2.3 From 854cf9df999691463aa382bc760d3a4322d015a5 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 1 Mar 2014 14:45:38 +0100 Subject: Using comma instead of string concatenation. --- MCServer/Plugins/InfoDump.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index 03ce46d99..e7ed157e3 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -579,7 +579,7 @@ local function DumpPluginInfoForum(a_PluginFolder, a_PluginInfo) DumpCommandsForum(a_PluginInfo, f); DumpPermissionsForum(a_PluginInfo, f); if (a_PluginInfo.SourceLocation ~= nil) then - f:write("[b][color=blue]Source:[/color] [url=" .. a_PluginInfo.SourceLocation .. "]Link[/url][/b]"); + f:write("[b][color=blue]Source:[/color] [url=", a_PluginInfo.SourceLocation, "]Link[/url][/b]"); end f:close(); -- cgit v1.2.3 From 5c5502be9e46a0a5d44b6994e8075e5588598912 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 1 Mar 2014 17:04:17 +0200 Subject: Refactored global block property arrays --- src/BlockInfo.cpp | 423 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/BlockInfo.h | 54 +++++++ 2 files changed, 477 insertions(+) create mode 100644 src/BlockInfo.cpp create mode 100644 src/BlockInfo.h diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp new file mode 100644 index 000000000..6ae59db53 --- /dev/null +++ b/src/BlockInfo.cpp @@ -0,0 +1,423 @@ + +#include "Globals.h" + +#include "BlockInfo.h" + + + + + +BlockInfo BlockInfo::ms_Info[256]; + + + + + +BlockInfo::BlockInfo() + : m_LightValue(0x00) + , m_SpreadLightFalloff(0x0f) + , m_Transparent(false) + , m_OneHitDig(false) + , m_PistonBreakable(false) + , m_IsSnowable(true) + , m_RequiresSpecialTool(false) + , m_IsSolid(true) + , m_FullyOccupiesVoxel(false) +{} + + + + + +BlockInfo & BlockInfo::GetById(unsigned int a_ID) +{ + ASSERT(a_ID < 256); + + return ms_Info[a_ID]; +} + + + + + +void BlockInfo::Initialize(void) +{ + // Emissive blocks + ms_Info[E_BLOCK_FIRE ].m_LightValue = 15; + ms_Info[E_BLOCK_GLOWSTONE ].m_LightValue = 15; + ms_Info[E_BLOCK_JACK_O_LANTERN ].m_LightValue = 15; + ms_Info[E_BLOCK_LAVA ].m_LightValue = 15; + ms_Info[E_BLOCK_STATIONARY_LAVA ].m_LightValue = 15; + ms_Info[E_BLOCK_END_PORTAL ].m_LightValue = 15; + ms_Info[E_BLOCK_REDSTONE_LAMP_ON ].m_LightValue = 15; + ms_Info[E_BLOCK_TORCH ].m_LightValue = 14; + ms_Info[E_BLOCK_BURNING_FURNACE ].m_LightValue = 13; + ms_Info[E_BLOCK_NETHER_PORTAL ].m_LightValue = 11; + ms_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_LightValue = 9; + ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_LightValue = 9; + ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_LightValue = 7; + ms_Info[E_BLOCK_BREWING_STAND ].m_LightValue = 1; + ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_LightValue = 1; + ms_Info[E_BLOCK_DRAGON_EGG ].m_LightValue = 1; + + + // Spread blocks + ms_Info[E_BLOCK_AIR ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_CAKE ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_CHEST ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_COBWEB ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_CROPS ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_FENCE ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_FENCE_GATE ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_FIRE ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_GLASS ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_GLASS_PANE ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_GLOWSTONE ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_IRON_BARS ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_IRON_DOOR ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_LEAVES ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_SIGN_POST ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_TORCH ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_VINES ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_WALLSIGN ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_WOODEN_DOOR ].m_SpreadLightFalloff = 1; + + // Light in water and lava dissapears faster: + ms_Info[E_BLOCK_LAVA ].m_SpreadLightFalloff = 3; + ms_Info[E_BLOCK_STATIONARY_LAVA ].m_SpreadLightFalloff = 3; + ms_Info[E_BLOCK_STATIONARY_WATER ].m_SpreadLightFalloff = 3; + ms_Info[E_BLOCK_WATER ].m_SpreadLightFalloff = 3; + + + // Transparent blocks + ms_Info[E_BLOCK_ACTIVATOR_RAIL ].m_Transparent = true; + ms_Info[E_BLOCK_AIR ].m_Transparent = true; + ms_Info[E_BLOCK_BIG_FLOWER ].m_Transparent = true; + ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_Transparent = true; + ms_Info[E_BLOCK_CARROTS ].m_Transparent = true; + ms_Info[E_BLOCK_CHEST ].m_Transparent = true; + ms_Info[E_BLOCK_COBWEB ].m_Transparent = true; + ms_Info[E_BLOCK_CROPS ].m_Transparent = true; + ms_Info[E_BLOCK_DANDELION ].m_Transparent = true; + ms_Info[E_BLOCK_DETECTOR_RAIL ].m_Transparent = true; + ms_Info[E_BLOCK_ENDER_CHEST ].m_Transparent = true; + ms_Info[E_BLOCK_FENCE ].m_Transparent = true; + ms_Info[E_BLOCK_FENCE_GATE ].m_Transparent = true; + ms_Info[E_BLOCK_FIRE ].m_Transparent = true; + ms_Info[E_BLOCK_FLOWER ].m_Transparent = true; + ms_Info[E_BLOCK_FLOWER_POT ].m_Transparent = true; + ms_Info[E_BLOCK_GLASS ].m_Transparent = true; + ms_Info[E_BLOCK_GLASS_PANE ].m_Transparent = true; + ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_Transparent = true; + ms_Info[E_BLOCK_ICE ].m_Transparent = true; + ms_Info[E_BLOCK_IRON_DOOR ].m_Transparent = true; + ms_Info[E_BLOCK_LAVA ].m_Transparent = true; + ms_Info[E_BLOCK_LEAVES ].m_Transparent = true; + ms_Info[E_BLOCK_LEVER ].m_Transparent = true; + ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_Transparent = true; + ms_Info[E_BLOCK_MELON_STEM ].m_Transparent = true; + ms_Info[E_BLOCK_NETHER_BRICK_FENCE ].m_Transparent = true; + ms_Info[E_BLOCK_NEW_LEAVES ].m_Transparent = true; + ms_Info[E_BLOCK_POTATOES ].m_Transparent = true; + ms_Info[E_BLOCK_POWERED_RAIL ].m_Transparent = true; + ms_Info[E_BLOCK_PISTON_EXTENSION ].m_Transparent = true; + ms_Info[E_BLOCK_PUMPKIN_STEM ].m_Transparent = true; + ms_Info[E_BLOCK_RAIL ].m_Transparent = true; + ms_Info[E_BLOCK_RED_MUSHROOM ].m_Transparent = true; + ms_Info[E_BLOCK_SIGN_POST ].m_Transparent = true; + ms_Info[E_BLOCK_SNOW ].m_Transparent = true; + ms_Info[E_BLOCK_STAINED_GLASS ].m_Transparent = true; + ms_Info[E_BLOCK_STAINED_GLASS_PANE ].m_Transparent = true; + ms_Info[E_BLOCK_STATIONARY_LAVA ].m_Transparent = true; + ms_Info[E_BLOCK_STATIONARY_WATER ].m_Transparent = true; + ms_Info[E_BLOCK_STONE_BUTTON ].m_Transparent = true; + ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_Transparent = true; + ms_Info[E_BLOCK_TALL_GRASS ].m_Transparent = true; + ms_Info[E_BLOCK_TORCH ].m_Transparent = true; + ms_Info[E_BLOCK_VINES ].m_Transparent = true; + ms_Info[E_BLOCK_WALLSIGN ].m_Transparent = true; + ms_Info[E_BLOCK_WATER ].m_Transparent = true; + ms_Info[E_BLOCK_WOODEN_BUTTON ].m_Transparent = true; + ms_Info[E_BLOCK_WOODEN_DOOR ].m_Transparent = true; + ms_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_Transparent = true; + + // TODO: Any other transparent blocks? + + + // One hit break blocks: + ms_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_OneHitDig = true; + ms_Info[E_BLOCK_BIG_FLOWER ].m_OneHitDig = true; + ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_OneHitDig = true; + ms_Info[E_BLOCK_CARROTS ].m_OneHitDig = true; + ms_Info[E_BLOCK_CROPS ].m_OneHitDig = true; + ms_Info[E_BLOCK_DANDELION ].m_OneHitDig = true; + ms_Info[E_BLOCK_FIRE ].m_OneHitDig = true; + ms_Info[E_BLOCK_FLOWER ].m_OneHitDig = true; + ms_Info[E_BLOCK_FLOWER_POT ].m_OneHitDig = true; + ms_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_OneHitDig = true; + ms_Info[E_BLOCK_MELON_STEM ].m_OneHitDig = true; + ms_Info[E_BLOCK_POTATOES ].m_OneHitDig = true; + ms_Info[E_BLOCK_PUMPKIN_STEM ].m_OneHitDig = true; + ms_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_OneHitDig = true; + ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_OneHitDig = true; + ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_OneHitDig = true; + ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_OneHitDig = true; + ms_Info[E_BLOCK_REDSTONE_WIRE ].m_OneHitDig = true; + ms_Info[E_BLOCK_RED_MUSHROOM ].m_OneHitDig = true; + ms_Info[E_BLOCK_REEDS ].m_OneHitDig = true; + ms_Info[E_BLOCK_SAPLING ].m_OneHitDig = true; + ms_Info[E_BLOCK_TNT ].m_OneHitDig = true; + ms_Info[E_BLOCK_TALL_GRASS ].m_OneHitDig = true; + ms_Info[E_BLOCK_TORCH ].m_OneHitDig = true; + + + // Blocks that break when pushed by piston: + ms_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_PistonBreakable = true; + ms_Info[E_BLOCK_AIR ].m_PistonBreakable = true; + ms_Info[E_BLOCK_BED ].m_PistonBreakable = true; + ms_Info[E_BLOCK_BIG_FLOWER ].m_PistonBreakable = true; + ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_PistonBreakable = true; + ms_Info[E_BLOCK_COBWEB ].m_PistonBreakable = true; + ms_Info[E_BLOCK_CROPS ].m_PistonBreakable = true; + ms_Info[E_BLOCK_DANDELION ].m_PistonBreakable = true; + ms_Info[E_BLOCK_DEAD_BUSH ].m_PistonBreakable = true; + ms_Info[E_BLOCK_FIRE ].m_PistonBreakable = true; + ms_Info[E_BLOCK_FLOWER ].m_PistonBreakable = true; + ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_PistonBreakable = true; + ms_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_PistonBreakable = true; + ms_Info[E_BLOCK_IRON_DOOR ].m_PistonBreakable = true; + ms_Info[E_BLOCK_JACK_O_LANTERN ].m_PistonBreakable = true; + ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_PistonBreakable = true; + ms_Info[E_BLOCK_LADDER ].m_PistonBreakable = true; + ms_Info[E_BLOCK_LAVA ].m_PistonBreakable = true; + ms_Info[E_BLOCK_LEVER ].m_PistonBreakable = true; + ms_Info[E_BLOCK_MELON ].m_PistonBreakable = true; + ms_Info[E_BLOCK_MELON_STEM ].m_PistonBreakable = true; + ms_Info[E_BLOCK_PUMPKIN ].m_PistonBreakable = true; + ms_Info[E_BLOCK_PUMPKIN_STEM ].m_PistonBreakable = true; + ms_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_PistonBreakable = true; + ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_PistonBreakable = true; + ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_PistonBreakable = true; + ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_PistonBreakable = true; + ms_Info[E_BLOCK_REDSTONE_WIRE ].m_PistonBreakable = true; + ms_Info[E_BLOCK_RED_MUSHROOM ].m_PistonBreakable = true; + ms_Info[E_BLOCK_REEDS ].m_PistonBreakable = true; + ms_Info[E_BLOCK_SNOW ].m_PistonBreakable = true; + ms_Info[E_BLOCK_STATIONARY_LAVA ].m_PistonBreakable = true; + ms_Info[E_BLOCK_STATIONARY_WATER ].m_PistonBreakable = true; + ms_Info[E_BLOCK_STONE_BUTTON ].m_PistonBreakable = true; + ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_PistonBreakable = true; + ms_Info[E_BLOCK_TALL_GRASS ].m_PistonBreakable = true; + ms_Info[E_BLOCK_TORCH ].m_PistonBreakable = true; + ms_Info[E_BLOCK_VINES ].m_PistonBreakable = true; + ms_Info[E_BLOCK_WATER ].m_PistonBreakable = true; + ms_Info[E_BLOCK_WOODEN_BUTTON ].m_PistonBreakable = true; + ms_Info[E_BLOCK_WOODEN_DOOR ].m_PistonBreakable = true; + ms_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_PistonBreakable = true; + + + // Blocks that cannot be snowed over: + ms_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_IsSnowable = false; + ms_Info[E_BLOCK_AIR ].m_IsSnowable = false; + ms_Info[E_BLOCK_BIG_FLOWER ].m_IsSnowable = false; + ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_IsSnowable = false; + ms_Info[E_BLOCK_CACTUS ].m_IsSnowable = false; + ms_Info[E_BLOCK_CHEST ].m_IsSnowable = false; + ms_Info[E_BLOCK_CROPS ].m_IsSnowable = false; + ms_Info[E_BLOCK_DANDELION ].m_IsSnowable = false; + ms_Info[E_BLOCK_FIRE ].m_IsSnowable = false; + ms_Info[E_BLOCK_FLOWER ].m_IsSnowable = false; + ms_Info[E_BLOCK_GLASS ].m_IsSnowable = false; + ms_Info[E_BLOCK_ICE ].m_IsSnowable = false; + ms_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_IsSnowable = false; + ms_Info[E_BLOCK_LAVA ].m_IsSnowable = false; + ms_Info[E_BLOCK_LILY_PAD ].m_IsSnowable = false; + ms_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_IsSnowable = false; + ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_IsSnowable = false; + ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_IsSnowable = false; + ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_IsSnowable = false; + ms_Info[E_BLOCK_REDSTONE_WIRE ].m_IsSnowable = false; + ms_Info[E_BLOCK_RED_MUSHROOM ].m_IsSnowable = false; + ms_Info[E_BLOCK_REEDS ].m_IsSnowable = false; + ms_Info[E_BLOCK_SAPLING ].m_IsSnowable = false; + ms_Info[E_BLOCK_SIGN_POST ].m_IsSnowable = false; + ms_Info[E_BLOCK_SNOW ].m_IsSnowable = false; + ms_Info[E_BLOCK_STAINED_GLASS ].m_IsSnowable = false; + ms_Info[E_BLOCK_STAINED_GLASS_PANE ].m_IsSnowable = false; + ms_Info[E_BLOCK_STATIONARY_LAVA ].m_IsSnowable = false; + ms_Info[E_BLOCK_STATIONARY_WATER ].m_IsSnowable = false; + ms_Info[E_BLOCK_TALL_GRASS ].m_IsSnowable = false; + ms_Info[E_BLOCK_TNT ].m_IsSnowable = false; + ms_Info[E_BLOCK_TORCH ].m_IsSnowable = false; + ms_Info[E_BLOCK_VINES ].m_IsSnowable = false; + ms_Info[E_BLOCK_WALLSIGN ].m_IsSnowable = false; + ms_Info[E_BLOCK_WATER ].m_IsSnowable = false; + + + // Blocks that don't drop without a special tool: + ms_Info[E_BLOCK_BRICK ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_CAULDRON ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_COAL_ORE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_COBBLESTONE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_COBBLESTONE_STAIRS ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_COBWEB ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_DIAMOND_BLOCK ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_DIAMOND_ORE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_DOUBLE_STONE_SLAB ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_EMERALD_ORE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_END_STONE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_GOLD_BLOCK ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_GOLD_ORE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_IRON_BLOCK ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_IRON_ORE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_LAPIS_BLOCK ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_LAPIS_ORE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_MOSSY_COBBLESTONE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_NETHERRACK ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_NETHER_BRICK ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_NETHER_BRICK_STAIRS ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_OBSIDIAN ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_REDSTONE_ORE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_SANDSTONE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_SANDSTONE_STAIRS ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_SNOW ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_STONE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_STONE_BRICKS ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_STONE_BRICK_STAIRS ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_STONE_SLAB ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_VINES ].m_RequiresSpecialTool = true; + + + // Nonsolid blocks: + ms_Info[E_BLOCK_ACTIVATOR_RAIL ].m_IsSolid = false; + ms_Info[E_BLOCK_AIR ].m_IsSolid = false; + ms_Info[E_BLOCK_BIG_FLOWER ].m_IsSolid = false; + ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_IsSolid = false; + ms_Info[E_BLOCK_CARROTS ].m_IsSolid = false; + ms_Info[E_BLOCK_COBWEB ].m_IsSolid = false; + ms_Info[E_BLOCK_CROPS ].m_IsSolid = false; + ms_Info[E_BLOCK_DANDELION ].m_IsSolid = false; + ms_Info[E_BLOCK_DETECTOR_RAIL ].m_IsSolid = false; + ms_Info[E_BLOCK_END_PORTAL ].m_IsSolid = false; + ms_Info[E_BLOCK_FIRE ].m_IsSolid = false; + ms_Info[E_BLOCK_FLOWER ].m_IsSolid = false; + ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_IsSolid = false; + ms_Info[E_BLOCK_LAVA ].m_IsSolid = false; + ms_Info[E_BLOCK_LEVER ].m_IsSolid = false; + ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_IsSolid = false; + ms_Info[E_BLOCK_MELON_STEM ].m_IsSolid = false; + ms_Info[E_BLOCK_NETHER_PORTAL ].m_IsSolid = false; + ms_Info[E_BLOCK_PISTON_EXTENSION ].m_IsSolid = false; + ms_Info[E_BLOCK_POTATOES ].m_IsSolid = false; + ms_Info[E_BLOCK_POWERED_RAIL ].m_IsSolid = false; + ms_Info[E_BLOCK_RAIL ].m_IsSolid = false; + ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_IsSolid = false; + ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_IsSolid = false; + ms_Info[E_BLOCK_REDSTONE_WIRE ].m_IsSolid = false; + ms_Info[E_BLOCK_RED_MUSHROOM ].m_IsSolid = false; + ms_Info[E_BLOCK_REEDS ].m_IsSolid = false; + ms_Info[E_BLOCK_SAPLING ].m_IsSolid = false; + ms_Info[E_BLOCK_SIGN_POST ].m_IsSolid = false; + ms_Info[E_BLOCK_SNOW ].m_IsSolid = false; + ms_Info[E_BLOCK_STATIONARY_LAVA ].m_IsSolid = false; + ms_Info[E_BLOCK_STATIONARY_WATER ].m_IsSolid = false; + ms_Info[E_BLOCK_STONE_BUTTON ].m_IsSolid = false; + ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_IsSolid = false; + ms_Info[E_BLOCK_TALL_GRASS ].m_IsSolid = false; + ms_Info[E_BLOCK_TORCH ].m_IsSolid = false; + ms_Info[E_BLOCK_TRIPWIRE ].m_IsSolid = false; + ms_Info[E_BLOCK_VINES ].m_IsSolid = false; + ms_Info[E_BLOCK_WALLSIGN ].m_IsSolid = false; + ms_Info[E_BLOCK_WATER ].m_IsSolid = false; + ms_Info[E_BLOCK_WOODEN_BUTTON ].m_IsSolid = false; + ms_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_IsSolid = false; + ms_Info[E_BLOCK_WOODEN_SLAB ].m_IsSolid = false; + + + // Torch placeable blocks: + ms_Info[E_BLOCK_NEW_LOG ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_BEDROCK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_BLOCK_OF_COAL ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_BLOCK_OF_REDSTONE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_BOOKCASE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_BRICK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_CLAY ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_COAL_ORE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_COBBLESTONE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_COMMAND_BLOCK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_CRAFTING_TABLE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_DIAMOND_BLOCK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_DIAMOND_ORE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_DIRT ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_DISPENSER ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_DOUBLE_STONE_SLAB ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_DOUBLE_WOODEN_SLAB ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_DROPPER ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_EMERALD_BLOCK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_EMERALD_ORE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_END_STONE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_FURNACE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_GLOWSTONE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_GOLD_BLOCK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_GOLD_ORE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_GRASS ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_GRAVEL ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_HARDENED_CLAY ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_HAY_BALE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_HUGE_BROWN_MUSHROOM ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_HUGE_RED_MUSHROOM ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_IRON_BLOCK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_IRON_ORE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_JACK_O_LANTERN ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_JUKEBOX ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_LAPIS_BLOCK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_LAPIS_ORE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_LOG ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_MELON ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_MOSSY_COBBLESTONE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_MYCELIUM ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_NETHERRACK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_NETHER_BRICK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_NETHER_QUARTZ_ORE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_NOTE_BLOCK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_OBSIDIAN ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_PACKED_ICE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_PLANKS ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_PUMPKIN ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_QUARTZ_BLOCK ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_REDSTONE_LAMP_OFF ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_REDSTONE_LAMP_ON ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_REDSTONE_ORE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_SANDSTONE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_SAND ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_SILVERFISH_EGG ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_SPONGE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_STAINED_CLAY ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_WOOL ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_STONE ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_STONE_BRICKS ].m_FullyOccupiesVoxel = true; +} + + + + + +// This is actually just some code that needs to run at program startup, so it is wrapped into a global var's constructor: +class cBlockInfoInitializer +{ +public: + cBlockInfoInitializer(void) + { + BlockInfo::Initialize(); + } +} BlockInfoInitializer; + + + + + diff --git a/src/BlockInfo.h b/src/BlockInfo.h new file mode 100644 index 000000000..1e09b0df5 --- /dev/null +++ b/src/BlockInfo.h @@ -0,0 +1,54 @@ + +#pragma once + + + + + + +class BlockInfo +{ +public: + + BlockInfo(); + + /** (Re-)Initializes the internal BlockInfo structures. */ + static void Initialize(void); + + /** Returns the associated BlockInfo structure. */ + static BlockInfo & GetById(unsigned int a_ID); + + NIBBLETYPE m_LightValue; + NIBBLETYPE m_SpreadLightFalloff; + + bool m_Transparent; + bool m_OneHitDig; + bool m_PistonBreakable; + bool m_IsSnowable; + bool m_RequiresSpecialTool; + bool m_IsSolid; + bool m_FullyOccupiesVoxel; + + + inline static NIBBLETYPE GetLightValue (unsigned int a_ID) { return GetById(a_ID).m_LightValue; } + inline static NIBBLETYPE GetSpreadLightFalloff(unsigned int a_ID) { return GetById(a_ID).m_SpreadLightFalloff; } + inline static bool IsTransparent (unsigned int a_ID) { return GetById(a_ID).m_Transparent; } + inline static bool IsOneHitDig (unsigned int a_ID) { return GetById(a_ID).m_OneHitDig; } + inline static bool IsPistoneBreakable (unsigned int a_ID) { return GetById(a_ID).m_PistonBreakable; } + inline static bool IsSnowable (unsigned int a_ID) { return GetById(a_ID).m_IsSnowable; } + inline static bool RequiresSpecialTool (unsigned int a_ID) { return GetById(a_ID).m_RequiresSpecialTool; } + inline static bool IsSolid (unsigned int a_ID) { return GetById(a_ID).m_IsSolid; } + inline static bool FullyOccupiesVoxel (unsigned int a_ID) { return GetById(a_ID).m_FullyOccupiesVoxel; } + + +protected: + + // TODO xdot: Change to std::vector to support dynamic block IDs + static BlockInfo ms_Info[256]; + + +}; + + + + -- cgit v1.2.3 From 0acfbdd91283c96fd0f371f51029a72d6c9cd3de Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Mar 2014 09:47:27 -0800 Subject: Final implementation of MetaRotater --- src/Blocks/MetaRotater.h | 96 +++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h index f1656f1bd..b83ed177a 100644 --- a/src/Blocks/MetaRotater.h +++ b/src/Blocks/MetaRotater.h @@ -1,7 +1,7 @@ #pragma once -template +template class cMetaRotater : public Base { public: @@ -19,64 +19,70 @@ public: }; -template -NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) { -NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); -switch (a_Meta & BitFilter) -{ -case South: return West | OtherMeta; -case West: return North | OtherMeta; -case North: return East | OtherMeta; -case East: return South | OtherMeta; -} -ASSERT(!"Invalid Meta value"); -return a_Meta; + NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); + switch (a_Meta & BitFilter) + { + case South: return West | OtherMeta; + case West: return North | OtherMeta; + case North: return East | OtherMeta; + case East: return South | OtherMeta; + } + if(AssertIfNotMatched) + { + ASSERT(!"Invalid Meta value"); + return a_Meta; + } } -template -NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) { -NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); -switch (a_Meta & BitFilter) -{ -case South: return East | OtherMeta; -case East: return North | OtherMeta; -case North: return West | OtherMeta; -case West: return South | OtherMeta; -} -ASSERT(!"Invalid Meta value"); -return a_Meta; + NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); + switch (a_Meta & BitFilter) + { + case South: return East | OtherMeta; + case East: return North | OtherMeta; + case North: return West | OtherMeta; + case West: return South | OtherMeta; + } + if(AssertIfNotMatched) + { + ASSERT(!"Invalid Meta value"); + return a_Meta; + } } -template -NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) { -NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); -switch (a_Meta & BitFilter) -{ -case South: return North | OtherMeta; -case North: return South | OtherMeta; -} -// Not Facing North or South; No change. -return a_Meta; + NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); + switch (a_Meta & BitFilter) + { + case South: return North | OtherMeta; + case North: return South | OtherMeta; + } + // Not Facing North or South; No change. + return a_Meta; } -template -NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) { -NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); -switch (a_Meta & BitFilter) -{ -case West: return East | OtherMeta; -case East: return West | OtherMeta; -} -// Not Facing East or West; No change. -return a_Meta; + NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); + switch (a_Meta & BitFilter) + { + case West: return East | OtherMeta; + case East: return West | OtherMeta; + } + // Not Facing East or West; No change. + return a_Meta; } -- cgit v1.2.3 From 65edffd5b04623dcd4cebbd1afb2575e98eee5db Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Mar 2014 10:04:50 -0800 Subject: Implemented Rotations --- src/Blocks/BlockBed.h | 4 +-- src/Blocks/BlockButton.h | 5 ++-- src/Blocks/BlockChest.h | 5 ++-- src/Blocks/BlockComparator.h | 5 ++-- src/Blocks/BlockDoor.h | 5 ++-- src/Blocks/BlockDropSpenser.h | 1 + src/Blocks/BlockEnderchest.h | 2 +- src/Blocks/BlockFenceGate.h | 6 ++-- src/Blocks/BlockStairs.h | 68 ++----------------------------------------- src/Blocks/BlockTorch.h | 67 ++---------------------------------------- src/Blocks/BlockVine.h | 30 ++----------------- 11 files changed, 28 insertions(+), 170 deletions(-) diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 6e8884114..d8a796735 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -12,11 +12,11 @@ class cBlockBedHandler : - public cMetaRotater + public cMetaRotater { public: cBlockBedHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 5a4bf7c96..4daa03005 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -2,16 +2,17 @@ #include "BlockHandler.h" #include "Chunk.h" +#include "MetaRotater.h" class cBlockButtonHandler : - public cMetaRotater + public cMetaRotater { public: cBlockButtonHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 4ab23bced..6a13e826e 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -4,17 +4,18 @@ #include "BlockEntity.h" #include "../BlockArea.h" #include "../Entities/Player.h" +#include "MetaRotater.h" class cBlockChestHandler : - public cMetaRotater + public cMetaRotater { public: cBlockChestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index 7e672eece..238e687ab 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -3,17 +3,18 @@ #include "BlockHandler.h" #include "BlockRedstoneRepeater.h" +#include "MetaRotater.h" class cBlockComparatorHandler : - public cMetaRotater + public cMetaRotater { public: cBlockComparatorHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index c3647b203..8e3f2d83f 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -4,14 +4,15 @@ #include "BlockHandler.h" #include "../Entities/Player.h" #include "Chunk.h" +#include "MetaRotater.h" class cBlockDoorHandler : - public cMetaRotater + public cMetaRotater { - typedef super cMetaRotater; + typedef super cMetaRotater; public: cBlockDoorHandler(BLOCKTYPE a_BlockType); diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index 2253fcd1b..73937577a 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -6,6 +6,7 @@ #pragma once #include "../Piston.h" +#include "MetaRotater.h" diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index ed3f37013..6ca83399a 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -2,7 +2,7 @@ #pragma once #include "BlockEntity.h" - +#include "MetaRotater.h" diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index 035579e8e..c33393590 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -2,17 +2,17 @@ #pragma once #include "BlockHandler.h" - +#include "MetaRotater.h" class cBlockFenceGateHandler : - public cMetaRotater + public cMetaRotater { public: cBlockFenceGateHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index c1887bc46..f07afc9f0 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -2,17 +2,17 @@ #pragma once #include "BlockHandler.h" - +#include "MetaRotater.h" class cBlockStairsHandler : - public cBlockHandler + public cMetaRotater { public: cBlockStairsHandler(BLOCKTYPE a_BlockType) : - cBlockHandler(a_BlockType) + cMetaRotater(a_BlockType) { } @@ -96,54 +96,6 @@ public: } - virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override - { - // Bits 3 and 4 stay, the rest is swapped around according to a table: - NIBBLETYPE TopBits = (a_Meta & 0x0c); - switch (a_Meta & 0x03) - { - case 0x00: return TopBits | 0x03; // East -> North - case 0x01: return TopBits | 0x02; // West -> South - case 0x02: return TopBits | 0x00; // South -> East - case 0x03: return TopBits | 0x01; // North -> West - } - // Not reachable, but to avoid a compiler warning: - return 0; - } - - - virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override - { - // Bits 3 and 4 stay, the rest is swapped around according to a table: - NIBBLETYPE TopBits = (a_Meta & 0x0c); - switch (a_Meta & 0x03) - { - case 0x00: return TopBits | 0x02; // East -> South - case 0x01: return TopBits | 0x03; // West -> North - case 0x02: return TopBits | 0x01; // South -> West - case 0x03: return TopBits | 0x00; // North -> East - } - // Not reachable, but to avoid a compiler warning: - return 0; - } - - - virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override - { - // Bits 3 and 4 stay, the rest is swapped around according to a table: - NIBBLETYPE TopBits = (a_Meta & 0x0c); - switch (a_Meta & 0x03) - { - case 0x00: return TopBits | 0x00; // East -> East - case 0x01: return TopBits | 0x01; // West -> West - case 0x02: return TopBits | 0x03; // South -> North - case 0x03: return TopBits | 0x02; // North -> South - } - // Not reachable, but to avoid a compiler warning: - return 0; - } - - virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override { // Toggle bit 3: @@ -151,20 +103,6 @@ public: } - virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override - { - // Bits 3 and 4 stay, the rest is swapped around according to a table: - NIBBLETYPE TopBits = (a_Meta & 0x0c); - switch (a_Meta & 0x03) - { - case 0x00: return TopBits | 0x01; // East -> West - case 0x01: return TopBits | 0x00; // West -> East - case 0x02: return TopBits | 0x02; // South -> South - case 0x03: return TopBits | 0x03; // North -> North - } - // Not reachable, but to avoid a compiler warning: - return 0; - } } ; diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index f2a4c8665..59c896857 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -2,17 +2,17 @@ #include "BlockHandler.h" #include "../Chunk.h" - +#include "MetaRotater.h" class cBlockTorchHandler : - public cBlockHandler + public cMetaRotater { public: cBlockTorchHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotater(a_BlockType) { } @@ -185,67 +185,6 @@ public: { return "step.wood"; } - - - virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override - { - // Bit 4 stays, the rest is swapped around according to a table: - NIBBLETYPE TopBits = (a_Meta & 0x08); - switch (a_Meta & 0x07) - { - case 0x01: return TopBits | 0x04; // East -> North - case 0x02: return TopBits | 0x03; // West -> South - case 0x03: return TopBits | 0x01; // South -> East - case 0x04: return TopBits | 0x02; // North -> West - default: return a_Meta; // Floor -> Floor - } - } - - - virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override - { - // Bit 4 stays, the rest is swapped around according to a table: - NIBBLETYPE TopBits = (a_Meta & 0x08); - switch (a_Meta & 0x07) - { - case 0x01: return TopBits | 0x03; // East -> South - case 0x02: return TopBits | 0x04; // West -> North - case 0x03: return TopBits | 0x02; // South -> West - case 0x04: return TopBits | 0x01; // North -> East - default: return a_Meta; // Floor -> Floor - } - } - - - virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override - { - // Bit 4 stays, the rest is swapped around according to a table: - NIBBLETYPE TopBits = (a_Meta & 0x08); - switch (a_Meta & 0x07) - { - case 0x03: return TopBits | 0x04; // South -> North - case 0x04: return TopBits | 0x03; // North -> South - default: return a_Meta; // Keep the rest - } - } - - - // Mirroring around the XZ plane doesn't make sense for floor torches, - // the others stay the same, so let's keep all the metas the same. - // The base class does tht for us, no need to override MetaMirrorXZ() - - - virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override - { - // Bit 4 stays, the rest is swapped around according to a table: - NIBBLETYPE TopBits = (a_Meta & 0x08); - switch (a_Meta & 0x07) - { - case 0x01: return TopBits | 0x02; // East -> West - case 0x02: return TopBits | 0x01; // West -> East - default: return a_Meta; // Keep the rest - } - } } ; diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index ee7dcee8a..9e2105f67 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -2,17 +2,17 @@ #pragma once #include "BlockHandler.h" - +#include "MetaRotater.h" class cBlockVineHandler : - public cBlockHandler + public cMetaRotater { public: cBlockVineHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotater(a_BlockType) { } @@ -169,31 +169,7 @@ public: a_World->SetBlock(X, Y - 1, Z, E_BLOCK_VINES, a_World->GetBlockMeta(X, Y, Z)); } } - - virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override - { - return ((a_Meta >> 1) | (a_Meta << 3)) & 0x0f; // Rotate bits to the right - } - - virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override - { - return ((a_Meta << 1) | (a_Meta >> 3)) & 0x0f; // Rotate bits to the left - } - - - virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override - { - // Bits 2 and 4 stay, bits 1 and 3 swap - return ((a_Meta & 0x0a) | ((a_Meta & 0x01) << 2) | ((a_Meta & 0x04) >> 2)); - } - - - virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override - { - // Bits 1 and 3 stay, bits 2 and 4 swap - return ((a_Meta & 0x05) | ((a_Meta & 0x02) << 2) | ((a_Meta & 0x08) >> 2)); - } } ; -- cgit v1.2.3 From 5093b75ef1488b3687e1c54c893ab68b4475e451 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Mar 2014 10:14:24 -0800 Subject: Revesed typedef --- src/Blocks/BlockDoor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 8e3f2d83f..0caeb7dba 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -12,7 +12,7 @@ class cBlockDoorHandler : public cMetaRotater { - typedef super cMetaRotater; + typedef cMetaRotater super; public: cBlockDoorHandler(BLOCKTYPE a_BlockType); -- cgit v1.2.3 From 1e1d89fd2005ee634094fd3d55638965d41acecf Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Mar 2014 10:17:55 -0800 Subject: Fixed errors --- src/Blocks/BlockChest.h | 2 +- src/Blocks/BlockDropSpenser.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 6a13e826e..1646454a7 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -15,7 +15,7 @@ class cBlockChestHandler : { public: cBlockChestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index 73937577a..adc819a4c 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -17,7 +17,7 @@ class cBlockDropSpenserHandler : { public: cBlockDropSpenserHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotater(a_BlockType) { } -- cgit v1.2.3 From d73cdba1f66a92f011ac881b581595c0959139ef Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 1 Mar 2014 21:34:19 +0200 Subject: g_BlockXXX => cBlockInfo::XXX --- src/BlockInfo.cpp | 10 +++++----- src/BlockInfo.h | 27 +++++++++++++++++++++----- src/Blocks/BlockButton.h | 2 +- src/Blocks/BlockCactus.h | 2 +- src/Blocks/BlockDirt.h | 4 ++-- src/Blocks/BlockLadder.h | 2 +- src/Blocks/BlockLever.h | 2 +- src/Blocks/BlockRail.h | 4 ++-- src/Blocks/BlockRedstone.h | 2 +- src/Blocks/BlockSnow.h | 2 +- src/Blocks/BlockTorch.h | 6 +++--- src/Blocks/BlockTrapdoor.h | 2 +- src/Blocks/BlockVine.h | 2 +- src/Chunk.cpp | 10 +++++----- src/ClientHandle.cpp | 2 +- src/Defines.h | 2 +- src/Entities/Entity.cpp | 6 +++--- src/Entities/Minecart.cpp | 16 +++++++-------- src/Entities/Player.cpp | 2 +- src/Entities/ProjectileEntity.cpp | 4 ++-- src/Generating/FinishGen.cpp | 6 +++--- src/Globals.h | 1 + src/Items/ItemRedstoneDust.h | 2 +- src/LightingThread.cpp | 4 ++-- src/LightingThread.h | 4 ++-- src/MobSpawner.cpp | 14 ++++++------- src/Mobs/Monster.cpp | 10 +++++----- src/Mobs/SnowGolem.cpp | 2 +- src/Piston.cpp | 2 +- src/Simulator/FireSimulator.cpp | 2 +- src/Simulator/IncrementalRedstoneSimulator.cpp | 4 ++-- src/Simulator/IncrementalRedstoneSimulator.h | 2 +- src/Tracer.cpp | 2 +- 33 files changed, 91 insertions(+), 73 deletions(-) diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index 6ae59db53..5fd6d33c1 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -7,13 +7,13 @@ -BlockInfo BlockInfo::ms_Info[256]; +cBlockInfo cBlockInfo::ms_Info[256]; -BlockInfo::BlockInfo() +cBlockInfo::cBlockInfo() : m_LightValue(0x00) , m_SpreadLightFalloff(0x0f) , m_Transparent(false) @@ -29,7 +29,7 @@ BlockInfo::BlockInfo() -BlockInfo & BlockInfo::GetById(unsigned int a_ID) +cBlockInfo & cBlockInfo::GetById(unsigned int a_ID) { ASSERT(a_ID < 256); @@ -40,7 +40,7 @@ BlockInfo & BlockInfo::GetById(unsigned int a_ID) -void BlockInfo::Initialize(void) +void cBlockInfo::Initialize(void) { // Emissive blocks ms_Info[E_BLOCK_FIRE ].m_LightValue = 15; @@ -413,7 +413,7 @@ class cBlockInfoInitializer public: cBlockInfoInitializer(void) { - BlockInfo::Initialize(); + cBlockInfo::Initialize(); } } BlockInfoInitializer; diff --git a/src/BlockInfo.h b/src/BlockInfo.h index 1e09b0df5..a06c47a47 100644 --- a/src/BlockInfo.h +++ b/src/BlockInfo.h @@ -6,27 +6,44 @@ -class BlockInfo +class cBlockInfo { public: - BlockInfo(); + cBlockInfo(); /** (Re-)Initializes the internal BlockInfo structures. */ static void Initialize(void); /** Returns the associated BlockInfo structure. */ - static BlockInfo & GetById(unsigned int a_ID); + static cBlockInfo & GetById(unsigned int a_ID); + + /** How much light do the blocks emit on their own? */ NIBBLETYPE m_LightValue; + + /** How much light do the blocks consume? */ NIBBLETYPE m_SpreadLightFalloff; + /** Is a block completely transparent? (light doesn't get decreased(?)) */ bool m_Transparent; + + /** Is a block destroyed after a single hit? */ bool m_OneHitDig; + + /** Can a piston break this block? */ bool m_PistonBreakable; + + /** Can this block hold snow atop? */ bool m_IsSnowable; + + /** Does this block require a tool to drop? */ bool m_RequiresSpecialTool; + + /** Is this block solid (player cannot walk through)? */ bool m_IsSolid; + + /** Does this block fully occupy it's voxel - is it a 'full' block? */ bool m_FullyOccupiesVoxel; @@ -34,7 +51,7 @@ public: inline static NIBBLETYPE GetSpreadLightFalloff(unsigned int a_ID) { return GetById(a_ID).m_SpreadLightFalloff; } inline static bool IsTransparent (unsigned int a_ID) { return GetById(a_ID).m_Transparent; } inline static bool IsOneHitDig (unsigned int a_ID) { return GetById(a_ID).m_OneHitDig; } - inline static bool IsPistoneBreakable (unsigned int a_ID) { return GetById(a_ID).m_PistonBreakable; } + inline static bool IsPistonBreakable (unsigned int a_ID) { return GetById(a_ID).m_PistonBreakable; } inline static bool IsSnowable (unsigned int a_ID) { return GetById(a_ID).m_IsSnowable; } inline static bool RequiresSpecialTool (unsigned int a_ID) { return GetById(a_ID).m_RequiresSpecialTool; } inline static bool IsSolid (unsigned int a_ID) { return GetById(a_ID).m_IsSolid; } @@ -44,7 +61,7 @@ public: protected: // TODO xdot: Change to std::vector to support dynamic block IDs - static BlockInfo ms_Info[256]; + static cBlockInfo ms_Info[256]; }; diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index ca6850ced..2db9b7ec7 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -101,7 +101,7 @@ public: AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn); - return (a_RelY > 0) && (g_BlockIsSolid[BlockIsOn]); + return (a_RelY > 0) && (cBlockInfo::IsSolid(BlockIsOn)); } } ; diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h index 83595d2b9..ed441517d 100644 --- a/src/Blocks/BlockCactus.h +++ b/src/Blocks/BlockCactus.h @@ -54,7 +54,7 @@ public: NIBBLETYPE BlockMeta; if ( a_Chunk.UnboundedRelGetBlock(a_RelX + Coords[i].x, a_RelY, a_RelZ + Coords[i].z, BlockType, BlockMeta) && - (g_BlockIsSolid[BlockType]) + cBlockInfo::IsSolid(BlockType) ) { return false; diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index 91534c5e5..544424a04 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -36,7 +36,7 @@ public: if (a_RelY < cChunkDef::Height - 1) { BLOCKTYPE Above = a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ); - if ((!g_BlockTransparent[Above] && !g_BlockOneHitDig[Above]) || IsBlockWater(Above)) + if ((!cBlockInfo::IsTransparent(Above) && !cBlockInfo::IsOneHitDig(Above)) || IsBlockWater(Above)) { a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_DIRT, E_META_DIRT_NORMAL); return; @@ -77,7 +77,7 @@ public: BLOCKTYPE AboveDest; NIBBLETYPE AboveMeta; Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta); - if ((g_BlockOneHitDig[AboveDest] || g_BlockTransparent[AboveDest]) && !IsBlockWater(AboveDest)) + if ((cBlockInfo::IsOneHitDig(AboveDest) || cBlockInfo::IsTransparent(AboveDest)) && !IsBlockWater(AboveDest)) { Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0); } diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h index 6a105d5c9..a3e9edc6b 100644 --- a/src/Blocks/BlockLadder.h +++ b/src/Blocks/BlockLadder.h @@ -91,7 +91,7 @@ public: AddFaceDirection( a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); - return g_BlockIsSolid[a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ)]; + return cBlockInfo::IsSolid(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ)); } diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index 48c7e774b..ef6e102cd 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -102,7 +102,7 @@ public: AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn); - return (a_RelY > 0) && (g_BlockIsSolid[BlockIsOn]); + return (a_RelY > 0) && cBlockInfo::IsSolid(BlockIsOn); } } ; diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 52d6f60b3..07e9814cd 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -98,7 +98,7 @@ public: { return false; } - if (!g_BlockIsSolid[a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)]) + if (!cBlockInfo::IsSolid(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ))) { return false; } @@ -130,7 +130,7 @@ public: // Too close to the edge, cannot simulate return true; } - return g_BlockIsSolid[BlockType]; + return cBlockInfo::IsSolid(BlockType); } } return true; diff --git a/src/Blocks/BlockRedstone.h b/src/Blocks/BlockRedstone.h index 10de96197..a898c9acb 100644 --- a/src/Blocks/BlockRedstone.h +++ b/src/Blocks/BlockRedstone.h @@ -20,7 +20,7 @@ public: virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { - return ((a_RelY > 0) && g_BlockFullyOccupiesVoxel[a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)]); + return ((a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ))); } diff --git a/src/Blocks/BlockSnow.h b/src/Blocks/BlockSnow.h index a3daf0393..b21995d3c 100644 --- a/src/Blocks/BlockSnow.h +++ b/src/Blocks/BlockSnow.h @@ -72,7 +72,7 @@ public: BLOCKTYPE BlockBelow = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ); NIBBLETYPE MetaBelow = a_Chunk.GetMeta(a_RelX, a_RelY - 1, a_RelZ); - if (g_BlockIsSnowable[BlockBelow] || ((BlockBelow == E_BLOCK_SNOW) && (MetaBelow == 7))) + if (cBlockInfo::IsSnowable(BlockBelow) || ((BlockBelow == E_BLOCK_SNOW) && (MetaBelow == 7))) { // If block below is snowable, or it is a thin slow block and has a meta of 7 (full thin snow block), say yay return true; diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index f2a4c8665..84bbb37ec 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -99,7 +99,7 @@ public: static bool CanBePlacedOn(BLOCKTYPE a_BlockType, eBlockFace a_BlockFace) { - if ( !g_BlockFullyOccupiesVoxel[a_BlockType] ) + if ( !cBlockInfo::FullyOccupiesVoxel(a_BlockType) ) { return (a_BlockFace == BLOCK_FACE_TOP); // Allow placement only when torch upright (for glass, etc.); exceptions won't even be sent by client, no need to handle } @@ -129,7 +129,7 @@ public: { return Face; } - else if ((g_BlockFullyOccupiesVoxel[BlockInQuestion]) && (i != BLOCK_FACE_BOTTOM)) + else if (cBlockInfo::FullyOccupiesVoxel(BlockInQuestion) && (i != BLOCK_FACE_BOTTOM)) { // Otherwise, if block in that direction is torch placeable and we haven't gotten to it via the bottom face, return that face return Face; @@ -163,7 +163,7 @@ public: // No need to check for upright orientation, it was done when the torch was placed return true; } - else if ( !g_BlockFullyOccupiesVoxel[BlockInQuestion] ) + else if ( !cBlockInfo::FullyOccupiesVoxel(BlockInQuestion) ) { return false; } diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 08fc28327..70a369e69 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -97,7 +97,7 @@ public: AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn); - return (a_RelY > 0) && (g_BlockIsSolid[BlockIsOn]); + return (a_RelY > 0) && cBlockInfo::IsSolid(BlockIsOn); } }; diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index ee7dcee8a..d8c114284 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -70,7 +70,7 @@ public: /// Returns true if the specified block type is good for vines to attach to static bool IsBlockAttachable(BLOCKTYPE a_BlockType) { - return (a_BlockType == E_BLOCK_LEAVES) || g_BlockIsSolid[a_BlockType]; + return (a_BlockType == E_BLOCK_LEAVES) || cBlockInfo::IsSolid(a_BlockType); } diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 8dfbbeef5..a75828461 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -883,7 +883,7 @@ void cChunk::ApplyWeatherToTop() FastSetBlock(X, Height, Z, E_BLOCK_SNOW, TopMeta - 1); } } - else if (g_BlockIsSnowable[TopBlock]) + else if (cBlockInfo::IsSnowable(TopBlock)) { SetBlock(X, Height + 1, Z, E_BLOCK_SNOW, 0); } @@ -1540,10 +1540,10 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT SetNibble(m_BlockMeta, index, a_BlockMeta); // ONLY recalculate lighting if it's necessary! - if( - (g_BlockLightValue[OldBlockType ] != g_BlockLightValue[a_BlockType]) || - (g_BlockSpreadLightFalloff[OldBlockType] != g_BlockSpreadLightFalloff[a_BlockType]) || - (g_BlockTransparent[OldBlockType] != g_BlockTransparent[a_BlockType]) + if ( + (cBlockInfo::GetLightValue (OldBlockType) != cBlockInfo::GetLightValue (a_BlockType)) || + (cBlockInfo::GetSpreadLightFalloff(OldBlockType) != cBlockInfo::GetSpreadLightFalloff(a_BlockType)) || + (cBlockInfo::IsTransparent (OldBlockType) != cBlockInfo::IsTransparent (a_BlockType)) ) { m_IsLightValid = false; diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index b08ceb5f6..60f14af54 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -819,7 +819,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc if ( (m_Player->IsGameModeCreative()) || // In creative mode, digging is done immediately - g_BlockOneHitDig[a_OldBlock] // One-hit blocks get destroyed immediately, too + cBlockInfo::IsOneHitDig(a_OldBlock) // One-hit blocks get destroyed immediately, too ) { HandleBlockDigFinished(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta); diff --git a/src/Defines.h b/src/Defines.h index ba2866f83..31d48860f 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -654,7 +654,7 @@ namespace ItemCategory inline bool BlockRequiresSpecialTool(BLOCKTYPE a_BlockType) { if(!IsValidBlock(a_BlockType)) return false; - return g_BlockRequiresSpecialTool[a_BlockType]; + return cBlockInfo::RequiresSpecialTool(a_BlockType); } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 8554ab2a5..96e8c15a5 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -582,11 +582,11 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width); BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ ); BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; - if (!g_BlockIsSolid[BlockIn]) // Making sure we are not inside a solid block + if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block { if (m_bOnGround) // check if it's still on the ground { - if (!g_BlockIsSolid[BlockBelow]) // Check if block below is air or water. + if (!cBlockInfo::IsSolid(BlockBelow)) // Check if block below is air or water. { m_bOnGround = false; } @@ -616,7 +616,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) // The pickup is too close to an unloaded chunk, bail out of any physics handling return; } - if (!g_BlockIsSolid[GotBlock]) + if (!cBlockInfo::IsSolid(GotBlock)) { NextPos.x += gCrossCoords[i].x; NextPos.z += gCrossCoords[i].z; diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index d854906b7..f52a7b6d9 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -720,7 +720,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) if (GetSpeedZ() > 0) { BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())); - if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) + if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { // We could try to detect a block in front based purely on coordinates, but xoft made a bounding box system - why not use? :P cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())), 0.5, 1); @@ -737,7 +737,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) else if (GetSpeedZ() < 0) { BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1); - if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) + if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ() - 1), GetWidth() / 2, GetHeight()); @@ -757,7 +757,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) if (GetSpeedX() > 0) { BLOCKTYPE Block = m_World->GetBlock((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); - if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) + if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { cBoundingBox bbBlock(Vector3d((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); @@ -773,7 +773,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) else if (GetSpeedX() < 0) { BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); - if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) + if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX() - 1, floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); @@ -798,10 +798,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) BLOCKTYPE BlockZM = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); BLOCKTYPE BlockZP = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); if ( - (!IsBlockRail(BlockXM) && g_BlockIsSolid[BlockXM]) || - (!IsBlockRail(BlockXP) && g_BlockIsSolid[BlockXP]) || - (!IsBlockRail(BlockZM) && g_BlockIsSolid[BlockZM]) || - (!IsBlockRail(BlockZP) && g_BlockIsSolid[BlockZP]) + (!IsBlockRail(BlockXM) && cBlockInfo::IsSolid(BlockXM)) || + (!IsBlockRail(BlockXP) && cBlockInfo::IsSolid(BlockXP)) || + (!IsBlockRail(BlockZM) && cBlockInfo::IsSolid(BlockZM)) || + (!IsBlockRail(BlockZP) && cBlockInfo::IsSolid(BlockZP)) ) { SetSpeed(0, 0, 0); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 8f94f1feb..42ee14cf3 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1904,7 +1904,7 @@ void cPlayer::Detach() { for (int z = PosZ - 2; z <= (PosZ + 2); ++z) { - if (!g_BlockIsSolid[m_World->GetBlock(x, y, z)] && g_BlockIsSolid[m_World->GetBlock(x, y - 1, z)]) + if (!cBlockInfo::IsSolid(m_World->GetBlock(x, y, z)) && cBlockInfo::IsSolid(m_World->GetBlock(x, y - 1, z))) { TeleportToCoords(x, y, z); return; diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index ef82c6e94..03bc0c99d 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -50,12 +50,12 @@ protected: LOGD("Hit block %d:%d at {%d, %d, %d} face %d, %s (%s)", a_BlockType, a_BlockMeta, a_BlockX, a_BlockY, a_BlockZ, a_EntryFace, - g_BlockIsSolid[a_BlockType] ? "solid" : "non-solid", + cBlockInfo::IsSolid(a_BlockType) ? "solid" : "non-solid", ItemToString(cItem(a_BlockType, 1, a_BlockMeta)).c_str() ); */ - if (g_BlockIsSolid[a_BlockType]) + if (cBlockInfo::IsSolid(a_BlockType)) { // The projectile hit a solid block // Calculate the exact hit coords: diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 02045f76a..f2d66af70 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -88,7 +88,7 @@ void cFinishGenNetherClumpFoliage::GenFinish(cChunkDesc & a_ChunkDesc) { continue; } - if (!g_BlockIsSolid[a_ChunkDesc.GetBlockType(PosX, y - 1, PosZ)]) // Only place on solid blocks + if (!cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(PosX, y - 1, PosZ))) // Only place on solid blocks { continue; } @@ -131,7 +131,7 @@ void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a } BLOCKTYPE BlockBelow = a_ChunkDesc.GetBlockType(x, y - 1, z); - if (!g_BlockIsSolid[BlockBelow]) // Only place on solid blocks + if (!cBlockInfo::IsSolid(BlockBelow)) // Only place on solid blocks { continue; } @@ -329,7 +329,7 @@ void cFinishGenSnow::GenFinish(cChunkDesc & a_ChunkDesc) case biFrozenOcean: { int Height = a_ChunkDesc.GetHeight(x, z); - if (g_BlockIsSnowable[a_ChunkDesc.GetBlockType(x, Height, z)]) + if (cBlockInfo::IsSnowable(a_ChunkDesc.GetBlockType(x, Height, z))) { a_ChunkDesc.SetBlockType(x, Height + 1, z, E_BLOCK_SNOW); a_ChunkDesc.SetHeight(x, z, Height + 1); diff --git a/src/Globals.h b/src/Globals.h index e4737a98a..28805a83f 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -250,6 +250,7 @@ T Clamp(T a_Value, T a_Min, T a_Max) #include "ChunkDef.h" #include "BiomeDef.h" #include "BlockID.h" +#include "BlockInfo.h" #include "Entities/Effects.h" diff --git a/src/Items/ItemRedstoneDust.h b/src/Items/ItemRedstoneDust.h index 18c6b8615..274d905a5 100644 --- a/src/Items/ItemRedstoneDust.h +++ b/src/Items/ItemRedstoneDust.h @@ -27,7 +27,7 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override { - if (!g_BlockFullyOccupiesVoxel[a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ)]) // Some solid blocks, such as cocoa beans, are not suitable for dust + if (!cBlockInfo::FullyOccupiesVoxel(a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ))) // Some solid blocks, such as cocoa beans, are not suitable for dust { return false; } diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index 9c81d004d..44dadb8a9 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -391,7 +391,7 @@ void cLightingThread::PrepareBlockLight(void) int idx = BaseZ + x; for (int y = m_HeightMap[idx], Index = idx + y * BlocksPerYLayer; y >= 0; y--, Index -= BlocksPerYLayer) { - if (g_BlockLightValue[m_BlockTypes[Index]] == 0) + if (cBlockInfo::GetLightValue(m_BlockTypes[Index]) == 0) { continue; } @@ -401,7 +401,7 @@ void cLightingThread::PrepareBlockLight(void) m_SeedIdx1[m_NumSeeds++] = Index; // Light it up: - m_BlockLight[Index] = g_BlockLightValue[m_BlockTypes[Index]]; + m_BlockLight[Index] = cBlockInfo::GetLightValue(m_BlockTypes[Index]); } } } diff --git a/src/LightingThread.h b/src/LightingThread.h index 72d561348..198f27248 100644 --- a/src/LightingThread.h +++ b/src/LightingThread.h @@ -169,13 +169,13 @@ protected: ASSERT(a_DstIdx >= 0); ASSERT(a_DstIdx < (int)ARRAYCOUNT(m_BlockTypes)); - if (a_Light[a_SrcIdx] <= a_Light[a_DstIdx] + g_BlockSpreadLightFalloff[m_BlockTypes[a_DstIdx]]) + if (a_Light[a_SrcIdx] <= a_Light[a_DstIdx] + cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx])) { // We're not offering more light than the dest block already has return; } - a_Light[a_DstIdx] = a_Light[a_SrcIdx] - g_BlockSpreadLightFalloff[m_BlockTypes[a_DstIdx]]; + a_Light[a_DstIdx] = a_Light[a_SrcIdx] - cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx]); if (!a_IsSeedOut[a_DstIdx]) { a_IsSeedOut[a_DstIdx] = true; diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index c86268e63..7704f6cf3 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -145,7 +145,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R case cMonster::mtBat: { - return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4) && (TargetBlock == E_BLOCK_AIR) && (!g_BlockTransparent[BlockAbove]); + return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4) && (TargetBlock == E_BLOCK_AIR) && !cBlockInfo::IsTransparent(BlockAbove); } case cMonster::mtChicken: @@ -157,7 +157,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R return ( (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && - (!g_BlockTransparent[BlockBelow]) && + (!cBlockInfo::IsTransparent(BlockBelow)) && (BlockBelow == E_BLOCK_GRASS) && (SkyLight >= 9) ); @@ -188,7 +188,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (BlockTop == E_BLOCK_AIR) && - (!g_BlockTransparent[BlockBelow]) && + (!cBlockInfo::IsTransparent(BlockBelow)) && (SkyLight <= 7) && (BlockLight <= 7) ); @@ -215,7 +215,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R HaveFloor || ( a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1, a_RelZ + z, TargetBlock) && - !g_BlockTransparent[TargetBlock] + !cBlockInfo::IsTransparent(TargetBlock) ) ); } @@ -230,7 +230,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R return ( (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && - (!g_BlockTransparent[BlockBelow]) && + (!cBlockInfo::IsTransparent(BlockBelow)) && (SkyLight <= 7) && (BlockLight <= 7) && (m_Random.NextInt(2, a_Biome) == 0) @@ -242,7 +242,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R return ( (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && - (!g_BlockTransparent[BlockBelow]) && + (!cBlockInfo::IsTransparent(BlockBelow)) && ( (a_RelY <= 40) || (a_Biome == biSwampland) ) @@ -255,7 +255,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R return ( (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && - (!g_BlockTransparent[BlockBelow]) && + (!cBlockInfo::IsTransparent(BlockBelow)) && (m_Random.NextInt(20, a_Biome) == 0) ); } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index ac9137ccd..6e3c91d58 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -148,11 +148,11 @@ void cMonster::TickPathFinding() BLOCKTYPE BlockAtYPP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 2, gCrossCoords[i].z + PosZ); BLOCKTYPE BlockAtYM = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY - 1, gCrossCoords[i].z + PosZ); - if ((!g_BlockIsSolid[BlockAtY]) && (!g_BlockIsSolid[BlockAtYP]) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) + if ((!cBlockInfo::IsSolid(BlockAtY)) && (!cBlockInfo::IsSolid(BlockAtYP)) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) { m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY, gCrossCoords[i].z + PosZ)); } - else if ((g_BlockIsSolid[BlockAtY]) && (!g_BlockIsSolid[BlockAtYP]) && (!g_BlockIsSolid[BlockAtYPP]) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) + else if ((cBlockInfo::IsSolid(BlockAtY)) && (!cBlockInfo::IsSolid(BlockAtYP)) && (!cBlockInfo::IsSolid(BlockAtYPP)) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) { m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY + 1, gCrossCoords[i].z + PosZ)); } @@ -416,9 +416,9 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) else if (PosY > cChunkDef::Height) PosY = cChunkDef::Height; - if (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))]) + if (!cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ)))) { - while (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY > 0)) + while (!cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY > 0)) { PosY--; } @@ -427,7 +427,7 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) } else { - while (g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY < cChunkDef::Height)) + while (cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY < cChunkDef::Height)) { PosY++; } diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index 67e3a3bb8..c1979a495 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -38,7 +38,7 @@ void cSnowGolem::Tick(float a_Dt, cChunk & a_Chunk) { BLOCKTYPE BlockBelow = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()) - 1, (int) floor(GetPosZ())); BLOCKTYPE Block = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ())); - if (Block == E_BLOCK_AIR && g_BlockIsSolid[BlockBelow]) + if (Block == E_BLOCK_AIR && cBlockInfo::IsSolid(BlockBelow)) { m_World->SetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ()), E_BLOCK_SNOW, 0); } diff --git a/src/Piston.cpp b/src/Piston.cpp index 5eb14451d..b21d576f3 100644 --- a/src/Piston.cpp +++ b/src/Piston.cpp @@ -242,7 +242,7 @@ bool cPiston::CanPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) bool cPiston::CanBreakPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { UNUSED(a_BlockMeta); - return g_BlockPistonBreakable[a_BlockType]; + return cBlockInfo::IsPistonBreakable(a_BlockType); } diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index b77fa1658..6aef97079 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -239,7 +239,7 @@ int cFireSimulator::GetBurnStepTime(cChunk * a_Chunk, int a_RelX, int a_RelY, in { return m_BurnStepTimeFuel; } - IsBlockBelowSolid = g_BlockIsSolid[BlockBelow]; + IsBlockBelowSolid = cBlockInfo::IsSolid(BlockBelow); } for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 91de9e0cc..0640227b0 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -566,14 +566,14 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block { if ((i >= 4) && (i <= 7)) // If we are currently checking for wire surrounding ourself one block above... { - if (g_BlockIsSolid[m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)]) // If there is something solid above us (wire cut off)... + if (cBlockInfo::IsSolid(m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))) // If there is something solid above us (wire cut off)... { continue; // We don't receive power from that wire } } else if ((i >= 8) && (i <= 11)) // See above, but this is for wire below us { - if (g_BlockIsSolid[m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y + 1, a_BlockZ + gCrossCoords[i].z)]) + if (cBlockInfo::IsSolid(m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y + 1, a_BlockZ + gCrossCoords[i].z))) { continue; } diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index e6bc28621..8b7363366 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -170,7 +170,7 @@ private: /* ====== Misc Functions ====== */ /** Returns if a block is viable to be the MiddleBlock of a SetLinkedPowered operation */ - inline static bool IsViableMiddleBlock(BLOCKTYPE Block) { return g_BlockFullyOccupiesVoxel[Block]; } + inline static bool IsViableMiddleBlock(BLOCKTYPE Block) { return cBlockInfo::FullyOccupiesVoxel(Block); } /** Returns if a block is a mechanism (something that accepts power and does something) */ inline static bool IsMechanism(BLOCKTYPE Block) diff --git a/src/Tracer.cpp b/src/Tracer.cpp index ef136302f..968a64439 100644 --- a/src/Tracer.cpp +++ b/src/Tracer.cpp @@ -226,7 +226,7 @@ bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int BLOCKTYPE BlockID = m_World->GetBlock(pos.x, pos.y, pos.z); // Block is counted as a collision if we are not doing a line of sight and it is solid, // or if the block is not air and not water. That way mobs can still see underwater. - if ((!a_LineOfSight && g_BlockIsSolid[BlockID]) || (a_LineOfSight && (BlockID != E_BLOCK_AIR) && !IsBlockWater(BlockID))) + if ((!a_LineOfSight && cBlockInfo::IsSolid(BlockID)) || (a_LineOfSight && (BlockID != E_BLOCK_AIR) && !IsBlockWater(BlockID))) { BlockHitPosition = pos; int Normal = GetHitNormal(a_Start, End, pos ); -- cgit v1.2.3 From 29cc1ed05160955d1a17e63a0e9b26b9203e5d0f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 1 Mar 2014 20:51:58 +0100 Subject: Ignoring all plugin subfolders. Plugins developed directly with MCS have been added explicitly; other plugins are ignored. --- MCServer/Plugins/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/MCServer/Plugins/.gitignore b/MCServer/Plugins/.gitignore index 89eab800a..8553945b5 100644 --- a/MCServer/Plugins/.gitignore +++ b/MCServer/Plugins/.gitignore @@ -1,2 +1,3 @@ *.txt *.md +*/ -- cgit v1.2.3 From 2f85c9648b3f109bb579611dbb9af45b64c8a2f8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 1 Mar 2014 20:56:09 +0100 Subject: Unified StructureGens and FinisherGens. Now they are all Finishers. Fixes #398. --- src/Generating/Caves.cpp | 6 +- src/Generating/Caves.h | 16 ++-- src/Generating/ComposableGenerator.cpp | 157 +++++++++++++++------------------ src/Generating/ComposableGenerator.h | 56 ++++-------- src/Generating/MineShafts.cpp | 2 +- src/Generating/MineShafts.h | 6 +- src/Generating/Ravines.cpp | 2 +- src/Generating/Ravines.h | 6 +- src/Generating/StructGen.cpp | 10 +-- src/Generating/StructGen.h | 30 +++---- 10 files changed, 128 insertions(+), 163 deletions(-) diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp index 2571e6b77..98b7c8681 100644 --- a/src/Generating/Caves.cpp +++ b/src/Generating/Caves.cpp @@ -762,7 +762,7 @@ void cStructGenWormNestCaves::ClearCache(void) -void cStructGenWormNestCaves::GenStructures(cChunkDesc & a_ChunkDesc) +void cStructGenWormNestCaves::GenFinish(cChunkDesc & a_ChunkDesc) { int ChunkX = a_ChunkDesc.GetChunkX(); int ChunkZ = a_ChunkDesc.GetChunkZ(); @@ -902,7 +902,7 @@ static float GetMarbleNoise( float x, float y, float z, cNoise & a_Noise ) -void cStructGenMarbleCaves::GenStructures(cChunkDesc & a_ChunkDesc) +void cStructGenMarbleCaves::GenFinish(cChunkDesc & a_ChunkDesc) { cNoise Noise(m_Seed); for (int z = 0; z < cChunkDef::Width; z++) @@ -938,7 +938,7 @@ void cStructGenMarbleCaves::GenStructures(cChunkDesc & a_ChunkDesc) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cStructGenDualRidgeCaves: -void cStructGenDualRidgeCaves::GenStructures(cChunkDesc & a_ChunkDesc) +void cStructGenDualRidgeCaves::GenFinish(cChunkDesc & a_ChunkDesc) { for (int z = 0; z < cChunkDef::Width; z++) { diff --git a/src/Generating/Caves.h b/src/Generating/Caves.h index ea7f10bf4..7c45c056b 100644 --- a/src/Generating/Caves.h +++ b/src/Generating/Caves.h @@ -20,7 +20,7 @@ class cStructGenMarbleCaves : - public cStructureGen + public cFinishGen { public: cStructGenMarbleCaves(int a_Seed) : m_Seed(a_Seed) {} @@ -29,8 +29,8 @@ protected: int m_Seed; - // cStructureGen override: - virtual void GenStructures(cChunkDesc & a_ChunkDesc) override; + // cFinishGen override: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; @@ -38,7 +38,7 @@ protected: class cStructGenDualRidgeCaves : - public cStructureGen + public cFinishGen { public: cStructGenDualRidgeCaves(int a_Seed, float a_Threshold) : @@ -55,8 +55,8 @@ protected: int m_Seed; float m_Threshold; - // cStructureGen override: - virtual void GenStructures(cChunkDesc & a_ChunkDesc) override; + // cFinishGen override: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; @@ -64,7 +64,7 @@ protected: class cStructGenWormNestCaves : - public cStructureGen + public cFinishGen { public: cStructGenWormNestCaves(int a_Seed, int a_Size = 64, int a_Grid = 96, int a_MaxOffset = 128) : @@ -94,7 +94,7 @@ protected: void GetCavesForChunk(int a_ChunkX, int a_ChunkZ, cCaveSystems & a_Caves); // cStructGen override: - virtual void GenStructures(cChunkDesc & a_ChunkDesc) override; + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index cfa7e9c6f..e96e9a645 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -133,11 +133,6 @@ cComposableGenerator::~cComposableGenerator() delete *itr; } m_FinishGens.clear(); - for (cStructureGenList::const_iterator itr = m_StructureGens.begin(); itr != m_StructureGens.end(); ++itr) - { - delete *itr; - } - m_StructureGens.clear(); delete m_CompositionGen; m_CompositionGen = NULL; @@ -164,7 +159,6 @@ void cComposableGenerator::Initialize(cIniFile & a_IniFile) InitBiomeGen(a_IniFile); InitHeightGen(a_IniFile); InitCompositionGen(a_IniFile); - InitStructureGens(a_IniFile); InitFinishGens(a_IniFile); } @@ -201,14 +195,6 @@ void cComposableGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a m_CompositionGen->ComposeTerrain(a_ChunkDesc); } - if (a_ChunkDesc.IsUsingDefaultStructures()) - { - for (cStructureGenList::iterator itr = m_StructureGens.begin(); itr != m_StructureGens.end(); ++itr) - { - (*itr)->GenStructures(a_ChunkDesc); - } // for itr - m_StructureGens[] - } - if (a_ChunkDesc.IsUsingDefaultFinish()) { for (cFinishGenList::iterator itr = m_FinishGens.begin(); itr != m_FinishGens.end(); ++itr) @@ -290,35 +276,69 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile) -void cComposableGenerator::InitStructureGens(cIniFile & a_IniFile) +void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) { - AString Structures = a_IniFile.GetValueSet("Generator", "Structures", "Ravines, WormNestCaves, WaterLakes, LavaLakes, OreNests, Trees"); - int Seed = m_ChunkGenerator.GetSeed(); - AStringVector Str = StringSplitAndTrim(Structures, ","); + eDimension Dimension = StringToDimension(a_IniFile.GetValue("General", "Dimension", "Overworld")); + + // Older configuration used "Structures" in addition to "Finishers"; we don't distinguish between the two anymore (#398) + // Therefore, we load Structures from the ini file for compatibility, but move its contents over to Finishers: + AString Structures = a_IniFile.GetValue("Generator", "Structures", ""); + AString Finishers = a_IniFile.GetValueSet("Generator", "Finishers", "Ravines, WormNestCaves, WaterLakes, LavaLakes, OreNests, Trees, SprinkleFoliage, Ice, Snow, Lilypads, BottomLava, DeadBushes, PreSimulator"); + if (!Structures.empty()) + { + LOGINFO("[Generator].Structures is deprecated, moving the contents to [Generator].Finishers."); + // Structures used to generate before Finishers, so place them first: + Structures.append(", "); + Finishers = Structures + Finishers; + a_IniFile.SetValue("Generator", "Finishers", Finishers); + } + a_IniFile.DeleteValue("Generator", "Structures"); + + // Create all requested finishers: + AStringVector Str = StringSplitAndTrim(Finishers, ","); for (AStringVector::const_iterator itr = Str.begin(); itr != Str.end(); ++itr) { - if (NoCaseCompare(*itr, "DualRidgeCaves") == 0) + // Finishers, alpha-sorted: + if (NoCaseCompare(*itr, "BottomLava") == 0) { - float Threshold = (float)a_IniFile.GetValueSetF("Generator", "DualRidgeCavesThreshold", 0.3); - m_StructureGens.push_back(new cStructGenDualRidgeCaves(Seed, Threshold)); + int DefaultBottomLavaLevel = (Dimension == dimNether) ? 30 : 10; + int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel); + m_FinishGens.push_back(new cFinishGenBottomLava(BottomLavaLevel)); + } + else if (NoCaseCompare(*itr, "DeadBushes") == 0) + { + m_FinishGens.push_back(new cFinishGenSingleBiomeSingleTopBlock(Seed, E_BLOCK_DEAD_BUSH, biDesert, 2, E_BLOCK_SAND, E_BLOCK_SAND)); } else if (NoCaseCompare(*itr, "DirectOverhangs") == 0) { - m_StructureGens.push_back(new cStructGenDirectOverhangs(Seed)); + m_FinishGens.push_back(new cStructGenDirectOverhangs(Seed)); } else if (NoCaseCompare(*itr, "DistortedMembraneOverhangs") == 0) { - m_StructureGens.push_back(new cStructGenDistortedMembraneOverhangs(Seed)); + m_FinishGens.push_back(new cStructGenDistortedMembraneOverhangs(Seed)); + } + else if (NoCaseCompare(*itr, "DualRidgeCaves") == 0) + { + float Threshold = (float)a_IniFile.GetValueSetF("Generator", "DualRidgeCavesThreshold", 0.3); + m_FinishGens.push_back(new cStructGenDualRidgeCaves(Seed, Threshold)); + } + else if (NoCaseCompare(*itr, "Ice") == 0) + { + m_FinishGens.push_back(new cFinishGenIce); } else if (NoCaseCompare(*itr, "LavaLakes") == 0) { int Probability = a_IniFile.GetValueSetI("Generator", "LavaLakesProbability", 10); - m_StructureGens.push_back(new cStructGenLakes(Seed * 5 + 16873, E_BLOCK_STATIONARY_LAVA, *m_HeightGen, Probability)); + m_FinishGens.push_back(new cStructGenLakes(Seed * 5 + 16873, E_BLOCK_STATIONARY_LAVA, *m_HeightGen, Probability)); + } + else if (NoCaseCompare(*itr, "LavaSprings") == 0) + { + m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_LAVA, a_IniFile, Dimension)); } else if (NoCaseCompare(*itr, "MarbleCaves") == 0) { - m_StructureGens.push_back(new cStructGenMarbleCaves(Seed)); + m_FinishGens.push_back(new cStructGenMarbleCaves(Seed)); } else if (NoCaseCompare(*itr, "MineShafts") == 0) { @@ -327,71 +347,11 @@ void cComposableGenerator::InitStructureGens(cIniFile & a_IniFile) int ChanceCorridor = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCorridor", 600); int ChanceCrossing = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCrossing", 200); int ChanceStaircase = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceStaircase", 200); - m_StructureGens.push_back(new cStructGenMineShafts( + m_FinishGens.push_back(new cStructGenMineShafts( Seed, GridSize, MaxSystemSize, ChanceCorridor, ChanceCrossing, ChanceStaircase )); } - else if (NoCaseCompare(*itr, "OreNests") == 0) - { - m_StructureGens.push_back(new cStructGenOreNests(Seed)); - } - else if (NoCaseCompare(*itr, "Ravines") == 0) - { - m_StructureGens.push_back(new cStructGenRavines(Seed, 128)); - } - else if (NoCaseCompare(*itr, "Trees") == 0) - { - m_StructureGens.push_back(new cStructGenTrees(Seed, m_BiomeGen, m_HeightGen, m_CompositionGen)); - } - else if (NoCaseCompare(*itr, "WaterLakes") == 0) - { - int Probability = a_IniFile.GetValueSetI("Generator", "WaterLakesProbability", 25); - m_StructureGens.push_back(new cStructGenLakes(Seed * 3 + 652, E_BLOCK_STATIONARY_WATER, *m_HeightGen, Probability)); - } - else if (NoCaseCompare(*itr, "WormNestCaves") == 0) - { - m_StructureGens.push_back(new cStructGenWormNestCaves(Seed)); - } - else - { - LOGWARNING("Unknown structure generator: \"%s\". Ignoring.", itr->c_str()); - } - } // for itr - Str[] -} - - - - - -void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) -{ - int Seed = m_ChunkGenerator.GetSeed(); - eDimension Dimension = StringToDimension(a_IniFile.GetValue("General", "Dimension", "Overworld")); - - AString Finishers = a_IniFile.GetValueSet("Generator", "Finishers", "SprinkleFoliage,Ice,Snow,Lilypads,BottomLava,DeadBushes,PreSimulator"); - AStringVector Str = StringSplitAndTrim(Finishers, ","); - for (AStringVector::const_iterator itr = Str.begin(); itr != Str.end(); ++itr) - { - // Finishers, alpha-sorted: - if (NoCaseCompare(*itr, "BottomLava") == 0) - { - int DefaultBottomLavaLevel = (Dimension == dimNether) ? 30 : 10; - int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel); - m_FinishGens.push_back(new cFinishGenBottomLava(BottomLavaLevel)); - } - else if (NoCaseCompare(*itr, "DeadBushes") == 0) - { - m_FinishGens.push_back(new cFinishGenSingleBiomeSingleTopBlock(Seed, E_BLOCK_DEAD_BUSH, biDesert, 2, E_BLOCK_SAND, E_BLOCK_SAND)); - } - else if (NoCaseCompare(*itr, "Ice") == 0) - { - m_FinishGens.push_back(new cFinishGenIce); - } - else if (NoCaseCompare(*itr, "LavaSprings") == 0) - { - m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_LAVA, a_IniFile, Dimension)); - } else if (NoCaseCompare(*itr, "Lilypads") == 0) { m_FinishGens.push_back(new cFinishGenSingleBiomeSingleTopBlock(Seed, E_BLOCK_LILY_PAD, biSwampland, 4, E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER)); @@ -400,10 +360,18 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) { m_FinishGens.push_back(new cFinishGenNetherClumpFoliage(Seed)); } + else if (NoCaseCompare(*itr, "OreNests") == 0) + { + m_FinishGens.push_back(new cStructGenOreNests(Seed)); + } else if (NoCaseCompare(*itr, "PreSimulator") == 0) { m_FinishGens.push_back(new cFinishGenPreSimulator); } + else if (NoCaseCompare(*itr, "Ravines") == 0) + { + m_FinishGens.push_back(new cStructGenRavines(Seed, 128)); + } else if (NoCaseCompare(*itr, "Snow") == 0) { m_FinishGens.push_back(new cFinishGenSnow); @@ -412,10 +380,27 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) { m_FinishGens.push_back(new cFinishGenSprinkleFoliage(Seed)); } + else if (NoCaseCompare(*itr, "Trees") == 0) + { + m_FinishGens.push_back(new cStructGenTrees(Seed, m_BiomeGen, m_HeightGen, m_CompositionGen)); + } + else if (NoCaseCompare(*itr, "WaterLakes") == 0) + { + int Probability = a_IniFile.GetValueSetI("Generator", "WaterLakesProbability", 25); + m_FinishGens.push_back(new cStructGenLakes(Seed * 3 + 652, E_BLOCK_STATIONARY_WATER, *m_HeightGen, Probability)); + } else if (NoCaseCompare(*itr, "WaterSprings") == 0) { m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_WATER, a_IniFile, Dimension)); } + else if (NoCaseCompare(*itr, "WormNestCaves") == 0) + { + m_FinishGens.push_back(new cStructGenWormNestCaves(Seed)); + } + else + { + LOGWARNING("Unknown Finisher in the [Generator] section: \"%s\". Ignoring.", itr->c_str()); + } } // for itr - Str[] } diff --git a/src/Generating/ComposableGenerator.h b/src/Generating/ComposableGenerator.h index 29add0636..6b7627d2e 100644 --- a/src/Generating/ComposableGenerator.h +++ b/src/Generating/ComposableGenerator.h @@ -43,16 +43,16 @@ class cBiomeGen public: virtual ~cBiomeGen() {} // Force a virtual destructor in descendants - /// Generates biomes for the given chunk + /** Generates biomes for the given chunk */ virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) = 0; - /// Reads parameters from the ini file, prepares generator for use. + /** Reads parameters from the ini file, prepares generator for use. */ virtual void InitializeBiomeGen(cIniFile & a_IniFile) {} - /// Creates the correct BiomeGen descendant based on the ini file settings and the seed provided. - /// a_CacheOffByDefault gets set to whether the cache should be disabled by default - /// Used in BiomeVisualiser, too. - /// Implemented in BioGen.cpp! + /** Creates the correct BiomeGen descendant based on the ini file settings and the seed provided. + a_CacheOffByDefault gets set to whether the cache should be disabled by default. + Used in BiomeVisualiser, too. + Implemented in BioGen.cpp! */ static cBiomeGen * CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault); } ; @@ -72,10 +72,10 @@ class cTerrainHeightGen public: virtual ~cTerrainHeightGen() {} // Force a virtual destructor in descendants - /// Generates heightmap for the given chunk + /** Generates heightmap for the given chunk */ virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) = 0; - /// Reads parameters from the ini file, prepares generator for use. + /** Reads parameters from the ini file, prepares generator for use. */ virtual void InitializeHeightGen(cIniFile & a_IniFile) {} /** Creates the correct TerrainHeightGen descendant based on the ini file settings and the seed provided. @@ -102,7 +102,7 @@ public: virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) = 0; - /// Reads parameters from the ini file, prepares generator for use. + /** Reads parameters from the ini file, prepares generator for use. */ virtual void InitializeCompoGen(cIniFile & a_IniFile) {} /** Creates the correct TerrainCompositionGen descendant based on the ini file settings and the seed provided. @@ -116,28 +116,12 @@ public: -/** The interface that a structure generator must implement -Structures are generated after the terrain composition took place. It should modify the blocktype data to account -for whatever structures the generator is generating. -Note that ores are considered structures too, at least from the interface point of view. -Also note that a worldgenerator may contain multiple structure generators, one for each type of structure -*/ -class cStructureGen -{ -public: - virtual ~cStructureGen() {} // Force a virtual destructor in descendants - - virtual void GenStructures(cChunkDesc & a_ChunkDesc) = 0; -} ; - -typedef std::list cStructureGenList; - - - - - /** The interface that a finisher must implement -Finisher implements small additions after all structures have been generated. +Finisher implements changes to the chunk after the rough terrain has been generated. +Examples of finishers are trees, snow, ore, lilypads and others. +Note that a worldgenerator may contain multiple finishers. +Also note that previously we used to distinguish between a structuregen and a finisher; this distinction is +no longer relevant, all structure generators are considered finishers now (#398) */ class cFinishGen { @@ -171,7 +155,6 @@ protected: cBiomeGen * m_BiomeGen; cTerrainHeightGen * m_HeightGen; cTerrainCompositionGen * m_CompositionGen; - cStructureGenList m_StructureGens; cFinishGenList m_FinishGens; // Generators underlying the caches: @@ -180,19 +163,16 @@ protected: cTerrainCompositionGen * m_UnderlyingCompositionGen; - /// Reads the biome gen settings from the ini and initializes m_BiomeGen accordingly + /** Reads the biome gen settings from the ini and initializes m_BiomeGen accordingly */ void InitBiomeGen(cIniFile & a_IniFile); - /// Reads the HeightGen settings from the ini and initializes m_HeightGen accordingly + /** Reads the HeightGen settings from the ini and initializes m_HeightGen accordingly */ void InitHeightGen(cIniFile & a_IniFile); - /// Reads the CompositionGen settings from the ini and initializes m_CompositionGen accordingly + /** Reads the CompositionGen settings from the ini and initializes m_CompositionGen accordingly */ void InitCompositionGen(cIniFile & a_IniFile); - /// Reads the structures to generate from the ini and initializes m_StructureGens accordingly - void InitStructureGens(cIniFile & a_IniFile); - - /// Reads the finishers from the ini and initializes m_FinishGens accordingly + /** Reads the finishers from the ini and initializes m_FinishGens accordingly */ void InitFinishGens(cIniFile & a_IniFile); } ; diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp index cc39cef7b..d9acc57bb 100644 --- a/src/Generating/MineShafts.cpp +++ b/src/Generating/MineShafts.cpp @@ -1407,7 +1407,7 @@ void cStructGenMineShafts::GetMineShaftSystemsForChunk( -void cStructGenMineShafts::GenStructures(cChunkDesc & a_ChunkDesc) +void cStructGenMineShafts::GenFinish(cChunkDesc & a_ChunkDesc) { int ChunkX = a_ChunkDesc.GetChunkX(); int ChunkZ = a_ChunkDesc.GetChunkZ(); diff --git a/src/Generating/MineShafts.h b/src/Generating/MineShafts.h index c53d3bc53..ba32e75ad 100644 --- a/src/Generating/MineShafts.h +++ b/src/Generating/MineShafts.h @@ -17,7 +17,7 @@ class cStructGenMineShafts : - public cStructureGen + public cFinishGen { public: cStructGenMineShafts( @@ -52,8 +52,8 @@ protected: */ void GetMineShaftSystemsForChunk(int a_ChunkX, int a_ChunkZ, cMineShaftSystems & a_MineShaftSystems); - // cStructureGen overrides: - virtual void GenStructures(cChunkDesc & a_ChunkDesc) override; + // cFinishGen overrides: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; diff --git a/src/Generating/Ravines.cpp b/src/Generating/Ravines.cpp index cfda47e32..e64f55214 100644 --- a/src/Generating/Ravines.cpp +++ b/src/Generating/Ravines.cpp @@ -117,7 +117,7 @@ void cStructGenRavines::ClearCache(void) -void cStructGenRavines::GenStructures(cChunkDesc & a_ChunkDesc) +void cStructGenRavines::GenFinish(cChunkDesc & a_ChunkDesc) { int ChunkX = a_ChunkDesc.GetChunkX(); int ChunkZ = a_ChunkDesc.GetChunkZ(); diff --git a/src/Generating/Ravines.h b/src/Generating/Ravines.h index 05164a5b2..c76b9f19f 100644 --- a/src/Generating/Ravines.h +++ b/src/Generating/Ravines.h @@ -17,7 +17,7 @@ class cStructGenRavines : - public cStructureGen + public cFinishGen { public: cStructGenRavines(int a_Seed, int a_Size); @@ -37,8 +37,8 @@ protected: /// Returns all ravines that *may* intersect the given chunk. All the ravines are valid until the next call to this function. void GetRavinesForChunk(int a_ChunkX, int a_ChunkZ, cRavines & a_Ravines); - // cStructureGen override: - virtual void GenStructures(cChunkDesc & a_ChunkDesc) override; + // cFinishGen override: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index 47945cc2b..3cc8a09c3 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -54,7 +54,7 @@ const int NEST_SIZE_GRAVEL = 32; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cStructGenTrees: -void cStructGenTrees::GenStructures(cChunkDesc & a_ChunkDesc) +void cStructGenTrees::GenFinish(cChunkDesc & a_ChunkDesc) { int ChunkX = a_ChunkDesc.GetChunkX(); int ChunkZ = a_ChunkDesc.GetChunkZ(); @@ -306,7 +306,7 @@ int cStructGenTrees::GetNumTrees( /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cStructGenOreNests: -void cStructGenOreNests::GenStructures(cChunkDesc & a_ChunkDesc) +void cStructGenOreNests::GenFinish(cChunkDesc & a_ChunkDesc) { int ChunkX = a_ChunkDesc.GetChunkX(); int ChunkZ = a_ChunkDesc.GetChunkZ(); @@ -413,7 +413,7 @@ void cStructGenOreNests::GenerateOre(int a_ChunkX, int a_ChunkZ, BLOCKTYPE a_Ore /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cStructGenLakes: -void cStructGenLakes::GenStructures(cChunkDesc & a_ChunkDesc) +void cStructGenLakes::GenFinish(cChunkDesc & a_ChunkDesc) { int ChunkX = a_ChunkDesc.GetChunkX(); int ChunkZ = a_ChunkDesc.GetChunkZ(); @@ -545,7 +545,7 @@ cStructGenDirectOverhangs::cStructGenDirectOverhangs(int a_Seed) : -void cStructGenDirectOverhangs::GenStructures(cChunkDesc & a_ChunkDesc) +void cStructGenDirectOverhangs::GenFinish(cChunkDesc & a_ChunkDesc) { // If there is no column of the wanted biome, bail out: if (!HasWantedBiome(a_ChunkDesc)) @@ -665,7 +665,7 @@ cStructGenDistortedMembraneOverhangs::cStructGenDistortedMembraneOverhangs(int a -void cStructGenDistortedMembraneOverhangs::GenStructures(cChunkDesc & a_ChunkDesc) +void cStructGenDistortedMembraneOverhangs::GenFinish(cChunkDesc & a_ChunkDesc) { const NOISE_DATATYPE Frequency = (NOISE_DATATYPE)16; const NOISE_DATATYPE Amount = (NOISE_DATATYPE)1; diff --git a/src/Generating/StructGen.h b/src/Generating/StructGen.h index 853748bb8..9176bc192 100644 --- a/src/Generating/StructGen.h +++ b/src/Generating/StructGen.h @@ -21,7 +21,7 @@ class cStructGenTrees : - public cStructureGen + public cFinishGen { public: cStructGenTrees(int a_Seed, cBiomeGen * a_BiomeGen, cTerrainHeightGen * a_HeightGen, cTerrainCompositionGen * a_CompositionGen) : @@ -64,8 +64,8 @@ protected: const cChunkDef::BiomeMap & a_Biomes ); - // cStructureGen override: - virtual void GenStructures(cChunkDesc & a_ChunkDesc) override; + // cFinishGen override: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; @@ -73,7 +73,7 @@ protected: class cStructGenOreNests : - public cStructureGen + public cFinishGen { public: cStructGenOreNests(int a_Seed) : m_Noise(a_Seed), m_Seed(a_Seed) {} @@ -82,8 +82,8 @@ protected: cNoise m_Noise; int m_Seed; - // cStructureGen override: - virtual void GenStructures(cChunkDesc & a_ChunkDesc) override; + // cFinishGen override: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; void GenerateOre(int a_ChunkX, int a_ChunkZ, BLOCKTYPE a_OreType, int a_MaxHeight, int a_NumNests, int a_NestSize, cChunkDef::BlockTypes & a_BlockTypes, int a_Seq); } ; @@ -93,7 +93,7 @@ protected: class cStructGenLakes : - public cStructureGen + public cFinishGen { public: cStructGenLakes(int a_Seed, BLOCKTYPE a_Fluid, cTerrainHeightGen & a_HeiGen, int a_Probability) : @@ -112,8 +112,8 @@ protected: cTerrainHeightGen & m_HeiGen; int m_Probability; ///< Chance, 0 .. 100, of a chunk having the lake - // cStructureGen override: - virtual void GenStructures(cChunkDesc & a_ChunkDesc) override; + // cFinishGen override: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; /// Creates a lake image for the specified chunk into a_Lake void CreateLakeImage(int a_ChunkX, int a_ChunkZ, cBlockArea & a_Lake); @@ -125,7 +125,7 @@ protected: class cStructGenDirectOverhangs : - public cStructureGen + public cFinishGen { public: cStructGenDirectOverhangs(int a_Seed); @@ -134,8 +134,8 @@ protected: cNoise m_Noise1; cNoise m_Noise2; - // cStructureGen override: - virtual void GenStructures(cChunkDesc & a_ChunkDesc) override; + // cFinishGen override: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; bool HasWantedBiome(cChunkDesc & a_ChunkDesc) const; } ; @@ -145,7 +145,7 @@ protected: class cStructGenDistortedMembraneOverhangs : - public cStructureGen + public cFinishGen { public: cStructGenDistortedMembraneOverhangs(int a_Seed); @@ -156,8 +156,8 @@ protected: cNoise m_NoiseZ; cNoise m_NoiseH; - // cStructureGen override: - virtual void GenStructures(cChunkDesc & a_ChunkDesc) override; + // cFinishGen override: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; -- cgit v1.2.3 From 2325a1a162a888e34ed7f80b2e59d3987b034b51 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 1 Mar 2014 20:59:22 +0100 Subject: ChunkDesc warns about StructureGen's deprecation. --- src/Generating/ChunkDesc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp index d9529b4b0..308fbe423 100644 --- a/src/Generating/ChunkDesc.cpp +++ b/src/Generating/ChunkDesc.cpp @@ -209,6 +209,7 @@ bool cChunkDesc::IsUsingDefaultComposition(void) const void cChunkDesc::SetUseDefaultStructures(bool a_bUseDefaultStructures) { + LOGWARNING("%s: Structures are no longer accounted for, use Finishers instead", __FUNCTION__); m_bUseDefaultStructures = a_bUseDefaultStructures; } @@ -218,6 +219,7 @@ void cChunkDesc::SetUseDefaultStructures(bool a_bUseDefaultStructures) bool cChunkDesc::IsUsingDefaultStructures(void) const { + LOGWARNING("%s: Structures are no longer accounted for, use Finishers instead", __FUNCTION__); return m_bUseDefaultStructures; } -- cgit v1.2.3 From 2998228e85bb535ea49f3ef0d7314274a72dd9b9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 2 Mar 2014 08:22:27 +0100 Subject: Added more documentation for FastNBT parser. --- src/WorldStorage/FastNBT.h | 48 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h index d68ebd54c..01a9ad274 100644 --- a/src/WorldStorage/FastNBT.h +++ b/src/WorldStorage/FastNBT.h @@ -106,6 +106,10 @@ public: /** Parses and contains the parsed data Also implements data accessor functions for tree traversal and value getters The data pointer passed in the constructor is assumed to be valid throughout the object's life. Care must be taken not to initialize from a temporary. +The parser decomposes the input data into a tree of tags that is stored as an array of cFastNBTTag items, +and accessing the tree is done by using the array indices for tags. Each tag stores the indices for its parent, +first child, last child, prev sibling and next sibling, a value of -1 indicates that the indice is not valid. +Each primitive tag also stores the length of the contained data, in bytes. */ class cParsedNBT { @@ -114,13 +118,32 @@ public: bool IsValid(void) const {return m_IsValid; } + /** Returns the root tag of the hierarchy. */ int GetRoot(void) const {return 0; } + + /** Returns the first child of the specified tag, or -1 if none / not applicable. */ int GetFirstChild (int a_Tag) const { return m_Tags[a_Tag].m_FirstChild; } + + /** Returns the last child of the specified tag, or -1 if none / not applicable. */ int GetLastChild (int a_Tag) const { return m_Tags[a_Tag].m_LastChild; } + + /** Returns the next sibling of the specified tag, or -1 if none. */ int GetNextSibling(int a_Tag) const { return m_Tags[a_Tag].m_NextSibling; } + + /** Returns the previous sibling of the specified tag, or -1 if none. */ int GetPrevSibling(int a_Tag) const { return m_Tags[a_Tag].m_PrevSibling; } - int GetDataLength (int a_Tag) const { return m_Tags[a_Tag].m_DataLength; } + + /** Returns the length of the tag's data, in bytes. + Not valid for Compound or List tags! */ + int GetDataLength (int a_Tag) const + { + ASSERT(m_Tags[a_Tag].m_Type != TAG_List); + ASSERT(m_Tags[a_Tag].m_Type != TAG_Compound); + return m_Tags[a_Tag].m_DataLength; + } + /** Returns the data stored in this tag. + Not valid for Compound or List tags! */ const char * GetData(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type != TAG_List); @@ -128,47 +151,56 @@ public: return m_Data + m_Tags[a_Tag].m_DataStart; } + /** Returns the direct child tag of the specified name, or -1 if no such tag. */ int FindChildByName(int a_Tag, const AString & a_Name) const { return FindChildByName(a_Tag, a_Name.c_str(), a_Name.length()); } + /** Returns the direct child tag of the specified name, or -1 if no such tag. */ int FindChildByName(int a_Tag, const char * a_Name, size_t a_NameLength = 0) const; - int FindTagByPath (int a_Tag, const AString & a_Path) const; + + /** Returns the child tag of the specified path (Name1\Name2\Name3...), or -1 if no such tag. */ + int FindTagByPath(int a_Tag, const AString & a_Path) const; eTagType GetType(int a_Tag) const { return m_Tags[a_Tag].m_Type; } - /// Returns the children type for a list tag; undefined on other tags. If list empty, returns TAG_End + /** Returns the children type for a List tag; undefined on other tags. If list empty, returns TAG_End. */ eTagType GetChildrenType(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type == TAG_List); return (m_Tags[a_Tag].m_FirstChild < 0) ? TAG_End : m_Tags[m_Tags[a_Tag].m_FirstChild].m_Type; } + /** Returns the value stored in a Byte tag. Not valid for any other tag type. */ inline unsigned char GetByte(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type == TAG_Byte); return (unsigned char)(m_Data[m_Tags[a_Tag].m_DataStart]); } + /** Returns the value stored in a Short tag. Not valid for any other tag type. */ inline Int16 GetShort(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type == TAG_Short); return GetBEShort(m_Data + m_Tags[a_Tag].m_DataStart); } + /** Returns the value stored in an Int tag. Not valid for any other tag type. */ inline Int32 GetInt(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type == TAG_Int); return GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); } + /** Returns the value stored in a Long tag. Not valid for any other tag type. */ inline Int64 GetLong(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type == TAG_Long); return NetworkToHostLong8(m_Data + m_Tags[a_Tag].m_DataStart); } + /** Returns the value stored in a Float tag. Not valid for any other tag type. */ inline float GetFloat(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type == TAG_Float); @@ -186,12 +218,21 @@ public: return f; } + /** Returns the value stored in a Double tag. Not valid for any other tag type. */ inline double GetDouble(int a_Tag) const { + // Cause a compile-time error if sizeof(double) != 8 + // If your platform produces a compiler error here, you'll need to add code that manually decodes 64-bit doubles + char Check1[9 - sizeof(double)]; // Fails if sizeof(double) > 8 + char Check2[sizeof(double) - 7]; // Fails if sizeof(double) < 8 + UNUSED(Check1); + UNUSED(Check2); + ASSERT(m_Tags[a_Tag].m_Type == TAG_Double); return NetworkToHostDouble8(m_Data + m_Tags[a_Tag].m_DataStart); } + /** Returns the value stored in a String tag. Not valid for any other tag type. */ inline AString GetString(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type == TAG_String); @@ -200,6 +241,7 @@ public: return res; } + /** Returns the tag's name. For tags that are not named, returns an empty string. */ inline AString GetName(int a_Tag) const { AString res; -- cgit v1.2.3 From 3ca56b39bce5ad59625d2ffb5ae730858fed8bcd Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 2 Mar 2014 10:50:24 +0200 Subject: Exported cBlockInfo --- MCServer/Plugins/APIDump/APIDesc.lua | 32 ++++++++++++++++++++++++++++++++ src/Bindings/AllToLua.pkg | 1 + src/BlockInfo.h | 11 ++++++++--- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 4d0113223..695d1a853 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -290,6 +290,38 @@ g_APIDesc = }, -- AdditionalInfo }, -- cBlockArea + cBlockInfo = + { + Desc = [[ + This class is used to query and register block properties. + ]], + Functions = + { + FullyOccupiesVoxel = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block fully occupies its voxel." }, + GetById = { Params = "ID", Return = "{{cBlockInfo}}", Notes = "Returns the {{cBlockInfo}} structure for the block with the specified ID." }, + GetLightValue = { Params = "ID", Return = "number", Notes = "Returns how much light the specified block emits on its own." }, + GetSpreadLightFalloff = { Params = "ID", Return = "number", Notes = "Returns how much light the specified block consumes." }, + IsOneHitDig = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block will be destroyed after a single hit." }, + IsPistonBreakable = { Params = "ID", Return = "bool", Notes = "Returns whether a piston can break the specified block." }, + IsSnowable = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block can hold snow atop." }, + IsSolid = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block is solid." }, + IsTransparent = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block is transparent." }, + RequiresSpecialTool = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block requires a special tool to drop." }, + }, + Variables = + { + m_FullyOccupiesVoxel = { Type = "bool", Notes = "Does this block fully occupy its voxel - is it a 'full' block?" }, + m_IsSnowable = { Type = "bool", Notes = "Can this block hold snow atop?" }, + m_IsSolid = { Type = "bool", Notes = "Is this block solid (player cannot walk through)?" }, + m_LightValue = { Type = "number", Notes = "How much light do the blocks emit on their own?" }, + m_OneHitDig = { Type = "bool", Notes = "Is a block destroyed after a single hit?" }, + m_PistonBreakable = { Type = "bool", Notes = "Can a piston break this block?" }, + m_RequiresSpecialTool = { Type = "bool", Notes = "Does this block require a tool to drop?" }, + m_SpreadLightFalloff = { Type = "number", Notes = "How much light do the blocks consume?" }, + m_Transparent = { Type = "bool", Notes = "Is a block completely transparent? (light doesn't get decreased(?))" }, + }, + }, -- cBlockInfo + cChatColor = { Desc = [[ diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 1a2140771..6b067b1e5 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -26,6 +26,7 @@ $cfile "WebPlugin.h" $cfile "LuaWindow.h" $cfile "../BlockID.h" +$cfile "../BlockInfo.h" $cfile "../StringUtils.h" $cfile "../Defines.h" $cfile "../ChatColor.h" diff --git a/src/BlockInfo.h b/src/BlockInfo.h index a06c47a47..57092ca54 100644 --- a/src/BlockInfo.h +++ b/src/BlockInfo.h @@ -5,16 +5,19 @@ - +// tolua_begin class cBlockInfo { public: + // tolua_end cBlockInfo(); /** (Re-)Initializes the internal BlockInfo structures. */ static void Initialize(void); + // tolua_begin + /** Returns the associated BlockInfo structure. */ static cBlockInfo & GetById(unsigned int a_ID); @@ -43,7 +46,7 @@ public: /** Is this block solid (player cannot walk through)? */ bool m_IsSolid; - /** Does this block fully occupy it's voxel - is it a 'full' block? */ + /** Does this block fully occupy its voxel - is it a 'full' block? */ bool m_FullyOccupiesVoxel; @@ -57,6 +60,8 @@ public: inline static bool IsSolid (unsigned int a_ID) { return GetById(a_ID).m_IsSolid; } inline static bool FullyOccupiesVoxel (unsigned int a_ID) { return GetById(a_ID).m_FullyOccupiesVoxel; } + // tolua_end + protected: @@ -64,7 +69,7 @@ protected: static cBlockInfo ms_Info[256]; -}; +}; // tolua_export -- cgit v1.2.3 From 68b75f7b7a2ff09b55526c80f4201c029fae7ce7 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 2 Mar 2014 11:12:29 +0200 Subject: Manually exported g_Block tables --- src/Bindings/DeprecatedBindings.cpp | 434 ++++++++++++++++++++++++++++++++++++ src/Bindings/DeprecatedBindings.h | 8 + src/Bindings/LuaState.cpp | 2 + src/CMakeLists.txt | 1 + 4 files changed, 445 insertions(+) create mode 100644 src/Bindings/DeprecatedBindings.cpp create mode 100644 src/Bindings/DeprecatedBindings.h diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp new file mode 100644 index 000000000..08d775f10 --- /dev/null +++ b/src/Bindings/DeprecatedBindings.cpp @@ -0,0 +1,434 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "DeprecatedBindings.h" +#include "tolua++/include/tolua++.h" + +#include "Plugin.h" +#include "PluginLua.h" +#include "PluginManager.h" +#include "LuaWindow.h" +#include "LuaChunkStay.h" + +#include "../BlockInfo.h" + + + + + +/* get function: g_BlockLightValue */ +#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockLightValue +static int tolua_get_AllToLua_g_BlockLightValue(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + tolua_pushnumber(tolua_S,(lua_Number)cBlockInfo::GetLightValue(tolua_index)); + return 1; +} +#endif //#ifndef TOLUA_DISABLE + +/* set function: g_BlockLightValue */ +#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockLightValue +static int tolua_set_AllToLua_g_BlockLightValue(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + cBlockInfo::GetById(tolua_index).m_LightValue = ((unsigned char) tolua_tonumber(tolua_S,3,0)); + return 0; +} +#endif //#ifndef TOLUA_DISABLE + +/* get function: g_BlockSpreadLightFalloff */ +#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockSpreadLightFalloff +static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + tolua_pushnumber(tolua_S,(lua_Number)cBlockInfo::GetSpreadLightFalloff(tolua_index)); + return 1; +} +#endif //#ifndef TOLUA_DISABLE + +/* set function: g_BlockSpreadLightFalloff */ +#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockSpreadLightFalloff +static int tolua_set_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + cBlockInfo::GetById(tolua_index).m_SpreadLightFalloff = ((unsigned char) tolua_tonumber(tolua_S,3,0)); + return 0; +} +#endif //#ifndef TOLUA_DISABLE + +/* get function: g_BlockTransparent */ +#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockTransparent +static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsTransparent(tolua_index)); + return 1; +} +#endif //#ifndef TOLUA_DISABLE + +/* set function: g_BlockTransparent */ +#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockTransparent +static int tolua_set_AllToLua_g_BlockTransparent(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + cBlockInfo::GetById(tolua_index).m_Transparent = ((bool) tolua_toboolean(tolua_S,3,0)); + return 0; +} +#endif //#ifndef TOLUA_DISABLE + +/* get function: g_BlockOneHitDig */ +#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockOneHitDig +static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsOneHitDig(tolua_index)); + return 1; +} +#endif //#ifndef TOLUA_DISABLE + +/* set function: g_BlockOneHitDig */ +#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockOneHitDig +static int tolua_set_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + cBlockInfo::GetById(tolua_index).m_OneHitDig = ((bool) tolua_toboolean(tolua_S,3,0)); + return 0; +} +#endif //#ifndef TOLUA_DISABLE + +/* get function: g_BlockPistonBreakable */ +#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockPistonBreakable +static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=256) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsPistonBreakable(tolua_index)); + return 1; +} +#endif //#ifndef TOLUA_DISABLE + +/* set function: g_BlockPistonBreakable */ +#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockPistonBreakable +static int tolua_set_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=256) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + cBlockInfo::GetById(tolua_index).m_PistonBreakable = ((bool) tolua_toboolean(tolua_S,3,0)); + return 0; +} +#endif //#ifndef TOLUA_DISABLE + +/* get function: g_BlockIsSnowable */ +#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSnowable +static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=256) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsSnowable(tolua_index)); + return 1; +} +#endif //#ifndef TOLUA_DISABLE + +/* set function: g_BlockIsSnowable */ +#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSnowable +static int tolua_set_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=256) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + cBlockInfo::GetById(tolua_index).m_IsSnowable = ((bool) tolua_toboolean(tolua_S,3,0)); + return 0; +} +#endif //#ifndef TOLUA_DISABLE + +/* get function: g_BlockRequiresSpecialTool */ +#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockRequiresSpecialTool +static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=256) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + tolua_pushboolean(tolua_S,(bool)cBlockInfo::RequiresSpecialTool(tolua_index)); + return 1; +} +#endif //#ifndef TOLUA_DISABLE + +/* set function: g_BlockRequiresSpecialTool */ +#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockRequiresSpecialTool +static int tolua_set_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=256) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + cBlockInfo::GetById(tolua_index).m_RequiresSpecialTool = ((bool) tolua_toboolean(tolua_S,3,0)); + return 0; +} +#endif //#ifndef TOLUA_DISABLE + +/* get function: g_BlockIsSolid */ +#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSolid +static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=256) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsSolid(tolua_index)); + return 1; +} +#endif //#ifndef TOLUA_DISABLE + +/* set function: g_BlockIsSolid */ +#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSolid +static int tolua_set_AllToLua_g_BlockIsSolid(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=256) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + cBlockInfo::GetById(tolua_index).m_IsSolid = ((bool) tolua_toboolean(tolua_S,3,0)); + return 0; +} +#endif //#ifndef TOLUA_DISABLE + +/* get function: g_BlockFullyOccupiesVoxel */ +#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockFullyOccupiesVoxel +static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=256) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + tolua_pushboolean(tolua_S,(bool)cBlockInfo::FullyOccupiesVoxel(tolua_index)); + return 1; +} +#endif //#ifndef TOLUA_DISABLE + +/* set function: g_BlockFullyOccupiesVoxel */ +#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockFullyOccupiesVoxel +static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) +{ + int tolua_index; + #ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } + #endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0); + #ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=256) + tolua_error(tolua_S,"array indexing out of range.",NULL); + #endif + cBlockInfo::GetById(tolua_index).m_FullyOccupiesVoxel = ((bool) tolua_toboolean(tolua_S,3,0)); + return 0; +} +#endif //#ifndef TOLUA_DISABLE + + + + + +void DeprecatedBindings::Bind(lua_State * tolua_S) +{ + tolua_array(tolua_S, "g_BlockLightValue", tolua_get_AllToLua_g_BlockLightValue, tolua_set_AllToLua_g_BlockLightValue); + tolua_array(tolua_S, "g_BlockSpreadLightFalloff", tolua_get_AllToLua_g_BlockSpreadLightFalloff, tolua_set_AllToLua_g_BlockSpreadLightFalloff); + tolua_array(tolua_S, "g_BlockTransparent", tolua_get_AllToLua_g_BlockTransparent, tolua_set_AllToLua_g_BlockTransparent); + tolua_array(tolua_S, "g_BlockOneHitDig", tolua_get_AllToLua_g_BlockOneHitDig, tolua_set_AllToLua_g_BlockOneHitDig); + tolua_array(tolua_S, "g_BlockPistonBreakable", tolua_get_AllToLua_g_BlockPistonBreakable, tolua_set_AllToLua_g_BlockPistonBreakable); + tolua_array(tolua_S, "g_BlockIsSnowable", tolua_get_AllToLua_g_BlockIsSnowable, tolua_set_AllToLua_g_BlockIsSnowable); + tolua_array(tolua_S, "g_BlockRequiresSpecialTool", tolua_get_AllToLua_g_BlockRequiresSpecialTool, tolua_set_AllToLua_g_BlockRequiresSpecialTool); + tolua_array(tolua_S, "g_BlockIsSolid", tolua_get_AllToLua_g_BlockIsSolid, tolua_set_AllToLua_g_BlockIsSolid); + tolua_array(tolua_S, "g_BlockFullyOccupiesVoxel", tolua_get_AllToLua_g_BlockFullyOccupiesVoxel, tolua_set_AllToLua_g_BlockFullyOccupiesVoxel); +} + + + + diff --git a/src/Bindings/DeprecatedBindings.h b/src/Bindings/DeprecatedBindings.h new file mode 100644 index 000000000..5fc3cfa80 --- /dev/null +++ b/src/Bindings/DeprecatedBindings.h @@ -0,0 +1,8 @@ +#pragma once + +struct lua_State; +class DeprecatedBindings +{ +public: + static void Bind( lua_State* tolua_S ); +}; diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 45a066efe..a5540df17 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -14,6 +14,7 @@ extern "C" #include "tolua++/include/tolua++.h" #include "Bindings.h" #include "ManualBindings.h" +#include "DeprecatedBindings.h" // fwd: SQLite/lsqlite3.c extern "C" @@ -95,6 +96,7 @@ void cLuaState::Create(void) luaL_openlibs(m_LuaState); tolua_AllToLua_open(m_LuaState); ManualBindings::Bind(m_LuaState); + DeprecatedBindings::Bind(m_LuaState); luaopen_lsqlite3(m_LuaState); luaopen_lxp(m_LuaState); m_IsOwned = true; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 387556775..5e0731264 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -95,6 +95,7 @@ if (NOT MSVC) #add cpp files here add_library(Bindings Bindings/Bindings + Bindings/DeprecatedBindings Bindings/LuaChunkStay Bindings/LuaState Bindings/LuaWindow -- cgit v1.2.3 From cff4ee11f125efb0b10ffe19d84869b858416584 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 2 Mar 2014 11:30:20 +0200 Subject: Removed g_BlockXXX arrays --- src/Bindings/DeprecatedBindings.cpp | 4 + src/BlockID.cpp | 399 ------------------------------------ src/BlockID.h | 14 -- src/Defines.h | 27 --- 4 files changed, 4 insertions(+), 440 deletions(-) diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp index 08d775f10..3e4940494 100644 --- a/src/Bindings/DeprecatedBindings.cpp +++ b/src/Bindings/DeprecatedBindings.cpp @@ -418,6 +418,8 @@ static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) void DeprecatedBindings::Bind(lua_State * tolua_S) { + tolua_beginmodule(tolua_S, NULL); + tolua_array(tolua_S, "g_BlockLightValue", tolua_get_AllToLua_g_BlockLightValue, tolua_set_AllToLua_g_BlockLightValue); tolua_array(tolua_S, "g_BlockSpreadLightFalloff", tolua_get_AllToLua_g_BlockSpreadLightFalloff, tolua_set_AllToLua_g_BlockSpreadLightFalloff); tolua_array(tolua_S, "g_BlockTransparent", tolua_get_AllToLua_g_BlockTransparent, tolua_set_AllToLua_g_BlockTransparent); @@ -427,6 +429,8 @@ void DeprecatedBindings::Bind(lua_State * tolua_S) tolua_array(tolua_S, "g_BlockRequiresSpecialTool", tolua_get_AllToLua_g_BlockRequiresSpecialTool, tolua_set_AllToLua_g_BlockRequiresSpecialTool); tolua_array(tolua_S, "g_BlockIsSolid", tolua_get_AllToLua_g_BlockIsSolid, tolua_set_AllToLua_g_BlockIsSolid); tolua_array(tolua_S, "g_BlockFullyOccupiesVoxel", tolua_get_AllToLua_g_BlockFullyOccupiesVoxel, tolua_set_AllToLua_g_BlockFullyOccupiesVoxel); + + tolua_endmodule(tolua_S); } diff --git a/src/BlockID.cpp b/src/BlockID.cpp index ff1c54e3f..79e122032 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -12,20 +12,6 @@ -NIBBLETYPE g_BlockLightValue[256]; -NIBBLETYPE g_BlockSpreadLightFalloff[256]; -bool g_BlockTransparent[256]; -bool g_BlockOneHitDig[256]; -bool g_BlockPistonBreakable[256]; -bool g_BlockIsSnowable[256]; -bool g_BlockRequiresSpecialTool[256]; -bool g_BlockIsSolid[256]; -bool g_BlockFullyOccupiesVoxel[256]; - - - - - class cBlockIDMap { // Making the map case-insensitive: @@ -481,389 +467,4 @@ cItem GetIniItemSet(cIniFile & a_IniFile, const char * a_Section, const char * a -// This is actually just some code that needs to run at program startup, so it is wrapped into a global var's constructor: -class cBlockPropertiesInitializer -{ -public: - cBlockPropertiesInitializer(void) - { - memset(g_BlockLightValue, 0x00, sizeof(g_BlockLightValue)); - memset(g_BlockSpreadLightFalloff, 0x0f, sizeof(g_BlockSpreadLightFalloff)); // 0x0f means total falloff - memset(g_BlockTransparent, 0x00, sizeof(g_BlockTransparent)); - memset(g_BlockOneHitDig, 0x00, sizeof(g_BlockOneHitDig)); - memset(g_BlockPistonBreakable, 0x00, sizeof(g_BlockPistonBreakable)); - memset(g_BlockFullyOccupiesVoxel, 0x00, sizeof(g_BlockFullyOccupiesVoxel)); - - // Setting bools to true must be done manually, see http://forum.mc-server.org/showthread.php?tid=629&pid=5415#pid5415 - for (size_t i = 0; i < ARRAYCOUNT(g_BlockIsSnowable); i++) - { - g_BlockIsSnowable[i] = true; - } - memset(g_BlockRequiresSpecialTool, 0x00, sizeof(g_BlockRequiresSpecialTool)); // Set all blocks to false - - // Setting bools to true must be done manually, see http://forum.mc-server.org/showthread.php?tid=629&pid=5415#pid5415 - for (size_t i = 0; i < ARRAYCOUNT(g_BlockIsSolid); i++) - { - g_BlockIsSolid[i] = true; - } - - // Emissive blocks - g_BlockLightValue[E_BLOCK_FIRE] = 15; - g_BlockLightValue[E_BLOCK_GLOWSTONE] = 15; - g_BlockLightValue[E_BLOCK_JACK_O_LANTERN] = 15; - g_BlockLightValue[E_BLOCK_LAVA] = 15; - g_BlockLightValue[E_BLOCK_STATIONARY_LAVA] = 15; - g_BlockLightValue[E_BLOCK_END_PORTAL] = 15; - g_BlockLightValue[E_BLOCK_REDSTONE_LAMP_ON] = 15; - g_BlockLightValue[E_BLOCK_TORCH] = 14; - g_BlockLightValue[E_BLOCK_BURNING_FURNACE] = 13; - g_BlockLightValue[E_BLOCK_NETHER_PORTAL] = 11; - g_BlockLightValue[E_BLOCK_REDSTONE_ORE_GLOWING] = 9; - g_BlockLightValue[E_BLOCK_REDSTONE_REPEATER_ON] = 9; - g_BlockLightValue[E_BLOCK_REDSTONE_TORCH_ON] = 7; - g_BlockLightValue[E_BLOCK_BREWING_STAND] = 1; - g_BlockLightValue[E_BLOCK_BROWN_MUSHROOM] = 1; - g_BlockLightValue[E_BLOCK_DRAGON_EGG] = 1; - - // Spread blocks - g_BlockSpreadLightFalloff[E_BLOCK_AIR] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_CAKE] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_CHEST] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_COBWEB] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_CROPS] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_FENCE] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_FENCE_GATE] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_FIRE] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_GLASS] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_GLASS_PANE] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_GLOWSTONE] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_IRON_BARS] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_IRON_DOOR] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_LEAVES] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_SIGN_POST] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_TORCH] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_VINES] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_WALLSIGN] = 1; - g_BlockSpreadLightFalloff[E_BLOCK_WOODEN_DOOR] = 1; - - // Light in water and lava dissapears faster: - g_BlockSpreadLightFalloff[E_BLOCK_LAVA] = 3; - g_BlockSpreadLightFalloff[E_BLOCK_STATIONARY_LAVA] = 3; - g_BlockSpreadLightFalloff[E_BLOCK_STATIONARY_WATER] = 3; - g_BlockSpreadLightFalloff[E_BLOCK_WATER] = 3; - - // Transparent blocks - g_BlockTransparent[E_BLOCK_ACTIVATOR_RAIL] = true; - g_BlockTransparent[E_BLOCK_AIR] = true; - g_BlockTransparent[E_BLOCK_BIG_FLOWER] = true; - g_BlockTransparent[E_BLOCK_BROWN_MUSHROOM] = true; - g_BlockTransparent[E_BLOCK_CARROTS] = true; - g_BlockTransparent[E_BLOCK_CHEST] = true; - g_BlockTransparent[E_BLOCK_COBWEB] = true; - g_BlockTransparent[E_BLOCK_CROPS] = true; - g_BlockTransparent[E_BLOCK_DANDELION] = true; - g_BlockTransparent[E_BLOCK_DETECTOR_RAIL] = true; - g_BlockTransparent[E_BLOCK_ENDER_CHEST] = true; - g_BlockTransparent[E_BLOCK_FENCE] = true; - g_BlockTransparent[E_BLOCK_FENCE_GATE] = true; - g_BlockTransparent[E_BLOCK_FIRE] = true; - g_BlockTransparent[E_BLOCK_FLOWER] = true; - g_BlockTransparent[E_BLOCK_FLOWER_POT] = true; - g_BlockTransparent[E_BLOCK_GLASS] = true; - g_BlockTransparent[E_BLOCK_GLASS_PANE] = true; - g_BlockTransparent[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE] = true; - g_BlockTransparent[E_BLOCK_ICE] = true; - g_BlockTransparent[E_BLOCK_IRON_DOOR] = true; - g_BlockTransparent[E_BLOCK_LAVA] = true; - g_BlockTransparent[E_BLOCK_LEAVES] = true; - g_BlockTransparent[E_BLOCK_LEVER] = true; - g_BlockTransparent[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE] = true; - g_BlockTransparent[E_BLOCK_MELON_STEM] = true; - g_BlockTransparent[E_BLOCK_NETHER_BRICK_FENCE] = true; - g_BlockTransparent[E_BLOCK_NEW_LEAVES] = true; - g_BlockTransparent[E_BLOCK_POTATOES] = true; - g_BlockTransparent[E_BLOCK_POWERED_RAIL] = true; - g_BlockTransparent[E_BLOCK_PISTON_EXTENSION] = true; - g_BlockTransparent[E_BLOCK_PUMPKIN_STEM] = true; - g_BlockTransparent[E_BLOCK_RAIL] = true; - g_BlockTransparent[E_BLOCK_RED_MUSHROOM] = true; - g_BlockTransparent[E_BLOCK_SIGN_POST] = true; - g_BlockTransparent[E_BLOCK_SNOW] = true; - g_BlockTransparent[E_BLOCK_STAINED_GLASS] = true; - g_BlockTransparent[E_BLOCK_STAINED_GLASS_PANE] = true; - g_BlockTransparent[E_BLOCK_STATIONARY_LAVA] = true; - g_BlockTransparent[E_BLOCK_STATIONARY_WATER] = true; - g_BlockTransparent[E_BLOCK_STONE_BUTTON] = true; - g_BlockTransparent[E_BLOCK_STONE_PRESSURE_PLATE] = true; - g_BlockTransparent[E_BLOCK_TALL_GRASS] = true; - g_BlockTransparent[E_BLOCK_TORCH] = true; - g_BlockTransparent[E_BLOCK_VINES] = true; - g_BlockTransparent[E_BLOCK_WALLSIGN] = true; - g_BlockTransparent[E_BLOCK_WATER] = true; - g_BlockTransparent[E_BLOCK_WOODEN_BUTTON] = true; - g_BlockTransparent[E_BLOCK_WOODEN_DOOR] = true; - g_BlockTransparent[E_BLOCK_WOODEN_PRESSURE_PLATE] = true; - - // TODO: Any other transparent blocks? - - // One hit break blocks: - g_BlockOneHitDig[E_BLOCK_ACTIVE_COMPARATOR] = true; - g_BlockOneHitDig[E_BLOCK_BIG_FLOWER] = true; - g_BlockOneHitDig[E_BLOCK_BROWN_MUSHROOM] = true; - g_BlockOneHitDig[E_BLOCK_CARROTS] = true; - g_BlockOneHitDig[E_BLOCK_CROPS] = true; - g_BlockOneHitDig[E_BLOCK_DANDELION] = true; - g_BlockOneHitDig[E_BLOCK_FIRE] = true; - g_BlockOneHitDig[E_BLOCK_FLOWER] = true; - g_BlockOneHitDig[E_BLOCK_FLOWER_POT] = true; - g_BlockOneHitDig[E_BLOCK_INACTIVE_COMPARATOR] = true; - g_BlockOneHitDig[E_BLOCK_MELON_STEM] = true; - g_BlockOneHitDig[E_BLOCK_POTATOES] = true; - g_BlockOneHitDig[E_BLOCK_PUMPKIN_STEM] = true; - g_BlockOneHitDig[E_BLOCK_REDSTONE_REPEATER_OFF] = true; - g_BlockOneHitDig[E_BLOCK_REDSTONE_REPEATER_ON] = true; - g_BlockOneHitDig[E_BLOCK_REDSTONE_TORCH_OFF] = true; - g_BlockOneHitDig[E_BLOCK_REDSTONE_TORCH_ON] = true; - g_BlockOneHitDig[E_BLOCK_REDSTONE_WIRE] = true; - g_BlockOneHitDig[E_BLOCK_RED_MUSHROOM] = true; - g_BlockOneHitDig[E_BLOCK_REEDS] = true; - g_BlockOneHitDig[E_BLOCK_SAPLING] = true; - g_BlockOneHitDig[E_BLOCK_TNT] = true; - g_BlockOneHitDig[E_BLOCK_TALL_GRASS] = true; - g_BlockOneHitDig[E_BLOCK_TORCH] = true; - - // Blocks that break when pushed by piston: - g_BlockPistonBreakable[E_BLOCK_ACTIVE_COMPARATOR] = true; - g_BlockPistonBreakable[E_BLOCK_AIR] = true; - g_BlockPistonBreakable[E_BLOCK_BED] = true; - g_BlockPistonBreakable[E_BLOCK_BIG_FLOWER] = true; - g_BlockPistonBreakable[E_BLOCK_BROWN_MUSHROOM] = true; - g_BlockPistonBreakable[E_BLOCK_COBWEB] = true; - g_BlockPistonBreakable[E_BLOCK_CROPS] = true; - g_BlockPistonBreakable[E_BLOCK_DANDELION] = true; - g_BlockPistonBreakable[E_BLOCK_DEAD_BUSH] = true; - g_BlockPistonBreakable[E_BLOCK_FIRE] = true; - g_BlockPistonBreakable[E_BLOCK_FLOWER] = true; - g_BlockPistonBreakable[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE] = true; - g_BlockPistonBreakable[E_BLOCK_INACTIVE_COMPARATOR] = true; - g_BlockPistonBreakable[E_BLOCK_IRON_DOOR] = true; - g_BlockPistonBreakable[E_BLOCK_JACK_O_LANTERN] = true; - g_BlockPistonBreakable[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE] = true; - g_BlockPistonBreakable[E_BLOCK_LADDER] = true; - g_BlockPistonBreakable[E_BLOCK_LAVA] = true; - g_BlockPistonBreakable[E_BLOCK_LEVER] = true; - g_BlockPistonBreakable[E_BLOCK_MELON] = true; - g_BlockPistonBreakable[E_BLOCK_MELON_STEM] = true; - g_BlockPistonBreakable[E_BLOCK_PUMPKIN] = true; - g_BlockPistonBreakable[E_BLOCK_PUMPKIN_STEM] = true; - g_BlockPistonBreakable[E_BLOCK_REDSTONE_REPEATER_OFF] = true; - g_BlockPistonBreakable[E_BLOCK_REDSTONE_REPEATER_ON] = true; - g_BlockPistonBreakable[E_BLOCK_REDSTONE_TORCH_OFF] = true; - g_BlockPistonBreakable[E_BLOCK_REDSTONE_TORCH_ON] = true; - g_BlockPistonBreakable[E_BLOCK_REDSTONE_WIRE] = true; - g_BlockPistonBreakable[E_BLOCK_RED_MUSHROOM] = true; - g_BlockPistonBreakable[E_BLOCK_REEDS] = true; - g_BlockPistonBreakable[E_BLOCK_SNOW] = true; - g_BlockPistonBreakable[E_BLOCK_STATIONARY_LAVA] = true; - g_BlockPistonBreakable[E_BLOCK_STATIONARY_WATER] = true; - g_BlockPistonBreakable[E_BLOCK_STONE_BUTTON] = true; - g_BlockPistonBreakable[E_BLOCK_STONE_PRESSURE_PLATE] = true; - g_BlockPistonBreakable[E_BLOCK_TALL_GRASS] = true; - g_BlockPistonBreakable[E_BLOCK_TORCH] = true; - g_BlockPistonBreakable[E_BLOCK_VINES] = true; - g_BlockPistonBreakable[E_BLOCK_WATER] = true; - g_BlockPistonBreakable[E_BLOCK_WOODEN_BUTTON] = true; - g_BlockPistonBreakable[E_BLOCK_WOODEN_DOOR] = true; - g_BlockPistonBreakable[E_BLOCK_WOODEN_PRESSURE_PLATE] = true; - - - // Blocks that cannot be snowed over: - g_BlockIsSnowable[E_BLOCK_ACTIVE_COMPARATOR] = false; - g_BlockIsSnowable[E_BLOCK_AIR] = false; - g_BlockIsSnowable[E_BLOCK_BIG_FLOWER] = false; - g_BlockIsSnowable[E_BLOCK_BROWN_MUSHROOM] = false; - g_BlockIsSnowable[E_BLOCK_CACTUS] = false; - g_BlockIsSnowable[E_BLOCK_CHEST] = false; - g_BlockIsSnowable[E_BLOCK_CROPS] = false; - g_BlockIsSnowable[E_BLOCK_DANDELION] = false; - g_BlockIsSnowable[E_BLOCK_FIRE] = false; - g_BlockIsSnowable[E_BLOCK_FLOWER] = false; - g_BlockIsSnowable[E_BLOCK_GLASS] = false; - g_BlockIsSnowable[E_BLOCK_ICE] = false; - g_BlockIsSnowable[E_BLOCK_INACTIVE_COMPARATOR] = false; - g_BlockIsSnowable[E_BLOCK_LAVA] = false; - g_BlockIsSnowable[E_BLOCK_LILY_PAD] = false; - g_BlockIsSnowable[E_BLOCK_REDSTONE_REPEATER_OFF] = false; - g_BlockIsSnowable[E_BLOCK_REDSTONE_REPEATER_ON] = false; - g_BlockIsSnowable[E_BLOCK_REDSTONE_TORCH_OFF] = false; - g_BlockIsSnowable[E_BLOCK_REDSTONE_TORCH_ON] = false; - g_BlockIsSnowable[E_BLOCK_REDSTONE_WIRE] = false; - g_BlockIsSnowable[E_BLOCK_RED_MUSHROOM] = false; - g_BlockIsSnowable[E_BLOCK_REEDS] = false; - g_BlockIsSnowable[E_BLOCK_SAPLING] = false; - g_BlockIsSnowable[E_BLOCK_SIGN_POST] = false; - g_BlockIsSnowable[E_BLOCK_SNOW] = false; - g_BlockIsSnowable[E_BLOCK_STAINED_GLASS] = false; - g_BlockIsSnowable[E_BLOCK_STAINED_GLASS_PANE] = false; - g_BlockIsSnowable[E_BLOCK_STATIONARY_LAVA] = false; - g_BlockIsSnowable[E_BLOCK_STATIONARY_WATER] = false; - g_BlockIsSnowable[E_BLOCK_TALL_GRASS] = false; - g_BlockIsSnowable[E_BLOCK_TNT] = false; - g_BlockIsSnowable[E_BLOCK_TORCH] = false; - g_BlockIsSnowable[E_BLOCK_VINES] = false; - g_BlockIsSnowable[E_BLOCK_WALLSIGN] = false; - g_BlockIsSnowable[E_BLOCK_WATER] = false; - - - // Blocks that don't drop without a special tool: - g_BlockRequiresSpecialTool[E_BLOCK_BRICK] = true; - g_BlockRequiresSpecialTool[E_BLOCK_CAULDRON] = true; - g_BlockRequiresSpecialTool[E_BLOCK_COAL_ORE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_COBBLESTONE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_COBBLESTONE_STAIRS] = true; - g_BlockRequiresSpecialTool[E_BLOCK_COBWEB] = true; - g_BlockRequiresSpecialTool[E_BLOCK_DIAMOND_BLOCK] = true; - g_BlockRequiresSpecialTool[E_BLOCK_DIAMOND_ORE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_DOUBLE_STONE_SLAB] = true; - g_BlockRequiresSpecialTool[E_BLOCK_EMERALD_ORE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_END_STONE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_GOLD_BLOCK] = true; - g_BlockRequiresSpecialTool[E_BLOCK_GOLD_ORE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_IRON_BLOCK] = true; - g_BlockRequiresSpecialTool[E_BLOCK_IRON_ORE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_LAPIS_BLOCK] = true; - g_BlockRequiresSpecialTool[E_BLOCK_LAPIS_ORE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_MOSSY_COBBLESTONE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_NETHERRACK] = true; - g_BlockRequiresSpecialTool[E_BLOCK_NETHER_BRICK] = true; - g_BlockRequiresSpecialTool[E_BLOCK_NETHER_BRICK_STAIRS] = true; - g_BlockRequiresSpecialTool[E_BLOCK_OBSIDIAN] = true; - g_BlockRequiresSpecialTool[E_BLOCK_REDSTONE_ORE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_REDSTONE_ORE_GLOWING] = true; - g_BlockRequiresSpecialTool[E_BLOCK_SANDSTONE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_SANDSTONE_STAIRS] = true; - g_BlockRequiresSpecialTool[E_BLOCK_SNOW] = true; - g_BlockRequiresSpecialTool[E_BLOCK_STONE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_STONE_BRICKS] = true; - g_BlockRequiresSpecialTool[E_BLOCK_STONE_BRICK_STAIRS] = true; - g_BlockRequiresSpecialTool[E_BLOCK_STONE_PRESSURE_PLATE] = true; - g_BlockRequiresSpecialTool[E_BLOCK_STONE_SLAB] = true; - g_BlockRequiresSpecialTool[E_BLOCK_VINES] = true; - - // Nonsolid blocks: - g_BlockIsSolid[E_BLOCK_ACTIVATOR_RAIL] = false; - g_BlockIsSolid[E_BLOCK_AIR] = false; - g_BlockIsSolid[E_BLOCK_BIG_FLOWER] = false; - g_BlockIsSolid[E_BLOCK_BROWN_MUSHROOM] = false; - g_BlockIsSolid[E_BLOCK_CARROTS] = false; - g_BlockIsSolid[E_BLOCK_COBWEB] = false; - g_BlockIsSolid[E_BLOCK_CROPS] = false; - g_BlockIsSolid[E_BLOCK_DANDELION] = false; - g_BlockIsSolid[E_BLOCK_DETECTOR_RAIL] = false; - g_BlockIsSolid[E_BLOCK_END_PORTAL] = false; - g_BlockIsSolid[E_BLOCK_FIRE] = false; - g_BlockIsSolid[E_BLOCK_FLOWER] = false; - g_BlockIsSolid[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE] = false; - g_BlockIsSolid[E_BLOCK_LAVA] = false; - g_BlockIsSolid[E_BLOCK_LEVER] = false; - g_BlockIsSolid[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE] = false; - g_BlockIsSolid[E_BLOCK_MELON_STEM] = false; - g_BlockIsSolid[E_BLOCK_NETHER_PORTAL] = false; - g_BlockIsSolid[E_BLOCK_PISTON_EXTENSION] = false; - g_BlockIsSolid[E_BLOCK_POTATOES] = false; - g_BlockIsSolid[E_BLOCK_POWERED_RAIL] = false; - g_BlockIsSolid[E_BLOCK_RAIL] = false; - g_BlockIsSolid[E_BLOCK_REDSTONE_TORCH_OFF] = false; - g_BlockIsSolid[E_BLOCK_REDSTONE_TORCH_ON] = false; - g_BlockIsSolid[E_BLOCK_REDSTONE_WIRE] = false; - g_BlockIsSolid[E_BLOCK_RED_MUSHROOM] = false; - g_BlockIsSolid[E_BLOCK_REEDS] = false; - g_BlockIsSolid[E_BLOCK_SAPLING] = false; - g_BlockIsSolid[E_BLOCK_SIGN_POST] = false; - g_BlockIsSolid[E_BLOCK_SNOW] = false; - g_BlockIsSolid[E_BLOCK_STATIONARY_LAVA] = false; - g_BlockIsSolid[E_BLOCK_STATIONARY_WATER] = false; - g_BlockIsSolid[E_BLOCK_STONE_BUTTON] = false; - g_BlockIsSolid[E_BLOCK_STONE_PRESSURE_PLATE] = false; - g_BlockIsSolid[E_BLOCK_TALL_GRASS] = false; - g_BlockIsSolid[E_BLOCK_TORCH] = false; - g_BlockIsSolid[E_BLOCK_TRIPWIRE] = false; - g_BlockIsSolid[E_BLOCK_VINES] = false; - g_BlockIsSolid[E_BLOCK_WALLSIGN] = false; - g_BlockIsSolid[E_BLOCK_WATER] = false; - g_BlockIsSolid[E_BLOCK_WOODEN_BUTTON] = false; - g_BlockIsSolid[E_BLOCK_WOODEN_PRESSURE_PLATE] = false; - g_BlockIsSolid[E_BLOCK_WOODEN_SLAB] = false; - - // Torch placeable blocks: - g_BlockFullyOccupiesVoxel[E_BLOCK_NEW_LOG] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_BEDROCK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_BLOCK_OF_COAL] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_BLOCK_OF_REDSTONE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_BOOKCASE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_BRICK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_CLAY] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_COAL_ORE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_COBBLESTONE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_COMMAND_BLOCK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_CRAFTING_TABLE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_DIAMOND_BLOCK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_DIAMOND_ORE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_DIRT] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_DISPENSER] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_DOUBLE_STONE_SLAB] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_DOUBLE_WOODEN_SLAB] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_DROPPER] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_EMERALD_BLOCK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_EMERALD_ORE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_END_STONE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_FURNACE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_GLOWSTONE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_GOLD_BLOCK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_GOLD_ORE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_GRASS] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_GRAVEL] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_HARDENED_CLAY] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_HAY_BALE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_HUGE_BROWN_MUSHROOM] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_HUGE_RED_MUSHROOM] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_IRON_BLOCK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_IRON_ORE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_JACK_O_LANTERN] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_JUKEBOX] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_LAPIS_BLOCK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_LAPIS_ORE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_LOG] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_MELON] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_MOSSY_COBBLESTONE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_MYCELIUM] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_NETHERRACK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_NETHER_BRICK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_NETHER_QUARTZ_ORE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_NOTE_BLOCK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_OBSIDIAN] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_PACKED_ICE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_PLANKS] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_PUMPKIN] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_QUARTZ_BLOCK] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_REDSTONE_LAMP_OFF] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_REDSTONE_LAMP_ON] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_REDSTONE_ORE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_REDSTONE_ORE_GLOWING] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_SANDSTONE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_SAND] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_SILVERFISH_EGG] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_SPONGE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_STAINED_CLAY] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_WOOL] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_STONE] = true; - g_BlockFullyOccupiesVoxel[E_BLOCK_STONE_BRICKS] = true; - } -} BlockPropertiesInitializer; - - - - diff --git a/src/BlockID.h b/src/BlockID.h index 861bb8dae..1c454cd23 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -909,17 +909,3 @@ extern cItem GetIniItemSet(cIniFile & a_IniFile, const char * a_Section, const c -// Block properties: -extern NIBBLETYPE g_BlockLightValue[256]; -extern NIBBLETYPE g_BlockSpreadLightFalloff[256]; -extern bool g_BlockTransparent[256]; -extern bool g_BlockOneHitDig[256]; -extern bool g_BlockPistonBreakable[256]; -extern bool g_BlockIsSnowable[256]; -extern bool g_BlockRequiresSpecialTool[256]; -extern bool g_BlockIsSolid[256]; -extern bool g_BlockFullyOccupiesVoxel[256]; - - - - diff --git a/src/Defines.h b/src/Defines.h index 31d48860f..6d3d28c80 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -17,33 +17,6 @@ typedef std::vector cSlotNums; // tolua_begin -/// How much light do the blocks emit on their own? -extern unsigned char g_BlockLightValue[]; - -/// How much light do the block consume? -extern unsigned char g_BlockSpreadLightFalloff[]; - -/// Is a block completely transparent? (light doesn't get decreased(?)) -extern bool g_BlockTransparent[]; - -/// Is a block destroyed after a single hit? -extern bool g_BlockOneHitDig[]; - -/// Can a piston break this block? -extern bool g_BlockPistonBreakable[256]; - -/// Can this block hold snow atop? -extern bool g_BlockIsSnowable[256]; - -/// Does this block require a tool to drop? -extern bool g_BlockRequiresSpecialTool[256]; - -/// Is this block solid (player cannot walk through)? -extern bool g_BlockIsSolid[256]; - -/// Does this block fully occupy it's voxel - is it a 'full' block? -extern bool g_BlockFullyOccupiesVoxel[256]; - /// Experience Orb setup enum { -- cgit v1.2.3 From f40f2ad9283bd5aa587cd0943adc5f8c7a3b41c1 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 2 Mar 2014 12:59:09 +0200 Subject: APIDump: ID -> Type --- MCServer/Plugins/APIDump/APIDesc.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 695d1a853..ed9c32d32 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -297,16 +297,16 @@ g_APIDesc = ]], Functions = { - FullyOccupiesVoxel = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block fully occupies its voxel." }, - GetById = { Params = "ID", Return = "{{cBlockInfo}}", Notes = "Returns the {{cBlockInfo}} structure for the block with the specified ID." }, - GetLightValue = { Params = "ID", Return = "number", Notes = "Returns how much light the specified block emits on its own." }, - GetSpreadLightFalloff = { Params = "ID", Return = "number", Notes = "Returns how much light the specified block consumes." }, - IsOneHitDig = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block will be destroyed after a single hit." }, - IsPistonBreakable = { Params = "ID", Return = "bool", Notes = "Returns whether a piston can break the specified block." }, - IsSnowable = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block can hold snow atop." }, - IsSolid = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block is solid." }, - IsTransparent = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block is transparent." }, - RequiresSpecialTool = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block requires a special tool to drop." }, + FullyOccupiesVoxel = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block fully occupies its voxel." }, + GetById = { Params = "Type", Return = "{{cBlockInfo}}", Notes = "Returns the {{cBlockInfo}} structure for the specified type." }, + GetLightValue = { Params = "Type", Return = "number", Notes = "Returns how much light the specified block emits on its own." }, + GetSpreadLightFalloff = { Params = "Type", Return = "number", Notes = "Returns how much light the specified block consumes." }, + IsOneHitDig = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block will be destroyed after a single hit." }, + IsPistonBreakable = { Params = "Type", Return = "bool", Notes = "Returns whether a piston can break the specified block." }, + IsSnowable = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block can hold snow atop." }, + IsSolid = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block is solid." }, + IsTransparent = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block is transparent." }, + RequiresSpecialTool = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block requires a special tool to drop." }, }, Variables = { -- cgit v1.2.3 From 8990410f18a03ca553cca0103cd167bac06443cc Mon Sep 17 00:00:00 2001 From: worktycho Date: Sun, 2 Mar 2014 12:02:29 +0000 Subject: Reverted BlockVine --- src/Blocks/BlockVine.h | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index 9e2105f67..b8213f29b 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -1,4 +1,3 @@ - #pragma once #include "BlockHandler.h" @@ -8,11 +7,11 @@ class cBlockVineHandler : - public cMetaRotater + public cBlockHandler { public: cBlockVineHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cBlockHandler(a_BlockType) { } @@ -169,6 +168,31 @@ public: a_World->SetBlock(X, Y - 1, Z, E_BLOCK_VINES, a_World->GetBlockMeta(X, Y, Z)); } } + + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override + { + return ((a_Meta >> 1) | (a_Meta << 3)) & 0x0f; // Rotate bits to the right + } + + + virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override + { + return ((a_Meta << 1) | (a_Meta >> 3)) & 0x0f; // Rotate bits to the left + } + + + virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override + { + // Bits 2 and 4 stay, bits 1 and 3 swap + return ((a_Meta & 0x0a) | ((a_Meta & 0x01) << 2) | ((a_Meta & 0x04) >> 2)); + } + + + virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override + { + // Bits 1 and 3 stay, bits 2 and 4 swap + return ((a_Meta & 0x05) | ((a_Meta & 0x02) << 2) | ((a_Meta & 0x08) >> 2)); + } } ; -- cgit v1.2.3 From 10fdc51b0a9b571b118b257109014e1c29591698 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Sun, 2 Mar 2014 14:35:03 +0100 Subject: Creeper fixes - Fixed explosion time (1.5s, according to minecraftwiki) - Creeper explodes if right clicked with flint and steel --- src/Mobs/Creeper.cpp | 41 ++++++++++++++++++++++++++++++++--------- src/Mobs/Creeper.h | 3 ++- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 40ee20e44..3471b4cf1 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -4,6 +4,7 @@ #include "Creeper.h" #include "../World.h" #include "../Entities/ProjectileEntity.h" +#include "../Entities/Player.h" @@ -13,6 +14,7 @@ cCreeper::cCreeper(void) : super("Creeper", mtCreeper, "mob.creeper.say", "mob.creeper.say", 0.6, 1.8), m_bIsBlowing(false), m_bIsCharged(false), + m_BurnedWithFlintAndSteel(false), m_ExplodingTimer(0) { } @@ -25,12 +27,25 @@ void cCreeper::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - if (!ReachedFinalDestination()) + if (!ReachedFinalDestination() && !m_BurnedWithFlintAndSteel) { m_ExplodingTimer = 0; m_bIsBlowing = false; m_World->BroadcastEntityMetadata(*this); } + else + { + if (m_bIsBlowing) + { + m_ExplodingTimer += 1; + } + + if (m_ExplodingTimer == 30) + { + m_World->DoExplosionAt((m_bIsCharged ? 5 : 3), GetPosX(), GetPosY(), GetPosZ(), false, esMonster, this); + Destroy(); + } + } } @@ -80,22 +95,30 @@ void cCreeper::Attack(float a_Dt) { UNUSED(a_Dt); - m_ExplodingTimer += 1; - if (!m_bIsBlowing) { m_World->BroadcastSoundEffect("game.tnt.primed", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 1.f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); m_bIsBlowing = true; m_World->BroadcastEntityMetadata(*this); } - - if (m_ExplodingTimer == 20) - { - m_World->DoExplosionAt((m_bIsCharged ? 5 : 3), GetPosX(), GetPosY(), GetPosZ(), false, esMonster, this); - Destroy(); - } } + +void cCreeper::OnRightClicked(cPlayer & a_Player) +{ + if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_FLINT_AND_STEEL)) + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.UseEquippedItem(); + } + m_World->BroadcastSoundEffect("game.tnt.primed", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 1.f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_bIsBlowing = true; + m_World->BroadcastEntityMetadata(*this); + m_BurnedWithFlintAndSteel = true; + } +} + diff --git a/src/Mobs/Creeper.h b/src/Mobs/Creeper.h index 0f71e5ad2..9abca369b 100644 --- a/src/Mobs/Creeper.h +++ b/src/Mobs/Creeper.h @@ -21,13 +21,14 @@ public: virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void Attack(float a_Dt) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void OnRightClicked(cPlayer & a_Player) override; bool IsBlowing(void) const {return m_bIsBlowing; } bool IsCharged(void) const {return m_bIsCharged; } private: - bool m_bIsBlowing, m_bIsCharged; + bool m_bIsBlowing, m_bIsCharged, m_BurnedWithFlintAndSteel; int m_ExplodingTimer; } ; -- cgit v1.2.3 From 0c87341631198386c765bc18848fbd93e66c1aab Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 2 Mar 2014 16:24:09 +0200 Subject: GetById => Get --- MCServer/Plugins/APIDump/APIDesc.lua | 20 ++++++++++---------- src/Bindings/DeprecatedBindings.cpp | 18 +++++++++--------- src/BlockInfo.cpp | 6 +++--- src/BlockInfo.h | 20 ++++++++++---------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index ed9c32d32..0b6f33b37 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -297,16 +297,16 @@ g_APIDesc = ]], Functions = { - FullyOccupiesVoxel = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block fully occupies its voxel." }, - GetById = { Params = "Type", Return = "{{cBlockInfo}}", Notes = "Returns the {{cBlockInfo}} structure for the specified type." }, - GetLightValue = { Params = "Type", Return = "number", Notes = "Returns how much light the specified block emits on its own." }, - GetSpreadLightFalloff = { Params = "Type", Return = "number", Notes = "Returns how much light the specified block consumes." }, - IsOneHitDig = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block will be destroyed after a single hit." }, - IsPistonBreakable = { Params = "Type", Return = "bool", Notes = "Returns whether a piston can break the specified block." }, - IsSnowable = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block can hold snow atop." }, - IsSolid = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block is solid." }, - IsTransparent = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block is transparent." }, - RequiresSpecialTool = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block requires a special tool to drop." }, + FullyOccupiesVoxel = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block fully occupies its voxel." }, + Get = { Params = "Type", Return = "{{cBlockInfo}}", Notes = "(STATIC) Returns the {{cBlockInfo}} structure for the specified type." }, + GetLightValue = { Params = "Type", Return = "number", Notes = "(STATIC) Returns how much light the specified block emits on its own." }, + GetSpreadLightFalloff = { Params = "Type", Return = "number", Notes = "(STATIC) Returns how much light the specified block consumes." }, + IsOneHitDig = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block will be destroyed after a single hit." }, + IsPistonBreakable = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether a piston can break the specified block." }, + IsSnowable = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block can hold snow atop." }, + IsSolid = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block is solid." }, + IsTransparent = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block is transparent." }, + RequiresSpecialTool = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block requires a special tool to drop." }, }, Variables = { diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp index 3e4940494..7c0d8dca1 100644 --- a/src/Bindings/DeprecatedBindings.cpp +++ b/src/Bindings/DeprecatedBindings.cpp @@ -55,7 +55,7 @@ static int tolua_set_AllToLua_g_BlockLightValue(lua_State* tolua_S) if (tolua_index<0) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::GetById(tolua_index).m_LightValue = ((unsigned char) tolua_tonumber(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_LightValue = ((unsigned char) tolua_tonumber(tolua_S,3,0)); return 0; } #endif //#ifndef TOLUA_DISABLE @@ -99,7 +99,7 @@ static int tolua_set_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) if (tolua_index<0) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::GetById(tolua_index).m_SpreadLightFalloff = ((unsigned char) tolua_tonumber(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_SpreadLightFalloff = ((unsigned char) tolua_tonumber(tolua_S,3,0)); return 0; } #endif //#ifndef TOLUA_DISABLE @@ -143,7 +143,7 @@ static int tolua_set_AllToLua_g_BlockTransparent(lua_State* tolua_S) if (tolua_index<0) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::GetById(tolua_index).m_Transparent = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_Transparent = ((bool) tolua_toboolean(tolua_S,3,0)); return 0; } #endif //#ifndef TOLUA_DISABLE @@ -187,7 +187,7 @@ static int tolua_set_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) if (tolua_index<0) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::GetById(tolua_index).m_OneHitDig = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_OneHitDig = ((bool) tolua_toboolean(tolua_S,3,0)); return 0; } #endif //#ifndef TOLUA_DISABLE @@ -231,7 +231,7 @@ static int tolua_set_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) if (tolua_index<0 || tolua_index>=256) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::GetById(tolua_index).m_PistonBreakable = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_PistonBreakable = ((bool) tolua_toboolean(tolua_S,3,0)); return 0; } #endif //#ifndef TOLUA_DISABLE @@ -275,7 +275,7 @@ static int tolua_set_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) if (tolua_index<0 || tolua_index>=256) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::GetById(tolua_index).m_IsSnowable = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_IsSnowable = ((bool) tolua_toboolean(tolua_S,3,0)); return 0; } #endif //#ifndef TOLUA_DISABLE @@ -319,7 +319,7 @@ static int tolua_set_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) if (tolua_index<0 || tolua_index>=256) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::GetById(tolua_index).m_RequiresSpecialTool = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_RequiresSpecialTool = ((bool) tolua_toboolean(tolua_S,3,0)); return 0; } #endif //#ifndef TOLUA_DISABLE @@ -363,7 +363,7 @@ static int tolua_set_AllToLua_g_BlockIsSolid(lua_State* tolua_S) if (tolua_index<0 || tolua_index>=256) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::GetById(tolua_index).m_IsSolid = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_IsSolid = ((bool) tolua_toboolean(tolua_S,3,0)); return 0; } #endif //#ifndef TOLUA_DISABLE @@ -407,7 +407,7 @@ static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) if (tolua_index<0 || tolua_index>=256) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::GetById(tolua_index).m_FullyOccupiesVoxel = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_FullyOccupiesVoxel = ((bool) tolua_toboolean(tolua_S,3,0)); return 0; } #endif //#ifndef TOLUA_DISABLE diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index 5fd6d33c1..c73ae18b6 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -29,11 +29,11 @@ cBlockInfo::cBlockInfo() -cBlockInfo & cBlockInfo::GetById(unsigned int a_ID) +cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type) { - ASSERT(a_ID < 256); + ASSERT(a_Type < 256); - return ms_Info[a_ID]; + return ms_Info[a_Type]; } diff --git a/src/BlockInfo.h b/src/BlockInfo.h index 57092ca54..34a845b20 100644 --- a/src/BlockInfo.h +++ b/src/BlockInfo.h @@ -19,7 +19,7 @@ public: // tolua_begin /** Returns the associated BlockInfo structure. */ - static cBlockInfo & GetById(unsigned int a_ID); + static cBlockInfo & Get(BLOCKTYPE a_Type); /** How much light do the blocks emit on their own? */ @@ -50,15 +50,15 @@ public: bool m_FullyOccupiesVoxel; - inline static NIBBLETYPE GetLightValue (unsigned int a_ID) { return GetById(a_ID).m_LightValue; } - inline static NIBBLETYPE GetSpreadLightFalloff(unsigned int a_ID) { return GetById(a_ID).m_SpreadLightFalloff; } - inline static bool IsTransparent (unsigned int a_ID) { return GetById(a_ID).m_Transparent; } - inline static bool IsOneHitDig (unsigned int a_ID) { return GetById(a_ID).m_OneHitDig; } - inline static bool IsPistonBreakable (unsigned int a_ID) { return GetById(a_ID).m_PistonBreakable; } - inline static bool IsSnowable (unsigned int a_ID) { return GetById(a_ID).m_IsSnowable; } - inline static bool RequiresSpecialTool (unsigned int a_ID) { return GetById(a_ID).m_RequiresSpecialTool; } - inline static bool IsSolid (unsigned int a_ID) { return GetById(a_ID).m_IsSolid; } - inline static bool FullyOccupiesVoxel (unsigned int a_ID) { return GetById(a_ID).m_FullyOccupiesVoxel; } + inline static NIBBLETYPE GetLightValue (BLOCKTYPE a_Type) { return Get(a_Type).m_LightValue; } + inline static NIBBLETYPE GetSpreadLightFalloff(BLOCKTYPE a_Type) { return Get(a_Type).m_SpreadLightFalloff; } + inline static bool IsTransparent (BLOCKTYPE a_Type) { return Get(a_Type).m_Transparent; } + inline static bool IsOneHitDig (BLOCKTYPE a_Type) { return Get(a_Type).m_OneHitDig; } + inline static bool IsPistonBreakable (BLOCKTYPE a_Type) { return Get(a_Type).m_PistonBreakable; } + inline static bool IsSnowable (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSnowable; } + inline static bool RequiresSpecialTool (BLOCKTYPE a_Type) { return Get(a_Type).m_RequiresSpecialTool; } + inline static bool IsSolid (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSolid; } + inline static bool FullyOccupiesVoxel (BLOCKTYPE a_Type) { return Get(a_Type).m_FullyOccupiesVoxel; } // tolua_end -- cgit v1.2.3 From e4b2502896febbbf1d53fee1970e973bc6afde04 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 2 Mar 2014 16:01:37 +0100 Subject: Add Trapdoor Functions to cWorld and fix Trapdoor Redstone Bugs --- src/Blocks/BlockTrapdoor.h | 4 ++- src/Simulator/IncrementalRedstoneSimulator.cpp | 8 +++--- src/World.cpp | 37 ++++++++++++++++++++++++++ src/World.h | 6 +++++ 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 08fc28327..251044afd 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -36,8 +36,10 @@ public: { // Flip the ON bit on/off using the XOR bitwise operation NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x04); - a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); + + cWorld * World = (cWorld *) &a_WorldInterface; + World->BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0, a_Player->GetClientHandle()); } virtual bool GetPlacementBlockTypeMeta( diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 91de9e0cc..74b30f920 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -937,17 +937,15 @@ void cIncrementalRedstoneSimulator::HandleTrapdoor(int a_BlockX, int a_BlockY, i { if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x4); - m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); + m_World.SetTrapdoorOpen(a_BlockX, a_BlockY, a_BlockZ, true); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); - } + } } else { if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0xB); // Take into account that the fourth bit is needed for trapdoors too - m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); + m_World.SetTrapdoorOpen(a_BlockX, a_BlockY, a_BlockZ, false); SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); } } diff --git a/src/World.cpp b/src/World.cpp index ffdae2a37..ca72d2e20 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2647,6 +2647,43 @@ bool cWorld::SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, co +bool cWorld::IsTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + if (GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_TRAPDOOR) + { + return false; + } + + NIBBLETYPE Meta = GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + return (Meta & 0x4) > 0; +} + + + + + +bool cWorld::SetTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_Open) +{ + if (GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_TRAPDOOR) + { + return false; + } + + NIBBLETYPE Meta = GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + bool IsOpen = (Meta & 0x4) > 0; + if (a_Open != IsOpen) + { + SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta ^ 0x4); + BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); + return true; + } + return false; +} + + + + + void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) { m_ChunkMap->MarkChunkRegenerating(a_ChunkX, a_ChunkZ); diff --git a/src/World.h b/src/World.h index 4b74f7aba..ec6805dcf 100644 --- a/src/World.h +++ b/src/World.h @@ -342,6 +342,12 @@ public: /** Sets the command block command. Returns true if command changed. */ bool SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command); // tolua_export + /** Is the trapdoor open? */ + bool IsTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export + + /** Set the state of a trapdoor */ + bool SetTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_Open); // tolua_export + /** Regenerate the given chunk: */ void RegenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export -- cgit v1.2.3 From 274d2bcb17791c292a2095af649b1a4c51246d23 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 2 Mar 2014 16:05:39 +0100 Subject: Added blockface mirroring and rotating. --- src/Defines.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/Defines.h b/src/Defines.h index 6d3d28c80..018ecb1d3 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -226,6 +226,56 @@ inline const char * ClickActionToString(eClickAction a_ClickAction) +/** Returns a blockface mirrored around the Y axis (doesn't change up/down). */ +inline eBlockFace MirrorBlockFaceY(eBlockFace a_BlockFace) +{ + switch (a_BlockFace) + { + case BLOCK_FACE_XM: return BLOCK_FACE_XP; + case BLOCK_FACE_XP: return BLOCK_FACE_XM; + case BLOCK_FACE_ZM: return BLOCK_FACE_ZP; + case BLOCK_FACE_ZP: return BLOCK_FACE_ZM; + } + return a_BlockFace; +} + + + + + +/** Returns a blockface rotated around the Y axis counter-clockwise. */ +inline eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace) +{ + switch (a_BlockFace) + { + case BLOCK_FACE_XM: return BLOCK_FACE_ZP; + case BLOCK_FACE_XP: return BLOCK_FACE_ZM; + case BLOCK_FACE_ZM: return BLOCK_FACE_XM; + case BLOCK_FACE_ZP: return BLOCK_FACE_XP; + } + return a_BlockFace; +} + + + + + +inline eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace) +{ + switch (a_BlockFace) + { + case BLOCK_FACE_XM: return BLOCK_FACE_ZM; + case BLOCK_FACE_XP: return BLOCK_FACE_ZP; + case BLOCK_FACE_ZM: return BLOCK_FACE_XP; + case BLOCK_FACE_ZP: return BLOCK_FACE_XM; + } + return a_BlockFace; +} + + + + + inline bool IsValidBlock(int a_BlockType) { if ( -- cgit v1.2.3 From 5e427ee82592bd411a6b7ae0e9f1bd574ff68eb3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 2 Mar 2014 16:16:22 +0100 Subject: More documentation (thanks to madmaxoft) and use GetBlockTypeMeta --- src/World.cpp | 12 ++++++++---- src/World.h | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index ca72d2e20..6c9ea7453 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2649,12 +2649,14 @@ bool cWorld::SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, co bool cWorld::IsTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ) { - if (GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_TRAPDOOR) + BLOCKTYPE Block; + NIBBLETYPE Meta; + GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, Block, Meta); + if (Block != E_BLOCK_TRAPDOOR) { return false; } - NIBBLETYPE Meta = GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); return (Meta & 0x4) > 0; } @@ -2664,12 +2666,14 @@ bool cWorld::IsTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ) bool cWorld::SetTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_Open) { - if (GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_TRAPDOOR) + BLOCKTYPE Block; + NIBBLETYPE Meta; + GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, Block, Meta); + if (Block != E_BLOCK_TRAPDOOR) { return false; } - NIBBLETYPE Meta = GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); bool IsOpen = (Meta & 0x4) > 0; if (a_Open != IsOpen) { diff --git a/src/World.h b/src/World.h index ec6805dcf..25b42888c 100644 --- a/src/World.h +++ b/src/World.h @@ -342,10 +342,10 @@ public: /** Sets the command block command. Returns true if command changed. */ bool SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command); // tolua_export - /** Is the trapdoor open? */ + /** Is the trapdoor open? Returns false if there is no trapdoor at the specified coords. */ bool IsTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export - /** Set the state of a trapdoor */ + /** Set the state of a trapdoor. Returns true if the trapdoor was update, false if there was no trapdoor at those coords. */ bool SetTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_Open); // tolua_export /** Regenerate the given chunk: */ -- cgit v1.2.3 From 7fb354e8f09d16832b1261a5dc9b43d6a8d2fd0e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 2 Mar 2014 16:34:16 +0100 Subject: Fixed MSVC warnings in DeprecatedBindings. --- src/Bindings/DeprecatedBindings.cpp | 84 +++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 8 deletions(-) diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp index 7c0d8dca1..408b1b84a 100644 --- a/src/Bindings/DeprecatedBindings.cpp +++ b/src/Bindings/DeprecatedBindings.cpp @@ -38,6 +38,10 @@ static int tolua_get_AllToLua_g_BlockLightValue(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE + + + + /* set function: g_BlockLightValue */ #ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockLightValue static int tolua_set_AllToLua_g_BlockLightValue(lua_State* tolua_S) @@ -60,6 +64,10 @@ static int tolua_set_AllToLua_g_BlockLightValue(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE + + + + /* get function: g_BlockSpreadLightFalloff */ #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockSpreadLightFalloff static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) @@ -82,6 +90,10 @@ static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE + + + + /* set function: g_BlockSpreadLightFalloff */ #ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockSpreadLightFalloff static int tolua_set_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) @@ -104,6 +116,10 @@ static int tolua_set_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE + + + + /* get function: g_BlockTransparent */ #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockTransparent static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S) @@ -121,11 +137,15 @@ static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S) if (tolua_index<0) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsTransparent(tolua_index)); + tolua_pushboolean(tolua_S, cBlockInfo::IsTransparent(tolua_index)); return 1; } #endif //#ifndef TOLUA_DISABLE + + + + /* set function: g_BlockTransparent */ #ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockTransparent static int tolua_set_AllToLua_g_BlockTransparent(lua_State* tolua_S) @@ -143,11 +163,15 @@ static int tolua_set_AllToLua_g_BlockTransparent(lua_State* tolua_S) if (tolua_index<0) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::Get(tolua_index).m_Transparent = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_Transparent = (tolua_toboolean(tolua_S,3,0) != 0); return 0; } #endif //#ifndef TOLUA_DISABLE + + + + /* get function: g_BlockOneHitDig */ #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockOneHitDig static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) @@ -170,6 +194,10 @@ static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE + + + + /* set function: g_BlockOneHitDig */ #ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockOneHitDig static int tolua_set_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) @@ -187,11 +215,15 @@ static int tolua_set_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) if (tolua_index<0) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::Get(tolua_index).m_OneHitDig = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_OneHitDig = (tolua_toboolean(tolua_S,3,0) != 0); return 0; } #endif //#ifndef TOLUA_DISABLE + + + + /* get function: g_BlockPistonBreakable */ #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockPistonBreakable static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) @@ -214,6 +246,10 @@ static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE + + + + /* set function: g_BlockPistonBreakable */ #ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockPistonBreakable static int tolua_set_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) @@ -231,11 +267,15 @@ static int tolua_set_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) if (tolua_index<0 || tolua_index>=256) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::Get(tolua_index).m_PistonBreakable = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_PistonBreakable = (tolua_toboolean(tolua_S,3,0) != 0); return 0; } #endif //#ifndef TOLUA_DISABLE + + + + /* get function: g_BlockIsSnowable */ #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSnowable static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) @@ -258,6 +298,10 @@ static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE + + + + /* set function: g_BlockIsSnowable */ #ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSnowable static int tolua_set_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) @@ -275,11 +319,15 @@ static int tolua_set_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) if (tolua_index<0 || tolua_index>=256) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::Get(tolua_index).m_IsSnowable = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_IsSnowable = (tolua_toboolean(tolua_S,3,0) != 0); return 0; } #endif //#ifndef TOLUA_DISABLE + + + + /* get function: g_BlockRequiresSpecialTool */ #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockRequiresSpecialTool static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) @@ -302,6 +350,10 @@ static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE + + + + /* set function: g_BlockRequiresSpecialTool */ #ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockRequiresSpecialTool static int tolua_set_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) @@ -319,11 +371,15 @@ static int tolua_set_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) if (tolua_index<0 || tolua_index>=256) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::Get(tolua_index).m_RequiresSpecialTool = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_RequiresSpecialTool = (tolua_toboolean(tolua_S,3,0) != 0); return 0; } #endif //#ifndef TOLUA_DISABLE + + + + /* get function: g_BlockIsSolid */ #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSolid static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S) @@ -346,6 +402,10 @@ static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE + + + + /* set function: g_BlockIsSolid */ #ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSolid static int tolua_set_AllToLua_g_BlockIsSolid(lua_State* tolua_S) @@ -363,11 +423,15 @@ static int tolua_set_AllToLua_g_BlockIsSolid(lua_State* tolua_S) if (tolua_index<0 || tolua_index>=256) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::Get(tolua_index).m_IsSolid = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_IsSolid = (tolua_toboolean(tolua_S,3,0) != 0); return 0; } #endif //#ifndef TOLUA_DISABLE + + + + /* get function: g_BlockFullyOccupiesVoxel */ #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockFullyOccupiesVoxel static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) @@ -390,6 +454,10 @@ static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE + + + + /* set function: g_BlockFullyOccupiesVoxel */ #ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockFullyOccupiesVoxel static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) @@ -407,7 +475,7 @@ static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) if (tolua_index<0 || tolua_index>=256) tolua_error(tolua_S,"array indexing out of range.",NULL); #endif - cBlockInfo::Get(tolua_index).m_FullyOccupiesVoxel = ((bool) tolua_toboolean(tolua_S,3,0)); + cBlockInfo::Get(tolua_index).m_FullyOccupiesVoxel = (tolua_toboolean(tolua_S,3,0) != 0); return 0; } #endif //#ifndef TOLUA_DISABLE -- cgit v1.2.3 From 0c8d08cb0962640bb3688f80ff782245daa2747c Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 2 Mar 2014 16:48:55 +0100 Subject: Simplified and more clearer infodump for Github. --- MCServer/Plugins/InfoDump.lua | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index e7ed157e3..ede4c0e8b 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -317,26 +317,19 @@ local function WriteCommandsCategoryGithub(a_Category, f) if (CategoryName == "") then CategoryName = "General"; end - f:write("\n## ", GithubizeString(a_Category.DisplayName or CategoryName), "\n"); + f:write("\n### ", GithubizeString(a_Category.DisplayName or CategoryName), "\n"); -- Write description: if (a_Category.Description ~= "") then - f:write(GithubizeString(a_Category.Description), "\n"); + f:write(GithubizeString(a_Category.Description), "\n\n"); end + f:write("| Command | Permission | Discription | \n") + f:write("| ------- | ---------- | ----------- | \n") + -- Write commands: - f:write("\n"); for idx2, cmd in ipairs(a_Category.Commands) do - f:write("\n### ", cmd.CommandString, "\n", GithubizeString(cmd.Info.HelpString or "UNDOCUMENTED"), "\n\n"); - if (cmd.Info.Permission ~= nil) then - f:write("Permission required: **", cmd.Info.Permission, "**\n\n"); - end - if (cmd.Info.DetailedDescription ~= nil) then - f:write(GithubizeString(cmd.Info.DetailedDescription)); - end - if (cmd.Info.ParameterCombinations ~= nil) then - WriteCommandParameterCombinationsGithub(cmd.CommandString, cmd.Info.ParameterCombinations, f); - end + f:write("|", cmd.CommandString, " | ", cmd.Info.Permission or "", " | ", GithubizeString(cmd.Info.HelpString or "UNDOCUMENTED"), "| \n") end f:write("\n\n") end @@ -601,7 +594,7 @@ local function DumpPluginInfoGithub(a_PluginFolder, a_PluginInfo) f:write(GithubizeString(a_PluginInfo.Description), "\n"); DumpAdditionalInfoGithub(a_PluginInfo, f); DumpCommandsGithub(a_PluginInfo, f); - DumpPermissionsGithub(a_PluginInfo, f); + --DumpPermissionsGithub(a_PluginInfo, f); -- Seems a little overkill since they are already mentioned in the commands. f:close(); end -- cgit v1.2.3 From 20e377ea7b64f60bd5565b8c97ce26750e0eeb5e Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 2 Mar 2014 16:55:04 +0100 Subject: Fixed typo Discription => Description --- MCServer/Plugins/InfoDump.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index ede4c0e8b..59263d056 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -324,7 +324,7 @@ local function WriteCommandsCategoryGithub(a_Category, f) f:write(GithubizeString(a_Category.Description), "\n\n"); end - f:write("| Command | Permission | Discription | \n") + f:write("| Command | Permission | Description | \n") f:write("| ------- | ---------- | ----------- | \n") -- Write commands: -- cgit v1.2.3 From 070d483236279e69c736e740fa8459d3ac627790 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 2 Mar 2014 21:25:05 +0200 Subject: cBlockInfo now manages the respective cBlockHandler --- src/BlockInfo.cpp | 22 +++++++++++++++++++++ src/BlockInfo.h | 27 ++++++++++++++++++++++++++ src/Blocks/BlockHandler.cpp | 45 ++----------------------------------------- src/Blocks/BlockHandler.h | 22 +++------------------ src/Blocks/ChunkInterface.cpp | 2 +- src/ClientHandle.cpp | 6 +++--- src/Items/ItemHandler.cpp | 2 +- src/Mobs/Villager.cpp | 2 +- src/Root.cpp | 1 - src/Scoreboard.cpp | 12 +++++++++--- src/World.cpp | 2 +- 11 files changed, 70 insertions(+), 73 deletions(-) diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index c73ae18b6..195af49c7 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -2,6 +2,7 @@ #include "Globals.h" #include "BlockInfo.h" +#include "Blocks/BlockHandler.h" @@ -23,12 +24,25 @@ cBlockInfo::cBlockInfo() , m_RequiresSpecialTool(false) , m_IsSolid(true) , m_FullyOccupiesVoxel(false) + , m_Handler(NULL) {} +cBlockInfo::~cBlockInfo() +{ + if (m_Handler != NULL) + { + delete m_Handler; + } +} + + + + + cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type) { ASSERT(a_Type < 256); @@ -42,6 +56,14 @@ cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type) void cBlockInfo::Initialize(void) { + for (unsigned int i = 0; i < 256; ++i) + { + if (ms_Info[i].m_Handler == NULL) + { + ms_Info[i].m_Handler = cBlockHandler::CreateBlockHandler((BLOCKTYPE) i); + } + } + // Emissive blocks ms_Info[E_BLOCK_FIRE ].m_LightValue = 15; ms_Info[E_BLOCK_GLOWSTONE ].m_LightValue = 15; diff --git a/src/BlockInfo.h b/src/BlockInfo.h index 34a845b20..40c1db867 100644 --- a/src/BlockInfo.h +++ b/src/BlockInfo.h @@ -5,6 +5,13 @@ +// fwd: +class cBlockHandler; + + + + + // tolua_begin class cBlockInfo { @@ -13,6 +20,8 @@ public: cBlockInfo(); + ~cBlockInfo(); + /** (Re-)Initializes the internal BlockInfo structures. */ static void Initialize(void); @@ -49,6 +58,12 @@ public: /** Does this block fully occupy its voxel - is it a 'full' block? */ bool m_FullyOccupiesVoxel; + // tolua_end + + /** Associated block handler. */ + cBlockHandler * m_Handler; + + // tolua_begin inline static NIBBLETYPE GetLightValue (BLOCKTYPE a_Type) { return Get(a_Type).m_LightValue; } inline static NIBBLETYPE GetSpreadLightFalloff(BLOCKTYPE a_Type) { return Get(a_Type).m_SpreadLightFalloff; } @@ -62,6 +77,8 @@ public: // tolua_end + inline static cBlockHandler * GetHandler (BLOCKTYPE a_Type) { return Get(a_Type).m_Handler; } + protected: @@ -74,3 +91,13 @@ protected: + +// Shortcut to get the blockhandler for a specific block +inline cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType) +{ + return cBlockInfo::Get(a_BlockType).m_Handler; +} + + + + diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 834727c9a..052f88f7a 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -77,33 +77,6 @@ -bool cBlockHandler::m_HandlerInitialized = false; -cBlockHandler * cBlockHandler::m_BlockHandler[256]; - - - - - -cBlockHandler * cBlockHandler::GetBlockHandler(BLOCKTYPE a_BlockType) -{ - if (!m_HandlerInitialized) - { - // We have to initialize - memset(m_BlockHandler, 0, sizeof(m_BlockHandler)); - m_HandlerInitialized = true; - } - if (m_BlockHandler[a_BlockType] != NULL) - { - return m_BlockHandler[a_BlockType]; - } - - return m_BlockHandler[a_BlockType] = CreateBlockHandler(a_BlockType); -} - - - - - cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) { switch(a_BlockType) @@ -192,7 +165,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_REDSTONE_REPEATER_ON: return new cBlockRedstoneRepeaterHandler(a_BlockType); case E_BLOCK_REDSTONE_TORCH_OFF: return new cBlockRedstoneTorchHandler (a_BlockType); case E_BLOCK_REDSTONE_TORCH_ON: return new cBlockRedstoneTorchHandler (a_BlockType); - case E_BLOCK_REDSTONE_WIRE: return new cBlockRedstoneHandler (a_BlockType); + case E_BLOCK_REDSTONE_WIRE: return new cBlockRedstoneHandler (a_BlockType); case E_BLOCK_RED_MUSHROOM: return new cBlockMushroomHandler (a_BlockType); case E_BLOCK_RED_ROSE: return new cBlockFlowerHandler (a_BlockType); case E_BLOCK_SAND: return new cBlockSandHandler (a_BlockType); @@ -231,20 +204,6 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) -void cBlockHandler::Deinit() -{ - for (int i = 0; i < 256; i++) - { - delete m_BlockHandler[i]; - } - memset(m_BlockHandler, 0, sizeof(m_BlockHandler)); // Don't leave any dangling pointers around, just in case - m_HandlerInitialized = false; -} - - - - - cBlockHandler::cBlockHandler(BLOCKTYPE a_BlockType) { m_BlockType = a_BlockType; @@ -329,7 +288,7 @@ void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, int a_Bl { if ((a_BlockY >= 0) && (a_BlockY < cChunkDef::Height)) { - GetBlockHandler(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + cBlockInfo::GetHandler(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); } } diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index a2913d7f8..c46a46045 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -136,30 +136,14 @@ public: /// Block meta following mirroring virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) { return a_Meta; } - /// Get the blockhandler for a specific block id - static cBlockHandler * GetBlockHandler(BLOCKTYPE a_BlockType); - - /// Deletes all initialised block handlers - static void Deinit(); - protected: BLOCKTYPE m_BlockType; // Creates a new blockhandler for the given block type. For internal use only, use ::GetBlockHandler() instead. - static cBlockHandler *CreateBlockHandler(BLOCKTYPE a_BlockType); - static cBlockHandler *m_BlockHandler[256]; - static bool m_HandlerInitialized; //used to detect if the blockhandlers are initialized -}; - - + static cBlockHandler * CreateBlockHandler(BLOCKTYPE a_BlockType); - - -// Shortcut to get the blockhandler for a specific block -inline cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType) -{ - return cBlockHandler::GetBlockHandler(a_BlockType); -} + friend class cBlockInfo; +}; diff --git a/src/Blocks/ChunkInterface.cpp b/src/Blocks/ChunkInterface.cpp index b2dda19f4..540581ae7 100644 --- a/src/Blocks/ChunkInterface.cpp +++ b/src/Blocks/ChunkInterface.cpp @@ -6,7 +6,7 @@ bool cChunkInterface::DigBlock(cWorldInterface & a_WorldInterface, int a_X, int a_Y, int a_Z) { - cBlockHandler *Handler = cBlockHandler::GetBlockHandler(GetBlock(a_X, a_Y, a_Z)); + cBlockHandler * Handler = cBlockInfo::GetHandler(GetBlock(a_X, a_Y, a_Z)); Handler->OnDestroyed(*this, a_WorldInterface, a_X, a_Y, a_Z); return m_ChunkMap->DigBlock(a_X, a_Y, a_Z); } diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 07a8984c5..6982a6227 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -838,7 +838,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc cWorld * World = m_Player->GetWorld(); cChunkInterface ChunkInterface(World->GetChunkMap()); - cBlockHandler * Handler = cBlockHandler::GetBlockHandler(a_OldBlock); + cBlockHandler * Handler = cBlockInfo::GetHandler(a_OldBlock); Handler->OnDigging(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ); cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem()); @@ -852,7 +852,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc int pZ = a_BlockZ; AddFaceDirection(pX, pY, pZ, a_BlockFace); // Get the block in front of the clicked coordinates (m_bInverse defaulted to false) - Handler = cBlockHandler::GetBlockHandler(World->GetBlock(pX, pY, pZ)); + Handler = cBlockInfo::GetHandler(World->GetBlock(pX, pY, pZ)); if (Handler->IsClickedThrough()) { @@ -963,7 +963,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); - cBlockHandler * BlockHandler = cBlockHandler::GetBlockHandler(BlockType); + cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType); if (BlockHandler->IsUseable() && !m_Player->IsCrouched()) { diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 507f7fa86..1d357fcf1 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -285,7 +285,7 @@ void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const UNUSED(a_Item); BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); - cBlockHandler * Handler = cBlockHandler::GetBlockHandler(Block); + cBlockHandler * Handler = cBlockInfo::GetHandler(Block); if (a_Player->IsGameModeSurvival()) { diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 09a6e2d09..bbd8d6aaa 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -150,7 +150,7 @@ void cVillager::HandleFarmerTryHarvestCrops() BLOCKTYPE CropBlock = m_World->GetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); if (IsBlockFarmable(CropBlock) && m_World->GetBlockMeta(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z) == 0x7) { - cBlockHandler * Handler = cBlockHandler::GetBlockHandler(CropBlock); + cBlockHandler * Handler = cBlockInfo::GetHandler(CropBlock); cChunkInterface ChunkInterface(m_World->GetChunkMap()); cBlockInServerPluginInterface PluginInterface(*m_World); Handler->DropBlock(ChunkInterface, *m_World, PluginInterface, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); diff --git a/src/Root.cpp b/src/Root.cpp index af2cb9e4b..78c94888d 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -245,7 +245,6 @@ void cRoot::Start(void) delete m_PluginManager; m_PluginManager = NULL; cItemHandler::Deinit(); - cBlockHandler::Deinit(); LOG("Cleaning up..."); delete m_Server; m_Server = NULL; diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 05fd0314d..c1da27086 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -312,12 +312,18 @@ bool cScoreboard::RemoveObjective(const AString & a_Name) return false; } - m_Objectives.erase(it); - ASSERT(m_World != NULL); m_World->BroadcastScoreboardObjective(it->second.GetName(), it->second.GetDisplayName(), 1); - // TODO 2014-03-01 xdot: Remove objective from display slot + for (unsigned int i = 0; i < (unsigned int) dsCount; ++i) + { + if (m_Display[i] == &it->second) + { + SetDisplay(NULL, (eDisplaySlot) i); + } + } + + m_Objectives.erase(it); return true; } diff --git a/src/World.cpp b/src/World.cpp index ffdae2a37..2dfa85d64 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1723,7 +1723,7 @@ bool cWorld::GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure) bool cWorld::DigBlock(int a_X, int a_Y, int a_Z) { - cBlockHandler *Handler = cBlockHandler::GetBlockHandler(GetBlock(a_X, a_Y, a_Z)); + cBlockHandler * Handler = cBlockInfo::GetHandler(GetBlock(a_X, a_Y, a_Z)); cChunkInterface ChunkInterface(GetChunkMap()); Handler->OnDestroyed(ChunkInterface, *this, a_X, a_Y, a_Z); return m_ChunkMap->DigBlock(a_X, a_Y, a_Z); -- cgit v1.2.3 From 1d67345989ac1e55bd0ed18baaf80becfbf37e74 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 2 Mar 2014 21:04:01 +0100 Subject: Add cancelling to WeatherChanging event. --- src/World.cpp | 53 ++++++++++++++++++++++++++++++++++++++++------------- src/World.h | 3 +++ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index 6c9ea7453..88cc19559 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -307,25 +307,52 @@ void cWorld::CastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) +int cWorld::GetDefaultWeatherInterval(eWeather a_Weather) +{ + switch (a_Weather) + { + case eWeather_Sunny: + { + return 14400 + (m_TickRand.randInt() % 4800); // 12 - 16 minutes + } + case eWeather_Rain: + { + return 9600 + (m_TickRand.randInt() % 7200); // 8 - 14 minutes + } + case eWeather_ThunderStorm: + { + return 2400 + (m_TickRand.randInt() % 4800); // 2 - 6 minutes + } + default: + { + LOGWARNING("Missing default weather interval for weather %d.", a_Weather); + return 1200; + } + } // switch (Weather) +} + + + + + void cWorld::SetWeather(eWeather a_NewWeather) { // Do the plugins agree? Do they want a different weather? - cRoot::Get()->GetPluginManager()->CallHookWeatherChanging(*this, a_NewWeather); + if (cRoot::Get()->GetPluginManager()->CallHookWeatherChanging(*this, a_NewWeather)) + { + m_WeatherInterval = GetDefaultWeatherInterval(m_Weather); + return; + } // Set new period for the selected weather: - switch (a_NewWeather) + m_WeatherInterval = GetDefaultWeatherInterval(a_NewWeather); + + // The weather can't be found: + if (m_WeatherInterval == 1200) { - case eWeather_Sunny: m_WeatherInterval = 14400 + (m_TickRand.randInt() % 4800); break; // 12 - 16 minutes - case eWeather_Rain: m_WeatherInterval = 9600 + (m_TickRand.randInt() % 7200); break; // 8 - 14 minutes - case eWeather_ThunderStorm: m_WeatherInterval = 2400 + (m_TickRand.randInt() % 4800); break; // 2 - 6 minutes - default: - { - LOGWARNING("Requested unknown weather %d, setting sunny for a minute instead.", a_NewWeather); - a_NewWeather = eWeather_Sunny; - m_WeatherInterval = 1200; - break; - } - } // switch (NewWeather) + return; + } + m_Weather = a_NewWeather; BroadcastWeather(m_Weather); diff --git a/src/World.h b/src/World.h index 25b42888c..27f1482e5 100644 --- a/src/World.h +++ b/src/World.h @@ -139,6 +139,9 @@ public: BroadcastTimeUpdate(); } + /** Returns the default weather interval for the specific weather type */ + int GetDefaultWeatherInterval(eWeather a_Weather); + /** Returns the current game mode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable */ eGameMode GetGameMode(void) const { return m_GameMode; } -- cgit v1.2.3 From 6536233f4d0bb9411895ce78d1c57e37a7aac044 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 2 Mar 2014 12:29:20 -0800 Subject: Reformated MetaRotater --- src/Blocks/MetaRotater.h | 49 +++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h index b83ed177a..5493c87e2 100644 --- a/src/Blocks/MetaRotater.h +++ b/src/Blocks/MetaRotater.h @@ -1,7 +1,18 @@ +// MetaRotater.h + +// Provides a mixin for rotations and reflections + #pragma once -template +/* +Provides a mixin for rotations and reflections following the standard pattern of apply mask then use case. + +Usage: +Inherit from this class providing your base class as Base, the BitMask for the direction bits in bitmask and the masked value for the directions in North, East, South, West. There is also an aptional parameter AssertIfNotMatched. Set this if it is invalid for a block to exist in any other state. +*/ + +template class cMetaRotater : public Base { public: @@ -19,18 +30,18 @@ public: }; -template -NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) { - NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); - switch (a_Meta & BitFilter) + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) { case South: return West | OtherMeta; case West: return North | OtherMeta; case North: return East | OtherMeta; case East: return South | OtherMeta; } - if(AssertIfNotMatched) + if (AssertIfNotMatched) { ASSERT(!"Invalid Meta value"); return a_Meta; @@ -38,18 +49,18 @@ NIBBLETYPE cMetaRotater -NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) { - NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); - switch (a_Meta & BitFilter) + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) { case South: return East | OtherMeta; case East: return North | OtherMeta; case North: return West | OtherMeta; case West: return South | OtherMeta; } - if(AssertIfNotMatched) + if (AssertIfNotMatched) { ASSERT(!"Invalid Meta value"); return a_Meta; @@ -58,11 +69,11 @@ NIBBLETYPE cMetaRotater -NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) { - NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); - switch (a_Meta & BitFilter) + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) { case South: return North | OtherMeta; case North: return South | OtherMeta; @@ -74,11 +85,11 @@ NIBBLETYPE cMetaRotater -NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) { - NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); - switch (a_Meta & BitFilter) + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) { case West: return East | OtherMeta; case East: return West | OtherMeta; -- cgit v1.2.3 From a38be148ba980e7d54bf72c9056502850d81c77a Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 2 Mar 2014 12:33:08 -0800 Subject: Reformatted --- src/Blocks/BlockBed.h | 4 ++-- src/Blocks/BlockButton.h | 4 ++-- src/Blocks/BlockChest.h | 4 ++-- src/Blocks/BlockComparator.h | 4 ++-- src/Blocks/BlockDoor.h | 4 ++-- src/Blocks/BlockDropSpenser.h | 4 ++-- src/Blocks/BlockEnderchest.h | 4 ++-- src/Blocks/BlockFenceGate.h | 4 ++-- src/Blocks/BlockStairs.h | 4 ++-- src/Blocks/BlockTorch.h | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index d8a796735..6daa94730 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -12,11 +12,11 @@ class cBlockBedHandler : - public cMetaRotater + public cMetaRotater { public: cBlockBedHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 4daa03005..e4923c441 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -8,11 +8,11 @@ class cBlockButtonHandler : - public cMetaRotater + public cMetaRotater { public: cBlockButtonHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 1646454a7..30588d8fc 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -11,11 +11,11 @@ class cBlockChestHandler : - public cMetaRotater + public cMetaRotater { public: cBlockChestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index 238e687ab..a8536b149 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -10,11 +10,11 @@ class cBlockComparatorHandler : - public cMetaRotater + public cMetaRotater { public: cBlockComparatorHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 0caeb7dba..ef73a5d42 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -10,9 +10,9 @@ class cBlockDoorHandler : - public cMetaRotater + public cMetaRotater { - typedef cMetaRotater super; + typedef cMetaRotater super; public: cBlockDoorHandler(BLOCKTYPE a_BlockType); diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index adc819a4c..7e0ad0e55 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -13,11 +13,11 @@ class cBlockDropSpenserHandler : - public cMetaRotater + public cMetaRotater { public: cBlockDropSpenserHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index 6ca83399a..97cf484fb 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -8,11 +8,11 @@ class cBlockEnderchestHandler : - public cMetaRotater + public cMetaRotater { public: cBlockEnderchestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index c33393590..8c94e4875 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -8,11 +8,11 @@ class cBlockFenceGateHandler : - public cMetaRotater + public cMetaRotater { public: cBlockFenceGateHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index f07afc9f0..bbbe0ee84 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -8,11 +8,11 @@ class cBlockStairsHandler : - public cMetaRotater + public cMetaRotater { public: cBlockStairsHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 59c896857..03a63ac72 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -8,11 +8,11 @@ class cBlockTorchHandler : - public cMetaRotater + public cMetaRotater { public: cBlockTorchHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } -- cgit v1.2.3 From 36fd78af35b49d64b97e93df6428ace787c88c4c Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 2 Mar 2014 22:55:14 +0200 Subject: Removed if condition --- src/BlockInfo.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index 195af49c7..399efcd9b 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -33,10 +33,7 @@ cBlockInfo::cBlockInfo() cBlockInfo::~cBlockInfo() { - if (m_Handler != NULL) - { - delete m_Handler; - } + delete m_Handler; } -- cgit v1.2.3 From 442c1d96fc77a91b917c7a7aefb7f8f23c0a7e10 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 3 Mar 2014 20:55:04 +0100 Subject: Fixed previous weather changes. cWorld::GetDefaultWeatherInterval() returns -1 for unknown weather. --- src/World.cpp | 6 +++--- src/World.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index 58d50d3a8..6ee0def91 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -325,8 +325,8 @@ int cWorld::GetDefaultWeatherInterval(eWeather a_Weather) } default: { - LOGWARNING("Missing default weather interval for weather %d.", a_Weather); - return 1200; + LOGWARNING("%s: Missing default weather interval for weather %d.", __FUNCTION__, a_Weather); + return -1; } } // switch (Weather) } @@ -348,7 +348,7 @@ void cWorld::SetWeather(eWeather a_NewWeather) m_WeatherInterval = GetDefaultWeatherInterval(a_NewWeather); // The weather can't be found: - if (m_WeatherInterval == 1200) + if (m_WeatherInterval < 0) { return; } diff --git a/src/World.h b/src/World.h index 27f1482e5..93397c014 100644 --- a/src/World.h +++ b/src/World.h @@ -139,7 +139,8 @@ public: BroadcastTimeUpdate(); } - /** Returns the default weather interval for the specific weather type */ + /** Returns the default weather interval for the specific weather type. + Returns -1 for any unknown weather. */ int GetDefaultWeatherInterval(eWeather a_Weather); /** Returns the current game mode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable */ -- cgit v1.2.3 From e50ffba1ad1cae0154828ccc210ba4949af088f3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Mar 2014 18:40:55 +0100 Subject: Fixed an assert in map-loading. The maps were loaded too soon, the world wasn't initialized yet. --- src/World.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index 6ee0def91..37c07b398 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -264,8 +264,6 @@ cWorld::cWorld(const AString & a_WorldName) : // Load the scoreboard cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard); Serializer.Load(); - - m_MapManager.LoadMapData(); } @@ -652,13 +650,13 @@ void cWorld::Start(void) m_LastSpawnMonster.insert(std::map::value_type(cMonster::mfAmbient, 0)); m_LastSpawnMonster.insert(std::map::value_type(cMonster::mfWater, 0)); + m_MapManager.LoadMapData(); // Save any changes that the defaults may have done to the ini file: if (!IniFile.WriteFile(m_IniFileName)) { LOGWARNING("Could not write world config to %s", m_IniFileName.c_str()); } - } -- cgit v1.2.3 From ecfe17b096994649610c03561496d8506648322c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Mar 2014 21:55:24 +0100 Subject: cLuaState: Made public the GetStackValue() functions. --- src/Bindings/LuaState.cpp | 18 ++++++--- src/Bindings/LuaState.h | 97 ++++++++++++++++++++++++----------------------- 2 files changed, 61 insertions(+), 54 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index a5540df17..1890dcfe5 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -716,7 +716,7 @@ void cLuaState::Push(cBlockEntity * a_BlockEntity) -void cLuaState::GetReturn(int a_StackPos, bool & a_ReturnedVal) +void cLuaState::GetStackValue(int a_StackPos, bool & a_ReturnedVal) { a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0); } @@ -725,11 +725,17 @@ void cLuaState::GetReturn(int a_StackPos, bool & a_ReturnedVal) -void cLuaState::GetReturn(int a_StackPos, AString & a_ReturnedVal) +void cLuaState::GetStackValue(int a_StackPos, AString & a_Value) { - if (lua_isstring(m_LuaState, a_StackPos)) + size_t len = 0; + const char * data = lua_tolstring(m_LuaState, a_StackPos, &len); + if (data != NULL) + { + a_Value.assign(data, len); + } + else { - a_ReturnedVal = tolua_tocppstring(m_LuaState, a_StackPos, a_ReturnedVal.c_str()); + a_Value.clear(); } } @@ -737,7 +743,7 @@ void cLuaState::GetReturn(int a_StackPos, AString & a_ReturnedVal) -void cLuaState::GetReturn(int a_StackPos, int & a_ReturnedVal) +void cLuaState::GetStackValue(int a_StackPos, int & a_ReturnedVal) { if (lua_isnumber(m_LuaState, a_StackPos)) { @@ -749,7 +755,7 @@ void cLuaState::GetReturn(int a_StackPos, int & a_ReturnedVal) -void cLuaState::GetReturn(int a_StackPos, double & a_ReturnedVal) +void cLuaState::GetStackValue(int a_StackPos, double & a_ReturnedVal) { if (lua_isnumber(m_LuaState, a_StackPos)) { diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index dcb660c3f..4a7a6fadb 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -197,6 +197,19 @@ public: void Push(void * a_Ptr); void Push(cHopperEntity * a_Hopper); void Push(cBlockEntity * a_BlockEntity); + + /** Retrieve value at a_StackPos, if it is a valid bool. If not, a_Value is unchanged */ + void GetStackValue(int a_StackPos, bool & a_Value); + + /** Retrieve value at a_StackPos, if it is a valid string. If not, a_Value is unchanged */ + void GetStackValue(int a_StackPos, AString & a_Value); + + /** Retrieve value at a_StackPos, if it is a valid number. If not, a_Value is unchanged */ + void GetStackValue(int a_StackPos, int & a_Value); + + /** Retrieve value at a_StackPos, if it is a valid number. If not, a_Value is unchanged */ + void GetStackValue(int a_StackPos, double & a_Value); + /** Call any 0-param 0-return Lua function in a single line: */ template @@ -270,7 +283,7 @@ public: { return false; } - GetReturn(-1, a_Ret1); + GetStackValue(-1, a_Ret1); lua_pop(m_LuaState, 1); return true; } @@ -292,7 +305,7 @@ public: { return false; } - GetReturn(-1, a_Ret1); + GetStackValue(-1, a_Ret1); lua_pop(m_LuaState, 1); ASSERT(InitialTop == lua_gettop(m_LuaState)); return true; @@ -315,7 +328,7 @@ public: { return false; } - GetReturn(-1, a_Ret1); + GetStackValue(-1, a_Ret1); lua_pop(m_LuaState, 1); return true; } @@ -338,7 +351,7 @@ public: { return false; } - GetReturn(-1, a_Ret1); + GetStackValue(-1, a_Ret1); lua_pop(m_LuaState, 1); return true; } @@ -362,7 +375,7 @@ public: { return false; } - GetReturn(-1, a_Ret1); + GetStackValue(-1, a_Ret1); lua_pop(m_LuaState, 1); return true; } @@ -387,7 +400,7 @@ public: { return false; } - GetReturn(-1, a_Ret1); + GetStackValue(-1, a_Ret1); lua_pop(m_LuaState, 1); return true; } @@ -414,7 +427,7 @@ public: { return false; } - GetReturn(-1, a_Ret1); + GetStackValue(-1, a_Ret1); lua_pop(m_LuaState, 1); return true; } @@ -442,7 +455,7 @@ public: { return false; } - GetReturn(-1, a_Ret1); + GetStackValue(-1, a_Ret1); lua_pop(m_LuaState, 1); return true; } @@ -471,7 +484,7 @@ public: { return false; } - GetReturn(-1, a_Ret1); + GetStackValue(-1, a_Ret1); lua_pop(m_LuaState, 1); return true; } @@ -501,7 +514,7 @@ public: { return false; } - GetReturn(-1, a_Ret1); + GetStackValue(-1, a_Ret1); lua_pop(m_LuaState, 1); return true; } @@ -532,7 +545,7 @@ public: { return false; } - GetReturn(-1, a_Ret1); + GetStackValue(-1, a_Ret1); lua_pop(m_LuaState, 1); return true; } @@ -553,8 +566,8 @@ public: { return false; } - GetReturn(-2, a_Ret1); - GetReturn(-1, a_Ret2); + GetStackValue(-2, a_Ret1); + GetStackValue(-1, a_Ret2); lua_pop(m_LuaState, 2); return true; } @@ -576,8 +589,8 @@ public: { return false; } - GetReturn(-2, a_Ret1); - GetReturn(-1, a_Ret2); + GetStackValue(-2, a_Ret1); + GetStackValue(-1, a_Ret2); lua_pop(m_LuaState, 2); return true; } @@ -601,8 +614,8 @@ public: { return false; } - GetReturn(-2, a_Ret1); - GetReturn(-1, a_Ret2); + GetStackValue(-2, a_Ret1); + GetStackValue(-1, a_Ret2); lua_pop(m_LuaState, 2); return true; } @@ -627,8 +640,8 @@ public: { return false; } - GetReturn(-2, a_Ret1); - GetReturn(-1, a_Ret2); + GetStackValue(-2, a_Ret1); + GetStackValue(-1, a_Ret2); lua_pop(m_LuaState, 2); return true; } @@ -654,8 +667,8 @@ public: { return false; } - GetReturn(-2, a_Ret1); - GetReturn(-1, a_Ret2); + GetStackValue(-2, a_Ret1); + GetStackValue(-1, a_Ret2); lua_pop(m_LuaState, 2); return true; } @@ -683,8 +696,8 @@ public: { return false; } - GetReturn(-2, a_Ret1); - GetReturn(-1, a_Ret2); + GetStackValue(-2, a_Ret1); + GetStackValue(-1, a_Ret2); lua_pop(m_LuaState, 2); return true; } @@ -713,8 +726,8 @@ public: { return false; } - GetReturn(-2, a_Ret1); - GetReturn(-1, a_Ret2); + GetStackValue(-2, a_Ret1); + GetStackValue(-1, a_Ret2); lua_pop(m_LuaState, 2); return true; } @@ -743,9 +756,9 @@ public: { return false; } - GetReturn(-3, a_Ret1); - GetReturn(-2, a_Ret2); - GetReturn(-1, a_Ret3); + GetStackValue(-3, a_Ret1); + GetStackValue(-2, a_Ret2); + GetStackValue(-1, a_Ret3); lua_pop(m_LuaState, 3); return true; } @@ -775,9 +788,9 @@ public: { return false; } - GetReturn(-3, a_Ret1); - GetReturn(-2, a_Ret2); - GetReturn(-1, a_Ret3); + GetStackValue(-3, a_Ret1); + GetStackValue(-2, a_Ret2); + GetStackValue(-1, a_Ret3); lua_pop(m_LuaState, 3); return true; } @@ -808,11 +821,11 @@ public: { return false; } - GetReturn(-5, a_Ret1); - GetReturn(-4, a_Ret2); - GetReturn(-3, a_Ret3); - GetReturn(-2, a_Ret4); - GetReturn(-1, a_Ret5); + GetStackValue(-5, a_Ret1); + GetStackValue(-4, a_Ret2); + GetStackValue(-3, a_Ret3); + GetStackValue(-2, a_Ret4); + GetStackValue(-1, a_Ret5); lua_pop(m_LuaState, 5); return true; } @@ -918,18 +931,6 @@ protected: /** Pushes a usertype of the specified class type onto the stack */ void PushUserType(void * a_Object, const char * a_Type); - /** Retrieve value returned at a_StackPos, if it is a valid bool. If not, a_ReturnedVal is unchanged */ - void GetReturn(int a_StackPos, bool & a_ReturnedVal); - - /** Retrieve value returned at a_StackPos, if it is a valid string. If not, a_ReturnedVal is unchanged */ - void GetReturn(int a_StackPos, AString & a_ReturnedVal); - - /** Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged */ - void GetReturn(int a_StackPos, int & a_ReturnedVal); - - /** Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged */ - void GetReturn(int a_StackPos, double & a_ReturnedVal); - /** Calls the function that has been pushed onto the stack by PushFunction(), with arguments pushed by PushXXX(). -- cgit v1.2.3 From 8f782885640a270bfe23843dff82367d28f9fb23 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Mar 2014 22:17:23 +0100 Subject: Manually exported cCompositeChat modifiers. This adds chaining support to them. Fixes #755. --- src/Bindings/ManualBindings.cpp | 258 ++++++++++++++++++++++++++++++++++++++++ src/CompositeChat.h | 17 +-- 2 files changed, 268 insertions(+), 7 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index fcdd728be..9fbc2e842 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -26,6 +26,7 @@ #include "md5/md5.h" #include "../LineBlockTracer.h" #include "../WorldStorage/SchematicFileSerializer.h" +#include "../CompositeChat.h" @@ -2511,6 +2512,253 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) +static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S) +{ + // function cCompositeChat:AddRunCommandPart(Message, Command, [Style]) + // Exported manually to support call-chaining (return *this) + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cCompositeChat") || + !L.CheckParamString(2, 3) + ) + { + return 0; + } + cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddRunCommandPart'", NULL); + return 0; + } + + // Add the part: + AString Text, Command, Style; + L.GetStackValue(2, Text); + L.GetStackValue(3, Command); + L.GetStackValue(4, Style); + self->AddRunCommandPart(Text, Command, Style); + + // Cut away everything from the stack except for the cCompositeChat instance; return that: + lua_settop(L, 1); + return 1; +} + + + + + +static int tolua_cCompositeChat_AddSuggestCommandPart(lua_State * tolua_S) +{ + // function cCompositeChat:AddSuggestCommandPart(Message, Command, [Style]) + // Exported manually to support call-chaining (return *this) + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cCompositeChat") || + !L.CheckParamString(2, 3) + ) + { + return 0; + } + cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddSuggestCommandPart'", NULL); + return 0; + } + + // Add the part: + AString Text, Command, Style; + L.GetStackValue(2, Text); + L.GetStackValue(3, Command); + L.GetStackValue(4, Style); + self->AddSuggestCommandPart(Text, Command, Style); + + // Cut away everything from the stack except for the cCompositeChat instance; return that: + lua_settop(L, 1); + return 1; +} + + + + + +static int tolua_cCompositeChat_AddTextPart(lua_State * tolua_S) +{ + // function cCompositeChat:AddTextPart(Message, [Style]) + // Exported manually to support call-chaining (return *this) + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cCompositeChat") || + !L.CheckParamString(2) + ) + { + return 0; + } + cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddTextPart'", NULL); + return 0; + } + + // Add the part: + AString Text, Style; + L.GetStackValue(2, Text); + L.GetStackValue(3, Style); + self->AddTextPart(Text, Style); + + // Cut away everything from the stack except for the cCompositeChat instance; return that: + lua_settop(L, 1); + return 1; +} + + + + + +static int tolua_cCompositeChat_AddUrlPart(lua_State * tolua_S) +{ + // function cCompositeChat:AddTextPart(Message, Url, [Style]) + // Exported manually to support call-chaining (return *this) + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cCompositeChat") || + !L.CheckParamString(2, 3) + ) + { + return 0; + } + cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddUrlPart'", NULL); + return 0; + } + + // Add the part: + AString Text, Url, Style; + L.GetStackValue(2, Text); + L.GetStackValue(3, Url); + L.GetStackValue(4, Style); + self->AddUrlPart(Text, Url, Style); + + // Cut away everything from the stack except for the cCompositeChat instance; return that: + lua_settop(L, 1); + return 1; +} + + + + + +static int tolua_cCompositeChat_ParseText(lua_State * tolua_S) +{ + // function cCompositeChat:ParseText(TextMessage) + // Exported manually to support call-chaining (return *this) + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cCompositeChat") || + !L.CheckParamString(2) + ) + { + return 0; + } + cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:ParseText'", NULL); + return 0; + } + + // Parse the text: + AString Text; + L.GetStackValue(2, Text); + self->ParseText(Text); + + // Cut away everything from the stack except for the cCompositeChat instance; return that: + lua_settop(L, 1); + return 1; +} + + + + + +static int tolua_cCompositeChat_SetMessageType(lua_State * tolua_S) +{ + // function cCompositeChat:SetMessageType(MessageType) + // Exported manually to support call-chaining (return *this) + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cCompositeChat") || + !L.CheckParamNumber(2) + ) + { + return 0; + } + cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:SetMessageType'", NULL); + return 0; + } + + // Set the type: + int MessageType; + L.GetStackValue(1, MessageType); + self->SetMessageType((eMessageType)MessageType); + + // Cut away everything from the stack except for the cCompositeChat instance; return that: + lua_settop(L, 1); + return 1; +} + + + + + +static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S) +{ + // function cCompositeChat:UnderlineUrls() + // Exported manually to support call-chaining (return *this) + + // Check params: + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cCompositeChat")) + { + return 0; + } + cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:UnderlineUrls'", NULL); + return 0; + } + + // Call the processing + self->UnderlineUrls(); + + // Cut away everything from the stack except for the cCompositeChat instance; return that: + lua_settop(L, 1); + return 1; +} + + + + + void ManualBindings::Bind(lua_State * tolua_S) { tolua_beginmodule(tolua_S, NULL); @@ -2535,6 +2783,16 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cCompositeChat"); + tolua_function(tolua_S, "AddRunCommandPart", tolua_cCompositeChat_AddRunCommandPart); + tolua_function(tolua_S, "AddSuggestCommandPart", tolua_cCompositeChat_AddSuggestCommandPart); + tolua_function(tolua_S, "AddTextPart", tolua_cCompositeChat_AddTextPart); + tolua_function(tolua_S, "AddUrlPart", tolua_cCompositeChat_AddUrlPart); + tolua_function(tolua_S, "ParseText", tolua_cCompositeChat_ParseText); + tolua_function(tolua_S, "SetMessageType", tolua_cCompositeChat_SetMessageType); + tolua_function(tolua_S, "UnderlineUrls", tolua_cCompositeChat_UnderlineUrls); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cHopperEntity"); tolua_function(tolua_S, "GetOutputBlockPos", tolua_cHopperEntity_GetOutputBlockPos); tolua_endmodule(tolua_S); diff --git a/src/CompositeChat.h b/src/CompositeChat.h index 51600da4f..27319490d 100644 --- a/src/CompositeChat.h +++ b/src/CompositeChat.h @@ -124,14 +124,15 @@ public: /** Removes all parts from the object. */ void Clear(void); + // tolua_end + + // The following are exported in ManualBindings in order to support chaining - they return *this in Lua (#755) + /** Adds a plain text part, with optional style. The default style is plain white text. */ void AddTextPart(const AString & a_Message, const AString & a_Style = ""); - // tolua_end - - /** Adds a part that is translated client-side, with the formatting parameters and optional style. - Exported in ManualBindings due to AStringVector usage - Lua uses an array-table of strings. */ + /** Adds a part that is translated client-side, with the formatting parameters and optional style. */ void AddClientTranslatedPart(const AString & a_TranslationID, const AStringVector & a_Parameters, const AString & a_Style = ""); // tolua_begin @@ -155,12 +156,14 @@ public: /** Sets the message type, which is indicated by prefixes added to the message when serializing. */ void SetMessageType(eMessageType a_MessageType); - /** Returns the message type set previously by SetMessageType(). */ - eMessageType GetMessageType(void) const { return m_MessageType; } - /** Adds the "underline" style to each part that is an URL. */ void UnderlineUrls(void); + // tolua_begin + + /** Returns the message type set previously by SetMessageType(). */ + eMessageType GetMessageType(void) const { return m_MessageType; } + // tolua_end const cParts & GetParts(void) const { return m_Parts; } -- cgit v1.2.3 From ab30d94b2fed330bb487e30960d82c0bedff37b4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Mar 2014 22:17:47 +0100 Subject: Debuggers: Added simple test for cCompositeChat. --- MCServer/Plugins/Debuggers/Debuggers.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 66894d835..329a652cd 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -30,6 +30,7 @@ function Initialize(Plugin) PM:AddHook(cPluginManager.HOOK_CHUNK_GENERATED, OnChunkGenerated); PM:AddHook(cPluginManager.HOOK_PLUGINS_LOADED, OnPluginsLoaded); PM:AddHook(cPluginManager.HOOK_PLUGIN_MESSAGE, OnPluginMessage); + PM:AddHook(cPluginManager.HOOK_PLAYER_JOINED, OnPlayerJoined) PM:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "- Shows a list of all the loaded entities"); PM:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "- Kills all the loaded entities"); @@ -1258,3 +1259,17 @@ end + +function OnPlayerJoined(a_Player) + -- Test composite chat chaining: + a_Player:SendMessage(cCompositeChat() + :AddTextPart("Hello, ") + :AddUrlPart(a_Player:GetName(), "www.mc-server.org", "u@2") + :AddSuggestCommandPart(", and welcome.", "/help", "u") + :AddRunCommandPart(" SetDay", "/time set 0") + ) +end + + + + -- cgit v1.2.3 From a845c051b8df10c6eaf1f68d3c37abe71425e9d6 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Mar 2014 22:25:31 +0100 Subject: Fixed some gcc warnings in Defines.h. --- src/Defines.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Defines.h b/src/Defines.h index 018ecb1d3..6ab2274a4 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -235,8 +235,8 @@ inline eBlockFace MirrorBlockFaceY(eBlockFace a_BlockFace) case BLOCK_FACE_XP: return BLOCK_FACE_XM; case BLOCK_FACE_ZM: return BLOCK_FACE_ZP; case BLOCK_FACE_ZP: return BLOCK_FACE_ZM; + default: return a_BlockFace; } - return a_BlockFace; } @@ -252,8 +252,8 @@ inline eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace) case BLOCK_FACE_XP: return BLOCK_FACE_ZM; case BLOCK_FACE_ZM: return BLOCK_FACE_XM; case BLOCK_FACE_ZP: return BLOCK_FACE_XP; + default: return a_BlockFace; } - return a_BlockFace; } @@ -268,8 +268,8 @@ inline eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace) case BLOCK_FACE_XP: return BLOCK_FACE_ZP; case BLOCK_FACE_ZM: return BLOCK_FACE_XP; case BLOCK_FACE_ZP: return BLOCK_FACE_XM; + default: return a_BlockFace; } - return a_BlockFace; } -- cgit v1.2.3 From 1ea17c0a75b84d5f4070c57ad2a7d6cbb4e8b79b Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 5 Mar 2014 15:54:38 +0200 Subject: Implemented vanilla-like fluid simulator --- src/Scoreboard.cpp | 2 +- src/Simulator/FloodyFluidSimulator.cpp | 23 +++-- src/Simulator/FloodyFluidSimulator.h | 12 ++- src/Simulator/VanillaFluidSimulator.cpp | 150 ++++++++++++++++++++++++++++++++ src/Simulator/VanillaFluidSimulator.h | 42 +++++++++ src/World.cpp | 26 ++++-- 6 files changed, 238 insertions(+), 17 deletions(-) create mode 100644 src/Simulator/VanillaFluidSimulator.cpp create mode 100644 src/Simulator/VanillaFluidSimulator.h diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index c1da27086..8088e624b 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -506,7 +506,7 @@ bool cScoreboard::ForEachObjective(cObjectiveCallback& a_Callback) bool cScoreboard::ForEachTeam(cTeamCallback& a_Callback) { - cCSLock Lock(m_CSObjectives); + cCSLock Lock(m_CSTeams); for (cTeamMap::iterator it = m_Teams.begin(); it != m_Teams.end(); ++it) { diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp index 95182345c..b1ac734d7 100644 --- a/src/Simulator/FloodyFluidSimulator.cpp +++ b/src/Simulator/FloodyFluidSimulator.cpp @@ -86,7 +86,12 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re { // Spread only down, possibly washing away what's there or turning lava to stone / cobble / obsidian: SpreadToNeighbor(a_Chunk, a_RelX, a_RelY - 1, a_RelZ, 8); - SpreadFurther = false; + + // Source blocks spread both downwards and sideways + if (MyMeta != 0) + { + SpreadFurther = false; + } } // If source creation is on, check for it here: else if ( @@ -105,10 +110,7 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re if (SpreadFurther && (NewMeta < 8)) { // Spread to the neighbors: - SpreadToNeighbor(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, NewMeta); - SpreadToNeighbor(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, NewMeta); - SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ - 1, NewMeta); - SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ + 1, NewMeta); + Spread(a_Chunk, a_RelX, a_RelY, a_RelZ, NewMeta); } // Mark as processed: @@ -119,6 +121,17 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re +void cFloodyFluidSimulator::Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta) +{ + SpreadToNeighbor(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, a_NewMeta); + SpreadToNeighbor(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, a_NewMeta); + SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ - 1, a_NewMeta); + SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ + 1, a_NewMeta); +} + + + + bool cFloodyFluidSimulator::CheckTributaries(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_MyMeta) { // If we have a section above, check if there's fluid above this block that would feed it: diff --git a/src/Simulator/FloodyFluidSimulator.h b/src/Simulator/FloodyFluidSimulator.h index c4af2e246..5fd91b2b1 100644 --- a/src/Simulator/FloodyFluidSimulator.h +++ b/src/Simulator/FloodyFluidSimulator.h @@ -38,14 +38,20 @@ protected: // cDelayedFluidSimulator overrides: virtual void SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override; - /// Checks tributaries, if not fed, decreases the block's level and returns true + /** Checks tributaries, if not fed, decreases the block's level and returns true. */ bool CheckTributaries(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_MyMeta); - /// Spreads into the specified block, if the blocktype there allows. a_Area is for checking. + /** Spreads into the specified block, if the blocktype there allows. a_Area is for checking. */ void SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta); - /// Checks if there are enough neighbors to create a source at the coords specified; turns into source and returns true if so + /** Checks if there are enough neighbors to create a source at the coords specified; turns into source and returns true if so. */ bool CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ); + + /** Spread water to neighbors. + * + * May be overridden to provide more sophisticated algorithms. + */ + virtual void Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta); } ; diff --git a/src/Simulator/VanillaFluidSimulator.cpp b/src/Simulator/VanillaFluidSimulator.cpp new file mode 100644 index 000000000..5308d162b --- /dev/null +++ b/src/Simulator/VanillaFluidSimulator.cpp @@ -0,0 +1,150 @@ + +// VanillaFluidSimulator.cpp + +#include "Globals.h" + +#include "VanillaFluidSimulator.h" +#include "../World.h" +#include "../Chunk.h" +#include "../BlockArea.h" +#include "../Blocks/BlockHandler.h" +#include "../BlockInServerPluginInterface.h" + + + + + +static const int InfiniteCost = 100; + + + + + +cVanillaFluidSimulator::cVanillaFluidSimulator( + cWorld & a_World, + BLOCKTYPE a_Fluid, + BLOCKTYPE a_StationaryFluid, + NIBBLETYPE a_Falloff, + int a_TickDelay, + int a_NumNeighborsForSource +) : super(a_World, a_Fluid, a_StationaryFluid, a_Falloff, a_TickDelay, a_NumNeighborsForSource) +{ +} + + + + + +void cVanillaFluidSimulator::Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta) +{ + int Cost[4]; + Cost[0] = CalculateFlowCost(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, X_PLUS); + Cost[1] = CalculateFlowCost(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, X_MINUS); + Cost[2] = CalculateFlowCost(a_Chunk, a_RelX, a_RelY, a_RelZ + 1, Z_PLUS); + Cost[3] = CalculateFlowCost(a_Chunk, a_RelX, a_RelY, a_RelZ - 1, Z_MINUS); + + int MinCost = InfiniteCost; + for (unsigned int i = 0; i < ARRAYCOUNT(Cost); ++i) + { + if (Cost[i] < MinCost) + { + MinCost = Cost[i]; + } + } + + if (Cost[0] == MinCost) + { + SpreadToNeighbor(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, a_NewMeta); + } + if (Cost[1] == MinCost) + { + SpreadToNeighbor(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, a_NewMeta); + } + if (Cost[2] == MinCost) + { + SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ + 1, a_NewMeta); + } + if (Cost[3] == MinCost) + { + SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ - 1, a_NewMeta); + } +} + + + + + +int cVanillaFluidSimulator::CalculateFlowCost(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, Direction a_Dir, unsigned a_Iteration) +{ + int Cost = InfiniteCost; + + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + + // Check if block is passable + if (!a_Chunk->UnboundedRelGetBlock(a_RelX, a_RelY, a_RelZ, BlockType, BlockMeta)) + { + return Cost; + } + if (!IsPassableForFluid(BlockType)) + { + return Cost; + } + + // Check if block below is passable + if (!a_Chunk->UnboundedRelGetBlock(a_RelX, a_RelY - 1, a_RelZ, BlockType, BlockMeta)) + { + return Cost; + } + if (IsPassableForFluid(BlockType)) + { + // Path found, exit + return a_Iteration; + } + + // 5 blocks away, bail out + if (a_Iteration > 3) + { + return Cost; + } + + // Recurse + if (a_Dir != X_MINUS) + { + int NextCost = CalculateFlowCost(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, X_PLUS, a_Iteration + 1); + if (NextCost < Cost) + { + Cost = NextCost; + } + } + if (a_Dir != X_PLUS) + { + int NextCost = CalculateFlowCost(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, X_MINUS, a_Iteration + 1); + if (NextCost < Cost) + { + Cost = NextCost; + } + } + if (a_Dir != Z_MINUS) + { + int NextCost = CalculateFlowCost(a_Chunk, a_RelX, a_RelY, a_RelZ + 1, Z_PLUS, a_Iteration + 1); + if (NextCost < Cost) + { + Cost = NextCost; + } + } + if (a_Dir != Z_PLUS) + { + int NextCost = CalculateFlowCost(a_Chunk, a_RelX, a_RelY, a_RelZ - 1, Z_MINUS, a_Iteration + 1); + if (NextCost < Cost) + { + Cost = NextCost; + } + } + + return Cost; +} + + + + diff --git a/src/Simulator/VanillaFluidSimulator.h b/src/Simulator/VanillaFluidSimulator.h new file mode 100644 index 000000000..a9ea98b5a --- /dev/null +++ b/src/Simulator/VanillaFluidSimulator.h @@ -0,0 +1,42 @@ + +// VanillaFluidSimulator.h + + + + + +#pragma once + +#include "FloodyFluidSimulator.h" + + + + + +// fwd: +class cBlockArea; + + + + + +class cVanillaFluidSimulator : + public cFloodyFluidSimulator +{ + typedef cFloodyFluidSimulator super; + +public: + cVanillaFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_Falloff, int a_TickDelay, int a_NumNeighborsForSource); + +protected: + // cFloodyFluidSimulator overrides: + virtual void Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta) override; + + /** Recursively calculates the minimum number of blocks needed to descend a level. */ + int CalculateFlowCost(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, Direction a_Dir, unsigned a_Iteration = 0); + +} ; + + + + diff --git a/src/World.cpp b/src/World.cpp index 2dfa85d64..01ba5e503 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -34,6 +34,7 @@ #include "Simulator/NoopRedstoneSimulator.h" #include "Simulator/SandSimulator.h" #include "Simulator/IncrementalRedstoneSimulator.h" +#include "Simulator/VanillaFluidSimulator.h" #include "Simulator/VaporizeFluidSimulator.h" // Mobs: @@ -2987,8 +2988,8 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c AString SimulatorName = a_IniFile.GetValueSet("Physics", SimulatorNameKey, ""); if (SimulatorName.empty()) { - LOGWARNING("[Physics] %s not present or empty in %s, using the default of \"Floody\".", SimulatorNameKey.c_str(), GetIniFileName().c_str()); - SimulatorName = "Floody"; + LOGWARNING("[Physics] %s not present or empty in %s, using the default of \"Vanilla\".", SimulatorNameKey.c_str(), GetIniFileName().c_str()); + SimulatorName = "Vanilla"; } cFluidSimulator * res = NULL; @@ -3012,15 +3013,24 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c } else { - if (NoCaseCompare(SimulatorName, "floody") != 0) - { - // The simulator name doesn't match anything we have, issue a warning: - LOGWARNING("%s [Physics]:%s specifies an unknown simulator, using the default \"Floody\".", GetIniFileName().c_str(), SimulatorNameKey.c_str()); - } int Falloff = a_IniFile.GetValueSetI(SimulatorSectionName, "Falloff", IsWater ? 1 : 2); int TickDelay = a_IniFile.GetValueSetI(SimulatorSectionName, "TickDelay", IsWater ? 5 : 30); int NumNeighborsForSource = a_IniFile.GetValueSetI(SimulatorSectionName, "NumNeighborsForSource", IsWater ? 2 : -1); - res = new cFloodyFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource); + + if (NoCaseCompare(SimulatorName, "floody") == 0) + { + res = new cFloodyFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource); + } + else if (NoCaseCompare(SimulatorName, "vanilla") == 0) + { + res = new cVanillaFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource); + } + else + { + // The simulator name doesn't match anything we have, issue a warning: + LOGWARNING("%s [Physics]:%s specifies an unknown simulator, using the default \"Vanilla\".", GetIniFileName().c_str(), SimulatorNameKey.c_str()); + res = new cVanillaFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource); + } } m_SimulatorManager->RegisterSimulator(res, Rate); -- cgit v1.2.3 From d4a5b16c52c41da59d2fe3405570653521e5d36e Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 5 Mar 2014 15:10:20 +0100 Subject: Add data backsending, when the Client interacts a Block and the Interact is cancelled. --- src/Blocks/BlockComparator.h | 6 ++++++ src/Blocks/BlockDoor.cpp | 21 +++++++++++++++++++++ src/Blocks/BlockDoor.h | 1 + src/Blocks/BlockFenceGate.h | 6 ++++++ src/Blocks/BlockHandler.cpp | 10 ++++++++++ src/Blocks/BlockHandler.h | 5 ++++- src/Blocks/BlockRedstoneRepeater.h | 8 +++++++- src/Blocks/BlockTNT.h | 32 ++++++++++++++++++++++++++++++++ src/Blocks/BlockTrapdoor.h | 5 +++++ src/ClientHandle.cpp | 14 ++++++++++---- 10 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 src/Blocks/BlockTNT.h diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index aba390d9d..b0ac75aaf 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -26,6 +26,12 @@ public: } + virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override + { + a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { // Reset meta to 0 diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index 2ff5c1c37..6c51feab3 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -55,6 +55,27 @@ void cBlockDoorHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterfac +void cBlockDoorHandler::OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) +{ + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + a_Player->GetClientHandle()->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta); + + if (Meta & 8) + { + // Current block is top of the door + a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, a_Player); + } + else + { + // Current block is bottom of the door + a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, a_Player); + } +} + + + + + void cBlockDoorHandler::OnPlacedByPlayer( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index ef0dbb787..68be2c658 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -16,6 +16,7 @@ public: virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; + virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override; virtual const char * GetStepSound(void) override; diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index fb984f345..a14510724 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -48,6 +48,12 @@ public: } + virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override + { + a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); + } + + virtual bool IsUseable(void) override { return true; diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 052f88f7a..c5165986c 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -57,6 +57,7 @@ #include "BlockRedstoneLamp.h" #include "BlockRedstoneRepeater.h" #include "BlockRedstoneTorch.h" +#include "BlockTNT.h" #include "BlockSand.h" #include "BlockSapling.h" #include "BlockSideways.h" @@ -185,6 +186,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_TALL_GRASS: return new cBlockTallGrassHandler (a_BlockType); case E_BLOCK_TORCH: return new cBlockTorchHandler (a_BlockType); case E_BLOCK_TRAPDOOR: return new cBlockTrapdoorHandler (a_BlockType); + case E_BLOCK_TNT: return new cBlockTNTHandler (a_BlockType); case E_BLOCK_VINES: return new cBlockVineHandler (a_BlockType); case E_BLOCK_WALLSIGN: return new cBlockSignHandler (a_BlockType); case E_BLOCK_WATER: return new cBlockFluidHandler (a_BlockType); @@ -320,6 +322,14 @@ void cBlockHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & +void cBlockHandler::OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) +{ +} + + + + + void cBlockHandler::ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) { // Setting the meta to a_BlockMeta keeps most textures. The few other blocks have to override this. diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index c46a46045..fbb36d96a 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -69,6 +69,9 @@ public: /// Called if the user right clicks the block and the block is useable virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); + /** Called when a Right Click to this Block is cancelled */ + virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace); + /// Called when the item is mined to convert it into pickups. Pickups may specify multiple items. Appends items to a_Pickups, preserves its original contents virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta); @@ -80,7 +83,7 @@ public: /// Checks if the block can stay at the specified relative coords in the chunk virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk); - + /** Checks if the block can be placed at this point. Default: CanBeAt(...) NOTE: This call doesn't actually place the block diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h index eb0918acf..81e3f2b8f 100644 --- a/src/Blocks/BlockRedstoneRepeater.h +++ b/src/Blocks/BlockRedstoneRepeater.h @@ -29,7 +29,7 @@ public: a_BlockMeta = RepeaterRotationToMetaData(a_Player->GetYaw()); return true; } - + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { @@ -37,6 +37,12 @@ public: } + virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override + { + a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { // Reset meta to 0 diff --git a/src/Blocks/BlockTNT.h b/src/Blocks/BlockTNT.h new file mode 100644 index 000000000..a9044d65e --- /dev/null +++ b/src/Blocks/BlockTNT.h @@ -0,0 +1,32 @@ + +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockTNTHandler : + public cBlockHandler +{ +public: + cBlockTNTHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + virtual const char * GetStepSound(void) override + { + return "step.wood"; + } + + virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override + { + a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); + } +}; + + + + diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index a28861e69..ffeebd647 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -42,6 +42,11 @@ public: World->BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0, a_Player->GetClientHandle()); } + virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override + { + a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); + } + virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 6982a6227..870568cdf 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -920,14 +920,22 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, ItemToFullString(a_HeldItem).c_str() ); + cWorld * World = m_Player->GetWorld(); + cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); if (PlgMgr->CallHookPlayerRightClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ)) { // A plugin doesn't agree with the action, replace the block on the client and quit: + cChunkInterface ChunkInterface(World->GetChunkMap()); + BLOCKTYPE BlockType = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType); + BlockHandler->OnCancelRightClick(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); + if (a_BlockFace > -1) { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); - m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); + World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); + World->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); //2 block high things } return; } @@ -953,12 +961,10 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e if (a_BlockFace > -1) { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); - m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); + World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); } return; } - - cWorld * World = m_Player->GetWorld(); BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; -- cgit v1.2.3 From ee1ba3e0b094ce80965eb2f1dd599fca6ff6736c Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 5 Mar 2014 15:14:20 +0100 Subject: Set tnt step sound to step.grass --- src/Blocks/BlockTNT.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/BlockTNT.h b/src/Blocks/BlockTNT.h index a9044d65e..f5cdecb9a 100644 --- a/src/Blocks/BlockTNT.h +++ b/src/Blocks/BlockTNT.h @@ -18,7 +18,7 @@ public: virtual const char * GetStepSound(void) override { - return "step.wood"; + return "step.grass"; } virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override -- cgit v1.2.3 From 86615428cd3d967c8bd73628fe8946405060d24c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 5 Mar 2014 18:28:42 +0100 Subject: APIDump: Ignoring classes by exact match. "cCompositeChat" was ignored because it matched "os". --- MCServer/Plugins/APIDump/APIDesc.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 0b6f33b37..1d30ea72d 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2701,16 +2701,16 @@ end IgnoreClasses = { - "coroutine", - "debug", - "io", - "math", - "package", - "os", - "string", - "table", - "g_Stats", - "g_TrackedPages", + "^coroutine$", + "^debug$", + "^io$", + "^math$", + "^package$", + "^os$", + "^string$", + "^table$", + "^g_Stats$", + "^g_TrackedPages$", }, IgnoreFunctions = -- cgit v1.2.3 From 036608c6453857e7faf3b32f05fa5d9f62b93fa0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 5 Mar 2014 18:56:32 +0100 Subject: APIDump: Documented the cCompositeChat class. --- MCServer/Plugins/APIDump/APIDesc.lua | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 1d30ea72d..94cdd0063 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -483,6 +483,58 @@ end }, }, -- cClientHandle + cCompositeChat = + { + Desc = [[ + Encapsulates a chat message that can contain various formatting, URLs, commands executed on click + and commands suggested on click. The chat message can be sent by the regular chat-sending functions, + {{cPlayer}}:SendMessage(), {{cWorld}}:BroadcastChat() and {{cRoot}}:BroadcastChat().

    +

    + Note that most of the functions in this class are so-called modifiers - they modify the object and + then return the object itself, so that they can be chained one after another. + ]], + Functions = + { + constructor = + { + { Params = "", Return = "", Notes = "Creates an empty chat message" }, + { Params = "Text", Return = "", Notes = "Creates a chat message containing the specified text, parsed by the ParseText() function. This allows easy migration from old chat messages." }, + }, + AddRunCommandPart = { Params = "Text, Command, [Style]", Return = "self", Notes = "Adds a text which, when clicked, runs the specified command. Chaining." }, + AddSuggestCommandPart = { Params = "Text, Command, [Style]", Return = "self", Notes = "Adds a text which, when clicked, puts the specified command into the player's chat input area. Chaining." }, + AddTextPart = { Params = "Text, [Style]", Return = "self", Notes = "Adds a regular text. Chaining." }, + AddUrlPart = { Params = "Text, Url, [Style]", Return = "self", Notes = "Adds a text which, when clicked, opens up a browser at the specified URL. Chaining." }, + Clear = { Params = "", Return = "", Notes = "Removes all parts from this object" }, + GetMessageType = { Params = "", Return = "MessageType", Notes = "Returns the MessageType (mtXXX constant) that is associated with this message. When sent to a player, the message will be formatted according to this message type and the player's settings (adding \"[INFO]\" prefix etc.)" }, + ParseText = { Params = "Text", Return = "self", Notes = "Adds text, while recognizing http and https URLs and old-style formatting codes (\"@2\"). Chaining." }, + SetMessageType = { Params = "MessageType", Return = "self", Notes = "Sets the MessageType (mtXXX constant) that is associated with this message. When sent to a player, the message will be formatted according to this message type and the player's settings (adding \"[INFO]\" prefix etc.) Chaining." }, + UnderlineUrls = { Params = "", Return = "self", Notes = "Makes all URL parts contained in the message underlined. Doesn't affect parts added in the future. Chaining." }, + }, + + AdditionalInfo = + { + { + Header = "Chaining example", + Contents = [[ + Sending a chat message that is composed of multiple different parts has been made easy thanks to + chaining. Consider the following example that shows how a message containing all kinds of parts + is sent (adapted from the Debuggers plugin): +

    +function OnPlayerJoined(a_Player)
    +	-- Send an example composite chat message to the player:
    +	a_Player:SendMessage(cCompositeChat()
    +		:AddTextPart("Hello, ")
    +		:AddUrlPart(a_Player:GetName(), "www.mc-server.org", "u@2")  -- Colored underlined link
    +		:AddSuggestCommandPart(", and welcome.", "/help", "u")       -- Underlined suggest-command
    +		:AddRunCommandPart(" SetDay", "/time set 0")                 -- Regular text that will execute command when clicked
    +		:SetMessageType(mtJoin)                                      -- It is a join-message
    +	)
    +end
    + ]], + }, + }, -- AdditionalInfo + }, -- cCompositeChat + cCraftingGrid = { Desc = [[ -- cgit v1.2.3 From dc0cbd594c05395b5d71af8a8a1f24b10c2d0d50 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 5 Mar 2014 19:17:59 +0100 Subject: The APIDump generates a list of all the permissions again. --- MCServer/Plugins/InfoDump.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index 59263d056..c61f9c9e6 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -530,12 +530,13 @@ local function DumpPermissionsGithub(a_PluginInfo, f) -- Dump the permissions: f:write("\n# Permissions\n"); + f:write("| Permissions | Description | Commands | Recommended groups |\n") + f:write("| ----------- | ----------- | -------- | ------------------ |\n") for idx, perm in ipairs(Permissions) do - f:write("### ", perm.Name, "\n"); - f:write(GithubizeString(perm.Info.Description or "")); + f:write(perm.Name, " | "); + f:write(GithubizeString(perm.Info.Description or ""), " | "); local CommandsAffected = perm.Info.CommandsAffected or {}; if (#CommandsAffected > 0) then - f:write("\n\nCommands affected:\n - "); local Affects = {}; for idx2, cmd in ipairs(CommandsAffected) do if (type(cmd) == "string") then @@ -544,11 +545,10 @@ local function DumpPermissionsGithub(a_PluginInfo, f) table.insert(Affects, GetCommandRefGithub(cmd.Name, cmd)); end end - f:write(table.concat(Affects, "\n - ")); - f:write("\n"); + f:write(table.concat(Affects, ", "), " | "); end if (perm.Info.RecommendedGroups ~= nil) then - f:write("\n\nRecommended groups: ", perm.Info.RecommendedGroups, "\n"); + f:write(perm.Info.RecommendedGroups, " |"); end f:write("\n"); end @@ -594,7 +594,7 @@ local function DumpPluginInfoGithub(a_PluginFolder, a_PluginInfo) f:write(GithubizeString(a_PluginInfo.Description), "\n"); DumpAdditionalInfoGithub(a_PluginInfo, f); DumpCommandsGithub(a_PluginInfo, f); - --DumpPermissionsGithub(a_PluginInfo, f); -- Seems a little overkill since they are already mentioned in the commands. + DumpPermissionsGithub(a_PluginInfo, f); f:close(); end -- cgit v1.2.3 From 594ddd86a04d895fdecb1cd4767031abc5c8dcca Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 5 Mar 2014 19:33:43 +0100 Subject: Add SendBlockTo to cWorldInterface --- src/Blocks/BlockComparator.h | 3 ++- src/Blocks/BlockDoor.cpp | 8 +++++--- src/Blocks/BlockFenceGate.h | 2 +- src/Blocks/BlockHandler.h | 2 +- src/Blocks/BlockRedstoneRepeater.h | 3 ++- src/Blocks/BlockTNT.h | 2 +- src/Blocks/BlockTrapdoor.h | 3 ++- src/Blocks/WorldInterface.h | 3 +++ src/World.h | 2 +- 9 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index b0ac75aaf..cea35a864 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -28,7 +28,8 @@ public: virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override { - a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); + UNUSED(a_ChunkInterface); + a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); } diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index 6c51feab3..0acf04852 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -57,18 +57,20 @@ void cBlockDoorHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterfac void cBlockDoorHandler::OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) { + UNUSED(a_ChunkInterface); + + a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - a_Player->GetClientHandle()->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta); if (Meta & 8) { // Current block is top of the door - a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, a_Player); + a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, a_Player); } else { // Current block is bottom of the door - a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, a_Player); + a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, a_Player); } } diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index a14510724..1abe1eecf 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -50,7 +50,7 @@ public: virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override { - a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); + a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); } diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index fbb36d96a..50c2e2ad5 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -83,7 +83,7 @@ public: /// Checks if the block can stay at the specified relative coords in the chunk virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk); - + /** Checks if the block can be placed at this point. Default: CanBeAt(...) NOTE: This call doesn't actually place the block diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h index 81e3f2b8f..1e2a86949 100644 --- a/src/Blocks/BlockRedstoneRepeater.h +++ b/src/Blocks/BlockRedstoneRepeater.h @@ -39,7 +39,8 @@ public: virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override { - a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); + UNUSED(a_ChunkInterface); + a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); } diff --git a/src/Blocks/BlockTNT.h b/src/Blocks/BlockTNT.h index f5cdecb9a..283a03730 100644 --- a/src/Blocks/BlockTNT.h +++ b/src/Blocks/BlockTNT.h @@ -23,7 +23,7 @@ public: virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override { - a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); + a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); } }; diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index ffeebd647..9bae92c4d 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -44,7 +44,8 @@ public: virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override { - a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); + UNUSED(a_ChunkInterface); + a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); } virtual bool GetPlacementBlockTypeMeta( diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index b6f2f55a7..c38ffc6db 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -27,4 +27,7 @@ public: /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */ virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) = 0; + + /** If there is a block entity at the specified coords, sends it to the client specified */ + virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, cPlayer * a_Player) = 0; }; diff --git a/src/World.h b/src/World.h index 93397c014..69d0d6b41 100644 --- a/src/World.h +++ b/src/World.h @@ -455,7 +455,7 @@ public: // tolua_begin bool DigBlock (int a_X, int a_Y, int a_Z); - void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player ); + virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player); double GetSpawnX(void) const { return m_SpawnX; } double GetSpawnY(void) const { return m_SpawnY; } -- cgit v1.2.3 From 53231bebd650b9398060cee1434ad4c44152d36e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 5 Mar 2014 22:12:48 +0000 Subject: Added extra awesomeness to TNT + TNT now has a chance of flinging FallingBlock entities around * Improved TNT damage * Improved TNT spawning visuals * Possible fix for 'SetSwimState failure' messages in debug --- src/ChunkMap.cpp | 31 +- src/Entities/Entity.cpp | 380 +++++++++++++------------ src/Entities/Entity.h | 1 + src/Entities/FallingBlock.cpp | 19 +- src/Items/ItemLighter.h | 2 +- src/Simulator/IncrementalRedstoneSimulator.cpp | 2 +- src/World.cpp | 6 +- 7 files changed, 232 insertions(+), 209 deletions(-) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index b5795fbaf..b13337b44 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1832,8 +1832,17 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc. m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z); } + else if (m_World->GetTickRandomNumber(100) < 20) // 20% chance of flinging stuff around + { + if (!cBlockInfo::FullyOccupiesVoxel(area.GetBlockType(bx + x, by + y, bz + z))) + { + break; + } + m_World->SpawnFallingBlock(bx + x, by + y + 5, bz + z, area.GetBlockType(bx + x, by + y, bz + z), area.GetBlockMeta(bx + x, by + y, bz + z)); + } area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR); a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z)); + break; } } // switch (BlockType) } // for z @@ -1846,11 +1855,10 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ public cEntityCallback { public: - cTNTDamageCallback(cBoundingBox & a_bbTNT, Vector3d a_ExplosionPos, int a_ExplosionSize, int a_ExplosionSizeSq) : + cTNTDamageCallback(cBoundingBox & a_bbTNT, Vector3d a_ExplosionPos, int a_ExplosionSize) : m_bbTNT(a_bbTNT), m_ExplosionPos(a_ExplosionPos), - m_ExplosionSize(a_ExplosionSize), - m_ExplosionSizeSq(a_ExplosionSizeSq) + m_ExplosionSize(a_ExplosionSize) { } @@ -1873,14 +1881,16 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ } Vector3d AbsoluteEntityPos(abs(EntityPos.x), abs(EntityPos.y), abs(EntityPos.z)); - Vector3d MaxExplosionBoundary(m_ExplosionSizeSq, m_ExplosionSizeSq, m_ExplosionSizeSq); // Work out how far we are from the edge of the TNT's explosive effect AbsoluteEntityPos -= m_ExplosionPos; - AbsoluteEntityPos = MaxExplosionBoundary - AbsoluteEntityPos; - double FinalDamage = ((AbsoluteEntityPos.x + AbsoluteEntityPos.y + AbsoluteEntityPos.z) / 3) * m_ExplosionSize; - FinalDamage = a_Entity->GetMaxHealth() - abs(FinalDamage); + // All to positive + AbsoluteEntityPos.x = abs(AbsoluteEntityPos.x); + AbsoluteEntityPos.y = abs(AbsoluteEntityPos.y); + AbsoluteEntityPos.z = abs(AbsoluteEntityPos.z); + + double FinalDamage = (((1 / AbsoluteEntityPos.x) + (1 / AbsoluteEntityPos.y) + (1 / AbsoluteEntityPos.z)) * 2) * m_ExplosionSize; // Clip damage values if (FinalDamage > a_Entity->GetMaxHealth()) @@ -1888,7 +1898,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ else if (FinalDamage < 0) FinalDamage = 0; - if (!a_Entity->IsTNT()) // Don't apply damage to other TNT entities, they should be invincible + if (!a_Entity->IsTNT() && !a_Entity->IsFallingBlock()) // Don't apply damage to other TNT entities, they should be invincible { a_Entity->TakeDamage(dtExplosion, NULL, (int)FinalDamage, 0); } @@ -1898,7 +1908,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ if (distance_explosion.SqrLength() < 4096.0) { distance_explosion.Normalize(); - distance_explosion *= m_ExplosionSizeSq; + distance_explosion *= m_ExplosionSize * m_ExplosionSize; a_Entity->AddSpeed(distance_explosion); } @@ -1910,14 +1920,13 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ cBoundingBox & m_bbTNT; Vector3d m_ExplosionPos; int m_ExplosionSize; - int m_ExplosionSizeSq; }; cBoundingBox bbTNT(Vector3d(a_BlockX, a_BlockY, a_BlockZ), 0.5, 1); bbTNT.Expand(ExplosionSizeInt * 2, ExplosionSizeInt * 2, ExplosionSizeInt * 2); - cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), ExplosionSizeInt, ExplosionSizeSq); + cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), ExplosionSizeInt); ForEachEntity(TNTDamageCallback); // Wake up all simulators for the area, so that water and lava flows and sand falls into the blasted holes (FS #391): diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 96e8c15a5..3eac0e2e8 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -521,27 +521,35 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) { if (a_Chunk.IsValid()) { - HandlePhysics(a_Dt, a_Chunk); - } - } - if (a_Chunk.IsValid()) - { - TickBurning(a_Chunk); - } - if ((a_Chunk.IsValid()) && (GetPosY() < -46)) - { - TickInVoid(a_Chunk); - } - else - m_TicksSinceLastVoidDamage = 0; + cChunk * NextChunk = a_Chunk.GetNeighborChunk(POSX_TOINT, POSZ_TOINT); - if (IsMob() || IsPlayer()) - { - // Set swimming state - SetSwimState(a_Chunk); + if ((NextChunk == NULL) || !NextChunk->IsValid()) + { + return; + } + + TickBurning(*NextChunk); - // Handle drowning - HandleAir(); + if (GetPosY() < VOID_BOUNDARY) + { + TickInVoid(*NextChunk); + } + else + { + m_TicksSinceLastVoidDamage = 0; + } + + if (IsMob() || IsPlayer()) + { + // Set swimming state + SetSwimState(*NextChunk); + + // Handle drowning + HandleAir(); + } + + HandlePhysics(a_Dt, *NextChunk); + } } } @@ -562,7 +570,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) { // Outside of the world - + cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); // See if we can commit our changes. If not, we will discard them. if (NextChunk != NULL) @@ -571,210 +579,208 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) NextPos += (NextSpeed * a_Dt); SetPosition(NextPos); } + return; } - // Make sure we got the correct chunk and a valid one. No one ever knows... - cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); - if (NextChunk != NULL) + int RelBlockX = BlockX - (a_Chunk.GetPosX() * cChunkDef::Width); + int RelBlockZ = BlockZ - (a_Chunk.GetPosZ() * cChunkDef::Width); + BLOCKTYPE BlockIn = a_Chunk.GetBlock( RelBlockX, BlockY, RelBlockZ ); + BLOCKTYPE BlockBelow = (BlockY > 0) ? a_Chunk.GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; + if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block { - int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width); - int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width); - BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ ); - BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; - if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block + if (m_bOnGround) // check if it's still on the ground { - if (m_bOnGround) // check if it's still on the ground + if (!cBlockInfo::IsSolid(BlockBelow)) // Check if block below is air or water. { - if (!cBlockInfo::IsSolid(BlockBelow)) // Check if block below is air or water. - { - m_bOnGround = false; - } + m_bOnGround = false; } } - else - { - // Push out entity. - BLOCKTYPE GotBlock; + } + else + { + // Push out entity. + BLOCKTYPE GotBlock; - static const struct - { - int x, y, z; - } gCrossCoords[] = - { - { 1, 0, 0}, - {-1, 0, 0}, - { 0, 0, 1}, - { 0, 0, -1}, - } ; - - bool IsNoAirSurrounding = true; - for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) + static const struct + { + int x, y, z; + } gCrossCoords[] = + { + { 1, 0, 0}, + {-1, 0, 0}, + { 0, 0, 1}, + { 0, 0, -1}, + } ; + + bool IsNoAirSurrounding = true; + for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) + { + if (!a_Chunk.UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock)) { - if (!NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock)) - { - // The pickup is too close to an unloaded chunk, bail out of any physics handling - return; - } - if (!cBlockInfo::IsSolid(GotBlock)) - { - NextPos.x += gCrossCoords[i].x; - NextPos.z += gCrossCoords[i].z; - IsNoAirSurrounding = false; - break; - } - } // for i - gCrossCoords[] - - if (IsNoAirSurrounding) + // The pickup is too close to an unloaded chunk, bail out of any physics handling + return; + } + if (!cBlockInfo::IsSolid(GotBlock)) { - NextPos.y += 0.5; + NextPos.x += gCrossCoords[i].x; + NextPos.z += gCrossCoords[i].z; + IsNoAirSurrounding = false; + break; } + } // for i - gCrossCoords[] + + if (IsNoAirSurrounding) + { + NextPos.y += 0.5; + } - m_bOnGround = true; + m_bOnGround = true; - /* - // DEBUG: - LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}", - m_UniqueID, GetClass(), BlockX, BlockY, BlockZ - ); - */ - } + /* + // DEBUG: + LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}", + m_UniqueID, GetClass(), BlockX, BlockY, BlockZ + ); + */ + } - if (!m_bOnGround) + if (!m_bOnGround) + { + float fallspeed; + if (IsBlockWater(BlockIn)) { - float fallspeed; - if (IsBlockWater(BlockIn)) - { - fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water. - } - else if (BlockIn == E_BLOCK_COBWEB) - { - NextSpeed.y *= 0.05; // Reduce overall falling speed - fallspeed = 0; // No falling. - } - else - { - // Normal gravity - fallspeed = m_Gravity * a_Dt; - } - NextSpeed.y += fallspeed; + fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water. + } + else if (BlockIn == E_BLOCK_COBWEB) + { + NextSpeed.y *= 0.05; // Reduce overall falling speed + fallspeed = 0; // No falling. } else { - // Friction - if (NextSpeed.SqrLength() > 0.0004f) + // Normal gravity + fallspeed = m_Gravity * a_Dt; + } + NextSpeed.y += fallspeed; + } + else + { + // Friction + if (NextSpeed.SqrLength() > 0.0004f) + { + NextSpeed.x *= 0.7f / (1 + a_Dt); + if (fabs(NextSpeed.x) < 0.05) { - NextSpeed.x *= 0.7f / (1 + a_Dt); - if (fabs(NextSpeed.x) < 0.05) - { - NextSpeed.x = 0; - } - NextSpeed.z *= 0.7f / (1 + a_Dt); - if (fabs(NextSpeed.z) < 0.05) - { - NextSpeed.z = 0; - } + NextSpeed.x = 0; + } + NextSpeed.z *= 0.7f / (1 + a_Dt); + if (fabs(NextSpeed.z) < 0.05) + { + NextSpeed.z = 0; } } + } - // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we - // might have different speed modifiers according to terrain. - if (BlockIn == E_BLOCK_COBWEB) - { - NextSpeed.x *= 0.25; - NextSpeed.z *= 0.25; - } + // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we + // might have different speed modifiers according to terrain. + if (BlockIn == E_BLOCK_COBWEB) + { + NextSpeed.x *= 0.25; + NextSpeed.z *= 0.25; + } - //Get water direction - Direction WaterDir = m_World->GetWaterSimulator()->GetFlowingDirection(BlockX, BlockY, BlockZ); + //Get water direction + Direction WaterDir = m_World->GetWaterSimulator()->GetFlowingDirection(BlockX, BlockY, BlockZ); - m_WaterSpeed *= 0.9f; //Reduce speed each tick + m_WaterSpeed *= 0.9f; //Reduce speed each tick - switch(WaterDir) - { - case X_PLUS: - m_WaterSpeed.x = 0.2f; - m_bOnGround = false; - break; - case X_MINUS: - m_WaterSpeed.x = -0.2f; - m_bOnGround = false; - break; - case Z_PLUS: - m_WaterSpeed.z = 0.2f; - m_bOnGround = false; - break; - case Z_MINUS: - m_WaterSpeed.z = -0.2f; - m_bOnGround = false; - break; - - default: + switch(WaterDir) + { + case X_PLUS: + m_WaterSpeed.x = 0.2f; + m_bOnGround = false; break; - } + case X_MINUS: + m_WaterSpeed.x = -0.2f; + m_bOnGround = false; + break; + case Z_PLUS: + m_WaterSpeed.z = 0.2f; + m_bOnGround = false; + break; + case Z_MINUS: + m_WaterSpeed.z = -0.2f; + m_bOnGround = false; + break; + + default: + break; + } - if (fabs(m_WaterSpeed.x) < 0.05) - { - m_WaterSpeed.x = 0; - } + if (fabs(m_WaterSpeed.x) < 0.05) + { + m_WaterSpeed.x = 0; + } - if (fabs(m_WaterSpeed.z) < 0.05) - { - m_WaterSpeed.z = 0; - } + if (fabs(m_WaterSpeed.z) < 0.05) + { + m_WaterSpeed.z = 0; + } - NextSpeed += m_WaterSpeed; + NextSpeed += m_WaterSpeed; - if( NextSpeed.SqrLength() > 0.f ) + if( NextSpeed.SqrLength() > 0.f ) + { + cTracer Tracer( GetWorld() ); + int Ret = Tracer.Trace( NextPos, NextSpeed, 2 ); + if( Ret ) // Oh noez! we hit something { - cTracer Tracer( GetWorld() ); - int Ret = Tracer.Trace( NextPos, NextSpeed, 2 ); - if( Ret ) // Oh noez! we hit something + // Set to hit position + if( (Tracer.RealHit - NextPos).SqrLength() <= ( NextSpeed * a_Dt ).SqrLength() ) { - // Set to hit position - if( (Tracer.RealHit - NextPos).SqrLength() <= ( NextSpeed * a_Dt ).SqrLength() ) + if( Ret == 1 ) { - if( Ret == 1 ) + if( Tracer.HitNormal.x != 0.f ) NextSpeed.x = 0.f; + if( Tracer.HitNormal.y != 0.f ) NextSpeed.y = 0.f; + if( Tracer.HitNormal.z != 0.f ) NextSpeed.z = 0.f; + + if( Tracer.HitNormal.y > 0 ) // means on ground { - if( Tracer.HitNormal.x != 0.f ) NextSpeed.x = 0.f; - if( Tracer.HitNormal.y != 0.f ) NextSpeed.y = 0.f; - if( Tracer.HitNormal.z != 0.f ) NextSpeed.z = 0.f; - - if( Tracer.HitNormal.y > 0 ) // means on ground - { - m_bOnGround = true; - } + m_bOnGround = true; } - NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z); - NextPos.x += Tracer.HitNormal.x * 0.3f; - NextPos.y += Tracer.HitNormal.y * 0.05f; // Any larger produces entity vibration-upon-the-spot - NextPos.z += Tracer.HitNormal.z * 0.3f; - } - else - { - NextPos += (NextSpeed * a_Dt); } + NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z); + NextPos.x += Tracer.HitNormal.x * 0.3f; + NextPos.y += Tracer.HitNormal.y * 0.05f; // Any larger produces entity vibration-upon-the-spot + NextPos.z += Tracer.HitNormal.z * 0.3f; } else { - // We didn't hit anything, so move =] NextPos += (NextSpeed * a_Dt); } } - BlockX = (int) floor(NextPos.x); - BlockZ = (int) floor(NextPos.z); - NextChunk = NextChunk->GetNeighborChunk(BlockX,BlockZ); - // See if we can commit our changes. If not, we will discard them. - if (NextChunk != NULL) + else { - if (NextPos.x != GetPosX()) SetPosX(NextPos.x); - if (NextPos.y != GetPosY()) SetPosY(NextPos.y); - if (NextPos.z != GetPosZ()) SetPosZ(NextPos.z); - if (NextSpeed.x != GetSpeedX()) SetSpeedX(NextSpeed.x); - if (NextSpeed.y != GetSpeedY()) SetSpeedY(NextSpeed.y); - if (NextSpeed.z != GetSpeedZ()) SetSpeedZ(NextSpeed.z); + // We didn't hit anything, so move =] + NextPos += (NextSpeed * a_Dt); } } + + BlockX = (int) floor(NextPos.x); + BlockZ = (int) floor(NextPos.z); + + cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); + // See if we can commit our changes. If not, we will discard them. + if (NextChunk != NULL) + { + if (NextPos.x != GetPosX()) SetPosX(NextPos.x); + if (NextPos.y != GetPosY()) SetPosY(NextPos.y); + if (NextPos.z != GetPosZ()) SetPosZ(NextPos.z); + if (NextSpeed.x != GetSpeedX()) SetSpeedX(NextSpeed.x); + if (NextSpeed.y != GetSpeedY()) SetSpeedY(NextSpeed.y); + if (NextSpeed.z != GetSpeedZ()) SetSpeedZ(NextSpeed.z); + } } @@ -815,14 +821,13 @@ void cEntity::TickBurning(cChunk & a_Chunk) { int RelX = x; int RelZ = z; - cChunk * CurChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelX, RelZ); - if (CurChunk == NULL) - { - continue; - } + for (int y = MinY; y <= MaxY; y++) { - switch (CurChunk->GetBlock(RelX, y, RelZ)) + BLOCKTYPE Block; + a_Chunk.UnboundedRelGetBlockType(RelX, y, RelZ, Block); + + switch (Block) { case E_BLOCK_FIRE: { @@ -922,7 +927,7 @@ void cEntity::TickInVoid(cChunk & a_Chunk) void cEntity::SetSwimState(cChunk & a_Chunk) { - int RelY = (int)floor(m_LastPosY + 0.1); + int RelY = (int)floor(GetPosY() + 0.1); if ((RelY < 0) || (RelY >= cChunkDef::Height - 1)) { m_IsSwimming = false; @@ -931,11 +936,10 @@ void cEntity::SetSwimState(cChunk & a_Chunk) } BLOCKTYPE BlockIn; - int RelX = (int)floor(m_LastPosX) - a_Chunk.GetPosX() * cChunkDef::Width; - int RelZ = (int)floor(m_LastPosZ) - a_Chunk.GetPosZ() * cChunkDef::Width; + int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; // Check if the player is swimming: - // Use Unbounded, because we're being called *after* processing super::Tick(), which could have changed our chunk if (!a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockIn)) { // This sometimes happens on Linux machines diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index b3b1cef83..ee3f25cd8 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -119,6 +119,7 @@ public: BURN_TICKS = 200, ///< How long to keep an entity burning after it has stood in lava / fire MAX_AIR_LEVEL = 300, ///< Maximum air an entity can have DROWNING_TICKS = 20, ///< Number of ticks per heart of damage + VOID_BOUNDARY = -46 ///< At what position Y to begin applying void damage } ; cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height); diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index 9fcd9ac80..a66c7e4ae 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -33,20 +33,16 @@ void cFallingBlock::SpawnOn(cClientHandle & a_ClientHandle) void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) { - float MilliDt = a_Dt * 0.001f; - AddSpeedY(MilliDt * -9.8f); - AddPosY(GetSpeedY() * MilliDt); - // GetWorld()->BroadcastTeleportEntity(*this); // Test position - int BlockX = m_OriginalPosition.x; + int BlockX = POSX_TOINT; int BlockY = (int)(GetPosY() - 0.5); - int BlockZ = m_OriginalPosition.z; + int BlockZ = POSZ_TOINT; if (BlockY < 0) { // Fallen out of this world, just continue falling until out of sight, then destroy: - if (BlockY < 100) + if (BlockY < VOID_BOUNDARY) { Destroy(true); } @@ -86,6 +82,15 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) Destroy(true); return; } + + float MilliDt = a_Dt * 0.001f; + AddSpeedY(MilliDt * -9.8f); + AddPosition(GetSpeed() * MilliDt); + + if ((GetSpeedX() != 0) || (GetSpeedZ() != 0)) + { + BroadcastMovementUpdate(); + } } diff --git a/src/Items/ItemLighter.h b/src/Items/ItemLighter.h index cc7daeb08..a828cd4fa 100644 --- a/src/Items/ItemLighter.h +++ b/src/Items/ItemLighter.h @@ -34,8 +34,8 @@ public: { // Activate the TNT: a_World->BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); - a_World->SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom a_World->SetBlock(a_BlockX,a_BlockY,a_BlockZ, E_BLOCK_AIR, 0); + a_World->SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom break; } default: diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 0640227b0..c9305b8ff 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -838,8 +838,8 @@ void cIncrementalRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_ if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) { m_World.BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); - m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom } } diff --git a/src/World.cpp b/src/World.cpp index ffdae2a37..d6b88f187 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1696,7 +1696,11 @@ void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, double a_FuseTim UNUSED(a_InitialVelocityCoeff); cTNTEntity * TNT = new cTNTEntity(a_X, a_Y, a_Z, a_FuseTimeInSec); TNT->Initialize(this); - // TODO: Add a bit of speed in horiz and vert axes, based on the a_InitialVelocityCoeff + TNT->SetSpeed( + a_InitialVelocityCoeff * (GetTickRandomNumber(2) - 1), /** -1, 0, 1 */ + a_InitialVelocityCoeff * 2, + a_InitialVelocityCoeff * (GetTickRandomNumber(2) - 1) + ); } -- cgit v1.2.3 From 99b9e6dce5ee49c1062074ce9f6d0669b2b265cc Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 6 Mar 2014 11:08:47 +0100 Subject: Broadcast the Equipped Item, if the Slot is changed. --- src/Inventory.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Inventory.cpp b/src/Inventory.cpp index 7f434adfd..c7c089d5f 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -204,6 +204,12 @@ void cInventory::SetSlot(int a_SlotNum, const cItem & a_Item) return; } Grid->SetSlot(GridSlotNum, a_Item); + + // Broadcast the Equipped Item, if the Slot is changed. + if ((Grid == &m_HotbarSlots) && (m_EquippedSlotNum == (a_SlotNum - invHotbarOffset))) + { + m_Owner.GetWorld()->BroadcastEntityEquipment(m_Owner, 0, a_Item, m_Owner.GetClientHandle()); + } } -- cgit v1.2.3 From 1c7a580e520ba6c28936e46d36abba658bd477b1 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 6 Mar 2014 13:35:53 +0100 Subject: Fix comment --- src/Blocks/WorldInterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index c38ffc6db..e59b00eff 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -28,6 +28,6 @@ public: /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */ virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) = 0; - /** If there is a block entity at the specified coords, sends it to the client specified */ + /** Sends the block on those coords to the player */ virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, cPlayer * a_Player) = 0; }; -- cgit v1.2.3 From 787a71929cd4095681b37acf81332b7b9c3ddf89 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 7 Mar 2014 01:30:34 +0100 Subject: Add Flower Pots --- src/Bindings/ManualBindings.cpp | 2 + src/BlockEntities/BlockEntity.cpp | 2 + src/BlockEntities/FlowerPotEntity.cpp | 134 ++++++++++++++++++++++++++++++++ src/BlockEntities/FlowerPotEntity.h | 74 ++++++++++++++++++ src/Blocks/BlockFlowerPot.h | 83 +------------------- src/Chunk.cpp | 35 +++++++++ src/Chunk.h | 7 +- src/ChunkMap.cpp | 18 +++++ src/ChunkMap.h | 5 ++ src/Protocol/Protocol17x.cpp | 16 +++- src/World.cpp | 9 +++ src/World.h | 9 ++- src/WorldStorage/NBTChunkSerializer.cpp | 15 ++++ src/WorldStorage/NBTChunkSerializer.h | 2 + src/WorldStorage/WSSAnvil.cpp | 36 +++++++++ src/WorldStorage/WSSAnvil.h | 1 + src/WorldStorage/WSSCompact.cpp | 40 +++++++++- 17 files changed, 401 insertions(+), 87 deletions(-) create mode 100644 src/BlockEntities/FlowerPotEntity.cpp create mode 100644 src/BlockEntities/FlowerPotEntity.h diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 9fbc2e842..3570b2c1e 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -23,6 +23,7 @@ #include "../BlockEntities/HopperEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/MobHeadEntity.h" +#include "../BlockEntities/FlowerPotEntity.h" #include "md5/md5.h" #include "../LineBlockTracer.h" #include "../WorldStorage/SchematicFileSerializer.h" @@ -2820,6 +2821,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithMobHeadBlockAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithFlowerPotAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk); diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 57ad83de9..b42318c2f 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -10,6 +10,7 @@ #include "DispenserEntity.h" #include "DropperEntity.h" #include "EnderChestEntity.h" +#include "FlowerPotEntity.h" #include "FurnaceEntity.h" #include "HopperEntity.h" #include "JukeboxEntity.h" @@ -30,6 +31,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_FLOWER_POT: return new cFlowerPotEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); diff --git a/src/BlockEntities/FlowerPotEntity.cpp b/src/BlockEntities/FlowerPotEntity.cpp new file mode 100644 index 000000000..87bf8b921 --- /dev/null +++ b/src/BlockEntities/FlowerPotEntity.cpp @@ -0,0 +1,134 @@ + +// FlowerPotEntity.cpp + +// Implements the cFlowerPotEntity class representing a single sign in the world + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules +#include "json/json.h" +#include "FlowerPotEntity.h" +#include "../Entities/Player.h" +#include "../Item.h" + + + + + +cFlowerPotEntity::cFlowerPotEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + super(E_BLOCK_FLOWER_POT, a_BlockX, a_BlockY, a_BlockZ, a_World) +{ +} + + + + + +// It don't do anything when 'used' +void cFlowerPotEntity::UsedBy(cPlayer * a_Player) +{ + if (IsItemInPot()) + { + return; + } + + cItem SelectedItem = a_Player->GetInventory().GetEquippedItem(); + if (IsFlower(SelectedItem.m_ItemType, SelectedItem.m_ItemDamage)) + { + m_Item = SelectedItem.CopyOne(); + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); + } + m_World->BroadcastBlockEntity(m_PosX, m_PosY, m_PosZ, a_Player->GetClientHandle()); + } +} + + + + + +void cFlowerPotEntity::SendTo(cClientHandle & a_Client) +{ + a_Client.SendUpdateBlockEntity(*this); +} + + + + + +void cFlowerPotEntity::Destroy(void) +{ + // Drop the contents as pickups: + if (!m_Item.IsEmpty()) + { + ASSERT(m_World != NULL); + cItems Pickups; + Pickups.Add(m_Item); + m_World->SpawnItemPickups(Pickups, m_PosX + 0.5, m_PosY + 0.5, m_PosZ + 0.5); + + m_Item.Empty(); + } +} + + + + + +bool cFlowerPotEntity::LoadFromJson(const Json::Value & a_Value) +{ + m_PosX = a_Value.get("x", 0).asInt(); + m_PosY = a_Value.get("y", 0).asInt(); + m_PosZ = a_Value.get("z", 0).asInt(); + + m_Item = cItem(); + m_Item.FromJson(a_Value.get("Item", 0)); + + return true; +} + + + + + +void cFlowerPotEntity::SaveToJson(Json::Value & a_Value) +{ + a_Value["x"] = m_PosX; + a_Value["y"] = m_PosY; + a_Value["z"] = m_PosZ; + + Json::Value Item; + m_Item.GetJson(Item); + a_Value["Item"] = Item; +} + + + + + +bool cFlowerPotEntity::IsFlower(short m_ItemType, short m_ItemData) +{ + switch (m_ItemType) + { + case E_BLOCK_DANDELION: + case E_BLOCK_FLOWER: + case E_BLOCK_CACTUS: + case E_BLOCK_BROWN_MUSHROOM: + case E_BLOCK_RED_MUSHROOM: + case E_BLOCK_SAPLING: + case E_BLOCK_DEAD_BUSH: + { + return true; + } + case E_BLOCK_TALL_GRASS: + { + return (m_ItemData == (short) 2); + } + default: + { + return false; + } + } +} + + + + diff --git a/src/BlockEntities/FlowerPotEntity.h b/src/BlockEntities/FlowerPotEntity.h new file mode 100644 index 000000000..da3fe9b7e --- /dev/null +++ b/src/BlockEntities/FlowerPotEntity.h @@ -0,0 +1,74 @@ +// FlowerPotEntity.h + +// Declares the cFlowerPotEntity class representing a single sign in the world + + + + + +#pragma once + +#include "BlockEntity.h" + +class cItem; + + + + + +namespace Json +{ + class Value; +} + + + + + +// tolua_begin + +class cFlowerPotEntity : + public cBlockEntity +{ + typedef cBlockEntity super; + +public: + + // tolua_end + + /** Creates a new flowerpot entity at the specified block coords. a_World may be NULL */ + cFlowerPotEntity(int a_BlocX, int a_BlockY, int a_BlockZ, cWorld * a_World); + + bool LoadFromJson( const Json::Value& a_Value ); + virtual void SaveToJson(Json::Value& a_Value ) override; + + virtual void Destroy(void) override; + + // tolua_begin + + /** Is a flower in the pot? */ + bool IsItemInPot(void) { return !m_Item.IsEmpty(); } + + /** Get the item in the flower pot */ + cItem GetItem(void) const { return m_Item; } + + /** Set the item in the flower pot */ + void SetItem(const cItem a_Item) { m_Item = a_Item; } + + // tolua_end + + virtual void UsedBy(cPlayer * a_Player) override; + virtual void SendTo(cClientHandle & a_Client) override; + + static bool IsFlower(short m_ItemType, short m_ItemData); + + static const char * GetClassStatic(void) { return "cFlowerPotEntity"; } + +private: + + cItem m_Item; +} ; // tolua_export + + + + diff --git a/src/Blocks/BlockFlowerPot.h b/src/Blocks/BlockFlowerPot.h index 4de85f629..fc75ef638 100644 --- a/src/Blocks/BlockFlowerPot.h +++ b/src/Blocks/BlockFlowerPot.h @@ -2,101 +2,24 @@ #pragma once #include "BlockHandler.h" +#include "BlockEntity.h" class cBlockFlowerPotHandler : - public cBlockHandler + public cBlockEntityHandler { public: cBlockFlowerPotHandler(BLOCKTYPE a_BlockType) : - cBlockHandler(a_BlockType) + cBlockEntityHandler(a_BlockType) { } - virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { a_Pickups.push_back(cItem(E_ITEM_FLOWER_POT, 1, 0)); - if (a_BlockMeta == 0) - { - return; - } - cItem Plant; - switch (a_BlockMeta) - { - case 1: Plant = cItem(E_BLOCK_RED_ROSE, 1, 0); break; - case 2: Plant = cItem(E_BLOCK_YELLOW_FLOWER, 1, 0); break; - case 3: Plant = cItem(E_BLOCK_SAPLING, 1, E_META_SAPLING_APPLE); break; - case 4: Plant = cItem(E_BLOCK_SAPLING, 1, E_META_SAPLING_CONIFER); break; - case 5: Plant = cItem(E_BLOCK_SAPLING, 1, E_META_SAPLING_BIRCH); break; - case 6: Plant = cItem(E_BLOCK_SAPLING, 1, E_META_SAPLING_JUNGLE); break; - case 7: Plant = cItem(E_BLOCK_RED_MUSHROOM, 1, 0); break; - case 8: Plant = cItem(E_BLOCK_BROWN_MUSHROOM, 1, 0); break; - case 9: Plant = cItem(E_BLOCK_CACTUS, 1, 0); break; - case 10: Plant = cItem(E_BLOCK_DEAD_BUSH, 1, 0); break; - case 11: Plant = cItem(E_BLOCK_TALL_GRASS, 1, E_META_TALL_GRASS_FERN); break; - default: return; - } - a_Pickups.push_back(Plant); - } - - - void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) - { - NIBBLETYPE Meta = a_World->GetBlockMeta( a_BlockX, a_BlockY, a_BlockZ ); - if (Meta != 0) - { - // Already filled - return; - } - - switch (a_Player->GetEquippedItem().m_ItemType) - { - case E_BLOCK_RED_ROSE: Meta = 1; break; - case E_BLOCK_YELLOW_FLOWER: Meta = 2; break; - case E_BLOCK_SAPLING: - { - switch (a_Player->GetEquippedItem().m_ItemDamage) - { - case E_META_SAPLING_APPLE: Meta = 3; break; - case E_META_SAPLING_CONIFER: Meta = 4; break; - case E_META_SAPLING_BIRCH: Meta = 5; break; - case E_META_SAPLING_JUNGLE: Meta = 6; break; - } - break; - } - case E_BLOCK_RED_MUSHROOM: Meta = 7; break; - case E_BLOCK_BROWN_MUSHROOM: Meta = 8; break; - case E_BLOCK_CACTUS: Meta = 9; break; - case E_BLOCK_DEAD_BUSH: Meta = 10; break; - case E_BLOCK_TALL_GRASS: - { - if (a_Player->GetEquippedItem().m_ItemDamage == E_META_TALL_GRASS_FERN) - { - Meta = 11; - } - else - { - return; - } - break; - } - } - - if (a_Player->GetGameMode() != gmCreative) - { - a_Player->GetInventory().RemoveOneEquippedItem(); - } - a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); - } - - - virtual bool IsUseable(void) override - { - return true; } } ; diff --git a/src/Chunk.cpp b/src/Chunk.cpp index a75828461..b5b776147 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -20,6 +20,7 @@ #include "BlockEntities/NoteEntity.h" #include "BlockEntities/SignEntity.h" #include "BlockEntities/MobHeadEntity.h" +#include "BlockEntities/FlowerPotEntity.h" #include "Entities/Pickup.h" #include "Item.h" #include "Noise.h" @@ -1311,6 +1312,7 @@ void cChunk::CreateBlockEntities(void) case E_BLOCK_HEAD: case E_BLOCK_NOTE_BLOCK: case E_BLOCK_JUKEBOX: + case E_BLOCK_FLOWER_POT: { if (!HasBlockEntityAt(x + m_PosX * Width, y + m_PosY * Height, z + m_PosZ * Width)) { @@ -1440,6 +1442,7 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, case E_BLOCK_HEAD: case E_BLOCK_NOTE_BLOCK: case E_BLOCK_JUKEBOX: + case E_BLOCK_FLOWER_POT: { AddBlockEntity(cBlockEntity::CreateByBlockType(a_BlockType, a_BlockMeta, WorldPos.x, WorldPos.y, WorldPos.z, m_World)); break; @@ -2369,6 +2372,38 @@ bool cChunk::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMob +bool cChunk::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback) +{ + // The blockentity list is locked by the parent chunkmap's CS + for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2) + { + ++itr2; + if (((*itr)->GetPosX() != a_BlockX) || ((*itr)->GetPosY() != a_BlockY) || ((*itr)->GetPosZ() != a_BlockZ)) + { + continue; + } + if ((*itr)->GetBlockType() != E_BLOCK_FLOWER_POT) + { + // There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out + return false; + } + + // The correct block entity is here, + if (a_Callback.Item((cFlowerPotEntity *)*itr)) + { + return false; + } + return true; + } // for itr - m_BlockEntitites[] + + // Not found: + return false; +} + + + + + bool cChunk::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { // The blockentity list is locked by the parent chunkmap's CS diff --git a/src/Chunk.h b/src/Chunk.h index c9e9697ca..e8b46f631 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -32,6 +32,7 @@ class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; class cMobHeadEntity; +class cFlowerPotEntity; class cBlockArea; class cPawn; class cPickup; @@ -49,6 +50,7 @@ typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; typedef cItemCallback cMobHeadBlockCallback; +typedef cItemCallback cFlowerPotCallback; @@ -253,9 +255,12 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); - /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob header block at those coords or callback returns true, returns true if found */ + /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); + /** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */ + bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback); + /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index b5795fbaf..7f999fd31 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2200,6 +2200,24 @@ bool cChunkMap::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c +bool cChunkMap::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback) +{ + int ChunkX, ChunkZ; + int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; + cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + if ((Chunk == NULL) && !Chunk->IsValid()) + { + return false; + } + return Chunk->DoWithFlowerPotAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); +} + + + + + bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { int ChunkX, ChunkZ; diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 9df68c403..6d35b2ebf 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -26,6 +26,7 @@ class cFurnaceEntity; class cNoteEntity; class cCommandBlockEntity; class cMobHeadEntity; +class cFlowerPotEntity; class cPawn; class cPickup; class cChunkDataSerializer; @@ -41,6 +42,7 @@ typedef cItemCallback cChestCallback; typedef cItemCallback cDispenserCallback; typedef cItemCallback cDropperCallback; typedef cItemCallback cDropSpenserCallback; +typedef cItemCallback cFlowerPotCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; @@ -259,6 +261,9 @@ public: /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Lua-accessible + /** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */ + bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback); // Lua-accessible + /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 992023464..18646254f 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -29,6 +29,7 @@ Implements the 1.7.x protocol classes: #include "../UI/Window.h" #include "../BlockEntities/CommandBlockEntity.h" #include "../BlockEntities/MobHeadEntity.h" +#include "../BlockEntities/FlowerPotEntity.h" #include "../CompositeChat.h" @@ -1115,6 +1116,7 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text case E_BLOCK_HEAD: Action = 4; break; // Update Mobhead entity + case E_BLOCK_FLOWER_POT: Action = 5; break; // Update flower pot default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break; } Pkt.WriteByte(Action); @@ -2345,7 +2347,7 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt case E_BLOCK_HEAD: { cMobHeadEntity & MobHeadEntity = (cMobHeadEntity &)a_BlockEntity; - + Writer.AddInt("x", MobHeadEntity.GetPosX()); Writer.AddInt("y", MobHeadEntity.GetPosY()); Writer.AddInt("z", MobHeadEntity.GetPosZ()); @@ -2355,6 +2357,18 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though break; } + case E_BLOCK_FLOWER_POT: + { + cFlowerPotEntity & FlowerPotEntity = (cFlowerPotEntity &)a_BlockEntity; + + Writer.AddInt("x", FlowerPotEntity.GetPosX()); + Writer.AddInt("y", FlowerPotEntity.GetPosY()); + Writer.AddInt("z", FlowerPotEntity.GetPosZ()); + Writer.AddInt("Item", (Int32) FlowerPotEntity.GetItem().m_ItemType); + Writer.AddInt("Data", (Int32) FlowerPotEntity.GetItem().m_ItemDamage); + Writer.AddString("id", "FlowerPot"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though + break; + } default: break; } diff --git a/src/World.cpp b/src/World.cpp index 37c07b398..335c6a00d 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1206,6 +1206,15 @@ bool cWorld::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMob +bool cWorld::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback) +{ + return m_ChunkMap->DoWithFlowerPotAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); +} + + + + + bool cWorld::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { return m_ChunkMap->GetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4); diff --git a/src/World.h b/src/World.h index 93397c014..ee74742c4 100644 --- a/src/World.h +++ b/src/World.h @@ -44,6 +44,7 @@ class cWorldGenerator; // The generator that actually generates the chunks for class cChunkGenerator; // The thread responsible for generating chunks class cChestEntity; class cDispenserEntity; +class cFlowerPotEntity; class cFurnaceEntity; class cNoteEntity; class cMobHeadEntity; @@ -61,6 +62,7 @@ typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; typedef cItemCallback cMobHeadBlockCallback; +typedef cItemCallback cFlowerPotCallback; @@ -531,10 +533,13 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Exported in ManualBindings.cpp - + /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Exported in ManualBindings.cpp - + + /** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */ + bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback); // Exported in ManualBindings.cpp + /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Exported in ManualBindings.cpp diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index c1c659b36..6d0e29958 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -20,6 +20,7 @@ #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" #include "../BlockEntities/MobHeadEntity.h" +#include "../BlockEntities/FlowerPotEntity.h" #include "../Entities/Entity.h" #include "../Entities/FallingBlock.h" @@ -275,6 +276,19 @@ void cNBTChunkSerializer::AddMobHeadEntity(cMobHeadEntity * a_MobHead) +void cNBTChunkSerializer::AddFlowerPotEntity(cFlowerPotEntity * a_FlowerPot) +{ + m_Writer.BeginCompound(""); + AddBasicTileEntity(a_FlowerPot, "FlowerPot"); + m_Writer.AddInt ("Item", (Int32) a_FlowerPot->GetItem().m_ItemType); + m_Writer.AddInt ("Data", (Int32) a_FlowerPot->GetItem().m_ItemDamage); + m_Writer.EndCompound(); +} + + + + + void cNBTChunkSerializer::AddBasicEntity(cEntity * a_Entity, const AString & a_ClassName) { m_Writer.AddString("id", a_ClassName); @@ -687,6 +701,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) case E_BLOCK_CHEST: AddChestEntity ((cChestEntity *) a_Entity); break; case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break; case E_BLOCK_DROPPER: AddDropperEntity ((cDropperEntity *) a_Entity); break; + case E_BLOCK_FLOWER_POT: AddFlowerPotEntity ((cFlowerPotEntity *) a_Entity); break; case E_BLOCK_FURNACE: AddFurnaceEntity ((cFurnaceEntity *) a_Entity); break; case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; case E_BLOCK_SIGN_POST: diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index 5f9e16ed1..8a9e18413 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -30,6 +30,7 @@ class cJukeboxEntity; class cNoteEntity; class cSignEntity; class cMobHeadEntity; +class cFlowerPotEntity; class cFallingBlock; class cMinecart; class cMinecartWithChest; @@ -96,6 +97,7 @@ protected: void AddSignEntity (cSignEntity * a_Sign); void AddMobHeadEntity (cMobHeadEntity * a_MobHead); void AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock); + void AddFlowerPotEntity(cFlowerPotEntity * a_FlowerPot); // Entities: void AddBasicEntity (cEntity * a_Entity, const AString & a_ClassName); diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 05332d23d..680f2458f 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -25,6 +25,7 @@ #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" #include "../BlockEntities/MobHeadEntity.h" +#include "../BlockEntities/FlowerPotEntity.h" #include "../Mobs/Monster.h" @@ -578,6 +579,10 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con { LoadDropperFromNBT(a_BlockEntities, a_NBT, Child); } + else if (strncmp(a_NBT.GetData(sID), "FlowerPot", a_NBT.GetDataLength(sID)) == 0) + { + LoadFlowerPotFromNBT(a_BlockEntities, a_NBT, Child); + } else if (strncmp(a_NBT.GetData(sID), "Furnace", a_NBT.GetDataLength(sID)) == 0) { LoadFurnaceFromNBT(a_BlockEntities, a_NBT, Child, a_BlockTypes, a_BlockMetas); @@ -760,6 +765,37 @@ void cWSSAnvil::LoadDropperFromNBT(cBlockEntityList & a_BlockEntities, const cPa +void cWSSAnvil::LoadFlowerPotFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); + int x, y, z; + if (!GetBlockEntityNBTPos(a_NBT, a_TagIdx, x, y, z)) + { + return; + } + std::auto_ptr FlowerPot(new cFlowerPotEntity(x, y, z, m_World)); + short ItemType = 0, ItemData = 0; + + int currentLine = a_NBT.FindChildByName(a_TagIdx, "Item"); + if (currentLine >= 0) + { + ItemType = (short) a_NBT.GetInt(currentLine); + } + + currentLine = a_NBT.FindChildByName(a_TagIdx, "Data"); + if (currentLine >= 0) + { + ItemData = (short) a_NBT.GetInt(currentLine); + } + + FlowerPot->SetItem(cItem(ItemType, 1, ItemData)); + a_BlockEntities.push_back(FlowerPot.release()); +} + + + + + void cWSSAnvil::LoadFurnaceFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas) { ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 4acf3f2a1..b26345b13 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -135,6 +135,7 @@ protected: void LoadChestFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadDispenserFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadDropperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadFlowerPotFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadFurnaceFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas); void LoadHopperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadJukeboxFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 4c0684dd8..5e49e4909 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -12,8 +12,10 @@ #include "../BlockEntities/ChestEntity.h" #include "../BlockEntities/CommandBlockEntity.h" #include "../BlockEntities/DispenserEntity.h" +#include "../BlockEntities/FlowerPotEntity.h" #include "../BlockEntities/FurnaceEntity.h" #include "../BlockEntities/JukeboxEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" @@ -75,12 +77,14 @@ void cJsonChunkSerializer::BlockEntity(cBlockEntity * a_BlockEntity) case E_BLOCK_CHEST: SaveInto = "Chests"; break; case E_BLOCK_DISPENSER: SaveInto = "Dispensers"; break; case E_BLOCK_DROPPER: SaveInto = "Droppers"; break; + case E_BLOCK_FLOWER_POT: SaveInto = "FlowerPots"; break; case E_BLOCK_FURNACE: SaveInto = "Furnaces"; break; case E_BLOCK_SIGN_POST: SaveInto = "Signs"; break; case E_BLOCK_WALLSIGN: SaveInto = "Signs"; break; case E_BLOCK_NOTE_BLOCK: SaveInto = "Notes"; break; case E_BLOCK_JUKEBOX: SaveInto = "Jukeboxes"; break; case E_BLOCK_COMMAND_BLOCK: SaveInto = "CommandBlocks"; break; + case E_BLOCK_HEAD: SaveInto = "MobHeads"; break; default: { @@ -298,6 +302,21 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En } } // for itr - AllDispensers[] + // Load Flowerpots: + Json::Value AllFlowerPots = a_Value.get("FlowerPots", Json::nullValue); + for (Json::Value::iterator itr = AllFlowerPots.begin(); itr != AllFlowerPots.end(); ++itr) + { + std::auto_ptr FlowerPotEntity(new cFlowerPotEntity(0, 0, 0, a_World)); + if (!FlowerPotEntity->LoadFromJson(*itr)) + { + LOGWARNING("ERROR READING FLOWERPOT FROM JSON!" ); + } + else + { + a_BlockEntities.push_back(FlowerPotEntity.release()); + } + } // for itr - AllFlowerPots[] + // Load furnaces: Json::Value AllFurnaces = a_Value.get("Furnaces", Json::nullValue); for (Json::Value::iterator itr = AllFurnaces.begin(); itr != AllFurnaces.end(); ++itr) @@ -331,7 +350,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En // Load note blocks: Json::Value AllNotes = a_Value.get("Notes", Json::nullValue); - for( Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr ) + for (Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr) { std::auto_ptr NoteEntity(new cNoteEntity(0, 0, 0, a_World)); if (!NoteEntity->LoadFromJson(*itr)) @@ -346,7 +365,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En // Load jukeboxes: Json::Value AllJukeboxes = a_Value.get("Jukeboxes", Json::nullValue); - for( Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr ) + for (Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr) { std::auto_ptr JukeboxEntity(new cJukeboxEntity(0, 0, 0, a_World)); if (!JukeboxEntity->LoadFromJson(*itr)) @@ -361,7 +380,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En // Load command blocks: Json::Value AllCommandBlocks = a_Value.get("CommandBlocks", Json::nullValue); - for( Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr ) + for (Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr) { std::auto_ptr CommandBlockEntity(new cCommandBlockEntity(0, 0, 0, a_World)); if (!CommandBlockEntity->LoadFromJson(*itr)) @@ -373,6 +392,21 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En a_BlockEntities.push_back(CommandBlockEntity.release()); } } // for itr - AllCommandBlocks[] + + // Load mob heads: + Json::Value AllMobHeads = a_Value.get("MobHeads", Json::nullValue); + for (Json::Value::iterator itr = AllMobHeads.begin(); itr != AllMobHeads.end(); ++itr) + { + std::auto_ptr MobHeadEntity(new cMobHeadEntity(0, 0, 0, a_World)); + if (!MobHeadEntity->LoadFromJson(*itr)) + { + LOGWARNING("ERROR READING MOB HEAD FROM JSON!" ); + } + else + { + a_BlockEntities.push_back(MobHeadEntity.release()); + } + } // for itr - AllMobHeads[] } -- cgit v1.2.3 From 97d803e34f51470774a6bfc2232cae0b041a1aa0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 7 Mar 2014 09:17:13 +0100 Subject: Added cBlockArea serialization to string. Fixes #665. --- src/Bindings/ManualBindings.cpp | 73 +++++++++++++-- src/WorldStorage/SchematicFileSerializer.cpp | 134 +++++++++++++++++++++------ src/WorldStorage/SchematicFileSerializer.h | 33 ++++++- 3 files changed, 202 insertions(+), 38 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 9fbc2e842..f9d04ce90 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2483,6 +2483,37 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) +static int tolua_cBlockArea_LoadFromSchematicString(lua_State * tolua_S) +{ + // function cBlockArea::LoadFromSchematicString + // Exported manually because function has been moved to SchematicFileSerilizer.cpp + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cBlockArea") || + !L.CheckParamString (2) || + !L.CheckParamEnd (3) + ) + { + return 0; + } + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::LoadFromSchematicFile'", NULL); + return 0; + } + + AString Data; + L.GetStackValue(2, Data); + bool res = cSchematicFileSerializer::LoadFromSchematicString(*self, Data); + tolua_pushboolean(tolua_S, res); + return 1; +} + + + + + static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) { // function cBlockArea::SaveToSchematicFile @@ -2512,6 +2543,34 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) +static int tolua_cBlockArea_SaveToSchematicString(lua_State * tolua_S) +{ + // function cBlockArea::SaveToSchematicString + // Exported manually because function has been moved to SchematicFileSerilizer.cpp + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cBlockArea") || + !L.CheckParamEnd (2) + ) + { + return 0; + } + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::SaveToSchematicFile'", NULL); + return 0; + } + + AString Data = cSchematicFileSerializer::SaveToSchematicString(*self); + L.Push(Data); + return 1; +} + + + + + static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S) { // function cCompositeChat:AddRunCommandPart(Message, Command, [Style]) @@ -2775,12 +2834,14 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cBlockArea"); - tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cBlockArea_GetBlockTypeMeta); - tolua_function(tolua_S, "GetOrigin", tolua_cBlockArea_GetOrigin); - tolua_function(tolua_S, "GetRelBlockTypeMeta", tolua_cBlockArea_GetRelBlockTypeMeta); - tolua_function(tolua_S, "GetSize", tolua_cBlockArea_GetSize); - tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile); - tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); + tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cBlockArea_GetBlockTypeMeta); + tolua_function(tolua_S, "GetOrigin", tolua_cBlockArea_GetOrigin); + tolua_function(tolua_S, "GetRelBlockTypeMeta", tolua_cBlockArea_GetRelBlockTypeMeta); + tolua_function(tolua_S, "GetSize", tolua_cBlockArea_GetSize); + tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile); + tolua_function(tolua_S, "LoadFromSchematicString", tolua_cBlockArea_LoadFromSchematicString); + tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); + tolua_function(tolua_S, "SaveToSchematicString", tolua_cBlockArea_SaveToSchematicString); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cCompositeChat"); diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp index 45fd967bd..a6ae8d8e0 100644 --- a/src/WorldStorage/SchematicFileSerializer.cpp +++ b/src/WorldStorage/SchematicFileSerializer.cpp @@ -1,10 +1,18 @@ +// SchematicFileSerializer.cpp + +// Implements the cSchematicFileSerializer class representing the interface to load and save cBlockArea to a .schematic file + #include "Globals.h" #include "OSSupport/GZipFile.h" #include "FastNBT.h" - #include "SchematicFileSerializer.h" +#include "../StringCompression.h" + + + + bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName) { @@ -40,48 +48,51 @@ bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea & a_BlockArea, c -bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName) +bool cSchematicFileSerializer::LoadFromSchematicString(cBlockArea & a_BlockArea, const AString & a_SchematicData) { - cFastNBTWriter Writer("Schematic"); - Writer.AddShort("Width", a_BlockArea.m_SizeX); - Writer.AddShort("Height", a_BlockArea.m_SizeY); - Writer.AddShort("Length", a_BlockArea.m_SizeZ); - Writer.AddString("Materials", "Alpha"); - if (a_BlockArea.HasBlockTypes()) + // Uncompress the data: + AString UngzippedData; + if (UncompressStringGZIP(a_SchematicData.data(), a_SchematicData.size(), UngzippedData) != Z_OK) { - Writer.AddByteArray("Blocks", (const char *)a_BlockArea.m_BlockTypes, a_BlockArea.GetBlockCount()); - } - else - { - AString Dummy(a_BlockArea.GetBlockCount(), 0); - Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size()); + LOG("%s: Cannot unGZip the schematic data.", __FUNCTION__); + return false; } - if (a_BlockArea.HasBlockMetas()) + + // Parse the NBT: + cParsedNBT NBT(UngzippedData.data(), UngzippedData.size()); + if (!NBT.IsValid()) { - Writer.AddByteArray("Data", (const char *)a_BlockArea.m_BlockMetas, a_BlockArea.GetBlockCount()); + LOG("%s: Cannot parse the NBT in the schematic data.", __FUNCTION__); + return false; } - else + + return LoadFromSchematicNBT(a_BlockArea, NBT); +} + + + + + +bool cSchematicFileSerializer::SaveToSchematicFile(const cBlockArea & a_BlockArea, const AString & a_FileName) +{ + // Serialize into NBT data: + AString NBT = SaveToSchematicNBT(a_BlockArea); + if (NBT.empty()) { - AString Dummy(a_BlockArea.GetBlockCount(), 0); - Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); + LOG("%s: Cannot serialize the area into an NBT representation for file \"%s\".", __FUNCTION__, a_FileName.c_str()); + return false; } - // TODO: Save entities and block entities - Writer.BeginList("Entities", TAG_Compound); - Writer.EndList(); - Writer.BeginList("TileEntities", TAG_Compound); - Writer.EndList(); - Writer.Finish(); // Save to file cGZipFile File; if (!File.Open(a_FileName, cGZipFile::fmWrite)) { - LOG("Cannot open file \"%s\" for writing.", a_FileName.c_str()); + LOG("%s: Cannot open file \"%s\" for writing.", __FUNCTION__, a_FileName.c_str()); return false; } - if (!File.Write(Writer.GetResult())) + if (!File.Write(NBT)) { - LOG("Cannot write data to file \"%s\".", a_FileName.c_str()); + LOG("%s: Cannot write data to file \"%s\".", __FUNCTION__, a_FileName.c_str()); return false; } return true; @@ -92,6 +103,31 @@ bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea & a_BlockArea, con +AString cSchematicFileSerializer::SaveToSchematicString(const cBlockArea & a_BlockArea) +{ + // Serialize into NBT data: + AString NBT = SaveToSchematicNBT(a_BlockArea); + if (NBT.empty()) + { + LOG("%s: Cannot serialize the area into an NBT representation.", __FUNCTION__); + return false; + } + + // Gzip the data: + AString Compressed; + int res = CompressStringGZIP(NBT.data(), NBT.size(), Compressed); + if (res != Z_OK) + { + LOG("%s: Cannot Gzip the area data NBT representation: %d", __FUNCTION__, res); + return false; + } + return Compressed; +} + + + + + bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT) { int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials"); @@ -170,3 +206,45 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP } + + + +AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockArea) +{ + cFastNBTWriter Writer("Schematic"); + Writer.AddShort("Width", a_BlockArea.m_SizeX); + Writer.AddShort("Height", a_BlockArea.m_SizeY); + Writer.AddShort("Length", a_BlockArea.m_SizeZ); + Writer.AddString("Materials", "Alpha"); + if (a_BlockArea.HasBlockTypes()) + { + Writer.AddByteArray("Blocks", (const char *)a_BlockArea.m_BlockTypes, a_BlockArea.GetBlockCount()); + } + else + { + AString Dummy(a_BlockArea.GetBlockCount(), 0); + Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size()); + } + if (a_BlockArea.HasBlockMetas()) + { + Writer.AddByteArray("Data", (const char *)a_BlockArea.m_BlockMetas, a_BlockArea.GetBlockCount()); + } + else + { + AString Dummy(a_BlockArea.GetBlockCount(), 0); + Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); + } + + // TODO: Save entities and block entities + Writer.BeginList("Entities", TAG_Compound); + Writer.EndList(); + Writer.BeginList("TileEntities", TAG_Compound); + Writer.EndList(); + Writer.Finish(); + + return Writer.GetResult(); +} + + + + diff --git a/src/WorldStorage/SchematicFileSerializer.h b/src/WorldStorage/SchematicFileSerializer.h index 9be2e5b57..f6ce1c16c 100644 --- a/src/WorldStorage/SchematicFileSerializer.h +++ b/src/WorldStorage/SchematicFileSerializer.h @@ -1,4 +1,12 @@ +// SchematicFileSerializer.h + +// Declares the cSchematicFileSerializer class representing the interface to load and save cBlockArea to a .schematic file + + + + + #pragma once #include "../BlockArea.h" @@ -13,17 +21,34 @@ class cParsedNBT; + class cSchematicFileSerializer { public: - /// Loads an area from a .schematic file. Returns true if successful + /** Loads an area from a .schematic file. Returns true if successful. */ static bool LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName); - /// Saves the area into a .schematic file. Returns true if successful - static bool SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName); + /** Loads an area from a string containing the .schematic file data. Returns true if successful. */ + static bool LoadFromSchematicString(cBlockArea & a_BlockArea, const AString & a_SchematicData); + + /** Saves the area into a .schematic file. Returns true if successful. */ + static bool SaveToSchematicFile(const cBlockArea & a_BlockArea, const AString & a_FileName); + + /** Saves the area into a string containing the .schematic file data. + Returns the data, or empty string if failed. */ + static AString SaveToSchematicString(const cBlockArea & a_BlockArea); private: - /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful. + /** Loads the area from a schematic file uncompressed and parsed into a NBT tree. + Returns true if successful. */ static bool LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT); + + /** Saves the area into a NBT representation and returns the NBT data as a string. + Returns an empty string if failed. */ + static AString SaveToSchematicNBT(const cBlockArea & a_BlockArea); }; + + + + -- cgit v1.2.3 From 166ab59582d90194a6fcd6849afe8f2e60d64019 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 7 Mar 2014 09:17:42 +0100 Subject: APIDump: Documented cBlockArea string-serialization functions. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 94cdd0063..30ce4cc2b 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -134,6 +134,7 @@ g_APIDesc = HasBlockSkyLights = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include skylight" }, HasBlockTypes = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include block types" }, LoadFromSchematicFile = { Params = "FileName", Return = "", Notes = "Clears current content and loads new content from the specified schematic file. Returns true if successful. Returns false and logs error if unsuccessful, old content is preserved in such a case." }, + LoadFromSchematicString = { Params = "SchematicData", Return = "", Notes = "Clears current content and loads new content from the specified string (assumed to contain .schematic data). Returns true if successful. Returns false and logs error if unsuccessful, old content is preserved in such a case." }, Merge = { { Params = "BlockAreaSrc, {{Vector3i|RelMinCoords}}, Strategy", Return = "", Notes = "Merges BlockAreaSrc into this object at the specified relative coords, using the specified strategy" }, @@ -161,6 +162,7 @@ g_APIDesc = RotateCW = { Params = "", Return = "", Notes = "Rotates the block area around the Y axis, clockwise (north -> east). Modifies blocks' metas (if present) to match." }, RotateCWNoMeta = { Params = "", Return = "", Notes = "Rotates the block area around the Y axis, clockwise (north -> east). Doesn't modify blocks' metas." }, SaveToSchematicFile = { Params = "FileName", Return = "", Notes = "Saves the current contents to a schematic file. Returns true if successful." }, + SaveToSchematicString = { Params = "", Return = "string", Notes = "Saves the current contents to a string (in a .schematic file format). Returns the data if successful, empty string if failed." }, SetBlockLight = { Params = "BlockX, BlockY, BlockZ, BlockLight", Return = "", Notes = "Sets the blocklight at the specified absolute coords" }, SetBlockMeta = { Params = "BlockX, BlockY, BlockZ, BlockMeta", Return = "", Notes = "Sets the block meta at the specified absolute coords" }, SetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified absolute coords" }, -- cgit v1.2.3 From f6aaeb74a9bb50488c2c5b5732f43dae4beef15c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 7 Mar 2014 09:18:10 +0100 Subject: Debuggers: Added a test of the cBlockArea string-serialization. --- MCServer/Plugins/Debuggers/Debuggers.lua | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 329a652cd..f99c48242 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -71,6 +71,8 @@ function Initialize(Plugin) -- TestExpatBindings(); -- TestPluginCalls(); + TestBlockAreasString() + return true end; @@ -202,6 +204,42 @@ end +function TestBlockAreasString() + -- Write one area to string, then to file: + local BA1 = cBlockArea() + BA1:Create(5, 5, 5, cBlockArea.baTypes + cBlockArea.baMetas) + BA1:Fill(cBlockArea.baTypes, E_BLOCK_DIAMOND_BLOCK) + BA1:FillRelCuboid(1, 3, 1, 3, 1, 3, cBlockArea.baTypes, E_BLOCK_GOLD_BLOCK) + local Data = BA1:SaveToSchematicString() + if ((type(Data) ~= "string") or (Data == "")) then + LOG("Cannot save schematic to string") + return + end + cFile:CreateFolder("schematics") + local f = io.open("schematics/StringTest.schematic", "w") + f:write(Data) + f:close() + + -- Load a second area from that file: + local BA2 = cBlockArea() + if not(BA2:LoadFromSchematicFile("schematics/StringTest.schematic")) then + LOG("Cannot read schematic from string test file") + return + end + BA2:Clear() + + -- Load another area from a string in that file: + f = io.open("schematics/StringTest.schematic", "r") + Data = f:read("*all") + if not(BA2:LoadFromSchematicString(Data)) then + LOG("Cannot load schematic from string") + end +end + + + + + function TestSQLiteBindings() LOG("Testing SQLite bindings..."); -- cgit v1.2.3 From 31df0268089b931b36d009bcf843a59107682d02 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 7 Mar 2014 10:25:18 +0100 Subject: Rewound PolarSSL to master branch. The current Devel branch fails to build on RasPi. --- lib/polarssl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/polarssl b/lib/polarssl index 2ceda5798..2cb1a0c40 160000 --- a/lib/polarssl +++ b/lib/polarssl @@ -1 +1 @@ -Subproject commit 2ceda579893ceb23c5eb0d56df47dc235644e0f4 +Subproject commit 2cb1a0c4009ecf368ecc74eb428394e10f9e6d00 -- cgit v1.2.3 From c2090c0d11313bd67b02c482f1ca80d5c4567d27 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 7 Mar 2014 11:44:16 +0100 Subject: Add Lua Bindings for FlowerPotEntity.h and add documentation. --- src/Bindings/AllToLua.pkg | 2 ++ src/Bindings/ManualBindings.cpp | 2 +- src/Blocks/BlockMobHead.h | 5 +++-- src/CMakeLists.txt | 1 + src/Chunk.cpp | 2 +- src/Chunk.h | 4 ++-- src/ChunkMap.cpp | 4 ++-- src/ChunkMap.h | 4 ++-- src/World.cpp | 4 ++-- src/World.h | 4 ++-- 10 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 6b067b1e5..2676281f9 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -58,6 +58,8 @@ $cfile "../BlockEntities/HopperEntity.h" $cfile "../BlockEntities/JukeboxEntity.h" $cfile "../BlockEntities/NoteEntity.h" $cfile "../BlockEntities/SignEntity.h" +$cfile "../BlockEntities/MobHeadEntity.h" +$cfile "../BlockEntities/FlowerPotEntity.h" $cfile "../WebAdmin.h" $cfile "../Root.h" $cfile "../Vector3f.h" diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 3570b2c1e..b094da5fc 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2820,7 +2820,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "DoWithFurnaceAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ); - tolua_function(tolua_S, "DoWithMobHeadBlockAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithMobHeadAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithFlowerPotAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index 6a00c3acd..2b128f13b 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -29,7 +29,7 @@ public: BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) override { - class cCallback : public cMobHeadBlockCallback + class cCallback : public cMobHeadCallback { cPlayer * m_Player; NIBBLETYPE m_OldBlockMeta; @@ -45,6 +45,7 @@ public: a_MobHeadEntity->SetType(static_cast(m_OldBlockMeta)); a_MobHeadEntity->SetRotation(static_cast(Rotation)); + a_MobHeadEntity->GetWorld()->BroadcastBlockEntity(a_MobHeadEntity->GetPosX(), a_MobHeadEntity->GetPosY(), a_MobHeadEntity->GetPosZ(), m_Player->GetClientHandle()); return false; } @@ -59,7 +60,7 @@ public: a_BlockMeta = a_BlockFace; cWorld * World = (cWorld *) &a_WorldInterface; - World->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, Callback); + World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback); a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); } } ; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e0731264..5029906aa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,6 +40,7 @@ if (NOT MSVC) BlockEntities/NoteEntity.h BlockEntities/SignEntity.h BlockEntities/MobHeadEntity.h + BlockEntities/FlowerPotEntity.h BlockID.h BoundingBox.h ChatColor.h diff --git a/src/Chunk.cpp b/src/Chunk.cpp index b5b776147..957d7d575 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -2340,7 +2340,7 @@ bool cChunk::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom -bool cChunk::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) +bool cChunk::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback) { // The blockentity list is locked by the parent chunkmap's CS for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2) diff --git a/src/Chunk.h b/src/Chunk.h index e8b46f631..b3fa563cc 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -49,7 +49,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cMobHeadBlockCallback; +typedef cItemCallback cMobHeadCallback; typedef cItemCallback cFlowerPotCallback; @@ -256,7 +256,7 @@ public: bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ - bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); + bool DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback); /** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */ bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback); diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 7f999fd31..40964c654 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2182,7 +2182,7 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c -bool cChunkMap::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) +bool cChunkMap::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback) { int ChunkX, ChunkZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; @@ -2193,7 +2193,7 @@ bool cChunkMap::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c { return false; } - return Chunk->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return Chunk->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 6d35b2ebf..9d973f2a9 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -46,7 +46,7 @@ typedef cItemCallback cFlowerPotCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cMobHeadBlockCallback; +typedef cItemCallback cMobHeadCallback; typedef cItemCallback cChunkCallback; @@ -259,7 +259,7 @@ public: bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Lua-accessible /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ - bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Lua-accessible + bool DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback); // Lua-accessible /** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */ bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback); // Lua-accessible diff --git a/src/World.cpp b/src/World.cpp index 335c6a00d..ecb278e85 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1197,9 +1197,9 @@ bool cWorld::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom -bool cWorld::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) +bool cWorld::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback) { - return m_ChunkMap->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } diff --git a/src/World.h b/src/World.h index ee74742c4..e6c665785 100644 --- a/src/World.h +++ b/src/World.h @@ -61,7 +61,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cMobHeadBlockCallback; +typedef cItemCallback cMobHeadCallback; typedef cItemCallback cFlowerPotCallback; @@ -535,7 +535,7 @@ public: bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Exported in ManualBindings.cpp /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ - bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Exported in ManualBindings.cpp + bool DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback); // Exported in ManualBindings.cpp /** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */ bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback); // Exported in ManualBindings.cpp -- cgit v1.2.3 From 880852394275c4cc3c458582fc245f6f22f9d200 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 7 Mar 2014 15:42:03 +0200 Subject: Fixed water/lava interaction --- src/Simulator/FloodyFluidSimulator.cpp | 66 ++++++++++++++++++++++++++++++++- src/Simulator/FloodyFluidSimulator.h | 3 ++ src/Simulator/VanillaFluidSimulator.cpp | 4 +- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp index b1ac734d7..48655afb3 100644 --- a/src/Simulator/FloodyFluidSimulator.cpp +++ b/src/Simulator/FloodyFluidSimulator.cpp @@ -54,14 +54,21 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re a_Chunk->GetMeta(a_RelX, a_RelY, a_RelZ) ); - NIBBLETYPE MyMeta = a_Chunk->GetMeta(a_RelX, a_RelY, a_RelZ); - if (!IsAnyFluidBlock(a_Chunk->GetBlock(a_RelX, a_RelY, a_RelZ))) + BLOCKTYPE MyBlock; NIBBLETYPE MyMeta; + a_Chunk->GetBlockTypeMeta(a_RelX, a_RelY, a_RelZ, MyBlock, MyMeta); + + if (!IsAnyFluidBlock(MyBlock)) { // Can happen - if a block is scheduled for simulating and gets replaced in the meantime. FLOG(" BadBlockType exit"); return; } + if (HardenBlock(a_Chunk, a_RelX, a_RelY, a_RelZ, MyBlock, MyMeta)) + { + return; + } + if (MyMeta != 0) { // Source blocks aren't checked for tributaries, others are. @@ -309,6 +316,8 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i a_NewMeta ); a_NearChunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta); + + HardenBlock(a_NearChunk, a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta); } @@ -361,3 +370,56 @@ bool cFloodyFluidSimulator::CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX + +bool cFloodyFluidSimulator::HardenBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) +{ + // Only lava blocks can harden + if (!IsBlockLava(a_BlockType)) + { + return false; + } + + bool ShouldHarden = false; + + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + static const Vector3i Coords[] = + { + Vector3i( 1, 0, 0), + Vector3i(-1, 0, 0), + Vector3i( 0, 0, 1), + Vector3i( 0, 0, -1), + }; + for (size_t i = 0; i < ARRAYCOUNT(Coords); i++) + { + if (!a_Chunk->UnboundedRelGetBlock(a_RelX + Coords[i].x, a_RelY, a_RelZ + Coords[i].z, BlockType, BlockMeta)) + { + continue; + } + if (IsBlockWater(BlockType)) + { + ShouldHarden = true; + } + } // for i - Coords[] + + if (ShouldHarden) + { + if (a_Meta == 0) + { + // Source lava block + a_Chunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_OBSIDIAN, 0); + return true; + } + // Ignore last lava level + else if (a_Meta <= 4) + { + a_Chunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_COBBLESTONE, 0); + return true; + } + } + + return false; +} + + + diff --git a/src/Simulator/FloodyFluidSimulator.h b/src/Simulator/FloodyFluidSimulator.h index 5fd91b2b1..c0ccd422f 100644 --- a/src/Simulator/FloodyFluidSimulator.h +++ b/src/Simulator/FloodyFluidSimulator.h @@ -47,6 +47,9 @@ protected: /** Checks if there are enough neighbors to create a source at the coords specified; turns into source and returns true if so. */ bool CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ); + /** Check if block should harden (Water/Lava interaction) */ + bool HardenBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta); + /** Spread water to neighbors. * * May be overridden to provide more sophisticated algorithms. diff --git a/src/Simulator/VanillaFluidSimulator.cpp b/src/Simulator/VanillaFluidSimulator.cpp index 5308d162b..78aff9d68 100644 --- a/src/Simulator/VanillaFluidSimulator.cpp +++ b/src/Simulator/VanillaFluidSimulator.cpp @@ -86,7 +86,7 @@ int cVanillaFluidSimulator::CalculateFlowCost(cChunk * a_Chunk, int a_RelX, int { return Cost; } - if (!IsPassableForFluid(BlockType)) + if (!IsPassableForFluid(BlockType) && !IsBlockLiquid(BlockType)) { return Cost; } @@ -96,7 +96,7 @@ int cVanillaFluidSimulator::CalculateFlowCost(cChunk * a_Chunk, int a_RelX, int { return Cost; } - if (IsPassableForFluid(BlockType)) + if (IsPassableForFluid(BlockType) || IsBlockLiquid(BlockType)) { // Path found, exit return a_Iteration; -- cgit v1.2.3 From 8fdffbb48caa527b83b40baf88e841d1593e79b6 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 7 Mar 2014 16:14:11 +0100 Subject: Add missing documentation files --- MCServer/Plugins/APIDump/APIDesc.lua | 2 ++ MCServer/Plugins/APIDump/Classes/BlockEntities.lua | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 94cdd0063..9df9d0e77 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2150,7 +2150,9 @@ end DoWithDropSpenserAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper or a dispenser at the specified coords, calls the CallbackFunction with the {{cDropSpenserEntity}} parameter representing the dropper or dispenser. The CallbackFunction has the following signature:
    function Callback({{cDropSpenserEntity|DropSpenserEntity}}, [CallbackData])
    Note that this can be used to access both dispensers and droppers in a similar way. The function returns false if there is neither dispenser nor dropper, or if there is, it returns the bool value that the callback has returned." }, DoWithDropperAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper at the specified coords, calls the CallbackFunction with the {{cDropperEntity}} parameter representing the dropper. The CallbackFunction has the following signature:
    function Callback({{cDropperEntity|DropperEntity}}, [CallbackData])
    The function returns false if there is no dropper, or if there is, it returns the bool value that the callback has returned." }, DoWithEntityByID = { Params = "EntityID, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If an entity with the specified ID exists, calls the callback with the {{cEntity}} parameter representing the entity. The CallbackFunction has the following signature:
    function Callback({{cEntity|Entity}}, [CallbackData])
    The function returns false if the entity was not found, and it returns the same bool value that the callback has returned if the entity was found." }, + DoWithFlowerPotAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a flower pot at the specified coords, calls the CallbackFunction with the {{cFlowerPotEntity}} parameter representing the flower pot. The CallbackFunction has the following signature:
    function Callback({{cFlowerPotEntity|FlowerPotEntity}}, [CallbackData])
    The function returns false if there is no flower pot, or if there is, it returns the bool value that the callback has returned." }, DoWithFurnaceAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a furnace at the specified coords, calls the CallbackFunction with the {{cFurnaceEntity}} parameter representing the furnace. The CallbackFunction has the following signature:
    function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])
    The function returns false if there is no furnace, or if there is, it returns the bool value that the callback has returned." }, + DoWithModHeadAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a mob head at the specified coords, calls the CallbackFunction with the {{cMobHeadEntity}} parameter representing the furnace. The CallbackFunction has the following signature:
    function Callback({{cMobHeadEntity|MobHeadEntity}}, [CallbackData])
    The function returns false if there is no mob head, or if there is, it returns the bool value that the callback has returned." }, DoWithNoteBlockAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a note block at the specified coords, calls the CallbackFunction with the {{cNoteEntity}} parameter representing the note block. The CallbackFunction has the following signature:
    function Callback({{cNoteEntity|NoteEntity}}, [CallbackData])
    The function returns false if there is no note block, or if there is, it returns the bool value that the callback has returned." }, DoWithPlayer = { Params = "PlayerName, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a player of the specified name (exact match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature:
    function Callback({{cPlayer|Player}}, [CallbackData])
    The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." }, FastSetBlock = diff --git a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua index 61a8e8d22..3deb50ade 100644 --- a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua +++ b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua @@ -238,6 +238,20 @@ World:ForEachChestInChunk(Player:GetChunkX(), Player:GetChunkZ(), }, Inherits = "cBlockEntity"; }, -- cSignEntity + + cFlowerPotEntity = + { + Desc = [[ + This class represents a flower pot entity in the world. + ]], + Functions = + { + IsItemInPot = { Params = "", Return = "bool", Notes = "Is a flower in the pot?" }, + GetItem = { Params = "", Return = "cItem", Notes = "Returns the item in the flower pot." }, + SetItem = { Params = "cItem", Return = "", Notes = "Set the item in the flower pot" }, + }, + Inherits = "cBlockEntity"; + }, -- cFlowerPotEntity } -- cgit v1.2.3 From fd4eda7d248884a48b5d7c67d4c59ee3a9dbb149 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 7 Mar 2014 17:43:06 +0100 Subject: Fixed a typo. --- src/Bindings/ManualBindings.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index f9d04ce90..0dcb336ef 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2456,7 +2456,7 @@ static int tolua_cBlockArea_GetSize(lua_State * tolua_S) static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) { // function cBlockArea::LoadFromSchematicFile - // Exported manually because function has been moved to SchematicFileSerilizer.cpp + // Exported manually because function has been moved to SchematicFileSerializer.cpp cLuaState L(tolua_S); if ( !L.CheckParamUserType(1, "cBlockArea") || @@ -2486,7 +2486,7 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) static int tolua_cBlockArea_LoadFromSchematicString(lua_State * tolua_S) { // function cBlockArea::LoadFromSchematicString - // Exported manually because function has been moved to SchematicFileSerilizer.cpp + // Exported manually because function has been moved to SchematicFileSerializer.cpp cLuaState L(tolua_S); if ( !L.CheckParamUserType(1, "cBlockArea") || @@ -2517,7 +2517,7 @@ static int tolua_cBlockArea_LoadFromSchematicString(lua_State * tolua_S) static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) { // function cBlockArea::SaveToSchematicFile - // Exported manually because function has been moved to SchematicFileSerilizer.cpp + // Exported manually because function has been moved to SchematicFileSerializer.cpp cLuaState L(tolua_S); if ( !L.CheckParamUserType(1, "cBlockArea") || @@ -2546,7 +2546,7 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) static int tolua_cBlockArea_SaveToSchematicString(lua_State * tolua_S) { // function cBlockArea::SaveToSchematicString - // Exported manually because function has been moved to SchematicFileSerilizer.cpp + // Exported manually because function has been moved to SchematicFileSerializer.cpp cLuaState L(tolua_S); if ( !L.CheckParamUserType(1, "cBlockArea") || -- cgit v1.2.3 From eff054027face23320f55a01fe5884fe285204b6 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 7 Mar 2014 17:51:43 +0100 Subject: Link cItem in the documentation --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- MCServer/Plugins/APIDump/Classes/BlockEntities.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 9df9d0e77..39f7cbcd7 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2152,7 +2152,7 @@ end DoWithEntityByID = { Params = "EntityID, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If an entity with the specified ID exists, calls the callback with the {{cEntity}} parameter representing the entity. The CallbackFunction has the following signature:
    function Callback({{cEntity|Entity}}, [CallbackData])
    The function returns false if the entity was not found, and it returns the same bool value that the callback has returned if the entity was found." }, DoWithFlowerPotAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a flower pot at the specified coords, calls the CallbackFunction with the {{cFlowerPotEntity}} parameter representing the flower pot. The CallbackFunction has the following signature:
    function Callback({{cFlowerPotEntity|FlowerPotEntity}}, [CallbackData])
    The function returns false if there is no flower pot, or if there is, it returns the bool value that the callback has returned." }, DoWithFurnaceAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a furnace at the specified coords, calls the CallbackFunction with the {{cFurnaceEntity}} parameter representing the furnace. The CallbackFunction has the following signature:
    function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])
    The function returns false if there is no furnace, or if there is, it returns the bool value that the callback has returned." }, - DoWithModHeadAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a mob head at the specified coords, calls the CallbackFunction with the {{cMobHeadEntity}} parameter representing the furnace. The CallbackFunction has the following signature:
    function Callback({{cMobHeadEntity|MobHeadEntity}}, [CallbackData])
    The function returns false if there is no mob head, or if there is, it returns the bool value that the callback has returned." }, + DoWithMobHeadAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a mob head at the specified coords, calls the CallbackFunction with the {{cMobHeadEntity}} parameter representing the furnace. The CallbackFunction has the following signature:
    function Callback({{cMobHeadEntity|MobHeadEntity}}, [CallbackData])
    The function returns false if there is no mob head, or if there is, it returns the bool value that the callback has returned." }, DoWithNoteBlockAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a note block at the specified coords, calls the CallbackFunction with the {{cNoteEntity}} parameter representing the note block. The CallbackFunction has the following signature:
    function Callback({{cNoteEntity|NoteEntity}}, [CallbackData])
    The function returns false if there is no note block, or if there is, it returns the bool value that the callback has returned." }, DoWithPlayer = { Params = "PlayerName, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a player of the specified name (exact match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature:
    function Callback({{cPlayer|Player}}, [CallbackData])
    The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." }, FastSetBlock = diff --git a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua index 3deb50ade..de42f66df 100644 --- a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua +++ b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua @@ -247,8 +247,8 @@ World:ForEachChestInChunk(Player:GetChunkX(), Player:GetChunkZ(), Functions = { IsItemInPot = { Params = "", Return = "bool", Notes = "Is a flower in the pot?" }, - GetItem = { Params = "", Return = "cItem", Notes = "Returns the item in the flower pot." }, - SetItem = { Params = "cItem", Return = "", Notes = "Set the item in the flower pot" }, + GetItem = { Params = "", Return = "{{cItem|Item}}", Notes = "Returns the item in the flower pot." }, + SetItem = { Params = "{{cItem|Item}}", Return = "", Notes = "Set the item in the flower pot" }, }, Inherits = "cBlockEntity"; }, -- cFlowerPotEntity -- cgit v1.2.3 From fac56bb935de5a808b197ccc4a886f262d94dc99 Mon Sep 17 00:00:00 2001 From: worktycho Date: Fri, 7 Mar 2014 16:55:45 +0000 Subject: Enabled -ffast-math --- SetFlags.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index ded57e6d7..6e86ac0aa 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -1,5 +1,4 @@ - macro (add_flags_lnk FLAGS) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAGS}") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FLAGS}") @@ -50,6 +49,9 @@ macro(set_flags) else() add_flags_cxx("-pthread") endif() + + #we support non-IEEE 754 fpus so can make no guarentees about error + add_flags_cxx("-ffast-math") else() # Let gcc / clang know that we're compiling a multi-threaded app: @@ -62,6 +64,9 @@ macro(set_flags) # We use a signed char (fixes #640 on RasPi) add_flags_cxx("-fsigned-char") + + #we support non-IEEE 754 fpus so can make no guarentees about error + add_flags_cxx("-ffast-math") endif() -- cgit v1.2.3 From 2a3d8d46ec5d269b220ed1fb711cb4d2bfa9dfeb Mon Sep 17 00:00:00 2001 From: worktycho Date: Fri, 7 Mar 2014 17:04:38 +0000 Subject: Only use fast-math in exes --- SetFlags.cmake | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 6e86ac0aa..a5bd3a0a2 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -1,4 +1,3 @@ - macro (add_flags_lnk FLAGS) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAGS}") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FLAGS}") @@ -49,9 +48,6 @@ macro(set_flags) else() add_flags_cxx("-pthread") endif() - - #we support non-IEEE 754 fpus so can make no guarentees about error - add_flags_cxx("-ffast-math") else() # Let gcc / clang know that we're compiling a multi-threaded app: @@ -65,8 +61,6 @@ macro(set_flags) # We use a signed char (fixes #640 on RasPi) add_flags_cxx("-fsigned-char") - #we support non-IEEE 754 fpus so can make no guarentees about error - add_flags_cxx("-ffast-math") endif() @@ -189,6 +183,9 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") add_flags_cxx("-Wall -Wextra") + + #we support non-IEEE 754 fpus so can make no guarentees about error + add_flags_cxx("-ffast-math") endif() endmacro() -- cgit v1.2.3 From 95ea0ef43dfbcf2240a0ece70d2829ce63ab0dd3 Mon Sep 17 00:00:00 2001 From: worktycho Date: Fri, 7 Mar 2014 17:22:37 +0000 Subject: Fixed clang compile --- SetFlags.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index a5bd3a0a2..6a8211fa2 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -184,8 +184,13 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") add_flags_cxx("-Wall -Wextra") - #we support non-IEEE 754 fpus so can make no guarentees about error + # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") + + # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_flags_cxx("-D__extern_always_inline=inline") + endif() endif() endmacro() -- cgit v1.2.3 From b480148116ea7099c9a6afda83f74a3d45815a83 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 7 Mar 2014 10:26:07 -0800 Subject: Fixed warnings --- SetFlags.cmake | 2 +- src/Bindings/LuaState.cpp | 1 + src/Items/ItemHandler.h | 3 +++ src/OSSupport/SocketThreads.h | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 6a8211fa2..35831e7e9 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -182,7 +182,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall -Wextra") + add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter") # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 1890dcfe5..aa6ee05b3 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -677,6 +677,7 @@ void cLuaState::Push(Vector3i * a_Vector) void cLuaState::Push(void * a_Ptr) { + UNUSED(a_Ptr); ASSERT(IsValid()); // Investigate the cause of this - what is the callstack? diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index ef3f37a7a..5b6c239cc 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -21,6 +21,9 @@ class cItemHandler public: cItemHandler(int a_ItemType); + // Force virtual destructor + virtual ~cItemHandler() {} + /// Called when the player tries to use the item (right mouse button). Return false to make the item unusable. DEFAULT: False virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir); diff --git a/src/OSSupport/SocketThreads.h b/src/OSSupport/SocketThreads.h index fcd2ce11f..b2eb5950f 100644 --- a/src/OSSupport/SocketThreads.h +++ b/src/OSSupport/SocketThreads.h @@ -103,7 +103,7 @@ private: public: cSocketThread(cSocketThreads * a_Parent); - ~cSocketThread(); + virtual ~cSocketThread(); // All these methods assume parent's m_CS is locked bool HasEmptySlot(void) const {return m_NumSlots < MAX_SLOTS; } -- cgit v1.2.3 From 7f389522ef1f40e847a4a7828ad55e50c0151b00 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 7 Mar 2014 10:42:13 -0800 Subject: Fixed warnings --- src/Blocks/BlockStairs.h | 8 ++++++++ src/Blocks/BlockVine.h | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index c1887bc46..93035b3b1 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -25,6 +25,14 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override { + UNUSED(a_ChunkInterface); + UNUSED(a_BlockX); + UNUSED(a_BlockY); + UNUSED(a_BlockZ); + UNUSED(a_CursorX); + UNUSED(a_CursorY); + UNUSED(a_CursorZ); + UNUSED(a_BlockMeta); a_BlockType = m_BlockType; a_BlockMeta = RotationToMetaData(a_Player->GetYaw()); switch (a_BlockFace) diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index d8c114284..0934a451b 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -24,6 +24,10 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override { + UNUSED(a_Player); + UNUSED(a_CursorX); + UNUSED(a_CursorY); + UNUSED(a_CursorZ); // TODO: Disallow placement where the vine doesn't attach to something properly BLOCKTYPE BlockType = 0; NIBBLETYPE BlockMeta; @@ -162,11 +166,17 @@ public: return false; } - virtual void OnUpdate(cWorld * a_World, int X, int Y, int Z) + virtual void OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) { - if (a_World->GetBlock(X, Y - 1, Z) == E_BLOCK_AIR) + UNUSED(a_ChunkInterface); + UNUSED(a_WorldInterface); + UNUSED(a_BlockPluginInterface); + + BLOCKTYPE Block; + a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY - 1, a_RelZ, Block); + if (Block == E_BLOCK_AIR) { - a_World->SetBlock(X, Y - 1, Z, E_BLOCK_VINES, a_World->GetBlockMeta(X, Y, Z)); + a_Chunk.UnboundedRelSetBlock(a_RelX, a_RelY - 1, a_RelZ, E_BLOCK_VINES, a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); } } -- cgit v1.2.3 From d86fc1af0640675c707330e671d69b23e27d20c1 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 7 Mar 2014 20:49:40 +0200 Subject: Added some comments --- src/Simulator/FloodyFluidSimulator.cpp | 2 ++ src/Simulator/FloodyFluidSimulator.h | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp index 48655afb3..03e94e791 100644 --- a/src/Simulator/FloodyFluidSimulator.cpp +++ b/src/Simulator/FloodyFluidSimulator.cpp @@ -64,8 +64,10 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re return; } + // When in contact with water, lava should harden if (HardenBlock(a_Chunk, a_RelX, a_RelY, a_RelZ, MyBlock, MyMeta)) { + // Block was changed, bail out return; } diff --git a/src/Simulator/FloodyFluidSimulator.h b/src/Simulator/FloodyFluidSimulator.h index c0ccd422f..632de3bb2 100644 --- a/src/Simulator/FloodyFluidSimulator.h +++ b/src/Simulator/FloodyFluidSimulator.h @@ -47,7 +47,10 @@ protected: /** Checks if there are enough neighbors to create a source at the coords specified; turns into source and returns true if so. */ bool CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ); - /** Check if block should harden (Water/Lava interaction) */ + /** Checks if the specified block should harden (Water/Lava interaction) and if so, converts it to a suitable block. + * + * Returns whether the block was changed or not. + */ bool HardenBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta); /** Spread water to neighbors. -- cgit v1.2.3 From d33d72f0dc9ef8969c6b57592fbce54165641591 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 7 Mar 2014 11:04:25 -0800 Subject: Warnings --- src/ByteBuffer.cpp | 10 +++++----- src/ByteBuffer.h | 24 ++++++++++++------------ src/Protocol/Protocol.h | 2 +- src/Protocol/Protocol125.cpp | 2 +- src/Protocol/Protocol125.h | 21 +++++++++++++++++---- src/Protocol/Protocol132.cpp | 2 +- src/Protocol/Protocol132.h | 2 +- src/Protocol/Protocol17x.cpp | 2 +- src/Protocol/Protocol17x.h | 2 +- src/Protocol/ProtocolRecognizer.cpp | 2 +- src/Protocol/ProtocolRecognizer.h | 2 +- 11 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index d2d3beb97..32a367462 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -171,7 +171,7 @@ cByteBuffer::~cByteBuffer() -bool cByteBuffer::Write(const char * a_Bytes, int a_Count) +bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count) { CHECK_THREAD; CheckValid(); @@ -263,7 +263,7 @@ int cByteBuffer::GetReadableSpace(void) const -bool cByteBuffer::CanReadBytes(int a_Count) const +bool cByteBuffer::CanReadBytes(size_t a_Count) const { CHECK_THREAD; CheckValid(); @@ -274,7 +274,7 @@ bool cByteBuffer::CanReadBytes(int a_Count) const -bool cByteBuffer::CanWriteBytes(int a_Count) const +bool cByteBuffer::CanWriteBytes(size_t a_Count) const { CHECK_THREAD; CheckValid(); @@ -767,7 +767,7 @@ bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars) -bool cByteBuffer::SkipRead(int a_Count) +bool cByteBuffer::SkipRead(size_t a_Count) { CHECK_THREAD; CheckValid(); @@ -860,7 +860,7 @@ void cByteBuffer::ReadAgain(AString & a_Out) -void cByteBuffer::AdvanceReadPos(int a_Count) +void cByteBuffer::AdvanceReadPos(size_t a_Count) { CHECK_THREAD; CheckValid(); diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h index cbce119b1..5fdf48c28 100644 --- a/src/ByteBuffer.h +++ b/src/ByteBuffer.h @@ -31,7 +31,7 @@ public: ~cByteBuffer(); /// Writes the bytes specified to the ringbuffer. Returns true if successful, false if not - bool Write(const char * a_Bytes, int a_Count); + bool Write(const char * a_Bytes, size_t a_Count); /// Returns the number of bytes that can be successfully written to the ringbuffer int GetFreeSpace(void) const; @@ -46,10 +46,10 @@ public: int GetDataStart(void) const { return m_DataStart; } /// Returns true if the specified amount of bytes are available for reading - bool CanReadBytes(int a_Count) const; + bool CanReadBytes(size_t a_Count) const; /// Returns true if the specified amount of bytes are available for writing - bool CanWriteBytes(int a_Count) const; + bool CanWriteBytes(size_t a_Count) const; // Read the specified datatype and advance the read pointer; return true if successfully read: bool ReadChar (char & a_Value); @@ -92,19 +92,19 @@ public: bool WriteLEInt (int a_Value); /// Reads a_Count bytes into a_Buffer; returns true if successful - bool ReadBuf(void * a_Buffer, int a_Count); + bool ReadBuf(void * a_Buffer, size_t a_Count); /// Writes a_Count bytes into a_Buffer; returns true if successful - bool WriteBuf(const void * a_Buffer, int a_Count); + bool WriteBuf(const void * a_Buffer, size_t a_Count); /// Reads a_Count bytes into a_String; returns true if successful - bool ReadString(AString & a_String, int a_Count); + bool ReadString(AString & a_String, size_t a_Count); /// Reads 2 * a_NumChars bytes and interprets it as a UTF16-BE string, converting it into UTF8 string a_String bool ReadUTF16String(AString & a_String, int a_NumChars); /// Skips reading by a_Count bytes; returns false if not enough bytes in the ringbuffer - bool SkipRead(int a_Count); + bool SkipRead(size_t a_Count); /// Reads all available data into a_Data void ReadAll(AString & a_Data); @@ -126,18 +126,18 @@ public: protected: char * m_Buffer; - int m_BufferSize; // Total size of the ringbuffer + size_t m_BufferSize; // Total size of the ringbuffer #ifdef _DEBUG volatile unsigned long m_ThreadID; // Thread that is currently accessing the object, checked via cSingleThreadAccessChecker #endif // _DEBUG - int m_DataStart; // Where the data starts in the ringbuffer - int m_WritePos; // Where the data ends in the ringbuffer - int m_ReadPos; // Where the next read will start in the ringbuffer + size_t m_DataStart; // Where the data starts in the ringbuffer + size_t m_WritePos; // Where the data ends in the ringbuffer + size_t m_ReadPos; // Where the next read will start in the ringbuffer /// Advances the m_ReadPos by a_Count bytes - void AdvanceReadPos(int a_Count); + void AdvanceReadPos(size_t a_Count); } ; diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index b5560f7c1..d3383bf0d 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -52,7 +52,7 @@ public: virtual ~cProtocol() {} /// Called when client sends some data - virtual void DataReceived(const char * a_Data, int a_Size) = 0; + virtual void DataReceived(const char * a_Data, size_t a_Size) = 0; // Sending stuff to clients (alphabetically sorted): virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) = 0; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 3980350f5..e032e4050 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1186,7 +1186,7 @@ void cProtocol125::SendData(const char * a_Data, int a_Size) -void cProtocol125::DataReceived(const char * a_Data, int a_Size) +void cProtocol125::DataReceived(const char * a_Data, size_t a_Size) { if (!m_ReceivedData.Write(a_Data, a_Size)) { diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 1d1484a60..66f3227b0 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -24,7 +24,7 @@ public: cProtocol125(cClientHandle * a_Client); /// Called when client sends some data: - virtual void DataReceived(const char * a_Data, int a_Size) override; + virtual void DataReceived(const char * a_Data, size_t a_Size) override; /// Sending stuff to clients (alphabetically sorted): virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override; @@ -57,9 +57,17 @@ public: virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override; - virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override {} // This protocol doesn't support such message + virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override + { + // This protocol doesn't support such message + UNUSED(a_ID); + UNUSED(a_Scale); + } virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override; - virtual void SendPaintingSpawn (const cPainting & a_Painting) override {}; + virtual void SendPaintingSpawn (const cPainting & a_Painting) override + { + UNUSED(a_Painting); + }; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override {} // This protocol doesn't support such message virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; @@ -73,7 +81,12 @@ public: virtual void SendRespawn (void) override; virtual void SendExperience (void) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; - virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override {} // This protocol doesn't support such message + virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override + { + UNUSED(a_Name); + UNUSED(a_DisplayName); + UNUSED(a_Mode); + } // This protocol doesn't support such message virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override {} // This protocol doesn't support such message virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override {} // This protocol doesn't support such message virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index 1f9222a69..8df550c7b 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -108,7 +108,7 @@ cProtocol132::~cProtocol132() -void cProtocol132::DataReceived(const char * a_Data, int a_Size) +void cProtocol132::DataReceived(const char * a_Data, size_t a_Size) { if (m_IsEncrypted) { diff --git a/src/Protocol/Protocol132.h b/src/Protocol/Protocol132.h index 89f4636f5..0702fbf5a 100644 --- a/src/Protocol/Protocol132.h +++ b/src/Protocol/Protocol132.h @@ -40,7 +40,7 @@ public: virtual ~cProtocol132(); /// Called when client sends some data: - virtual void DataReceived(const char * a_Data, int a_Size) override; + virtual void DataReceived(const char * a_Data, size_t a_Size) override; // Sending commands (alphabetically sorted): virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 18646254f..cb9e5b9b1 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -98,7 +98,7 @@ cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAdd -void cProtocol172::DataReceived(const char * a_Data, int a_Size) +void cProtocol172::DataReceived(const char * a_Data, size_t a_Size) { if (m_IsEncrypted) { diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 113501568..41163009e 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -56,7 +56,7 @@ public: cProtocol172(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); /** Called when client sends some data: */ - virtual void DataReceived(const char * a_Data, int a_Size) override; + virtual void DataReceived(const char * a_Data, size_t a_Size) override; /** Sending stuff to clients (alphabetically sorted): */ virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 84b052146..3b9003e60 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -68,7 +68,7 @@ AString cProtocolRecognizer::GetVersionTextFromInt(int a_ProtocolVersion) -void cProtocolRecognizer::DataReceived(const char * a_Data, int a_Size) +void cProtocolRecognizer::DataReceived(const char * a_Data, size_t a_Size) { if (m_Protocol == NULL) { diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index 6aaafedeb..d7fb8fad2 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -59,7 +59,7 @@ public: static AString GetVersionTextFromInt(int a_ProtocolVersion); /// Called when client sends some data: - virtual void DataReceived(const char * a_Data, int a_Size) override; + virtual void DataReceived(const char * a_Data, size_t a_Size) override; /// Sending stuff to clients (alphabetically sorted): virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override; -- cgit v1.2.3 From 21e85b07456f12c029ab32c396285ad13063964f Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 7 Mar 2014 11:15:04 -0800 Subject: Warnings --- src/Generating/MineShafts.cpp | 2 ++ src/Generating/Trees.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp index d9acc57bb..28dc37567 100644 --- a/src/Generating/MineShafts.cpp +++ b/src/Generating/MineShafts.cpp @@ -69,6 +69,8 @@ public: m_BoundingBox(a_BoundingBox) { } + + virtual ~cMineShaft() {} /// Returns true if this mineshaft intersects the specified cuboid bool DoesIntersect(const cCuboid & a_Other) diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp index a660285d1..4909587b1 100644 --- a/src/Generating/Trees.cpp +++ b/src/Generating/Trees.cpp @@ -595,7 +595,7 @@ void GetPineTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise { break; } - ASSERT(LayerSize < ARRAYCOUNT(BigOs)); + ASSERT((size_t)LayerSize < ARRAYCOUNT(BigOs)); PushCoordBlocks(a_BlockX, h, a_BlockZ, a_OtherBlocks, BigOs[LayerSize].Coords, BigOs[LayerSize].Count, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); h--; } -- cgit v1.2.3 From d51cab2d3bb579b663c1211dfc1e69039165c06f Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 7 Mar 2014 11:16:16 -0800 Subject: Turned on Werror --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 35831e7e9..e6ba782fc 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -182,7 +182,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter") + add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter -Wno-error=switch") # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") -- cgit v1.2.3 From 72697cfb4f7cfa8e82cba4960ac9e8c729c3b24d Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 7 Mar 2014 11:23:28 -0800 Subject: Added support to overide CMake build type with env vars --- src/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5029906aa..cafa519c3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,14 @@ include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/polarssl/include") set(FOLDERS OSSupport HTTPServer Items Blocks Protocol Generating) set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities) +if(DEFINED ENV{MCSERVER_BUILD_TYPE}) + message("Setting build type to $ENV{MCSERVER_BUILD_TYPE}") + set(CMAKE_BUILD_TYPE $ENV{MCSERVER_BUILD_TYPE}) +endif() + +if(DEFINED ENV{MCSERVER_FORCE32}) + set(FORCE32 $ENV{MCSERVER_FORCE32}) +endif() if (NOT MSVC) -- cgit v1.2.3 From 53fe82eaf85dc3bcd2cfdc12ffb2266e10f91e79 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 7 Mar 2014 11:26:36 -0800 Subject: Added travis support for multiple build types --- .travis.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c6537cf47..a12ca55e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,13 @@ compiler: - gcc - clang # Build MCServer -script: cmake . -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_TOOLS=1 -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | ./MCServer) +script: cmake . -DBUILD_TOOLS=1 -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | ./MCServer) + +env: + - MCSERVER_BUILD_TYPE=RELEASE + - MCSERVER_BUILD_TYPE=DEBUG + - MCSERVER_BUILD_TYPE=RELEASE MCSERVER_FORCE32=1 + - MCSERVER_BUILD_TYPE=DEBUG MCSERVER_FORCE32=1 # Notification Settings notifications: -- cgit v1.2.3 From 6b153a5014612a998179f4637139061ed11da6db Mon Sep 17 00:00:00 2001 From: worktycho Date: Fri, 7 Mar 2014 19:59:49 +0000 Subject: Move env code part 1 --- src/CMakeLists.txt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cafa519c3..c2de26664 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,3 @@ - cmake_minimum_required (VERSION 2.8.2) project (MCServer) @@ -9,15 +8,6 @@ include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/polarssl/include") set(FOLDERS OSSupport HTTPServer Items Blocks Protocol Generating) set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities) -if(DEFINED ENV{MCSERVER_BUILD_TYPE}) - message("Setting build type to $ENV{MCSERVER_BUILD_TYPE}") - set(CMAKE_BUILD_TYPE $ENV{MCSERVER_BUILD_TYPE}) -endif() - -if(DEFINED ENV{MCSERVER_FORCE32}) - set(FORCE32 $ENV{MCSERVER_FORCE32}) -endif() - if (NOT MSVC) -- cgit v1.2.3 From c67e008a4e3c19a79f82af4d430e43e6ea0eabbf Mon Sep 17 00:00:00 2001 From: worktycho Date: Fri, 7 Mar 2014 20:03:05 +0000 Subject: Fixed wrong path in debug mode --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index a12ca55e0..14dad4df4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,13 +3,13 @@ compiler: - gcc - clang # Build MCServer -script: cmake . -DBUILD_TOOLS=1 -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | ./MCServer) +script: cmake . -DBUILD_TOOLS=1 -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | $MCSERVER_PATH) env: - - MCSERVER_BUILD_TYPE=RELEASE - - MCSERVER_BUILD_TYPE=DEBUG - - MCSERVER_BUILD_TYPE=RELEASE MCSERVER_FORCE32=1 - - MCSERVER_BUILD_TYPE=DEBUG MCSERVER_FORCE32=1 + - MCSERVER_BUILD_TYPE=RELEASE MCSERVER_PATH=./MCServer + - MCSERVER_BUILD_TYPE=DEBUG MCSERVER_PATH=./MCServer_debug + - MCSERVER_BUILD_TYPE=RELEASE MCSERVER_FORCE32=1 MCSERVER_PATH=./MCServer + - MCSERVER_BUILD_TYPE=DEBUG MCSERVER_FORCE32=1 MCSERVER_PATH=./MCServer_debug # Notification Settings notifications: -- cgit v1.2.3 From 0eea9eb99841ba379475a277af860d22ac156071 Mon Sep 17 00:00:00 2001 From: worktycho Date: Fri, 7 Mar 2014 20:16:16 +0000 Subject: Move env code part 2 Only just noticed I committed this on the wrong branch. --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05b6d879b..e7e8daf7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,15 @@ cmake_minimum_required (VERSION 2.6) # Without this, the MSVC variable isn't defined for MSVC builds ( http://www.cmake.org/pipermail/cmake/2011-November/047130.html ) enable_language(CXX C) +if(DEFINED ENV{MCSERVER_BUILD_TYPE}) + message("Setting build type to $ENV{MCSERVER_BUILD_TYPE}") + set(CMAKE_BUILD_TYPE $ENV{MCSERVER_BUILD_TYPE}) +endif() + +if(DEFINED ENV{MCSERVER_FORCE32}) + set(FORCE32 $ENV{MCSERVER_FORCE32}) +endif() + # This has to be done before any flags have been set up. if(${BUILD_TOOLS}) add_subdirectory(Tools/MCADefrag/) -- cgit v1.2.3 From ffdf5f2022cbeb568cb6ff28448aad98876334b1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 7 Mar 2014 21:28:52 +0100 Subject: Fixed cBlockArea schematic string saving signature. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- src/Bindings/ManualBindings.cpp | 10 +++++++--- src/WorldStorage/SchematicFileSerializer.cpp | 7 +++---- src/WorldStorage/SchematicFileSerializer.h | 4 ++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 5f1b11a4c..1e572492b 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -162,7 +162,7 @@ g_APIDesc = RotateCW = { Params = "", Return = "", Notes = "Rotates the block area around the Y axis, clockwise (north -> east). Modifies blocks' metas (if present) to match." }, RotateCWNoMeta = { Params = "", Return = "", Notes = "Rotates the block area around the Y axis, clockwise (north -> east). Doesn't modify blocks' metas." }, SaveToSchematicFile = { Params = "FileName", Return = "", Notes = "Saves the current contents to a schematic file. Returns true if successful." }, - SaveToSchematicString = { Params = "", Return = "string", Notes = "Saves the current contents to a string (in a .schematic file format). Returns the data if successful, empty string if failed." }, + SaveToSchematicString = { Params = "", Return = "string", Notes = "Saves the current contents to a string (in a .schematic file format). Returns the data if successful, nil if failed." }, SetBlockLight = { Params = "BlockX, BlockY, BlockZ, BlockLight", Return = "", Notes = "Sets the blocklight at the specified absolute coords" }, SetBlockMeta = { Params = "BlockX, BlockY, BlockZ, BlockMeta", Return = "", Notes = "Sets the block meta at the specified absolute coords" }, SetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified absolute coords" }, diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 05dc9717e..a5247bbe6 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2563,9 +2563,13 @@ static int tolua_cBlockArea_SaveToSchematicString(lua_State * tolua_S) return 0; } - AString Data = cSchematicFileSerializer::SaveToSchematicString(*self); - L.Push(Data); - return 1; + AString Data; + if (cSchematicFileSerializer::SaveToSchematicString(*self, Data)) + { + L.Push(Data); + return 1; + } + return 0; } diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp index a6ae8d8e0..b021aeb0c 100644 --- a/src/WorldStorage/SchematicFileSerializer.cpp +++ b/src/WorldStorage/SchematicFileSerializer.cpp @@ -103,7 +103,7 @@ bool cSchematicFileSerializer::SaveToSchematicFile(const cBlockArea & a_BlockAre -AString cSchematicFileSerializer::SaveToSchematicString(const cBlockArea & a_BlockArea) +bool cSchematicFileSerializer::SaveToSchematicString(const cBlockArea & a_BlockArea, AString & a_Out) { // Serialize into NBT data: AString NBT = SaveToSchematicNBT(a_BlockArea); @@ -114,14 +114,13 @@ AString cSchematicFileSerializer::SaveToSchematicString(const cBlockArea & a_Blo } // Gzip the data: - AString Compressed; - int res = CompressStringGZIP(NBT.data(), NBT.size(), Compressed); + int res = CompressStringGZIP(NBT.data(), NBT.size(), a_Out); if (res != Z_OK) { LOG("%s: Cannot Gzip the area data NBT representation: %d", __FUNCTION__, res); return false; } - return Compressed; + return true; } diff --git a/src/WorldStorage/SchematicFileSerializer.h b/src/WorldStorage/SchematicFileSerializer.h index f6ce1c16c..05b6c74f4 100644 --- a/src/WorldStorage/SchematicFileSerializer.h +++ b/src/WorldStorage/SchematicFileSerializer.h @@ -36,8 +36,8 @@ public: static bool SaveToSchematicFile(const cBlockArea & a_BlockArea, const AString & a_FileName); /** Saves the area into a string containing the .schematic file data. - Returns the data, or empty string if failed. */ - static AString SaveToSchematicString(const cBlockArea & a_BlockArea); + Returns true if successful, false on failure. The data is stored into a_Out. */ + static bool SaveToSchematicString(const cBlockArea & a_BlockArea, AString & a_Out); private: /** Loads the area from a schematic file uncompressed and parsed into a NBT tree. -- cgit v1.2.3 From f5e374be41ef3bde93e0faaa76208e3e0e15e9ea Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 8 Mar 2014 10:25:46 +0100 Subject: Add TNT Save/Load and add Netbeans projects to .gitignore --- .gitignore | 1 + src/Entities/TNTEntity.cpp | 27 +++++++++++++++++---------- src/Entities/TNTEntity.h | 23 ++++++++++++++++------- src/WorldStorage/NBTChunkSerializer.cpp | 15 ++++++++++++++- src/WorldStorage/NBTChunkSerializer.h | 2 ++ src/WorldStorage/WSSAnvil.cpp | 28 ++++++++++++++++++++++++++++ src/WorldStorage/WSSAnvil.h | 1 + 7 files changed, 79 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index c8ad93a80..c544f394d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/ +nbproject/ ipch/ Win32/ MCServer/MCServer diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp index 339107b2e..4f361403c 100644 --- a/src/Entities/TNTEntity.cpp +++ b/src/Entities/TNTEntity.cpp @@ -10,8 +10,7 @@ cTNTEntity::cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec) : super(etTNT, a_X, a_Y, a_Z, 0.98, 0.98), - m_Counter(0), - m_MaxFuseTime(a_FuseTimeInSec) + m_FuseTicks(a_FuseTimeInSec) { } @@ -21,8 +20,7 @@ cTNTEntity::cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSe cTNTEntity::cTNTEntity(const Vector3d & a_Pos, double a_FuseTimeInSec) : super(etTNT, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98), - m_Counter(0), - m_MaxFuseTime(a_FuseTimeInSec) + m_FuseTicks(a_FuseTimeInSec) { } @@ -42,18 +40,27 @@ void cTNTEntity::SpawnOn(cClientHandle & a_ClientHandle) +void cTNTEntity::Explode(void) +{ + m_FuseTicks = 0; + Destroy(true); + LOGD("BOOM at {%f,%f,%f}", GetPosX(), GetPosY(), GetPosZ()); + m_World->DoExplosionAt(4.0, GetPosX() + 0.49, GetPosY() + 0.49, GetPosZ() + 0.49, true, esPrimedTNT, this); +} + + + + + void cTNTEntity::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); BroadcastMovementUpdate(); float delta_time = a_Dt / 1000; // Convert miliseconds to seconds - m_Counter += delta_time; - if (m_Counter > m_MaxFuseTime) // Check if we go KABOOOM + m_FuseTicks -= delta_time; + if (m_FuseTicks <= 0) { - Destroy(true); - LOGD("BOOM at {%f,%f,%f}", GetPosX(), GetPosY(), GetPosZ()); - m_World->DoExplosionAt(4.0, GetPosX() + 0.49, GetPosY() + 0.49, GetPosZ() + 0.49, true, esPrimedTNT, this); - return; + Explode(); } } diff --git a/src/Entities/TNTEntity.h b/src/Entities/TNTEntity.h index d1fcae766..8f83f52d9 100644 --- a/src/Entities/TNTEntity.h +++ b/src/Entities/TNTEntity.h @@ -16,19 +16,28 @@ public: // tolua_end CLASS_PROTODEF(cTNTEntity); - cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec); - cTNTEntity(const Vector3d & a_Pos, double a_FuseTimeInSec); + cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec = 4); + cTNTEntity(const Vector3d & a_Pos, double a_FuseTimeInSec = 4); // cEntity overrides: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - - double GetCounterTime(void) const { return m_Counter; } // tolua_export - double GetMaxFuseTime(void) const { return m_MaxFuseTime; } // tolua_export + + // tolua_begin + + /** Explode the tnt */ + void Explode(void); + + /** Returns the fuse ticks until the tnt will explode */ + double GetFuseTicks(void) const { return m_FuseTicks; } + + /** Set the fuse ticks until the tnt will explode */ + void SetFuseTicks(double a_FuseTicks) { m_FuseTicks = a_FuseTicks; } + + // tolua_end protected: - double m_Counter; ///< How much time has elapsed since the object was created, in seconds - double m_MaxFuseTime; ///< How long the fuse is, in seconds + double m_FuseTicks; ///< How much time in seconds is left, while the tnt will explode }; // tolua_export diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 6d0e29958..06b815333 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -28,6 +28,7 @@ #include "../Entities/Minecart.h" #include "../Entities/Pickup.h" #include "../Entities/ProjectileEntity.h" +#include "../Entities/TNTEntity.h" #include "../Mobs/Monster.h" #include "../Mobs/Bat.h" @@ -583,6 +584,18 @@ void cNBTChunkSerializer::AddProjectileEntity(cProjectileEntity * a_Projectile) +void cNBTChunkSerializer::AddTNTEntity(cTNTEntity * a_TNT) +{ + m_Writer.BeginCompound(""); + AddBasicEntity(a_TNT, "PrimedTnt"); + m_Writer.AddByte("Fuse", ((unsigned char)a_TNT->GetFuseTicks()) * 10); + m_Writer.EndCompound(); +} + + + + + void cNBTChunkSerializer::AddMinecartChestContents(cMinecartWithChest * a_Minecart) { m_Writer.BeginList("Items", TAG_Compound); @@ -662,7 +675,7 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity) case cEntity::etMonster: AddMonsterEntity ((cMonster *) a_Entity); break; case cEntity::etPickup: AddPickupEntity ((cPickup *) a_Entity); break; case cEntity::etProjectile: AddProjectileEntity ((cProjectileEntity *)a_Entity); break; - case cEntity::etTNT: /* TODO */ break; + case cEntity::etTNT: AddTNTEntity ((cTNTEntity *) a_Entity); break; case cEntity::etExpOrb: /* TODO */ break; case cEntity::etItemFrame: /* TODO */ break; case cEntity::etPainting: /* TODO */ break; diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index 8a9e18413..3b486d2bc 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -41,6 +41,7 @@ class cMonster; class cPickup; class cItemGrid; class cProjectileEntity; +class cTNTEntity; @@ -107,6 +108,7 @@ protected: void AddMonsterEntity (cMonster * a_Monster); void AddPickupEntity (cPickup * a_Pickup); void AddProjectileEntity (cProjectileEntity * a_Projectile); + void AddTNTEntity (cTNTEntity * a_TNT); void AddMinecartChestContents(cMinecartWithChest * a_Minecart); diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 680f2458f..fa0c4dbd9 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -36,6 +36,7 @@ #include "../Entities/Minecart.h" #include "../Entities/Pickup.h" #include "../Entities/ProjectileEntity.h" +#include "../Entities/TNTEntity.h" @@ -1231,6 +1232,10 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a { LoadPigZombieFromNBT(a_Entities, a_NBT, a_EntityTagIdx); } + else if (strncmp(a_IDTag, "PrimedTnt", a_IDTagLength) == 0) + { + LoadTNTFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + } // TODO: other entities } @@ -2167,6 +2172,29 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT +void cWSSAnvil::LoadTNTFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + std::auto_ptr TNT(new cTNTEntity(0.0, 0.0, 0.0, 0)); + if (!LoadEntityBaseFromNBT(*TNT.get(), a_NBT, a_TagIdx)) + { + return; + } + + // Load Fuse Ticks: + int FuseTicks = a_NBT.FindChildByName(a_TagIdx, "Fuse"); + if (FuseTicks > 0) + { + int MojangFuseTicks = (int) a_NBT.GetByte(FuseTicks); + TNT->SetFuseTicks((double) MojangFuseTicks / 10); + } + + a_Entities.push_back(TNT.release()); +} + + + + + bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx) { double Pos[3]; diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index b26345b13..fe93d16c3 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -192,6 +192,7 @@ protected: void LoadWolfFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadPigZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadTNTFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); /// Loads entity common data from the NBT compound; returns true if successful bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx); -- cgit v1.2.3 From baeff21a5b693a99057aa5a7dc218bf93630b35a Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 8 Mar 2014 10:29:57 +0100 Subject: Add new tnt documentation --- MCServer/Plugins/APIDump/APIDesc.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 39f7cbcd7..5cea49cb1 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2023,8 +2023,9 @@ end Desc = "This class manages a TNT entity.", Functions = { - GetCounterTime = { Return = "number", Notes = "Returns the time until the entity explodes." }, - GetMaxFuseTime = { Return = "number", Notes = "Returns how long the fuse was." }, + Explode = { Return = "", Notes = "Explode the tnt." }, + GetFuseTicks = { Return = "number", Notes = "Returns the fuse ticks (in seconds) until the tnt will explode." }, + SetFuseTicks = { Return = "number", Notes = "Set the fuse ticks (in seconds) until the tnt will explode." }, }, Inherits = "cEntity", }, -- cgit v1.2.3 From 6679641b9e5ddb833b32ab7163cabaa8003e769e Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 8 Mar 2014 12:53:15 +0200 Subject: cBlockInfo-related changes from #723 --- src/BlockInfo.cpp | 9 +++++++++ src/Blocks/BlockHandler.cpp | 1 + src/Items/ItemPickaxe.h | 22 +++++++++++----------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index 399efcd9b..20336a07c 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -271,6 +271,11 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_VINES ].m_IsSnowable = false; ms_Info[E_BLOCK_WALLSIGN ].m_IsSnowable = false; ms_Info[E_BLOCK_WATER ].m_IsSnowable = false; + ms_Info[E_BLOCK_RAIL ].m_IsSnowable = false; + ms_Info[E_BLOCK_ACTIVATOR_RAIL ].m_IsSnowable = false; + ms_Info[E_BLOCK_POWERED_RAIL ].m_IsSnowable = false; + ms_Info[E_BLOCK_DETECTOR_RAIL ].m_IsSnowable = false; + ms_Info[E_BLOCK_COBWEB ].m_IsSnowable = false; // Blocks that don't drop without a special tool: @@ -309,6 +314,10 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_RequiresSpecialTool = true; ms_Info[E_BLOCK_STONE_SLAB ].m_RequiresSpecialTool = true; ms_Info[E_BLOCK_VINES ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_FURNACE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_LIT_FURNACE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_ANVIL ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_ENCHANTMENT_TABLE ].m_RequiresSpecialTool = true; // Nonsolid blocks: diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index c5165986c..aa97b2ca9 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -146,6 +146,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_NETHER_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_NETHER_PORTAL: return new cBlockPortalHandler (a_BlockType); case E_BLOCK_NETHER_WART: return new cBlockNetherWartHandler (a_BlockType); + case E_BLOCK_NETHER_QUARTZ_ORE: return new cBlockOreHandler (a_BlockType); case E_BLOCK_NEW_LEAVES: return new cBlockNewLeavesHandler (a_BlockType); case E_BLOCK_NEW_LOG: return new cBlockSidewaysHandler (a_BlockType); case E_BLOCK_NOTE_BLOCK: return new cBlockNoteHandler (a_BlockType); diff --git a/src/Items/ItemPickaxe.h b/src/Items/ItemPickaxe.h index bde7f0905..2a8e40daa 100644 --- a/src/Items/ItemPickaxe.h +++ b/src/Items/ItemPickaxe.h @@ -19,17 +19,13 @@ public: { switch(m_ItemType) { - case E_ITEM_WOODEN_PICKAXE: - case E_ITEM_GOLD_PICKAXE: - return 1; - case E_ITEM_STONE_PICKAXE: - return 2; - case E_ITEM_IRON_PICKAXE: - return 3; - case E_ITEM_DIAMOND_PICKAXE: - return 4; - default: - return 0; + case E_ITEM_WOODEN_PICKAXE: return 1; + case E_ITEM_GOLD_PICKAXE: return 1; + case E_ITEM_STONE_PICKAXE: return 2; + case E_ITEM_IRON_PICKAXE: return 3; + case E_ITEM_DIAMOND_PICKAXE: return 4; + + default: return 0; } } @@ -61,6 +57,10 @@ public: return PickaxeLevel() >= 2; } + case E_BLOCK_ANVIL: + case E_BLOCK_ENCHANTMENT_TABLE: + case E_BLOCK_FURNACE: + case E_BLOCK_LIT_FURNACE: case E_BLOCK_COAL_ORE: case E_BLOCK_STONE: case E_BLOCK_COBBLESTONE: -- cgit v1.2.3 From b37966fd214fb048a415a33291a85ee8c263691c Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 8 Mar 2014 12:24:33 +0100 Subject: Change TNT Fuse to ticks --- src/BlockEntities/DispenserEntity.cpp | 2 +- src/Entities/TNTEntity.cpp | 12 ++++++------ src/Entities/TNTEntity.h | 10 +++++----- src/Items/ItemLighter.h | 4 ++-- src/Simulator/IncrementalRedstoneSimulator.cpp | 2 +- src/World.cpp | 4 ++-- src/World.h | 2 +- src/WorldStorage/NBTChunkSerializer.cpp | 2 +- src/WorldStorage/WSSAnvil.cpp | 3 +-- 9 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 374f3d6e3..cbfbb1b6a 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -116,7 +116,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) { double TNTX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width); double TNTZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - m_World->SpawnPrimedTNT(TNTX, DispY + 0.5, TNTZ, 4, 0); // 4 seconds fuse, no initial velocity + m_World->SpawnPrimedTNT(TNTX, DispY + 0.5, TNTZ, 80, 0); // 80 ticks fuse, no initial velocity m_Contents.ChangeSlotCount(a_SlotNum, -1); } break; diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp index 4f361403c..02f31f5bb 100644 --- a/src/Entities/TNTEntity.cpp +++ b/src/Entities/TNTEntity.cpp @@ -8,9 +8,9 @@ -cTNTEntity::cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec) : +cTNTEntity::cTNTEntity(double a_X, double a_Y, double a_Z, int a_FuseTicks) : super(etTNT, a_X, a_Y, a_Z, 0.98, 0.98), - m_FuseTicks(a_FuseTimeInSec) + m_FuseTicks(a_FuseTicks) { } @@ -18,9 +18,9 @@ cTNTEntity::cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSe -cTNTEntity::cTNTEntity(const Vector3d & a_Pos, double a_FuseTimeInSec) : +cTNTEntity::cTNTEntity(const Vector3d & a_Pos, int a_FuseTicks) : super(etTNT, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98), - m_FuseTicks(a_FuseTimeInSec) + m_FuseTicks(a_FuseTicks) { } @@ -56,8 +56,8 @@ void cTNTEntity::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); BroadcastMovementUpdate(); - float delta_time = a_Dt / 1000; // Convert miliseconds to seconds - m_FuseTicks -= delta_time; + + m_FuseTicks -= 1; if (m_FuseTicks <= 0) { Explode(); diff --git a/src/Entities/TNTEntity.h b/src/Entities/TNTEntity.h index 8f83f52d9..116f5a8cb 100644 --- a/src/Entities/TNTEntity.h +++ b/src/Entities/TNTEntity.h @@ -16,8 +16,8 @@ public: // tolua_end CLASS_PROTODEF(cTNTEntity); - cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec = 4); - cTNTEntity(const Vector3d & a_Pos, double a_FuseTimeInSec = 4); + cTNTEntity(double a_X, double a_Y, double a_Z, int a_FuseTicks = 80); + cTNTEntity(const Vector3d & a_Pos, int a_FuseTicks = 80); // cEntity overrides: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; @@ -29,15 +29,15 @@ public: void Explode(void); /** Returns the fuse ticks until the tnt will explode */ - double GetFuseTicks(void) const { return m_FuseTicks; } + int GetFuseTicks(void) const { return m_FuseTicks; } /** Set the fuse ticks until the tnt will explode */ - void SetFuseTicks(double a_FuseTicks) { m_FuseTicks = a_FuseTicks; } + void SetFuseTicks(int a_FuseTicks) { m_FuseTicks = a_FuseTicks; } // tolua_end protected: - double m_FuseTicks; ///< How much time in seconds is left, while the tnt will explode + int m_FuseTicks; ///< How much ticks is left, while the tnt will explode }; // tolua_export diff --git a/src/Items/ItemLighter.h b/src/Items/ItemLighter.h index cc7daeb08..18873e911 100644 --- a/src/Items/ItemLighter.h +++ b/src/Items/ItemLighter.h @@ -33,8 +33,8 @@ public: case E_BLOCK_TNT: { // Activate the TNT: - a_World->BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); - a_World->SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom + a_World->BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 1.0f, 1.0f); + a_World->SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5); // 80 ticks to boom a_World->SetBlock(a_BlockX,a_BlockY,a_BlockZ, E_BLOCK_AIR, 0); break; } diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index f377b0aa7..ca2ef4b1a 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -838,7 +838,7 @@ void cIncrementalRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_ if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) { m_World.BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); - m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom + m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5); // 80 ticks to boom m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); } } diff --git a/src/World.cpp b/src/World.cpp index ecb278e85..ebc37f7b2 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1725,10 +1725,10 @@ int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType -void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec, double a_InitialVelocityCoeff) +void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTicks, double a_InitialVelocityCoeff) { UNUSED(a_InitialVelocityCoeff); - cTNTEntity * TNT = new cTNTEntity(a_X, a_Y, a_Z, a_FuseTimeInSec); + cTNTEntity * TNT = new cTNTEntity(a_X, a_Y, a_Z, a_FuseTicks); TNT->Initialize(this); // TODO: Add a bit of speed in horiz and vert axes, based on the a_InitialVelocityCoeff } diff --git a/src/World.h b/src/World.h index e6c665785..517b6b4fa 100644 --- a/src/World.h +++ b/src/World.h @@ -445,7 +445,7 @@ public: int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward); /** Spawns a new primed TNT entity at the specified block coords and specified fuse duration. Initial velocity is given based on the relative coefficient provided */ - void SpawnPrimedTNT(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec, double a_InitialVelocityCoeff = 1); + void SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTimeInSec = 80, double a_InitialVelocityCoeff = 1); // tolua_end diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 06b815333..17cf838c3 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -588,7 +588,7 @@ void cNBTChunkSerializer::AddTNTEntity(cTNTEntity * a_TNT) { m_Writer.BeginCompound(""); AddBasicEntity(a_TNT, "PrimedTnt"); - m_Writer.AddByte("Fuse", ((unsigned char)a_TNT->GetFuseTicks()) * 10); + m_Writer.AddByte("Fuse", (unsigned char)a_TNT->GetFuseTicks()); m_Writer.EndCompound(); } diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index fa0c4dbd9..b52b74932 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2184,8 +2184,7 @@ void cWSSAnvil::LoadTNTFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB int FuseTicks = a_NBT.FindChildByName(a_TagIdx, "Fuse"); if (FuseTicks > 0) { - int MojangFuseTicks = (int) a_NBT.GetByte(FuseTicks); - TNT->SetFuseTicks((double) MojangFuseTicks / 10); + TNT->SetFuseTicks((int) a_NBT.GetByte(FuseTicks)); } a_Entities.push_back(TNT.release()); -- cgit v1.2.3 From 60091bcba3f5e533a5b2a749e40f52556297e867 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 8 Mar 2014 12:31:20 +0100 Subject: Change tnt documentation to ticks --- MCServer/Plugins/APIDump/APIDesc.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 6d8272a95..28dffc1b6 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2026,8 +2026,8 @@ end Functions = { Explode = { Return = "", Notes = "Explode the tnt." }, - GetFuseTicks = { Return = "number", Notes = "Returns the fuse ticks (in seconds) until the tnt will explode." }, - SetFuseTicks = { Return = "number", Notes = "Set the fuse ticks (in seconds) until the tnt will explode." }, + GetFuseTicks = { Return = "number", Notes = "Returns the fuse ticks until the tnt will explode." }, + SetFuseTicks = { Return = "number", Notes = "Set the fuse ticks until the tnt will explode." }, }, Inherits = "cEntity", }, @@ -2262,7 +2262,7 @@ end SpawnMob = { Params = "X, Y, Z, {{cMonster|MonsterType}}", Return = "EntityID", Notes = "Spawns the specified type of mob at the specified coords. Returns the EntityID of the creates entity, or -1 on failure. " }, SpawnFallingBlock = { Params = "X, Y, Z, BlockType, BlockMeta", Return = "EntityID", Notes = "Spawns an {{cFallingBlock|Falling Block}} entity at the specified coords with the given block type/meta" }, SpawnExperienceOrb = { Params = "X, Y, Z, Reward", Return = "EntityID", Notes = "Spawns an {{cExpOrb|experience orb}} at the specified coords, with the given reward" }, - SpawnPrimedTNT = { Params = "X, Y, Z, FuseTimeSecs, InitialVelocityCoeff", Return = "", Notes = "Spawns a {{cTNTEntity|primed TNT entity}} at the specified coords, with the given fuse time. The entity gets a random speed multiplied by the InitialVelocityCoeff, 1 being the default value." }, + SpawnPrimedTNT = { Params = "X, Y, Z, FuseTicks, InitialVelocityCoeff", Return = "", Notes = "Spawns a {{cTNTEntity|primed TNT entity}} at the specified coords, with the given fuse ticks. The entity gets a random speed multiplied by the InitialVelocityCoeff, 1 being the default value." }, TryGetHeight = { Params = "BlockX, BlockZ", Return = "IsValid, Height", Notes = "Returns true and height of the highest non-air block if the chunk is loaded, or false otherwise." }, UpdateSign = { Params = "X, Y, Z, Line1, Line2, Line3, Line4, [{{cPlayer|Player}}]", Return = "", Notes = "Sets the sign text at the specified coords. The sign-updating hooks are called for the change. The Player parameter is used to indicate the player from whom the change has come, it may be nil. Same as SetSignLiens()" }, UseBlockEntity = { Params = "{{cPlayer|Player}}, BlockX, BlockY, BlockZ", Return = "", Notes = "Makes the specified Player use the block entity at the specified coords (open chest UI, etc.) If the cords are in an unloaded chunk or there's no block entity, ignores the call." }, -- cgit v1.2.3 From 16ebbca35b8fc91061f0141625c292a8096e3b6d Mon Sep 17 00:00:00 2001 From: worktycho Date: Sat, 8 Mar 2014 14:23:00 +0000 Subject: Moved returns --- src/Blocks/MetaRotater.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h index 5493c87e2..d3664b6f1 100644 --- a/src/Blocks/MetaRotater.h +++ b/src/Blocks/MetaRotater.h @@ -1,4 +1,3 @@ - // MetaRotater.h // Provides a mixin for rotations and reflections @@ -44,11 +43,12 @@ NIBBLETYPE cMetaRotater NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) { @@ -63,8 +63,8 @@ NIBBLETYPE cMetaRotater Date: Sat, 8 Mar 2014 15:21:09 +0000 Subject: Disable -Werror on this branch --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 35831e7e9..6a8211fa2 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -182,7 +182,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter") + add_flags_cxx("-Wall -Wextra") # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") -- cgit v1.2.3 From 9b47366d0323f09c77b607da778191e79b65335b Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 8 Mar 2014 07:36:52 -0800 Subject: Actually Fixed ByteBuffer --- src/ByteBuffer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 32a367462..8080c1bdc 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -650,7 +650,7 @@ bool cByteBuffer::WriteLEInt(int a_Value) -bool cByteBuffer::ReadBuf(void * a_Buffer, int a_Count) +bool cByteBuffer::ReadBuf(void * a_Buffer, size_t a_Count) { CHECK_THREAD; CheckValid(); @@ -684,7 +684,7 @@ bool cByteBuffer::ReadBuf(void * a_Buffer, int a_Count) -bool cByteBuffer::WriteBuf(const void * a_Buffer, int a_Count) +bool cByteBuffer::WriteBuf(const void * a_Buffer, size_t a_Count) { CHECK_THREAD; CheckValid(); @@ -714,7 +714,7 @@ bool cByteBuffer::WriteBuf(const void * a_Buffer, int a_Count) -bool cByteBuffer::ReadString(AString & a_String, int a_Count) +bool cByteBuffer::ReadString(AString & a_String, size_t a_Count) { CHECK_THREAD; CheckValid(); -- cgit v1.2.3 From 307fad0f257c825c8d433a3e82f2989a8fddd3e0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 8 Mar 2014 08:33:38 -0800 Subject: Fixed issues with int vs size_t and a few other warnings --- src/BlockInfo.cpp | 2 -- src/Blocks/BlockHandler.h | 2 ++ src/ByteBuffer.cpp | 20 ++++++++++---------- src/ByteBuffer.h | 6 +++--- src/ClientHandle.cpp | 4 ++-- src/Entities/Minecart.cpp | 4 ++-- src/Entities/Minecart.h | 4 ++-- src/Protocol/Protocol17x.cpp | 4 ++-- src/Root.cpp | 6 ++---- src/Simulator/DelayedFluidSimulator.cpp | 2 +- 10 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index 20336a07c..d1ecfdf7e 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -42,8 +42,6 @@ cBlockInfo::~cBlockInfo() cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type) { - ASSERT(a_Type < 256); - return ms_Info[a_Type]; } diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 50c2e2ad5..3a3efb3cc 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -23,6 +23,8 @@ class cBlockHandler { public: cBlockHandler(BLOCKTYPE a_BlockType); + + virtual ~cBlockHandler() {} /// Called when the block gets ticked either by a random tick or by a queued tick. /// Note that the coords are chunk-relative! diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 8080c1bdc..bda1105f5 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -177,15 +177,15 @@ bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count) CheckValid(); // Store the current free space for a check after writing: - int CurFreeSpace = GetFreeSpace(); - int CurReadableSpace = GetReadableSpace(); - int WrittenBytes = 0; + size_t CurFreeSpace = GetFreeSpace(); + size_t CurReadableSpace = GetReadableSpace(); + size_t WrittenBytes = 0; if (CurFreeSpace < a_Count) { return false; } - int TillEnd = m_BufferSize - m_WritePos; + size_t TillEnd = m_BufferSize - m_WritePos; if (TillEnd <= a_Count) { // Need to wrap around the ringbuffer end @@ -216,7 +216,7 @@ bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count) -int cByteBuffer::GetFreeSpace(void) const +size_t cByteBuffer::GetFreeSpace(void) const { CHECK_THREAD; CheckValid(); @@ -234,7 +234,7 @@ int cByteBuffer::GetFreeSpace(void) const /// Returns the number of bytes that are currently in the ringbuffer. Note GetReadableBytes() -int cByteBuffer::GetUsedSpace(void) const +size_t cByteBuffer::GetUsedSpace(void) const { CHECK_THREAD; CheckValid(); @@ -246,7 +246,7 @@ int cByteBuffer::GetUsedSpace(void) const /// Returns the number of bytes that are currently available for reading (may be less than UsedSpace due to some data having been read already) -int cByteBuffer::GetReadableSpace(void) const +size_t cByteBuffer::GetReadableSpace(void) const { CHECK_THREAD; CheckValid(); @@ -657,7 +657,7 @@ bool cByteBuffer::ReadBuf(void * a_Buffer, size_t a_Count) ASSERT(a_Count >= 0); NEEDBYTES(a_Count); char * Dst = (char *)a_Buffer; // So that we can do byte math - int BytesToEndOfBuffer = m_BufferSize - m_ReadPos; + size_t BytesToEndOfBuffer = m_BufferSize - m_ReadPos; ASSERT(BytesToEndOfBuffer >= 0); // Sanity check if (BytesToEndOfBuffer <= a_Count) { @@ -691,7 +691,7 @@ bool cByteBuffer::WriteBuf(const void * a_Buffer, size_t a_Count) ASSERT(a_Count >= 0); PUTBYTES(a_Count); char * Src = (char *)a_Buffer; // So that we can do byte math - int BytesToEndOfBuffer = m_BufferSize - m_WritePos; + size_t BytesToEndOfBuffer = m_BufferSize - m_WritePos; if (BytesToEndOfBuffer <= a_Count) { // Reading across the ringbuffer end, read the first part and adjust parameters: @@ -722,7 +722,7 @@ bool cByteBuffer::ReadString(AString & a_String, size_t a_Count) NEEDBYTES(a_Count); a_String.clear(); a_String.reserve(a_Count); - int BytesToEndOfBuffer = m_BufferSize - m_ReadPos; + size_t BytesToEndOfBuffer = m_BufferSize - m_ReadPos; ASSERT(BytesToEndOfBuffer >= 0); // Sanity check if (BytesToEndOfBuffer <= a_Count) { diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h index 5fdf48c28..ed2e10a55 100644 --- a/src/ByteBuffer.h +++ b/src/ByteBuffer.h @@ -34,13 +34,13 @@ public: bool Write(const char * a_Bytes, size_t a_Count); /// Returns the number of bytes that can be successfully written to the ringbuffer - int GetFreeSpace(void) const; + size_t GetFreeSpace(void) const; /// Returns the number of bytes that are currently in the ringbuffer. Note GetReadableBytes() - int GetUsedSpace(void) const; + size_t GetUsedSpace(void) const; /// Returns the number of bytes that are currently available for reading (may be less than UsedSpace due to some data having been read already) - int GetReadableSpace(void) const; + size_t GetReadableSpace(void) const; /// Returns the current data start index. For debugging purposes. int GetDataStart(void) const { return m_DataStart; } diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 870568cdf..53c859721 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -96,8 +96,8 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_ShouldCheckDownloaded(false), m_NumExplosionsThisTick(0), m_UniqueID(0), - m_Locale("en_GB"), - m_HasSentPlayerChunk(false) + m_HasSentPlayerChunk(false), + m_Locale("en_GB") { m_Protocol = new cProtocolRecognizer(this); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index f52a7b6d9..7f38aa35a 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -1031,9 +1031,9 @@ cMinecartWithChest::cMinecartWithChest(double a_X, double a_Y, double a_Z) : -void cMinecartWithChest::SetSlot(int a_Idx, const cItem & a_Item) +void cMinecartWithChest::SetSlot(size_t a_Idx, const cItem & a_Item) { - ASSERT((a_Idx >= 0) && (a_Idx < ARRAYCOUNT(m_Items))); + ASSERT(a_Idx < ARRAYCOUNT(m_Items)); m_Items[a_Idx] = a_Item; } diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index 073e78953..ebdb576e0 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -122,7 +122,7 @@ public: const cItem & GetSlot(int a_Idx) const { return m_Items[a_Idx]; } cItem & GetSlot(int a_Idx) { return m_Items[a_Idx]; } - void SetSlot(int a_Idx, const cItem & a_Item); + void SetSlot(size_t a_Idx, const cItem & a_Item); protected: @@ -193,4 +193,4 @@ public: CLASS_PROTODEF(cMinecartWithHopper); cMinecartWithHopper(double a_X, double a_Y, double a_Z); -} ; \ No newline at end of file +} ; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index cb9e5b9b1..8e0d33227 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1244,7 +1244,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) if (m_ReceivedData.GetReadableSpace() > 0) { AString AllData; - int OldReadableSpace = m_ReceivedData.GetReadableSpace(); + size_t OldReadableSpace = m_ReceivedData.GetReadableSpace(); m_ReceivedData.ReadAll(AllData); m_ReceivedData.ResetRead(); m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace); @@ -1366,7 +1366,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) if (g_ShouldLogCommIn && (m_ReceivedData.GetReadableSpace() > 0)) { AString AllData; - int OldReadableSpace = m_ReceivedData.GetReadableSpace(); + size_t OldReadableSpace = m_ReceivedData.GetReadableSpace(); m_ReceivedData.ReadAll(AllData); m_ReceivedData.ResetRead(); m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace); diff --git a/src/Root.cpp b/src/Root.cpp index 78c94888d..69f18104e 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -593,7 +593,6 @@ bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallbac unsigned m_NameLength; const AString m_PlayerName; - cPlayerListCallback & m_Callback; virtual bool Item (cPlayer * a_pPlayer) { unsigned int Rating = RateCompareString (m_PlayerName, a_pPlayer->GetName()); @@ -615,18 +614,17 @@ bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallbac } public: - cCallback (const AString & a_PlayerName, cPlayerListCallback & a_Callback) : + cCallback (const AString & a_PlayerName) : m_BestRating(0), m_NameLength(a_PlayerName.length()), m_PlayerName(a_PlayerName), - m_Callback(a_Callback), m_BestMatch(NULL), m_NumMatches(0) {} cPlayer * m_BestMatch; unsigned m_NumMatches; - } Callback (a_PlayerName, a_Callback); + } Callback (a_PlayerName); ForEachPlayer( Callback ); if (Callback.m_NumMatches == 1) diff --git a/src/Simulator/DelayedFluidSimulator.cpp b/src/Simulator/DelayedFluidSimulator.cpp index 3d2170e44..bc5158d95 100644 --- a/src/Simulator/DelayedFluidSimulator.cpp +++ b/src/Simulator/DelayedFluidSimulator.cpp @@ -20,7 +20,7 @@ bool cDelayedFluidSimulatorChunkData::cSlot::Add(int a_RelX, int a_RelY, int a_RelZ) { ASSERT(a_RelZ >= 0); - ASSERT(a_RelZ < ARRAYCOUNT(m_Blocks)); + ASSERT(a_RelZ < static_cast(ARRAYCOUNT(m_Blocks))); cCoordWithIntVector & Blocks = m_Blocks[a_RelZ]; int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); -- cgit v1.2.3 From 66970fe943ccc414c2f4fb722852f0461b8ddca2 Mon Sep 17 00:00:00 2001 From: Jan-Fabian Humann Date: Sat, 8 Mar 2014 17:55:53 +0100 Subject: Split cClientHandle::HandleEntityAction() into three seperate functions HandleEntityCrouch, HandleEntityLeaveBed and HandleEntitySprinting. --- src/ClientHandle.cpp | 58 +++++++++++++++++++++++--------------------- src/ClientHandle.h | 4 ++- src/Protocol/Protocol125.cpp | 23 +++++++++++++++++- src/Protocol/Protocol16x.cpp | 23 +++++++++++++++++- src/Protocol/Protocol17x.cpp | 22 ++++++++++++++++- 5 files changed, 98 insertions(+), 32 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 870568cdf..79fdc5e04 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1453,7 +1453,7 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) -void cClientHandle::HandleEntityAction(int a_EntityID, char a_ActionID) +void cClientHandle::HandleEntityCrouch(int a_EntityID, bool a_IsCrouching) { if (a_EntityID != m_Player->GetUniqueID()) { @@ -1461,35 +1461,37 @@ void cClientHandle::HandleEntityAction(int a_EntityID, char a_ActionID) return; } - switch (a_ActionID) + m_Player->SetCrouch(a_IsCrouching); +} + + + + + +void cClientHandle::HandleEntityLeaveBed(int a_EntityID) +{ + if (a_EntityID != m_Player->GetUniqueID()) { - case 1: // Crouch - { - m_Player->SetCrouch(true); - break; - } - case 2: // Uncrouch - { - m_Player->SetCrouch(false); - break; - } - case 3: // Leave bed - { - m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, 2); - break; - } - case 4: // Start sprinting - { - m_Player->SetSprint(true); - break; - } - case 5: // Stop sprinting - { - m_Player->SetSprint(false); - SendPlayerMaxSpeed(); - break; - } + // We should only receive entity actions from the entity that is performing the action + return; } + + m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, 2); +} + + + + + +void cClientHandle::HandleEntitySprinting(int a_EntityID, bool a_IsSprinting) +{ + if (a_EntityID != m_Player->GetUniqueID()) + { + // We should only receive entity actions from the entity that is performing the action + return; + } + + m_Player->SetSprint(a_IsSprinting); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 194533402..035fadfe4 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -188,7 +188,9 @@ public: void HandleChat (const AString & a_Message); void HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem); void HandleDisconnect (const AString & a_Reason); - void HandleEntityAction (int a_EntityID, char a_ActionID); + void HandleEntityCrouch (int a_EntityID, bool a_IsCrouching); + void HandleEntityLeaveBed (int a_EntityID); + void HandleEntitySprinting (int a_EntityID, bool a_IsSprinting); /** Called when the protocol handshake has been received (for protocol versions that support it; otherwise the first instant when a username is received). diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 3980350f5..556ed1d08 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1375,7 +1375,28 @@ int cProtocol125::ParseEntityAction(void) { HANDLE_PACKET_READ(ReadBEInt, int, EntityID); HANDLE_PACKET_READ(ReadChar, char, ActionID); - m_Client->HandleEntityAction(EntityID, ActionID); + + if (ActionID == 1) // Crouch + { + m_Client->HandleEntityCrouch(EntityID, true); + } + else if (ActionID == 2) // Uncrouch + { + m_Client->HandleEntityCrouch(EntityID, false); + } + else if (ActionID == 3) // Leave Bed + { + m_Client->HandleEntityLeaveBed(EntityID); + } + else if (ActionID == 4) // Start sprinting + { + m_Client->HandleEntitySprinting(EntityID, true); + } + else if (ActionID == 5) // Stop sprinting + { + m_Client->HandleEntitySprinting(EntityID, false); + } + return PARSE_OK; } diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index cfa27b3c4..6a41a577f 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -184,7 +184,28 @@ int cProtocol161::ParseEntityAction(void) HANDLE_PACKET_READ(ReadBEInt, int, EntityID); HANDLE_PACKET_READ(ReadChar, char, ActionID); HANDLE_PACKET_READ(ReadBEInt, int, UnknownHorseVal); - m_Client->HandleEntityAction(EntityID, ActionID); + + if (ActionID == 1) // Crouch + { + m_Client->HandleEntityCrouch(EntityID, true); + } + else if (ActionID == 2) // Uncrouch + { + m_Client->HandleEntityCrouch(EntityID, false); + } + else if (ActionID == 3) // Leave Bed + { + m_Client->HandleEntityLeaveBed(EntityID); + } + else if (ActionID == 4) // Start sprinting + { + m_Client->HandleEntitySprinting(EntityID, true); + } + else if (ActionID == 5) // Stop sprinting + { + m_Client->HandleEntitySprinting(EntityID, false); + } + return PARSE_OK; } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 18646254f..19998a483 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1732,7 +1732,27 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEInt, int, PlayerID); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Action); HANDLE_READ(a_ByteBuffer, ReadBEInt, int, JumpBoost); - m_Client->HandleEntityAction(PlayerID, Action); + + if (Action == 1) // Crouch + { + m_Client->HandleEntityCrouch(PlayerID, true); + } + else if (Action == 2) // Uncrouch + { + m_Client->HandleEntityCrouch(PlayerID, false); + } + else if (Action == 3) // Leave Bed + { + m_Client->HandleEntityLeaveBed(PlayerID); + } + else if (Action == 4) // Start sprinting + { + m_Client->HandleEntitySprinting(PlayerID, true); + } + else if (Action == 5) // Stop sprinting + { + m_Client->HandleEntitySprinting(PlayerID, false); + } } -- cgit v1.2.3 From 72f9c8b06970cb351121ad1e02cccc268db8c56d Mon Sep 17 00:00:00 2001 From: Jan-Fabian Humann Date: Sat, 8 Mar 2014 19:26:32 +0100 Subject: Changed if-else to switch-case --- src/Protocol/Protocol125.cpp | 24 +++++++++++------------- src/Protocol/Protocol16x.cpp | 24 +++++++++++------------- src/Protocol/Protocol17x.cpp | 24 +++++++++++------------- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 556ed1d08..169ab0c85 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1376,25 +1376,23 @@ int cProtocol125::ParseEntityAction(void) HANDLE_PACKET_READ(ReadBEInt, int, EntityID); HANDLE_PACKET_READ(ReadChar, char, ActionID); - if (ActionID == 1) // Crouch + switch (ActionID) { + case 1: // Crouch m_Client->HandleEntityCrouch(EntityID, true); - } - else if (ActionID == 2) // Uncrouch - { + break; + case 2: // Uncrouch m_Client->HandleEntityCrouch(EntityID, false); - } - else if (ActionID == 3) // Leave Bed - { + break; + case 3: // Leave Bed m_Client->HandleEntityLeaveBed(EntityID); - } - else if (ActionID == 4) // Start sprinting - { + break; + case 4: // Start sprinting m_Client->HandleEntitySprinting(EntityID, true); - } - else if (ActionID == 5) // Stop sprinting - { + break; + case 5: // Stop sprinting m_Client->HandleEntitySprinting(EntityID, false); + break; } return PARSE_OK; diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index 6a41a577f..4b1b4f408 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -185,25 +185,23 @@ int cProtocol161::ParseEntityAction(void) HANDLE_PACKET_READ(ReadChar, char, ActionID); HANDLE_PACKET_READ(ReadBEInt, int, UnknownHorseVal); - if (ActionID == 1) // Crouch + switch (ActionID) { + case 1: // Crouch m_Client->HandleEntityCrouch(EntityID, true); - } - else if (ActionID == 2) // Uncrouch - { + break; + case 2: // Uncrouch m_Client->HandleEntityCrouch(EntityID, false); - } - else if (ActionID == 3) // Leave Bed - { + break; + case 3: // Leave Bed m_Client->HandleEntityLeaveBed(EntityID); - } - else if (ActionID == 4) // Start sprinting - { + break; + case 4: // Start sprinting m_Client->HandleEntitySprinting(EntityID, true); - } - else if (ActionID == 5) // Stop sprinting - { + break; + case 5: // Stop sprinting m_Client->HandleEntitySprinting(EntityID, false); + break; } return PARSE_OK; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 19998a483..b0ec72a7d 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1733,25 +1733,23 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Action); HANDLE_READ(a_ByteBuffer, ReadBEInt, int, JumpBoost); - if (Action == 1) // Crouch + switch (Action) { + case 1: // Crouch m_Client->HandleEntityCrouch(PlayerID, true); - } - else if (Action == 2) // Uncrouch - { + break; + case 2: // Unchrouch m_Client->HandleEntityCrouch(PlayerID, false); - } - else if (Action == 3) // Leave Bed - { + break; + case 3: // Leave Bed m_Client->HandleEntityLeaveBed(PlayerID); - } - else if (Action == 4) // Start sprinting - { + break; + case 4: // Start sprinting m_Client->HandleEntitySprinting(PlayerID, true); - } - else if (Action == 5) // Stop sprinting - { + break; + case 5: // Stop sprinting m_Client->HandleEntitySprinting(PlayerID, false); + break; } } -- cgit v1.2.3 From 27fa2b72ba629e8175d33dace463bd7b7035a6e0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 8 Mar 2014 11:05:37 -0800 Subject: Enabled self test of bytebuffer --- src/ByteBuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index bda1105f5..adb8e9294 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -44,7 +44,7 @@ -#if 0 +#ifdef SELF_TEST /// Self-test of the VarInt-reading and writing code class cByteBufferSelfTest -- cgit v1.2.3 From a6ed75c1fbd7d3a38336e8649b59950837529b14 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 8 Mar 2014 11:18:51 -0800 Subject: Added tons more asserts to bytebuffer --- src/ByteBuffer.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index adb8e9294..67fe1012c 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -185,6 +185,7 @@ bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count) { return false; } + ASSERT(m_BufferSize >= m_WritePos); size_t TillEnd = m_BufferSize - m_WritePos; if (TillEnd <= a_Count) { @@ -223,9 +224,13 @@ size_t cByteBuffer::GetFreeSpace(void) const if (m_WritePos >= m_DataStart) { // Wrap around the buffer end: + ASSERT(m_BufferSize >= m_WritePos); + ASSERT((m_BufferSize - m_WritePos + m_DataStart) >= 1); return m_BufferSize - m_WritePos + m_DataStart - 1; } // Single free space partition: + ASSERT(m_BufferSize >= m_WritePos); + ASSERT(m_BufferSize - m_WritePos >= 1); return m_DataStart - m_WritePos - 1; } @@ -238,6 +243,8 @@ size_t cByteBuffer::GetUsedSpace(void) const { CHECK_THREAD; CheckValid(); + ASSERT(m_BufferSize >= GetFreeSpace()); + ASSERT((m_BufferSize - GetFreeSpace()) >= 1); return m_BufferSize - GetFreeSpace() - 1; } @@ -253,9 +260,11 @@ size_t cByteBuffer::GetReadableSpace(void) const if (m_ReadPos > m_WritePos) { // Wrap around the buffer end: + ASSERT(m_BufferSize >= m_ReadPos); return m_BufferSize - m_ReadPos + m_WritePos; } // Single readable space partition: + ASSERT(m_WritePos >= m_ReadPos); return m_WritePos - m_ReadPos ; } @@ -654,11 +663,10 @@ bool cByteBuffer::ReadBuf(void * a_Buffer, size_t a_Count) { CHECK_THREAD; CheckValid(); - ASSERT(a_Count >= 0); NEEDBYTES(a_Count); char * Dst = (char *)a_Buffer; // So that we can do byte math + ASSERT(m_BufferSize >= m_ReadPos); size_t BytesToEndOfBuffer = m_BufferSize - m_ReadPos; - ASSERT(BytesToEndOfBuffer >= 0); // Sanity check if (BytesToEndOfBuffer <= a_Count) { // Reading across the ringbuffer end, read the first part and adjust parameters: @@ -688,9 +696,9 @@ bool cByteBuffer::WriteBuf(const void * a_Buffer, size_t a_Count) { CHECK_THREAD; CheckValid(); - ASSERT(a_Count >= 0); PUTBYTES(a_Count); char * Src = (char *)a_Buffer; // So that we can do byte math + ASSERT(m_BufferSize >= m_ReadPos); size_t BytesToEndOfBuffer = m_BufferSize - m_WritePos; if (BytesToEndOfBuffer <= a_Count) { @@ -718,18 +726,18 @@ bool cByteBuffer::ReadString(AString & a_String, size_t a_Count) { CHECK_THREAD; CheckValid(); - ASSERT(a_Count >= 0); NEEDBYTES(a_Count); a_String.clear(); a_String.reserve(a_Count); + ASSERT(m_BufferSize >= m_ReadPos); size_t BytesToEndOfBuffer = m_BufferSize - m_ReadPos; - ASSERT(BytesToEndOfBuffer >= 0); // Sanity check if (BytesToEndOfBuffer <= a_Count) { // Reading across the ringbuffer end, read the first part and adjust parameters: if (BytesToEndOfBuffer > 0) { a_String.assign(m_Buffer + m_ReadPos, BytesToEndOfBuffer); + ASSERT(a_Count >= BytesToEndOfBuffer); a_Count -= BytesToEndOfBuffer; } m_ReadPos = 0; @@ -771,7 +779,6 @@ bool cByteBuffer::SkipRead(size_t a_Count) { CHECK_THREAD; CheckValid(); - ASSERT(a_Count >= 0); if (!CanReadBytes(a_Count)) { return false; @@ -809,6 +816,7 @@ bool cByteBuffer::ReadToByteBuffer(cByteBuffer & a_Dst, size_t a_NumBytes) size_t num = (a_NumBytes > sizeof(buf)) ? sizeof(buf) : a_NumBytes; VERIFY(ReadBuf(buf, num)); VERIFY(a_Dst.Write(buf, num)); + ASSERT(a_NumBytes >= num); a_NumBytes -= num; } return true; @@ -846,13 +854,15 @@ void cByteBuffer::ReadAgain(AString & a_Out) // Used by ProtoProxy to repeat communication twice, once for parsing and the other time for the remote party CHECK_THREAD; CheckValid(); - int DataStart = m_DataStart; + size_t DataStart = m_DataStart; if (m_ReadPos < m_DataStart) { // Across the ringbuffer end, read the first part and adjust next part's start: + ASSERT(m_BufferSize >= m_DataStart); a_Out.append(m_Buffer + m_DataStart, m_BufferSize - m_DataStart); DataStart = 0; } + ASSERT(m_ReadPos >= DataStart); a_Out.append(m_Buffer + DataStart, m_ReadPos - DataStart); } -- cgit v1.2.3 From 6b530bde75b33be5f88444cc583548a2e7292a97 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 8 Mar 2014 11:53:37 -0800 Subject: Added static --- src/ByteBuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 67fe1012c..a3b40e5ef 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -47,7 +47,7 @@ #ifdef SELF_TEST /// Self-test of the VarInt-reading and writing code -class cByteBufferSelfTest +static class cByteBufferSelfTest { public: cByteBufferSelfTest(void) -- cgit v1.2.3 From 17f27d1750083dc0a3eb958d554184839d7f92f2 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 8 Mar 2014 21:14:59 +0100 Subject: Added switch case indent notice --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a0a332f30..7ec7058ae 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,8 +22,10 @@ Code Stuff - This helps prevent mistakes such as `if (a & 1 == 0)` * White space is free, so use it freely - "freely" as in "plentifully", not "arbitrarily" + * All `case` statements inside a `switch` need an extra indent. * Each and every control statement deserves its braces. This helps maintainability later on when the file is edited, lines added or removed - the control logic doesn't break so easily. - The only exception: a `switch` statement with all `case` statements being a single short statement is allowed to use the short brace-less form. + - These two rules really mean that indent is governed by braces * Add an empty last line in all source files (GCC and GIT can complain otherwise) * Use doxy-comments for functions in the header file, format as `/** Description */` * Use spaces after the comment markers: `// Comment` instead of `//Comment` -- cgit v1.2.3 From 8d2ebf8e19e1556d256f75678d2272bb6739030f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 6 Mar 2014 20:06:53 +0000 Subject: Slight plugin messaging changes - Clients are not allowed to register duplicate channels - Clients are not allowed to use channels that were not registered --- src/ClientHandle.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 870568cdf..c677862eb 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -555,12 +555,25 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString } else if (a_Channel == "REGISTER") { + if (HasPluginChannel(a_Channel)) + { + SendPluginMessage("UNREGISTER", a_Channel); + return; // Can't register again if already taken - kinda defeats the point of plugin messaging! + } + RegisterPluginChannels(BreakApartPluginChannels(a_Message)); } else if (a_Channel == "UNREGISTER") { UnregisterPluginChannels(BreakApartPluginChannels(a_Message)); } + else if (!HasPluginChannel(a_Channel)) + { + // Ignore if client sent something but didn't register the channel first + LOGD("Player %s sent a plugin message on channel \"%s\", but didn't REGISTER it first", GetUsername().c_str(), a_Channel.c_str()); + SendPluginMessage("UNREGISTER", a_Channel); + return; + } cPluginManager::Get()->CallHookPluginMessage(*this, a_Channel, a_Message); } -- cgit v1.2.3 From ff186f9735bd08727d6d010e6815c103b2e181e8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Mar 2014 01:23:55 +0000 Subject: TNT explodes when consumed by fire Fixed FS#406 --- src/Simulator/FireSimulator.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index 4967c83f9..6079ea740 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -335,20 +335,33 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel { BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; - if (!a_Chunk->UnboundedRelGetBlock(a_RelX + gNeighborCoords[i].x, a_RelY + gNeighborCoords[i].y, a_RelZ + gNeighborCoords[i].z, BlockType, BlockMeta)) + int X = a_RelX + gNeighborCoords[i].x; + int Z = a_RelZ + gNeighborCoords[i].z; + + cChunkPtr Neighbour = a_Chunk->GetRelNeighborChunkAdjustCoords(X, Z); + if (Neighbour == NULL) { - // Neighbor not accessible, ignore it continue; } + Neighbour->GetBlockTypeMeta(X, a_RelY + gCrossCoords[i].y, Z, BlockType, BlockMeta); + if (!IsFuel(BlockType)) { continue; } + + if (BlockType == E_BLOCK_TNT) + { + int AbsX = X + Neighbour->GetPosX() * cChunkDef::Width; + int AbsZ = Z + Neighbour->GetPosZ() * cChunkDef::Width; + + m_World.SpawnPrimedTNT(AbsX, a_RelY + gNeighborCoords[i].y, AbsZ, 0); + Neighbour->SetBlock(X, a_RelY + gNeighborCoords[i].y, Z, E_BLOCK_AIR, 0); + return; + } + bool ShouldReplaceFuel = (m_World.GetTickRandomNumber(MAX_CHANCE_REPLACE_FUEL) < m_ReplaceFuelChance); - a_Chunk->UnboundedRelSetBlock( - a_RelX + gNeighborCoords[i].x, a_RelY + gNeighborCoords[i].y, a_RelZ + gNeighborCoords[i].z, - ShouldReplaceFuel ? E_BLOCK_FIRE : E_BLOCK_AIR, 0 - ); + Neighbour->SetBlock(X, a_RelY + gNeighborCoords[i].y, Z, ShouldReplaceFuel ? E_BLOCK_FIRE : E_BLOCK_AIR, 0); } // for i - Coords[] } -- cgit v1.2.3 From d872f2e41dfe141e1b04cdfb73c915b9bcdb55ea Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Mar 2014 01:49:32 +0000 Subject: Updated Core --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 3b416b07a..013a32a7f 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 3b416b07a339b3abcbc127070d56eea05b05373d +Subproject commit 013a32a7fb3c8a6cfe0aef892d4c7394d4e1be59 -- cgit v1.2.3 From f74ee8fb51c015f678438cc1dccf23d1d3c2cf6a Mon Sep 17 00:00:00 2001 From: Jan-Fabian Humann Date: Sun, 9 Mar 2014 10:55:06 +0100 Subject: Adjusted style of switch/case --- src/Protocol/Protocol125.cpp | 20 +++++--------------- src/Protocol/Protocol16x.cpp | 20 +++++--------------- src/Protocol/Protocol17x.cpp | 20 +++++--------------- 3 files changed, 15 insertions(+), 45 deletions(-) diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 169ab0c85..ca286bafb 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1378,21 +1378,11 @@ int cProtocol125::ParseEntityAction(void) switch (ActionID) { - case 1: // Crouch - m_Client->HandleEntityCrouch(EntityID, true); - break; - case 2: // Uncrouch - m_Client->HandleEntityCrouch(EntityID, false); - break; - case 3: // Leave Bed - m_Client->HandleEntityLeaveBed(EntityID); - break; - case 4: // Start sprinting - m_Client->HandleEntitySprinting(EntityID, true); - break; - case 5: // Stop sprinting - m_Client->HandleEntitySprinting(EntityID, false); - break; + case 1: m_Client->HandleEntityCrouch(EntityID, true); break; // Crouch + case 2: m_Client->HandleEntityCrouch(EntityID, false); break; // Uncrouch + case 3: m_Client->HandleEntityLeaveBed(EntityID); break; // Leave Bed + case 4: m_Client->HandleEntitySprinting(EntityID, true); break; // Start sprinting + case 5: m_Client->HandleEntitySprinting(EntityID, false); break; // Stop sprinting } return PARSE_OK; diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index 4b1b4f408..f6ec0a199 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -187,21 +187,11 @@ int cProtocol161::ParseEntityAction(void) switch (ActionID) { - case 1: // Crouch - m_Client->HandleEntityCrouch(EntityID, true); - break; - case 2: // Uncrouch - m_Client->HandleEntityCrouch(EntityID, false); - break; - case 3: // Leave Bed - m_Client->HandleEntityLeaveBed(EntityID); - break; - case 4: // Start sprinting - m_Client->HandleEntitySprinting(EntityID, true); - break; - case 5: // Stop sprinting - m_Client->HandleEntitySprinting(EntityID, false); - break; + case 1: m_Client->HandleEntityCrouch(EntityID, true); break; // Crouch + case 2: m_Client->HandleEntityCrouch(EntityID, false); break; // Uncrouch + case 3: m_Client->HandleEntityLeaveBed(EntityID); break; // Leave Bed + case 4: m_Client->HandleEntitySprinting(EntityID, true); break; // Start sprinting + case 5: m_Client->HandleEntitySprinting(EntityID, false); break; // Stop sprinting } return PARSE_OK; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index b0ec72a7d..0bb9a1204 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1735,21 +1735,11 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer) switch (Action) { - case 1: // Crouch - m_Client->HandleEntityCrouch(PlayerID, true); - break; - case 2: // Unchrouch - m_Client->HandleEntityCrouch(PlayerID, false); - break; - case 3: // Leave Bed - m_Client->HandleEntityLeaveBed(PlayerID); - break; - case 4: // Start sprinting - m_Client->HandleEntitySprinting(PlayerID, true); - break; - case 5: // Stop sprinting - m_Client->HandleEntitySprinting(PlayerID, false); - break; + case 1: m_Client->HandleEntityCrouch(PlayerID, true); break; // Crouch + case 2: m_Client->HandleEntityCrouch(PlayerID, false); break; // Uncrouch + case 3: m_Client->HandleEntityLeaveBed(PlayerID); break; // Leave Bed + case 4: m_Client->HandleEntitySprinting(PlayerID, true); break; // Start sprinting + case 5: m_Client->HandleEntitySprinting(PlayerID, false); break; // Stop sprinting } } -- cgit v1.2.3 From b4e3d0aa4e573200d1fffc3073e791c54d9eb20c Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 04:37:36 -0700 Subject: Turned off Wunused-parameter --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index e6ba782fc..4e20c84ab 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -182,7 +182,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter -Wno-error=switch") + add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch") # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") -- cgit v1.2.3 From 14c2f620d181614cd87270f8811b162858b53a49 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 04:43:22 -0700 Subject: FIxed int in test --- src/ByteBuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index a3b40e5ef..96a135562 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -86,7 +86,7 @@ public: cByteBuffer buf(3); for (int i = 0; i < 1000; i++) { - int FreeSpace = buf.GetFreeSpace(); + size_t FreeSpace = buf.GetFreeSpace(); assert(buf.GetReadableSpace() == 0); assert(FreeSpace > 0); assert(buf.Write("a", 1)); -- cgit v1.2.3 From 59d42ec5b2c666f1f50c9763dad13e97e2c6040f Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 04:58:08 -0700 Subject: Enabled loads of clang warnings --- SetFlags.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SetFlags.cmake b/SetFlags.cmake index 4e20c84ab..56d32b8fe 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -190,6 +190,8 @@ macro(set_exe_flags) # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") add_flags_cxx("-D__extern_always_inline=inline") + add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") + add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation") endif() endif() -- cgit v1.2.3 From 4cb0b82d1df560ad32c92eede91f466c75a87c87 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 05:05:37 -0700 Subject: Fixed some warnings --- src/ChunkDef.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 7be2fa2df..63431f211 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -65,8 +65,8 @@ public: enum { // Chunk dimensions: - Width = 16, - Height = 256, + Width = 16U, + Height = 256U, NumBlocks = Width * Height * Width, /// If the data is collected into a single buffer, how large it needs to be: @@ -132,7 +132,7 @@ public: } - inline static unsigned int MakeIndexNoCheck(int x, int y, int z) + inline static unsigned int MakeIndexNoCheck(unsigned int x, unsigned int y, unsigned int z) { #if AXIS_ORDER == AXIS_ORDER_XZY // For some reason, NOT using the Horner schema is faster. Weird. @@ -240,7 +240,7 @@ public: { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { - int Index = MakeIndexNoCheck(x, y, z); + unsigned int Index = MakeIndexNoCheck(x, y, z); return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); @@ -256,7 +256,7 @@ public: return; } a_Buffer[a_BlockIdx / 2] = ( - (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble + (a_Buffer[a_BlockIdx / 2] & (0xf0 >> (static_cast(a_BlockIdx & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set ); } @@ -282,13 +282,13 @@ public: } - inline static char GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos ) + inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos ) { return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z ); } - inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, char a_Value ) + inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value ) { SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value ); } @@ -306,6 +306,9 @@ The virtual methods are called in the same order as they're declared here. class cChunkDataCallback abstract { public: + + virtual ~cChunkDataCallback() {} + /** Called before any other callbacks to inform of the current coords (only in processes where multiple chunks can be processed, such as cWorld::ForEachChunkInRect()). If false is returned, the chunk is skipped. -- cgit v1.2.3 From e2cbebe522c8d52dc68e513d7896c1f0d21d5b71 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 27 Feb 2014 23:33:46 +0000 Subject: Fix Linux compile --- src/CraftingRecipes.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index 41de0da8c..5d9992fd3 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -806,6 +806,8 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti } case E_ITEM_DYE: { + int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY); + // Found a dye in ingredients... for (cRecipeSlots::const_iterator itrnumerodos = Recipe->m_Ingredients.begin(); itrnumerodos != Recipe->m_Ingredients.end(); ++itrnumerodos) { @@ -821,7 +823,7 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti // Yep, push back fade colour and exit the loop // There is a potential for flexibility here - we can move the goto out of the loop, so we can add multiple dyes (∴ multiple fade colours) // That will require lots of dye-adding to crafting.txt though - TODO, perchance? - int GridID = (itrnumerotres->x + a_OffsetX) + a_GridStride * (itrnumerotres->y + a_OffsetY); + GridID = (itrnumerotres->x + a_OffsetX) + a_GridStride * (itrnumerotres->y + a_OffsetY); Recipe->m_Result.m_FireworkItem.m_FadeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage)); goto next; } @@ -830,7 +832,6 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti } // Just normal crafting of star, push back normal colours - int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY); Recipe->m_Result.m_FireworkItem.m_Colours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage)); next: -- cgit v1.2.3 From c05a1db88d2a81b5aa93881c9791bcaadaad6304 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 1 Mar 2014 21:24:36 +0000 Subject: CheckBlockInteractionsRate() fixed & enabled --- src/ClientHandle.cpp | 48 +++++++++++++++++++----------------------------- src/ClientHandle.h | 4 +++- src/Entities/Player.cpp | 25 ------------------------- src/Entities/Player.h | 11 +---------- 4 files changed, 23 insertions(+), 65 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index b08ceb5f6..ef33a313d 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -52,6 +52,9 @@ /** Maximum number of explosions to send this tick, server will start dropping if exceeded */ #define MAX_EXPLOSIONS_PER_TICK 20 +/** Maximum number of block change interactions a player can perform per tick - exceeding this causes a kick */ +#define MAX_BLOCK_CHANGE_INTERACTIONS 20 + /** How many ticks before the socket is closed after the client is destroyed (#31) */ static const int TICKS_BEFORE_CLOSE = 20; @@ -687,6 +690,14 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status ); + m_NumBlockChangeInteractionsThisTick++; + + if (!CheckBlockInteractionsRate()) + { + Kick("Too many blocks were destroyed per unit time - hacked client?"); + return; + } + cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); if (PlgMgr->CallHookPlayerLeftClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status)) { @@ -694,12 +705,6 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); return; } - - if (!CheckBlockInteractionsRate()) - { - // Too many interactions per second, simply ignore. Probably a hacked client, so don't even send bak the block - return; - } switch (a_Status) { @@ -924,7 +929,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e if (PlgMgr->CallHookPlayerRightClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ)) { // A plugin doesn't agree with the action, replace the block on the client and quit: - if (a_BlockFace > -1) + if (a_BlockFace > BLOCK_FACE_NONE) { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); @@ -934,7 +939,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e if (!CheckBlockInteractionsRate()) { - LOGD("Too many block interactions, aborting placement"); + Kick("Too many blocks were destroyed per unit time - hacked client?"); return; } @@ -1613,28 +1618,12 @@ bool cClientHandle::CheckBlockInteractionsRate(void) { ASSERT(m_Player != NULL); ASSERT(m_Player->GetWorld() != NULL); - /* - // TODO: _X 2012_11_01: This needs a total re-thinking and rewriting - int LastActionCnt = m_Player->GetLastBlockActionCnt(); - if ((m_Player->GetWorld()->GetTime() - m_Player->GetLastBlockActionTime()) < 0.1) - { - // Limit the number of block interactions per tick - m_Player->SetLastBlockActionTime(); //Player tried to interact with a block. Reset last block interation time. - m_Player->SetLastBlockActionCnt(LastActionCnt + 1); - if (m_Player->GetLastBlockActionCnt() > MAXBLOCKCHANGEINTERACTIONS) - { - // Kick if more than MAXBLOCKCHANGEINTERACTIONS per tick - LOGWARN("Player %s tried to interact with a block too quickly! (could indicate bot) Was Kicked.", m_Username.c_str()); - Kick("You're a baaaaaad boy!"); - return false; - } - } - else + + if (m_NumBlockChangeInteractionsThisTick > MAX_BLOCK_CHANGE_INTERACTIONS) { - m_Player->SetLastBlockActionCnt(0); // Reset count - m_Player->SetLastBlockActionTime(); // Player tried to interact with a block. Reset last block interation time. + return false; } - */ + return true; } @@ -1707,8 +1696,9 @@ void cClientHandle::Tick(float a_Dt) } } - // Reset explosion counter: + // Reset explosion & block change counters: m_NumExplosionsThisTick = 0; + m_NumBlockChangeInteractionsThisTick = 0; } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 194533402..2382e81cf 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -46,7 +46,6 @@ class cClientHandle : // tolua_export public cSocketThreads::cCallback { // tolua_export public: - static const int MAXBLOCKCHANGEINTERACTIONS = 20; // 5 didn't help, 10 still doesn't work in Creative, 20 seems to have done the trick #if defined(ANDROID_NDK) static const int DEFAULT_VIEW_DISTANCE = 4; // The default ViewDistance (used when no value is set in Settings.ini) @@ -319,6 +318,9 @@ private: /** Number of explosions sent this tick */ int m_NumExplosionsThisTick; + + /** Number of place or break interactions this tick */ + int m_NumBlockChangeInteractionsThisTick; static int s_ClientCount; int m_UniqueID; diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index f4039e548..2a62931ab 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -38,10 +38,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_Inventory(*this) , m_CurrentWindow(NULL) , m_InventoryWindow(NULL) - , m_TimeLastPickupCheck(0.f) , m_Color('-') - , m_LastBlockActionTime(0) - , m_LastBlockActionCnt(0) , m_GameMode(eGameMode_NotSet) , m_IP("") , m_ClientHandle(a_Client) @@ -79,7 +76,6 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) m_LastPlayerListTime = t1.GetNowTime(); m_TimeLastTeleportPacket = 0; - m_TimeLastPickupCheck = 0; m_PlayerName = a_PlayerName; m_bDirtyPosition = true; // So chunks are streamed to player at spawn @@ -1055,27 +1051,6 @@ void cPlayer::CloseWindowIfID(char a_WindowID, bool a_CanRefuse) -void cPlayer::SetLastBlockActionTime() -{ - if (m_World != NULL) - { - m_LastBlockActionTime = m_World->GetWorldAge() / 20.0f; - } -} - - - - - -void cPlayer::SetLastBlockActionCnt( int a_LastBlockActionCnt ) -{ - m_LastBlockActionCnt = a_LastBlockActionCnt; -} - - - - - void cPlayer::SetGameMode(eGameMode a_GameMode) { if ((a_GameMode < gmMin) || (a_GameMode >= gmMax)) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index a795bb9eb..f9404dfaf 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -50,7 +50,7 @@ public: /// Returns the curently equipped weapon; empty item if none virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); } - /// Returns the currently equipped helmet; empty item if nonte + /// Returns the currently equipped helmet; empty item if none virtual cItem GetEquippedHelmet(void) const override { return m_Inventory.GetEquippedHelmet(); } /// Returns the currently equipped chestplate; empty item if none @@ -165,11 +165,6 @@ public: // tolua_end void SetIP(const AString & a_IP); - - float GetLastBlockActionTime() { return m_LastBlockActionTime; } - int GetLastBlockActionCnt() { return m_LastBlockActionCnt; } - void SetLastBlockActionCnt( int ); - void SetLastBlockActionTime(); // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); @@ -416,12 +411,8 @@ protected: cWindow * m_CurrentWindow; cWindow * m_InventoryWindow; - float m_TimeLastPickupCheck; - char m_Color; - float m_LastBlockActionTime; - int m_LastBlockActionCnt; eGameMode m_GameMode; AString m_IP; -- cgit v1.2.3 From 217aaca699cf1fa85740da4d1f0b71d4b8d806d7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 1 Mar 2014 21:25:01 +0000 Subject: Moved firework handler to separate function * Also simplified and improved readability of code --- src/CraftingRecipes.cpp | 93 ++++++++++++++++++++++++------------------------- src/CraftingRecipes.h | 3 ++ 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index 5d9992fd3..868182394 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -763,13 +763,24 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti } Recipe->m_Ingredients.insert(Recipe->m_Ingredients.end(), MatchedSlots.begin(), MatchedSlots.end()); - - // Henceforth is code to handle fireworks // We use Recipe instead of a_Recipe because we want the wildcard ingredients' slot numbers as well, which was just added previously + HandleFireworks(a_CraftingGrid, Recipe.get(), a_GridStride, a_OffsetX, a_OffsetY); + + return Recipe.release(); +} + + + + + +void cCraftingRecipes::HandleFireworks(const cItem * a_CraftingGrid, cCraftingRecipes::cRecipe * a_Recipe, int a_GridStride, int a_OffsetX, int a_OffsetY) +{ + // TODO: add support for more than one dye in the recipe + // A manual and temporary solution (listing everything) is in crafting.txt for fade colours, but a programmatic solutions needs to be done for everything else - if (Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_ROCKET) + if (a_Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_ROCKET) { - for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr) + for (cRecipeSlots::const_iterator itr = a_Recipe->m_Ingredients.begin(); itr != a_Recipe->m_Ingredients.end(); ++itr) { switch (itr->m_Item.m_ItemType) { @@ -777,80 +788,66 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti { // Result was a rocket, found a star - copy star data to rocket data int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY); - Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem); + a_Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem); break; } case E_ITEM_GUNPOWDER: { // Gunpowder - increase flight time - Recipe->m_Result.m_FireworkItem.m_FlightTimeInTicks += 20; + a_Recipe->m_Result.m_FireworkItem.m_FlightTimeInTicks += 20; break; } case E_ITEM_PAPER: break; - default: LOG("Unexpected item in firework rocket recipe, was the crafting file fireworks section changed?"); break; + default: LOG("Unexpected item in firework rocket a_Recipe, was the crafting file fireworks section changed?"); break; } } } - else if (Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_STAR) + else if (a_Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_STAR) { - for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr) + std::vector DyeColours; + bool FoundStar = false; + + for (cRecipeSlots::const_iterator itr = a_Recipe->m_Ingredients.begin(); itr != a_Recipe->m_Ingredients.end(); ++itr) { switch (itr->m_Item.m_ItemType) { case E_ITEM_FIREWORK_STAR: { // Result was star, found another star - probably adding fade colours, but copy data over anyhow + FoundStar = true; int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY); - Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem); + a_Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem); break; } case E_ITEM_DYE: { int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY); - - // Found a dye in ingredients... - for (cRecipeSlots::const_iterator itrnumerodos = Recipe->m_Ingredients.begin(); itrnumerodos != Recipe->m_Ingredients.end(); ++itrnumerodos) - { - // Loop through ingredients. Can we find a star? - if (itrnumerodos->m_Item.m_ItemType == E_ITEM_FIREWORK_STAR) - { - // Yes, this is definately adding fade colours, unless crafting.txt was changed :/ - for (cRecipeSlots::const_iterator itrnumerotres = Recipe->m_Ingredients.begin(); itrnumerotres != Recipe->m_Ingredients.end(); ++itrnumerotres) - { - // Loop again, can we find dye? - if (itrnumerotres->m_Item.m_ItemType == E_ITEM_DYE) - { - // Yep, push back fade colour and exit the loop - // There is a potential for flexibility here - we can move the goto out of the loop, so we can add multiple dyes (∴ multiple fade colours) - // That will require lots of dye-adding to crafting.txt though - TODO, perchance? - GridID = (itrnumerotres->x + a_OffsetX) + a_GridStride * (itrnumerotres->y + a_OffsetY); - Recipe->m_Result.m_FireworkItem.m_FadeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage)); - goto next; - } - } - } - } - - // Just normal crafting of star, push back normal colours - Recipe->m_Result.m_FireworkItem.m_Colours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage)); - - next: + DyeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage)); break; } case E_ITEM_GUNPOWDER: break; - case E_ITEM_DIAMOND: Recipe->m_Result.m_FireworkItem.m_HasTrail = true; break; - case E_ITEM_GLOWSTONE_DUST: Recipe->m_Result.m_FireworkItem.m_HasFlicker = true; break; - - case E_ITEM_FIRE_CHARGE: Recipe->m_Result.m_FireworkItem.m_Type = 1; break; - case E_ITEM_GOLD_NUGGET: Recipe->m_Result.m_FireworkItem.m_Type = 2; break; - case E_ITEM_FEATHER: Recipe->m_Result.m_FireworkItem.m_Type = 4; break; - case E_ITEM_HEAD: Recipe->m_Result.m_FireworkItem.m_Type = 3; break; - default: LOG("Unexpected item in firework star recipe, was the crafting file fireworks section changed?"); break; // ermahgerd BARD ardmins + case E_ITEM_DIAMOND: a_Recipe->m_Result.m_FireworkItem.m_HasTrail = true; break; + case E_ITEM_GLOWSTONE_DUST: a_Recipe->m_Result.m_FireworkItem.m_HasFlicker = true; break; + + case E_ITEM_FIRE_CHARGE: a_Recipe->m_Result.m_FireworkItem.m_Type = 1; break; + case E_ITEM_GOLD_NUGGET: a_Recipe->m_Result.m_FireworkItem.m_Type = 2; break; + case E_ITEM_FEATHER: a_Recipe->m_Result.m_FireworkItem.m_Type = 4; break; + case E_ITEM_HEAD: a_Recipe->m_Result.m_FireworkItem.m_Type = 3; break; + default: LOG("Unexpected item in firework star a_Recipe, was the crafting file fireworks section changed?"); break; // ermahgerd BARD ardmins } } - } - return Recipe.release(); + if (FoundStar && (!DyeColours.empty())) + { + // Found a star and a dye? Fade colours. + a_Recipe->m_Result.m_FireworkItem.m_FadeColours = DyeColours; + } + else if (!DyeColours.empty()) + { + // Only dye? Normal colours. + a_Recipe->m_Result.m_FireworkItem.m_Colours = DyeColours; + } + } } diff --git a/src/CraftingRecipes.h b/src/CraftingRecipes.h index 9d92cbfab..90e41eddc 100644 --- a/src/CraftingRecipes.h +++ b/src/CraftingRecipes.h @@ -165,6 +165,9 @@ protected: /// Checks if the grid matches the specified recipe, offset by the specified offsets. Returns a matched cRecipe * if so, or NULL if not matching. Caller must delete the return value! cRecipe * MatchRecipe(const cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight, int a_GridStride, const cRecipe * a_Recipe, int a_OffsetX, int a_OffsetY); + + /** Searches for anything firework related, and does the data setting if appropriate */ + void HandleFireworks(const cItem * a_CraftingGrid, cCraftingRecipes::cRecipe * a_Recipe, int a_GridStride, int a_OffsetX, int a_OffsetY); } ; -- cgit v1.2.3 From 8f134adb6dab3ad171f34a2e08a314e591380def Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 1 Mar 2014 21:25:27 +0000 Subject: Improved formatting of username tabcomplete --- src/World.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index ffb463169..8b791fa48 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2929,18 +2929,18 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = m_Players.begin(), end = m_Players.end(); itr != end; ++itr) { - size_t LastSpace = a_Text.find_last_of(" "); //Find the position of the last space + size_t LastSpace = a_Text.find_last_of(" "); // Find the position of the last space - std::string LastWord = a_Text.substr(LastSpace + 1, a_Text.length()); //Find the last word - std::string PlayerName ((*itr)->GetName()); - std::size_t Found = PlayerName.find(LastWord); //Try to find last word in playername + AString LastWord = a_Text.substr(LastSpace + 1, a_Text.length()); // Find the last word + AString PlayerName ((*itr)->GetName()); + size_t Found = PlayerName.find(LastWord); // Try to find last word in playername - if (Found!=0) + if (Found == AString::npos) { - continue; //No match + continue; // No match } - a_Results.push_back((*itr)->GetName()); //Match! + a_Results.push_back(PlayerName); // Match! } } -- cgit v1.2.3 From d5180ef2308f0de6c9a7a828e5914e8424b9b16f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 1 Mar 2014 21:25:46 +0000 Subject: Added extra dye rules to crafting.txt --- MCServer/crafting.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/MCServer/crafting.txt b/MCServer/crafting.txt index bce0c5e9e..60cda0673 100644 --- a/MCServer/crafting.txt +++ b/MCServer/crafting.txt @@ -478,5 +478,12 @@ FireworkStar = Gunpowder, * | Dye ^-1, * | Goldnugget, * | Glowdust, * | Dia FireworkStar = Gunpowder, * | Dye ^-1, * | Feather, * | Glowdust, * | Diamond, * FireworkStar = Gunpowder, * | Dye ^-1, * | SkeletonHead ^-1, * | Glowdust, * | Diamond, * -# Star colour-change +# Star fade colour-change FireworkStar = FireworkStar, * | Dye ^-1, * +FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * +FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * +FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * +FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * +FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * +FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * +FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * -- cgit v1.2.3 From 124fc8bc664f96158b4db28372da62896d1db211 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 1 Mar 2014 21:26:43 +0000 Subject: Demonstrated issues with GetDataLength() --- src/WorldStorage/FireworksSerializer.cpp | 12 +++++++----- src/WorldStorage/FireworksSerializer.h | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index 7f5077912..34204ae8a 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -89,26 +89,28 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB if (ExplosionName == "Colors") { - if (a_NBT.GetDataLength(explosiontag) == 0) + int DataLength = a_NBT.GetDataLength(explosiontag); + if (DataLength == 0) { continue; } const int * ColourData = (const int *)(a_NBT.GetData(explosiontag)); - for (int i = 0; i < ARRAYCOUNT(ColourData); i++) + for (int i = 0; i < DataLength; i++) { a_FireworkItem.m_Colours.push_back(ntohl(ColourData[i])); } } else if (ExplosionName == "FadeColors") { - if (a_NBT.GetDataLength(explosiontag) == 0) + int DataLength = a_NBT.GetDataLength(explosiontag); + if (DataLength == 0) { continue; } const int * FadeColourData = (const int *)(a_NBT.GetData(explosiontag)); - for (int i = 0; i < ARRAYCOUNT(FadeColourData); i++) + for (int i = 0; i < DataLength; i++) { a_FireworkItem.m_FadeColours.push_back(ntohl(FadeColourData[i])); } @@ -244,6 +246,6 @@ int cFireworkItem::GetVanillaColourCodeFromDye(short a_DyeMeta) case E_META_DYE_MAGENTA: return 12801229; case E_META_DYE_ORANGE: return 15435844; case E_META_DYE_WHITE: return 15790320; - default: ASSERT(!"Unhandled dye meta whilst trying to get colour code for fireworks!"); break; + default: ASSERT(!"Unhandled dye meta whilst trying to get colour code for fireworks!"); return 0; } } diff --git a/src/WorldStorage/FireworksSerializer.h b/src/WorldStorage/FireworksSerializer.h index 37fb6c883..5b87bafdb 100644 --- a/src/WorldStorage/FireworksSerializer.h +++ b/src/WorldStorage/FireworksSerializer.h @@ -64,15 +64,19 @@ public: /** Writes firework NBT data to a Writer object */ static void WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFastNBTWriter & a_Writer, const ENUM_ITEM_ID a_Type); + /** Reads NBT data from a NBT object and populates a FireworkItem with it */ static void ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNBT & a_NBT, int a_TagIdx, const ENUM_ITEM_ID a_Type); /** Converts the firework's vector of colours into a string of values separated by a semicolon */ static AString ColoursToString(const cFireworkItem & a_FireworkItem); + /** Parses a string containing encoded firework colours and populates a FireworkItem with it */ static void ColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem); + /** Converts the firework's vector of fade colours into a string of values separated by a semicolon */ static AString FadeColoursToString(const cFireworkItem & a_FireworkItem); + /** Parses a string containing encoded firework fade colours and populates a FireworkItem with it */ static void FadeColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem); -- cgit v1.2.3 From a2fb28dd082b85d714970f119a82cdba3583037a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Mar 2014 16:28:51 +0000 Subject: Fixed data length issues --- src/ClientHandle.cpp | 2 +- src/WorldStorage/FireworksSerializer.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index ef33a313d..9f08b43a5 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -939,7 +939,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e if (!CheckBlockInteractionsRate()) { - Kick("Too many blocks were destroyed per unit time - hacked client?"); + Kick("Too many blocks were placed/interacted with per unit time - hacked client?"); return; } diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index 34204ae8a..464bf225d 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -89,7 +89,8 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB if (ExplosionName == "Colors") { - int DataLength = a_NBT.GetDataLength(explosiontag); + // Divide by four as data length returned in bytes + int DataLength = a_NBT.GetDataLength(explosiontag) / 4; if (DataLength == 0) { continue; @@ -103,7 +104,7 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB } else if (ExplosionName == "FadeColors") { - int DataLength = a_NBT.GetDataLength(explosiontag); + int DataLength = a_NBT.GetDataLength(explosiontag) / 4; if (DataLength == 0) { continue; -- cgit v1.2.3 From 76bf7ad8132f2d36cf974d7a376ca7b911343eac Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Mar 2014 17:41:34 +0000 Subject: Hexified colours --- src/WorldStorage/FireworksSerializer.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index 464bf225d..0e0094e76 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -231,22 +231,22 @@ int cFireworkItem::GetVanillaColourCodeFromDye(short a_DyeMeta) switch (a_DyeMeta) { - case E_META_DYE_BLACK: return 1973019; - case E_META_DYE_RED: return 11743532; - case E_META_DYE_GREEN: return 3887386; - case E_META_DYE_BROWN: return 5320730; - case E_META_DYE_BLUE: return 2437522; - case E_META_DYE_PURPLE: return 8073150; - case E_META_DYE_CYAN: return 2651799; - case E_META_DYE_LIGHTGRAY: return 11250603; - case E_META_DYE_GRAY: return 4408131; - case E_META_DYE_PINK: return 14188952; - case E_META_DYE_LIGHTGREEN: return 4312372; - case E_META_DYE_YELLOW: return 14602026; - case E_META_DYE_LIGHTBLUE: return 6719955; - case E_META_DYE_MAGENTA: return 12801229; - case E_META_DYE_ORANGE: return 15435844; - case E_META_DYE_WHITE: return 15790320; + case E_META_DYE_BLACK: return 0x1E1B1B; + case E_META_DYE_RED: return 0xB3312C; + case E_META_DYE_GREEN: return 0x3B511A; + case E_META_DYE_BROWN: return 0x51301A; + case E_META_DYE_BLUE: return 0x253192; + case E_META_DYE_PURPLE: return 0x7B2FBE; + case E_META_DYE_CYAN: return 0x287697; + case E_META_DYE_LIGHTGRAY: return 0xABABAB; + case E_META_DYE_GRAY: return 0x434343; + case E_META_DYE_PINK: return 0xD88198; + case E_META_DYE_LIGHTGREEN: return 0x41CD34; + case E_META_DYE_YELLOW: return 0xDECF2A; + case E_META_DYE_LIGHTBLUE: return 0x6689D3; + case E_META_DYE_MAGENTA: return 0xC354CD; + case E_META_DYE_ORANGE: return 0xEB8844; + case E_META_DYE_WHITE: return 0xF0F0F0; default: ASSERT(!"Unhandled dye meta whilst trying to get colour code for fireworks!"); return 0; } } -- cgit v1.2.3 From e6305d29a53c9a0c5e607629d30fec70e01cccab Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 7 Mar 2014 18:37:18 +0100 Subject: Added the first skeleton code for PieceGenerator. This is a WIP and won't work / isn't used at all. --- src/Generating/PieceGenerator.cpp | 332 ++++++++++++++++++++++++++++++++++++++ src/Generating/PieceGenerator.h | 213 ++++++++++++++++++++++++ 2 files changed, 545 insertions(+) create mode 100644 src/Generating/PieceGenerator.cpp create mode 100644 src/Generating/PieceGenerator.h diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp new file mode 100644 index 000000000..04513666d --- /dev/null +++ b/src/Generating/PieceGenerator.cpp @@ -0,0 +1,332 @@ + +// PieceGenerator.cpp + +// Implements the cBFSPieceGenerator class and cDFSPieceGenerator class +// representing base classes for generating structures composed of individual "pieces" + +#include "Globals.h" +#include "PieceGenerator.h" + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPiece: + +cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const +{ + cPiece::cConnector res(a_Connector); + + // Rotate the res connector: + Vector3i Size = GetSize(); + switch (a_NumCCWRotations) + { + case 0: + { + // No rotation needed + break; + } + case 1: + { + // 1 CCW rotation: + int NewX = Size.z - res.m_X; + int NewZ = res.m_Z; + res.m_X = NewX; + res.m_Z = NewZ; + res.m_Direction = RotateBlockFaceCCW(res.m_Direction); + break; + } + case 2: + { + // 2 rotations ( = axis flip): + res.m_X = Size.x - res.m_X; + res.m_Z = Size.z - res.m_Z; + res.m_Direction = MirrorBlockFaceY(res.m_Direction); + break; + } + case 3: + { + // 1 CW rotation: + int NewX = res.m_Z; + int NewZ = Size.x - res.m_X; + res.m_X = NewX; + res.m_Z = NewZ; + res.m_Direction = RotateBlockFaceCW(res.m_Direction); + break; + } + } + + // Move the res connector: + res.m_X += a_MoveX; + res.m_Y += a_MoveY; + res.m_Z += a_MoveZ; + + return res; +} + + + + + +cCuboid cPiece::RotateHitBoxToConnector( + const cPiece::cConnector & a_MyConnector, + const cPiece::cConnector & a_ToConnector, + int a_NumCCWRotations +) const +{ + cCuboid res = GetHitBox(); + switch (a_NumCCWRotations) + { + case 0: + { + // No rotation, return the hitbox as-is + break; + } + case 1: + { + // 1 CCW rotation: + // TODO: res.p1.x = + break; + } + } + return res; +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPlacedPiece: + +cPlacedPiece::cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece, const Vector3i & a_Coords, int a_NumCCWRotations) : + m_Parent(a_Parent), + m_Piece(&a_Piece), + m_Coords(a_Coords), + m_NumCCWRotations(a_NumCCWRotations) +{ + m_Depth = (m_Parent == NULL) ? 0 : (m_Parent->GetDepth() + 1); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPieceGenerator: + +cPieceGenerator::cPieceGenerator(cPiecePool & a_PiecePool, int a_Seed) : + m_PiecePool(a_PiecePool), + m_Noise(a_Seed), + m_Seed(a_Seed) +{ +} + + + + + +cPlacedPiece cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors) +{ + m_PiecePool.Reset(); + int rnd = m_Noise.IntNoise3DInt(a_BlockX, a_BlockY, a_BlockZ) / 7; + + // Choose a random one of the starting pieces: + cPieces StartingPieces = m_PiecePool.GetStartingPieces(); + cPiece * StartingPiece = StartingPieces[rnd % StartingPieces.size()]; + rnd = rnd >> 16; + + // Choose a random supported rotation: + int Rotations[4] = {0}; + int NumRotations = 1; + for (int i = 1; i < ARRAYCOUNT(Rotations); i++) + { + if (StartingPiece->CanRotateCCW(i)) + { + Rotations[NumRotations] = i; + NumRotations += 1; + } + } + int Rotation = Rotations[rnd % NumRotations]; + + cPlacedPiece res(NULL, *StartingPiece, Vector3i(a_BlockX, a_BlockY, a_BlockZ), Rotation); + + // Place the piece's connectors into a_OutConnectors: + const cPiece::cConnectors & Conn = StartingPiece->GetConnectors(); + for (cPiece::cConnectors::const_iterator itr = Conn.begin(), end = Conn.end(); itr != end; ++itr) + { + a_OutConnectors.push_back( + cFreeConnector(res, StartingPiece->RotateMoveConnector(*itr, Rotation, a_BlockX, a_BlockY, a_BlockZ)) + ); + } + + return res; +} + + + + + +bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiece, const cPiece::cConnector & a_Connector, cPlacedPieces & a_OutPieces) +{ + // Translation of direction - direction -> number of CCW rotations needed: + // You need DirectionRotationTable[rot1][rot2] CCW turns to get from rot1 to rot2 + static const int DirectionRotationTable[6][6] = + { + /* YM, YP, ZM, ZP, XM, XP + /* YM */ { 0, 0, 0, 0, 0, 0}, + /* YP */ { 0, 0, 0, 0, 0, 0}, + /* ZM */ { 0, 0, 0, 2, 1, 3}, + /* ZP */ { 0, 0, 2, 0, 3, 1}, + /* XM */ { 0, 0, 3, 1, 0, 2}, + /* XP */ { 0, 0, 1, 3, 2, 0}, + }; + + // Get a list of available connections: + const int * RotTable = DirectionRotationTable[a_Connector.m_Direction]; + cConnections Connections; + cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(a_Connector.m_Type); + Connections.reserve(AvailablePieces.size()); + for (cPieces::iterator itrP = AvailablePieces.begin(), endP = AvailablePieces.end(); itrP != endP; ++itrP) + { + cPiece::cConnectors Connectors = (*itrP)->GetConnectors(); + for (cPiece::cConnectors::iterator itrC = Connectors.begin(), endC = Connectors.end(); itrC != endC; ++itrC) + { + if (itrC->m_Type != a_Connector.m_Type) + { + continue; + } + // This is a same-type connector, find out how to rotate to it: + int NumCCWRotations = RotTable[itrC->m_Direction]; + if (!(*itrP)->CanRotateCCW(NumCCWRotations)) + { + // Doesn't support this rotation + continue; + } + if (!CheckConnection(a_Connector, **itrP, *itrC, NumCCWRotations, a_OutPieces)) + { + // Doesn't fit in this rotation + continue; + } + Connections.push_back(cConnection(**itrP, *itrC, NumCCWRotations)); + } // for itrC - Connectors[] + } // for itrP - AvailablePieces[] + if (Connections.empty()) + { + // No available connections, bail out + return false; + } + + // Choose a random connection from the list: + int rnd = m_Noise.IntNoise3DInt(a_Connector.m_X, a_Connector.m_Y, a_Connector.m_Z) / 7; + cConnection & Conn = Connections[rnd % Connections.size()]; + + // Place the piece: + cPiece::cConnector NewConnector = Conn.m_Piece->RotateMoveConnector(*(Conn.m_Connector), Conn.m_NumCCWRotations, 0, 0, 0); + Vector3i Coords = a_ParentPiece.GetCoords(); + Coords.x -= NewConnector.m_X; + Coords.y -= NewConnector.m_Y; + Coords.z -= NewConnector.m_Z; + a_OutPieces.push_back(cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), Coords, Conn.m_NumCCWRotations)); + return false; +} + + + + + +bool cPieceGenerator::CheckConnection( + const cPiece::cConnector & a_ExistingConnector, + const cPiece & a_Piece, + const cPiece::cConnector & a_NewConnector, + int a_NumCCWRotations, + const cPlacedPieces & a_OutPieces +) +{ + // For each placed piece, test the hitbox against the new piece: + cCuboid RotatedHitBox = a_Piece.RotateHitBoxToConnector(a_NewConnector, a_ExistingConnector, a_NumCCWRotations); + for (cPlacedPieces::const_iterator itr = a_OutPieces.begin(), end = a_OutPieces.end(); itr != end; ++itr) + { + if (itr->GetHitBox().DoesIntersect(RotatedHitBox)) + { + return false; + } + } + return true; +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPieceGenerator::cConnection: + +cPieceGenerator::cConnection::cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations) : + m_Piece(&a_Piece), + m_Connector(&a_Connector), + m_NumCCWRotations(a_NumCCWRotations) +{ +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPieceGenerator::cFreeConnector: + +cPieceGenerator::cFreeConnector::cFreeConnector(cPlacedPiece & a_Piece, const cPiece::cConnector & a_Connector) : + m_Piece(&a_Piece), + m_Connector(a_Connector) +{ +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cBFSPieceGenerator: + +cBFSPieceGenerator::cBFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed) : + super(a_PiecePool, a_Seed) +{ +} + + + + + +void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces) +{ + a_OutPieces.clear(); + cFreeConnectors ConnectorPool; + + // Place the starting piece: + a_OutPieces.push_back(PlaceStartingPiece(a_BlockX, a_BlockY, a_BlockZ, ConnectorPool)); + + // Place pieces at the available connectors: + /* + Instead of removing them one by one from the pool, we process them sequentially and take note of the last + processed one. To save on memory, once the number of processed connectors reaches a big number, a chunk + of the connectors is removed. + */ + size_t NumProcessed = 0; + while (ConnectorPool.size() > NumProcessed) + { + cFreeConnector & Conn = ConnectorPool[NumProcessed]; + TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces); + NumProcessed++; + if (NumProcessed > 1000) + { + ConnectorPool.erase(ConnectorPool.begin(), ConnectorPool.begin() + NumProcessed); + NumProcessed = 0; + } + } +} + + + + diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h new file mode 100644 index 000000000..3bc71a0ab --- /dev/null +++ b/src/Generating/PieceGenerator.h @@ -0,0 +1,213 @@ + +// PieceGenerator.h + +// Declares the cBFSPieceGenerator class and cDFSPieceGenerator class +// representing base classes for generating structures composed of individual "pieces" + +/* +Each uses a slightly different approach to generating: + - DFS extends pieces one by one until it hits the configured depth (or can't connect another piece anymore), + then starts looking at adjacent connectors (like depth-first search). + - BFS keeps a pool of currently-open connectors, chooses one at random and tries to place a piece on it, + thus possibly extending the pool of open connectors (like breadth-first search). +*/ + + + + + +#pragma once + +#include "../Defines.h" +#include "../Cuboid.h" +#include "../Noise.h" + + + + + +/** Represents a single piece. Can have multiple connectors of different types where other pieces can connect. */ +class cPiece +{ +public: + struct cConnector + { + int m_X; + int m_Y; + int m_Z; + int m_Type; + eBlockFace m_Direction; + + cConnector(int a_X, int a_Y, int a_Z, int a_Type, eBlockFace m_Direction); + }; + + typedef std::vector cConnectors; + + /** Returns all of the available connectors that the piece has. + Each connector has a (relative) position in the piece, and a type associated with it. */ + virtual cConnectors GetConnectors(void) const = 0; + + /** Returns the dimensions of this piece. + The dimensions cover the entire piece, there is no block that the piece generates outside of this size. */ + virtual Vector3i GetSize(void) const = 0; + + /** Returns the "hitbox" of this piece. + A hitbox is what is compared and must not intersect other pieces' hitboxes when generating. */ + virtual cCuboid GetHitBox(void) const = 0; + + /** Returns true if the piece can be rotated CCW the specific number of 90-degree turns. */ + virtual bool CanRotateCCW(int a_NumRotations) const = 0; + + /** Returns a copy of the connector that is rotated and then moved by the specified amounts. */ + cConnector RotateMoveConnector(const cConnector & a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const; + + /** Returns the hitbox after the specified number of rotations and moved so that a_MyConnector is placed at a_ToConnector*/ + cCuboid RotateHitBoxToConnector(const cConnector & a_MyConnector, const cConnector & a_ToConnector, int a_NumCCWRotations) const; +}; + +typedef std::vector cPieces; + + + + + +class cPiecePool +{ +public: + /** Returns a list of pieces that contain the specified connector type. + The cPiece pointers returned are managed by the pool and the caller doesn't free them. */ + virtual cPieces GetPiecesWithConnector(int a_ConnectorType) = 0; + + /** Returns the pieces that should be used as the starting point. + Multiple starting points are supported, one of the returned piece will be chosen. */ + virtual cPieces GetStartingPieces(void) = 0; + + /** Called after a piece is placed, to notify the pool that it has been used. + The pool may adjust the pieces it will return the next time. */ + virtual void PiecePlaced(const cPiece & a_Piece) = 0; + + /** Called when the pool has finished the current structure and should reset any piece-counters it has + for a new structure. */ + virtual void Reset(void) = 0; +}; + + + + + +/** Represents a single piece that has been placed to specific coords in the world. */ +class cPlacedPiece +{ +public: + cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece, const Vector3i & a_Coords, int a_NumCCWRotations); + + const cPiece & GetPiece (void) const { return *m_Piece; } + const Vector3i & GetCoords (void) const { return m_Coords; } + const int GetNumCCWRotations(void) const { return m_NumCCWRotations; } + const cCuboid & GetHitBox (void) const { return m_HitBox; } + const int GetDepth (void) const { return m_Depth; } + +protected: + const cPlacedPiece * m_Parent; + const cPiece * m_Piece; + Vector3i m_Coords; + int m_NumCCWRotations; + cCuboid m_HitBox; + int m_Depth; +}; + +typedef std::vector cPlacedPieces; + + + + + +class cPieceGenerator +{ +public: + cPieceGenerator(cPiecePool & a_PiecePool, int a_Seed); + +protected: + /** The type used for storing a connection from one piece to another, while building the piece tree. */ + struct cConnection + { + cPiece * m_Piece; // The piece being connected + cPiece::cConnector * m_Connector; // The piece's connector being used + int m_NumCCWRotations; // Number of rotations necessary to match the two connectors + + cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations); + }; + typedef std::vector cConnections; + + /** The type used for storing a pool of connectors that will be attempted to expand by another piece. */ + struct cFreeConnector + { + cPlacedPiece * m_Piece; + cPiece::cConnector m_Connector; + + cFreeConnector(cPlacedPiece & a_Piece, const cPiece::cConnector & a_Connector); + }; + typedef std::vector cFreeConnectors; + + + cPiecePool & m_PiecePool; + cNoise m_Noise; + int m_Seed; + + + /** Selects a starting piece and places it, including the rotations. + Also puts the piece's connectors in a_OutConnectors. */ + cPlacedPiece PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors); + + /** Tries to place a new piece at the specified (placed) connector. Returns true if successful. */ + bool TryPlacePieceAtConnector( + const cPlacedPiece & a_ParentPiece, + const cPiece::cConnector & a_Connector, + cPlacedPieces & a_OutPieces + ); + + /** Checks if the specified piece would fit with the already-placed pieces, using the specified connector + and number of CCW rotations. + Returns true if the piece fits, false if not. */ + bool CheckConnection( + const cPiece::cConnector & a_ExistingConnector, // The existing connector + const cPiece & a_Piece, // The new piece + const cPiece::cConnector & a_NewConnector, // The connector of the new piece + int a_NumCCWRotations, // Number of rotations for the new piece to align the connector + const cPlacedPieces & a_OutPieces // All the already-placed pieces to check + ); +} ; + + + + + +class cBFSPieceGenerator : + public cPieceGenerator +{ + typedef cPieceGenerator super; + +public: + cBFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed); + + /** Generates a placement for pieces at the specified coords. */ + void PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces); +}; + + + + + +class cDFSPieceGenerator : + public cPieceGenerator +{ +public: + cDFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed); + + /** Generates a placement for pieces at the specified coords. */ + void PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces); +}; + + + + -- cgit v1.2.3 From 93f0de521a0e2abb9c35dfb06bd3d306c548bf1b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 7 Mar 2014 21:43:15 +0100 Subject: Added Vector3i::Move(). --- src/Vector3i.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- src/Vector3i.h | 47 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 82 insertions(+), 17 deletions(-) diff --git a/src/Vector3i.cpp b/src/Vector3i.cpp index 4ce1e2cf3..2106aea6d 100644 --- a/src/Vector3i.cpp +++ b/src/Vector3i.cpp @@ -1,6 +1,11 @@ +// Vector3i.cpp + +// Implements the Vector3i class representing an int-based 3D vector + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules +#include "math.h" #include "Vector3i.h" #include "Vector3d.h" @@ -8,9 +13,46 @@ -Vector3i::Vector3i( const Vector3d & v ) - : x( (int)v.x ) - , y( (int)v.y ) - , z( (int)v.z ) +Vector3i::Vector3i(const Vector3d & v) : + x((int)v.x), + y((int)v.y), + z((int)v.z) +{ +} + + + + + +Vector3i::Vector3i(void) : + x(0), + y(0), + z(0) +{ +} + + + + + +Vector3i::Vector3i(int a_x, int a_y, int a_z) : + x(a_x), + y(a_y), + z(a_z) +{ +} + + + + + +void Vector3i::Move(int a_MoveX, int a_MoveY, int a_MoveZ) { -} \ No newline at end of file + x += a_MoveX; + y += a_MoveY; + z += a_MoveZ; +} + + + + diff --git a/src/Vector3i.h b/src/Vector3i.h index 7d726a7b3..39e138683 100644 --- a/src/Vector3i.h +++ b/src/Vector3i.h @@ -1,22 +1,45 @@ + +// Vector3i.h + +// Declares the Vector3i class representing an int-based 3D vector + + + + + #pragma once -#include + + + +// fwd: class Vector3d; -class Vector3i // tolua_export -{ // tolua_export -public: // tolua_export - Vector3i( const Vector3d & v ); // tolua_export - Vector3i() : x(0), y(0), z(0) {} // tolua_export - Vector3i(int a_x, int a_y, int a_z) : x(a_x), y(a_y), z(a_z) {} // tolua_export - inline void Set(int a_x, int a_y, int a_z) { x = a_x, y = a_y, z = a_z; } // tolua_export - inline float Length() const { return sqrtf( (float)( x * x + y * y + z * z) ); } // tolua_export - inline int SqrLength() const { return x * x + y * y + z * z; } // tolua_export - inline bool Equals( const Vector3i & v ) const { return (x == v.x && y == v.y && z == v.z ); } // tolua_export - inline bool Equals( const Vector3i * v ) const { return (x == v->x && y == v->y && z == v->z ); } // tolua_export + + +// tolua_begin +class Vector3i +{ +public: + /** Creates an int vector based on the floor()-ed coords of a double vector. */ + Vector3i(const Vector3d & v); + + Vector3i(void); + Vector3i(int a_x, int a_y, int a_z); + + inline void Set(int a_x, int a_y, int a_z) { x = a_x, y = a_y, z = a_z; } + inline float Length() const { return sqrtf( (float)( x * x + y * y + z * z) ); } + inline int SqrLength() const { return x * x + y * y + z * z; } + + inline bool Equals( const Vector3i & v ) const { return (x == v.x && y == v.y && z == v.z ); } + inline bool Equals( const Vector3i * v ) const { return (x == v->x && y == v->y && z == v->z ); } + + void Move(int a_MoveX, int a_MoveY, int a_MoveZ); + + // tolua_end void operator += ( const Vector3i& a_V ) { x += a_V.x; y += a_V.y; z += a_V.z; } void operator += ( Vector3i* a_V ) { x += a_V->x; y += a_V->y; z += a_V->z; } -- cgit v1.2.3 From 5be983e7752091adbf7262f3074b3062ea44ae73 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 10:05:30 +0100 Subject: Added BlockFaceToString() translation function. --- src/Defines.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Defines.h b/src/Defines.h index 6ab2274a4..d2fcce576 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -276,6 +276,26 @@ inline eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace) +/** Returns the textual representation of the BlockFace constant. */ +inline AString BlockFaceToString(eBlockFace a_BlockFace) +{ + switch (a_BlockFace) + { + case BLOCK_FACE_XM: return "BLOCK_FACE_XM"; + case BLOCK_FACE_XP: return "BLOCK_FACE_XP"; + case BLOCK_FACE_YM: return "BLOCK_FACE_YM"; + case BLOCK_FACE_YP: return "BLOCK_FACE_YP"; + case BLOCK_FACE_ZM: return "BLOCK_FACE_ZM"; + case BLOCK_FACE_ZP: return "BLOCK_FACE_ZP"; + case BLOCK_FACE_NONE: return "BLOCK_FACE_NONE"; + } + return Printf("Unknown BLOCK_FACE: %d", a_BlockFace); +} + + + + + inline bool IsValidBlock(int a_BlockType) { if ( -- cgit v1.2.3 From b9190fc04e1463371cec773d069315a6743a56d5 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 10:11:33 +0100 Subject: PieceGenerator can connect two connectors of the same type. Also added extensive debugging output and a test. --- src/Generating/PieceGenerator.cpp | 347 ++++++++++++++++++++++++++++++++------ src/Generating/PieceGenerator.h | 51 ++++-- 2 files changed, 338 insertions(+), 60 deletions(-) diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index 04513666d..58ccaf2c2 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -11,9 +11,169 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Self-test: + +static class cPieceGeneratorSelfTest : + public cPiecePool +{ +public: + cPieceGeneratorSelfTest(void) + { + // Prepare the internal state: + InitializePieces(); + + // Generate: + cBFSPieceGenerator Gen(*this, 0); + cPlacedPieces OutPieces; + Gen.PlacePieces(500, 50, 500, 3, OutPieces); + + // Print out the pieces: + printf("OutPieces.size() = %u\n", OutPieces.size()); + size_t idx = 0; + for (cPlacedPieces::const_iterator itr = OutPieces.begin(), end = OutPieces.end(); itr != end; ++itr, ++idx) + { + const Vector3i & Coords = (*itr)->GetCoords(); + cCuboid Hitbox = (*itr)->GetHitBox(); + Hitbox.Sort(); + printf("%u: {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx, + Coords.x, Coords.y, Coords.z, + (*itr)->GetNumCCWRotations(), + Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z, + Hitbox.p2.x, Hitbox.p2.y, Hitbox.p2.z, + Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1 + ); + } // itr - OutPieces[] + printf("Done.\n"); + + // Free the placed pieces properly: + Gen.FreePieces(OutPieces); + } + + ~cPieceGeneratorSelfTest() + { + // Dealloc all the pieces: + for (cPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) + { + delete *itr; + } + m_Pieces.clear(); + } + +protected: + class cTestPiece : + public cPiece + { + int m_Size; + public: + cTestPiece(int a_Size) : + m_Size(a_Size) + { + } + + virtual cConnectors GetConnectors(void) const override + { + // Each piece has 4 connectors, one of each type, plus one extra, at the center of its walls: + cConnectors res; + res.push_back(cConnector(m_Size / 2, 1, 0, 0, BLOCK_FACE_ZM)); + res.push_back(cConnector(m_Size / 2, 1, m_Size - 1, 1, BLOCK_FACE_ZP)); + res.push_back(cConnector(0, 1, m_Size / 2, 2, BLOCK_FACE_XM)); + res.push_back(cConnector(m_Size - 1, 1, m_Size / 2, m_Size % 3, BLOCK_FACE_XP)); + return res; + } + + virtual Vector3i GetSize(void) const override + { + return Vector3i(m_Size, 5, m_Size); + } + + virtual cCuboid GetHitBox(void) const override + { + return cCuboid(0, 0, 0, m_Size - 1, 4, m_Size - 1); + } + + virtual bool CanRotateCCW(int a_NumCCWRotations) const override + { + return true; + } + }; + + cPieces m_Pieces; + + virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override + { + // Each piece contains each connector + return m_Pieces; + } + + + virtual cPieces GetStartingPieces(void) override + { + return m_Pieces; + } + + + virtual void PiecePlaced(const cPiece & a_Piece) override + { + UNUSED(a_Piece); + } + + + virtual void Reset(void) override + { + } + + + void InitializePieces(void) + { + m_Pieces.push_back(new cTestPiece(5)); + m_Pieces.push_back(new cTestPiece(7)); + m_Pieces.push_back(new cTestPiece(9)); + } +} g_Test; + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cPiece: + +Vector3i cPiece::RotatePos(const Vector3i & a_Pos, int a_NumCCWRotations) const +{ + Vector3i Size = GetSize(); + switch (a_NumCCWRotations) + { + case 0: + { + // No rotation needed + return a_Pos; + } + case 1: + { + // 1 CCW rotation: + return Vector3i(a_Pos.z, a_Pos.y, Size.x - a_Pos.x - 1); + } + case 2: + { + // 2 rotations ( = axis flip): + return Vector3i(Size.x - a_Pos.x - 1, a_Pos.y, Size.z - a_Pos.z - 1); + } + case 3: + { + // 1 CW rotation: + return Vector3i(Size.z - a_Pos.z - 1, a_Pos.y, a_Pos.x); + } + } + ASSERT(!"Unhandled rotation"); + return a_Pos; +} + + + + + cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const { cPiece::cConnector res(a_Connector); @@ -30,37 +190,28 @@ cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, i case 1: { // 1 CCW rotation: - int NewX = Size.z - res.m_X; - int NewZ = res.m_Z; - res.m_X = NewX; - res.m_Z = NewZ; res.m_Direction = RotateBlockFaceCCW(res.m_Direction); break; } case 2: { // 2 rotations ( = axis flip): - res.m_X = Size.x - res.m_X; - res.m_Z = Size.z - res.m_Z; res.m_Direction = MirrorBlockFaceY(res.m_Direction); break; } case 3: { // 1 CW rotation: - int NewX = res.m_Z; - int NewZ = Size.x - res.m_X; - res.m_X = NewX; - res.m_Z = NewZ; res.m_Direction = RotateBlockFaceCW(res.m_Direction); break; } } + res.m_Pos = RotatePos(a_Connector.m_Pos, a_NumCCWRotations); // Move the res connector: - res.m_X += a_MoveX; - res.m_Y += a_MoveY; - res.m_Z += a_MoveZ; + res.m_Pos.x += a_MoveX; + res.m_Pos.y += a_MoveY; + res.m_Pos.z += a_MoveZ; return res; } @@ -71,25 +222,28 @@ cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, i cCuboid cPiece::RotateHitBoxToConnector( const cPiece::cConnector & a_MyConnector, - const cPiece::cConnector & a_ToConnector, + const Vector3i & a_ToConnectorPos, int a_NumCCWRotations ) const { + ASSERT(a_NumCCWRotations == (a_NumCCWRotations % 4)); + Vector3i ConnPos = RotatePos(a_MyConnector.m_Pos, a_NumCCWRotations); + ConnPos = a_ToConnectorPos - ConnPos; + return RotateMoveHitBox(a_NumCCWRotations, ConnPos.x, ConnPos.y, ConnPos.z); +} + + + + + +cCuboid cPiece::RotateMoveHitBox(int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const +{ + ASSERT(a_NumCCWRotations == (a_NumCCWRotations % 4)); cCuboid res = GetHitBox(); - switch (a_NumCCWRotations) - { - case 0: - { - // No rotation, return the hitbox as-is - break; - } - case 1: - { - // 1 CCW rotation: - // TODO: res.p1.x = - break; - } - } + res.p1 = RotatePos(res.p1, a_NumCCWRotations); + res.p2 = RotatePos(res.p2, a_NumCCWRotations); + res.p1.Move(a_MoveX, a_MoveY, a_MoveZ); + res.p2.Move(a_MoveX, a_MoveY, a_MoveZ); return res; } @@ -97,6 +251,31 @@ cCuboid cPiece::RotateHitBoxToConnector( +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPiece::cConnector: + +cPiece::cConnector::cConnector(int a_X, int a_Y, int a_Z, int a_Type, eBlockFace a_Direction) : + m_Pos(a_X, a_Y, a_Z), + m_Type(a_Type), + m_Direction(a_Direction) +{ +} + + + + + +cPiece::cConnector::cConnector(const Vector3i & a_Pos, int a_Type, eBlockFace a_Direction) : + m_Pos(a_Pos), + m_Type(a_Type), + m_Direction(a_Direction) +{ +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cPlacedPiece: @@ -107,6 +286,7 @@ cPlacedPiece::cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece m_NumCCWRotations(a_NumCCWRotations) { m_Depth = (m_Parent == NULL) ? 0 : (m_Parent->GetDepth() + 1); + m_HitBox = a_Piece.RotateMoveHitBox(a_NumCCWRotations, a_Coords.x, a_Coords.y, a_Coords.z); } @@ -127,7 +307,20 @@ cPieceGenerator::cPieceGenerator(cPiecePool & a_PiecePool, int a_Seed) : -cPlacedPiece cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors) +void cPieceGenerator::FreePieces(cPlacedPieces & a_PlacedPieces) +{ + for (cPlacedPieces::iterator itr = a_PlacedPieces.begin(), end = a_PlacedPieces.end(); itr != end; ++itr) + { + delete *itr; + } // for itr - a_PlacedPieces[] + a_PlacedPieces.clear(); +} + + + + + +cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors) { m_PiecePool.Reset(); int rnd = m_Noise.IntNoise3DInt(a_BlockX, a_BlockY, a_BlockZ) / 7; @@ -150,7 +343,7 @@ cPlacedPiece cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, int } int Rotation = Rotations[rnd % NumRotations]; - cPlacedPiece res(NULL, *StartingPiece, Vector3i(a_BlockX, a_BlockY, a_BlockZ), Rotation); + cPlacedPiece * res = new cPlacedPiece(NULL, *StartingPiece, Vector3i(a_BlockX, a_BlockY, a_BlockZ), Rotation); // Place the piece's connectors into a_OutConnectors: const cPiece::cConnectors & Conn = StartingPiece->GetConnectors(); @@ -171,7 +364,7 @@ cPlacedPiece cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, int bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiece, const cPiece::cConnector & a_Connector, cPlacedPieces & a_OutPieces) { // Translation of direction - direction -> number of CCW rotations needed: - // You need DirectionRotationTable[rot1][rot2] CCW turns to get from rot1 to rot2 + // You need DirectionRotationTable[rot1][rot2] CCW turns to connect rot1 to rot2 (they are opposite) static const int DirectionRotationTable[6][6] = { /* YM, YP, ZM, ZP, XM, XP @@ -188,6 +381,12 @@ bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiec cConnections Connections; cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(a_Connector.m_Type); Connections.reserve(AvailablePieces.size()); + Vector3i ConnPos = a_Connector.m_Pos; // The position at which the new connector should be placed - 1 block away from the connector + AddFaceDirection(ConnPos.x, ConnPos.y, ConnPos.z, a_Connector.m_Direction); + + // DEBUG: + printf("Placing piece at pos {%d, %d, %d}, direction %s\n", ConnPos.x, ConnPos.y, ConnPos.z, BlockFaceToString(a_Connector.m_Direction).c_str()); + for (cPieces::iterator itrP = AvailablePieces.begin(), endP = AvailablePieces.end(); itrP != endP; ++itrP) { cPiece::cConnectors Connectors = (*itrP)->GetConnectors(); @@ -204,7 +403,7 @@ bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiec // Doesn't support this rotation continue; } - if (!CheckConnection(a_Connector, **itrP, *itrC, NumCCWRotations, a_OutPieces)) + if (!CheckConnection(a_Connector, ConnPos, **itrP, *itrC, NumCCWRotations, a_OutPieces)) { // Doesn't fit in this rotation continue; @@ -219,17 +418,23 @@ bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiec } // Choose a random connection from the list: - int rnd = m_Noise.IntNoise3DInt(a_Connector.m_X, a_Connector.m_Y, a_Connector.m_Z) / 7; + int rnd = m_Noise.IntNoise3DInt(a_Connector.m_Pos.x, a_Connector.m_Pos.y, a_Connector.m_Pos.z) / 7; cConnection & Conn = Connections[rnd % Connections.size()]; // Place the piece: - cPiece::cConnector NewConnector = Conn.m_Piece->RotateMoveConnector(*(Conn.m_Connector), Conn.m_NumCCWRotations, 0, 0, 0); - Vector3i Coords = a_ParentPiece.GetCoords(); - Coords.x -= NewConnector.m_X; - Coords.y -= NewConnector.m_Y; - Coords.z -= NewConnector.m_Z; - a_OutPieces.push_back(cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), Coords, Conn.m_NumCCWRotations)); - return false; + printf("Chosen connector at {%d, %d, %d}, direction %s, needs %d rotations\n", + Conn.m_Connector.m_Pos.x, Conn.m_Connector.m_Pos.y, Conn.m_Connector.m_Pos.z, + BlockFaceToString(Conn.m_Connector.m_Direction).c_str(), + Conn.m_NumCCWRotations + ); + Vector3i NewPos = Conn.m_Piece->RotatePos(Conn.m_Connector.m_Pos, Conn.m_NumCCWRotations); + ConnPos -= NewPos; + a_OutPieces.push_back(new cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), ConnPos, Conn.m_NumCCWRotations)); + + // Add the new piece's connectors to the list of free connectors: + // TODO + + return true; } @@ -238,6 +443,7 @@ bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiec bool cPieceGenerator::CheckConnection( const cPiece::cConnector & a_ExistingConnector, + const Vector3i & a_ToPos, const cPiece & a_Piece, const cPiece::cConnector & a_NewConnector, int a_NumCCWRotations, @@ -245,10 +451,10 @@ bool cPieceGenerator::CheckConnection( ) { // For each placed piece, test the hitbox against the new piece: - cCuboid RotatedHitBox = a_Piece.RotateHitBoxToConnector(a_NewConnector, a_ExistingConnector, a_NumCCWRotations); + cCuboid RotatedHitBox = a_Piece.RotateHitBoxToConnector(a_NewConnector, a_ToPos, a_NumCCWRotations); for (cPlacedPieces::const_iterator itr = a_OutPieces.begin(), end = a_OutPieces.end(); itr != end; ++itr) { - if (itr->GetHitBox().DoesIntersect(RotatedHitBox)) + if ((*itr)->GetHitBox().DoesIntersect(RotatedHitBox)) { return false; } @@ -260,12 +466,32 @@ bool cPieceGenerator::CheckConnection( +// DEBUG: +void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed) +{ + printf(" Connector pool: %u items\n", a_ConnectorPool.size() - a_NumProcessed); + size_t idx = 0; + for (cPieceGenerator::cFreeConnectors::const_iterator itr = a_ConnectorPool.begin() + a_NumProcessed, end = a_ConnectorPool.end(); itr != end; ++itr, ++idx) + { + printf(" %u: {%d, %d, %d}, type %d, direction %s\n", + idx, + itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z, + itr->m_Connector.m_Type, + BlockFaceToString(itr->m_Connector.m_Direction).c_str() + ); + } // for itr - a_ConnectorPool[] +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cPieceGenerator::cConnection: cPieceGenerator::cConnection::cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations) : m_Piece(&a_Piece), - m_Connector(&a_Connector), + m_Connector(a_Connector), m_NumCCWRotations(a_NumCCWRotations) { } @@ -277,8 +503,8 @@ cPieceGenerator::cConnection::cConnection(cPiece & a_Piece, cPiece::cConnector & /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cPieceGenerator::cFreeConnector: -cPieceGenerator::cFreeConnector::cFreeConnector(cPlacedPiece & a_Piece, const cPiece::cConnector & a_Connector) : - m_Piece(&a_Piece), +cPieceGenerator::cFreeConnector::cFreeConnector(cPlacedPiece * a_Piece, const cPiece::cConnector & a_Connector) : + m_Piece(a_Piece), m_Connector(a_Connector) { } @@ -299,7 +525,7 @@ cBFSPieceGenerator::cBFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed) : -void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces) +void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, int a_MaxDepth, cPlacedPieces & a_OutPieces) { a_OutPieces.clear(); cFreeConnectors ConnectorPool; @@ -307,6 +533,17 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, c // Place the starting piece: a_OutPieces.push_back(PlaceStartingPiece(a_BlockX, a_BlockY, a_BlockZ, ConnectorPool)); + // DEBUG: + printf("Placed the starting piece at {%d, %d, %d}\n", a_BlockX, a_BlockY, a_BlockZ); + cCuboid Hitbox = a_OutPieces[0]->GetHitBox(); + Hitbox.Sort(); + printf(" Hitbox: {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", + Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z, + Hitbox.p2.x, Hitbox.p2.y, Hitbox.p2.z, + Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1 + ); + DebugConnectorPool(ConnectorPool, 0); + // Place pieces at the available connectors: /* Instead of removing them one by one from the pool, we process them sequentially and take note of the last @@ -317,7 +554,23 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, c while (ConnectorPool.size() > NumProcessed) { cFreeConnector & Conn = ConnectorPool[NumProcessed]; - TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces); + if (Conn.m_Piece->GetDepth() < a_MaxDepth) + { + if (TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces)) + { + const cPlacedPiece * NewPiece = a_OutPieces.back(); + const Vector3i & Coords = NewPiece->GetCoords(); + printf("Placed a new piece at {%d, %d, %d}, rotation %d\n", Coords.x, Coords.y, Coords.z, NewPiece->GetNumCCWRotations()); + cCuboid Hitbox = NewPiece->GetHitBox(); + Hitbox.Sort(); + printf(" Hitbox: {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", + Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z, + Hitbox.p2.x, Hitbox.p2.y, Hitbox.p2.z, + Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1 + ); + DebugConnectorPool(ConnectorPool, NumProcessed + 1); + } + } NumProcessed++; if (NumProcessed > 1000) { diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h index 3bc71a0ab..0e24510ae 100644 --- a/src/Generating/PieceGenerator.h +++ b/src/Generating/PieceGenerator.h @@ -32,13 +32,18 @@ class cPiece public: struct cConnector { - int m_X; - int m_Y; - int m_Z; + /** Position relative to the piece */ + Vector3i m_Pos; + + /** Type of the connector. Any arbitrary number; the generator connects only connectors of the same type. */ int m_Type; + + /** Direction in which the connector is facing. + Will be matched by the opposite direction for the connecting connector. */ eBlockFace m_Direction; - cConnector(int a_X, int a_Y, int a_Z, int a_Type, eBlockFace m_Direction); + cConnector(int a_X, int a_Y, int a_Z, int a_Type, eBlockFace a_Direction); + cConnector(const Vector3i & a_Pos, int a_Type, eBlockFace a_Direction); }; typedef std::vector cConnectors; @@ -58,11 +63,17 @@ public: /** Returns true if the piece can be rotated CCW the specific number of 90-degree turns. */ virtual bool CanRotateCCW(int a_NumRotations) const = 0; + /** Returns a copy of the a_Pos after rotating the piece the specified number of CCW rotations. */ + Vector3i RotatePos(const Vector3i & a_Pos, int a_NumCCWRotations) const; + /** Returns a copy of the connector that is rotated and then moved by the specified amounts. */ cConnector RotateMoveConnector(const cConnector & a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const; - /** Returns the hitbox after the specified number of rotations and moved so that a_MyConnector is placed at a_ToConnector*/ - cCuboid RotateHitBoxToConnector(const cConnector & a_MyConnector, const cConnector & a_ToConnector, int a_NumCCWRotations) const; + /** Returns the hitbox after the specified number of rotations and moved so that a_MyConnector is placed at a_ToConnectorPos. */ + cCuboid RotateHitBoxToConnector(const cConnector & a_MyConnector, const Vector3i & a_ToConnectorPos, int a_NumCCWRotations) const; + + /** Returns the hitbox after the specified number of CCW rotations and moved by the specified amounts. */ + cCuboid RotateMoveHitBox(int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const; }; typedef std::vector cPieces; @@ -116,7 +127,7 @@ protected: int m_Depth; }; -typedef std::vector cPlacedPieces; +typedef std::vector cPlacedPieces; @@ -127,12 +138,16 @@ class cPieceGenerator public: cPieceGenerator(cPiecePool & a_PiecePool, int a_Seed); + /** Cleans up all the memory used by the placed pieces. + Call this utility function instead of freeing the items on your own. */ + void FreePieces(cPlacedPieces & a_PlacedPieces); + protected: /** The type used for storing a connection from one piece to another, while building the piece tree. */ struct cConnection { cPiece * m_Piece; // The piece being connected - cPiece::cConnector * m_Connector; // The piece's connector being used + cPiece::cConnector m_Connector; // The piece's connector being used (relative non-rotated coords) int m_NumCCWRotations; // Number of rotations necessary to match the two connectors cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations); @@ -145,7 +160,7 @@ protected: cPlacedPiece * m_Piece; cPiece::cConnector m_Connector; - cFreeConnector(cPlacedPiece & a_Piece, const cPiece::cConnector & a_Connector); + cFreeConnector(cPlacedPiece * a_Piece, const cPiece::cConnector & a_Connector); }; typedef std::vector cFreeConnectors; @@ -157,7 +172,7 @@ protected: /** Selects a starting piece and places it, including the rotations. Also puts the piece's connectors in a_OutConnectors. */ - cPlacedPiece PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors); + cPlacedPiece * PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors); /** Tries to place a new piece at the specified (placed) connector. Returns true if successful. */ bool TryPlacePieceAtConnector( @@ -168,14 +183,22 @@ protected: /** Checks if the specified piece would fit with the already-placed pieces, using the specified connector and number of CCW rotations. + a_ExistingConnector is in world-coords and is already rotated properly + a_ToPos is the world-coords position on which the new connector should be placed (1 block away from a_ExistingConnector, in its Direction) + a_NewConnector is in the original (non-rotated) coords. Returns true if the piece fits, false if not. */ bool CheckConnection( const cPiece::cConnector & a_ExistingConnector, // The existing connector + const Vector3i & a_ToPos, // The position on which the new connector should be placed const cPiece & a_Piece, // The new piece const cPiece::cConnector & a_NewConnector, // The connector of the new piece int a_NumCCWRotations, // Number of rotations for the new piece to align the connector const cPlacedPieces & a_OutPieces // All the already-placed pieces to check ); + + /** DEBUG: Outputs all the connectors in the pool into stdout. + a_NumProcessed signals the number of connectors from the pool that should be considered processed (not listed). */ + void DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed); } ; @@ -190,8 +213,9 @@ class cBFSPieceGenerator : public: cBFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed); - /** Generates a placement for pieces at the specified coords. */ - void PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces); + /** Generates a placement for pieces at the specified coords. + Caller must free each individual cPlacedPiece in a_OutPieces. */ + void PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, int a_MaxDepth, cPlacedPieces & a_OutPieces); }; @@ -204,7 +228,8 @@ class cDFSPieceGenerator : public: cDFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed); - /** Generates a placement for pieces at the specified coords. */ + /** Generates a placement for pieces at the specified coords. + Caller must free each individual cPlacedPiece in a_OutPieces. */ void PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces); }; -- cgit v1.2.3 From 77787fb719bf6437d4101f091b5b9acedea83dd3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Mar 2014 14:55:47 +0000 Subject: != FACE_NONE --- src/ClientHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index d268a4122..1bd55a461 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -949,7 +949,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType); BlockHandler->OnCancelRightClick(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); - if (a_BlockFace > BLOCK_FACE_NONE) + if (a_BlockFace != BLOCK_FACE_NONE) { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); -- cgit v1.2.3 From b64e9fb7f52e4a2b75b49413fdc2194132885370 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Mar 2014 00:17:23 +0000 Subject: Beds now work properly fixes #707 Also fixes FS392 Conflicts: src/Blocks/WorldInterface.h src/ClientHandle.cpp --- src/Blocks/BlockBed.cpp | 73 +++++++++++++++++++++++++++++++++++++---- src/Blocks/BroadcastInterface.h | 5 +-- src/Blocks/WorldInterface.h | 8 ++++- src/Entities/Player.h | 17 ++++++++-- src/World.h | 8 ++--- 5 files changed, 94 insertions(+), 17 deletions(-) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 3dad4feba..ca3927827 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -51,6 +51,49 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInt +class cTimeFastForwardTester : + public cPlayerListCallback +{ + virtual bool Item(cPlayer * a_Player) override + { + if (!a_Player->IsInBed()) + { + return true; + } + + return false; + } +}; + + + + + +class cPlayerBedStateUnsetter : + public cPlayerListCallback +{ +public: + cPlayerBedStateUnsetter(Vector3i a_Position, cWorldInterface & a_WorldInterface) : + m_Position(a_Position), m_WorldInterface(a_WorldInterface) + { + } + + virtual bool Item(cPlayer * a_Player) override + { + a_Player->SetIsInBed(false); + m_WorldInterface.GetBroadcastManager().BroadcastEntityAnimation(*a_Player, 2); + return false; + } + +private: + Vector3i m_Position; + cWorldInterface & m_WorldInterface; +}; + + + + + void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { if (a_WorldInterface.GetDimension() != dimOverworld) @@ -69,6 +112,8 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface } else { + Vector3i PillowDirection(0, 0, 0); + if (Meta & 0x8) { // Is pillow @@ -77,16 +122,30 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface else { // Is foot end - Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); - if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + VERIFY((Meta & 0x4) != 1); // Occupied flag should never be set, else our compilator (intended) is broken + + PillowDirection = MetaDataToDirection(Meta & 0x7); + if (a_ChunkInterface.GetBlock(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z) == E_BLOCK_BED) // Must always use pillow location for sleeping { - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z); } } - a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (Meta | (1 << 2))); - } - - } else { + + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta | 0x4); // Where 0x4 = occupied bit + a_Player->SetIsInBed(true); + + cTimeFastForwardTester Tester; + if (a_WorldInterface.ForEachPlayer(Tester)) + { + cPlayerBedStateUnsetter Unsetter(Vector3i(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z), a_WorldInterface); + a_WorldInterface.ForEachPlayer(Unsetter); + a_WorldInterface.SetTimeOfDay(0); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0xB); // Where 0xB = 1011, and zero is to make sure 'occupied' bit is always unset + } + } + } + else + { a_Player->SendMessageFailure("You can only sleep at night"); } } diff --git a/src/Blocks/BroadcastInterface.h b/src/Blocks/BroadcastInterface.h index f6ccd580b..01966ffbd 100644 --- a/src/Blocks/BroadcastInterface.h +++ b/src/Blocks/BroadcastInterface.h @@ -5,6 +5,7 @@ class cBroadcastInterface { public: - virtual void BroadcastUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0; - virtual void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL) = 0; + virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0; + virtual void BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL) = 0; + virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) = 0; }; diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index e59b00eff..580339d32 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -27,7 +27,13 @@ public: /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */ virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) = 0; - + /** Sends the block on those coords to the player */ virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, cPlayer * a_Player) = 0; + + /** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */ + virtual bool ForEachPlayer(cItemCallback & a_Callback) = 0; + + virtual void SetTimeOfDay(Int64 a_TimeOfDay) = 0; + }; diff --git a/src/Entities/Player.h b/src/Entities/Player.h index a795bb9eb..83a553821 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -275,6 +275,9 @@ public: /// Returns true if the player is currently flying. bool IsFlying(void) const { return m_IsFlying; } + /** Returns if a player is sleeping in a bed */ + bool IsInBed(void) const { return m_bIsInBed; } + /// returns true if the player has thrown out a floater. bool IsFishing(void) const { return m_IsFishing; } @@ -283,6 +286,9 @@ public: int GetFloaterID(void) const { return m_FloaterID; } // tolua_end + + /** Sets a player's in-bed state; we can't be sure plugins will keep this value updated, so no exporting */ + void SetIsInBed(bool a_Flag) { m_bIsInBed = a_Flag; } /// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet void StartEating(void); @@ -376,8 +382,8 @@ protected: GroupList m_ResolvedGroups; GroupList m_Groups; - std::string m_PlayerName; - std::string m_LoadedWorldName; + AString m_PlayerName; + AString m_LoadedWorldName; /// Xp Level stuff enum @@ -465,7 +471,7 @@ protected: int m_FloaterID; - cTeam* m_Team; + cTeam * m_Team; @@ -488,6 +494,11 @@ protected: /// Adds food exhaustion based on the difference between Pos and LastPos, sprinting status and swimming (in water block) void ApplyFoodExhaustionFromMovement(); + + /** Flag representing whether the player is currently in a bed + Set by a right click on unoccupied bed, unset by a time fast forward or teleport */ + bool m_bIsInBed; + } ; // tolua_export diff --git a/src/World.h b/src/World.h index 0a0939dd1..738697c94 100644 --- a/src/World.h +++ b/src/World.h @@ -134,7 +134,7 @@ public: m_WeatherInterval = a_WeatherInterval; } - void SetTimeOfDay(Int64 a_TimeOfDay) + virtual void SetTimeOfDay(Int64 a_TimeOfDay) { m_TimeOfDay = a_TimeOfDay; m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0; @@ -204,7 +204,7 @@ public: void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL); void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); - void BroadcastEntityAnimation (const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL); + virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL); void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); // tolua_export void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL); void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL); @@ -217,7 +217,7 @@ public: void BroadcastTeleportEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL); - virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ); + virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ); void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL); virtual cBroadcastInterface & GetBroadcastManager() @@ -274,7 +274,7 @@ public: void RemovePlayer( cPlayer* a_Player ); /** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */ - bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << + virtual bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << /** Calls the callback for the player of the given name; returns true if the player was found and the callback called, false if player not found. Callback return ignored */ bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << -- cgit v1.2.3 From 888c3f1af7b817ab770703ce0638e0eef07d2d31 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Mar 2014 15:53:03 +0000 Subject: Fixed VERIFY --- src/Blocks/BlockBed.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index ca3927827..6a3c6a55b 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -122,7 +122,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface else { // Is foot end - VERIFY((Meta & 0x4) != 1); // Occupied flag should never be set, else our compilator (intended) is broken + VERIFY((Meta & 0x4) != 0x4); // Occupied flag should never be set, else our compilator (intended) is broken PillowDirection = MetaDataToDirection(Meta & 0x7); if (a_ChunkInterface.GetBlock(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z) == E_BLOCK_BED) // Must always use pillow location for sleeping -- cgit v1.2.3 From c5436e1ae75928f08a411d29a0b28241c3f2b062 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 09:16:15 -0700 Subject: Lots more warnings --- SetFlags.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/SetFlags.cmake b/SetFlags.cmake index 56d32b8fe..ec2f6c556 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -192,6 +192,15 @@ macro(set_exe_flags) add_flags_cxx("-D__extern_always_inline=inline") add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation") + add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=padded") + add_flags_cxx("-Wno-error=deprecated -Wno-error=weak-vtables -Wno-error=float-equal") + add_flags_cxx("-Wno-error=missing-prototypes -Wno-error=non-virtual-dtor") + add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") + add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") + add_flags_cxx("-Wno-error=cast-align -Wno-error=unused-macros") + add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") + add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef") + add_flags_cxx("-Wno-error=format-nonliteral") endif() endif() -- cgit v1.2.3 From f4201e0b825479c6ae8ff3165fc0b7fa949c0006 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 09:25:16 -0700 Subject: Fixed gcc error --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 5e49e4909..4301e1733 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = 16; +const int MAX_PAK_FILES = 16U; /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From e73caf30f09248a7e428a937226e0383e69ff6ce Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 09:33:40 -0700 Subject: Fix gcc error attempt 2 --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 4301e1733..885099713 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = 16U; +const int MAX_PAK_FILES = static_cast(16); /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From ebf163b77a030553c616d19179a9cd0f6de787a6 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 09:45:59 -0700 Subject: Unsigned types take 3 --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 885099713..663260aaa 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = static_cast(16); +const int MAX_PAK_FILES = static_cast(16); /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From b8cd0b0897f42f0d294203cec68729f43ecb711d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 17:48:17 +0100 Subject: Hotfix for MSVC compilation. --- src/Protocol/Protocol125.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 66f3227b0..aca24c03a 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -11,6 +11,7 @@ #include "Protocol.h" #include "../ByteBuffer.h" +#include "../Entities/Painting.h" -- cgit v1.2.3 From 167ef3b7a1a1ec23330552decfc7d005ccfc8caa Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 09:52:49 -0700 Subject: Take 4 --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 663260aaa..6e39b44cc 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = static_cast(16); +const int MAX_PAK_FILES = static_cast(16); /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From 5c4c147e487e9dc08cfacd156b1f60a485460b75 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 17:58:01 +0100 Subject: Silenced useless MSVC warnings in cMetaRotater. --- src/Blocks/MetaRotater.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h index d3664b6f1..dde88e6db 100644 --- a/src/Blocks/MetaRotater.h +++ b/src/Blocks/MetaRotater.h @@ -4,6 +4,15 @@ #pragma once +// MSVC generates warnings for the templated AssertIfNotMatched parameter conditions, so disable it: +#ifdef _MSC_VER + #pragma warning(disable: 4127) // Conditional expression is constant +#endif + + + + + /* Provides a mixin for rotations and reflections following the standard pattern of apply mask then use case. @@ -29,6 +38,9 @@ public: }; + + + template NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) { @@ -49,6 +61,8 @@ NIBBLETYPE cMetaRotater NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) { @@ -69,6 +83,8 @@ NIBBLETYPE cMetaRotater NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) { @@ -85,6 +101,7 @@ NIBBLETYPE cMetaRotater NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) { @@ -97,3 +114,7 @@ NIBBLETYPE cMetaRotater Date: Sun, 9 Mar 2014 10:04:07 -0700 Subject: Take 5 --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 6e39b44cc..18d4452d9 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = static_cast(16); +const int MAX_PAK_FILES = static_cast(16); /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From 430aba9f1dc5db8c3d1ec9f9552bb41f8a0b21b0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 10:10:36 -0700 Subject: Its a const not a macro --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 18d4452d9..95477838e 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = static_cast(16); +const size_t MAX_PAK_FILES = 16; /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From 676dcfd1c74a36882b5b9bb75749e3bd86b75d9e Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 10:32:56 -0700 Subject: Globals.h is now warnings free again. Also turned off Wpadded as it is indicates potental performance issues rather than potential bugs --- SetFlags.cmake | 2 +- src/ChunkDef.h | 32 ++++++++++++++++++++++++-------- src/Globals.h | 2 -- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index ec2f6c556..82472f333 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -192,7 +192,7 @@ macro(set_exe_flags) add_flags_cxx("-D__extern_always_inline=inline") add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation") - add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=padded") + add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-padded") add_flags_cxx("-Wno-error=deprecated -Wno-error=weak-vtables -Wno-error=float-equal") add_flags_cxx("-Wno-error=missing-prototypes -Wno-error=non-virtual-dtor") add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 63431f211..a5059348c 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -124,7 +124,9 @@ public: (z < Width) && (z > -1) ) { - return MakeIndexNoCheck(x, y, z); + return MakeIndexNoCheck(static_cast(x), + static_cast(y), + static_cast(z)); } LOGERROR("cChunkDef::MakeIndex(): coords out of range: {%d, %d, %d}; returning fake index 0", x, y, z); ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!"); @@ -166,7 +168,9 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type; + a_BlockTypes[MakeIndexNoCheck(static_cast(a_X), + static_cast(a_Y), + static_cast(a_Z))] = a_Type; } @@ -182,7 +186,9 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)]; + return a_BlockTypes[MakeIndexNoCheck(static_cast(a_X), + static_cast(a_Y), + static_cast(a_Z))]; } @@ -240,7 +246,9 @@ public: { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { - unsigned int Index = MakeIndexNoCheck(x, y, z); + unsigned int Index = MakeIndexNoCheck(static_cast(x), + static_cast(y), + static_cast(z)); return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); @@ -255,8 +263,8 @@ public: ASSERT(!"cChunkDef::SetNibble(): index out of range!"); return; } - a_Buffer[a_BlockIdx / 2] = ( - (a_Buffer[a_BlockIdx / 2] & (0xf0 >> (static_cast(a_BlockIdx & 1) * 4))) | // The untouched nibble + a_Buffer[a_BlockIdx / 2] = static_cast( + (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set ); } @@ -274,8 +282,10 @@ public: return; } - int Index = MakeIndexNoCheck(x, y, z); - a_Buffer[Index / 2] = ( + unsigned int Index = MakeIndexNoCheck(static_cast(x), + static_cast(y), + static_cast(z)); + a_Buffer[Index / 2] = static_cast( (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set ); @@ -435,6 +445,9 @@ Used primarily for entity moving while both chunks are locked. class cClientDiffCallback { public: + + virtual ~cClientDiffCallback() {} + /// Called for clients that are in Chunk1 and not in Chunk2, virtual void Removed(cClientHandle * a_Client) = 0; @@ -495,6 +508,9 @@ typedef std::vector cChunkCoordsVector; class cChunkCoordCallback { public: + + virtual ~cChunkCoordCallback() {} + virtual void Call(int a_ChunkX, int a_ChunkZ) = 0; } ; diff --git a/src/Globals.h b/src/Globals.h index 28805a83f..98611fc55 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -254,5 +254,3 @@ T Clamp(T a_Value, T a_Min, T a_Max) #include "Entities/Effects.h" - - -- cgit v1.2.3 From 713c59b60b6a096554eda7fabc7696b33a6fcb59 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 10:41:53 -0700 Subject: Treat enum missmatches as warnings for now as there is such a large number of them. --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 82472f333..e71bf315d 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -182,7 +182,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch") + add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch -Wno-error=enum-compare") # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") -- cgit v1.2.3 From 617ad0b5f8e8d469ec017a0e83754f7401f64d00 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 10:46:39 -0700 Subject: Only enable -Werror in gcc because gcc doesn't let you suppress enum missmatch warnings --- SetFlags.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index e71bf315d..a9657fff1 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -182,7 +182,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch -Wno-error=enum-compare") + add_flags_cxx("-Wall -Wextra -Wno-unused-parameter -Wno-error=switch") # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") @@ -190,7 +190,7 @@ macro(set_exe_flags) # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") add_flags_cxx("-D__extern_always_inline=inline") - add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") + add_flags_cxx("-Werror -Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation") add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-padded") add_flags_cxx("-Wno-error=deprecated -Wno-error=weak-vtables -Wno-error=float-equal") -- cgit v1.2.3 From 3aff0b44bcb751606339de6498713b3ef2ce0e33 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Mar 2014 17:51:02 +0000 Subject: Fixed #778 - stack overflow.com --- src/Entities/Floater.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h index 865d6dc50..f3b51d77b 100644 --- a/src/Entities/Floater.h +++ b/src/Entities/Floater.h @@ -11,7 +11,7 @@ class cFloater : public cEntity { - typedef cFloater super; + typedef cEntity super; public: //tolua_end -- cgit v1.2.3 From e5fc3c63f2ab4bcc8d225f746afd07d01ad9d08c Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 10:52:12 -0700 Subject: Fix IsThread destructor --- src/OSSupport/IsThread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OSSupport/IsThread.h b/src/OSSupport/IsThread.h index b8784ea33..42b8bfdda 100644 --- a/src/OSSupport/IsThread.h +++ b/src/OSSupport/IsThread.h @@ -34,7 +34,7 @@ protected: public: cIsThread(const AString & iThreadName); - ~cIsThread(); + virtual ~cIsThread(); /// Starts the thread; returns without waiting for the actual start bool Start(void); -- cgit v1.2.3 From 9825dbfd34c65580d795065d1a82e7697b9c5cbd Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 11:21:42 -0700 Subject: Fixed Mesannine twister to use UInt32 --- MCServer/Plugins/Core | 2 +- src/ByteBuffer.h | 2 +- src/Defines.h | 2 +- src/Map.h | 2 +- src/MersenneTwister.h | 4 +++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 013a32a7f..3b416b07a 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 013a32a7fb3c8a6cfe0aef892d4c7394d4e1be59 +Subproject commit 3b416b07a339b3abcbc127070d56eea05b05373d diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h index ed2e10a55..1915467f3 100644 --- a/src/ByteBuffer.h +++ b/src/ByteBuffer.h @@ -43,7 +43,7 @@ public: size_t GetReadableSpace(void) const; /// Returns the current data start index. For debugging purposes. - int GetDataStart(void) const { return m_DataStart; } + size_t GetDataStart(void) const { return m_DataStart; } /// Returns true if the specified amount of bytes are available for reading bool CanReadBytes(size_t a_Count) const; diff --git a/src/Defines.h b/src/Defines.h index 6ab2274a4..fd240c91a 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -469,7 +469,7 @@ inline void EulerToVector(double a_Pan, double a_Pitch, double & a_X, double & a inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, double & a_Pitch) { - if (a_X != 0) + if (fabs(a_X) < std::numeric_limits::epsilon() ) { a_Pan = atan2(a_Z, a_X) * 180 / PI - 90; } diff --git a/src/Map.h b/src/Map.h index a313d5431..ee7c537b1 100644 --- a/src/Map.h +++ b/src/Map.h @@ -64,7 +64,7 @@ public: unsigned int GetPixelX(void) const { return m_PixelX; } unsigned int GetPixelZ(void) const { return m_PixelZ; } - int GetRot(void) const { return m_Rot; } + unsigned int GetRot(void) const { return m_Rot; } eType GetType(void) const { return m_Type; } diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h index f4c7b0699..07b6b1e5c 100644 --- a/src/MersenneTwister.h +++ b/src/MersenneTwister.h @@ -59,10 +59,12 @@ #include #include +#include "Globals.h" + class MTRand { // Data public: - typedef long uint32; // unsigned integer type, at least 32 bits + typedef UInt32 uint32; // unsigned integer type, at least 32 bits enum { N = 624 }; // length of state vector enum { SAVE = N + 1 }; // length of array for save() -- cgit v1.2.3 From 1fdeabcf78394d197a7ab5e0f9edca07abdedd0e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 19:30:38 +0100 Subject: cPieceGenerator: New connectors are added to the free pool. --- src/Generating/PieceGenerator.cpp | 32 ++++++++++++++++++++++++++------ src/Generating/PieceGenerator.h | 7 ++++--- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index 58ccaf2c2..c8e4ec71b 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -361,7 +361,12 @@ cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, i -bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiece, const cPiece::cConnector & a_Connector, cPlacedPieces & a_OutPieces) +bool cPieceGenerator::TryPlacePieceAtConnector( + const cPlacedPiece & a_ParentPiece, + const cPiece::cConnector & a_Connector, + cPlacedPieces & a_OutPieces, + cPieceGenerator::cFreeConnectors & a_OutConnectors +) { // Translation of direction - direction -> number of CCW rotations needed: // You need DirectionRotationTable[rot1][rot2] CCW turns to connect rot1 to rot2 (they are opposite) @@ -429,10 +434,24 @@ bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiec ); Vector3i NewPos = Conn.m_Piece->RotatePos(Conn.m_Connector.m_Pos, Conn.m_NumCCWRotations); ConnPos -= NewPos; - a_OutPieces.push_back(new cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), ConnPos, Conn.m_NumCCWRotations)); + cPlacedPiece * PlacedPiece = new cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), ConnPos, Conn.m_NumCCWRotations); + a_OutPieces.push_back(PlacedPiece); // Add the new piece's connectors to the list of free connectors: - // TODO + cPiece::cConnectors Connectors = Conn.m_Piece->GetConnectors(); + + // DEBUG: + printf("Adding %u connectors to the pool\n", Connectors.size() - 1); + + for (cPiece::cConnectors::const_iterator itr = Connectors.begin(), end = Connectors.end(); itr != end; ++itr) + { + if (itr->m_Pos.Equals(Conn.m_Connector.m_Pos)) + { + // This is the connector through which we have been connected to the parent, don't add + continue; + } + a_OutConnectors.push_back(cFreeConnector(PlacedPiece, Conn.m_Piece->RotateMoveConnector(*itr, Conn.m_NumCCWRotations, ConnPos.x, ConnPos.y, ConnPos.z))); + } return true; } @@ -473,11 +492,12 @@ void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors size_t idx = 0; for (cPieceGenerator::cFreeConnectors::const_iterator itr = a_ConnectorPool.begin() + a_NumProcessed, end = a_ConnectorPool.end(); itr != end; ++itr, ++idx) { - printf(" %u: {%d, %d, %d}, type %d, direction %s\n", + printf(" %u: {%d, %d, %d}, type %d, direction %s, depth %d\n", idx, itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z, itr->m_Connector.m_Type, - BlockFaceToString(itr->m_Connector.m_Direction).c_str() + BlockFaceToString(itr->m_Connector.m_Direction).c_str(), + itr->m_Piece->GetDepth() ); } // for itr - a_ConnectorPool[] } @@ -556,7 +576,7 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, i cFreeConnector & Conn = ConnectorPool[NumProcessed]; if (Conn.m_Piece->GetDepth() < a_MaxDepth) { - if (TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces)) + if (TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces, ConnectorPool)) { const cPlacedPiece * NewPiece = a_OutPieces.back(); const Vector3i & Coords = NewPiece->GetCoords(); diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h index 0e24510ae..310c21fdd 100644 --- a/src/Generating/PieceGenerator.h +++ b/src/Generating/PieceGenerator.h @@ -176,9 +176,10 @@ protected: /** Tries to place a new piece at the specified (placed) connector. Returns true if successful. */ bool TryPlacePieceAtConnector( - const cPlacedPiece & a_ParentPiece, - const cPiece::cConnector & a_Connector, - cPlacedPieces & a_OutPieces + const cPlacedPiece & a_ParentPiece, // The existing piece to a new piece should be placed + const cPiece::cConnector & a_Connector, // The existing connector (world-coords) to which a new piece should be placed + cPlacedPieces & a_OutPieces, // Already placed pieces, to be checked for intersections + cFreeConnectors & a_OutConnectors // List of free connectors to which the new connectors will be placed ); /** Checks if the specified piece would fit with the already-placed pieces, using the specified connector -- cgit v1.2.3 From 1bf99b5fd26d142106d7a097900ebfe8a6279ad4 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 11:47:22 -0700 Subject: Be more parinoid about int sizes --- src/Defines.h | 3 ++- src/Globals.h | 18 ++++++++++++++++-- src/MersenneTwister.h | 2 -- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Defines.h b/src/Defines.h index fd240c91a..592b9434a 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -2,6 +2,7 @@ #pragma once #include "ChatColor.h" +#include @@ -469,7 +470,7 @@ inline void EulerToVector(double a_Pan, double a_Pitch, double & a_X, double & a inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, double & a_Pitch) { - if (fabs(a_X) < std::numeric_limits::epsilon() ) + if (fabs(a_X) < std::numeric_limits::epsilon()) { a_Pan = atan2(a_Z, a_X) * 180 / PI - 90; } diff --git a/src/Globals.h b/src/Globals.h index 98611fc55..b046e6db0 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -81,7 +81,7 @@ #endif - +#include // Integral types with predefined sizes: @@ -96,8 +96,22 @@ typedef unsigned short UInt16; typedef unsigned char Byte; +// If you get an error about specialization check the size of integral types +template +class SizeChecker; + +template +class SizeChecker { + T v; +}; +template class SizeChecker; +template class SizeChecker; +template class SizeChecker; +template class SizeChecker; +template class SizeChecker; +template class SizeChecker; // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for any class that shouldn't allow copying itself @@ -179,7 +193,7 @@ typedef unsigned char Byte; #include #include #include - +#include diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h index 07b6b1e5c..2c5440f17 100644 --- a/src/MersenneTwister.h +++ b/src/MersenneTwister.h @@ -59,8 +59,6 @@ #include #include -#include "Globals.h" - class MTRand { // Data public: -- cgit v1.2.3 From 8889d3b73347a7cc094a0e233479e96f2bc25a49 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 19:54:27 +0100 Subject: Added cCuboid::Engulf(). --- src/Cuboid.cpp | 34 ++++++++++++++++++++++++++++++++++ src/Cuboid.h | 3 +++ 2 files changed, 37 insertions(+) diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp index 782837b23..dc8df8500 100644 --- a/src/Cuboid.cpp +++ b/src/Cuboid.cpp @@ -197,3 +197,37 @@ bool cCuboid::IsSorted(void) const + +void cCuboid::Engulf(const Vector3i & a_Point) +{ + if (a_Point.x < p1.x) + { + p1.x = a_Point.x; + } + else if (a_Point.x > p2.x) + { + p2.x = a_Point.x; + } + + if (a_Point.y < p1.y) + { + p1.y = a_Point.y; + } + else if (a_Point.y > p2.y) + { + p2.y = a_Point.y; + } + + if (a_Point.z < p1.z) + { + p1.z = a_Point.z; + } + else if (a_Point.z > p2.z) + { + p2.z = a_Point.z; + } +} + + + + diff --git a/src/Cuboid.h b/src/Cuboid.h index 51ccf799b..50a69b853 100644 --- a/src/Cuboid.h +++ b/src/Cuboid.h @@ -86,6 +86,9 @@ public: /** Returns true if the coords are properly sorted (lesser in p1, greater in p2) */ bool IsSorted(void) const; + + /** If needed, expands the cuboid so that it contains the specified point. Assumes sorted. Doesn't contract. */ + void Engulf(const Vector3i & a_Point); } ; // tolua_end -- cgit v1.2.3 From 2eaae82a2a6f22b684ea153267c8f06f18145753 Mon Sep 17 00:00:00 2001 From: worktycho Date: Sun, 9 Mar 2014 18:57:43 +0000 Subject: Mentiod that we use some c++11 exstensions Eg override, abstract, va_copy, long long. --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7ec7058ae..0c36be8b7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ Code Stuff ---------- - * We use C++03 + * We use C++03 with some C++11 extensions (ask if you think that something would be useful) * Use the provided wrappers for OS stuff: - Threading is done by inheriting from `cIsThread`, thread synchronization through `cCriticalSection`, `cSemaphore` and `cEvent`, file access and filesystem operations through the `cFile` class, high-precision timers through `cTimer`, high-precision sleep through `cSleep` * No magic numbers, use named constants: -- cgit v1.2.3 From 81bf846e648bf757a67699c57f2a9e66f6850416 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 21:58:12 +0100 Subject: ChunkDef: Replaced enums with static const ints. This makes them easier to use in std::min et al. --- src/ChunkDef.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 7be2fa2df..7876c58e7 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -62,16 +62,12 @@ typedef unsigned char HEIGHTTYPE; class cChunkDef { public: - enum - { - // Chunk dimensions: - Width = 16, - Height = 256, - NumBlocks = Width * Height * Width, - - /// If the data is collected into a single buffer, how large it needs to be: - BlockDataSize = cChunkDef::NumBlocks * 2 + (cChunkDef::NumBlocks / 2), // 2.5 * numblocks - } ; + // Chunk dimensions: + static const int Width = 16; + static const int Height = 256; + static const int NumBlocks = Width * Height * Width; + /// If the data is collected into a single buffer, how large it needs to be: + static const int BlockDataSize = cChunkDef::NumBlocks * 2 + (cChunkDef::NumBlocks / 2); // 2.5 * numblocks /// The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the highest non-air block in the column typedef HEIGHTTYPE HeightMap[Width * Width]; -- cgit v1.2.3 From dacb6cef1d6d2942f01d15186d8a12b30d39a385 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 22:02:08 +0100 Subject: Hardened cCuboid with asserts for its assumptions. --- src/Cuboid.cpp | 6 ++++++ src/Cuboid.h | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp index dc8df8500..2400c64f3 100644 --- a/src/Cuboid.cpp +++ b/src/Cuboid.cpp @@ -72,6 +72,9 @@ int cCuboid::GetVolume(void) const bool cCuboid::DoesIntersect(const cCuboid & a_Other) const { + ASSERT(IsSorted()); + ASSERT(a_Other.IsSorted()); + // In order for cuboids to intersect, each of their coord intervals need to intersect return ( DoIntervalsIntersect(p1.x, p2.x, a_Other.p1.x, a_Other.p2.x) && @@ -86,6 +89,9 @@ bool cCuboid::DoesIntersect(const cCuboid & a_Other) const bool cCuboid::IsCompletelyInside(const cCuboid & a_Outer) const { + ASSERT(IsSorted()); + ASSERT(a_Outer.IsSorted()); + return ( (p1.x >= a_Outer.p1.x) && (p2.x <= a_Outer.p2.x) && diff --git a/src/Cuboid.h b/src/Cuboid.h index 50a69b853..b95517f69 100644 --- a/src/Cuboid.h +++ b/src/Cuboid.h @@ -34,7 +34,8 @@ public: Works on unsorted cuboids, too. */ int GetVolume(void) const; - /** Returns true if the cuboids have at least one voxel in common. Both coords are considered inclusive. */ + /** Returns true if the cuboids have at least one voxel in common. Both coords are considered inclusive. + Assumes both cuboids are sorted. */ bool DoesIntersect(const cCuboid & a_Other) const; bool IsInside(const Vector3i & v) const @@ -64,7 +65,8 @@ public: ); } - /** Returns true if this cuboid is completely inside the specifie cuboid (in all 6 coords) */ + /** Returns true if this cuboid is completely inside the specifie cuboid (in all 6 coords). + Assumes both cuboids are sorted. */ bool IsCompletelyInside(const cCuboid & a_Outer) const; /** Moves the cuboid by the specified offsets in each direction */ @@ -72,7 +74,7 @@ public: /** Expands the cuboid by the specified amount in each direction. Works on unsorted cuboids as well. - Note that this function doesn't check for underflows. */ + Note that this function doesn't check for underflows when using negative amounts. */ void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ); /** Clamps both X coords to the specified range. Works on unsorted cuboids, too. */ -- cgit v1.2.3 From 0e985293b50ec89a163f40222825b3c147135b9a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 22:04:29 +0100 Subject: A working POCPiece generator. --- src/Generating/ComposableGenerator.cpp | 5 + src/Generating/POCPieceGenerator.cpp | 265 +++++++++++++++++++++++++++++++++ src/Generating/POCPieceGenerator.h | 54 +++++++ src/Generating/PieceGenerator.cpp | 31 +++- src/Generating/PieceGenerator.h | 10 +- 5 files changed, 359 insertions(+), 6 deletions(-) create mode 100644 src/Generating/POCPieceGenerator.cpp create mode 100644 src/Generating/POCPieceGenerator.h diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index e96e9a645..6c00b5905 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -22,6 +22,7 @@ #include "EndGen.h" #include "MineShafts.h" #include "Noise3DGenerator.h" +#include "POCPieceGenerator.h" #include "Ravines.h" @@ -364,6 +365,10 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) { m_FinishGens.push_back(new cStructGenOreNests(Seed)); } + else if (NoCaseCompare(*itr, "POCPieces") == 0) + { + m_FinishGens.push_back(new cPOCPieceGenerator(Seed)); + } else if (NoCaseCompare(*itr, "PreSimulator") == 0) { m_FinishGens.push_back(new cFinishGenPreSimulator); diff --git a/src/Generating/POCPieceGenerator.cpp b/src/Generating/POCPieceGenerator.cpp new file mode 100644 index 000000000..9edfcc64f --- /dev/null +++ b/src/Generating/POCPieceGenerator.cpp @@ -0,0 +1,265 @@ + +// POCPieceGenerator.cpp + +// Implements the cPOCPieceGenerator class representing a Proof-Of_Concept structure generator using the cPieceGenerator technique +// The generator generates a maze of rooms at {0, 100, 0} + +#include "Globals.h" +#include "POCPieceGenerator.h" +#include "ChunkDesc.h" + + + + + +/** POC pieces are simple boxes that have connectors in the middle of their walls. +Each wall has one connector, there are 3 connector types that get assigned semi-randomly. +The piece also knows how to imprint itself in a cChunkDesc, each piece has a different color glass +and each connector is uses a different color wool frame. */ +class cPOCPiece : + public cPiece +{ +public: + cPOCPiece(int a_Size) : + m_Size(a_Size) + { + m_Connectors.push_back(cConnector(m_Size / 2, 1, 0, 0, BLOCK_FACE_ZM)); + m_Connectors.push_back(cConnector(m_Size / 2, 1, m_Size - 1, 1, BLOCK_FACE_ZP)); + m_Connectors.push_back(cConnector(0, 1, m_Size / 2, 2, BLOCK_FACE_XM)); + m_Connectors.push_back(cConnector(m_Size - 1, 1, m_Size / 2, m_Size % 3, BLOCK_FACE_XP)); + } + + + /** Imprints the piece in the specified chunk. Assumes they intersect. */ + void ImprintInChunk(cChunkDesc & a_ChunkDesc, const Vector3i & a_Pos, int a_NumCCWRotations) + { + int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; + int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; + Vector3i Min = a_Pos; + Min.Move(-BlockX, 0, -BlockZ); + Vector3i Max = Min; + Max.Move(m_Size - 1, 2, m_Size - 1); + ASSERT(Min.x < cChunkDef::Width); + ASSERT(Min.z < cChunkDef::Width); + ASSERT(Max.x >= 0); + ASSERT(Max.z >= 0); + if (Min.x >= 0) + { + // Draw the XM wall: + a_ChunkDesc.FillRelCuboid(Min.x, Min.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16); + } + if (Min.z >= 0) + { + // Draw the ZM wall: + a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Min.z, Min.z, E_BLOCK_STAINED_GLASS, m_Size % 16); + } + if (Max.x < cChunkDef::Width) + { + // Draw the XP wall: + a_ChunkDesc.FillRelCuboid(Max.x, Max.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16); + } + if (Max.z < cChunkDef::Width) + { + // Draw the ZP wall: + a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Max.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16); + } + + // Draw all the connectors: + for (cConnectors::const_iterator itr = m_Connectors.begin(), end = m_Connectors.end(); itr != end; ++itr) + { + cConnector Conn = cPiece::RotateMoveConnector(*itr, a_NumCCWRotations, a_Pos.x, a_Pos.y, a_Pos.z); + Conn.m_Pos.Move(-BlockX, 0, -BlockZ); + if ( + (Conn.m_Pos.x >= 0) && (Conn.m_Pos.x < cChunkDef::Width) && + (Conn.m_Pos.z >= 0) && (Conn.m_Pos.z < cChunkDef::Width) + ) + { + a_ChunkDesc.SetBlockTypeMeta(Conn.m_Pos.x, Conn.m_Pos.y, Conn.m_Pos.z, E_BLOCK_WOOL, itr->m_Type % 16); + } + + /* + // TODO: Frame the connectors + switch (itr->m_Direction) + { + case BLOCK_FACE_XM: + case BLOCK_FACE_XP: + { + // TODO + break; + } + + case BLOCK_FACE_ZM: + case BLOCK_FACE_ZP: + { + // TODO + break; + } + } + */ + } // for itr - m_Connectors[] + } + +protected: + int m_Size; + cConnectors m_Connectors; + + // cPiece overrides: + virtual cConnectors GetConnectors(void) const override + { + return m_Connectors; + } + + virtual Vector3i GetSize(void) const override + { + return Vector3i(m_Size, 3, m_Size); + } + + virtual cCuboid GetHitBox(void) const override + { + return cCuboid(0, 0, 0, m_Size - 1, 2, m_Size - 1); + } + + virtual bool CanRotateCCW(int a_NumRotations) const override + { + return true; + } +}; + + + + + +static void DebugPieces(const cPlacedPieces & a_Pieces) +{ + size_t idx = 0; + for (cPlacedPieces::const_iterator itr = a_Pieces.begin(), end = a_Pieces.end(); itr != end; ++itr, ++idx) + { + const cCuboid & HitBox = (*itr)->GetHitBox(); + printf(" %u: %d rotations, {%d - %d, %d - %d}\n", + idx, (*itr)->GetNumCCWRotations(), + HitBox.p1.x, HitBox.p2.x, HitBox.p1.z, HitBox.p2.z + ); + } // for itr - a_Pieces[] +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cPOCPieceGenerator: + +cPOCPieceGenerator::cPOCPieceGenerator(int a_Seed) : + m_Seed(a_Seed) +{ + // Prepare a vector of available pieces: + m_AvailPieces.push_back(new cPOCPiece(5)); + m_AvailPieces.push_back(new cPOCPiece(7)); + m_AvailPieces.push_back(new cPOCPiece(9)); + + // Generate the structure: + cBFSPieceGenerator Gen(*this, a_Seed); + Gen.PlacePieces(0, 50, 0, 6, m_Pieces); + + // DebugPieces(m_Pieces); + + // Get the smallest cuboid encompassing the entire generated structure: + cCuboid Bounds(0, 50, 0, 0, 50, 0); + for (cPlacedPieces::const_iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) + { + Vector3i MinCoords = (*itr)->GetCoords(); + Bounds.Engulf(MinCoords); + Bounds.Engulf(MinCoords + (*itr)->GetPiece().GetSize()); + } // for itr - m_Pieces[] + m_Bounds = Bounds; +} + + + + + +cPOCPieceGenerator::~cPOCPieceGenerator() +{ + cPieceGenerator::FreePieces(m_Pieces); +} + + + + + +void cPOCPieceGenerator::GenFinish(cChunkDesc & a_ChunkDesc) +{ + int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; + int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; + if ( + (BlockX + 16 < m_Bounds.p1.x) || (BlockX > m_Bounds.p2.x) || // X coords out of bounds of the generated structure + (BlockZ + 16 < m_Bounds.p1.z) || (BlockZ > m_Bounds.p2.z) // Z coords out of bounds of the generated structure + ) + { + return; + } + + // Imprint each piece in the chunk: + for (cPlacedPieces::const_iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) + { + const Vector3i & Pos = (*itr)->GetCoords(); + Vector3i Size = (*itr)->GetPiece().GetSize(); + if (((*itr)->GetNumCCWRotations() % 2) == 1) + { + std::swap(Size.x, Size.z); + } + if ( + (Pos.x >= BlockX + 16) || (Pos.x + Size.x - 1 < BlockX) || + (Pos.z >= BlockZ + 16) || (Pos.z + Size.z - 1 < BlockZ) + ) + { + // This piece doesn't intersect the chunk + continue; + } + + ((cPOCPiece &)(*itr)->GetPiece()).ImprintInChunk(a_ChunkDesc, Pos, (*itr)->GetNumCCWRotations()); + } // for itr - m_Pieces[] + a_ChunkDesc.UpdateHeightmap(); +} + + + + + +cPieces cPOCPieceGenerator::GetPiecesWithConnector(int a_ConnectorType) +{ + // Each piece has each connector + return m_AvailPieces; +} + + + + + +cPieces cPOCPieceGenerator::GetStartingPieces(void) +{ + // Any piece can be a starting piece + return m_AvailPieces; +} + + + + + +void cPOCPieceGenerator::PiecePlaced(const cPiece & a_Piece) +{ + UNUSED(a_Piece); +} + + + + + +void cPOCPieceGenerator::Reset(void) +{ + // Nothing needed +} + + + + diff --git a/src/Generating/POCPieceGenerator.h b/src/Generating/POCPieceGenerator.h new file mode 100644 index 000000000..de3114ce0 --- /dev/null +++ b/src/Generating/POCPieceGenerator.h @@ -0,0 +1,54 @@ + +// POCPieceGenerator.h + +// Declares the cPOCPieceGenerator class representing a Proof-Of_Concept structure generator using the cPieceGenerator technique +// The generator generates a maze of rooms at {0, 100, 0} + + + + + +#pragma once + +#include "PieceGenerator.h" +#include "ComposableGenerator.h" + + + + + +class cPOCPieceGenerator : + public cFinishGen, + protected cPiecePool +{ +public: + cPOCPieceGenerator(int a_Seed); + ~cPOCPieceGenerator(); + +protected: + int m_Seed; + + /** The pieces from which the generated structure is built. */ + cPieces m_AvailPieces; + + /** The placed pieces of the generated structure. */ + cPlacedPieces m_Pieces; + + /** Bounds of the complete structure, to save on processing outside chunks. */ + cCuboid m_Bounds; + + + // cFinishGen overrides: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; + + // cPiecePool overrides: + virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override; + virtual cPieces GetStartingPieces(void) override; + virtual void PiecePlaced(const cPiece & a_Piece) override; + virtual void Reset(void) override; +} ; + + + + + diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index c8e4ec71b..e3de5b951 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -11,6 +11,8 @@ +#ifdef SELF_TEST + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Self-test: @@ -132,6 +134,8 @@ protected: } } g_Test; +#endif // SELF_TEST + @@ -287,6 +291,7 @@ cPlacedPiece::cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece { m_Depth = (m_Parent == NULL) ? 0 : (m_Parent->GetDepth() + 1); m_HitBox = a_Piece.RotateMoveHitBox(a_NumCCWRotations, a_Coords.x, a_Coords.y, a_Coords.z); + m_HitBox.Sort(); } @@ -375,10 +380,10 @@ bool cPieceGenerator::TryPlacePieceAtConnector( /* YM, YP, ZM, ZP, XM, XP /* YM */ { 0, 0, 0, 0, 0, 0}, /* YP */ { 0, 0, 0, 0, 0, 0}, - /* ZM */ { 0, 0, 0, 2, 1, 3}, - /* ZP */ { 0, 0, 2, 0, 3, 1}, - /* XM */ { 0, 0, 3, 1, 0, 2}, - /* XP */ { 0, 0, 1, 3, 2, 0}, + /* ZM */ { 0, 0, 2, 0, 1, 3}, + /* ZP */ { 0, 0, 0, 2, 3, 1}, + /* XM */ { 0, 0, 3, 1, 2, 0}, + /* XP */ { 0, 0, 1, 3, 0, 2}, }; // Get a list of available connections: @@ -389,8 +394,10 @@ bool cPieceGenerator::TryPlacePieceAtConnector( Vector3i ConnPos = a_Connector.m_Pos; // The position at which the new connector should be placed - 1 block away from the connector AddFaceDirection(ConnPos.x, ConnPos.y, ConnPos.z, a_Connector.m_Direction); + /* // DEBUG: - printf("Placing piece at pos {%d, %d, %d}, direction %s\n", ConnPos.x, ConnPos.y, ConnPos.z, BlockFaceToString(a_Connector.m_Direction).c_str()); + printf("Placing piece at connector pos {%d, %d, %d}, direction %s\n", ConnPos.x, ConnPos.y, ConnPos.z, BlockFaceToString(a_Connector.m_Direction).c_str()); + //*/ for (cPieces::iterator itrP = AvailablePieces.begin(), endP = AvailablePieces.end(); itrP != endP; ++itrP) { @@ -427,11 +434,15 @@ bool cPieceGenerator::TryPlacePieceAtConnector( cConnection & Conn = Connections[rnd % Connections.size()]; // Place the piece: + /* + // DEBUG printf("Chosen connector at {%d, %d, %d}, direction %s, needs %d rotations\n", Conn.m_Connector.m_Pos.x, Conn.m_Connector.m_Pos.y, Conn.m_Connector.m_Pos.z, BlockFaceToString(Conn.m_Connector.m_Direction).c_str(), Conn.m_NumCCWRotations ); + //*/ + Vector3i NewPos = Conn.m_Piece->RotatePos(Conn.m_Connector.m_Pos, Conn.m_NumCCWRotations); ConnPos -= NewPos; cPlacedPiece * PlacedPiece = new cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), ConnPos, Conn.m_NumCCWRotations); @@ -440,8 +451,10 @@ bool cPieceGenerator::TryPlacePieceAtConnector( // Add the new piece's connectors to the list of free connectors: cPiece::cConnectors Connectors = Conn.m_Piece->GetConnectors(); + /* // DEBUG: printf("Adding %u connectors to the pool\n", Connectors.size() - 1); + //*/ for (cPiece::cConnectors::const_iterator itr = Connectors.begin(), end = Connectors.end(); itr != end; ++itr) { @@ -471,6 +484,7 @@ bool cPieceGenerator::CheckConnection( { // For each placed piece, test the hitbox against the new piece: cCuboid RotatedHitBox = a_Piece.RotateHitBoxToConnector(a_NewConnector, a_ToPos, a_NumCCWRotations); + RotatedHitBox.Sort(); for (cPlacedPieces::const_iterator itr = a_OutPieces.begin(), end = a_OutPieces.end(); itr != end; ++itr) { if ((*itr)->GetHitBox().DoesIntersect(RotatedHitBox)) @@ -485,6 +499,7 @@ bool cPieceGenerator::CheckConnection( +//* // DEBUG: void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed) { @@ -501,6 +516,7 @@ void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors ); } // for itr - a_ConnectorPool[] } +//*/ @@ -553,6 +569,7 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, i // Place the starting piece: a_OutPieces.push_back(PlaceStartingPiece(a_BlockX, a_BlockY, a_BlockZ, ConnectorPool)); + /* // DEBUG: printf("Placed the starting piece at {%d, %d, %d}\n", a_BlockX, a_BlockY, a_BlockZ); cCuboid Hitbox = a_OutPieces[0]->GetHitBox(); @@ -563,6 +580,7 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, i Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1 ); DebugConnectorPool(ConnectorPool, 0); + //*/ // Place pieces at the available connectors: /* @@ -578,6 +596,8 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, i { if (TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces, ConnectorPool)) { + /* + // DEBUG: const cPlacedPiece * NewPiece = a_OutPieces.back(); const Vector3i & Coords = NewPiece->GetCoords(); printf("Placed a new piece at {%d, %d, %d}, rotation %d\n", Coords.x, Coords.y, Coords.z, NewPiece->GetNumCCWRotations()); @@ -589,6 +609,7 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, i Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1 ); DebugConnectorPool(ConnectorPool, NumProcessed + 1); + //*/ } } NumProcessed++; diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h index 310c21fdd..9dd5bcfba 100644 --- a/src/Generating/PieceGenerator.h +++ b/src/Generating/PieceGenerator.h @@ -30,6 +30,9 @@ Each uses a slightly different approach to generating: class cPiece { public: + // Force a virtual destructor in all descendants + virtual ~cPiece() {} + struct cConnector { /** Position relative to the piece */ @@ -82,9 +85,14 @@ typedef std::vector cPieces; +/** This class is an interface that provides pieces for the generator. It can keep track of what pieces were +placed and adjust the returned piece vectors. */ class cPiecePool { public: + // Force a virtual destructor in all descendants: + virtual ~cPiecePool() {} + /** Returns a list of pieces that contain the specified connector type. The cPiece pointers returned are managed by the pool and the caller doesn't free them. */ virtual cPieces GetPiecesWithConnector(int a_ConnectorType) = 0; @@ -140,7 +148,7 @@ public: /** Cleans up all the memory used by the placed pieces. Call this utility function instead of freeing the items on your own. */ - void FreePieces(cPlacedPieces & a_PlacedPieces); + static void FreePieces(cPlacedPieces & a_PlacedPieces); protected: /** The type used for storing a connection from one piece to another, while building the piece tree. */ -- cgit v1.2.3 From 0f412a0a022b75823561c2f78e5f0c9469b0d1b4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Mar 2014 21:48:18 +0000 Subject: Removed uneeded meta obtain --- src/Simulator/FireSimulator.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index 6079ea740..31cc0b670 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -1,4 +1,3 @@ - #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "FireSimulator.h" @@ -334,7 +333,6 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel for (size_t i = 0; i < ARRAYCOUNT(gNeighborCoords); i++) { BLOCKTYPE BlockType; - NIBBLETYPE BlockMeta; int X = a_RelX + gNeighborCoords[i].x; int Z = a_RelZ + gNeighborCoords[i].z; @@ -343,7 +341,7 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel { continue; } - Neighbour->GetBlockTypeMeta(X, a_RelY + gCrossCoords[i].y, Z, BlockType, BlockMeta); + BlockType = Neighbour->GetBlockTypeMeta(X, a_RelY + gCrossCoords[i].y, Z); if (!IsFuel(BlockType)) { -- cgit v1.2.3 From 0b9763fc5a84ac171338484f653fdae2a2bc999a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 10 Mar 2014 07:55:47 +0100 Subject: Fixed MSVC2008 compilation. --- src/WorldStorage/FireworksSerializer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index 0e0094e76..1f05b470d 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -20,8 +20,8 @@ void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFa a_Writer.AddByte("Flicker", a_FireworkItem.m_HasFlicker); a_Writer.AddByte("Trail", a_FireworkItem.m_HasTrail); a_Writer.AddByte("Type", a_FireworkItem.m_Type); - a_Writer.AddIntArray("Colors", a_FireworkItem.m_Colours.data(), a_FireworkItem.m_Colours.size()); - a_Writer.AddIntArray("FadeColors", a_FireworkItem.m_FadeColours.data(), a_FireworkItem.m_FadeColours.size()); + a_Writer.AddIntArray("Colors", &(a_FireworkItem.m_Colours[0]), a_FireworkItem.m_Colours.size()); + a_Writer.AddIntArray("FadeColors", &(a_FireworkItem.m_FadeColours[0]), a_FireworkItem.m_FadeColours.size()); a_Writer.EndCompound(); a_Writer.EndList(); a_Writer.EndCompound(); @@ -35,11 +35,11 @@ void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFa a_Writer.AddByte("Type", a_FireworkItem.m_Type); if (!a_FireworkItem.m_Colours.empty()) { - a_Writer.AddIntArray("Colors", a_FireworkItem.m_Colours.data(), a_FireworkItem.m_Colours.size()); + a_Writer.AddIntArray("Colors", &(a_FireworkItem.m_Colours[0]), a_FireworkItem.m_Colours.size()); } if (!a_FireworkItem.m_FadeColours.empty()) { - a_Writer.AddIntArray("FadeColors", a_FireworkItem.m_FadeColours.data(), a_FireworkItem.m_FadeColours.size()); + a_Writer.AddIntArray("FadeColors", &(a_FireworkItem.m_FadeColours[0]), a_FireworkItem.m_FadeColours.size()); } a_Writer.EndCompound(); break; -- cgit v1.2.3 From 6c4807556141f49a3fa5ff63474e6b95e5fd5cbf Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 10 Mar 2014 08:38:40 +0100 Subject: POCPieces: Added height. Now the pieces connect in different heights, too, creating a true 3D maze. --- src/Generating/POCPieceGenerator.cpp | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Generating/POCPieceGenerator.cpp b/src/Generating/POCPieceGenerator.cpp index 9edfcc64f..d7619b8ff 100644 --- a/src/Generating/POCPieceGenerator.cpp +++ b/src/Generating/POCPieceGenerator.cpp @@ -20,13 +20,14 @@ class cPOCPiece : public cPiece { public: - cPOCPiece(int a_Size) : - m_Size(a_Size) + cPOCPiece(int a_SizeXZ, int a_Height) : + m_SizeXZ(a_SizeXZ), + m_Height(a_Height) { - m_Connectors.push_back(cConnector(m_Size / 2, 1, 0, 0, BLOCK_FACE_ZM)); - m_Connectors.push_back(cConnector(m_Size / 2, 1, m_Size - 1, 1, BLOCK_FACE_ZP)); - m_Connectors.push_back(cConnector(0, 1, m_Size / 2, 2, BLOCK_FACE_XM)); - m_Connectors.push_back(cConnector(m_Size - 1, 1, m_Size / 2, m_Size % 3, BLOCK_FACE_XP)); + m_Connectors.push_back(cConnector(m_SizeXZ / 2, a_Height / 2, 0, 0, BLOCK_FACE_ZM)); + m_Connectors.push_back(cConnector(m_SizeXZ / 2, a_Height / 2, m_SizeXZ - 1, 1, BLOCK_FACE_ZP)); + m_Connectors.push_back(cConnector(0, a_Height / 2, m_SizeXZ / 2, 2, BLOCK_FACE_XM)); + m_Connectors.push_back(cConnector(m_SizeXZ - 1, a_Height - 1, m_SizeXZ / 2, m_SizeXZ % 3, BLOCK_FACE_XP)); } @@ -38,7 +39,7 @@ public: Vector3i Min = a_Pos; Min.Move(-BlockX, 0, -BlockZ); Vector3i Max = Min; - Max.Move(m_Size - 1, 2, m_Size - 1); + Max.Move(m_SizeXZ - 1, m_Height - 1, m_SizeXZ - 1); ASSERT(Min.x < cChunkDef::Width); ASSERT(Min.z < cChunkDef::Width); ASSERT(Max.x >= 0); @@ -46,22 +47,22 @@ public: if (Min.x >= 0) { // Draw the XM wall: - a_ChunkDesc.FillRelCuboid(Min.x, Min.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16); + a_ChunkDesc.FillRelCuboid(Min.x, Min.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_SizeXZ % 16); } if (Min.z >= 0) { // Draw the ZM wall: - a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Min.z, Min.z, E_BLOCK_STAINED_GLASS, m_Size % 16); + a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Min.z, Min.z, E_BLOCK_STAINED_GLASS, m_SizeXZ % 16); } if (Max.x < cChunkDef::Width) { // Draw the XP wall: - a_ChunkDesc.FillRelCuboid(Max.x, Max.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16); + a_ChunkDesc.FillRelCuboid(Max.x, Max.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_SizeXZ % 16); } if (Max.z < cChunkDef::Width) { // Draw the ZP wall: - a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Max.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16); + a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Max.z, Max.z, E_BLOCK_STAINED_GLASS, m_SizeXZ % 16); } // Draw all the connectors: @@ -100,7 +101,8 @@ public: } protected: - int m_Size; + int m_SizeXZ; + int m_Height; cConnectors m_Connectors; // cPiece overrides: @@ -111,12 +113,12 @@ protected: virtual Vector3i GetSize(void) const override { - return Vector3i(m_Size, 3, m_Size); + return Vector3i(m_SizeXZ, m_Height, m_SizeXZ); } virtual cCuboid GetHitBox(void) const override { - return cCuboid(0, 0, 0, m_Size - 1, 2, m_Size - 1); + return cCuboid(0, 0, 0, m_SizeXZ - 1, m_Height - 1, m_SizeXZ - 1); } virtual bool CanRotateCCW(int a_NumRotations) const override @@ -153,9 +155,10 @@ cPOCPieceGenerator::cPOCPieceGenerator(int a_Seed) : m_Seed(a_Seed) { // Prepare a vector of available pieces: - m_AvailPieces.push_back(new cPOCPiece(5)); - m_AvailPieces.push_back(new cPOCPiece(7)); - m_AvailPieces.push_back(new cPOCPiece(9)); + m_AvailPieces.push_back(new cPOCPiece(5, 3)); + m_AvailPieces.push_back(new cPOCPiece(7, 5)); + m_AvailPieces.push_back(new cPOCPiece(9, 5)); + m_AvailPieces.push_back(new cPOCPiece(5, 7)); // Generate the structure: cBFSPieceGenerator Gen(*this, a_Seed); -- cgit v1.2.3 From 0cce0478d846114f49c4b8fe201aee7a1bb06b22 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 10 Mar 2014 17:07:46 +0100 Subject: This allows a blockarea to have an Offset. --- src/BlockArea.cpp | 19 +++++++++++++++++++ src/BlockArea.h | 5 +++++ src/WorldStorage/SchematicFileSerializer.cpp | 23 +++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index d07ef747a..986b2ee25 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -168,6 +168,7 @@ cBlockArea::cBlockArea(void) : m_SizeX(0), m_SizeY(0), m_SizeZ(0), + m_Offset(0,0,0), m_BlockTypes(NULL), m_BlockMetas(NULL), m_BlockLight(NULL), @@ -254,6 +255,24 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) +void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) +{ + m_Offset.Set(a_OffsetX, a_OffsetY, a_OffsetZ); +} + + + + + +void cBlockArea::SetOffset(Vector3i a_Offset) +{ + m_Offset.Set(a_Offset.x, a_Offset.y, a_Offset.z); +} + + + + + void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ) { m_OriginX = a_OriginX; diff --git a/src/BlockArea.h b/src/BlockArea.h index 0703f195e..d89c9b372 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -209,6 +209,8 @@ public: void SetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockLight); void SetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockSkyLight); void SetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockSkyLight); + void SetOffset (int a_OffsetX, int a_OffsetY, int a_OffsetZ); + void SetOffset (Vector3i a_Offset); // Getters: BLOCKTYPE GetRelBlockType (int a_RelX, int a_RelY, int a_RelZ) const; @@ -219,6 +221,7 @@ public: NIBBLETYPE GetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ) const; NIBBLETYPE GetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ) const; NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ) const; + Vector3i GetOffset (void) const {return m_Offset;} void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); @@ -299,6 +302,8 @@ protected: int m_SizeY; int m_SizeZ; + Vector3i m_Offset; + BLOCKTYPE * m_BlockTypes; NIBBLETYPE * m_BlockMetas; // Each meta is stored as a separate byte for faster access NIBBLETYPE * m_BlockLight; // Each light value is stored as a separate byte for faster access diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp index b021aeb0c..0aea931eb 100644 --- a/src/WorldStorage/SchematicFileSerializer.cpp +++ b/src/WorldStorage/SchematicFileSerializer.cpp @@ -177,6 +177,25 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP a_BlockArea.Clear(); a_BlockArea.SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes); + int TOffsetX = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetX"); + int TOffsetY = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetY"); + int TOffsetZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetZ"); + + if ( + (TOffsetX < 0) || (TOffsetY < 0) || (TOffsetZ < 0) || + (a_NBT.GetType(TOffsetX) != TAG_Int) || + (a_NBT.GetType(TOffsetY) != TAG_Int) || + (a_NBT.GetType(TOffsetZ) != TAG_Int) + ) + { + // Not every schematic file has an offset, so we shoudn't give a warn message. + a_BlockArea.SetOffset(0, 0, 0); + } + else + { + a_BlockArea.SetOffset(a_NBT.GetInt(TOffsetX), a_NBT.GetInt(TOffsetY), a_NBT.GetInt(TOffsetZ)); + } + // Copy the block types and metas: int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ; if (a_NBT.GetDataLength(TBlockTypes) < NumBytes) @@ -234,6 +253,10 @@ AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockA Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); } + Writer.AddInt("WEOffsetX", a_BlockArea.m_Offset.x); + Writer.AddInt("WEOffsetY", a_BlockArea.m_Offset.y); + Writer.AddInt("WEOffsetZ", a_BlockArea.m_Offset.z); + // TODO: Save entities and block entities Writer.BeginList("Entities", TAG_Compound); Writer.EndList(); -- cgit v1.2.3 From 30353cd2285d8d2e9ec38c1015c7d45dbdb82b39 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 10:24:44 -0700 Subject: Fixed MTRand warnings --- src/MersenneTwister.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h index 2c5440f17..759b8a1ae 100644 --- a/src/MersenneTwister.h +++ b/src/MersenneTwister.h @@ -72,7 +72,7 @@ protected: uint32 state[N]; // internal state uint32 *pNext; // next value to get from state - int left; // number of values left before reload needed + uint32 left; // number of values left before reload needed // Methods public: @@ -164,7 +164,7 @@ inline void MTRand::initialize( const uint32 seed ) // only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto. uint32 *s = state; uint32 *r = state; - int i = 1; + uint32 i = 1; *s++ = seed & 0xffffffffUL; for( ; i < N; ++i ) { @@ -205,9 +205,9 @@ inline void MTRand::seed( uint32 *const bigSeed, const uint32 seedLength ) // in each element are discarded. // Just call seed() if you want to get array from /dev/urandom initialize(19650218UL); - int i = 1; + uint32 i = 1; uint32 j = 0; - int k = ( (uint32)N > seedLength ? (uint32)N : seedLength ); + uint32 k = ( (uint32)N > seedLength ? (uint32)N : seedLength ); for( ; k; --k ) { state[i] = -- cgit v1.2.3 From 8665233522da3454a77c4c40ace03d3a61150023 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 10:32:51 -0700 Subject: Fixed cast between types of different alignment in cSocket --- src/OSSupport/Socket.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp index 6afaceedf..c29e495c3 100644 --- a/src/OSSupport/Socket.cpp +++ b/src/OSSupport/Socket.cpp @@ -307,7 +307,8 @@ bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Por CloseSocket(); return false; } - addr = *((unsigned long*)hp->h_addr); + // Should be optimised to a single word copy + memcpy(&addr, hp->h_addr, hp->h_length); } sockaddr_in server; -- cgit v1.2.3 From e2e7f2184f09562753be1a474c2d7e8273b1e83b Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 10:38:21 -0700 Subject: Fixed cast to type with different alignment in BlockingTCPLink --- src/OSSupport/BlockingTCPLink.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OSSupport/BlockingTCPLink.cpp b/src/OSSupport/BlockingTCPLink.cpp index e9c00d6d4..07f48b955 100644 --- a/src/OSSupport/BlockingTCPLink.cpp +++ b/src/OSSupport/BlockingTCPLink.cpp @@ -70,7 +70,7 @@ bool cBlockingTCPLink::Connect(const char * iAddress, unsigned int iPort) } } - server.sin_addr.s_addr = *((unsigned long *)hp->h_addr); + memcpy(&server.sin_addr.s_addr,hp->h_addr, hp->h_length); server.sin_family = AF_INET; server.sin_port = htons( (unsigned short)iPort); if (connect(m_Socket, (struct sockaddr *)&server, sizeof(server))) -- cgit v1.2.3 From 7c974b27b1c334da3cd83769398fa9104a2e3253 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 10:42:52 -0700 Subject: Removed unused macro --- src/Protocol/Protocol125.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 50ebb6d43..69f4934d8 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1269,19 +1269,6 @@ int cProtocol125::ParsePacket(unsigned char a_PacketType) -#define HANDLE_PACKET_PARSE(Packet) \ - { \ - int res = Packet.Parse(m_ReceivedData); \ - if (res < 0) \ - { \ - return res; \ - } \ - } - - - - - int cProtocol125::ParseArmAnim(void) { HANDLE_PACKET_READ(ReadBEInt, int, EntityID); -- cgit v1.2.3 From 8864e7d8ca63c972793234d3c65aa534fdec06ad Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:13:07 -0700 Subject: Fixed alignment issues in Fireworks Serializer --- src/WorldStorage/FireworksSerializer.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index 1f05b470d..bdd5952ad 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -90,16 +90,16 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB if (ExplosionName == "Colors") { // Divide by four as data length returned in bytes - int DataLength = a_NBT.GetDataLength(explosiontag) / 4; + int DataLength = a_NBT.GetDataLength(explosiontag); if (DataLength == 0) { continue; } - const int * ColourData = (const int *)(a_NBT.GetData(explosiontag)); - for (int i = 0; i < DataLength; i++) + const char * ColourData = (a_NBT.GetData(explosiontag)); + for (int i = 0; i < DataLength; i += 4 /* Size of network int*/) { - a_FireworkItem.m_Colours.push_back(ntohl(ColourData[i])); + a_FireworkItem.m_Colours.push_back(GetBEInt(ColourData + i)); } } else if (ExplosionName == "FadeColors") @@ -110,10 +110,10 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB continue; } - const int * FadeColourData = (const int *)(a_NBT.GetData(explosiontag)); - for (int i = 0; i < DataLength; i++) + const char * FadeColourData = (a_NBT.GetData(explosiontag)); + for (int i = 0; i < DataLength; i += 4 /* Size of network int*/) { - a_FireworkItem.m_FadeColours.push_back(ntohl(FadeColourData[i])); + a_FireworkItem.m_FadeColours.push_back(GetBEInt(FadeColourData + i)); } } } -- cgit v1.2.3 From cff66315137e90db1292fa01640aae2e2d23b862 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:14:34 -0700 Subject: Removed unused macro from WSSCompact --- src/WorldStorage/WSSCompact.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 95477838e..1e84fb4ad 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -764,7 +764,6 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() // Cannot use cChunk::MakeIndex because it might change again????????? // For compatibility, use what we know is current - #define MAKE_2_INDEX( x, y, z ) ( y + (z * 256) + (x * 256 * 16) ) #define MAKE_3_INDEX( x, y, z ) ( x + (z * 16) + (y * 16 * 16) ) unsigned int InChunkOffset = 0; -- cgit v1.2.3 From b2733fad220243a631f9625cc84a50b70b6f43de Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 10 Mar 2014 18:23:12 +0000 Subject: Fixed compile --- src/Simulator/FireSimulator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index 31cc0b670..26712e6e6 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -1,3 +1,4 @@ + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "FireSimulator.h" @@ -341,7 +342,7 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel { continue; } - BlockType = Neighbour->GetBlockTypeMeta(X, a_RelY + gCrossCoords[i].y, Z); + BlockType = Neighbour->GetBlock(X, a_RelY + gCrossCoords[i].y, Z); if (!IsFuel(BlockType)) { -- cgit v1.2.3 From 8947f802940213d371863710e1c3ac873b2dc4b9 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:24:12 -0700 Subject: Use string.reserve to avoid the need to do inplace byteswap --- src/WorldStorage/FastNBT.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp index 8f80c3f75..f1f092e0b 100644 --- a/src/WorldStorage/FastNBT.cpp +++ b/src/WorldStorage/FastNBT.cpp @@ -506,22 +506,18 @@ void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, si { TagCommon(a_Name, TAG_IntArray); Int32 len = htonl(a_NumElements); + size_t cap = m_Result.capacity(); + size_t size = m_Result.length(); + if ((cap - size) < (4 + a_NumElements * 4)) + { + m_Result.reserve(size +4 + a_NumElements * 4); + } m_Result.append((const char *)&len, 4); -#if defined(ANDROID_NDK) - // Android has alignment issues - cannot byteswap (htonl) an int that is not 32-bit-aligned, which happens in the regular version for (size_t i = 0; i < a_NumElements; i++) { int Element = htonl(a_Value[i]); m_Result.append((const char *)&Element, 4); } -#else - int * Elements = (int *)(m_Result.data() + m_Result.size()); - m_Result.append(a_NumElements * 4, (char)0); - for (size_t i = 0; i < a_NumElements; i++) - { - Elements[i] = htonl(a_Value[i]); - } -#endif } -- cgit v1.2.3 From 2eca30aebc9a4f7307c31a75ca23e19fa3f1a4a7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:34:20 -0700 Subject: Removed Some unnessicary macros --- src/ClientHandle.cpp | 13 ------------- src/LightingThread.cpp | 6 ------ src/WorldStorage/WSSAnvil.cpp | 4 ++-- 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 94c9f5f71..df728e83b 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -36,19 +36,6 @@ - - -#define AddPistonDir(x, y, z, dir, amount) switch (dir) { case 0: (y)-=(amount); break; case 1: (y)+=(amount); break;\ - case 2: (z)-=(amount); break; case 3: (z)+=(amount); break;\ - case 4: (x)-=(amount); break; case 5: (x)+=(amount); break; } - - - - - -/** If the number of queued outgoing packets reaches this, the client will be kicked */ -#define MAX_OUTGOING_PACKETS 2000 - /** Maximum number of explosions to send this tick, server will start dropping if exceeded */ #define MAX_EXPLOSIONS_PER_TICK 20 diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index 44dadb8a9..302473d71 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -13,12 +13,6 @@ -/// If more than this many chunks are in the queue, a warning is printed to the log -#define WARN_ON_QUEUE_SIZE 800 - - - - /// Chunk data callback that takes the chunk data and puts them into cLightingThread's m_BlockTypes[] / m_HeightMap[]: class cReader : diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index eb159f28d..070738164 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -507,10 +507,10 @@ cChunkDef::BiomeMap * cWSSAnvil::LoadBiomeMapFromNBT(cChunkDef::BiomeMap * a_Bio // The biomes stored don't match in size return NULL; } - const int * BiomeData = (const int *)(a_NBT.GetData(a_TagIdx)); + const char * BiomeData = (a_NBT.GetData(a_TagIdx)); for (size_t i = 0; i < ARRAYCOUNT(*a_BiomeMap); i++) { - (*a_BiomeMap)[i] = (EMCSBiome)(ntohl(BiomeData[i])); + (*a_BiomeMap)[i] = (EMCSBiome)(GetBEInt(&BiomeData[i * 4])); if ((*a_BiomeMap)[i] == 0xff) { // Unassigned biomes -- cgit v1.2.3 From 462829e23d8d3404e58ffc64fd19cf39e9be218f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 10 Mar 2014 18:35:02 +0000 Subject: Shrapnel now configurable --- src/ChunkMap.cpp | 2 +- src/World.cpp | 3 +-- src/World.h | 6 ++++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index b13337b44..e750ad731 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1832,7 +1832,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc. m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z); } - else if (m_World->GetTickRandomNumber(100) < 20) // 20% chance of flinging stuff around + else if (m_World->IsTNTShrapnelEnabled() && (m_World->GetTickRandomNumber(100) < 20)) // 20% chance of flinging stuff around { if (!cBlockInfo::FullyOccupiesVoxel(area.GetBlockType(bx + x, by + y, bz + z))) { diff --git a/src/World.cpp b/src/World.cpp index d6b88f187..89d0cf454 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -250,8 +250,6 @@ cWorld::cWorld(const AString & a_WorldName) : m_SkyDarkness(0), m_Weather(eWeather_Sunny), m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :) - m_bCommandBlocksEnabled(false), - m_bUseChatPrefixes(true), m_Scoreboard(this), m_MapManager(this), m_GeneratorCallbacks(*this), @@ -554,6 +552,7 @@ void cWorld::Start(void) m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false); m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true); m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true); + m_bTNTSpawnsShrapnel = IniFile.GetValueSetB("Physics", "IsTNTShrapnelEnabled", true); m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false); m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true); m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true); diff --git a/src/World.h b/src/World.h index 4b74f7aba..d7d5b5059 100644 --- a/src/World.h +++ b/src/World.h @@ -590,6 +590,9 @@ public: bool AreCommandBlocksEnabled(void) const { return m_bCommandBlocksEnabled; } void SetCommandBlocksEnabled(bool a_Flag) { m_bCommandBlocksEnabled = a_Flag; } + bool IsTNTShrapnelEnabled(void) const { return m_bTNTSpawnsShrapnel; } + void SetTNTShrapnelEnabled(bool a_Flag) { m_bTNTSpawnsShrapnel = a_Flag; } + bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; } void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; } @@ -847,6 +850,9 @@ private: /** Whether prefixes such as [INFO] are prepended to SendMessageXXX() / BroadcastChatXXX() functions */ bool m_bUseChatPrefixes; + + /** Whether TNT explosions, done via cWorld::DoExplosionAt(), should project random affected blocks as FallingBlock entities */ + bool m_bTNTSpawnsShrapnel; cChunkGenerator m_Generator; -- cgit v1.2.3 From b78c729880705c1bf28f266b087046c4eaed8317 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:56:23 -0700 Subject: Fixed Alignment issue in ByteBuffer --- src/ByteBuffer.cpp | 2 +- src/StringUtils.cpp | 7 ++----- src/StringUtils.h | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 96a135562..a7553786e 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -767,7 +767,7 @@ bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars) { return false; } - RawBEToUTF8((short *)(RawData.data()), a_NumChars, a_String); + RawBEToUTF8((RawData.data()), a_NumChars, a_String); return true; } diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 3fe75d611..3e047fb5c 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -288,13 +288,13 @@ void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & // Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8 -AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8) +AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8) { a_UTF8.clear(); a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size for (int i = 0; i < a_NumShorts; i++) { - int c = ntohs(*(a_RawData + i)); + int c = GetBEShort(a_RawData + i*2); if (c < 0x80) { a_UTF8.push_back((char)c); @@ -364,10 +364,7 @@ Notice from the original file: #define UNI_MAX_BMP 0x0000FFFF #define UNI_MAX_UTF16 0x0010FFFF -#define UNI_MAX_UTF32 0x7FFFFFFF -#define UNI_MAX_LEGAL_UTF32 0x0010FFFF #define UNI_SUR_HIGH_START 0xD800 -#define UNI_SUR_HIGH_END 0xDBFF #define UNI_SUR_LOW_START 0xDC00 #define UNI_SUR_LOW_END 0xDFFF diff --git a/src/StringUtils.h b/src/StringUtils.h index dfbfc2a75..b64108409 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -58,7 +58,7 @@ extern unsigned int RateCompareString(const AString & s1, const AString & s2 ); extern void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith); // tolua_export /// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8 -extern AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8); +extern AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8); /// Converts a UTF-8 string into a UTF-16 BE string, packing that back into AString; return a ref to a_UTF16 extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16); -- cgit v1.2.3 From 693734bd8307f3089368cb3aca662641f92f2e71 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:57:04 -0700 Subject: Enable error on cast-align and unused macros --- SetFlags.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index a9657fff1..d9308f603 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -197,7 +197,6 @@ macro(set_exe_flags) add_flags_cxx("-Wno-error=missing-prototypes -Wno-error=non-virtual-dtor") add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") - add_flags_cxx("-Wno-error=cast-align -Wno-error=unused-macros") add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef") add_flags_cxx("-Wno-error=format-nonliteral") -- cgit v1.2.3 From bc556e7f00ee28198b5ba3e46c1c06caab8fc37b Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 12:21:18 -0700 Subject: Fixed Issues in ProtoProxy --- Tools/ProtoProxy/Connection.cpp | 16 ++++++++-------- Tools/ProtoProxy/Connection.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index 91d2fc42f..be908f303 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -131,8 +131,6 @@ } \ } - -#define MAX_ENC_LEN 1024 @@ -473,14 +471,14 @@ bool cConnection::SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a -bool cConnection::SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, int a_Size, const char * a_Peer) +bool cConnection::SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer) { DataLog(a_Data, a_Size, "Encrypting %d bytes to %s", a_Size, a_Peer); const Byte * Data = (const Byte *)a_Data; while (a_Size > 0) { Byte Buffer[64 KiB]; - int NumBytes = (a_Size > sizeof(Buffer)) ? sizeof(Buffer) : a_Size; + size_t NumBytes = (a_Size > sizeof(Buffer)) ? sizeof(Buffer) : a_Size; a_Encryptor.ProcessData(Buffer, Data, NumBytes); bool res = SendData(a_Socket, (const char *)Buffer, NumBytes, a_Peer); if (!res) @@ -2263,7 +2261,9 @@ bool cConnection::HandleServerSpawnObjectVehicle(void) HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Yaw); HANDLE_SERVER_PACKET_READ(ReadBEInt, int, DataIndicator); AString ExtraData; - short VelocityX, VelocityY, VelocityZ; + short VelocityX = 0; + short VelocityY = 0; + short VelocityZ = 0; if (DataIndicator != 0) { HANDLE_SERVER_PACKET_READ(ReadBEShort, short, SpeedX); @@ -2697,7 +2697,7 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata) a_Metadata.push_back(x); while (x != 0x7f) { - int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index + //int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index int Type = ((unsigned)((unsigned char)x)) >> 5; // Upper 3 bits = type int Length = 0; switch (Type) @@ -2772,7 +2772,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) { int Index = ((unsigned)((unsigned char)a_Metadata[pos])) & 0x1f; // Lower 5 bits = index int Type = ((unsigned)((unsigned char)a_Metadata[pos])) >> 5; // Upper 3 bits = type - int Length = 0; + //int Length = 0; switch (Type) { case 0: @@ -2827,7 +2827,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) ASSERT(!"Cannot parse item description from metadata"); return; } - int After = bb.GetReadableSpace(); + //int After = bb.GetReadableSpace(); int BytesConsumed = BytesLeft - bb.GetReadableSpace(); Log("%sslot[%d] = %s (%d bytes)", Indent.c_str(), Index, ItemDesc.c_str(), BytesConsumed); diff --git a/Tools/ProtoProxy/Connection.h b/Tools/ProtoProxy/Connection.h index 5e4f8cd7b..70b759d0f 100644 --- a/Tools/ProtoProxy/Connection.h +++ b/Tools/ProtoProxy/Connection.h @@ -109,7 +109,7 @@ protected: bool SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a_Peer); /// Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false - bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, int a_Size, const char * a_Peer); + bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer); /// Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer); -- cgit v1.2.3 From bb28f0d1e3fa685791433220d0bf96bda6d4937e Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 12:36:01 -0700 Subject: Fixed assert --- src/ByteBuffer.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index a7553786e..ae4e72737 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -46,6 +46,9 @@ #ifdef SELF_TEST +#define assert_test(x) ( !!(x) || \ + LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), abort(1)) + /// Self-test of the VarInt-reading and writing code static class cByteBufferSelfTest { @@ -62,11 +65,11 @@ public: cByteBuffer buf(50); buf.Write("\x05\xac\x02\x00", 4); UInt32 v1; - assert(buf.ReadVarInt(v1) && (v1 == 5)); + assert_test(buf.ReadVarInt(v1) && (v1 == 5)); UInt32 v2; - assert(buf.ReadVarInt(v2) && (v2 == 300)); + assert_test(buf.ReadVarInt(v2) && (v2 == 300)); UInt32 v3; - assert(buf.ReadVarInt(v3) && (v3 == 0)); + assert_test(buf.ReadVarInt(v3) && (v3 == 0)); } void TestWrite(void) @@ -77,8 +80,8 @@ public: buf.WriteVarInt(0); AString All; buf.ReadAll(All); - assert(All.size() == 4); - assert(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0); + assert_test(All.size() == 4); + assert_test(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0); } void TestWrap(void) @@ -87,17 +90,17 @@ public: for (int i = 0; i < 1000; i++) { size_t FreeSpace = buf.GetFreeSpace(); - assert(buf.GetReadableSpace() == 0); - assert(FreeSpace > 0); - assert(buf.Write("a", 1)); - assert(buf.CanReadBytes(1)); - assert(buf.GetReadableSpace() == 1); + assert_test(buf.GetReadableSpace() == 0); + assert_test(FreeSpace > 0); + assert_test(buf.Write("a", 1)); + assert_test(buf.CanReadBytes(1)); + assert_test(buf.GetReadableSpace() == 1); unsigned char v = 0; - assert(buf.ReadByte(v)); - assert(v == 'a'); - assert(buf.GetReadableSpace() == 0); + assert_test(buf.ReadByte(v)); + assert_test(v == 'a'); + assert_test(buf.GetReadableSpace() == 0); buf.CommitRead(); - assert(buf.GetFreeSpace() == FreeSpace); // We're back to normal + assert_test(buf.GetFreeSpace() == FreeSpace); // We're back to normal } } -- cgit v1.2.3 From 4ed68916d8c0ac4b5384bbaf83088b52ca2d47d9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 10 Mar 2014 20:52:53 +0100 Subject: Revert "Fixed some warnings" This reverts commit 4cb0b82d1df560ad32c92eede91f466c75a87c87. --- src/ChunkDef.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 63431f211..7be2fa2df 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -65,8 +65,8 @@ public: enum { // Chunk dimensions: - Width = 16U, - Height = 256U, + Width = 16, + Height = 256, NumBlocks = Width * Height * Width, /// If the data is collected into a single buffer, how large it needs to be: @@ -132,7 +132,7 @@ public: } - inline static unsigned int MakeIndexNoCheck(unsigned int x, unsigned int y, unsigned int z) + inline static unsigned int MakeIndexNoCheck(int x, int y, int z) { #if AXIS_ORDER == AXIS_ORDER_XZY // For some reason, NOT using the Horner schema is faster. Weird. @@ -240,7 +240,7 @@ public: { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { - unsigned int Index = MakeIndexNoCheck(x, y, z); + int Index = MakeIndexNoCheck(x, y, z); return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); @@ -256,7 +256,7 @@ public: return; } a_Buffer[a_BlockIdx / 2] = ( - (a_Buffer[a_BlockIdx / 2] & (0xf0 >> (static_cast(a_BlockIdx & 1) * 4))) | // The untouched nibble + (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set ); } @@ -282,13 +282,13 @@ public: } - inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos ) + inline static char GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos ) { return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z ); } - inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value ) + inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, char a_Value ) { SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value ); } @@ -306,9 +306,6 @@ The virtual methods are called in the same order as they're declared here. class cChunkDataCallback abstract { public: - - virtual ~cChunkDataCallback() {} - /** Called before any other callbacks to inform of the current coords (only in processes where multiple chunks can be processed, such as cWorld::ForEachChunkInRect()). If false is returned, the chunk is skipped. -- cgit v1.2.3 From e9e2852ce1d7b3cdbbcc115d63f1d4d0ab25457f Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 13:12:43 -0700 Subject: Fixed test asserts --- src/ByteBuffer.cpp | 3 --- src/CompositeChat.cpp | 62 ++++++++++++++++++++++++------------------------- src/CraftingRecipes.cpp | 2 ++ src/Globals.h | 7 +++--- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index ae4e72737..9d97d8614 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -46,9 +46,6 @@ #ifdef SELF_TEST -#define assert_test(x) ( !!(x) || \ - LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), abort(1)) - /// Self-test of the VarInt-reading and writing code static class cByteBufferSelfTest { diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index 3eec35657..19ed30d78 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -32,15 +32,15 @@ public: cCompositeChat Msg; Msg.ParseText("Testing @2color codes and http://links parser"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 4); - assert(Parts[0]->m_PartType == cCompositeChat::ptText); - assert(Parts[1]->m_PartType == cCompositeChat::ptText); - assert(Parts[2]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[3]->m_PartType == cCompositeChat::ptText); - assert(Parts[0]->m_Style == ""); - assert(Parts[1]->m_Style == "@2"); - assert(Parts[2]->m_Style == "@2"); - assert(Parts[3]->m_Style == "@2"); + assert_test(Parts.size() == 4); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[3]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[0]->m_Style == ""); + assert_test(Parts[1]->m_Style == "@2"); + assert_test(Parts[2]->m_Style == "@2"); + assert_test(Parts[3]->m_Style == "@2"); } void TestParser2(void) @@ -48,15 +48,15 @@ public: cCompositeChat Msg; Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 4); - assert(Parts[0]->m_PartType == cCompositeChat::ptText); - assert(Parts[1]->m_PartType == cCompositeChat::ptText); - assert(Parts[2]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[3]->m_PartType == cCompositeChat::ptText); - assert(Parts[0]->m_Style == "@3"); - assert(Parts[1]->m_Style == "@5"); - assert(Parts[2]->m_Style == "@5"); - assert(Parts[3]->m_Style == "@5"); + assert_test(Parts.size() == 4); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[3]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[0]->m_Style == "@3"); + assert_test(Parts[1]->m_Style == "@5"); + assert_test(Parts[2]->m_Style == "@5"); + assert_test(Parts[3]->m_Style == "@5"); } void TestParser3(void) @@ -64,11 +64,11 @@ public: cCompositeChat Msg; Msg.ParseText("http://links.starting the text"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 2); - assert(Parts[0]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[1]->m_PartType == cCompositeChat::ptText); - assert(Parts[0]->m_Style == ""); - assert(Parts[1]->m_Style == ""); + assert_test(Parts.size() == 2); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[0]->m_Style == ""); + assert_test(Parts[1]->m_Style == ""); } void TestParser4(void) @@ -76,11 +76,11 @@ public: cCompositeChat Msg; Msg.ParseText("links finishing the text: http://some.server"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 2); - assert(Parts[0]->m_PartType == cCompositeChat::ptText); - assert(Parts[1]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[0]->m_Style == ""); - assert(Parts[1]->m_Style == ""); + assert_test(Parts.size() == 2); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[0]->m_Style == ""); + assert_test(Parts[1]->m_Style == ""); } void TestParser5(void) @@ -88,9 +88,9 @@ public: cCompositeChat Msg; Msg.ParseText("http://only.links"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 1); - assert(Parts[0]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[0]->m_Style == ""); + assert_test(Parts.size() == 1); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[0]->m_Style == ""); } } gTest; diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index 868182394..be9f45caa 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -192,7 +192,9 @@ void cCraftingGrid::Dump(void) { for (int y = 0; y < m_Height; y++) for (int x = 0; x < m_Width; x++) { + #ifdef _DEBUG int idx = x + m_Width * y; + #endif LOGD("Slot (%d, %d): Type %d, health %d, count %d", x, y, m_Items[idx].m_ItemType, m_Items[idx].m_ItemDamage, m_Items[idx].m_ItemCount ); diff --git a/src/Globals.h b/src/Globals.h index b046e6db0..2cd160677 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -234,9 +234,10 @@ template class SizeChecker; // Pretty much the same as ASSERT() but stays in Release builds #define VERIFY( x ) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), exit(1), 0 ) ) - - - +// Same as assert but in all Self test builds +#ifdef SELF_TEST +#define assert_test(x) ( !!(x) || (assert(0), exit(1), 0)) +#endif /// A generic interface used mainly in ForEach() functions template class cItemCallback -- cgit v1.2.3 From 26d7ed661225ed092bd79c55e16134aef770ee3b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 10 Mar 2014 21:16:13 +0100 Subject: Removed debugging output. Kept it commented-out for later revisions, if needed. --- src/Generating/POCPieceGenerator.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Generating/POCPieceGenerator.cpp b/src/Generating/POCPieceGenerator.cpp index d7619b8ff..9ed4b565e 100644 --- a/src/Generating/POCPieceGenerator.cpp +++ b/src/Generating/POCPieceGenerator.cpp @@ -2,7 +2,7 @@ // POCPieceGenerator.cpp // Implements the cPOCPieceGenerator class representing a Proof-Of_Concept structure generator using the cPieceGenerator technique -// The generator generates a maze of rooms at {0, 100, 0} +// The generator generates a maze of rooms at {0, 50, 0} #include "Globals.h" #include "POCPieceGenerator.h" @@ -131,6 +131,7 @@ protected: +/* static void DebugPieces(const cPlacedPieces & a_Pieces) { size_t idx = 0; @@ -143,6 +144,7 @@ static void DebugPieces(const cPlacedPieces & a_Pieces) ); } // for itr - a_Pieces[] } +//*/ -- cgit v1.2.3 From 98e15a34a416c31d4689836f4f38161f1270513c Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 13:18:53 -0700 Subject: Fixed xofts issues --- Tools/ProtoProxy/Connection.cpp | 2 +- src/ChunkDef.h | 26 ++++++++------------------ src/StringUtils.cpp | 2 +- src/WorldStorage/FastNBT.cpp | 2 +- src/WorldStorage/FireworksSerializer.cpp | 4 ++++ 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index be908f303..73688d310 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -2697,7 +2697,7 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata) a_Metadata.push_back(x); while (x != 0x7f) { - //int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index + // int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index int Type = ((unsigned)((unsigned char)x)) >> 5; // Upper 3 bits = type int Length = 0; switch (Type) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index a5059348c..fcda64f5c 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -124,9 +124,7 @@ public: (z < Width) && (z > -1) ) { - return MakeIndexNoCheck(static_cast(x), - static_cast(y), - static_cast(z)); + return MakeIndexNoCheck(x, y, z); } LOGERROR("cChunkDef::MakeIndex(): coords out of range: {%d, %d, %d}; returning fake index 0", x, y, z); ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!"); @@ -134,13 +132,13 @@ public: } - inline static unsigned int MakeIndexNoCheck(unsigned int x, unsigned int y, unsigned int z) + inline static unsigned int MakeIndexNoCheck(int x, int y, int z) { #if AXIS_ORDER == AXIS_ORDER_XZY // For some reason, NOT using the Horner schema is faster. Weird. - return x + (z * cChunkDef::Width) + (y * cChunkDef::Width * cChunkDef::Width); // 1.2 is XZY + return static_cast(x + (z * cChunkDef::Width) + (y * cChunkDef::Width * cChunkDef::Width)); // 1.2 is XZY #elif AXIS_ORDER == AXIS_ORDER_YZX - return y + (z * cChunkDef::Width) + (x * cChunkDef::Height * cChunkDef::Width); // 1.1 is YZX + return static_cast(y + (z * cChunkDef::Width) + (x * cChunkDef::Height * cChunkDef::Width)); // 1.1 is YZX #endif } @@ -168,9 +166,7 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - a_BlockTypes[MakeIndexNoCheck(static_cast(a_X), - static_cast(a_Y), - static_cast(a_Z))] = a_Type; + a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type; } @@ -186,9 +182,7 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - return a_BlockTypes[MakeIndexNoCheck(static_cast(a_X), - static_cast(a_Y), - static_cast(a_Z))]; + return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)]; } @@ -246,9 +240,7 @@ public: { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { - unsigned int Index = MakeIndexNoCheck(static_cast(x), - static_cast(y), - static_cast(z)); + unsigned int Index = MakeIndexNoCheck(x, y, z); return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); @@ -282,9 +274,7 @@ public: return; } - unsigned int Index = MakeIndexNoCheck(static_cast(x), - static_cast(y), - static_cast(z)); + unsigned int Index = MakeIndexNoCheck(x, y, z); a_Buffer[Index / 2] = static_cast( (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 3e047fb5c..3f9275798 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -294,7 +294,7 @@ AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8) a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size for (int i = 0; i < a_NumShorts; i++) { - int c = GetBEShort(a_RawData + i*2); + int c = GetBEShort(&a_RawData[i * 2]); if (c < 0x80) { a_UTF8.push_back((char)c); diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp index f1f092e0b..be25fd1a4 100644 --- a/src/WorldStorage/FastNBT.cpp +++ b/src/WorldStorage/FastNBT.cpp @@ -510,7 +510,7 @@ void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, si size_t size = m_Result.length(); if ((cap - size) < (4 + a_NumElements * 4)) { - m_Result.reserve(size +4 + a_NumElements * 4); + m_Result.reserve(size + 4 + (a_NumElements * 4)); } m_Result.append((const char *)&len, 4); for (size_t i = 0; i < a_NumElements; i++) diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index bdd5952ad..3c97ae0a2 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -91,6 +91,8 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB { // Divide by four as data length returned in bytes int DataLength = a_NBT.GetDataLength(explosiontag); + // round to the next highest multiple of four + DataLength -= DataLength % 4; if (DataLength == 0) { continue; @@ -105,6 +107,8 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB else if (ExplosionName == "FadeColors") { int DataLength = a_NBT.GetDataLength(explosiontag) / 4; + // round to the next highest multiple of four + DataLength -= DataLength % 4; if (DataLength == 0) { continue; -- cgit v1.2.3 From e4c7aac1cce39822a39da6bde28ac2066c9c0026 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 13:52:13 -0700 Subject: Prepended Travis to env vars --- .travis.yml | 8 ++++---- CMakeLists.txt | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 14dad4df4..0ab25ae3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,10 @@ compiler: script: cmake . -DBUILD_TOOLS=1 -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | $MCSERVER_PATH) env: - - MCSERVER_BUILD_TYPE=RELEASE MCSERVER_PATH=./MCServer - - MCSERVER_BUILD_TYPE=DEBUG MCSERVER_PATH=./MCServer_debug - - MCSERVER_BUILD_TYPE=RELEASE MCSERVER_FORCE32=1 MCSERVER_PATH=./MCServer - - MCSERVER_BUILD_TYPE=DEBUG MCSERVER_FORCE32=1 MCSERVER_PATH=./MCServer_debug + - TRAVIS_MCSERVER_BUILD_TYPE=RELEASE MCSERVER_PATH=./MCServer + - TRAVIS_MCSERVER_BUILD_TYPE=DEBUG MCSERVER_PATH=./MCServer_debug + - TRAVIS_MCSERVER_BUILD_TYPE=RELEASE TRAVIS_MCSERVER_FORCE32=1 MCSERVER_PATH=./MCServer + - TRAVIS_MCSERVER_BUILD_TYPE=DEBUG TRAVIS_MCSERVER_FORCE32=1 MCSERVER_PATH=./MCServer_debug # Notification Settings notifications: diff --git a/CMakeLists.txt b/CMakeLists.txt index e7e8daf7d..9a860920c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,13 +3,15 @@ cmake_minimum_required (VERSION 2.6) # Without this, the MSVC variable isn't defined for MSVC builds ( http://www.cmake.org/pipermail/cmake/2011-November/047130.html ) enable_language(CXX C) -if(DEFINED ENV{MCSERVER_BUILD_TYPE}) - message("Setting build type to $ENV{MCSERVER_BUILD_TYPE}") - set(CMAKE_BUILD_TYPE $ENV{MCSERVER_BUILD_TYPE}) +# These env variables are used for configuring Travis CI builds. +# See https://github.com/mc-server/MCServer/pull/767 +if(DEFINED ENV{TRAVIS_MCSERVER_BUILD_TYPE}) + message("Setting build type to $ENV{TRAVIS_MCSERVER_BUILD_TYPE}") + set(CMAKE_BUILD_TYPE $ENV{TRAVIS_MCSERVER_BUILD_TYPE}) endif() -if(DEFINED ENV{MCSERVER_FORCE32}) - set(FORCE32 $ENV{MCSERVER_FORCE32}) +if(DEFINED ENV{TRAVIS_MCSERVER_FORCE32}) + set(FORCE32 $ENV{TRAVIS_MCSERVER_FORCE32}) endif() # This has to be done before any flags have been set up. -- cgit v1.2.3 From e213e5f9fcb3681a5f383546e17b9800d4a4804a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 18:23:21 +0100 Subject: Renamed m_Offset to m_WEOffset --- src/BlockArea.cpp | 6 +++--- src/BlockArea.h | 5 +++-- src/WorldStorage/SchematicFileSerializer.cpp | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index dfdf998df..983dbe46b 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -168,7 +168,7 @@ cBlockArea::cBlockArea(void) : m_SizeX(0), m_SizeY(0), m_SizeZ(0), - m_Offset(0,0,0), + m_WEOffset(0, 0, 0), m_BlockTypes(NULL), m_BlockMetas(NULL), m_BlockLight(NULL), @@ -257,7 +257,7 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) { - m_Offset.Set(a_OffsetX, a_OffsetY, a_OffsetZ); + m_WEOffset.Set(a_OffsetX, a_OffsetY, a_OffsetZ); } @@ -266,7 +266,7 @@ void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) void cBlockArea::SetOffset(const Vector3i & a_Offset) { - m_Offset.Set(a_Offset.x, a_Offset.y, a_Offset.z); + m_WEOffset.Set(a_Offset.x, a_Offset.y, a_Offset.z); } diff --git a/src/BlockArea.h b/src/BlockArea.h index 75b8db3a6..76424d02f 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -221,7 +221,7 @@ public: NIBBLETYPE GetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ) const; NIBBLETYPE GetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ) const; NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ) const; - const Vector3i & GetOffset (void) const {return m_Offset;} + const Vector3i & GetOffset (void) const {return m_WEOffset;} void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); @@ -302,7 +302,8 @@ protected: int m_SizeY; int m_SizeZ; - Vector3i m_Offset; + // Used for schematics that are created by the WorldEdit plugin. The offset is used for player-relative pasting. + Vector3i m_WEOffset; BLOCKTYPE * m_BlockTypes; NIBBLETYPE * m_BlockMetas; // Each meta is stored as a separate byte for faster access diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp index 0aea931eb..b899540df 100644 --- a/src/WorldStorage/SchematicFileSerializer.cpp +++ b/src/WorldStorage/SchematicFileSerializer.cpp @@ -253,9 +253,9 @@ AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockA Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); } - Writer.AddInt("WEOffsetX", a_BlockArea.m_Offset.x); - Writer.AddInt("WEOffsetY", a_BlockArea.m_Offset.y); - Writer.AddInt("WEOffsetZ", a_BlockArea.m_Offset.z); + Writer.AddInt("WEOffsetX", a_BlockArea.m_WEOffset.x); + Writer.AddInt("WEOffsetY", a_BlockArea.m_WEOffset.y); + Writer.AddInt("WEOffsetZ", a_BlockArea.m_WEOffset.z); // TODO: Save entities and block entities Writer.BeginList("Entities", TAG_Compound); -- cgit v1.2.3 From fa4ff28bc04f73a2af98a0f00e536e2b5293cbf1 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 19:38:56 +0100 Subject: Documented the functions. --- MCServer/Plugins/APIDump/APIDesc.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 1e572492b..54b2372f8 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -115,6 +115,7 @@ g_APIDesc = GetBlockType = { Params = "BlockX, BlockY, BlockZ", Return = "BLOCKTYPE", Notes = "Returns the block type at the specified absolute coords" }, GetBlockTypeMeta = { Params = "BlockX, BlockY, BlockZ", Return = "BLOCKTYPE, NIBBLETYPE", Notes = "Returns the block type and meta at the specified absolute coords" }, GetDataTypes = { Params = "", Return = "number", Notes = "Returns the mask of datatypes that the objectis currently holding" }, + GetOffset = { Params = "", Returns = "Vector3i", Notes = "Returns the offset wich are sometimes saved in schematic files if created by WorldEdit (Bukkit) for player-relative pasting. The default is 0, 0, 0"}, GetOrigin = { Params = "", Return = "OriginX, OriginY, OriginZ", Notes = "Returns the origin coords of where the area was read from." }, GetOriginX = { Params = "", Return = "number", Notes = "Returns the origin x-coord" }, GetOriginY = { Params = "", Return = "number", Notes = "Returns the origin y-coord" }, @@ -168,6 +169,11 @@ g_APIDesc = SetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified absolute coords" }, SetBlockType = { Params = "BlockX, BlockY, BlockZ, BlockType", Return = "", Notes = "Sets the block type at the specified absolute coords" }, SetBlockTypeMeta = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block type and meta at the specified absolute coords" }, + SetOffset = + { + { Params = "{{Vector3i|Offset}}", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, + { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, + } SetOrigin = { { Params = "{{Vector3i|Origin}}", Return = "", Notes = "Resets the origin for the absolute coords. Only affects how absolute coords are translated into relative coords." }, -- cgit v1.2.3 From 7d1e32a28b167faa6b17235283822da0cc7b2c13 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 19:45:16 +0100 Subject: Fixed APIDump --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 54b2372f8..5d4b89425 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -173,7 +173,7 @@ g_APIDesc = { { Params = "{{Vector3i|Offset}}", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, - } + }, SetOrigin = { { Params = "{{Vector3i|Origin}}", Return = "", Notes = "Resets the origin for the absolute coords. Only affects how absolute coords are translated into relative coords." }, -- cgit v1.2.3 From 950614da7e700b8847f0dcc0bac9d76367801a3f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 07:46:14 +0100 Subject: Renamed cBlockArea Offset to WEOffset. Even in getters / setters. --- src/BlockArea.cpp | 4 ++-- src/BlockArea.h | 9 +++++---- src/WorldStorage/SchematicFileSerializer.cpp | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 983dbe46b..406e18a3b 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -255,7 +255,7 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) -void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) +void cBlockArea::SetWEOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) { m_WEOffset.Set(a_OffsetX, a_OffsetY, a_OffsetZ); } @@ -264,7 +264,7 @@ void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) -void cBlockArea::SetOffset(const Vector3i & a_Offset) +void cBlockArea::SetWEOffset(const Vector3i & a_Offset) { m_WEOffset.Set(a_Offset.x, a_Offset.y, a_Offset.z); } diff --git a/src/BlockArea.h b/src/BlockArea.h index 76424d02f..31918ce8c 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -209,8 +209,8 @@ public: void SetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockLight); void SetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockSkyLight); void SetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockSkyLight); - void SetOffset (int a_OffsetX, int a_OffsetY, int a_OffsetZ); - void SetOffset (const Vector3i & a_Offset); + void SetWEOffset (int a_OffsetX, int a_OffsetY, int a_OffsetZ); + void SetWEOffset (const Vector3i & a_Offset); // Getters: BLOCKTYPE GetRelBlockType (int a_RelX, int a_RelY, int a_RelZ) const; @@ -221,7 +221,7 @@ public: NIBBLETYPE GetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ) const; NIBBLETYPE GetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ) const; NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ) const; - const Vector3i & GetOffset (void) const {return m_WEOffset;} + const Vector3i & GetWEOffset (void) const {return m_WEOffset;} void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); @@ -302,7 +302,8 @@ protected: int m_SizeY; int m_SizeZ; - // Used for schematics that are created by the WorldEdit plugin. The offset is used for player-relative pasting. + /** An extra data value sometimes stored in the .schematic file. Used mainly by the WorldEdit plugin. + cBlockArea doesn't use this value in any way. */ Vector3i m_WEOffset; BLOCKTYPE * m_BlockTypes; diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp index b899540df..ef67fdb13 100644 --- a/src/WorldStorage/SchematicFileSerializer.cpp +++ b/src/WorldStorage/SchematicFileSerializer.cpp @@ -189,11 +189,11 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP ) { // Not every schematic file has an offset, so we shoudn't give a warn message. - a_BlockArea.SetOffset(0, 0, 0); + a_BlockArea.SetWEOffset(0, 0, 0); } else { - a_BlockArea.SetOffset(a_NBT.GetInt(TOffsetX), a_NBT.GetInt(TOffsetY), a_NBT.GetInt(TOffsetZ)); + a_BlockArea.SetWEOffset(a_NBT.GetInt(TOffsetX), a_NBT.GetInt(TOffsetY), a_NBT.GetInt(TOffsetZ)); } // Copy the block types and metas: -- cgit v1.2.3 From 15c70a1f68ac176993b647cb0860cd190b7631d0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 07:53:25 +0100 Subject: APIDump: Updated WEOffset-related docs. --- MCServer/Plugins/APIDump/APIDesc.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 086791006..18b90adbf 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -114,8 +114,7 @@ g_APIDesc = GetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ", Return = "NIBBLETYPE", Notes = "Returns the skylight at the specified absolute coords" }, GetBlockType = { Params = "BlockX, BlockY, BlockZ", Return = "BLOCKTYPE", Notes = "Returns the block type at the specified absolute coords" }, GetBlockTypeMeta = { Params = "BlockX, BlockY, BlockZ", Return = "BLOCKTYPE, NIBBLETYPE", Notes = "Returns the block type and meta at the specified absolute coords" }, - GetDataTypes = { Params = "", Return = "number", Notes = "Returns the mask of datatypes that the objectis currently holding" }, - GetOffset = { Params = "", Returns = "Vector3i", Notes = "Returns the offset wich are sometimes saved in schematic files if created by WorldEdit (Bukkit) for player-relative pasting. The default is 0, 0, 0"}, + GetDataTypes = { Params = "", Return = "number", Notes = "Returns the mask of datatypes that the object is currently holding" }, GetOrigin = { Params = "", Return = "OriginX, OriginY, OriginZ", Notes = "Returns the origin coords of where the area was read from." }, GetOriginX = { Params = "", Return = "number", Notes = "Returns the origin x-coord" }, GetOriginY = { Params = "", Return = "number", Notes = "Returns the origin y-coord" }, @@ -130,6 +129,7 @@ g_APIDesc = GetSizeY = { Params = "", Return = "number", Notes = "Returns the size of the held data in the y-axis" }, GetSizeZ = { Params = "", Return = "number", Notes = "Returns the size of the held data in the z-axis" }, GetVolume = { Params = "", Return = "number", Notes = "Returns the volume of the area - the total number of blocks stored within." }, + GetWEOffset = { Params = "", Return = "{{Vector3i}}", Notes = "Returns the WE offset, a data value sometimes stored in the schematic files. MCServer doesn't use this value, but provides access to it using this method. The default is {0, 0, 0}."}, HasBlockLights = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include blocklight" }, HasBlockMetas = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include block metas" }, HasBlockSkyLights = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include skylight" }, @@ -169,11 +169,6 @@ g_APIDesc = SetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified absolute coords" }, SetBlockType = { Params = "BlockX, BlockY, BlockZ, BlockType", Return = "", Notes = "Sets the block type at the specified absolute coords" }, SetBlockTypeMeta = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block type and meta at the specified absolute coords" }, - SetOffset = - { - { Params = "{{Vector3i|Offset}}", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, - { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, - }, SetOrigin = { { Params = "{{Vector3i|Origin}}", Return = "", Notes = "Resets the origin for the absolute coords. Only affects how absolute coords are translated into relative coords." }, @@ -184,6 +179,11 @@ g_APIDesc = SetRelBlockSkyLight = { Params = "RelBlockX, RelBlockY, RelBlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified relative coords" }, SetRelBlockType = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockType", Return = "", Notes = "Sets the block type at the specified relative coords" }, SetRelBlockTypeMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block type and meta at the specified relative coords" }, + SetWEOffset = + { + { Params = "{{Vector3i|Offset}}", Return = "", Notes = "Sets the WE offset, a data value sometimes stored in the schematic files. Mostly used for WorldEdit. MCServer doesn't use this value, but provides access to it using this method." }, + { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Sets the WE offset, a data value sometimes stored in the schematic files. Mostly used for WorldEdit. MCServer doesn't use this value, but provides access to it using this method." }, + }, Write = { { Params = "World, {{Vector3i|MinPoint}}, DataTypes", Return = "bool", Notes = "Writes the area into World at the specified coords, returns true if successful" }, -- cgit v1.2.3 From 04dcd850d6c5609bd5ecea2c60b0be0148571d61 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 11 Mar 2014 08:30:01 +0100 Subject: APIDump: Removed old documentation, documented some new functions. --- MCServer/Plugins/APIDump/APIDesc.lua | 21 +++++++++++++++------ MCServer/Plugins/APIDump/Classes/Geometry.lua | 2 ++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 18b90adbf..3c99b82de 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -423,6 +423,7 @@ g_APIDesc = SetUseDefaultFinish = { Params = "bool", Return = "", Notes = "Sets the chunk to use default finishers or not" }, SetUseDefaultHeight = { Params = "bool", Return = "", Notes = "Sets the chunk to use default height generator or not" }, SetUseDefaultStructures = { Params = "bool", Return = "", Notes = "Sets the chunk to use default structures or not" }, + UpdateHeightmap = { Params = "", Return = "", Notes = "Updates the heightmap to match current contents. The plugins should do that if they modify the contents and don't modify the heightmap accordingly; MCServer expects (and checks in Debug mode) that the heightmap matches the contents when the cChunkDesc is returned from a plugin." }, WriteBlockArea = { Params = "{{cBlockArea|BlockArea}}, MinRelX, MinRelY, MinRelZ", Return = "", Notes = "Writes data from the block area into the chunk" }, }, AdditionalInfo = @@ -472,6 +473,7 @@ end Functions = { + GetLocale = { Params = "", Return = "Locale", Notes = "Returns the locale string that the client sends as part of the protocol handshake. Can be used to provide localized strings." }, GetPing = { Params = "", Return = "number", Notes = "Returns the ping time, in ms" }, GetPlayer = { Params = "", Return = "{{cPlayer|cPlayer}}", Notes = "Returns the player object connected to this client. Note that this may be nil, for example if the player object is not yet spawned." }, GetUniqueID = { Params = "", Return = "number", Notes = "Returns the UniqueID of the client used to identify the client in the server" }, @@ -480,6 +482,7 @@ end HasPluginChannel = { Params = "ChannelName", Return = "bool", Notes = "Returns true if the client has registered to receive messages on the specified plugin channel." }, Kick = { Params = "Reason", Return = "", Notes = "Kicks the user with the specified reason" }, SendPluginMessage = { Params = "Channel, Message", Return = "", Notes = "Sends the plugin message on the specified channel." }, + SetLocale = { Params = "Locale", Return = "", Notes = "Sets the locale that MCServer keeps on record. Initially the locale is initialized in protocol handshake, this function allows plugins to override the stored value (but only server-side and only until the user disconnects)." }, SetUsername = { Params = "Name", Return = "", Notes = "Sets the username" }, SetViewDistance = { Params = "ViewDistance", Return = "", Notes = "Sets the viewdistance (number of chunks loaded for the player in each direction)" }, SendBlockChange = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sends a BlockChange packet to the client. This can be used to create fake blocks only for that player." }, @@ -883,7 +886,6 @@ cFile:Delete("/usr/bin/virus.exe"); SetColor = { Return = "" }, GetColor = { Return = "string" }, AddCommand = { Return = "" }, - HasCommand = { Return = "bool" }, AddPermission = { Return = "" }, InheritFrom = { Return = "" }, }, @@ -1150,7 +1152,6 @@ These ItemGrids are available in the API and can be manipulated by the plugins, IsEnchantable = { Params = "", Return = "bool", Notes = "Returns true if the item is enchantable" }, IsFullStack = { Params = "", Return = "bool", Notes = "Returns true if the item is stacked up to its maximum stacking" }, IsSameType = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is of the same ItemType as the one stored in the object. This is true even if the two items have different enchantments" }, - IsStackableWith = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is stackable with the one stored in the object. Two items with different enchantments cannot be stacked" }, IsBothNameAndLoreEmpty = { Params = "", Return = "bool", Notes = "Returns if both the custom name and lore are not set." }, IsCustomNameEmpty = { Params = "", Return = "bool", Notes = "Returns if the custom name of the cItem is empty." }, IsLoreEmpty = { Params = "", Return = "", Notes = "Returns if the lore of the cItem is empty." }, @@ -1656,7 +1657,6 @@ a_Player:OpenWindow(Window); AddToGroup = { Params = "GroupName", Return = "", Notes = "Temporarily adds the player to the specified group. The assignment is lost when the player disconnects." }, CalcLevelFromXp = { Params = "XPAmount", Return = "number", Notes = "(STATIC) Returns the level which is reached with the specified amount of XP. Inverse of XpForLevel()." }, CanFly = { Return = "bool", Notes = "Returns if the player is able to fly." }, - CanUseCommand = { Params = "Command", Return = "bool", Notes = "Returns true if the player is allowed to use the specified command." }, CloseWindow = { Params = "[CanRefuse]", Return = "", Notes = "Closes the currently open UI window. If CanRefuse is true (default), the window may refuse the closing." }, CloseWindowIfID = { Params = "WindowID, [CanRefuse]", Return = "", Notes = "Closes the currently open UI window if its ID matches the given ID. If CanRefuse is true (default), the window may refuse the closing." }, DeltaExperience = { Params = "DeltaXP", Return = "", Notes = "Adds or removes XP from the current XP amount. Won't allow XP to go negative. Returns the new experience, -1 on error (XP overflow)." }, @@ -1733,7 +1733,6 @@ a_Player:OpenWindow(Window); SetSprint = { Params = "IsSprinting", Return = "", Notes = "Sets whether the player is sprinting or not." }, SetSprintingMaxSpeed = { Params = "SprintingMaxSpeed", Return = "", Notes = "Sets the sprinting maximum speed (as reported by the 1.6.1+ protocols)" }, SetVisible = { Params = "IsVisible", Return = "", Notes = "Sets the player visibility to other players" }, - TossItem = { Params = "DraggedItem, [Amount], [CreateType], [CreateDamage]", Return = "", Notes = "FIXME: This function will be rewritten, avoid it. It tosses an item, either from the inventory, dragged in hand (while in UI window) or a newly created one." }, XpForLevel = { Params = "XPLevel", Return = "number", Notes = "(STATIC) Returns the total amount of XP needed for the specified XP level. Inverse of CalcLevelFromXp()." }, }, Constants = @@ -2630,7 +2629,8 @@ end ]], Functions = { - AddFaceDirection = {Params = "BlockX, BlockY, BlockZ, BlockFace, [IsInverse]", Return = "BlockX, BlockY, BlockZ", Notes = "Returns the coords of a block adjacent to the specified block through the specified {{Globals#BlockFace|face}}"}, + AddFaceDirection = {Params = "BlockX, BlockY, BlockZ, BlockFace, [IsInverse]", Return = "BlockX, BlockY, BlockZ", Notes = "Returns the coords of a block adjacent to the specified block through the specified {{Globals#BlockFaces|face}}"}, + BlockFaceToString = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "string", Notes = "Returns the string representation of the {{Globals#BlockFaces|eBlockFace}} constant. Uses the axis-direction-based names, such as BLOCK_FACE_XP." }, BlockStringToType = {Params = "BlockTypeString", Return = "BLOCKTYPE", Notes = "Returns the block type parsed from the given string"}, ClickActionToString = {Params = "{{Globals#ClickAction|ClickAction}}", Return = "string", Notes = "Returns a string description of the ClickAction enumerated value"}, DamageTypeToString = {Params = "{{Globals#DamageType|DamageType}}", Return = "string", Notes = "Converts the {{Globals#DamageType|DamageType}} enumerated value to a string representation "}, @@ -2649,9 +2649,12 @@ end LOGINFO = {Params = "string", Notes = "Logs a text into the server console using 'info' severity (yellow text)"}, LOGWARN = {Params = "string", Notes = "Logs a text into the server console using 'warning' severity (red text); OBSOLETE, use LOGWARNING() instead"}, LOGWARNING = {Params = "string", Notes = "Logs a text into the server console using 'warning' severity (red text)"}, + MirrorBlockFaceY = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "{{Globals#BlockFaces|eBlockFace}}", Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after mirroring it around the Y axis (or rotating 180 degrees around it)." }, NoCaseCompare = {Params = "string, string", Return = "number", Notes = "Case-insensitive string comparison; returns 0 if the strings are the same"}, NormalizeAngleDegrees = { Params = "AngleDegrees", Return = "AngleDegrees", Notes = "Returns the angle, wrapped into the [-180, +180) range." }, ReplaceString = {Params = "full-string, to-be-replaced-string, to-replace-string", Notes = "Replaces *each* occurence of to-be-replaced-string in full-string with to-replace-string"}, + RotateBlockFaceCCW = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "{{Globals#BlockFaces|eBlockFace}}", Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after rotating it around the Y axis 90 degrees counter-clockwise." }, + RotateBlockFaceCW = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "{{Globals#BlockFaces|eBlockFace}}", Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after rotating it around the Y axis 90 degrees clockwise." }, StringSplit = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered."}, StringSplitAndTrim = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered. Each of the separate strings is trimmed (whitespace removed from the beginning and end of the string)"}, StringToBiome = {Params = "string", Return = "{{Globals#BiomeTypes|BiomeType}}", Notes = "Converts a string representation to a {{Globals#BiomeTypes|BiomeType}} enumerated value"}, @@ -2698,7 +2701,13 @@ end Include = "^BLOCK_FACE_.*", TextBefore = [[ These constants are used to describe individual faces of the block. They are used when the - client is interacting with a block, or when the {{cLineBlockTracer}} hits a block, etc. + client is interacting with a block in the {{OnPlayerBreakingBlock|HOOK_PLAYER_BREAKING_BLOCK}}, + {{OnPlayerBrokenBlock|HOOK_PLAYER_BROKEN_BLOCK}}, {{OnPlayerLeftClick|HOOK_PLAYER_LEFT_CLICK}}, + {{OnPlayerPlacedBlock|HOOK_PLAYER_PLACED_BLOCK}}, {{OnPlayerPlacingBlock|HOOK_PLAYER_PLACING_BLOCK}}, + {{OnPlayerRightClick|HOOK_PLAYER_RIGHT_CLICK}}, {{OnPlayerUsedBlock|HOOK_PLAYER_USED_BLOCK}}, + {{OnPlayerUsedItem|HOOK_PLAYER_USED_ITEM}}, {{OnPlayerUsingBlock|HOOK_PLAYER_USING_BLOCK}}, + and {{OnPlayerUsingItem|HOOK_PLAYER_USING_ITEM}} hooks, or when the {{cLineBlockTracer}} hits a + block, etc. ]], }, ClickAction = diff --git a/MCServer/Plugins/APIDump/Classes/Geometry.lua b/MCServer/Plugins/APIDump/Classes/Geometry.lua index e83d6e4b1..6f95c4cbf 100644 --- a/MCServer/Plugins/APIDump/Classes/Geometry.lua +++ b/MCServer/Plugins/APIDump/Classes/Geometry.lua @@ -76,6 +76,7 @@ return DifY = { Params = "", Return = "number", Notes = "Returns the difference between the two Y coords (Y-size minus 1). Assumes sorted." }, DifZ = { Params = "", Return = "number", Notes = "Returns the difference between the two Z coords (Z-size minus 1). Assumes sorted." }, DoesIntersect = { Params = "OtherCuboid", Return = "bool", Notes = "Returns true if this cuboid has at least one voxel in common with OtherCuboid. Note that edges are considered inclusive. Assumes both sorted." }, + Engulf = { Params = "{{Vector3i|Point}}", Return = "", Notes = "If needed, expands the cuboid to include the specified point. Doesn't shrink. Assumes sorted. " }, Expand = { Params = "SubMinX, AddMaxX, SubMinY, AddMaxY, SubMinZ, AddMaxZ", Return = "", Notes = "Expands the cuboid by the specified amount in each direction. Works on unsorted cuboids as well. NOTE: this function doesn't check for underflows." }, GetVolume = { Params = "", Return = "number", Notes = "Returns the volume of the cuboid, in blocks. Note that the volume considers both coords inclusive. Works on unsorted cuboids, too." }, IsCompletelyInside = { Params = "OuterCuboid", Return = "bool", Notes = "Returns true if this cuboid is completely inside (in all directions) in OuterCuboid. Assumes both sorted." }, @@ -308,6 +309,7 @@ end }, Equals = { Params = "Vector3i", Return = "bool", Notes = "Returns true if this vector is exactly the same as the specified vector." }, Length = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector." }, + Move = { Params = "X, Y, Z", Return = "", Notes = "Moves the vector by the specified amount in each axis direction." }, Set = { Params = "x, y, z", Return = "", Notes = "Sets all the coords of the vector at once" }, SqrLength = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector, squared. This operation is slightly less computationally expensive than Length(), while it conserves some properties of Length(), such as comparison." }, }, -- cgit v1.2.3 From 541175d8a08515568d75a8d6b57bc4841e273c4a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 14:44:21 +0100 Subject: Using ```const Vector3i &``` --- src/BlockArea.cpp | 2 +- src/BlockArea.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 986b2ee25..dfdf998df 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -264,7 +264,7 @@ void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) -void cBlockArea::SetOffset(Vector3i a_Offset) +void cBlockArea::SetOffset(const Vector3i & a_Offset) { m_Offset.Set(a_Offset.x, a_Offset.y, a_Offset.z); } diff --git a/src/BlockArea.h b/src/BlockArea.h index d89c9b372..75b8db3a6 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -210,7 +210,7 @@ public: void SetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockSkyLight); void SetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockSkyLight); void SetOffset (int a_OffsetX, int a_OffsetY, int a_OffsetZ); - void SetOffset (Vector3i a_Offset); + void SetOffset (const Vector3i & a_Offset); // Getters: BLOCKTYPE GetRelBlockType (int a_RelX, int a_RelY, int a_RelZ) const; @@ -221,7 +221,7 @@ public: NIBBLETYPE GetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ) const; NIBBLETYPE GetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ) const; NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ) const; - Vector3i GetOffset (void) const {return m_Offset;} + const Vector3i & GetOffset (void) const {return m_Offset;} void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); -- cgit v1.2.3 From b4bf13aa4f004a7819e262679a295d8ca886557b Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 11 Mar 2014 16:01:17 +0200 Subject: Unified Vector classes --- src/Bindings/AllToLua.pkg | 10 +- src/Bindings/LuaState.h | 3 +- src/BlockArea.h | 2 +- src/BoundingBox.h | 2 +- src/CMakeLists.txt | 4 +- src/ChunkDef.h | 2 +- src/ClientHandle.cpp | 3 - src/ClientHandle.h | 2 +- src/Cuboid.h | 3 +- src/Entities/Entity.h | 4 +- src/Entities/Player.cpp | 1 + src/Globals.h | 8 ++ src/LineBlockTracer.cpp | 2 +- src/Matrix4f.h | 2 +- src/Mobs/Bat.cpp | 2 +- src/Mobs/Squid.cpp | 2 +- src/Scoreboard.h | 2 + src/Server.cpp | 2 +- src/Simulator/Simulator.cpp | 1 - src/Simulator/Simulator.h | 2 +- src/Tracer.cpp | 4 - src/Tracer.h | 3 +- src/Vector3.h | 264 ++++++++++++++++++++++++++++++++++++++++++ src/Vector3d.cpp | 77 ------------ src/Vector3d.h | 81 ------------- src/Vector3f.cpp | 34 ------ src/Vector3f.h | 47 -------- src/Vector3i.cpp | 58 ---------- src/Vector3i.h | 68 ----------- src/World.cpp | 1 - src/World.h | 3 +- src/WorldStorage/WSSCompact.h | 2 +- 32 files changed, 300 insertions(+), 401 deletions(-) create mode 100644 src/Vector3.h delete mode 100644 src/Vector3d.cpp delete mode 100644 src/Vector3d.h delete mode 100644 src/Vector3f.cpp delete mode 100644 src/Vector3f.h delete mode 100644 src/Vector3i.cpp delete mode 100644 src/Vector3i.h diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 2676281f9..302714318 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -11,6 +11,7 @@ typedef unsigned int UInt32; typedef unsigned short UInt16; +$cfile "../Vector3.h" $cfile "../ChunkDef.h" $cfile "../BiomeDef.h" @@ -62,9 +63,6 @@ $cfile "../BlockEntities/MobHeadEntity.h" $cfile "../BlockEntities/FlowerPotEntity.h" $cfile "../WebAdmin.h" $cfile "../Root.h" -$cfile "../Vector3f.h" -$cfile "../Vector3d.h" -$cfile "../Vector3i.h" $cfile "../Matrix4f.h" $cfile "../Cuboid.h" $cfile "../BoundingBox.h" @@ -97,4 +95,10 @@ typedef unsigned char Byte; +// Aliases +$renaming Vector3 @ Vector3d +$renaming Vector3 @ Vector3f +$renaming Vector3 @ Vector3i + + diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 4a7a6fadb..1156f5363 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -29,6 +29,8 @@ extern "C" #include "lua/src/lauxlib.h" } +#include "../Vector3.h" + @@ -52,7 +54,6 @@ class cWebAdmin; struct HTTPTemplateRequest; class cTNTEntity; class cCreeper; -class Vector3i; class cHopperEntity; class cBlockEntity; diff --git a/src/BlockArea.h b/src/BlockArea.h index 0703f195e..0e52a5de0 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -13,13 +13,13 @@ #pragma once #include "ForEachChunkProvider.h" +#include "Vector3.h" // fwd: class cCuboid; -class Vector3i; diff --git a/src/BoundingBox.h b/src/BoundingBox.h index 9ac5f11b8..a7c6c3eea 100644 --- a/src/BoundingBox.h +++ b/src/BoundingBox.h @@ -8,7 +8,7 @@ #pragma once -#include "Vector3d.h" +#include "Vector3.h" #include "Defines.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c2de26664..04736c2d7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -70,9 +70,7 @@ if (NOT MSVC) StringUtils.h Tracer.h UI/Window.h - Vector3d.h - Vector3f.h - Vector3i.h + Vector3.h WebAdmin.h World.h ) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 7876c58e7..04a7f5af2 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -9,7 +9,7 @@ #pragma once -#include "Vector3i.h" +#include "Vector3.h" #include "BiomeDef.h" diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 94c9f5f71..9083d7ae0 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -22,9 +22,6 @@ #include "Blocks/BlockSlab.h" #include "Blocks/ChunkInterface.h" -#include "Vector3f.h" -#include "Vector3d.h" - #include "Root.h" #include "Authenticator.h" diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 72b1c7d09..8366caa16 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -12,7 +12,7 @@ #define CCLIENTHANDLE_H_INCLUDED #include "Defines.h" -#include "Vector3d.h" +#include "Vector3.h" #include "OSSupport/SocketThreads.h" #include "ChunkDef.h" #include "ByteBuffer.h" diff --git a/src/Cuboid.h b/src/Cuboid.h index b95517f69..b90a09e05 100644 --- a/src/Cuboid.h +++ b/src/Cuboid.h @@ -1,8 +1,7 @@ #pragma once -#include "Vector3i.h" -#include "Vector3d.h" +#include "Vector3.h" diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index b3b1cef83..a73565de7 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -2,9 +2,7 @@ #pragma once #include "../Item.h" -#include "../Vector3d.h" -#include "../Vector3f.h" -#include "../Vector3i.h" +#include "../Vector3.h" diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index ccdd151f3..440d30595 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -14,6 +14,7 @@ #include "../OSSupport/Timer.h" #include "../Chunk.h" #include "../Items/ItemHandler.h" +#include "../Vector3.h" #include "inifile/iniFile.h" #include "json/json.h" diff --git a/src/Globals.h b/src/Globals.h index 28805a83f..b8acfca64 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -246,6 +246,14 @@ T Clamp(T a_Value, T a_Min, T a_Max) +#ifndef TOLUA_TEMPLATE_BIND +#define TOLUA_TEMPLATE_BIND(x) +#endif + + + + + // Common headers (part 2, with macros): #include "ChunkDef.h" #include "BiomeDef.h" diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp index da1c7f2fd..f4f29e833 100644 --- a/src/LineBlockTracer.cpp +++ b/src/LineBlockTracer.cpp @@ -5,7 +5,7 @@ #include "Globals.h" #include "LineBlockTracer.h" -#include "Vector3d.h" +#include "Vector3.h" #include "World.h" #include "Chunk.h" diff --git a/src/Matrix4f.h b/src/Matrix4f.h index 249c92f5f..0e36974ad 100644 --- a/src/Matrix4f.h +++ b/src/Matrix4f.h @@ -2,7 +2,7 @@ #define _USE_MATH_DEFINES #include -#include "Vector3f.h" +#include "Vector3.h" class Matrix4f { diff --git a/src/Mobs/Bat.cpp b/src/Mobs/Bat.cpp index b9c82996b..1417ddd9e 100644 --- a/src/Mobs/Bat.cpp +++ b/src/Mobs/Bat.cpp @@ -2,7 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Bat.h" -#include "../Vector3d.h" +#include "../Vector3.h" #include "../Chunk.h" diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index ba9171b39..bd0e141a0 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -2,7 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Squid.h" -#include "../Vector3d.h" +#include "../Vector3.h" #include "../Chunk.h" diff --git a/src/Scoreboard.h b/src/Scoreboard.h index e22ecaeb1..2fae5e499 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -150,6 +150,8 @@ public: /** Removes all registered players */ void Reset(void); + // tolua_begin + /** Returns the number of registered players */ unsigned int GetNumPlayers(void) const; diff --git a/src/Server.cpp b/src/Server.cpp index fcbcaa919..1b168ff20 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -24,7 +24,7 @@ #include "MersenneTwister.h" #include "inifile/iniFile.h" -#include "Vector3f.h" +#include "Vector3.h" #include #include diff --git a/src/Simulator/Simulator.cpp b/src/Simulator/Simulator.cpp index 06fd0f858..0739f0187 100644 --- a/src/Simulator/Simulator.cpp +++ b/src/Simulator/Simulator.cpp @@ -3,7 +3,6 @@ #include "Simulator.h" #include "../World.h" -#include "../Vector3i.h" #include "../BlockID.h" #include "../Defines.h" #include "../Chunk.h" diff --git a/src/Simulator/Simulator.h b/src/Simulator/Simulator.h index a25b7f1b6..a2e2a5742 100644 --- a/src/Simulator/Simulator.h +++ b/src/Simulator/Simulator.h @@ -1,7 +1,7 @@ #pragma once -#include "../Vector3i.h" +#include "../Vector3.h" #include "inifile/iniFile.h" diff --git a/src/Tracer.cpp b/src/Tracer.cpp index 968a64439..6da6b2ad7 100644 --- a/src/Tracer.cpp +++ b/src/Tracer.cpp @@ -4,10 +4,6 @@ #include "Tracer.h" #include "World.h" -#include "Vector3f.h" -#include "Vector3i.h" -#include "Vector3d.h" - #include "Entities/Entity.h" #ifndef _WIN32 diff --git a/src/Tracer.h b/src/Tracer.h index 6c2ab6792..bdb080f0d 100644 --- a/src/Tracer.h +++ b/src/Tracer.h @@ -1,8 +1,7 @@ #pragma once -#include "Vector3i.h" -#include "Vector3f.h" +#include "Vector3.h" diff --git a/src/Vector3.h b/src/Vector3.h new file mode 100644 index 000000000..0be52248d --- /dev/null +++ b/src/Vector3.h @@ -0,0 +1,264 @@ + +#pragma once + + + + +#include + + + + + + + + + +template +// tolua_begin +class Vector3 +{ + + TOLUA_TEMPLATE_BIND((T, int, float, double)) + +public: + + T x, y, z; + + + inline Vector3() : x(0), y(0), z(0) {} + inline Vector3(T a_x, T a_y, T a_z) : x(a_x), y(a_y), z(a_z) {} + + + // tolua_end + template + Vector3(const Vector3<_T> & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} + + template + Vector3(const Vector3<_T> * a_Rhs) : x(a_Rhs->x), y(a_Rhs->y), z(a_Rhs->z) {} + // tolua_begin + + + inline void Set(T a_x, T a_y, T a_z) + { + x = a_x; + y = a_y; + z = a_z; + } + + inline void Normalize(void) + { + T Len = 1.0 / Length(); + + x *= Len; + y *= Len; + z *= Len; + } + + inline Vector3 NormalizeCopy(void) const + { + T Len = 1.0 / Length(); + + return Vector3( + x * Len, + y * Len, + z * Len + ); + } + + inline void NormalizeCopy(Vector3 & a_Rhs) const + { + T Len = 1.0 / Length(); + + a_Rhs.Set( + x * Len, + y * Len, + z * Len + ); + } + + inline T Length(void) const + { + return sqrt(x * x + y * y + z * z); + } + + inline T SqrLength(void) const + { + return x * x + y * y + z * z; + } + + inline T Dot(const Vector3 & a_Rhs) const + { + return x * a_Rhs.x + y * a_Rhs.y + z * a_Rhs.z; + } + + inline Vector3 Cross(const Vector3 & a_Rhs) const + { + return Vector3( + y * a_Rhs.z - z * a_Rhs.y, + z * a_Rhs.x - x * a_Rhs.z, + x * a_Rhs.y - y * a_Rhs.x + ); + } + + inline bool Equals(const Vector3 & a_Rhs) const + { + return x == a_Rhs.x && y == a_Rhs.y && z == a_Rhs.z; + } + + inline bool operator < (const Vector3 & a_Rhs) + { + // return (x < a_Rhs.x) && (y < a_Rhs.y) && (z < a_Rhs.z); ? + return (x < a_Rhs.x) || (x == a_Rhs.x && y < a_Rhs.y) || (x == a_Rhs.x && y == a_Rhs.y && z < a_Rhs.z); + } + + inline void Move(T a_X, T a_Y, T a_Z) + { + x += a_X; + y += a_Y; + z += a_Z; + } + + // tolua_end + + inline void operator += (const Vector3 & a_Rhs) + { + x += a_Rhs.x; + y += a_Rhs.y; + z += a_Rhs.z; + } + + inline void operator -= (const Vector3 & a_Rhs) + { + x -= a_Rhs.x; + y -= a_Rhs.y; + z -= a_Rhs.z; + } + + inline void operator *= (const Vector3 & a_Rhs) + { + x *= a_Rhs.x; + y *= a_Rhs.y; + z *= a_Rhs.z; + } + + inline void operator *= (T a_v) + { + x *= a_v; + y *= a_v; + z *= a_v; + } + + // tolua_begin + + inline Vector3 operator + (const Vector3& a_Rhs) const + { + return Vector3( + x + a_Rhs.x, + y + a_Rhs.y, + z + a_Rhs.z + ); + } + + inline Vector3 operator - (const Vector3& a_Rhs) const + { + return Vector3( + x - a_Rhs.x, + y - a_Rhs.y, + z - a_Rhs.z + ); + } + + inline Vector3 operator * (const Vector3& a_Rhs) const + { + return Vector3( + x * a_Rhs.x, + y * a_Rhs.y, + z * a_Rhs.z + ); + } + + inline Vector3 operator * (T a_v) const + { + return Vector3( + x * a_v, + y * a_v, + z * a_v + ); + } + + inline Vector3 operator / (T a_v) const + { + return Vector3( + x / a_v, + y / a_v, + z / a_v + ); + } + + inline double LineCoeffToXYPlane(const Vector3 & a_OtherEnd, T a_Z) const + { + if (abs(z - a_OtherEnd.z) < EPS) + { + return NO_INTERSECTION; + } + + return (a_Z - z) / (a_OtherEnd.z - z); + } + + inline double LineCoeffToXZPlane(const Vector3 & a_OtherEnd, T a_Y) const + { + if (abs(y - a_OtherEnd.y) < EPS) + { + return NO_INTERSECTION; + } + + return (a_Y - y) / (a_OtherEnd.y - y); + } + + inline double LineCoeffToYZPlane(const Vector3 & a_OtherEnd, T a_X) const + { + if (abs(x - a_OtherEnd.x) < EPS) + { + return NO_INTERSECTION; + } + + return (a_X - x) / (a_OtherEnd.x - x); + } + + /** The max difference between two coords for which the coords are assumed equal. */ + static const double EPS; + + /** Return value of LineCoeffToPlane() if the line is parallel to the plane. */ + static const double NO_INTERSECTION; +}; +// tolua_end + +template +const double Vector3::EPS = 0.000001; + +template +const double Vector3::NO_INTERSECTION = 1e70; + + + + + +// tolua_begin +typedef Vector3 Vector3d; +typedef Vector3 Vector3f; +typedef Vector3 Vector3i; +// tolua_end + + + + + +typedef std::list cVector3iList; +typedef std::vector cVector3iArray; + + + + + + diff --git a/src/Vector3d.cpp b/src/Vector3d.cpp deleted file mode 100644 index 96ebebab5..000000000 --- a/src/Vector3d.cpp +++ /dev/null @@ -1,77 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "Vector3d.h" -#include "Vector3f.h" - - - - - -const double Vector3d::EPS = 0.000001; ///< The max difference between two coords for which the coords are assumed equal -const double Vector3d::NO_INTERSECTION = 1e70; ///< Return value of LineCoeffToPlane() if the line is parallel to the plane - - - - - -Vector3d::Vector3d(const Vector3f & v) : - x(v.x), - y(v.y), - z(v.z) -{ -} - - - - - -Vector3d::Vector3d(const Vector3f * v) : - x(v->x), - y(v->y), - z(v->z) -{ -} - - - - - -double Vector3d::LineCoeffToXYPlane(const Vector3d & a_OtherEnd, double a_Z) const -{ - if (abs(z - a_OtherEnd.z) < EPS) - { - return NO_INTERSECTION; - } - return (a_Z - z) / (a_OtherEnd.z - z); -} - - - - - -double Vector3d::LineCoeffToXZPlane(const Vector3d & a_OtherEnd, double a_Y) const -{ - if (abs(y - a_OtherEnd.y) < EPS) - { - return NO_INTERSECTION; - } - return (a_Y - y) / (a_OtherEnd.y - y); -} - - - - - -double Vector3d::LineCoeffToYZPlane(const Vector3d & a_OtherEnd, double a_X) const -{ - if (abs(x - a_OtherEnd.x) < EPS) - { - return NO_INTERSECTION; - } - return (a_X - x) / (a_OtherEnd.x - x); -} - - - - diff --git a/src/Vector3d.h b/src/Vector3d.h deleted file mode 100644 index a06a17c09..000000000 --- a/src/Vector3d.h +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once - -#include - -class Vector3f; - - - -// tolua_begin - -class Vector3d -{ -public: - // convert from float - Vector3d(const Vector3f & v); - Vector3d(const Vector3f * v); - - Vector3d() : x(0), y(0), z(0) {} - Vector3d(double a_x, double a_y, double a_z) : x(a_x), y(a_y), z(a_z) {} - - inline void Set(double a_x, double a_y, double a_z) { x = a_x, y = a_y, z = a_z; } - inline void Normalize() { double l = 1.0f / Length(); x *= l; y *= l; z *= l; } - inline Vector3d NormalizeCopy() { double l = 1.0f / Length(); return Vector3d( x * l, y * l, z * l ); } - inline void NormalizeCopy(Vector3d & a_V) { double l = 1.0f / Length(); a_V.Set(x*l, y*l, z*l ); } - inline double Length() const { return (double)sqrt( x * x + y * y + z * z ); } - inline double SqrLength() const { return x * x + y * y + z * z; } - inline double Dot( const Vector3d & a_V ) const { return x * a_V.x + y * a_V.y + z * a_V.z; } - inline Vector3d Cross( const Vector3d & v ) const { return Vector3d( y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); } - - /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Z coord - The result satisfies the following equation: - (*this + Result * (a_OtherEnd - *this)).z = a_Z - If the line is too close to being parallel, this function returns NO_INTERSECTION - */ - double LineCoeffToXYPlane(const Vector3d & a_OtherEnd, double a_Z) const; - - /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Y coord - The result satisfies the following equation: - (*this + Result * (a_OtherEnd - *this)).y = a_Y - If the line is too close to being parallel, this function returns NO_INTERSECTION - */ - double LineCoeffToXZPlane(const Vector3d & a_OtherEnd, double a_Y) const; - - /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified X coord - The result satisfies the following equation: - (*this + Result * (a_OtherEnd - *this)).x = a_X - If the line is too close to being parallel, this function returns NO_INTERSECTION - */ - double LineCoeffToYZPlane(const Vector3d & a_OtherEnd, double a_X) const; - - inline bool Equals(const Vector3d & v) const { return ((x == v.x) && (y == v.y) && (z == v.z)); } - - // tolua_end - - void operator += ( const Vector3d& a_V ) { x += a_V.x; y += a_V.y; z += a_V.z; } - void operator += ( Vector3d* a_V ) { x += a_V->x; y += a_V->y; z += a_V->z; } - void operator -= ( const Vector3d& a_V ) { x -= a_V.x; y -= a_V.y; z -= a_V.z; } - void operator -= ( Vector3d* a_V ) { x -= a_V->x; y -= a_V->y; z -= a_V->z; } - void operator *= ( double a_f ) { x *= a_f; y *= a_f; z *= a_f; } - - // tolua_begin - - Vector3d operator + (const Vector3d & v2) const { return Vector3d(x + v2.x, y + v2.y, z + v2.z ); } - Vector3d operator + (const Vector3d * v2) const { return Vector3d(x + v2->x, y + v2->y, z + v2->z ); } - Vector3d operator - (const Vector3d & v2) const { return Vector3d(x - v2.x, y - v2.y, z - v2.z ); } - Vector3d operator - (const Vector3d * v2) const { return Vector3d(x - v2->x, y - v2->y, z - v2->z ); } - Vector3d operator * (const double f) const { return Vector3d(x * f, y * f, z * f ); } - Vector3d operator * (const Vector3d & v2) const { return Vector3d(x * v2.x, y * v2.y, z * v2.z ); } - Vector3d operator / (const double f) const { return Vector3d(x / f, y / f, z / f ); } - - double x, y, z; - - static const double EPS; ///< The max difference between two coords for which the coords are assumed equal - static const double NO_INTERSECTION; ///< Return value of LineCoeffToPlane() if the line is parallel to the plane -} ; - -// tolua_end - - - - diff --git a/src/Vector3f.cpp b/src/Vector3f.cpp deleted file mode 100644 index 59d71d371..000000000 --- a/src/Vector3f.cpp +++ /dev/null @@ -1,34 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "Vector3f.h" -#include "Vector3d.h" -#include "Vector3i.h" - -Vector3f::Vector3f( const Vector3d & v ) - : x( (float)v.x ) - , y( (float)v.y ) - , z( (float)v.z ) -{ -} - -Vector3f::Vector3f( const Vector3d * v ) - : x( (float)v->x ) - , y( (float)v->y ) - , z( (float)v->z ) -{ -} - -Vector3f::Vector3f( const Vector3i & v ) - : x( (float)v.x ) - , y( (float)v.y ) - , z( (float)v.z ) -{ -} - -Vector3f::Vector3f( const Vector3i * v ) - : x( (float)v->x ) - , y( (float)v->y ) - , z( (float)v->z ) -{ -} \ No newline at end of file diff --git a/src/Vector3f.h b/src/Vector3f.h deleted file mode 100644 index adb154ad7..000000000 --- a/src/Vector3f.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include - -class Vector3i; -class Vector3d; -class Vector3f // tolua_export -{ // tolua_export -public: // tolua_export - Vector3f( const Vector3d & v ); // tolua_export - Vector3f( const Vector3d * v ); // tolua_export - Vector3f( const Vector3i & v ); // tolua_export - Vector3f( const Vector3i * v ); // tolua_export - - - Vector3f() : x(0), y(0), z(0) {} // tolua_export - Vector3f(float a_x, float a_y, float a_z) : x(a_x), y(a_y), z(a_z) {} // tolua_export - - inline void Set(float a_x, float a_y, float a_z) { x = a_x, y = a_y, z = a_z; } // tolua_export - inline void Normalize() { float l = 1.0f / Length(); x *= l; y *= l; z *= l; } // tolua_export - inline Vector3f NormalizeCopy() const { float l = 1.0f / Length(); return Vector3f( x * l, y * l, z * l ); }// tolua_export - inline void NormalizeCopy(Vector3f & a_V) const { float l = 1.0f / Length(); a_V.Set(x*l, y*l, z*l ); } // tolua_export - inline float Length() const { return (float)sqrtf( x * x + y * y + z * z ); } // tolua_export - inline float SqrLength() const { return x * x + y * y + z * z; } // tolua_export - inline float Dot( const Vector3f & a_V ) const { return x * a_V.x + y * a_V.y + z * a_V.z; } // tolua_export - inline Vector3f Cross( const Vector3f & v ) const { return Vector3f( y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); } // tolua_export - - inline bool Equals( const Vector3f & v ) const { return (x == v.x && y == v.y && z == v.z ); } // tolua_export - - void operator += ( const Vector3f& a_V ) { x += a_V.x; y += a_V.y; z += a_V.z; } - void operator += ( Vector3f* a_V ) { x += a_V->x; y += a_V->y; z += a_V->z; } - void operator -= ( const Vector3f& a_V ) { x -= a_V.x; y -= a_V.y; z -= a_V.z; } - void operator -= ( Vector3f* a_V ) { x -= a_V->x; y -= a_V->y; z -= a_V->z; } - void operator *= ( float a_f ) { x *= a_f; y *= a_f; z *= a_f; } - void operator *= ( Vector3f* a_V ) { x *= a_V->x; y *= a_V->y; z *= a_V->z; } - void operator *= ( const Vector3f& a_V ) { x *= a_V.x; y *= a_V.y; z *= a_V.z; } - - Vector3f operator + ( const Vector3f& v2 ) const { return Vector3f( x + v2.x, y + v2.y, z + v2.z ); } // tolua_export - Vector3f operator + ( const Vector3f* v2 ) const { return Vector3f( x + v2->x, y + v2->y, z + v2->z ); } // tolua_export - Vector3f operator - ( const Vector3f& v2 ) const { return Vector3f( x - v2.x, y - v2.y, z - v2.z ); } // tolua_export - Vector3f operator - ( const Vector3f* v2 ) const { return Vector3f( x - v2->x, y - v2->y, z - v2->z ); } // tolua_export - Vector3f operator * ( const float f ) const { return Vector3f( x * f, y * f, z * f ); } // tolua_export - Vector3f operator * ( const Vector3f& v2 ) const { return Vector3f( x * v2.x, y * v2.y, z * v2.z ); } // tolua_export - - float x, y, z; // tolua_export - -};// tolua_export diff --git a/src/Vector3i.cpp b/src/Vector3i.cpp deleted file mode 100644 index 2106aea6d..000000000 --- a/src/Vector3i.cpp +++ /dev/null @@ -1,58 +0,0 @@ - -// Vector3i.cpp - -// Implements the Vector3i class representing an int-based 3D vector - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "math.h" -#include "Vector3i.h" -#include "Vector3d.h" - - - - - -Vector3i::Vector3i(const Vector3d & v) : - x((int)v.x), - y((int)v.y), - z((int)v.z) -{ -} - - - - - -Vector3i::Vector3i(void) : - x(0), - y(0), - z(0) -{ -} - - - - - -Vector3i::Vector3i(int a_x, int a_y, int a_z) : - x(a_x), - y(a_y), - z(a_z) -{ -} - - - - - -void Vector3i::Move(int a_MoveX, int a_MoveY, int a_MoveZ) -{ - x += a_MoveX; - y += a_MoveY; - z += a_MoveZ; -} - - - - diff --git a/src/Vector3i.h b/src/Vector3i.h deleted file mode 100644 index 39e138683..000000000 --- a/src/Vector3i.h +++ /dev/null @@ -1,68 +0,0 @@ - -// Vector3i.h - -// Declares the Vector3i class representing an int-based 3D vector - - - - - -#pragma once - - - - - -// fwd: -class Vector3d; - - - - - -// tolua_begin -class Vector3i -{ -public: - /** Creates an int vector based on the floor()-ed coords of a double vector. */ - Vector3i(const Vector3d & v); - - Vector3i(void); - Vector3i(int a_x, int a_y, int a_z); - - inline void Set(int a_x, int a_y, int a_z) { x = a_x, y = a_y, z = a_z; } - inline float Length() const { return sqrtf( (float)( x * x + y * y + z * z) ); } - inline int SqrLength() const { return x * x + y * y + z * z; } - - inline bool Equals( const Vector3i & v ) const { return (x == v.x && y == v.y && z == v.z ); } - inline bool Equals( const Vector3i * v ) const { return (x == v->x && y == v->y && z == v->z ); } - - void Move(int a_MoveX, int a_MoveY, int a_MoveZ); - - // tolua_end - - void operator += ( const Vector3i& a_V ) { x += a_V.x; y += a_V.y; z += a_V.z; } - void operator += ( Vector3i* a_V ) { x += a_V->x; y += a_V->y; z += a_V->z; } - void operator -= ( const Vector3i& a_V ) { x -= a_V.x; y -= a_V.y; z -= a_V.z; } - void operator -= ( Vector3i* a_V ) { x -= a_V->x; y -= a_V->y; z -= a_V->z; } - void operator *= ( int a_f ) { x *= a_f; y *= a_f; z *= a_f; } - - friend Vector3i operator + ( const Vector3i& v1, const Vector3i& v2 ) { return Vector3i( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z ); } - friend Vector3i operator + ( const Vector3i& v1, Vector3i* v2 ) { return Vector3i( v1.x + v2->x, v1.y + v2->y, v1.z + v2->z ); } - friend Vector3i operator - ( const Vector3i& v1, const Vector3i& v2 ) { return Vector3i( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z ); } - friend Vector3i operator - ( const Vector3i& v1, Vector3i* v2 ) { return Vector3i( v1.x - v2->x, v1.y - v2->y, v1.z - v2->z ); } - friend Vector3i operator - ( const Vector3i* v1, Vector3i& v2 ) { return Vector3i( v1->x - v2.x, v1->y - v2.y, v1->z - v2.z ); } - friend Vector3i operator * ( const Vector3i& v, const int f ) { return Vector3i( v.x * f, v.y * f, v.z * f ); } - friend Vector3i operator * ( const Vector3i& v1, const Vector3i& v2 ) { return Vector3i( v1.x * v2.x, v1.y * v2.y, v1.z * v2.z ); } - friend Vector3i operator * ( const int f, const Vector3i& v ) { return Vector3i( v.x * f, v.y * f, v.z * f ); } - friend bool operator < ( const Vector3i& v1, const Vector3i& v2 ) { return (v1.x cVector3iList; -typedef std::vector cVector3iArray; - - - - diff --git a/src/World.cpp b/src/World.cpp index a9db6bf00..3d01dc40f 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -46,7 +46,6 @@ #include "Generating/Trees.h" #include "Bindings/PluginManager.h" #include "Blocks/BlockHandler.h" -#include "Vector3d.h" #include "Tracer.h" diff --git a/src/World.h b/src/World.h index d48db5911..a772710ab 100644 --- a/src/World.h +++ b/src/World.h @@ -14,8 +14,7 @@ #include "ChunkMap.h" #include "WorldStorage/WorldStorage.h" #include "Generating/ChunkGenerator.h" -#include "Vector3i.h" -#include "Vector3f.h" +#include "Vector3.h" #include "ChunkSender.h" #include "Defines.h" #include "LightingThread.h" diff --git a/src/WorldStorage/WSSCompact.h b/src/WorldStorage/WSSCompact.h index 64b8d7f31..4df146ec3 100644 --- a/src/WorldStorage/WSSCompact.h +++ b/src/WorldStorage/WSSCompact.h @@ -12,7 +12,7 @@ #define WSSCOMPACT_H_INCLUDED #include "WorldStorage.h" -#include "../Vector3i.h" +#include "../Vector3.h" #include "json/json.h" -- cgit v1.2.3 From deafec874d87b5b1ef0dd7fb094fd7b38634a0db Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 15:14:47 +0100 Subject: Snowballs now actualy hurt other entities. 3 damage for blazes and 1 for the ender dragon. Otherwise 0 --- src/Entities/ProjectileEntity.cpp | 26 ++++++++++++++++++++++++-- src/Entities/ProjectileEntity.h | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 03bc0c99d..92890919c 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -655,8 +655,6 @@ cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, do void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { - // TODO: Apply damage to certain mobs (blaze etc.) and anger all mobs - Destroy(); } @@ -664,6 +662,30 @@ void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFac +void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + if (a_EntityHit.IsMob()) + { + cMonster::eType MobType = ((cMonster &) a_EntityHit).GetMobType(); + if (MobType == cMonster::mtBlaze) + { + TotalDamage = 3; + } + else if (MobType == cMonster::mtEnderDragon) + { + TotalDamage = 1; + } + } + a_EntityHit.TakeDamage(dtRangedAttack, m_Creator, TotalDamage, 1); + + Destroy(true); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cBottleOEnchantingEntity : diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index e80592999..840dac871 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -259,6 +259,7 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; // tolua_begin -- cgit v1.2.3 From ef3c5a97a46212a0f8cd1a05125f4b75e3f32b74 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 16:24:05 +0100 Subject: TakeDamage now has the cThrownSnowballEntity instead of the creator's object. --- src/Entities/ProjectileEntity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 92890919c..37238a0c0 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -677,7 +677,7 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & TotalDamage = 1; } } - a_EntityHit.TakeDamage(dtRangedAttack, m_Creator, TotalDamage, 1); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); } -- cgit v1.2.3 From d64db443c2d0f094c4ee098fa1ffacb2c92e5d88 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 11 Mar 2014 18:10:15 +0200 Subject: LineCoeff Doc --- src/Vector3.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Vector3.h b/src/Vector3.h index 0be52248d..8ee7a87b0 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -10,10 +10,6 @@ - - - - template // tolua_begin class Vector3 @@ -196,6 +192,11 @@ public: ); } + /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Z coord. + The result satisfies the following equation: + (*this + Result * (a_OtherEnd - *this)).z = a_Z + If the line is too close to being parallel, this function returns NO_INTERSECTION + */ inline double LineCoeffToXYPlane(const Vector3 & a_OtherEnd, T a_Z) const { if (abs(z - a_OtherEnd.z) < EPS) @@ -206,6 +207,11 @@ public: return (a_Z - z) / (a_OtherEnd.z - z); } + /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Y coord. + The result satisfies the following equation: + (*this + Result * (a_OtherEnd - *this)).y = a_Y + If the line is too close to being parallel, this function returns NO_INTERSECTION + */ inline double LineCoeffToXZPlane(const Vector3 & a_OtherEnd, T a_Y) const { if (abs(y - a_OtherEnd.y) < EPS) @@ -216,6 +222,11 @@ public: return (a_Y - y) / (a_OtherEnd.y - y); } + /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified X coord. + The result satisfies the following equation: + (*this + Result * (a_OtherEnd - *this)).x = a_X + If the line is too close to being parallel, this function returns NO_INTERSECTION + */ inline double LineCoeffToYZPlane(const Vector3 & a_OtherEnd, T a_X) const { if (abs(x - a_OtherEnd.x) < EPS) @@ -231,9 +242,14 @@ public: /** Return value of LineCoeffToPlane() if the line is parallel to the plane. */ static const double NO_INTERSECTION; + }; // tolua_end + + + + template const double Vector3::EPS = 0.000001; -- cgit v1.2.3 From 9810d57a394b2bb56fbcfddb05d34dcd504a7b35 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 11 Mar 2014 18:32:33 +0200 Subject: Unified Matrix4 code --- src/Bindings/AllToLua.pkg | 1 - src/CMakeLists.txt | 1 - src/Entities/Entity.cpp | 2 +- src/Matrix4.h | 228 ++++++++++++++++++++++++++++++++++++++++++++++ src/Matrix4f.cpp | 4 - src/Matrix4f.h | 225 --------------------------------------------- src/Vector3.h | 2 +- 7 files changed, 230 insertions(+), 233 deletions(-) create mode 100644 src/Matrix4.h delete mode 100644 src/Matrix4f.cpp delete mode 100644 src/Matrix4f.h diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 302714318..1cd7c74f8 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -63,7 +63,6 @@ $cfile "../BlockEntities/MobHeadEntity.h" $cfile "../BlockEntities/FlowerPotEntity.h" $cfile "../WebAdmin.h" $cfile "../Root.h" -$cfile "../Matrix4f.h" $cfile "../Cuboid.h" $cfile "../BoundingBox.h" $cfile "../Tracer.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04736c2d7..0f8700692 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -62,7 +62,6 @@ if (NOT MSVC) Inventory.h Item.h ItemGrid.h - Matrix4f.h Mobs/Monster.h OSSupport/File.h Root.h diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 96e8c15a5..0750ae05e 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -4,7 +4,7 @@ #include "../World.h" #include "../Server.h" #include "../Root.h" -#include "../Matrix4f.h" +#include "../Matrix4.h" #include "../ClientHandle.h" #include "../Chunk.h" #include "../Simulator/FluidSimulator.h" diff --git a/src/Matrix4.h b/src/Matrix4.h new file mode 100644 index 000000000..14ccb94fd --- /dev/null +++ b/src/Matrix4.h @@ -0,0 +1,228 @@ + +#pragma once + + + + +#include + + + + + +template +// tolua_begin +class Matrix4 +{ + + TOLUA_TEMPLATE_BIND((T, float, double)) + + // tolua_end + +public: + + T cell[16]; + + enum + { + TX=3, TY=7, TZ=11, + D0=0, D1=5, D2=10, D3=15, + SX=D0, SY=D1, SZ=D2, + W=D3 + }; + + // tolua_begin + + inline Matrix4(void) + { + Identity(); + } + + inline Matrix4(const Matrix4 & a_Rhs) + { + *this = a_Rhs; + } + + inline Matrix4 & operator = (const Matrix4 & a_Rhs) + { + for (unsigned int i = 0; i < 16; ++i) + { + cell[i] = a_Rhs.cell[i]; + } + return *this; + } + + inline T & operator [] (int a_N) + { + ASSERT(a_N < 16); + return cell[a_N]; + } + + inline void Identity() + { + cell[1] = cell[2] = cell[TX] = cell[4] = cell[6] = cell[TY] = + cell[8] = cell[9] = cell[TZ] = cell[12] = cell[13] = cell[14] = 0; + cell[D0] = cell[D1] = cell[D2] = cell[W] = 1; + } + + inline void Init(const Vector3 & a_Pos, T a_RX, T a_RY, T a_RZ) + { + Matrix4 t; + t.RotateX(a_RZ); + RotateY(a_RY); + Concatenate(t); + t.RotateZ(a_RX); + Concatenate(t); + Translate(a_Pos); + } + + inline void RotateX(T a_RX) + { + T sx = (T) sin(a_RX * M_PI / 180); + T cx = (T) cos(a_RX * M_PI / 180); + + Identity(); + + cell[5] = cx, cell[6] = sx, cell[9] = -sx, cell[10] = cx; + } + + inline void RotateY(T a_RY) + { + T sy = (T) sin(a_RY * M_PI / 180); + T cy = (T) cos(a_RY * M_PI / 180); + + Identity(); + + cell[0] = cy, cell[2] = -sy, cell[8] = sy, cell[10] = cy; + } + + inline void RotateZ(T a_RZ) + { + T sz = (T) sin(a_RZ * M_PI / 180); + T cz = (T) cos(a_RZ * M_PI / 180); + + Identity(); + + cell[0] = cz; cell[1] = sz; + cell[4] = -sz; cell[5] = cz; + } + + inline void Translate(const Vector3 & a_Pos) + { + cell[TX] += a_Pos.x; + cell[TY] += a_Pos.y; + cell[TZ] += a_Pos.z; + } + + inline void SetTranslation(const Vector3 & a_Pos) + { + cell[TX] = a_Pos.x; + cell[TY] = a_Pos.y; + cell[TZ] = a_Pos.z; + } + + inline void Concatenate(const Matrix4 & m2) + { + Matrix4 res; + + for (unsigned int c = 0; c < 4; ++c) + { + for (unsigned int r = 0; r < 4; ++r) + { + res.cell[r * 4 + c] = ( + cell[r * 4] * m2.cell[c] + + cell[r * 4 + 1] * m2.cell[c + 4] + + cell[r * 4 + 2] * m2.cell[c + 8] + + cell[r * 4 + 3] * m2.cell[c + 12] + ); + } + } + + *this = res; + } + + inline Vector3 Transform(const Vector3 & v) const + { + T x = cell[0] * v.x + cell[1] * v.y + cell[2] * v.z + cell[3]; + T y = cell[4] * v.x + cell[5] * v.y + cell[6] * v.z + cell[7]; + T z = cell[8] * v.x + cell[9] * v.y + cell[10] * v.z + cell[11]; + + return Vector3(x, y, z); + } + + inline void Invert(void) + { + Matrix4 t; + + T tx = -cell[3]; + T ty = -cell[7]; + T tz = -cell[11]; + + for (unsigned int h = 0; h < 3; ++h) + { + for (unsigned int v = 0; v < 3; ++v) + { + t.cell[h + v * 4] = cell[v + h * 4]; + } + } + + for (unsigned int i = 0; i < 11; ++i) + { + cell[i] = t.cell[i]; + } + + cell[3] = tx * cell[0] + ty * cell[1] + tz * cell[2]; + cell[7] = tx * cell[4] + ty * cell[5] + tz * cell[6]; + cell[11] = tx * cell[8] + ty * cell[9] + tz * cell[10]; + } + + inline Vector3 GetXColumn(void) const + { + return Vector3(cell[0], cell[1], cell[2]); + } + + inline Vector3 GetYColumn(void) const + { + return Vector3(cell[4], cell[5], cell[6]); + } + + inline Vector3 GetZColumn(void) const + { + return Vector3(cell[8], cell[9], cell[10]); + } + + inline void SetXColumn(const Vector3 & a_X) + { + cell[0] = a_X.x; + cell[1] = a_X.y; + cell[2] = a_X.z; + } + + inline void SetYColumn(const Vector3 & a_Y) + { + cell[4] = a_Y.x; + cell[5] = a_Y.y; + cell[6] = a_Y.z; + } + + inline void SetZColumn(const Vector3 & a_Z) + { + cell[8] = a_Z.x; + cell[9] = a_Z.y; + cell[10] = a_Z.z; + } +}; +// tolua_end + + + + +// tolua_begin +typedef Matrix4 Matrix4d; +typedef Matrix4 Matrix4f; +// tolua_end + + + + + diff --git a/src/Matrix4f.cpp b/src/Matrix4f.cpp deleted file mode 100644 index d0a407a99..000000000 --- a/src/Matrix4f.cpp +++ /dev/null @@ -1,4 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -// _X: empty file?? diff --git a/src/Matrix4f.h b/src/Matrix4f.h deleted file mode 100644 index 0e36974ad..000000000 --- a/src/Matrix4f.h +++ /dev/null @@ -1,225 +0,0 @@ -#pragma once - -#define _USE_MATH_DEFINES -#include -#include "Vector3.h" - -class Matrix4f -{ -public: - enum - { - TX=3, - TY=7, - TZ=11, - D0=0, D1=5, D2=10, D3=15, - SX=D0, SY=D1, SZ=D2, - W=D3 - }; - Matrix4f() { Identity(); } - float& operator [] ( int a_N ) { return cell[a_N]; } - void Identity() - { - cell[1] = cell[2] = cell[TX] = cell[4] = cell[6] = cell[TY] = - cell[8] = cell[9] = cell[TZ] = cell[12] = cell[13] = cell[14] = 0; - cell[D0] = cell[D1] = cell[D2] = cell[W] = 1; - } - void Init( Vector3f a_Pos, float a_RX, float a_RY, float a_RZ ) - { - Matrix4f t; - t.RotateX( a_RZ ); - RotateY( a_RY ); - Concatenate( t ); - t.RotateZ( a_RX ); - Concatenate( t ); - Translate( a_Pos ); - } - void RotateX( float a_RX ) - { - float sx = (float)sin( a_RX * M_PI / 180 ); - float cx = (float)cos( a_RX * M_PI / 180 ); - Identity(); - cell[5] = cx, cell[6] = sx, cell[9] = -sx, cell[10] = cx; - } - void RotateY( float a_RY ) - { - float sy = (float)sin( a_RY * M_PI / 180 ); - float cy = (float)cos( a_RY * M_PI / 180 ); - Identity (); - cell[0] = cy, cell[2] = -sy, cell[8] = sy, cell[10] = cy; - } - void RotateZ( float a_RZ ) - { - float sz = (float)sin( a_RZ * M_PI / 180 ); - float cz = (float)cos( a_RZ * M_PI / 180 ); - Identity (); - cell[0] = cz, cell[1] = sz, cell[4] = -sz, cell[5] = cz; - } - void Translate( Vector3f a_Pos ) { cell[TX] += a_Pos.x; cell[TY] += a_Pos.y; cell[TZ] += a_Pos.z; } - void SetTranslation( Vector3f a_Pos ) { cell[TX] = a_Pos.x; cell[TY] = a_Pos.y; cell[TZ] = a_Pos.z; } - void Concatenate( const Matrix4f& m2 ) - { - Matrix4f res; - int c; - for ( c = 0; c < 4; c++ ) for ( int r = 0; r < 4; r++ ) - res.cell[r * 4 + c] = cell[r * 4] * m2.cell[c] + - cell[r * 4 + 1] * m2.cell[c + 4] + - cell[r * 4 + 2] * m2.cell[c + 8] + - cell[r * 4 + 3] * m2.cell[c + 12]; - for ( c = 0; c < 16; c++ ) cell[c] = res.cell[c]; - } - Vector3f Transform( const Vector3f& v ) const - { - float x = cell[0] * v.x + cell[1] * v.y + cell[2] * v.z + cell[3]; - float y = cell[4] * v.x + cell[5] * v.y + cell[6] * v.z + cell[7]; - float z = cell[8] * v.x + cell[9] * v.y + cell[10] * v.z + cell[11]; - return Vector3f( x, y, z ); - } - void Invert() - { - Matrix4f t; - int h, i; - float tx = -cell[3], ty = -cell[7], tz = -cell[11]; - for ( h = 0; h < 3; h++ ) for ( int v = 0; v < 3; v++ ) t.cell[h + v * 4] = cell[v + h * 4]; - for ( i = 0; i < 11; i++ ) cell[i] = t.cell[i]; - cell[3] = tx * cell[0] + ty * cell[1] + tz * cell[2]; - cell[7] = tx * cell[4] + ty * cell[5] + tz * cell[6]; - cell[11] = tx * cell[8] + ty * cell[9] + tz * cell[10]; - } - Vector3f GetXColumn() { return Vector3f( cell[0], cell[1], cell[2] ); } - Vector3f GetYColumn() { return Vector3f( cell[4], cell[5], cell[6] ); } - Vector3f GetZColumn() { return Vector3f( cell[8], cell[9], cell[10] ); } - void SetXColumn( const Vector3f & a_X ) - { - cell[0] = a_X.x; - cell[1] = a_X.y; - cell[2] = a_X.z; - } - void SetYColumn( const Vector3f & a_Y ) - { - cell[4] = a_Y.x; - cell[5] = a_Y.y; - cell[6] = a_Y.z; - } - void SetZColumn( const Vector3f & a_Z ) - { - cell[8] = a_Z.x; - cell[9] = a_Z.y; - cell[10] = a_Z.z; - } - float cell[16]; -}; - - - - - -class Matrix4d -{ -public: - enum - { - TX=3, - TY=7, - TZ=11, - D0=0, D1=5, D2=10, D3=15, - SX=D0, SY=D1, SZ=D2, - W=D3 - }; - Matrix4d() { Identity(); } - double& operator [] ( int a_N ) { return cell[a_N]; } - void Identity() - { - cell[1] = cell[2] = cell[TX] = cell[4] = cell[6] = cell[TY] = - cell[8] = cell[9] = cell[TZ] = cell[12] = cell[13] = cell[14] = 0; - cell[D0] = cell[D1] = cell[D2] = cell[W] = 1; - } - void Init( Vector3f a_Pos, double a_RX, double a_RY, double a_RZ ) - { - Matrix4d t; - t.RotateX( a_RZ ); - RotateY( a_RY ); - Concatenate( t ); - t.RotateZ( a_RX ); - Concatenate( t ); - Translate( a_Pos ); - } - void RotateX( double a_RX ) - { - double sx = (double)sin( a_RX * M_PI / 180 ); - double cx = (double)cos( a_RX * M_PI / 180 ); - Identity(); - cell[5] = cx, cell[6] = sx, cell[9] = -sx, cell[10] = cx; - } - void RotateY( double a_RY ) - { - double sy = (double)sin( a_RY * M_PI / 180 ); - double cy = (double)cos( a_RY * M_PI / 180 ); - Identity (); - cell[0] = cy, cell[2] = -sy, cell[8] = sy, cell[10] = cy; - } - void RotateZ( double a_RZ ) - { - double sz = (double)sin( a_RZ * M_PI / 180 ); - double cz = (double)cos( a_RZ * M_PI / 180 ); - Identity (); - cell[0] = cz, cell[1] = sz, cell[4] = -sz, cell[5] = cz; - } - void Translate( Vector3d a_Pos ) { cell[TX] += a_Pos.x; cell[TY] += a_Pos.y; cell[TZ] += a_Pos.z; } - void SetTranslation( Vector3d a_Pos ) { cell[TX] = a_Pos.x; cell[TY] = a_Pos.y; cell[TZ] = a_Pos.z; } - void Concatenate( const Matrix4d & m2 ) - { - Matrix4d res; - int c; - for ( c = 0; c < 4; c++ ) for ( int r = 0; r < 4; r++ ) - res.cell[r * 4 + c] = cell[r * 4] * m2.cell[c] + - cell[r * 4 + 1] * m2.cell[c + 4] + - cell[r * 4 + 2] * m2.cell[c + 8] + - cell[r * 4 + 3] * m2.cell[c + 12]; - for ( c = 0; c < 16; c++ ) cell[c] = res.cell[c]; - } - Vector3d Transform( const Vector3d & v ) const - { - double x = cell[0] * v.x + cell[1] * v.y + cell[2] * v.z + cell[3]; - double y = cell[4] * v.x + cell[5] * v.y + cell[6] * v.z + cell[7]; - double z = cell[8] * v.x + cell[9] * v.y + cell[10] * v.z + cell[11]; - return Vector3d( x, y, z ); - } - void Invert() - { - Matrix4d t; - int h, i; - double tx = -cell[3], ty = -cell[7], tz = -cell[11]; - for ( h = 0; h < 3; h++ ) for ( int v = 0; v < 3; v++ ) t.cell[h + v * 4] = cell[v + h * 4]; - for ( i = 0; i < 11; i++ ) cell[i] = t.cell[i]; - cell[3] = tx * cell[0] + ty * cell[1] + tz * cell[2]; - cell[7] = tx * cell[4] + ty * cell[5] + tz * cell[6]; - cell[11] = tx * cell[8] + ty * cell[9] + tz * cell[10]; - } - Vector3d GetXColumn() { return Vector3d( cell[0], cell[1], cell[2] ); } - Vector3d GetYColumn() { return Vector3d( cell[4], cell[5], cell[6] ); } - Vector3d GetZColumn() { return Vector3d( cell[8], cell[9], cell[10] ); } - void SetXColumn( const Vector3d & a_X ) - { - cell[0] = a_X.x; - cell[1] = a_X.y; - cell[2] = a_X.z; - } - void SetYColumn( const Vector3d & a_Y ) - { - cell[4] = a_Y.x; - cell[5] = a_Y.y; - cell[6] = a_Y.z; - } - void SetZColumn( const Vector3d & a_Z ) - { - cell[8] = a_Z.x; - cell[9] = a_Z.y; - cell[10] = a_Z.z; - } - double cell[16]; -} ; - - - - diff --git a/src/Vector3.h b/src/Vector3.h index 8ee7a87b0..841c3e7d1 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -22,7 +22,7 @@ public: T x, y, z; - inline Vector3() : x(0), y(0), z(0) {} + inline Vector3(void) : x(0), y(0), z(0) {} inline Vector3(T a_x, T a_y, T a_z) : x(a_x), y(a_y), z(a_z) {} -- cgit v1.2.3 From 728870ed9dd8231fe493863d6cb51766c5b244ca Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 12:35:44 -0700 Subject: Fixed Warnings in PieceGenerator --- src/Generating/PieceGenerator.cpp | 14 +++++++------- src/Generating/PieceGenerator.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index e3de5b951..8fcc14389 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -31,14 +31,14 @@ public: Gen.PlacePieces(500, 50, 500, 3, OutPieces); // Print out the pieces: - printf("OutPieces.size() = %u\n", OutPieces.size()); + printf("OutPieces.size() = %zu\n", OutPieces.size()); size_t idx = 0; for (cPlacedPieces::const_iterator itr = OutPieces.begin(), end = OutPieces.end(); itr != end; ++itr, ++idx) { const Vector3i & Coords = (*itr)->GetCoords(); cCuboid Hitbox = (*itr)->GetHitBox(); Hitbox.Sort(); - printf("%u: {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx, + printf("%zu: {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx, Coords.x, Coords.y, Coords.z, (*itr)->GetNumCCWRotations(), Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z, @@ -183,7 +183,6 @@ cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, i cPiece::cConnector res(a_Connector); // Rotate the res connector: - Vector3i Size = GetSize(); switch (a_NumCCWRotations) { case 0: @@ -338,7 +337,7 @@ cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, i // Choose a random supported rotation: int Rotations[4] = {0}; int NumRotations = 1; - for (int i = 1; i < ARRAYCOUNT(Rotations); i++) + for (size_t i = 1; i < ARRAYCOUNT(Rotations); i++) { if (StartingPiece->CanRotateCCW(i)) { @@ -378,7 +377,7 @@ bool cPieceGenerator::TryPlacePieceAtConnector( static const int DirectionRotationTable[6][6] = { /* YM, YP, ZM, ZP, XM, XP - /* YM */ { 0, 0, 0, 0, 0, 0}, + YM */ { 0, 0, 0, 0, 0, 0}, /* YP */ { 0, 0, 0, 0, 0, 0}, /* ZM */ { 0, 0, 2, 0, 1, 3}, /* ZP */ { 0, 0, 0, 2, 3, 1}, @@ -503,11 +502,12 @@ bool cPieceGenerator::CheckConnection( // DEBUG: void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed) { - printf(" Connector pool: %u items\n", a_ConnectorPool.size() - a_NumProcessed); + printf(" Connector pool: %zu items\n", a_ConnectorPool.size() - a_NumProcessed); size_t idx = 0; for (cPieceGenerator::cFreeConnectors::const_iterator itr = a_ConnectorPool.begin() + a_NumProcessed, end = a_ConnectorPool.end(); itr != end; ++itr, ++idx) { - printf(" %u: {%d, %d, %d}, type %d, direction %s, depth %d\n", + // Format specifier for size_t is zu + printf(" %zu: {%d, %d, %d}, type %d, direction %s, depth %d\n", idx, itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z, itr->m_Connector.m_Type, diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h index 9dd5bcfba..3386d7a94 100644 --- a/src/Generating/PieceGenerator.h +++ b/src/Generating/PieceGenerator.h @@ -122,9 +122,9 @@ public: const cPiece & GetPiece (void) const { return *m_Piece; } const Vector3i & GetCoords (void) const { return m_Coords; } - const int GetNumCCWRotations(void) const { return m_NumCCWRotations; } + int GetNumCCWRotations(void) const { return m_NumCCWRotations; } const cCuboid & GetHitBox (void) const { return m_HitBox; } - const int GetDepth (void) const { return m_Depth; } + int GetDepth (void) const { return m_Depth; } protected: const cPlacedPiece * m_Parent; -- cgit v1.2.3 From 0fc4a1ee06199db80edd4a9f79a4ba1c4369f656 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 12:36:51 -0700 Subject: Move comment --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index d9308f603..25310c368 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -187,8 +187,8 @@ macro(set_exe_flags) # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") - # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math add_flags_cxx("-D__extern_always_inline=inline") add_flags_cxx("-Werror -Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation") -- cgit v1.2.3 From 80cc824c0cf8634439dfb3913cf17af714b03d99 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 12:41:18 -0700 Subject: Fixed Chunkdef warnings --- src/ChunkDef.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 5dd64e1b5..61ad49ad0 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -112,7 +112,7 @@ public: } - inline static unsigned int MakeIndex(int x, int y, int z ) + inline static int MakeIndex(int x, int y, int z ) { if ( (x < Width) && (x > -1) && @@ -271,7 +271,7 @@ public: } int Index = MakeIndexNoCheck(x, y, z); - a_Buffer[Index / 2] = ( + a_Buffer[Index / 2] = static_cast( (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set ); -- cgit v1.2.3 From bb4b35e438a77ff45cded8938e1e3e2724a1587e Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 12:54:46 -0700 Subject: Rollback submodule change --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 3b416b07a..013a32a7f 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 3b416b07a339b3abcbc127070d56eea05b05373d +Subproject commit 013a32a7fb3c8a6cfe0aef892d4c7394d4e1be59 -- cgit v1.2.3 From abf4effaaf0eff1a98e005512f805211c2fad9a7 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 11 Mar 2014 21:58:50 +0200 Subject: Matrix4: Removed enum --- src/Matrix4.h | 40 ++++++++++++++++++---------------------- src/Vector3.h | 6 ++++++ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/Matrix4.h b/src/Matrix4.h index 14ccb94fd..a20c019e9 100644 --- a/src/Matrix4.h +++ b/src/Matrix4.h @@ -23,14 +23,6 @@ public: T cell[16]; - enum - { - TX=3, TY=7, TZ=11, - D0=0, D1=5, D2=10, D3=15, - SX=D0, SY=D1, SZ=D2, - W=D3 - }; - // tolua_begin inline Matrix4(void) @@ -60,9 +52,11 @@ public: inline void Identity() { - cell[1] = cell[2] = cell[TX] = cell[4] = cell[6] = cell[TY] = - cell[8] = cell[9] = cell[TZ] = cell[12] = cell[13] = cell[14] = 0; - cell[D0] = cell[D1] = cell[D2] = cell[W] = 1; + cell[1] = cell[2] = cell[3] = cell[4] = 0; + cell[6] = cell[7] = cell[8] = cell[9] = 0; + cell[11] = cell[12] = cell[13] = cell[14] = 0; + + cell[0] = cell[5] = cell[10] = cell[15] = 1; } inline void Init(const Vector3 & a_Pos, T a_RX, T a_RY, T a_RZ) @@ -83,7 +77,8 @@ public: Identity(); - cell[5] = cx, cell[6] = sx, cell[9] = -sx, cell[10] = cx; + cell[5] = cx; cell[6] = sx; + cell[9] = -sx; cell[10] = cx; } inline void RotateY(T a_RY) @@ -93,7 +88,8 @@ public: Identity(); - cell[0] = cy, cell[2] = -sy, cell[8] = sy, cell[10] = cy; + cell[0] = cy; cell[2] = -sy; + cell[8] = sy; cell[10] = cy; } inline void RotateZ(T a_RZ) @@ -109,16 +105,16 @@ public: inline void Translate(const Vector3 & a_Pos) { - cell[TX] += a_Pos.x; - cell[TY] += a_Pos.y; - cell[TZ] += a_Pos.z; + cell[3] += a_Pos.x; + cell[7] += a_Pos.y; + cell[11] += a_Pos.z; } inline void SetTranslation(const Vector3 & a_Pos) { - cell[TX] = a_Pos.x; - cell[TY] = a_Pos.y; - cell[TZ] = a_Pos.z; + cell[3] = a_Pos.x; + cell[7] = a_Pos.y; + cell[11] = a_Pos.z; } inline void Concatenate(const Matrix4 & m2) @@ -130,7 +126,7 @@ public: for (unsigned int r = 0; r < 4; ++r) { res.cell[r * 4 + c] = ( - cell[r * 4] * m2.cell[c] + + cell[r * 4 + 0] * m2.cell[c + 0] + cell[r * 4 + 1] * m2.cell[c + 4] + cell[r * 4 + 2] * m2.cell[c + 8] + cell[r * 4 + 3] * m2.cell[c + 12] @@ -207,8 +203,8 @@ public: inline void SetZColumn(const Vector3 & a_Z) { - cell[8] = a_Z.x; - cell[9] = a_Z.y; + cell[8] = a_Z.x; + cell[9] = a_Z.y; cell[10] = a_Z.z; } }; diff --git a/src/Vector3.h b/src/Vector3.h index 841c3e7d1..79c47ae77 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -26,6 +26,12 @@ public: inline Vector3(T a_x, T a_y, T a_z) : x(a_x), y(a_y), z(a_z) {} + // Hardcoded copy constructors (tolua++ does not support function templates .. yet) + Vector3(const Vector3 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} + Vector3(const Vector3 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} + Vector3(const Vector3 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} + + // tolua_end template Vector3(const Vector3<_T> & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} -- cgit v1.2.3 From 53faac10c50ba88ce540e0464123f388bd7db069 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 13:41:15 -0700 Subject: Added macros to follow format string checking through wrappers --- src/Globals.h | 4 ++++ src/OSSupport/File.h | 2 +- src/StringUtils.h | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Globals.h b/src/Globals.h index 2cd160677..e907614d7 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -38,6 +38,8 @@ // No alignment needed in MSVC #define ALIGN_8 #define ALIGN_16 + + #define FORMATSTRING(formatIndex,va_argsIndex) #elif defined(__GNUC__) @@ -56,6 +58,8 @@ // Some portability macros :) #define stricmp strcasecmp + + #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) #else diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index 07fce6661..e229035b7 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -131,7 +131,7 @@ public: /** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */ static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp - int Printf(const char * a_Fmt, ...); + int Printf(const char * a_Fmt, ...) FORMATSTRING(2,3); /** Flushes all the bufferef output into the file (only when writing) */ void Flush(void); diff --git a/src/StringUtils.h b/src/StringUtils.h index b64108409..a7f22b100 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -22,13 +22,13 @@ typedef std::list AStringList; /** Add the formated string to the existing data in the string */ -extern AString & AppendVPrintf(AString & str, const char * format, va_list args); +extern AString & AppendVPrintf(AString & str, const char * format, va_list args) FORMATSTRING(2,0); /// Output the formatted text into the string -extern AString & Printf (AString & str, const char * format, ...); +extern AString & Printf (AString & str, const char * format, ...) FORMATSTRING(2,3); /// Output the formatted text into string, return string by value -extern AString Printf(const char * format, ...); +extern AString Printf(const char * format, ...) FORMATSTRING(1,2); /// Add the formatted string to the existing data in the string extern AString & AppendPrintf (AString & str, const char * format, ...); -- cgit v1.2.3 From f64f8790274c4ee63b4eb904110bd35f93652d78 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 13:46:32 -0700 Subject: Fixed format errors in protocol --- src/Protocol/Protocol17x.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 8c800036e..e76c0fe49 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1251,7 +1251,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); AString Hex; CreateHexDump(Hex, AllData.data(), AllData.size(), 16); - m_CommLogFile.Printf("Incoming data, %d (0x%x) unparsed bytes already present in buffer:\n%s\n", + m_CommLogFile.Printf("Incoming data, %zu (0x%zx) unparsed bytes already present in buffer:\n%s\n", AllData.size(), AllData.size(), Hex.c_str() ); } @@ -1351,7 +1351,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) // Put a message in the comm log: if (g_ShouldLogCommIn) { - m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %d left) ^^^^^^\n\n\n", + m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %zu left) ^^^^^^\n\n\n", 1, bb.GetReadableSpace() ); m_CommLogFile.Flush(); @@ -1373,7 +1373,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); AString Hex; CreateHexDump(Hex, AllData.data(), AllData.size(), 16); - m_CommLogFile.Printf("There are %d (0x%x) bytes of non-parse-able data left in the buffer:\n%s", + m_CommLogFile.Printf("There are %zu (0x%zx) bytes of non-parse-able data left in the buffer:\n%s", m_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str() ); m_CommLogFile.Flush(); -- cgit v1.2.3 From a19f5fc484648d226899667410aeb82de354c714 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 13:51:56 -0700 Subject: Move Format issues --- src/CommandOutput.h | 2 +- src/Log.cpp | 2 +- src/Log.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/CommandOutput.h b/src/CommandOutput.h index 3763d625f..81d9ddb84 100644 --- a/src/CommandOutput.h +++ b/src/CommandOutput.h @@ -17,7 +17,7 @@ public: virtual ~cCommandOutputCallback() {}; // Force a virtual destructor in subclasses /// Syntax sugar function, calls Out() with Printf()-ed parameters; appends a "\n" - void Out(const char * a_Fmt, ...); + void Out(const char * a_Fmt, ...) FORMATSTRING(2,3); /// Called when the command wants to output anything; may be called multiple times virtual void Out(const AString & a_Text) = 0; diff --git a/src/Log.cpp b/src/Log.cpp index 1ea327d5d..54e2b7812 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -118,7 +118,7 @@ void cLog::Log(const char * a_Format, va_list argList) AString Line; #ifdef _DEBUG - Printf(Line, "[%04x|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); + Printf(Line, "[%04zu|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #else Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #endif diff --git a/src/Log.h b/src/Log.h index cba248dae..340fa23bc 100644 --- a/src/Log.h +++ b/src/Log.h @@ -14,8 +14,8 @@ private: public: cLog(const AString & a_FileName); ~cLog(); - void Log(const char * a_Format, va_list argList); - void Log(const char * a_Format, ...); + void Log(const char * a_Format, va_list argList) FORMATSTRING(2,0); + void Log(const char * a_Format, ...) FORMATSTRING(2,3); // tolua_begin void SimpleLog(const char * a_String); void OpenLog(const char * a_FileName); -- cgit v1.2.3 From 16b27c4b7ae2ccb03355148fa7fc7116190cc5fb Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 14:16:08 -0700 Subject: Fixed a load of format string errors --- src/Bindings/LuaState.cpp | 4 +++- src/ClientHandle.cpp | 2 +- src/CommandOutput.cpp | 4 ++-- src/CraftingRecipes.cpp | 2 +- src/FurnaceRecipe.cpp | 2 +- src/Generating/ChunkGenerator.cpp | 4 ++-- src/Item.cpp | 8 ++++---- src/MCLogger.h | 8 ++++---- src/OSSupport/SocketThreads.cpp | 2 +- src/Protocol/Protocol132.cpp | 2 +- src/Protocol/Protocol17x.cpp | 6 +++--- src/UI/Window.cpp | 2 +- src/WorldStorage/WSSCompact.cpp | 10 +++++----- 13 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index aa6ee05b3..2351f0c24 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1281,7 +1281,9 @@ void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header) { UNUSED(a_Header); // The param seems unused when compiling for release, so the compiler warns - LOGD((a_Header != NULL) ? a_Header : "Lua C API Stack contents:"); + + // Format string consisting only of %s is used to appease the compiler + LOGD("%s",(a_Header != NULL) ? a_Header : "Lua C API Stack contents:"); for (int i = lua_gettop(a_LuaState); i > 0; i--) { AString Value; diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index df728e83b..02b2e1c47 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -882,7 +882,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo LOGD("Prevented a dig/aim bug in the client (finish {%d, %d, %d} vs start {%d, %d, %d}, HSD: %s)", a_BlockX, a_BlockY, a_BlockZ, m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ, - m_HasStartedDigging + (m_HasStartedDigging ? "True" : "False") ); return; } diff --git a/src/CommandOutput.cpp b/src/CommandOutput.cpp index c221682a1..74f857284 100644 --- a/src/CommandOutput.cpp +++ b/src/CommandOutput.cpp @@ -51,7 +51,7 @@ void cLogCommandOutputCallback::Finished(void) { case '\n': { - LOG(m_Buffer.substr(last, i - last).c_str()); + LOG("%s",m_Buffer.substr(last, i - last).c_str()); last = i + 1; break; } @@ -59,7 +59,7 @@ void cLogCommandOutputCallback::Finished(void) } // for i - m_Buffer[] if (last < len) { - LOG(m_Buffer.substr(last).c_str()); + LOG("%s",m_Buffer.substr(last).c_str()); } // Clear the buffer for the next command output: diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index be9f45caa..30f21686c 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -340,7 +340,7 @@ void cCraftingRecipes::LoadRecipes(void) } AddRecipeLine(LineNum, Recipe); } // for itr - Split[] - LOG("Loaded %d crafting recipes", m_Recipes.size()); + LOG("Loaded %zu crafting recipes", m_Recipes.size()); } diff --git a/src/FurnaceRecipe.cpp b/src/FurnaceRecipe.cpp index 2e2276981..dd2f259f3 100644 --- a/src/FurnaceRecipe.cpp +++ b/src/FurnaceRecipe.cpp @@ -175,7 +175,7 @@ void cFurnaceRecipe::ReloadRecipes(void) { LOGERROR("ERROR: FurnaceRecipe, syntax error" ); } - LOG("Loaded %u furnace recipes and %u fuels", m_pState->Recipes.size(), m_pState->Fuel.size()); + LOG("Loaded %zu furnace recipes and %zu fuels", m_pState->Recipes.size(), m_pState->Fuel.size()); } diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index ef38f1399..92f6009ac 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -116,7 +116,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk // Add to queue, issue a warning if too many: if (m_Queue.size() >= QUEUE_WARNING_LIMIT) { - LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (%i)", a_ChunkX, a_ChunkZ, m_Queue.size()); + LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (%zu)", a_ChunkX, a_ChunkZ, m_Queue.size()); } m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); } @@ -180,7 +180,7 @@ BLOCKTYPE cChunkGenerator::GetIniBlock(cIniFile & a_IniFile, const AString & a_S BLOCKTYPE Block = BlockStringToType(BlockType); if (Block < 0) { - LOGWARN("[&s].%s Could not parse block value \"%s\". Using default: \"%s\".", a_SectionName.c_str(), a_ValueName.c_str(), BlockType.c_str(),a_Default.c_str()); + LOGWARN("[%s].%s Could not parse block value \"%s\". Using default: \"%s\".", a_SectionName.c_str(), a_ValueName.c_str(), BlockType.c_str(),a_Default.c_str()); return BlockStringToType(a_Default); } return Block; diff --git a/src/Item.cpp b/src/Item.cpp index 61d57e763..c8dda209c 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -216,7 +216,7 @@ cItem * cItems::Get(int a_Idx) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently %d items. Returning a nil.", a_Idx, size()); + LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently %zu items. Returning a nil.", a_Idx, size()); return NULL; } return &at(a_Idx); @@ -230,7 +230,7 @@ void cItems::Set(int a_Idx, const cItem & a_Item) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %d items. Not setting.", a_Idx, size()); + LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size()); return; } at(a_Idx) = a_Item; @@ -244,7 +244,7 @@ void cItems::Delete(int a_Idx) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %d items. Ignoring.", a_Idx, size()); + LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %zu items. Ignoring.", a_Idx, size()); return; } erase(begin() + a_Idx); @@ -258,7 +258,7 @@ void cItems::Set(int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDama { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %d items. Not setting.", a_Idx, size()); + LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size()); return; } at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage); diff --git a/src/MCLogger.h b/src/MCLogger.h index c949a4cdf..348b51242 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -57,10 +57,10 @@ private: -extern void LOG(const char* a_Format, ...); -extern void LOGINFO(const char* a_Format, ...); -extern void LOGWARN(const char* a_Format, ...); -extern void LOGERROR(const char* a_Format, ...); +extern void LOG(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1,2); diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp index a02661d2c..f37b00202 100644 --- a/src/OSSupport/SocketThreads.cpp +++ b/src/OSSupport/SocketThreads.cpp @@ -54,7 +54,7 @@ bool cSocketThreads::AddClient(const cSocket & a_Socket, cCallback * a_Client) } // No thread has free space, create a new one: - LOGD("Creating a new cSocketThread (currently have %d)", m_Threads.size()); + LOGD("Creating a new cSocketThread (currently have %zu)", m_Threads.size()); cSocketThread * Thread = new cSocketThread(this); if (!Thread->Start()) { diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index 8df550c7b..43fe90616 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -100,7 +100,7 @@ cProtocol132::~cProtocol132() { if (!m_DataToSend.empty()) { - LOGD("There are %d unsent bytes while deleting cProtocol132", m_DataToSend.size()); + LOGD("There are %zu unsent bytes while deleting cProtocol132", m_DataToSend.size()); } } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index e76c0fe49..9e5fe53fb 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1344,7 +1344,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) if (bb.GetReadableSpace() != 1) { // Read more or less than packet length, report as error - LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read %u bytes, packet contained %u bytes", + LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read %zu bytes, packet contained %u bytes", PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen ); @@ -2062,7 +2062,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) { AString HexDump; CreateHexDump(HexDump, a_Metadata.data(), a_Metadata.size(), 16); - LOGWARNING("Cannot unGZIP item metadata (%u bytes):\n%s", a_Metadata.size(), HexDump.c_str()); + LOGWARNING("Cannot unGZIP item metadata (%zu bytes):\n%s", a_Metadata.size(), HexDump.c_str()); return; } @@ -2072,7 +2072,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) { AString HexDump; CreateHexDump(HexDump, Uncompressed.data(), Uncompressed.size(), 16); - LOGWARNING("Cannot parse NBT item metadata: (%u bytes)\n%s", Uncompressed.size(), HexDump.c_str()); + LOGWARNING("Cannot parse NBT item metadata: (%zu bytes)\n%s", Uncompressed.size(), HexDump.c_str()); return; } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 1a8456f70..5249a4bca 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -637,7 +637,7 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int { if ((size_t)(a_Item.m_ItemCount) < a_SlotNums.size()) { - LOGWARNING("%s: Distributing less items (%d) than slots (%u)", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size()); + LOGWARNING("%s: Distributing less items (%d) than slots (%zu)", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size()); // This doesn't seem to happen with the 1.5.1 client, so we don't worry about it for now return 0; } diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 1e84fb4ad..b1e8d12b7 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -569,7 +569,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2() if( ChunksConverted % 32 == 0 ) { - LOGINFO("Updating \"%s\" version 1 to version 2: %d %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); + LOGINFO("Updating \"%s\" version 1 to version 2: %zu %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); } ChunksConverted++; @@ -607,7 +607,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2() if (UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %d) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", UncompressedSize, UncompressedData.size(), Header->m_ChunkX, Header->m_ChunkZ ); @@ -713,7 +713,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() if( ChunksConverted % 32 == 0 ) { - LOGINFO("Updating \"%s\" version 2 to version 3: %d %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); + LOGINFO("Updating \"%s\" version 2 to version 3: %zu %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); } ChunksConverted++; @@ -751,7 +751,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() if (UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %d) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", UncompressedSize, UncompressedData.size(), Header->m_ChunkX, Header->m_ChunkZ ); @@ -866,7 +866,7 @@ bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_Uncomp if (a_UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %d) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", a_UncompressedSize, UncompressedData.size(), a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ ); -- cgit v1.2.3 From 7e6ee7ef8158a037c11405986513aa344ce68f42 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 14:43:14 -0700 Subject: Fixed more Format issues --- src/ByteBuffer.cpp | 2 +- src/MCLogger.h | 14 +++++++------- src/Root.cpp | 10 +++++----- src/Server.cpp | 2 +- src/StringUtils.h | 2 +- src/World.cpp | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 9d97d8614..d3bcfe866 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -459,7 +459,7 @@ bool cByteBuffer::ReadVarUTF8String(AString & a_Value) } if (Size > MAX_STRING_SIZE) { - LOGWARNING("%s: String too large: %llu (%llu KiB)", __FUNCTION__, Size, Size / 1024); + LOGWARNING("%s: String too large: %u (%u KiB)", __FUNCTION__, Size, Size / 1024); } return ReadString(a_Value, (int)Size); } diff --git a/src/MCLogger.h b/src/MCLogger.h index 348b51242..ba9e4827f 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -21,10 +21,10 @@ public: // tolua_export ~cMCLogger(); // tolua_export - void Log(const char* a_Format, va_list a_ArgList); - void Info(const char* a_Format, va_list a_ArgList); - void Warn(const char* a_Format, va_list a_ArgList); - void Error(const char* a_Format, va_list a_ArgList); + void Log(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); + void Info(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); + void Warn(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); + void Error(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); void LogSimple(const char* a_Text, int a_LogType = 0 ); // tolua_export @@ -57,9 +57,9 @@ private: -extern void LOG(const char* a_Format, ...) FORMATSTRING(1,2); -extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1,2); -extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOG(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1,2); extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1,2); diff --git a/src/Root.cpp b/src/Root.cpp index 69f18104e..9a5dcac71 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -778,11 +778,11 @@ void cRoot::LogChunkStats(cCommandOutputCallback & a_Output) int Mem = NumValid * sizeof(cChunk); a_Output.Out(" Memory used by chunks: %d KiB (%d MiB)", (Mem + 1023) / 1024, (Mem + 1024 * 1024 - 1) / (1024 * 1024)); a_Output.Out(" Per-chunk memory size breakdown:"); - a_Output.Out(" block types: %6d bytes (%3d KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024); - a_Output.Out(" block metadata: %6d bytes (%3d KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); - a_Output.Out(" block lighting: %6d bytes (%3d KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); - a_Output.Out(" heightmap: %6d bytes (%3d KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024); - a_Output.Out(" biomemap: %6d bytes (%3d KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024); + a_Output.Out(" block types: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024); + a_Output.Out(" block metadata: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); + a_Output.Out(" block lighting: %6zu bytes (%3zu KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); + a_Output.Out(" heightmap: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024); + a_Output.Out(" biomemap: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024); int Rest = sizeof(cChunk) - sizeof(cChunkDef::BlockTypes) - 3 * sizeof(cChunkDef::BlockNibbles) - sizeof(cChunkDef::HeightMap) - sizeof(cChunkDef::BiomeMap); a_Output.Out(" other: %6d bytes (%3d KiB)", Rest, (Rest + 1023) / 1024); SumNumValid += NumValid; diff --git a/src/Server.cpp b/src/Server.cpp index fcbcaa919..194195136 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -550,7 +550,7 @@ void cServer::PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & for (AStringPairs::const_iterator itr = Callback.m_Commands.begin(), end = Callback.m_Commands.end(); itr != end; ++itr) { const AStringPair & cmd = *itr; - a_Output.Out(Printf("%-*s%s\n", Callback.m_MaxLen, cmd.first.c_str(), cmd.second.c_str())); + a_Output.Out(Printf("%-*s%s\n", static_cast(Callback.m_MaxLen), cmd.first.c_str(), cmd.second.c_str())); } // for itr - Callback.m_Commands[] a_Output.Finished(); } diff --git a/src/StringUtils.h b/src/StringUtils.h index a7f22b100..728ce31e6 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -31,7 +31,7 @@ extern AString & Printf (AString & str, const char * format, ...) FORMATST extern AString Printf(const char * format, ...) FORMATSTRING(1,2); /// Add the formatted string to the existing data in the string -extern AString & AppendPrintf (AString & str, const char * format, ...); +extern AString & AppendPrintf (AString & str, const char * format, ...) FORMATSTRING(2,3); /// Split the string at any of the listed delimiters, return as a stringvector extern AStringVector StringSplit(const AString & str, const AString & delim); diff --git a/src/World.cpp b/src/World.cpp index a9db6bf00..520ed9ae7 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -103,7 +103,7 @@ protected: { for (;;) { - LOG("%d chunks to load, %d chunks to generate", + LOG("%zu chunks to load, %d chunks to generate", m_World->GetStorage().GetLoadQueueLength(), m_World->GetGenerator().GetQueueLength() ); @@ -155,7 +155,7 @@ protected: { for (;;) { - LOG("%d chunks remaining to light", m_Lighting->GetQueueLength() + LOG("%zu chunks remaining to light", m_Lighting->GetQueueLength() ); // Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish -- cgit v1.2.3 From 9c6ca5a3edcfbcd1e9a18eec463ce7702770ceb2 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 14:43:56 -0700 Subject: made format-nonliteral an error --- SetFlags.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 25310c368..42cfa6769 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -199,7 +199,6 @@ macro(set_exe_flags) add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef") - add_flags_cxx("-Wno-error=format-nonliteral") endif() endif() -- cgit v1.2.3 From 3d15319e3c125507e48a66b3cdbb30feeaa652c1 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 15:55:37 -0700 Subject: Added macros support to tools --- Tools/MCADefrag/Globals.h | 5 ++++- Tools/ProtoProxy/Globals.h | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Tools/MCADefrag/Globals.h b/Tools/MCADefrag/Globals.h index 6f4bbdc76..0f31de7e3 100644 --- a/Tools/MCADefrag/Globals.h +++ b/Tools/MCADefrag/Globals.h @@ -37,7 +37,8 @@ // Some portability macros :) #define stricmp strcasecmp - + + #define FORMATSTRING(formatIndex,va_argsIndex) #else #error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler" @@ -58,6 +59,8 @@ #define ALIGN_8 #define ALIGN_16 */ + + #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) #endif diff --git a/Tools/ProtoProxy/Globals.h b/Tools/ProtoProxy/Globals.h index 547903e7a..0724d3a52 100644 --- a/Tools/ProtoProxy/Globals.h +++ b/Tools/ProtoProxy/Globals.h @@ -37,6 +37,8 @@ // Some portability macros :) #define stricmp strcasecmp + + #define FORMATSTRING(formatIndex,va_argsIndex) #else @@ -59,6 +61,9 @@ #define ALIGN_16 */ + #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) + + #endif @@ -233,4 +238,4 @@ public: #define LOGERROR printf #define LOGINFO printf -#define LOGWARNING printf \ No newline at end of file +#define LOGWARNING printf -- cgit v1.2.3 From 0c15fdf7b05ee6ad0705b2a789f6b709bbde2733 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 13:05:28 +0100 Subject: Moved Lua API registering into a separate function. This will allow us to use Lua as lite-config files as well, should we want to. --- src/Bindings/LuaState.cpp | 10 +++++++++- src/Bindings/LuaState.h | 7 ++++++- src/Bindings/PluginLua.cpp | 1 + src/WebAdmin.cpp | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index aa6ee05b3..1f0549a59 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -94,12 +94,20 @@ void cLuaState::Create(void) } m_LuaState = lua_open(); luaL_openlibs(m_LuaState); + m_IsOwned = true; +} + + + + + +void cLuaState::RegisterAPILibs(void) +{ tolua_AllToLua_open(m_LuaState); ManualBindings::Bind(m_LuaState); DeprecatedBindings::Bind(m_LuaState); luaopen_lsqlite3(m_LuaState); luaopen_lxp(m_LuaState); - m_IsOwned = true; } diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 4a7a6fadb..1495c72f0 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -139,9 +139,14 @@ public: /** Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions */ operator lua_State * (void) { return m_LuaState; } - /** Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor */ + /** Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor. + The regular Lua libs are registered, but the MCS API is not registered (so that Lua can be used as + lite-config as well), use RegisterAPILibs() to do that. */ void Create(void); + /** Registers all the API libraries that MCS provides into m_LuaState. */ + void RegisterAPILibs(void); + /** Closes the m_LuaState, if not closed already */ void Close(void); diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 45c8216be..cccbc3c93 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -75,6 +75,7 @@ bool cPluginLua::Initialize(void) if (!m_LuaState.IsValid()) { m_LuaState.Create(); + m_LuaState.RegisterAPILibs(); // Inject the identification global variables into the state: lua_pushlightuserdata(m_LuaState, this); diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp index e88de5947..402cd3035 100644 --- a/src/WebAdmin.cpp +++ b/src/WebAdmin.cpp @@ -127,6 +127,7 @@ bool cWebAdmin::Start(void) // Initialize the WebAdmin template script and load the file m_TemplateScript.Create(); + m_TemplateScript.RegisterAPILibs(); if (!m_TemplateScript.LoadFile(FILE_IO_PREFIX "webadmin/template.lua")) { LOGWARN("Could not load WebAdmin template \"%s\", using default template.", FILE_IO_PREFIX "webadmin/template.lua"); -- cgit v1.2.3 From a7f9df24d4537a0c7567fa5bbc9e62bb4ef16e56 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 13:11:34 +0100 Subject: The entire unknown command is echoed back to the user on error. --- src/Bindings/PluginManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index c7df6357e..b9cf160c4 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -248,7 +248,7 @@ bool cPluginManager::CallHookChat(cPlayer * a_Player, AString & a_Message) { AStringVector Split(StringSplit(a_Message, " ")); ASSERT(!Split.empty()); // This should not happen - we know there's at least one char in the message so the split needs to be at least one item long - a_Player->SendMessageInfo(Printf("Unknown command: \"%s\"", Split[0].c_str())); + a_Player->SendMessageInfo(Printf("Unknown command: \"%s\"", a_Message.c_str())); LOGINFO("Player %s issued an unknown command: \"%s\"", a_Player->GetName().c_str(), a_Message.c_str()); return true; // Cancel sending } -- cgit v1.2.3 From 5d7df54e35e99d41f69a44c5ea9c78a98fb557d0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 14:11:28 +0100 Subject: Fixed Lua string return values. Fixes #773. --- src/Bindings/LuaState.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 1f0549a59..dfc428bbc 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -742,10 +742,6 @@ void cLuaState::GetStackValue(int a_StackPos, AString & a_Value) { a_Value.assign(data, len); } - else - { - a_Value.clear(); - } } -- cgit v1.2.3 From a3a94436dcc1cc95c1476c8a88400b16ac279e71 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 12 Mar 2014 15:13:19 +0200 Subject: Vector3: Length() should always return a float --- src/Vector3.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Vector3.h b/src/Vector3.h index 79c47ae77..80583879a 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -27,9 +27,9 @@ public: // Hardcoded copy constructors (tolua++ does not support function templates .. yet) - Vector3(const Vector3 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} - Vector3(const Vector3 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} - Vector3(const Vector3 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} + Vector3(const Vector3 & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {} + Vector3(const Vector3 & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {} + Vector3(const Vector3 & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {} // tolua_end @@ -50,7 +50,7 @@ public: inline void Normalize(void) { - T Len = 1.0 / Length(); + double Len = 1.0 / Length(); x *= Len; y *= Len; @@ -59,7 +59,7 @@ public: inline Vector3 NormalizeCopy(void) const { - T Len = 1.0 / Length(); + double Len = 1.0 / Length(); return Vector3( x * Len, @@ -70,7 +70,7 @@ public: inline void NormalizeCopy(Vector3 & a_Rhs) const { - T Len = 1.0 / Length(); + double Len = 1.0 / Length(); a_Rhs.Set( x * Len, @@ -79,12 +79,12 @@ public: ); } - inline T Length(void) const + inline double Length(void) const { - return sqrt(x * x + y * y + z * z); + return sqrt((double)(x * x + y * y + z * z)); } - inline T SqrLength(void) const + inline double SqrLength(void) const { return x * x + y * y + z * z; } -- cgit v1.2.3 From 6f2bb0ad44592ac42334dc627afd3ad734b7a4ab Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 12 Mar 2014 16:13:03 +0200 Subject: M_PI MSVC Fix --- src/Matrix4.h | 2 +- src/Vector3.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Matrix4.h b/src/Matrix4.h index a20c019e9..456677f0f 100644 --- a/src/Matrix4.h +++ b/src/Matrix4.h @@ -3,7 +3,7 @@ - +#define _USE_MATH_DEFINES // Enable non-standard math defines (MSVC) #include diff --git a/src/Vector3.h b/src/Vector3.h index 80583879a..b7a810fc5 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -3,7 +3,7 @@ - +#define _USE_MATH_DEFINES // Enable non-standard math defines (MSVC) #include -- cgit v1.2.3 From 4a883be428ef1d8b22887eeb52736529658c7fd2 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 12 Mar 2014 16:30:57 +0200 Subject: Vector3: More casts --- src/Vector3.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Vector3.h b/src/Vector3.h index b7a810fc5..ba4abe3eb 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -52,9 +52,9 @@ public: { double Len = 1.0 / Length(); - x *= Len; - y *= Len; - z *= Len; + x = (T)(x * Len); + y = (T)(y * Len); + z = (T)(z * Len); } inline Vector3 NormalizeCopy(void) const @@ -62,9 +62,9 @@ public: double Len = 1.0 / Length(); return Vector3( - x * Len, - y * Len, - z * Len + (T)(x * Len), + (T)(y * Len), + (T)(z * Len) ); } @@ -73,9 +73,9 @@ public: double Len = 1.0 / Length(); a_Rhs.Set( - x * Len, - y * Len, - z * Len + (T)(x * Len), + (T)(y * Len), + (T)(z * Len) ); } -- cgit v1.2.3 From d545be9614e9d6717d19794ea8a49b6d4a0da52f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 15:33:28 +0100 Subject: Fixed missing comment terminator. --- src/Generating/PieceGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index e3de5b951..cf5ab6226 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -377,7 +377,7 @@ bool cPieceGenerator::TryPlacePieceAtConnector( // You need DirectionRotationTable[rot1][rot2] CCW turns to connect rot1 to rot2 (they are opposite) static const int DirectionRotationTable[6][6] = { - /* YM, YP, ZM, ZP, XM, XP + /* YM, YP, ZM, ZP, XM, XP */ /* YM */ { 0, 0, 0, 0, 0, 0}, /* YP */ { 0, 0, 0, 0, 0, 0}, /* ZM */ { 0, 0, 2, 0, 1, 3}, -- cgit v1.2.3 From ef58b0eb54c700800597031c37c3e76fef87cdfb Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 12 Mar 2014 09:49:37 -0700 Subject: Fixed comments an assert --- Tools/ProtoProxy/Connection.cpp | 4 ++-- src/Globals.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index 73688d310..46119ff42 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -2772,7 +2772,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) { int Index = ((unsigned)((unsigned char)a_Metadata[pos])) & 0x1f; // Lower 5 bits = index int Type = ((unsigned)((unsigned char)a_Metadata[pos])) >> 5; // Upper 3 bits = type - //int Length = 0; + // int Length = 0; switch (Type) { case 0: @@ -2827,7 +2827,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) ASSERT(!"Cannot parse item description from metadata"); return; } - //int After = bb.GetReadableSpace(); + // int After = bb.GetReadableSpace(); int BytesConsumed = BytesLeft - bb.GetReadableSpace(); Log("%sslot[%d] = %s (%d bytes)", Indent.c_str(), Index, ItemDesc.c_str(), BytesConsumed); diff --git a/src/Globals.h b/src/Globals.h index 2cd160677..6661aa476 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -236,7 +236,7 @@ template class SizeChecker; // Same as assert but in all Self test builds #ifdef SELF_TEST -#define assert_test(x) ( !!(x) || (assert(0), exit(1), 0)) +#define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0)) #endif /// A generic interface used mainly in ForEach() functions -- cgit v1.2.3 From a584b7b3bc95783025d9861964bd987f324ba981 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 12 Mar 2014 10:09:08 -0700 Subject: Fixed printf format compatabilty --- src/Generating/PieceGenerator.cpp | 9 ++++----- src/Globals.h | 5 +++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index 50bfe65fe..8999a5ff7 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -31,14 +31,14 @@ public: Gen.PlacePieces(500, 50, 500, 3, OutPieces); // Print out the pieces: - printf("OutPieces.size() = %zu\n", OutPieces.size()); + printf("OutPieces.size() = " SIZE_T_FMT "\n", OutPieces.size()); size_t idx = 0; for (cPlacedPieces::const_iterator itr = OutPieces.begin(), end = OutPieces.end(); itr != end; ++itr, ++idx) { const Vector3i & Coords = (*itr)->GetCoords(); cCuboid Hitbox = (*itr)->GetHitBox(); Hitbox.Sort(); - printf("%zu: {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx, + printf(SIZE_T_FMT ": {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx, Coords.x, Coords.y, Coords.z, (*itr)->GetNumCCWRotations(), Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z, @@ -502,12 +502,11 @@ bool cPieceGenerator::CheckConnection( // DEBUG: void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed) { - printf(" Connector pool: %zu items\n", a_ConnectorPool.size() - a_NumProcessed); + printf(" Connector pool: " SIZE_T_FMT " items\n", a_ConnectorPool.size() - a_NumProcessed); size_t idx = 0; for (cPieceGenerator::cFreeConnectors::const_iterator itr = a_ConnectorPool.begin() + a_NumProcessed, end = a_ConnectorPool.end(); itr != end; ++itr, ++idx) { - // Format specifier for size_t is zu - printf(" %zu: {%d, %d, %d}, type %d, direction %s, depth %d\n", + printf(" " SIZE_T_FMT ": {%d, %d, %d}, type %d, direction %s, depth %d\n", idx, itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z, itr->m_Connector.m_Type, diff --git a/src/Globals.h b/src/Globals.h index 5ced0cc39..b42a06970 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -38,6 +38,9 @@ // No alignment needed in MSVC #define ALIGN_8 #define ALIGN_16 + + // MSVC has its own custom version of zu format + #define SIZE_T_FMT "%Iu" #elif defined(__GNUC__) @@ -56,6 +59,8 @@ // Some portability macros :) #define stricmp strcasecmp + + #define SIZE_T_FMT "%zu" #else -- cgit v1.2.3 From 862e2194433b5d47aaf88261091b35a1ee663482 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 12 Mar 2014 10:34:50 -0700 Subject: Added additional macros to support the MSVC size_t format and changed all formats to use the macros --- src/CraftingRecipes.cpp | 2 +- src/FurnaceRecipe.cpp | 2 +- src/Generating/ChunkGenerator.cpp | 2 +- src/Globals.h | 4 ++++ src/Item.cpp | 8 ++++---- src/Log.cpp | 2 +- src/OSSupport/SocketThreads.cpp | 2 +- src/Protocol/Protocol132.cpp | 2 +- src/Protocol/Protocol17x.cpp | 12 ++++++------ src/Root.cpp | 10 +++++----- src/UI/Window.cpp | 2 +- src/World.cpp | 4 ++-- src/WorldStorage/WSSCompact.cpp | 10 +++++----- 13 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index 30f21686c..30e7a8733 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -340,7 +340,7 @@ void cCraftingRecipes::LoadRecipes(void) } AddRecipeLine(LineNum, Recipe); } // for itr - Split[] - LOG("Loaded %zu crafting recipes", m_Recipes.size()); + LOG("Loaded " SIZE_T_FMT " crafting recipes", m_Recipes.size()); } diff --git a/src/FurnaceRecipe.cpp b/src/FurnaceRecipe.cpp index dd2f259f3..1810d7c49 100644 --- a/src/FurnaceRecipe.cpp +++ b/src/FurnaceRecipe.cpp @@ -175,7 +175,7 @@ void cFurnaceRecipe::ReloadRecipes(void) { LOGERROR("ERROR: FurnaceRecipe, syntax error" ); } - LOG("Loaded %zu furnace recipes and %zu fuels", m_pState->Recipes.size(), m_pState->Fuel.size()); + LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size()); } diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index 92f6009ac..73f0223e8 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -116,7 +116,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk // Add to queue, issue a warning if too many: if (m_Queue.size() >= QUEUE_WARNING_LIMIT) { - LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (%zu)", a_ChunkX, a_ChunkZ, m_Queue.size()); + LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (" SIZE_T_FMT ")", a_ChunkX, a_ChunkZ, m_Queue.size()); } m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); } diff --git a/src/Globals.h b/src/Globals.h index faa168c59..08d9e971a 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -43,6 +43,8 @@ // MSVC has its own custom version of zu format #define SIZE_T_FMT "%Iu" + #define SIZE_T_FMT_PRECISION(x) "%" #x "Iu" + #define SIZE_T_FMT_HEX "%Ix" #elif defined(__GNUC__) @@ -65,6 +67,8 @@ #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) #define SIZE_T_FMT "%zu" + #define SIZE_T_FMT_PRECISION(x) "%" #x "zu" + #define SIZE_T_FMT_HEX "%zx" #else diff --git a/src/Item.cpp b/src/Item.cpp index c8dda209c..856b68be6 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -216,7 +216,7 @@ cItem * cItems::Get(int a_Idx) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently %zu items. Returning a nil.", a_Idx, size()); + LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently " SIZE_T_FMT " items. Returning a nil.", a_Idx, size()); return NULL; } return &at(a_Idx); @@ -230,7 +230,7 @@ void cItems::Set(int a_Idx, const cItem & a_Item) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size()); + LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Not setting.", a_Idx, size()); return; } at(a_Idx) = a_Item; @@ -244,7 +244,7 @@ void cItems::Delete(int a_Idx) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %zu items. Ignoring.", a_Idx, size()); + LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Ignoring.", a_Idx, size()); return; } erase(begin() + a_Idx); @@ -258,7 +258,7 @@ void cItems::Set(int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDama { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size()); + LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Not setting.", a_Idx, size()); return; } at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage); diff --git a/src/Log.cpp b/src/Log.cpp index 54e2b7812..395326398 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -118,7 +118,7 @@ void cLog::Log(const char * a_Format, va_list argList) AString Line; #ifdef _DEBUG - Printf(Line, "[%04zu|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); + Printf(Line, "[" SIZE_T_FMT_PRECISION(04) "|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #else Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #endif diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp index f37b00202..0bc1d6b55 100644 --- a/src/OSSupport/SocketThreads.cpp +++ b/src/OSSupport/SocketThreads.cpp @@ -54,7 +54,7 @@ bool cSocketThreads::AddClient(const cSocket & a_Socket, cCallback * a_Client) } // No thread has free space, create a new one: - LOGD("Creating a new cSocketThread (currently have %zu)", m_Threads.size()); + LOGD("Creating a new cSocketThread (currently have " SIZE_T_FMT ")", m_Threads.size()); cSocketThread * Thread = new cSocketThread(this); if (!Thread->Start()) { diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index 43fe90616..be9c503ed 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -100,7 +100,7 @@ cProtocol132::~cProtocol132() { if (!m_DataToSend.empty()) { - LOGD("There are %zu unsent bytes while deleting cProtocol132", m_DataToSend.size()); + LOGD("There are " SIZE_T_FMT " unsent bytes while deleting cProtocol132", m_DataToSend.size()); } } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 9e5fe53fb..6fc344eaf 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1251,7 +1251,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); AString Hex; CreateHexDump(Hex, AllData.data(), AllData.size(), 16); - m_CommLogFile.Printf("Incoming data, %zu (0x%zx) unparsed bytes already present in buffer:\n%s\n", + m_CommLogFile.Printf("Incoming data, " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") unparsed bytes already present in buffer:\n%s\n", AllData.size(), AllData.size(), Hex.c_str() ); } @@ -1344,14 +1344,14 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) if (bb.GetReadableSpace() != 1) { // Read more or less than packet length, report as error - LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read %zu bytes, packet contained %u bytes", + LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read " SIZE_T_FMT " bytes, packet contained %u bytes", PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen ); // Put a message in the comm log: if (g_ShouldLogCommIn) { - m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %zu left) ^^^^^^\n\n\n", + m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got " SIZE_T_FMT " left) ^^^^^^\n\n\n", 1, bb.GetReadableSpace() ); m_CommLogFile.Flush(); @@ -1373,7 +1373,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); AString Hex; CreateHexDump(Hex, AllData.data(), AllData.size(), 16); - m_CommLogFile.Printf("There are %zu (0x%zx) bytes of non-parse-able data left in the buffer:\n%s", + m_CommLogFile.Printf("There are " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") bytes of non-parse-able data left in the buffer:\n%s", m_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str() ); m_CommLogFile.Flush(); @@ -2062,7 +2062,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) { AString HexDump; CreateHexDump(HexDump, a_Metadata.data(), a_Metadata.size(), 16); - LOGWARNING("Cannot unGZIP item metadata (%zu bytes):\n%s", a_Metadata.size(), HexDump.c_str()); + LOGWARNING("Cannot unGZIP item metadata (" SIZE_T_FMT " bytes):\n%s", a_Metadata.size(), HexDump.c_str()); return; } @@ -2072,7 +2072,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) { AString HexDump; CreateHexDump(HexDump, Uncompressed.data(), Uncompressed.size(), 16); - LOGWARNING("Cannot parse NBT item metadata: (%zu bytes)\n%s", Uncompressed.size(), HexDump.c_str()); + LOGWARNING("Cannot parse NBT item metadata: (" SIZE_T_FMT " bytes)\n%s", Uncompressed.size(), HexDump.c_str()); return; } diff --git a/src/Root.cpp b/src/Root.cpp index 9a5dcac71..3555afb45 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -778,11 +778,11 @@ void cRoot::LogChunkStats(cCommandOutputCallback & a_Output) int Mem = NumValid * sizeof(cChunk); a_Output.Out(" Memory used by chunks: %d KiB (%d MiB)", (Mem + 1023) / 1024, (Mem + 1024 * 1024 - 1) / (1024 * 1024)); a_Output.Out(" Per-chunk memory size breakdown:"); - a_Output.Out(" block types: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024); - a_Output.Out(" block metadata: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); - a_Output.Out(" block lighting: %6zu bytes (%3zu KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); - a_Output.Out(" heightmap: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024); - a_Output.Out(" biomemap: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024); + a_Output.Out(" block types: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024); + a_Output.Out(" block metadata: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); + a_Output.Out(" block lighting: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); + a_Output.Out(" heightmap: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024); + a_Output.Out(" biomemap: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024); int Rest = sizeof(cChunk) - sizeof(cChunkDef::BlockTypes) - 3 * sizeof(cChunkDef::BlockNibbles) - sizeof(cChunkDef::HeightMap) - sizeof(cChunkDef::BiomeMap); a_Output.Out(" other: %6d bytes (%3d KiB)", Rest, (Rest + 1023) / 1024); SumNumValid += NumValid; diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 5249a4bca..aae7b99a3 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -637,7 +637,7 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int { if ((size_t)(a_Item.m_ItemCount) < a_SlotNums.size()) { - LOGWARNING("%s: Distributing less items (%d) than slots (%zu)", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size()); + LOGWARNING("%s: Distributing less items (%d) than slots (" SIZE_T_FMT ")", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size()); // This doesn't seem to happen with the 1.5.1 client, so we don't worry about it for now return 0; } diff --git a/src/World.cpp b/src/World.cpp index 3a6e63e57..8c3a1ff8a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -102,7 +102,7 @@ protected: { for (;;) { - LOG("%zu chunks to load, %d chunks to generate", + LOG("" SIZE_T_FMT " chunks to load, %d chunks to generate", m_World->GetStorage().GetLoadQueueLength(), m_World->GetGenerator().GetQueueLength() ); @@ -154,7 +154,7 @@ protected: { for (;;) { - LOG("%zu chunks remaining to light", m_Lighting->GetQueueLength() + LOG("" SIZE_T_FMT " chunks remaining to light", m_Lighting->GetQueueLength() ); // Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index b1e8d12b7..bb9d4b9e6 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -569,7 +569,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2() if( ChunksConverted % 32 == 0 ) { - LOGINFO("Updating \"%s\" version 1 to version 2: %zu %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); + LOGINFO("Updating \"%s\" version 1 to version 2: " SIZE_T_FMT " %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); } ChunksConverted++; @@ -607,7 +607,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2() if (UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]", UncompressedSize, UncompressedData.size(), Header->m_ChunkX, Header->m_ChunkZ ); @@ -713,7 +713,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() if( ChunksConverted % 32 == 0 ) { - LOGINFO("Updating \"%s\" version 2 to version 3: %zu %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); + LOGINFO("Updating \"%s\" version 2 to version 3: " SIZE_T_FMT " %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); } ChunksConverted++; @@ -751,7 +751,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() if (UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]", UncompressedSize, UncompressedData.size(), Header->m_ChunkX, Header->m_ChunkZ ); @@ -866,7 +866,7 @@ bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_Uncomp if (a_UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]", a_UncompressedSize, UncompressedData.size(), a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ ); -- cgit v1.2.3 From 9a28d1bbe1fc85981ded03e1d190612e6a688b5e Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 12 Mar 2014 11:56:24 -0700 Subject: Fixed comma --- src/Globals.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Globals.h b/src/Globals.h index 08d9e971a..45d403f27 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -39,7 +39,7 @@ #define ALIGN_8 #define ALIGN_16 - #define FORMATSTRING(formatIndex,va_argsIndex) + #define FORMATSTRING(formatIndex, va_argsIndex) // MSVC has its own custom version of zu format #define SIZE_T_FMT "%Iu" @@ -64,7 +64,7 @@ // Some portability macros :) #define stricmp strcasecmp - #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) + #define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) #define SIZE_T_FMT "%zu" #define SIZE_T_FMT_PRECISION(x) "%" #x "zu" -- cgit v1.2.3 From bba090ebddd4662f30dc86d3ce20073ef0fc2f6c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 14 Mar 2014 11:18:14 +0100 Subject: cPluginManager:Bind[Console]Command returns true on success. Fixes #801. --- MCServer/Plugins/APIDump/APIDesc.lua | 8 ++++---- src/Bindings/ManualBindings.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 3c99b82de..c5599b212 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1794,13 +1794,13 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); }, BindCommand = { - { Params = "Command, Permission, Callback, HelpString", Return = "", Notes = "(STATIC) Binds an in-game command with the specified callback function, permission and help string. By common convention, providing an empty string for HelpString will hide the command from the /help display." }, - { Params = "Command, Permission, Callback, HelpString", Return = "", Notes = "Binds an in-game command with the specified callback function, permission and help string. By common convention, providing an empty string for HelpString will hide the command from the /help display." }, + { Params = "Command, Permission, Callback, HelpString", Return = "[bool]", Notes = "(STATIC) Binds an in-game command with the specified callback function, permission and help string. By common convention, providing an empty string for HelpString will hide the command from the /help display. Returns true if successful, logs to console and returns no value on error." }, + { Params = "Command, Permission, Callback, HelpString", Return = "[bool]", Notes = "Binds an in-game command with the specified callback function, permission and help string. By common convention, providing an empty string for HelpString will hide the command from the /help display. Returns true if successful, logs to console and returns no value on error." }, }, BindConsoleCommand = { - { Params = "Command, Callback, HelpString", Return = "", Notes = "(STATIC) Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command." }, - { Params = "Command, Callback, HelpString", Return = "", Notes = "Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command." }, + { Params = "Command, Callback, HelpString", Return = "[bool]", Notes = "(STATIC) Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command. Returns true if successful, logs to console and returns no value on error." }, + { Params = "Command, Callback, HelpString", Return = "[bool]", Notes = "Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command. Returns true if successful, logs to console and returns no value on error." }, }, CallPlugin = { Params = "PluginName, FunctionName, [FunctionArgs...]", Return = "[FunctionRets]", Notes = "(STATIC) Calls the specified function in the specified plugin, passing all the given arguments to it. If it succeeds, it returns all the values returned by that function. If it fails, returns no value at all. Note that only strings, numbers, bools, nils and classes can be used for parameters and return values; tables and functions cannot be copied across plugins." }, DisablePlugin = { Params = "PluginName", Return = "bool", Notes = "Disables a plugin specified by its name. Returns true if the plugin was disabled, false if it wasn't found or wasn't active." }, diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index a5247bbe6..462ef3682 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1497,7 +1497,8 @@ static int tolua_cPluginManager_BindCommand(lua_State * L) } Plugin->BindCommand(Command, FnRef); - return 0; + lua_pushboolean(L, true); + return 1; } @@ -1561,7 +1562,8 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L) } Plugin->BindConsoleCommand(Command, FnRef); - return 0; + lua_pushboolean(L, true); + return 1; } -- cgit v1.2.3 From cd6ab5617cd7b26b13cfe26a950ca17fecefd550 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 06:11:49 -0700 Subject: Fixed xofts issues --- src/ByteBuffer.cpp | 2 +- src/CommandOutput.cpp | 4 ++-- src/CommandOutput.h | 2 +- src/Generating/PieceGenerator.h | 4 ++-- src/Globals.h | 3 ++- src/Log.cpp | 2 +- src/Log.h | 4 ++-- src/MCLogger.h | 16 ++++++++-------- src/OSSupport/File.h | 2 +- src/StringUtils.h | 8 ++++---- 10 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index d3bcfe866..1893d89a8 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -767,7 +767,7 @@ bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars) { return false; } - RawBEToUTF8((RawData.data()), a_NumChars, a_String); + RawBEToUTF8(RawData.data(), a_NumChars, a_String); return true; } diff --git a/src/CommandOutput.cpp b/src/CommandOutput.cpp index 74f857284..2c116b3d6 100644 --- a/src/CommandOutput.cpp +++ b/src/CommandOutput.cpp @@ -51,7 +51,7 @@ void cLogCommandOutputCallback::Finished(void) { case '\n': { - LOG("%s",m_Buffer.substr(last, i - last).c_str()); + LOG("%s", m_Buffer.substr(last, i - last).c_str()); last = i + 1; break; } @@ -59,7 +59,7 @@ void cLogCommandOutputCallback::Finished(void) } // for i - m_Buffer[] if (last < len) { - LOG("%s",m_Buffer.substr(last).c_str()); + LOG("%s", m_Buffer.substr(last).c_str()); } // Clear the buffer for the next command output: diff --git a/src/CommandOutput.h b/src/CommandOutput.h index 81d9ddb84..5682b4fd8 100644 --- a/src/CommandOutput.h +++ b/src/CommandOutput.h @@ -17,7 +17,7 @@ public: virtual ~cCommandOutputCallback() {}; // Force a virtual destructor in subclasses /// Syntax sugar function, calls Out() with Printf()-ed parameters; appends a "\n" - void Out(const char * a_Fmt, ...) FORMATSTRING(2,3); + void Out(const char * a_Fmt, ...) FORMATSTRING(2, 3); /// Called when the command wants to output anything; may be called multiple times virtual void Out(const AString & a_Text) = 0; diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h index 3386d7a94..bef9d3463 100644 --- a/src/Generating/PieceGenerator.h +++ b/src/Generating/PieceGenerator.h @@ -122,9 +122,9 @@ public: const cPiece & GetPiece (void) const { return *m_Piece; } const Vector3i & GetCoords (void) const { return m_Coords; } - int GetNumCCWRotations(void) const { return m_NumCCWRotations; } + int GetNumCCWRotations(void) const { return m_NumCCWRotations; } const cCuboid & GetHitBox (void) const { return m_HitBox; } - int GetDepth (void) const { return m_Depth; } + int GetDepth (void) const { return m_Depth; } protected: const cPlacedPiece * m_Parent; diff --git a/src/Globals.h b/src/Globals.h index 45d403f27..c2542f0d8 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -114,7 +114,8 @@ template class SizeChecker; template -class SizeChecker { +class SizeChecker +{ T v; }; diff --git a/src/Log.cpp b/src/Log.cpp index 395326398..a7be04b1a 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -118,7 +118,7 @@ void cLog::Log(const char * a_Format, va_list argList) AString Line; #ifdef _DEBUG - Printf(Line, "[" SIZE_T_FMT_PRECISION(04) "|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); + Printf(Line, "[%04lx|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #else Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #endif diff --git a/src/Log.h b/src/Log.h index 340fa23bc..d6a406154 100644 --- a/src/Log.h +++ b/src/Log.h @@ -14,8 +14,8 @@ private: public: cLog(const AString & a_FileName); ~cLog(); - void Log(const char * a_Format, va_list argList) FORMATSTRING(2,0); - void Log(const char * a_Format, ...) FORMATSTRING(2,3); + void Log(const char * a_Format, va_list argList) FORMATSTRING(2, 0); + void Log(const char * a_Format, ...) FORMATSTRING(2, 3); // tolua_begin void SimpleLog(const char * a_String); void OpenLog(const char * a_FileName); diff --git a/src/MCLogger.h b/src/MCLogger.h index ba9e4827f..996e60329 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -21,10 +21,10 @@ public: // tolua_export ~cMCLogger(); // tolua_export - void Log(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); - void Info(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); - void Warn(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); - void Error(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); + void Log(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); + void Info(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); + void Warn(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); + void Error(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); void LogSimple(const char* a_Text, int a_LogType = 0 ); // tolua_export @@ -57,10 +57,10 @@ private: -extern void LOG(const char* a_Format, ...) FORMATSTRING(1,2); -extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1,2); -extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1,2); -extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOG(const char* a_Format, ...) FORMATSTRING(1, 2); +extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1, 2); +extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1, 2); +extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2); diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index e229035b7..b394c5cb9 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -131,7 +131,7 @@ public: /** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */ static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp - int Printf(const char * a_Fmt, ...) FORMATSTRING(2,3); + int Printf(const char * a_Fmt, ...) FORMATSTRING(2, 3); /** Flushes all the bufferef output into the file (only when writing) */ void Flush(void); diff --git a/src/StringUtils.h b/src/StringUtils.h index 728ce31e6..4feff7553 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -22,16 +22,16 @@ typedef std::list AStringList; /** Add the formated string to the existing data in the string */ -extern AString & AppendVPrintf(AString & str, const char * format, va_list args) FORMATSTRING(2,0); +extern AString & AppendVPrintf(AString & str, const char * format, va_list args) FORMATSTRING(2, 0); /// Output the formatted text into the string -extern AString & Printf (AString & str, const char * format, ...) FORMATSTRING(2,3); +extern AString & Printf (AString & str, const char * format, ...) FORMATSTRING(2, 3); /// Output the formatted text into string, return string by value -extern AString Printf(const char * format, ...) FORMATSTRING(1,2); +extern AString Printf(const char * format, ...) FORMATSTRING(1, 2); /// Add the formatted string to the existing data in the string -extern AString & AppendPrintf (AString & str, const char * format, ...) FORMATSTRING(2,3); +extern AString & AppendPrintf (AString & str, const char * format, ...) FORMATSTRING(2, 3); /// Split the string at any of the listed delimiters, return as a stringvector extern AStringVector StringSplit(const AString & str, const AString & delim); -- cgit v1.2.3 From 35fe96b07d2bccb98eca4681b7fbf45b18009b9c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 14 Mar 2014 14:36:44 +0100 Subject: Fixed a warning. --- src/World.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index 3d01dc40f..c314a36da 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2453,14 +2453,14 @@ cPlayer * cWorld::FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit, { cTracer LineOfSight(this); - float ClosestDistance = a_SightLimit; - cPlayer* ClosestPlayer = NULL; + double ClosestDistance = a_SightLimit; + cPlayer * ClosestPlayer = NULL; cCSLock Lock(m_CSPlayers); for (cPlayerList::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) { Vector3f Pos = (*itr)->GetPosition(); - float Distance = (Pos - a_Pos).Length(); + double Distance = (Pos - a_Pos).Length(); if (Distance < ClosestDistance) { -- cgit v1.2.3 From 9b63156447882c57698aba48da37c82cc0f0b428 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 14 Mar 2014 14:37:39 +0100 Subject: cPlugin:BindConsoleCommand can be called statically. This has been documented before it was written. --- src/Bindings/ManualBindings.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 462ef3682..20bbc48f2 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1522,7 +1522,10 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L) // Read the arguments to this API call: tolua_Error tolua_err; int idx = 1; - if (tolua_isusertype(L, 1, "cPluginManager", 0, &tolua_err)) + if ( + tolua_isusertype(L, 1, "cPluginManager", 0, &tolua_err) || + tolua_isusertable(L, 1, "cPluginManager", 0, &tolua_err) + ) { idx++; } -- cgit v1.2.3 From 22cdbe99b434a4442502c292bd541093a80cc9b7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 06:44:04 -0700 Subject: Fixed a couple of missing defs --- SetFlags.cmake | 2 +- src/BoundingBox.cpp | 2 +- src/CompositeChat.cpp | 2 +- src/Noise.cpp | 8 -------- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 42cfa6769..cdafcaa83 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -198,7 +198,7 @@ macro(set_exe_flags) add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") - add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef") + add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code") endif() endif() diff --git a/src/BoundingBox.cpp b/src/BoundingBox.cpp index aab51c539..482f9923f 100644 --- a/src/BoundingBox.cpp +++ b/src/BoundingBox.cpp @@ -10,7 +10,7 @@ -#if SELF_TEST +#ifdef SELF_TEST /** A simple self-test that is executed on program start, used to verify bbox functionality */ static class SelfTest_BoundingBox diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index 19ed30d78..a917ee70f 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -10,7 +10,7 @@ -#if SELF_TEST +#ifdef SELF_TEST /** A simple self-test that verifies that the composite chat parser is working properly. */ class SelfTest_CompositeChat diff --git a/src/Noise.cpp b/src/Noise.cpp index 5f23a47f9..a97ea70c6 100644 --- a/src/Noise.cpp +++ b/src/Noise.cpp @@ -3,14 +3,6 @@ #include "Noise.h" - - - - -#if NOISE_USE_SSE - #include //_mm_mul_epi32 -#endif - #define FAST_FLOOR(x) (((x) < 0) ? (((int)x) - 1) : ((int)x)) -- cgit v1.2.3 From e61810e1bf67dc43861d4741b16e65b30fe8d23c Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 06:52:49 -0700 Subject: Removed invalid block face handling code The code for handling invalid block faces is removed by gcc and clang as it is undefined behavior for a enum to contain a value that is not part of the enum. Since the only way that the line can be executed is through undefined behavior clang and gcc remove it so the function fits in the caches better. --- src/Defines.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Defines.h b/src/Defines.h index 3b7654265..2e412209d 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -290,7 +290,6 @@ inline AString BlockFaceToString(eBlockFace a_BlockFace) case BLOCK_FACE_ZP: return "BLOCK_FACE_ZP"; case BLOCK_FACE_NONE: return "BLOCK_FACE_NONE"; } - return Printf("Unknown BLOCK_FACE: %d", a_BlockFace); } -- cgit v1.2.3 From 58fa8b40bf5700327d99d96d656994dab619b670 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 07:02:57 -0700 Subject: Removed missiterperatable malfunctioning error handling code --- src/Scoreboard.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 8088e624b..cfeb1d619 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -30,8 +30,6 @@ AString cObjective::TypeToString(eType a_Type) case otStatBlockMine: return "stat.mineBlock"; case otStatEntityKill: return "stat.killEntity"; case otStatEntityKilledBy: return "stat.entityKilledBy"; - - default: return ""; } } -- cgit v1.2.3 From b829c9b14e95f37a3a5ba70fc42cb8cfe9066522 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 07:12:00 -0700 Subject: Fixed a few unneeded breaks --- src/Map.cpp | 4 +++- src/StringUtils.cpp | 1 - src/main.cpp | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Map.cpp b/src/Map.cpp index 2d8f57168..79370b097 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -243,7 +243,7 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) { for (unsigned int Z = m_RelZ; Z < m_RelZ + PixelWidth; ++Z) { - unsigned int WaterDepth = 0; + // unsigned int WaterDepth = 0; BLOCKTYPE TargetBlock = E_BLOCK_AIR; NIBBLETYPE TargetMeta = 0; @@ -261,12 +261,14 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) continue; } // TODO 2014-02-22 xdot: Check if block is liquid + /* else if (false) { --Height; ++WaterDepth; continue; } + */ break; } diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 3f9275798..ad622d707 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -454,7 +454,6 @@ AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a if (!isLegalUTF8(source, extraBytesToRead + 1)) { return a_UTF16; - break; } // The cases all fall through. See "Note A" below. diff --git a/src/main.cpp b/src/main.cpp index 2ae8a413b..68eea7f4d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,7 +72,6 @@ void NonCtrlHandler(int a_Signal) LOGERROR(" D: | MCServer has encountered an error and needs to close"); LOGERROR("Details | SIGABRT: Server self-terminated due to an internal fault"); exit(EXIT_FAILURE); - break; } case SIGINT: case SIGTERM: -- cgit v1.2.3 From fed461bf2a6bf4e6dc2b6d0cc66b8e806806a859 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 07:12:18 -0700 Subject: Made unreachable code an error --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 42cfa6769..b22449142 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -198,7 +198,7 @@ macro(set_exe_flags) add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") - add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef") + add_flags_cxx("-Wno-missing-noreturn -Wno-error=undef") endif() endif() -- cgit v1.2.3 From cd7ef264be438a7c1b19eb6a0478ed5748e551bd Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 07:16:55 -0700 Subject: Disable global constructors and exit-time destructors warnings --- SetFlags.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 42cfa6769..05f2b90c0 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -196,8 +196,8 @@ macro(set_exe_flags) add_flags_cxx("-Wno-error=deprecated -Wno-error=weak-vtables -Wno-error=float-equal") add_flags_cxx("-Wno-error=missing-prototypes -Wno-error=non-virtual-dtor") add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") - add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") - add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") + add_flags_cxx("-Wno-exit-time-destructors -Wno-error=missing-variable-declarations") + add_flags_cxx("-Wno-global-constructors -Wno-implicit-fallthrough") add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef") endif() endif() -- cgit v1.2.3 From 2f81c1d7fbe7932da055581aa815edc9f6ff8191 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 07:33:47 -0700 Subject: Added NORETURN macro --- src/Globals.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Globals.h b/src/Globals.h index c2542f0d8..a5b9d391a 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -45,6 +45,8 @@ #define SIZE_T_FMT "%Iu" #define SIZE_T_FMT_PRECISION(x) "%" #x "Iu" #define SIZE_T_FMT_HEX "%Ix" + + #define NORETURN __declspec(noreturn) #elif defined(__GNUC__) @@ -69,6 +71,8 @@ #define SIZE_T_FMT "%zu" #define SIZE_T_FMT_PRECISION(x) "%" #x "zu" #define SIZE_T_FMT_HEX "%zx" + + #define NORETURN __attribute((__noreturn__)) #else -- cgit v1.2.3 From 8e11c270fc786a8b8b72aed71cf8feee659c4876 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 07:59:25 -0700 Subject: Added Noreturn attribtes to a couple of functions and made a missing noreturn an error --- SetFlags.cmake | 2 +- src/Bindings/LuaState.h | 2 +- src/DeadlockDetect.h | 2 +- src/Globals.h | 11 +++++++++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 42cfa6769..e636c5c95 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -198,7 +198,7 @@ macro(set_exe_flags) add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") - add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef") + add_flags_cxx("-Wno-error=unreachable-code -Wno-error=undef") endif() endif() diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 73f9629cb..f5cb8379d 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -200,7 +200,7 @@ public: void Push(const HTTPTemplateRequest * a_Request); void Push(cTNTEntity * a_TNTEntity); void Push(Vector3i * a_Vector); - void Push(void * a_Ptr); + NORETURNDEBUG void Push(void * a_Ptr); void Push(cHopperEntity * a_Hopper); void Push(cBlockEntity * a_BlockEntity); diff --git a/src/DeadlockDetect.h b/src/DeadlockDetect.h index cb2309169..6aa98acbb 100644 --- a/src/DeadlockDetect.h +++ b/src/DeadlockDetect.h @@ -60,7 +60,7 @@ protected: void CheckWorldAge(const AString & a_WorldName, Int64 a_Age); /// Called when a deadlock is detected. Aborts the server. - void DeadlockDetected(void); + NORETURN void DeadlockDetected(void); } ; diff --git a/src/Globals.h b/src/Globals.h index a5b9d391a..3e62832b7 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -46,7 +46,7 @@ #define SIZE_T_FMT_PRECISION(x) "%" #x "Iu" #define SIZE_T_FMT_HEX "%Ix" - #define NORETURN __declspec(noreturn) + #define NORETURN __declspec(noreturn) #elif defined(__GNUC__) @@ -72,7 +72,7 @@ #define SIZE_T_FMT_PRECISION(x) "%" #x "zu" #define SIZE_T_FMT_HEX "%zx" - #define NORETURN __attribute((__noreturn__)) + #define NORETURN __attribute((__noreturn__)) #else @@ -98,6 +98,13 @@ #endif +#ifdef _DEBUG + #define NORETURNDEBUG NORETURN +#else + #define NORETURNDEBUG +#endif + + #include -- cgit v1.2.3 From e3646fc877f52c848cfb8a383fdbe89140663199 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 08:05:35 -0700 Subject: Fixed a couple of unneeded returns in ProtoProxy --- Tools/ProtoProxy/Connection.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index 46119ff42..f02b503f1 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -387,8 +387,6 @@ bool cConnection::RelayFromServer(void) return CLIENTSEND(Buffer, res); } } - - return true; } @@ -425,8 +423,6 @@ bool cConnection::RelayFromClient(void) return SERVERSEND(Buffer, res); } } - - return true; } -- cgit v1.2.3 From a982b9b5ace6baab7dda4d7d905907009919dfea Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 14 Mar 2014 16:07:22 +0100 Subject: APIDump: Trigger the dump manually. Fixes #715. The dump can be triggerred by issuing an "api" console command, or in the webadmin. --- MCServer/Plugins/APIDump/main_APIDump.lua | 90 ++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 26 deletions(-) diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua index bd509dcb6..40b37f62c 100644 --- a/MCServer/Plugins/APIDump/main_APIDump.lua +++ b/MCServer/Plugins/APIDump/main_APIDump.lua @@ -9,22 +9,6 @@ -- Global variables: g_Plugin = nil; g_PluginFolder = ""; -g_TrackedPages = {}; -- List of tracked pages, to be checked later whether they exist. Each item is an array of referring pagenames. -g_Stats = -- Statistics about the documentation -{ - NumTotalClasses = 0, - NumUndocumentedClasses = 0, - NumTotalFunctions = 0, - NumUndocumentedFunctions = 0, - NumTotalConstants = 0, - NumUndocumentedConstants = 0, - NumTotalVariables = 0, - NumUndocumentedVariables = 0, - NumTotalHooks = 0, - NumUndocumentedHooks = 0, - NumTrackedLinks = 0, - NumInvalidLinks = 0, -} @@ -33,15 +17,34 @@ g_Stats = -- Statistics about the documentation function Initialize(Plugin) g_Plugin = Plugin; - - Plugin:SetName("APIDump"); - Plugin:SetVersion(1); + g_PluginFolder = Plugin:GetLocalFolder(); LOG("Initialising " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) - g_PluginFolder = Plugin:GetLocalFolder(); + cPluginManager:BindConsoleCommand("api", HandleCmdApi, "Dumps the Lua API docs into the API/ subfolder") + g_Plugin:AddWebTab("APIDump", HandleWebAdminDump) + -- TODO: Add a WebAdmin tab that has a Dump button + return true +end + + + + + +function HandleCmdApi(a_Split) + DumpApi() +end + + + + + +function DumpApi() + LOG("Dumping the API...") -- Load the API descriptions from the Classes and Hooks subfolders: + -- This needs to be done each time the command is invoked because the export modifies the tables' contents + dofile(g_PluginFolder .. "/APIDesc.lua") if (g_APIDesc.Classes == nil) then g_APIDesc.Classes = {}; end @@ -51,6 +54,24 @@ function Initialize(Plugin) LoadAPIFiles("/Classes/", g_APIDesc.Classes); LoadAPIFiles("/Hooks/", g_APIDesc.Hooks); + -- Reset the stats: + g_TrackedPages = {}; -- List of tracked pages, to be checked later whether they exist. Each item is an array of referring pagenames. + g_Stats = -- Statistics about the documentation + { + NumTotalClasses = 0, + NumUndocumentedClasses = 0, + NumTotalFunctions = 0, + NumUndocumentedFunctions = 0, + NumTotalConstants = 0, + NumUndocumentedConstants = 0, + NumTotalVariables = 0, + NumUndocumentedVariables = 0, + NumTotalHooks = 0, + NumUndocumentedHooks = 0, + NumTrackedLinks = 0, + NumInvalidLinks = 0, + } + -- dump all available API functions and objects: -- DumpAPITxt(); @@ -58,7 +79,6 @@ function Initialize(Plugin) DumpAPIHtml(); LOG("APIDump finished"); - return true end @@ -67,6 +87,9 @@ end function LoadAPIFiles(a_Folder, a_DstTable) + assert(type(a_Folder) == "string") + assert(type(a_DstTable) == "table") + local Folder = g_PluginFolder .. a_Folder; for idx, fnam in ipairs(cFile:GetFolderContents(Folder)) do local FileName = Folder .. fnam; @@ -317,6 +340,11 @@ end function DumpAPIHtml() LOG("Dumping all available functions and constants to API subfolder..."); + -- Create the output folder + if not(cFile:IsFolder("API")) then + cFile:CreateFolder("API"); + end + LOG("Copying static files.."); cFile:CreateFolder("API/Static"); local localFolder = g_Plugin:GetLocalFolder(); @@ -366,11 +394,6 @@ function DumpAPIHtml() ReadDescriptions(API); ReadHooks(Hooks); - -- Create the output folder - if not(cFile:IsFolder("API")) then - cFile:CreateFolder("API"); - end - -- Create a "class index" file, write each class as a link to that file, -- then dump class contents into class-specific file LOG("Writing HTML files..."); @@ -1428,3 +1451,18 @@ end + +function HandleWebAdminDump(a_Request) + if (a_Request.PostParams["Dump"] ~= nil) then + DumpApi() + end + return + [[ +

    Pressing the button will generate the API dump on the server. Note that this can take some time.

    +
    + ]] +end + + + + -- cgit v1.2.3 From dc1049da3cd8dbf77ba96caf75550711ca0fba86 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 14 Mar 2014 16:08:25 +0100 Subject: Ignoring all config and SQLite files in the output folder. --- MCServer/.gitignore | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/MCServer/.gitignore b/MCServer/.gitignore index 0fd04ef59..64f062ef7 100644 --- a/MCServer/.gitignore +++ b/MCServer/.gitignore @@ -19,10 +19,8 @@ schematics *.pdb memdump* *.grab -Galleries.cfg -Galleries.example.cfg -Galleries.sqlite -ProtectionAreas.sqlite +*.cfg +*.sqlite helgrind.log valgrind.log motd.txt -- cgit v1.2.3 From ccc29c7c6c344b00e5b6c9236cf615b253b9a1b5 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 14 Mar 2014 23:52:51 +0100 Subject: Add fireball interact --- src/BlockEntities/DispenserEntity.cpp | 6 ++++++ src/Items/ItemHandler.cpp | 1 + src/Items/ItemItemFrame.h | 6 +++++- src/Items/ItemLighter.h | 22 +++++++++++++++++++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index cbfbb1b6a..e03bf776d 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -138,6 +138,12 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) break; } + case E_ITEM_FIRE_CHARGE: + { + // TODO: Spawn fireball entity + break; + } + default: { DropFromSlot(a_Chunk, a_SlotNum); diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 1d357fcf1..232791f99 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -107,6 +107,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_EGG: return new cItemEggHandler(); case E_ITEM_EMPTY_MAP: return new cItemEmptyMapHandler(); case E_ITEM_ENDER_PEARL: return new cItemEnderPearlHandler(); + case E_ITEM_FIRE_CHARGE: return new cItemLighterHandler(a_ItemType); case E_ITEM_FIREWORK_ROCKET: return new cItemFireworkHandler(); case E_ITEM_FISHING_ROD: return new cItemFishingRodHandler(a_ItemType); case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType); diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h index 74e987445..27e7dba35 100644 --- a/src/Items/ItemItemFrame.h +++ b/src/Items/ItemItemFrame.h @@ -34,7 +34,11 @@ public: if (Block == E_BLOCK_AIR) { cItemFrame * ItemFrame = new cItemFrame(a_Dir, a_BlockX, a_BlockY, a_BlockZ); - ItemFrame->Initialize(a_World); + if (!ItemFrame->Initialize(a_World)) + { + delete ItemFrame; + return false; + } if (!a_Player->IsGameModeCreative()) { diff --git a/src/Items/ItemLighter.h b/src/Items/ItemLighter.h index 18873e911..2db6c829a 100644 --- a/src/Items/ItemLighter.h +++ b/src/Items/ItemLighter.h @@ -26,7 +26,26 @@ public: return false; } - a_Player->UseEquippedItem(); + if (!a_Player->IsGameModeCreative()) + { + switch (m_ItemType) + { + case E_ITEM_FLINT_AND_STEEL: + { + a_Player->UseEquippedItem(); + break; + } + case E_ITEM_FIRE_CHARGE: + { + a_Player->GetInventory().RemoveOneEquippedItem(); + break; + } + default: + { + ASSERT(!"Unknown Lighter Item!"); + } + } + } switch (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ)) { @@ -49,6 +68,7 @@ public: if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) { a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 0); + a_World->BroadcastSoundEffect("fire.ignite", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 1.0F, 1.04F); break; } } -- cgit v1.2.3 From 28898f710b191abb610f31085d6ae076511cc89c Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 15 Mar 2014 00:32:49 +0100 Subject: Add ExpOrb saving. --- src/Entities/ExpOrb.cpp | 26 ++++++--- src/Entities/ExpOrb.h | 16 +++++- src/Entities/Pickup.cpp | 2 +- src/WorldStorage/NBTChunkSerializer.cpp | 17 +++++- src/WorldStorage/NBTChunkSerializer.h | 2 + src/WorldStorage/WSSAnvil.cpp | 96 ++++++++++++++++++++++++--------- src/WorldStorage/WSSAnvil.h | 3 +- 7 files changed, 124 insertions(+), 38 deletions(-) diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 3398f1c7b..3623c869a 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -5,20 +5,26 @@ #include "../ClientHandle.h" -cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) : - cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98), - m_Reward(a_Reward) +cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) + : cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98) + , m_Reward(a_Reward) + , m_Timer(0.f) { + SetMaxHealth(5); + SetHealth(5); } -cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward) : - cEntity(etExpOrb, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98), - m_Reward(a_Reward) +cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward) + : cEntity(etExpOrb, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98) + , m_Reward(a_Reward) + , m_Timer(0.f) { + SetMaxHealth(5); + SetHealth(5); } @@ -52,7 +58,7 @@ void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk) LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward); a_ClosestPlayer->DeltaExperience(m_Reward); - m_World->BroadcastSoundEffect("random.orb", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_World->BroadcastSoundEffect("random.orb", (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); Destroy(); } @@ -64,4 +70,10 @@ void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk) BroadcastMovementUpdate(); } HandlePhysics(a_Dt, a_Chunk); + + m_Timer += a_Dt; + if (m_Timer >= 1000 * 60 * 5) // 5 minutes + { + Destroy(true); + } } diff --git a/src/Entities/ExpOrb.h b/src/Entities/ExpOrb.h index 47d86922c..b75859e4c 100644 --- a/src/Entities/ExpOrb.h +++ b/src/Entities/ExpOrb.h @@ -21,10 +21,22 @@ public: // Override functions virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void SpawnOn(cClientHandle & a_Client) override; + + /** Returns the number of ticks that this entity has existed */ + int GetAge(void) const { return (int)(m_Timer / 50); } // tolua_export + + /** Set the number of ticks that this entity has existed */ + void SetAge(int a_Age) { m_Timer = (float)(a_Age * 50); } // tolua_export - // cExpOrb functions - int GetReward(void) const { return m_Reward; } + /** Get the exp amount */ + int GetReward(void) const { return m_Reward; } // tolua_export + + /** Set the exp amount */ + void SetReward(int a_Reward) { m_Reward = a_Reward; } // tolua_export protected: int m_Reward; + + /** The number of ticks that the entity has existed / timer between collect and destroy; in msec */ + float m_Timer; } ; \ No newline at end of file diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index c5503c16a..7fc89b62b 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -82,7 +82,7 @@ cPickup::cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_It void cPickup::SpawnOn(cClientHandle & a_Client) { - a_Client.SendPickupSpawn(*this); + a_Client.SendPickupSpawn(*this); } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 17cf838c3..fa5547f46 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -29,6 +29,7 @@ #include "../Entities/Pickup.h" #include "../Entities/ProjectileEntity.h" #include "../Entities/TNTEntity.h" +#include "../Entities/ExpOrb.h" #include "../Mobs/Monster.h" #include "../Mobs/Bat.h" @@ -596,6 +597,20 @@ void cNBTChunkSerializer::AddTNTEntity(cTNTEntity * a_TNT) +void cNBTChunkSerializer::AddExpOrbEntity(cExpOrb* a_ExpOrb) +{ + m_Writer.BeginCompound(""); + AddBasicEntity(a_ExpOrb, "XPOrb"); + m_Writer.AddShort("Health", (short)(unsigned char)a_ExpOrb->GetHealth()); + m_Writer.AddShort("Age", (short)a_ExpOrb->GetAge()); + m_Writer.AddShort("Value", (short)a_ExpOrb->GetReward()); + m_Writer.EndCompound(); +} + + + + + void cNBTChunkSerializer::AddMinecartChestContents(cMinecartWithChest * a_Minecart) { m_Writer.BeginList("Items", TAG_Compound); @@ -676,7 +691,7 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity) case cEntity::etPickup: AddPickupEntity ((cPickup *) a_Entity); break; case cEntity::etProjectile: AddProjectileEntity ((cProjectileEntity *)a_Entity); break; case cEntity::etTNT: AddTNTEntity ((cTNTEntity *) a_Entity); break; - case cEntity::etExpOrb: /* TODO */ break; + case cEntity::etExpOrb: AddExpOrbEntity ((cExpOrb *) a_Entity); break; case cEntity::etItemFrame: /* TODO */ break; case cEntity::etPainting: /* TODO */ break; case cEntity::etPlayer: return; // Players aren't saved into the world diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index 3b486d2bc..22c309067 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -42,6 +42,7 @@ class cPickup; class cItemGrid; class cProjectileEntity; class cTNTEntity; +class cExpOrb; @@ -109,6 +110,7 @@ protected: void AddPickupEntity (cPickup * a_Pickup); void AddProjectileEntity (cProjectileEntity * a_Projectile); void AddTNTEntity (cTNTEntity * a_TNT); + void AddExpOrbEntity (cExpOrb * a_ExpOrb); void AddMinecartChestContents(cMinecartWithChest * a_Minecart); diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index b52b74932..c180f715f 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -37,6 +37,7 @@ #include "../Entities/Pickup.h" #include "../Entities/ProjectileEntity.h" #include "../Entities/TNTEntity.h" +#include "../Entities/ExpOrb.h" @@ -1092,6 +1093,14 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a { LoadPickupFromNBT(a_Entities, a_NBT, a_EntityTagIdx); } + else if (strncmp(a_IDTag, "PrimedTnt", a_IDTagLength) == 0) + { + LoadTNTFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + } + else if (strncmp(a_IDTag, "XPOrb", a_IDTagLength) == 0) + { + LoadExpOrbFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + } else if (strncmp(a_IDTag, "Arrow", a_IDTagLength) == 0) { LoadArrowFromNBT(a_Entities, a_NBT, a_EntityTagIdx); @@ -1232,10 +1241,6 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a { LoadPigZombieFromNBT(a_Entities, a_NBT, a_EntityTagIdx); } - else if (strncmp(a_IDTag, "PrimedTnt", a_IDTagLength) == 0) - { - LoadTNTFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - } // TODO: other entities } @@ -1393,6 +1398,9 @@ void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + // TODO: Add health and age + a_Entities.push_back(Pickup.release()); } @@ -1400,6 +1408,64 @@ void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a +void cWSSAnvil::LoadTNTFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + std::auto_ptr TNT(new cTNTEntity(0.0, 0.0, 0.0, 0)); + if (!LoadEntityBaseFromNBT(*TNT.get(), a_NBT, a_TagIdx)) + { + return; + } + + // Load Fuse Ticks: + int FuseTicks = a_NBT.FindChildByName(a_TagIdx, "Fuse"); + if (FuseTicks > 0) + { + TNT->SetFuseTicks((int) a_NBT.GetByte(FuseTicks)); + } + + a_Entities.push_back(TNT.release()); +} + + + + + +void cWSSAnvil::LoadExpOrbFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + std::auto_ptr ExpOrb(new cExpOrb(0.0, 0.0, 0.0, 0)); + if (!LoadEntityBaseFromNBT(*ExpOrb.get(), a_NBT, a_TagIdx)) + { + return; + } + + // Load Health: + int Health = a_NBT.FindChildByName(a_TagIdx, "Health"); + if (Health > 0) + { + ExpOrb->SetHealth((int) (a_NBT.GetShort(Health) & 0xFF)); + } + + // Load Age: + int Age = a_NBT.FindChildByName(a_TagIdx, "Age"); + if (Age > 0) + { + ExpOrb->SetAge(a_NBT.GetShort(Age)); + } + + // Load Reward (Value): + int Reward = a_NBT.FindChildByName(a_TagIdx, "Value"); + if (Reward > 0) + { + ExpOrb->SetReward(a_NBT.GetShort(Reward)); + } + + a_Entities.push_back(ExpOrb.release()); +} + + + + + void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { std::auto_ptr Arrow(new cArrowEntity(NULL, 0, 0, 0, Vector3d(0, 0, 0))); @@ -2172,28 +2238,6 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT -void cWSSAnvil::LoadTNTFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) -{ - std::auto_ptr TNT(new cTNTEntity(0.0, 0.0, 0.0, 0)); - if (!LoadEntityBaseFromNBT(*TNT.get(), a_NBT, a_TagIdx)) - { - return; - } - - // Load Fuse Ticks: - int FuseTicks = a_NBT.FindChildByName(a_TagIdx, "Fuse"); - if (FuseTicks > 0) - { - TNT->SetFuseTicks((int) a_NBT.GetByte(FuseTicks)); - } - - a_Entities.push_back(TNT.release()); -} - - - - - bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx) { double Pos[3]; diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index fe93d16c3..75b630d71 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -149,6 +149,8 @@ protected: void LoadBoatFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadFallingBlockFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadPickupFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadTNTFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadExpOrbFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadMinecartRFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadMinecartCFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); @@ -192,7 +194,6 @@ protected: void LoadWolfFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadPigZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); - void LoadTNTFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); /// Loads entity common data from the NBT compound; returns true if successful bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx); -- cgit v1.2.3 From cf137392885479d4e3f057c64cb078a6025f4b25 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 15 Mar 2014 00:43:38 +0100 Subject: Add health and age load to pickup's. --- src/CMakeLists.txt | 1 + src/Entities/ExpOrb.h | 15 +++++++++------ src/Entities/Pickup.h | 23 +++++++++++++---------- src/WorldStorage/NBTChunkSerializer.cpp | 10 +++++----- src/WorldStorage/WSSAnvil.cpp | 16 +++++++++++++++- 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5029906aa..52a792ba7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,6 +59,7 @@ if (NOT MSVC) Entities/Player.h Entities/ProjectileEntity.h Entities/TNTEntity.h + Entities/ExpOrb.h Generating/ChunkDesc.h Group.h Inventory.h diff --git a/src/Entities/ExpOrb.h b/src/Entities/ExpOrb.h index b75859e4c..c1150bd03 100644 --- a/src/Entities/ExpOrb.h +++ b/src/Entities/ExpOrb.h @@ -7,30 +7,33 @@ +// tolua_begin class cExpOrb : public cEntity { typedef cExpOrb super; public: + // tolua_end + CLASS_PROTODEF(cExpOrb); - + cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward); cExpOrb(const Vector3d & a_Pos, int a_Reward); // Override functions virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void SpawnOn(cClientHandle & a_Client) override; - + /** Returns the number of ticks that this entity has existed */ - int GetAge(void) const { return (int)(m_Timer / 50); } // tolua_export - + int GetAge(void) const { return (int)(m_Timer / 50); } // tolua_export + /** Set the number of ticks that this entity has existed */ void SetAge(int a_Age) { m_Timer = (float)(a_Age * 50); } // tolua_export /** Get the exp amount */ int GetReward(void) const { return m_Reward; } // tolua_export - + /** Set the exp amount */ void SetReward(int a_Reward) { m_Reward = a_Reward; } // tolua_export @@ -39,4 +42,4 @@ protected: /** The number of ticks that the entity has existed / timer between collect and destroy; in msec */ float m_Timer; -} ; \ No newline at end of file +} ; // tolua_export \ No newline at end of file diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h index c273567d1..74b917bce 100644 --- a/src/Entities/Pickup.h +++ b/src/Entities/Pickup.h @@ -26,31 +26,34 @@ public: CLASS_PROTODEF(cPickup); cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); - + cItem & GetItem(void) {return m_Item; } // tolua_export const cItem & GetItem(void) const {return m_Item; } virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - + bool CollectedBy(cPlayer * a_Dest); // tolua_export virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - - /// Returns the number of ticks that this entity has existed - int GetAge(void) const { return (int)(m_Timer / 50); } // tolua_export - - /// Returns true if the pickup has already been collected + + /** Returns the number of ticks that this entity has existed */ + int GetAge(void) const { return (int)(m_Timer / 50); } // tolua_export + + /** Set the number of ticks that this entity has existed */ + void SetAge(int a_Age) { m_Timer = (float)(a_Age * 50); } // tolua_export + + /** Returns true if the pickup has already been collected */ bool IsCollected(void) const { return m_bCollected; } // tolua_export - /// Returns true if created by player (i.e. vomiting), used for determining picking-up delay time + /** Returns true if created by player (i.e. vomiting), used for determining picking-up delay time */ bool IsPlayerCreated(void) const { return m_bIsPlayerCreated; } // tolua_export - + private: Vector3d m_ResultingSpeed; //Can be used to modify the resulting speed for the current tick ;) Vector3d m_WaterSpeed; - /// The number of ticks that the entity has existed / timer between collect and destroy; in msec + /** The number of ticks that the entity has existed / timer between collect and destroy; in msec */ float m_Timer; cItem m_Item; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index fa5547f46..37ebf0610 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -519,8 +519,8 @@ void cNBTChunkSerializer::AddPickupEntity(cPickup * a_Pickup) m_Writer.BeginCompound(""); AddBasicEntity(a_Pickup, "Item"); AddItem(a_Pickup->GetItem(), -1, "Item"); - m_Writer.AddShort("Health", a_Pickup->GetHealth()); - m_Writer.AddShort("Age", a_Pickup->GetAge()); + m_Writer.AddShort("Health", (Int16)(unsigned char)a_Pickup->GetHealth()); + m_Writer.AddShort("Age", (Int16)a_Pickup->GetAge()); m_Writer.EndCompound(); } @@ -601,9 +601,9 @@ void cNBTChunkSerializer::AddExpOrbEntity(cExpOrb* a_ExpOrb) { m_Writer.BeginCompound(""); AddBasicEntity(a_ExpOrb, "XPOrb"); - m_Writer.AddShort("Health", (short)(unsigned char)a_ExpOrb->GetHealth()); - m_Writer.AddShort("Age", (short)a_ExpOrb->GetAge()); - m_Writer.AddShort("Value", (short)a_ExpOrb->GetReward()); + m_Writer.AddShort("Health", (Int16)(unsigned char)a_ExpOrb->GetHealth()); + m_Writer.AddShort("Age", (Int16)a_ExpOrb->GetAge()); + m_Writer.AddShort("Value", (Int16)a_ExpOrb->GetReward()); m_Writer.EndCompound(); } diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index c180f715f..bb0a831b3 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1383,6 +1383,7 @@ void cWSSAnvil::LoadMinecartHFromNBT(cEntityList & a_Entities, const cParsedNBT void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { + // Load item: int ItemTag = a_NBT.FindChildByName(a_TagIdx, "Item"); if ((ItemTag < 0) || (a_NBT.GetType(ItemTag) != TAG_Compound)) { @@ -1393,13 +1394,26 @@ void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + std::auto_ptr Pickup(new cPickup(0, 0, 0, Item, false)); // Pickup delay doesn't matter, just say false if (!LoadEntityBaseFromNBT(*Pickup.get(), a_NBT, a_TagIdx)) { return; } - // TODO: Add health and age + // Load health: + int Health = a_NBT.FindChildByName(a_TagIdx, "Health"); + if (Health > 0) + { + Pickup->SetHealth((int) (a_NBT.GetShort(Health) & 0xFF)); + } + + // Load age: + int Age = a_NBT.FindChildByName(a_TagIdx, "Age"); + if (Age > 0) + { + Pickup->SetAge(a_NBT.GetShort(Age)); + } a_Entities.push_back(Pickup.release()); } -- cgit v1.2.3 From 7ac7304c913f9cf82a906589904068a3e7f09d43 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 15 Mar 2014 02:45:25 +0100 Subject: Add item frame saving. --- src/CMakeLists.txt | 2 + src/Entities/HangingEntity.cpp | 53 ++++++++++++++++++++ src/Entities/HangingEntity.h | 49 +++++++++++++++++++ src/Entities/ItemFrame.cpp | 39 ++------------- src/Entities/ItemFrame.h | 22 +++++---- src/WorldStorage/NBTChunkSerializer.cpp | 40 +++++++++++++++- src/WorldStorage/NBTChunkSerializer.h | 4 ++ src/WorldStorage/WSSAnvil.cpp | 85 +++++++++++++++++++++++++++++++++ src/WorldStorage/WSSAnvil.h | 3 ++ 9 files changed, 251 insertions(+), 46 deletions(-) create mode 100644 src/Entities/HangingEntity.cpp create mode 100644 src/Entities/HangingEntity.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 52a792ba7..4ea5c69e9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,6 +60,8 @@ if (NOT MSVC) Entities/ProjectileEntity.h Entities/TNTEntity.h Entities/ExpOrb.h + Entities/HangingEntity.h + Entities/ItemFrame.h Generating/ChunkDesc.h Group.h Inventory.h diff --git a/src/Entities/HangingEntity.cpp b/src/Entities/HangingEntity.cpp new file mode 100644 index 000000000..41ac86268 --- /dev/null +++ b/src/Entities/HangingEntity.cpp @@ -0,0 +1,53 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "HangingEntity.h" +#include "ClientHandle.h" +#include "Player.h" + + + + + +cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z) + : cEntity(a_EntityType, a_X, a_Y, a_Z, 0.8, 0.8) + , m_BlockFace(a_BlockFace) +{ + SetMaxHealth(1); + SetHealth(1); +} + + + + + +void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle) +{ + int Dir = 0; + + // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces + switch (m_BlockFace) + { + case BLOCK_FACE_ZP: break; // Initialised to zero + case BLOCK_FACE_ZM: Dir = 2; break; + case BLOCK_FACE_XM: Dir = 1; break; + case BLOCK_FACE_XP: Dir = 3; break; + default: ASSERT(!"Unhandled block face when trying to spawn item frame!"); return; + } + + if ((Dir == 0) || (Dir == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180 + { + SetYaw((Dir * 90) - 180); + } + else + { + SetYaw(Dir * 90); + } + + a_ClientHandle.SendSpawnObject(*this, 71, Dir, (Byte)GetYaw(), (Byte)GetPitch()); + a_ClientHandle.SendEntityMetadata(*this); +} + + + + diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h new file mode 100644 index 000000000..6498e4b5b --- /dev/null +++ b/src/Entities/HangingEntity.h @@ -0,0 +1,49 @@ + +#pragma once + +#include "Entity.h" + + + + + +// tolua_begin +class cHangingEntity : + public cEntity +{ + // tolua_end + typedef cEntity super; + +public: + + CLASS_PROTODEF(cHangingEntity); + + cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z); + + /** Returns the orientation from the hanging entity */ + eBlockFace GetDirection() const { return m_BlockFace; } // tolua_export + + /** Set the orientation from the hanging entity */ + void SetDirection(eBlockFace a_BlockFace) { m_BlockFace = a_BlockFace; } // tolua_export + + /** Returns the X coord. */ + int GetTileX() const { return POSX_TOINT; } // tolua_export + + /** Returns the Y coord. */ + int GetTileY() const { return POSY_TOINT; } // tolua_export + + /** Returns the Z coord. */ + int GetTileZ() const { return POSZ_TOINT; } // tolua_export + +private: + + virtual void SpawnOn(cClientHandle & a_ClientHandle) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override {}; + + eBlockFace m_BlockFace; + +}; // tolua_export + + + + diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index 8cfa5e18d..9dd909880 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -10,43 +10,10 @@ cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z) - : cEntity(etItemFrame, a_X, a_Y, a_Z, 0.8, 0.8), - m_BlockFace(a_BlockFace), - m_Item(E_BLOCK_AIR), - m_Rotation(0) + : cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z) + , m_Item(E_BLOCK_AIR) + , m_Rotation(0) { - SetMaxHealth(1); - SetHealth(1); -} - - - - - -void cItemFrame::SpawnOn(cClientHandle & a_ClientHandle) -{ - int Dir = 0; - - // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces - switch (m_BlockFace) - { - case BLOCK_FACE_ZP: break; // Initialised to zero - case BLOCK_FACE_ZM: Dir = 2; break; - case BLOCK_FACE_XM: Dir = 1; break; - case BLOCK_FACE_XP: Dir = 3; break; - default: ASSERT(!"Unhandled block face when trying to spawn item frame!"); return; - } - - if ((Dir == 0) || (Dir == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180 - { - SetYaw((Dir * 90) - 180); - } - else - { - SetYaw(Dir * 90); - } - - a_ClientHandle.SendSpawnObject(*this, 71, Dir, (Byte)GetYaw(), (Byte)GetPitch()); } diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h index 43915e3f9..6577e7d94 100644 --- a/src/Entities/ItemFrame.h +++ b/src/Entities/ItemFrame.h @@ -1,7 +1,7 @@ #pragma once -#include "Entity.h" +#include "HangingEntity.h" @@ -9,10 +9,10 @@ // tolua_begin class cItemFrame : - public cEntity + public cHangingEntity { // tolua_end - typedef cEntity super; + typedef cHangingEntity super; public: @@ -20,18 +20,24 @@ public: cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z); - const cItem & GetItem(void) { return m_Item; } - Byte GetRotation(void) const { return m_Rotation; } + /** Returns the item in the frame */ + const cItem & GetItem(void) { return m_Item; } // tolua_export + + /** Set the item in the frame */ + void SetItem(cItem & a_Item) { m_Item = a_Item; }; // tolua_export + + /** Returns the rotation from the item in the frame */ + Byte GetRotation(void) const { return m_Rotation; } // tolua_export + + /** Set the rotation from the item in the frame */ + void SetRotation(Byte a_Rotation) { m_Rotation = a_Rotation; } // tolua_export private: - virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void OnRightClicked(cPlayer & a_Player) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override {}; virtual void KilledBy(cEntity * a_Killer) override; virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override; - eBlockFace m_BlockFace; cItem m_Item; Byte m_Rotation; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 37ebf0610..6672d289e 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -30,6 +30,8 @@ #include "../Entities/ProjectileEntity.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" +#include "../Entities/HangingEntity.h" +#include "../Entities/ItemFrame.h" #include "../Mobs/Monster.h" #include "../Mobs/Bat.h" @@ -585,6 +587,25 @@ void cNBTChunkSerializer::AddProjectileEntity(cProjectileEntity * a_Projectile) +void cNBTChunkSerializer::AddHangingEntity(cHangingEntity * a_Hanging) +{ + m_Writer.AddByte("Direction", (unsigned char)a_Hanging->GetDirection()); + m_Writer.AddInt("TileX", a_Hanging->GetTileX()); + m_Writer.AddInt("TileY", a_Hanging->GetTileY()); + m_Writer.AddInt("TileZ", a_Hanging->GetTileZ()); + switch (a_Hanging->GetDirection()) + { + case 0: m_Writer.AddByte("Dir", (unsigned char)2); break; + case 1: m_Writer.AddByte("Dir", (unsigned char)1); break; + case 2: m_Writer.AddByte("Dir", (unsigned char)0); break; + case 3: m_Writer.AddByte("Dir", (unsigned char)3); break; + } +} + + + + + void cNBTChunkSerializer::AddTNTEntity(cTNTEntity * a_TNT) { m_Writer.BeginCompound(""); @@ -597,7 +618,7 @@ void cNBTChunkSerializer::AddTNTEntity(cTNTEntity * a_TNT) -void cNBTChunkSerializer::AddExpOrbEntity(cExpOrb* a_ExpOrb) +void cNBTChunkSerializer::AddExpOrbEntity(cExpOrb * a_ExpOrb) { m_Writer.BeginCompound(""); AddBasicEntity(a_ExpOrb, "XPOrb"); @@ -611,6 +632,21 @@ void cNBTChunkSerializer::AddExpOrbEntity(cExpOrb* a_ExpOrb) +void cNBTChunkSerializer::AddItemFrameEntity(cItemFrame * a_ItemFrame) +{ + m_Writer.BeginCompound(""); + AddBasicEntity(a_ItemFrame, "ItemFrame"); + AddHangingEntity(a_ItemFrame); + AddItem(a_ItemFrame->GetItem(), -1, "Item"); + m_Writer.AddByte("ItemRotation", (unsigned char)a_ItemFrame->GetRotation()); + m_Writer.AddFloat("ItemDropChance", 1.0F); + m_Writer.EndCompound(); +} + + + + + void cNBTChunkSerializer::AddMinecartChestContents(cMinecartWithChest * a_Minecart) { m_Writer.BeginList("Items", TAG_Compound); @@ -692,7 +728,7 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity) case cEntity::etProjectile: AddProjectileEntity ((cProjectileEntity *)a_Entity); break; case cEntity::etTNT: AddTNTEntity ((cTNTEntity *) a_Entity); break; case cEntity::etExpOrb: AddExpOrbEntity ((cExpOrb *) a_Entity); break; - case cEntity::etItemFrame: /* TODO */ break; + case cEntity::etItemFrame: AddItemFrameEntity ((cItemFrame *) a_Entity); break; case cEntity::etPainting: /* TODO */ break; case cEntity::etPlayer: return; // Players aren't saved into the world default: diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index 22c309067..c1134cd00 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -43,6 +43,8 @@ class cItemGrid; class cProjectileEntity; class cTNTEntity; class cExpOrb; +class cHangingEntity; +class cItemFrame; @@ -109,8 +111,10 @@ protected: void AddMonsterEntity (cMonster * a_Monster); void AddPickupEntity (cPickup * a_Pickup); void AddProjectileEntity (cProjectileEntity * a_Projectile); + void AddHangingEntity (cHangingEntity * a_Hanging); void AddTNTEntity (cTNTEntity * a_TNT); void AddExpOrbEntity (cExpOrb * a_ExpOrb); + void AddItemFrameEntity (cItemFrame * a_ItemFrame); void AddMinecartChestContents(cMinecartWithChest * a_Minecart); diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index bb0a831b3..6ac26c348 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -38,6 +38,8 @@ #include "../Entities/ProjectileEntity.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" +#include "../Entities/HangingEntity.h" +#include "../Entities/ItemFrame.h" @@ -1101,6 +1103,10 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a { LoadExpOrbFromNBT(a_Entities, a_NBT, a_EntityTagIdx); } + else if (strncmp(a_IDTag, "ItemFrame", a_IDTagLength) == 0) + { + LoadItemFrameFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + } else if (strncmp(a_IDTag, "Arrow", a_IDTagLength) == 0) { LoadArrowFromNBT(a_Entities, a_NBT, a_EntityTagIdx); @@ -1480,6 +1486,85 @@ void cWSSAnvil::LoadExpOrbFromNBT(cEntityList & a_Entities, const cParsedNBT & a +void cWSSAnvil::LoadHangingFromNBT(cHangingEntity & a_Hanging, const cParsedNBT & a_NBT, int a_TagIdx) +{ + int Direction = a_NBT.FindChildByName(a_TagIdx, "Direction"); + if (Direction > 0) + { + a_Hanging.SetDirection(static_cast((int)a_NBT.GetByte(Direction))); + } + else + { + Direction = a_NBT.FindChildByName(a_TagIdx, "Dir"); + if (Direction > 0) + { + switch ((int)a_NBT.GetByte(Direction)) + { + case 0: a_Hanging.SetDirection(BLOCK_FACE_NORTH); break; + case 1: a_Hanging.SetDirection(BLOCK_FACE_TOP); break; + case 2: a_Hanging.SetDirection(BLOCK_FACE_BOTTOM); break; + case 3: a_Hanging.SetDirection(BLOCK_FACE_SOUTH); break; + } + } + } + + LOG("LALALAL."); + int TileX = a_NBT.FindChildByName(a_TagIdx, "TileX"); + int TileY = a_NBT.FindChildByName(a_TagIdx, "TileY"); + int TileZ = a_NBT.FindChildByName(a_TagIdx, "TileZ"); + if ((TileX > 0) && (TileY > 0) && (TileZ > 0)) + { + LOG("YO!"); + a_Hanging.SetPosition( + (double)a_NBT.GetInt(TileX), + (double)a_NBT.GetInt(TileY), + (double)a_NBT.GetInt(TileZ) + ); + } +} + + + + + +void cWSSAnvil::LoadItemFrameFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + // Load item: + int ItemTag = a_NBT.FindChildByName(a_TagIdx, "Item"); + if ((ItemTag < 0) || (a_NBT.GetType(ItemTag) != TAG_Compound)) + { + return; + } + cItem Item; + if (!LoadItemFromNBT(Item, a_NBT, ItemTag)) + { + return; + } + + std::auto_ptr ItemFrame(new cItemFrame(BLOCK_FACE_NONE, 0.0, 0.0, 0.0)); + if (!LoadEntityBaseFromNBT(*ItemFrame.get(), a_NBT, a_TagIdx)) + { + return; + } + ItemFrame->SetItem(Item); + + LOG("BAUM! %d", Item.m_ItemType); + LoadHangingFromNBT(*ItemFrame.get(), a_NBT, a_TagIdx); + + // Load Rotation: + int Rotation = a_NBT.FindChildByName(a_TagIdx, "ItemRotation"); + if (Rotation > 0) + { + ItemFrame->SetRotation((Byte)a_NBT.GetByte(Rotation)); + } + + a_Entities.push_back(ItemFrame.release()); +} + + + + + void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { std::auto_ptr Arrow(new cArrowEntity(NULL, 0, 0, 0, Vector3d(0, 0, 0))); diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 75b630d71..50d0e555e 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -20,6 +20,7 @@ class cItemGrid; class cProjectileEntity; +class cHangingEntity; @@ -151,6 +152,8 @@ protected: void LoadPickupFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadTNTFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadExpOrbFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadHangingFromNBT (cHangingEntity & a_Hanging,const cParsedNBT & a_NBT, int a_TagIdx); + void LoadItemFrameFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadMinecartRFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadMinecartCFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); -- cgit v1.2.3 From 0442c41c872badfcc1a7a22c293161cc752623b8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 15 Mar 2014 07:50:39 +0100 Subject: Added cCuboid:Assign(OtherCuboid) API function. --- MCServer/Plugins/APIDump/Classes/Geometry.lua | 8 ++++++-- src/Cuboid.cpp | 14 ++++++++++++++ src/Cuboid.h | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/APIDump/Classes/Geometry.lua b/MCServer/Plugins/APIDump/Classes/Geometry.lua index 6f95c4cbf..78cd94f0c 100644 --- a/MCServer/Plugins/APIDump/Classes/Geometry.lua +++ b/MCServer/Plugins/APIDump/Classes/Geometry.lua @@ -63,12 +63,16 @@ return { constructor = { - { Params = "OtheCuboid", Return = "cCuboid", Notes = "Creates a new Cuboid object as a copy of OtherCuboid" }, + { Params = "OtherCuboid", Return = "cCuboid", Notes = "Creates a new Cuboid object as a copy of OtherCuboid" }, { Params = "{{Vector3i|Point1}}, {{Vector3i|Point2}}", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified points as its corners." }, { Params = "X, Y, Z", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified point as both its corners (the cuboid has a size of 1 in each direction)." }, { Params = "X1, Y1, Z1, X2, Y2, Z2", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified points as its corners." }, }, - Assign = { Params = "X1, Y1, Z1, X2, Y2, Z2", Return = "", Notes = "Assigns all the coords stored in the cuboid. Sort-state is ignored." }, + Assign = + { + { Params = "SrcCuboid", Return = "", Notes = "Copies all the coords from the src cuboid to this cuboid. Sort-state is ignored." }, + { Params = "X1, Y1, Z1, X2, Y2, Z2", Return = "", Notes = "Assigns all the coords to the specified values. Sort-state is ignored." }, + }, ClampX = { Params = "MinX, MaxX", Return = "", Notes = "Clamps both X coords into the range provided. Sortedness-agnostic." }, ClampY = { Params = "MinY, MaxY", Return = "", Notes = "Clamps both Y coords into the range provided. Sortedness-agnostic." }, ClampZ = { Params = "MinZ, MaxZ", Return = "", Notes = "Clamps both Z coords into the range provided. Sortedness-agnostic." }, diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp index 2400c64f3..3e5240248 100644 --- a/src/Cuboid.cpp +++ b/src/Cuboid.cpp @@ -38,6 +38,20 @@ void cCuboid::Assign(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2) +void cCuboid::Assign(const cCuboid & a_SrcCuboid) +{ + p1.x = a_SrcCuboid.p1.x; + p1.y = a_SrcCuboid.p1.y; + p1.z = a_SrcCuboid.p1.z; + p2.x = a_SrcCuboid.p2.x; + p2.y = a_SrcCuboid.p2.y; + p2.z = a_SrcCuboid.p2.z; +} + + + + + void cCuboid::Sort(void) { if (p1.x > p2.x) diff --git a/src/Cuboid.h b/src/Cuboid.h index b90a09e05..3239c54fc 100644 --- a/src/Cuboid.h +++ b/src/Cuboid.h @@ -21,6 +21,7 @@ public: cCuboid(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2) : p1(a_X1, a_Y1, a_Z1), p2(a_X2, a_Y2, a_Z2) {} void Assign(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2); + void Assign(const cCuboid & a_SrcCuboid); void Sort(void); -- cgit v1.2.3 From 62ed305f0760039e645d305a56b41d0ec5080ee0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 15 Mar 2014 07:51:33 +0100 Subject: APIDump: Fixed missing return statement. --- MCServer/Plugins/APIDump/main_APIDump.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua index 40b37f62c..4ed692b52 100644 --- a/MCServer/Plugins/APIDump/main_APIDump.lua +++ b/MCServer/Plugins/APIDump/main_APIDump.lua @@ -33,6 +33,7 @@ end function HandleCmdApi(a_Split) DumpApi() + return true end -- cgit v1.2.3 From d364c7befce884cac2347459512376937d2b8e69 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 15 Mar 2014 08:23:06 +0100 Subject: APIDump: Documented a forgotten cCuboid constructor. --- MCServer/Plugins/APIDump/Classes/Geometry.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/Classes/Geometry.lua b/MCServer/Plugins/APIDump/Classes/Geometry.lua index 78cd94f0c..9887bfb89 100644 --- a/MCServer/Plugins/APIDump/Classes/Geometry.lua +++ b/MCServer/Plugins/APIDump/Classes/Geometry.lua @@ -53,7 +53,7 @@ return { Desc = [[ cCuboid offers some native support for integral-boundary cuboids. A cuboid internally consists of - two {{Vector3i}}s. By default the cuboid doesn't make any assumptions about the defining points, + two {{Vector3i}}-s. By default the cuboid doesn't make any assumptions about the defining points, but for most of the operations in the cCuboid class, the p1 member variable is expected to be the minima and the p2 variable the maxima. The Sort() function guarantees this condition.

    @@ -63,6 +63,7 @@ return { constructor = { + { Params = "", Return = "cCuboid", Notes = "Creates a new Cuboid object with all-zero coords" }, { Params = "OtherCuboid", Return = "cCuboid", Notes = "Creates a new Cuboid object as a copy of OtherCuboid" }, { Params = "{{Vector3i|Point1}}, {{Vector3i|Point2}}", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified points as its corners." }, { Params = "X, Y, Z", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified point as both its corners (the cuboid has a size of 1 in each direction)." }, -- cgit v1.2.3 From 4a5bea159f13b0f72ac16513a8f5b4b90e5b0ca8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 15 Mar 2014 08:36:49 +0100 Subject: Debuggers: Added a test for WE selection API. This tests mc-server/WorldEdit#34. --- MCServer/Plugins/Debuggers/Debuggers.lua | 40 +++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index f99c48242..d2c9a2a49 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -56,7 +56,8 @@ function Initialize(Plugin) PM:BindCommand("/sched", "debuggers", HandleSched, "- Schedules a simple countdown using cWorld:ScheduleTask()"); PM:BindCommand("/cs", "debuggers", HandleChunkStay, "- Tests the ChunkStay Lua integration for the specified chunk coords"); PM:BindCommand("/compo", "debuggers", HandleCompo, "- Tests the cCompositeChat bindings") - PM:BindCommand("/sb", "debuggers", HandleSetBiome, "- Sets the biome around you to the specified one"); + PM:BindCommand("/sb", "debuggers", HandleSetBiome, "- Sets the biome around you to the specified one") + PM:BindCommand("/wesel", "debuggers", HandleWESel, "- Expands the current WE selection by 1 block in X/Z") Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers) Plugin:AddWebTab("StressTest", HandleRequest_StressTest) @@ -1298,6 +1299,43 @@ end +function HandleWESel(a_Split, a_Player) + -- Check if the selection is a cuboid: + local IsCuboid = cPluginManager:CallPlugin("WorldEdit", "IsPlayerSelectionCuboid") + if (IsCuboid == nil) then + a_Player:SendMessage(cCompositeChat():SetMessageType(mtFailure):AddTextPart("Cannot adjust selection, WorldEdit is not loaded")) + return true + elseif (IsCuboid == false) then + a_Player:SendMessage(cCompositeChat():SetMessageType(mtFailure):AddTextPart("Cannot adjust selection, the selection is not a cuboid")) + return true + end + + -- Get the selection: + local SelCuboid = cCuboid() + local IsSuccess = cPluginManager:CallPlugin("WorldEdit", "GetPlayerCuboidSelection", a_Player, SelCuboid) + if not(IsSuccess) then + a_Player:SendMessage(cCompositeChat():SetMessageType(mtFailure):AddTextPart("Cannot adjust selection, WorldEdit reported failure while getting current selection")) + return true + end + + -- Adjust the selection: + local NumBlocks = tonumber(a_Split[2] or "1") or 1 + SelCuboid:Expand(NumBlocks, NumBlocks, 0, 0, NumBlocks, NumBlocks) + + -- Set the selection: + local IsSuccess = cPluginManager:CallPlugin("WorldEdit", "SetPlayerCuboidSelection", a_Player, SelCuboid) + if not(IsSuccess) then + a_Player:SendMessage(cCompositeChat():SetMessageType(mtFailure):AddTextPart("Cannot adjust selection, WorldEdit reported failure while setting new selection")) + return true + end + a_Player:SendMessage(cCompositeChat():SetMessageType(mtInformation):AddTextPart("Successfully adjusted the selection by " .. NumBlocks .. " block(s)")) + return true +end + + + + + function OnPlayerJoined(a_Player) -- Test composite chat chaining: a_Player:SendMessage(cCompositeChat() -- cgit v1.2.3 From d6edd5f24e2717278093ef5a1e8376cd3c797478 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 15 Mar 2014 11:53:55 +0100 Subject: Remove old debug messages. --- src/WorldStorage/WSSAnvil.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 4f465e479..4dd4c755d 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1514,13 +1514,11 @@ void cWSSAnvil::LoadHangingFromNBT(cHangingEntity & a_Hanging, const cParsedNBT } } - LOG("LALALAL."); int TileX = a_NBT.FindChildByName(a_TagIdx, "TileX"); int TileY = a_NBT.FindChildByName(a_TagIdx, "TileY"); int TileZ = a_NBT.FindChildByName(a_TagIdx, "TileZ"); if ((TileX > 0) && (TileY > 0) && (TileZ > 0)) { - LOG("YO!"); a_Hanging.SetPosition( (double)a_NBT.GetInt(TileX), (double)a_NBT.GetInt(TileY), @@ -1554,7 +1552,6 @@ void cWSSAnvil::LoadItemFrameFromNBT(cEntityList & a_Entities, const cParsedNBT } ItemFrame->SetItem(Item); - LOG("BAUM! %d", Item.m_ItemType); LoadHangingFromNBT(*ItemFrame.get(), a_NBT, a_TagIdx); // Load Rotation: -- cgit v1.2.3 From 2e9fe777e425e65d733110247e73c1d9fb25ab1c Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 15 Mar 2014 06:45:26 -0700 Subject: Patched tolua to emit range checks for enums --- lib/tolua++/CMakeLists.txt | 21 + lib/tolua++/src/bin/basic_lua.h | 746 ++++++++++++++ lib/tolua++/src/bin/enumerate_lua.h | 281 ++++++ lib/tolua++/src/bin/function_lua.h | 1192 +++++++++++++++++++++++ lib/tolua++/src/bin/lua/enumerate.lua | 78 +- lib/tolua++/src/bin/lua/function.lua | 1 - lib/tolua++/src/bin/toluabind.c | 1730 +-------------------------------- src/CMakeLists.txt | 1 + 8 files changed, 2303 insertions(+), 1747 deletions(-) create mode 100644 lib/tolua++/src/bin/basic_lua.h create mode 100644 lib/tolua++/src/bin/enumerate_lua.h create mode 100644 lib/tolua++/src/bin/function_lua.h diff --git a/lib/tolua++/CMakeLists.txt b/lib/tolua++/CMakeLists.txt index 5ec8ee822..9c8943aac 100644 --- a/lib/tolua++/CMakeLists.txt +++ b/lib/tolua++/CMakeLists.txt @@ -5,6 +5,25 @@ project (tolua++) include_directories ("${PROJECT_SOURCE_DIR}/../../src/") include_directories ("${PROJECT_SOURCE_DIR}/include/") include_directories ("${PROJECT_SOURCE_DIR}/../") +include_directories ("${PROJECT_SOURCE_DIR}") + +if(UNIX) + add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h + COMMAND xxd -i lua/basic.lua >basic_lua.h + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ + DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/basic.lua) + add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h + COMMAND xxd -i lua/enumerate.lua >enumerate_lua.h + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ + DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/enumerate.lua) + add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h + COMMAND xxd -i lua/function.lua >function_lua.h + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ + DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/function.lua) + set_property(SOURCE src/bin/toluabind.c APPEND PROPERTY OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h) + message(hello) +endif() + file(GLOB LIB_SOURCE "src/lib/*.c" @@ -14,6 +33,8 @@ file(GLOB BIN_SOURCE "src/bin/*.c" ) + + add_executable(tolua ${BIN_SOURCE}) add_library(tolualib ${LIB_SOURCE}) diff --git a/lib/tolua++/src/bin/basic_lua.h b/lib/tolua++/src/bin/basic_lua.h new file mode 100644 index 000000000..9f3b114b4 --- /dev/null +++ b/lib/tolua++/src/bin/basic_lua.h @@ -0,0 +1,746 @@ +unsigned char lua_basic_lua[] = { + 0x2d, 0x2d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, 0x20, 0x62, 0x61, + 0x73, 0x69, 0x63, 0x20, 0x75, 0x74, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x20, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x0a, 0x2d, 0x2d, + 0x20, 0x57, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20, 0x62, 0x79, 0x20, + 0x57, 0x61, 0x6c, 0x64, 0x65, 0x6d, 0x61, 0x72, 0x20, 0x43, 0x65, 0x6c, + 0x65, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x65, 0x43, 0x47, 0x72, 0x61, + 0x66, 0x2f, 0x50, 0x55, 0x43, 0x2d, 0x52, 0x69, 0x6f, 0x0a, 0x2d, 0x2d, + 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x31, 0x39, 0x39, 0x38, 0x0a, 0x2d, 0x2d, + 0x20, 0x4c, 0x61, 0x73, 0x74, 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x3a, 0x20, 0x41, 0x70, 0x72, 0x20, 0x32, 0x30, 0x30, 0x33, 0x0a, 0x2d, + 0x2d, 0x20, 0x24, 0x49, 0x64, 0x3a, 0x20, 0x24, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x69, + 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, + 0x61, 0x72, 0x65, 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61, 0x6e, + 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, + 0x65, 0x20, 0x69, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72, 0x20, + 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x20, 0x69, 0x74, 0x2e, 0x0a, 0x2d, + 0x2d, 0x20, 0x54, 0x68, 0x65, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, + 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x64, 0x20, + 0x68, 0x65, 0x72, 0x65, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x69, 0x73, + 0x20, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x20, 0x22, 0x61, 0x73, 0x20, 0x69, + 0x73, 0x22, 0x20, 0x62, 0x61, 0x73, 0x69, 0x73, 0x2c, 0x20, 0x61, 0x6e, + 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, + 0x68, 0x6f, 0x72, 0x20, 0x68, 0x61, 0x73, 0x20, 0x6e, 0x6f, 0x20, 0x6f, + 0x62, 0x6c, 0x69, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x6f, + 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x20, 0x6d, 0x61, 0x69, + 0x6e, 0x74, 0x65, 0x6e, 0x61, 0x6e, 0x63, 0x65, 0x2c, 0x20, 0x73, 0x75, + 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2c, 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x73, 0x2c, 0x0a, 0x2d, 0x2d, 0x20, 0x65, 0x6e, 0x68, 0x61, 0x6e, + 0x63, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2c, 0x20, 0x6f, 0x72, 0x20, + 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2e, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x42, 0x61, 0x73, 0x69, + 0x63, 0x20, 0x43, 0x20, 0x74, 0x79, 0x70, 0x65, 0x73, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x74, 0x68, 0x65, 0x69, 0x72, 0x20, 0x63, 0x6f, 0x72, 0x72, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x4c, 0x75, + 0x61, 0x20, 0x74, 0x79, 0x70, 0x65, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x41, + 0x6c, 0x6c, 0x20, 0x6f, 0x63, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x63, + 0x65, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x22, 0x63, 0x68, 0x61, 0x72, 0x2a, + 0x22, 0x20, 0x77, 0x69, 0x6c, 0x6c, 0x20, 0x62, 0x65, 0x20, 0x72, 0x65, + 0x70, 0x6c, 0x61, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x22, 0x5f, + 0x63, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x2c, 0x0a, 0x2d, 0x2d, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x6f, 0x63, 0x63, + 0x75, 0x72, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x20, 0x6f, 0x66, 0x20, + 0x22, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x22, 0x20, 0x77, 0x69, 0x6c, 0x6c, + 0x20, 0x62, 0x65, 0x20, 0x72, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x64, + 0x20, 0x62, 0x79, 0x20, 0x22, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, + 0x74, 0x61, 0x22, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x3d, + 0x20, 0x7b, 0x0a, 0x20, 0x5b, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x5d, + 0x20, 0x3d, 0x20, 0x27, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x63, 0x68, + 0x61, 0x72, 0x27, 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, + 0x65, 0x72, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x69, 0x6e, 0x74, 0x27, + 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x27, + 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x27, 0x5d, + 0x20, 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x27, 0x2c, + 0x0a, 0x20, 0x5b, 0x27, 0x6c, 0x6f, 0x6e, 0x67, 0x27, 0x5d, 0x20, 0x3d, + 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x27, 0x2c, 0x0a, 0x20, + 0x5b, 0x27, 0x75, 0x6e, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x27, 0x5d, + 0x20, 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x27, 0x2c, + 0x0a, 0x20, 0x5b, 0x27, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x27, 0x5d, 0x20, + 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x27, 0x2c, 0x0a, + 0x20, 0x5b, 0x27, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x27, 0x5d, 0x20, + 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x27, 0x2c, 0x0a, + 0x20, 0x5b, 0x27, 0x5f, 0x63, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x27, + 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x27, + 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, + 0x74, 0x61, 0x27, 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x75, 0x73, 0x65, 0x72, + 0x64, 0x61, 0x74, 0x61, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x63, 0x68, + 0x61, 0x72, 0x2a, 0x27, 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x76, 0x6f, 0x69, + 0x64, 0x2a, 0x27, 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x75, 0x73, 0x65, 0x72, + 0x64, 0x61, 0x74, 0x61, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x62, 0x6f, + 0x6f, 0x6c, 0x27, 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x62, 0x6f, 0x6f, 0x6c, + 0x65, 0x61, 0x6e, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x6c, 0x75, 0x61, + 0x5f, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x27, 0x5d, 0x20, 0x3d, 0x20, + 0x27, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, + 0x4c, 0x55, 0x41, 0x5f, 0x56, 0x41, 0x4c, 0x55, 0x45, 0x27, 0x5d, 0x20, + 0x3d, 0x20, 0x27, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x27, 0x2c, 0x20, 0x20, + 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6d, + 0x70, 0x61, 0x74, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x20, 0x77, + 0x69, 0x74, 0x68, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x20, 0x34, 0x2e, + 0x30, 0x0a, 0x20, 0x5b, 0x27, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, + 0x74, 0x65, 0x2a, 0x27, 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, + 0x74, 0x65, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x5f, 0x6c, 0x73, 0x74, + 0x61, 0x74, 0x65, 0x27, 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, + 0x74, 0x65, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x6c, 0x75, 0x61, 0x5f, + 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x27, 0x5d, 0x20, 0x3d, + 0x20, 0x27, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x27, 0x2c, 0x0a, 0x7d, 0x0a, + 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, 0x63, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x0a, 0x20, 0x6e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x20, 0x3d, 0x20, 0x22, 0x6c, 0x75, 0x61, 0x5f, 0x4e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x22, 0x2c, 0x0a, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x20, 0x3d, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x63, + 0x68, 0x61, 0x72, 0x2a, 0x22, 0x2c, 0x0a, 0x20, 0x75, 0x73, 0x65, 0x72, + 0x64, 0x61, 0x74, 0x61, 0x20, 0x3d, 0x20, 0x22, 0x76, 0x6f, 0x69, 0x64, + 0x2a, 0x22, 0x2c, 0x0a, 0x20, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, + 0x20, 0x3d, 0x20, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x22, 0x2c, 0x0a, 0x20, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x3d, 0x20, 0x22, 0x69, 0x6e, 0x74, + 0x22, 0x2c, 0x0a, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3d, 0x20, + 0x22, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x22, + 0x2c, 0x0a, 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x72, + 0x65, 0x20, 0x75, 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x64, 0x6f, + 0x20, 0x61, 0x20, 0x27, 0x72, 0x61, 0x77, 0x20, 0x70, 0x75, 0x73, 0x68, + 0x27, 0x20, 0x6f, 0x66, 0x20, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, + 0x72, 0x61, 0x77, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x20, 0x3d, 0x20, 0x7b, + 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x4c, 0x69, 0x73, 0x74, 0x20, 0x6f, + 0x66, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, + 0x65, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x73, 0x0a, 0x2d, 0x2d, 0x20, + 0x45, 0x61, 0x63, 0x68, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, + 0x72, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x73, 0x20, 0x74, 0x6f, + 0x20, 0x61, 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, + 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x73, 0x74, + 0x6f, 0x72, 0x65, 0x73, 0x20, 0x69, 0x74, 0x73, 0x20, 0x74, 0x61, 0x67, + 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x2e, 0x0a, 0x5f, 0x75, 0x73, 0x65, + 0x72, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x4c, 0x69, 0x73, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x68, 0x61, + 0x76, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x62, 0x65, 0x20, 0x63, 0x6f, 0x6c, + 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x0a, 0x5f, 0x63, 0x6f, 0x6c, 0x6c, + 0x65, 0x63, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x4c, 0x69, 0x73, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x73, 0x0a, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, 0x7d, + 0x0a, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, + 0x65, 0x73, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x20, 0x3d, 0x20, 0x7b, 0x7d, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x20, 0x6f, 0x66, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x0a, 0x5f, 0x67, 0x6c, + 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, + 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x4c, 0x69, + 0x73, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x20, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x73, 0x0a, 0x5f, 0x67, 0x6c, + 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x3d, + 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x4c, 0x69, 0x73, 0x74, + 0x20, 0x6f, 0x66, 0x20, 0x61, 0x75, 0x74, 0x6f, 0x20, 0x72, 0x65, 0x6e, + 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x0a, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, + 0x69, 0x6e, 0x67, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, + 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x20, 0x28, 0x73, 0x29, + 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, + 0x6f, 0x6c, 0x64, 0x2c, 0x6e, 0x65, 0x77, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x25, 0x73, 0x2a, + 0x28, 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2a, 0x40, 0x25, 0x73, 0x2a, 0x28, + 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x29, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, 0x49, + 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x72, 0x65, 0x6e, 0x61, 0x6d, + 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x6e, 0x74, 0x61, 0x78, 0x3b, 0x20, + 0x69, 0x74, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, + 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, + 0x3a, 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x40, 0x70, 0x61, + 0x74, 0x74, 0x65, 0x72, 0x6e, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x09, 0x74, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x28, 0x5f, 0x72, + 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x2c, 0x7b, 0x6f, 0x6c, 0x64, + 0x3d, 0x6f, 0x6c, 0x64, 0x2c, 0x20, 0x6e, 0x65, 0x77, 0x3d, 0x6e, 0x65, + 0x77, 0x7d, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x72, + 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x20, 0x28, 0x73, 0x29, 0x0a, + 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, 0x2c, 0x67, 0x65, 0x74, + 0x6e, 0x28, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x29, + 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6d, 0x2c, 0x6e, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x2c, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x5b, 0x69, + 0x5d, 0x2e, 0x6f, 0x6c, 0x64, 0x2c, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, + 0x69, 0x6e, 0x67, 0x5b, 0x69, 0x5d, 0x2e, 0x6e, 0x65, 0x77, 0x29, 0x0a, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x20, 0x7e, 0x3d, 0x20, 0x30, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x6d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, + 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, + 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x28, + 0x73, 0x2c, 0x66, 0x29, 0x0a, 0x69, 0x66, 0x20, 0x5f, 0x63, 0x75, 0x72, + 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x22, 0x2a, 0x2a, 0x2a, 0x63, + 0x75, 0x72, 0x72, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x66, 0x6f, 0x72, + 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, + 0x2e, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x5f, 0x63, + 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x29, 0x29, 0x0a, 0x09, + 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, + 0x74, 0x72, 0x61, 0x63, 0x65, 0x62, 0x61, 0x63, 0x6b, 0x28, 0x29, 0x29, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x5f, 0x4f, 0x55, 0x54, 0x50, 0x55, + 0x54, 0x0a, 0x20, 0x5f, 0x4f, 0x55, 0x54, 0x50, 0x55, 0x54, 0x20, 0x3d, + 0x20, 0x5f, 0x53, 0x54, 0x44, 0x45, 0x52, 0x52, 0x0a, 0x20, 0x69, 0x66, + 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x31, 0x2c, + 0x31, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x23, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, 0x22, + 0x5c, 0x6e, 0x2a, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, 0x20, + 0x22, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, + 0x32, 0x29, 0x2e, 0x2e, 0x22, 0x2e, 0x5c, 0x6e, 0x5c, 0x6e, 0x22, 0x29, + 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, + 0x63, 0x6f, 0x64, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x73, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x5f, + 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x28, 0x2e, 0x2d, 0x5c, 0x6e, 0x29, 0x22, 0x29, 0x20, + 0x2d, 0x2d, 0x20, 0x65, 0x78, 0x74, 0x72, 0x61, 0x63, 0x74, 0x20, 0x66, + 0x69, 0x72, 0x73, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x20, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x5f, 0x63, 0x75, 0x72, + 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x2c, 0x22, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, 0x74, 0x61, 0x22, + 0x2c, 0x22, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x22, 0x29, 0x20, 0x2d, 0x2d, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x77, 0x69, 0x74, 0x68, + 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x27, 0x0a, 0x20, 0x20, 0x20, + 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, + 0x5f, 0x63, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x2c, 0x22, 0x63, + 0x68, 0x61, 0x72, 0x2a, 0x22, 0x29, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x27, + 0x63, 0x68, 0x61, 0x72, 0x2a, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x73, 0x20, + 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x5f, 0x6c, + 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x2c, 0x22, 0x6c, 0x75, 0x61, 0x5f, + 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x22, 0x29, 0x20, 0x20, 0x2d, 0x2d, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x77, 0x69, 0x74, 0x68, + 0x20, 0x27, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, + 0x27, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, 0x22, + 0x43, 0x6f, 0x64, 0x65, 0x20, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x20, 0x70, + 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x3a, 0x5c, 0x6e, 0x22, + 0x2e, 0x2e, 0x73, 0x2e, 0x2e, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, + 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x66, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x22, 0x28, 0x66, 0x20, 0x69, 0x73, + 0x20, 0x6e, 0x69, 0x6c, 0x29, 0x22, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x22, 0x5c, 0x6e, 0x2a, 0x2a, + 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, + 0x6e, 0x61, 0x6c, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3a, 0x20, 0x22, + 0x2e, 0x2e, 0x66, 0x2e, 0x2e, 0x73, 0x2e, 0x2e, 0x22, 0x2e, 0x5c, 0x6e, + 0x5c, 0x6e, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x5f, 0x4f, 0x55, 0x54, + 0x50, 0x55, 0x54, 0x20, 0x3d, 0x20, 0x6f, 0x75, 0x74, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x28, 0x6d, 0x73, 0x67, + 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x2e, + 0x71, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x5f, 0x4f, 0x55, 0x54, 0x50, + 0x55, 0x54, 0x0a, 0x20, 0x5f, 0x4f, 0x55, 0x54, 0x50, 0x55, 0x54, 0x20, + 0x3d, 0x20, 0x5f, 0x53, 0x54, 0x44, 0x45, 0x52, 0x52, 0x0a, 0x20, 0x77, + 0x72, 0x69, 0x74, 0x65, 0x28, 0x22, 0x5c, 0x6e, 0x2a, 0x2a, 0x20, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x20, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, + 0x3a, 0x20, 0x22, 0x2e, 0x2e, 0x6d, 0x73, 0x67, 0x2e, 0x2e, 0x22, 0x2e, + 0x5c, 0x6e, 0x5c, 0x6e, 0x22, 0x29, 0x0a, 0x20, 0x5f, 0x4f, 0x55, 0x54, + 0x50, 0x55, 0x54, 0x20, 0x3d, 0x20, 0x6f, 0x75, 0x74, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, + 0x65, 0x72, 0x20, 0x61, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x64, + 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3a, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x66, 0x75, 0x6c, + 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x72, 0x65, 0x67, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x28, 0x74, 0x29, 0x0a, 0x09, 0x2d, 0x2d, 0x69, 0x66, 0x20, 0x69, 0x73, + 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x29, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x74, 0x0a, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x69, + 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x29, 0x0a, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x5f, 0x75, 0x73, 0x65, 0x72, + 0x74, 0x79, 0x70, 0x65, 0x5b, 0x66, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x61, + 0x70, 0x70, 0x65, 0x6e, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, + 0x65, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x74, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x20, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x66, 0x75, 0x6c, 0x6c, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x76, 0x61, 0x72, 0x28, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x74, + 0x20, 0x3d, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, + 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x66, + 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x74, 0x0a, 0x09, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x09, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, + 0x65, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x79, + 0x70, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, + 0x69, 0x66, 0x20, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, + 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, + 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, + 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x2c, 0x74, 0x20, 0x3d, + 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, + 0x66, 0x28, 0x27, 0x27, 0x2c, 0x20, 0x74, 0x29, 0x0a, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x62, 0x20, 0x3d, 0x20, 0x5f, 0x62, 0x61, 0x73, + 0x69, 0x63, 0x5b, 0x74, 0x5d, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x62, 0x2c, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, 0x63, + 0x74, 0x79, 0x70, 0x65, 0x5b, 0x62, 0x5d, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x73, 0x70, 0x6c, + 0x69, 0x74, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x75, 0x73, + 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x70, 0x6c, + 0x69, 0x74, 0x20, 0x28, 0x73, 0x2c, 0x74, 0x29, 0x0a, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, + 0x7d, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, + 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x73, + 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x6c, 0x2e, + 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x20, 0x6c, 0x5b, 0x6c, 0x2e, + 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x20, 0x3d, 0x20, 0x22, + 0x25, 0x73, 0x2a, 0x28, 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2a, 0x22, 0x2e, + 0x2e, 0x74, 0x2e, 0x2e, 0x22, 0x25, 0x73, 0x2a, 0x22, 0x0a, 0x20, 0x73, + 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2b, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x73, 0x20, + 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x25, 0x73, + 0x2b, 0x24, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x73, 0x20, 0x3d, + 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x70, 0x2c, 0x66, 0x29, + 0x0a, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x6c, 0x2e, 0x6e, 0x20, + 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x6c, 0x5b, 0x6c, 0x2e, 0x6e, 0x5d, 0x20, + 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x28, 0x25, + 0x73, 0x25, 0x73, 0x2a, 0x29, 0x24, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x73, + 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x75, 0x73, + 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, + 0x6e, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72, 0x69, + 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x70, 0x61, 0x63, 0x69, + 0x61, 0x6c, 0x20, 0x63, 0x61, 0x73, 0x65, 0x73, 0x20, 0x6f, 0x66, 0x20, + 0x43, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x28, 0x74, 0x65, 0x6d, 0x70, + 0x6c, 0x61, 0x74, 0x65, 0x73, 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, + 0x72, 0x73, 0x2c, 0x20, 0x65, 0x74, 0x63, 0x29, 0x0a, 0x2d, 0x2d, 0x20, + 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x20, 0x63, 0x61, 0x6e, 0x27, + 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x27, 0x5e, 0x27, 0x20, 0x28, 0x61, 0x73, 0x20, 0x75, 0x73, + 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, + 0x66, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x65, 0x67, 0x69, 0x6e, + 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, + 0x69, 0x6e, 0x65, 0x29, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6c, 0x73, 0x6f, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x73, 0x20, 0x77, 0x68, 0x69, 0x74, + 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, + 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x20, 0x70, 0x61, + 0x74, 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, + 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, + 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, + 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x62, 0x65, + 0x67, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x65, 0x6e, 0x64, + 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, + 0x30, 0x7d, 0x0a, 0x0a, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x61, 0x64, 0x64, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x28, + 0x6f, 0x66, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x74, 0x6f, 0x6b, 0x65, + 0x6e, 0x5f, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x2c, 0x20, 0x6f, 0x66, 0x73, + 0x29, 0x0a, 0x09, 0x09, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, 0x20, 0x22, + 0x5e, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, + 0x09, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, + 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x6e, 0x20, + 0x2b, 0x20, 0x31, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x5b, 0x72, 0x65, + 0x74, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x6f, 0x66, + 0x73, 0x20, 0x3c, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x6c, 0x65, 0x6e, 0x28, 0x73, 0x29, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x75, 0x62, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x2c, 0x20, 0x2d, 0x31, 0x29, 0x0a, + 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x73, 0x75, 0x62, 0x2c, 0x20, 0x22, 0x5e, 0x22, 0x2e, 0x2e, + 0x70, 0x61, 0x74, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x61, 0x64, 0x64, 0x5f, + 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x28, 0x6f, 0x66, 0x73, 0x2d, 0x31, 0x29, + 0x0a, 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, + 0x73, 0x2b, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x5f, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, + 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x29, 0x0a, + 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, + 0x3d, 0x20, 0x22, 0x28, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x68, 0x61, + 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x3c, 0x22, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, + 0x66, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x28, + 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x20, 0x3d, 0x20, 0x22, 0x5e, 0x25, 0x62, 0x28, 0x29, 0x22, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x68, + 0x61, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x3c, 0x22, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x20, 0x3d, 0x20, 0x22, + 0x5e, 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x62, 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x75, + 0x62, 0x2c, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x29, 0x0a, 0x09, 0x09, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, + 0x75, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x64, + 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x3f, 0x0a, 0x09, 0x09, 0x09, 0x09, + 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, 0x2b, 0x31, + 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, + 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, + 0x20, 0x2b, 0x20, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, + 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, 0x2b, + 0x31, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x61, 0x64, + 0x64, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x28, 0x6f, 0x66, 0x73, 0x29, + 0x0a, 0x09, 0x2d, 0x2d, 0x69, 0x66, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x6e, + 0x20, 0x3d, 0x3d, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, + 0x09, 0x2d, 0x2d, 0x09, 0x72, 0x65, 0x74, 0x2e, 0x6e, 0x3d, 0x31, 0x0a, + 0x09, 0x2d, 0x2d, 0x09, 0x72, 0x65, 0x74, 0x5b, 0x31, 0x5d, 0x20, 0x3d, + 0x20, 0x22, 0x22, 0x0a, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x0a, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x6f, 0x6e, + 0x63, 0x61, 0x74, 0x65, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x74, 0x61, + 0x62, 0x6c, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x20, 0x28, 0x74, 0x2c, 0x66, + 0x2c, 0x6c, 0x2c, 0x6a, 0x73, 0x74, 0x72, 0x29, 0x0a, 0x09, 0x6a, 0x73, + 0x74, 0x72, 0x20, 0x3d, 0x20, 0x6a, 0x73, 0x74, 0x72, 0x20, 0x6f, 0x72, + 0x20, 0x22, 0x20, 0x22, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x73, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x69, 0x3d, 0x66, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, + 0x20, 0x69, 0x3c, 0x3d, 0x6c, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x73, + 0x20, 0x3d, 0x20, 0x73, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x20, + 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x69, 0x20, 0x3c, 0x3d, 0x20, 0x6c, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x2e, 0x2e, 0x6a, 0x73, 0x74, + 0x72, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x65, + 0x6e, 0x61, 0x74, 0x65, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x70, 0x61, 0x72, + 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x2c, 0x20, 0x66, 0x6f, 0x6c, + 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x20, 0x72, 0x75, 0x6c, 0x65, 0x73, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x20, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x20, + 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x69, + 0x3c, 0x3d, 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x2c, 0x27, 0x5b, 0x25, 0x28, + 0x2c, 0x22, 0x5d, 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, + 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x22, 0x5e, 0x5b, 0x25, 0x61, 0x5f, + 0x7e, 0x5d, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, + 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x6c, 0x69, + 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x27, 0x20, 0x27, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, + 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x61, 0x72, 0x67, + 0x5b, 0x69, 0x5d, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x61, 0x72, 0x67, + 0x5b, 0x69, 0x5d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x72, 0x67, + 0x5b, 0x69, 0x5d, 0x2c, 0x2d, 0x31, 0x2c, 0x2d, 0x31, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, + 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x72, 0x67, 0x5b, + 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x5d, 0x2c, 0x22, 0x5b, 0x25, 0x2f, 0x25, + 0x29, 0x25, 0x3b, 0x25, 0x7b, 0x25, 0x7d, 0x5d, 0x24, 0x22, 0x29, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, + 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, + 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x27, 0x5c, 0x6e, 0x27, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x6c, 0x69, + 0x6e, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x28, 0x2e, 0x2e, 0x2e, 0x29, + 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, + 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x69, 0x3c, 0x3d, 0x61, 0x72, + 0x67, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x5f, 0x63, + 0x6f, 0x6e, 0x74, 0x2c, 0x27, 0x5b, 0x25, 0x28, 0x2c, 0x22, 0x5d, 0x27, + 0x29, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, + 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, + 0x5d, 0x2c, 0x22, 0x5e, 0x5b, 0x25, 0x61, 0x5f, 0x7e, 0x5d, 0x22, 0x29, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x20, 0x77, + 0x72, 0x69, 0x74, 0x65, 0x28, 0x27, 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, + 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, + 0x20, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x20, 0x7e, 0x3d, 0x20, 0x27, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, + 0x6f, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, + 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x2d, 0x31, 0x2c, 0x2d, + 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, + 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x61, 0x72, 0x67, 0x5b, 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x5d, 0x2c, 0x22, + 0x5b, 0x25, 0x2f, 0x25, 0x29, 0x25, 0x3b, 0x25, 0x7b, 0x25, 0x7d, 0x5d, + 0x24, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x5f, + 0x63, 0x6f, 0x6e, 0x74, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x77, 0x72, 0x69, + 0x74, 0x65, 0x28, 0x27, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, + 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, + 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, + 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, + 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x5f, 0x68, 0x6f, + 0x6f, 0x6b, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x6e, 0x61, 0x6d, + 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, + 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x3d, 0x20, 0x22, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x22, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, + 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x73, 0x65, 0x74, 0x5f, 0x6e, + 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x22, 0x67, 0x65, 0x74, 0x5f, 0x22, 0x2e, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x2c, 0x20, 0x22, 0x73, 0x65, 0x74, 0x5f, 0x22, 0x2e, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, + 0x71, 0x74, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x73, 0x65, 0x74, 0x4e, 0x61, 0x6d, + 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x73, 0x65, 0x74, 0x22, 0x2e, 0x2e, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x75, 0x70, 0x70, 0x65, 0x72, + 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x29, 0x29, + 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, + 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x32, 0x2c, 0x20, 0x2d, 0x31, + 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, + 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6f, 0x76, + 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x2d, 0x2d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x6e, 0x61, + 0x6d, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x2d, + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x68, 0x6f, 0x6f, 0x6b, 0x73, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x72, 0x69, 0x67, + 0x68, 0x74, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, + 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, + 0x24, 0x5b, 0x69, 0x63, 0x68, 0x6c, 0x5d, 0x66, 0x69, 0x6c, 0x65, 0x20, + 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x73, 0x2c, 0x0a, + 0x2d, 0x2d, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x62, 0x65, 0x66, + 0x6f, 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, + 0x6e, 0x67, 0x20, 0x61, 0x6e, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, + 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, + 0x65, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x61, 0x73, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, + 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, + 0x72, 0x65, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x68, 0x6f, + 0x6f, 0x6b, 0x28, 0x70, 0x29, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x70, 0x2e, + 0x63, 0x6f, 0x64, 0x65, 0x20, 0x68, 0x61, 0x73, 0x20, 0x61, 0x6c, 0x6c, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x63, + 0x6f, 0x64, 0x65, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, + 0x20, 0x70, 0x6b, 0x67, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x72, + 0x20, 0x65, 0x76, 0x65, 0x72, 0x79, 0x20, 0x24, 0x69, 0x66, 0x69, 0x6c, + 0x65, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x0a, + 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x61, 0x20, 0x74, + 0x61, 0x62, 0x6c, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, + 0x64, 0x20, 0x27, 0x63, 0x6f, 0x64, 0x65, 0x27, 0x20, 0x69, 0x6e, 0x73, + 0x69, 0x64, 0x65, 0x2c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, + 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, + 0x6e, 0x79, 0x20, 0x65, 0x78, 0x74, 0x72, 0x61, 0x20, 0x61, 0x72, 0x67, + 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x70, 0x61, + 0x73, 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x24, 0x69, 0x66, 0x69, + 0x6c, 0x65, 0x2e, 0x20, 0x6e, 0x6f, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, + 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x74, + 0x2c, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, + 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x61, 0x66, 0x74, + 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, + 0x67, 0x20, 0x61, 0x6e, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x74, + 0x68, 0x61, 0x74, 0x27, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x63, 0x6f, + 0x64, 0x65, 0x20, 0x28, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x27, 0x24, 0x72, + 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x27, 0x2c, 0x20, 0x63, 0x6f, + 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2c, 0x20, 0x65, 0x74, 0x63, 0x29, + 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x72, 0x69, 0x67, 0x68, + 0x74, 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x70, 0x61, 0x72, + 0x73, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x63, 0x74, + 0x75, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x0a, 0x2d, 0x2d, + 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x50, + 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, + 0x74, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x74, + 0x68, 0x65, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x6f, 0x6e, 0x20, 0x74, + 0x68, 0x65, 0x20, 0x27, 0x63, 0x6f, 0x64, 0x65, 0x27, 0x20, 0x6b, 0x65, + 0x79, 0x2e, 0x20, 0x6e, 0x6f, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x70, 0x61, 0x72, 0x73, 0x65, + 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, + 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, + 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, + 0x65, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, + 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x61, 0x66, 0x74, 0x65, + 0x72, 0x20, 0x77, 0x72, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6c, + 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x2e, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x74, + 0x68, 0x65, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, 0x6f, + 0x62, 0x6a, 0x65, 0x63, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, + 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, + 0x6f, 0x6d, 0x20, 0x27, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, + 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, + 0x27, 0x20, 0x74, 0x6f, 0x20, 0x67, 0x65, 0x74, 0x20, 0x74, 0x68, 0x65, + 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x20, 0x74, 0x6f, 0x20, + 0x72, 0x65, 0x74, 0x72, 0x69, 0x65, 0x76, 0x65, 0x20, 0x61, 0x20, 0x70, + 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x0a, 0x2d, 0x2d, 0x20, 0x61, + 0x63, 0x63, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x6f, 0x20, + 0x69, 0x74, 0x73, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, + 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, + 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x72, 0x6f, 0x70, + 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, + 0x6d, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x64, 0x6f, 0x70, 0x61, 0x72, 0x73, 0x65, + 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x20, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x20, 0x70, + 0x61, 0x72, 0x73, 0x65, 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x2c, 0x20, 0x6f, 0x72, 0x20, + 0x61, 0x20, 0x73, 0x75, 0x62, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x72, + 0x73, 0x65, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x29, 0x0a, + 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, + 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x73, + 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x62, 0x65, 0x66, 0x6f, + 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, + 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, + 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, + 0x28, 0x66, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, + 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, + 0x6c, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, + 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x66, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, + 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x72, + 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x20, 0x63, 0x6f, 0x64, 0x65, + 0x20, 0x69, 0x73, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x5f, + 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x68, 0x6f, 0x6f, + 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, + 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x20, 0x61, 0x6e, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x2e, 0x2e, 0x2e, + 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x28, + 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x20, 0x70, 0x75, 0x73, 0x68, + 0x65, 0x72, 0x73, 0x0a, 0x0a, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, + 0x7d, 0x0a, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x74, 0x6f, + 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, + 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x70, + 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x65, + 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x65, + 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, + 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, + 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x3d, + 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x0a, 0x0a, 0x09, 0x77, 0x68, + 0x69, 0x6c, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x64, 0x6f, + 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, 0x5b, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, 0x5b, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x3d, + 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x65, 0x73, 0x5b, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x62, + 0x74, 0x79, 0x70, 0x65, 0x5d, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, 0x5d, + 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, + 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x65, + 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x75, 0x73, 0x65, 0x72, 0x74, + 0x79, 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x74, + 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, + 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x74, + 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, + 0x74, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, + 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, + 0x73, 0x65, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, + 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x69, 0x73, 0x5f, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, 0x5d, + 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, + 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x65, + 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x22, + 0x0a, 0x65, 0x6e, 0x64, 0x0a +}; +unsigned int lua_basic_lua_len = 8909; diff --git a/lib/tolua++/src/bin/enumerate_lua.h b/lib/tolua++/src/bin/enumerate_lua.h new file mode 100644 index 000000000..271cf2a23 --- /dev/null +++ b/lib/tolua++/src/bin/enumerate_lua.h @@ -0,0 +1,281 @@ +unsigned char lua_enumerate_lua[] = { + 0x2d, 0x2d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, 0x20, 0x65, 0x6e, + 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x57, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, + 0x20, 0x62, 0x79, 0x20, 0x57, 0x61, 0x6c, 0x64, 0x65, 0x6d, 0x61, 0x72, + 0x20, 0x43, 0x65, 0x6c, 0x65, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x65, + 0x43, 0x47, 0x72, 0x61, 0x66, 0x2f, 0x50, 0x55, 0x43, 0x2d, 0x52, 0x69, + 0x6f, 0x0a, 0x2d, 0x2d, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x31, 0x39, 0x39, + 0x38, 0x0a, 0x2d, 0x2d, 0x20, 0x24, 0x49, 0x64, 0x3a, 0x20, 0x65, 0x6e, + 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x2e, 0x6c, 0x75, 0x61, 0x2c, + 0x76, 0x20, 0x31, 0x2e, 0x33, 0x20, 0x32, 0x30, 0x30, 0x30, 0x2f, 0x30, + 0x31, 0x2f, 0x32, 0x34, 0x20, 0x32, 0x30, 0x3a, 0x34, 0x31, 0x3a, 0x31, + 0x35, 0x20, 0x63, 0x65, 0x6c, 0x65, 0x73, 0x20, 0x45, 0x78, 0x70, 0x20, + 0x24, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x63, + 0x6f, 0x64, 0x65, 0x20, 0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, + 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x3b, 0x20, 0x79, 0x6f, + 0x75, 0x20, 0x63, 0x61, 0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, + 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69, 0x74, 0x20, 0x61, 0x6e, + 0x64, 0x2f, 0x6f, 0x72, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x20, + 0x69, 0x74, 0x2e, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x68, 0x65, 0x20, 0x73, + 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x76, + 0x69, 0x64, 0x65, 0x64, 0x20, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6e, 0x64, + 0x65, 0x72, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x20, + 0x22, 0x61, 0x73, 0x20, 0x69, 0x73, 0x22, 0x20, 0x62, 0x61, 0x73, 0x69, + 0x73, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x20, 0x68, 0x61, 0x73, + 0x20, 0x6e, 0x6f, 0x20, 0x6f, 0x62, 0x6c, 0x69, 0x67, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, + 0x65, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x61, 0x6e, 0x63, + 0x65, 0x2c, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2c, 0x20, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x73, 0x2c, 0x0a, 0x2d, 0x2d, 0x20, + 0x65, 0x6e, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, + 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x52, 0x65, 0x70, 0x72, + 0x65, 0x73, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x65, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x68, + 0x65, 0x20, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x20, + 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x73, + 0x74, 0x6f, 0x72, 0x65, 0x64, 0x3a, 0x0a, 0x2d, 0x2d, 0x20, 0x20, 0x20, + 0x20, 0x7b, 0x69, 0x7d, 0x20, 0x3d, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x20, + 0x6f, 0x66, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, + 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x0a, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x45, + 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x3d, 0x20, 0x7b, + 0x0a, 0x7d, 0x0a, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x45, 0x6e, 0x75, 0x6d, + 0x65, 0x72, 0x61, 0x74, 0x65, 0x2e, 0x5f, 0x5f, 0x69, 0x6e, 0x64, 0x65, + 0x78, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x45, 0x6e, 0x75, + 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x0a, 0x73, 0x65, 0x74, 0x6d, 0x65, + 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x2c, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x29, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, + 0x72, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, + 0x65, 0x3a, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x20, 0x28, + 0x70, 0x72, 0x65, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, + 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, + 0x73, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x70, 0x72, 0x65, 0x20, 0x3d, 0x20, 0x70, 0x72, 0x65, 0x20, 0x6f, 0x72, + 0x20, 0x27, 0x27, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, + 0x63, 0x75, 0x72, 0x72, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, + 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x69, + 0x5d, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x28, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x2e, + 0x2e, 0x27, 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x73, 0x70, 0x61, 0x63, + 0x65, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x2e, 0x2e, + 0x27, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x50, 0x72, + 0x69, 0x6e, 0x74, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x3a, 0x70, + 0x72, 0x69, 0x6e, 0x74, 0x20, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2c, + 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, + 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x45, 0x6e, + 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x7b, 0x22, 0x29, 0x0a, 0x20, + 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, + 0x2e, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x22, 0x2e, + 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, + 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, + 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x27, 0x22, + 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x2e, 0x2e, 0x22, + 0x27, 0x28, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x2e, 0x22, 0x29, 0x2c, + 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x7d, 0x22, 0x2e, + 0x2e, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x3d, 0x20, + 0x7b, 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, + 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x63, 0x6f, 0x64, + 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, + 0x65, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x28, 0x29, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, + 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, 0x6d, + 0x73, 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x5d, + 0x20, 0x7e, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x3d, + 0x20, 0x31, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x22, 0x69, 0x6e, 0x74, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, + 0x73, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x28, 0x6c, 0x75, + 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x20, 0x4c, 0x2c, 0x20, + 0x69, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x2c, 0x20, 0x69, 0x6e, 0x74, 0x20, + 0x64, 0x65, 0x66, 0x2c, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x45, + 0x72, 0x72, 0x6f, 0x72, 0x2a, 0x20, 0x65, 0x72, 0x72, 0x29, 0x22, 0x29, + 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x7b, + 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x22, 0x69, 0x66, 0x20, 0x28, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x69, 0x73, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x4c, 0x2c, 0x6c, + 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x2c, 0x65, 0x72, 0x72, 0x29, 0x29, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x30, 0x3b, 0x22, 0x29, 0x0a, + 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x69, 0x6e, + 0x74, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x4c, + 0x2c, 0x6c, 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x29, 0x3b, 0x22, 0x29, 0x0a, + 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3e, 0x3d, 0x20, + 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x69, + 0x6e, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x26, 0x26, 0x20, 0x76, 0x61, + 0x6c, 0x20, 0x3c, 0x3d, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x3b, 0x22, + 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, + 0x7d, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, + 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, + 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, + 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x28, 0x74, + 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x73, + 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, + 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x45, 0x6e, 0x75, 0x6d, 0x65, + 0x72, 0x61, 0x74, 0x65, 0x29, 0x0a, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, + 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, + 0x65, 0x6e, 0x75, 0x6d, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x20, 0x69, 0x66, + 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, + 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x69, 0x66, + 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x22, + 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x56, 0x61, + 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, + 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, + 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, + 0x3d, 0x20, 0x67, 0x65, 0x74, 0x63, 0x75, 0x72, 0x72, 0x6e, 0x61, 0x6d, + 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x29, 0x0a, 0x09, 0x09, 0x09, + 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x28, 0x22, 0x56, 0x61, 0x72, + 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x22, 0x2e, 0x2e, 0x6e, 0x73, 0x2e, + 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, + 0x6f, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3c, 0x61, 0x6e, 0x6f, + 0x6e, 0x79, 0x6d, 0x6f, 0x75, 0x73, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x3e, + 0x20, 0x69, 0x73, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, 0x64, + 0x20, 0x61, 0x73, 0x20, 0x72, 0x65, 0x61, 0x64, 0x2d, 0x6f, 0x6e, 0x6c, + 0x79, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, + 0x62, 0x6c, 0x65, 0x28, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, + 0x65, 0x61, 0x64, 0x6f, 0x6e, 0x6c, 0x79, 0x20, 0x69, 0x6e, 0x74, 0x20, + 0x22, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6e, + 0x74, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x0a, + 0x09, 0x20, 0x69, 0x66, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x74, 0x2e, 0x61, 0x63, 0x63, + 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, + 0x2e, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, + 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x0a, 0x09, 0x09, 0x74, 0x2e, + 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, + 0x73, 0x20, 0x3d, 0x20, 0x74, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, + 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, + 0x73, 0x28, 0x29, 0x0a, 0x09, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, + 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, 0x78, 0x70, 0x65, 0x63, + 0x74, 0x73, 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, + 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, + 0x74, 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, + 0x74, 0x65, 0x20, 0x28, 0x6e, 0x2c, 0x62, 0x2c, 0x76, 0x61, 0x72, 0x6e, + 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x62, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x62, 0x2c, + 0x20, 0x22, 0x2c, 0x5b, 0x25, 0x73, 0x5c, 0x6e, 0x5d, 0x2a, 0x7d, 0x22, + 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x7d, 0x22, 0x29, 0x20, 0x2d, 0x2d, 0x20, + 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x6c, 0x61, + 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, + 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x62, 0x2c, 0x32, 0x2c, 0x2d, + 0x32, 0x29, 0x2c, 0x27, 0x2c, 0x27, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x65, + 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x62, 0x72, 0x61, + 0x63, 0x65, 0x73, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, + 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, 0x7d, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x3d, + 0x20, 0x30, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x69, + 0x6e, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x77, 0x68, + 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, + 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x74, 0x20, 0x3d, + 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, + 0x27, 0x3d, 0x27, 0x29, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x69, 0x73, + 0x63, 0x61, 0x72, 0x64, 0x20, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, + 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x2e, 0x6e, + 0x20, 0x3d, 0x20, 0x65, 0x2e, 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x09, + 0x09, 0x65, 0x5b, 0x65, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x74, + 0x5b, 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, + 0x3d, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x74, + 0x74, 0x5b, 0x32, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, + 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x74, 0x5b, 0x32, + 0x5d, 0x20, 0x3d, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x20, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x2b, + 0x20, 0x31, 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x64, 0x76, 0x61, 0x6e, 0x63, + 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, + 0x65, 0x64, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x09, 0x09, 0x69, + 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3e, 0x20, 0x6d, 0x61, + 0x78, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x61, + 0x78, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, + 0x32, 0x5d, 0x20, 0x3c, 0x20, 0x6d, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x74, + 0x74, 0x5b, 0x32, 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x09, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x73, 0x65, 0x74, 0x20, 0x6c, 0x75, + 0x61, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x0a, 0x09, 0x69, 0x20, 0x20, + 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x65, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x63, 0x75, + 0x72, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, + 0x29, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x65, 0x5b, 0x69, + 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x65, + 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x40, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x65, + 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, + 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x74, 0x5b, 0x32, 0x5d, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x5b, 0x32, + 0x5d, 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x72, 0x65, 0x6e, + 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x29, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x2e, 0x6c, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x5b, + 0x32, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, + 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x5b, 0x20, 0x6e, 0x73, 0x2e, 0x2e, 0x65, 0x5b, 0x69, 0x5d, + 0x20, 0x5d, 0x20, 0x3d, 0x20, 0x28, 0x6e, 0x73, 0x2e, 0x2e, 0x65, 0x5b, + 0x69, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, + 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x6e, 0x0a, 0x09, 0x65, 0x2e, 0x6d, 0x69, + 0x6e, 0x20, 0x3d, 0x20, 0x6d, 0x69, 0x6e, 0x0a, 0x09, 0x65, 0x2e, 0x6d, + 0x61, 0x78, 0x20, 0x3d, 0x20, 0x6d, 0x61, 0x78, 0x0a, 0x09, 0x69, 0x66, + 0x20, 0x6e, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x54, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, + 0x22, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x6e, 0x29, 0x0a, 0x09, + 0x09, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x5b, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x22, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x69, 0x73, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x6e, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x5f, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, + 0x65, 0x2c, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a +}; +unsigned int lua_enumerate_lua_len = 3329; diff --git a/lib/tolua++/src/bin/function_lua.h b/lib/tolua++/src/bin/function_lua.h new file mode 100644 index 000000000..c1317b9fe --- /dev/null +++ b/lib/tolua++/src/bin/function_lua.h @@ -0,0 +1,1192 @@ +unsigned char lua_function_lua[] = { + 0x2d, 0x2d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, 0x20, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x0a, 0x2d, 0x2d, 0x20, 0x57, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20, + 0x62, 0x79, 0x20, 0x57, 0x61, 0x6c, 0x64, 0x65, 0x6d, 0x61, 0x72, 0x20, + 0x43, 0x65, 0x6c, 0x65, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x65, 0x43, + 0x47, 0x72, 0x61, 0x66, 0x2f, 0x50, 0x55, 0x43, 0x2d, 0x52, 0x69, 0x6f, + 0x0a, 0x2d, 0x2d, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x31, 0x39, 0x39, 0x38, + 0x0a, 0x2d, 0x2d, 0x20, 0x24, 0x49, 0x64, 0x3a, 0x20, 0x24, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x63, 0x6f, 0x64, 0x65, + 0x20, 0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x73, 0x6f, 0x66, + 0x74, 0x77, 0x61, 0x72, 0x65, 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, + 0x61, 0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, + 0x75, 0x74, 0x65, 0x20, 0x69, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, + 0x72, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x20, 0x69, 0x74, 0x2e, + 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x68, 0x65, 0x20, 0x73, 0x6f, 0x66, 0x74, + 0x77, 0x61, 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, + 0x64, 0x20, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, + 0x69, 0x73, 0x20, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x20, 0x22, 0x61, 0x73, + 0x20, 0x69, 0x73, 0x22, 0x20, 0x62, 0x61, 0x73, 0x69, 0x73, 0x2c, 0x20, + 0x61, 0x6e, 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, + 0x75, 0x74, 0x68, 0x6f, 0x72, 0x20, 0x68, 0x61, 0x73, 0x20, 0x6e, 0x6f, + 0x20, 0x6f, 0x62, 0x6c, 0x69, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x74, 0x6f, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x20, 0x6d, + 0x61, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x61, 0x6e, 0x63, 0x65, 0x2c, 0x20, + 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2c, 0x20, 0x75, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x73, 0x2c, 0x0a, 0x2d, 0x2d, 0x20, 0x65, 0x6e, 0x68, + 0x61, 0x6e, 0x63, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2c, 0x20, 0x6f, + 0x72, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x2e, 0x0a, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x46, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x52, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, + 0x6e, 0x74, 0x73, 0x20, 0x61, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x2e, 0x0a, 0x2d, 0x2d, + 0x20, 0x54, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x69, + 0x6e, 0x67, 0x20, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x20, 0x61, 0x72, + 0x65, 0x20, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x64, 0x3a, 0x0a, 0x2d, 0x2d, + 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x20, 0x3d, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x72, 0x73, 0x0a, + 0x2d, 0x2d, 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x20, 0x70, 0x74, 0x72, 0x20, + 0x20, 0x3d, 0x20, 0x22, 0x2a, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x26, + 0x22, 0x2c, 0x20, 0x69, 0x66, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, + 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x70, 0x6f, 0x69, + 0x6e, 0x74, 0x65, 0x72, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x20, 0x72, 0x65, + 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x20, + 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, + 0x2d, 0x2d, 0x20, 0x20, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, + 0x6c, 0x75, 0x61, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x2d, 0x2d, 0x20, + 0x20, 0x61, 0x72, 0x67, 0x73, 0x20, 0x20, 0x3d, 0x20, 0x6c, 0x69, 0x73, + 0x74, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, + 0x74, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x20, 0x3d, 0x20, 0x69, 0x66, 0x20, 0x69, 0x74, 0x20, 0x69, 0x73, 0x20, + 0x61, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x20, 0x72, 0x65, 0x63, + 0x65, 0x69, 0x76, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6e, + 0x73, 0x74, 0x20, 0x22, 0x74, 0x68, 0x69, 0x73, 0x22, 0x2e, 0x0a, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x3d, 0x20, 0x7b, 0x0a, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, + 0x27, 0x27, 0x2c, 0x0a, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, + 0x27, 0x27, 0x2c, 0x0a, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, + 0x27, 0x2c, 0x0a, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, + 0x27, 0x2c, 0x0a, 0x20, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x7b, + 0x6e, 0x3d, 0x30, 0x7d, 0x2c, 0x0a, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x20, 0x3d, 0x20, 0x27, 0x27, 0x2c, 0x0a, 0x7d, 0x0a, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x5f, + 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x73, + 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x65, 0x61, 0x74, 0x75, + 0x72, 0x65, 0x29, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x63, 0x6c, + 0x61, 0x72, 0x65, 0x20, 0x74, 0x61, 0x67, 0x73, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x64, 0x65, 0x63, 0x6c, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x76, 0x61, 0x72, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x66, + 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, + 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, + 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x0a, 0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x20, + 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6d, 0x6f, 0x64, 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x2c, + 0x27, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, + 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, + 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x64, 0x65, + 0x63, 0x6c, 0x74, 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x69, + 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x57, 0x72, 0x69, + 0x74, 0x65, 0x20, 0x62, 0x69, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x2d, 0x2d, 0x20, 0x4f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x73, 0x20, 0x43, 0x2f, 0x43, 0x2b, 0x2b, + 0x20, 0x62, 0x69, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, + 0x65, 0x20, 0x28, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, + 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x29, 0x0a, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, + 0x64, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x2d, 0x32, + 0x2c, 0x2d, 0x31, 0x29, 0x20, 0x2d, 0x20, 0x31, 0x20, 0x20, 0x2d, 0x2d, + 0x20, 0x69, 0x6e, 0x64, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x6f, 0x76, + 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x65, 0x64, 0x20, 0x66, 0x75, 0x6e, + 0x63, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x72, 0x65, + 0x74, 0x20, 0x3d, 0x20, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, + 0x2d, 0x20, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, 0x6f, 0x66, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x65, 0x64, 0x20, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x73, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x3a, + 0x69, 0x6e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x28, 0x29, 0x0a, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x73, 0x74, 0x61, + 0x74, 0x69, 0x63, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x27, + 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x29, + 0x27, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x3d, + 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x66, + 0x6c, 0x61, 0x67, 0x73, 0x2e, 0x70, 0x75, 0x72, 0x65, 0x5f, 0x76, 0x69, + 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x6e, 0x6f, 0x20, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, + 0x20, 0x70, 0x75, 0x72, 0x65, 0x20, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, + 0x6c, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x0a, 0x20, 0x09, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, + 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x6d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x3a, 0x20, 0x6e, 0x65, 0x77, 0x5f, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x22, + 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2c, 0x22, 0x20, 0x2a, 0x2f, 0x22, + 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x6d, 0x65, 0x74, + 0x68, 0x6f, 0x64, 0x3a, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x20, 0x22, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2c, 0x22, + 0x20, 0x2a, 0x2f, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x3a, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x2c, 0x22, 0x20, 0x2a, 0x2f, 0x22, 0x29, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, + 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x22, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, + 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, + 0x4c, 0x45, 0x5f, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, + 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x5f, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x22, 0x5c, 0x6e, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x69, + 0x6e, 0x74, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, + 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, + 0x2c, 0x22, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, + 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x22, 0x29, + 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x22, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, + 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, + 0x4c, 0x45, 0x5f, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, + 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x22, 0x5c, 0x6e, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, + 0x20, 0x69, 0x6e, 0x74, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x53, 0x29, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x7b, 0x22, 0x29, 0x0a, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x79, + 0x70, 0x65, 0x73, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, + 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, + 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, 0x27, + 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x45, + 0x72, 0x72, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, + 0x72, 0x72, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x20, 0x69, 0x66, 0x20, 0x28, 0x5c, 0x6e, 0x27, 0x29, + 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, + 0x61, 0x72, 0x67, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, + 0x32, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, + 0x31, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, + 0x67, 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, + 0x65, 0x77, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, + 0x63, 0x7e, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x27, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, + 0x61, 0x62, 0x6c, 0x65, 0x27, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x22, + 0x2e, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x21, 0x27, 0x2e, 0x2e, 0x66, 0x75, 0x6e, 0x63, + 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x31, 0x2c, 0x22, 0x27, 0x2e, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, + 0x27, 0x22, 0x2c, 0x30, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x65, 0x72, 0x72, 0x29, 0x20, 0x7c, 0x7c, 0x5c, 0x6e, 0x27, 0x29, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x20, 0x61, 0x72, 0x67, 0x73, 0x0a, 0x20, 0x69, 0x66, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, + 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x77, + 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, + 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x62, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x20, 0x27, + 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, + 0x69, 0x5d, 0x3a, 0x6f, 0x75, 0x74, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x74, + 0x79, 0x70, 0x65, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x2e, 0x2e, 0x27, + 0x20, 0x7c, 0x7c, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, 0x74, 0x65, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x6e, + 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, + 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, + 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, + 0x65, 0x63, 0x6b, 0x20, 0x65, 0x6e, 0x64, 0x20, 0x6f, 0x66, 0x20, 0x6c, + 0x69, 0x73, 0x74, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x20, 0x20, 0x20, 0x20, 0x20, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x69, 0x73, 0x6e, 0x6f, 0x6f, 0x62, 0x6a, 0x28, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, + 0x2e, 0x2e, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, + 0x72, 0x72, 0x29, 0x5c, 0x6e, 0x20, 0x29, 0x27, 0x29, 0x0a, 0x09, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x67, 0x6f, 0x74, + 0x6f, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, + 0x6f, 0x72, 0x3b, 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, + 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, + 0x61, 0x64, 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, + 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x7b, 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x63, + 0x6c, 0x61, 0x72, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2c, 0x20, 0x69, + 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x73, 0x65, 0x0a, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x0a, 0x20, + 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, 0x73, + 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x7e, 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, + 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x2a, + 0x27, 0x2c, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x20, 0x3d, 0x20, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x28, + 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x2a, 0x29, 0x20, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x5f, + 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x74, + 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x31, 0x2c, 0x30, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, + 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, + 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x27, 0x5e, + 0x25, 0x73, 0x2a, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x25, 0x73, 0x25, + 0x73, 0x2a, 0x28, 0x2e, 0x2a, 0x29, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, + 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, + 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, + 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, + 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, + 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, + 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, + 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, + 0x65, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x73, 0x74, 0x61, + 0x74, 0x65, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, + 0x20, 0x6e, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, + 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, + 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x7e, + 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, + 0x74, 0x61, 0x74, 0x69, 0x63, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, + 0x4c, 0x55, 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, + 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x21, 0x73, 0x65, 0x6c, + 0x66, 0x29, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, + 0x6f, 0x72, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, + 0x27, 0x2e, 0x2e, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x22, 0x69, 0x6e, + 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x5c, 0x27, 0x73, 0x65, 0x6c, 0x66, + 0x5c, 0x27, 0x20, 0x69, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x5c, 0x27, 0x25, 0x73, 0x5c, 0x27, 0x22, 0x2c, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x2e, 0x2e, + 0x27, 0x22, 0x2c, 0x20, 0x4e, 0x55, 0x4c, 0x4c, 0x29, 0x3b, 0x27, 0x29, + 0x3b, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, + 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x65, 0x6c, 0x65, 0x6d, 0x65, + 0x6e, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, + 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, + 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, + 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, + 0x0a, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, + 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x67, 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, + 0x79, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x6e, + 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, + 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x70, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x68, 0x6f, + 0x6f, 0x6b, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, 0x0a, 0x0a, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x75, 0x74, 0x73, 0x69, 0x64, 0x65, 0x22, + 0x29, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x69, 0x66, 0x20, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x64, 0x65, + 0x6c, 0x65, 0x74, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x4d, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x65, + 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, + 0x6f, 0x72, 0x26, 0x5b, 0x5d, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, + 0x31, 0x27, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, + 0x69, 0x6c, 0x69, 0x74, 0x79, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x35, 0x20, 0x3f, 0x0a, 0x09, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2d, + 0x3e, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x5b, 0x5d, 0x28, + 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, + 0x31, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x2d, 0x31, 0x29, + 0x20, 0x3d, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, + 0x67, 0x73, 0x5b, 0x32, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, + 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x3e, 0x6f, 0x70, 0x65, 0x72, 0x61, + 0x74, 0x6f, 0x72, 0x5b, 0x5d, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x2c, 0x27, 0x29, 0x20, 0x3d, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x32, 0x5d, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x2c, 0x27, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7b, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, + 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x20, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, + 0x64, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x29, 0x20, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, 0x77, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x6e, 0x65, 0x77, 0x28, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x29, 0x28, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, + 0x63, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, + 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x2e, 0x27, 0x3a, 0x3a, 0x27, 0x2e, 0x2e, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x28, + 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x75, 0x74, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x61, + 0x73, 0x74, 0x5f, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x09, 0x2d, 0x2d, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x74, 0x61, 0x74, 0x69, + 0x63, 0x5f, 0x63, 0x61, 0x73, 0x74, 0x3c, 0x27, 0x2c, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, + 0x2c, 0x27, 0x20, 0x3e, 0x28, 0x2a, 0x73, 0x65, 0x6c, 0x66, 0x27, 0x29, + 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, + 0x65, 0x6c, 0x66, 0x2d, 0x3e, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, + 0x72, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, + 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, + 0x28, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, + 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x65, + 0x6c, 0x66, 0x2d, 0x3e, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x27, 0x29, 0x0a, + 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, + 0x73, 0x5b, 0x31, 0x5d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x77, 0x72, 0x69, 0x74, + 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, + 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, + 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, + 0x0a, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, + 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x70, 0x61, 0x73, 0x73, 0x70, 0x61, 0x72, + 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, + 0x31, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x69, 0x66, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, + 0x27, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x5b, 0x5d, 0x27, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, + 0x31, 0x27, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x2d, 0x31, 0x29, 0x3b, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, + 0x77, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x20, + 0x2d, 0x2d, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x20, 0x4d, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, 0x77, 0x28, 0x0a, 0x09, 0x65, 0x6c, + 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, + 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x3d, + 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x20, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x63, 0x74, 0x20, + 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x6e, + 0x65, 0x77, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, + 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x61, 0x73, + 0x74, 0x5f, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, 0x72, 0x61, + 0x77, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, + 0x5f, 0x72, 0x61, 0x77, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5b, 0x74, 0x5d, + 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, + 0x27, 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x72, 0x65, 0x74, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x27, 0x2e, 0x2e, 0x74, + 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x28, 0x27, 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x72, 0x65, 0x74, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x74, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x5f, 0x74, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, + 0x2c, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x22, + 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, + 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x74, + 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x75, 0x73, 0x68, 0x5f, + 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, + 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x28, 0x74, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7b, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, 0x5f, + 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, 0x6e, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x76, 0x6f, 0x69, 0x64, + 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x20, + 0x3d, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, 0x77, + 0x28, 0x28, 0x27, 0x2c, 0x6e, 0x65, 0x77, 0x5f, 0x74, 0x2c, 0x27, 0x29, + 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x29, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, + 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, + 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, + 0x5f, 0x67, 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x6c, 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, 0x28, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x23, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x20, 0x20, 0x20, 0x20, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x20, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x20, 0x3d, 0x20, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x63, 0x6f, 0x70, 0x79, 0x28, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, + 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x2c, 0x73, + 0x69, 0x7a, 0x65, 0x6f, 0x66, 0x28, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x29, + 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x27, 0x2c, + 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, + 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, + 0x72, 0x5f, 0x67, 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, + 0x2c, 0x6c, 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, 0x28, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, + 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, + 0x2a, 0x29, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, + 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, + 0x2c, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, + 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, + 0x69, 0x64, 0x2a, 0x29, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, + 0x74, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, + 0x29, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x64, + 0x20, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, + 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, + 0x67, 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x6c, + 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, 0x28, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, + 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, + 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, + 0x6e, 0x72, 0x65, 0x74, 0x20, 0x2b, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x72, 0x65, 0x74, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, + 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x7d, 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x73, 0x65, + 0x74, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x65, 0x6c, 0x65, 0x6d, + 0x65, 0x6e, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, + 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, + 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x73, + 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x6e, 0x61, 0x72, 0x67, + 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x20, 0x3d, + 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, + 0x2d, 0x2d, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x64, 0x79, 0x6e, 0x61, + 0x6d, 0x69, 0x63, 0x61, 0x6c, 0x6c, 0x79, 0x20, 0x61, 0x6c, 0x6c, 0x6f, + 0x63, 0x61, 0x74, 0x65, 0x64, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, + 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, + 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, + 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, + 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x66, 0x72, 0x65, + 0x65, 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x63, 0x61, + 0x6c, 0x6c, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x65, 0x6c, 0x66, + 0x29, 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x2e, + 0x2e, 0x6e, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x27, 0x3b, 0x27, 0x29, 0x0a, + 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x6f, 0x76, + 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x65, 0x64, 0x20, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x72, 0x20, 0x67, 0x65, 0x6e, + 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x0a, + 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, + 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, + 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, + 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x52, + 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, + 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3a, 0x5c, 0x6e, + 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x27, + 0x2e, 0x2e, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x72, 0x72, + 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x22, 0x23, 0x66, 0x65, + 0x72, 0x72, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5c, 0x27, 0x25, 0x73, 0x5c, 0x27, 0x2e, + 0x22, 0x2c, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, + 0x65, 0x29, 0x2e, 0x2e, 0x27, 0x22, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x09, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x30, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, + 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, + 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x09, 0x69, 0x66, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x3d, 0x20, + 0x22, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x3a, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x27, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x31, 0x2c, + 0x2d, 0x33, 0x29, 0x2e, 0x2e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x28, + 0x22, 0x25, 0x30, 0x32, 0x64, 0x22, 0x2c, 0x6f, 0x76, 0x65, 0x72, 0x6c, + 0x6f, 0x61, 0x64, 0x29, 0x2e, 0x2e, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, + 0x66, 0x20, 0x2f, 0x2f, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, + 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, + 0x45, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, + 0x20, 0x72, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x20, 0x63, + 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, 0x77, + 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, + 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, + 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, + 0x28, 0x31, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x67, 0x69, 0x73, + 0x74, 0x65, 0x72, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, + 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x20, 0x28, 0x70, 0x72, + 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, 0x70, + 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, + 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, + 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x2e, 0x70, 0x75, 0x72, + 0x65, 0x5f, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x6e, 0x6f, 0x20, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x20, + 0x77, 0x69, 0x74, 0x68, 0x20, 0x70, 0x75, 0x72, 0x65, 0x20, 0x76, 0x69, + 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, + 0x73, 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, + 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x27, 0x2e, 0x2e, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, + 0x27, 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, + 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x29, 0x3b, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x6e, 0x65, 0x77, + 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, + 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x70, 0x72, 0x65, + 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x53, 0x2c, 0x22, 0x2e, 0x63, 0x61, 0x6c, 0x6c, 0x22, 0x2c, 0x27, 0x2e, + 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, + 0x2e, 0x27, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x29, 0x3b, 0x27, 0x29, + 0x0a, 0x09, 0x20, 0x20, 0x2d, 0x2d, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x73, 0x65, 0x74, + 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x28, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, + 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x2c, 0x20, 0x22, 0x27, 0x2e, 0x2e, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, + 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x6d, 0x65, 0x74, + 0x68, 0x6f, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x3a, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x28, 0x69, 0x64, + 0x65, 0x6e, 0x74, 0x2c, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x29, 0x0a, 0x20, + 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, + 0x2e, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x22, + 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, + 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x20, 0x3d, + 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, + 0x64, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, + 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, + 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x70, 0x74, 0x72, + 0x20, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x70, 0x74, 0x72, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, + 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, + 0x2e, 0x2e, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, + 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, + 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, + 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, + 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x63, 0x6f, + 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x2e, 0x2e, 0x22, 0x27, + 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, + 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x63, 0x6e, 0x61, 0x6d, + 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, + 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, + 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, + 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, + 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, + 0x2e, 0x2e, 0x22, 0x20, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x7b, + 0x22, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, + 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, + 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, + 0x5b, 0x69, 0x5d, 0x3a, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, + 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x20, 0x22, 0x2c, 0x22, 0x2c, + 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x7d, 0x22, + 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, + 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x7d, 0x22, 0x2e, 0x2e, 0x63, 0x6c, 0x6f, + 0x73, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x69, 0x66, 0x20, 0x69, 0x74, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x6f, + 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x62, 0x79, 0x20, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x63, 0x6f, 0x6c, + 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x20, 0x3d, 0x20, 0x66, + 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x69, 0x73, 0x62, + 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x70, 0x74, 0x72, 0x3d, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x22, 0x25, 0x73, 0x2a, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x22, 0x2c, 0x22, 0x22, + 0x29, 0x0a, 0x09, 0x20, 0x74, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, + 0x3d, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x63, 0x6f, 0x6c, + 0x6c, 0x65, 0x63, 0x74, 0x5f, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x63, 0x6c, + 0x65, 0x61, 0x6e, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, + 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x20, 0x72, 0x20, 0x3d, + 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x09, 0x77, + 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, + 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x72, + 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, + 0x5b, 0x69, 0x5d, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x63, + 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, + 0x20, 0x6f, 0x72, 0x20, 0x72, 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, + 0x69, 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x65, + 0x20, 0x6c, 0x75, 0x61, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, + 0x6f, 0x61, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x3a, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x20, + 0x28, 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x3a, 0x6f, + 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, + 0x70, 0x61, 0x72, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x73, 0x20, 0x74, 0x72, 0x75, 0x65, 0x20, 0x69, 0x66, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, + 0x72, 0x20, 0x68, 0x61, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x6f, 0x62, 0x6a, + 0x65, 0x63, 0x74, 0x20, 0x61, 0x73, 0x20, 0x69, 0x74, 0x73, 0x20, 0x64, + 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, + 0x72, 0x2c, 0x20, 0x27, 0x3d, 0x27, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, + 0x65, 0x20, 0x65, 0x6e, 0x64, 0x20, 0x2d, 0x2d, 0x20, 0x69, 0x74, 0x20, + 0x68, 0x61, 0x73, 0x20, 0x6e, 0x6f, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, + 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x64, 0x65, 0x66, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, + 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x3d, 0x28, 0x2e, + 0x2a, 0x29, 0x24, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, + 0x61, 0x72, 0x2c, 0x20, 0x22, 0x7c, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x20, + 0x6f, 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x0a, 0x0a, 0x09, 0x09, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, + 0x72, 0x2c, 0x20, 0x22, 0x25, 0x2a, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x69, 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, + 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x20, 0x77, 0x69, 0x74, 0x68, + 0x20, 0x61, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, + 0x61, 0x72, 0x2c, 0x20, 0x27, 0x3d, 0x25, 0x73, 0x2a, 0x6e, 0x65, 0x77, + 0x27, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, + 0x25, 0x28, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, + 0x20, 0x69, 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, 0x70, 0x6f, 0x69, 0x6e, + 0x74, 0x65, 0x72, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x6e, 0x20, + 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x61, 0x73, 0x20, + 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x70, 0x61, 0x72, 0x61, + 0x6d, 0x65, 0x74, 0x65, 0x72, 0x2e, 0x2e, 0x20, 0x69, 0x73, 0x20, 0x74, + 0x68, 0x61, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x3f, 0x0a, 0x09, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, + 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x20, 0x2d, + 0x2d, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, 0x27, 0x4e, 0x55, 0x4c, 0x4c, + 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x69, + 0x6e, 0x67, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x5b, 0x25, 0x28, 0x26, + 0x5d, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, + 0x65, 0x6e, 0x64, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, + 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, + 0x61, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, + 0x72, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x28, 0x6d, 0x6f, 0x73, 0x74, + 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x6c, 0x79, 0x20, 0x66, 0x6f, 0x72, 0x20, + 0x61, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x72, 0x65, 0x66, 0x65, + 0x72, 0x65, 0x6e, 0x63, 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x69, + 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x26, 0x22, 0x29, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x69, 0x66, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, + 0x28, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x22, 0x3a, 0x22, 0x29, 0x20, 0x6f, + 0x72, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, + 0x6e, 0x65, 0x77, 0x25, 0x73, 0x2b, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x69, + 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, + 0x6e, 0x63, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x64, 0x65, 0x66, + 0x61, 0x75, 0x6c, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x73, 0x6f, 0x6d, 0x65, + 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x43, + 0x6c, 0x61, 0x73, 0x73, 0x3a, 0x3a, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, + 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x20, 0x43, 0x6c, + 0x61, 0x73, 0x73, 0x27, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x2d, + 0x2d, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, + 0x6c, 0x73, 0x65, 0x20, 0x2d, 0x2d, 0x20, 0x3f, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x70, 0x5f, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, + 0x67, 0x28, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x2c, 0x20, + 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x29, 0x20, 0x2d, 0x2d, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, + 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, + 0x61, 0x73, 0x74, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, + 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, + 0x2c, 0x73, 0x5f, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x6c, 0x61, 0x73, + 0x74, 0x5f, 0x61, 0x72, 0x67, 0x2c, 0x20, 0x22, 0x5e, 0x28, 0x5b, 0x5e, + 0x3d, 0x5d, 0x2b, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x61, 0x73, 0x74, + 0x5f, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x6c, 0x61, 0x73, 0x74, 0x5f, + 0x61, 0x72, 0x67, 0x2c, 0x20, 0x22, 0x28, 0x5b, 0x25, 0x25, 0x25, 0x28, + 0x25, 0x29, 0x5d, 0x29, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x25, 0x25, 0x31, + 0x22, 0x29, 0x3b, 0x0a, 0x09, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, + 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, + 0x73, 0x75, 0x62, 0x28, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, + 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x2c, 0x25, 0x73, 0x2a, 0x22, 0x2e, + 0x2e, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x22, + 0x25, 0x73, 0x2a, 0x25, 0x29, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, + 0x22, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x2c, 0x20, 0x73, + 0x5f, 0x61, 0x72, 0x67, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, 0x46, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, + 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, + 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, + 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x2e, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, + 0x28, 0x22, 0x23, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x27, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, + 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x29, 0x0a, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, + 0x28, 0x74, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x3a, 0x69, 0x6e, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x20, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x28, 0x27, + 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x69, 0x73, 0x20, 0x27, 0x2e, + 0x2e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x2c, 0x20, + 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x69, 0x73, 0x20, 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, + 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x3d, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6f, 0x72, + 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x6f, 0x72, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, 0x62, 0x3c, 0x3e, 0x22, + 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, + 0x6e, 0x65, 0x77, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6c, 0x6e, + 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x0a, + 0x20, 0x20, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, + 0x5f, 0x6e, 0x65, 0x77, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, + 0x20, 0x20, 0x20, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, + 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, + 0x20, 0x27, 0x2a, 0x27, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, + 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, + 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x3d, 0x3d, + 0x20, 0x27, 0x7e, 0x27, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x2e, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x5f, + 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x2e, 0x70, 0x61, + 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, + 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x20, 0x3d, 0x20, 0x27, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x27, + 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x3d, 0x20, 0x27, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x27, 0x0a, 0x20, + 0x20, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x5f, + 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, + 0x65, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x74, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, + 0x74, 0x3a, 0x63, 0x66, 0x75, 0x6e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x28, + 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x22, 0x29, 0x2e, 0x2e, 0x74, 0x3a, + 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x74, 0x29, 0x0a, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x72, + 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, 0x78, 0x70, + 0x65, 0x63, 0x74, 0x73, 0x20, 0x74, 0x68, 0x72, 0x65, 0x65, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x3a, 0x20, 0x6f, 0x6e, 0x65, 0x20, + 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x2c, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x6f, 0x74, 0x68, 0x65, + 0x72, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, + 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, + 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x20, + 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, + 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x22, 0x63, 0x6f, 0x6e, + 0x73, 0x74, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x65, 0x6d, 0x70, 0x74, 0x79, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x28, 0x64, 0x2c, 0x61, 0x2c, 0x63, 0x29, 0x0a, 0x20, + 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, + 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x27, 0x2c, 0x27, + 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, + 0x74, 0x65, 0x20, 0x62, 0x72, 0x61, 0x63, 0x65, 0x73, 0x0a, 0x20, 0x2d, + 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, + 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x28, + 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, + 0x32, 0x29, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x57, 0x27, 0x5d, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, + 0x69, 0x6e, 0x64, 0x28, 0x61, 0x2c, 0x20, 0x22, 0x25, 0x2e, 0x25, 0x2e, + 0x25, 0x2e, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x22, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, + 0x67, 0x28, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, + 0x6c, 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, + 0x20, 0x28, 0x60, 0x2e, 0x2e, 0x2e, 0x27, 0x29, 0x20, 0x61, 0x72, 0x65, + 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, + 0x65, 0x64, 0x2e, 0x20, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x69, 0x6e, 0x67, + 0x20, 0x22, 0x2e, 0x2e, 0x64, 0x2e, 0x2e, 0x61, 0x2e, 0x2e, 0x63, 0x29, + 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, + 0x6c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, 0x7d, + 0x0a, 0x0a, 0x20, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x20, 0x22, + 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x25, 0x28, 0x25, 0x29, 0x5d, 0x29, 0x25, + 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x31, 0x22, 0x29, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, 0x69, + 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x74, 0x72, 0x73, + 0x75, 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x3b, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, + 0x28, 0x61, 0x2c, 0x31, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x20, 0x31, 0x2c, + 0x20, 0x2d, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x6c, 0x65, + 0x6e, 0x28, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x2b, 0x31, 0x29, 0x29, 0x0a, + 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, + 0x20, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x2c, 0x22, + 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x2d, 0x31, 0x29, + 0x0a, 0x0a, 0x09, 0x09, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x22, 0x28, 0x22, + 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x6e, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x2c, 0x25, + 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x2e, 0x2e, 0x27, + 0x29, 0x27, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6e, 0x73, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, + 0x74, 0x73, 0x28, 0x6e, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x46, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x20, 0x6e, 0x73, 0x2c, 0x20, + 0x63, 0x29, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, + 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x09, + 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, + 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, + 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, 0x69, 0x5d, + 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, + 0x6c, 0x2e, 0x6e, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x6c, 0x5b, 0x6c, 0x2e, + 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x76, + 0x61, 0x72, 0x27, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, 0x0a, 0x20, 0x20, + 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, + 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, + 0x64, 0x2c, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x29, 0x0a, 0x20, 0x66, + 0x2e, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x6c, 0x0a, 0x20, 0x66, + 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x63, 0x0a, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x46, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x66, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6a, 0x6f, + 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x70, 0x2c, 0x20, 0x66, + 0x69, 0x72, 0x73, 0x74, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x0a, + 0x0a, 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x69, + 0x72, 0x73, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x61, + 0x73, 0x74, 0x20, 0x3d, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x6f, 0x72, + 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x67, 0x65, 0x74, 0x6e, 0x28, + 0x74, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x73, + 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x6f, 0x6f, 0x70, 0x20, + 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x66, 0x6f, 0x72, + 0x20, 0x69, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2c, 0x6c, + 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x6c, 0x73, 0x65, + 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, 0x09, 0x6c, 0x73, + 0x65, 0x70, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x70, 0x0a, 0x09, 0x09, 0x6c, + 0x6f, 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x72, 0x65, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, + 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, + 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, + 0x2c, 0x20, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x66, 0x61, + 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, + 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, + 0x74, 0x2e, 0x6e, 0x2c, 0x31, 0x2c, 0x2d, 0x31, 0x20, 0x64, 0x6f, 0x0a, + 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x70, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, + 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, 0x74, 0x5b, 0x69, + 0x5d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6c, + 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x0a, 0x09, 0x09, 0x09, 0x73, + 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x69, 0x66, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x2d, 0x2d, 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, + 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, 0x69, 0x70, 0x2c, + 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x73, 0x28, 0x73, + 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, + 0x5e, 0x25, 0x28, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x73, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, + 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x29, 0x24, 0x22, 0x2c, + 0x20, 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, + 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x20, 0x22, + 0x2c, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, + 0x65, 0x70, 0x2c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x22, 0x22, + 0x2c, 0x22, 0x22, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, + 0x2c, 0x74, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x74, 0x5b, + 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, + 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, + 0x09, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, + 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, 0x09, + 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x2c, 0x22, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x22, 0x28, 0x22, 0x2e, 0x2e, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x22, 0x29, + 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a +}; +unsigned int lua_function_lua_len = 14264; diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index 99fe74629..5f0dedfe1 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -48,6 +48,21 @@ function classEnumerate:print (ident,close) print(ident.."}"..close) end +_global_output_enums = {} + +-- write support code +function classEnumerate:supcode () + if _global_output_enums[self.name] ~= nil then + _global_output_enums[self.name] = 1 + output("int tolua_is" .. self.name .. " (lua_State* L, int lo, int def, tolua_Error* err)") + output("{") + output("if (!tolua_isnumber(L,lo,def,err)) return 0;") + output("int val = tolua_tonumber(L,lo,def);") + output("return val >= " .. self.min .. " && val <= " ..self.max .. ";") + output("}") + end +end + -- Internal constructor function _Enumerate (t,varname) setmetatable(t,classEnumerate) @@ -67,40 +82,57 @@ function _Enumerate (t,varname) t.access = parent.curr_member_access t.global_access = t:check_public_access() end -return t + return t end -- Constructor -- Expects a string representing the enumerate body function Enumerate (n,b,varname) b = string.gsub(b, ",[%s\n]*}", "\n}") -- eliminate last ',' - local t = split(strsub(b,2,-2),',') -- eliminate braces - local i = 1 - local e = {n=0} - while t[i] do - local tt = split(t[i],'=') -- discard initial value - e.n = e.n + 1 - e[e.n] = tt[1] - i = i+1 - end - -- set lua names - i = 1 - e.lnames = {} - local ns = getcurrnamespace() - while e[i] do - local t = split(e[i],'@') - e[i] = t[1] + local t = split(strsub(b,2,-2),',') -- eliminate braces + local i = 1 + local e = {n=0} + local value = 0 + local min = 0 + local max = 0 + while t[i] do + local tt = split(t[i],'=') -- discard initial value + e.n = e.n + 1 + e[e.n] = tt[1] + tt[2] = tonumber(tt[2]) + if tt[2] == nil then + tt[2] = value + end + value = tt[2] + 1 -- advance the selected value + if tt[2] > max then + max = tt[2] + end + if tt[2] < min then + min = tt[2] + end + i = i+1 + end + -- set lua names + i = 1 + e.lnames = {} + local ns = getcurrnamespace() + while e[i] do + local t = split(e[i],'@') + e[i] = t[1] if not t[2] then - t[2] = applyrenaming(t[1]) + t[2] = applyrenaming(t[1]) end - e.lnames[i] = t[2] or t[1] - _global_enums[ ns..e[i] ] = (ns..e[i]) - i = i+1 - end + e.lnames[i] = t[2] or t[1] + _global_enums[ ns..e[i] ] = (ns..e[i]) + i = i+1 + end e.name = n + e.min = min + e.max = max if n ~= "" then Typedef("int "..n) + _is_functions[n] = "tolua_is" .. n end - return _Enumerate(e, varname) + return _Enumerate(e, varname) end diff --git a/lib/tolua++/src/bin/lua/function.lua b/lib/tolua++/src/bin/lua/function.lua index 2358e9ff7..7120fb063 100644 --- a/lib/tolua++/src/bin/lua/function.lua +++ b/lib/tolua++/src/bin/lua/function.lua @@ -50,7 +50,6 @@ end -- Write binding function -- Outputs C/C++ binding function. function classFunction:supcode (local_constructor) - local overload = strsub(self.cname,-2,-1) - 1 -- indicate overloaded func local nret = 0 -- number of returned values local class = self:inclass() diff --git a/lib/tolua++/src/bin/toluabind.c b/lib/tolua++/src/bin/toluabind.c index bf71cf158..6be141580 100644 --- a/lib/tolua++/src/bin/toluabind.c +++ b/lib/tolua++/src/bin/toluabind.c @@ -384,603 +384,8 @@ TOLUA_API int tolua_tolua_open (lua_State* tolua_S) { /* begin embedded lua code */ int top = lua_gettop(tolua_S); - static unsigned char B[] = { - 45, 45, 32,116,111,108,117, 97, 58, 32, 98, 97,115,105, 99, - 32,117,116,105,108,105,116,121, 32,102,117,110, 99,116,105, - 111,110,115, 10, 45, 45, 32, 87,114,105,116,116,101,110, 32, - 98,121, 32, 87, 97,108,100,101,109, 97,114, 32, 67,101,108, - 101,115, 10, 45, 45, 32, 84,101, 67, 71,114, 97,102, 47, 80, - 85, 67, 45, 82,105,111, 10, 45, 45, 32, 74,117,108, 32, 49, - 57, 57, 56, 10, 45, 45, 32, 76, 97,115,116, 32,117,112,100, - 97,116,101, 58, 32, 65,112,114, 32, 50, 48, 48, 51, 10, 45, - 45, 32, 36, 73,100, 58, 32, 36, 10, 10, 45, 45, 32, 84,104, - 105,115, 32, 99,111,100,101, 32,105,115, 32,102,114,101,101, - 32,115,111,102,116,119, 97,114,101, 59, 32,121,111,117, 32, - 99, 97,110, 32,114,101,100,105,115,116,114,105, 98,117,116, - 101, 32,105,116, 32, 97,110,100, 47,111,114, 32,109,111,100, - 105,102,121, 32,105,116, 46, 10, 45, 45, 32, 84,104,101, 32, - 115,111,102,116,119, 97,114,101, 32,112,114,111,118,105,100, - 101,100, 32,104,101,114,101,117,110,100,101,114, 32,105,115, - 32,111,110, 32, 97,110, 32, 34, 97,115, 32,105,115, 34, 32, - 98, 97,115,105,115, 44, 32, 97,110,100, 10, 45, 45, 32,116, - 104,101, 32, 97,117,116,104,111,114, 32,104, 97,115, 32,110, - 111, 32,111, 98,108,105,103, 97,116,105,111,110, 32,116,111, - 32,112,114,111,118,105,100,101, 32,109, 97,105,110,116,101, - 110, 97,110, 99,101, 44, 32,115,117,112,112,111,114,116, 44, - 32,117,112,100, 97,116,101,115, 44, 10, 45, 45, 32,101,110, - 104, 97,110, 99,101,109,101,110,116,115, 44, 32,111,114, 32, - 109,111,100,105,102,105, 99, 97,116,105,111,110,115, 46, 10, - 10, 10, 45, 45, 32, 66, 97,115,105, 99, 32, 67, 32,116,121, - 112,101,115, 32, 97,110,100, 32,116,104,101,105,114, 32, 99, - 111,114,114,101,115,112,111,110,100,105,110,103, 32, 76,117, - 97, 32,116,121,112,101,115, 10, 45, 45, 32, 65,108,108, 32, - 111, 99, 99,117,114,114,101,110, 99,101,115, 32,111,102, 32, - 34, 99,104, 97,114, 42, 34, 32,119,105,108,108, 32, 98,101, - 32,114,101,112,108, 97, 99,101,100, 32, 98,121, 32, 34, 95, - 99,115,116,114,105,110,103, 34, 44, 10, 45, 45, 32, 97,110, - 100, 32, 97,108,108, 32,111, 99, 99,117,114,114,101,110, 99, - 101,115, 32,111,102, 32, 34,118,111,105,100, 42, 34, 32,119, - 105,108,108, 32, 98,101, 32,114,101,112,108, 97, 99,101,100, - 32, 98,121, 32, 34, 95,117,115,101,114,100, 97,116, 97, 34, - 10, 95, 98, 97,115,105, 99, 32, 61, 32,123, 10, 32, 91, 39, - 118,111,105,100, 39, 93, 32, 61, 32, 39, 39, 44, 10, 32, 91, - 39, 99,104, 97,114, 39, 93, 32, 61, 32, 39,110,117,109, 98, - 101,114, 39, 44, 10, 32, 91, 39,105,110,116, 39, 93, 32, 61, - 32, 39,110,117,109, 98,101,114, 39, 44, 10, 32, 91, 39,115, - 104,111,114,116, 39, 93, 32, 61, 32, 39,110,117,109, 98,101, - 114, 39, 44, 10, 32, 91, 39,108,111,110,103, 39, 93, 32, 61, - 32, 39,110,117,109, 98,101,114, 39, 44, 10, 32, 91, 39,117, - 110,115,105,103,110,101,100, 39, 93, 32, 61, 32, 39,110,117, - 109, 98,101,114, 39, 44, 10, 32, 91, 39,102,108,111, 97,116, - 39, 93, 32, 61, 32, 39,110,117,109, 98,101,114, 39, 44, 10, - 32, 91, 39,100,111,117, 98,108,101, 39, 93, 32, 61, 32, 39, - 110,117,109, 98,101,114, 39, 44, 10, 32, 91, 39, 95, 99,115, - 116,114,105,110,103, 39, 93, 32, 61, 32, 39,115,116,114,105, - 110,103, 39, 44, 10, 32, 91, 39, 95,117,115,101,114,100, 97, - 116, 97, 39, 93, 32, 61, 32, 39,117,115,101,114,100, 97,116, - 97, 39, 44, 10, 32, 91, 39, 99,104, 97,114, 42, 39, 93, 32, - 61, 32, 39,115,116,114,105,110,103, 39, 44, 10, 32, 91, 39, - 118,111,105,100, 42, 39, 93, 32, 61, 32, 39,117,115,101,114, - 100, 97,116, 97, 39, 44, 10, 32, 91, 39, 98,111,111,108, 39, - 93, 32, 61, 32, 39, 98,111,111,108,101, 97,110, 39, 44, 10, - 32, 91, 39,108,117, 97, 95, 79, 98,106,101, 99,116, 39, 93, - 32, 61, 32, 39,118, 97,108,117,101, 39, 44, 10, 32, 91, 39, - 76, 85, 65, 95, 86, 65, 76, 85, 69, 39, 93, 32, 61, 32, 39, - 118, 97,108,117,101, 39, 44, 32, 32, 32, 32, 45, 45, 32,102, - 111,114, 32, 99,111,109,112, 97,116,105, 98,105,108,105,116, - 121, 32,119,105,116,104, 32,116,111,108,117, 97, 32, 52, 46, - 48, 10, 32, 91, 39,108,117, 97, 95, 83,116, 97,116,101, 42, - 39, 93, 32, 61, 32, 39,115,116, 97,116,101, 39, 44, 10, 32, - 91, 39, 95,108,115,116, 97,116,101, 39, 93, 32, 61, 32, 39, - 115,116, 97,116,101, 39, 44, 10, 32, 91, 39,108,117, 97, 95, - 70,117,110, 99,116,105,111,110, 39, 93, 32, 61, 32, 39,118, - 97,108,117,101, 39, 44, 10,125, 10, 10, 95, 98, 97,115,105, - 99, 95, 99,116,121,112,101, 32, 61, 32,123, 10, 32,110,117, - 109, 98,101,114, 32, 61, 32, 34,108,117, 97, 95, 78,117,109, - 98,101,114, 34, 44, 10, 32,115,116,114,105,110,103, 32, 61, - 32, 34, 99,111,110,115,116, 32, 99,104, 97,114, 42, 34, 44, - 10, 32,117,115,101,114,100, 97,116, 97, 32, 61, 32, 34,118, - 111,105,100, 42, 34, 44, 10, 32, 98,111,111,108,101, 97,110, - 32, 61, 32, 34, 98,111,111,108, 34, 44, 10, 32,118, 97,108, - 117,101, 32, 61, 32, 34,105,110,116, 34, 44, 10, 32,115,116, - 97,116,101, 32, 61, 32, 34,108,117, 97, 95, 83,116, 97,116, - 101, 42, 34, 44, 10,125, 10, 10, 45, 45, 32,102,117,110, 99, - 116,105,111,110,115, 32,116,104,101, 32, 97,114,101, 32,117, - 115,101,100, 32,116,111, 32,100,111, 32, 97, 32, 39,114, 97, - 119, 32,112,117,115,104, 39, 32,111,102, 32, 98, 97,115,105, - 99, 32,116,121,112,101,115, 10, 95, 98, 97,115,105, 99, 95, - 114, 97,119, 95,112,117,115,104, 32, 61, 32,123,125, 10, 10, - 45, 45, 32, 76,105,115,116, 32,111,102, 32,117,115,101,114, - 32,100,101,102,105,110,101,100, 32,116,121,112,101,115, 10, - 45, 45, 32, 69, 97, 99,104, 32,116,121,112,101, 32, 99,111, - 114,114,101,115,112,111,110,100,115, 32,116,111, 32, 97, 32, - 118, 97,114,105, 97, 98,108,101, 32,110, 97,109,101, 32,116, - 104, 97,116, 32,115,116,111,114,101,115, 32,105,116,115, 32, - 116, 97,103, 32,118, 97,108,117,101, 46, 10, 95,117,115,101, - 114,116,121,112,101, 32, 61, 32,123,125, 10, 10, 45, 45, 32, - 76,105,115,116, 32,111,102, 32,116,121,112,101,115, 32,116, - 104, 97,116, 32,104, 97,118,101, 32,116,111, 32, 98,101, 32, - 99,111,108,108,101, 99,116,101,100, 10, 95, 99,111,108,108, - 101, 99,116, 32, 61, 32,123,125, 10, 10, 45, 45, 32, 76,105, - 115,116, 32,111,102, 32,116,121,112,101,115, 10, 95,103,108, - 111, 98, 97,108, 95,116,121,112,101,115, 32, 61, 32,123,110, - 61, 48,125, 10, 95,103,108,111, 98, 97,108, 95,116,121,112, - 101,115, 95,104, 97,115,104, 32, 61, 32,123,125, 10, 10, 45, - 45, 32,108,105,115,116, 32,111,102, 32, 99,108, 97,115,115, - 101,115, 10, 95,103,108,111, 98, 97,108, 95, 99,108, 97,115, - 115,101,115, 32, 61, 32,123,125, 10, 10, 45, 45, 32, 76,105, - 115,116, 32,111,102, 32,101,110,117,109, 32, 99,111,110,115, - 116, 97,110,116,115, 10, 95,103,108,111, 98, 97,108, 95,101, - 110,117,109,115, 32, 61, 32,123,125, 10, 10, 45, 45, 32, 76, - 105,115,116, 32,111,102, 32, 97,117,116,111, 32,114,101,110, - 97,109,105,110,103, 10, 95,114,101,110, 97,109,105,110,103, - 32, 61, 32,123,125, 10,102,117,110, 99,116,105,111,110, 32, - 97,112,112,101,110,100,114,101,110, 97,109,105,110,103, 32, - 40,115, 41, 10, 32,108,111, 99, 97,108, 32, 98, 44,101, 44, - 111,108,100, 44,110,101,119, 32, 61, 32,115,116,114,102,105, - 110,100, 40,115, 44, 34, 37,115, 42, 40, 46, 45, 41, 37,115, - 42, 64, 37,115, 42, 40, 46, 45, 41, 37,115, 42, 36, 34, 41, - 10, 9,105,102, 32,110,111,116, 32, 98, 32,116,104,101,110, - 10, 9, 32,101,114,114,111,114, 40, 34, 35, 73,110,118, 97, - 108,105,100, 32,114,101,110, 97,109,105,110,103, 32,115,121, - 110,116, 97,120, 59, 32,105,116, 32,115,104,111,117,108,100, - 32, 98,101, 32,111,102, 32,116,104,101, 32,102,111,114,109, - 58, 32,112, 97,116,116,101,114,110, 64,112, 97,116,116,101, - 114,110, 34, 41, 10, 9,101,110,100, 10, 9,116,105,110,115, - 101,114,116, 40, 95,114,101,110, 97,109,105,110,103, 44,123, - 111,108,100, 61,111,108,100, 44, 32,110,101,119, 61,110,101, - 119,125, 41, 10,101,110,100, 10, 10,102,117,110, 99,116,105, - 111,110, 32, 97,112,112,108,121,114,101,110, 97,109,105,110, - 103, 32, 40,115, 41, 10, 9,102,111,114, 32,105, 61, 49, 44, - 103,101,116,110, 40, 95,114,101,110, 97,109,105,110,103, 41, - 32,100,111, 10, 9, 32,108,111, 99, 97,108, 32,109, 44,110, - 32, 61, 32,103,115,117, 98, 40,115, 44, 95,114,101,110, 97, - 109,105,110,103, 91,105, 93, 46,111,108,100, 44, 95,114,101, - 110, 97,109,105,110,103, 91,105, 93, 46,110,101,119, 41, 10, - 9, 9,105,102, 32,110, 32,126, 61, 32, 48, 32,116,104,101, - 110, 10, 9, 9, 32,114,101,116,117,114,110, 32,109, 10, 9, - 9,101,110,100, 10, 9,101,110,100, 10, 9,114,101,116,117, - 114,110, 32,110,105,108, 10,101,110,100, 10, 10, 45, 45, 32, - 69,114,114,111,114, 32,104, 97,110,100,108,101,114, 10,102, - 117,110, 99,116,105,111,110, 32,116,111,108,117, 97, 95,101, - 114,114,111,114, 32, 40,115, 44,102, 41, 10,105,102, 32, 95, - 99,117,114,114, 95, 99,111,100,101, 32,116,104,101,110, 10, - 9,112,114,105,110,116, 40, 34, 42, 42, 42, 99,117,114,114, - 32, 99,111,100,101, 32,102,111,114, 32,101,114,114,111,114, - 32,105,115, 32, 34, 46, 46,116,111,115,116,114,105,110,103, - 40, 95, 99,117,114,114, 95, 99,111,100,101, 41, 41, 10, 9, - 112,114,105,110,116, 40,100,101, 98,117,103, 46,116,114, 97, - 99,101, 98, 97, 99,107, 40, 41, 41, 10,101,110,100, 10, 32, - 108,111, 99, 97,108, 32,111,117,116, 32, 61, 32, 95, 79, 85, - 84, 80, 85, 84, 10, 32, 95, 79, 85, 84, 80, 85, 84, 32, 61, - 32, 95, 83, 84, 68, 69, 82, 82, 10, 32,105,102, 32,115,116, - 114,115,117, 98, 40,115, 44, 49, 44, 49, 41, 32, 61, 61, 32, - 39, 35, 39, 32,116,104,101,110, 10, 32, 32,119,114,105,116, - 101, 40, 34, 92,110, 42, 42, 32,116,111,108,117, 97, 58, 32, - 34, 46, 46,115,116,114,115,117, 98, 40,115, 44, 50, 41, 46, - 46, 34, 46, 92,110, 92,110, 34, 41, 10, 32, 32,105,102, 32, - 95, 99,117,114,114, 95, 99,111,100,101, 32,116,104,101,110, - 10, 32, 32, 32,108,111, 99, 97,108, 32, 95, 44, 95, 44,115, - 32, 61, 32,115,116,114,102,105,110,100, 40, 95, 99,117,114, - 114, 95, 99,111,100,101, 44, 34, 94, 37,115, 42, 40, 46, 45, - 92,110, 41, 34, 41, 32, 45, 45, 32,101,120,116,114, 97, 99, - 116, 32,102,105,114,115,116, 32,108,105,110,101, 10, 32, 32, - 32,105,102, 32,115, 61, 61,110,105,108, 32,116,104,101,110, - 32,115, 32, 61, 32, 95, 99,117,114,114, 95, 99,111,100,101, - 32,101,110,100, 10, 32, 32, 32,115, 32, 61, 32,103,115,117, - 98, 40,115, 44, 34, 95,117,115,101,114,100, 97,116, 97, 34, - 44, 34,118,111,105,100, 42, 34, 41, 32, 45, 45, 32,114,101, - 116,117,114,110, 32,119,105,116,104, 32, 39,118,111,105,100, - 42, 39, 10, 32, 32, 32,115, 32, 61, 32,103,115,117, 98, 40, - 115, 44, 34, 95, 99,115,116,114,105,110,103, 34, 44, 34, 99, - 104, 97,114, 42, 34, 41, 32, 32, 45, 45, 32,114,101,116,117, - 114,110, 32,119,105,116,104, 32, 39, 99,104, 97,114, 42, 39, - 10, 32, 32, 32,115, 32, 61, 32,103,115,117, 98, 40,115, 44, - 34, 95,108,115,116, 97,116,101, 34, 44, 34,108,117, 97, 95, - 83,116, 97,116,101, 42, 34, 41, 32, 32, 45, 45, 32,114,101, - 116,117,114,110, 32,119,105,116,104, 32, 39,108,117, 97, 95, - 83,116, 97,116,101, 42, 39, 10, 32, 32, 32,119,114,105,116, - 101, 40, 34, 67,111,100,101, 32, 98,101,105,110,103, 32,112, - 114,111, 99,101,115,115,101,100, 58, 92,110, 34, 46, 46,115, - 46, 46, 34, 92,110, 34, 41, 10, 32, 32,101,110,100, 10, 32, - 101,108,115,101, 10, 32,105,102, 32,110,111,116, 32,102, 32, - 116,104,101,110, 32,102, 32, 61, 32, 34, 40,102, 32,105,115, - 32,110,105,108, 41, 34, 32,101,110,100, 10, 32, 32,112,114, - 105,110,116, 40, 34, 92,110, 42, 42, 32,116,111,108,117, 97, - 32,105,110,116,101,114,110, 97,108, 32,101,114,114,111,114, - 58, 32, 34, 46, 46,102, 46, 46,115, 46, 46, 34, 46, 92,110, - 92,110, 34, 41, 10, 32, 32,114,101,116,117,114,110, 10, 32, - 101,110,100, 10, 32, 95, 79, 85, 84, 80, 85, 84, 32, 61, 32, - 111,117,116, 10,101,110,100, 10, 10,102,117,110, 99,116,105, - 111,110, 32,119, 97,114,110,105,110,103, 32, 40,109,115,103, - 41, 10, 32,105,102, 32,102,108, 97,103,115, 46,113, 32,116, - 104,101,110, 32,114,101,116,117,114,110, 32,101,110,100, 10, - 32,108,111, 99, 97,108, 32,111,117,116, 32, 61, 32, 95, 79, - 85, 84, 80, 85, 84, 10, 32, 95, 79, 85, 84, 80, 85, 84, 32, - 61, 32, 95, 83, 84, 68, 69, 82, 82, 10, 32,119,114,105,116, - 101, 40, 34, 92,110, 42, 42, 32,116,111,108,117, 97, 32,119, - 97,114,110,105,110,103, 58, 32, 34, 46, 46,109,115,103, 46, - 46, 34, 46, 92,110, 92,110, 34, 41, 10, 32, 95, 79, 85, 84, - 80, 85, 84, 32, 61, 32,111,117,116, 10,101,110,100, 10, 10, - 45, 45, 32,114,101,103,105,115,116,101,114, 32, 97,110, 32, - 117,115,101,114, 32,100,101,102,105,110,101,100, 32,116,121, - 112,101, 58, 32,114,101,116,117,114,110,115, 32,102,117,108, - 108, 32,116,121,112,101, 10,102,117,110, 99,116,105,111,110, - 32,114,101,103,116,121,112,101, 32, 40,116, 41, 10, 9, 45, - 45,105,102, 32,105,115, 98, 97,115,105, 99, 40,116, 41, 32, - 116,104,101,110, 10, 9, 45, 45, 9,114,101,116,117,114,110, - 32,116, 10, 9, 45, 45,101,110,100, 10, 9,108,111, 99, 97, - 108, 32,102,116, 32, 61, 32,102,105,110,100,116,121,112,101, - 40,116, 41, 10, 10, 9,105,102, 32,110,111,116, 32, 95,117, - 115,101,114,116,121,112,101, 91,102,116, 93, 32,116,104,101, - 110, 10, 9, 9,114,101,116,117,114,110, 32, 97,112,112,101, - 110,100,117,115,101,114,116,121,112,101, 40,116, 41, 10, 9, - 101,110,100, 10, 9,114,101,116,117,114,110, 32,102,116, 10, - 101,110,100, 10, 10, 45, 45, 32,114,101,116,117,114,110, 32, - 116,121,112,101, 32,110, 97,109,101, 58, 32,114,101,116,117, - 114,110,115, 32,102,117,108,108, 32,116,121,112,101, 10,102, - 117,110, 99,116,105,111,110, 32,116,121,112,101,118, 97,114, - 40,116,121,112,101, 41, 10, 9,105,102, 32,116,121,112,101, - 32, 61, 61, 32, 39, 39, 32,111,114, 32,116,121,112,101, 32, - 61, 61, 32, 39,118,111,105,100, 39, 32,116,104,101,110, 10, - 9, 9,114,101,116,117,114,110, 32,116,121,112,101, 10, 9, - 101,108,115,101, 10, 9, 9,108,111, 99, 97,108, 32,102,116, - 32, 61, 32,102,105,110,100,116,121,112,101, 40,116,121,112, - 101, 41, 10, 9, 9,105,102, 32,102,116, 32,116,104,101,110, - 10, 9, 9, 9,114,101,116,117,114,110, 32,102,116, 10, 9, - 9,101,110,100, 10, 9, 9, 95,117,115,101,114,116,121,112, - 101, 91,116,121,112,101, 93, 32, 61, 32,116,121,112,101, 10, - 9, 9,114,101,116,117,114,110, 32,116,121,112,101, 10, 9, - 101,110,100, 10,101,110,100, 10, 10, 45, 45, 32, 99,104,101, - 99,107, 32,105,102, 32, 98, 97,115,105, 99, 32,116,121,112, - 101, 10,102,117,110, 99,116,105,111,110, 32,105,115, 98, 97, - 115,105, 99, 32, 40,116,121,112,101, 41, 10, 32,108,111, 99, - 97,108, 32,116, 32, 61, 32,103,115,117, 98, 40,116,121,112, - 101, 44, 39, 99,111,110,115,116, 32, 39, 44, 39, 39, 41, 10, - 32,108,111, 99, 97,108, 32,109, 44,116, 32, 61, 32, 97,112, - 112,108,121,116,121,112,101,100,101,102, 40, 39, 39, 44, 32, - 116, 41, 10, 32,108,111, 99, 97,108, 32, 98, 32, 61, 32, 95, - 98, 97,115,105, 99, 91,116, 93, 10, 32,105,102, 32, 98, 32, - 116,104,101,110, 10, 32, 32,114,101,116,117,114,110, 32, 98, - 44, 95, 98, 97,115,105, 99, 95, 99,116,121,112,101, 91, 98, - 93, 10, 32,101,110,100, 10, 32,114,101,116,117,114,110, 32, - 110,105,108, 10,101,110,100, 10, 10, 45, 45, 32,115,112,108, - 105,116, 32,115,116,114,105,110,103, 32,117,115,105,110,103, - 32, 97, 32,116,111,107,101,110, 10,102,117,110, 99,116,105, - 111,110, 32,115,112,108,105,116, 32, 40,115, 44,116, 41, 10, - 32,108,111, 99, 97,108, 32,108, 32, 61, 32,123,110, 61, 48, - 125, 10, 32,108,111, 99, 97,108, 32,102, 32, 61, 32,102,117, - 110, 99,116,105,111,110, 32, 40,115, 41, 10, 32, 32,108, 46, - 110, 32, 61, 32,108, 46,110, 32, 43, 32, 49, 10, 32, 32,108, - 91,108, 46,110, 93, 32, 61, 32,115, 10, 32, 32,114,101,116, - 117,114,110, 32, 34, 34, 10, 32,101,110,100, 10, 32,108,111, - 99, 97,108, 32,112, 32, 61, 32, 34, 37,115, 42, 40, 46, 45, - 41, 37,115, 42, 34, 46, 46,116, 46, 46, 34, 37,115, 42, 34, - 10, 32,115, 32, 61, 32,103,115,117, 98, 40,115, 44, 34, 94, - 37,115, 43, 34, 44, 34, 34, 41, 10, 32,115, 32, 61, 32,103, - 115,117, 98, 40,115, 44, 34, 37,115, 43, 36, 34, 44, 34, 34, - 41, 10, 32,115, 32, 61, 32,103,115,117, 98, 40,115, 44,112, - 44,102, 41, 10, 32,108, 46,110, 32, 61, 32,108, 46,110, 32, - 43, 32, 49, 10, 32,108, 91,108, 46,110, 93, 32, 61, 32,103, - 115,117, 98, 40,115, 44, 34, 40, 37,115, 37,115, 42, 41, 36, - 34, 44, 34, 34, 41, 10, 32,114,101,116,117,114,110, 32,108, - 10,101,110,100, 10, 10, 45, 45, 32,115,112,108,105,116,115, - 32, 97, 32,115,116,114,105,110,103, 32,117,115,105,110,103, - 32, 97, 32,112, 97,116,116,101,114,110, 44, 32, 99,111,110, - 115,105,100,101,114,105,110,103, 32,116,104,101, 32,115,112, - 97, 99,105, 97,108, 32, 99, 97,115,101,115, 32,111,102, 32, - 67, 32, 99,111,100,101, 32, 40,116,101,109,112,108, 97,116, - 101,115, 44, 32,102,117,110, 99,116,105,111,110, 32,112, 97, - 114, 97,109,101,116,101,114,115, 44, 32,101,116, 99, 41, 10, - 45, 45, 32,112, 97,116,116,101,114,110, 32, 99, 97,110, 39, - 116, 32, 99,111,110,116, 97,105,110, 32,116,104,101, 32, 39, - 94, 39, 32, 40, 97,115, 32,117,115,101,100, 32,116,111, 32, - 105,100,101,110,116,105,102,121, 32,116,104,101, 32, 98,101, - 103,105,110,105,110,103, 32,111,102, 32,116,104,101, 32,108, - 105,110,101, 41, 10, 45, 45, 32, 97,108,115,111, 32,115,116, - 114,105,112,115, 32,119,104,105,116,101,115,112, 97, 99,101, - 10,102,117,110, 99,116,105,111,110, 32,115,112,108,105,116, - 95, 99, 95,116,111,107,101,110,115, 40,115, 44, 32,112, 97, - 116, 41, 10, 10, 9,115, 32, 61, 32,115,116,114,105,110,103, - 46,103,115,117, 98, 40,115, 44, 32, 34, 94, 37,115, 42, 34, - 44, 32, 34, 34, 41, 10, 9,115, 32, 61, 32,115,116,114,105, - 110,103, 46,103,115,117, 98, 40,115, 44, 32, 34, 37,115, 42, - 36, 34, 44, 32, 34, 34, 41, 10, 10, 9,108,111, 99, 97,108, - 32,116,111,107,101,110, 95, 98,101,103,105,110, 32, 61, 32, - 49, 10, 9,108,111, 99, 97,108, 32,116,111,107,101,110, 95, - 101,110,100, 32, 61, 32, 49, 10, 9,108,111, 99, 97,108, 32, - 111,102,115, 32, 61, 32, 49, 10, 9,108,111, 99, 97,108, 32, - 114,101,116, 32, 61, 32,123,110, 61, 48,125, 10, 10, 9,102, - 117,110, 99,116,105,111,110, 32, 97,100,100, 95,116,111,107, - 101,110, 40,111,102,115, 41, 10, 10, 9, 9,108,111, 99, 97, - 108, 32,116, 32, 61, 32,115,116,114,105,110,103, 46,115,117, - 98, 40,115, 44, 32,116,111,107,101,110, 95, 98,101,103,105, - 110, 44, 32,111,102,115, 41, 10, 9, 9,116, 32, 61, 32,115, - 116,114,105,110,103, 46,103,115,117, 98, 40,116, 44, 32, 34, - 94, 37,115, 42, 34, 44, 32, 34, 34, 41, 10, 9, 9,116, 32, - 61, 32,115,116,114,105,110,103, 46,103,115,117, 98, 40,116, - 44, 32, 34, 37,115, 42, 36, 34, 44, 32, 34, 34, 41, 10, 9, - 9,114,101,116, 46,110, 32, 61, 32,114,101,116, 46,110, 32, - 43, 32, 49, 10, 9, 9,114,101,116, 91,114,101,116, 46,110, - 93, 32, 61, 32,116, 10, 9,101,110,100, 10, 10, 9,119,104, - 105,108,101, 32,111,102,115, 32, 60, 61, 32,115,116,114,105, - 110,103, 46,108,101,110, 40,115, 41, 32,100,111, 10, 10, 9, - 9,108,111, 99, 97,108, 32,115,117, 98, 32, 61, 32,115,116, - 114,105,110,103, 46,115,117, 98, 40,115, 44, 32,111,102,115, - 44, 32, 45, 49, 41, 10, 9, 9,108,111, 99, 97,108, 32, 98, - 44,101, 32, 61, 32,115,116,114,105,110,103, 46,102,105,110, - 100, 40,115,117, 98, 44, 32, 34, 94, 34, 46, 46,112, 97,116, - 41, 10, 9, 9,105,102, 32, 98, 32,116,104,101,110, 10, 9, - 9, 9, 97,100,100, 95,116,111,107,101,110, 40,111,102,115, - 45, 49, 41, 10, 9, 9, 9,111,102,115, 32, 61, 32,111,102, - 115, 43,101, 10, 9, 9, 9,116,111,107,101,110, 95, 98,101, - 103,105,110, 32, 61, 32,111,102,115, 10, 9, 9,101,108,115, - 101, 10, 9, 9, 9,108,111, 99, 97,108, 32, 99,104, 97,114, - 32, 61, 32,115,116,114,105,110,103, 46,115,117, 98, 40,115, - 44, 32,111,102,115, 44, 32,111,102,115, 41, 10, 9, 9, 9, - 105,102, 32, 99,104, 97,114, 32, 61, 61, 32, 34, 40, 34, 32, - 111,114, 32, 99,104, 97,114, 32, 61, 61, 32, 34, 60, 34, 32, - 116,104,101,110, 10, 10, 9, 9, 9, 9,108,111, 99, 97,108, - 32, 98,108,111, 99,107, 10, 9, 9, 9, 9,105,102, 32, 99, - 104, 97,114, 32, 61, 61, 32, 34, 40, 34, 32,116,104,101,110, - 32, 98,108,111, 99,107, 32, 61, 32, 34, 94, 37, 98, 40, 41, - 34, 32,101,110,100, 10, 9, 9, 9, 9,105,102, 32, 99,104, - 97,114, 32, 61, 61, 32, 34, 60, 34, 32,116,104,101,110, 32, - 98,108,111, 99,107, 32, 61, 32, 34, 94, 37, 98, 60, 62, 34, - 32,101,110,100, 10, 10, 9, 9, 9, 9, 98, 44,101, 32, 61, - 32,115,116,114,105,110,103, 46,102,105,110,100, 40,115,117, - 98, 44, 32, 98,108,111, 99,107, 41, 10, 9, 9, 9, 9,105, - 102, 32,110,111,116, 32, 98, 32,116,104,101,110, 10, 9, 9, - 9, 9, 9, 45, 45, 32,117,110,116,101,114,109,105,110, 97, - 116,101,100, 32, 98,108,111, 99,107, 63, 10, 9, 9, 9, 9, - 9,111,102,115, 32, 61, 32,111,102,115, 43, 49, 10, 9, 9, - 9, 9,101,108,115,101, 10, 9, 9, 9, 9, 9,111,102,115, - 32, 61, 32,111,102,115, 32, 43, 32,101, 10, 9, 9, 9, 9, - 101,110,100, 10, 10, 9, 9, 9,101,108,115,101, 10, 9, 9, - 9, 9,111,102,115, 32, 61, 32,111,102,115, 43, 49, 10, 9, - 9, 9,101,110,100, 10, 9, 9,101,110,100, 10, 10, 9,101, - 110,100, 10, 9, 97,100,100, 95,116,111,107,101,110, 40,111, - 102,115, 41, 10, 9, 45, 45,105,102, 32,114,101,116, 46,110, - 32, 61, 61, 32, 48, 32,116,104,101,110, 10, 10, 9, 45, 45, - 9,114,101,116, 46,110, 61, 49, 10, 9, 45, 45, 9,114,101, - 116, 91, 49, 93, 32, 61, 32, 34, 34, 10, 9, 45, 45,101,110, - 100, 10, 10, 9,114,101,116,117,114,110, 32,114,101,116, 10, - 10,101,110,100, 10, 10, 45, 45, 32, 99,111,110, 99, 97,116, - 101,110, 97,116,101, 32,115,116,114,105,110,103,115, 32,111, - 102, 32, 97, 32,116, 97, 98,108,101, 10,102,117,110, 99,116, - 105,111,110, 32, 99,111,110, 99, 97,116, 32, 40,116, 44,102, - 44,108, 44,106,115,116,114, 41, 10, 9,106,115,116,114, 32, - 61, 32,106,115,116,114, 32,111,114, 32, 34, 32, 34, 10, 32, - 108,111, 99, 97,108, 32,115, 32, 61, 32, 39, 39, 10, 32,108, - 111, 99, 97,108, 32,105, 61,102, 10, 32,119,104,105,108,101, - 32,105, 60, 61,108, 32,100,111, 10, 32, 32,115, 32, 61, 32, - 115, 46, 46,116, 91,105, 93, 10, 32, 32,105, 32, 61, 32,105, - 43, 49, 10, 32, 32,105,102, 32,105, 32, 60, 61, 32,108, 32, - 116,104,101,110, 32,115, 32, 61, 32,115, 46, 46,106,115,116, - 114, 32,101,110,100, 10, 32,101,110,100, 10, 32,114,101,116, - 117,114,110, 32,115, 10,101,110,100, 10, 10, 45, 45, 32, 99, - 111,110, 99, 97,116,101,110, 97,116,101, 32, 97,108,108, 32, - 112, 97,114, 97,109,101,116,101,114,115, 44, 32,102,111,108, - 108,111,119,105,110,103, 32,111,117,116,112,117,116, 32,114, - 117,108,101,115, 10,102,117,110, 99,116,105,111,110, 32, 99, - 111,110, 99, 97,116,112, 97,114, 97,109, 32, 40,108,105,110, - 101, 44, 32, 46, 46, 46, 41, 10, 32,108,111, 99, 97,108, 32, - 105, 61, 49, 10, 32,119,104,105,108,101, 32,105, 60, 61, 97, - 114,103, 46,110, 32,100,111, 10, 32, 32,105,102, 32, 95, 99, - 111,110,116, 32, 97,110,100, 32,110,111,116, 32,115,116,114, - 102,105,110,100, 40, 95, 99,111,110,116, 44, 39, 91, 37, 40, - 44, 34, 93, 39, 41, 32, 97,110,100, 10, 32, 32, 32, 32, 32, - 115,116,114,102,105,110,100, 40, 97,114,103, 91,105, 93, 44, - 34, 94, 91, 37, 97, 95,126, 93, 34, 41, 32,116,104,101,110, - 10, 9, 32, 32, 32, 32,108,105,110,101, 32, 61, 32,108,105, - 110,101, 32, 46, 46, 32, 39, 32, 39, 10, 32, 32,101,110,100, - 10, 32, 32,108,105,110,101, 32, 61, 32,108,105,110,101, 32, - 46, 46, 32, 97,114,103, 91,105, 93, 10, 32, 32,105,102, 32, - 97,114,103, 91,105, 93, 32,126, 61, 32, 39, 39, 32,116,104, - 101,110, 10, 32, 32, 32, 95, 99,111,110,116, 32, 61, 32,115, - 116,114,115,117, 98, 40, 97,114,103, 91,105, 93, 44, 45, 49, - 44, 45, 49, 41, 10, 32, 32,101,110,100, 10, 32, 32,105, 32, - 61, 32,105, 43, 49, 10, 32,101,110,100, 10, 32,105,102, 32, - 115,116,114,102,105,110,100, 40, 97,114,103, 91, 97,114,103, - 46,110, 93, 44, 34, 91, 37, 47, 37, 41, 37, 59, 37,123, 37, - 125, 93, 36, 34, 41, 32,116,104,101,110, 10, 32, 32, 95, 99, - 111,110,116, 61,110,105,108, 32,108,105,110,101, 32, 61, 32, - 108,105,110,101, 32, 46, 46, 32, 39, 92,110, 39, 10, 32,101, - 110,100, 10, 9,114,101,116,117,114,110, 32,108,105,110,101, - 10,101,110,100, 10, 10, 45, 45, 32,111,117,116,112,117,116, - 32,108,105,110,101, 10,102,117,110, 99,116,105,111,110, 32, - 111,117,116,112,117,116, 32, 40, 46, 46, 46, 41, 10, 32,108, - 111, 99, 97,108, 32,105, 61, 49, 10, 32,119,104,105,108,101, - 32,105, 60, 61, 97,114,103, 46,110, 32,100,111, 10, 32, 32, - 105,102, 32, 95, 99,111,110,116, 32, 97,110,100, 32,110,111, - 116, 32,115,116,114,102,105,110,100, 40, 95, 99,111,110,116, - 44, 39, 91, 37, 40, 44, 34, 93, 39, 41, 32, 97,110,100, 10, - 32, 32, 32, 32, 32,115,116,114,102,105,110,100, 40, 97,114, - 103, 91,105, 93, 44, 34, 94, 91, 37, 97, 95,126, 93, 34, 41, - 32,116,104,101,110, 10, 9, 32, 32, 32, 32,119,114,105,116, - 101, 40, 39, 32, 39, 41, 10, 32, 32,101,110,100, 10, 32, 32, - 119,114,105,116,101, 40, 97,114,103, 91,105, 93, 41, 10, 32, - 32,105,102, 32, 97,114,103, 91,105, 93, 32,126, 61, 32, 39, - 39, 32,116,104,101,110, 10, 32, 32, 32, 95, 99,111,110,116, - 32, 61, 32,115,116,114,115,117, 98, 40, 97,114,103, 91,105, - 93, 44, 45, 49, 44, 45, 49, 41, 10, 32, 32,101,110,100, 10, - 32, 32,105, 32, 61, 32,105, 43, 49, 10, 32,101,110,100, 10, - 32,105,102, 32,115,116,114,102,105,110,100, 40, 97,114,103, - 91, 97,114,103, 46,110, 93, 44, 34, 91, 37, 47, 37, 41, 37, - 59, 37,123, 37,125, 93, 36, 34, 41, 32,116,104,101,110, 10, - 32, 32, 95, 99,111,110,116, 61,110,105,108, 32,119,114,105, - 116,101, 40, 39, 92,110, 39, 41, 10, 32,101,110,100, 10,101, - 110,100, 10, 10,102,117,110, 99,116,105,111,110, 32,103,101, - 116, 95,112,114,111,112,101,114,116,121, 95,109,101,116,104, - 111,100,115, 40,112,116,121,112,101, 44, 32,110, 97,109,101, - 41, 10, 10, 9,105,102, 32,103,101,116, 95,112,114,111,112, - 101,114,116,121, 95,109,101,116,104,111,100,115, 95,104,111, - 111,107, 32, 97,110,100, 32,103,101,116, 95,112,114,111,112, - 101,114,116,121, 95,109,101,116,104,111,100,115, 95,104,111, - 111,107, 40,112,116,121,112,101, 44,110, 97,109,101, 41, 32, - 116,104,101,110, 10, 9, 9,114,101,116,117,114,110, 32,103, - 101,116, 95,112,114,111,112,101,114,116,121, 95,109,101,116, - 104,111,100,115, 95,104,111,111,107, 40,112,116,121,112,101, - 44, 32,110, 97,109,101, 41, 10, 9,101,110,100, 10, 10, 9, - 105,102, 32,112,116,121,112,101, 32, 61, 61, 32, 34,100,101, - 102, 97,117,108,116, 34, 32,116,104,101,110, 32, 45, 45, 32, - 103,101,116, 95,110, 97,109,101, 44, 32,115,101,116, 95,110, - 97,109,101, 10, 9, 9,114,101,116,117,114,110, 32, 34,103, - 101,116, 95, 34, 46, 46,110, 97,109,101, 44, 32, 34,115,101, - 116, 95, 34, 46, 46,110, 97,109,101, 10, 9,101,110,100, 10, - 10, 9,105,102, 32,112,116,121,112,101, 32, 61, 61, 32, 34, - 113,116, 34, 32,116,104,101,110, 32, 45, 45, 32,110, 97,109, - 101, 44, 32,115,101,116, 78, 97,109,101, 10, 9, 9,114,101, - 116,117,114,110, 32,110, 97,109,101, 44, 32, 34,115,101,116, - 34, 46, 46,115,116,114,105,110,103, 46,117,112,112,101,114, - 40,115,116,114,105,110,103, 46,115,117, 98, 40,110, 97,109, - 101, 44, 32, 49, 44, 32, 49, 41, 41, 46, 46,115,116,114,105, - 110,103, 46,115,117, 98, 40,110, 97,109,101, 44, 32, 50, 44, - 32, 45, 49, 41, 10, 9,101,110,100, 10, 10, 9,105,102, 32, - 112,116,121,112,101, 32, 61, 61, 32, 34,111,118,101,114,108, - 111, 97,100, 34, 32,116,104,101,110, 32, 45, 45, 32,110, 97, - 109,101, 44, 32,110, 97,109,101, 10, 9, 9,114,101,116,117, - 114,110, 32,110, 97,109,101, 44,110, 97,109,101, 10, 9,101, - 110,100, 10, 10, 9,114,101,116,117,114,110, 32,110,105,108, - 10,101,110,100, 10, 10, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 32,116,104,101, 32,104,111,111,107,115, - 10, 10, 45, 45, 32, 99, 97,108,108,101,100, 32,114,105,103, - 104,116, 32, 97,102,116,101,114, 32,112,114,111, 99,101,115, - 115,105,110,103, 32,116,104,101, 32, 36, 91,105, 99,104,108, - 93,102,105,108,101, 32,100,105,114,101, 99,116,105,118,101, - 115, 44, 10, 45, 45, 32,114,105,103,104,116, 32, 98,101,102, - 111,114,101, 32,112,114,111, 99,101,115,115,105,110,103, 32, - 97,110,121,116,104,105,110,103, 32,101,108,115,101, 10, 45, - 45, 32,116, 97,107,101,115, 32,116,104,101, 32,112, 97, 99, - 107, 97,103,101, 32,111, 98,106,101, 99,116, 32, 97,115, 32, - 116,104,101, 32,112, 97,114, 97,109,101,116,101,114, 10,102, - 117,110, 99,116,105,111,110, 32,112,114,101,112,114,111, 99, - 101,115,115, 95,104,111,111,107, 40,112, 41, 10, 9, 45, 45, - 32,112, 46, 99,111,100,101, 32,104, 97,115, 32, 97,108,108, - 32,116,104,101, 32,105,110,112,117,116, 32, 99,111,100,101, - 32,102,114,111,109, 32,116,104,101, 32,112,107,103, 10,101, - 110,100, 10, 10, 10, 45, 45, 32, 99, 97,108,108,101,100, 32, - 102,111,114, 32,101,118,101,114,121, 32, 36,105,102,105,108, - 101, 32,100,105,114,101, 99,116,105,118,101, 10, 45, 45, 32, - 116, 97,107,101,115, 32, 97, 32,116, 97, 98,108,101, 32,119, - 105,116,104, 32, 97, 32,115,116,114,105,110,103, 32, 99, 97, - 108,108,101,100, 32, 39, 99,111,100,101, 39, 32,105,110,115, - 105,100,101, 44, 32,116,104,101, 32,102,105,108,101,110, 97, - 109,101, 44, 32, 97,110,100, 32, 97,110,121, 32,101,120,116, - 114, 97, 32, 97,114,103,117,109,101,110,116,115, 10, 45, 45, - 32,112, 97,115,115,101,100, 32,116,111, 32, 36,105,102,105, - 108,101, 46, 32,110,111, 32,114,101,116,117,114,110, 32,118, - 97,108,117,101, 10,102,117,110, 99,116,105,111,110, 32,105, - 110, 99,108,117,100,101, 95,102,105,108,101, 95,104,111,111, - 107, 40,116, 44, 32,102,105,108,101,110, 97,109,101, 44, 32, - 46, 46, 46, 41, 10, 10,101,110,100, 10, 10, 45, 45, 32, 99, - 97,108,108,101,100, 32, 97,102,116,101,114, 32,112,114,111, - 99,101,115,115,105,110,103, 32, 97,110,121,116,104,105,110, - 103, 32,116,104, 97,116, 39,115, 32,110,111,116, 32, 99,111, - 100,101, 32, 40,108,105,107,101, 32, 39, 36,114,101,110, 97, - 109,105,110,103, 39, 44, 32, 99,111,109,109,101,110,116,115, - 44, 32,101,116, 99, 41, 10, 45, 45, 32, 97,110,100, 32,114, - 105,103,104,116, 32, 98,101,102,111,114,101, 32,112, 97,114, - 115,105,110,103, 32,116,104,101, 32, 97, 99,116,117, 97,108, - 32, 99,111,100,101, 46, 10, 45, 45, 32,116, 97,107,101,115, - 32,116,104,101, 32, 80, 97, 99,107, 97,103,101, 32,111, 98, - 106,101, 99,116, 32,119,105,116,104, 32, 97,108,108, 32,116, - 104,101, 32, 99,111,100,101, 32,111,110, 32,116,104,101, 32, - 39, 99,111,100,101, 39, 32,107,101,121, 46, 32,110,111, 32, - 114,101,116,117,114,110, 32,118, 97,108,117,101, 10,102,117, - 110, 99,116,105,111,110, 32,112,114,101,112, 97,114,115,101, - 95,104,111,111,107, 40,112, 97, 99,107, 97,103,101, 41, 10, - 10,101,110,100, 10, 10, 45, 45, 32, 99, 97,108,108,101,100, - 32, 98,101,102,111,114,101, 32,115,116, 97,114,116,105,110, - 103, 32,111,117,116,112,117,116, 10,102,117,110, 99,116,105, - 111,110, 32,112,114,101, 95,111,117,116,112,117,116, 95,104, - 111,111,107, 40,112, 97, 99,107, 97,103,101, 41, 10, 10,101, - 110,100, 10, 10, 45, 45, 32, 99, 97,108,108,101,100, 32, 97, - 102,116,101,114, 32,119,114,105,116,105,110,103, 32, 97,108, - 108, 32,116,104,101, 32,111,117,116,112,117,116, 46, 10, 45, - 45, 32,116, 97,107,101,115, 32,116,104,101, 32, 80, 97, 99, - 107, 97,103,101, 32,111, 98,106,101, 99,116, 10,102,117,110, - 99,116,105,111,110, 32,112,111,115,116, 95,111,117,116,112, - 117,116, 95,104,111,111,107, 40,112, 97, 99,107, 97,103,101, - 41, 10, 10,101,110,100, 10, 10, 10, 45, 45, 32, 99, 97,108, - 108,101,100, 32,102,114,111,109, 32, 39,103,101,116, 95,112, - 114,111,112,101,114,116,121, 95,109,101,116,104,111,100,115, - 39, 32,116,111, 32,103,101,116, 32,116,104,101, 32,109,101, - 116,104,111,100,115, 32,116,111, 32,114,101,116,114,105,101, - 118,101, 32, 97, 32,112,114,111,112,101,114,116,121, 10, 45, - 45, 32, 97, 99, 99,111,114,100,105,110,103, 32,116,111, 32, - 105,116,115, 32,116,121,112,101, 10,102,117,110, 99,116,105, - 111,110, 32,103,101,116, 95,112,114,111,112,101,114,116,121, - 95,109,101,116,104,111,100,115, 95,104,111,111,107, 40,112, - 114,111,112,101,114,116,121, 95,116,121,112,101, 44, 32,110, - 97,109,101, 41, 10, 10,101,110,100, 10, 10, 45, 45, 32, 99, - 97,108,108,101,100, 32,102,114,111,109, 32, 67,108, 97,115, - 115, 67,111,110,116, 97,105,110,101,114, 58,100,111,112, 97, - 114,115,101, 32,119,105,116,104, 32,116,104,101, 32,115,116, - 114,105,110,103, 32, 98,101,105,110,103, 32,112, 97,114,115, - 101,100, 10, 45, 45, 32,114,101,116,117,114,110, 32,110,105, - 108, 44, 32,111,114, 32, 97, 32,115,117, 98,115,116,114,105, - 110,103, 10,102,117,110, 99,116,105,111,110, 32,112, 97,114, - 115,101,114, 95,104,111,111,107, 40,115, 41, 10, 10, 9,114, - 101,116,117,114,110, 32,110,105,108, 10,101,110,100, 10, 10, - 45, 45, 32, 99, 97,108,108,101,100, 32,102,114,111,109, 32, - 99,108, 97,115,115, 70,117,110, 99,116,105,111,110, 58,115, - 117,112, 99,111,100,101, 44, 32, 98,101,102,111,114,101, 32, - 116,104,101, 32, 99, 97,108,108, 32,116,111, 32,116,104,101, - 32,102,117,110, 99,116,105,111,110, 32,105,115, 32,111,117, - 116,112,117,116, 10,102,117,110, 99,116,105,111,110, 32,112, - 114,101, 95, 99, 97,108,108, 95,104,111,111,107, 40,102, 41, - 10, 10,101,110,100, 10, 10, 45, 45, 32, 99, 97,108,108,101, - 100, 32,102,114,111,109, 32, 99,108, 97,115,115, 70,117,110, - 99,116,105,111,110, 58,115,117,112, 99,111,100,101, 44, 32, - 97,102,116,101,114, 32,116,104,101, 32, 99, 97,108,108, 32, - 116,111, 32,116,104,101, 32,102,117,110, 99,116,105,111,110, - 32,105,115, 32,111,117,116,112,117,116, 10,102,117,110, 99, - 116,105,111,110, 32,112,111,115,116, 95, 99, 97,108,108, 95, - 104,111,111,107, 40,102, 41, 10, 10,101,110,100, 10, 10, 45, - 45, 32, 99, 97,108,108,101,100, 32, 98,101,102,111,114,101, - 32,116,104,101, 32,114,101,103,105,115,116,101,114, 32, 99, - 111,100,101, 32,105,115, 32,111,117,116,112,117,116, 10,102, - 117,110, 99,116,105,111,110, 32,112,114,101, 95,114,101,103, - 105,115,116,101,114, 95,104,111,111,107, 40,112, 97, 99,107, - 97,103,101, 41, 10, 10,101,110,100, 10, 10, 45, 45, 32, 99, - 97,108,108,101,100, 32,116,111, 32,111,117,116,112,117,116, - 32, 97,110, 32,101,114,114,111,114, 32,109,101,115,115, 97, - 103,101, 10,102,117,110, 99,116,105,111,110, 32,111,117,116, - 112,117,116, 95,101,114,114,111,114, 95,104,111,111,107, 40, - 46, 46, 46, 41, 10, 9,114,101,116,117,114,110, 32,115,116, - 114,105,110,103, 46,102,111,114,109, 97,116, 40, 46, 46, 46, - 41, 10,101,110,100, 10, 10, 45, 45, 32, 99,117,115,116,111, - 109, 32,112,117,115,104,101,114,115, 10, 10, 95,112,117,115, - 104, 95,102,117,110, 99,116,105,111,110,115, 32, 61, 32,123, - 125, 10, 95,105,115, 95,102,117,110, 99,116,105,111,110,115, - 32, 61, 32,123,125, 10, 95,116,111, 95,102,117,110, 99,116, - 105,111,110,115, 32, 61, 32,123,125, 10, 10, 95, 98, 97,115, - 101, 95,112,117,115,104, 95,102,117,110, 99,116,105,111,110, - 115, 32, 61, 32,123,125, 10, 95, 98, 97,115,101, 95,105,115, - 95,102,117,110, 99,116,105,111,110,115, 32, 61, 32,123,125, - 10, 95, 98, 97,115,101, 95,116,111, 95,102,117,110, 99,116, - 105,111,110,115, 32, 61, 32,123,125, 10, 10,108,111, 99, 97, - 108, 32,102,117,110, 99,116,105,111,110, 32,115,101, 97,114, - 99,104, 95, 98, 97,115,101, 40,116, 44, 32,102,117,110, 99, - 115, 41, 10, 10, 9,108,111, 99, 97,108, 32, 99,108, 97,115, - 115, 32, 61, 32, 95,103,108,111, 98, 97,108, 95, 99,108, 97, - 115,115,101,115, 91,116, 93, 10, 10, 9,119,104,105,108,101, - 32, 99,108, 97,115,115, 32,100,111, 10, 9, 9,105,102, 32, - 102,117,110, 99,115, 91, 99,108, 97,115,115, 46,116,121,112, - 101, 93, 32,116,104,101,110, 10, 9, 9, 9,114,101,116,117, - 114,110, 32,102,117,110, 99,115, 91, 99,108, 97,115,115, 46, - 116,121,112,101, 93, 10, 9, 9,101,110,100, 10, 9, 9, 99, - 108, 97,115,115, 32, 61, 32, 95,103,108,111, 98, 97,108, 95, - 99,108, 97,115,115,101,115, 91, 99,108, 97,115,115, 46, 98, - 116,121,112,101, 93, 10, 9,101,110,100, 10, 9,114,101,116, - 117,114,110, 32,110,105,108, 10,101,110,100, 10, 10,102,117, - 110, 99,116,105,111,110, 32,103,101,116, 95,112,117,115,104, - 95,102,117,110, 99,116,105,111,110, 40,116, 41, 10, 9,114, - 101,116,117,114,110, 32, 95,112,117,115,104, 95,102,117,110, - 99,116,105,111,110,115, 91,116, 93, 32,111,114, 32,115,101, - 97,114, 99,104, 95, 98, 97,115,101, 40,116, 44, 32, 95, 98, - 97,115,101, 95,112,117,115,104, 95,102,117,110, 99,116,105, - 111,110,115, 41, 32,111,114, 32, 34,116,111,108,117, 97, 95, - 112,117,115,104,117,115,101,114,116,121,112,101, 34, 10,101, - 110,100, 10, 10,102,117,110, 99,116,105,111,110, 32,103,101, - 116, 95,116,111, 95,102,117,110, 99,116,105,111,110, 40,116, - 41, 10, 9,114,101,116,117,114,110, 32, 95,116,111, 95,102, - 117,110, 99,116,105,111,110,115, 91,116, 93, 32,111,114, 32, - 115,101, 97,114, 99,104, 95, 98, 97,115,101, 40,116, 44, 32, - 95, 98, 97,115,101, 95,116,111, 95,102,117,110, 99,116,105, - 111,110,115, 41, 32,111,114, 32, 34,116,111,108,117, 97, 95, - 116,111,117,115,101,114,116,121,112,101, 34, 10,101,110,100, - 10, 10,102,117,110, 99,116,105,111,110, 32,103,101,116, 95, - 105,115, 95,102,117,110, 99,116,105,111,110, 40,116, 41, 10, - 9,114,101,116,117,114,110, 32, 95,105,115, 95,102,117,110, - 99,116,105,111,110,115, 91,116, 93, 32,111,114, 32,115,101, - 97,114, 99,104, 95, 98, 97,115,101, 40,116, 44, 32, 95, 98, - 97,115,101, 95,105,115, 95,102,117,110, 99,116,105,111,110, - 115, 41, 32,111,114, 32, 34,116,111,108,117, 97, 95,105,115, - 117,115,101,114,116,121,112,101, 34, 10,101,110,100,32 - }; - tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua embedded: src/bin/lua/basic.lua"); + #include "basic_lua.h" + tolua_dobuffer(tolua_S,(char*)lua_basic_lua,sizeof(lua_basic_lua),"tolua embedded: src/bin/lua/basic.lua"); lua_settop(tolua_S, top); } /* end of embedded lua code */ @@ -3788,180 +3193,11 @@ TOLUA_API int tolua_tolua_open (lua_State* tolua_S) } /* end of embedded lua code */ + { /* begin embedded lua code */ int top = lua_gettop(tolua_S); - static unsigned char B[] = { - 45, 45, 32,116,111,108,117, 97, 58, 32,101,110,117,109,101, - 114, 97,116,101, 32, 99,108, 97,115,115, 10, 45, 45, 32, 87, - 114,105,116,116,101,110, 32, 98,121, 32, 87, 97,108,100,101, - 109, 97,114, 32, 67,101,108,101,115, 10, 45, 45, 32, 84,101, - 67, 71,114, 97,102, 47, 80, 85, 67, 45, 82,105,111, 10, 45, - 45, 32, 74,117,108, 32, 49, 57, 57, 56, 10, 45, 45, 32, 36, - 73,100, 58, 32,101,110,117,109,101,114, 97,116,101, 46,108, - 117, 97, 44,118, 32, 49, 46, 51, 32, 50, 48, 48, 48, 47, 48, - 49, 47, 50, 52, 32, 50, 48, 58, 52, 49, 58, 49, 53, 32, 99, - 101,108,101,115, 32, 69,120,112, 32, 36, 10, 10, 45, 45, 32, - 84,104,105,115, 32, 99,111,100,101, 32,105,115, 32,102,114, - 101,101, 32,115,111,102,116,119, 97,114,101, 59, 32,121,111, - 117, 32, 99, 97,110, 32,114,101,100,105,115,116,114,105, 98, - 117,116,101, 32,105,116, 32, 97,110,100, 47,111,114, 32,109, - 111,100,105,102,121, 32,105,116, 46, 10, 45, 45, 32, 84,104, - 101, 32,115,111,102,116,119, 97,114,101, 32,112,114,111,118, - 105,100,101,100, 32,104,101,114,101,117,110,100,101,114, 32, - 105,115, 32,111,110, 32, 97,110, 32, 34, 97,115, 32,105,115, - 34, 32, 98, 97,115,105,115, 44, 32, 97,110,100, 10, 45, 45, - 32,116,104,101, 32, 97,117,116,104,111,114, 32,104, 97,115, - 32,110,111, 32,111, 98,108,105,103, 97,116,105,111,110, 32, - 116,111, 32,112,114,111,118,105,100,101, 32,109, 97,105,110, - 116,101,110, 97,110, 99,101, 44, 32,115,117,112,112,111,114, - 116, 44, 32,117,112,100, 97,116,101,115, 44, 10, 45, 45, 32, - 101,110,104, 97,110, 99,101,109,101,110,116,115, 44, 32,111, - 114, 32,109,111,100,105,102,105, 99, 97,116,105,111,110,115, - 46, 10, 10, 10, 45, 45, 32, 69,110,117,109,101,114, 97,116, - 101, 32, 99,108, 97,115,115, 10, 45, 45, 32, 82,101,112,114, - 101,115,101,110,116,115, 32,101,110,117,109,101,114, 97,116, - 105,111,110, 10, 45, 45, 32, 84,104,101, 32,102,111,108,108, - 111,119,105,110,103, 32,102,105,101,108,100,115, 32, 97,114, - 101, 32,115,116,111,114,101,100, 58, 10, 45, 45, 32, 32, 32, - 32,123,105,125, 32, 61, 32,108,105,115,116, 32,111,102, 32, - 99,111,110,115,116, 97,110,116, 32,110, 97,109,101,115, 10, - 99,108, 97,115,115, 69,110,117,109,101,114, 97,116,101, 32, - 61, 32,123, 10,125, 10, 99,108, 97,115,115, 69,110,117,109, - 101,114, 97,116,101, 46, 95, 95,105,110,100,101,120, 32, 61, - 32, 99,108, 97,115,115, 69,110,117,109,101,114, 97,116,101, - 10,115,101,116,109,101,116, 97,116, 97, 98,108,101, 40, 99, - 108, 97,115,115, 69,110,117,109,101,114, 97,116,101, 44, 99, - 108, 97,115,115, 70,101, 97,116,117,114,101, 41, 10, 10, 45, - 45, 32,114,101,103,105,115,116,101,114, 32,101,110,117,109, - 101,114, 97,116,105,111,110, 10,102,117,110, 99,116,105,111, - 110, 32, 99,108, 97,115,115, 69,110,117,109,101,114, 97,116, - 101, 58,114,101,103,105,115,116,101,114, 32, 40,112,114,101, - 41, 10, 9,105,102, 32,110,111,116, 32,115,101,108,102, 58, - 99,104,101, 99,107, 95,112,117, 98,108,105, 99, 95, 97, 99, - 99,101,115,115, 40, 41, 32,116,104,101,110, 10, 9, 9,114, - 101,116,117,114,110, 10, 9,101,110,100, 10, 32,112,114,101, - 32, 61, 32,112,114,101, 32,111,114, 32, 39, 39, 10, 32,108, - 111, 99, 97,108, 32,110,115,112, 97, 99,101, 32, 61, 32,103, - 101,116,110, 97,109,101,115,112, 97, 99,101, 40, 99,108, 97, - 115,115, 67,111,110,116, 97,105,110,101,114, 46, 99,117,114, - 114, 41, 10, 32,108,111, 99, 97,108, 32,105, 61, 49, 10, 32, - 119,104,105,108,101, 32,115,101,108,102, 91,105, 93, 32,100, - 111, 10, 32, 9,105,102, 32,115,101,108,102, 46,108,110, 97, - 109,101,115, 91,105, 93, 32, 97,110,100, 32,115,101,108,102, - 46,108,110, 97,109,101,115, 91,105, 93, 32,126, 61, 32, 34, - 34, 32,116,104,101,110, 10, 9, 10, 9, 9,111,117,116,112, - 117,116, 40,112,114,101, 46, 46, 39,116,111,108,117, 97, 95, - 99,111,110,115,116, 97,110,116, 40,116,111,108,117, 97, 95, - 83, 44, 34, 39, 46, 46,115,101,108,102, 46,108,110, 97,109, - 101,115, 91,105, 93, 46, 46, 39, 34, 44, 39, 46, 46,110,115, - 112, 97, 99,101, 46, 46,115,101,108,102, 91,105, 93, 46, 46, - 39, 41, 59, 39, 41, 10, 9,101,110,100, 10, 32, 32,105, 32, - 61, 32,105, 43, 49, 10, 32,101,110,100, 10,101,110,100, 10, - 10, 45, 45, 32, 80,114,105,110,116, 32,109,101,116,104,111, - 100, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97,115, - 115, 69,110,117,109,101,114, 97,116,101, 58,112,114,105,110, - 116, 32, 40,105,100,101,110,116, 44, 99,108,111,115,101, 41, - 10, 32,112,114,105,110,116, 40,105,100,101,110,116, 46, 46, - 34, 69,110,117,109,101,114, 97,116,101,123, 34, 41, 10, 32, - 112,114,105,110,116, 40,105,100,101,110,116, 46, 46, 34, 32, - 110, 97,109,101, 32, 61, 32, 34, 46, 46,115,101,108,102, 46, - 110, 97,109,101, 41, 10, 32,108,111, 99, 97,108, 32,105, 61, - 49, 10, 32,119,104,105,108,101, 32,115,101,108,102, 91,105, - 93, 32,100,111, 10, 32, 32,112,114,105,110,116, 40,105,100, - 101,110,116, 46, 46, 34, 32, 39, 34, 46, 46,115,101,108,102, - 91,105, 93, 46, 46, 34, 39, 40, 34, 46, 46,115,101,108,102, - 46,108,110, 97,109,101,115, 91,105, 93, 46, 46, 34, 41, 44, - 34, 41, 10, 32, 32,105, 32, 61, 32,105, 43, 49, 10, 32,101, - 110,100, 10, 32,112,114,105,110,116, 40,105,100,101,110,116, - 46, 46, 34,125, 34, 46, 46, 99,108,111,115,101, 41, 10,101, - 110,100, 10, 10, 45, 45, 32, 73,110,116,101,114,110, 97,108, - 32, 99,111,110,115,116,114,117, 99,116,111,114, 10,102,117, - 110, 99,116,105,111,110, 32, 95, 69,110,117,109,101,114, 97, - 116,101, 32, 40,116, 44,118, 97,114,110, 97,109,101, 41, 10, - 32,115,101,116,109,101,116, 97,116, 97, 98,108,101, 40,116, - 44, 99,108, 97,115,115, 69,110,117,109,101,114, 97,116,101, - 41, 10, 32, 97,112,112,101,110,100, 40,116, 41, 10, 32, 97, - 112,112,101,110,100,101,110,117,109, 40,116, 41, 10, 9, 32, - 105,102, 32,118, 97,114,110, 97,109,101, 32, 97,110,100, 32, - 118, 97,114,110, 97,109,101, 32,126, 61, 32, 34, 34, 32,116, - 104,101,110, 10, 9, 9,105,102, 32,116, 46,110, 97,109,101, - 32,126, 61, 32, 34, 34, 32,116,104,101,110, 10, 9, 9, 9, - 86, 97,114,105, 97, 98,108,101, 40,116, 46,110, 97,109,101, - 46, 46, 34, 32, 34, 46, 46,118, 97,114,110, 97,109,101, 41, - 10, 9, 9,101,108,115,101, 10, 9, 9, 9,108,111, 99, 97, - 108, 32,110,115, 32, 61, 32,103,101,116, 99,117,114,114,110, - 97,109,101,115,112, 97, 99,101, 40, 41, 10, 9, 9, 9,119, - 97,114,110,105,110,103, 40, 34, 86, 97,114,105, 97, 98,108, - 101, 32, 34, 46, 46,110,115, 46, 46,118, 97,114,110, 97,109, - 101, 46, 46, 34, 32,111,102, 32,116,121,112,101, 32, 60, 97, - 110,111,110,121,109,111,117,115, 32,101,110,117,109, 62, 32, - 105,115, 32,100,101, 99,108, 97,114,101,100, 32, 97,115, 32, - 114,101, 97,100, 45,111,110,108,121, 34, 41, 10, 9, 9, 9, - 86, 97,114,105, 97, 98,108,101, 40, 34,116,111,108,117, 97, - 95,114,101, 97,100,111,110,108,121, 32,105,110,116, 32, 34, - 46, 46,118, 97,114,110, 97,109,101, 41, 10, 9, 9,101,110, - 100, 10, 9,101,110,100, 10, 9, 32,108,111, 99, 97,108, 32, - 112, 97,114,101,110,116, 32, 61, 32, 99,108, 97,115,115, 67, - 111,110,116, 97,105,110,101,114, 46, 99,117,114,114, 10, 9, - 32,105,102, 32,112, 97,114,101,110,116, 32,116,104,101,110, - 10, 9, 9,116, 46, 97, 99, 99,101,115,115, 32, 61, 32,112, - 97,114,101,110,116, 46, 99,117,114,114, 95,109,101,109, 98, - 101,114, 95, 97, 99, 99,101,115,115, 10, 9, 9,116, 46,103, - 108,111, 98, 97,108, 95, 97, 99, 99,101,115,115, 32, 61, 32, - 116, 58, 99,104,101, 99,107, 95,112,117, 98,108,105, 99, 95, - 97, 99, 99,101,115,115, 40, 41, 10, 9, 32,101,110,100, 10, - 114,101,116,117,114,110, 32,116, 10,101,110,100, 10, 10, 45, - 45, 32, 67,111,110,115,116,114,117, 99,116,111,114, 10, 45, - 45, 32, 69,120,112,101, 99,116,115, 32, 97, 32,115,116,114, - 105,110,103, 32,114,101,112,114,101,115,101,110,116,105,110, - 103, 32,116,104,101, 32,101,110,117,109,101,114, 97,116,101, - 32, 98,111,100,121, 10,102,117,110, 99,116,105,111,110, 32, - 69,110,117,109,101,114, 97,116,101, 32, 40,110, 44, 98, 44, - 118, 97,114,110, 97,109,101, 41, 10, 9, 98, 32, 61, 32,115, - 116,114,105,110,103, 46,103,115,117, 98, 40, 98, 44, 32, 34, - 44, 91, 37,115, 92,110, 93, 42,125, 34, 44, 32, 34, 92,110, - 125, 34, 41, 32, 45, 45, 32,101,108,105,109,105,110, 97,116, - 101, 32,108, 97,115,116, 32, 39, 44, 39, 10, 32,108,111, 99, - 97,108, 32,116, 32, 61, 32,115,112,108,105,116, 40,115,116, - 114,115,117, 98, 40, 98, 44, 50, 44, 45, 50, 41, 44, 39, 44, - 39, 41, 32, 45, 45, 32,101,108,105,109,105,110, 97,116,101, - 32, 98,114, 97, 99,101,115, 10, 32,108,111, 99, 97,108, 32, - 105, 32, 61, 32, 49, 10, 32,108,111, 99, 97,108, 32,101, 32, - 61, 32,123,110, 61, 48,125, 10, 32,119,104,105,108,101, 32, - 116, 91,105, 93, 32,100,111, 10, 32, 32,108,111, 99, 97,108, - 32,116,116, 32, 61, 32,115,112,108,105,116, 40,116, 91,105, - 93, 44, 39, 61, 39, 41, 32, 32, 45, 45, 32,100,105,115, 99, - 97,114,100, 32,105,110,105,116,105, 97,108, 32,118, 97,108, - 117,101, 10, 32, 32,101, 46,110, 32, 61, 32,101, 46,110, 32, - 43, 32, 49, 10, 32, 32,101, 91,101, 46,110, 93, 32, 61, 32, - 116,116, 91, 49, 93, 10, 32, 32,105, 32, 61, 32,105, 43, 49, - 10, 32,101,110,100, 10, 32, 45, 45, 32,115,101,116, 32,108, - 117, 97, 32,110, 97,109,101,115, 10, 32,105, 32, 32, 61, 32, - 49, 10, 32,101, 46,108,110, 97,109,101,115, 32, 61, 32,123, - 125, 10, 32,108,111, 99, 97,108, 32,110,115, 32, 61, 32,103, - 101,116, 99,117,114,114,110, 97,109,101,115,112, 97, 99,101, - 40, 41, 10, 32,119,104,105,108,101, 32,101, 91,105, 93, 32, - 100,111, 10, 32, 32,108,111, 99, 97,108, 32,116, 32, 61, 32, - 115,112,108,105,116, 40,101, 91,105, 93, 44, 39, 64, 39, 41, - 10, 32, 32,101, 91,105, 93, 32, 61, 32,116, 91, 49, 93, 10, - 9, 9,105,102, 32,110,111,116, 32,116, 91, 50, 93, 32,116, - 104,101,110, 10, 9, 9, 32,116, 91, 50, 93, 32, 61, 32, 97, - 112,112,108,121,114,101,110, 97,109,105,110,103, 40,116, 91, - 49, 93, 41, 10, 9, 9,101,110,100, 10, 32, 32,101, 46,108, - 110, 97,109,101,115, 91,105, 93, 32, 61, 32,116, 91, 50, 93, - 32,111,114, 32,116, 91, 49, 93, 10, 32, 32, 95,103,108,111, - 98, 97,108, 95,101,110,117,109,115, 91, 32,110,115, 46, 46, - 101, 91,105, 93, 32, 93, 32, 61, 32, 40,110,115, 46, 46,101, - 91,105, 93, 41, 10, 32, 32,105, 32, 61, 32,105, 43, 49, 10, - 32,101,110,100, 10, 9,101, 46,110, 97,109,101, 32, 61, 32, - 110, 10, 9,105,102, 32,110, 32,126, 61, 32, 34, 34, 32,116, - 104,101,110, 10, 9, 9, 84,121,112,101,100,101,102, 40, 34, - 105,110,116, 32, 34, 46, 46,110, 41, 10, 9,101,110,100, 10, - 32,114,101,116,117,114,110, 32, 95, 69,110,117,109,101,114, - 97,116,101, 40,101, 44, 32,118, 97,114,110, 97,109,101, 41, - 10,101,110,100,32 - }; - tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua embedded: src/bin/lua/enumerate.lua"); + #include "enumerate_lua.h" + tolua_dobuffer(tolua_S,(char*)lua_enumerate_lua,sizeof(lua_enumerate_lua),"tolua embedded: src/bin/lua/enumerate.lua"); lua_settop(tolua_S, top); } /* end of embedded lua code */ @@ -5972,960 +5208,8 @@ TOLUA_API int tolua_tolua_open (lua_State* tolua_S) { /* begin embedded lua code */ int top = lua_gettop(tolua_S); - static unsigned char B[] = { - 45, 45, 32,116,111,108,117, 97, 58, 32,102,117,110, 99,116, - 105,111,110, 32, 99,108, 97,115,115, 10, 45, 45, 32, 87,114, - 105,116,116,101,110, 32, 98,121, 32, 87, 97,108,100,101,109, - 97,114, 32, 67,101,108,101,115, 10, 45, 45, 32, 84,101, 67, - 71,114, 97,102, 47, 80, 85, 67, 45, 82,105,111, 10, 45, 45, - 32, 74,117,108, 32, 49, 57, 57, 56, 10, 45, 45, 32, 36, 73, - 100, 58, 32, 36, 10, 10, 45, 45, 32, 84,104,105,115, 32, 99, - 111,100,101, 32,105,115, 32,102,114,101,101, 32,115,111,102, - 116,119, 97,114,101, 59, 32,121,111,117, 32, 99, 97,110, 32, - 114,101,100,105,115,116,114,105, 98,117,116,101, 32,105,116, - 32, 97,110,100, 47,111,114, 32,109,111,100,105,102,121, 32, - 105,116, 46, 10, 45, 45, 32, 84,104,101, 32,115,111,102,116, - 119, 97,114,101, 32,112,114,111,118,105,100,101,100, 32,104, - 101,114,101,117,110,100,101,114, 32,105,115, 32,111,110, 32, - 97,110, 32, 34, 97,115, 32,105,115, 34, 32, 98, 97,115,105, - 115, 44, 32, 97,110,100, 10, 45, 45, 32,116,104,101, 32, 97, - 117,116,104,111,114, 32,104, 97,115, 32,110,111, 32,111, 98, - 108,105,103, 97,116,105,111,110, 32,116,111, 32,112,114,111, - 118,105,100,101, 32,109, 97,105,110,116,101,110, 97,110, 99, - 101, 44, 32,115,117,112,112,111,114,116, 44, 32,117,112,100, - 97,116,101,115, 44, 10, 45, 45, 32,101,110,104, 97,110, 99, - 101,109,101,110,116,115, 44, 32,111,114, 32,109,111,100,105, - 102,105, 99, 97,116,105,111,110,115, 46, 10, 10, 10, 10, 45, - 45, 32, 70,117,110, 99,116,105,111,110, 32, 99,108, 97,115, - 115, 10, 45, 45, 32, 82,101,112,114,101,115,101,110,116,115, - 32, 97, 32,102,117,110, 99,116,105,111,110, 32,111,114, 32, - 97, 32, 99,108, 97,115,115, 32,109,101,116,104,111,100, 46, - 10, 45, 45, 32, 84,104,101, 32,102,111,108,108,111,119,105, - 110,103, 32,102,105,101,108,100,115, 32, 97,114,101, 32,115, - 116,111,114,101,100, 58, 10, 45, 45, 32, 32,109,111,100, 32, - 32, 61, 32,116,121,112,101, 32,109,111,100,105,102,105,101, - 114,115, 10, 45, 45, 32, 32,116,121,112,101, 32, 61, 32,116, - 121,112,101, 10, 45, 45, 32, 32,112,116,114, 32, 32, 61, 32, - 34, 42, 34, 32,111,114, 32, 34, 38, 34, 44, 32,105,102, 32, - 114,101,112,114,101,115,101,110,116,105,110,103, 32, 97, 32, - 112,111,105,110,116,101,114, 32,111,114, 32, 97, 32,114,101, - 102,101,114,101,110, 99,101, 10, 45, 45, 32, 32,110, 97,109, - 101, 32, 61, 32,110, 97,109,101, 10, 45, 45, 32, 32,108,110, - 97,109,101, 32, 61, 32,108,117, 97, 32,110, 97,109,101, 10, - 45, 45, 32, 32, 97,114,103,115, 32, 32, 61, 32,108,105,115, - 116, 32,111,102, 32, 97,114,103,117,109,101,110,116, 32,100, - 101, 99,108, 97,114, 97,116,105,111,110,115, 10, 45, 45, 32, - 32, 99,111,110,115,116, 32, 61, 32,105,102, 32,105,116, 32, - 105,115, 32, 97, 32,109,101,116,104,111,100, 32,114,101, 99, - 101,105,118,105,110,103, 32, 97, 32, 99,111,110,115,116, 32, - 34,116,104,105,115, 34, 46, 10, 99,108, 97,115,115, 70,117, - 110, 99,116,105,111,110, 32, 61, 32,123, 10, 32,109,111,100, - 32, 61, 32, 39, 39, 44, 10, 32,116,121,112,101, 32, 61, 32, - 39, 39, 44, 10, 32,112,116,114, 32, 61, 32, 39, 39, 44, 10, - 32,110, 97,109,101, 32, 61, 32, 39, 39, 44, 10, 32, 97,114, - 103,115, 32, 61, 32,123,110, 61, 48,125, 44, 10, 32, 99,111, - 110,115,116, 32, 61, 32, 39, 39, 44, 10,125, 10, 99,108, 97, - 115,115, 70,117,110, 99,116,105,111,110, 46, 95, 95,105,110, - 100,101,120, 32, 61, 32, 99,108, 97,115,115, 70,117,110, 99, - 116,105,111,110, 10,115,101,116,109,101,116, 97,116, 97, 98, - 108,101, 40, 99,108, 97,115,115, 70,117,110, 99,116,105,111, - 110, 44, 99,108, 97,115,115, 70,101, 97,116,117,114,101, 41, - 10, 10, 45, 45, 32,100,101, 99,108, 97,114,101, 32,116, 97, - 103,115, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97, - 115,115, 70,117,110, 99,116,105,111,110, 58,100,101, 99,108, - 116,121,112,101, 32, 40, 41, 10, 32,115,101,108,102, 46,116, - 121,112,101, 32, 61, 32,116,121,112,101,118, 97,114, 40,115, - 101,108,102, 46,116,121,112,101, 41, 10, 32,105,102, 32,115, - 116,114,102,105,110,100, 40,115,101,108,102, 46,109,111,100, - 44, 39, 99,111,110,115,116, 39, 41, 32,116,104,101,110, 10, - 9, 32,115,101,108,102, 46,116,121,112,101, 32, 61, 32, 39, - 99,111,110,115,116, 32, 39, 46, 46,115,101,108,102, 46,116, - 121,112,101, 10, 9, 9,115,101,108,102, 46,109,111,100, 32, - 61, 32,103,115,117, 98, 40,115,101,108,102, 46,109,111,100, - 44, 39, 99,111,110,115,116, 39, 44, 39, 39, 41, 10, 9,101, - 110,100, 10, 32,108,111, 99, 97,108, 32,105, 61, 49, 10, 32, - 119,104,105,108,101, 32,115,101,108,102, 46, 97,114,103,115, - 91,105, 93, 32,100,111, 10, 32, 32,115,101,108,102, 46, 97, - 114,103,115, 91,105, 93, 58,100,101, 99,108,116,121,112,101, - 40, 41, 10, 32, 32,105, 32, 61, 32,105, 43, 49, 10, 32,101, - 110,100, 10,101,110,100, 10, 10, 10, 45, 45, 32, 87,114,105, - 116,101, 32, 98,105,110,100,105,110,103, 32,102,117,110, 99, - 116,105,111,110, 10, 45, 45, 32, 79,117,116,112,117,116,115, - 32, 67, 47, 67, 43, 43, 32, 98,105,110,100,105,110,103, 32, - 102,117,110, 99,116,105,111,110, 46, 10,102,117,110, 99,116, - 105,111,110, 32, 99,108, 97,115,115, 70,117,110, 99,116,105, - 111,110, 58,115,117,112, 99,111,100,101, 32, 40,108,111, 99, - 97,108, 95, 99,111,110,115,116,114,117, 99,116,111,114, 41, - 10, 10, 32,108,111, 99, 97,108, 32,111,118,101,114,108,111, - 97,100, 32, 61, 32,115,116,114,115,117, 98, 40,115,101,108, - 102, 46, 99,110, 97,109,101, 44, 45, 50, 44, 45, 49, 41, 32, - 45, 32, 49, 32, 32, 45, 45, 32,105,110,100,105, 99, 97,116, - 101, 32,111,118,101,114,108,111, 97,100,101,100, 32,102,117, - 110, 99, 10, 32,108,111, 99, 97,108, 32,110,114,101,116, 32, - 61, 32, 48, 32, 32, 32, 32, 32, 32, 45, 45, 32,110,117,109, - 98,101,114, 32,111,102, 32,114,101,116,117,114,110,101,100, - 32,118, 97,108,117,101,115, 10, 32,108,111, 99, 97,108, 32, - 99,108, 97,115,115, 32, 61, 32,115,101,108,102, 58,105,110, - 99,108, 97,115,115, 40, 41, 10, 32,108,111, 99, 97,108, 32, - 95, 44, 95, 44,115,116, 97,116,105, 99, 32, 61, 32,115,116, - 114,102,105,110,100, 40,115,101,108,102, 46,109,111,100, 44, - 39, 94, 37,115, 42, 40,115,116, 97,116,105, 99, 41, 39, 41, - 10, 32,105,102, 32, 99,108, 97,115,115, 32,116,104,101,110, - 10, 10, 32, 9,105,102, 32,115,101,108,102, 46,110, 97,109, - 101, 32, 61, 61, 32, 39,110,101,119, 39, 32, 97,110,100, 32, - 115,101,108,102, 46,112, 97,114,101,110,116, 46,102,108, 97, - 103,115, 46,112,117,114,101, 95,118,105,114,116,117, 97,108, - 32,116,104,101,110, 10, 32, 9, 9, 45, 45, 32,110,111, 32, - 99,111,110,115,116,114,117, 99,116,111,114, 32,102,111,114, - 32, 99,108, 97,115,115,101,115, 32,119,105,116,104, 32,112, - 117,114,101, 32,118,105,114,116,117, 97,108, 32,109,101,116, - 104,111,100,115, 10, 32, 9, 9,114,101,116,117,114,110, 10, - 32, 9,101,110,100, 10, 10, 32, 9,105,102, 32,108,111, 99, - 97,108, 95, 99,111,110,115,116,114,117, 99,116,111,114, 32, - 116,104,101,110, 10, 9, 9,111,117,116,112,117,116, 40, 34, - 47, 42, 32,109,101,116,104,111,100, 58, 32,110,101,119, 95, - 108,111, 99, 97,108, 32,111,102, 32, 99,108, 97,115,115, 32, - 34, 44, 99,108, 97,115,115, 44, 34, 32, 42, 47, 34, 41, 10, - 9,101,108,115,101, 10, 9, 9,111,117,116,112,117,116, 40, - 34, 47, 42, 32,109,101,116,104,111,100, 58, 34, 44,115,101, - 108,102, 46,110, 97,109,101, 44, 34, 32,111,102, 32, 99,108, - 97,115,115, 32, 34, 44, 99,108, 97,115,115, 44, 34, 32, 42, - 47, 34, 41, 10, 9,101,110,100, 10, 32,101,108,115,101, 10, - 32, 32,111,117,116,112,117,116, 40, 34, 47, 42, 32,102,117, - 110, 99,116,105,111,110, 58, 34, 44,115,101,108,102, 46,110, - 97,109,101, 44, 34, 32, 42, 47, 34, 41, 10, 32,101,110,100, - 10, 10, 32,105,102, 32,108,111, 99, 97,108, 95, 99,111,110, - 115,116,114,117, 99,116,111,114, 32,116,104,101,110, 10, 32, - 32,111,117,116,112,117,116, 40, 34, 35,105,102,110,100,101, - 102, 32, 84, 79, 76, 85, 65, 95, 68, 73, 83, 65, 66, 76, 69, - 95, 34, 46, 46,115,101,108,102, 46, 99,110, 97,109,101, 46, - 46, 34, 95,108,111, 99, 97,108, 34, 41, 10, 32, 32,111,117, - 116,112,117,116, 40, 34, 92,110,115,116, 97,116,105, 99, 32, - 105,110,116, 34, 44,115,101,108,102, 46, 99,110, 97,109,101, - 46, 46, 34, 95,108,111, 99, 97,108, 34, 44, 34, 40,108,117, - 97, 95, 83,116, 97,116,101, 42, 32,116,111,108,117, 97, 95, - 83, 41, 34, 41, 10, 32,101,108,115,101, 10, 32, 32,111,117, - 116,112,117,116, 40, 34, 35,105,102,110,100,101,102, 32, 84, - 79, 76, 85, 65, 95, 68, 73, 83, 65, 66, 76, 69, 95, 34, 46, - 46,115,101,108,102, 46, 99,110, 97,109,101, 41, 10, 32, 32, - 111,117,116,112,117,116, 40, 34, 92,110,115,116, 97,116,105, - 99, 32,105,110,116, 34, 44,115,101,108,102, 46, 99,110, 97, - 109,101, 44, 34, 40,108,117, 97, 95, 83,116, 97,116,101, 42, - 32,116,111,108,117, 97, 95, 83, 41, 34, 41, 10, 32,101,110, - 100, 10, 32,111,117,116,112,117,116, 40, 34,123, 34, 41, 10, - 10, 32, 45, 45, 32, 99,104,101, 99,107, 32,116,121,112,101, - 115, 10, 9,105,102, 32,111,118,101,114,108,111, 97,100, 32, - 60, 32, 48, 32,116,104,101,110, 10, 9, 32,111,117,116,112, - 117,116, 40, 39, 35,105,102,110,100,101,102, 32, 84, 79, 76, - 85, 65, 95, 82, 69, 76, 69, 65, 83, 69, 92,110, 39, 41, 10, - 9,101,110,100, 10, 9,111,117,116,112,117,116, 40, 39, 32, - 116,111,108,117, 97, 95, 69,114,114,111,114, 32,116,111,108, - 117, 97, 95,101,114,114, 59, 39, 41, 10, 32,111,117,116,112, - 117,116, 40, 39, 32,105,102, 32, 40, 92,110, 39, 41, 10, 32, - 45, 45, 32, 99,104,101, 99,107, 32,115,101,108,102, 10, 32, - 108,111, 99, 97,108, 32,110, 97,114,103, 10, 32,105,102, 32, - 99,108, 97,115,115, 32,116,104,101,110, 32,110, 97,114,103, - 61, 50, 32,101,108,115,101, 32,110, 97,114,103, 61, 49, 32, - 101,110,100, 10, 32,105,102, 32, 99,108, 97,115,115, 32,116, - 104,101,110, 10, 9, 9,108,111, 99, 97,108, 32,102,117,110, - 99, 32, 61, 32,103,101,116, 95,105,115, 95,102,117,110, 99, - 116,105,111,110, 40,115,101,108,102, 46,112, 97,114,101,110, - 116, 46,116,121,112,101, 41, 10, 9, 9,108,111, 99, 97,108, - 32,116,121,112,101, 32, 61, 32,115,101,108,102, 46,112, 97, - 114,101,110,116, 46,116,121,112,101, 10, 9, 9,105,102, 32, - 115,101,108,102, 46,110, 97,109,101, 61, 61, 39,110,101,119, - 39, 32,111,114, 32,115,116, 97,116,105, 99,126, 61,110,105, - 108, 32,116,104,101,110, 10, 9, 9, 9,102,117,110, 99, 32, - 61, 32, 39,116,111,108,117, 97, 95,105,115,117,115,101,114, - 116, 97, 98,108,101, 39, 10, 9, 9, 9,116,121,112,101, 32, - 61, 32,115,101,108,102, 46,112, 97,114,101,110,116, 46,116, - 121,112,101, 10, 9, 9,101,110,100, 10, 9, 9,105,102, 32, - 115,101,108,102, 46, 99,111,110,115,116, 32,126, 61, 32, 39, - 39, 32,116,104,101,110, 10, 9, 9, 9,116,121,112,101, 32, - 61, 32, 34, 99,111,110,115,116, 32, 34, 46, 46,116,121,112, - 101, 10, 9, 9,101,110,100, 10, 9, 9,111,117,116,112,117, - 116, 40, 39, 32, 32, 32, 32, 32, 33, 39, 46, 46,102,117,110, - 99, 46, 46, 39, 40,116,111,108,117, 97, 95, 83, 44, 49, 44, - 34, 39, 46, 46,116,121,112,101, 46, 46, 39, 34, 44, 48, 44, - 38,116,111,108,117, 97, 95,101,114,114, 41, 32,124,124, 92, - 110, 39, 41, 10, 32,101,110,100, 10, 32, 45, 45, 32, 99,104, - 101, 99,107, 32, 97,114,103,115, 10, 32,105,102, 32,115,101, - 108,102, 46, 97,114,103,115, 91, 49, 93, 46,116,121,112,101, - 32,126, 61, 32, 39,118,111,105,100, 39, 32,116,104,101,110, - 10, 32, 32,108,111, 99, 97,108, 32,105, 61, 49, 10, 32, 32, - 119,104,105,108,101, 32,115,101,108,102, 46, 97,114,103,115, - 91,105, 93, 32,100,111, 10, 32, 32, 32,108,111, 99, 97,108, - 32, 98,116,121,112,101, 32, 61, 32,105,115, 98, 97,115,105, - 99, 40,115,101,108,102, 46, 97,114,103,115, 91,105, 93, 46, - 116,121,112,101, 41, 10, 32, 32, 32,105,102, 32, 98,116,121, - 112,101, 32,126, 61, 32, 39,118, 97,108,117,101, 39, 32, 97, - 110,100, 32, 98,116,121,112,101, 32,126, 61, 32, 39,115,116, - 97,116,101, 39, 32,116,104,101,110, 10, 32, 32, 32, 32,111, - 117,116,112,117,116, 40, 39, 32, 32, 32, 32, 32, 39, 46, 46, - 115,101,108,102, 46, 97,114,103,115, 91,105, 93, 58,111,117, - 116, 99,104,101, 99,107,116,121,112,101, 40,110, 97,114,103, - 41, 46, 46, 39, 32,124,124, 92,110, 39, 41, 10, 32, 32, 32, - 101,110,100, 10, 32, 32, 32,105,102, 32, 98,116,121,112,101, - 32,126, 61, 32, 39,115,116, 97,116,101, 39, 32,116,104,101, - 110, 10, 9, 32, 32, 32,110, 97,114,103, 32, 61, 32,110, 97, - 114,103, 43, 49, 10, 32, 32, 32,101,110,100, 10, 32, 32, 32, - 105, 32, 61, 32,105, 43, 49, 10, 32, 32,101,110,100, 10, 32, - 101,110,100, 10, 32, 45, 45, 32, 99,104,101, 99,107, 32,101, - 110,100, 32,111,102, 32,108,105,115,116, 10, 32,111,117,116, - 112,117,116, 40, 39, 32, 32, 32, 32, 32, 33,116,111,108,117, - 97, 95,105,115,110,111,111, 98,106, 40,116,111,108,117, 97, - 95, 83, 44, 39, 46, 46,110, 97,114,103, 46, 46, 39, 44, 38, - 116,111,108,117, 97, 95,101,114,114, 41, 92,110, 32, 41, 39, - 41, 10, 9,111,117,116,112,117,116, 40, 39, 32, 32,103,111, - 116,111, 32,116,111,108,117, 97, 95,108,101,114,114,111,114, - 59, 39, 41, 10, 10, 32,111,117,116,112,117,116, 40, 39, 32, - 101,108,115,101, 92,110, 39, 41, 10, 9,105,102, 32,111,118, - 101,114,108,111, 97,100, 32, 60, 32, 48, 32,116,104,101,110, - 10, 9, 32,111,117,116,112,117,116, 40, 39, 35,101,110,100, - 105,102, 92,110, 39, 41, 10, 9,101,110,100, 10, 9,111,117, - 116,112,117,116, 40, 39, 32,123, 39, 41, 10, 10, 32, 45, 45, - 32,100,101, 99,108, 97,114,101, 32,115,101,108,102, 44, 32, - 105,102, 32,116,104,101, 32, 99, 97,115,101, 10, 32,108,111, - 99, 97,108, 32,110, 97,114,103, 10, 32,105,102, 32, 99,108, - 97,115,115, 32,116,104,101,110, 32,110, 97,114,103, 61, 50, - 32,101,108,115,101, 32,110, 97,114,103, 61, 49, 32,101,110, - 100, 10, 32,105,102, 32, 99,108, 97,115,115, 32, 97,110,100, - 32,115,101,108,102, 46,110, 97,109,101,126, 61, 39,110,101, - 119, 39, 32, 97,110,100, 32,115,116, 97,116,105, 99, 61, 61, - 110,105,108, 32,116,104,101,110, 10, 32, 32,111,117,116,112, - 117,116, 40, 39, 32, 39, 44,115,101,108,102, 46, 99,111,110, - 115,116, 44,115,101,108,102, 46,112, 97,114,101,110,116, 46, - 116,121,112,101, 44, 39, 42, 39, 44, 39,115,101,108,102, 32, - 61, 32, 39, 41, 10, 32, 32,111,117,116,112,117,116, 40, 39, - 40, 39, 44,115,101,108,102, 46, 99,111,110,115,116, 44,115, - 101,108,102, 46,112, 97,114,101,110,116, 46,116,121,112,101, - 44, 39, 42, 41, 32, 39, 41, 10, 32, 32,108,111, 99, 97,108, - 32,116,111, 95,102,117,110, 99, 32, 61, 32,103,101,116, 95, - 116,111, 95,102,117,110, 99,116,105,111,110, 40,115,101,108, - 102, 46,112, 97,114,101,110,116, 46,116,121,112,101, 41, 10, - 32, 32,111,117,116,112,117,116, 40,116,111, 95,102,117,110, - 99, 44, 39, 40,116,111,108,117, 97, 95, 83, 44, 49, 44, 48, - 41, 59, 39, 41, 10, 32,101,108,115,101,105,102, 32,115,116, - 97,116,105, 99, 32,116,104,101,110, 10, 32, 32, 95, 44, 95, - 44,115,101,108,102, 46,109,111,100, 32, 61, 32,115,116,114, - 102,105,110,100, 40,115,101,108,102, 46,109,111,100, 44, 39, - 94, 37,115, 42,115,116, 97,116,105, 99, 37,115, 37,115, 42, - 40, 46, 42, 41, 39, 41, 10, 32,101,110,100, 10, 32, 45, 45, - 32,100,101, 99,108, 97,114,101, 32,112, 97,114, 97,109,101, - 116,101,114,115, 10, 32,105,102, 32,115,101,108,102, 46, 97, - 114,103,115, 91, 49, 93, 46,116,121,112,101, 32,126, 61, 32, - 39,118,111,105,100, 39, 32,116,104,101,110, 10, 32, 32,108, - 111, 99, 97,108, 32,105, 61, 49, 10, 32, 32,119,104,105,108, - 101, 32,115,101,108,102, 46, 97,114,103,115, 91,105, 93, 32, - 100,111, 10, 32, 32, 32,115,101,108,102, 46, 97,114,103,115, - 91,105, 93, 58,100,101, 99,108, 97,114,101, 40,110, 97,114, - 103, 41, 10, 32, 32, 32,105,102, 32,105,115, 98, 97,115,105, - 99, 40,115,101,108,102, 46, 97,114,103,115, 91,105, 93, 46, - 116,121,112,101, 41, 32,126, 61, 32, 34,115,116, 97,116,101, - 34, 32,116,104,101,110, 10, 9, 32, 32, 32,110, 97,114,103, - 32, 61, 32,110, 97,114,103, 43, 49, 10, 32, 32, 32,101,110, - 100, 10, 32, 32, 32,105, 32, 61, 32,105, 43, 49, 10, 32, 32, - 101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32, 99, - 104,101, 99,107, 32,115,101,108,102, 10, 32,105,102, 32, 99, - 108, 97,115,115, 32, 97,110,100, 32,115,101,108,102, 46,110, - 97,109,101,126, 61, 39,110,101,119, 39, 32, 97,110,100, 32, - 115,116, 97,116,105, 99, 61, 61,110,105,108, 32,116,104,101, - 110, 10, 9, 32,111,117,116,112,117,116, 40, 39, 35,105,102, - 110,100,101,102, 32, 84, 79, 76, 85, 65, 95, 82, 69, 76, 69, - 65, 83, 69, 92,110, 39, 41, 10, 9, 32,111,117,116,112,117, - 116, 40, 39, 32, 32,105,102, 32, 40, 33,115,101,108,102, 41, - 32,116,111,108,117, 97, 95,101,114,114,111,114, 40,116,111, - 108,117, 97, 95, 83, 44, 34, 39, 46, 46,111,117,116,112,117, - 116, 95,101,114,114,111,114, 95,104,111,111,107, 40, 34,105, - 110,118, 97,108,105,100, 32, 92, 39,115,101,108,102, 92, 39, - 32,105,110, 32,102,117,110, 99,116,105,111,110, 32, 92, 39, - 37,115, 92, 39, 34, 44, 32,115,101,108,102, 46,110, 97,109, - 101, 41, 46, 46, 39, 34, 44, 32, 78, 85, 76, 76, 41, 59, 39, - 41, 59, 10, 9, 32,111,117,116,112,117,116, 40, 39, 35,101, - 110,100,105,102, 92,110, 39, 41, 10, 32,101,110,100, 10, 10, - 32, 45, 45, 32,103,101,116, 32, 97,114,114, 97,121, 32,101, - 108,101,109,101,110,116, 32,118, 97,108,117,101,115, 10, 32, - 105,102, 32, 99,108, 97,115,115, 32,116,104,101,110, 32,110, - 97,114,103, 61, 50, 32,101,108,115,101, 32,110, 97,114,103, - 61, 49, 32,101,110,100, 10, 32,105,102, 32,115,101,108,102, - 46, 97,114,103,115, 91, 49, 93, 46,116,121,112,101, 32,126, - 61, 32, 39,118,111,105,100, 39, 32,116,104,101,110, 10, 32, - 32,108,111, 99, 97,108, 32,105, 61, 49, 10, 32, 32,119,104, - 105,108,101, 32,115,101,108,102, 46, 97,114,103,115, 91,105, - 93, 32,100,111, 10, 32, 32, 32,115,101,108,102, 46, 97,114, - 103,115, 91,105, 93, 58,103,101,116, 97,114,114, 97,121, 40, - 110, 97,114,103, 41, 10, 32, 32, 32,110, 97,114,103, 32, 61, - 32,110, 97,114,103, 43, 49, 10, 32, 32, 32,105, 32, 61, 32, - 105, 43, 49, 10, 32, 32,101,110,100, 10, 32,101,110,100, 10, - 10, 32,112,114,101, 95, 99, 97,108,108, 95,104,111,111,107, - 40,115,101,108,102, 41, 10, 10, 32,108,111, 99, 97,108, 32, - 111,117,116, 32, 61, 32,115,116,114,105,110,103, 46,102,105, - 110,100, 40,115,101,108,102, 46,109,111,100, 44, 32, 34,116, - 111,108,117, 97, 95,111,117,116,115,105,100,101, 34, 41, 10, - 32, 45, 45, 32, 99, 97,108,108, 32,102,117,110, 99,116,105, - 111,110, 10, 32,105,102, 32, 99,108, 97,115,115, 32, 97,110, - 100, 32,115,101,108,102, 46,110, 97,109,101, 61, 61, 39,100, - 101,108,101,116,101, 39, 32,116,104,101,110, 10, 32, 32,111, - 117,116,112,117,116, 40, 39, 32, 32, 77,116,111,108,117, 97, - 95,100,101,108,101,116,101, 40,115,101,108,102, 41, 59, 39, - 41, 10, 32,101,108,115,101,105,102, 32, 99,108, 97,115,115, - 32, 97,110,100, 32,115,101,108,102, 46,110, 97,109,101, 32, - 61, 61, 32, 39,111,112,101,114, 97,116,111,114, 38, 91, 93, - 39, 32,116,104,101,110, 10, 32, 32,105,102, 32,102,108, 97, - 103,115, 91, 39, 49, 39, 93, 32,116,104,101,110, 32, 45, 45, - 32,102,111,114, 32, 99,111,109,112, 97,116,105, 98,105,108, - 105,116,121, 32,119,105,116,104, 32,116,111,108,117, 97, 53, - 32, 63, 10, 9,111,117,116,112,117,116, 40, 39, 32, 32,115, - 101,108,102, 45, 62,111,112,101,114, 97,116,111,114, 91, 93, - 40, 39, 44,115,101,108,102, 46, 97,114,103,115, 91, 49, 93, - 46,110, 97,109,101, 44, 39, 45, 49, 41, 32, 61, 32, 39, 44, - 115,101,108,102, 46, 97,114,103,115, 91, 50, 93, 46,110, 97, - 109,101, 44, 39, 59, 39, 41, 10, 32, 32,101,108,115,101, 10, - 32, 32, 32, 32,111,117,116,112,117,116, 40, 39, 32, 32,115, - 101,108,102, 45, 62,111,112,101,114, 97,116,111,114, 91, 93, - 40, 39, 44,115,101,108,102, 46, 97,114,103,115, 91, 49, 93, - 46,110, 97,109,101, 44, 39, 41, 32, 61, 32, 39, 44,115,101, - 108,102, 46, 97,114,103,115, 91, 50, 93, 46,110, 97,109,101, - 44, 39, 59, 39, 41, 10, 32, 32,101,110,100, 10, 32,101,108, - 115,101, 10, 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, - 123, 39, 41, 10, 32, 32,105,102, 32,115,101,108,102, 46,116, - 121,112,101, 32,126, 61, 32, 39, 39, 32, 97,110,100, 32,115, - 101,108,102, 46,116,121,112,101, 32,126, 61, 32, 39,118,111, - 105,100, 39, 32,116,104,101,110, 10, 32, 32, 32,111,117,116, - 112,117,116, 40, 39, 32, 32, 39, 44,115,101,108,102, 46,109, - 111,100, 44,115,101,108,102, 46,116,121,112,101, 44,115,101, - 108,102, 46,112,116,114, 44, 39,116,111,108,117, 97, 95,114, - 101,116, 32, 61, 32, 39, 41, 10, 32, 32, 32,111,117,116,112, - 117,116, 40, 39, 40, 39, 44,115,101,108,102, 46,109,111,100, - 44,115,101,108,102, 46,116,121,112,101, 44,115,101,108,102, - 46,112,116,114, 44, 39, 41, 32, 39, 41, 10, 32, 32,101,108, - 115,101, 10, 32, 32, 32,111,117,116,112,117,116, 40, 39, 32, - 32, 39, 41, 10, 32, 32,101,110,100, 10, 32, 32,105,102, 32, - 99,108, 97,115,115, 32, 97,110,100, 32,115,101,108,102, 46, - 110, 97,109,101, 61, 61, 39,110,101,119, 39, 32,116,104,101, - 110, 10, 32, 32, 32,111,117,116,112,117,116, 40, 39, 77,116, - 111,108,117, 97, 95,110,101,119, 40, 40, 39, 44,115,101,108, - 102, 46,116,121,112,101, 44, 39, 41, 40, 39, 41, 10, 32, 32, - 101,108,115,101,105,102, 32, 99,108, 97,115,115, 32, 97,110, - 100, 32,115,116, 97,116,105, 99, 32,116,104,101,110, 10, 9, - 105,102, 32,111,117,116, 32,116,104,101,110, 10, 9, 9,111, - 117,116,112,117,116, 40,115,101,108,102, 46,110, 97,109,101, - 44, 39, 40, 39, 41, 10, 9,101,108,115,101, 10, 9, 9,111, - 117,116,112,117,116, 40, 99,108, 97,115,115, 46, 46, 39, 58, - 58, 39, 46, 46,115,101,108,102, 46,110, 97,109,101, 44, 39, - 40, 39, 41, 10, 9,101,110,100, 10, 32, 32,101,108,115,101, - 105,102, 32, 99,108, 97,115,115, 32,116,104,101,110, 10, 9, - 105,102, 32,111,117,116, 32,116,104,101,110, 10, 9, 9,111, - 117,116,112,117,116, 40,115,101,108,102, 46,110, 97,109,101, - 44, 39, 40, 39, 41, 10, 9,101,108,115,101, 10, 9, 32, 32, - 105,102, 32,115,101,108,102, 46, 99, 97,115,116, 95,111,112, - 101,114, 97,116,111,114, 32,116,104,101,110, 10, 9, 32, 32, - 9, 45, 45,111,117,116,112,117,116, 40, 39,115,116, 97,116, - 105, 99, 95, 99, 97,115,116, 60, 39, 44,115,101,108,102, 46, - 109,111,100, 44,115,101,108,102, 46,116,121,112,101, 44,115, - 101,108,102, 46,112,116,114, 44, 39, 32, 62, 40, 42,115,101, - 108,102, 39, 41, 10, 9, 9,111,117,116,112,117,116, 40, 39, - 115,101,108,102, 45, 62,111,112,101,114, 97,116,111,114, 32, - 39, 44,115,101,108,102, 46,109,111,100, 44,115,101,108,102, - 46,116,121,112,101, 44, 39, 40, 39, 41, 10, 9, 32, 32,101, - 108,115,101, 10, 9, 9,111,117,116,112,117,116, 40, 39,115, - 101,108,102, 45, 62, 39, 46, 46,115,101,108,102, 46,110, 97, - 109,101, 44, 39, 40, 39, 41, 10, 9, 32, 32,101,110,100, 10, - 9,101,110,100, 10, 32, 32,101,108,115,101, 10, 32, 32, 32, - 111,117,116,112,117,116, 40,115,101,108,102, 46,110, 97,109, - 101, 44, 39, 40, 39, 41, 10, 32, 32,101,110,100, 10, 10, 32, - 32,105,102, 32,111,117,116, 32, 97,110,100, 32,110,111,116, - 32,115,116, 97,116,105, 99, 32,116,104,101,110, 10, 32, 32, - 9,111,117,116,112,117,116, 40, 39,115,101,108,102, 39, 41, - 10, 9,105,102, 32,115,101,108,102, 46, 97,114,103,115, 91, - 49, 93, 32, 97,110,100, 32,115,101,108,102, 46, 97,114,103, - 115, 91, 49, 93, 46,110, 97,109,101, 32,126, 61, 32, 39, 39, - 32,116,104,101,110, 10, 9, 9,111,117,116,112,117,116, 40, - 39, 44, 39, 41, 10, 9,101,110,100, 10, 32, 32,101,110,100, - 10, 32, 32, 45, 45, 32,119,114,105,116,101, 32,112, 97,114, - 97,109,101,116,101,114,115, 10, 32, 32,108,111, 99, 97,108, - 32,105, 61, 49, 10, 32, 32,119,104,105,108,101, 32,115,101, - 108,102, 46, 97,114,103,115, 91,105, 93, 32,100,111, 10, 32, - 32, 32,115,101,108,102, 46, 97,114,103,115, 91,105, 93, 58, - 112, 97,115,115,112, 97,114, 40, 41, 10, 32, 32, 32,105, 32, - 61, 32,105, 43, 49, 10, 32, 32, 32,105,102, 32,115,101,108, - 102, 46, 97,114,103,115, 91,105, 93, 32,116,104,101,110, 10, - 32, 32, 32, 32,111,117,116,112,117,116, 40, 39, 44, 39, 41, - 10, 32, 32, 32,101,110,100, 10, 32, 32,101,110,100, 10, 10, - 32, 32,105,102, 32, 99,108, 97,115,115, 32, 97,110,100, 32, - 115,101,108,102, 46,110, 97,109,101, 32, 61, 61, 32, 39,111, - 112,101,114, 97,116,111,114, 91, 93, 39, 32, 97,110,100, 32, - 102,108, 97,103,115, 91, 39, 49, 39, 93, 32,116,104,101,110, - 10, 9,111,117,116,112,117,116, 40, 39, 45, 49, 41, 59, 39, - 41, 10, 32, 32,101,108,115,101, 10, 9,105,102, 32, 99,108, - 97,115,115, 32, 97,110,100, 32,115,101,108,102, 46,110, 97, - 109,101, 61, 61, 39,110,101,119, 39, 32,116,104,101,110, 10, - 9, 9,111,117,116,112,117,116, 40, 39, 41, 41, 59, 39, 41, - 32, 45, 45, 32, 99,108,111,115,101, 32, 77,116,111,108,117, - 97, 95,110,101,119, 40, 10, 9,101,108,115,101, 10, 9, 9, - 111,117,116,112,117,116, 40, 39, 41, 59, 39, 41, 10, 9,101, - 110,100, 10, 32, 32,101,110,100, 10, 10, 32, 32, 45, 45, 32, - 114,101,116,117,114,110, 32,118, 97,108,117,101,115, 10, 32, - 32,105,102, 32,115,101,108,102, 46,116,121,112,101, 32,126, - 61, 32, 39, 39, 32, 97,110,100, 32,115,101,108,102, 46,116, - 121,112,101, 32,126, 61, 32, 39,118,111,105,100, 39, 32,116, - 104,101,110, 10, 32, 32, 32,110,114,101,116, 32, 61, 32,110, - 114,101,116, 32, 43, 32, 49, 10, 32, 32, 32,108,111, 99, 97, - 108, 32,116, 44, 99,116, 32, 61, 32,105,115, 98, 97,115,105, - 99, 40,115,101,108,102, 46,116,121,112,101, 41, 10, 32, 32, - 32,105,102, 32,116, 32, 97,110,100, 32,115,101,108,102, 46, - 110, 97,109,101, 32,126, 61, 32, 34,110,101,119, 34, 32,116, - 104,101,110, 10, 32, 32, 32, 9,105,102, 32,115,101,108,102, - 46, 99, 97,115,116, 95,111,112,101,114, 97,116,111,114, 32, - 97,110,100, 32, 95, 98, 97,115,105, 99, 95,114, 97,119, 95, - 112,117,115,104, 91,116, 93, 32,116,104,101,110, 10, 9, 9, - 111,117,116,112,117,116, 40, 39, 32, 32, 32, 39, 44, 95, 98, - 97,115,105, 99, 95,114, 97,119, 95,112,117,115,104, 91,116, - 93, 44, 39, 40,116,111,108,117, 97, 95, 83, 44, 40, 39, 44, - 99,116, 44, 39, 41,116,111,108,117, 97, 95,114,101,116, 41, - 59, 39, 41, 10, 32, 32, 32, 9,101,108,115,101, 10, 9, 32, - 32, 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32,116, - 111,108,117, 97, 95,112,117,115,104, 39, 46, 46,116, 46, 46, - 39, 40,116,111,108,117, 97, 95, 83, 44, 40, 39, 44, 99,116, - 44, 39, 41,116,111,108,117, 97, 95,114,101,116, 41, 59, 39, - 41, 10, 9,101,110,100, 10, 32, 32, 32,101,108,115,101, 10, - 9,116, 32, 61, 32,115,101,108,102, 46,116,121,112,101, 10, - 9,110,101,119, 95,116, 32, 61, 32,115,116,114,105,110,103, - 46,103,115,117, 98, 40,116, 44, 32, 34, 99,111,110,115,116, - 37,115, 43, 34, 44, 32, 34, 34, 41, 10, 9,108,111, 99, 97, - 108, 32,111,119,110,101,100, 32, 61, 32,102, 97,108,115,101, - 10, 9,105,102, 32,115,116,114,105,110,103, 46,102,105,110, - 100, 40,115,101,108,102, 46,109,111,100, 44, 32, 34,116,111, - 108,117, 97, 95,111,119,110,101,100, 34, 41, 32,116,104,101, - 110, 10, 9, 9,111,119,110,101,100, 32, 61, 32,116,114,117, - 101, 10, 9,101,110,100, 10, 32, 32, 32, 32,108,111, 99, 97, - 108, 32,112,117,115,104, 95,102,117,110, 99, 32, 61, 32,103, - 101,116, 95,112,117,115,104, 95,102,117,110, 99,116,105,111, - 110, 40,116, 41, 10, 32, 32, 32, 32,105,102, 32,115,101,108, - 102, 46,112,116,114, 32, 61, 61, 32, 39, 39, 32,116,104,101, - 110, 10, 32, 32, 32, 32, 32,111,117,116,112,117,116, 40, 39, - 32, 32, 32,123, 39, 41, 10, 32, 32, 32, 32, 32,111,117,116, - 112,117,116, 40, 39, 35,105,102,100,101,102, 32, 95, 95, 99, - 112,108,117,115,112,108,117,115, 92,110, 39, 41, 10, 32, 32, - 32, 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, 32, - 118,111,105,100, 42, 32,116,111,108,117, 97, 95,111, 98,106, - 32, 61, 32, 77,116,111,108,117, 97, 95,110,101,119, 40, 40, - 39, 44,110,101,119, 95,116, 44, 39, 41, 40,116,111,108,117, - 97, 95,114,101,116, 41, 41, 59, 39, 41, 10, 32, 32, 32, 32, - 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, 32, 39, 44, - 112,117,115,104, 95,102,117,110, 99, 44, 39, 40,116,111,108, - 117, 97, 95, 83, 44,116,111,108,117, 97, 95,111, 98,106, 44, - 34, 39, 44,116, 44, 39, 34, 41, 59, 39, 41, 10, 32, 32, 32, - 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, 32,116, - 111,108,117, 97, 95,114,101,103,105,115,116,101,114, 95,103, - 99, 40,116,111,108,117, 97, 95, 83, 44,108,117, 97, 95,103, - 101,116,116,111,112, 40,116,111,108,117, 97, 95, 83, 41, 41, - 59, 39, 41, 10, 32, 32, 32, 32, 32,111,117,116,112,117,116, - 40, 39, 35,101,108,115,101, 92,110, 39, 41, 10, 32, 32, 32, - 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, 32,118, - 111,105,100, 42, 32,116,111,108,117, 97, 95,111, 98,106, 32, - 61, 32,116,111,108,117, 97, 95, 99,111,112,121, 40,116,111, - 108,117, 97, 95, 83, 44, 40,118,111,105,100, 42, 41, 38,116, - 111,108,117, 97, 95,114,101,116, 44,115,105,122,101,111,102, - 40, 39, 44,116, 44, 39, 41, 41, 59, 39, 41, 10, 32, 32, 32, - 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, 32, 39, - 44,112,117,115,104, 95,102,117,110, 99, 44, 39, 40,116,111, - 108,117, 97, 95, 83, 44,116,111,108,117, 97, 95,111, 98,106, - 44, 34, 39, 44,116, 44, 39, 34, 41, 59, 39, 41, 10, 32, 32, - 32, 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, 32, - 116,111,108,117, 97, 95,114,101,103,105,115,116,101,114, 95, - 103, 99, 40,116,111,108,117, 97, 95, 83, 44,108,117, 97, 95, - 103,101,116,116,111,112, 40,116,111,108,117, 97, 95, 83, 41, - 41, 59, 39, 41, 10, 32, 32, 32, 32, 32,111,117,116,112,117, - 116, 40, 39, 35,101,110,100,105,102, 92,110, 39, 41, 10, 32, - 32, 32, 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, - 125, 39, 41, 10, 32, 32, 32, 32,101,108,115,101,105,102, 32, - 115,101,108,102, 46,112,116,114, 32, 61, 61, 32, 39, 38, 39, - 32,116,104,101,110, 10, 32, 32, 32, 32, 32,111,117,116,112, - 117,116, 40, 39, 32, 32, 32, 39, 44,112,117,115,104, 95,102, - 117,110, 99, 44, 39, 40,116,111,108,117, 97, 95, 83, 44, 40, - 118,111,105,100, 42, 41, 38,116,111,108,117, 97, 95,114,101, - 116, 44, 34, 39, 44,116, 44, 39, 34, 41, 59, 39, 41, 10, 32, - 32, 32, 32,101,108,115,101, 10, 9, 32,111,117,116,112,117, - 116, 40, 39, 32, 32, 32, 39, 44,112,117,115,104, 95,102,117, - 110, 99, 44, 39, 40,116,111,108,117, 97, 95, 83, 44, 40,118, - 111,105,100, 42, 41,116,111,108,117, 97, 95,114,101,116, 44, - 34, 39, 44,116, 44, 39, 34, 41, 59, 39, 41, 10, 9, 32,105, - 102, 32,111,119,110,101,100, 32,111,114, 32,108,111, 99, 97, - 108, 95, 99,111,110,115,116,114,117, 99,116,111,114, 32,116, - 104,101,110, 10, 32, 32, 32, 32, 32, 32,111,117,116,112,117, - 116, 40, 39, 32, 32, 32, 32,116,111,108,117, 97, 95,114,101, - 103,105,115,116,101,114, 95,103, 99, 40,116,111,108,117, 97, - 95, 83, 44,108,117, 97, 95,103,101,116,116,111,112, 40,116, - 111,108,117, 97, 95, 83, 41, 41, 59, 39, 41, 10, 9, 32,101, - 110,100, 10, 32, 32, 32, 32,101,110,100, 10, 32, 32, 32,101, - 110,100, 10, 32, 32,101,110,100, 10, 32, 32,108,111, 99, 97, - 108, 32,105, 61, 49, 10, 32, 32,119,104,105,108,101, 32,115, - 101,108,102, 46, 97,114,103,115, 91,105, 93, 32,100,111, 10, - 32, 32, 32,110,114,101,116, 32, 61, 32,110,114,101,116, 32, - 43, 32,115,101,108,102, 46, 97,114,103,115, 91,105, 93, 58, - 114,101,116,118, 97,108,117,101, 40, 41, 10, 32, 32, 32,105, - 32, 61, 32,105, 43, 49, 10, 32, 32,101,110,100, 10, 32, 32, - 111,117,116,112,117,116, 40, 39, 32, 32,125, 39, 41, 10, 10, - 32, 32, 45, 45, 32,115,101,116, 32, 97,114,114, 97,121, 32, - 101,108,101,109,101,110,116, 32,118, 97,108,117,101,115, 10, - 32, 32,105,102, 32, 99,108, 97,115,115, 32,116,104,101,110, - 32,110, 97,114,103, 61, 50, 32,101,108,115,101, 32,110, 97, - 114,103, 61, 49, 32,101,110,100, 10, 32, 32,105,102, 32,115, - 101,108,102, 46, 97,114,103,115, 91, 49, 93, 46,116,121,112, - 101, 32,126, 61, 32, 39,118,111,105,100, 39, 32,116,104,101, - 110, 10, 32, 32, 32,108,111, 99, 97,108, 32,105, 61, 49, 10, - 32, 32, 32,119,104,105,108,101, 32,115,101,108,102, 46, 97, - 114,103,115, 91,105, 93, 32,100,111, 10, 32, 32, 32, 32,115, - 101,108,102, 46, 97,114,103,115, 91,105, 93, 58,115,101,116, - 97,114,114, 97,121, 40,110, 97,114,103, 41, 10, 32, 32, 32, - 32,110, 97,114,103, 32, 61, 32,110, 97,114,103, 43, 49, 10, - 32, 32, 32, 32,105, 32, 61, 32,105, 43, 49, 10, 32, 32, 32, - 101,110,100, 10, 32, 32,101,110,100, 10, 10, 32, 32, 45, 45, - 32,102,114,101,101, 32,100,121,110, 97,109,105, 99, 97,108, - 108,121, 32, 97,108,108,111, 99, 97,116,101,100, 32, 97,114, - 114, 97,121, 10, 32, 32,105,102, 32,115,101,108,102, 46, 97, - 114,103,115, 91, 49, 93, 46,116,121,112,101, 32,126, 61, 32, - 39,118,111,105,100, 39, 32,116,104,101,110, 10, 32, 32, 32, - 108,111, 99, 97,108, 32,105, 61, 49, 10, 32, 32, 32,119,104, - 105,108,101, 32,115,101,108,102, 46, 97,114,103,115, 91,105, - 93, 32,100,111, 10, 32, 32, 32, 32,115,101,108,102, 46, 97, - 114,103,115, 91,105, 93, 58,102,114,101,101, 97,114,114, 97, - 121, 40, 41, 10, 32, 32, 32, 32,105, 32, 61, 32,105, 43, 49, - 10, 32, 32, 32,101,110,100, 10, 32, 32,101,110,100, 10, 32, - 101,110,100, 10, 10, 32,112,111,115,116, 95, 99, 97,108,108, - 95,104,111,111,107, 40,115,101,108,102, 41, 10, 10, 32,111, - 117,116,112,117,116, 40, 39, 32,125, 39, 41, 10, 32,111,117, - 116,112,117,116, 40, 39, 32,114,101,116,117,114,110, 32, 39, - 46, 46,110,114,101,116, 46, 46, 39, 59, 39, 41, 10, 10, 32, - 45, 45, 32, 99, 97,108,108, 32,111,118,101,114,108,111, 97, - 100,101,100, 32,102,117,110, 99,116,105,111,110, 32,111,114, - 32,103,101,110,101,114, 97,116,101, 32,101,114,114,111,114, - 10, 9,105,102, 32,111,118,101,114,108,111, 97,100, 32, 60, - 32, 48, 32,116,104,101,110, 10, 10, 9, 9,111,117,116,112, - 117,116, 40, 39, 35,105,102,110,100,101,102, 32, 84, 79, 76, - 85, 65, 95, 82, 69, 76, 69, 65, 83, 69, 92,110, 39, 41, 10, - 9, 9,111,117,116,112,117,116, 40, 39,116,111,108,117, 97, - 95,108,101,114,114,111,114, 58, 92,110, 39, 41, 10, 9, 9, - 111,117,116,112,117,116, 40, 39, 32,116,111,108,117, 97, 95, - 101,114,114,111,114, 40,116,111,108,117, 97, 95, 83, 44, 34, - 39, 46, 46,111,117,116,112,117,116, 95,101,114,114,111,114, - 95,104,111,111,107, 40, 34, 35,102,101,114,114,111,114, 32, - 105,110, 32,102,117,110, 99,116,105,111,110, 32, 92, 39, 37, - 115, 92, 39, 46, 34, 44, 32,115,101,108,102, 46,108,110, 97, - 109,101, 41, 46, 46, 39, 34, 44, 38,116,111,108,117, 97, 95, - 101,114,114, 41, 59, 39, 41, 10, 9, 9,111,117,116,112,117, - 116, 40, 39, 32,114,101,116,117,114,110, 32, 48, 59, 39, 41, - 10, 9, 9,111,117,116,112,117,116, 40, 39, 35,101,110,100, - 105,102, 92,110, 39, 41, 10, 9,101,108,115,101, 10, 9, 9, - 108,111, 99, 97,108, 32, 95,108,111, 99, 97,108, 32, 61, 32, - 34, 34, 10, 9, 9,105,102, 32,108,111, 99, 97,108, 95, 99, - 111,110,115,116,114,117, 99,116,111,114, 32,116,104,101,110, - 10, 9, 9, 9, 95,108,111, 99, 97,108, 32, 61, 32, 34, 95, - 108,111, 99, 97,108, 34, 10, 9, 9,101,110,100, 10, 9, 9, - 111,117,116,112,117,116, 40, 39,116,111,108,117, 97, 95,108, - 101,114,114,111,114, 58, 92,110, 39, 41, 10, 9, 9,111,117, - 116,112,117,116, 40, 39, 32,114,101,116,117,114,110, 32, 39, - 46, 46,115,116,114,115,117, 98, 40,115,101,108,102, 46, 99, - 110, 97,109,101, 44, 49, 44, 45, 51, 41, 46, 46,102,111,114, - 109, 97,116, 40, 34, 37, 48, 50,100, 34, 44,111,118,101,114, - 108,111, 97,100, 41, 46, 46, 95,108,111, 99, 97,108, 46, 46, - 39, 40,116,111,108,117, 97, 95, 83, 41, 59, 39, 41, 10, 9, - 101,110,100, 10, 32,111,117,116,112,117,116, 40, 39,125, 39, - 41, 10, 32,111,117,116,112,117,116, 40, 39, 35,101,110,100, - 105,102, 32, 47, 47, 35,105,102,110,100,101,102, 32, 84, 79, - 76, 85, 65, 95, 68, 73, 83, 65, 66, 76, 69, 92,110, 39, 41, - 10, 32,111,117,116,112,117,116, 40, 39, 92,110, 39, 41, 10, - 10, 9, 45, 45, 32,114,101, 99,117,114,115,105,118,101, 32, - 99, 97,108,108, 32,116,111, 32,119,114,105,116,101, 32,108, - 111, 99, 97,108, 32, 99,111,110,115,116,114,117, 99,116,111, - 114, 10, 9,105,102, 32, 99,108, 97,115,115, 32, 97,110,100, - 32,115,101,108,102, 46,110, 97,109,101, 61, 61, 39,110,101, - 119, 39, 32, 97,110,100, 32,110,111,116, 32,108,111, 99, 97, - 108, 95, 99,111,110,115,116,114,117, 99,116,111,114, 32,116, - 104,101,110, 10, 10, 9, 9,115,101,108,102, 58,115,117,112, - 99,111,100,101, 40, 49, 41, 10, 9,101,110,100, 10, 10,101, - 110,100, 10, 10, 10, 45, 45, 32,114,101,103,105,115,116,101, - 114, 32,102,117,110, 99,116,105,111,110, 10,102,117,110, 99, - 116,105,111,110, 32, 99,108, 97,115,115, 70,117,110, 99,116, - 105,111,110, 58,114,101,103,105,115,116,101,114, 32, 40,112, - 114,101, 41, 10, 10, 9,105,102, 32,110,111,116, 32,115,101, - 108,102, 58, 99,104,101, 99,107, 95,112,117, 98,108,105, 99, - 95, 97, 99, 99,101,115,115, 40, 41, 32,116,104,101,110, 10, - 9, 9,114,101,116,117,114,110, 10, 9,101,110,100, 10, 10, - 32, 9,105,102, 32,115,101,108,102, 46,110, 97,109,101, 32, - 61, 61, 32, 39,110,101,119, 39, 32, 97,110,100, 32,115,101, - 108,102, 46,112, 97,114,101,110,116, 46,102,108, 97,103,115, - 46,112,117,114,101, 95,118,105,114,116,117, 97,108, 32,116, - 104,101,110, 10, 32, 9, 9, 45, 45, 32,110,111, 32, 99,111, - 110,115,116,114,117, 99,116,111,114, 32,102,111,114, 32, 99, - 108, 97,115,115,101,115, 32,119,105,116,104, 32,112,117,114, - 101, 32,118,105,114,116,117, 97,108, 32,109,101,116,104,111, - 100,115, 10, 32, 9, 9,114,101,116,117,114,110, 10, 32, 9, - 101,110,100, 10, 10, 32,111,117,116,112,117,116, 40,112,114, - 101, 46, 46, 39,116,111,108,117, 97, 95,102,117,110, 99,116, - 105,111,110, 40,116,111,108,117, 97, 95, 83, 44, 34, 39, 46, - 46,115,101,108,102, 46,108,110, 97,109,101, 46, 46, 39, 34, - 44, 39, 46, 46,115,101,108,102, 46, 99,110, 97,109,101, 46, - 46, 39, 41, 59, 39, 41, 10, 32, 32,105,102, 32,115,101,108, - 102, 46,110, 97,109,101, 32, 61, 61, 32, 39,110,101,119, 39, - 32,116,104,101,110, 10, 9, 32, 32,111,117,116,112,117,116, - 40,112,114,101, 46, 46, 39,116,111,108,117, 97, 95,102,117, - 110, 99,116,105,111,110, 40,116,111,108,117, 97, 95, 83, 44, - 34,110,101,119, 95,108,111, 99, 97,108, 34, 44, 39, 46, 46, - 115,101,108,102, 46, 99,110, 97,109,101, 46, 46, 39, 95,108, - 111, 99, 97,108, 41, 59, 39, 41, 10, 9, 32, 32,111,117,116, - 112,117,116, 40,112,114,101, 46, 46, 39,116,111,108,117, 97, - 95,102,117,110, 99,116,105,111,110, 40,116,111,108,117, 97, - 95, 83, 44, 34, 46, 99, 97,108,108, 34, 44, 39, 46, 46,115, - 101,108,102, 46, 99,110, 97,109,101, 46, 46, 39, 95,108,111, - 99, 97,108, 41, 59, 39, 41, 10, 9, 32, 32, 45, 45,111,117, - 116,112,117,116, 40, 39, 32,116,111,108,117, 97, 95,115,101, - 116, 95, 99, 97,108,108, 95,101,118,101,110,116, 40,116,111, - 108,117, 97, 95, 83, 44, 39, 46, 46,115,101,108,102, 46, 99, - 110, 97,109,101, 46, 46, 39, 95,108,111, 99, 97,108, 44, 32, - 34, 39, 46, 46,115,101,108,102, 46,112, 97,114,101,110,116, - 46,116,121,112,101, 46, 46, 39, 34, 41, 59, 39, 41, 10, 32, - 32,101,110,100, 10,101,110,100, 10, 10, 45, 45, 32, 80,114, - 105,110,116, 32,109,101,116,104,111,100, 10,102,117,110, 99, - 116,105,111,110, 32, 99,108, 97,115,115, 70,117,110, 99,116, - 105,111,110, 58,112,114,105,110,116, 32, 40,105,100,101,110, - 116, 44, 99,108,111,115,101, 41, 10, 32,112,114,105,110,116, - 40,105,100,101,110,116, 46, 46, 34, 70,117,110, 99,116,105, - 111,110,123, 34, 41, 10, 32,112,114,105,110,116, 40,105,100, - 101,110,116, 46, 46, 34, 32,109,111,100, 32, 32, 61, 32, 39, - 34, 46, 46,115,101,108,102, 46,109,111,100, 46, 46, 34, 39, - 44, 34, 41, 10, 32,112,114,105,110,116, 40,105,100,101,110, - 116, 46, 46, 34, 32,116,121,112,101, 32, 61, 32, 39, 34, 46, - 46,115,101,108,102, 46,116,121,112,101, 46, 46, 34, 39, 44, - 34, 41, 10, 32,112,114,105,110,116, 40,105,100,101,110,116, - 46, 46, 34, 32,112,116,114, 32, 32, 61, 32, 39, 34, 46, 46, - 115,101,108,102, 46,112,116,114, 46, 46, 34, 39, 44, 34, 41, - 10, 32,112,114,105,110,116, 40,105,100,101,110,116, 46, 46, - 34, 32,110, 97,109,101, 32, 61, 32, 39, 34, 46, 46,115,101, - 108,102, 46,110, 97,109,101, 46, 46, 34, 39, 44, 34, 41, 10, - 32,112,114,105,110,116, 40,105,100,101,110,116, 46, 46, 34, - 32,108,110, 97,109,101, 32, 61, 32, 39, 34, 46, 46,115,101, - 108,102, 46,108,110, 97,109,101, 46, 46, 34, 39, 44, 34, 41, - 10, 32,112,114,105,110,116, 40,105,100,101,110,116, 46, 46, - 34, 32, 99,111,110,115,116, 32, 61, 32, 39, 34, 46, 46,115, - 101,108,102, 46, 99,111,110,115,116, 46, 46, 34, 39, 44, 34, - 41, 10, 32,112,114,105,110,116, 40,105,100,101,110,116, 46, - 46, 34, 32, 99,110, 97,109,101, 32, 61, 32, 39, 34, 46, 46, - 115,101,108,102, 46, 99,110, 97,109,101, 46, 46, 34, 39, 44, - 34, 41, 10, 32,112,114,105,110,116, 40,105,100,101,110,116, - 46, 46, 34, 32,108,110, 97,109,101, 32, 61, 32, 39, 34, 46, - 46,115,101,108,102, 46,108,110, 97,109,101, 46, 46, 34, 39, - 44, 34, 41, 10, 32,112,114,105,110,116, 40,105,100,101,110, - 116, 46, 46, 34, 32, 97,114,103,115, 32, 61, 32,123, 34, 41, - 10, 32,108,111, 99, 97,108, 32,105, 61, 49, 10, 32,119,104, - 105,108,101, 32,115,101,108,102, 46, 97,114,103,115, 91,105, - 93, 32,100,111, 10, 32, 32,115,101,108,102, 46, 97,114,103, - 115, 91,105, 93, 58,112,114,105,110,116, 40,105,100,101,110, - 116, 46, 46, 34, 32, 32, 34, 44, 34, 44, 34, 41, 10, 32, 32, - 105, 32, 61, 32,105, 43, 49, 10, 32,101,110,100, 10, 32,112, - 114,105,110,116, 40,105,100,101,110,116, 46, 46, 34, 32,125, - 34, 41, 10, 32,112,114,105,110,116, 40,105,100,101,110,116, - 46, 46, 34,125, 34, 46, 46, 99,108,111,115,101, 41, 10,101, - 110,100, 10, 10, 45, 45, 32, 99,104,101, 99,107, 32,105,102, - 32,105,116, 32,114,101,116,117,114,110,115, 32, 97,110, 32, - 111, 98,106,101, 99,116, 32, 98,121, 32,118, 97,108,117,101, - 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, - 70,117,110, 99,116,105,111,110, 58,114,101,113,117,105,114, - 101, 99,111,108,108,101, 99,116,105,111,110, 32, 40,116, 41, - 10, 9,108,111, 99, 97,108, 32,114, 32, 61, 32,102, 97,108, - 115,101, 10, 9,105,102, 32,115,101,108,102, 46,116,121,112, - 101, 32,126, 61, 32, 39, 39, 32, 97,110,100, 32,110,111,116, - 32,105,115, 98, 97,115,105, 99, 40,115,101,108,102, 46,116, - 121,112,101, 41, 32, 97,110,100, 32,115,101,108,102, 46,112, - 116,114, 61, 61, 39, 39, 32,116,104,101,110, 10, 9, 9,108, - 111, 99, 97,108, 32,116,121,112,101, 32, 61, 32,103,115,117, - 98, 40,115,101,108,102, 46,116,121,112,101, 44, 34, 37,115, - 42, 99,111,110,115,116, 37,115, 43, 34, 44, 34, 34, 41, 10, - 9, 32,116, 91,116,121,112,101, 93, 32, 61, 32, 34,116,111, - 108,117, 97, 95, 99,111,108,108,101, 99,116, 95, 34, 32, 46, - 46, 32, 99,108,101, 97,110, 95,116,101,109,112,108, 97,116, - 101, 40,116,121,112,101, 41, 10, 9, 32,114, 32, 61, 32,116, - 114,117,101, 10, 9,101,110,100, 10, 9,108,111, 99, 97,108, - 32,105, 61, 49, 10, 9,119,104,105,108,101, 32,115,101,108, - 102, 46, 97,114,103,115, 91,105, 93, 32,100,111, 10, 9, 9, - 114, 32, 61, 32,115,101,108,102, 46, 97,114,103,115, 91,105, - 93, 58,114,101,113,117,105,114,101, 99,111,108,108,101, 99, - 116,105,111,110, 40,116, 41, 32,111,114, 32,114, 10, 9, 9, - 105, 32, 61, 32,105, 43, 49, 10, 9,101,110,100, 10, 9,114, - 101,116,117,114,110, 32,114, 10,101,110,100, 10, 10, 45, 45, - 32,100,101,116,101,114,109,105,110,101, 32,108,117, 97, 32, - 102,117,110, 99,116,105,111,110, 32,110, 97,109,101, 32,111, - 118,101,114,108,111, 97,100, 10,102,117,110, 99,116,105,111, - 110, 32, 99,108, 97,115,115, 70,117,110, 99,116,105,111,110, - 58,111,118,101,114,108,111, 97,100, 32, 40, 41, 10, 32,114, - 101,116,117,114,110, 32,115,101,108,102, 46,112, 97,114,101, - 110,116, 58,111,118,101,114,108,111, 97,100, 40,115,101,108, - 102, 46,108,110, 97,109,101, 41, 10,101,110,100, 10, 10, 10, - 102,117,110, 99,116,105,111,110, 32,112, 97,114, 97,109, 95, - 111, 98,106,101, 99,116, 40,112, 97,114, 41, 32, 45, 45, 32, - 114,101,116,117,114,110,115, 32,116,114,117,101, 32,105,102, - 32,116,104,101, 32,112, 97,114, 97,109,101,116,101,114, 32, - 104, 97,115, 32, 97,110, 32,111, 98,106,101, 99,116, 32, 97, - 115, 32,105,116,115, 32,100,101,102, 97,117,108,116, 32,118, - 97,108,117,101, 10, 10, 9,105,102, 32,110,111,116, 32,115, - 116,114,105,110,103, 46,102,105,110,100, 40,112, 97,114, 44, - 32, 39, 61, 39, 41, 32,116,104,101,110, 32,114,101,116,117, - 114,110, 32,102, 97,108,115,101, 32,101,110,100, 32, 45, 45, - 32,105,116, 32,104, 97,115, 32,110,111, 32,100,101,102, 97, - 117,108,116, 32,118, 97,108,117,101, 10, 10, 9,108,111, 99, - 97,108, 32, 95, 44, 95, 44,100,101,102, 32, 61, 32,115,116, - 114,105,110,103, 46,102,105,110,100, 40,112, 97,114, 44, 32, - 34, 61, 40, 46, 42, 41, 36, 34, 41, 10, 10, 9,105,102, 32, - 115,116,114,105,110,103, 46,102,105,110,100, 40,112, 97,114, - 44, 32, 34,124, 34, 41, 32,116,104,101,110, 32, 45, 45, 32, - 97, 32,108,105,115,116, 32,111,102, 32,102,108, 97,103,115, - 10, 10, 9, 9,114,101,116,117,114,110, 32,116,114,117,101, - 10, 9,101,110,100, 10, 10, 9,105,102, 32,115,116,114,105, - 110,103, 46,102,105,110,100, 40,112, 97,114, 44, 32, 34, 37, - 42, 34, 41, 32,116,104,101,110, 32, 45, 45, 32,105,116, 39, - 115, 32, 97, 32,112,111,105,110,116,101,114, 32,119,105,116, - 104, 32, 97, 32,100,101,102, 97,117,108,116, 32,118, 97,108, - 117,101, 10, 10, 9, 9,105,102, 32,115,116,114,105,110,103, - 46,102,105,110,100, 40,112, 97,114, 44, 32, 39, 61, 37,115, - 42,110,101,119, 39, 41, 32,111,114, 32,115,116,114,105,110, - 103, 46,102,105,110,100, 40,112, 97,114, 44, 32, 34, 37, 40, - 34, 41, 32,116,104,101,110, 32, 45, 45, 32,105,116, 39,115, - 32, 97, 32,112,111,105,110,116,101,114, 32,119,105,116,104, - 32, 97,110, 32,105,110,115,116, 97,110, 99,101, 32, 97,115, - 32,100,101,102, 97,117,108,116, 32,112, 97,114, 97,109,101, - 116,101,114, 46, 46, 32,105,115, 32,116,104, 97,116, 32,118, - 97,108,105,100, 63, 10, 9, 9, 9,114,101,116,117,114,110, - 32,116,114,117,101, 10, 9, 9,101,110,100, 10, 9, 9,114, - 101,116,117,114,110, 32,102, 97,108,115,101, 32, 45, 45, 32, - 100,101,102, 97,117,108,116, 32,118, 97,108,117,101, 32,105, - 115, 32, 39, 78, 85, 76, 76, 39, 32,111,114, 32,115,111,109, - 101,116,104,105,110,103, 10, 9,101,110,100, 10, 10, 10, 9, - 105,102, 32,115,116,114,105,110,103, 46,102,105,110,100, 40, - 112, 97,114, 44, 32, 34, 91, 37, 40, 38, 93, 34, 41, 32,116, - 104,101,110, 10, 9, 9,114,101,116,117,114,110, 32,116,114, - 117,101, 10, 9,101,110,100, 32, 45, 45, 32,100,101,102, 97, - 117,108,116, 32,118, 97,108,117,101, 32,105,115, 32, 97, 32, - 99,111,110,115,116,114,117, 99,116,111,114, 32, 99, 97,108, - 108, 32, 40,109,111,115,116, 32,108,105,107,101,108,121, 32, - 102,111,114, 32, 97, 32, 99,111,110,115,116, 32,114,101,102, - 101,114,101,110, 99,101, 41, 10, 10, 9, 45, 45,105,102, 32, - 115,116,114,105,110,103, 46,102,105,110,100, 40,112, 97,114, - 44, 32, 34, 38, 34, 41, 32,116,104,101,110, 10, 10, 9, 45, - 45, 9,105,102, 32,115,116,114,105,110,103, 46,102,105,110, - 100, 40,100,101,102, 44, 32, 34, 58, 34, 41, 32,111,114, 32, - 115,116,114,105,110,103, 46,102,105,110,100, 40,100,101,102, - 44, 32, 34, 94, 37,115, 42,110,101,119, 37,115, 43, 34, 41, - 32,116,104,101,110, 10, 10, 9, 45, 45, 9, 9, 45, 45, 32, - 105,116, 39,115, 32, 97, 32,114,101,102,101,114,101,110, 99, - 101, 32,119,105,116,104, 32,100,101,102, 97,117,108,116, 32, - 116,111, 32,115,111,109,101,116,104,105,110,103, 32,108,105, - 107,101, 32, 67,108, 97,115,115, 58, 58,109,101,109, 98,101, - 114, 44, 32,111,114, 32, 39,110,101,119, 32, 67,108, 97,115, - 115, 39, 10, 9, 45, 45, 9, 9,114,101,116,117,114,110, 32, - 116,114,117,101, 10, 9, 45, 45, 9,101,110,100, 10, 9, 45, - 45,101,110,100, 10, 10, 9,114,101,116,117,114,110, 32,102, - 97,108,115,101, 32, 45, 45, 32, 63, 10,101,110,100, 10, 10, - 102,117,110, 99,116,105,111,110, 32,115,116,114,105,112, 95, - 108, 97,115,116, 95, 97,114,103, 40, 97,108,108, 95, 97,114, - 103,115, 44, 32,108, 97,115,116, 95, 97,114,103, 41, 32, 45, - 45, 32,115,116,114,105,112,115, 32,116,104,101, 32,100,101, - 102, 97,117,108,116, 32,118, 97,108,117,101, 32,102,114,111, - 109, 32,116,104,101, 32,108, 97,115,116, 32, 97,114,103,117, - 109,101,110,116, 10, 10, 9,108,111, 99, 97,108, 32, 95, 44, - 95, 44,115, 95, 97,114,103, 32, 61, 32,115,116,114,105,110, - 103, 46,102,105,110,100, 40,108, 97,115,116, 95, 97,114,103, - 44, 32, 34, 94, 40, 91, 94, 61, 93, 43, 41, 34, 41, 10, 9, - 108, 97,115,116, 95, 97,114,103, 32, 61, 32,115,116,114,105, - 110,103, 46,103,115,117, 98, 40,108, 97,115,116, 95, 97,114, - 103, 44, 32, 34, 40, 91, 37, 37, 37, 40, 37, 41, 93, 41, 34, - 44, 32, 34, 37, 37, 37, 49, 34, 41, 59, 10, 9, 97,108,108, - 95, 97,114,103,115, 32, 61, 32,115,116,114,105,110,103, 46, - 103,115,117, 98, 40, 97,108,108, 95, 97,114,103,115, 44, 32, - 34, 37,115, 42, 44, 37,115, 42, 34, 46, 46,108, 97,115,116, - 95, 97,114,103, 46, 46, 34, 37,115, 42, 37, 41, 37,115, 42, - 36, 34, 44, 32, 34, 41, 34, 41, 10, 9,114,101,116,117,114, - 110, 32, 97,108,108, 95, 97,114,103,115, 44, 32,115, 95, 97, - 114,103, 10,101,110,100, 10, 10, 10, 10, 45, 45, 32, 73,110, - 116,101,114,110, 97,108, 32, 99,111,110,115,116,114,117, 99, - 116,111,114, 10,102,117,110, 99,116,105,111,110, 32, 95, 70, - 117,110, 99,116,105,111,110, 32, 40,116, 41, 10, 32,115,101, - 116,109,101,116, 97,116, 97, 98,108,101, 40,116, 44, 99,108, - 97,115,115, 70,117,110, 99,116,105,111,110, 41, 10, 10, 32, - 105,102, 32,116, 46, 99,111,110,115,116, 32,126, 61, 32, 39, - 99,111,110,115,116, 39, 32, 97,110,100, 32,116, 46, 99,111, - 110,115,116, 32,126, 61, 32, 39, 39, 32,116,104,101,110, 10, - 32, 32,101,114,114,111,114, 40, 34, 35,105,110,118, 97,108, - 105,100, 32, 39, 99,111,110,115,116, 39, 32,115,112,101, 99, - 105,102,105, 99, 97,116,105,111,110, 34, 41, 10, 32,101,110, - 100, 10, 10, 32, 97,112,112,101,110,100, 40,116, 41, 10, 32, - 105,102, 32,116, 58,105,110, 99,108, 97,115,115, 40, 41, 32, - 116,104,101,110, 10, 32, 45, 45,112,114,105,110,116, 32, 40, - 39,116, 46,110, 97,109,101, 32,105,115, 32, 39, 46, 46,116, - 46,110, 97,109,101, 46, 46, 39, 44, 32,112, 97,114,101,110, - 116, 46,110, 97,109,101, 32,105,115, 32, 39, 46, 46,116, 46, - 112, 97,114,101,110,116, 46,110, 97,109,101, 41, 10, 32, 32, - 105,102, 32,115,116,114,105,110,103, 46,103,115,117, 98, 40, - 116, 46,110, 97,109,101, 44, 32, 34, 37, 98, 60, 62, 34, 44, - 32, 34, 34, 41, 32, 61, 61, 32,115,116,114,105,110,103, 46, - 103,115,117, 98, 40,116, 46,112, 97,114,101,110,116, 46,111, - 114,105,103,105,110, 97,108, 95,110, 97,109,101, 32,111,114, - 32,116, 46,112, 97,114,101,110,116, 46,110, 97,109,101, 44, - 32, 34, 37, 98, 60, 62, 34, 44, 32, 34, 34, 41, 32,116,104, - 101,110, 10, 32, 32, 32,116, 46,110, 97,109,101, 32, 61, 32, - 39,110,101,119, 39, 10, 32, 32, 32,116, 46,108,110, 97,109, - 101, 32, 61, 32, 39,110,101,119, 39, 10, 32, 32, 32,116, 46, - 112, 97,114,101,110,116, 46, 95,110,101,119, 32, 61, 32,116, - 114,117,101, 10, 32, 32, 32,116, 46,116,121,112,101, 32, 61, - 32,116, 46,112, 97,114,101,110,116, 46,110, 97,109,101, 10, - 32, 32, 32,116, 46,112,116,114, 32, 61, 32, 39, 42, 39, 10, - 32, 32,101,108,115,101,105,102, 32,115,116,114,105,110,103, - 46,103,115,117, 98, 40,116, 46,110, 97,109,101, 44, 32, 34, - 37, 98, 60, 62, 34, 44, 32, 34, 34, 41, 32, 61, 61, 32, 39, - 126, 39, 46, 46,115,116,114,105,110,103, 46,103,115,117, 98, - 40,116, 46,112, 97,114,101,110,116, 46,111,114,105,103,105, - 110, 97,108, 95,110, 97,109,101, 32,111,114, 32,116, 46,112, - 97,114,101,110,116, 46,110, 97,109,101, 44, 32, 34, 37, 98, - 60, 62, 34, 44, 32, 34, 34, 41, 32,116,104,101,110, 10, 32, - 32, 32,116, 46,110, 97,109,101, 32, 61, 32, 39,100,101,108, - 101,116,101, 39, 10, 32, 32, 32,116, 46,108,110, 97,109,101, - 32, 61, 32, 39,100,101,108,101,116,101, 39, 10, 32, 32, 32, - 116, 46,112, 97,114,101,110,116, 46, 95,100,101,108,101,116, - 101, 32, 61, 32,116,114,117,101, 10, 32, 32,101,110,100, 10, - 32,101,110,100, 10, 32,116, 46, 99,110, 97,109,101, 32, 61, - 32,116, 58, 99,102,117,110, 99,110, 97,109,101, 40, 34,116, - 111,108,117, 97, 34, 41, 46, 46,116, 58,111,118,101,114,108, - 111, 97,100, 40,116, 41, 10, 32,114,101,116,117,114,110, 32, - 116, 10,101,110,100, 10, 10, 45, 45, 32, 67,111,110,115,116, - 114,117, 99,116,111,114, 10, 45, 45, 32, 69,120,112,101, 99, - 116,115, 32,116,104,114,101,101, 32,115,116,114,105,110,103, - 115, 58, 32,111,110,101, 32,114,101,112,114,101,115,101,110, - 116,105,110,103, 32,116,104,101, 32,102,117,110, 99,116,105, - 111,110, 32,100,101, 99,108, 97,114, 97,116,105,111,110, 44, - 10, 45, 45, 32, 97,110,111,116,104,101,114, 32,114,101,112, - 114,101,115,101,110,116,105,110,103, 32,116,104,101, 32, 97, - 114,103,117,109,101,110,116, 32,108,105,115,116, 44, 32, 97, - 110,100, 32,116,104,101, 32,116,104,105,114,100, 32,114,101, - 112,114,101,115,101,110,116,105,110,103, 10, 45, 45, 32,116, - 104,101, 32, 34, 99,111,110,115,116, 34, 32,111,114, 32,101, - 109,112,116,121, 32,115,116,114,105,110,103, 46, 10,102,117, - 110, 99,116,105,111,110, 32, 70,117,110, 99,116,105,111,110, - 32, 40,100, 44, 97, 44, 99, 41, 10, 32, 45, 45,108,111, 99, - 97,108, 32,116, 32, 61, 32,115,112,108,105,116, 40,115,116, - 114,115,117, 98, 40, 97, 44, 50, 44, 45, 50, 41, 44, 39, 44, - 39, 41, 32, 45, 45, 32,101,108,105,109,105,110, 97,116,101, - 32, 98,114, 97, 99,101,115, 10, 32, 45, 45,108,111, 99, 97, - 108, 32,116, 32, 61, 32,115,112,108,105,116, 95,112, 97,114, - 97,109,115, 40,115,116,114,115,117, 98, 40, 97, 44, 50, 44, - 45, 50, 41, 41, 10, 10, 9,105,102, 32,110,111,116, 32,102, - 108, 97,103,115, 91, 39, 87, 39, 93, 32, 97,110,100, 32,115, - 116,114,105,110,103, 46,102,105,110,100, 40, 97, 44, 32, 34, - 37, 46, 37, 46, 37, 46, 37,115, 42, 37, 41, 34, 41, 32,116, - 104,101,110, 10, 10, 9, 9,119, 97,114,110,105,110,103, 40, - 34, 70,117,110, 99,116,105,111,110,115, 32,119,105,116,104, - 32,118, 97,114,105, 97, 98,108,101, 32, 97,114,103,117,109, - 101,110,116,115, 32, 40, 96, 46, 46, 46, 39, 41, 32, 97,114, - 101, 32,110,111,116, 32,115,117,112,112,111,114,116,101,100, - 46, 32, 73,103,110,111,114,105,110,103, 32, 34, 46, 46,100, - 46, 46, 97, 46, 46, 99, 41, 10, 9, 9,114,101,116,117,114, - 110, 32,110,105,108, 10, 9,101,110,100, 10, 10, 10, 32,108, - 111, 99, 97,108, 32,105, 61, 49, 10, 32,108,111, 99, 97,108, - 32,108, 32, 61, 32,123,110, 61, 48,125, 10, 10, 32, 9, 97, - 32, 61, 32,115,116,114,105,110,103, 46,103,115,117, 98, 40, - 97, 44, 32, 34, 37,115, 42, 40, 91, 37, 40, 37, 41, 93, 41, - 37,115, 42, 34, 44, 32, 34, 37, 49, 34, 41, 10, 9,108,111, - 99, 97,108, 32,116, 44,115,116,114,105,112, 44,108, 97,115, - 116, 32, 61, 32,115,116,114,105,112, 95,112, 97,114,115, 40, - 115,116,114,115,117, 98, 40, 97, 44, 50, 44, 45, 50, 41, 41, - 59, 10, 9,105,102, 32,115,116,114,105,112, 32,116,104,101, - 110, 10, 9, 9, 45, 45,108,111, 99, 97,108, 32,110,115, 32, - 61, 32,115,116,114,105,110,103, 46,115,117, 98, 40,115,116, - 114,115,117, 98, 40, 97, 44, 49, 44, 45, 50, 41, 44, 32, 49, - 44, 32, 45, 40,115,116,114,105,110,103, 46,108,101,110, 40, - 108, 97,115,116, 41, 43, 49, 41, 41, 10, 9, 9,108,111, 99, - 97,108, 32,110,115, 32, 61, 32,106,111,105,110, 40,116, 44, - 32, 34, 44, 34, 44, 32, 49, 44, 32,108, 97,115,116, 45, 49, - 41, 10, 10, 9, 9,110,115, 32, 61, 32, 34, 40, 34, 46, 46, - 115,116,114,105,110,103, 46,103,115,117, 98, 40,110,115, 44, - 32, 34, 37,115, 42, 44, 37,115, 42, 36, 34, 44, 32, 34, 34, - 41, 46, 46, 39, 41, 39, 10, 9, 9, 45, 45,110,115, 32, 61, - 32,115,116,114,105,112, 95,100,101,102, 97,117,108,116,115, - 40,110,115, 41, 10, 10, 9, 9,108,111, 99, 97,108, 32,102, - 32, 61, 32, 70,117,110, 99,116,105,111,110, 40,100, 44, 32, - 110,115, 44, 32, 99, 41, 10, 9, 9,102,111,114, 32,105, 61, - 49, 44,108, 97,115,116, 32,100,111, 10, 9, 9, 9,116, 91, - 105, 93, 32, 61, 32,115,116,114,105,110,103, 46,103,115,117, - 98, 40,116, 91,105, 93, 44, 32, 34, 61, 46, 42, 36, 34, 44, - 32, 34, 34, 41, 10, 9, 9,101,110,100, 10, 9,101,110,100, - 10, 10, 32,119,104,105,108,101, 32,116, 91,105, 93, 32,100, - 111, 10, 32, 32,108, 46,110, 32, 61, 32,108, 46,110, 43, 49, - 10, 32, 32,108, 91,108, 46,110, 93, 32, 61, 32, 68,101, 99, - 108, 97,114, 97,116,105,111,110, 40,116, 91,105, 93, 44, 39, - 118, 97,114, 39, 44,116,114,117,101, 41, 10, 32, 32,105, 32, - 61, 32,105, 43, 49, 10, 32,101,110,100, 10, 32,108,111, 99, - 97,108, 32,102, 32, 61, 32, 68,101, 99,108, 97,114, 97,116, - 105,111,110, 40,100, 44, 39,102,117,110, 99, 39, 41, 10, 32, - 102, 46, 97,114,103,115, 32, 61, 32,108, 10, 32,102, 46, 99, - 111,110,115,116, 32, 61, 32, 99, 10, 32,114,101,116,117,114, - 110, 32, 95, 70,117,110, 99,116,105,111,110, 40,102, 41, 10, - 101,110,100, 10, 10,102,117,110, 99,116,105,111,110, 32,106, - 111,105,110, 40,116, 44, 32,115,101,112, 44, 32,102,105,114, - 115,116, 44, 32,108, 97,115,116, 41, 10, 10, 9,102,105,114, - 115,116, 32, 61, 32,102,105,114,115,116, 32,111,114, 32, 49, - 10, 9,108, 97,115,116, 32, 61, 32,108, 97,115,116, 32,111, - 114, 32,116, 97, 98,108,101, 46,103,101,116,110, 40,116, 41, - 10, 9,108,111, 99, 97,108, 32,108,115,101,112, 32, 61, 32, - 34, 34, 10, 9,108,111, 99, 97,108, 32,114,101,116, 32, 61, - 32, 34, 34, 10, 9,108,111, 99, 97,108, 32,108,111,111,112, - 32, 61, 32,102, 97,108,115,101, 10, 9,102,111,114, 32,105, - 32, 61, 32,102,105,114,115,116, 44,108, 97,115,116, 32,100, - 111, 10, 10, 9, 9,114,101,116, 32, 61, 32,114,101,116, 46, - 46,108,115,101,112, 46, 46,116, 91,105, 93, 10, 9, 9,108, - 115,101,112, 32, 61, 32,115,101,112, 10, 9, 9,108,111,111, - 112, 32, 61, 32,116,114,117,101, 10, 9,101,110,100, 10, 9, - 105,102, 32,110,111,116, 32,108,111,111,112, 32,116,104,101, - 110, 10, 9, 9,114,101,116,117,114,110, 32, 34, 34, 10, 9, - 101,110,100, 10, 10, 9,114,101,116,117,114,110, 32,114,101, - 116, 10,101,110,100, 10, 10,102,117,110, 99,116,105,111,110, - 32,115,116,114,105,112, 95,112, 97,114,115, 40,115, 41, 10, - 10, 9,108,111, 99, 97,108, 32,116, 32, 61, 32,115,112,108, - 105,116, 95, 99, 95,116,111,107,101,110,115, 40,115, 44, 32, - 39, 44, 39, 41, 10, 9,108,111, 99, 97,108, 32,115,116,114, - 105,112, 32, 61, 32,102, 97,108,115,101, 10, 9,108,111, 99, - 97,108, 32,108, 97,115,116, 10, 10, 9,102,111,114, 32,105, - 61,116, 46,110, 44, 49, 44, 45, 49, 32,100,111, 10, 10, 9, - 9,105,102, 32,110,111,116, 32,115,116,114,105,112, 32, 97, - 110,100, 32,112, 97,114, 97,109, 95,111, 98,106,101, 99,116, - 40,116, 91,105, 93, 41, 32,116,104,101,110, 10, 9, 9, 9, - 108, 97,115,116, 32, 61, 32,105, 10, 9, 9, 9,115,116,114, - 105,112, 32, 61, 32,116,114,117,101, 10, 9, 9,101,110,100, - 10, 9, 9, 45, 45,105,102, 32,115,116,114,105,112, 32,116, - 104,101,110, 10, 9, 9, 45, 45, 9,116, 91,105, 93, 32, 61, - 32,115,116,114,105,110,103, 46,103,115,117, 98, 40,116, 91, - 105, 93, 44, 32, 34, 61, 46, 42, 36, 34, 44, 32, 34, 34, 41, - 10, 9, 9, 45, 45,101,110,100, 10, 9,101,110,100, 10, 10, - 9,114,101,116,117,114,110, 32,116, 44,115,116,114,105,112, - 44,108, 97,115,116, 10, 10,101,110,100, 10, 10,102,117,110, - 99,116,105,111,110, 32,115,116,114,105,112, 95,100,101,102, - 97,117,108,116,115, 40,115, 41, 10, 10, 9,115, 32, 61, 32, - 115,116,114,105,110,103, 46,103,115,117, 98, 40,115, 44, 32, - 34, 94, 37, 40, 34, 44, 32, 34, 34, 41, 10, 9,115, 32, 61, - 32,115,116,114,105,110,103, 46,103,115,117, 98, 40,115, 44, - 32, 34, 37, 41, 36, 34, 44, 32, 34, 34, 41, 10, 10, 9,108, - 111, 99, 97,108, 32,116, 32, 61, 32,115,112,108,105,116, 95, - 99, 95,116,111,107,101,110,115, 40,115, 44, 32, 34, 44, 34, - 41, 10, 9,108,111, 99, 97,108, 32,115,101,112, 44, 32,114, - 101,116, 32, 61, 32, 34, 34, 44, 34, 34, 10, 9,102,111,114, - 32,105, 61, 49, 44,116, 46,110, 32,100,111, 10, 9, 9,116, - 91,105, 93, 32, 61, 32,115,116,114,105,110,103, 46,103,115, - 117, 98, 40,116, 91,105, 93, 44, 32, 34, 61, 46, 42, 36, 34, - 44, 32, 34, 34, 41, 10, 9, 9,114,101,116, 32, 61, 32,114, - 101,116, 46, 46,115,101,112, 46, 46,116, 91,105, 93, 10, 9, - 9,115,101,112, 32, 61, 32, 34, 44, 34, 10, 9,101,110,100, - 10, 10, 9,114,101,116,117,114,110, 32, 34, 40, 34, 46, 46, - 114,101,116, 46, 46, 34, 41, 34, 10,101,110,100,32 - }; - tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua embedded: src/bin/lua/function.lua"); + #include "function_lua.h" + tolua_dobuffer(tolua_S,(char*)lua_function_lua,sizeof(lua_function_lua),"tolua embedded: src/bin/lua/function.lua"); lua_settop(tolua_S, top); } /* end of embedded lua code */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f8700692..6d3f6ddc6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,7 @@ if (NOT MSVC) #lib dependecies are not included set(BINDING_DEPENDECIES + tolua ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/virtual_method_hooks.lua ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/AllToLua.pkg Bindings/LuaFunctions.h -- cgit v1.2.3 From 04f1d58561c13ead8927ab0cd216f200892af086 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 15 Mar 2014 07:08:09 -0700 Subject: Fixed unessicary return --- src/DeadlockDetect.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/DeadlockDetect.cpp b/src/DeadlockDetect.cpp index c42d09b89..4dc7bfde6 100644 --- a/src/DeadlockDetect.cpp +++ b/src/DeadlockDetect.cpp @@ -121,7 +121,6 @@ void cDeadlockDetect::CheckWorldAge(const AString & a_WorldName, Int64 a_Age) if (itr->second.m_NumCyclesSame > (1000 * m_IntervalSec) / CYCLE_MILLISECONDS) { DeadlockDetected(); - return; } } else -- cgit v1.2.3 From a427f004b8c110d3ecf66ec34ad2a1134f01e68f Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 15 Mar 2014 07:15:02 -0700 Subject: Fix indentation --- lib/tolua++/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tolua++/CMakeLists.txt b/lib/tolua++/CMakeLists.txt index 9c8943aac..5e04cbe1f 100644 --- a/lib/tolua++/CMakeLists.txt +++ b/lib/tolua++/CMakeLists.txt @@ -16,7 +16,7 @@ if(UNIX) COMMAND xxd -i lua/enumerate.lua >enumerate_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/enumerate.lua) - add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h + add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h COMMAND xxd -i lua/function.lua >function_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/function.lua) -- cgit v1.2.3 From 7f84c8d60b1265f31aa58bfa4e01739dd279c528 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 15 Mar 2014 10:42:35 -0700 Subject: Patched tolua to understand size_t --- lib/tolua++/src/bin/basic_lua.h | 4 +++- lib/tolua++/src/bin/lua/basic.lua | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/tolua++/src/bin/basic_lua.h b/lib/tolua++/src/bin/basic_lua.h index 9f3b114b4..6adbaa4a6 100644 --- a/lib/tolua++/src/bin/basic_lua.h +++ b/lib/tolua++/src/bin/basic_lua.h @@ -61,6 +61,8 @@ unsigned char lua_basic_lua[] = { 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x27, 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x27, 0x2c, 0x0a, + 0x20, 0x5b, 0x27, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x74, 0x27, 0x5d, 0x20, + 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x5f, 0x63, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x27, 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x27, 0x2c, 0x0a, 0x20, 0x5b, 0x27, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, @@ -743,4 +745,4 @@ unsigned char lua_basic_lua[] = { 0x5f, 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a }; -unsigned int lua_basic_lua_len = 8909; +unsigned int lua_basic_lua_len = 8933; diff --git a/lib/tolua++/src/bin/lua/basic.lua b/lib/tolua++/src/bin/lua/basic.lua index f651f1fe6..10cb5b18b 100644 --- a/lib/tolua++/src/bin/lua/basic.lua +++ b/lib/tolua++/src/bin/lua/basic.lua @@ -23,6 +23,7 @@ _basic = { ['unsigned'] = 'number', ['float'] = 'number', ['double'] = 'number', + ['size_t'] = 'number', ['_cstring'] = 'string', ['_userdata'] = 'userdata', ['char*'] = 'string', -- cgit v1.2.3 From db73e37e2d9261a1ec27964ee453f7c59312af79 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 15 Mar 2014 20:33:34 +0100 Subject: Created a small plugin for InfoDump It allows you to dump the info of a plugin by pressing a button in the webadmin. --- MCServer/Plugins/DumpInfo/Init.lua | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 MCServer/Plugins/DumpInfo/Init.lua diff --git a/MCServer/Plugins/DumpInfo/Init.lua b/MCServer/Plugins/DumpInfo/Init.lua new file mode 100644 index 000000000..0fa542bb8 --- /dev/null +++ b/MCServer/Plugins/DumpInfo/Init.lua @@ -0,0 +1,49 @@ +function Initialize(a_Plugin) + a_Plugin:SetName("DumpInfo") + a_Plugin:SetVersion(1) + + -- Check if the infodump file exists. + if (not cFile:Exists("Plugins/InfoDump.lua")) then + LOGWARN("[DumpInfo] InfoDump.lua was not found.") + return false + end + + -- Add the webtab. + a_Plugin:AddWebTab("DumpPlugin", HandleDumpPluginRequest) + return true +end + + + + + +function HandleDumpPluginRequest(a_Request) + local Content = "" + + -- Check if it already was requested to dump a plugin. + if (a_Request.PostParams["DumpInfo"] ~= nil) then + local F = loadfile("Plugins/InfoDump.lua") + F("Plugins/" .. a_Request.PostParams["DumpInfo"]) + end + + Content = Content .. [[ + +]] + + -- Loop through each plugin that is found. + for PluginName, k in pairs(cPluginManager:Get():GetAllPlugins()) do + + -- Check if there is a file called 'Info.lua' or 'info.lua' + if (cFile:Exists("Plugins/" .. PluginName .. "/Info.lua") or cFile:Exists("Plugins/" .. PluginName .. "/info.lua")) then + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + end + end + + Content = Content .. [[ +
    DumpInfo
    " .. PluginName .. "
    " + Content = Content .. "
    ]] + + return Content +end -- cgit v1.2.3 From 3e0dfbc7a14f2d9784225e39a5dcf2ecdd5c6538 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 16 Mar 2014 07:59:58 -0700 Subject: Made buffers static const --- lib/tolua++/CMakeLists.txt | 6 +++--- lib/tolua++/src/bin/basic_lua.h | 2 +- lib/tolua++/src/bin/enumerate_lua.h | 2 +- lib/tolua++/src/bin/function_lua.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/tolua++/CMakeLists.txt b/lib/tolua++/CMakeLists.txt index 5e04cbe1f..095fc152e 100644 --- a/lib/tolua++/CMakeLists.txt +++ b/lib/tolua++/CMakeLists.txt @@ -9,15 +9,15 @@ include_directories ("${PROJECT_SOURCE_DIR}") if(UNIX) add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h - COMMAND xxd -i lua/basic.lua >basic_lua.h + COMMAND xxd -i lua/basic.lua | sed 's/unsigned char/static const unsigned char/g' >basic_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/basic.lua) add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h - COMMAND xxd -i lua/enumerate.lua >enumerate_lua.h + COMMAND xxd -i lua/enumerate.lua | sed 's/unsigned char/static const unsigned char/g' >enumerate_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/enumerate.lua) add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h - COMMAND xxd -i lua/function.lua >function_lua.h + COMMAND xxd -i lua/function.lua | sed 's/unsigned char/static const unsigned char/g' >function_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/function.lua) set_property(SOURCE src/bin/toluabind.c APPEND PROPERTY OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h) diff --git a/lib/tolua++/src/bin/basic_lua.h b/lib/tolua++/src/bin/basic_lua.h index 9f3b114b4..107d1a953 100644 --- a/lib/tolua++/src/bin/basic_lua.h +++ b/lib/tolua++/src/bin/basic_lua.h @@ -1,4 +1,4 @@ -unsigned char lua_basic_lua[] = { +static const unsigned char lua_basic_lua[] = { 0x2d, 0x2d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, 0x20, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x75, 0x74, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x0a, 0x2d, 0x2d, diff --git a/lib/tolua++/src/bin/enumerate_lua.h b/lib/tolua++/src/bin/enumerate_lua.h index 271cf2a23..f7285dc9a 100644 --- a/lib/tolua++/src/bin/enumerate_lua.h +++ b/lib/tolua++/src/bin/enumerate_lua.h @@ -1,4 +1,4 @@ -unsigned char lua_enumerate_lua[] = { +static const unsigned char lua_enumerate_lua[] = { 0x2d, 0x2d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x57, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, diff --git a/lib/tolua++/src/bin/function_lua.h b/lib/tolua++/src/bin/function_lua.h index c1317b9fe..705cb1a8f 100644 --- a/lib/tolua++/src/bin/function_lua.h +++ b/lib/tolua++/src/bin/function_lua.h @@ -1,4 +1,4 @@ -unsigned char lua_function_lua[] = { +static const unsigned char lua_function_lua[] = { 0x2d, 0x2d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x57, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20, -- cgit v1.2.3 From 4e0edc9fa7acca81ad28be3ff7b74d8178b29091 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 17:42:23 +0100 Subject: Add anvil direction. --- src/Blocks/BlockAnvil.h | 63 +++++++++++++++++++++++++++++++++++++++++++ src/Blocks/BlockHandler.cpp | 2 ++ src/WorldStorage/WSSAnvil.cpp | 10 ++++++- 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/Blocks/BlockAnvil.h diff --git a/src/Blocks/BlockAnvil.h b/src/Blocks/BlockAnvil.h new file mode 100644 index 000000000..aadec2e94 --- /dev/null +++ b/src/Blocks/BlockAnvil.h @@ -0,0 +1,63 @@ + +#pragma once + +#include "BlockHandler.h" +#include "../World.h" +#include "../Entities/Player.h" + + + + + +class cBlockAnvilHandler : + public cBlockHandler +{ +public: + cBlockAnvilHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + a_Pickups.push_back(cItem(E_BLOCK_ANVIL, 1, a_BlockMeta)); + } + + virtual bool GetPlacementBlockTypeMeta( + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = m_BlockType; + + int Direction = (int)floor(a_Player->GetYaw() * 4.0 / 360.0 + 0.5) & 0x3; + int RawMeta = a_BlockMeta >> 2; + + Direction++; + Direction %= 4; + switch (Direction) + { + case 0: a_BlockMeta = 0x2 | RawMeta << 2; break; + case 1: a_BlockMeta = 0x3 | RawMeta << 2; break; + case 2: a_BlockMeta = 0x0 | RawMeta << 2; break; + case 3: a_BlockMeta = 0x1 | RawMeta << 2; break; + default: + { + return false; + } + } + + return true; + } + + virtual bool IsUseable() override + { + return true; + } +} ; + + + + diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index aa97b2ca9..5b8effc07 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -6,6 +6,7 @@ #include "../Root.h" #include "../Bindings/PluginManager.h" #include "../Chunk.h" +#include "BlockAnvil.h" #include "BlockBed.h" #include "BlockBrewingStand.h" #include "BlockButton.h" @@ -85,6 +86,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) // Block handlers, alphabetically sorted: case E_BLOCK_ACACIA_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_ACTIVATOR_RAIL: return new cBlockRailHandler (a_BlockType); + case E_BLOCK_ANVIL: return new cBlockAnvilHandler (a_BlockType); case E_BLOCK_BED: return new cBlockBedHandler (a_BlockType); case E_BLOCK_BIRCH_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_BREWING_STAND: return new cBlockBrewingStandHandler (a_BlockType); diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 4dd4c755d..19405f4aa 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1497,7 +1497,15 @@ void cWSSAnvil::LoadHangingFromNBT(cHangingEntity & a_Hanging, const cParsedNBT int Direction = a_NBT.FindChildByName(a_TagIdx, "Direction"); if (Direction > 0) { - a_Hanging.SetDirection(static_cast((int)a_NBT.GetByte(Direction))); + Direction = (int)a_NBT.GetByte(Direction); + if ((Direction < 0) || (Direction > 5)) + { + a_Hanging.SetDirection(BLOCK_FACE_NORTH); + } + else + { + a_Hanging.SetDirection(static_cast(Direction)); + } } else { -- cgit v1.2.3 From 568038ab5241cf7699bb74dd0c158e12bc34f68d Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 19:25:00 +0100 Subject: Fix anvil pickups. --- src/Blocks/BlockAnvil.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/BlockAnvil.h b/src/Blocks/BlockAnvil.h index aadec2e94..9f5f84be0 100644 --- a/src/Blocks/BlockAnvil.h +++ b/src/Blocks/BlockAnvil.h @@ -20,7 +20,7 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { - a_Pickups.push_back(cItem(E_BLOCK_ANVIL, 1, a_BlockMeta)); + a_Pickups.push_back(cItem(E_BLOCK_ANVIL, 1, a_BlockMeta >> 2)); } virtual bool GetPlacementBlockTypeMeta( -- cgit v1.2.3 From 4ec5a95a7a690cb69fb5e9f44b2c9c2b3b678d09 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 20:26:13 +0100 Subject: Add cake --- src/Blocks/BlockCake.h | 55 +++++++++++++++++++++++++++++++++++++++++++++ src/Blocks/BlockHandler.cpp | 2 ++ src/Items/ItemCake.h | 41 +++++++++++++++++++++++++++++++++ src/Items/ItemHandler.cpp | 3 +++ 4 files changed, 101 insertions(+) create mode 100644 src/Blocks/BlockCake.h create mode 100644 src/Items/ItemCake.h diff --git a/src/Blocks/BlockCake.h b/src/Blocks/BlockCake.h new file mode 100644 index 000000000..639f5eaba --- /dev/null +++ b/src/Blocks/BlockCake.h @@ -0,0 +1,55 @@ +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockCakeHandler : + public cBlockHandler +{ +public: + cBlockCakeHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + { + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + + if (!a_Player->Feed(2, 0.1)) + { + return; + } + + if ((Meta + 1) >= 6) + { + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + } + else + { + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta + 1); + } + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + // Give nothing + } + + virtual bool IsUseable(void) override + { + return true; + } + + virtual const char * GetStepSound(void) override + { + return "step.cloth"; + } +} ; + + + + diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index aa97b2ca9..89a703de7 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -10,6 +10,7 @@ #include "BlockBrewingStand.h" #include "BlockButton.h" #include "BlockCactus.h" +#include "BlockCake.h" #include "BlockCarpet.h" #include "BlockCauldron.h" #include "BlockChest.h" @@ -91,6 +92,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_BROWN_MUSHROOM: return new cBlockMushroomHandler (a_BlockType); case E_BLOCK_CACTUS: return new cBlockCactusHandler (a_BlockType); + case E_BLOCK_CAKE: return new cBlockCakeHandler (a_BlockType); case E_BLOCK_CARROTS: return new cBlockCropsHandler (a_BlockType); case E_BLOCK_CARPET: return new cBlockCarpetHandler (a_BlockType); case E_BLOCK_CAULDRON: return new cBlockCauldronHandler (a_BlockType); diff --git a/src/Items/ItemCake.h b/src/Items/ItemCake.h new file mode 100644 index 000000000..48e23ed59 --- /dev/null +++ b/src/Items/ItemCake.h @@ -0,0 +1,41 @@ + +#pragma once + +#include "ItemHandler.h" + + + + + +class cItemCakeHandler : + public cItemHandler +{ +public: + cItemCakeHandler(int a_ItemType) : + cItemHandler(a_ItemType) + { + } + + + virtual bool IsPlaceable(void) override + { + return true; + } + + + virtual bool GetPlacementBlockTypeMeta( + cWorld * a_World, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = E_BLOCK_CAKE; + a_BlockMeta = 0; + return true; + } +} ; + + + + diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 1d357fcf1..cd391480c 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -13,6 +13,7 @@ #include "ItemBow.h" #include "ItemBrewingStand.h" #include "ItemBucket.h" +#include "ItemCake.h" #include "ItemCauldron.h" #include "ItemCloth.h" #include "ItemComparator.h" @@ -101,6 +102,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_BOTTLE_O_ENCHANTING: return new cItemBottleOEnchantingHandler(); case E_ITEM_BOW: return new cItemBowHandler; case E_ITEM_BREWING_STAND: return new cItemBrewingStandHandler(a_ItemType); + case E_ITEM_CAKE: return new cItemCakeHandler(a_ItemType); case E_ITEM_CAULDRON: return new cItemCauldronHandler(a_ItemType); case E_ITEM_COMPARATOR: return new cItemComparatorHandler(a_ItemType); case E_ITEM_DYE: return new cItemDyeHandler(a_ItemType); @@ -337,6 +339,7 @@ char cItemHandler::GetMaxStackSize(void) case E_ITEM_BREWING_STAND: return 64; case E_ITEM_BUCKET: return 16; case E_ITEM_CARROT: return 64; + case E_ITEM_CAKE: return 1; case E_ITEM_CAULDRON: return 64; case E_ITEM_CLAY: return 64; case E_ITEM_CLAY_BRICK: return 64; -- cgit v1.2.3 From 96d80f981ee1e7d746135b99eabe3ddd84413781 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 20:57:23 +0100 Subject: Change if-clause in BlockCake.h --- src/Blocks/BlockCake.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/BlockCake.h b/src/Blocks/BlockCake.h index 639f5eaba..36e133388 100644 --- a/src/Blocks/BlockCake.h +++ b/src/Blocks/BlockCake.h @@ -24,7 +24,7 @@ public: return; } - if ((Meta + 1) >= 6) + if (Meta >= 5) { a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); } -- cgit v1.2.3 From ef50e73a9c3053b8787ded3d26b3a5d3b6c92edc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 16 Mar 2014 18:44:23 +0100 Subject: Added common eMessageType aliases. --- src/Defines.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Defines.h b/src/Defines.h index 3b7654265..38411c69d 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -530,16 +530,22 @@ enum eMessageType // http://forum.mc-server.org/showthread.php?tid=1212 // MessageType... - mtCustom, // Send raw data without any processing - mtFailure, // Something could not be done (i.e. command not executed due to insufficient privilege) - mtInformation, // Informational message (i.e. command usage) - mtSuccess, // Something executed successfully - mtWarning, // Something concerning (i.e. reload) is about to happen - mtFatal, // Something catastrophic occured (i.e. plugin crash) - mtDeath, // Denotes death of player - mtPrivateMessage, // Player to player messaging identifier - mtJoin, // A player has joined the server - mtLeave, // A player has left the server + mtCustom, // Send raw data without any processing + mtFailure, // Something could not be done (i.e. command not executed due to insufficient privilege) + mtInformation, // Informational message (i.e. command usage) + mtSuccess, // Something executed successfully + mtWarning, // Something concerning (i.e. reload) is about to happen + mtFatal, // Something catastrophic occured (i.e. plugin crash) + mtDeath, // Denotes death of player + mtPrivateMessage, // Player to player messaging identifier + mtJoin, // A player has joined the server + mtLeave, // A player has left the server + + // Common aliases: + mtFail = mtFailure, + mtError = mtFailure, + mtInfo = mtInformation, + mtPM = mtPrivateMessage, }; -- cgit v1.2.3 From 5ac863f7fa780329e9dbe4e087162e33e0b7213c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 16 Mar 2014 18:45:01 +0100 Subject: Removed the @EnableMobDebug.lua file. It is not needed anymore, ZeroBrane Studio now has direct support for invoking the debugger in MCS plugins. --- MCServer/Plugins/@EnableMobDebug.lua | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 MCServer/Plugins/@EnableMobDebug.lua diff --git a/MCServer/Plugins/@EnableMobDebug.lua b/MCServer/Plugins/@EnableMobDebug.lua deleted file mode 100644 index 48d4c36b7..000000000 --- a/MCServer/Plugins/@EnableMobDebug.lua +++ /dev/null @@ -1,29 +0,0 @@ - --- @EnableMobDebug.lua - --- Enables the MobDebug debugger, used by ZeroBrane Studio, for a plugin --- Needs to be named with a @ at the start so that it's loaded as the first file of the plugin - ---[[ -Usage: -Copy this file to your plugin's folder when you want to debug that plugin -You should neither check this file into the plugin's version control system, -nor distribute it in the final release. ---]] - - - - - --- Try to load the debugger, be silent about failures: -local IsSuccess, MobDebug = pcall(require, "mobdebug") -if (IsSuccess) then - MobDebug.start() - - -- The debugger will automatically put a breakpoint on this line, use this opportunity to set more breakpoints in your code - LOG(cPluginManager:GetCurrentPlugin():GetName() .. ": MobDebug enabled") -end - - - - -- cgit v1.2.3 From 4227066f6d564a0e816b190f2726f036bff5b34d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 16 Mar 2014 21:30:44 +0100 Subject: Fixed InfoReg.lua's handling of multi-level commands. --- MCServer/Plugins/InfoReg.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/InfoReg.lua b/MCServer/Plugins/InfoReg.lua index 1cf68dbed..b3717884a 100644 --- a/MCServer/Plugins/InfoReg.lua +++ b/MCServer/Plugins/InfoReg.lua @@ -59,13 +59,13 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_ return true; end - -- Check if the handler is valid: + -- If the handler is not valid, check the next sublevel: if (Subcommand.Handler == nil) then if (Subcommand.Subcommands == nil) then LOG("Cannot find handler for command " .. a_CmdString .. " " .. Verb); return false; end - ListSubcommands(a_Player, Subcommand.Subcommands, a_CmdString .. " " .. Verb); + MultiCommandHandler(a_Split, a_Player, a_CmdString .. " " .. Verb, Subcommand, a_Level + 1); return true; end -- cgit v1.2.3 From b9fce71bf68768ee86ce128f353fea5533f50732 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 14:01:22 +0100 Subject: Add new leaves to all classes. --- src/BlockInfo.cpp | 1 + src/Blocks/BlockLeaves.h | 3 ++- src/Blocks/BlockMushroom.h | 1 + src/Blocks/BlockVine.h | 2 +- src/ChunkMap.cpp | 7 +++++++ src/Items/ItemHandler.cpp | 1 + src/Items/ItemShears.h | 5 +++-- src/MobSpawner.cpp | 2 +- src/WorldStorage/WSSAnvil.cpp | 1 + 9 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index d1ecfdf7e..7d438ba3e 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -93,6 +93,7 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_IRON_BARS ].m_SpreadLightFalloff = 1; ms_Info[E_BLOCK_IRON_DOOR ].m_SpreadLightFalloff = 1; ms_Info[E_BLOCK_LEAVES ].m_SpreadLightFalloff = 1; + ms_Info[E_BLOCK_NEW_LEAVES ].m_SpreadLightFalloff = 1; ms_Info[E_BLOCK_SIGN_POST ].m_SpreadLightFalloff = 1; ms_Info[E_BLOCK_TORCH ].m_SpreadLightFalloff = 1; ms_Info[E_BLOCK_VINES ].m_SpreadLightFalloff = 1; diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 7b8f0b378..954b993d6 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -16,6 +16,7 @@ { \ case E_BLOCK_LEAVES: a_Area.SetBlockType(x, y, z, (BLOCKTYPE)(E_BLOCK_SPONGE + i + 1)); break; \ case E_BLOCK_LOG: return true; \ + case E_BLOCK_NEW_LOG: return true; \ } bool HasNearLog(cBlockArea &a_Area, int a_BlockX, int a_BlockY, int a_BlockZ); @@ -86,7 +87,7 @@ public: return; } - if ((Meta & 0x8) != 0) + if ((Meta & 0x8) == 0) { // These leaves have been checked for decay lately and nothing around them changed return; diff --git a/src/Blocks/BlockMushroom.h b/src/Blocks/BlockMushroom.h index 623cfda64..c30c1a401 100644 --- a/src/Blocks/BlockMushroom.h +++ b/src/Blocks/BlockMushroom.h @@ -39,6 +39,7 @@ public: case E_BLOCK_CACTUS: case E_BLOCK_ICE: case E_BLOCK_LEAVES: + case E_BLOCK_NEW_LEAVES: case E_BLOCK_AIR: { return false; diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index 708583e70..8041d9359 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -73,7 +73,7 @@ public: /// Returns true if the specified block type is good for vines to attach to static bool IsBlockAttachable(BLOCKTYPE a_BlockType) { - return (a_BlockType == E_BLOCK_LEAVES) || cBlockInfo::IsSolid(a_BlockType); + return (a_BlockType == E_BLOCK_LEAVES) || (a_BlockType == E_BLOCK_NEW_LEAVES) || cBlockInfo::IsSolid(a_BlockType); } diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 40964c654..62c1ec544 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1383,6 +1383,13 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks) } break; } + case E_BLOCK_NEW_LEAVES: + { + if (itr->BlockType == E_BLOCK_NEW_LOG) + { + Chunk->SetBlock(itr->x, itr->y, itr->z, itr->BlockType, itr->BlockMeta); + } + } } } // for itr - a_Blocks[] } diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index cd391480c..136bc3096 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -95,6 +95,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) // Single item per handler, alphabetically sorted: case E_BLOCK_LEAVES: return new cItemLeavesHandler(a_ItemType); + case E_BLOCK_NEW_LEAVES: return new cItemLeavesHandler(a_ItemType); case E_BLOCK_SAPLING: return new cItemSaplingHandler(a_ItemType); case E_BLOCK_WOOL: return new cItemClothHandler(a_ItemType); case E_ITEM_BED: return new cItemBedHandler(a_ItemType); diff --git a/src/Items/ItemShears.h b/src/Items/ItemShears.h index b8f75f5ba..39d2776fa 100644 --- a/src/Items/ItemShears.h +++ b/src/Items/ItemShears.h @@ -28,10 +28,10 @@ public: virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); - if (Block == E_BLOCK_LEAVES) + if ((Block == E_BLOCK_LEAVES) || (Block == E_BLOCK_NEW_LEAVES)) { cItems Drops; - Drops.push_back(cItem(E_BLOCK_LEAVES, 1, a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x03)); + Drops.push_back(cItem(Block, 1, a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x03)); a_World->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ); a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); @@ -49,6 +49,7 @@ public: case E_BLOCK_COBWEB: case E_BLOCK_VINES: case E_BLOCK_LEAVES: + case E_BLOCK_NEW_LEAVES: { return true; } diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index 7704f6cf3..a0d0f5c54 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -169,7 +169,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && ( - (BlockBelow == E_BLOCK_GRASS) || (BlockBelow == E_BLOCK_LEAVES) + (BlockBelow == E_BLOCK_GRASS) || (BlockBelow == E_BLOCK_LEAVES) || (BlockBelow == E_BLOCK_NEW_LEAVES) ) && (a_RelY >= 62) && (m_Random.NextInt(3, a_Biome) != 0) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 070738164..fa916c484 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -366,6 +366,7 @@ bool cWSSAnvil::LoadChunkFromNBT(const cChunkCoords & a_Chunk, const cParsedNBT { case E_BLOCK_AIR: case E_BLOCK_LEAVES: + case E_BLOCK_NEW_LEAVES: { // nothing needed break; -- cgit v1.2.3 From c5740c27a9ac7df1baca802caa0bb8a45cb8005a Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 16:15:22 +0100 Subject: Wrong if in BlockLeaves --- src/Blocks/BlockLeaves.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 954b993d6..a6d3373c1 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -87,7 +87,7 @@ public: return; } - if ((Meta & 0x8) == 0) + if ((Meta & 0x8) != 0) { // These leaves have been checked for decay lately and nothing around them changed return; -- cgit v1.2.3 From 5a9f17060d09316931fd246e7b5f059a6bf4abac Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 16 Mar 2014 21:52:28 +0100 Subject: Only check for "Info.lua" with capital I --- MCServer/Plugins/DumpInfo/Init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/DumpInfo/Init.lua b/MCServer/Plugins/DumpInfo/Init.lua index 0fa542bb8..5d9c752b0 100644 --- a/MCServer/Plugins/DumpInfo/Init.lua +++ b/MCServer/Plugins/DumpInfo/Init.lua @@ -34,7 +34,7 @@ function HandleDumpPluginRequest(a_Request) for PluginName, k in pairs(cPluginManager:Get():GetAllPlugins()) do -- Check if there is a file called 'Info.lua' or 'info.lua' - if (cFile:Exists("Plugins/" .. PluginName .. "/Info.lua") or cFile:Exists("Plugins/" .. PluginName .. "/info.lua")) then + if (cFile:Exists("Plugins/" .. PluginName .. "/Info.lua")) then Content = Content .. "" Content = Content .. "" .. PluginName .. "" Content = Content .. "

    " -- cgit v1.2.3 From 260d13c7a40ab1af917158906df4b9c09974b704 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 16 Mar 2014 21:56:14 +0100 Subject: Added override specifier where appropriate in cWorld. --- src/World.h | 75 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/src/World.h b/src/World.h index 1950104a8..bd9ed8d16 100644 --- a/src/World.h +++ b/src/World.h @@ -125,15 +125,16 @@ public: // tolua_begin int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; } - virtual Int64 GetWorldAge(void) const { return m_WorldAge; } - virtual Int64 GetTimeOfDay(void) const { return m_TimeOfDay; } + + virtual Int64 GetWorldAge (void) const { return m_WorldAge; } // override, cannot specify due to tolua + virtual Int64 GetTimeOfDay(void) const { return m_TimeOfDay; } // override, cannot specify due to tolua void SetTicksUntilWeatherChange(int a_WeatherInterval) { m_WeatherInterval = a_WeatherInterval; } - virtual void SetTimeOfDay(Int64 a_TimeOfDay) + virtual void SetTimeOfDay(Int64 a_TimeOfDay) // override, cannot specify due to tolua { m_TimeOfDay = a_TimeOfDay; m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0; @@ -191,35 +192,35 @@ public: void BroadcastChat (const cCompositeChat & a_Message, const cClientHandle * a_Exclude = NULL); // tolua_end - void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); - void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL); - void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); - void BroadcastEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = NULL); - void BroadcastEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL); - void BroadcastEntityHeadLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); - void BroadcastEntityLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); - void BroadcastEntityMetadata (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); - void BroadcastEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); - void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); - void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL); - void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); - virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL); - void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); // tolua_export - void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL); - void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL); - void BroadcastScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode); - void BroadcastScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode); - void BroadcastDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display); - void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // tolua_export a_Src coords are Block * 8 - void BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL); // tolua_export - void BroadcastSpawnEntity (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); - void BroadcastTeleportEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); - void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); - void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL); - virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ); - void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL); - - virtual cBroadcastInterface & GetBroadcastManager() + void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); + void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL); + void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityHeadLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityMetadata (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) override; + void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); // tolua_export + void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL); + void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL); + void BroadcastScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode); + void BroadcastScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode); + void BroadcastDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display); + void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // tolua_export a_Src coords are Block * 8 + void BroadcastSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL); // tolua_export + void BroadcastSpawnEntity (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + void BroadcastTeleportEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); + void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL); + virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override; + void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL); + + virtual cBroadcastInterface & GetBroadcastManager(void) override { return *this; } @@ -273,7 +274,7 @@ public: void RemovePlayer( cPlayer* a_Player ); /** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */ - virtual bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << + virtual bool ForEachPlayer(cPlayerListCallback & a_Callback) override; // >> EXPORTED IN MANUALBINDINGS << /** Calls the callback for the player of the given name; returns true if the player was found and the callback called, false if player not found. Callback return ignored */ bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << @@ -365,7 +366,7 @@ public: bool IsChunkLighted(int a_ChunkX, int a_ChunkZ); /** Calls the callback for each chunk in the coords specified (all cords are inclusive). Returns true if all chunks have been processed successfully */ - virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback); + virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) override; // tolua_begin @@ -456,7 +457,7 @@ public: // tolua_begin bool DigBlock (int a_X, int a_Y, int a_Z); - virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player); + virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player); // override, cannot specify due to tolua double GetSpawnX(void) const { return m_SpawnX; } double GetSpawnY(void) const { return m_SpawnY; } @@ -507,7 +508,7 @@ public: | esWitherBirth | TBD | | esPlugin | void * | */ - virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); // tolua_export + virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); // tolua_export // override, cannot specify due to tolua /** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */ bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Exported in ManualBindings.cpp @@ -703,7 +704,7 @@ public: bool IsBlockDirectlyWatered(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */ - virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType); // tolua_export + virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType); // tolua_export // override, cannot specify due to tolua int SpawnMobFinalize(cMonster* a_Monster); /** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise */ -- cgit v1.2.3 From 89027cb67510f49114b9cd99c585009465a3ef66 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 16 Mar 2014 22:00:28 +0100 Subject: Fixed double to float conversions. --- src/BlockEntities/HopperEntity.cpp | 2 +- src/ChunkMap.cpp | 91 +++++++++++++------------- src/Mobs/Monster.cpp | 10 +-- src/Simulator/IncrementalRedstoneSimulator.cpp | 2 +- 4 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index af7043767..41fb9f811 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -219,7 +219,7 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) Vector3f EntityPos = a_Entity->GetPosition(); Vector3f BlockPos(m_Pos.x + 0.5f, (float)m_Pos.y + 1, m_Pos.z + 0.5f); // One block above hopper, and search from center outwards - float Distance = (EntityPos - BlockPos).Length(); + double Distance = (EntityPos - BlockPos).Length(); if (Distance < 0.5) { diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 62c1ec544..60fbf39d4 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1791,57 +1791,58 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ BLOCKTYPE Block = area.GetBlockType(bx + x, by + y, bz + z); switch (Block) { - case E_BLOCK_TNT: - { - // Activate the TNT, with a random fuse between 10 to 30 game ticks - double FuseTime = (double)(10 + m_World->GetTickRandomNumber(20)) / 20; - m_World->SpawnPrimedTNT(a_BlockX + x + 0.5, a_BlockY + y + 0.5, a_BlockZ + z + 0.5, FuseTime); - area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR); - a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z)); - break; - } - case E_BLOCK_OBSIDIAN: - case E_BLOCK_BEDROCK: - case E_BLOCK_WATER: - case E_BLOCK_LAVA: - { - // These blocks are not affected by explosions - break; - } - - case E_BLOCK_STATIONARY_WATER: - { - // Turn into simulated water: - area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_WATER); - break; - } + case E_BLOCK_TNT: + { + // Activate the TNT, with a random fuse between 10 to 30 game ticks + int FuseTime = 10 + m_World->GetTickRandomNumber(20); + m_World->SpawnPrimedTNT(a_BlockX + x + 0.5, a_BlockY + y + 0.5, a_BlockZ + z + 0.5, FuseTime); + area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR); + a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z)); + break; + } + + case E_BLOCK_OBSIDIAN: + case E_BLOCK_BEDROCK: + case E_BLOCK_WATER: + case E_BLOCK_LAVA: + { + // These blocks are not affected by explosions + break; + } - case E_BLOCK_STATIONARY_LAVA: - { - // Turn into simulated lava: - area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_LAVA); - break; - } + case E_BLOCK_STATIONARY_WATER: + { + // Turn into simulated water: + area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_WATER); + break; + } - case E_BLOCK_AIR: - { - // No pickups for air - break; - } + case E_BLOCK_STATIONARY_LAVA: + { + // Turn into simulated lava: + area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_LAVA); + break; + } - default: - { - if (m_World->GetTickRandomNumber(100) <= 25) // 25% chance of pickups + case E_BLOCK_AIR: { - cItems Drops; - cBlockHandler * Handler = BlockHandler(Block); + // No pickups for air + break; + } - Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc. - m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z); + default: + { + if (m_World->GetTickRandomNumber(100) <= 25) // 25% chance of pickups + { + cItems Drops; + cBlockHandler * Handler = BlockHandler(Block); + + Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc. + m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z); + } + area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR); + a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z)); } - area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR); - a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z)); - } } // switch (BlockType) } // for z } // for y diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 6e3c91d58..16d6aed1f 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -82,11 +82,11 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_AttackRange(2) , m_AttackInterval(0) , m_SightDistance(25) - , m_DropChanceWeapon(0.085) - , m_DropChanceHelmet(0.085) - , m_DropChanceChestplate(0.085) - , m_DropChanceLeggings(0.085) - , m_DropChanceBoots(0.085) + , m_DropChanceWeapon(0.085f) + , m_DropChanceHelmet(0.085f) + , m_DropChanceChestplate(0.085f) + , m_DropChanceLeggings(0.085f) + , m_DropChanceBoots(0.085f) , m_CanPickUpLoot(true) , m_BurnsInDaylight(false) { diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index ca2ef4b1a..6ace8ade9 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -1062,7 +1062,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_Bloc { Vector3f EntityPos = a_Entity->GetPosition(); Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f); - float Distance = (EntityPos - BlockPos).Length(); + double Distance = (EntityPos - BlockPos).Length(); if (Distance <= 0.7) { -- cgit v1.2.3 From 0a505576e5220113dfbcc140b70659f822a17f44 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 17 Mar 2014 10:28:04 -0700 Subject: Fixed =~ bug --- lib/tolua++/src/bin/enumerate_lua.h | 2 +- lib/tolua++/src/bin/lua/enumerate.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tolua++/src/bin/enumerate_lua.h b/lib/tolua++/src/bin/enumerate_lua.h index f7285dc9a..f460f297b 100644 --- a/lib/tolua++/src/bin/enumerate_lua.h +++ b/lib/tolua++/src/bin/enumerate_lua.h @@ -113,7 +113,7 @@ static const unsigned char lua_enumerate_lua[] = { 0x0a, 0x09, 0x69, 0x66, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x5d, - 0x20, 0x7e, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x3d, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x3d, diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index 5f0dedfe1..9c534a020 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -52,7 +52,7 @@ _global_output_enums = {} -- write support code function classEnumerate:supcode () - if _global_output_enums[self.name] ~= nil then + if _global_output_enums[self.name] == nil then _global_output_enums[self.name] = 1 output("int tolua_is" .. self.name .. " (lua_State* L, int lo, int def, tolua_Error* err)") output("{") -- cgit v1.2.3 From 9447cd20f3bff89d87bda07320c5ccbb45aa7556 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 17 Mar 2014 22:12:02 +0100 Subject: Fixed a crash in firework rockets. Fixes #816. --- src/WorldStorage/FireworksSerializer.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index 3c97ae0a2..744fc731f 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -20,8 +20,14 @@ void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFa a_Writer.AddByte("Flicker", a_FireworkItem.m_HasFlicker); a_Writer.AddByte("Trail", a_FireworkItem.m_HasTrail); a_Writer.AddByte("Type", a_FireworkItem.m_Type); - a_Writer.AddIntArray("Colors", &(a_FireworkItem.m_Colours[0]), a_FireworkItem.m_Colours.size()); - a_Writer.AddIntArray("FadeColors", &(a_FireworkItem.m_FadeColours[0]), a_FireworkItem.m_FadeColours.size()); + if (!a_FireworkItem.m_Colours.empty()) + { + a_Writer.AddIntArray("Colors", &(a_FireworkItem.m_Colours[0]), a_FireworkItem.m_Colours.size()); + } + if (!a_FireworkItem.m_FadeColours.empty()) + { + a_Writer.AddIntArray("FadeColors", &(a_FireworkItem.m_FadeColours[0]), a_FireworkItem.m_FadeColours.size()); + } a_Writer.EndCompound(); a_Writer.EndList(); a_Writer.EndCompound(); -- cgit v1.2.3 From 4dc5650023c234a9e82c97c795d8c39016063c51 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 18 Mar 2014 13:54:17 +0100 Subject: Fixed cGZipFile::ReadRestOfFile returning incorrect value. --- src/OSSupport/GZipFile.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/OSSupport/GZipFile.cpp b/src/OSSupport/GZipFile.cpp index cbf6be6c4..b13e519e0 100644 --- a/src/OSSupport/GZipFile.cpp +++ b/src/OSSupport/GZipFile.cpp @@ -73,12 +73,15 @@ int cGZipFile::ReadRestOfFile(AString & a_Contents) // Since the gzip format doesn't really support getting the uncompressed length, we need to read incrementally. Yuck! int NumBytesRead = 0; + int TotalBytes = 0; char Buffer[64 KiB]; while ((NumBytesRead = gzread(m_File, Buffer, sizeof(Buffer))) > 0) { + TotalBytes += NumBytesRead; a_Contents.append(Buffer, NumBytesRead); } - return NumBytesRead; + // NumBytesRead is < 0 on error + return (NumBytesRead >= 0) ? TotalBytes : NumBytesRead; } -- cgit v1.2.3 From 38aad32a8b92a0189483f0f61a42660ee31a835c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 18 Mar 2014 13:54:32 +0100 Subject: Debuggers: Using binary file mode for .schematics. --- MCServer/Plugins/Debuggers/Debuggers.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index d2c9a2a49..fe3efa306 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -217,7 +217,7 @@ function TestBlockAreasString() return end cFile:CreateFolder("schematics") - local f = io.open("schematics/StringTest.schematic", "w") + local f = io.open("schematics/StringTest.schematic", "wb") f:write(Data) f:close() @@ -230,7 +230,7 @@ function TestBlockAreasString() BA2:Clear() -- Load another area from a string in that file: - f = io.open("schematics/StringTest.schematic", "r") + f = io.open("schematics/StringTest.schematic", "rb") Data = f:read("*all") if not(BA2:LoadFromSchematicString(Data)) then LOG("Cannot load schematic from string") -- cgit v1.2.3 From 91f64da2a6895f2dee7d010e71282b0c5fb6bf02 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 18 Mar 2014 15:45:16 +0100 Subject: Fixed chunkmap tree block replacing. --- src/ChunkMap.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 60fbf39d4..ffba52d54 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1376,19 +1376,13 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks) break; } case E_BLOCK_LEAVES: - { - if (itr->BlockType == E_BLOCK_LOG) - { - Chunk->SetBlock(itr->x, itr->y, itr->z, itr->BlockType, itr->BlockMeta); - } - break; - } case E_BLOCK_NEW_LEAVES: { - if (itr->BlockType == E_BLOCK_NEW_LOG) + if ((itr->BlockType == E_BLOCK_LOG) || (itr->BlockType == E_BLOCK_NEW_LOG)) { Chunk->SetBlock(itr->x, itr->y, itr->z, itr->BlockType, itr->BlockMeta); } + break; } } } // for itr - a_Blocks[] -- cgit v1.2.3 From 23ffaa19b7c93f076a2d5a85018f7fb1a2260ea8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Mar 2014 20:45:10 +0000 Subject: Added levels of shrapnel --- src/ChunkMap.cpp | 10 +++++++--- src/World.cpp | 4 +++- src/World.h | 12 ++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index ab4e01334..6ce928252 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1832,13 +1832,17 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc. m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z); } - else if (m_World->IsTNTShrapnelEnabled() && (m_World->GetTickRandomNumber(100) < 20)) // 20% chance of flinging stuff around + else if ((m_World->GetTNTShrapnelLevel() > 0) && (m_World->GetTickRandomNumber(100) < 20)) // 20% chance of flinging stuff around { - if (!cBlockInfo::FullyOccupiesVoxel(area.GetBlockType(bx + x, by + y, bz + z))) + if (!cBlockInfo::FullyOccupiesVoxel(Block)) { break; } - m_World->SpawnFallingBlock(bx + x, by + y + 5, bz + z, area.GetBlockType(bx + x, by + y, bz + z), area.GetBlockMeta(bx + x, by + y, bz + z)); + else if ((m_World->GetTNTShrapnelLevel() == 1) && ((Block != E_BLOCK_SAND) && (Block != E_BLOCK_GRAVEL))) + { + break; + } + m_World->SpawnFallingBlock(bx + x, by + y + 5, bz + z, Block, area.GetBlockMeta(bx + x, by + y, bz + z)); } area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR); a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z)); diff --git a/src/World.cpp b/src/World.cpp index cf18e3a45..18109b2af 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -578,13 +578,15 @@ void cWorld::Start(void) m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false); m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true); m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true); - m_bTNTSpawnsShrapnel = IniFile.GetValueSetB("Physics", "IsTNTShrapnelEnabled", true); + m_TNTShrapnelLevel = IniFile.GetValueSetI("Physics", "TNTShrapnelLevel", 2); m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false); m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true); m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true); m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true); m_GameMode = (eGameMode)IniFile.GetValueSetI("General", "Gamemode", m_GameMode); + if (m_TNTShrapnelLevel > 2) + m_TNTShrapnelLevel = 2; // Load allowed mobs: const char * DefaultMonsters = ""; diff --git a/src/World.h b/src/World.h index ea24c39d5..2804e8386 100644 --- a/src/World.h +++ b/src/World.h @@ -605,8 +605,8 @@ public: bool AreCommandBlocksEnabled(void) const { return m_bCommandBlocksEnabled; } void SetCommandBlocksEnabled(bool a_Flag) { m_bCommandBlocksEnabled = a_Flag; } - bool IsTNTShrapnelEnabled(void) const { return m_bTNTSpawnsShrapnel; } - void SetTNTShrapnelEnabled(bool a_Flag) { m_bTNTSpawnsShrapnel = a_Flag; } + unsigned char GetTNTShrapnelLevel(void) const { return m_TNTShrapnelLevel; } + void SetTNTShrapnelLevel(int a_Flag) { m_TNTShrapnelLevel = a_Flag; } bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; } void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; } @@ -866,8 +866,12 @@ private: /** Whether prefixes such as [INFO] are prepended to SendMessageXXX() / BroadcastChatXXX() functions */ bool m_bUseChatPrefixes; - /** Whether TNT explosions, done via cWorld::DoExplosionAt(), should project random affected blocks as FallingBlock entities */ - bool m_bTNTSpawnsShrapnel; + /** The level of DoExplosionAt() projecting random affected blocks as FallingBlock entities + 0 = None + 1 = Only sand and gravel + 2 = All blocks + */ + int m_TNTShrapnelLevel; cChunkGenerator m_Generator; -- cgit v1.2.3 From 4a67114f5654668f746f43dfa82732257571a103 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 19 Mar 2014 13:57:06 +0100 Subject: LuaChunkStay: Removed a debugging output. --- src/Bindings/LuaChunkStay.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp index 0e982637f..db865cfa4 100644 --- a/src/Bindings/LuaChunkStay.cpp +++ b/src/Bindings/LuaChunkStay.cpp @@ -131,9 +131,6 @@ void cLuaChunkStay::Enable(cChunkMap & a_ChunkMap, int a_OnChunkAvailableStackPo void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ) { - // DEBUG: - LOGD("LuaChunkStay: Chunk [%d, %d] is now available, calling the callback...", a_ChunkX, a_ChunkZ); - cPluginLua::cOperation Op(m_Plugin); Op().Call((int)m_OnChunkAvailable, a_ChunkX, a_ChunkZ); } -- cgit v1.2.3 From 7c717fe6df582111efc0907f5535d32ce8d72786 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 19 Mar 2014 13:57:37 +0100 Subject: APIDump: Reformatted the plugin to avoid all ZBS Analyzer issues. --- MCServer/Plugins/APIDump/main_APIDump.lua | 897 ++++++++++++++---------------- 1 file changed, 429 insertions(+), 468 deletions(-) diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua index 4ed692b52..6d4a6ebc5 100644 --- a/MCServer/Plugins/APIDump/main_APIDump.lua +++ b/MCServer/Plugins/APIDump/main_APIDump.lua @@ -7,92 +7,22 @@ -- Global variables: -g_Plugin = nil; -g_PluginFolder = ""; +local g_Plugin = nil +local g_PluginFolder = "" +local g_Stats = {} +local g_TrackedPages = {} -function Initialize(Plugin) - g_Plugin = Plugin; - g_PluginFolder = Plugin:GetLocalFolder(); - - LOG("Initialising " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) - - cPluginManager:BindConsoleCommand("api", HandleCmdApi, "Dumps the Lua API docs into the API/ subfolder") - g_Plugin:AddWebTab("APIDump", HandleWebAdminDump) - -- TODO: Add a WebAdmin tab that has a Dump button - return true -end - - - - - -function HandleCmdApi(a_Split) - DumpApi() - return true -end - - - - - -function DumpApi() - LOG("Dumping the API...") - - -- Load the API descriptions from the Classes and Hooks subfolders: - -- This needs to be done each time the command is invoked because the export modifies the tables' contents - dofile(g_PluginFolder .. "/APIDesc.lua") - if (g_APIDesc.Classes == nil) then - g_APIDesc.Classes = {}; - end - if (g_APIDesc.Hooks == nil) then - g_APIDesc.Hooks = {}; - end - LoadAPIFiles("/Classes/", g_APIDesc.Classes); - LoadAPIFiles("/Hooks/", g_APIDesc.Hooks); - - -- Reset the stats: - g_TrackedPages = {}; -- List of tracked pages, to be checked later whether they exist. Each item is an array of referring pagenames. - g_Stats = -- Statistics about the documentation - { - NumTotalClasses = 0, - NumUndocumentedClasses = 0, - NumTotalFunctions = 0, - NumUndocumentedFunctions = 0, - NumTotalConstants = 0, - NumUndocumentedConstants = 0, - NumTotalVariables = 0, - NumUndocumentedVariables = 0, - NumTotalHooks = 0, - NumUndocumentedHooks = 0, - NumTrackedLinks = 0, - NumInvalidLinks = 0, - } - - -- dump all available API functions and objects: - -- DumpAPITxt(); - - -- Dump all available API object in HTML format into a subfolder: - DumpAPIHtml(); - - LOG("APIDump finished"); - return true -end - - - - - -function LoadAPIFiles(a_Folder, a_DstTable) +local function LoadAPIFiles(a_Folder, a_DstTable) assert(type(a_Folder) == "string") assert(type(a_DstTable) == "table") local Folder = g_PluginFolder .. a_Folder; - for idx, fnam in ipairs(cFile:GetFolderContents(Folder)) do + for _, fnam in ipairs(cFile:GetFolderContents(Folder)) do local FileName = Folder .. fnam; -- We only want .lua files from the folder: if (cFile:IsFile(FileName) and fnam:match(".*%.lua$")) then @@ -113,45 +43,7 @@ end -function DumpAPITxt() - LOG("Dumping all available functions to API.txt..."); - function dump (prefix, a, Output) - for i, v in pairs (a) do - if (type(v) == "table") then - if (GetChar(i, 1) ~= ".") then - if (v == _G) then - -- LOG(prefix .. i .. " == _G, CYCLE, ignoring"); - elseif (v == _G.package) then - -- LOG(prefix .. i .. " == _G.package, ignoring"); - else - dump(prefix .. i .. ".", v, Output) - end - end - elseif (type(v) == "function") then - if (string.sub(i, 1, 2) ~= "__") then - table.insert(Output, prefix .. i .. "()"); - end - end - end - end - - local Output = {}; - dump("", _G, Output); - - table.sort(Output); - local f = io.open("API.txt", "w"); - for i, n in ipairs(Output) do - f:write(n, "\n"); - end - f:close(); - LOG("API.txt written."); -end - - - - - -function CreateAPITables() +local function CreateAPITables() --[[ We want an API table of the following shape: local API = { @@ -218,7 +110,7 @@ function CreateAPITables() -- Member variables: local SetField = a_ClassObj[".set"] or {}; if ((a_ClassObj[".get"] ~= nil) and (type(a_ClassObj[".get"]) == "table")) then - for k, v in pairs(a_ClassObj[".get"]) do + for k in pairs(a_ClassObj[".get"]) do if (SetField[k] == nil) then -- It is a read-only variable, add it as a constant: table.insert(res.Constants, {Name = k, Value = ""}); @@ -259,7 +151,7 @@ local function WriteArticles(f)

    The following articles provide various extra information on plugin development

      ]]); - for i, extra in ipairs(g_APIDesc.ExtraPages) do + for _, extra in ipairs(g_APIDesc.ExtraPages) do local SrcFileName = g_PluginFolder .. "/" .. extra.FileName; if (cFile:Exists(SrcFileName)) then local DstFileName = "API/" .. extra.FileName; @@ -279,20 +171,125 @@ end -local function WriteClasses(f, a_API, a_ClassMenu) - f:write([[ -

      Class index

      -

      The following classes are available in the MCServer Lua scripting language: -

        - ]]); - for i, cls in ipairs(a_API) do - f:write("
      • ", cls.Name, "
      • \n"); - WriteHtmlClass(cls, a_API, a_ClassMenu); +-- Make a link out of anything with the special linkifying syntax {{link|title}} +local function LinkifyString(a_String, a_Referrer) + assert(a_Referrer ~= nil); + assert(a_Referrer ~= ""); + + --- Adds a page to the list of tracked pages (to be checked for existence at the end) + local function AddTrackedPage(a_PageName) + local Pg = (g_TrackedPages[a_PageName] or {}); + table.insert(Pg, a_Referrer); + g_TrackedPages[a_PageName] = Pg; end - f:write([[ -

      + + --- Creates the HTML for the specified link and title + local function CreateLink(Link, Title) + if (Link:sub(1, 7) == "http://") then + -- The link is a full absolute URL, do not modify, do not track: + return "" .. Title .. ""; + end + local idxHash = Link:find("#"); + if (idxHash ~= nil) then + -- The link contains an anchor: + if (idxHash == 1) then + -- Anchor in the current page, no need to track: + return "" .. Title .. ""; + end + -- Anchor in another page: + local PageName = Link:sub(1, idxHash - 1); + AddTrackedPage(PageName); + return "" .. Title .. ""; + end + -- Link without anchor: + AddTrackedPage(Link); + return "" .. Title .. ""; + end + + -- Linkify the strings using the CreateLink() function: + local txt = a_String:gsub("{{([^|}]*)|([^}]*)}}", CreateLink) -- {{link|title}} + txt = txt:gsub("{{([^|}]*)}}", -- {{LinkAndTitle}} + function(LinkAndTitle) + local idxHash = LinkAndTitle:find("#"); + if (idxHash ~= nil) then + -- The LinkAndTitle contains a hash, remove the hashed part from the title: + return CreateLink(LinkAndTitle, LinkAndTitle:sub(1, idxHash - 1)); + end + return CreateLink(LinkAndTitle, LinkAndTitle); + end + ); + return txt; +end + + + + + +local function WriteHtmlHook(a_Hook, a_HookNav) + local fnam = "API/" .. a_Hook.DefaultFnName .. ".html"; + local f, error = io.open(fnam, "w"); + if (f == nil) then + LOG("Cannot write \"" .. fnam .. "\": \"" .. error .. "\"."); + return; + end + local HookName = a_Hook.DefaultFnName; + + f:write([[ + + MCServer API - ]], HookName, [[ Hook + + + + + + +
      +
      +

      ]], a_Hook.Name, [[


      +
      +
      + Index:
      + Articles
      + Classes
      + Hooks
      +
      + Quick navigation:
      ]]); + f:write(a_HookNav); + f:write([[ +

      + ]]); + f:write(LinkifyString(a_Hook.Desc, HookName)); + f:write("

      \n

      Callback function

      \n

      The default name for the callback function is "); + f:write(a_Hook.DefaultFnName, ". It has the following signature:\n"); + f:write("

      function ", HookName, "(");
      +	if (a_Hook.Params == nil) then
      +		a_Hook.Params = {};
      +	end
      +	for i, param in ipairs(a_Hook.Params) do
      +		if (i > 1) then
      +			f:write(", ");
      +		end
      +		f:write(param.Name);
      +	end
      +	f:write(")
      \n

      Parameters:

      \n\n"); + for _, param in ipairs(a_Hook.Params) do + f:write("\n"); + end + f:write("
      NameTypeNotes
      ", param.Name, "", LinkifyString(param.Type, HookName), "", LinkifyString(param.Notes, HookName), "
      \n

      " .. (a_Hook.Returns or "") .. "

      \n\n"); + f:write([[

      Code examples

      Registering the callback

      ]]); + f:write("
      \n");
      +	f:write([[cPluginManager:AddHook(cPluginManager.]] .. a_Hook.Name .. ", My" .. a_Hook.DefaultFnName .. [[);]]);
      +	f:write("
      \n\n"); + local Examples = a_Hook.CodeExamples or {}; + for _, example in ipairs(Examples) do + f:write("

      ", (example.Title or "missing Title"), "

      \n"); + f:write("

      ", (example.Desc or "missing Desc"), "

      \n"); + f:write("
      ", (example.Code or "missing Code"), "\n
      \n\n"); + end + f:write([[
      ]]); + f:close(); end @@ -318,7 +315,7 @@ local function WriteHooks(f, a_Hooks, a_UndocumentedHooks, a_HookNav) Called when ]]); - for i, hook in ipairs(a_Hooks) do + for _, hook in ipairs(a_Hooks) do if (hook.DefaultFnName == nil) then -- The hook is not documented yet f:write(" \n " .. hook.Name .. "\n (No documentation yet)\n \n"); @@ -338,162 +335,13 @@ end -function DumpAPIHtml() - LOG("Dumping all available functions and constants to API subfolder..."); - - -- Create the output folder - if not(cFile:IsFolder("API")) then - cFile:CreateFolder("API"); - end - - LOG("Copying static files.."); - cFile:CreateFolder("API/Static"); - local localFolder = g_Plugin:GetLocalFolder(); - for idx, fnam in ipairs(cFile:GetFolderContents(localFolder .. "/Static")) do - cFile:Delete("API/Static/" .. fnam); - cFile:Copy(localFolder .. "/Static/" .. fnam, "API/Static/" .. fnam); - end - - LOG("Creating API tables..."); - local API, Globals = CreateAPITables(); - local Hooks = {}; - local UndocumentedHooks = {}; - - -- Sort the classes by name: - LOG("Sorting..."); - table.sort(API, - function (c1, c2) - return (string.lower(c1.Name) < string.lower(c2.Name)); - end - ); - - g_Stats.NumTotalClasses = #API; - - -- Add Globals into the API: - Globals.Name = "Globals"; - table.insert(API, Globals); - - -- Extract hook constants: - for name, obj in pairs(cPluginManager) do - if ( - (type(obj) == "number") and - name:match("HOOK_.*") and - (name ~= "HOOK_MAX") and - (name ~= "HOOK_NUM_HOOKS") - ) then - table.insert(Hooks, { Name = name }); - end - end - table.sort(Hooks, - function(Hook1, Hook2) - return (Hook1.Name < Hook2.Name); - end - ); - - -- Read in the descriptions: - LOG("Reading descriptions..."); - ReadDescriptions(API); - ReadHooks(Hooks); - - -- Create a "class index" file, write each class as a link to that file, - -- then dump class contents into class-specific file - LOG("Writing HTML files..."); - local f = io.open("API/index.html", "w"); - if (f == nil) then - LOGINFO("Cannot output HTML API: " .. err); - return; - end - - -- Create a class navigation menu that will be inserted into each class file for faster navigation (#403) - local ClassMenuTab = {}; - for idx, cls in ipairs(API) do - table.insert(ClassMenuTab, ""); - table.insert(ClassMenuTab, cls.Name); - table.insert(ClassMenuTab, "
      "); - end - local ClassMenu = table.concat(ClassMenuTab, ""); - - -- Create a hook navigation menu that will be inserted into each hook file for faster navigation(#403) - local HookNavTab = {}; - for idx, hook in ipairs(Hooks) do - table.insert(HookNavTab, ""); - table.insert(HookNavTab, (hook.Name:gsub("^HOOK_", ""))); -- remove the "HOOK_" part of the name - table.insert(HookNavTab, "
      "); - end - local HookNav = table.concat(HookNavTab, ""); - - -- Write the HTML file: - f:write([[ - - - MCServer API - Index - - - -
      -
      -

      MCServer API - Index

      -
      -
      -

      The API reference is divided into the following sections:

      - -
      - ]]); - - WriteArticles(f); - WriteClasses(f, API, ClassMenu); - WriteHooks(f, Hooks, UndocumentedHooks, HookNav); - - -- Copy the static files to the output folder: - local StaticFiles = - { - "main.css", - "prettify.js", - "prettify.css", - "lang-lua.js", - }; - for idx, fnam in ipairs(StaticFiles) do - cFile:Delete("API/" .. fnam); - cFile:Copy(g_Plugin:GetLocalFolder() .. "/" .. fnam, "API/" .. fnam); - end - - -- List the documentation problems: - LOG("Listing leftovers..."); - ListUndocumentedObjects(API, UndocumentedHooks); - ListUnexportedObjects(); - ListMissingPages(); - - WriteStats(f); - - f:write([[
    - - -]]); - f:close(); - - LOG("API subfolder written"); -end - - - - - -function ReadDescriptions(a_API) +local function ReadDescriptions(a_API) -- Returns true if the class of the specified name is to be ignored local function IsClassIgnored(a_ClsName) if (g_APIDesc.IgnoreClasses == nil) then return false; end - for i, name in ipairs(g_APIDesc.IgnoreClasses) do + for _, name in ipairs(g_APIDesc.IgnoreClasses) do if (a_ClsName:match(name)) then return true; end @@ -511,7 +359,7 @@ function ReadDescriptions(a_API) return false; end local FnName = a_ClassName .. "." .. a_FnName; - for i, name in ipairs(g_APIDesc.IgnoreFunctions) do + for _, name in ipairs(g_APIDesc.IgnoreFunctions) do if (FnName:match(name)) then return true; end @@ -524,7 +372,7 @@ function ReadDescriptions(a_API) if (g_APIDesc.IgnoreConstants == nil) then return false; end; - for i, name in ipairs(g_APIDesc.IgnoreConstants) do + for _, name in ipairs(g_APIDesc.IgnoreConstants) do if (a_CnName:match(name)) then return true; end @@ -537,7 +385,7 @@ function ReadDescriptions(a_API) if (g_APIDesc.IgnoreVariables == nil) then return false; end; - for i, name in ipairs(g_APIDesc.IgnoreVariables) do + for _, name in ipairs(g_APIDesc.IgnoreVariables) do if (a_VarName:match(name)) then return true; end @@ -547,7 +395,7 @@ function ReadDescriptions(a_API) -- Remove ignored classes from a_API: local APICopy = {}; - for i, cls in ipairs(a_API) do + for _, cls in ipairs(a_API) do if not(IsClassIgnored(cls.Name)) then table.insert(APICopy, cls); end @@ -557,14 +405,14 @@ function ReadDescriptions(a_API) end; -- Process the documentation for each class: - for i, cls in ipairs(a_API) do + for _, cls in ipairs(a_API) do -- Initialize default values for each class: cls.ConstantGroups = {}; cls.NumConstantsInGroups = 0; cls.NumConstantsInGroupsForDescendants = 0; -- Rename special functions: - for j, fn in ipairs(cls.Functions) do + for _, fn in ipairs(cls.Functions) do if (fn.Name == ".call") then fn.DocID = "constructor"; fn.Name = "() (constructor)"; @@ -594,7 +442,7 @@ function ReadDescriptions(a_API) -- Process inheritance: if (APIDesc.Inherits ~= nil) then - for j, icls in ipairs(a_API) do + for _, icls in ipairs(a_API) do if (icls.Name == APIDesc.Inherits) then table.insert(icls.Descendants, cls); cls.Inherits = icls; @@ -614,7 +462,7 @@ function ReadDescriptions(a_API) if (APIDesc.Functions ~= nil) then -- Assign function descriptions: - for j, func in ipairs(cls.Functions) do + for _, func in ipairs(cls.Functions) do local FnName = func.DocID or func.Name; local FnDesc = APIDesc.Functions[FnName]; if (FnDesc == nil) then @@ -630,7 +478,7 @@ function ReadDescriptions(a_API) AddFunction(func.Name, FnDesc.Params, FnDesc.Return, FnDesc.Notes); else -- Multiple function overloads - for k, desc in ipairs(FnDesc) do + for _, desc in ipairs(FnDesc) do AddFunction(func.Name, desc.Params, desc.Return, desc.Notes); end -- for k, desc - FnDesc[] end @@ -641,7 +489,7 @@ function ReadDescriptions(a_API) -- Replace functions with their described and overload-expanded versions: cls.Functions = DoxyFunctions; else -- if (APIDesc.Functions ~= nil) - for j, func in ipairs(cls.Functions) do + for _, func in ipairs(cls.Functions) do local FnName = func.DocID or func.Name; if not(IsFunctionIgnored(cls.Name, FnName)) then table.insert(cls.UndocumentedFunctions, FnName); @@ -651,7 +499,7 @@ function ReadDescriptions(a_API) if (APIDesc.Constants ~= nil) then -- Assign constant descriptions: - for j, cons in ipairs(cls.Constants) do + for _, cons in ipairs(cls.Constants) do local CnDesc = APIDesc.Constants[cons.Name]; if (CnDesc == nil) then -- Not documented @@ -664,7 +512,7 @@ function ReadDescriptions(a_API) end end -- for j, cons else -- if (APIDesc.Constants ~= nil) - for j, cons in ipairs(cls.Constants) do + for _, cons in ipairs(cls.Constants) do if not(IsConstantIgnored(cls.Name .. "." .. cons.Name)) then table.insert(cls.UndocumentedConstants, cons.Name); end @@ -673,7 +521,7 @@ function ReadDescriptions(a_API) -- Assign member variables' descriptions: if (APIDesc.Variables ~= nil) then - for j, var in ipairs(cls.Variables) do + for _, var in ipairs(cls.Variables) do local VarDesc = APIDesc.Variables[var.Name]; if (VarDesc == nil) then -- Not documented @@ -688,7 +536,7 @@ function ReadDescriptions(a_API) end end -- for j, var else -- if (APIDesc.Variables ~= nil) - for j, var in ipairs(cls.Variables) do + for _, var in ipairs(cls.Variables) do if not(IsVariableIgnored(cls.Name .. "." .. var.Name)) then table.insert(cls.UndocumentedVariables, var.Name); end @@ -706,8 +554,8 @@ function ReadDescriptions(a_API) group.Include = { group.Include }; end local NumInGroup = 0; - for idx, incl in ipairs(group.Include or {}) do - for cidx, cons in ipairs(cls.Constants) do + for _, incl in ipairs(group.Include or {}) do + for _, cons in ipairs(cls.Constants) do if ((cons.Group == nil) and cons.Name:match(incl)) then cons.Group = group; table.insert(group.Constants, cons); @@ -733,7 +581,7 @@ function ReadDescriptions(a_API) -- Remove grouped constants from the normal list: local NewConstants = {}; - for idx, cons in ipairs(cls.Constants) do + for _, cons in ipairs(cls.Constants) do if (cons.Group == nil) then table.insert(NewConstants, cons); end @@ -749,18 +597,18 @@ function ReadDescriptions(a_API) cls.UndocumentedVariables = {}; cls.Variables = cls.Variables or {}; g_Stats.NumUndocumentedClasses = g_Stats.NumUndocumentedClasses + 1; - for j, func in ipairs(cls.Functions) do + for _, func in ipairs(cls.Functions) do local FnName = func.DocID or func.Name; if not(IsFunctionIgnored(cls.Name, FnName)) then table.insert(cls.UndocumentedFunctions, FnName); end end -- for j, func - cls.Functions[] - for j, cons in ipairs(cls.Constants) do + for _, cons in ipairs(cls.Constants) do if not(IsConstantIgnored(cls.Name .. "." .. cons.Name)) then table.insert(cls.UndocumentedConstants, cons.Name); end end -- for j, cons - cls.Constants[] - for j, var in ipairs(cls.Variables) do + for _, var in ipairs(cls.Variables) do if not(IsConstantIgnored(cls.Name .. "." .. var.Name)) then table.insert(cls.UndocumentedVariables, var.Name); end @@ -769,7 +617,7 @@ function ReadDescriptions(a_API) -- Remove ignored functions: local NewFunctions = {}; - for j, fn in ipairs(cls.Functions) do + for _, fn in ipairs(cls.Functions) do if (not(IsFunctionIgnored(cls.Name, fn.Name))) then table.insert(NewFunctions, fn); end @@ -792,7 +640,7 @@ function ReadDescriptions(a_API) -- Remove ignored constants: local NewConstants = {}; - for j, cn in ipairs(cls.Constants) do + for _, cn in ipairs(cls.Constants) do if (not(IsFunctionIgnored(cls.Name, cn.Name))) then table.insert(NewConstants, cn); end @@ -808,7 +656,7 @@ function ReadDescriptions(a_API) -- Remove ignored member variables: local NewVariables = {}; - for j, var in ipairs(cls.Variables) do + for _, var in ipairs(cls.Variables) do if (not(IsVariableIgnored(cls.Name .. "." .. var.Name))) then table.insert(NewVariables, var); end @@ -824,7 +672,7 @@ function ReadDescriptions(a_API) end -- for i, cls -- Sort the descendants lists: - for i, cls in ipairs(a_API) do + for _, cls in ipairs(a_API) do table.sort(cls.Descendants, function(c1, c2) return (c1.Name < c2.Name); @@ -837,7 +685,7 @@ end -function ReadHooks(a_Hooks) +local function ReadHooks(a_Hooks) --[[ a_Hooks = { { Name = "HOOK_1"}, @@ -846,7 +694,7 @@ function ReadHooks(a_Hooks) }; We want to add hook descriptions to each hook in this array --]] - for i, hook in ipairs(a_Hooks) do + for _, hook in ipairs(a_Hooks) do local HookDesc = g_APIDesc.Hooks[hook.Name]; if (HookDesc ~= nil) then for key, val in pairs(HookDesc) do @@ -861,63 +709,10 @@ end --- Make a link out of anything with the special linkifying syntax {{link|title}} -function LinkifyString(a_String, a_Referrer) - assert(a_Referrer ~= nil); - assert(a_Referrer ~= ""); - - --- Adds a page to the list of tracked pages (to be checked for existence at the end) - local function AddTrackedPage(a_PageName) - local Pg = (g_TrackedPages[a_PageName] or {}); - table.insert(Pg, a_Referrer); - g_TrackedPages[a_PageName] = Pg; - end - - --- Creates the HTML for the specified link and title - local function CreateLink(Link, Title) - if (Link:sub(1, 7) == "http://") then - -- The link is a full absolute URL, do not modify, do not track: - return "" .. Title .. ""; - end - local idxHash = Link:find("#"); - if (idxHash ~= nil) then - -- The link contains an anchor: - if (idxHash == 1) then - -- Anchor in the current page, no need to track: - return "" .. Title .. ""; - end - -- Anchor in another page: - local PageName = Link:sub(1, idxHash - 1); - AddTrackedPage(PageName); - return "" .. Title .. ""; - end - -- Link without anchor: - AddTrackedPage(Link); - return "" .. Title .. ""; - end - - -- Linkify the strings using the CreateLink() function: - local txt = a_String:gsub("{{([^|}]*)|([^}]*)}}", CreateLink) -- {{link|title}} - txt = txt:gsub("{{([^|}]*)}}", -- {{LinkAndTitle}} - function(LinkAndTitle) - local idxHash = LinkAndTitle:find("#"); - if (idxHash ~= nil) then - -- The LinkAndTitle contains a hash, remove the hashed part from the title: - return CreateLink(LinkAndTitle, LinkAndTitle:sub(1, idxHash - 1)); - end - return CreateLink(LinkAndTitle, LinkAndTitle); - end - ); - return txt; -end - - - - - -function WriteHtmlClass(a_ClassAPI, a_AllAPI, a_ClassMenu) +local function WriteHtmlClass(a_ClassAPI, a_ClassMenu) local cf, err = io.open("API/" .. a_ClassAPI.Name .. ".html", "w"); if (cf == nil) then + LOGINFO("Cannot write HTML API for class " .. a_ClassAPI.Name .. ": " .. err) return; end @@ -931,7 +726,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI, a_ClassMenu) cf:write("

    Functions inherited from ", a_InheritedName, "

    \n"); end cf:write("\n\n"); - for i, func in ipairs(a_Functions) do + for _, func in ipairs(a_Functions) do cf:write("\n"); cf:write("\n"); cf:write("\n"); @@ -942,7 +737,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI, a_ClassMenu) local function WriteConstantTable(a_Constants, a_Source) cf:write("
    NameParametersReturn valueNotes
    ", func.Name, "", LinkifyString(func.Params or "", (a_InheritedName or a_ClassAPI.Name)), "", LinkifyString(func.Return or "", (a_InheritedName or a_ClassAPI.Name)), "
    \n\n"); - for i, cons in ipairs(a_Constants) do + for _, cons in ipairs(a_Constants) do cf:write("\n"); cf:write("\n"); cf:write("\n"); @@ -965,7 +760,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI, a_ClassMenu) WriteConstantTable(a_Constants, Source); end - for k, group in pairs(a_ConstantGroups) do + for _, group in pairs(a_ConstantGroups) do if ((a_InheritedName == nil) or group.ShowInDescendants) then cf:write("

    "); cf:write(LinkifyString(group.TextBefore or "", Source)); @@ -985,7 +780,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI, a_ClassMenu) end cf:write("

    NameValueNotes
    ", cons.Name, "", cons.Value, "", LinkifyString(cons.Notes or "", a_Source), "
    \n"); - for i, var in ipairs(a_Variables) do + for _, var in ipairs(a_Variables) do cf:write("\n"); cf:write("\n"); cf:write("\n \n"); @@ -998,7 +793,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI, a_ClassMenu) return; end cf:write("
      "); - for i, desc in ipairs(a_Descendants) do + for _, desc in ipairs(a_Descendants) do cf:write("
    • ", desc.Name, ""); WriteDescendants(desc.Descendants); cf:write("
    • \n"); @@ -1049,7 +844,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI, a_ClassMenu) local HasConstants = (#a_ClassAPI.Constants > 0) or (a_ClassAPI.NumConstantsInGroups > 0); local HasFunctions = (#a_ClassAPI.Functions > 0); local HasVariables = (#a_ClassAPI.Variables > 0); - for idx, cls in ipairs(InheritanceChain) do + for _, cls in ipairs(InheritanceChain) do HasConstants = HasConstants or (#cls.Constants > 0) or (cls.NumConstantsInGroupsForDescendants > 0); HasFunctions = HasFunctions or (#cls.Functions > 0); HasVariables = HasVariables or (#cls.Variables > 0); @@ -1088,7 +883,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI, a_ClassMenu) cf:write("

      Inheritance

      \n"); if (#InheritanceChain > 0) then cf:write("

      This class inherits from the following parent classes:

        \n"); - for i, cls in ipairs(InheritanceChain) do + for _, cls in ipairs(InheritanceChain) do cf:write("
      • ", cls.Name, "
      • \n"); end cf:write("

      \n"); @@ -1105,7 +900,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI, a_ClassMenu) cf:write("

      Constants

      \n"); WriteConstants(a_ClassAPI.Constants, a_ClassAPI.ConstantGroups, a_ClassAPI.NumConstantsInGroups, nil); g_Stats.NumTotalConstants = g_Stats.NumTotalConstants + #a_ClassAPI.Constants + (a_ClassAPI.NumConstantsInGroups or 0); - for i, cls in ipairs(InheritanceChain) do + for _, cls in ipairs(InheritanceChain) do WriteConstants(cls.Constants, cls.ConstantGroups, cls.NumConstantsInGroupsForDescendants, cls.Name); end; end; @@ -1115,102 +910,51 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI, a_ClassMenu) cf:write("

      Member variables

      \n"); WriteVariables(a_ClassAPI.Variables, nil); g_Stats.NumTotalVariables = g_Stats.NumTotalVariables + #a_ClassAPI.Variables; - for i, cls in ipairs(InheritanceChain) do + for _, cls in ipairs(InheritanceChain) do WriteVariables(cls.Variables, cls.Name); end; end - - -- Write the functions, including the inherited ones: - if (HasFunctions) then - cf:write("

      Functions

      \n"); - WriteFunctions(a_ClassAPI.Functions, nil); - g_Stats.NumTotalFunctions = g_Stats.NumTotalFunctions + #a_ClassAPI.Functions; - for i, cls in ipairs(InheritanceChain) do - WriteFunctions(cls.Functions, cls.Name); - end - end - - -- Write the additional infos: - if (a_ClassAPI.AdditionalInfo ~= nil) then - for i, additional in ipairs(a_ClassAPI.AdditionalInfo) do - cf:write("

      ", additional.Header, "

      \n"); - cf:write(LinkifyString(additional.Contents, ClassName)); - end - end - - cf:write([[
    NameTypeNotes
    ", var.Name, "", LinkifyString(var.Type or "(undocumented)", a_InheritedName or a_ClassAPI.Name), "", LinkifyString(var.Notes or "", a_InheritedName or a_ClassAPI.Name), "
    ]]); - cf:close(); -end - - - - - -function WriteHtmlHook(a_Hook, a_HookNav) - local fnam = "API/" .. a_Hook.DefaultFnName .. ".html"; - local f, error = io.open(fnam, "w"); - if (f == nil) then - LOG("Cannot write \"" .. fnam .. "\": \"" .. error .. "\"."); - return; - end - local HookName = a_Hook.DefaultFnName; - - f:write([[ - - MCServer API - ]], HookName, [[ Hook - - - - - - -
    -
    -

    ]], a_Hook.Name, [[

    -
    -
    -
    - Index:
    - Articles
    - Classes
    - Hooks
    -
    - Quick navigation:
    - ]]); - f:write(a_HookNav); - f:write([[ -

    - ]]); - f:write(LinkifyString(a_Hook.Desc, HookName)); - f:write("

    \n

    Callback function

    \n

    The default name for the callback function is "); - f:write(a_Hook.DefaultFnName, ". It has the following signature:\n"); - f:write("

    function ", HookName, "(");
    -	if (a_Hook.Params == nil) then
    -		a_Hook.Params = {};
    -	end
    -	for i, param in ipairs(a_Hook.Params) do
    -		if (i > 1) then
    -			f:write(", ");
    +	
    +	-- Write the functions, including the inherited ones:
    +	if (HasFunctions) then
    +		cf:write("

    Functions

    \n"); + WriteFunctions(a_ClassAPI.Functions, nil); + g_Stats.NumTotalFunctions = g_Stats.NumTotalFunctions + #a_ClassAPI.Functions; + for _, cls in ipairs(InheritanceChain) do + WriteFunctions(cls.Functions, cls.Name); end - f:write(param.Name); end - f:write(")
    \n

    Parameters:

    \n\n"); - for i, param in ipairs(a_Hook.Params) do - f:write("\n"); + + -- Write the additional infos: + if (a_ClassAPI.AdditionalInfo ~= nil) then + for i, additional in ipairs(a_ClassAPI.AdditionalInfo) do + cf:write("

    ", additional.Header, "

    \n"); + cf:write(LinkifyString(additional.Contents, ClassName)); + end end - f:write("
    NameTypeNotes
    ", param.Name, "", LinkifyString(param.Type, HookName), "", LinkifyString(param.Notes, HookName), "
    \n

    " .. (a_Hook.Returns or "") .. "

    \n\n"); - f:write([[

    Code examples

    Registering the callback

    ]]); - f:write("
    \n");
    -	f:write([[cPluginManager:AddHook(cPluginManager.]] .. a_Hook.Name .. ", My" .. a_Hook.DefaultFnName .. [[);]]);
    -	f:write("
    \n\n"); - local Examples = a_Hook.CodeExamples or {}; - for i, example in ipairs(Examples) do - f:write("

    ", (example.Title or "missing Title"), "

    \n"); - f:write("

    ", (example.Desc or "missing Desc"), "

    \n"); - f:write("
    ", (example.Code or "missing Code"), "\n
    \n\n"); + + cf:write([[
    ]]); + cf:close(); +end + + + + + +local function WriteClasses(f, a_API, a_ClassMenu) + f:write([[ +

    Class index

    +

    The following classes are available in the MCServer Lua scripting language: +

      + ]]); + for _, cls in ipairs(a_API) do + f:write("
    • ", cls.Name, "
    • \n"); + WriteHtmlClass(cls, a_ClassMenu); end - f:write([[]]); - f:close(); + f:write([[ +

    +
    + ]]); end @@ -1218,12 +962,12 @@ end --- Writes a list of undocumented objects into a file -function ListUndocumentedObjects(API, UndocumentedHooks) +local function ListUndocumentedObjects(API, UndocumentedHooks) f = io.open("API/_undocumented.lua", "w"); if (f ~= nil) then f:write("\n-- This is the list of undocumented API objects, automatically generated by APIDump\n\n"); f:write("g_APIDesc =\n{\n\tClasses =\n\t{\n"); - for i, cls in ipairs(API) do + for _, cls in ipairs(API) do local HasFunctions = ((cls.UndocumentedFunctions ~= nil) and (#cls.UndocumentedFunctions > 0)); local HasConstants = ((cls.UndocumentedConstants ~= nil) and (#cls.UndocumentedConstants > 0)); local HasVariables = ((cls.UndocumentedVariables ~= nil) and (#cls.UndocumentedVariables > 0)); @@ -1240,7 +984,7 @@ function ListUndocumentedObjects(API, UndocumentedHooks) if (HasFunctions) then f:write("\t\t\tFunctions =\n\t\t\t{\n"); table.sort(cls.UndocumentedFunctions); - for j, fn in ipairs(cls.UndocumentedFunctions) do + for _, fn in ipairs(cls.UndocumentedFunctions) do f:write("\t\t\t\t" .. fn .. " = { Params = \"\", Return = \"\", Notes = \"\" },\n"); end -- for j, fn - cls.UndocumentedFunctions[] f:write("\t\t\t},\n\n"); @@ -1249,7 +993,7 @@ function ListUndocumentedObjects(API, UndocumentedHooks) if (HasConstants) then f:write("\t\t\tConstants =\n\t\t\t{\n"); table.sort(cls.UndocumentedConstants); - for j, cn in ipairs(cls.UndocumentedConstants) do + for _, cn in ipairs(cls.UndocumentedConstants) do f:write("\t\t\t\t" .. cn .. " = { Notes = \"\" },\n"); end -- for j, fn - cls.UndocumentedConstants[] f:write("\t\t\t},\n\n"); @@ -1258,7 +1002,7 @@ function ListUndocumentedObjects(API, UndocumentedHooks) if (HasVariables) then f:write("\t\t\tVariables =\n\t\t\t{\n"); table.sort(cls.UndocumentedVariables); - for j, vn in ipairs(cls.UndocumentedVariables) do + for _, vn in ipairs(cls.UndocumentedVariables) do f:write("\t\t\t\t" .. vn .. " = { Type = \"\", Notes = \"\" },\n"); end -- for j, fn - cls.UndocumentedVariables[] f:write("\t\t\t},\n\n"); @@ -1306,7 +1050,7 @@ end --- Lists the API objects that are documented but not available in the API: -function ListUnexportedObjects() +local function ListUnexportedObjects() f = io.open("API/_unexported-documented.txt", "w"); if (f ~= nil) then for clsname, cls in pairs(g_APIDesc.Classes) do @@ -1338,7 +1082,7 @@ end -function ListMissingPages() +local function ListMissingPages() local MissingPages = {}; local NumLinks = 0; for PageName, Referrers in pairs(g_TrackedPages) do @@ -1368,7 +1112,7 @@ function ListMissingPages() LOGWARNING("Cannot open _missingPages.txt for writing: '" .. err .. "'. There are " .. #MissingPages .. " pages missing."); return; end - for idx, pg in ipairs(MissingPages) do + for _, pg in ipairs(MissingPages) do f:write(pg.Name .. ":\n"); -- Sort and output the referrers: table.sort(pg.Refs); @@ -1384,7 +1128,7 @@ end --- Writes the documentation statistics (in g_Stats) into the given HTML file -function WriteStats(f) +local function WriteStats(f) local function ExportMeter(a_Percent) local Color; if (a_Percent > 99) then @@ -1453,7 +1197,198 @@ end -function HandleWebAdminDump(a_Request) +local function DumpAPIHtml(a_API) + LOG("Dumping all available functions and constants to API subfolder..."); + + -- Create the output folder + if not(cFile:IsFolder("API")) then + cFile:CreateFolder("API"); + end + + LOG("Copying static files.."); + cFile:CreateFolder("API/Static"); + local localFolder = g_Plugin:GetLocalFolder(); + for _, fnam in ipairs(cFile:GetFolderContents(localFolder .. "/Static")) do + cFile:Delete("API/Static/" .. fnam); + cFile:Copy(localFolder .. "/Static/" .. fnam, "API/Static/" .. fnam); + end + + -- Extract hook constants: + local Hooks = {}; + local UndocumentedHooks = {}; + for name, obj in pairs(cPluginManager) do + if ( + (type(obj) == "number") and + name:match("HOOK_.*") and + (name ~= "HOOK_MAX") and + (name ~= "HOOK_NUM_HOOKS") + ) then + table.insert(Hooks, { Name = name }); + end + end + table.sort(Hooks, + function(Hook1, Hook2) + return (Hook1.Name < Hook2.Name); + end + ); + + -- Read in the descriptions: + LOG("Reading descriptions..."); + ReadDescriptions(a_API); + ReadHooks(Hooks); + + -- Create a "class index" file, write each class as a link to that file, + -- then dump class contents into class-specific file + LOG("Writing HTML files..."); + local f, err = io.open("API/index.html", "w"); + if (f == nil) then + LOGINFO("Cannot output HTML API: " .. err); + return; + end + + -- Create a class navigation menu that will be inserted into each class file for faster navigation (#403) + local ClassMenuTab = {}; + for _, cls in ipairs(a_API) do + table.insert(ClassMenuTab, ""); + table.insert(ClassMenuTab, cls.Name); + table.insert(ClassMenuTab, "
    "); + end + local ClassMenu = table.concat(ClassMenuTab, ""); + + -- Create a hook navigation menu that will be inserted into each hook file for faster navigation(#403) + local HookNavTab = {}; + for _, hook in ipairs(Hooks) do + table.insert(HookNavTab, ""); + table.insert(HookNavTab, (hook.Name:gsub("^HOOK_", ""))); -- remove the "HOOK_" part of the name + table.insert(HookNavTab, "
    "); + end + local HookNav = table.concat(HookNavTab, ""); + + -- Write the HTML file: + f:write([[ + + + MCServer API - Index + + + +
    +
    +

    MCServer API - Index

    +
    +
    +

    The API reference is divided into the following sections:

    + +
    + ]]); + + WriteArticles(f); + WriteClasses(f, a_API, ClassMenu); + WriteHooks(f, Hooks, UndocumentedHooks, HookNav); + + -- Copy the static files to the output folder: + local StaticFiles = + { + "main.css", + "prettify.js", + "prettify.css", + "lang-lua.js", + }; + for _, fnam in ipairs(StaticFiles) do + cFile:Delete("API/" .. fnam); + cFile:Copy(g_Plugin:GetLocalFolder() .. "/" .. fnam, "API/" .. fnam); + end + + -- List the documentation problems: + LOG("Listing leftovers..."); + ListUndocumentedObjects(a_API, UndocumentedHooks); + ListUnexportedObjects(); + ListMissingPages(); + + WriteStats(f); + + f:write([[ +
    + +]]); + f:close(); + + LOG("API subfolder written"); +end + + + + + +local function DumpApi() + LOG("Dumping the API...") + + -- Load the API descriptions from the Classes and Hooks subfolders: + -- This needs to be done each time the command is invoked because the export modifies the tables' contents + dofile(g_PluginFolder .. "/APIDesc.lua") + if (g_APIDesc.Classes == nil) then + g_APIDesc.Classes = {}; + end + if (g_APIDesc.Hooks == nil) then + g_APIDesc.Hooks = {}; + end + LoadAPIFiles("/Classes/", g_APIDesc.Classes); + LoadAPIFiles("/Hooks/", g_APIDesc.Hooks); + + -- Reset the stats: + g_TrackedPages = {}; -- List of tracked pages, to be checked later whether they exist. Each item is an array of referring pagenames. + g_Stats = -- Statistics about the documentation + { + NumTotalClasses = 0, + NumUndocumentedClasses = 0, + NumTotalFunctions = 0, + NumUndocumentedFunctions = 0, + NumTotalConstants = 0, + NumUndocumentedConstants = 0, + NumTotalVariables = 0, + NumUndocumentedVariables = 0, + NumTotalHooks = 0, + NumUndocumentedHooks = 0, + NumTrackedLinks = 0, + NumInvalidLinks = 0, + } + + -- Create the API tables: + local API, Globals = CreateAPITables(); + + -- Sort the classes by name: + table.sort(API, + function (c1, c2) + return (string.lower(c1.Name) < string.lower(c2.Name)); + end + ); + g_Stats.NumTotalClasses = #API; + + -- Add Globals into the API: + Globals.Name = "Globals"; + table.insert(API, Globals); + + -- Dump all available API object in HTML format into a subfolder: + DumpAPIHtml(API); + + LOG("APIDump finished"); + return true +end + + + + + +local function HandleWebAdminDump(a_Request) if (a_Request.PostParams["Dump"] ~= nil) then DumpApi() end @@ -1467,3 +1402,29 @@ end + +local function HandleCmdApi(a_Split) + DumpApi() + return true +end + + + + + +function Initialize(Plugin) + g_Plugin = Plugin; + g_PluginFolder = Plugin:GetLocalFolder(); + + LOG("Initialising " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) + + cPluginManager:BindConsoleCommand("api", HandleCmdApi, "Dumps the Lua API docs into the API/ subfolder") + g_Plugin:AddWebTab("APIDump", HandleWebAdminDump) + -- TODO: Add a WebAdmin tab that has a Dump button + return true +end + + + + + -- cgit v1.2.3 From e8f7c18ba75be4e62b9b0b7f55c5fe8eae1af1ec Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 19 Mar 2014 11:34:33 -0700 Subject: Fixed type error in lua bindings --- lib/tolua++/src/bin/enumerate_lua.h | 319 +++++++++++++++++----------------- lib/tolua++/src/bin/lua/enumerate.lua | 6 +- 2 files changed, 163 insertions(+), 162 deletions(-) diff --git a/lib/tolua++/src/bin/enumerate_lua.h b/lib/tolua++/src/bin/enumerate_lua.h index f460f297b..bf209519b 100644 --- a/lib/tolua++/src/bin/enumerate_lua.h +++ b/lib/tolua++/src/bin/enumerate_lua.h @@ -118,164 +118,165 @@ static const unsigned char lua_enumerate_lua[] = { 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x22, 0x69, 0x6e, 0x74, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, - 0x73, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, - 0x61, 0x6d, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x28, 0x6c, 0x75, - 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x20, 0x4c, 0x2c, 0x20, - 0x69, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x2c, 0x20, 0x69, 0x6e, 0x74, 0x20, - 0x64, 0x65, 0x66, 0x2c, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x45, - 0x72, 0x72, 0x6f, 0x72, 0x2a, 0x20, 0x65, 0x72, 0x72, 0x29, 0x22, 0x29, - 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x7b, - 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x22, 0x69, 0x66, 0x20, 0x28, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x69, 0x73, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x4c, 0x2c, 0x6c, - 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x2c, 0x65, 0x72, 0x72, 0x29, 0x29, 0x20, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x30, 0x3b, 0x22, 0x29, 0x0a, - 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x69, 0x6e, - 0x74, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x4c, - 0x2c, 0x6c, 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x29, 0x3b, 0x22, 0x29, 0x0a, - 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3e, 0x3d, 0x20, - 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x69, - 0x6e, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x26, 0x26, 0x20, 0x76, 0x61, - 0x6c, 0x20, 0x3c, 0x3d, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x3b, 0x22, + 0x22, 0x6c, 0x75, 0x61, 0x5f, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x22, 0x20, 0x2e, 0x2e, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x2e, + 0x2e, 0x20, 0x22, 0x20, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, + 0x74, 0x65, 0x2a, 0x20, 0x4c, 0x2c, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x6c, + 0x6f, 0x2c, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x64, 0x65, 0x66, 0x2c, 0x20, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x2a, + 0x20, 0x65, 0x72, 0x72, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x7b, 0x22, 0x29, 0x0a, 0x09, 0x09, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x69, 0x66, 0x20, 0x28, + 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x6e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x28, 0x4c, 0x2c, 0x6c, 0x6f, 0x2c, 0x64, 0x65, 0x66, + 0x2c, 0x65, 0x72, 0x72, 0x29, 0x29, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x30, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x22, 0x6c, 0x75, 0x61, 0x5f, 0x4e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x28, 0x4c, 0x2c, 0x6c, 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x29, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, - 0x7d, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, - 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, - 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x28, 0x74, - 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x73, - 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, - 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x45, 0x6e, 0x75, 0x6d, 0x65, - 0x72, 0x61, 0x74, 0x65, 0x29, 0x0a, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, - 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, - 0x65, 0x6e, 0x75, 0x6d, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x20, 0x69, 0x66, - 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x61, 0x6e, 0x64, - 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, - 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x69, 0x66, - 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x22, - 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x56, 0x61, - 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, - 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, - 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, - 0x3d, 0x20, 0x67, 0x65, 0x74, 0x63, 0x75, 0x72, 0x72, 0x6e, 0x61, 0x6d, - 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x29, 0x0a, 0x09, 0x09, 0x09, - 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x28, 0x22, 0x56, 0x61, 0x72, - 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x22, 0x2e, 0x2e, 0x6e, 0x73, 0x2e, - 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, - 0x6f, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3c, 0x61, 0x6e, 0x6f, - 0x6e, 0x79, 0x6d, 0x6f, 0x75, 0x73, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x3e, - 0x20, 0x69, 0x73, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, 0x64, - 0x20, 0x61, 0x73, 0x20, 0x72, 0x65, 0x61, 0x64, 0x2d, 0x6f, 0x6e, 0x6c, - 0x79, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, - 0x62, 0x6c, 0x65, 0x28, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, - 0x65, 0x61, 0x64, 0x6f, 0x6e, 0x6c, 0x79, 0x20, 0x69, 0x6e, 0x74, 0x20, - 0x22, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, - 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6e, - 0x74, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, - 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x0a, - 0x09, 0x20, 0x69, 0x66, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x74, 0x2e, 0x61, 0x63, 0x63, - 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, - 0x2e, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, - 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x0a, 0x09, 0x09, 0x74, 0x2e, - 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, - 0x73, 0x20, 0x3d, 0x20, 0x74, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, - 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, - 0x73, 0x28, 0x29, 0x0a, 0x09, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, - 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, - 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, 0x78, 0x70, 0x65, 0x63, - 0x74, 0x73, 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, - 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, - 0x74, 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x0a, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, - 0x74, 0x65, 0x20, 0x28, 0x6e, 0x2c, 0x62, 0x2c, 0x76, 0x61, 0x72, 0x6e, - 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x62, 0x20, 0x3d, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x62, 0x2c, - 0x20, 0x22, 0x2c, 0x5b, 0x25, 0x73, 0x5c, 0x6e, 0x5d, 0x2a, 0x7d, 0x22, - 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x7d, 0x22, 0x29, 0x20, 0x2d, 0x2d, 0x20, - 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x6c, 0x61, - 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, - 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x62, 0x2c, 0x32, 0x2c, 0x2d, - 0x32, 0x29, 0x2c, 0x27, 0x2c, 0x27, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x65, - 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x62, 0x72, 0x61, - 0x63, 0x65, 0x73, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, - 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, 0x7d, 0x0a, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x3d, - 0x20, 0x30, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x69, - 0x6e, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x77, 0x68, - 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, - 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x74, 0x20, 0x3d, - 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, - 0x27, 0x3d, 0x27, 0x29, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x69, 0x73, - 0x63, 0x61, 0x72, 0x64, 0x20, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, - 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x2e, 0x6e, - 0x20, 0x3d, 0x20, 0x65, 0x2e, 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x09, - 0x09, 0x65, 0x5b, 0x65, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x74, - 0x5b, 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, - 0x3d, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x74, - 0x74, 0x5b, 0x32, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, - 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x74, 0x5b, 0x32, - 0x5d, 0x20, 0x3d, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x09, 0x09, - 0x65, 0x6e, 0x64, 0x20, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x2b, - 0x20, 0x31, 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x64, 0x76, 0x61, 0x6e, 0x63, - 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, - 0x65, 0x64, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x09, 0x09, 0x69, - 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3e, 0x20, 0x6d, 0x61, - 0x78, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x61, - 0x78, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x0a, 0x09, 0x09, - 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, - 0x32, 0x5d, 0x20, 0x3c, 0x20, 0x6d, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x74, - 0x74, 0x5b, 0x32, 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, - 0x09, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x73, 0x65, 0x74, 0x20, 0x6c, 0x75, - 0x61, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x0a, 0x09, 0x69, 0x20, 0x20, - 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x65, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, - 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x63, 0x75, - 0x72, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, - 0x29, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x65, 0x5b, 0x69, - 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x65, - 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x40, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x65, - 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, - 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x74, 0x5b, 0x32, 0x5d, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x5b, 0x32, - 0x5d, 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x72, 0x65, 0x6e, - 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x29, 0x0a, - 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x2e, 0x6c, 0x6e, - 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x5b, - 0x32, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, - 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x65, 0x6e, 0x75, - 0x6d, 0x73, 0x5b, 0x20, 0x6e, 0x73, 0x2e, 0x2e, 0x65, 0x5b, 0x69, 0x5d, - 0x20, 0x5d, 0x20, 0x3d, 0x20, 0x28, 0x6e, 0x73, 0x2e, 0x2e, 0x65, 0x5b, - 0x69, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, - 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x2e, 0x6e, 0x61, - 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x6e, 0x0a, 0x09, 0x65, 0x2e, 0x6d, 0x69, - 0x6e, 0x20, 0x3d, 0x20, 0x6d, 0x69, 0x6e, 0x0a, 0x09, 0x65, 0x2e, 0x6d, - 0x61, 0x78, 0x20, 0x3d, 0x20, 0x6d, 0x61, 0x78, 0x0a, 0x09, 0x69, 0x66, - 0x20, 0x6e, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x09, 0x09, 0x54, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, - 0x22, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x6e, 0x29, 0x0a, 0x09, - 0x09, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x5b, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x22, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x69, 0x73, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x6e, 0x0a, - 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x5f, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, - 0x65, 0x2c, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, - 0x65, 0x6e, 0x64, 0x0a, 0x0a + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3e, + 0x3d, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6d, 0x69, 0x6e, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2e, 0x30, 0x20, 0x26, + 0x26, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3c, 0x3d, 0x20, 0x22, 0x20, 0x2e, + 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x2e, 0x2e, + 0x20, 0x22, 0x2e, 0x30, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x7d, 0x22, 0x29, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x49, + 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, + 0x61, 0x74, 0x65, 0x20, 0x28, 0x74, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, + 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, + 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x29, 0x0a, + 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, + 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x75, 0x6d, 0x28, 0x74, + 0x29, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, + 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x22, + 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, + 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x63, + 0x75, 0x72, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, + 0x28, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, + 0x67, 0x28, 0x22, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, + 0x22, 0x2e, 0x2e, 0x6e, 0x73, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, + 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3c, 0x61, 0x6e, 0x6f, 0x6e, 0x79, 0x6d, 0x6f, 0x75, 0x73, + 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x3e, 0x20, 0x69, 0x73, 0x20, 0x64, 0x65, + 0x63, 0x6c, 0x61, 0x72, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20, 0x72, 0x65, + 0x61, 0x64, 0x2d, 0x6f, 0x6e, 0x6c, 0x79, 0x22, 0x29, 0x0a, 0x09, 0x09, + 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x22, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x6f, 0x6e, 0x6c, + 0x79, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, 0x72, + 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x2e, 0x63, 0x75, 0x72, 0x72, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x70, + 0x61, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x74, 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, + 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x5f, + 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, + 0x73, 0x0a, 0x09, 0x09, 0x74, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, + 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x74, 0x3a, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, + 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x28, 0x29, 0x0a, 0x09, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, + 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, + 0x20, 0x45, 0x78, 0x70, 0x65, 0x63, 0x74, 0x73, 0x20, 0x61, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, + 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x65, + 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x62, 0x6f, 0x64, + 0x79, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x45, + 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x28, 0x6e, 0x2c, + 0x62, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, + 0x62, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, + 0x73, 0x75, 0x62, 0x28, 0x62, 0x2c, 0x20, 0x22, 0x2c, 0x5b, 0x25, 0x73, + 0x5c, 0x6e, 0x5d, 0x2a, 0x7d, 0x22, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x7d, + 0x22, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, + 0x61, 0x74, 0x65, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, + 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, + 0x28, 0x62, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x27, 0x2c, 0x27, + 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, + 0x74, 0x65, 0x20, 0x62, 0x72, 0x61, 0x63, 0x65, 0x73, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x6e, + 0x3d, 0x30, 0x7d, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x30, 0x0a, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x61, 0x78, 0x20, 0x3d, + 0x20, 0x30, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, + 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x74, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, + 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x3d, 0x27, 0x29, 0x20, 0x20, + 0x2d, 0x2d, 0x20, 0x64, 0x69, 0x73, 0x63, 0x61, 0x72, 0x64, 0x20, 0x69, + 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x0a, 0x09, 0x09, 0x65, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x65, 0x2e, 0x6e, + 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x09, 0x09, 0x65, 0x5b, 0x65, 0x2e, 0x6e, + 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, 0x09, + 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6e, 0x75, + 0x6d, 0x62, 0x65, 0x72, 0x28, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x29, 0x0a, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, + 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x09, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x20, 0x0a, 0x20, + 0x20, 0x09, 0x09, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x3d, 0x20, 0x74, + 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x2b, 0x20, 0x31, 0x20, 0x2d, 0x2d, 0x20, + 0x61, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, + 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x20, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, + 0x5d, 0x20, 0x3e, 0x20, 0x6d, 0x61, 0x78, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x74, 0x74, + 0x5b, 0x32, 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, + 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3c, 0x20, 0x6d, + 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6d, + 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x0a, 0x09, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, 0x69, + 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x20, + 0x73, 0x65, 0x74, 0x20, 0x6c, 0x75, 0x61, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x0a, 0x09, 0x69, 0x20, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x65, + 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, + 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, + 0x20, 0x67, 0x65, 0x74, 0x63, 0x75, 0x72, 0x72, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x29, 0x0a, 0x09, 0x77, 0x68, 0x69, + 0x6c, 0x65, 0x20, 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, + 0x70, 0x6c, 0x69, 0x74, 0x28, 0x65, 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x40, + 0x27, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, + 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x61, 0x70, + 0x70, 0x6c, 0x79, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x28, + 0x74, 0x5b, 0x31, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x09, 0x65, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x69, + 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x6f, 0x72, 0x20, + 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, + 0x61, 0x6c, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x20, 0x6e, 0x73, + 0x2e, 0x2e, 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x5d, 0x20, 0x3d, 0x20, 0x28, + 0x6e, 0x73, 0x2e, 0x2e, 0x65, 0x5b, 0x69, 0x5d, 0x29, 0x0a, 0x09, 0x09, + 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x09, 0x65, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x6e, + 0x0a, 0x09, 0x65, 0x2e, 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x6d, 0x69, + 0x6e, 0x0a, 0x09, 0x65, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x6d, + 0x61, 0x78, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x20, 0x7e, 0x3d, 0x20, + 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x54, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, 0x22, 0x69, 0x6e, 0x74, 0x20, 0x22, + 0x2e, 0x2e, 0x6e, 0x29, 0x0a, 0x09, 0x09, 0x5f, 0x69, 0x73, 0x5f, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x6e, 0x5d, 0x20, + 0x3d, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x22, + 0x20, 0x2e, 0x2e, 0x20, 0x6e, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x45, 0x6e, 0x75, 0x6d, + 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, 0x65, 0x2c, 0x20, 0x76, 0x61, 0x72, + 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a }; -unsigned int lua_enumerate_lua_len = 3329; +unsigned int lua_enumerate_lua_len = 3347; diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index 9c534a020..a00b434aa 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -54,11 +54,11 @@ _global_output_enums = {} function classEnumerate:supcode () if _global_output_enums[self.name] == nil then _global_output_enums[self.name] = 1 - output("int tolua_is" .. self.name .. " (lua_State* L, int lo, int def, tolua_Error* err)") + output("lua_Number tolua_is" .. self.name .. " (lua_State* L, int lo, int def, tolua_Error* err)") output("{") output("if (!tolua_isnumber(L,lo,def,err)) return 0;") - output("int val = tolua_tonumber(L,lo,def);") - output("return val >= " .. self.min .. " && val <= " ..self.max .. ";") + output("lua_Number val = tolua_tonumber(L,lo,def);") + output("return val >= " .. self.min .. ".0 && val <= " ..self.max .. ".0;") output("}") end end -- cgit v1.2.3 From 04adca34106a83e7ccd8d3e6107e16d79595ba6d Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 19 Mar 2014 12:02:26 -0700 Subject: Fixed tolua emitting isnumber insteand of is --- lib/tolua++/src/bin/basic_lua.h | 882 +++++++++++++++++----------------- lib/tolua++/src/bin/enumerate_lua.h | 21 +- lib/tolua++/src/bin/lua/basic.lua | 6 +- lib/tolua++/src/bin/lua/enumerate.lua | 2 +- 4 files changed, 462 insertions(+), 449 deletions(-) diff --git a/lib/tolua++/src/bin/basic_lua.h b/lib/tolua++/src/bin/basic_lua.h index 107d1a953..32536af6a 100644 --- a/lib/tolua++/src/bin/basic_lua.h +++ b/lib/tolua++/src/bin/basic_lua.h @@ -289,458 +289,466 @@ static const unsigned char lua_basic_lua[] = { 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x0a, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x2c, 0x74, 0x20, 0x3d, - 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, - 0x66, 0x28, 0x27, 0x27, 0x2c, 0x20, 0x74, 0x29, 0x0a, 0x20, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x62, 0x20, 0x3d, 0x20, 0x5f, 0x62, 0x61, 0x73, - 0x69, 0x63, 0x5b, 0x74, 0x5d, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, - 0x6e, 0x20, 0x62, 0x2c, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, 0x63, - 0x74, 0x79, 0x70, 0x65, 0x5b, 0x62, 0x5d, 0x0a, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, - 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x73, 0x70, 0x6c, - 0x69, 0x74, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x75, 0x73, - 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x0a, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x70, 0x6c, - 0x69, 0x74, 0x20, 0x28, 0x73, 0x2c, 0x74, 0x29, 0x0a, 0x20, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, - 0x7d, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, - 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x73, - 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x6c, 0x2e, - 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x20, 0x6c, 0x5b, 0x6c, 0x2e, - 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x20, 0x3d, 0x20, 0x22, - 0x25, 0x73, 0x2a, 0x28, 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2a, 0x22, 0x2e, - 0x2e, 0x74, 0x2e, 0x2e, 0x22, 0x25, 0x73, 0x2a, 0x22, 0x0a, 0x20, 0x73, - 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x5e, - 0x25, 0x73, 0x2b, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x73, 0x20, - 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x25, 0x73, - 0x2b, 0x24, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x73, 0x20, 0x3d, - 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x70, 0x2c, 0x66, 0x29, - 0x0a, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x6c, 0x2e, 0x6e, 0x20, - 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x6c, 0x5b, 0x6c, 0x2e, 0x6e, 0x5d, 0x20, - 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x28, 0x25, - 0x73, 0x25, 0x73, 0x2a, 0x29, 0x24, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, - 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x0a, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x73, - 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x75, 0x73, - 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, - 0x6e, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72, 0x69, - 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x70, 0x61, 0x63, 0x69, - 0x61, 0x6c, 0x20, 0x63, 0x61, 0x73, 0x65, 0x73, 0x20, 0x6f, 0x66, 0x20, - 0x43, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x28, 0x74, 0x65, 0x6d, 0x70, - 0x6c, 0x61, 0x74, 0x65, 0x73, 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, - 0x72, 0x73, 0x2c, 0x20, 0x65, 0x74, 0x63, 0x29, 0x0a, 0x2d, 0x2d, 0x20, - 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x20, 0x63, 0x61, 0x6e, 0x27, - 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x20, 0x74, 0x68, - 0x65, 0x20, 0x27, 0x5e, 0x27, 0x20, 0x28, 0x61, 0x73, 0x20, 0x75, 0x73, - 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, - 0x66, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x65, 0x67, 0x69, 0x6e, - 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, - 0x69, 0x6e, 0x65, 0x29, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6c, 0x73, 0x6f, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x73, 0x20, 0x77, 0x68, 0x69, 0x74, - 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, - 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x20, 0x70, 0x61, - 0x74, 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x5f, 0x69, 0x73, + 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, + 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x2c, 0x74, 0x20, + 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, 0x65, 0x64, + 0x65, 0x66, 0x28, 0x27, 0x27, 0x2c, 0x20, 0x74, 0x29, 0x0a, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x20, 0x3d, 0x20, 0x5f, 0x62, 0x61, + 0x73, 0x69, 0x63, 0x5b, 0x74, 0x5d, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x62, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x62, 0x2c, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, + 0x63, 0x74, 0x79, 0x70, 0x65, 0x5b, 0x62, 0x5d, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, + 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x73, 0x70, + 0x6c, 0x69, 0x74, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x75, + 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x70, + 0x6c, 0x69, 0x74, 0x20, 0x28, 0x73, 0x2c, 0x74, 0x29, 0x0a, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, + 0x30, 0x7d, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, + 0x3d, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, + 0x73, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x6c, + 0x2e, 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x20, 0x6c, 0x5b, 0x6c, + 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x0a, 0x20, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x20, 0x3d, 0x20, + 0x22, 0x25, 0x73, 0x2a, 0x28, 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2a, 0x22, + 0x2e, 0x2e, 0x74, 0x2e, 0x2e, 0x22, 0x25, 0x73, 0x2a, 0x22, 0x0a, 0x20, + 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, + 0x5e, 0x25, 0x73, 0x2b, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x73, + 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x25, + 0x73, 0x2b, 0x24, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x73, 0x20, + 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x70, 0x2c, 0x66, + 0x29, 0x0a, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x6c, 0x2e, 0x6e, + 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x6c, 0x5b, 0x6c, 0x2e, 0x6e, 0x5d, + 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x28, + 0x25, 0x73, 0x25, 0x73, 0x2a, 0x29, 0x24, 0x22, 0x2c, 0x22, 0x22, 0x29, + 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, + 0x73, 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x75, + 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, + 0x72, 0x6e, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72, + 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x70, 0x61, 0x63, + 0x69, 0x61, 0x6c, 0x20, 0x63, 0x61, 0x73, 0x65, 0x73, 0x20, 0x6f, 0x66, + 0x20, 0x43, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x28, 0x74, 0x65, 0x6d, + 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, + 0x65, 0x72, 0x73, 0x2c, 0x20, 0x65, 0x74, 0x63, 0x29, 0x0a, 0x2d, 0x2d, + 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x20, 0x63, 0x61, 0x6e, + 0x27, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x20, 0x74, + 0x68, 0x65, 0x20, 0x27, 0x5e, 0x27, 0x20, 0x28, 0x61, 0x73, 0x20, 0x75, + 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x69, 0x64, 0x65, 0x6e, 0x74, + 0x69, 0x66, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x65, 0x67, 0x69, + 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, + 0x6c, 0x69, 0x6e, 0x65, 0x29, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6c, 0x73, + 0x6f, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x73, 0x20, 0x77, 0x68, 0x69, + 0x74, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, + 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x20, 0x70, + 0x61, 0x74, 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, + 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, + 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, + 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x62, + 0x65, 0x67, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x65, 0x6e, + 0x64, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x6e, + 0x3d, 0x30, 0x7d, 0x0a, 0x0a, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x61, 0x64, 0x64, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x28, 0x6f, 0x66, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x5f, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x2c, 0x20, 0x6f, 0x66, + 0x73, 0x29, 0x0a, 0x09, 0x09, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, - 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, - 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, - 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x62, 0x65, - 0x67, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x65, 0x6e, 0x64, - 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, - 0x30, 0x7d, 0x0a, 0x0a, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x61, 0x64, 0x64, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x28, - 0x6f, 0x66, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x74, 0x6f, 0x6b, 0x65, - 0x6e, 0x5f, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x2c, 0x20, 0x6f, 0x66, 0x73, - 0x29, 0x0a, 0x09, 0x09, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, - 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, 0x20, 0x22, - 0x5e, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, - 0x09, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, - 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, - 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, - 0x74, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x6e, 0x20, - 0x2b, 0x20, 0x31, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x5b, 0x72, 0x65, - 0x74, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x0a, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x6f, 0x66, - 0x73, 0x20, 0x3c, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, - 0x6c, 0x65, 0x6e, 0x28, 0x73, 0x29, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x75, 0x62, 0x20, 0x3d, + 0x09, 0x09, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x25, 0x73, + 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x72, + 0x65, 0x74, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x6e, + 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x5b, 0x72, + 0x65, 0x74, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x6f, + 0x66, 0x73, 0x20, 0x3c, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x6c, 0x65, 0x6e, 0x28, 0x73, 0x29, 0x20, 0x64, 0x6f, 0x0a, 0x0a, + 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x75, 0x62, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, + 0x28, 0x73, 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x2c, 0x20, 0x2d, 0x31, 0x29, + 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, + 0x6e, 0x64, 0x28, 0x73, 0x75, 0x62, 0x2c, 0x20, 0x22, 0x5e, 0x22, 0x2e, + 0x2e, 0x70, 0x61, 0x74, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x62, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x61, 0x64, 0x64, + 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x28, 0x6f, 0x66, 0x73, 0x2d, 0x31, + 0x29, 0x0a, 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, + 0x66, 0x73, 0x2b, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x6f, 0x6b, 0x65, + 0x6e, 0x5f, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x6f, 0x66, + 0x73, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, - 0x73, 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x2c, 0x20, 0x2d, 0x31, 0x29, 0x0a, - 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x20, - 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, - 0x64, 0x28, 0x73, 0x75, 0x62, 0x2c, 0x20, 0x22, 0x5e, 0x22, 0x2e, 0x2e, - 0x70, 0x61, 0x74, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x61, 0x64, 0x64, 0x5f, - 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x28, 0x6f, 0x66, 0x73, 0x2d, 0x31, 0x29, - 0x0a, 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, - 0x73, 0x2b, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x5f, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, - 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x20, - 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, - 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x29, 0x0a, - 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, - 0x3d, 0x20, 0x22, 0x28, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x68, 0x61, - 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x3c, 0x22, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, - 0x66, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x28, - 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x20, 0x3d, 0x20, 0x22, 0x5e, 0x25, 0x62, 0x28, 0x29, 0x22, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x68, + 0x73, 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x29, + 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, + 0x3d, 0x3d, 0x20, 0x22, 0x28, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x3c, 0x22, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x20, 0x3d, 0x20, 0x22, - 0x5e, 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x62, 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x75, - 0x62, 0x2c, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x29, 0x0a, 0x09, 0x09, - 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, - 0x75, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x64, - 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x3f, 0x0a, 0x09, 0x09, 0x09, 0x09, - 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, 0x2b, 0x31, - 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, - 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, - 0x20, 0x2b, 0x20, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x0a, 0x09, 0x09, 0x09, 0x09, + 0x69, 0x66, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, + 0x28, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x20, 0x3d, 0x20, 0x22, 0x5e, 0x25, 0x62, 0x28, 0x29, 0x22, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, + 0x68, 0x61, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x3c, 0x22, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x20, 0x3d, 0x20, + 0x22, 0x5e, 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x09, 0x09, 0x09, 0x09, 0x62, 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, + 0x75, 0x62, 0x2c, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x29, 0x0a, 0x09, + 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, + 0x20, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, + 0x64, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x3f, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, 0x2b, - 0x31, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x61, 0x64, - 0x64, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x28, 0x6f, 0x66, 0x73, 0x29, - 0x0a, 0x09, 0x2d, 0x2d, 0x69, 0x66, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x6e, - 0x20, 0x3d, 0x3d, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, - 0x09, 0x2d, 0x2d, 0x09, 0x72, 0x65, 0x74, 0x2e, 0x6e, 0x3d, 0x31, 0x0a, - 0x09, 0x2d, 0x2d, 0x09, 0x72, 0x65, 0x74, 0x5b, 0x31, 0x5d, 0x20, 0x3d, - 0x20, 0x22, 0x22, 0x0a, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x0a, - 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x6f, 0x6e, - 0x63, 0x61, 0x74, 0x65, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x74, 0x61, - 0x62, 0x6c, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x20, 0x28, 0x74, 0x2c, 0x66, - 0x2c, 0x6c, 0x2c, 0x6a, 0x73, 0x74, 0x72, 0x29, 0x0a, 0x09, 0x6a, 0x73, - 0x74, 0x72, 0x20, 0x3d, 0x20, 0x6a, 0x73, 0x74, 0x72, 0x20, 0x6f, 0x72, - 0x20, 0x22, 0x20, 0x22, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x73, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x69, 0x3d, 0x66, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, - 0x20, 0x69, 0x3c, 0x3d, 0x6c, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x73, - 0x20, 0x3d, 0x20, 0x73, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x20, - 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x69, - 0x66, 0x20, 0x69, 0x20, 0x3c, 0x3d, 0x20, 0x6c, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x2e, 0x2e, 0x6a, 0x73, 0x74, - 0x72, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x0a, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x65, - 0x6e, 0x61, 0x74, 0x65, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x70, 0x61, 0x72, - 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x2c, 0x20, 0x66, 0x6f, 0x6c, - 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x20, 0x72, 0x75, 0x6c, 0x65, 0x73, 0x0a, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, - 0x61, 0x72, 0x61, 0x6d, 0x20, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x20, - 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x69, - 0x3c, 0x3d, 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x20, - 0x20, 0x69, 0x66, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x61, 0x6e, - 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, - 0x64, 0x28, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x2c, 0x27, 0x5b, 0x25, 0x28, - 0x2c, 0x22, 0x5d, 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, - 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x22, 0x5e, 0x5b, 0x25, 0x61, 0x5f, - 0x7e, 0x5d, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, - 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x6c, 0x69, - 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x27, 0x20, 0x27, 0x0a, 0x20, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, - 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x61, 0x72, 0x67, - 0x5b, 0x69, 0x5d, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x61, 0x72, 0x67, - 0x5b, 0x69, 0x5d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, - 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x72, 0x67, - 0x5b, 0x69, 0x5d, 0x2c, 0x2d, 0x31, 0x2c, 0x2d, 0x31, 0x29, 0x0a, 0x20, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, - 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, + 0x31, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x09, 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, + 0x73, 0x20, 0x2b, 0x20, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, + 0x2b, 0x31, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x61, + 0x64, 0x64, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x28, 0x6f, 0x66, 0x73, + 0x29, 0x0a, 0x09, 0x2d, 0x2d, 0x69, 0x66, 0x20, 0x72, 0x65, 0x74, 0x2e, + 0x6e, 0x20, 0x3d, 0x3d, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x72, 0x65, 0x74, 0x2e, 0x6e, 0x3d, 0x31, + 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x72, 0x65, 0x74, 0x5b, 0x31, 0x5d, 0x20, + 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x65, 0x74, + 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x6f, + 0x6e, 0x63, 0x61, 0x74, 0x65, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x74, + 0x61, 0x62, 0x6c, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x20, 0x28, 0x74, 0x2c, + 0x66, 0x2c, 0x6c, 0x2c, 0x6a, 0x73, 0x74, 0x72, 0x29, 0x0a, 0x09, 0x6a, + 0x73, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x6a, 0x73, 0x74, 0x72, 0x20, 0x6f, + 0x72, 0x20, 0x22, 0x20, 0x22, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x73, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x20, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x66, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, + 0x65, 0x20, 0x69, 0x3c, 0x3d, 0x6c, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, + 0x73, 0x20, 0x3d, 0x20, 0x73, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, + 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x69, 0x20, 0x3c, 0x3d, 0x20, 0x6c, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x2e, 0x2e, 0x6a, 0x73, + 0x74, 0x72, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, + 0x65, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x2c, 0x20, 0x66, 0x6f, + 0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x20, 0x72, 0x75, 0x6c, 0x65, 0x73, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, + 0x70, 0x61, 0x72, 0x61, 0x6d, 0x20, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, + 0x20, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, + 0x69, 0x3c, 0x3d, 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, + 0x6e, 0x64, 0x28, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x2c, 0x27, 0x5b, 0x25, + 0x28, 0x2c, 0x22, 0x5d, 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x22, 0x5e, 0x5b, 0x25, 0x61, + 0x5f, 0x7e, 0x5d, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x20, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x6c, + 0x69, 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x27, 0x20, 0x27, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, + 0x3d, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x61, 0x72, + 0x67, 0x5b, 0x69, 0x5d, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x61, 0x72, + 0x67, 0x5b, 0x69, 0x5d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x72, + 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x2d, 0x31, 0x2c, 0x2d, 0x31, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, + 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x72, 0x67, + 0x5b, 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x5d, 0x2c, 0x22, 0x5b, 0x25, 0x2f, + 0x25, 0x29, 0x25, 0x3b, 0x25, 0x7b, 0x25, 0x7d, 0x5d, 0x24, 0x22, 0x29, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x5f, 0x63, 0x6f, 0x6e, + 0x74, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, + 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x27, 0x5c, 0x6e, + 0x27, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x6c, + 0x69, 0x6e, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x28, 0x2e, 0x2e, 0x2e, + 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, + 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x69, 0x3c, 0x3d, 0x61, + 0x72, 0x67, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x69, 0x66, + 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x5f, + 0x63, 0x6f, 0x6e, 0x74, 0x2c, 0x27, 0x5b, 0x25, 0x28, 0x2c, 0x22, 0x5d, + 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x72, 0x67, 0x5b, - 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x5d, 0x2c, 0x22, 0x5b, 0x25, 0x2f, 0x25, - 0x29, 0x25, 0x3b, 0x25, 0x7b, 0x25, 0x7d, 0x5d, 0x24, 0x22, 0x29, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, - 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, - 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x27, 0x5c, 0x6e, 0x27, - 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, - 0x6e, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x6c, 0x69, - 0x6e, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x28, 0x2e, 0x2e, 0x2e, 0x29, - 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, - 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x69, 0x3c, 0x3d, 0x61, 0x72, - 0x67, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, - 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, - 0x74, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x5f, 0x63, - 0x6f, 0x6e, 0x74, 0x2c, 0x27, 0x5b, 0x25, 0x28, 0x2c, 0x22, 0x5d, 0x27, - 0x29, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, - 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, - 0x5d, 0x2c, 0x22, 0x5e, 0x5b, 0x25, 0x61, 0x5f, 0x7e, 0x5d, 0x22, 0x29, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x20, 0x77, - 0x72, 0x69, 0x74, 0x65, 0x28, 0x27, 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, - 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, - 0x20, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x20, 0x7e, 0x3d, 0x20, 0x27, - 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, - 0x6f, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, - 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x2d, 0x31, 0x2c, 0x2d, - 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, - 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, - 0x61, 0x72, 0x67, 0x5b, 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x5d, 0x2c, 0x22, - 0x5b, 0x25, 0x2f, 0x25, 0x29, 0x25, 0x3b, 0x25, 0x7b, 0x25, 0x7d, 0x5d, - 0x24, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x5f, - 0x63, 0x6f, 0x6e, 0x74, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x77, 0x72, 0x69, - 0x74, 0x65, 0x28, 0x27, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, - 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, - 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x6e, 0x61, 0x6d, 0x65, - 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, - 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, - 0x6f, 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x20, 0x61, 0x6e, 0x64, - 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, - 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x5f, 0x68, 0x6f, - 0x6f, 0x6b, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x6e, 0x61, 0x6d, - 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, + 0x69, 0x5d, 0x2c, 0x22, 0x5e, 0x5b, 0x25, 0x61, 0x5f, 0x7e, 0x5d, 0x22, + 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x20, + 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, 0x27, 0x20, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, + 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x29, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x20, 0x7e, 0x3d, 0x20, + 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, + 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x2d, 0x31, 0x2c, + 0x2d, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, + 0x28, 0x61, 0x72, 0x67, 0x5b, 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x5d, 0x2c, + 0x22, 0x5b, 0x25, 0x2f, 0x25, 0x29, 0x25, 0x3b, 0x25, 0x7b, 0x25, 0x7d, + 0x5d, 0x24, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x77, 0x72, + 0x69, 0x74, 0x65, 0x28, 0x27, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, - 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, - 0x2c, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, - 0x3d, 0x3d, 0x20, 0x22, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x22, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, - 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x73, 0x65, 0x74, 0x5f, 0x6e, - 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x22, 0x67, 0x65, 0x74, 0x5f, 0x22, 0x2e, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x2c, 0x20, 0x22, 0x73, 0x65, 0x74, 0x5f, 0x22, 0x2e, 0x2e, 0x6e, - 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, - 0x66, 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, - 0x71, 0x74, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, - 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x73, 0x65, 0x74, 0x4e, 0x61, 0x6d, - 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, - 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x73, 0x65, 0x74, 0x22, 0x2e, 0x2e, - 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x75, 0x70, 0x70, 0x65, 0x72, - 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, - 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x29, 0x29, - 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, - 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x32, 0x2c, 0x20, 0x2d, 0x31, - 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, - 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6f, 0x76, - 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x20, 0x2d, 0x2d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x6e, 0x61, + 0x73, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x6e, 0x61, 0x6d, + 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x67, 0x65, 0x74, 0x5f, + 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, + 0x68, 0x6f, 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, + 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x5f, 0x68, + 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x6e, 0x61, + 0x6d, 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, + 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, + 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x74, 0x79, 0x70, + 0x65, 0x2c, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, + 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, + 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x73, 0x65, 0x74, 0x5f, + 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x22, 0x67, 0x65, 0x74, 0x5f, 0x22, 0x2e, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x73, 0x65, 0x74, 0x5f, 0x22, 0x2e, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, + 0x22, 0x71, 0x74, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x73, 0x65, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x2d, - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x68, 0x6f, 0x6f, 0x6b, 0x73, 0x0a, 0x0a, 0x2d, - 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x72, 0x69, 0x67, - 0x68, 0x74, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, - 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x24, 0x5b, 0x69, 0x63, 0x68, 0x6c, 0x5d, 0x66, 0x69, 0x6c, 0x65, 0x20, - 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x73, 0x2c, 0x0a, - 0x2d, 0x2d, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x62, 0x65, 0x66, - 0x6f, 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x73, 0x65, 0x74, 0x22, 0x2e, + 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x75, 0x70, 0x70, 0x65, + 0x72, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, + 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x29, + 0x29, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, + 0x62, 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x32, 0x2c, 0x20, 0x2d, + 0x31, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, + 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6f, + 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x68, 0x6f, 0x6f, 0x6b, 0x73, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x72, 0x69, + 0x67, 0x68, 0x74, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x70, 0x72, + 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, + 0x20, 0x24, 0x5b, 0x69, 0x63, 0x68, 0x6c, 0x5d, 0x66, 0x69, 0x6c, 0x65, + 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x73, 0x2c, + 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x62, 0x65, + 0x66, 0x6f, 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, + 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6e, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, + 0x65, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x63, 0x6b, 0x61, + 0x67, 0x65, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x61, 0x73, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, + 0x65, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x70, 0x72, 0x65, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x68, + 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x29, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x70, + 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x68, 0x61, 0x73, 0x20, 0x61, 0x6c, + 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, + 0x63, 0x6f, 0x64, 0x65, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x70, 0x6b, 0x67, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x6f, + 0x72, 0x20, 0x65, 0x76, 0x65, 0x72, 0x79, 0x20, 0x24, 0x69, 0x66, 0x69, + 0x6c, 0x65, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, + 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x61, 0x20, + 0x74, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x63, 0x61, 0x6c, 0x6c, + 0x65, 0x64, 0x20, 0x27, 0x63, 0x6f, 0x64, 0x65, 0x27, 0x20, 0x69, 0x6e, + 0x73, 0x69, 0x64, 0x65, 0x2c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, + 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x61, 0x6e, 0x79, 0x20, 0x65, 0x78, 0x74, 0x72, 0x61, 0x20, 0x61, 0x72, + 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x70, + 0x61, 0x73, 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x24, 0x69, 0x66, + 0x69, 0x6c, 0x65, 0x2e, 0x20, 0x6e, 0x6f, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, + 0x65, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, + 0x74, 0x2c, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x20, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x61, 0x66, + 0x74, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6e, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, - 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, - 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, - 0x65, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x61, 0x73, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, - 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, - 0x72, 0x65, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x68, 0x6f, - 0x6f, 0x6b, 0x28, 0x70, 0x29, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x70, 0x2e, - 0x63, 0x6f, 0x64, 0x65, 0x20, 0x68, 0x61, 0x73, 0x20, 0x61, 0x6c, 0x6c, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x63, - 0x6f, 0x64, 0x65, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x70, 0x6b, 0x67, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, - 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x72, - 0x20, 0x65, 0x76, 0x65, 0x72, 0x79, 0x20, 0x24, 0x69, 0x66, 0x69, 0x6c, - 0x65, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x0a, - 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x61, 0x20, 0x74, - 0x61, 0x62, 0x6c, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, - 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, - 0x64, 0x20, 0x27, 0x63, 0x6f, 0x64, 0x65, 0x27, 0x20, 0x69, 0x6e, 0x73, - 0x69, 0x64, 0x65, 0x2c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, - 0x6e, 0x79, 0x20, 0x65, 0x78, 0x74, 0x72, 0x61, 0x20, 0x61, 0x72, 0x67, - 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x70, 0x61, - 0x73, 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x24, 0x69, 0x66, 0x69, - 0x6c, 0x65, 0x2e, 0x20, 0x6e, 0x6f, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x74, 0x68, 0x61, 0x74, 0x27, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x63, + 0x6f, 0x64, 0x65, 0x20, 0x28, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x27, 0x24, + 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x27, 0x2c, 0x20, 0x63, + 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2c, 0x20, 0x65, 0x74, 0x63, + 0x29, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x72, 0x69, 0x67, + 0x68, 0x74, 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x70, 0x61, + 0x72, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x63, + 0x74, 0x75, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x0a, 0x2d, + 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, + 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, 0x6f, 0x62, 0x6a, 0x65, + 0x63, 0x74, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x6c, 0x6c, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x6f, 0x6e, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x27, 0x63, 0x6f, 0x64, 0x65, 0x27, 0x20, 0x6b, + 0x65, 0x79, 0x2e, 0x20, 0x6e, 0x6f, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, - 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x74, - 0x2c, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, - 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, - 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x61, 0x66, 0x74, - 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, - 0x67, 0x20, 0x61, 0x6e, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x74, - 0x68, 0x61, 0x74, 0x27, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x63, 0x6f, - 0x64, 0x65, 0x20, 0x28, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x27, 0x24, 0x72, - 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x27, 0x2c, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2c, 0x20, 0x65, 0x74, 0x63, 0x29, - 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x72, 0x69, 0x67, 0x68, - 0x74, 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x70, 0x61, 0x72, - 0x73, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x63, 0x74, - 0x75, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x0a, 0x2d, 0x2d, - 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x50, - 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, - 0x74, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x6f, 0x6e, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x27, 0x63, 0x6f, 0x64, 0x65, 0x27, 0x20, 0x6b, 0x65, - 0x79, 0x2e, 0x20, 0x6e, 0x6f, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x70, 0x61, 0x72, 0x73, 0x65, - 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, - 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, - 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, - 0x65, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x70, 0x61, 0x72, 0x73, + 0x65, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, - 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x61, 0x66, 0x74, 0x65, - 0x72, 0x20, 0x77, 0x72, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6c, - 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x2e, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, 0x6f, - 0x62, 0x6a, 0x65, 0x63, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x6f, 0x75, 0x74, 0x70, + 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x62, 0x65, 0x66, 0x6f, + 0x72, 0x65, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74, 0x69, 0x6e, 0x67, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, - 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, + 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x61, 0x66, 0x74, + 0x65, 0x72, 0x20, 0x77, 0x72, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, + 0x6c, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x2e, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, + 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, + 0x6b, 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, + 0x72, 0x6f, 0x6d, 0x20, 0x27, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, + 0x73, 0x27, 0x20, 0x74, 0x6f, 0x20, 0x67, 0x65, 0x74, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x20, 0x74, 0x6f, + 0x20, 0x72, 0x65, 0x74, 0x72, 0x69, 0x65, 0x76, 0x65, 0x20, 0x61, 0x20, + 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x0a, 0x2d, 0x2d, 0x20, + 0x61, 0x63, 0x63, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x6f, + 0x20, 0x69, 0x74, 0x73, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, + 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, + 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, - 0x6f, 0x6d, 0x20, 0x27, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, - 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, - 0x27, 0x20, 0x74, 0x6f, 0x20, 0x67, 0x65, 0x74, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x20, 0x74, 0x6f, 0x20, - 0x72, 0x65, 0x74, 0x72, 0x69, 0x65, 0x76, 0x65, 0x20, 0x61, 0x20, 0x70, - 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x0a, 0x2d, 0x2d, 0x20, 0x61, - 0x63, 0x63, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x6f, 0x20, - 0x69, 0x74, 0x73, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, - 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, - 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x72, 0x6f, 0x70, - 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x6e, - 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x6f, 0x6d, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x64, 0x6f, 0x70, 0x61, 0x72, 0x73, + 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x20, + 0x70, 0x61, 0x72, 0x73, 0x65, 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x2c, 0x20, 0x6f, 0x72, + 0x20, 0x61, 0x20, 0x73, 0x75, 0x62, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, + 0x72, 0x73, 0x65, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x29, + 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, + 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, + 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, + 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x62, 0x65, 0x66, + 0x6f, 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x6c, 0x6c, + 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x70, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x68, 0x6f, 0x6f, + 0x6b, 0x28, 0x66, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, - 0x6d, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, - 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x64, 0x6f, 0x70, 0x61, 0x72, 0x73, 0x65, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x20, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x20, 0x70, - 0x61, 0x72, 0x73, 0x65, 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x2c, 0x20, 0x6f, 0x72, 0x20, - 0x61, 0x20, 0x73, 0x75, 0x62, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x0a, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x72, - 0x73, 0x65, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x29, 0x0a, - 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, + 0x6d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x2c, + 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, + 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x63, 0x61, 0x6c, 0x6c, + 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x66, 0x29, 0x0a, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, + 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, + 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x20, 0x63, 0x6f, 0x64, + 0x65, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, + 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x68, 0x6f, + 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, - 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x63, 0x6c, 0x61, - 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x73, - 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x62, 0x65, 0x66, 0x6f, - 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, - 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, - 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, - 0x28, 0x66, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, - 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, - 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, - 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, - 0x6c, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, - 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, - 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x66, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, - 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x72, - 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x20, 0x63, 0x6f, 0x64, 0x65, - 0x20, 0x69, 0x73, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x5f, - 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x68, 0x6f, 0x6f, - 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, - 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, - 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x20, 0x61, 0x6e, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6d, 0x65, - 0x73, 0x73, 0x61, 0x67, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x72, - 0x72, 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x2e, 0x2e, 0x2e, - 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x28, - 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, - 0x20, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x20, 0x70, 0x75, 0x73, 0x68, - 0x65, 0x72, 0x73, 0x0a, 0x0a, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, - 0x7d, 0x0a, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x74, 0x6f, - 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, - 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x70, - 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x65, - 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x65, - 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, - 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, - 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x3d, - 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, - 0x73, 0x73, 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x0a, 0x0a, 0x09, 0x77, 0x68, - 0x69, 0x6c, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x64, 0x6f, - 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, 0x5b, - 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, 0x5b, 0x63, 0x6c, 0x61, - 0x73, 0x73, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x0a, 0x09, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x3d, - 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, - 0x73, 0x73, 0x65, 0x73, 0x5b, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x62, - 0x74, 0x79, 0x70, 0x65, 0x5d, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, - 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, 0x5d, - 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, - 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x65, - 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x75, 0x73, 0x65, 0x72, 0x74, - 0x79, 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, - 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x74, - 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, - 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x74, - 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, + 0x6c, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x20, 0x61, 0x6e, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, + 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x2e, 0x2e, + 0x2e, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, + 0x28, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x20, 0x70, 0x75, 0x73, + 0x68, 0x65, 0x72, 0x73, 0x0a, 0x0a, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, + 0x7b, 0x7d, 0x0a, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x65, + 0x6e, 0x75, 0x6d, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x74, + 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, + 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, + 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x62, 0x61, 0x73, + 0x65, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x62, 0x61, 0x73, + 0x65, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, + 0x74, 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, 0x29, 0x0a, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, + 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x0a, 0x0a, 0x09, 0x77, + 0x68, 0x69, 0x6c, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x64, + 0x6f, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, + 0x5b, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x5d, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, 0x5b, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, + 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, + 0x62, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x70, 0x75, 0x73, 0x68, + 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, + 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, + 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, 0x73, + 0x65, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x75, 0x73, 0x65, 0x72, + 0x74, 0x79, 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, + 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, + 0x74, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, + 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x5b, 0x74, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, + 0x68, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, + 0x61, 0x73, 0x65, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, + 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x73, + 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, + 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x65, 0x6e, + 0x75, 0x6d, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x5f, 0x69, + 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, - 0x73, 0x65, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x73, 0x65, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, - 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, 0x0a, - 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x69, 0x73, 0x5f, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, 0x5d, - 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, - 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x65, - 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, - 0x5f, 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x22, - 0x0a, 0x65, 0x6e, 0x64, 0x0a + 0x75, 0x61, 0x5f, 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, + 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a }; -unsigned int lua_basic_lua_len = 8909; +unsigned int lua_basic_lua_len = 9007; diff --git a/lib/tolua++/src/bin/enumerate_lua.h b/lib/tolua++/src/bin/enumerate_lua.h index bf209519b..db5c1bf3f 100644 --- a/lib/tolua++/src/bin/enumerate_lua.h +++ b/lib/tolua++/src/bin/enumerate_lua.h @@ -269,14 +269,15 @@ static const unsigned char lua_enumerate_lua[] = { 0x0a, 0x09, 0x65, 0x2e, 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x6d, 0x69, 0x6e, 0x0a, 0x09, 0x65, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x6d, 0x61, 0x78, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x20, 0x7e, 0x3d, 0x20, - 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x54, 0x79, - 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, 0x22, 0x69, 0x6e, 0x74, 0x20, 0x22, - 0x2e, 0x2e, 0x6e, 0x29, 0x0a, 0x09, 0x09, 0x5f, 0x69, 0x73, 0x5f, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x6e, 0x5d, 0x20, - 0x3d, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x22, - 0x20, 0x2e, 0x2e, 0x20, 0x6e, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x45, 0x6e, 0x75, 0x6d, - 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, 0x65, 0x2c, 0x20, 0x76, 0x61, 0x72, - 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a + 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x5f, 0x65, + 0x6e, 0x75, 0x6d, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x28, 0x22, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x22, 0x20, 0x2e, 0x2e, + 0x20, 0x6e, 0x29, 0x0a, 0x09, 0x09, 0x54, 0x79, 0x70, 0x65, 0x64, 0x65, + 0x66, 0x28, 0x22, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x6e, 0x29, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x5f, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, + 0x28, 0x65, 0x2c, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a }; -unsigned int lua_enumerate_lua_len = 3347; +unsigned int lua_enumerate_lua_len = 3354; diff --git a/lib/tolua++/src/bin/lua/basic.lua b/lib/tolua++/src/bin/lua/basic.lua index f651f1fe6..d195f6dec 100644 --- a/lib/tolua++/src/bin/lua/basic.lua +++ b/lib/tolua++/src/bin/lua/basic.lua @@ -148,6 +148,9 @@ end -- check if basic type function isbasic (type) local t = gsub(type,'const ','') + if _enum_is_functions[t] then + return nil + end local m,t = applytypedef('', t) local b = _basic[t] if b then @@ -382,6 +385,7 @@ end _push_functions = {} _is_functions = {} +_enum_is_functions = {} _to_functions = {} _base_push_functions = {} @@ -410,5 +414,5 @@ function get_to_function(t) end function get_is_function(t) - return _is_functions[t] or search_base(t, _base_is_functions) or "tolua_isusertype" + return _enum_is_functions[t] or _is_functions[t] or search_base(t, _base_is_functions) or "tolua_isusertype" end diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index a00b434aa..d5d4426cf 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -130,8 +130,8 @@ function Enumerate (n,b,varname) e.min = min e.max = max if n ~= "" then + _enum_is_functions[n] = ("tolua_is" .. n) Typedef("int "..n) - _is_functions[n] = "tolua_is" .. n end return _Enumerate(e, varname) end -- cgit v1.2.3 From 363c92ed534d5cffe164079359b62a0768bc0f80 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 19 Mar 2014 12:06:12 -0700 Subject: Added unreachable lines backit prtected by preprocessor guards --- src/Defines.h | 4 ++++ src/Scoreboard.cpp | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/Defines.h b/src/Defines.h index 7f7a2eeb1..1a8b3fa4a 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -290,6 +290,10 @@ inline AString BlockFaceToString(eBlockFace a_BlockFace) case BLOCK_FACE_ZP: return "BLOCK_FACE_ZP"; case BLOCK_FACE_NONE: return "BLOCK_FACE_NONE"; } + // clang optimisises this line away then warns that it has done so. + #if !defined(__clang__) + return Printf("Unknown BLOCK_FACE: %d", a_BlockFace); + #endif } diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index cfeb1d619..4c89ce265 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -30,7 +30,13 @@ AString cObjective::TypeToString(eType a_Type) case otStatBlockMine: return "stat.mineBlock"; case otStatEntityKill: return "stat.killEntity"; case otStatEntityKilledBy: return "stat.entityKilledBy"; + + // clang optimisises this line away then warns that it has done so. + #if !defined(__clang__) + default: return ""; + #endif } + } -- cgit v1.2.3 From 6a3fe7adcc2a3855a574dbfc2bb79c86e7539f26 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 19 Mar 2014 12:38:00 -0700 Subject: Fixed bugs in patched tolua output --- lib/tolua++/CMakeLists.txt | 6 +- lib/tolua++/src/bin/basic_lua.h | 36 +- lib/tolua++/src/bin/declaration_lua.h | 1264 +++++++++++++++++++ lib/tolua++/src/bin/enumerate_lua.h | 338 ++--- lib/tolua++/src/bin/function_lua.h | 2056 ++++++++++++++++--------------- lib/tolua++/src/bin/lua/basic.lua | 15 +- lib/tolua++/src/bin/lua/declaration.lua | 2 + lib/tolua++/src/bin/lua/enumerate.lua | 8 +- lib/tolua++/src/bin/lua/function.lua | 10 + lib/tolua++/src/bin/toluabind.c | 1007 +-------------- 10 files changed, 2531 insertions(+), 2211 deletions(-) create mode 100644 lib/tolua++/src/bin/declaration_lua.h diff --git a/lib/tolua++/CMakeLists.txt b/lib/tolua++/CMakeLists.txt index 095fc152e..75a301a53 100644 --- a/lib/tolua++/CMakeLists.txt +++ b/lib/tolua++/CMakeLists.txt @@ -20,7 +20,11 @@ if(UNIX) COMMAND xxd -i lua/function.lua | sed 's/unsigned char/static const unsigned char/g' >function_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/function.lua) - set_property(SOURCE src/bin/toluabind.c APPEND PROPERTY OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h) + add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/declaration_lua.h + COMMAND xxd -i lua/declaration.lua | sed 's/unsigned char/static const unsigned char/g' >declaration_lua.h + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ + DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/declaration.lua) + set_property(SOURCE src/bin/toluabind.c APPEND PROPERTY OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h ${PROJECT_SOURCE_DIR}/src/bin/declaration_lua.h) message(hello) endif() diff --git a/lib/tolua++/src/bin/basic_lua.h b/lib/tolua++/src/bin/basic_lua.h index 32536af6a..d4b816a2c 100644 --- a/lib/tolua++/src/bin/basic_lua.h +++ b/lib/tolua++/src/bin/basic_lua.h @@ -282,17 +282,18 @@ static const unsigned char lua_basic_lua[] = { 0x65, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, - 0x69, 0x66, 0x20, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x74, 0x79, 0x70, - 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, - 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, - 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, - 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x0a, - 0x20, 0x69, 0x66, 0x20, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x5f, 0x69, 0x73, - 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, - 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x69, 0x73, 0x20, 0x65, 0x6e, 0x75, + 0x6d, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, + 0x73, 0x65, 0x6e, 0x75, 0x6d, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x65, + 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x20, 0x69, 0x66, 0x20, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x74, 0x79, + 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x28, 0x74, 0x79, 0x70, + 0x65, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, + 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x79, 0x70, 0x65, 0x2c, + 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x2c, 0x74, 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, 0x27, 0x27, 0x2c, 0x20, 0x74, 0x29, 0x0a, 0x20, 0x6c, @@ -690,8 +691,7 @@ static const unsigned char lua_basic_lua[] = { 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x65, - 0x6e, 0x75, 0x6d, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x74, + 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, @@ -740,9 +740,11 @@ static const unsigned char lua_basic_lua[] = { 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, - 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x65, 0x6e, - 0x75, 0x6d, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x5f, 0x69, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, + 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x69, 0x73, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, @@ -751,4 +753,4 @@ static const unsigned char lua_basic_lua[] = { 0x75, 0x61, 0x5f, 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a }; -unsigned int lua_basic_lua_len = 9007; +unsigned int lua_basic_lua_len = 9031; diff --git a/lib/tolua++/src/bin/declaration_lua.h b/lib/tolua++/src/bin/declaration_lua.h new file mode 100644 index 000000000..0e3486604 --- /dev/null +++ b/lib/tolua++/src/bin/declaration_lua.h @@ -0,0 +1,1264 @@ +static const unsigned char lua_declaration_lua[] = { + 0x2d, 0x2d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, 0x20, 0x64, 0x65, + 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x57, 0x72, 0x69, 0x74, 0x74, + 0x65, 0x6e, 0x20, 0x62, 0x79, 0x20, 0x57, 0x61, 0x6c, 0x64, 0x65, 0x6d, + 0x61, 0x72, 0x20, 0x43, 0x65, 0x6c, 0x65, 0x73, 0x0a, 0x2d, 0x2d, 0x20, + 0x54, 0x65, 0x43, 0x47, 0x72, 0x61, 0x66, 0x2f, 0x50, 0x55, 0x43, 0x2d, + 0x52, 0x69, 0x6f, 0x0a, 0x2d, 0x2d, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x31, + 0x39, 0x39, 0x38, 0x0a, 0x2d, 0x2d, 0x20, 0x24, 0x49, 0x64, 0x3a, 0x20, + 0x24, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x63, + 0x6f, 0x64, 0x65, 0x20, 0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, + 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x3b, 0x20, 0x79, 0x6f, + 0x75, 0x20, 0x63, 0x61, 0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, + 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69, 0x74, 0x20, 0x61, 0x6e, + 0x64, 0x2f, 0x6f, 0x72, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x20, + 0x69, 0x74, 0x2e, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x68, 0x65, 0x20, 0x73, + 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x76, + 0x69, 0x64, 0x65, 0x64, 0x20, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6e, 0x64, + 0x65, 0x72, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x20, + 0x22, 0x61, 0x73, 0x20, 0x69, 0x73, 0x22, 0x20, 0x62, 0x61, 0x73, 0x69, + 0x73, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x20, 0x68, 0x61, 0x73, + 0x20, 0x6e, 0x6f, 0x20, 0x6f, 0x62, 0x6c, 0x69, 0x67, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, + 0x65, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x61, 0x6e, 0x63, + 0x65, 0x2c, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2c, 0x20, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x73, 0x2c, 0x0a, 0x2d, 0x2d, 0x20, + 0x65, 0x6e, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, + 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x52, 0x65, + 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x76, 0x61, 0x72, + 0x69, 0x61, 0x62, 0x6c, 0x65, 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x72, 0x67, 0x75, + 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x2d, 0x2d, 0x20, 0x53, 0x74, 0x6f, + 0x72, 0x65, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x6c, 0x6c, + 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x20, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, + 0x3a, 0x0a, 0x2d, 0x2d, 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x20, 0x3d, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, + 0x65, 0x72, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x20, + 0x70, 0x74, 0x72, 0x20, 0x20, 0x3d, 0x20, 0x22, 0x2a, 0x22, 0x20, 0x6f, + 0x72, 0x20, 0x22, 0x26, 0x22, 0x2c, 0x20, 0x69, 0x66, 0x20, 0x72, 0x65, + 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, + 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x20, 0x6f, 0x72, 0x20, + 0x61, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x0a, + 0x2d, 0x2d, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x20, 0x64, 0x69, 0x6d, 0x20, + 0x20, 0x3d, 0x20, 0x64, 0x69, 0x6d, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, + 0x2c, 0x20, 0x69, 0x66, 0x20, 0x61, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, + 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x20, 0x64, 0x65, 0x66, 0x20, 0x20, 0x3d, + 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x2c, 0x20, 0x69, 0x66, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x28, + 0x6f, 0x6e, 0x6c, 0x79, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x72, 0x67, + 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x29, 0x0a, 0x2d, 0x2d, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x20, 0x20, 0x3d, 0x20, 0x22, 0x2a, 0x22, 0x20, 0x6f, + 0x72, 0x20, 0x22, 0x26, 0x22, 0x2c, 0x20, 0x69, 0x66, 0x20, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x62, 0x65, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x65, 0x64, 0x20, 0x28, 0x6f, + 0x6e, 0x6c, 0x79, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x72, 0x67, 0x75, + 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x29, 0x0a, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x3d, 0x20, 0x7b, 0x0a, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x27, + 0x27, 0x2c, 0x0a, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x27, + 0x27, 0x2c, 0x0a, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, 0x27, + 0x2c, 0x0a, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x27, + 0x2c, 0x0a, 0x20, 0x64, 0x69, 0x6d, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x2c, + 0x0a, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x2c, 0x0a, + 0x20, 0x64, 0x65, 0x66, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x7d, 0x0a, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x5f, 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78, + 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, + 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x73, 0x65, 0x74, 0x6d, + 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x65, 0x61, 0x74, 0x75, + 0x72, 0x65, 0x29, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x20, 0x61, 0x6e, 0x20, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, + 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x6e, 0x61, + 0x6d, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x76, 0x61, 0x72, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x28, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x5f, 0x76, 0x61, 0x72, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x5f, 0x76, 0x61, 0x72, 0x6e, 0x75, + 0x6d, 0x62, 0x65, 0x72, 0x20, 0x3d, 0x20, 0x30, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x5f, 0x76, 0x61, 0x72, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x20, 0x3d, 0x20, 0x5f, 0x76, 0x61, 0x72, 0x6e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x76, 0x61, 0x72, + 0x5f, 0x22, 0x2e, 0x2e, 0x5f, 0x76, 0x61, 0x72, 0x6e, 0x75, 0x6d, 0x62, + 0x65, 0x72, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, + 0x68, 0x65, 0x63, 0x6b, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x2d, 0x2d, + 0x20, 0x49, 0x74, 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x69, 0x64, 0x65, + 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x73, 0x20, 0x64, 0x65, 0x66, 0x61, + 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x28, + 0x29, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x31, 0x2c, 0x31, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x5b, 0x27, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x66, 0x69, 0x6e, 0x64, + 0x74, 0x79, 0x70, 0x65, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, + 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x27, + 0x25, 0x73, 0x25, 0x73, 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x6d, 0x5b, + 0x6d, 0x2e, 0x6e, 0x5d, 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, + 0x28, 0x6d, 0x2c, 0x31, 0x2c, 0x6d, 0x2e, 0x6e, 0x2d, 0x31, 0x29, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x3d, 0x27, + 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x3d, 0x3d, 0x32, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x31, 0x5d, + 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, + 0x3d, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x5f, + 0x76, 0x61, 0x72, 0x28, 0x74, 0x5b, 0x74, 0x2e, 0x6e, 0x5d, 0x29, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x2c, 0x22, 0x25, 0x5b, 0x28, 0x2e, 0x2d, 0x29, 0x25, 0x5d, + 0x22, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x31, 0x2c, 0x62, + 0x2d, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, + 0x69, 0x6d, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x5f, 0x65, 0x6e, + 0x75, 0x6d, 0x5f, 0x76, 0x61, 0x72, 0x28, 0x64, 0x29, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x20, 0x3d, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x76, + 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6b, 0x69, + 0x6e, 0x64, 0x3d, 0x3d, 0x27, 0x76, 0x61, 0x72, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x3d, 0x27, 0x27, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x7e, + 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x20, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x76, 0x61, 0x72, 0x6e, 0x61, + 0x6d, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, + 0x66, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x3d, 0x27, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, 0x20, 0x27, + 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x5f, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x28, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x64, 0x6a, 0x75, 0x73, 0x74, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x63, 0x68, 0x61, 0x72, + 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, + 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x27, 0x63, 0x68, 0x61, 0x72, 0x2a, 0x27, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, + 0x20, 0x27, 0x76, 0x61, 0x72, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x20, 0x22, 0x3a, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, + 0x20, 0x2d, 0x2d, 0x20, 0x3f, 0x3f, 0x3f, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x68, 0x65, + 0x63, 0x6b, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x53, + 0x75, 0x62, 0x73, 0x74, 0x69, 0x74, 0x75, 0x74, 0x65, 0x73, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x27, 0x73, 0x2e, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x29, + 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, + 0x69, 0x66, 0x20, 0x74, 0x68, 0x65, 0x72, 0x65, 0x20, 0x69, 0x73, 0x20, + 0x61, 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x20, 0x74, 0x6f, + 0x20, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x61, 0x73, 0x69, 0x63, + 0x20, 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6b, 0x69, 0x6e, 0x64, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x62, 0x61, 0x73, 0x69, 0x63, 0x3d, 0x3d, 0x27, 0x6e, 0x75, + 0x6d, 0x62, 0x65, 0x72, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x20, 0x22, 0x25, 0x2a, 0x22, + 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x5f, 0x75, + 0x73, 0x65, 0x72, 0x64, 0x61, 0x74, 0x61, 0x27, 0x0a, 0x20, 0x09, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x22, 0x22, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x62, 0x61, + 0x73, 0x69, 0x63, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x70, 0x74, 0x72, 0x7e, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x72, 0x65, 0x74, + 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x0a, + 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, + 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x69, 0x73, + 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x5f, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, 0x74, 0x61, 0x20, 0x3d, 0x20, + 0x74, 0x72, 0x75, 0x65, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x20, 0x69, 0x66, 0x20, 0x74, 0x68, 0x65, 0x72, 0x65, 0x20, + 0x69, 0x73, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x74, 0x6f, 0x20, + 0x62, 0x65, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x65, 0x64, 0x0a, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, + 0x7e, 0x3d, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x72, 0x65, 0x74, 0x7e, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, + 0x27, 0x23, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x3a, 0x20, 0x63, 0x61, 0x6e, + 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x61, + 0x6e, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x6f, 0x66, 0x20, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x73, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x65, + 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x27, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x27, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2a, 0x27, 0x0a, 0x20, + 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, + 0x74, 0x61, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x76, 0x6f, + 0x69, 0x64, 0x2a, 0x27, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, + 0x3d, 0x20, 0x27, 0x5f, 0x63, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x63, 0x68, 0x61, 0x72, 0x2a, + 0x27, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, + 0x5f, 0x6c, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x20, 0x27, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, + 0x2a, 0x27, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x72, 0x65, 0x73, 0x6f, 0x6c, 0x76, 0x65, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x73, 0x20, 0x69, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x0a, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, + 0x6f, 0x6c, 0x76, 0x65, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, + 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x28, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x2d, 0x2d, 0x0a, 0x2d, 0x2d, 0x20, 0x2d, 0x2d, 0x20, 0x69, 0x66, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x2c, 0x20, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, + 0x74, 0x69, 0x63, 0x61, 0x6c, 0x6c, 0x79, 0x20, 0x73, 0x65, 0x74, 0x20, + 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x72, 0x65, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x2d, + 0x2d, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, + 0x3d, 0x20, 0x27, 0x30, 0x27, 0x0a, 0x2d, 0x2d, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x2d, 0x2d, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x72, 0x65, 0x73, 0x6f, 0x6c, + 0x76, 0x65, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x73, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, + 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x62, 0x2c, 0x5f, 0x2c, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x74, 0x79, + 0x70, 0x65, 0x2c, 0x20, 0x22, 0x28, 0x25, 0x62, 0x3c, 0x3e, 0x29, 0x22, + 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x0a, 0x09, 0x09, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, + 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x6d, 0x2c, + 0x20, 0x32, 0x2c, 0x20, 0x2d, 0x32, 0x29, 0x2c, 0x20, 0x22, 0x2c, 0x22, + 0x29, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, 0x2c, + 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x67, 0x65, 0x74, 0x6e, 0x28, + 0x6d, 0x29, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x5b, 0x69, + 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, + 0x73, 0x75, 0x62, 0x28, 0x6d, 0x5b, 0x69, 0x5d, 0x2c, 0x22, 0x25, 0x73, + 0x2a, 0x28, 0x5b, 0x25, 0x2a, 0x26, 0x5d, 0x29, 0x22, 0x2c, 0x20, 0x22, + 0x25, 0x31, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x6d, + 0x5b, 0x69, 0x5d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x69, 0x73, 0x65, + 0x6e, 0x75, 0x6d, 0x28, 0x6d, 0x5b, 0x69, 0x5d, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x20, 0x5f, 0x2c, 0x20, 0x6d, 0x5b, 0x69, 0x5d, 0x20, 0x3d, + 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, + 0x66, 0x28, 0x22, 0x22, 0x2c, 0x20, 0x6d, 0x5b, 0x69, 0x5d, 0x29, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x6d, 0x5b, 0x69, 0x5d, + 0x20, 0x3d, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, + 0x6d, 0x5b, 0x69, 0x5d, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x6d, 0x5b, 0x69, + 0x5d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x6d, 0x5b, 0x69, 0x5d, 0x20, 0x3d, + 0x20, 0x72, 0x65, 0x73, 0x6f, 0x6c, 0x76, 0x65, 0x5f, 0x74, 0x65, 0x6d, + 0x70, 0x6c, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x28, + 0x6d, 0x5b, 0x69, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x69, 0x0a, 0x09, 0x09, 0x74, 0x79, + 0x70, 0x65, 0x2c, 0x62, 0x2c, 0x69, 0x20, 0x3d, 0x20, 0x62, 0x72, 0x65, + 0x61, 0x6b, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, + 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, + 0x74, 0x28, 0x22, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x20, 0x69, 0x73, + 0x20, 0x22, 0x2c, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x6d, 0x2c, + 0x20, 0x31, 0x2c, 0x20, 0x6d, 0x2e, 0x6e, 0x29, 0x29, 0x0a, 0x09, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, + 0x74, 0x65, 0x5f, 0x70, 0x61, 0x72, 0x74, 0x20, 0x3d, 0x20, 0x22, 0x3c, + 0x22, 0x2e, 0x2e, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x6d, 0x2c, + 0x20, 0x31, 0x2c, 0x20, 0x6d, 0x2e, 0x6e, 0x2c, 0x20, 0x22, 0x2c, 0x22, + 0x29, 0x2e, 0x2e, 0x22, 0x3e, 0x22, 0x0a, 0x09, 0x09, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, + 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, 0x74, 0x79, 0x70, + 0x65, 0x2c, 0x20, 0x62, 0x2c, 0x20, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, + 0x74, 0x65, 0x5f, 0x70, 0x61, 0x72, 0x74, 0x29, 0x0a, 0x09, 0x09, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, + 0x22, 0x3e, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x3e, 0x20, 0x3e, 0x22, 0x29, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x62, 0x72, 0x65, + 0x61, 0x6b, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, + 0x73, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, + 0x65, 0x2c, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, + 0x20, 0x22, 0x28, 0x25, 0x62, 0x3c, 0x3e, 0x29, 0x22, 0x29, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, + 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x2c, 0x20, 0x62, + 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x0a, 0x09, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, + 0x2c, 0x20, 0x30, 0x2c, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, + 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, 0x73, 0x2c, 0x20, + 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x0a, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x62, 0x20, 0x3d, 0x3d, 0x20, 0x30, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x73, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, + 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x62, 0x2d, 0x31, + 0x29, 0x2e, 0x2e, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x2e, 0x2e, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, + 0x62, 0x2c, 0x20, 0x2d, 0x31, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x6d, 0x65, 0x74, + 0x68, 0x6f, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, + 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2c, 0x63, 0x6c, 0x6f, 0x73, 0x65, + 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, + 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, + 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, + 0x6d, 0x6f, 0x64, 0x20, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2e, 0x2e, 0x22, 0x27, 0x2c, + 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, + 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, + 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, + 0x2e, 0x22, 0x20, 0x70, 0x74, 0x72, 0x20, 0x20, 0x3d, 0x20, 0x27, 0x22, + 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2e, 0x2e, + 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, + 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, + 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x64, 0x69, 0x6d, 0x20, 0x20, 0x3d, + 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, + 0x6d, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, + 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, + 0x20, 0x64, 0x65, 0x66, 0x20, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x2e, 0x2e, 0x22, 0x27, + 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, + 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x72, 0x65, 0x74, 0x20, + 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, + 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, + 0x2e, 0x22, 0x7d, 0x22, 0x2e, 0x2e, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x29, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x20, 0x69, 0x66, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, + 0x6f, 0x66, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x20, 0x61, 0x72, + 0x65, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x65, 0x64, 0x20, 0x74, + 0x6f, 0x20, 0x4c, 0x75, 0x61, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, + 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x72, 0x65, 0x71, 0x75, + 0x69, 0x72, 0x65, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x09, 0x20, + 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, + 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x09, + 0x09, 0x09, 0x09, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x69, 0x73, 0x62, 0x61, + 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, + 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x3a, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, + 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x22, 0x25, 0x73, + 0x2a, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x22, 0x2c, 0x22, + 0x22, 0x29, 0x0a, 0x09, 0x09, 0x74, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, + 0x20, 0x3d, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x63, 0x6f, + 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x5f, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x63, + 0x6c, 0x65, 0x61, 0x6e, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, + 0x65, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, + 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, 0x20, 0x74, 0x61, 0x67, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x3a, 0x64, 0x65, 0x63, 0x6c, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x28, 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x79, 0x70, 0x65, 0x76, 0x61, 0x72, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, + 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x27, 0x63, 0x6f, + 0x6e, 0x73, 0x74, 0x27, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, + 0x20, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x67, 0x73, + 0x75, 0x62, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, + 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2a, 0x27, 0x2c, 0x27, + 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x69, 0x6e, + 0x67, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x3a, 0x6f, 0x75, 0x74, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x64, 0x65, 0x66, 0x0a, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x73, + 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x64, 0x65, 0x66, 0x7e, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x64, 0x65, 0x66, 0x20, 0x3d, 0x20, 0x31, + 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x64, 0x65, 0x66, + 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, + 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x2d, + 0x2d, 0x69, 0x66, 0x20, 0x74, 0x3d, 0x3d, 0x27, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x2d, 0x2d, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x69, 0x73, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x61, + 0x72, 0x72, 0x61, 0x79, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, + 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, + 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, 0x2e, 0x2e, 0x27, 0x2c, 0x26, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x27, 0x0a, 0x09, + 0x2d, 0x2d, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x27, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, + 0x73, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, + 0x27, 0x2c, 0x30, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, + 0x72, 0x72, 0x29, 0x27, 0x0a, 0x20, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x27, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x27, 0x2e, + 0x2e, 0x74, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, + 0x2c, 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, 0x2e, 0x2e, 0x27, 0x2c, 0x26, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x27, 0x0a, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x69, 0x73, 0x65, 0x6e, + 0x75, 0x6d, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x27, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x69, 0x73, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, + 0x2c, 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, 0x2e, 0x2e, 0x27, 0x2c, 0x26, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x27, 0x0a, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, + 0x67, 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x20, + 0x6f, 0x72, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x28, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x6e, 0x69, 0x6c, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, 0x26, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x20, 0x7c, + 0x7c, 0x20, 0x21, 0x27, 0x2e, 0x2e, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, + 0x63, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, + 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, + 0x22, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x2e, 0x2e, 0x27, 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, + 0x2e, 0x2e, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, + 0x72, 0x72, 0x29, 0x29, 0x27, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x21, 0x27, + 0x2e, 0x2e, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2e, 0x2e, 0x27, + 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, + 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, 0x22, 0x27, 0x2e, 0x2e, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, + 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, 0x2e, 0x2e, 0x27, 0x2c, + 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x27, + 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x62, 0x75, 0x69, 0x6c, 0x64, + 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x28, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x20, 0x63, 0x70, 0x6c, 0x75, 0x73, + 0x70, 0x6c, 0x75, 0x73, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x3d, 0x3d, + 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, + 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, 0x27, + 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x6f, 0x64, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x63, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x25, 0x73, 0x2b, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, + 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x27, 0x2c, 0x27, 0x27, 0x29, + 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, + 0x74, 0x65, 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x6d, 0x6f, + 0x64, 0x69, 0x66, 0x69, 0x65, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, + 0x72, 0x72, 0x61, 0x79, 0x73, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x7e, + 0x3d, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x79, 0x70, 0x65, + 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, + 0x20, 0x27, 0x2a, 0x27, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x69, + 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x22, 0x20, + 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x74, + 0x79, 0x70, 0x65, 0x2c, 0x70, 0x74, 0x72, 0x29, 0x0a, 0x20, 0x69, 0x66, + 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, + 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, + 0x65, 0x2c, 0x27, 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, + 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, + 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, + 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x7e, + 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, + 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, + 0x2c, 0x27, 0x5b, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, + 0x6d, 0x2c, 0x27, 0x5d, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x63, 0x70, 0x6c, 0x75, 0x73, + 0x70, 0x6c, 0x75, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, + 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, + 0x27, 0x20, 0x3d, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, + 0x65, 0x77, 0x5f, 0x64, 0x69, 0x6d, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, + 0x65, 0x2c, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x2c, 0x20, 0x27, 0x2e, 0x2e, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x2e, 0x2e, 0x27, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, + 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, + 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, + 0x27, 0x20, 0x3d, 0x20, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x2c, + 0x70, 0x74, 0x72, 0x2c, 0x27, 0x2a, 0x29, 0x27, 0x2c, 0x0a, 0x09, 0x09, + 0x27, 0x6d, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x28, 0x28, 0x27, 0x2c, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x2c, 0x27, 0x29, 0x2a, 0x73, + 0x69, 0x7a, 0x65, 0x6f, 0x66, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, + 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x69, 0x6e, + 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x20, 0x3d, + 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x20, 0x3d, + 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, + 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, + 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x20, 0x27, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x53, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x20, 0x20, 0x09, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x28, 0x22, 0x74, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, 0x2e, 0x74, 0x6f, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x74, 0x29, 0x2e, 0x2e, 0x22, + 0x2c, 0x20, 0x70, 0x74, 0x72, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, 0x2e, + 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x70, 0x74, 0x72, 0x29, 0x29, 0x0a, 0x20, 0x20, 0x09, 0x69, + 0x66, 0x20, 0x74, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, + 0x65, 0x72, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x20, 0x22, 0x25, 0x2a, 0x22, 0x29, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x74, 0x20, 0x3d, + 0x20, 0x27, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, 0x74, 0x61, 0x27, 0x0a, + 0x20, 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x74, 0x72, + 0x3d, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x69, + 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x2a, + 0x27, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x69, 0x6e, 0x65, + 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, + 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x28, 0x28, 0x27, + 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x69, 0x6e, + 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x2a, 0x27, + 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x69, 0x6e, 0x65, + 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, + 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x29, 0x20, 0x27, + 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x69, 0x73, 0x65, 0x6e, 0x75, 0x6d, + 0x28, 0x6e, 0x63, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, + 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, + 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x28, 0x69, 0x6e, 0x74, 0x29, 0x20, 0x27, + 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x64, 0x65, 0x66, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, 0x7e, + 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x64, 0x65, 0x66, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, + 0x65, 0x66, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x28, 0x70, 0x74, 0x72, + 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x26, + 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x74, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x64, 0x65, 0x66, + 0x20, 0x3d, 0x20, 0x22, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x26, + 0x28, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x29, 0x22, 0x2e, 0x2e, 0x64, 0x65, 0x66, + 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x69, 0x66, 0x20, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, + 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, + 0x2c, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x27, 0x2e, + 0x2e, 0x74, 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, + 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x27, 0x2c, + 0x64, 0x65, 0x66, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, + 0x65, 0x74, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x6c, + 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, + 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x74, + 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, + 0x2c, 0x27, 0x2c, 0x27, 0x2c, 0x64, 0x65, 0x66, 0x2c, 0x27, 0x29, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, + 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, + 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, 0x20, 0x28, 0x6e, 0x61, 0x72, + 0x67, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x3d, 0x3d, 0x6e, 0x69, + 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, + 0x5f, 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, + 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x64, + 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x6e, + 0x61, 0x72, 0x67, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, 0x29, 0x0a, 0x09, + 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6c, + 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x62, 0x75, 0x69, + 0x6c, 0x64, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x66, 0x61, 0x6c, 0x73, 0x65, + 0x29, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, + 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x62, 0x75, 0x69, 0x6c, + 0x64, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x28, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x29, + 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x47, 0x65, 0x74, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, + 0x65, 0x74, 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x3a, 0x67, 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x28, 0x6e, + 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x7b, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, + 0x4c, 0x55, 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, + 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x64, 0x65, 0x66, 0x3b, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x64, 0x65, 0x66, 0x7e, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x20, 0x64, 0x65, 0x66, 0x3d, 0x31, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x20, 0x64, 0x65, 0x66, 0x3d, 0x30, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x69, + 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x28, 0x74, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x21, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x27, 0x2e, 0x2e, 0x74, + 0x2e, 0x2e, 0x27, 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, + 0x27, 0x2c, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, + 0x2c, 0x27, 0x2c, 0x27, 0x2c, 0x64, 0x65, 0x66, 0x2c, 0x27, 0x2c, 0x26, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x29, 0x27, + 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x20, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x28, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x61, 0x72, + 0x72, 0x61, 0x79, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x22, 0x27, 0x2c, + 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x22, 0x2c, 0x27, 0x2c, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x2c, 0x27, 0x2c, 0x27, 0x2c, 0x64, + 0x65, 0x66, 0x2c, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x65, 0x72, 0x72, 0x29, 0x29, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x20, 0x20, 0x20, 0x20, 0x67, 0x6f, 0x74, 0x6f, 0x20, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3b, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, + 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7b, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x20, 0x20, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x69, 0x3b, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x20, 0x20, 0x66, 0x6f, 0x72, 0x28, 0x69, 0x3d, 0x30, 0x3b, 0x20, 0x69, + 0x3c, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, + 0x2e, 0x2e, 0x27, 0x3b, 0x69, 0x2b, 0x2b, 0x29, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x69, + 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x74, 0x72, + 0x20, 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x7e, 0x3d, 0x27, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, + 0x2a, 0x27, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x5b, 0x69, + 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x6e, 0x6f, 0x74, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x74, + 0x72, 0x3d, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x2a, 0x27, 0x29, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x28, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x74, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x29, 0x20, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x64, + 0x65, 0x66, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, 0x7e, 0x3d, 0x20, + 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x64, 0x65, 0x66, 0x20, + 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x66, 0x69, + 0x65, 0x6c, 0x64, 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x2e, 0x27, 0x28, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, + 0x67, 0x2c, 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x27, 0x2c, 0x64, 0x65, + 0x66, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x66, + 0x69, 0x65, 0x6c, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, + 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, + 0x61, 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x27, 0x2c, + 0x64, 0x65, 0x66, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7d, 0x27, + 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x47, 0x65, 0x74, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, + 0x65, 0x74, 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x3a, 0x73, 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x28, 0x6e, + 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, + 0x75, 0x62, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x27, + 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x20, 0x20, 0x7b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x69, + 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x72, 0x28, 0x69, 0x3d, 0x30, + 0x3b, 0x20, 0x69, 0x3c, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x64, 0x69, 0x6d, 0x2e, 0x2e, 0x27, 0x3b, 0x69, 0x2b, 0x2b, 0x29, 0x27, + 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, + 0x63, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, + 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x66, 0x69, 0x65, 0x6c, + 0x64, 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, + 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x28, 0x27, 0x2c, 0x63, 0x74, 0x2c, + 0x27, 0x29, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x2c, 0x27, 0x5b, 0x69, 0x5d, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, + 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, + 0x7b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, + 0x5f, 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, + 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x76, 0x6f, 0x69, + 0x64, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, + 0x20, 0x3d, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, + 0x77, 0x28, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x29, + 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x27, 0x5b, 0x69, 0x5d, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, + 0x73, 0x68, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, + 0x79, 0x70, 0x65, 0x5f, 0x61, 0x6e, 0x64, 0x5f, 0x74, 0x61, 0x6b, 0x65, + 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x28, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, + 0x2c, 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6c, + 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, + 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x6f, 0x62, 0x6a, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x63, 0x6f, 0x70, 0x79, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, + 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x26, 0x27, 0x2c, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x5b, 0x69, + 0x5d, 0x2c, 0x73, 0x69, 0x7a, 0x65, 0x6f, 0x66, 0x28, 0x27, 0x2c, 0x74, + 0x79, 0x70, 0x65, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, + 0x73, 0x68, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, + 0x79, 0x70, 0x65, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x69, 0x2b, 0x31, + 0x2c, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x2c, 0x22, + 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, + 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, + 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x20, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x66, 0x69, 0x65, 0x6c, 0x64, + 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, + 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, + 0x29, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x27, 0x5b, 0x69, 0x5d, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x79, 0x70, + 0x65, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7d, 0x27, + 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, 0x64, 0x79, 0x6e, 0x61, + 0x6d, 0x69, 0x63, 0x61, 0x6c, 0x6c, 0x79, 0x20, 0x61, 0x6c, 0x6c, 0x6f, + 0x63, 0x61, 0x74, 0x65, 0x64, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x3a, 0x66, 0x72, 0x65, 0x65, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, + 0x28, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x3d, 0x3d, 0x6e, 0x69, + 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, + 0x5f, 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, + 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x64, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x5f, 0x64, 0x69, 0x6d, 0x28, 0x27, 0x2c, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x23, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x66, 0x72, 0x65, 0x65, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, + 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x50, 0x61, 0x73, + 0x73, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x3a, 0x70, 0x61, 0x73, 0x73, 0x70, 0x61, 0x72, 0x20, 0x28, 0x29, + 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, + 0x72, 0x3d, 0x3d, 0x27, 0x26, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x2a, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x72, 0x65, 0x74, 0x3d, 0x3d, 0x27, 0x2a, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x26, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x52, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, + 0x74, 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, + 0x72, 0x65, 0x74, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x28, 0x29, 0x0a, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x72, 0x65, 0x74, + 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x63, 0x74, + 0x20, 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x7e, 0x3d, + 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x27, 0x2e, 0x2e, 0x74, + 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x28, 0x27, 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x27, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, + 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x75, 0x73, 0x68, + 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, + 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, + 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, + 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x27, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x2c, + 0x22, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x31, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x30, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, + 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, + 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x0a, + 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, + 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, + 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x20, 0x74, + 0x3a, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x28, + 0x29, 0x0a, 0x20, 0x74, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x6e, 0x61, + 0x6d, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x74, 0x3a, 0x63, 0x68, 0x65, 0x63, + 0x6b, 0x74, 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x66, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x6e, 0x64, + 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x20, 0x6f, 0x72, 0x20, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x20, + 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x69, 0x73, 0x65, 0x6e, 0x75, + 0x6d, 0x28, 0x66, 0x74, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x74, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, + 0x65, 0x64, 0x65, 0x66, 0x28, 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, + 0x66, 0x74, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x74, 0x2e, 0x6b, 0x69, 0x6e, 0x64, 0x3d, 0x3d, 0x22, 0x76, + 0x61, 0x72, 0x22, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x28, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x74, 0x2e, 0x6d, + 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, + 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x25, 0x73, 0x22, 0x29, 0x20, + 0x6f, 0x72, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, + 0x6e, 0x64, 0x28, 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, + 0x79, 0x24, 0x22, 0x29, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x09, 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2e, 0x6d, + 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, + 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x22, 0x2c, 0x20, 0x22, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, + 0x79, 0x5f, 0x5f, 0x22, 0x2e, 0x2e, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, + 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, + 0x29, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, + 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, 0x78, 0x70, 0x65, 0x63, 0x74, + 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x2e, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x68, 0x65, 0x20, 0x6b, 0x69, 0x6e, + 0x64, 0x20, 0x6f, 0x66, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x61, 0x6e, 0x20, 0x62, 0x65, 0x20, + 0x22, 0x76, 0x61, 0x72, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x66, 0x75, + 0x6e, 0x63, 0x22, 0x2e, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x28, 0x73, 0x2c, 0x6b, 0x69, 0x6e, 0x64, 0x2c, 0x69, 0x73, + 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x29, 0x0a, + 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, + 0x74, 0x65, 0x20, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x20, 0x69, 0x66, + 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, + 0x65, 0x64, 0x0a, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x73, 0x2c, 0x22, 0x25, 0x73, 0x2a, 0x3d, 0x25, 0x73, 0x2a, 0x22, + 0x2c, 0x22, 0x3d, 0x22, 0x29, 0x0a, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, + 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x3c, + 0x22, 0x2c, 0x20, 0x22, 0x3c, 0x22, 0x29, 0x0a, 0x0a, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x64, 0x65, 0x66, 0x62, 0x2c, 0x74, 0x6d, 0x70, + 0x64, 0x65, 0x66, 0x0a, 0x20, 0x64, 0x65, 0x66, 0x62, 0x2c, 0x5f, 0x2c, + 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, + 0x22, 0x28, 0x3d, 0x2e, 0x2a, 0x29, 0x24, 0x22, 0x29, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x64, 0x65, 0x66, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x3d, 0x2e, + 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x0a, 0x20, 0x09, 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, 0x20, + 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x76, + 0x61, 0x72, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x2d, + 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, + 0x66, 0x6f, 0x72, 0x6d, 0x3a, 0x20, 0x76, 0x6f, 0x69, 0x64, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, + 0x6f, 0x72, 0x20, 0x73, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, + 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x2c, 0x20, 0x6b, 0x69, + 0x6e, 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x2c, 0x20, 0x69, + 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, + 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, + 0x65, 0x72, 0x7d, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, + 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x3a, 0x20, + 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x2a, 0x26, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, + 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, + 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x27, 0x25, 0x2a, 0x25, + 0x73, 0x2a, 0x26, 0x27, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, + 0x6e, 0x20, 0x3d, 0x3d, 0x20, 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, + 0x20, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x20, 0x20, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, + 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, + 0x74, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, + 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, + 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, + 0x27, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, + 0x65, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x2e, 0x2e, 0x74, 0x6d, + 0x70, 0x64, 0x65, 0x66, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x70, 0x74, 0x72, + 0x20, 0x3d, 0x20, 0x27, 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x72, + 0x65, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x2c, 0x0a, 0x20, 0x20, + 0x20, 0x2d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x72, 0x65, + 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, + 0x74, 0x65, 0x28, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x20, 0x74, + 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x2c, 0x0a, 0x20, + 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x6d, 0x5b, 0x6d, + 0x2e, 0x6e, 0x5d, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x20, + 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x6d, 0x2c, 0x31, + 0x2c, 0x6d, 0x2e, 0x6e, 0x2d, 0x31, 0x29, 0x2c, 0x0a, 0x20, 0x20, 0x20, + 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, + 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, + 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, 0x64, + 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, + 0x65, 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, + 0x3a, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x2a, 0x2a, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, + 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x73, 0x28, 0x73, 0x2c, 0x27, 0x25, 0x2a, 0x25, 0x73, 0x2a, 0x25, 0x2a, + 0x27, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x20, 0x3d, + 0x3d, 0x20, 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x66, + 0x75, 0x6e, 0x63, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, 0x69, 0x6e, 0x76, + 0x61, 0x6c, 0x69, 0x64, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x3a, 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, + 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, + 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x73, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, + 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, + 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, + 0x66, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, + 0x27, 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x20, + 0x3d, 0x20, 0x27, 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x2d, 0x2d, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, + 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, + 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x20, 0x74, 0x62, 0x2c, 0x20, + 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, + 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x63, + 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x6d, 0x2c, 0x31, 0x2c, 0x6d, 0x2e, + 0x6e, 0x2d, 0x31, 0x29, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x73, 0x5f, + 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, 0x3d, 0x20, + 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, + 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x20, + 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x3a, 0x20, 0x6d, + 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x26, 0x20, 0x6e, 0x61, 0x6d, + 0x65, 0x0a, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, + 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, + 0x27, 0x26, 0x27, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, + 0x20, 0x3d, 0x3d, 0x20, 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, + 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, + 0x27, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, + 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, + 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, + 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x0a, 0x20, + 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x32, + 0x5d, 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, 0x2c, 0x0a, 0x20, + 0x20, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x2c, + 0x0a, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, + 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, + 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, + 0x2c, 0x20, 0x74, 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, + 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, + 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, + 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, + 0x6d, 0x2c, 0x31, 0x2c, 0x6d, 0x2e, 0x6e, 0x2d, 0x31, 0x29, 0x2c, 0x0a, + 0x20, 0x20, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, + 0x74, 0x65, 0x72, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, + 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, + 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x7d, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, + 0x6f, 0x72, 0x6d, 0x3a, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x2a, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x73, 0x31, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x73, 0x2c, 0x22, 0x28, 0x25, 0x62, 0x5c, 0x5b, 0x5c, 0x5d, 0x29, + 0x22, 0x2c, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, + 0x6e, 0x29, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x67, 0x73, + 0x75, 0x62, 0x28, 0x6e, 0x2c, 0x27, 0x25, 0x2a, 0x27, 0x2c, 0x27, 0x5c, + 0x31, 0x27, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x29, 0x0a, 0x20, 0x74, 0x20, + 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x31, 0x2c, 0x27, 0x25, 0x2a, 0x27, + 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x20, 0x3d, 0x3d, + 0x20, 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x74, 0x5b, + 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, + 0x32, 0x5d, 0x2c, 0x27, 0x5c, 0x31, 0x27, 0x2c, 0x27, 0x25, 0x2a, 0x27, + 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x65, + 0x20, 0x2a, 0x20, 0x69, 0x6e, 0x20, 0x64, 0x69, 0x6d, 0x65, 0x6e, 0x73, + 0x69, 0x6f, 0x6e, 0x20, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, + 0x6f, 0x6e, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, + 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, + 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x73, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, + 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, + 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, + 0x66, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, + 0x27, 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x20, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x0a, 0x20, + 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x72, + 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, + 0x61, 0x74, 0x65, 0x28, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x20, + 0x74, 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x2c, 0x0a, + 0x20, 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, + 0x63, 0x61, 0x74, 0x28, 0x6d, 0x2c, 0x31, 0x2c, 0x6d, 0x2e, 0x6e, 0x2d, + 0x31, 0x29, 0x20, 0x20, 0x20, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x73, + 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, 0x3d, + 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, + 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, + 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6b, 0x69, 0x6e, 0x64, + 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x76, 0x61, 0x72, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, + 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x3a, 0x20, + 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6e, 0x61, 0x6d, + 0x65, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, + 0x6c, 0x69, 0x74, 0x28, 0x73, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, 0x2a, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, + 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, + 0x73, 0x2c, 0x27, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x5b, 0x74, + 0x2e, 0x6e, 0x5d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x76, 0x20, + 0x3d, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x76, 0x61, 0x72, + 0x6e, 0x61, 0x6d, 0x65, 0x28, 0x29, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, + 0x76, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x74, 0x2e, 0x6e, 0x5d, 0x3b, 0x20, + 0x74, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x74, 0x2e, 0x6e, 0x2d, 0x31, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, + 0x20, 0x76, 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, 0x2c, 0x0a, + 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, + 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, + 0x6c, 0x61, 0x74, 0x65, 0x28, 0x74, 0x5b, 0x74, 0x2e, 0x6e, 0x5d, 0x2c, + 0x20, 0x74, 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x2c, + 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, + 0x5b, 0x74, 0x2e, 0x6e, 0x5d, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x6f, + 0x64, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x74, + 0x2c, 0x31, 0x2c, 0x74, 0x2e, 0x6e, 0x2d, 0x31, 0x29, 0x2c, 0x0a, 0x20, + 0x20, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, + 0x65, 0x72, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, + 0x6d, 0x65, 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, + 0x6e, 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x7d, 0x0a, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x2d, 0x2d, 0x20, + 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x66, 0x75, 0x6e, + 0x63, 0x22, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x3a, + 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6e, 0x61, + 0x6d, 0x65, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x20, 0x3d, 0x20, 0x73, + 0x70, 0x6c, 0x69, 0x74, 0x28, 0x73, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, + 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, + 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, + 0x28, 0x73, 0x2c, 0x27, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x20, 0x3d, 0x20, 0x74, 0x5b, + 0x74, 0x2e, 0x6e, 0x5d, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x6c, 0x61, 0x73, + 0x74, 0x20, 0x77, 0x6f, 0x72, 0x64, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x74, 0x70, 0x2c, 0x6d, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, + 0x2e, 0x6e, 0x3e, 0x31, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x74, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x74, 0x2e, 0x6e, 0x2d, + 0x31, 0x5d, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x64, 0x20, 0x3d, 0x20, 0x63, + 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x74, 0x2c, 0x31, 0x2c, 0x74, 0x2e, + 0x6e, 0x2d, 0x32, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x2d, 0x2d, 0x69, 0x66, 0x20, 0x74, 0x70, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x20, 0x74, 0x70, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, + 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, + 0x74, 0x70, 0x2c, 0x20, 0x74, 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, + 0x6c, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, + 0x65, 0x20, 0x3d, 0x20, 0x76, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x70, 0x2c, 0x0a, 0x20, 0x20, 0x20, + 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x6d, 0x64, 0x2c, 0x0a, 0x20, 0x20, + 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, + 0x72, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, + 0x65, 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, + 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a +}; +unsigned int lua_declaration_lua_len = 15132; diff --git a/lib/tolua++/src/bin/enumerate_lua.h b/lib/tolua++/src/bin/enumerate_lua.h index db5c1bf3f..cd5bdda83 100644 --- a/lib/tolua++/src/bin/enumerate_lua.h +++ b/lib/tolua++/src/bin/enumerate_lua.h @@ -103,6 +103,20 @@ static const unsigned char lua_enumerate_lua[] = { 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x7d, 0x22, 0x2e, 0x2e, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x65, 0x6d, + 0x69, 0x74, 0x65, 0x6e, 0x75, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x74, + 0x79, 0x70, 0x65, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x69, 0x6e, 0x74, 0x20, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x22, 0x20, 0x2e, 0x2e, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x74, 0x79, 0x70, 0x65, 0x2c, 0x22, 0x3a, 0x3a, 0x22, 0x2c, 0x22, 0x5f, + 0x22, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x28, 0x6c, 0x75, 0x61, + 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x20, 0x4c, 0x2c, 0x20, 0x69, + 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x2a, 0x20, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x2a, 0x20, + 0x65, 0x72, 0x72, 0x29, 0x3b, 0x22, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, @@ -118,166 +132,166 @@ static const unsigned char lua_enumerate_lua[] = { 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x22, 0x6c, 0x75, 0x61, 0x5f, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x22, 0x20, 0x2e, 0x2e, - 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x2e, - 0x2e, 0x20, 0x22, 0x20, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, - 0x74, 0x65, 0x2a, 0x20, 0x4c, 0x2c, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x6c, - 0x6f, 0x2c, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x64, 0x65, 0x66, 0x2c, 0x20, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x2a, - 0x20, 0x65, 0x72, 0x72, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x7b, 0x22, 0x29, 0x0a, 0x09, 0x09, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x69, 0x66, 0x20, 0x28, - 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x6e, 0x75, 0x6d, - 0x62, 0x65, 0x72, 0x28, 0x4c, 0x2c, 0x6c, 0x6f, 0x2c, 0x64, 0x65, 0x66, - 0x2c, 0x65, 0x72, 0x72, 0x29, 0x29, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, - 0x6e, 0x20, 0x30, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x22, 0x6c, 0x75, 0x61, 0x5f, 0x4e, 0x75, 0x6d, - 0x62, 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, - 0x28, 0x4c, 0x2c, 0x6c, 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x29, 0x3b, 0x22, - 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3e, - 0x3d, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x6d, 0x69, 0x6e, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2e, 0x30, 0x20, 0x26, - 0x26, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3c, 0x3d, 0x20, 0x22, 0x20, 0x2e, - 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x2e, 0x2e, - 0x20, 0x22, 0x2e, 0x30, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x7d, 0x22, 0x29, 0x0a, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x49, - 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, - 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, - 0x61, 0x74, 0x65, 0x20, 0x28, 0x74, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, - 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, - 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, - 0x73, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x29, 0x0a, - 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, - 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x75, 0x6d, 0x28, 0x74, - 0x29, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, - 0x6d, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, - 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x09, 0x09, 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, - 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x22, - 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, - 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x63, - 0x75, 0x72, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, - 0x28, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, - 0x67, 0x28, 0x22, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, - 0x22, 0x2e, 0x2e, 0x6e, 0x73, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, - 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x79, 0x70, - 0x65, 0x20, 0x3c, 0x61, 0x6e, 0x6f, 0x6e, 0x79, 0x6d, 0x6f, 0x75, 0x73, - 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x3e, 0x20, 0x69, 0x73, 0x20, 0x64, 0x65, - 0x63, 0x6c, 0x61, 0x72, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20, 0x72, 0x65, - 0x61, 0x64, 0x2d, 0x6f, 0x6e, 0x6c, 0x79, 0x22, 0x29, 0x0a, 0x09, 0x09, - 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x22, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x6f, 0x6e, 0x6c, - 0x79, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, 0x72, - 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x63, 0x6c, - 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, - 0x2e, 0x63, 0x75, 0x72, 0x72, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x70, - 0x61, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x09, 0x74, 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, - 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x5f, - 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, - 0x73, 0x0a, 0x09, 0x09, 0x74, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, - 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x74, 0x3a, - 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, - 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x28, 0x29, 0x0a, 0x09, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, - 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, - 0x20, 0x45, 0x78, 0x70, 0x65, 0x63, 0x74, 0x73, 0x20, 0x61, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, - 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x65, - 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x62, 0x6f, 0x64, - 0x79, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x45, - 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x28, 0x6e, 0x2c, - 0x62, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, - 0x62, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, - 0x73, 0x75, 0x62, 0x28, 0x62, 0x2c, 0x20, 0x22, 0x2c, 0x5b, 0x25, 0x73, - 0x5c, 0x6e, 0x5d, 0x2a, 0x7d, 0x22, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x7d, - 0x22, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, - 0x61, 0x74, 0x65, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, - 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, - 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, - 0x28, 0x62, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x27, 0x2c, 0x27, - 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, - 0x74, 0x65, 0x20, 0x62, 0x72, 0x61, 0x63, 0x65, 0x73, 0x0a, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x6e, - 0x3d, 0x30, 0x7d, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x30, 0x0a, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x61, 0x78, 0x20, 0x3d, - 0x20, 0x30, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, - 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x74, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, - 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x3d, 0x27, 0x29, 0x20, 0x20, - 0x2d, 0x2d, 0x20, 0x64, 0x69, 0x73, 0x63, 0x61, 0x72, 0x64, 0x20, 0x69, - 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x0a, 0x09, 0x09, 0x65, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x65, 0x2e, 0x6e, - 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x09, 0x09, 0x65, 0x5b, 0x65, 0x2e, 0x6e, - 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, 0x09, - 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6e, 0x75, - 0x6d, 0x62, 0x65, 0x72, 0x28, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x29, 0x0a, - 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, - 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x09, 0x09, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x20, 0x0a, 0x20, - 0x20, 0x09, 0x09, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x3d, 0x20, 0x74, - 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x2b, 0x20, 0x31, 0x20, 0x2d, 0x2d, 0x20, - 0x61, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x20, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, - 0x5d, 0x20, 0x3e, 0x20, 0x6d, 0x61, 0x78, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x74, 0x74, - 0x5b, 0x32, 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, - 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3c, 0x20, 0x6d, - 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6d, - 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x0a, 0x09, - 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, 0x69, - 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x20, - 0x73, 0x65, 0x74, 0x20, 0x6c, 0x75, 0x61, 0x20, 0x6e, 0x61, 0x6d, 0x65, - 0x73, 0x0a, 0x09, 0x69, 0x20, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x65, - 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, - 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, - 0x20, 0x67, 0x65, 0x74, 0x63, 0x75, 0x72, 0x72, 0x6e, 0x61, 0x6d, 0x65, - 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x29, 0x0a, 0x09, 0x77, 0x68, 0x69, - 0x6c, 0x65, 0x20, 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, - 0x70, 0x6c, 0x69, 0x74, 0x28, 0x65, 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x40, - 0x27, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, - 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, - 0x74, 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x09, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x61, 0x70, - 0x70, 0x6c, 0x79, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x28, - 0x74, 0x5b, 0x31, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x09, 0x65, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x69, - 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x6f, 0x72, 0x20, - 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, - 0x61, 0x6c, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x20, 0x6e, 0x73, - 0x2e, 0x2e, 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x5d, 0x20, 0x3d, 0x20, 0x28, - 0x6e, 0x73, 0x2e, 0x2e, 0x65, 0x5b, 0x69, 0x5d, 0x29, 0x0a, 0x09, 0x09, - 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, - 0x0a, 0x09, 0x65, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x6e, - 0x0a, 0x09, 0x65, 0x2e, 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x6d, 0x69, - 0x6e, 0x0a, 0x09, 0x65, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x6d, - 0x61, 0x78, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x20, 0x7e, 0x3d, 0x20, - 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x5f, 0x65, - 0x6e, 0x75, 0x6d, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x28, 0x22, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x22, 0x20, 0x2e, 0x2e, - 0x20, 0x6e, 0x29, 0x0a, 0x09, 0x09, 0x54, 0x79, 0x70, 0x65, 0x64, 0x65, - 0x66, 0x28, 0x22, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x6e, 0x29, - 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, - 0x6e, 0x20, 0x5f, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, - 0x28, 0x65, 0x2c, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, - 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a + 0x22, 0x69, 0x6e, 0x74, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, + 0x73, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x3a, 0x3a, 0x22, 0x2c, 0x22, 0x5f, 0x22, + 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x28, 0x6c, 0x75, 0x61, 0x5f, + 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x20, 0x4c, 0x2c, 0x20, 0x69, 0x6e, + 0x74, 0x20, 0x6c, 0x6f, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, + 0x63, 0x68, 0x61, 0x72, 0x20, 0x2a, 0x20, 0x74, 0x79, 0x70, 0x65, 0x2c, + 0x20, 0x69, 0x6e, 0x74, 0x20, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x2a, 0x20, 0x65, + 0x72, 0x72, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x22, 0x7b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x69, 0x66, 0x20, 0x28, 0x21, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x6e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x28, 0x4c, 0x2c, 0x6c, 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x2c, 0x65, + 0x72, 0x72, 0x29, 0x29, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x30, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x22, 0x6c, 0x75, 0x61, 0x5f, 0x4e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x4c, + 0x2c, 0x6c, 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x29, 0x3b, 0x22, 0x29, 0x0a, + 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3e, 0x3d, 0x20, + 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x69, + 0x6e, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2e, 0x30, 0x20, 0x26, 0x26, 0x20, + 0x76, 0x61, 0x6c, 0x20, 0x3c, 0x3d, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x2e, 0x2e, 0x20, 0x22, + 0x2e, 0x30, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x22, 0x7d, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x49, 0x6e, 0x74, + 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, + 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x5f, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, + 0x65, 0x20, 0x28, 0x74, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, + 0x29, 0x0a, 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, + 0x62, 0x6c, 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x45, + 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x29, 0x0a, 0x20, 0x61, + 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x61, 0x70, + 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x75, 0x6d, 0x28, 0x74, 0x29, 0x0a, + 0x09, 0x20, 0x69, 0x66, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, + 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x65, + 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x63, 0x75, 0x72, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x29, + 0x0a, 0x09, 0x09, 0x09, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x28, + 0x22, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x22, 0x2e, + 0x2e, 0x6e, 0x73, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, + 0x2e, 0x2e, 0x22, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3c, 0x61, 0x6e, 0x6f, 0x6e, 0x79, 0x6d, 0x6f, 0x75, 0x73, 0x20, 0x65, + 0x6e, 0x75, 0x6d, 0x3e, 0x20, 0x69, 0x73, 0x20, 0x64, 0x65, 0x63, 0x6c, + 0x61, 0x72, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20, 0x72, 0x65, 0x61, 0x64, + 0x2d, 0x6f, 0x6e, 0x6c, 0x79, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x56, + 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x22, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x6f, 0x6e, 0x6c, 0x79, 0x20, + 0x69, 0x6e, 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, + 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, + 0x61, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, + 0x75, 0x72, 0x72, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x74, + 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x70, 0x61, + 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x6d, 0x65, + 0x6d, 0x62, 0x65, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x0a, + 0x09, 0x09, 0x74, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x61, + 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x74, 0x3a, 0x63, 0x68, + 0x65, 0x63, 0x6b, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, + 0x63, 0x63, 0x65, 0x73, 0x73, 0x28, 0x29, 0x0a, 0x09, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, + 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, + 0x78, 0x70, 0x65, 0x63, 0x74, 0x73, 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, + 0x74, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x65, 0x6e, 0x75, + 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x45, 0x6e, 0x75, + 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x28, 0x6e, 0x2c, 0x62, 0x2c, + 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x62, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x62, 0x2c, 0x20, 0x22, 0x2c, 0x5b, 0x25, 0x73, 0x5c, 0x6e, + 0x5d, 0x2a, 0x7d, 0x22, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x7d, 0x22, 0x29, + 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, + 0x65, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, + 0x6c, 0x69, 0x74, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x62, + 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x27, 0x2c, 0x27, 0x29, 0x20, + 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, + 0x20, 0x62, 0x72, 0x61, 0x63, 0x65, 0x73, 0x0a, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, + 0x7d, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x30, + 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, 0x69, 0x5d, + 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x74, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, + 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x3d, 0x27, 0x29, 0x20, 0x20, 0x2d, 0x2d, + 0x20, 0x64, 0x69, 0x73, 0x63, 0x61, 0x72, 0x64, 0x20, 0x69, 0x6e, 0x69, + 0x74, 0x69, 0x61, 0x6c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x09, + 0x09, 0x65, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x65, 0x2e, 0x6e, 0x20, 0x2b, + 0x20, 0x31, 0x0a, 0x09, 0x09, 0x65, 0x5b, 0x65, 0x2e, 0x6e, 0x5d, 0x20, + 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x74, 0x74, + 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, + 0x65, 0x72, 0x28, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x29, 0x0a, 0x09, 0x09, + 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x3d, 0x20, + 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x20, 0x0a, 0x20, 0x20, 0x09, + 0x09, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, + 0x32, 0x5d, 0x20, 0x2b, 0x20, 0x31, 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x64, + 0x76, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65, + 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, + 0x3e, 0x20, 0x6d, 0x61, 0x78, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x09, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, + 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, + 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3c, 0x20, 0x6d, 0x69, 0x6e, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x69, 0x6e, + 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x73, 0x65, + 0x74, 0x20, 0x6c, 0x75, 0x61, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x0a, + 0x09, 0x69, 0x20, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x65, 0x2e, 0x6c, + 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x67, + 0x65, 0x74, 0x63, 0x75, 0x72, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, + 0x61, 0x63, 0x65, 0x28, 0x29, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, + 0x20, 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, + 0x69, 0x74, 0x28, 0x65, 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x40, 0x27, 0x29, + 0x0a, 0x09, 0x09, 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x5b, + 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x09, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, + 0x79, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x28, 0x74, 0x5b, + 0x31, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, + 0x65, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x20, + 0x3d, 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x5b, + 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, + 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x20, 0x6e, 0x73, 0x2e, 0x2e, + 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x5d, 0x20, 0x3d, 0x20, 0x28, 0x6e, 0x73, + 0x2e, 0x2e, 0x65, 0x5b, 0x69, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x20, + 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x65, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x6e, 0x0a, 0x09, + 0x65, 0x2e, 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x6d, 0x69, 0x6e, 0x0a, + 0x09, 0x65, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x6d, 0x61, 0x78, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x5f, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x5b, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x09, + 0x54, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, 0x22, 0x69, 0x6e, 0x74, + 0x20, 0x22, 0x2e, 0x2e, 0x6e, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x45, 0x6e, 0x75, + 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, 0x65, 0x2c, 0x20, 0x76, 0x61, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a }; -unsigned int lua_enumerate_lua_len = 3354; +unsigned int lua_enumerate_lua_len = 3528; diff --git a/lib/tolua++/src/bin/function_lua.h b/lib/tolua++/src/bin/function_lua.h index 705cb1a8f..544a6f8a8 100644 --- a/lib/tolua++/src/bin/function_lua.h +++ b/lib/tolua++/src/bin/function_lua.h @@ -120,228 +120,202 @@ static const unsigned char lua_function_lua[] = { 0x74, 0x69, 0x63, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x27, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x29, - 0x27, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x3d, - 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x66, - 0x6c, 0x61, 0x67, 0x73, 0x2e, 0x70, 0x75, 0x72, 0x65, 0x5f, 0x76, 0x69, - 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, - 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x6e, 0x6f, 0x20, 0x63, 0x6f, 0x6e, 0x73, - 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, - 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, - 0x20, 0x70, 0x75, 0x72, 0x65, 0x20, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, - 0x6c, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x0a, 0x20, 0x09, - 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, - 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x6d, 0x65, 0x74, 0x68, - 0x6f, 0x64, 0x3a, 0x20, 0x6e, 0x65, 0x77, 0x5f, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x22, - 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2c, 0x22, 0x20, 0x2a, 0x2f, 0x22, - 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x6d, 0x65, 0x74, - 0x68, 0x6f, 0x64, 0x3a, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, - 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x6c, 0x61, - 0x73, 0x73, 0x20, 0x22, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2c, 0x22, - 0x20, 0x2a, 0x2f, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, - 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x3a, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, - 0x6d, 0x65, 0x2c, 0x22, 0x20, 0x2a, 0x2f, 0x22, 0x29, 0x0a, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, - 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x22, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, - 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, - 0x4c, 0x45, 0x5f, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, - 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x5f, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x22, 0x5c, 0x6e, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x69, - 0x6e, 0x74, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, - 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, - 0x2c, 0x22, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, - 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x22, 0x29, - 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x22, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, - 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, - 0x4c, 0x45, 0x5f, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, - 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x22, 0x5c, 0x6e, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, - 0x20, 0x69, 0x6e, 0x74, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, - 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x53, 0x29, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x7b, 0x22, 0x29, 0x0a, 0x0a, - 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x79, - 0x70, 0x65, 0x73, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, - 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, - 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, 0x27, - 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x45, - 0x72, 0x72, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, - 0x72, 0x72, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x27, 0x20, 0x69, 0x66, 0x20, 0x28, 0x5c, 0x6e, 0x27, 0x29, - 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, - 0x61, 0x72, 0x67, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, - 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, - 0x32, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, - 0x31, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, - 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, - 0x67, 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, - 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, - 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, - 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, - 0x65, 0x77, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, - 0x63, 0x7e, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x27, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, - 0x61, 0x62, 0x6c, 0x65, 0x27, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x79, 0x70, - 0x65, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, - 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x79, 0x70, - 0x65, 0x20, 0x3d, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x22, - 0x2e, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, - 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x21, 0x27, 0x2e, 0x2e, 0x66, 0x75, 0x6e, 0x63, - 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, - 0x31, 0x2c, 0x22, 0x27, 0x2e, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, - 0x27, 0x22, 0x2c, 0x30, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x65, 0x72, 0x72, 0x29, 0x20, 0x7c, 0x7c, 0x5c, 0x6e, 0x27, 0x29, 0x0a, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, - 0x63, 0x6b, 0x20, 0x61, 0x72, 0x67, 0x73, 0x0a, 0x20, 0x69, 0x66, 0x20, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, - 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, - 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x77, - 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, - 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x74, 0x79, 0x70, 0x65, 0x20, - 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x74, - 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x62, 0x74, 0x79, 0x70, - 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x20, 0x27, - 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, - 0x69, 0x5d, 0x3a, 0x6f, 0x75, 0x74, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x74, - 0x79, 0x70, 0x65, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x2e, 0x2e, 0x27, - 0x20, 0x7c, 0x7c, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x74, 0x79, - 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, 0x74, 0x65, - 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x6e, - 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, - 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, - 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, - 0x65, 0x63, 0x6b, 0x20, 0x65, 0x6e, 0x64, 0x20, 0x6f, 0x66, 0x20, 0x6c, - 0x69, 0x73, 0x74, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x20, 0x20, 0x20, 0x20, 0x20, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, - 0x5f, 0x69, 0x73, 0x6e, 0x6f, 0x6f, 0x62, 0x6a, 0x28, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, - 0x2e, 0x2e, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, - 0x72, 0x72, 0x29, 0x5c, 0x6e, 0x20, 0x29, 0x27, 0x29, 0x0a, 0x09, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x67, 0x6f, 0x74, - 0x6f, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, - 0x6f, 0x72, 0x3b, 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x27, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, - 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, - 0x61, 0x64, 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, - 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, - 0x7b, 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x63, - 0x6c, 0x61, 0x72, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2c, 0x20, 0x69, - 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x73, 0x65, 0x0a, 0x20, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x0a, 0x20, - 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, 0x73, - 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, - 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, - 0x7e, 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, - 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x27, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, - 0x6f, 0x6e, 0x73, 0x74, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, - 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x2a, - 0x27, 0x2c, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x20, 0x3d, 0x20, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x28, - 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, - 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, - 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x2a, 0x29, 0x20, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x5f, - 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x74, - 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x74, - 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x31, 0x2c, 0x30, 0x29, - 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, - 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x20, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, - 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, - 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x27, 0x5e, - 0x25, 0x73, 0x2a, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x25, 0x73, 0x25, - 0x73, 0x2a, 0x28, 0x2e, 0x2a, 0x29, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, - 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, + 0x27, 0x29, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x74, 0x79, 0x70, 0x65, 0x73, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x65, 0x6e, + 0x75, 0x6d, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, - 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, - 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, - 0x65, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, - 0x66, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x74, - 0x79, 0x70, 0x65, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x73, 0x74, 0x61, - 0x74, 0x65, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, - 0x20, 0x6e, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, - 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, - 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, - 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, + 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x69, 0x73, 0x65, 0x6e, + 0x75, 0x6d, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, + 0x5b, 0x69, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6d, 0x69, 0x74, + 0x65, 0x6e, 0x75, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x74, 0x79, 0x70, + 0x65, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, + 0x69, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, + 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, + 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x66, 0x6c, + 0x61, 0x67, 0x73, 0x2e, 0x70, 0x75, 0x72, 0x65, 0x5f, 0x76, 0x69, 0x72, + 0x74, 0x75, 0x61, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, + 0x09, 0x2d, 0x2d, 0x20, 0x6e, 0x6f, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, + 0x70, 0x75, 0x72, 0x65, 0x20, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, + 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x0a, 0x20, 0x09, 0x09, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, + 0x64, 0x3a, 0x20, 0x6e, 0x65, 0x77, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6f, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x22, 0x2c, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2c, 0x22, 0x20, 0x2a, 0x2f, 0x22, 0x29, + 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x6d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x3a, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x2c, 0x22, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x20, 0x22, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2c, 0x22, 0x20, + 0x2a, 0x2f, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, + 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x3a, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x2c, 0x22, 0x20, 0x2a, 0x2f, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x22, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, + 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, + 0x45, 0x5f, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, + 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x22, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x22, 0x5c, 0x6e, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x69, 0x6e, + 0x74, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, + 0x65, 0x2e, 0x2e, 0x22, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x2c, + 0x22, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, + 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x22, 0x29, 0x0a, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x22, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, + 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, + 0x45, 0x5f, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, + 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x22, 0x5c, 0x6e, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, + 0x69, 0x6e, 0x74, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, + 0x29, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x7b, 0x22, 0x29, 0x0a, 0x0a, 0x20, + 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x73, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, + 0x6f, 0x61, 0x64, 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, + 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, + 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, 0x27, 0x29, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x45, 0x72, + 0x72, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, + 0x72, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x69, 0x66, 0x20, 0x28, 0x5c, 0x6e, 0x27, 0x29, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, + 0x72, 0x67, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, + 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, + 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, + 0x77, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, + 0x7e, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x27, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, 0x61, + 0x62, 0x6c, 0x65, 0x27, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x22, 0x2e, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x21, 0x27, 0x2e, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x2e, + 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x31, + 0x2c, 0x22, 0x27, 0x2e, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, + 0x22, 0x2c, 0x30, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, + 0x72, 0x72, 0x29, 0x20, 0x7c, 0x7c, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, + 0x6b, 0x20, 0x61, 0x72, 0x67, 0x73, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, + 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, + 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, + 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, + 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x62, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x20, 0x27, 0x2e, + 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, + 0x5d, 0x3a, 0x6f, 0x75, 0x74, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x74, 0x79, + 0x70, 0x65, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x2e, 0x2e, 0x27, 0x20, + 0x7c, 0x7c, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x6e, 0x61, + 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, 0x0a, + 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, + 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x20, 0x65, 0x6e, 0x64, 0x20, 0x6f, 0x66, 0x20, 0x6c, 0x69, + 0x73, 0x74, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x69, 0x73, 0x6e, 0x6f, 0x6f, 0x62, 0x6a, 0x28, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, + 0x2e, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, + 0x72, 0x29, 0x5c, 0x6e, 0x20, 0x29, 0x27, 0x29, 0x0a, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x67, 0x6f, 0x74, 0x6f, + 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x3b, 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, + 0x64, 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, + 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x7b, + 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x63, 0x6c, + 0x61, 0x72, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2c, 0x20, 0x69, 0x66, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x73, 0x65, 0x0a, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x7e, 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, - 0x4c, 0x55, 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, - 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x21, 0x73, 0x65, 0x6c, - 0x66, 0x29, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, - 0x6f, 0x72, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, - 0x27, 0x2e, 0x2e, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x72, - 0x72, 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x22, 0x69, 0x6e, - 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x5c, 0x27, 0x73, 0x65, 0x6c, 0x66, - 0x5c, 0x27, 0x20, 0x69, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x20, 0x5c, 0x27, 0x25, 0x73, 0x5c, 0x27, 0x22, 0x2c, 0x20, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x2e, 0x2e, - 0x27, 0x22, 0x2c, 0x20, 0x4e, 0x55, 0x4c, 0x4c, 0x29, 0x3b, 0x27, 0x29, - 0x3b, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, - 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x65, 0x6c, 0x65, 0x6d, 0x65, - 0x6e, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x0a, 0x20, 0x69, - 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, 0x73, 0x65, - 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6f, + 0x6e, 0x73, 0x74, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x2a, 0x27, + 0x2c, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x20, 0x3d, 0x20, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x28, 0x27, + 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x2c, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, + 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x2a, 0x29, 0x20, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x5f, 0x66, + 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x74, 0x6f, + 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x31, 0x2c, 0x30, 0x29, 0x3b, + 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, + 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, + 0x64, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x27, 0x5e, 0x25, + 0x73, 0x2a, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x25, 0x73, 0x25, 0x73, + 0x2a, 0x28, 0x2e, 0x2a, 0x29, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, + 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, @@ -349,204 +323,268 @@ static const unsigned char lua_function_lua[] = { 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, - 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x67, 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, - 0x79, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x6e, - 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, - 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, - 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x20, 0x70, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x68, 0x6f, - 0x6f, 0x6b, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, 0x0a, 0x0a, 0x20, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x75, 0x74, 0x73, 0x69, 0x64, 0x65, 0x22, - 0x29, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x69, 0x66, 0x20, - 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x64, 0x65, - 0x6c, 0x65, 0x74, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, - 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x4d, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, - 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x65, - 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, - 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, - 0x6f, 0x72, 0x26, 0x5b, 0x5d, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x20, 0x20, 0x69, 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, - 0x31, 0x27, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, - 0x66, 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, - 0x69, 0x6c, 0x69, 0x74, 0x79, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x35, 0x20, 0x3f, 0x0a, 0x09, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2d, - 0x3e, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x5b, 0x5d, 0x28, - 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, - 0x31, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x2d, 0x31, 0x29, - 0x20, 0x3d, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, - 0x67, 0x73, 0x5b, 0x32, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, - 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, - 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, - 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x3e, 0x6f, 0x70, 0x65, 0x72, 0x61, - 0x74, 0x6f, 0x72, 0x5b, 0x5d, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, + 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, + 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, + 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x73, 0x74, 0x61, 0x74, + 0x65, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x20, + 0x6e, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, + 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, + 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, 0x20, + 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x7e, 0x3d, + 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, + 0x61, 0x74, 0x69, 0x63, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, + 0x55, 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, + 0x27, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x21, 0x73, 0x65, 0x6c, 0x66, + 0x29, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x27, + 0x2e, 0x2e, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x72, 0x72, + 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x22, 0x69, 0x6e, 0x76, + 0x61, 0x6c, 0x69, 0x64, 0x20, 0x5c, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x5c, + 0x27, 0x20, 0x69, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x5c, 0x27, 0x25, 0x73, 0x5c, 0x27, 0x22, 0x2c, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x2e, 0x2e, 0x27, + 0x22, 0x2c, 0x20, 0x4e, 0x55, 0x4c, 0x4c, 0x29, 0x3b, 0x27, 0x29, 0x3b, + 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, + 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x20, + 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, + 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x0a, 0x20, 0x69, 0x66, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, + 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, + 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, + 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, + 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, + 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, + 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, + 0x5b, 0x69, 0x5d, 0x3a, 0x67, 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, + 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, + 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, 0x0a, + 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, + 0x70, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x68, 0x6f, 0x6f, + 0x6b, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, 0x0a, 0x0a, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x6f, 0x75, 0x74, 0x73, 0x69, 0x64, 0x65, 0x22, 0x29, + 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x64, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x4d, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x28, + 0x73, 0x65, 0x6c, 0x66, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, + 0x72, 0x26, 0x5b, 0x5d, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x31, + 0x27, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x66, + 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x69, + 0x6c, 0x69, 0x74, 0x79, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x35, 0x20, 0x3f, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x3e, + 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x5b, 0x5d, 0x28, 0x27, + 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, + 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x2d, 0x31, 0x29, 0x20, + 0x3d, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, + 0x73, 0x5b, 0x32, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x3b, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x3e, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, + 0x6f, 0x72, 0x5b, 0x5d, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x27, 0x29, 0x20, 0x3d, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x32, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x2c, 0x27, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7b, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, + 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x20, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, + 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x28, + 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x29, 0x20, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x6e, 0x65, 0x77, 0x28, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x29, 0x28, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x75, + 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, + 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x2e, 0x2e, 0x27, 0x3a, 0x3a, 0x27, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, + 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, + 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, + 0x28, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x61, 0x73, + 0x74, 0x5f, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x09, 0x2d, 0x2d, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, + 0x5f, 0x63, 0x61, 0x73, 0x74, 0x3c, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, + 0x27, 0x20, 0x3e, 0x28, 0x2a, 0x73, 0x65, 0x6c, 0x66, 0x27, 0x29, 0x0a, + 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x65, + 0x6c, 0x66, 0x2d, 0x3e, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, + 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x28, + 0x27, 0x29, 0x0a, 0x09, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x65, 0x6c, + 0x66, 0x2d, 0x3e, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, + 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x27, 0x28, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x27, 0x29, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, + 0x5b, 0x31, 0x5d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x2c, 0x27, 0x29, 0x20, 0x3d, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x32, 0x5d, 0x2e, 0x6e, 0x61, - 0x6d, 0x65, 0x2c, 0x27, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7b, 0x27, 0x29, 0x0a, + 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x2c, + 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, + 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x0a, + 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, + 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, + 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, + 0x5b, 0x69, 0x5d, 0x3a, 0x70, 0x61, 0x73, 0x73, 0x70, 0x61, 0x72, 0x28, + 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, + 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, + 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x5b, 0x5d, 0x27, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x31, + 0x27, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x2d, 0x31, 0x29, 0x3b, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, 0x77, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x20, 0x2d, + 0x2d, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x20, 0x4d, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x6e, 0x65, 0x77, 0x28, 0x0a, 0x09, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x20, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, - 0x64, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x29, 0x20, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x63, - 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, 0x77, - 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, - 0x5f, 0x6e, 0x65, 0x77, 0x28, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x29, 0x28, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, - 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, - 0x63, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, - 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, - 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, - 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x63, - 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x2e, 0x27, 0x3a, 0x3a, 0x27, 0x2e, 0x2e, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x28, - 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6c, - 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x75, 0x74, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, - 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, - 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x61, - 0x73, 0x74, 0x5f, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x09, 0x2d, 0x2d, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x74, 0x61, 0x74, 0x69, - 0x63, 0x5f, 0x63, 0x61, 0x73, 0x74, 0x3c, 0x27, 0x2c, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, - 0x79, 0x70, 0x65, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, - 0x2c, 0x27, 0x20, 0x3e, 0x28, 0x2a, 0x73, 0x65, 0x6c, 0x66, 0x27, 0x29, - 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, - 0x65, 0x6c, 0x66, 0x2d, 0x3e, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, - 0x72, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, - 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, - 0x28, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, - 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x65, - 0x6c, 0x66, 0x2d, 0x3e, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x20, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, - 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, - 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, - 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x27, 0x29, 0x0a, - 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, - 0x73, 0x5b, 0x31, 0x5d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x6e, 0x61, - 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, + 0x6e, 0x72, 0x65, 0x74, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x20, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x63, 0x74, 0x20, 0x3d, + 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x6e, 0x65, + 0x77, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x09, + 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x61, 0x73, 0x74, + 0x5f, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, 0x72, 0x61, 0x77, + 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x77, 0x72, 0x69, 0x74, - 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, - 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, - 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, - 0x0a, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, - 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x70, 0x61, 0x73, 0x73, 0x70, 0x61, 0x72, - 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, - 0x31, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x69, 0x66, - 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, - 0x27, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x5b, 0x5d, 0x27, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, - 0x31, 0x27, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x2d, 0x31, 0x29, 0x3b, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, - 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, - 0x77, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x20, - 0x2d, 0x2d, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x20, 0x4d, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, 0x77, 0x28, 0x0a, 0x09, 0x65, 0x6c, - 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, - 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, - 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, - 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, - 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x3d, - 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x20, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x63, 0x74, 0x20, - 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, - 0x69, 0x66, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x6e, - 0x65, 0x77, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, - 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x61, 0x73, - 0x74, 0x5f, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x20, 0x61, - 0x6e, 0x64, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, 0x72, 0x61, - 0x77, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, - 0x5f, 0x72, 0x61, 0x77, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5b, 0x74, 0x5d, - 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, + 0x20, 0x20, 0x20, 0x27, 0x2c, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, + 0x72, 0x61, 0x77, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5b, 0x74, 0x5d, 0x2c, + 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x27, + 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x72, 0x65, 0x74, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x09, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x27, 0x2e, 0x2e, 0x74, 0x2e, + 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x27, 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x74, 0x6f, 0x6c, 0x75, 0x61, - 0x5f, 0x72, 0x65, 0x74, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, - 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x20, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x27, 0x2e, 0x2e, 0x74, - 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, - 0x28, 0x27, 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x72, 0x65, 0x74, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, - 0x74, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, - 0x65, 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x5f, 0x74, 0x20, 0x3d, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, - 0x2c, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x22, - 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, - 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, - 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x09, 0x09, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x74, - 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x75, 0x73, 0x68, 0x5f, - 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, - 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x28, 0x74, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, - 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7b, - 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, 0x5f, - 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, 0x6e, + 0x5f, 0x72, 0x65, 0x74, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x74, + 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x5f, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, + 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x22, 0x2c, + 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, + 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, + 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, + 0x77, 0x6e, 0x65, 0x64, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x74, 0x72, + 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, + 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x75, + 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, + 0x74, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7b, 0x27, + 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, 0x5f, 0x5f, + 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, 0x6e, 0x27, + 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x76, 0x6f, 0x69, 0x64, 0x2a, + 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x20, 0x3d, + 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, 0x77, 0x28, + 0x28, 0x27, 0x2c, 0x6e, 0x65, 0x77, 0x5f, 0x74, 0x2c, 0x27, 0x29, 0x28, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x76, 0x6f, 0x69, 0x64, - 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x20, - 0x3d, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, 0x77, - 0x28, 0x28, 0x27, 0x2c, 0x6e, 0x65, 0x77, 0x5f, 0x74, 0x2c, 0x27, 0x29, - 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x29, 0x29, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, 0x75, + 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, + 0x67, 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x6c, + 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, 0x28, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x23, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x20, 0x20, 0x20, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x20, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x63, 0x6f, 0x70, 0x79, 0x28, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x26, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x2c, 0x73, 0x69, + 0x7a, 0x65, 0x6f, 0x66, 0x28, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, @@ -559,634 +597,614 @@ static const unsigned char lua_function_lua[] = { 0x6c, 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x23, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x20, 0x20, 0x20, 0x20, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x20, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x20, 0x3d, 0x20, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x63, 0x6f, 0x70, 0x79, 0x28, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, - 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x2c, 0x73, - 0x69, 0x7a, 0x65, 0x6f, 0x66, 0x28, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x29, - 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x27, 0x2c, + 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x20, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, 0x75, + 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, + 0x29, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x2c, + 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, - 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, - 0x72, 0x5f, 0x67, 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, - 0x2c, 0x6c, 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, 0x28, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x20, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, - 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, - 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, - 0x2a, 0x29, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, 0x69, + 0x64, 0x2a, 0x29, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x20, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, - 0x2c, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, - 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, - 0x69, 0x64, 0x2a, 0x29, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, - 0x74, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, - 0x29, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x64, - 0x20, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, - 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, - 0x67, 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x6c, - 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, 0x28, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, - 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, - 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, - 0x6e, 0x72, 0x65, 0x74, 0x20, 0x2b, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x72, 0x65, 0x74, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, - 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, - 0x7d, 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x73, 0x65, - 0x74, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x65, 0x6c, 0x65, 0x6d, - 0x65, 0x6e, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x0a, 0x20, - 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, - 0x73, 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, - 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, - 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, - 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x73, - 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x6e, 0x61, 0x72, 0x67, - 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x20, 0x3d, - 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, + 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, + 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x67, + 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x6c, 0x75, + 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, 0x28, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, + 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, + 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x6e, + 0x72, 0x65, 0x74, 0x20, 0x2b, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, + 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x72, 0x65, 0x74, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, + 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7d, + 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x73, 0x65, 0x74, + 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x65, 0x6c, 0x65, 0x6d, 0x65, + 0x6e, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, 0x73, + 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, + 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, + 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x73, 0x65, + 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, + 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, + 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x2d, + 0x2d, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x64, 0x79, 0x6e, 0x61, 0x6d, + 0x69, 0x63, 0x61, 0x6c, 0x6c, 0x79, 0x20, 0x61, 0x6c, 0x6c, 0x6f, 0x63, + 0x61, 0x74, 0x65, 0x64, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, + 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, + 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, + 0x31, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, + 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x66, 0x72, 0x65, 0x65, + 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, - 0x2d, 0x2d, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x64, 0x79, 0x6e, 0x61, - 0x6d, 0x69, 0x63, 0x61, 0x6c, 0x6c, 0x79, 0x20, 0x61, 0x6c, 0x6c, 0x6f, - 0x63, 0x61, 0x74, 0x65, 0x64, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x0a, - 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, - 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, - 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, - 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, - 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x66, 0x72, 0x65, - 0x65, 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, - 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x63, 0x61, - 0x6c, 0x6c, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x65, 0x6c, 0x66, - 0x29, 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x2e, - 0x2e, 0x6e, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x27, 0x3b, 0x27, 0x29, 0x0a, - 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x6f, 0x76, - 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x65, 0x64, 0x20, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x72, 0x20, 0x67, 0x65, 0x6e, - 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x0a, - 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, - 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, - 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, - 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x52, - 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, - 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3a, 0x5c, 0x6e, - 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x6f, - 0x72, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x27, - 0x2e, 0x2e, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x72, 0x72, - 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x22, 0x23, 0x66, 0x65, - 0x72, 0x72, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5c, 0x27, 0x25, 0x73, 0x5c, 0x27, 0x2e, - 0x22, 0x2c, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, - 0x65, 0x29, 0x2e, 0x2e, 0x27, 0x22, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x09, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x30, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, - 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, - 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x09, 0x69, 0x66, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, - 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x09, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x3d, 0x20, - 0x22, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x0a, 0x09, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, - 0x72, 0x3a, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x27, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x31, 0x2c, - 0x2d, 0x33, 0x29, 0x2e, 0x2e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x28, - 0x22, 0x25, 0x30, 0x32, 0x64, 0x22, 0x2c, 0x6f, 0x76, 0x65, 0x72, 0x6c, - 0x6f, 0x61, 0x64, 0x29, 0x2e, 0x2e, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, - 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, - 0x66, 0x20, 0x2f, 0x2f, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, - 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, - 0x45, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x27, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, - 0x20, 0x72, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x20, 0x63, - 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, - 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x63, - 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, 0x77, - 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, - 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, - 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, - 0x28, 0x31, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x67, 0x69, 0x73, - 0x74, 0x65, 0x72, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, - 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, - 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x20, 0x28, 0x70, 0x72, - 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, - 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, 0x70, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, - 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, - 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, - 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, - 0x6e, 0x74, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x2e, 0x70, 0x75, 0x72, - 0x65, 0x5f, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x6e, 0x6f, 0x20, - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, - 0x66, 0x6f, 0x72, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x20, - 0x77, 0x69, 0x74, 0x68, 0x20, 0x70, 0x75, 0x72, 0x65, 0x20, 0x76, 0x69, - 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, - 0x73, 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, - 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x27, 0x2e, 0x2e, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, - 0x27, 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, - 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x29, 0x3b, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, - 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x6e, 0x65, 0x77, - 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, - 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, - 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x70, 0x72, 0x65, - 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x53, 0x2c, 0x22, 0x2e, 0x63, 0x61, 0x6c, 0x6c, 0x22, 0x2c, 0x27, 0x2e, - 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, - 0x2e, 0x27, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x29, 0x3b, 0x27, 0x29, - 0x0a, 0x09, 0x20, 0x20, 0x2d, 0x2d, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x73, 0x65, 0x74, - 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x28, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, - 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x2c, 0x20, 0x22, 0x27, 0x2e, 0x2e, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, - 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x6d, 0x65, 0x74, - 0x68, 0x6f, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x3a, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x28, 0x69, 0x64, - 0x65, 0x6e, 0x74, 0x2c, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x29, 0x0a, 0x20, - 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, - 0x2e, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x22, - 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, - 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x20, 0x3d, - 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, - 0x64, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, - 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, - 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, - 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, - 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x70, 0x74, 0x72, - 0x20, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x70, 0x74, 0x72, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, - 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, - 0x2e, 0x2e, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, - 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x63, 0x61, 0x6c, + 0x6c, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, + 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x2e, 0x2e, + 0x6e, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x27, 0x3b, 0x27, 0x29, 0x0a, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x6f, 0x76, 0x65, + 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x65, 0x64, 0x20, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x72, 0x20, 0x67, 0x65, 0x6e, 0x65, + 0x72, 0x61, 0x74, 0x65, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x20, + 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x6e, + 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x52, 0x45, + 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3a, 0x5c, 0x6e, 0x27, + 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x6f, 0x72, + 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x27, 0x2e, + 0x2e, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x22, 0x23, 0x66, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x5c, 0x27, 0x25, 0x73, 0x5c, 0x27, 0x2e, 0x22, + 0x2c, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, + 0x29, 0x2e, 0x2e, 0x27, 0x22, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x65, 0x72, 0x72, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x30, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, + 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, + 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x09, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x22, + 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x0a, 0x09, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, + 0x3a, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x27, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x31, 0x2c, 0x2d, + 0x33, 0x29, 0x2e, 0x2e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x28, 0x22, + 0x25, 0x30, 0x32, 0x64, 0x22, 0x2c, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, + 0x61, 0x64, 0x29, 0x2e, 0x2e, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x2e, + 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x3b, + 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, + 0x20, 0x2f, 0x2f, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, + 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, 0x45, + 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x20, + 0x72, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x20, 0x63, 0x61, + 0x6c, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, + 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, + 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x73, + 0x65, 0x6c, 0x66, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x28, + 0x31, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, + 0x65, 0x72, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x72, + 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x20, 0x28, 0x70, 0x72, 0x65, + 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, 0x70, 0x75, + 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x28, + 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x09, + 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, + 0x74, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x2e, 0x70, 0x75, 0x72, 0x65, + 0x5f, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x6e, 0x6f, 0x20, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x66, + 0x6f, 0x72, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x20, 0x77, + 0x69, 0x74, 0x68, 0x20, 0x70, 0x75, 0x72, 0x65, 0x20, 0x76, 0x69, 0x72, + 0x74, 0x75, 0x61, 0x6c, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, + 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x27, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, + 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, + 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x6e, 0x65, 0x77, 0x5f, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x5f, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, + 0x2e, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, + 0x2c, 0x22, 0x2e, 0x63, 0x61, 0x6c, 0x6c, 0x22, 0x2c, 0x27, 0x2e, 0x2e, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, + 0x27, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x29, 0x3b, 0x27, 0x29, 0x0a, + 0x09, 0x20, 0x20, 0x2d, 0x2d, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x73, 0x65, 0x74, 0x5f, + 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x28, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x5f, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x2c, 0x20, 0x22, 0x27, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x6d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x3a, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x28, 0x69, 0x64, 0x65, + 0x6e, 0x74, 0x2c, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x29, 0x0a, 0x20, 0x70, + 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, + 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x22, 0x29, + 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, + 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x20, 0x3d, 0x20, + 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, - 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, - 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, - 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x63, 0x6f, - 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x2e, 0x2e, 0x22, 0x27, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, - 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x63, 0x6e, 0x61, 0x6d, - 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, - 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, - 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, - 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, - 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, - 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, - 0x2e, 0x2e, 0x22, 0x20, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x7b, - 0x22, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, - 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, - 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, - 0x5b, 0x69, 0x5d, 0x3a, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, - 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x20, 0x22, 0x2c, 0x22, 0x2c, - 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, - 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, - 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x7d, 0x22, - 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, - 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x7d, 0x22, 0x2e, 0x2e, 0x63, 0x6c, 0x6f, - 0x73, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, - 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x69, 0x66, 0x20, 0x69, 0x74, 0x20, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x6f, - 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x62, 0x79, 0x20, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x70, 0x74, 0x72, 0x20, + 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x70, 0x74, 0x72, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, + 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, + 0x2e, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, + 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, + 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, + 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6c, + 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, + 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x63, 0x6f, 0x6e, + 0x73, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x2e, 0x2e, 0x22, 0x27, 0x2c, + 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, + 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x63, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, + 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, + 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, + 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, + 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, + 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, + 0x2e, 0x22, 0x20, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x22, + 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, + 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, + 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, + 0x69, 0x5d, 0x3a, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, + 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x20, 0x22, 0x2c, 0x22, 0x2c, 0x22, + 0x29, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x7d, 0x22, 0x29, + 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, + 0x74, 0x2e, 0x2e, 0x22, 0x7d, 0x22, 0x2e, 0x2e, 0x63, 0x6c, 0x6f, 0x73, + 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, + 0x68, 0x65, 0x63, 0x6b, 0x20, 0x69, 0x66, 0x20, 0x69, 0x74, 0x20, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x6f, 0x62, + 0x6a, 0x65, 0x63, 0x74, 0x20, 0x62, 0x79, 0x20, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x63, 0x6f, 0x6c, 0x6c, + 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x20, 0x3d, 0x20, 0x66, 0x61, + 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x69, 0x73, 0x62, 0x61, + 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x70, 0x74, 0x72, 0x3d, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x22, 0x25, 0x73, 0x2a, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x22, 0x2c, 0x22, 0x22, 0x29, + 0x0a, 0x09, 0x20, 0x74, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, 0x3d, + 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6c, + 0x65, 0x63, 0x74, 0x5f, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x63, 0x6c, 0x65, + 0x61, 0x6e, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, + 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x20, 0x72, 0x20, 0x3d, 0x20, + 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x09, 0x77, 0x68, + 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, + 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x72, 0x20, + 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, + 0x69, 0x5d, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x63, 0x6f, + 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, 0x20, + 0x6f, 0x72, 0x20, 0x72, 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, 0x69, + 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x72, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x64, 0x65, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x65, 0x20, + 0x6c, 0x75, 0x61, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, + 0x61, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x63, 0x6f, 0x6c, - 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x20, 0x3d, 0x20, 0x66, - 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x69, 0x73, 0x62, - 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, - 0x70, 0x65, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x70, 0x74, 0x72, 0x3d, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, - 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x22, 0x25, 0x73, 0x2a, - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x22, 0x2c, 0x22, 0x22, - 0x29, 0x0a, 0x09, 0x20, 0x74, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, - 0x3d, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x63, 0x6f, 0x6c, - 0x6c, 0x65, 0x63, 0x74, 0x5f, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x63, 0x6c, - 0x65, 0x61, 0x6e, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, - 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x20, 0x72, 0x20, 0x3d, - 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x09, 0x77, - 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, - 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x72, - 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, - 0x5b, 0x69, 0x5d, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x63, - 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, - 0x20, 0x6f, 0x72, 0x20, 0x72, 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, - 0x69, 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x65, - 0x20, 0x6c, 0x75, 0x61, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, - 0x6f, 0x61, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x3a, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x20, - 0x28, 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x3a, 0x6f, - 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, - 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, - 0x61, 0x72, 0x61, 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, - 0x70, 0x61, 0x72, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x73, 0x20, 0x74, 0x72, 0x75, 0x65, 0x20, 0x69, 0x66, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, - 0x72, 0x20, 0x68, 0x61, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x6f, 0x62, 0x6a, - 0x65, 0x63, 0x74, 0x20, 0x61, 0x73, 0x20, 0x69, 0x74, 0x73, 0x20, 0x64, - 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, - 0x72, 0x2c, 0x20, 0x27, 0x3d, 0x27, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, - 0x65, 0x20, 0x65, 0x6e, 0x64, 0x20, 0x2d, 0x2d, 0x20, 0x69, 0x74, 0x20, - 0x68, 0x61, 0x73, 0x20, 0x6e, 0x6f, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, - 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x0a, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x64, 0x65, 0x66, - 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, - 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x3d, 0x28, 0x2e, - 0x2a, 0x29, 0x24, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, - 0x61, 0x72, 0x2c, 0x20, 0x22, 0x7c, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x20, - 0x6f, 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x0a, 0x0a, 0x09, 0x09, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, - 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, + 0x6e, 0x3a, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x28, + 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x3a, 0x6f, 0x76, + 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, 0x70, + 0x61, 0x72, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x73, 0x20, 0x74, 0x72, 0x75, 0x65, 0x20, 0x69, 0x66, 0x20, 0x74, + 0x68, 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, + 0x20, 0x68, 0x61, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x6f, 0x62, 0x6a, 0x65, + 0x63, 0x74, 0x20, 0x61, 0x73, 0x20, 0x69, 0x74, 0x73, 0x20, 0x64, 0x65, + 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, + 0x2c, 0x20, 0x27, 0x3d, 0x27, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, + 0x20, 0x65, 0x6e, 0x64, 0x20, 0x2d, 0x2d, 0x20, 0x69, 0x74, 0x20, 0x68, + 0x61, 0x73, 0x20, 0x6e, 0x6f, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, + 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x64, 0x65, 0x66, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x3d, 0x28, 0x2e, 0x2a, + 0x29, 0x24, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, - 0x72, 0x2c, 0x20, 0x22, 0x25, 0x2a, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x69, 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, - 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x20, 0x77, 0x69, 0x74, 0x68, - 0x20, 0x61, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, - 0x61, 0x72, 0x2c, 0x20, 0x27, 0x3d, 0x25, 0x73, 0x2a, 0x6e, 0x65, 0x77, - 0x27, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, - 0x25, 0x28, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, - 0x20, 0x69, 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, 0x70, 0x6f, 0x69, 0x6e, - 0x74, 0x65, 0x72, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x6e, 0x20, - 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x61, 0x73, 0x20, - 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x70, 0x61, 0x72, 0x61, - 0x6d, 0x65, 0x74, 0x65, 0x72, 0x2e, 0x2e, 0x20, 0x69, 0x73, 0x20, 0x74, - 0x68, 0x61, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x3f, 0x0a, 0x09, - 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, - 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x20, 0x2d, - 0x2d, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, 0x27, 0x4e, 0x55, 0x4c, 0x4c, - 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x69, - 0x6e, 0x67, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x09, 0x69, - 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, - 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x5b, 0x25, 0x28, 0x26, - 0x5d, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, + 0x72, 0x2c, 0x20, 0x22, 0x7c, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x20, 0x6f, + 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x0a, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, - 0x65, 0x6e, 0x64, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, - 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, - 0x61, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, - 0x72, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x28, 0x6d, 0x6f, 0x73, 0x74, - 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x6c, 0x79, 0x20, 0x66, 0x6f, 0x72, 0x20, - 0x61, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x72, 0x65, 0x66, 0x65, - 0x72, 0x65, 0x6e, 0x63, 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x69, - 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, - 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x26, 0x22, 0x29, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x69, 0x66, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, + 0x2c, 0x20, 0x22, 0x25, 0x2a, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x2d, 0x2d, 0x20, 0x69, 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, 0x70, + 0x6f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, + 0x61, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x0a, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, + 0x72, 0x2c, 0x20, 0x27, 0x3d, 0x25, 0x73, 0x2a, 0x6e, 0x65, 0x77, 0x27, + 0x29, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x25, + 0x28, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, + 0x69, 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, + 0x65, 0x72, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x6e, 0x20, 0x69, + 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x61, 0x73, 0x20, 0x64, + 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, + 0x65, 0x74, 0x65, 0x72, 0x2e, 0x2e, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, + 0x61, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x3f, 0x0a, 0x09, 0x09, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, + 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x20, 0x2d, 0x2d, + 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, 0x27, 0x4e, 0x55, 0x4c, 0x4c, 0x27, + 0x20, 0x6f, 0x72, 0x20, 0x73, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x69, 0x6e, + 0x67, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, - 0x28, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x22, 0x3a, 0x22, 0x29, 0x20, 0x6f, - 0x72, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, - 0x64, 0x28, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, - 0x6e, 0x65, 0x77, 0x25, 0x73, 0x2b, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x69, - 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, - 0x6e, 0x63, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x64, 0x65, 0x66, - 0x61, 0x75, 0x6c, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x73, 0x6f, 0x6d, 0x65, - 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x43, - 0x6c, 0x61, 0x73, 0x73, 0x3a, 0x3a, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, - 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x20, 0x43, 0x6c, - 0x61, 0x73, 0x73, 0x27, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x09, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x2d, - 0x2d, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, - 0x6c, 0x73, 0x65, 0x20, 0x2d, 0x2d, 0x20, 0x3f, 0x0a, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x70, 0x5f, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, - 0x67, 0x28, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x2c, 0x20, - 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x29, 0x20, 0x2d, 0x2d, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, - 0x61, 0x73, 0x74, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, - 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, - 0x2c, 0x73, 0x5f, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x6c, 0x61, 0x73, - 0x74, 0x5f, 0x61, 0x72, 0x67, 0x2c, 0x20, 0x22, 0x5e, 0x28, 0x5b, 0x5e, - 0x3d, 0x5d, 0x2b, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x61, 0x73, 0x74, - 0x5f, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, - 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x6c, 0x61, 0x73, 0x74, 0x5f, - 0x61, 0x72, 0x67, 0x2c, 0x20, 0x22, 0x28, 0x5b, 0x25, 0x25, 0x25, 0x28, - 0x25, 0x29, 0x5d, 0x29, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x25, 0x25, 0x31, - 0x22, 0x29, 0x3b, 0x0a, 0x09, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, - 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, - 0x73, 0x75, 0x62, 0x28, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, - 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x2c, 0x25, 0x73, 0x2a, 0x22, 0x2e, - 0x2e, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x22, - 0x25, 0x73, 0x2a, 0x25, 0x29, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, - 0x22, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x2c, 0x20, 0x73, - 0x5f, 0x61, 0x72, 0x67, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, 0x46, 0x75, - 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, - 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, - 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, - 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x63, - 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x2e, - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, - 0x28, 0x22, 0x23, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x27, - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, - 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x29, 0x0a, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, - 0x28, 0x74, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x3a, 0x69, 0x6e, - 0x63, 0x6c, 0x61, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x20, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x28, 0x27, - 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x69, 0x73, 0x20, 0x27, 0x2e, - 0x2e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x2c, 0x20, - 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, - 0x69, 0x73, 0x20, 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, - 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, - 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, - 0x62, 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, - 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x3d, 0x3d, + 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x5b, 0x25, 0x28, 0x26, 0x5d, + 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, + 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, 0x61, + 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, + 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x28, 0x6d, 0x6f, 0x73, 0x74, 0x20, + 0x6c, 0x69, 0x6b, 0x65, 0x6c, 0x79, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, + 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, + 0x65, 0x6e, 0x63, 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x69, 0x66, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, + 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x26, 0x22, 0x29, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x69, 0x66, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x64, 0x65, 0x66, 0x2c, 0x20, 0x22, 0x3a, 0x22, 0x29, 0x20, 0x6f, 0x72, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, + 0x28, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x6e, + 0x65, 0x77, 0x25, 0x73, 0x2b, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x69, 0x74, + 0x27, 0x73, 0x20, 0x61, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, + 0x63, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x64, 0x65, 0x66, 0x61, + 0x75, 0x6c, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x73, 0x6f, 0x6d, 0x65, 0x74, + 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x43, 0x6c, + 0x61, 0x73, 0x73, 0x3a, 0x3a, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x2c, + 0x20, 0x6f, 0x72, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x20, 0x43, 0x6c, 0x61, + 0x73, 0x73, 0x27, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x2d, 0x2d, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, + 0x73, 0x65, 0x20, 0x2d, 0x2d, 0x20, 0x3f, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x70, 0x5f, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, + 0x28, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x2c, 0x20, 0x6c, + 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x29, 0x20, 0x2d, 0x2d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x70, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x64, + 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x61, + 0x73, 0x74, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x0a, + 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, + 0x73, 0x5f, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x6c, 0x61, 0x73, 0x74, + 0x5f, 0x61, 0x72, 0x67, 0x2c, 0x20, 0x22, 0x5e, 0x28, 0x5b, 0x5e, 0x3d, + 0x5d, 0x2b, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, + 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, + 0x72, 0x67, 0x2c, 0x20, 0x22, 0x28, 0x5b, 0x25, 0x25, 0x25, 0x28, 0x25, + 0x29, 0x5d, 0x29, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x25, 0x25, 0x31, 0x22, + 0x29, 0x3b, 0x0a, 0x09, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, + 0x75, 0x62, 0x28, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x2c, + 0x20, 0x22, 0x25, 0x73, 0x2a, 0x2c, 0x25, 0x73, 0x2a, 0x22, 0x2e, 0x2e, + 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x22, 0x25, + 0x73, 0x2a, 0x25, 0x29, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, + 0x29, 0x22, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x2c, 0x20, 0x73, 0x5f, + 0x61, 0x72, 0x67, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, 0x46, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x73, + 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, + 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x63, 0x6f, + 0x6e, 0x73, 0x74, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x2e, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, + 0x22, 0x23, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x27, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, + 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x29, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28, + 0x74, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x3a, 0x69, 0x6e, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x28, 0x27, 0x74, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x69, 0x73, 0x20, 0x27, 0x2e, 0x2e, + 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x2c, 0x20, 0x70, + 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x69, + 0x73, 0x20, 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, + 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, - 0x28, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6f, 0x72, - 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x20, - 0x6f, 0x72, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, - 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, 0x62, 0x3c, 0x3e, 0x22, - 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, - 0x20, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, - 0x6e, 0x65, 0x77, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6c, 0x6e, - 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x0a, - 0x20, 0x20, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, - 0x5f, 0x6e, 0x65, 0x77, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, - 0x20, 0x20, 0x20, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, - 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, - 0x20, 0x27, 0x2a, 0x27, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, - 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, - 0x62, 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, - 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x3d, 0x3d, - 0x20, 0x27, 0x7e, 0x27, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, - 0x6e, 0x74, 0x2e, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x5f, - 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x2e, 0x70, 0x61, - 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, - 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x20, 0x3d, 0x20, 0x27, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x27, - 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, - 0x3d, 0x20, 0x27, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x27, 0x0a, 0x20, + 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, 0x62, + 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x3d, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6f, 0x72, 0x69, + 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, + 0x72, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x2c, + 0x20, 0x22, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x6e, + 0x65, 0x77, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6c, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x5f, - 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, - 0x65, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x74, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, - 0x74, 0x3a, 0x63, 0x66, 0x75, 0x6e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x28, - 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x22, 0x29, 0x2e, 0x2e, 0x74, 0x3a, - 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x74, 0x29, 0x0a, - 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x72, - 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, 0x78, 0x70, - 0x65, 0x63, 0x74, 0x73, 0x20, 0x74, 0x68, 0x72, 0x65, 0x65, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x3a, 0x20, 0x6f, 0x6e, 0x65, 0x20, - 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x2c, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x6f, 0x74, 0x68, 0x65, - 0x72, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, - 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, - 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x61, 0x6e, - 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x20, - 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, - 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x22, 0x63, 0x6f, 0x6e, - 0x73, 0x74, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x65, 0x6d, 0x70, 0x74, 0x79, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x0a, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x20, 0x28, 0x64, 0x2c, 0x61, 0x2c, 0x63, 0x29, 0x0a, 0x20, - 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, - 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, - 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x27, 0x2c, 0x27, - 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, - 0x74, 0x65, 0x20, 0x62, 0x72, 0x61, 0x63, 0x65, 0x73, 0x0a, 0x20, 0x2d, + 0x6e, 0x65, 0x77, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x20, + 0x20, 0x20, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, + 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, + 0x27, 0x2a, 0x27, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, 0x62, + 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x3d, 0x3d, 0x20, + 0x27, 0x7e, 0x27, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, + 0x74, 0x2e, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x5f, 0x6e, + 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, + 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x3d, 0x20, 0x27, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x27, 0x0a, + 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, + 0x20, 0x27, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x27, 0x0a, 0x20, 0x20, + 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x5f, 0x64, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, + 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x74, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x74, + 0x3a, 0x63, 0x66, 0x75, 0x6e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x28, 0x22, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x22, 0x29, 0x2e, 0x2e, 0x74, 0x3a, 0x6f, + 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, + 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, 0x78, 0x70, 0x65, + 0x63, 0x74, 0x73, 0x20, 0x74, 0x68, 0x72, 0x65, 0x65, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x73, 0x3a, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x72, + 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x2c, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x6f, 0x74, 0x68, 0x65, 0x72, + 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, + 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, + 0x6e, 0x74, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x20, 0x72, + 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x0a, + 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x28, 0x64, 0x2c, 0x61, 0x2c, 0x63, 0x29, 0x0a, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, - 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x28, - 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, - 0x32, 0x29, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, - 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x57, 0x27, 0x5d, 0x20, - 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, - 0x69, 0x6e, 0x64, 0x28, 0x61, 0x2c, 0x20, 0x22, 0x25, 0x2e, 0x25, 0x2e, - 0x25, 0x2e, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x22, 0x29, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, - 0x67, 0x28, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, - 0x6c, 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, - 0x20, 0x28, 0x60, 0x2e, 0x2e, 0x2e, 0x27, 0x29, 0x20, 0x61, 0x72, 0x65, - 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, - 0x65, 0x64, 0x2e, 0x20, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x69, 0x6e, 0x67, - 0x20, 0x22, 0x2e, 0x2e, 0x64, 0x2e, 0x2e, 0x61, 0x2e, 0x2e, 0x63, 0x29, - 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, - 0x6c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x20, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, 0x7d, - 0x0a, 0x0a, 0x20, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, - 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x20, 0x22, - 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x25, 0x28, 0x25, 0x29, 0x5d, 0x29, 0x25, - 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x31, 0x22, 0x29, 0x0a, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, 0x69, - 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x74, 0x72, 0x73, - 0x75, 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x3b, - 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, - 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, - 0x28, 0x61, 0x2c, 0x31, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x20, 0x31, 0x2c, - 0x20, 0x2d, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x6c, 0x65, - 0x6e, 0x28, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x2b, 0x31, 0x29, 0x29, 0x0a, - 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, - 0x20, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x2c, 0x22, - 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x2d, 0x31, 0x29, - 0x0a, 0x0a, 0x09, 0x09, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x22, 0x28, 0x22, - 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, - 0x62, 0x28, 0x6e, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x2c, 0x25, - 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x2e, 0x2e, 0x27, - 0x29, 0x27, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6e, 0x73, 0x20, 0x3d, 0x20, - 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, - 0x74, 0x73, 0x28, 0x6e, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x46, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x20, 0x6e, 0x73, 0x2c, 0x20, - 0x63, 0x29, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, - 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x09, - 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, - 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, - 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, - 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, - 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, 0x69, 0x5d, - 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, - 0x6c, 0x2e, 0x6e, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x6c, 0x5b, 0x6c, 0x2e, - 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x76, - 0x61, 0x72, 0x27, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, 0x0a, 0x20, 0x20, - 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, - 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, - 0x64, 0x2c, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x29, 0x0a, 0x20, 0x66, - 0x2e, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x6c, 0x0a, 0x20, 0x66, - 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x63, 0x0a, 0x20, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x46, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x66, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, - 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6a, 0x6f, - 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x70, 0x2c, 0x20, 0x66, - 0x69, 0x72, 0x73, 0x74, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x0a, - 0x0a, 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x69, - 0x72, 0x73, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x61, - 0x73, 0x74, 0x20, 0x3d, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x6f, 0x72, - 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x67, 0x65, 0x74, 0x6e, 0x28, - 0x74, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x73, - 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x6f, 0x6f, 0x70, 0x20, - 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x66, 0x6f, 0x72, - 0x20, 0x69, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2c, 0x6c, - 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, 0x09, 0x72, 0x65, - 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x6c, 0x73, 0x65, - 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, 0x09, 0x6c, 0x73, - 0x65, 0x70, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x70, 0x0a, 0x09, 0x09, 0x6c, - 0x6f, 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, - 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, - 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x72, 0x65, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, - 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, - 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, - 0x2c, 0x20, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x66, 0x61, - 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, - 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, - 0x74, 0x2e, 0x6e, 0x2c, 0x31, 0x2c, 0x2d, 0x31, 0x20, 0x64, 0x6f, 0x0a, - 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x70, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, - 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, 0x74, 0x5b, 0x69, - 0x5d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6c, - 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x0a, 0x09, 0x09, 0x09, 0x73, - 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, - 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x69, 0x66, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x2d, 0x2d, 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, - 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, - 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, - 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x65, 0x6e, - 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, 0x69, 0x70, 0x2c, - 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, - 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x73, 0x28, 0x73, - 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, - 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, - 0x5e, 0x25, 0x28, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x73, - 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, - 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x29, 0x24, 0x22, 0x2c, - 0x20, 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, - 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x20, 0x22, - 0x2c, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, - 0x65, 0x70, 0x2c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x22, 0x22, - 0x2c, 0x22, 0x22, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, - 0x2c, 0x74, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x74, 0x5b, - 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, - 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, - 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, - 0x09, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, - 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, 0x09, - 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x2c, 0x22, 0x0a, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x22, 0x28, 0x22, 0x2e, 0x2e, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x22, 0x29, - 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a + 0x70, 0x6c, 0x69, 0x74, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, + 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x27, 0x2c, 0x27, 0x29, + 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, + 0x65, 0x20, 0x62, 0x72, 0x61, 0x63, 0x65, 0x73, 0x0a, 0x20, 0x2d, 0x2d, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, + 0x6c, 0x69, 0x74, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x28, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, + 0x29, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x57, 0x27, 0x5d, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, + 0x6e, 0x64, 0x28, 0x61, 0x2c, 0x20, 0x22, 0x25, 0x2e, 0x25, 0x2e, 0x25, + 0x2e, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, + 0x28, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, + 0x77, 0x69, 0x74, 0x68, 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, + 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x20, + 0x28, 0x60, 0x2e, 0x2e, 0x2e, 0x27, 0x29, 0x20, 0x61, 0x72, 0x65, 0x20, + 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, + 0x64, 0x2e, 0x20, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x69, 0x6e, 0x67, 0x20, + 0x22, 0x2e, 0x2e, 0x64, 0x2e, 0x2e, 0x61, 0x2e, 0x2e, 0x63, 0x29, 0x0a, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x20, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, 0x7d, 0x0a, + 0x0a, 0x20, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x20, 0x22, 0x25, + 0x73, 0x2a, 0x28, 0x5b, 0x25, 0x28, 0x25, 0x29, 0x5d, 0x29, 0x25, 0x73, + 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x31, 0x22, 0x29, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, 0x69, 0x70, + 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x3b, 0x0a, + 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, + 0x61, 0x2c, 0x31, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x20, 0x31, 0x2c, 0x20, + 0x2d, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x6c, 0x65, 0x6e, + 0x28, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x2b, 0x31, 0x29, 0x29, 0x0a, 0x09, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, + 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x2c, 0x22, 0x2c, + 0x20, 0x31, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x2d, 0x31, 0x29, 0x0a, + 0x0a, 0x09, 0x09, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x22, 0x28, 0x22, 0x2e, + 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x6e, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x2c, 0x25, 0x73, + 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x2e, 0x2e, 0x27, 0x29, + 0x27, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, + 0x73, 0x28, 0x6e, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x46, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x20, 0x6e, 0x73, 0x2c, 0x20, 0x63, + 0x29, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, 0x2c, + 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x09, 0x74, + 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, + 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, 0x69, 0x5d, 0x20, + 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x6c, + 0x2e, 0x6e, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x6c, 0x5b, 0x6c, 0x2e, 0x6e, + 0x5d, 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x76, 0x61, + 0x72, 0x27, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, + 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x44, + 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, + 0x2c, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x29, 0x0a, 0x20, 0x66, 0x2e, + 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x6c, 0x0a, 0x20, 0x66, 0x2e, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x63, 0x0a, 0x20, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x46, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x28, 0x66, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6a, 0x6f, 0x69, + 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x70, 0x2c, 0x20, 0x66, 0x69, + 0x72, 0x73, 0x74, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x0a, 0x0a, + 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x72, + 0x73, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x61, 0x73, + 0x74, 0x20, 0x3d, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x6f, 0x72, 0x20, + 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x67, 0x65, 0x74, 0x6e, 0x28, 0x74, + 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x73, 0x65, + 0x70, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x3d, + 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, + 0x69, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2c, 0x6c, 0x61, + 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, + 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x6c, 0x73, 0x65, 0x70, + 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, 0x09, 0x6c, 0x73, 0x65, + 0x70, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x70, 0x0a, 0x09, 0x09, 0x6c, 0x6f, + 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, + 0x6f, 0x6f, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, + 0x65, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x70, + 0x61, 0x72, 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, + 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, + 0x20, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, + 0x73, 0x65, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x61, + 0x73, 0x74, 0x0a, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x74, + 0x2e, 0x6e, 0x2c, 0x31, 0x2c, 0x2d, 0x31, 0x20, 0x64, 0x6f, 0x0a, 0x0a, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x70, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, + 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, 0x74, 0x5b, 0x69, 0x5d, + 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6c, 0x61, + 0x73, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x0a, 0x09, 0x09, 0x09, 0x73, 0x74, + 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x69, 0x66, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x2d, 0x2d, 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, + 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, + 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, 0x69, 0x70, 0x2c, 0x6c, + 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, + 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x73, 0x28, 0x73, 0x29, + 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, + 0x25, 0x28, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x73, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x29, 0x24, 0x22, 0x2c, 0x20, + 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, + 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x2c, + 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x65, + 0x70, 0x2c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x2c, + 0x22, 0x22, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, 0x2c, + 0x74, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x74, 0x5b, 0x69, + 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, + 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, + 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, + 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x73, + 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, 0x09, 0x73, + 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x2c, 0x22, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, + 0x28, 0x22, 0x2e, 0x2e, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x22, 0x29, 0x22, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a }; -unsigned int lua_function_lua_len = 14264; +unsigned int lua_function_lua_len = 14479; diff --git a/lib/tolua++/src/bin/lua/basic.lua b/lib/tolua++/src/bin/lua/basic.lua index d195f6dec..b5788f2be 100644 --- a/lib/tolua++/src/bin/lua/basic.lua +++ b/lib/tolua++/src/bin/lua/basic.lua @@ -145,12 +145,14 @@ function typevar(type) end end +-- is enum +function isenum (type) + return _enums[type] +end + -- check if basic type function isbasic (type) local t = gsub(type,'const ','') - if _enum_is_functions[t] then - return nil - end local m,t = applytypedef('', t) local b = _basic[t] if b then @@ -385,7 +387,7 @@ end _push_functions = {} _is_functions = {} -_enum_is_functions = {} +_enums = {} _to_functions = {} _base_push_functions = {} @@ -414,5 +416,8 @@ function get_to_function(t) end function get_is_function(t) - return _enum_is_functions[t] or _is_functions[t] or search_base(t, _base_is_functions) or "tolua_isusertype" + if _enums[t] then + return "tolua_is" .. t + end + return _is_functions[t] or search_base(t, _base_is_functions) or "tolua_isusertype" end diff --git a/lib/tolua++/src/bin/lua/declaration.lua b/lib/tolua++/src/bin/lua/declaration.lua index 73bbe910e..5a2adfed9 100644 --- a/lib/tolua++/src/bin/lua/declaration.lua +++ b/lib/tolua++/src/bin/lua/declaration.lua @@ -229,6 +229,8 @@ function classDeclaration:outchecktype (narg) --end elseif t then return '!tolua_is'..t..'(tolua_S,'..narg..','..def..',&tolua_err)' + elseif isenum(self.type) then + return '!tolua_is'..self.type..'(tolua_S,'..narg..','..def..',&tolua_err)' else local is_func = get_is_function(self.type) if self.ptr == '&' or self.ptr == '' then diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index d5d4426cf..ef3a9574c 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -48,13 +48,17 @@ function classEnumerate:print (ident,close) print(ident.."}"..close) end +function emitenumprototype(type) + output("int tolua_is" .. string.gsub(type,"::","_") .. " (lua_State* L, int lo, const char * type, int def, tolua_Error* err);") +end + _global_output_enums = {} -- write support code function classEnumerate:supcode () if _global_output_enums[self.name] == nil then _global_output_enums[self.name] = 1 - output("lua_Number tolua_is" .. self.name .. " (lua_State* L, int lo, int def, tolua_Error* err)") + output("int tolua_is" .. string.gsub(self.name,"::","_") .. " (lua_State* L, int lo, const char * type, int def, tolua_Error* err)") output("{") output("if (!tolua_isnumber(L,lo,def,err)) return 0;") output("lua_Number val = tolua_tonumber(L,lo,def);") @@ -130,7 +134,7 @@ function Enumerate (n,b,varname) e.min = min e.max = max if n ~= "" then - _enum_is_functions[n] = ("tolua_is" .. n) + _enums[n] = 1 Typedef("int "..n) end return _Enumerate(e, varname) diff --git a/lib/tolua++/src/bin/lua/function.lua b/lib/tolua++/src/bin/lua/function.lua index 7120fb063..ad1ab4225 100644 --- a/lib/tolua++/src/bin/lua/function.lua +++ b/lib/tolua++/src/bin/lua/function.lua @@ -54,6 +54,16 @@ function classFunction:supcode (local_constructor) local nret = 0 -- number of returned values local class = self:inclass() local _,_,static = strfind(self.mod,'^%s*(static)') + -- prototypes for enum functions + if self.args[1].type ~= 'void' then + local i=1 + while self.args[i] do + if isenum(self.args[i].type) then + emitenumprototype(self.args[i].type) + end + i = i+1 + end + end if class then if self.name == 'new' and self.parent.flags.pure_virtual then diff --git a/lib/tolua++/src/bin/toluabind.c b/lib/tolua++/src/bin/toluabind.c index 6be141580..06b371f70 100644 --- a/lib/tolua++/src/bin/toluabind.c +++ b/lib/tolua++/src/bin/toluabind.c @@ -3204,1011 +3204,8 @@ TOLUA_API int tolua_tolua_open (lua_State* tolua_S) { /* begin embedded lua code */ int top = lua_gettop(tolua_S); - static unsigned char B[] = { - 45, 45, 32,116,111,108,117, 97, 58, 32,100,101, 99,108, 97, - 114, 97,116,105,111,110, 32, 99,108, 97,115,115, 10, 45, 45, - 32, 87,114,105,116,116,101,110, 32, 98,121, 32, 87, 97,108, - 100,101,109, 97,114, 32, 67,101,108,101,115, 10, 45, 45, 32, - 84,101, 67, 71,114, 97,102, 47, 80, 85, 67, 45, 82,105,111, - 10, 45, 45, 32, 74,117,108, 32, 49, 57, 57, 56, 10, 45, 45, - 32, 36, 73,100, 58, 32, 36, 10, 10, 45, 45, 32, 84,104,105, - 115, 32, 99,111,100,101, 32,105,115, 32,102,114,101,101, 32, - 115,111,102,116,119, 97,114,101, 59, 32,121,111,117, 32, 99, - 97,110, 32,114,101,100,105,115,116,114,105, 98,117,116,101, - 32,105,116, 32, 97,110,100, 47,111,114, 32,109,111,100,105, - 102,121, 32,105,116, 46, 10, 45, 45, 32, 84,104,101, 32,115, - 111,102,116,119, 97,114,101, 32,112,114,111,118,105,100,101, - 100, 32,104,101,114,101,117,110,100,101,114, 32,105,115, 32, - 111,110, 32, 97,110, 32, 34, 97,115, 32,105,115, 34, 32, 98, - 97,115,105,115, 44, 32, 97,110,100, 10, 45, 45, 32,116,104, - 101, 32, 97,117,116,104,111,114, 32,104, 97,115, 32,110,111, - 32,111, 98,108,105,103, 97,116,105,111,110, 32,116,111, 32, - 112,114,111,118,105,100,101, 32,109, 97,105,110,116,101,110, - 97,110, 99,101, 44, 32,115,117,112,112,111,114,116, 44, 32, - 117,112,100, 97,116,101,115, 44, 10, 45, 45, 32,101,110,104, - 97,110, 99,101,109,101,110,116,115, 44, 32,111,114, 32,109, - 111,100,105,102,105, 99, 97,116,105,111,110,115, 46, 10, 10, - 10, 45, 45, 32, 68,101, 99,108, 97,114, 97,116,105,111,110, - 32, 99,108, 97,115,115, 10, 45, 45, 32, 82,101,112,114,101, - 115,101,110,116,115, 32,118, 97,114,105, 97, 98,108,101, 44, - 32,102,117,110, 99,116,105,111,110, 44, 32,111,114, 32, 97, - 114,103,117,109,101,110,116, 32,100,101, 99,108, 97,114, 97, - 116,105,111,110, 46, 10, 45, 45, 32, 83,116,111,114,101,115, - 32,116,104,101, 32,102,111,108,108,111,119,105,110,103, 32, - 102,105,101,108,100,115, 58, 10, 45, 45, 32, 32,109,111,100, - 32, 32, 61, 32,116,121,112,101, 32,109,111,100,105,102,105, - 101,114,115, 10, 45, 45, 32, 32,116,121,112,101, 32, 61, 32, - 116,121,112,101, 10, 45, 45, 32, 32,112,116,114, 32, 32, 61, - 32, 34, 42, 34, 32,111,114, 32, 34, 38, 34, 44, 32,105,102, - 32,114,101,112,114,101,115,101,110,116,105,110,103, 32, 97, - 32,112,111,105,110,116,101,114, 32,111,114, 32, 97, 32,114, - 101,102,101,114,101,110, 99,101, 10, 45, 45, 32, 32,110, 97, - 109,101, 32, 61, 32,110, 97,109,101, 10, 45, 45, 32, 32,100, - 105,109, 32, 32, 61, 32,100,105,109,101,110,115,105,111,110, - 44, 32,105,102, 32, 97, 32,118,101, 99,116,111,114, 10, 45, - 45, 32, 32,100,101,102, 32, 32, 61, 32,100,101,102, 97,117, - 108,116, 32,118, 97,108,117,101, 44, 32,105,102, 32, 97,110, - 121, 32, 40,111,110,108,121, 32,102,111,114, 32, 97,114,103, - 117,109,101,110,116,115, 41, 10, 45, 45, 32, 32,114,101,116, - 32, 32, 61, 32, 34, 42, 34, 32,111,114, 32, 34, 38, 34, 44, - 32,105,102, 32,118, 97,108,117,101, 32,105,115, 32,116,111, - 32, 98,101, 32,114,101,116,117,114,110,101,100, 32, 40,111, - 110,108,121, 32,102,111,114, 32, 97,114,103,117,109,101,110, - 116,115, 41, 10, 99,108, 97,115,115, 68,101, 99,108, 97,114, - 97,116,105,111,110, 32, 61, 32,123, 10, 32,109,111,100, 32, - 61, 32, 39, 39, 44, 10, 32,116,121,112,101, 32, 61, 32, 39, - 39, 44, 10, 32,112,116,114, 32, 61, 32, 39, 39, 44, 10, 32, - 110, 97,109,101, 32, 61, 32, 39, 39, 44, 10, 32,100,105,109, - 32, 61, 32, 39, 39, 44, 10, 32,114,101,116, 32, 61, 32, 39, - 39, 44, 10, 32,100,101,102, 32, 61, 32, 39, 39, 10,125, 10, - 99,108, 97,115,115, 68,101, 99,108, 97,114, 97,116,105,111, - 110, 46, 95, 95,105,110,100,101,120, 32, 61, 32, 99,108, 97, - 115,115, 68,101, 99,108, 97,114, 97,116,105,111,110, 10,115, - 101,116,109,101,116, 97,116, 97, 98,108,101, 40, 99,108, 97, - 115,115, 68,101, 99,108, 97,114, 97,116,105,111,110, 44, 99, - 108, 97,115,115, 70,101, 97,116,117,114,101, 41, 10, 10, 45, - 45, 32, 67,114,101, 97,116,101, 32, 97,110, 32,117,110,105, - 113,117,101, 32,118, 97,114,105, 97, 98,108,101, 32,110, 97, - 109,101, 10,102,117,110, 99,116,105,111,110, 32, 99,114,101, - 97,116,101, 95,118, 97,114,110, 97,109,101, 32, 40, 41, 10, - 32,105,102, 32,110,111,116, 32, 95,118, 97,114,110,117,109, - 98,101,114, 32,116,104,101,110, 32, 95,118, 97,114,110,117, - 109, 98,101,114, 32, 61, 32, 48, 32,101,110,100, 10, 32, 95, - 118, 97,114,110,117,109, 98,101,114, 32, 61, 32, 95,118, 97, - 114,110,117,109, 98,101,114, 32, 43, 32, 49, 10, 32,114,101, - 116,117,114,110, 32, 34,116,111,108,117, 97, 95,118, 97,114, - 95, 34, 46, 46, 95,118, 97,114,110,117,109, 98,101,114, 10, - 101,110,100, 10, 10, 45, 45, 32, 67,104,101, 99,107, 32,100, - 101, 99,108, 97,114, 97,116,105,111,110, 32,110, 97,109,101, - 10, 45, 45, 32, 73,116, 32, 97,108,115,111, 32,105,100,101, - 110,116,105,102,105,101,115, 32,100,101,102, 97,117,108,116, - 32,118, 97,108,117,101,115, 10,102,117,110, 99,116,105,111, - 110, 32, 99,108, 97,115,115, 68,101, 99,108, 97,114, 97,116, - 105,111,110, 58, 99,104,101, 99,107,110, 97,109,101, 32, 40, - 41, 10, 10, 32,105,102, 32,115,116,114,115,117, 98, 40,115, - 101,108,102, 46,110, 97,109,101, 44, 49, 44, 49, 41, 32, 61, - 61, 32, 39, 91, 39, 32, 97,110,100, 32,110,111,116, 32,102, - 105,110,100,116,121,112,101, 40,115,101,108,102, 46,116,121, - 112,101, 41, 32,116,104,101,110, 10, 32, 32,115,101,108,102, - 46,110, 97,109,101, 32, 61, 32,115,101,108,102, 46,116,121, - 112,101, 46, 46,115,101,108,102, 46,110, 97,109,101, 10, 32, - 32,108,111, 99, 97,108, 32,109, 32, 61, 32,115,112,108,105, - 116, 40,115,101,108,102, 46,109,111,100, 44, 39, 37,115, 37, - 115, 42, 39, 41, 10, 32, 32,115,101,108,102, 46,116,121,112, - 101, 32, 61, 32,109, 91,109, 46,110, 93, 10, 32, 32,115,101, - 108,102, 46,109,111,100, 32, 61, 32, 99,111,110, 99, 97,116, - 40,109, 44, 49, 44,109, 46,110, 45, 49, 41, 10, 32,101,110, - 100, 10, 10, 32,108,111, 99, 97,108, 32,116, 32, 61, 32,115, - 112,108,105,116, 40,115,101,108,102, 46,110, 97,109,101, 44, - 39, 61, 39, 41, 10, 32,105,102, 32,116, 46,110, 61, 61, 50, - 32,116,104,101,110, 10, 32, 32,115,101,108,102, 46,110, 97, - 109,101, 32, 61, 32,116, 91, 49, 93, 10, 32, 32,115,101,108, - 102, 46,100,101,102, 32, 61, 32,102,105,110,100, 95,101,110, - 117,109, 95,118, 97,114, 40,116, 91,116, 46,110, 93, 41, 10, - 32,101,110,100, 10, 10, 32,108,111, 99, 97,108, 32, 98, 44, - 101, 44,100, 32, 61, 32,115,116,114,102,105,110,100, 40,115, - 101,108,102, 46,110, 97,109,101, 44, 34, 37, 91, 40, 46, 45, - 41, 37, 93, 34, 41, 10, 32,105,102, 32, 98, 32,116,104,101, - 110, 10, 32, 32,115,101,108,102, 46,110, 97,109,101, 32, 61, - 32,115,116,114,115,117, 98, 40,115,101,108,102, 46,110, 97, - 109,101, 44, 49, 44, 98, 45, 49, 41, 10, 32, 32,115,101,108, - 102, 46,100,105,109, 32, 61, 32,102,105,110,100, 95,101,110, - 117,109, 95,118, 97,114, 40,100, 41, 10, 32,101,110,100, 10, - 10, 10, 32,105,102, 32,115,101,108,102, 46,116,121,112,101, - 32,126, 61, 32, 39, 39, 32, 97,110,100, 32,115,101,108,102, - 46,116,121,112,101, 32,126, 61, 32, 39,118,111,105,100, 39, - 32, 97,110,100, 32,115,101,108,102, 46,110, 97,109,101, 32, - 61, 61, 32, 39, 39, 32,116,104,101,110, 10, 32, 32,115,101, - 108,102, 46,110, 97,109,101, 32, 61, 32, 99,114,101, 97,116, - 101, 95,118, 97,114,110, 97,109,101, 40, 41, 10, 32,101,108, - 115,101,105,102, 32,115,101,108,102, 46,107,105,110,100, 61, - 61, 39,118, 97,114, 39, 32,116,104,101,110, 10, 32, 32,105, - 102, 32,115,101,108,102, 46,116,121,112,101, 61, 61, 39, 39, - 32, 97,110,100, 32,115,101,108,102, 46,110, 97,109,101,126, - 61, 39, 39, 32,116,104,101,110, 10, 32, 32, 32,115,101,108, - 102, 46,116,121,112,101, 32, 61, 32,115,101,108,102, 46,116, - 121,112,101, 46, 46,115,101,108,102, 46,110, 97,109,101, 10, - 32, 32, 32,115,101,108,102, 46,110, 97,109,101, 32, 61, 32, - 99,114,101, 97,116,101, 95,118, 97,114,110, 97,109,101, 40, - 41, 10, 32, 32,101,108,115,101,105,102, 32,102,105,110,100, - 116,121,112,101, 40,115,101,108,102, 46,110, 97,109,101, 41, - 32,116,104,101,110, 10, 32, 32, 32,105,102, 32,115,101,108, - 102, 46,116,121,112,101, 61, 61, 39, 39, 32,116,104,101,110, - 32,115,101,108,102, 46,116,121,112,101, 32, 61, 32,115,101, - 108,102, 46,110, 97,109,101, 10, 32, 32, 32,101,108,115,101, - 32,115,101,108,102, 46,116,121,112,101, 32, 61, 32,115,101, - 108,102, 46,116,121,112,101, 46, 46, 39, 32, 39, 46, 46,115, - 101,108,102, 46,110, 97,109,101, 32,101,110,100, 10, 32, 32, - 32,115,101,108,102, 46,110, 97,109,101, 32, 61, 32, 99,114, - 101, 97,116,101, 95,118, 97,114,110, 97,109,101, 40, 41, 10, - 32, 32,101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, - 32, 97,100,106,117,115,116, 32,116,121,112,101, 32,111,102, - 32,115,116,114,105,110,103, 10, 32,105,102, 32,115,101,108, - 102, 46,116,121,112,101, 32, 61, 61, 32, 39, 99,104, 97,114, - 39, 32, 97,110,100, 32,115,101,108,102, 46,100,105,109, 32, - 126, 61, 32, 39, 39, 32,116,104,101,110, 10, 9, 32,115,101, - 108,102, 46,116,121,112,101, 32, 61, 32, 39, 99,104, 97,114, - 42, 39, 10, 32,101,110,100, 10, 10, 9,105,102, 32,115,101, - 108,102, 46,107,105,110,100, 32, 97,110,100, 32,115,101,108, - 102, 46,107,105,110,100, 32, 61, 61, 32, 39,118, 97,114, 39, - 32,116,104,101,110, 10, 9, 9,115,101,108,102, 46,110, 97, - 109,101, 32, 61, 32,115,116,114,105,110,103, 46,103,115,117, - 98, 40,115,101,108,102, 46,110, 97,109,101, 44, 32, 34, 58, - 46, 42, 36, 34, 44, 32, 34, 34, 41, 32, 45, 45, 32, 63, 63, - 63, 10, 9,101,110,100, 10,101,110,100, 10, 10, 45, 45, 32, - 67,104,101, 99,107, 32,100,101, 99,108, 97,114, 97,116,105, - 111,110, 32,116,121,112,101, 10, 45, 45, 32, 83,117, 98,115, - 116,105,116,117,116,101,115, 32,116,121,112,101,100,101,102, - 39,115, 46, 10,102,117,110, 99,116,105,111,110, 32, 99,108, - 97,115,115, 68,101, 99,108, 97,114, 97,116,105,111,110, 58, - 99,104,101, 99,107,116,121,112,101, 32, 40, 41, 10, 10, 32, - 45, 45, 32, 99,104,101, 99,107, 32,105,102, 32,116,104,101, - 114,101, 32,105,115, 32, 97, 32,112,111,105,110,116,101,114, - 32,116,111, 32, 98, 97,115,105, 99, 32,116,121,112,101, 10, - 32,108,111, 99, 97,108, 32, 98, 97,115,105, 99, 32, 61, 32, - 105,115, 98, 97,115,105, 99, 40,115,101,108,102, 46,116,121, - 112,101, 41, 10, 32,105,102, 32,115,101,108,102, 46,107,105, - 110,100, 32, 61, 61, 32, 39,102,117,110, 99, 39, 32, 97,110, - 100, 32, 98, 97,115,105, 99, 61, 61, 39,110,117,109, 98,101, - 114, 39, 32, 97,110,100, 32,115,116,114,105,110,103, 46,102, - 105,110,100, 40,115,101,108,102, 46,112,116,114, 44, 32, 34, - 37, 42, 34, 41, 32,116,104,101,110, 10, 32, 9,115,101,108, - 102, 46,116,121,112,101, 32, 61, 32, 39, 95,117,115,101,114, - 100, 97,116, 97, 39, 10, 32, 9,115,101,108,102, 46,112,116, - 114, 32, 61, 32, 34, 34, 10, 32,101,110,100, 10, 32,105,102, - 32, 98, 97,115,105, 99, 32, 97,110,100, 32,115,101,108,102, - 46,112,116,114,126, 61, 39, 39, 32,116,104,101,110, 10, 32, - 32,115,101,108,102, 46,114,101,116, 32, 61, 32,115,101,108, - 102, 46,112,116,114, 10, 32, 32,115,101,108,102, 46,112,116, - 114, 32, 61, 32,110,105,108, 10, 32, 32,105,102, 32,105,115, - 98, 97,115,105, 99, 40,115,101,108,102, 46,116,121,112,101, - 41, 32, 61, 61, 32, 39,110,117,109, 98,101,114, 39, 32,116, - 104,101,110, 10, 32, 32, 9,115,101,108,102, 46,114,101,116, - 117,114,110, 95,117,115,101,114,100, 97,116, 97, 32, 61, 32, - 116,114,117,101, 10, 32, 32,101,110,100, 10, 32,101,110,100, - 10, 10, 32, 45, 45, 32, 99,104,101, 99,107, 32,105,102, 32, - 116,104,101,114,101, 32,105,115, 32, 97,114,114, 97,121, 32, - 116,111, 32, 98,101, 32,114,101,116,117,114,110,101,100, 10, - 32,105,102, 32,115,101,108,102, 46,100,105,109,126, 61, 39, - 39, 32, 97,110,100, 32,115,101,108,102, 46,114,101,116,126, - 61, 39, 39, 32,116,104,101,110, 10, 32, 32, 32,101,114,114, - 111,114, 40, 39, 35,105,110,118, 97,108,105,100, 32,112, 97, - 114, 97,109,101,116,101,114, 58, 32, 99, 97,110,110,111,116, - 32,114,101,116,117,114,110, 32, 97,110, 32, 97,114,114, 97, - 121, 32,111,102, 32,118, 97,108,117,101,115, 39, 41, 10, 32, - 101,110,100, 10, 32, 45, 45, 32,114,101,115,116,111,114,101, - 32, 39,118,111,105,100, 42, 39, 32, 97,110,100, 32, 39,115, - 116,114,105,110,103, 42, 39, 10, 32,105,102, 32,115,101,108, - 102, 46,116,121,112,101, 32, 61, 61, 32, 39, 95,117,115,101, - 114,100, 97,116, 97, 39, 32,116,104,101,110, 32,115,101,108, - 102, 46,116,121,112,101, 32, 61, 32, 39,118,111,105,100, 42, - 39, 10, 32,101,108,115,101,105,102, 32,115,101,108,102, 46, - 116,121,112,101, 32, 61, 61, 32, 39, 95, 99,115,116,114,105, - 110,103, 39, 32,116,104,101,110, 32,115,101,108,102, 46,116, - 121,112,101, 32, 61, 32, 39, 99,104, 97,114, 42, 39, 10, 32, - 101,108,115,101,105,102, 32,115,101,108,102, 46,116,121,112, - 101, 32, 61, 61, 32, 39, 95,108,115,116, 97,116,101, 39, 32, - 116,104,101,110, 32,115,101,108,102, 46,116,121,112,101, 32, - 61, 32, 39,108,117, 97, 95, 83,116, 97,116,101, 42, 39, 10, - 32,101,110,100, 10, 10, 32, 45, 45, 32,114,101,115,111,108, - 118,101, 32,116,121,112,101,115, 32,105,110,115,105,100,101, - 32,116,104,101, 32,116,101,109,112,108, 97,116,101,115, 10, - 32,105,102, 32,115,101,108,102, 46,116,121,112,101, 32,116, - 104,101,110, 10, 9, 32,115,101,108,102, 46,116,121,112,101, - 32, 61, 32,114,101,115,111,108,118,101, 95,116,101,109,112, - 108, 97,116,101, 95,116,121,112,101,115, 40,115,101,108,102, - 46,116,121,112,101, 41, 10, 32,101,110,100, 10, 10, 45, 45, - 10, 45, 45, 32, 45, 45, 32,105,102, 32,114,101,116,117,114, - 110,105,110,103, 32,118, 97,108,117,101, 44, 32, 97,117,116, - 111,109, 97,116,105, 99, 97,108,108,121, 32,115,101,116, 32, - 100,101,102, 97,117,108,116, 32,118, 97,108,117,101, 10, 45, - 45, 32,105,102, 32,115,101,108,102, 46,114,101,116, 32,126, - 61, 32, 39, 39, 32, 97,110,100, 32,115,101,108,102, 46,100, - 101,102, 32, 61, 61, 32, 39, 39, 32,116,104,101,110, 10, 45, - 45, 32, 32,115,101,108,102, 46,100,101,102, 32, 61, 32, 39, - 48, 39, 10, 45, 45, 32,101,110,100, 10, 45, 45, 10, 10,101, - 110,100, 10, 10,102,117,110, 99,116,105,111,110, 32,114,101, - 115,111,108,118,101, 95,116,101,109,112,108, 97,116,101, 95, - 116,121,112,101,115, 40,116,121,112,101, 41, 10, 10, 9,105, - 102, 32,105,115, 98, 97,115,105, 99, 40,116,121,112,101, 41, - 32,116,104,101,110, 10, 9, 9,114,101,116,117,114,110, 32, - 116,121,112,101, 10, 9,101,110,100, 10, 9,108,111, 99, 97, - 108, 32, 98, 44, 95, 44,109, 32, 61, 32,115,116,114,105,110, - 103, 46,102,105,110,100, 40,116,121,112,101, 44, 32, 34, 40, - 37, 98, 60, 62, 41, 34, 41, 10, 9,105,102, 32, 98, 32,116, - 104,101,110, 10, 10, 9, 9,109, 32, 61, 32,115,112,108,105, - 116, 95, 99, 95,116,111,107,101,110,115, 40,115,116,114,105, - 110,103, 46,115,117, 98, 40,109, 44, 32, 50, 44, 32, 45, 50, - 41, 44, 32, 34, 44, 34, 41, 10, 9, 9,102,111,114, 32,105, - 61, 49, 44, 32,116, 97, 98,108,101, 46,103,101,116,110, 40, - 109, 41, 32,100,111, 10, 9, 9, 9,109, 91,105, 93, 32, 61, - 32,115,116,114,105,110,103, 46,103,115,117, 98, 40,109, 91, - 105, 93, 44, 34, 37,115, 42, 40, 91, 37, 42, 38, 93, 41, 34, - 44, 32, 34, 37, 49, 34, 41, 10, 9, 9, 9,105,102, 32,110, - 111,116, 32,105,115, 98, 97,115,105, 99, 40,109, 91,105, 93, - 41, 32,116,104,101,110, 10, 9, 9, 9, 9,105,102, 32,110, - 111,116, 32,105,115,101,110,117,109, 40,109, 91,105, 93, 41, - 32,116,104,101,110, 32, 95, 44, 32,109, 91,105, 93, 32, 61, - 32, 97,112,112,108,121,116,121,112,101,100,101,102, 40, 34, - 34, 44, 32,109, 91,105, 93, 41, 32,101,110,100, 10, 9, 9, - 9, 9,109, 91,105, 93, 32, 61, 32,102,105,110,100,116,121, - 112,101, 40,109, 91,105, 93, 41, 32,111,114, 32,109, 91,105, - 93, 10, 9, 9, 9, 9,109, 91,105, 93, 32, 61, 32,114,101, - 115,111,108,118,101, 95,116,101,109,112,108, 97,116,101, 95, - 116,121,112,101,115, 40,109, 91,105, 93, 41, 10, 9, 9, 9, - 101,110,100, 10, 9, 9,101,110,100, 10, 10, 9, 9,108,111, - 99, 97,108, 32, 98, 44,105, 10, 9, 9,116,121,112,101, 44, - 98, 44,105, 32, 61, 32, 98,114,101, 97,107, 95,116,101,109, - 112,108, 97,116,101, 40,116,121,112,101, 41, 10, 45, 45,112, - 114,105,110,116, 40, 34, 99,111,110, 99, 97,116, 32,105,115, - 32, 34, 44, 99,111,110, 99, 97,116, 40,109, 44, 32, 49, 44, - 32,109, 46,110, 41, 41, 10, 9, 9,108,111, 99, 97,108, 32, - 116,101,109,112,108, 97,116,101, 95,112, 97,114,116, 32, 61, - 32, 34, 60, 34, 46, 46, 99,111,110, 99, 97,116, 40,109, 44, - 32, 49, 44, 32,109, 46,110, 44, 32, 34, 44, 34, 41, 46, 46, - 34, 62, 34, 10, 9, 9,116,121,112,101, 32, 61, 32,114,101, - 98,117,105,108,100, 95,116,101,109,112,108, 97,116,101, 40, - 116,121,112,101, 44, 32, 98, 44, 32,116,101,109,112,108, 97, - 116,101, 95,112, 97,114,116, 41, 10, 9, 9,116,121,112,101, - 32, 61, 32,115,116,114,105,110,103, 46,103,115,117, 98, 40, - 116,121,112,101, 44, 32, 34, 62, 62, 34, 44, 32, 34, 62, 32, - 62, 34, 41, 10, 9,101,110,100, 10, 9,114,101,116,117,114, - 110, 32,116,121,112,101, 10,101,110,100, 10, 10,102,117,110, - 99,116,105,111,110, 32, 98,114,101, 97,107, 95,116,101,109, - 112,108, 97,116,101, 40,115, 41, 10, 9,108,111, 99, 97,108, - 32, 98, 44,101, 44,116,105,109,112,108, 32, 61, 32,115,116, - 114,105,110,103, 46,102,105,110,100, 40,115, 44, 32, 34, 40, - 37, 98, 60, 62, 41, 34, 41, 10, 9,105,102, 32,116,105,109, - 112,108, 32,116,104,101,110, 10, 9, 9,115, 32, 61, 32,115, - 116,114,105,110,103, 46,103,115,117, 98, 40,115, 44, 32, 34, - 37, 98, 60, 62, 34, 44, 32, 34, 34, 41, 10, 9, 9,114,101, - 116,117,114,110, 32,115, 44, 32, 98, 44, 32,116,105,109,112, - 108, 10, 9,101,108,115,101, 10, 9, 9,114,101,116,117,114, - 110, 32,115, 44, 32, 48, 44, 32,110,105,108, 10, 9,101,110, - 100, 10,101,110,100, 10, 10,102,117,110, 99,116,105,111,110, - 32,114,101, 98,117,105,108,100, 95,116,101,109,112,108, 97, - 116,101, 40,115, 44, 32, 98, 44, 32,116,105,109,112,108, 41, - 10, 10, 9,105,102, 32, 98, 32, 61, 61, 32, 48, 32,116,104, - 101,110, 10, 9, 9,114,101,116,117,114,110, 32,115, 10, 9, - 101,110,100, 10, 10, 9,114,101,116,117,114,110, 32,115,116, - 114,105,110,103, 46,115,117, 98, 40,115, 44, 32, 49, 44, 32, - 98, 45, 49, 41, 46, 46,116,105,109,112,108, 46, 46,115,116, - 114,105,110,103, 46,115,117, 98, 40,115, 44, 32, 98, 44, 32, - 45, 49, 41, 10,101,110,100, 10, 10, 45, 45, 32, 80,114,105, - 110,116, 32,109,101,116,104,111,100, 10,102,117,110, 99,116, - 105,111,110, 32, 99,108, 97,115,115, 68,101, 99,108, 97,114, - 97,116,105,111,110, 58,112,114,105,110,116, 32, 40,105,100, - 101,110,116, 44, 99,108,111,115,101, 41, 10, 32,112,114,105, - 110,116, 40,105,100,101,110,116, 46, 46, 34, 68,101, 99,108, - 97,114, 97,116,105,111,110,123, 34, 41, 10, 32,112,114,105, - 110,116, 40,105,100,101,110,116, 46, 46, 34, 32,109,111,100, - 32, 32, 61, 32, 39, 34, 46, 46,115,101,108,102, 46,109,111, - 100, 46, 46, 34, 39, 44, 34, 41, 10, 32,112,114,105,110,116, - 40,105,100,101,110,116, 46, 46, 34, 32,116,121,112,101, 32, - 61, 32, 39, 34, 46, 46,115,101,108,102, 46,116,121,112,101, - 46, 46, 34, 39, 44, 34, 41, 10, 32,112,114,105,110,116, 40, - 105,100,101,110,116, 46, 46, 34, 32,112,116,114, 32, 32, 61, - 32, 39, 34, 46, 46,115,101,108,102, 46,112,116,114, 46, 46, - 34, 39, 44, 34, 41, 10, 32,112,114,105,110,116, 40,105,100, - 101,110,116, 46, 46, 34, 32,110, 97,109,101, 32, 61, 32, 39, - 34, 46, 46,115,101,108,102, 46,110, 97,109,101, 46, 46, 34, - 39, 44, 34, 41, 10, 32,112,114,105,110,116, 40,105,100,101, - 110,116, 46, 46, 34, 32,100,105,109, 32, 32, 61, 32, 39, 34, - 46, 46,115,101,108,102, 46,100,105,109, 46, 46, 34, 39, 44, - 34, 41, 10, 32,112,114,105,110,116, 40,105,100,101,110,116, - 46, 46, 34, 32,100,101,102, 32, 32, 61, 32, 39, 34, 46, 46, - 115,101,108,102, 46,100,101,102, 46, 46, 34, 39, 44, 34, 41, - 10, 32,112,114,105,110,116, 40,105,100,101,110,116, 46, 46, - 34, 32,114,101,116, 32, 32, 61, 32, 39, 34, 46, 46,115,101, - 108,102, 46,114,101,116, 46, 46, 34, 39, 44, 34, 41, 10, 32, - 112,114,105,110,116, 40,105,100,101,110,116, 46, 46, 34,125, - 34, 46, 46, 99,108,111,115,101, 41, 10,101,110,100, 10, 10, - 45, 45, 32, 99,104,101, 99,107, 32,105,102, 32, 97,114,114, - 97,121, 32,111,102, 32,118, 97,108,117,101,115, 32, 97,114, - 101, 32,114,101,116,117,114,110,101,100, 32,116,111, 32, 76, - 117, 97, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97, - 115,115, 68,101, 99,108, 97,114, 97,116,105,111,110, 58,114, - 101,113,117,105,114,101, 99,111,108,108,101, 99,116,105,111, - 110, 32, 40,116, 41, 10, 32,105,102, 32,115,101,108,102, 46, - 109,111,100, 32,126, 61, 32, 39, 99,111,110,115,116, 39, 32, - 97,110,100, 10, 9, 32, 32, 32, 32,115,101,108,102, 46,100, - 105,109, 32, 97,110,100, 32,115,101,108,102, 46,100,105,109, - 32,126, 61, 32, 39, 39, 32, 97,110,100, 10, 9, 9, 9, 9, - 32,110,111,116, 32,105,115, 98, 97,115,105, 99, 40,115,101, - 108,102, 46,116,121,112,101, 41, 32, 97,110,100, 10, 9, 9, - 9, 9, 32,115,101,108,102, 46,112,116,114, 32, 61, 61, 32, - 39, 39, 32, 97,110,100, 32,115,101,108,102, 58, 99,104,101, - 99,107, 95,112,117, 98,108,105, 99, 95, 97, 99, 99,101,115, - 115, 40, 41, 32,116,104,101,110, 10, 9, 9,108,111, 99, 97, - 108, 32,116,121,112,101, 32, 61, 32,103,115,117, 98, 40,115, - 101,108,102, 46,116,121,112,101, 44, 34, 37,115, 42, 99,111, - 110,115,116, 37,115, 43, 34, 44, 34, 34, 41, 10, 9, 9,116, - 91,116,121,112,101, 93, 32, 61, 32, 34,116,111,108,117, 97, - 95, 99,111,108,108,101, 99,116, 95, 34, 32, 46, 46, 32, 99, - 108,101, 97,110, 95,116,101,109,112,108, 97,116,101, 40,116, - 121,112,101, 41, 10, 9, 9,114,101,116,117,114,110, 32,116, - 114,117,101, 10, 9,101,110,100, 10, 9,114,101,116,117,114, - 110, 32,102, 97,108,115,101, 10,101,110,100, 10, 10, 45, 45, - 32,100,101, 99,108, 97,114,101, 32,116, 97,103, 10,102,117, - 110, 99,116,105,111,110, 32, 99,108, 97,115,115, 68,101, 99, - 108, 97,114, 97,116,105,111,110, 58,100,101, 99,108,116,121, - 112,101, 32, 40, 41, 10, 10, 9,115,101,108,102, 46,116,121, - 112,101, 32, 61, 32,116,121,112,101,118, 97,114, 40,115,101, - 108,102, 46,116,121,112,101, 41, 10, 9,105,102, 32,115,116, - 114,102,105,110,100, 40,115,101,108,102, 46,109,111,100, 44, - 39, 99,111,110,115,116, 39, 41, 32,116,104,101,110, 10, 9, - 9,115,101,108,102, 46,116,121,112,101, 32, 61, 32, 39, 99, - 111,110,115,116, 32, 39, 46, 46,115,101,108,102, 46,116,121, - 112,101, 10, 9, 9,115,101,108,102, 46,109,111,100, 32, 61, - 32,103,115,117, 98, 40,115,101,108,102, 46,109,111,100, 44, - 39, 99,111,110,115,116, 37,115, 42, 39, 44, 39, 39, 41, 10, - 9,101,110,100, 10,101,110,100, 10, 10, 10, 45, 45, 32,111, - 117,116,112,117,116, 32,116,121,112,101, 32, 99,104,101, 99, - 107,105,110,103, 10,102,117,110, 99,116,105,111,110, 32, 99, - 108, 97,115,115, 68,101, 99,108, 97,114, 97,116,105,111,110, - 58,111,117,116, 99,104,101, 99,107,116,121,112,101, 32, 40, - 110, 97,114,103, 41, 10, 32,108,111, 99, 97,108, 32,100,101, - 102, 10, 32,108,111, 99, 97,108, 32,116, 32, 61, 32,105,115, - 98, 97,115,105, 99, 40,115,101,108,102, 46,116,121,112,101, - 41, 10, 32,105,102, 32,115,101,108,102, 46,100,101,102,126, - 61, 39, 39, 32,116,104,101,110, 10, 32, 32,100,101,102, 32, - 61, 32, 49, 10, 32,101,108,115,101, 10, 32, 32,100,101,102, - 32, 61, 32, 48, 10, 32,101,110,100, 10, 32,105,102, 32,115, - 101,108,102, 46,100,105,109, 32,126, 61, 32, 39, 39, 32,116, - 104,101,110, 10, 9, 45, 45,105,102, 32,116, 61, 61, 39,115, - 116,114,105,110,103, 39, 32,116,104,101,110, 10, 9, 45, 45, - 9,114,101,116,117,114,110, 32, 39,116,111,108,117, 97, 95, - 105,115,115,116,114,105,110,103, 97,114,114, 97,121, 40,116, - 111,108,117, 97, 95, 83, 44, 39, 46, 46,110, 97,114,103, 46, - 46, 39, 44, 39, 46, 46,100,101,102, 46, 46, 39, 44, 38,116, - 111,108,117, 97, 95,101,114,114, 41, 39, 10, 9, 45, 45,101, - 108,115,101, 10, 9,114,101,116,117,114,110, 32, 39, 33,116, - 111,108,117, 97, 95,105,115,116, 97, 98,108,101, 40,116,111, - 108,117, 97, 95, 83, 44, 39, 46, 46,110, 97,114,103, 46, 46, - 39, 44, 48, 44, 38,116,111,108,117, 97, 95,101,114,114, 41, - 39, 10, 32, 9, 45, 45,101,110,100, 10, 32,101,108,115,101, - 105,102, 32,116, 32,116,104,101,110, 10, 9,114,101,116,117, - 114,110, 32, 39, 33,116,111,108,117, 97, 95,105,115, 39, 46, - 46,116, 46, 46, 39, 40,116,111,108,117, 97, 95, 83, 44, 39, - 46, 46,110, 97,114,103, 46, 46, 39, 44, 39, 46, 46,100,101, - 102, 46, 46, 39, 44, 38,116,111,108,117, 97, 95,101,114,114, - 41, 39, 10, 32,101,108,115,101, 10, 32, 32,108,111, 99, 97, - 108, 32,105,115, 95,102,117,110, 99, 32, 61, 32,103,101,116, - 95,105,115, 95,102,117,110, 99,116,105,111,110, 40,115,101, - 108,102, 46,116,121,112,101, 41, 10, 32, 32,105,102, 32,115, - 101,108,102, 46,112,116,114, 32, 61, 61, 32, 39, 38, 39, 32, - 111,114, 32,115,101,108,102, 46,112,116,114, 32, 61, 61, 32, - 39, 39, 32,116,104,101,110, 10, 32, 32, 9,114,101,116,117, - 114,110, 32, 39, 40,116,111,108,117, 97, 95,105,115,118, 97, - 108,117,101,110,105,108, 40,116,111,108,117, 97, 95, 83, 44, - 39, 46, 46,110, 97,114,103, 46, 46, 39, 44, 38,116,111,108, - 117, 97, 95,101,114,114, 41, 32,124,124, 32, 33, 39, 46, 46, - 105,115, 95,102,117,110, 99, 46, 46, 39, 40,116,111,108,117, - 97, 95, 83, 44, 39, 46, 46,110, 97,114,103, 46, 46, 39, 44, - 34, 39, 46, 46,115,101,108,102, 46,116,121,112,101, 46, 46, - 39, 34, 44, 39, 46, 46,100,101,102, 46, 46, 39, 44, 38,116, - 111,108,117, 97, 95,101,114,114, 41, 41, 39, 10, 32, 32,101, - 108,115,101, 10, 9,114,101,116,117,114,110, 32, 39, 33, 39, - 46, 46,105,115, 95,102,117,110, 99, 46, 46, 39, 40,116,111, - 108,117, 97, 95, 83, 44, 39, 46, 46,110, 97,114,103, 46, 46, - 39, 44, 34, 39, 46, 46,115,101,108,102, 46,116,121,112,101, - 46, 46, 39, 34, 44, 39, 46, 46,100,101,102, 46, 46, 39, 44, - 38,116,111,108,117, 97, 95,101,114,114, 41, 39, 10, 32, 32, - 101,110,100, 10, 32,101,110,100, 10,101,110,100, 10, 10,102, - 117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, 68,101, - 99,108, 97,114, 97,116,105,111,110, 58, 98,117,105,108,100, - 100,101, 99,108, 97,114, 97,116,105,111,110, 32, 40,110, 97, - 114,103, 44, 32, 99,112,108,117,115,112,108,117,115, 41, 10, - 32,108,111, 99, 97,108, 32, 97,114,114, 97,121, 32, 61, 32, - 115,101,108,102, 46,100,105,109, 32,126, 61, 32, 39, 39, 32, - 97,110,100, 32,116,111,110,117,109, 98,101,114, 40,115,101, - 108,102, 46,100,105,109, 41, 61, 61,110,105,108, 10, 9,108, - 111, 99, 97,108, 32,108,105,110,101, 32, 61, 32, 34, 34, 10, - 32,108,111, 99, 97,108, 32,112,116,114, 32, 61, 32, 39, 39, - 10, 32,108,111, 99, 97,108, 32,109,111,100, 10, 32,108,111, - 99, 97,108, 32,116,121,112,101, 32, 61, 32,115,101,108,102, - 46,116,121,112,101, 10, 32,108,111, 99, 97,108, 32,110, 99, - 116,121,112,101, 32, 61, 32,103,115,117, 98, 40,115,101,108, - 102, 46,116,121,112,101, 44, 39, 99,111,110,115,116, 37,115, - 43, 39, 44, 39, 39, 41, 10, 32,105,102, 32,115,101,108,102, - 46,100,105,109, 32,126, 61, 32, 39, 39, 32,116,104,101,110, - 10, 9, 32,116,121,112,101, 32, 61, 32,103,115,117, 98, 40, - 115,101,108,102, 46,116,121,112,101, 44, 39, 99,111,110,115, - 116, 37,115, 43, 39, 44, 39, 39, 41, 32, 32, 45, 45, 32,101, - 108,105,109,105,110, 97,116,101,115, 32, 99,111,110,115,116, - 32,109,111,100,105,102,105,101,114, 32,102,111,114, 32, 97, - 114,114, 97,121,115, 10, 32,101,110,100, 10, 32,105,102, 32, - 115,101,108,102, 46,112,116,114,126, 61, 39, 39, 32, 97,110, - 100, 32,110,111,116, 32,105,115, 98, 97,115,105, 99, 40,116, - 121,112,101, 41, 32,116,104,101,110, 32,112,116,114, 32, 61, - 32, 39, 42, 39, 32,101,110,100, 10, 32,108,105,110,101, 32, - 61, 32, 99,111,110, 99, 97,116,112, 97,114, 97,109, 40,108, - 105,110,101, 44, 34, 32, 34, 44,115,101,108,102, 46,109,111, - 100, 44,116,121,112,101, 44,112,116,114, 41, 10, 32,105,102, - 32, 97,114,114, 97,121, 32,116,104,101,110, 10, 32, 32,108, - 105,110,101, 32, 61, 32, 99,111,110, 99, 97,116,112, 97,114, - 97,109, 40,108,105,110,101, 44, 39, 42, 39, 41, 10, 32,101, - 110,100, 10, 32,108,105,110,101, 32, 61, 32, 99,111,110, 99, - 97,116,112, 97,114, 97,109, 40,108,105,110,101, 44,115,101, - 108,102, 46,110, 97,109,101, 41, 10, 32,105,102, 32,115,101, - 108,102, 46,100,105,109, 32,126, 61, 32, 39, 39, 32,116,104, - 101,110, 10, 32, 32,105,102, 32,116,111,110,117,109, 98,101, - 114, 40,115,101,108,102, 46,100,105,109, 41,126, 61,110,105, - 108, 32,116,104,101,110, 10, 32, 32, 32,108,105,110,101, 32, - 61, 32, 99,111,110, 99, 97,116,112, 97,114, 97,109, 40,108, - 105,110,101, 44, 39, 91, 39, 44,115,101,108,102, 46,100,105, - 109, 44, 39, 93, 59, 39, 41, 10, 32, 32,101,108,115,101, 10, - 9,105,102, 32, 99,112,108,117,115,112,108,117,115, 32,116, - 104,101,110, 10, 9, 9,108,105,110,101, 32, 61, 32, 99,111, - 110, 99, 97,116,112, 97,114, 97,109, 40,108,105,110,101, 44, - 39, 32, 61, 32, 77,116,111,108,117, 97, 95,110,101,119, 95, - 100,105,109, 40, 39, 44,116,121,112,101, 44,112,116,114, 44, - 39, 44, 32, 39, 46, 46,115,101,108,102, 46,100,105,109, 46, - 46, 39, 41, 59, 39, 41, 10, 9,101,108,115,101, 10, 9, 9, - 108,105,110,101, 32, 61, 32, 99,111,110, 99, 97,116,112, 97, - 114, 97,109, 40,108,105,110,101, 44, 39, 32, 61, 32, 40, 39, - 44,116,121,112,101, 44,112,116,114, 44, 39, 42, 41, 39, 44, - 10, 9, 9, 39,109, 97,108,108,111, 99, 40, 40, 39, 44,115, - 101,108,102, 46,100,105,109, 44, 39, 41, 42,115,105,122,101, - 111,102, 40, 39, 44,116,121,112,101, 44,112,116,114, 44, 39, - 41, 41, 59, 39, 41, 10, 9,101,110,100, 10, 32, 32,101,110, - 100, 10, 32,101,108,115,101, 10, 32, 32,108,111, 99, 97,108, - 32,116, 32, 61, 32,105,115, 98, 97,115,105, 99, 40,116,121, - 112,101, 41, 10, 32, 32,108,105,110,101, 32, 61, 32, 99,111, - 110, 99, 97,116,112, 97,114, 97,109, 40,108,105,110,101, 44, - 39, 32, 61, 32, 39, 41, 10, 32, 32,105,102, 32,116, 32, 61, - 61, 32, 39,115,116, 97,116,101, 39, 32,116,104,101,110, 10, - 32, 32, 9,108,105,110,101, 32, 61, 32, 99,111,110, 99, 97, - 116,112, 97,114, 97,109, 40,108,105,110,101, 44, 32, 39,116, - 111,108,117, 97, 95, 83, 59, 39, 41, 10, 32, 32,101,108,115, - 101, 10, 32, 32, 9, 45, 45,112,114,105,110,116, 40, 34,116, - 32,105,115, 32, 34, 46, 46,116,111,115,116,114,105,110,103, - 40,116, 41, 46, 46, 34, 44, 32,112,116,114, 32,105,115, 32, - 34, 46, 46,116,111,115,116,114,105,110,103, 40,115,101,108, - 102, 46,112,116,114, 41, 41, 10, 32, 32, 9,105,102, 32,116, - 32, 61, 61, 32, 39,110,117,109, 98,101,114, 39, 32, 97,110, - 100, 32,115,116,114,105,110,103, 46,102,105,110,100, 40,115, - 101,108,102, 46,112,116,114, 44, 32, 34, 37, 42, 34, 41, 32, - 116,104,101,110, 10, 32, 32, 9, 9,116, 32, 61, 32, 39,117, - 115,101,114,100, 97,116, 97, 39, 10, 32, 32, 9,101,110,100, - 10, 9,105,102, 32,110,111,116, 32,116, 32, 97,110,100, 32, - 112,116,114, 61, 61, 39, 39, 32,116,104,101,110, 32,108,105, - 110,101, 32, 61, 32, 99,111,110, 99, 97,116,112, 97,114, 97, - 109, 40,108,105,110,101, 44, 39, 42, 39, 41, 32,101,110,100, - 10, 9,108,105,110,101, 32, 61, 32, 99,111,110, 99, 97,116, - 112, 97,114, 97,109, 40,108,105,110,101, 44, 39, 40, 40, 39, - 44,115,101,108,102, 46,109,111,100, 44,116,121,112,101, 41, - 10, 9,105,102, 32,110,111,116, 32,116, 32,116,104,101,110, - 10, 9, 9,108,105,110,101, 32, 61, 32, 99,111,110, 99, 97, - 116,112, 97,114, 97,109, 40,108,105,110,101, 44, 39, 42, 39, - 41, 10, 9,101,110,100, 10, 9,108,105,110,101, 32, 61, 32, - 99,111,110, 99, 97,116,112, 97,114, 97,109, 40,108,105,110, - 101, 44, 39, 41, 32, 39, 41, 10, 9,105,102, 32,105,115,101, - 110,117,109, 40,110, 99,116,121,112,101, 41, 32,116,104,101, - 110, 10, 9, 9,108,105,110,101, 32, 61, 32, 99,111,110, 99, - 97,116,112, 97,114, 97,109, 40,108,105,110,101, 44, 39, 40, - 105,110,116, 41, 32, 39, 41, 10, 9,101,110,100, 10, 9,108, - 111, 99, 97,108, 32,100,101,102, 32, 61, 32, 48, 10, 9,105, - 102, 32,115,101,108,102, 46,100,101,102, 32,126, 61, 32, 39, - 39, 32,116,104,101,110, 10, 9, 9,100,101,102, 32, 61, 32, - 115,101,108,102, 46,100,101,102, 10, 9, 9,105,102, 32, 40, - 112,116,114, 32, 61, 61, 32, 39, 39, 32,111,114, 32,115,101, - 108,102, 46,112,116,114, 32, 61, 61, 32, 39, 38, 39, 41, 32, - 97,110,100, 32,110,111,116, 32,116, 32,116,104,101,110, 10, - 9, 9, 9,100,101,102, 32, 61, 32, 34, 40,118,111,105,100, - 42, 41, 38, 40, 99,111,110,115,116, 32, 34, 46, 46,116,121, - 112,101, 46, 46, 34, 41, 34, 46, 46,100,101,102, 10, 9, 9, - 101,110,100, 10, 9,101,110,100, 10, 9,105,102, 32,116, 32, - 116,104,101,110, 10, 9, 9,108,105,110,101, 32, 61, 32, 99, - 111,110, 99, 97,116,112, 97,114, 97,109, 40,108,105,110,101, - 44, 39,116,111,108,117, 97, 95,116,111, 39, 46, 46,116, 44, - 39, 40,116,111,108,117, 97, 95, 83, 44, 39, 44,110, 97,114, - 103, 44, 39, 44, 39, 44,100,101,102, 44, 39, 41, 41, 59, 39, - 41, 10, 9,101,108,115,101, 10, 9, 9,108,111, 99, 97,108, - 32,116,111, 95,102,117,110, 99, 32, 61, 32,103,101,116, 95, - 116,111, 95,102,117,110, 99,116,105,111,110, 40,116,121,112, - 101, 41, 10, 9, 9,108,105,110,101, 32, 61, 32, 99,111,110, - 99, 97,116,112, 97,114, 97,109, 40,108,105,110,101, 44,116, - 111, 95,102,117,110, 99, 46, 46, 39, 40,116,111,108,117, 97, - 95, 83, 44, 39, 44,110, 97,114,103, 44, 39, 44, 39, 44,100, - 101,102, 44, 39, 41, 41, 59, 39, 41, 10, 9,101,110,100, 10, - 32, 32,101,110,100, 10, 32,101,110,100, 10, 9,114,101,116, - 117,114,110, 32,108,105,110,101, 10,101,110,100, 10, 10, 45, - 45, 32, 68,101, 99,108, 97,114,101, 32,118, 97,114,105, 97, - 98,108,101, 10,102,117,110, 99,116,105,111,110, 32, 99,108, - 97,115,115, 68,101, 99,108, 97,114, 97,116,105,111,110, 58, - 100,101, 99,108, 97,114,101, 32, 40,110, 97,114,103, 41, 10, - 32,105,102, 32,115,101,108,102, 46,100,105,109, 32,126, 61, - 32, 39, 39, 32, 97,110,100, 32,116,111,110,117,109, 98,101, - 114, 40,115,101,108,102, 46,100,105,109, 41, 61, 61,110,105, - 108, 32,116,104,101,110, 10, 9, 32,111,117,116,112,117,116, - 40, 39, 35,105,102,100,101,102, 32, 95, 95, 99,112,108,117, - 115,112,108,117,115, 92,110, 39, 41, 10, 9, 9,111,117,116, - 112,117,116, 40,115,101,108,102, 58, 98,117,105,108,100,100, - 101, 99,108, 97,114, 97,116,105,111,110, 40,110, 97,114,103, - 44,116,114,117,101, 41, 41, 10, 9, 9,111,117,116,112,117, - 116, 40, 39, 35,101,108,115,101, 92,110, 39, 41, 10, 9, 9, - 111,117,116,112,117,116, 40,115,101,108,102, 58, 98,117,105, - 108,100,100,101, 99,108, 97,114, 97,116,105,111,110, 40,110, - 97,114,103, 44,102, 97,108,115,101, 41, 41, 10, 9, 32,111, - 117,116,112,117,116, 40, 39, 35,101,110,100,105,102, 92,110, - 39, 41, 10, 9,101,108,115,101, 10, 9, 9,111,117,116,112, - 117,116, 40,115,101,108,102, 58, 98,117,105,108,100,100,101, - 99,108, 97,114, 97,116,105,111,110, 40,110, 97,114,103, 44, - 102, 97,108,115,101, 41, 41, 10, 9,101,110,100, 10,101,110, - 100, 10, 10, 45, 45, 32, 71,101,116, 32,112, 97,114, 97,109, - 101,116,101,114, 32,118, 97,108,117,101, 10,102,117,110, 99, - 116,105,111,110, 32, 99,108, 97,115,115, 68,101, 99,108, 97, - 114, 97,116,105,111,110, 58,103,101,116, 97,114,114, 97,121, - 32, 40,110, 97,114,103, 41, 10, 32,105,102, 32,115,101,108, - 102, 46,100,105,109, 32,126, 61, 32, 39, 39, 32,116,104,101, - 110, 10, 9, 32,108,111, 99, 97,108, 32,116,121,112,101, 32, - 61, 32,103,115,117, 98, 40,115,101,108,102, 46,116,121,112, - 101, 44, 39, 99,111,110,115,116, 32, 39, 44, 39, 39, 41, 10, - 32, 32,111,117,116,112,117,116, 40, 39, 32, 32,123, 39, 41, - 10, 9, 32,111,117,116,112,117,116, 40, 39, 35,105,102,110, - 100,101,102, 32, 84, 79, 76, 85, 65, 95, 82, 69, 76, 69, 65, - 83, 69, 92,110, 39, 41, 10, 32, 32,108,111, 99, 97,108, 32, - 100,101,102, 59, 32,105,102, 32,115,101,108,102, 46,100,101, - 102,126, 61, 39, 39, 32,116,104,101,110, 32,100,101,102, 61, - 49, 32,101,108,115,101, 32,100,101,102, 61, 48, 32,101,110, - 100, 10, 9, 9,108,111, 99, 97,108, 32,116, 32, 61, 32,105, - 115, 98, 97,115,105, 99, 40,116,121,112,101, 41, 10, 9, 9, - 105,102, 32, 40,116, 41, 32,116,104,101,110, 10, 9, 9, 32, - 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32,105,102, - 32, 40, 33,116,111,108,117, 97, 95,105,115, 39, 46, 46,116, - 46, 46, 39, 97,114,114, 97,121, 40,116,111,108,117, 97, 95, - 83, 44, 39, 44,110, 97,114,103, 44, 39, 44, 39, 44,115,101, - 108,102, 46,100,105,109, 44, 39, 44, 39, 44,100,101,102, 44, - 39, 44, 38,116,111,108,117, 97, 95,101,114,114, 41, 41, 39, - 41, 10, 9, 9,101,108,115,101, 10, 9, 9, 32, 32, 32,111, - 117,116,112,117,116, 40, 39, 32, 32, 32,105,102, 32, 40, 33, - 116,111,108,117, 97, 95,105,115,117,115,101,114,116,121,112, - 101, 97,114,114, 97,121, 40,116,111,108,117, 97, 95, 83, 44, - 39, 44,110, 97,114,103, 44, 39, 44, 34, 39, 44,116,121,112, - 101, 44, 39, 34, 44, 39, 44,115,101,108,102, 46,100,105,109, - 44, 39, 44, 39, 44,100,101,102, 44, 39, 44, 38,116,111,108, - 117, 97, 95,101,114,114, 41, 41, 39, 41, 10, 9, 9,101,110, - 100, 10, 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, - 32,103,111,116,111, 32,116,111,108,117, 97, 95,108,101,114, - 114,111,114, 59, 39, 41, 10, 32, 32,111,117,116,112,117,116, - 40, 39, 32, 32, 32,101,108,115,101, 92,110, 39, 41, 10, 9, - 32,111,117,116,112,117,116, 40, 39, 35,101,110,100,105,102, - 92,110, 39, 41, 10, 32, 32,111,117,116,112,117,116, 40, 39, - 32, 32, 32,123, 39, 41, 10, 32, 32,111,117,116,112,117,116, - 40, 39, 32, 32, 32, 32,105,110,116, 32,105, 59, 39, 41, 10, - 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, 32,102, - 111,114, 40,105, 61, 48, 59, 32,105, 60, 39, 46, 46,115,101, - 108,102, 46,100,105,109, 46, 46, 39, 59,105, 43, 43, 41, 39, - 41, 10, 32, 32,108,111, 99, 97,108, 32,116, 32, 61, 32,105, - 115, 98, 97,115,105, 99, 40,116,121,112,101, 41, 10, 32, 32, - 108,111, 99, 97,108, 32,112,116,114, 32, 61, 32, 39, 39, 10, - 32, 32,105,102, 32,115,101,108,102, 46,112,116,114,126, 61, - 39, 39, 32,116,104,101,110, 32,112,116,114, 32, 61, 32, 39, - 42, 39, 32,101,110,100, 10, 32, 32,111,117,116,112,117,116, - 40, 39, 32, 32, 32, 39, 44,115,101,108,102, 46,110, 97,109, - 101, 46, 46, 39, 91,105, 93, 32, 61, 32, 39, 41, 10, 32, 32, - 105,102, 32,110,111,116, 32,116, 32, 97,110,100, 32,112,116, - 114, 61, 61, 39, 39, 32,116,104,101,110, 32,111,117,116,112, - 117,116, 40, 39, 42, 39, 41, 32,101,110,100, 10, 32, 32,111, - 117,116,112,117,116, 40, 39, 40, 40, 39, 44,116,121,112,101, - 41, 10, 32, 32,105,102, 32,110,111,116, 32,116, 32,116,104, - 101,110, 10, 32, 32, 32,111,117,116,112,117,116, 40, 39, 42, - 39, 41, 10, 32, 32,101,110,100, 10, 32, 32,111,117,116,112, - 117,116, 40, 39, 41, 32, 39, 41, 10, 32, 32,108,111, 99, 97, - 108, 32,100,101,102, 32, 61, 32, 48, 10, 32, 32,105,102, 32, - 115,101,108,102, 46,100,101,102, 32,126, 61, 32, 39, 39, 32, - 116,104,101,110, 32,100,101,102, 32, 61, 32,115,101,108,102, - 46,100,101,102, 32,101,110,100, 10, 32, 32,105,102, 32,116, - 32,116,104,101,110, 10, 32, 32, 32,111,117,116,112,117,116, - 40, 39,116,111,108,117, 97, 95,116,111,102,105,101,108,100, - 39, 46, 46,116, 46, 46, 39, 40,116,111,108,117, 97, 95, 83, - 44, 39, 44,110, 97,114,103, 44, 39, 44,105, 43, 49, 44, 39, - 44,100,101,102, 44, 39, 41, 41, 59, 39, 41, 10, 32, 32,101, - 108,115,101, 10, 32, 32, 32,111,117,116,112,117,116, 40, 39, - 116,111,108,117, 97, 95,116,111,102,105,101,108,100,117,115, - 101,114,116,121,112,101, 40,116,111,108,117, 97, 95, 83, 44, - 39, 44,110, 97,114,103, 44, 39, 44,105, 43, 49, 44, 39, 44, - 100,101,102, 44, 39, 41, 41, 59, 39, 41, 10, 32, 32,101,110, - 100, 10, 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, - 125, 39, 41, 10, 32, 32,111,117,116,112,117,116, 40, 39, 32, - 32,125, 39, 41, 10, 32,101,110,100, 10,101,110,100, 10, 10, - 45, 45, 32, 71,101,116, 32,112, 97,114, 97,109,101,116,101, - 114, 32,118, 97,108,117,101, 10,102,117,110, 99,116,105,111, - 110, 32, 99,108, 97,115,115, 68,101, 99,108, 97,114, 97,116, - 105,111,110, 58,115,101,116, 97,114,114, 97,121, 32, 40,110, - 97,114,103, 41, 10, 32,105,102, 32,110,111,116, 32,115,116, - 114,102,105,110,100, 40,115,101,108,102, 46,116,121,112,101, - 44, 39, 99,111,110,115,116, 37,115, 43, 39, 41, 32, 97,110, - 100, 32,115,101,108,102, 46,100,105,109, 32,126, 61, 32, 39, - 39, 32,116,104,101,110, 10, 9, 32,108,111, 99, 97,108, 32, - 116,121,112,101, 32, 61, 32,103,115,117, 98, 40,115,101,108, - 102, 46,116,121,112,101, 44, 39, 99,111,110,115,116, 32, 39, - 44, 39, 39, 41, 10, 32, 32,111,117,116,112,117,116, 40, 39, - 32, 32,123, 39, 41, 10, 32, 32,111,117,116,112,117,116, 40, - 39, 32, 32, 32,105,110,116, 32,105, 59, 39, 41, 10, 32, 32, - 111,117,116,112,117,116, 40, 39, 32, 32, 32,102,111,114, 40, - 105, 61, 48, 59, 32,105, 60, 39, 46, 46,115,101,108,102, 46, - 100,105,109, 46, 46, 39, 59,105, 43, 43, 41, 39, 41, 10, 32, - 32,108,111, 99, 97,108, 32,116, 44, 99,116, 32, 61, 32,105, - 115, 98, 97,115,105, 99, 40,116,121,112,101, 41, 10, 32, 32, - 105,102, 32,116, 32,116,104,101,110, 10, 32, 32, 32,111,117, - 116,112,117,116, 40, 39, 32, 32, 32, 32,116,111,108,117, 97, - 95,112,117,115,104,102,105,101,108,100, 39, 46, 46,116, 46, - 46, 39, 40,116,111,108,117, 97, 95, 83, 44, 39, 44,110, 97, - 114,103, 44, 39, 44,105, 43, 49, 44, 40, 39, 44, 99,116, 44, - 39, 41, 39, 44,115,101,108,102, 46,110, 97,109,101, 44, 39, - 91,105, 93, 41, 59, 39, 41, 10, 32, 32,101,108,115,101, 10, - 32, 32, 32,105,102, 32,115,101,108,102, 46,112,116,114, 32, - 61, 61, 32, 39, 39, 32,116,104,101,110, 10, 32, 32, 32, 32, - 32,111,117,116,112,117,116, 40, 39, 32, 32, 32,123, 39, 41, - 10, 32, 32, 32, 32, 32,111,117,116,112,117,116, 40, 39, 35, - 105,102,100,101,102, 32, 95, 95, 99,112,108,117,115,112,108, - 117,115, 92,110, 39, 41, 10, 32, 32, 32, 32, 32,111,117,116, - 112,117,116, 40, 39, 32, 32, 32, 32,118,111,105,100, 42, 32, - 116,111,108,117, 97, 95,111, 98,106, 32, 61, 32, 77,116,111, - 108,117, 97, 95,110,101,119, 40, 40, 39, 44,116,121,112,101, - 44, 39, 41, 40, 39, 44,115,101,108,102, 46,110, 97,109,101, - 44, 39, 91,105, 93, 41, 41, 59, 39, 41, 10, 32, 32, 32, 32, - 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, 32,116,111, - 108,117, 97, 95,112,117,115,104,102,105,101,108,100,117,115, - 101,114,116,121,112,101, 95, 97,110,100, 95,116, 97,107,101, - 111,119,110,101,114,115,104,105,112, 40,116,111,108,117, 97, - 95, 83, 44, 39, 44,110, 97,114,103, 44, 39, 44,105, 43, 49, - 44,116,111,108,117, 97, 95,111, 98,106, 44, 34, 39, 44,116, - 121,112,101, 44, 39, 34, 41, 59, 39, 41, 10, 32, 32, 32, 32, - 32,111,117,116,112,117,116, 40, 39, 35,101,108,115,101, 92, - 110, 39, 41, 10, 32, 32, 32, 32, 32,111,117,116,112,117,116, - 40, 39, 32, 32, 32, 32,118,111,105,100, 42, 32,116,111,108, - 117, 97, 95,111, 98,106, 32, 61, 32,116,111,108,117, 97, 95, - 99,111,112,121, 40,116,111,108,117, 97, 95, 83, 44, 40,118, - 111,105,100, 42, 41, 38, 39, 44,115,101,108,102, 46,110, 97, - 109,101, 44, 39, 91,105, 93, 44,115,105,122,101,111,102, 40, - 39, 44,116,121,112,101, 44, 39, 41, 41, 59, 39, 41, 10, 32, - 32, 32, 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, 32, - 32,116,111,108,117, 97, 95,112,117,115,104,102,105,101,108, - 100,117,115,101,114,116,121,112,101, 40,116,111,108,117, 97, - 95, 83, 44, 39, 44,110, 97,114,103, 44, 39, 44,105, 43, 49, - 44,116,111,108,117, 97, 95,111, 98,106, 44, 34, 39, 44,116, - 121,112,101, 44, 39, 34, 41, 59, 39, 41, 10, 32, 32, 32, 32, - 32,111,117,116,112,117,116, 40, 39, 35,101,110,100,105,102, - 92,110, 39, 41, 10, 32, 32, 32, 32, 32,111,117,116,112,117, - 116, 40, 39, 32, 32, 32,125, 39, 41, 10, 32, 32, 32,101,108, - 115,101, 10, 32, 32, 32, 32,111,117,116,112,117,116, 40, 39, - 32, 32, 32,116,111,108,117, 97, 95,112,117,115,104,102,105, - 101,108,100,117,115,101,114,116,121,112,101, 40,116,111,108, - 117, 97, 95, 83, 44, 39, 44,110, 97,114,103, 44, 39, 44,105, - 43, 49, 44, 40,118,111,105,100, 42, 41, 39, 44,115,101,108, - 102, 46,110, 97,109,101, 44, 39, 91,105, 93, 44, 34, 39, 44, - 116,121,112,101, 44, 39, 34, 41, 59, 39, 41, 10, 32, 32, 32, - 101,110,100, 10, 32, 32,101,110,100, 10, 32, 32,111,117,116, - 112,117,116, 40, 39, 32, 32,125, 39, 41, 10, 32,101,110,100, - 10,101,110,100, 10, 10, 45, 45, 32, 70,114,101,101, 32,100, - 121,110, 97,109,105, 99, 97,108,108,121, 32, 97,108,108,111, - 99, 97,116,101,100, 32, 97,114,114, 97,121, 10,102,117,110, - 99,116,105,111,110, 32, 99,108, 97,115,115, 68,101, 99,108, - 97,114, 97,116,105,111,110, 58,102,114,101,101, 97,114,114, - 97,121, 32, 40, 41, 10, 32,105,102, 32,115,101,108,102, 46, - 100,105,109, 32,126, 61, 32, 39, 39, 32, 97,110,100, 32,116, - 111,110,117,109, 98,101,114, 40,115,101,108,102, 46,100,105, - 109, 41, 61, 61,110,105,108, 32,116,104,101,110, 10, 9, 32, - 111,117,116,112,117,116, 40, 39, 35,105,102,100,101,102, 32, - 95, 95, 99,112,108,117,115,112,108,117,115, 92,110, 39, 41, - 10, 9, 9,111,117,116,112,117,116, 40, 39, 32, 32, 77,116, - 111,108,117, 97, 95,100,101,108,101,116,101, 95,100,105,109, - 40, 39, 44,115,101,108,102, 46,110, 97,109,101, 44, 39, 41, - 59, 39, 41, 10, 9, 32,111,117,116,112,117,116, 40, 39, 35, - 101,108,115,101, 92,110, 39, 41, 10, 32, 32,111,117,116,112, - 117,116, 40, 39, 32, 32,102,114,101,101, 40, 39, 44,115,101, - 108,102, 46,110, 97,109,101, 44, 39, 41, 59, 39, 41, 10, 9, - 32,111,117,116,112,117,116, 40, 39, 35,101,110,100,105,102, - 92,110, 39, 41, 10, 32,101,110,100, 10,101,110,100, 10, 10, - 45, 45, 32, 80, 97,115,115, 32,112, 97,114, 97,109,101,116, - 101,114, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97, - 115,115, 68,101, 99,108, 97,114, 97,116,105,111,110, 58,112, - 97,115,115,112, 97,114, 32, 40, 41, 10, 32,105,102, 32,115, - 101,108,102, 46,112,116,114, 61, 61, 39, 38, 39, 32, 97,110, - 100, 32,110,111,116, 32,105,115, 98, 97,115,105, 99, 40,115, - 101,108,102, 46,116,121,112,101, 41, 32,116,104,101,110, 10, - 32, 32,111,117,116,112,117,116, 40, 39, 42, 39, 46, 46,115, - 101,108,102, 46,110, 97,109,101, 41, 10, 32,101,108,115,101, - 105,102, 32,115,101,108,102, 46,114,101,116, 61, 61, 39, 42, - 39, 32,116,104,101,110, 10, 32, 32,111,117,116,112,117,116, - 40, 39, 38, 39, 46, 46,115,101,108,102, 46,110, 97,109,101, - 41, 10, 32,101,108,115,101, 10, 32, 32,111,117,116,112,117, - 116, 40,115,101,108,102, 46,110, 97,109,101, 41, 10, 32,101, - 110,100, 10,101,110,100, 10, 10, 45, 45, 32, 82,101,116,117, - 114,110, 32,112, 97,114, 97,109,101,116,101,114, 32,118, 97, - 108,117,101, 10,102,117,110, 99,116,105,111,110, 32, 99,108, - 97,115,115, 68,101, 99,108, 97,114, 97,116,105,111,110, 58, - 114,101,116,118, 97,108,117,101, 32, 40, 41, 10, 32,105,102, - 32,115,101,108,102, 46,114,101,116, 32,126, 61, 32, 39, 39, - 32,116,104,101,110, 10, 32, 32,108,111, 99, 97,108, 32,116, - 44, 99,116, 32, 61, 32,105,115, 98, 97,115,105, 99, 40,115, - 101,108,102, 46,116,121,112,101, 41, 10, 32, 32,105,102, 32, - 116, 32, 97,110,100, 32,116,126, 61, 39, 39, 32,116,104,101, - 110, 10, 32, 32, 32,111,117,116,112,117,116, 40, 39, 32, 32, - 32,116,111,108,117, 97, 95,112,117,115,104, 39, 46, 46,116, - 46, 46, 39, 40,116,111,108,117, 97, 95, 83, 44, 40, 39, 44, - 99,116, 44, 39, 41, 39, 46, 46,115,101,108,102, 46,110, 97, - 109,101, 46, 46, 39, 41, 59, 39, 41, 10, 32, 32,101,108,115, - 101, 10, 32, 32, 32,108,111, 99, 97,108, 32,112,117,115,104, - 95,102,117,110, 99, 32, 61, 32,103,101,116, 95,112,117,115, - 104, 95,102,117,110, 99,116,105,111,110, 40,115,101,108,102, - 46,116,121,112,101, 41, 10, 32, 32, 32,111,117,116,112,117, - 116, 40, 39, 32, 32, 32, 39, 44,112,117,115,104, 95,102,117, - 110, 99, 44, 39, 40,116,111,108,117, 97, 95, 83, 44, 40,118, - 111,105,100, 42, 41, 39, 46, 46,115,101,108,102, 46,110, 97, - 109,101, 46, 46, 39, 44, 34, 39, 44,115,101,108,102, 46,116, - 121,112,101, 44, 39, 34, 41, 59, 39, 41, 10, 32, 32,101,110, - 100, 10, 32, 32,114,101,116,117,114,110, 32, 49, 10, 32,101, - 110,100, 10, 32,114,101,116,117,114,110, 32, 48, 10,101,110, - 100, 10, 10, 45, 45, 32, 73,110,116,101,114,110, 97,108, 32, - 99,111,110,115,116,114,117, 99,116,111,114, 10,102,117,110, - 99,116,105,111,110, 32, 95, 68,101, 99,108, 97,114, 97,116, - 105,111,110, 32, 40,116, 41, 10, 10, 32,115,101,116,109,101, - 116, 97,116, 97, 98,108,101, 40,116, 44, 99,108, 97,115,115, - 68,101, 99,108, 97,114, 97,116,105,111,110, 41, 10, 32,116, - 58, 98,117,105,108,100,110, 97,109,101,115, 40, 41, 10, 32, - 116, 58, 99,104,101, 99,107,110, 97,109,101, 40, 41, 10, 32, - 116, 58, 99,104,101, 99,107,116,121,112,101, 40, 41, 10, 32, - 108,111, 99, 97,108, 32,102,116, 32, 61, 32,102,105,110,100, - 116,121,112,101, 40,116, 46,116,121,112,101, 41, 32,111,114, - 32,116, 46,116,121,112,101, 10, 32,105,102, 32,110,111,116, - 32,105,115,101,110,117,109, 40,102,116, 41, 32,116,104,101, - 110, 10, 9,116, 46,109,111,100, 44, 32,116, 46,116,121,112, - 101, 32, 61, 32, 97,112,112,108,121,116,121,112,101,100,101, - 102, 40,116, 46,109,111,100, 44, 32,102,116, 41, 10, 32,101, - 110,100, 10, 10, 32,105,102, 32,116, 46,107,105,110,100, 61, - 61, 34,118, 97,114, 34, 32, 97,110,100, 32, 40,115,116,114, - 105,110,103, 46,102,105,110,100, 40,116, 46,109,111,100, 44, - 32, 34,116,111,108,117, 97, 95,112,114,111,112,101,114,116, - 121, 37,115, 34, 41, 32,111,114, 32,115,116,114,105,110,103, - 46,102,105,110,100, 40,116, 46,109,111,100, 44, 32, 34,116, - 111,108,117, 97, 95,112,114,111,112,101,114,116,121, 36, 34, - 41, 41, 32,116,104,101,110, 10, 32, 9,116, 46,109,111,100, - 32, 61, 32,115,116,114,105,110,103, 46,103,115,117, 98, 40, - 116, 46,109,111,100, 44, 32, 34,116,111,108,117, 97, 95,112, - 114,111,112,101,114,116,121, 34, 44, 32, 34,116,111,108,117, - 97, 95,112,114,111,112,101,114,116,121, 95, 95, 34, 46, 46, - 103,101,116, 95,112,114,111,112,101,114,116,121, 95,116,121, - 112,101, 40, 41, 41, 10, 32,101,110,100, 10, 10, 32,114,101, - 116,117,114,110, 32,116, 10,101,110,100, 10, 10, 45, 45, 32, - 67,111,110,115,116,114,117, 99,116,111,114, 10, 45, 45, 32, - 69,120,112,101, 99,116,115, 32,116,104,101, 32,115,116,114, - 105,110,103, 32,100,101, 99,108, 97,114, 97,116,105,111,110, - 46, 10, 45, 45, 32, 84,104,101, 32,107,105,110,100, 32,111, - 102, 32,100,101, 99,108, 97,114, 97,116,105,111,110, 32, 99, - 97,110, 32, 98,101, 32, 34,118, 97,114, 34, 32,111,114, 32, - 34,102,117,110, 99, 34, 46, 10,102,117,110, 99,116,105,111, - 110, 32, 68,101, 99,108, 97,114, 97,116,105,111,110, 32, 40, - 115, 44,107,105,110,100, 44,105,115, 95,112, 97,114, 97,109, - 101,116,101,114, 41, 10, 10, 32, 45, 45, 32,101,108,105,109, - 105,110, 97,116,101, 32,115,112, 97, 99,101,115, 32,105,102, - 32,100,101,102, 97,117,108,116, 32,118, 97,108,117,101, 32, - 105,115, 32,112,114,111,118,105,100,101,100, 10, 32,115, 32, - 61, 32,103,115,117, 98, 40,115, 44, 34, 37,115, 42, 61, 37, - 115, 42, 34, 44, 34, 61, 34, 41, 10, 32,115, 32, 61, 32,103, - 115,117, 98, 40,115, 44, 32, 34, 37,115, 42, 60, 34, 44, 32, - 34, 60, 34, 41, 10, 10, 32,108,111, 99, 97,108, 32,100,101, - 102, 98, 44,116,109,112,100,101,102, 10, 32,100,101,102, 98, - 44, 95, 44,116,109,112,100,101,102, 32, 61, 32,115,116,114, - 105,110,103, 46,102,105,110,100, 40,115, 44, 32, 34, 40, 61, - 46, 42, 41, 36, 34, 41, 10, 32,105,102, 32,100,101,102, 98, - 32,116,104,101,110, 10, 32, 9,115, 32, 61, 32,115,116,114, - 105,110,103, 46,103,115,117, 98, 40,115, 44, 32, 34, 61, 46, - 42, 36, 34, 44, 32, 34, 34, 41, 10, 32,101,108,115,101, 10, - 32, 9,116,109,112,100,101,102, 32, 61, 32, 39, 39, 10, 32, - 101,110,100, 10, 32,105,102, 32,107,105,110,100, 32, 61, 61, - 32, 34,118, 97,114, 34, 32,116,104,101,110, 10, 32, 32, 45, - 45, 32, 99,104,101, 99,107, 32,116,104,101, 32,102,111,114, - 109, 58, 32,118,111,105,100, 10, 32, 32,105,102, 32,115, 32, - 61, 61, 32, 39, 39, 32,111,114, 32,115, 32, 61, 61, 32, 39, - 118,111,105,100, 39, 32,116,104,101,110, 10, 32, 32, 32,114, - 101,116,117,114,110, 32, 95, 68,101, 99,108, 97,114, 97,116, - 105,111,110,123,116,121,112,101, 32, 61, 32, 39,118,111,105, - 100, 39, 44, 32,107,105,110,100, 32, 61, 32,107,105,110,100, - 44, 32,105,115, 95,112, 97,114, 97,109,101,116,101,114, 32, - 61, 32,105,115, 95,112, 97,114, 97,109,101,116,101,114,125, - 10, 32, 32,101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, - 45, 32, 99,104,101, 99,107, 32,116,104,101, 32,102,111,114, - 109, 58, 32,109,111,100, 32,116,121,112,101, 42, 38, 32,110, - 97,109,101, 10, 32,108,111, 99, 97,108, 32,116, 32, 61, 32, - 115,112,108,105,116, 95, 99, 95,116,111,107,101,110,115, 40, - 115, 44, 39, 37, 42, 37,115, 42, 38, 39, 41, 10, 32,105,102, - 32,116, 46,110, 32, 61, 61, 32, 50, 32,116,104,101,110, 10, - 32, 32,105,102, 32,107,105,110,100, 32, 61, 61, 32, 39,102, - 117,110, 99, 39, 32,116,104,101,110, 10, 32, 32, 32,101,114, - 114,111,114, 40, 34, 35,105,110,118, 97,108,105,100, 32,102, - 117,110, 99,116,105,111,110, 32,114,101,116,117,114,110, 32, - 116,121,112,101, 58, 32, 34, 46, 46,115, 41, 10, 32, 32,101, - 110,100, 10, 32, 32, 45, 45,108,111, 99, 97,108, 32,109, 32, - 61, 32,115,112,108,105,116, 40,116, 91, 49, 93, 44, 39, 37, - 115, 37,115, 42, 39, 41, 10, 32, 32,108,111, 99, 97,108, 32, - 109, 32, 61, 32,115,112,108,105,116, 95, 99, 95,116,111,107, - 101,110,115, 40,116, 91, 49, 93, 44, 39, 37,115, 43, 39, 41, - 10, 32, 32,114,101,116,117,114,110, 32, 95, 68,101, 99,108, - 97,114, 97,116,105,111,110,123, 10, 32, 32, 32,110, 97,109, - 101, 32, 61, 32,116, 91, 50, 93, 46, 46,116,109,112,100,101, - 102, 44, 10, 32, 32, 32,112,116,114, 32, 61, 32, 39, 42, 39, - 44, 10, 32, 32, 32,114,101,116, 32, 61, 32, 39, 38, 39, 44, - 10, 32, 32, 32, 45, 45,116,121,112,101, 32, 61, 32,114,101, - 98,117,105,108,100, 95,116,101,109,112,108, 97,116,101, 40, - 109, 91,109, 46,110, 93, 44, 32,116, 98, 44, 32,116,105,109, - 112,108, 41, 44, 10, 32, 32, 32,116,121,112,101, 32, 61, 32, - 109, 91,109, 46,110, 93, 44, 10, 32, 32, 32,109,111,100, 32, - 61, 32, 99,111,110, 99, 97,116, 40,109, 44, 49, 44,109, 46, - 110, 45, 49, 41, 44, 10, 32, 32, 32,105,115, 95,112, 97,114, - 97,109,101,116,101,114, 32, 61, 32,105,115, 95,112, 97,114, - 97,109,101,116,101,114, 44, 10, 32, 32, 32,107,105,110,100, - 32, 61, 32,107,105,110,100, 10, 32, 32,125, 10, 32,101,110, - 100, 10, 10, 32, 45, 45, 32, 99,104,101, 99,107, 32,116,104, - 101, 32,102,111,114,109, 58, 32,109,111,100, 32,116,121,112, - 101, 42, 42, 32,110, 97,109,101, 10, 32,116, 32, 61, 32,115, - 112,108,105,116, 95, 99, 95,116,111,107,101,110,115, 40,115, - 44, 39, 37, 42, 37,115, 42, 37, 42, 39, 41, 10, 32,105,102, - 32,116, 46,110, 32, 61, 61, 32, 50, 32,116,104,101,110, 10, - 32, 32,105,102, 32,107,105,110,100, 32, 61, 61, 32, 39,102, - 117,110, 99, 39, 32,116,104,101,110, 10, 32, 32, 32,101,114, - 114,111,114, 40, 34, 35,105,110,118, 97,108,105,100, 32,102, - 117,110, 99,116,105,111,110, 32,114,101,116,117,114,110, 32, - 116,121,112,101, 58, 32, 34, 46, 46,115, 41, 10, 32, 32,101, - 110,100, 10, 32, 32, 45, 45,108,111, 99, 97,108, 32,109, 32, - 61, 32,115,112,108,105,116, 40,116, 91, 49, 93, 44, 39, 37, - 115, 37,115, 42, 39, 41, 10, 32, 32,108,111, 99, 97,108, 32, - 109, 32, 61, 32,115,112,108,105,116, 95, 99, 95,116,111,107, - 101,110,115, 40,116, 91, 49, 93, 44, 39, 37,115, 43, 39, 41, - 10, 32, 32,114,101,116,117,114,110, 32, 95, 68,101, 99,108, - 97,114, 97,116,105,111,110,123, 10, 32, 32, 32,110, 97,109, - 101, 32, 61, 32,116, 91, 50, 93, 46, 46,116,109,112,100,101, - 102, 44, 10, 32, 32, 32,112,116,114, 32, 61, 32, 39, 42, 39, - 44, 10, 32, 32, 32,114,101,116, 32, 61, 32, 39, 42, 39, 44, - 10, 32, 32, 32, 45, 45,116,121,112,101, 32, 61, 32,114,101, - 98,117,105,108,100, 95,116,101,109,112,108, 97,116,101, 40, - 109, 91,109, 46,110, 93, 44, 32,116, 98, 44, 32,116,105,109, - 112,108, 41, 44, 10, 32, 32, 32,116,121,112,101, 32, 61, 32, - 109, 91,109, 46,110, 93, 44, 10, 32, 32, 32,109,111,100, 32, - 61, 32, 99,111,110, 99, 97,116, 40,109, 44, 49, 44,109, 46, - 110, 45, 49, 41, 44, 10, 32, 32, 32,105,115, 95,112, 97,114, - 97,109,101,116,101,114, 32, 61, 32,105,115, 95,112, 97,114, - 97,109,101,116,101,114, 44, 10, 32, 32, 32,107,105,110,100, - 32, 61, 32,107,105,110,100, 10, 32, 32,125, 10, 32,101,110, - 100, 10, 10, 32, 45, 45, 32, 99,104,101, 99,107, 32,116,104, - 101, 32,102,111,114,109, 58, 32,109,111,100, 32,116,121,112, - 101, 38, 32,110, 97,109,101, 10, 32,116, 32, 61, 32,115,112, - 108,105,116, 95, 99, 95,116,111,107,101,110,115, 40,115, 44, - 39, 38, 39, 41, 10, 32,105,102, 32,116, 46,110, 32, 61, 61, - 32, 50, 32,116,104,101,110, 10, 32, 32, 45, 45,108,111, 99, - 97,108, 32,109, 32, 61, 32,115,112,108,105,116, 40,116, 91, - 49, 93, 44, 39, 37,115, 37,115, 42, 39, 41, 10, 32, 32,108, - 111, 99, 97,108, 32,109, 32, 61, 32,115,112,108,105,116, 95, - 99, 95,116,111,107,101,110,115, 40,116, 91, 49, 93, 44, 39, - 37,115, 43, 39, 41, 10, 32, 32,114,101,116,117,114,110, 32, - 95, 68,101, 99,108, 97,114, 97,116,105,111,110,123, 10, 32, - 32, 32,110, 97,109,101, 32, 61, 32,116, 91, 50, 93, 46, 46, - 116,109,112,100,101,102, 44, 10, 32, 32, 32,112,116,114, 32, - 61, 32, 39, 38, 39, 44, 10, 32, 32, 32, 45, 45,116,121,112, - 101, 32, 61, 32,114,101, 98,117,105,108,100, 95,116,101,109, - 112,108, 97,116,101, 40,109, 91,109, 46,110, 93, 44, 32,116, - 98, 44, 32,116,105,109,112,108, 41, 44, 10, 32, 32, 32,116, - 121,112,101, 32, 61, 32,109, 91,109, 46,110, 93, 44, 10, 32, - 32, 32,109,111,100, 32, 61, 32, 99,111,110, 99, 97,116, 40, - 109, 44, 49, 44,109, 46,110, 45, 49, 41, 44, 10, 32, 32, 32, - 105,115, 95,112, 97,114, 97,109,101,116,101,114, 32, 61, 32, - 105,115, 95,112, 97,114, 97,109,101,116,101,114, 44, 10, 32, - 32, 32,107,105,110,100, 32, 61, 32,107,105,110,100, 10, 32, - 32,125, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32, 99,104, - 101, 99,107, 32,116,104,101, 32,102,111,114,109, 58, 32,109, - 111,100, 32,116,121,112,101, 42, 32,110, 97,109,101, 10, 32, - 108,111, 99, 97,108, 32,115, 49, 32, 61, 32,103,115,117, 98, - 40,115, 44, 34, 40, 37, 98, 92, 91, 92, 93, 41, 34, 44,102, - 117,110, 99,116,105,111,110, 32, 40,110, 41, 32,114,101,116, - 117,114,110, 32,103,115,117, 98, 40,110, 44, 39, 37, 42, 39, - 44, 39, 92, 49, 39, 41, 32,101,110,100, 41, 10, 32,116, 32, - 61, 32,115,112,108,105,116, 95, 99, 95,116,111,107,101,110, - 115, 40,115, 49, 44, 39, 37, 42, 39, 41, 10, 32,105,102, 32, - 116, 46,110, 32, 61, 61, 32, 50, 32,116,104,101,110, 10, 32, - 32,116, 91, 50, 93, 32, 61, 32,103,115,117, 98, 40,116, 91, - 50, 93, 44, 39, 92, 49, 39, 44, 39, 37, 42, 39, 41, 32, 45, - 45, 32,114,101,115,116,111,114,101, 32, 42, 32,105,110, 32, - 100,105,109,101,110,115,105,111,110, 32,101,120,112,114,101, - 115,115,105,111,110, 10, 32, 32, 45, 45,108,111, 99, 97,108, - 32,109, 32, 61, 32,115,112,108,105,116, 40,116, 91, 49, 93, - 44, 39, 37,115, 37,115, 42, 39, 41, 10, 32, 32,108,111, 99, - 97,108, 32,109, 32, 61, 32,115,112,108,105,116, 95, 99, 95, - 116,111,107,101,110,115, 40,116, 91, 49, 93, 44, 39, 37,115, - 43, 39, 41, 10, 32, 32,114,101,116,117,114,110, 32, 95, 68, - 101, 99,108, 97,114, 97,116,105,111,110,123, 10, 32, 32, 32, - 110, 97,109,101, 32, 61, 32,116, 91, 50, 93, 46, 46,116,109, - 112,100,101,102, 44, 10, 32, 32, 32,112,116,114, 32, 61, 32, - 39, 42, 39, 44, 10, 32, 32, 32,116,121,112,101, 32, 61, 32, - 109, 91,109, 46,110, 93, 44, 10, 32, 32, 32, 45, 45,116,121, - 112,101, 32, 61, 32,114,101, 98,117,105,108,100, 95,116,101, - 109,112,108, 97,116,101, 40,109, 91,109, 46,110, 93, 44, 32, - 116, 98, 44, 32,116,105,109,112,108, 41, 44, 10, 32, 32, 32, - 109,111,100, 32, 61, 32, 99,111,110, 99, 97,116, 40,109, 44, - 49, 44,109, 46,110, 45, 49, 41, 32, 32, 32, 44, 10, 32, 32, - 32,105,115, 95,112, 97,114, 97,109,101,116,101,114, 32, 61, - 32,105,115, 95,112, 97,114, 97,109,101,116,101,114, 44, 10, - 32, 32, 32,107,105,110,100, 32, 61, 32,107,105,110,100, 10, - 32, 32,125, 10, 32,101,110,100, 10, 10, 32,105,102, 32,107, - 105,110,100, 32, 61, 61, 32, 39,118, 97,114, 39, 32,116,104, - 101,110, 10, 32, 32, 45, 45, 32, 99,104,101, 99,107, 32,116, - 104,101, 32,102,111,114,109, 58, 32,109,111,100, 32,116,121, - 112,101, 32,110, 97,109,101, 10, 32, 32, 45, 45,116, 32, 61, - 32,115,112,108,105,116, 40,115, 44, 39, 37,115, 37,115, 42, - 39, 41, 10, 32, 32,116, 32, 61, 32,115,112,108,105,116, 95, - 99, 95,116,111,107,101,110,115, 40,115, 44, 39, 37,115, 43, - 39, 41, 10, 32, 32,108,111, 99, 97,108, 32,118, 10, 32, 32, - 105,102, 32,102,105,110,100,116,121,112,101, 40,116, 91,116, - 46,110, 93, 41, 32,116,104,101,110, 32,118, 32, 61, 32, 99, - 114,101, 97,116,101, 95,118, 97,114,110, 97,109,101, 40, 41, - 32,101,108,115,101, 32,118, 32, 61, 32,116, 91,116, 46,110, - 93, 59, 32,116, 46,110, 32, 61, 32,116, 46,110, 45, 49, 32, - 101,110,100, 10, 32, 32,114,101,116,117,114,110, 32, 95, 68, - 101, 99,108, 97,114, 97,116,105,111,110,123, 10, 32, 32, 32, - 110, 97,109,101, 32, 61, 32,118, 46, 46,116,109,112,100,101, - 102, 44, 10, 32, 32, 32, 45, 45,116,121,112,101, 32, 61, 32, - 114,101, 98,117,105,108,100, 95,116,101,109,112,108, 97,116, - 101, 40,116, 91,116, 46,110, 93, 44, 32,116, 98, 44, 32,116, - 105,109,112,108, 41, 44, 10, 32, 32, 32,116,121,112,101, 32, - 61, 32,116, 91,116, 46,110, 93, 44, 10, 32, 32, 32,109,111, - 100, 32, 61, 32, 99,111,110, 99, 97,116, 40,116, 44, 49, 44, - 116, 46,110, 45, 49, 41, 44, 10, 32, 32, 32,105,115, 95,112, - 97,114, 97,109,101,116,101,114, 32, 61, 32,105,115, 95,112, - 97,114, 97,109,101,116,101,114, 44, 10, 32, 32, 32,107,105, - 110,100, 32, 61, 32,107,105,110,100, 10, 32, 32,125, 10, 10, - 32,101,108,115,101, 32, 45, 45, 32,107,105,110,100, 32, 61, - 61, 32, 34,102,117,110, 99, 34, 10, 10, 32, 32, 45, 45, 32, - 99,104,101, 99,107, 32,116,104,101, 32,102,111,114,109, 58, - 32,109,111,100, 32,116,121,112,101, 32,110, 97,109,101, 10, - 32, 32, 45, 45,116, 32, 61, 32,115,112,108,105,116, 40,115, - 44, 39, 37,115, 37,115, 42, 39, 41, 10, 32, 32,116, 32, 61, - 32,115,112,108,105,116, 95, 99, 95,116,111,107,101,110,115, - 40,115, 44, 39, 37,115, 43, 39, 41, 10, 32, 32,108,111, 99, - 97,108, 32,118, 32, 61, 32,116, 91,116, 46,110, 93, 32, 32, - 45, 45, 32,108, 97,115,116, 32,119,111,114,100, 32,105,115, - 32,116,104,101, 32,102,117,110, 99,116,105,111,110, 32,110, - 97,109,101, 10, 32, 32,108,111, 99, 97,108, 32,116,112, 44, - 109,100, 10, 32, 32,105,102, 32,116, 46,110, 62, 49, 32,116, - 104,101,110, 10, 32, 32, 32,116,112, 32, 61, 32,116, 91,116, - 46,110, 45, 49, 93, 10, 32, 32, 32,109,100, 32, 61, 32, 99, - 111,110, 99, 97,116, 40,116, 44, 49, 44,116, 46,110, 45, 50, - 41, 10, 32, 32,101,110,100, 10, 32, 32, 45, 45,105,102, 32, - 116,112, 32,116,104,101,110, 32,116,112, 32, 61, 32,114,101, - 98,117,105,108,100, 95,116,101,109,112,108, 97,116,101, 40, - 116,112, 44, 32,116, 98, 44, 32,116,105,109,112,108, 41, 32, - 101,110,100, 10, 32, 32,114,101,116,117,114,110, 32, 95, 68, - 101, 99,108, 97,114, 97,116,105,111,110,123, 10, 32, 32, 32, - 110, 97,109,101, 32, 61, 32,118, 44, 10, 32, 32, 32,116,121, - 112,101, 32, 61, 32,116,112, 44, 10, 32, 32, 32,109,111,100, - 32, 61, 32,109,100, 44, 10, 32, 32, 32,105,115, 95,112, 97, - 114, 97,109,101,116,101,114, 32, 61, 32,105,115, 95,112, 97, - 114, 97,109,101,116,101,114, 44, 10, 32, 32, 32,107,105,110, - 100, 32, 61, 32,107,105,110,100, 10, 32, 32,125, 10, 32,101, - 110,100, 10, 10,101,110,100,32 - }; - tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua embedded: src/bin/lua/declaration.lua"); + #include "declaration_lua.h" + tolua_dobuffer(tolua_S,(char*)lua_declaration_lua,sizeof(lua_declaration_lua),"tolua embedded: src/bin/lua/declaration.lua"); lua_settop(tolua_S, top); } /* end of embedded lua code */ -- cgit v1.2.3 From 96e0b2691262548442e17e114b2201ef55325621 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 19 Mar 2014 22:42:56 +0100 Subject: APIDump: Added ZeroBraneStudio API export. Fixes #821. --- MCServer/Plugins/APIDump/main_APIDump.lua | 133 ++++++++++++++++++++++++++++-- 1 file changed, 128 insertions(+), 5 deletions(-) diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua index 6d4a6ebc5..2e1aa445d 100644 --- a/MCServer/Plugins/APIDump/main_APIDump.lua +++ b/MCServer/Plugins/APIDump/main_APIDump.lua @@ -1231,10 +1231,6 @@ local function DumpAPIHtml(a_API) return (Hook1.Name < Hook2.Name); end ); - - -- Read in the descriptions: - LOG("Reading descriptions..."); - ReadDescriptions(a_API); ReadHooks(Hooks); -- Create a "class index" file, write each class as a link to that file, @@ -1329,6 +1325,126 @@ end +--- Returns the string with extra tabs and CR/LFs removed +local function CleanUpDescription(a_Desc) + -- Get rid of indent and newlines, normalize whitespace: + local res = a_Desc:gsub("[\n\t]", "") + res = a_Desc:gsub("%s%s+", " ") + + -- Replace paragraph marks with newlines: + res = res:gsub("

    ", "\n") + res = res:gsub("

    ", "") + + -- Replace list items with dashes: + res = res:gsub("", "") + res = res:gsub("
  • ", "\n - ") + res = res:gsub("
  • ", "") + + return res +end + + + + + +--- Writes a list of methods into the specified file in ZBS format +local function WriteZBSMethods(f, a_Methods) + for _, func in ipairs(a_Methods or {}) do + f:write("\t\t\t[\"", func.Name, "\"] =\n") + f:write("\t\t\t{\n") + f:write("\t\t\t\ttype = \"method\",\n") + if ((func.Notes ~= nil) and (func.Notes ~= "")) then + f:write("\t\t\t\tdescription = [[", CleanUpDescription(func.Notes or ""), " ]],\n") + end + f:write("\t\t\t},\n") + end +end + + + + + +--- Writes a list of constants into the specified file in ZBS format +local function WriteZBSConstants(f, a_Constants) + for _, cons in ipairs(a_Constants or {}) do + f:write("\t\t\t[\"", cons.Name, "\"] =\n") + f:write("\t\t\t{\n") + f:write("\t\t\t\ttype = \"value\",\n") + if ((cons.Desc ~= nil) and (cons.Desc ~= "")) then + f:write("\t\t\t\tdescription = [[", CleanUpDescription(cons.Desc or ""), " ]],\n") + end + f:write("\t\t\t},\n") + end +end + + + + + +--- Writes one MCS class definition into the specified file in ZBS format +local function WriteZBSClass(f, a_Class) + assert(type(a_Class) == "table") + + -- Write class header: + f:write("\t", a_Class.Name, " =\n\t{\n") + f:write("\t\ttype = \"class\",\n") + f:write("\t\tdescription = [[", CleanUpDescription(a_Class.Desc or ""), " ]],\n") + f:write("\t\tchilds =\n") + f:write("\t\t{\n") + + -- Export methods and constants: + WriteZBSMethods(f, a_Class.Functions) + WriteZBSConstants(f, a_Class.Constants) + + -- Finish the class definition: + f:write("\t\t},\n") + f:write("\t},\n\n") +end + + + + + +--- Dumps the entire API table into a file in the ZBS format +local function DumpAPIZBS(a_API) + LOG("Dumping ZBS API description...") + local f, err = io.open("mcserver.lua", "w") + if (f == nil) then + LOG("Cannot open mcserver.lua for writing, ZBS API will not be dumped. " .. err) + return + end + + -- Write the file header: + f:write("-- This is a MCServer API file automatically generated by the APIDump plugin\n") + f:write("-- Note that any manual changes will be overwritten by the next dump\n\n") + f:write("return {\n") + + -- Export each class except Globals, store those aside: + local Globals + for _, cls in ipairs(a_API) do + if (cls.Name ~= "Globals") then + WriteZBSClass(f, cls) + else + Globals = cls + end + end + + -- Export the globals: + if (Globals) then + WriteZBSMethods(f, Globals.Functions) + WriteZBSConstants(f, Globals.Constants) + end + + -- Finish the file: + f:write("}\n") + f:close() + LOG("ZBS API dumped...") +end + + + + + local function DumpApi() LOG("Dumping the API...") @@ -1377,9 +1493,16 @@ local function DumpApi() Globals.Name = "Globals"; table.insert(API, Globals); - -- Dump all available API object in HTML format into a subfolder: + -- Read in the descriptions: + LOG("Reading descriptions..."); + ReadDescriptions(API); + + -- Dump all available API objects in HTML format into a subfolder: DumpAPIHtml(API); + -- Dump all available API objects in format used by ZeroBraneStudio API descriptions: + DumpAPIZBS(API) + LOG("APIDump finished"); return true end -- cgit v1.2.3 From d6a72da3821091f23f063942dbafdc3a5c0b34ac Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 19 Mar 2014 22:51:02 +0100 Subject: APIDump: Updated comments to reflect current code. --- MCServer/Plugins/APIDump/main_APIDump.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua index 2e1aa445d..7455c3cd2 100644 --- a/MCServer/Plugins/APIDump/main_APIDump.lua +++ b/MCServer/Plugins/APIDump/main_APIDump.lua @@ -1541,9 +1541,12 @@ function Initialize(Plugin) LOG("Initialising " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) + -- Bind a console command to dump the API: cPluginManager:BindConsoleCommand("api", HandleCmdApi, "Dumps the Lua API docs into the API/ subfolder") + + -- Add a WebAdmin tab that has a Dump button g_Plugin:AddWebTab("APIDump", HandleWebAdminDump) - -- TODO: Add a WebAdmin tab that has a Dump button + return true end -- cgit v1.2.3 From 74b7f51b898575bacec52663e5e8601d6bfd36bd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 19 Mar 2014 22:55:47 +0100 Subject: Errors in Lua don't include the error handler in the stack trace. Fixes #817. --- src/Bindings/LuaState.cpp | 10 +++++----- src/Bindings/LuaState.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index f24e15c3b..0bb047873 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1080,20 +1080,20 @@ bool cLuaState::ReportErrors(lua_State * a_LuaState, int a_Status) -void cLuaState::LogStackTrace(void) +void cLuaState::LogStackTrace(int a_StartingDepth) { - LogStackTrace(m_LuaState); + LogStackTrace(m_LuaState, a_StartingDepth); } -void cLuaState::LogStackTrace(lua_State * a_LuaState) +void cLuaState::LogStackTrace(lua_State * a_LuaState, int a_StartingDepth) { LOGWARNING("Stack trace:"); lua_Debug entry; - int depth = 0; + int depth = a_StartingDepth; while (lua_getstack(a_LuaState, depth, &entry)) { lua_getinfo(a_LuaState, "Sln", &entry); @@ -1312,7 +1312,7 @@ void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header) int cLuaState::ReportFnCallErrors(lua_State * a_LuaState) { LOGWARNING("LUA: %s", lua_tostring(a_LuaState, -1)); - LogStackTrace(a_LuaState); + LogStackTrace(a_LuaState, 1); return 1; // We left the error message on the stack as the return value } diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index f5cb8379d..356a284e0 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -868,10 +868,10 @@ public: static bool ReportErrors(lua_State * a_LuaState, int status); /** Logs all items in the current stack trace to the server console */ - void LogStackTrace(void); + void LogStackTrace(int a_StartingDepth = 0); /** Logs all items in the current stack trace to the server console */ - static void LogStackTrace(lua_State * a_LuaState); + static void LogStackTrace(lua_State * a_LuaState, int a_StartingDepth = 0); /** Returns the type of the item on the specified position in the stack */ AString GetTypeText(int a_StackPos); -- cgit v1.2.3 From 0524d70774f830b08abb1dee4e8340b25c569d2a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 19 Mar 2014 23:06:39 +0000 Subject: ENUMified shrapnel level --- src/BlockID.h | 12 ++++++++---- src/ChunkMap.cpp | 4 ++-- src/World.cpp | 6 +++--- src/World.h | 10 ++++------ 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index 1c454cd23..e305e9237 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -852,10 +852,14 @@ enum eExplosionSource esWitherSkullBlack, esWitherSkullBlue, esWitherBirth, - esPlugin, - - // Obsolete constants, kept for compatibility, will be removed after some time: - esCreeper = esMonster, + esPlugin +} ; + +enum eShrapnelLevel +{ + slNone, + slGravityAffectedOnly, + slAll } ; // tolua_end diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 867b37ed0..e695f0ab2 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1834,13 +1834,13 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc. m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z); } - else if ((m_World->GetTNTShrapnelLevel() > 0) && (m_World->GetTickRandomNumber(100) < 20)) // 20% chance of flinging stuff around + else if ((m_World->GetTNTShrapnelLevel() > slNone) && (m_World->GetTickRandomNumber(100) < 20)) // 20% chance of flinging stuff around { if (!cBlockInfo::FullyOccupiesVoxel(Block)) { break; } - else if ((m_World->GetTNTShrapnelLevel() == 1) && ((Block != E_BLOCK_SAND) && (Block != E_BLOCK_GRAVEL))) + else if ((m_World->GetTNTShrapnelLevel() == slGravityAffectedOnly) && ((Block != E_BLOCK_SAND) && (Block != E_BLOCK_GRAVEL))) { break; } diff --git a/src/World.cpp b/src/World.cpp index 22bc406e0..01281625a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -577,15 +577,15 @@ void cWorld::Start(void) m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false); m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true); m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true); - m_TNTShrapnelLevel = IniFile.GetValueSetI("Physics", "TNTShrapnelLevel", 2); + m_TNTShrapnelLevel = (eShrapnelLevel)IniFile.GetValueSetI("Physics", "TNTShrapnelLevel", 2); m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false); m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true); m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true); m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true); m_GameMode = (eGameMode)IniFile.GetValueSetI("General", "Gamemode", m_GameMode); - if (m_TNTShrapnelLevel > 2) - m_TNTShrapnelLevel = 2; + if (m_TNTShrapnelLevel > slAll) + m_TNTShrapnelLevel = slAll; // Load allowed mobs: const char * DefaultMonsters = ""; diff --git a/src/World.h b/src/World.h index 21c6ea01c..46aece18f 100644 --- a/src/World.h +++ b/src/World.h @@ -605,8 +605,8 @@ public: bool AreCommandBlocksEnabled(void) const { return m_bCommandBlocksEnabled; } void SetCommandBlocksEnabled(bool a_Flag) { m_bCommandBlocksEnabled = a_Flag; } - unsigned char GetTNTShrapnelLevel(void) const { return m_TNTShrapnelLevel; } - void SetTNTShrapnelLevel(int a_Flag) { m_TNTShrapnelLevel = a_Flag; } + eShrapnelLevel GetTNTShrapnelLevel(void) const { return m_TNTShrapnelLevel; } + void SetTNTShrapnelLevel(eShrapnelLevel a_Flag) { m_TNTShrapnelLevel = a_Flag; } bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; } void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; } @@ -867,11 +867,9 @@ private: bool m_bUseChatPrefixes; /** The level of DoExplosionAt() projecting random affected blocks as FallingBlock entities - 0 = None - 1 = Only sand and gravel - 2 = All blocks + See the eShrapnelLevel enumeration for details */ - int m_TNTShrapnelLevel; + eShrapnelLevel m_TNTShrapnelLevel; cChunkGenerator m_Generator; -- cgit v1.2.3 From a0720a65d631e0f88b93067cc5ca84c650aa41cb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 19 Mar 2014 23:07:16 +0000 Subject: Minor Entity.cpp cleanup --- src/Entities/Entity.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 97c8e2164..221cbbea7 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -733,22 +733,19 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) if( NextSpeed.SqrLength() > 0.f ) { cTracer Tracer( GetWorld() ); - int Ret = Tracer.Trace( NextPos, NextSpeed, 2 ); - if( Ret ) // Oh noez! we hit something + bool HasHit = Tracer.Trace( NextPos, NextSpeed, 2 ); + if (HasHit) // Oh noez! we hit something { // Set to hit position - if( (Tracer.RealHit - NextPos).SqrLength() <= ( NextSpeed * a_Dt ).SqrLength() ) + if ((Tracer.RealHit - NextPos).SqrLength() <= (NextSpeed * a_Dt).SqrLength()) { - if( Ret == 1 ) - { - if( Tracer.HitNormal.x != 0.f ) NextSpeed.x = 0.f; - if( Tracer.HitNormal.y != 0.f ) NextSpeed.y = 0.f; - if( Tracer.HitNormal.z != 0.f ) NextSpeed.z = 0.f; + if (Tracer.HitNormal.x != 0.f) NextSpeed.x = 0.f; + if (Tracer.HitNormal.y != 0.f) NextSpeed.y = 0.f; + if (Tracer.HitNormal.z != 0.f) NextSpeed.z = 0.f; - if( Tracer.HitNormal.y > 0 ) // means on ground - { - m_bOnGround = true; - } + if (Tracer.HitNormal.y > 0) // means on ground + { + m_bOnGround = true; } NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z); NextPos.x += Tracer.HitNormal.x * 0.3f; -- cgit v1.2.3 From 3e49cada80dc219cb9894772bae9237b5bc81562 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 19 Mar 2014 23:07:58 +0000 Subject: Added braces --- src/World.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/World.cpp b/src/World.cpp index 01281625a..14abaa242 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -585,7 +585,9 @@ void cWorld::Start(void) m_GameMode = (eGameMode)IniFile.GetValueSetI("General", "Gamemode", m_GameMode); if (m_TNTShrapnelLevel > slAll) + { m_TNTShrapnelLevel = slAll; + } // Load allowed mobs: const char * DefaultMonsters = ""; -- cgit v1.2.3 From 964647a9006af475bea71272e313f3575cf4d37f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Mar 2014 09:16:47 +0100 Subject: Made pushing plain pointer to Lua a valid operation, with a warning. This is used for exotic explosions, and the NORETURNDEBUG macro caused MSVC warnings across the entire cLuaState class (MSVC marked ALL Push() function overloads as non-returning) --- src/Bindings/LuaState.cpp | 5 +++-- src/Bindings/LuaState.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 0bb047873..47380b8a7 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -689,9 +689,10 @@ void cLuaState::Push(void * a_Ptr) ASSERT(IsValid()); // Investigate the cause of this - what is the callstack? - LOGWARNING("Lua engine encountered an error - attempting to push a plain pointer"); + // One code path leading here is the OnHookExploding / OnHookExploded with exotic parameters. Need to decide what to do with them + LOGWARNING("Lua engine: attempting to push a plain pointer, pushing nil instead."); + LOGWARNING("This indicates an unimplemented part of MCS bindings"); LogStackTrace(); - ASSERT(!"A plain pointer should never be pushed on Lua stack"); lua_pushnil(m_LuaState); m_NumCurrentFunctionArgs += 1; diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 356a284e0..f0047b362 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -200,7 +200,7 @@ public: void Push(const HTTPTemplateRequest * a_Request); void Push(cTNTEntity * a_TNTEntity); void Push(Vector3i * a_Vector); - NORETURNDEBUG void Push(void * a_Ptr); + void Push(void * a_Ptr); void Push(cHopperEntity * a_Hopper); void Push(cBlockEntity * a_BlockEntity); -- cgit v1.2.3 From b1ad3322e555449879a94558e796358fe057f74b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Mar 2014 09:28:29 +0100 Subject: Fixed code style after recent merge. --- src/BlockID.h | 6 +++++- src/World.cpp | 58 ++++++++++++++++++++++++++++------------------------------ 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index e305e9237..8adefcfba 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -852,9 +852,13 @@ enum eExplosionSource esWitherSkullBlack, esWitherSkullBlue, esWitherBirth, - esPlugin + esPlugin, } ; + + + + enum eShrapnelLevel { slNone, diff --git a/src/World.cpp b/src/World.cpp index 14abaa242..3f157157a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -560,34 +560,33 @@ void cWorld::Start(void) m_SpawnZ = IniFile.GetValueF("SpawnPosition", "Z", m_SpawnZ); } - m_StorageSchema = IniFile.GetValueSet ("Storage", "Schema", m_StorageSchema); - m_StorageCompressionFactor = IniFile.GetValueSetI("Storage", "CompressionFactor", m_StorageCompressionFactor); - m_MaxCactusHeight = IniFile.GetValueSetI("Plants", "MaxCactusHeight", 3); - m_MaxSugarcaneHeight = IniFile.GetValueSetI("Plants", "MaxSugarcaneHeight", 3); - m_IsCactusBonemealable = IniFile.GetValueSetB("Plants", "IsCactusBonemealable", false); - m_IsCarrotsBonemealable = IniFile.GetValueSetB("Plants", "IsCarrotsBonemealable", true); - m_IsCropsBonemealable = IniFile.GetValueSetB("Plants", "IsCropsBonemealable", true); - m_IsGrassBonemealable = IniFile.GetValueSetB("Plants", "IsGrassBonemealable", true); - m_IsMelonStemBonemealable = IniFile.GetValueSetB("Plants", "IsMelonStemBonemealable", true); - m_IsMelonBonemealable = IniFile.GetValueSetB("Plants", "IsMelonBonemealable", false); - m_IsPotatoesBonemealable = IniFile.GetValueSetB("Plants", "IsPotatoesBonemealable", true); - m_IsPumpkinStemBonemealable = IniFile.GetValueSetB("Plants", "IsPumpkinStemBonemealable", true); - m_IsPumpkinBonemealable = IniFile.GetValueSetB("Plants", "IsPumpkinBonemealable", false); - m_IsSaplingBonemealable = IniFile.GetValueSetB("Plants", "IsSaplingBonemealable", true); - m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false); - m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true); - m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true); - m_TNTShrapnelLevel = (eShrapnelLevel)IniFile.GetValueSetI("Physics", "TNTShrapnelLevel", 2); - m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false); - m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true); - m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true); - m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true); - - m_GameMode = (eGameMode)IniFile.GetValueSetI("General", "Gamemode", m_GameMode); - if (m_TNTShrapnelLevel > slAll) - { - m_TNTShrapnelLevel = slAll; - } + m_StorageSchema = IniFile.GetValueSet ("Storage", "Schema", m_StorageSchema); + m_StorageCompressionFactor = IniFile.GetValueSetI("Storage", "CompressionFactor", m_StorageCompressionFactor); + m_MaxCactusHeight = IniFile.GetValueSetI("Plants", "MaxCactusHeight", 3); + m_MaxSugarcaneHeight = IniFile.GetValueSetI("Plants", "MaxSugarcaneHeight", 3); + m_IsCactusBonemealable = IniFile.GetValueSetB("Plants", "IsCactusBonemealable", false); + m_IsCarrotsBonemealable = IniFile.GetValueSetB("Plants", "IsCarrotsBonemealable", true); + m_IsCropsBonemealable = IniFile.GetValueSetB("Plants", "IsCropsBonemealable", true); + m_IsGrassBonemealable = IniFile.GetValueSetB("Plants", "IsGrassBonemealable", true); + m_IsMelonStemBonemealable = IniFile.GetValueSetB("Plants", "IsMelonStemBonemealable", true); + m_IsMelonBonemealable = IniFile.GetValueSetB("Plants", "IsMelonBonemealable", false); + m_IsPotatoesBonemealable = IniFile.GetValueSetB("Plants", "IsPotatoesBonemealable", true); + m_IsPumpkinStemBonemealable = IniFile.GetValueSetB("Plants", "IsPumpkinStemBonemealable", true); + m_IsPumpkinBonemealable = IniFile.GetValueSetB("Plants", "IsPumpkinBonemealable", false); + m_IsSaplingBonemealable = IniFile.GetValueSetB("Plants", "IsSaplingBonemealable", true); + m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false); + m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true); + m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true); + int TNTShrapnelLevel = IniFile.GetValueSetI("Physics", "TNTShrapnelLevel", (int)slNone); + m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false); + m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true); + m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true); + m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true); + int GameMode = IniFile.GetValueSetI("General", "Gamemode", (int)m_GameMode); + + // Adjust the enum-backed variables into their respective bounds: + m_GameMode = (eGameMode) Clamp(GameMode, (int)gmSurvival, (int)gmAdventure); + m_TNTShrapnelLevel = (eShrapnelLevel)Clamp(TNTShrapnelLevel, (int)slNone, (int)slAll); // Load allowed mobs: const char * DefaultMonsters = ""; @@ -1730,14 +1729,13 @@ int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTicks, double a_InitialVelocityCoeff) { - UNUSED(a_InitialVelocityCoeff); cTNTEntity * TNT = new cTNTEntity(a_X, a_Y, a_Z, a_FuseTicks); TNT->Initialize(this); TNT->SetSpeed( a_InitialVelocityCoeff * (GetTickRandomNumber(2) - 1), /** -1, 0, 1 */ a_InitialVelocityCoeff * 2, a_InitialVelocityCoeff * (GetTickRandomNumber(2) - 1) - ); + ); } -- cgit v1.2.3 From 93d4cbb989abff814800a11d8f23caa0de83e157 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Mar 2014 15:21:28 +0100 Subject: ProtoProxy: Fixed MSVC compilation. --- Tools/ProtoProxy/Globals.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tools/ProtoProxy/Globals.h b/Tools/ProtoProxy/Globals.h index 0724d3a52..e2f5aa860 100644 --- a/Tools/ProtoProxy/Globals.h +++ b/Tools/ProtoProxy/Globals.h @@ -22,6 +22,8 @@ #define ALIGN_8 #define ALIGN_16 + #define FORMATSTRING(formatIndex, va_argsIndex) + #elif defined(__GNUC__) // TODO: Can GCC explicitly mark classes as abstract (no instances can be created)? @@ -38,7 +40,7 @@ // Some portability macros :) #define stricmp strcasecmp - #define FORMATSTRING(formatIndex,va_argsIndex) + #define FORMATSTRING(formatIndex, va_argsIndex) #else @@ -61,7 +63,7 @@ #define ALIGN_16 */ - #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) + #define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) #endif -- cgit v1.2.3 From 64d9390069650bbbc1850d5602b9854a1c1a7257 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Mar 2014 15:45:42 +0100 Subject: Rewritten player speeds to be relative unit-less. Value of 1 means "default speed", 2 means "double the speed", 0.5 means "half the speed". This allows for easier plugins and is more future-proof. --- MCServer/Plugins/APIDump/APIDesc.lua | 10 +++++----- src/Entities/Player.cpp | 4 ++-- src/Entities/Player.h | 14 +++++++++----- src/Protocol/Protocol16x.cpp | 4 ++-- src/Protocol/Protocol17x.cpp | 7 ++++--- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index c5599b212..39bbb0c77 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1680,11 +1680,11 @@ a_Player:OpenWindow(Window); GetGroups = { Return = "array-table of {{cGroup}}", Notes = "Returns all the groups that this player is member of, as a table. The groups are stored in the array part of the table, beginning with index 1."}, GetIP = { Return = "string", Notes = "Returns the IP address of the player, if available. Returns an empty string if there's no IP to report."}, GetInventory = { Return = "{{cInventory|Inventory}}", Notes = "Returns the player's inventory"}, - GetMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's current maximum speed (as reported by the 1.6.1+ protocols)" }, + GetMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's current maximum speed, relative to the game default speed. Takes into account the sprinting / flying status." }, GetName = { Return = "string", Notes = "Returns the player's name" }, - GetNormalMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's maximum walking speed (as reported by the 1.6.1+ protocols)" }, + GetNormalMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's maximum walking speed, relative to the game default speed. Defaults to 1, but plugins may modify it for faster or slower walking." }, GetResolvedPermissions = { Return = "array-table of string", Notes = "Returns all the player's permissions, as a table. The permissions are stored in the array part of the table, beginning with index 1." }, - GetSprintingMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's maximum sprinting speed (as reported by the 1.6.1+ protocols)" }, + GetSprintingMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's maximum sprinting speed, relative to the game default speed. Defaults to 1.3, but plugins may modify it for faster or slower sprinting." }, GetStance = { Return = "number", Notes = "Returns the player's stance (Y-pos of player's eyes)" }, GetThrowSpeed = { Params = "SpeedCoeff", Return = "{{Vector3d}}", Notes = "Returns the speed vector for an object thrown with the specified speed coeff. Basically returns the normalized look vector multiplied by the coeff, with a slight random variation." }, GetThrowStartPos = { Params = "", Return = "{{Vector3d}}", Notes = "Returns the position where the projectiles should start when thrown by this player." }, @@ -1729,9 +1729,9 @@ a_Player:OpenWindow(Window); SetGameMode = { Params = "{{eGameMode|NewGameMode}}", Return = "", Notes = "Sets the gamemode for the player. The new gamemode overrides the world's default gamemode, unless it is set to gmInherit." }, SetIsFishing = { Params = "IsFishing, [FloaterEntityID]", Return = "", Notes = "Sets the 'IsFishing' flag for the player. The floater entity ID is expected for the true variant, it can be omitted when IsFishing is false. FIXME: Undefined behavior when multiple fishing rods are used simultanously" }, SetName = { Params = "Name", Return = "", Notes = "Sets the player name. This rename will NOT be visible to any players already in the server who are close enough to see this player." }, - SetNormalMaxSpeed = { Params = "NormalMaxSpeed", Return = "", Notes = "Sets the normal (walking) maximum speed (as reported by the 1.6.1+ protocols)" }, + SetNormalMaxSpeed = { Params = "NormalMaxSpeed", Return = "", Notes = "Sets the normal (walking) maximum speed, relative to the game default speed. The default value is 1. Sends the updated speed to the client, if appropriate." }, SetSprint = { Params = "IsSprinting", Return = "", Notes = "Sets whether the player is sprinting or not." }, - SetSprintingMaxSpeed = { Params = "SprintingMaxSpeed", Return = "", Notes = "Sets the sprinting maximum speed (as reported by the 1.6.1+ protocols)" }, + SetSprintingMaxSpeed = { Params = "SprintingMaxSpeed", Return = "", Notes = "Sets the sprinting maximum speed, relative to the game default speed. The default value is 1.3. Sends the updated speed to the client, if appropriate." }, SetVisible = { Params = "IsVisible", Return = "", Notes = "Sets the player visibility to other players" }, XpForLevel = { Params = "XPLevel", Return = "number", Notes = "(STATIC) Returns the total amount of XP needed for the specified XP level. Inverse of CalcLevelFromXp()." }, }, diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 440d30595..47d0d9c61 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -43,8 +43,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_GameMode(eGameMode_NotSet) , m_IP("") , m_ClientHandle(a_Client) - , m_NormalMaxSpeed(0.1) - , m_SprintingMaxSpeed(0.13) + , m_NormalMaxSpeed(1.0) + , m_SprintingMaxSpeed(1.3) , m_IsCrouched(false) , m_IsSprinting(false) , m_IsFlying(false) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index c25053c21..451dde8fc 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -331,13 +331,13 @@ public: // tolua_begin - /// Returns the current maximum speed, as reported in the 1.6.1+ protocol (takes current sprinting state into account) + /// Returns the current relative maximum speed (takes current sprinting state into account) double GetMaxSpeed(void) const; - /// Gets the normal maximum speed, as reported in the 1.6.1+ protocol, in the protocol units + /// Gets the normal relative maximum speed double GetNormalMaxSpeed(void) const { return m_NormalMaxSpeed; } - /// Gets the sprinting maximum speed, as reported in the 1.6.1+ protocol, in the protocol units + /// Gets the sprinting relative maximum speed double GetSprintingMaxSpeed(void) const { return m_SprintingMaxSpeed; } /// Sets the normal maximum speed, as reported in the 1.6.1+ protocol. Sends the update to player, if needed. @@ -432,10 +432,14 @@ protected: cSlotNums m_InventoryPaintSlots; - /// Max speed, in ENTITY_PROPERTIES packet's units, when the player is walking. 0.1 by default + /** Max speed, relative to the game default. + 1 means regular speed, 2 means twice as fast, 0.5 means half-speed. + Default value is 1. */ double m_NormalMaxSpeed; - /// Max speed, in ENTITY_PROPERTIES packet's units, when the player is sprinting. 0.13 by default + /** Max speed, relative to the game default max speed. + 1 means regular speed, 2 means twice as fast, 0.5 means half-speed. + Default value is 1.3 */ double m_SprintingMaxSpeed; bool m_IsCrouched; diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index f6ec0a199..ecb24254f 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -135,7 +135,7 @@ void cProtocol161::SendPlayerMaxSpeed(void) WriteInt(m_Client->GetPlayer()->GetUniqueID()); WriteInt(1); WriteString("generic.movementSpeed"); - WriteDouble(m_Client->GetPlayer()->GetMaxSpeed()); + WriteDouble(0.1 * m_Client->GetPlayer()->GetMaxSpeed()); Flush(); } @@ -267,7 +267,7 @@ void cProtocol162::SendPlayerMaxSpeed(void) WriteInt(m_Client->GetPlayer()->GetUniqueID()); WriteInt(1); WriteString("generic.movementSpeed"); - WriteDouble(m_Client->GetPlayer()->GetMaxSpeed()); + WriteDouble(0.1 * m_Client->GetPlayer()->GetMaxSpeed()); WriteShort(0); Flush(); } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 6fc344eaf..21c77e903 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -689,7 +689,7 @@ void cProtocol172::SendPlayerAbilities(void) Pkt.WriteByte(Flags); // TODO: Pkt.WriteFloat(m_Client->GetPlayer()->GetMaxFlyingSpeed()); Pkt.WriteFloat(0.05f); - Pkt.WriteFloat((float)m_Client->GetPlayer()->GetMaxSpeed()); + Pkt.WriteFloat((float)(0.1 * m_Client->GetPlayer()->GetMaxSpeed())); } @@ -743,13 +743,14 @@ void cProtocol172::SendPlayerMaxSpeed(void) Pkt.WriteInt(m_Client->GetPlayer()->GetUniqueID()); Pkt.WriteInt(1); // Count Pkt.WriteString("generic.movementSpeed"); - Pkt.WriteDouble(0.1); + // The default game speed is 0.1, multiply that value by the relative speed: + Pkt.WriteDouble(0.1 * m_Client->GetPlayer()->GetNormalMaxSpeed()); if (m_Client->GetPlayer()->IsSprinting()) { Pkt.WriteShort(1); // Modifier count Pkt.WriteInt64(0x662a6b8dda3e4c1c); Pkt.WriteInt64(0x881396ea6097278d); // UUID of the modifier - Pkt.WriteDouble(0.3); + Pkt.WriteDouble(m_Client->GetPlayer()->GetSprintingMaxSpeed() - m_Client->GetPlayer()->GetNormalMaxSpeed()); Pkt.WriteByte(2); } else -- cgit v1.2.3 From 9fae50f44796c4230845c5dd29e82395827d45ff Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Mar 2014 16:05:22 +0100 Subject: APIDump: Fixed wrong escaped strings. --- MCServer/Plugins/APIDump/APIDesc.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 39bbb0c77..19609295d 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2792,11 +2792,11 @@ end "Globals.xpcall", "Globals.decoda_output", -- When running under Decoda, this function gets added to the global namespace "sqlite3.__newindex", - "%a+\.__%a+", -- AnyClass.__Anything - "%a+\.\.collector", -- AnyClass..collector - "%a+\.new", -- AnyClass.new - "%a+.new_local", -- AnyClass.new_local - "%a+.delete", -- AnyClass.delete + "%a+%.__%a+", -- AnyClass.__Anything + "%a+%.%.collector", -- AnyClass..collector + "%a+%.new", -- AnyClass.new + "%a+%.new_local", -- AnyClass.new_local + "%a+%.delete", -- AnyClass.delete -- Functions global in the APIDump plugin: "CreateAPITables", -- cgit v1.2.3 From b370cacf0c0e1234aef1efd9c442ff335a379258 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Mar 2014 16:14:40 +0100 Subject: Plugins can set flying speed. --- MCServer/Plugins/APIDump/APIDesc.lua | 8 +- src/Entities/Player.cpp | 33 +++++++- src/Entities/Player.h | 160 +++++++++++++++++++---------------- src/Protocol/Protocol17x.cpp | 3 +- 4 files changed, 124 insertions(+), 80 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 19609295d..74e7bf860 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1666,17 +1666,18 @@ a_Player:OpenWindow(Window); GetClientHandle = { Params = "", Return = "{{cClientHandle}}", Notes = "Returns the client handle representing the player's connection. May be nil (AI players)." }, GetColor = { Return = "string", Notes = "Returns the full color code to be used for this player (based on the first group). Prefix player messages with this code." }, GetCurrentXp = { Params = "", Return = "number", Notes = "Returns the current amount of XP" }, - GetEffectiveGameMode = { Params = "", Return = "{{eGameMode|GameMode}}", Notes = "Returns the current resolved game mode of the player. If the player is set to inherit the world's gamemode, returns that instead. See also GetGameMode() and IsGameModeXXX() functions." }, + GetEffectiveGameMode = { Params = "", Return = "{{Globals#GameMode|GameMode}}", Notes = "(OBSOLETE) Returns the current resolved game mode of the player. If the player is set to inherit the world's gamemode, returns that instead. See also GetGameMode() and IsGameModeXXX() functions. Note that this function is the same as GetGameMode(), use that function instead." }, GetEquippedItem = { Params = "", Return = "{{cItem}}", Notes = "Returns the item that the player is currently holding; empty item if holding nothing." }, GetEyeHeight = { Return = "number", Notes = "Returns the height of the player's eyes, in absolute coords" }, GetEyePosition = { Return = "{{Vector3d|EyePositionVector}}", Notes = "Returns the position of the player's eyes, as a {{Vector3d}}" }, GetFloaterID = { Params = "", Return = "number", Notes = "Returns the Entity ID of the fishing hook floater that belongs to the player. Returns -1 if no floater is associated with the player. FIXME: Undefined behavior when the player has used multiple fishing rods simultanously." }, + GetFlyingMaxSpeed = { Params = "", Return = "number", Notes = "Returns the maximum flying speed, relative to the default game flying speed. Defaults to 1, but plugins may modify it for faster or slower flying." }, GetFoodExhaustionLevel = { Params = "", Return = "number", Notes = "Returns the food exhaustion level" }, GetFoodLevel = { Params = "", Return = "number", Notes = "Returns the food level (number of half-drumsticks on-screen)" }, GetFoodPoisonedTicksRemaining = { Params = "", Return = "", Notes = "Returns the number of ticks left for the food posoning effect" }, GetFoodSaturationLevel = { Params = "", Return = "number", Notes = "Returns the food saturation (overcharge of the food level, is depleted before food level)" }, GetFoodTickTimer = { Params = "", Return = "", Notes = "Returns the number of ticks past the last food-based heal or damage action; when this timer reaches 80, a new heal / damage is applied." }, - GetGameMode = { Return = "{{eGameMode|GameMode}}", Notes = "Returns the player's gamemode. The player may have their gamemode unassigned, in which case they inherit the gamemode from the current {{cWorld|world}}.
    NOTE: Instead of comparing the value returned by this function to the gmXXX constants, use the IsGameModeXXX() functions. These functions handle the gamemode inheritance automatically."}, + GetGameMode = { Return = "{{Globals#GameMode|GameMode}}", Notes = "Returns the player's gamemode. The player may have their gamemode unassigned, in which case they inherit the gamemode from the current {{cWorld|world}}.
    NOTE: Instead of comparing the value returned by this function to the gmXXX constants, use the IsGameModeXXX() functions. These functions handle the gamemode inheritance automatically."}, GetGroups = { Return = "array-table of {{cGroup}}", Notes = "Returns all the groups that this player is member of, as a table. The groups are stored in the array part of the table, beginning with index 1."}, GetIP = { Return = "string", Notes = "Returns the IP address of the player, if available. Returns an empty string if there's no IP to report."}, GetInventory = { Return = "{{cInventory|Inventory}}", Notes = "Returns the player's inventory"}, @@ -1721,12 +1722,13 @@ a_Player:OpenWindow(Window); SetCrouch = { Params = "IsCrouched", Return = "", Notes = "Sets the crouch state, broadcasts the change to other players." }, SetCurrentExperience = { Params = "XPAmount", Return = "", Notes = "Sets the current amount of experience (and indirectly, the XP level)." }, SetFlying = { Params = "IsFlying", Notes = "Sets if the player is flying or not." }, + SetFlyingMaxSpeed = { Params = "FlyingMaxSpeed", Return = "", Notes = "Sets the flying maximum speed, relative to the game default speed. The default value is 1. Sends the updated speed to the client." }, SetFoodExhaustionLevel = { Params = "ExhaustionLevel", Return = "", Notes = "Sets the food exhaustion to the specified level." }, SetFoodLevel = { Params = "FoodLevel", Return = "", Notes = "Sets the food level (number of half-drumsticks on-screen)" }, SetFoodPoisonedTicksRemaining = { Params = "FoodPoisonedTicksRemaining", Return = "", Notes = "Sets the number of ticks remaining for food poisoning. Doesn't send foodpoisoning effect to the client, use FoodPoison() for that." }, SetFoodSaturationLevel = { Params = "FoodSaturationLevel", Return = "", Notes = "Sets the food saturation (overcharge of the food level)." }, SetFoodTickTimer = { Params = "FoodTickTimer", Return = "", Notes = "Sets the number of ticks past the last food-based heal or damage action; when this timer reaches 80, a new heal / damage is applied." }, - SetGameMode = { Params = "{{eGameMode|NewGameMode}}", Return = "", Notes = "Sets the gamemode for the player. The new gamemode overrides the world's default gamemode, unless it is set to gmInherit." }, + SetGameMode = { Params = "{{Globals#GameMode|NewGameMode}}", Return = "", Notes = "Sets the gamemode for the player. The new gamemode overrides the world's default gamemode, unless it is set to gmInherit." }, SetIsFishing = { Params = "IsFishing, [FloaterEntityID]", Return = "", Notes = "Sets the 'IsFishing' flag for the player. The floater entity ID is expected for the true variant, it can be omitted when IsFishing is false. FIXME: Undefined behavior when multiple fishing rods are used simultanously" }, SetName = { Params = "Name", Return = "", Notes = "Sets the player name. This rename will NOT be visible to any players already in the server who are close enough to see this player." }, SetNormalMaxSpeed = { Params = "NormalMaxSpeed", Return = "", Notes = "Sets the normal (walking) maximum speed, relative to the game default speed. The default value is 1. Sends the updated speed to the client, if appropriate." }, diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 47d0d9c61..863aaa799 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -45,6 +45,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_ClientHandle(a_Client) , m_NormalMaxSpeed(1.0) , m_SprintingMaxSpeed(1.3) + , m_FlyingMaxSpeed(1.0) , m_IsCrouched(false) , m_IsSprinting(false) , m_IsFlying(false) @@ -684,7 +685,21 @@ const cSlotNums & cPlayer::GetInventoryPaintSlots(void) const double cPlayer::GetMaxSpeed(void) const { - return m_IsSprinting ? m_SprintingMaxSpeed : m_NormalMaxSpeed; + if (m_IsFlying) + { + return m_FlyingMaxSpeed; + } + else + { + if (m_IsSprinting) + { + return m_SprintingMaxSpeed; + } + else + { + return m_NormalMaxSpeed; + } + } } @@ -694,7 +709,7 @@ double cPlayer::GetMaxSpeed(void) const void cPlayer::SetNormalMaxSpeed(double a_Speed) { m_NormalMaxSpeed = a_Speed; - if (!m_IsSprinting) + if (!m_IsSprinting && !m_IsFlying) { m_ClientHandle->SendPlayerMaxSpeed(); } @@ -707,7 +722,7 @@ void cPlayer::SetNormalMaxSpeed(double a_Speed) void cPlayer::SetSprintingMaxSpeed(double a_Speed) { m_SprintingMaxSpeed = a_Speed; - if (m_IsSprinting) + if (m_IsSprinting && !m_IsFlying) { m_ClientHandle->SendPlayerMaxSpeed(); } @@ -717,6 +732,18 @@ void cPlayer::SetSprintingMaxSpeed(double a_Speed) +void cPlayer::SetFlyingMaxSpeed(double a_Speed) +{ + m_FlyingMaxSpeed = a_Speed; + + // Update the flying speed, always: + m_ClientHandle->SendPlayerAbilities(); +} + + + + + void cPlayer::SetCrouch(bool a_IsCrouched) { // Set the crouch status, broadcast to all visible players diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 451dde8fc..ea32dbfb9 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -47,19 +47,19 @@ public: virtual void HandlePhysics(float a_Dt, cChunk &) override { UNUSED(a_Dt); }; - /// Returns the curently equipped weapon; empty item if none + /** Returns the curently equipped weapon; empty item if none */ virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); } - /// Returns the currently equipped helmet; empty item if none + /** Returns the currently equipped helmet; empty item if none */ virtual cItem GetEquippedHelmet(void) const override { return m_Inventory.GetEquippedHelmet(); } - /// Returns the currently equipped chestplate; empty item if none + /** Returns the currently equipped chestplate; empty item if none */ virtual cItem GetEquippedChestplate(void) const override { return m_Inventory.GetEquippedChestplate(); } - /// Returns the currently equipped leggings; empty item if none + /** Returns the currently equipped leggings; empty item if none */ virtual cItem GetEquippedLeggings(void) const override { return m_Inventory.GetEquippedLeggings(); } - /// Returns the currently equipped boots; empty item if none + /** Returns the currently equipped boots; empty item if none */ virtual cItem GetEquippedBoots(void) const override { return m_Inventory.GetEquippedBoots(); } @@ -77,36 +77,41 @@ public: */ short DeltaExperience(short a_Xp_delta); - /// Gets the experience total - XpTotal for score on death + /** Gets the experience total - XpTotal for score on death */ inline short GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; } - /// Gets the currrent experience + /** Gets the currrent experience */ inline short GetCurrentXp(void) { return m_CurrentXp; } - /// Gets the current level - XpLevel + /** Gets the current level - XpLevel */ short GetXpLevel(void); - /// Gets the experience bar percentage - XpP + /** Gets the experience bar percentage - XpP */ float GetXpPercentage(void); - /// Caculates the amount of XP needed for a given level, ref: http://minecraft.gamepedia.com/XP + /** Caculates the amount of XP needed for a given level + Ref: http://minecraft.gamepedia.com/XP + */ static short XpForLevel(short int a_Level); - /// inverse of XpForLevel, ref: http://minecraft.gamepedia.com/XP values are as per this with pre-calculations + /** Inverse of XpForLevel + Ref: http://minecraft.gamepedia.com/XP + values are as per this with pre-calculations + */ static short CalcLevelFromXp(short int a_CurrentXp); // tolua_end - /// Starts charging the equipped bow + /** Starts charging the equipped bow */ void StartChargingBow(void); - /// Finishes charging the current bow. Returns the number of ticks for which the bow has been charged + /** Finishes charging the current bow. Returns the number of ticks for which the bow has been charged */ int FinishChargingBow(void); - /// Cancels the current bow charging + /** Cancels the current bow charging */ void CancelChargingBow(void); - /// Returns true if the player is currently charging the bow + /** Returns true if the player is currently charging the bow */ bool IsChargingBow(void) const { return m_IsChargingBow; } void SetTouchGround( bool a_bTouchGround ); @@ -124,16 +129,16 @@ public: // tolua_begin - /// Returns the position where projectiles thrown by this player should start, player eye position + adjustment + /** Returns the position where projectiles thrown by this player should start, player eye position + adjustment */ Vector3d GetThrowStartPos(void) const; - /// Returns the initial speed vector of a throw, with a 3D length of a_SpeedCoeff. + /** Returns the initial speed vector of a throw, with a 3D length of a_SpeedCoeff. */ Vector3d GetThrowSpeed(double a_SpeedCoeff) const; - /// Returns the current gamemode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable + /** Returns the current gamemode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable */ eGameMode GetGameMode(void) const { return m_GameMode; } - /// Returns the current effective gamemode (inherited gamemode is resolved before returning) + /** Returns the current effective gamemode (inherited gamemode is resolved before returning) */ eGameMode GetEffectiveGameMode(void) const { return (m_GameMode == gmNotSet) ? m_World->GetGameMode() : m_GameMode; } /** Sets the gamemode for the player. @@ -142,24 +147,24 @@ public: */ void SetGameMode(eGameMode a_GameMode); - /// Returns true if the player is in Creative mode, either explicitly, or by inheriting from current world + /** Returns true if the player is in Creative mode, either explicitly, or by inheriting from current world */ bool IsGameModeCreative(void) const; - /// Returns true if the player is in Survival mode, either explicitly, or by inheriting from current world + /** Returns true if the player is in Survival mode, either explicitly, or by inheriting from current world */ bool IsGameModeSurvival(void) const; - /// Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current world + /** Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current world */ bool IsGameModeAdventure(void) const; AString GetIP(void) const { return m_IP; } // tolua_export - /// Returns the associated team, NULL if none + /** Returns the associated team, NULL if none */ cTeam * GetTeam(void) { return m_Team; } // tolua_export - /// Sets the player team, NULL if none + /** Sets the player team, NULL if none */ void SetTeam(cTeam * a_Team); - /// Forces the player to query the scoreboard for his team + /** Forces the player to query the scoreboard for his team */ cTeam * UpdateTeam(void); // tolua_end @@ -169,24 +174,24 @@ public: // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); - /// Forces the player to move in the given direction. + /** Forces the player to move in the given direction. */ void ForceSetSpeed(Vector3d a_Direction); // tolua_export - /// Tries to move to a new position, with attachment-related checks (y == -999) + /** Tries to move to a new position, with attachment-related checks (y == -999) */ void MoveTo(const Vector3d & a_NewPos); // tolua_export cWindow * GetWindow(void) { return m_CurrentWindow; } // tolua_export const cWindow * GetWindow(void) const { return m_CurrentWindow; } - /// Opens the specified window; closes the current one first using CloseWindow() + /** Opens the specified window; closes the current one first using CloseWindow() */ void OpenWindow(cWindow * a_Window); // Exported in ManualBindings.cpp // tolua_begin - /// Closes the current window, resets current window to m_InventoryWindow. A plugin may refuse the closing if a_CanRefuse is true + /** Closes the current window, resets current window to m_InventoryWindow. A plugin may refuse the closing if a_CanRefuse is true */ void CloseWindow(bool a_CanRefuse = true); - /// Closes the current window if it matches the specified ID, resets current window to m_InventoryWindow + /** Closes the current window if it matches the specified ID, resets current window to m_InventoryWindow */ void CloseWindowIfID(char a_WindowID, bool a_CanRefuse = true); cClientHandle * GetClientHandle(void) const { return m_ClientHandle; } @@ -208,10 +213,10 @@ public: typedef std::list< cGroup* > GroupList; typedef std::list< std::string > StringList; - /// Adds a player to existing group or creates a new group when it doesn't exist + /** Adds a player to existing group or creates a new group when it doesn't exist */ void AddToGroup( const AString & a_GroupName ); // tolua_export - /// Removes a player from the group, resolves permissions and group inheritance (case sensitive) + /** Removes a player from the group, resolves permissions and group inheritance (case sensitive) */ void RemoveFromGroup( const AString & a_GroupName ); // tolua_export bool HasPermission( const AString & a_Permission ); // tolua_export @@ -234,7 +239,7 @@ public: /** tosses a pickup newly created from a_Item */ void TossPickup(const cItem & a_Item); - /// Heals the player by the specified amount of HPs (positive only); sends health update + /** Heals the player by the specified amount of HPs (positive only); sends health update */ void Heal(int a_Health); int GetFoodLevel (void) const { return m_FoodLevel; } @@ -243,7 +248,7 @@ public: double GetFoodExhaustionLevel (void) const { return m_FoodExhaustionLevel; } int GetFoodPoisonedTicksRemaining(void) const { return m_FoodPoisonedTicksRemaining; } - /// Returns true if the player is satiated, i. e. their foodlevel is at the max and they cannot eat anymore + /** Returns true if the player is satiated, i. e. their foodlevel is at the max and they cannot eat anymore */ bool IsSatiated(void) const { return (m_FoodLevel >= MAX_FOOD_LEVEL); } void SetFoodLevel (int a_FoodLevel); @@ -252,28 +257,28 @@ public: void SetFoodExhaustionLevel (double a_FoodExhaustionLevel); void SetFoodPoisonedTicksRemaining(int a_FoodPoisonedTicksRemaining); - /// Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed, false if player "full" + /** Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed, false if player "full" */ bool Feed(int a_Food, double a_Saturation); - /// Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values. + /** Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values. */ void AddFoodExhaustion(double a_Exhaustion) { m_FoodExhaustionLevel += a_Exhaustion; } - /// Starts the food poisoning for the specified amount of ticks; if already foodpoisoned, sets FoodPoisonedTicksRemaining to the larger of the two + /** Starts the food poisoning for the specified amount of ticks; if already foodpoisoned, sets FoodPoisonedTicksRemaining to the larger of the two */ void FoodPoison(int a_NumTicks); - /// Returns true if the player is currently in the process of eating the currently equipped item + /** Returns true if the player is currently in the process of eating the currently equipped item */ bool IsEating(void) const { return (m_EatingFinishTick >= 0); } - /// Returns true if the player is currently flying. + /** Returns true if the player is currently flying. */ bool IsFlying(void) const { return m_IsFlying; } /** Returns if a player is sleeping in a bed */ bool IsInBed(void) const { return m_bIsInBed; } - /// returns true if the player has thrown out a floater. + /** returns true if the player has thrown out a floater. */ bool IsFishing(void) const { return m_IsFishing; } void SetIsFishing(bool a_IsFishing, int a_FloaterID = -1) { m_IsFishing = a_IsFishing; m_FloaterID = a_FloaterID; } @@ -285,13 +290,13 @@ public: /** Sets a player's in-bed state; we can't be sure plugins will keep this value updated, so no exporting */ void SetIsInBed(bool a_Flag) { m_bIsInBed = a_Flag; } - /// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet + /** Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet */ void StartEating(void); - /// Finishes eating the currently equipped item. Consumes the item, updates health and broadcasts the packets + /** Finishes eating the currently equipped item. Consumes the item, updates health and broadcasts the packets */ void FinishEating(void); - /// Aborts the current eating operation + /** Aborts the current eating operation */ void AbortEating(void); virtual void KilledBy(cEntity * a_Killer) override; @@ -320,45 +325,51 @@ public: cItem & GetDraggingItem(void) {return m_DraggingItem; } // In UI windows, when inventory-painting: - /// Clears the list of slots that are being inventory-painted. To be used by cWindow only + /** Clears the list of slots that are being inventory-painted. To be used by cWindow only */ void ClearInventoryPaintSlots(void); - /// Adds a slot to the list for inventory painting. To be used by cWindow only + /** Adds a slot to the list for inventory painting. To be used by cWindow only */ void AddInventoryPaintSlot(int a_SlotNum); - /// Returns the list of slots currently stored for inventory painting. To be used by cWindow only + /** Returns the list of slots currently stored for inventory painting. To be used by cWindow only */ const cSlotNums & GetInventoryPaintSlots(void) const; // tolua_begin - /// Returns the current relative maximum speed (takes current sprinting state into account) + /** Returns the current relative maximum speed (takes current sprinting / flying state into account) */ double GetMaxSpeed(void) const; - /// Gets the normal relative maximum speed + /** Gets the normal relative maximum speed */ double GetNormalMaxSpeed(void) const { return m_NormalMaxSpeed; } - /// Gets the sprinting relative maximum speed + /** Gets the sprinting relative maximum speed */ double GetSprintingMaxSpeed(void) const { return m_SprintingMaxSpeed; } - /// Sets the normal maximum speed, as reported in the 1.6.1+ protocol. Sends the update to player, if needed. + /** Gets the flying relative maximum speed */ + double GetFlyingMaxSpeed(void) const { return m_FlyingMaxSpeed; } + + /** Sets the normal relative maximum speed. Sends the update to player, if needed. */ void SetNormalMaxSpeed(double a_Speed); - /// Sets the sprinting maximum speed, as reported in the 1.6.1+ protocol. Sends the update to player, if needed. + /** Sets the sprinting relative maximum speed. Sends the update to player, if needed. */ void SetSprintingMaxSpeed(double a_Speed); - /// Sets the crouch status, broadcasts to all visible players + /** Sets the flying relative maximum speed. Sends the update to player, if needed. */ + void SetFlyingMaxSpeed(double a_Speed); + + /** Sets the crouch status, broadcasts to all visible players */ void SetCrouch(bool a_IsCrouched); - /// Starts or stops sprinting, sends the max speed update to the client, if needed + /** Starts or stops sprinting, sends the max speed update to the client, if needed */ void SetSprint(bool a_IsSprinting); - /// Flags the player as flying + /** Flags the player as flying */ void SetFlying(bool a_IsFlying); - /// If true the player can fly even when he's not in creative. + /** If true the player can fly even when he's not in creative. */ void SetCanFly(bool a_CanFly); - /// Returns wheter the player can fly or not. + /** Returns wheter the player can fly or not. */ virtual bool CanFly(void) const { return m_CanFly; } // tolua_end @@ -380,7 +391,7 @@ protected: AString m_PlayerName; AString m_LoadedWorldName; - /// Xp Level stuff + /** Xp Level stuff */ enum { XP_TO_LEVEL15 = 255, @@ -391,22 +402,22 @@ protected: bool m_bVisible; // Food-related variables: - /// Represents the food bar, one point equals half a "drumstick" + /** Represents the food bar, one point equals half a "drumstick" */ int m_FoodLevel; - /// "Overcharge" for the m_FoodLevel; is depleted before m_FoodLevel + /** "Overcharge" for the m_FoodLevel; is depleted before m_FoodLevel */ double m_FoodSaturationLevel; - /// Count-up to the healing or damaging action, based on m_FoodLevel + /** Count-up to the healing or damaging action, based on m_FoodLevel */ int m_FoodTickTimer; - /// A "buffer" which adds up hunger before it is substracted from m_FoodSaturationLevel or m_FoodLevel. Each action adds a little + /** A "buffer" which adds up hunger before it is substracted from m_FoodSaturationLevel or m_FoodLevel. Each action adds a little */ double m_FoodExhaustionLevel; - /// Number of ticks remaining for the foodpoisoning effect; zero if not foodpoisoned + /** Number of ticks remaining for the foodpoisoning effect; zero if not foodpoisoned */ int m_FoodPoisonedTicksRemaining; - /// Last position that has been recorded for food-related processing: + /** Last position that has been recorded for food-related processing: */ Vector3d m_LastFoodPos; float m_LastJumpHeight; @@ -422,7 +433,7 @@ protected: eGameMode m_GameMode; AString m_IP; - /// The item being dragged by the cursor while in a UI window + /** The item being dragged by the cursor while in a UI window */ cItem m_DraggingItem; long long m_LastPlayerListTime; @@ -437,11 +448,16 @@ protected: Default value is 1. */ double m_NormalMaxSpeed; - /** Max speed, relative to the game default max speed. + /** Max speed, relative to the game default max speed, when sprinting. 1 means regular speed, 2 means twice as fast, 0.5 means half-speed. - Default value is 1.3 */ + Default value is 1.3. */ double m_SprintingMaxSpeed; + /** Max speed, relative to the game default flying max speed, when flying. + 1 means regular speed, 2 means twice as fast, 0.5 means half-speed. + Default value is 1. */ + double m_FlyingMaxSpeed; + bool m_IsCrouched; bool m_IsSprinting; bool m_IsFlying; @@ -451,10 +467,10 @@ protected: bool m_CanFly; // If this is true the player can fly. Even if he is not in creative. - /// The world tick in which eating will be finished. -1 if not eating + /** The world tick in which eating will be finished. -1 if not eating */ Int64 m_EatingFinishTick; - /// Player Xp level + /** Player Xp level */ short int m_LifetimeTotalXp; short int m_CurrentXp; @@ -475,19 +491,19 @@ protected: virtual void Destroyed(void); - /// Filters out damage for creative mode/friendly fire + /** Filters out damage for creative mode/friendly fire */ virtual void DoTakeDamage(TakeDamageInfo & TDI) override; /** Stops players from burning in creative mode */ virtual void TickBurning(cChunk & a_Chunk) override; - /// Called in each tick to handle food-related processing + /** Called in each tick to handle food-related processing */ void HandleFood(void); - /// Called in each tick if the player is fishing to make sure the floater dissapears when the player doesn't have a fishing rod as equipped item. + /** Called in each tick if the player is fishing to make sure the floater dissapears when the player doesn't have a fishing rod as equipped item. */ void HandleFloater(void); - /// Adds food exhaustion based on the difference between Pos and LastPos, sprinting status and swimming (in water block) + /** Adds food exhaustion based on the difference between Pos and LastPos, sprinting status and swimming (in water block) */ void ApplyFoodExhaustionFromMovement(); /** Flag representing whether the player is currently in a bed diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 21c77e903..721ed349e 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -687,8 +687,7 @@ void cProtocol172::SendPlayerAbilities(void) Flags |= 0x04; } Pkt.WriteByte(Flags); - // TODO: Pkt.WriteFloat(m_Client->GetPlayer()->GetMaxFlyingSpeed()); - Pkt.WriteFloat(0.05f); + Pkt.WriteFloat((float)(0.05 * m_Client->GetPlayer()->GetFlyingMaxSpeed())); Pkt.WriteFloat((float)(0.1 * m_Client->GetPlayer()->GetMaxSpeed())); } -- cgit v1.2.3 From a69a1ef0325c5e472f1dd736f3a14a260d747ad9 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 20 Mar 2014 13:23:15 -0700 Subject: Fixed enum checking functions not being called in generated code --- lib/tolua++/src/bin/basic_lua.h | 1214 +++++++++--------- lib/tolua++/src/bin/declaration_lua.h | 1471 +++++++++++----------- lib/tolua++/src/bin/enumerate_lua.h | 362 +++--- lib/tolua++/src/bin/function_lua.h | 2078 +++++++++++++++---------------- lib/tolua++/src/bin/lua/basic.lua | 4 +- lib/tolua++/src/bin/lua/declaration.lua | 4 +- lib/tolua++/src/bin/lua/enumerate.lua | 6 +- lib/tolua++/src/bin/lua/function.lua | 2 +- 8 files changed, 2572 insertions(+), 2569 deletions(-) diff --git a/lib/tolua++/src/bin/basic_lua.h b/lib/tolua++/src/bin/basic_lua.h index d4b816a2c..2128cb44b 100644 --- a/lib/tolua++/src/bin/basic_lua.h +++ b/lib/tolua++/src/bin/basic_lua.h @@ -135,622 +135,624 @@ static const unsigned char lua_basic_lua[] = { 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x4c, 0x69, 0x73, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x75, 0x74, 0x6f, 0x20, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x0a, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, - 0x69, 0x6e, 0x67, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, + 0x69, 0x6e, 0x67, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x5f, 0x65, + 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, + 0x64, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x20, 0x28, 0x73, + 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, + 0x2c, 0x6f, 0x6c, 0x64, 0x2c, 0x6e, 0x65, 0x77, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x25, 0x73, + 0x2a, 0x28, 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2a, 0x40, 0x25, 0x73, 0x2a, + 0x28, 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x29, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, + 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x72, 0x65, 0x6e, 0x61, + 0x6d, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x6e, 0x74, 0x61, 0x78, 0x3b, + 0x20, 0x69, 0x74, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, + 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, + 0x6d, 0x3a, 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x40, 0x70, + 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x74, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x28, 0x5f, + 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x2c, 0x7b, 0x6f, 0x6c, + 0x64, 0x3d, 0x6f, 0x6c, 0x64, 0x2c, 0x20, 0x6e, 0x65, 0x77, 0x3d, 0x6e, + 0x65, 0x77, 0x7d, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x20, 0x28, 0x73, 0x29, - 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, - 0x6f, 0x6c, 0x64, 0x2c, 0x6e, 0x65, 0x77, 0x20, 0x3d, 0x20, 0x73, 0x74, - 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x25, 0x73, 0x2a, - 0x28, 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2a, 0x40, 0x25, 0x73, 0x2a, 0x28, - 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x29, 0x0a, 0x09, 0x69, - 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x09, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, 0x49, - 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x72, 0x65, 0x6e, 0x61, 0x6d, - 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x6e, 0x74, 0x61, 0x78, 0x3b, 0x20, - 0x69, 0x74, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, - 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, - 0x3a, 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x40, 0x70, 0x61, - 0x74, 0x74, 0x65, 0x72, 0x6e, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, - 0x0a, 0x09, 0x74, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x28, 0x5f, 0x72, - 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x2c, 0x7b, 0x6f, 0x6c, 0x64, - 0x3d, 0x6f, 0x6c, 0x64, 0x2c, 0x20, 0x6e, 0x65, 0x77, 0x3d, 0x6e, 0x65, - 0x77, 0x7d, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x72, - 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x20, 0x28, 0x73, 0x29, 0x0a, - 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, 0x2c, 0x67, 0x65, 0x74, - 0x6e, 0x28, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x29, - 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x6d, 0x2c, 0x6e, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, - 0x2c, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x5b, 0x69, - 0x5d, 0x2e, 0x6f, 0x6c, 0x64, 0x2c, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, - 0x69, 0x6e, 0x67, 0x5b, 0x69, 0x5d, 0x2e, 0x6e, 0x65, 0x77, 0x29, 0x0a, - 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x20, 0x7e, 0x3d, 0x20, 0x30, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x6d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, - 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, - 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, - 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x28, - 0x73, 0x2c, 0x66, 0x29, 0x0a, 0x69, 0x66, 0x20, 0x5f, 0x63, 0x75, 0x72, - 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x22, 0x2a, 0x2a, 0x2a, 0x63, - 0x75, 0x72, 0x72, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x66, 0x6f, 0x72, - 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, - 0x2e, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x5f, 0x63, - 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x29, 0x29, 0x0a, 0x09, - 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, - 0x74, 0x72, 0x61, 0x63, 0x65, 0x62, 0x61, 0x63, 0x6b, 0x28, 0x29, 0x29, - 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x5f, 0x4f, 0x55, 0x54, 0x50, 0x55, - 0x54, 0x0a, 0x20, 0x5f, 0x4f, 0x55, 0x54, 0x50, 0x55, 0x54, 0x20, 0x3d, - 0x20, 0x5f, 0x53, 0x54, 0x44, 0x45, 0x52, 0x52, 0x0a, 0x20, 0x69, 0x66, - 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x31, 0x2c, - 0x31, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x23, 0x27, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, 0x22, - 0x5c, 0x6e, 0x2a, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, 0x20, - 0x22, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, - 0x32, 0x29, 0x2e, 0x2e, 0x22, 0x2e, 0x5c, 0x6e, 0x5c, 0x6e, 0x22, 0x29, - 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, - 0x63, 0x6f, 0x64, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x73, - 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x5f, - 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x22, 0x5e, - 0x25, 0x73, 0x2a, 0x28, 0x2e, 0x2d, 0x5c, 0x6e, 0x29, 0x22, 0x29, 0x20, - 0x2d, 0x2d, 0x20, 0x65, 0x78, 0x74, 0x72, 0x61, 0x63, 0x74, 0x20, 0x66, - 0x69, 0x72, 0x73, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x20, 0x20, - 0x20, 0x69, 0x66, 0x20, 0x73, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x5f, 0x63, 0x75, 0x72, - 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, - 0x20, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, - 0x2c, 0x22, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, 0x74, 0x61, 0x22, - 0x2c, 0x22, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x22, 0x29, 0x20, 0x2d, 0x2d, - 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x77, 0x69, 0x74, 0x68, - 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x27, 0x0a, 0x20, 0x20, 0x20, - 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, - 0x5f, 0x63, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x2c, 0x22, 0x63, - 0x68, 0x61, 0x72, 0x2a, 0x22, 0x29, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x27, - 0x63, 0x68, 0x61, 0x72, 0x2a, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x73, 0x20, - 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x5f, 0x6c, - 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x2c, 0x22, 0x6c, 0x75, 0x61, 0x5f, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x22, 0x29, 0x20, 0x20, 0x2d, 0x2d, - 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x77, 0x69, 0x74, 0x68, - 0x20, 0x27, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, - 0x27, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, 0x22, - 0x43, 0x6f, 0x64, 0x65, 0x20, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x20, 0x70, - 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x3a, 0x5c, 0x6e, 0x22, - 0x2e, 0x2e, 0x73, 0x2e, 0x2e, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x0a, 0x20, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, - 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x66, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x22, 0x28, 0x66, 0x20, 0x69, 0x73, - 0x20, 0x6e, 0x69, 0x6c, 0x29, 0x22, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, - 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x22, 0x5c, 0x6e, 0x2a, 0x2a, - 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, - 0x6e, 0x61, 0x6c, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3a, 0x20, 0x22, - 0x2e, 0x2e, 0x66, 0x2e, 0x2e, 0x73, 0x2e, 0x2e, 0x22, 0x2e, 0x5c, 0x6e, - 0x5c, 0x6e, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, - 0x6e, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x5f, 0x4f, 0x55, 0x54, - 0x50, 0x55, 0x54, 0x20, 0x3d, 0x20, 0x6f, 0x75, 0x74, 0x0a, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, - 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x28, 0x6d, 0x73, 0x67, - 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x2e, - 0x71, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, - 0x6e, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, 0x2c, 0x67, 0x65, + 0x74, 0x6e, 0x28, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, + 0x29, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6d, 0x2c, 0x6e, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x5b, + 0x69, 0x5d, 0x2e, 0x6f, 0x6c, 0x64, 0x2c, 0x5f, 0x72, 0x65, 0x6e, 0x61, + 0x6d, 0x69, 0x6e, 0x67, 0x5b, 0x69, 0x5d, 0x2e, 0x6e, 0x65, 0x77, 0x29, + 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x20, 0x7e, 0x3d, 0x20, 0x30, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x6d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x68, 0x61, 0x6e, 0x64, 0x6c, + 0x65, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, + 0x28, 0x73, 0x2c, 0x66, 0x29, 0x0a, 0x69, 0x66, 0x20, 0x5f, 0x63, 0x75, + 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x22, 0x2a, 0x2a, 0x2a, + 0x63, 0x75, 0x72, 0x72, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x66, 0x6f, + 0x72, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x69, 0x73, 0x20, 0x22, + 0x2e, 0x2e, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x5f, + 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x29, 0x29, 0x0a, + 0x09, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x64, 0x65, 0x62, 0x75, 0x67, + 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x62, 0x61, 0x63, 0x6b, 0x28, 0x29, + 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x5f, 0x4f, 0x55, 0x54, 0x50, 0x55, 0x54, 0x0a, 0x20, 0x5f, 0x4f, 0x55, 0x54, 0x50, 0x55, 0x54, 0x20, - 0x3d, 0x20, 0x5f, 0x53, 0x54, 0x44, 0x45, 0x52, 0x52, 0x0a, 0x20, 0x77, - 0x72, 0x69, 0x74, 0x65, 0x28, 0x22, 0x5c, 0x6e, 0x2a, 0x2a, 0x20, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x20, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, - 0x3a, 0x20, 0x22, 0x2e, 0x2e, 0x6d, 0x73, 0x67, 0x2e, 0x2e, 0x22, 0x2e, - 0x5c, 0x6e, 0x5c, 0x6e, 0x22, 0x29, 0x0a, 0x20, 0x5f, 0x4f, 0x55, 0x54, - 0x50, 0x55, 0x54, 0x20, 0x3d, 0x20, 0x6f, 0x75, 0x74, 0x0a, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, - 0x65, 0x72, 0x20, 0x61, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x64, - 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3a, - 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x66, 0x75, 0x6c, - 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x72, 0x65, 0x67, 0x74, 0x79, 0x70, 0x65, 0x20, - 0x28, 0x74, 0x29, 0x0a, 0x09, 0x2d, 0x2d, 0x69, 0x66, 0x20, 0x69, 0x73, - 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x29, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x74, 0x0a, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x69, - 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x29, 0x0a, 0x0a, 0x09, - 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x5f, 0x75, 0x73, 0x65, 0x72, - 0x74, 0x79, 0x70, 0x65, 0x5b, 0x66, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x61, - 0x70, 0x70, 0x65, 0x6e, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, - 0x65, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x74, 0x0a, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x20, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x66, 0x75, 0x6c, 0x6c, 0x20, - 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x76, 0x61, 0x72, 0x28, 0x74, 0x79, - 0x70, 0x65, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, - 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x79, - 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x65, 0x6c, 0x73, - 0x65, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x74, - 0x20, 0x3d, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, - 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x66, - 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x74, 0x0a, 0x09, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x09, 0x09, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, - 0x65, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x79, - 0x70, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x69, 0x73, 0x20, 0x65, 0x6e, 0x75, - 0x6d, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, - 0x73, 0x65, 0x6e, 0x75, 0x6d, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, - 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x65, - 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x0a, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, - 0x20, 0x69, 0x66, 0x20, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x74, 0x79, - 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, - 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x28, 0x74, 0x79, 0x70, - 0x65, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, - 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x79, 0x70, 0x65, 0x2c, - 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x27, 0x29, - 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x2c, 0x74, 0x20, - 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, 0x65, 0x64, - 0x65, 0x66, 0x28, 0x27, 0x27, 0x2c, 0x20, 0x74, 0x29, 0x0a, 0x20, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x20, 0x3d, 0x20, 0x5f, 0x62, 0x61, - 0x73, 0x69, 0x63, 0x5b, 0x74, 0x5d, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x62, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x62, 0x2c, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, - 0x63, 0x74, 0x79, 0x70, 0x65, 0x5b, 0x62, 0x5d, 0x0a, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, - 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x73, 0x70, - 0x6c, 0x69, 0x74, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x75, - 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x70, - 0x6c, 0x69, 0x74, 0x20, 0x28, 0x73, 0x2c, 0x74, 0x29, 0x0a, 0x20, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, - 0x30, 0x7d, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, - 0x3d, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, - 0x73, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x6c, - 0x2e, 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x20, 0x6c, 0x5b, 0x6c, - 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x0a, 0x20, 0x20, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x20, 0x3d, 0x20, - 0x22, 0x25, 0x73, 0x2a, 0x28, 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2a, 0x22, - 0x2e, 0x2e, 0x74, 0x2e, 0x2e, 0x22, 0x25, 0x73, 0x2a, 0x22, 0x0a, 0x20, - 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, - 0x5e, 0x25, 0x73, 0x2b, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x73, - 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x25, - 0x73, 0x2b, 0x24, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x73, 0x20, - 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x70, 0x2c, 0x66, - 0x29, 0x0a, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x6c, 0x2e, 0x6e, - 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x6c, 0x5b, 0x6c, 0x2e, 0x6e, 0x5d, - 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x28, - 0x25, 0x73, 0x25, 0x73, 0x2a, 0x29, 0x24, 0x22, 0x2c, 0x22, 0x22, 0x29, - 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x0a, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, - 0x73, 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x75, - 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, - 0x72, 0x6e, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72, - 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x70, 0x61, 0x63, - 0x69, 0x61, 0x6c, 0x20, 0x63, 0x61, 0x73, 0x65, 0x73, 0x20, 0x6f, 0x66, - 0x20, 0x43, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x28, 0x74, 0x65, 0x6d, - 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, - 0x65, 0x72, 0x73, 0x2c, 0x20, 0x65, 0x74, 0x63, 0x29, 0x0a, 0x2d, 0x2d, - 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x20, 0x63, 0x61, 0x6e, - 0x27, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x27, 0x5e, 0x27, 0x20, 0x28, 0x61, 0x73, 0x20, 0x75, - 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x69, 0x64, 0x65, 0x6e, 0x74, - 0x69, 0x66, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x65, 0x67, 0x69, - 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x6c, 0x69, 0x6e, 0x65, 0x29, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6c, 0x73, - 0x6f, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x73, 0x20, 0x77, 0x68, 0x69, - 0x74, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, - 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x20, 0x70, - 0x61, 0x74, 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, - 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, - 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, - 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x62, - 0x65, 0x67, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x65, 0x6e, - 0x64, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x6e, - 0x3d, 0x30, 0x7d, 0x0a, 0x0a, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x20, 0x61, 0x64, 0x64, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x28, 0x6f, 0x66, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, - 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x74, 0x6f, 0x6b, - 0x65, 0x6e, 0x5f, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x2c, 0x20, 0x6f, 0x66, - 0x73, 0x29, 0x0a, 0x09, 0x09, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, 0x20, - 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, - 0x09, 0x09, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x25, 0x73, - 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x72, - 0x65, 0x74, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x6e, - 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x5b, 0x72, - 0x65, 0x74, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x0a, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x6f, - 0x66, 0x73, 0x20, 0x3c, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x6c, 0x65, 0x6e, 0x28, 0x73, 0x29, 0x20, 0x64, 0x6f, 0x0a, 0x0a, - 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x75, 0x62, 0x20, - 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, - 0x28, 0x73, 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x2c, 0x20, 0x2d, 0x31, 0x29, - 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, - 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, - 0x6e, 0x64, 0x28, 0x73, 0x75, 0x62, 0x2c, 0x20, 0x22, 0x5e, 0x22, 0x2e, - 0x2e, 0x70, 0x61, 0x74, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x62, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x61, 0x64, 0x64, - 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x28, 0x6f, 0x66, 0x73, 0x2d, 0x31, - 0x29, 0x0a, 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, - 0x66, 0x73, 0x2b, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x6f, 0x6b, 0x65, - 0x6e, 0x5f, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x6f, 0x66, - 0x73, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, + 0x3d, 0x20, 0x5f, 0x53, 0x54, 0x44, 0x45, 0x52, 0x52, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x31, + 0x2c, 0x31, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x23, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, + 0x22, 0x5c, 0x6e, 0x2a, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, + 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x2c, 0x32, 0x29, 0x2e, 0x2e, 0x22, 0x2e, 0x5c, 0x6e, 0x5c, 0x6e, 0x22, + 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, + 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, + 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x22, + 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x2e, 0x2d, 0x5c, 0x6e, 0x29, 0x22, 0x29, + 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x78, 0x74, 0x72, 0x61, 0x63, 0x74, 0x20, + 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x20, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x5f, 0x63, 0x75, + 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x20, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x22, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, 0x74, 0x61, + 0x22, 0x2c, 0x22, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x22, 0x29, 0x20, 0x2d, + 0x2d, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x77, 0x69, 0x74, + 0x68, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x27, 0x0a, 0x20, 0x20, + 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, + 0x22, 0x5f, 0x63, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x2c, 0x22, + 0x63, 0x68, 0x61, 0x72, 0x2a, 0x22, 0x29, 0x20, 0x20, 0x2d, 0x2d, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, + 0x27, 0x63, 0x68, 0x61, 0x72, 0x2a, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x73, + 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x5f, + 0x6c, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x2c, 0x22, 0x6c, 0x75, 0x61, + 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x22, 0x29, 0x20, 0x20, 0x2d, + 0x2d, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x77, 0x69, 0x74, + 0x68, 0x20, 0x27, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, + 0x2a, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, + 0x22, 0x43, 0x6f, 0x64, 0x65, 0x20, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x20, + 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x3a, 0x5c, 0x6e, + 0x22, 0x2e, 0x2e, 0x73, 0x2e, 0x2e, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, + 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x66, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x22, 0x28, 0x66, 0x20, 0x69, + 0x73, 0x20, 0x6e, 0x69, 0x6c, 0x29, 0x22, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x22, 0x5c, 0x6e, 0x2a, + 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x20, 0x69, 0x6e, 0x74, 0x65, + 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3a, 0x20, + 0x22, 0x2e, 0x2e, 0x66, 0x2e, 0x2e, 0x73, 0x2e, 0x2e, 0x22, 0x2e, 0x5c, + 0x6e, 0x5c, 0x6e, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x5f, 0x4f, 0x55, + 0x54, 0x50, 0x55, 0x54, 0x20, 0x3d, 0x20, 0x6f, 0x75, 0x74, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x28, 0x6d, 0x73, + 0x67, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, + 0x2e, 0x71, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x5f, 0x4f, 0x55, 0x54, + 0x50, 0x55, 0x54, 0x0a, 0x20, 0x5f, 0x4f, 0x55, 0x54, 0x50, 0x55, 0x54, + 0x20, 0x3d, 0x20, 0x5f, 0x53, 0x54, 0x44, 0x45, 0x52, 0x52, 0x0a, 0x20, + 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, 0x22, 0x5c, 0x6e, 0x2a, 0x2a, 0x20, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x20, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, + 0x67, 0x3a, 0x20, 0x22, 0x2e, 0x2e, 0x6d, 0x73, 0x67, 0x2e, 0x2e, 0x22, + 0x2e, 0x5c, 0x6e, 0x5c, 0x6e, 0x22, 0x29, 0x0a, 0x20, 0x5f, 0x4f, 0x55, + 0x54, 0x50, 0x55, 0x54, 0x20, 0x3d, 0x20, 0x6f, 0x75, 0x74, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x67, 0x69, 0x73, + 0x74, 0x65, 0x72, 0x20, 0x61, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, + 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, + 0x3a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x66, 0x75, + 0x6c, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x72, 0x65, 0x67, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x2d, 0x2d, 0x69, 0x66, 0x20, 0x69, + 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x74, 0x0a, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x74, 0x20, 0x3d, 0x20, 0x66, + 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x29, 0x0a, 0x0a, + 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x5f, 0x75, 0x73, 0x65, + 0x72, 0x74, 0x79, 0x70, 0x65, 0x5b, 0x66, 0x74, 0x5d, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, + 0x70, 0x65, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x74, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x66, 0x75, 0x6c, 0x6c, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x76, 0x61, 0x72, 0x28, 0x74, + 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x65, 0x6c, + 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, + 0x74, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, + 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, + 0x66, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x74, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, + 0x70, 0x65, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x69, 0x73, 0x20, 0x65, 0x6e, + 0x75, 0x6d, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x69, 0x73, 0x65, 0x6e, 0x75, 0x6d, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, + 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x74, + 0x79, 0x70, 0x65, 0x5d, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x69, 0x66, 0x20, 0x62, 0x61, + 0x73, 0x69, 0x63, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, + 0x63, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x20, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x6d, 0x2c, 0x74, 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, + 0x79, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, 0x27, 0x27, 0x2c, + 0x20, 0x74, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, + 0x20, 0x3d, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5b, 0x74, 0x5d, + 0x0a, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x62, 0x2c, 0x5f, + 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, 0x63, 0x74, 0x79, 0x70, 0x65, 0x5b, + 0x62, 0x5d, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, + 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x20, 0x28, 0x73, + 0x2c, 0x74, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, + 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, 0x7d, 0x0a, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x73, 0x29, 0x0a, 0x20, 0x20, 0x6c, + 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x2b, 0x20, 0x31, + 0x0a, 0x20, 0x20, 0x6c, 0x5b, 0x6c, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, + 0x73, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, + 0x22, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x28, 0x2e, + 0x2d, 0x29, 0x25, 0x73, 0x2a, 0x22, 0x2e, 0x2e, 0x74, 0x2e, 0x2e, 0x22, + 0x25, 0x73, 0x2a, 0x22, 0x0a, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, + 0x75, 0x62, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2b, 0x22, 0x2c, + 0x22, 0x22, 0x29, 0x0a, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x22, 0x25, 0x73, 0x2b, 0x24, 0x22, 0x2c, 0x22, + 0x22, 0x29, 0x0a, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x73, 0x2c, 0x70, 0x2c, 0x66, 0x29, 0x0a, 0x20, 0x6c, 0x2e, 0x6e, + 0x20, 0x3d, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, + 0x6c, 0x5b, 0x6c, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x22, 0x28, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x29, + 0x24, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x73, 0x20, 0x61, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, + 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x2c, 0x20, 0x63, 0x6f, + 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x73, 0x70, 0x61, 0x63, 0x69, 0x61, 0x6c, 0x20, 0x63, 0x61, + 0x73, 0x65, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x43, 0x20, 0x63, 0x6f, 0x64, + 0x65, 0x20, 0x28, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, + 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x2c, 0x20, 0x65, + 0x74, 0x63, 0x29, 0x0a, 0x2d, 0x2d, 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, + 0x72, 0x6e, 0x20, 0x63, 0x61, 0x6e, 0x27, 0x74, 0x20, 0x63, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x27, 0x5e, 0x27, + 0x20, 0x28, 0x61, 0x73, 0x20, 0x75, 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f, + 0x20, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x79, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x6f, + 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x29, 0x0a, + 0x2d, 0x2d, 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x70, 0x73, 0x20, 0x77, 0x68, 0x69, 0x74, 0x65, 0x73, 0x70, 0x61, 0x63, + 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, + 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x73, 0x28, 0x73, 0x2c, 0x20, 0x70, 0x61, 0x74, 0x29, 0x0a, 0x0a, 0x09, + 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, + 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, + 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, + 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, + 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x20, 0x3d, + 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x5f, 0x65, 0x6e, 0x64, 0x20, 0x3d, 0x20, 0x31, 0x0a, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x66, 0x73, 0x20, 0x3d, + 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x65, + 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, 0x7d, 0x0a, 0x0a, 0x09, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x64, 0x64, + 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x28, 0x6f, 0x66, 0x73, 0x29, 0x0a, + 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, - 0x73, 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x29, - 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, - 0x3d, 0x3d, 0x20, 0x22, 0x28, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x68, - 0x61, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x3c, 0x22, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x0a, 0x09, 0x09, 0x09, 0x09, - 0x69, 0x66, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, - 0x28, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x20, 0x3d, 0x20, 0x22, 0x5e, 0x25, 0x62, 0x28, 0x29, 0x22, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, - 0x68, 0x61, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x3c, 0x22, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x20, 0x3d, 0x20, - 0x22, 0x5e, 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x0a, 0x09, 0x09, 0x09, 0x09, 0x62, 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, - 0x75, 0x62, 0x2c, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x29, 0x0a, 0x09, - 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, - 0x20, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, - 0x64, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x3f, 0x0a, 0x09, 0x09, 0x09, - 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, 0x2b, - 0x31, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, - 0x09, 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, - 0x73, 0x20, 0x2b, 0x20, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, - 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, - 0x2b, 0x31, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, - 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x61, - 0x64, 0x64, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x28, 0x6f, 0x66, 0x73, - 0x29, 0x0a, 0x09, 0x2d, 0x2d, 0x69, 0x66, 0x20, 0x72, 0x65, 0x74, 0x2e, - 0x6e, 0x20, 0x3d, 0x3d, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x72, 0x65, 0x74, 0x2e, 0x6e, 0x3d, 0x31, - 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x72, 0x65, 0x74, 0x5b, 0x31, 0x5d, 0x20, - 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, 0x0a, - 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x65, 0x74, - 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x6f, - 0x6e, 0x63, 0x61, 0x74, 0x65, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x74, - 0x61, 0x62, 0x6c, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x20, 0x28, 0x74, 0x2c, - 0x66, 0x2c, 0x6c, 0x2c, 0x6a, 0x73, 0x74, 0x72, 0x29, 0x0a, 0x09, 0x6a, - 0x73, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x6a, 0x73, 0x74, 0x72, 0x20, 0x6f, - 0x72, 0x20, 0x22, 0x20, 0x22, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x73, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x20, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x66, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, - 0x65, 0x20, 0x69, 0x3c, 0x3d, 0x6c, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, - 0x73, 0x20, 0x3d, 0x20, 0x73, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, - 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, - 0x69, 0x66, 0x20, 0x69, 0x20, 0x3c, 0x3d, 0x20, 0x6c, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x2e, 0x2e, 0x6a, 0x73, - 0x74, 0x72, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x0a, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, - 0x65, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x70, 0x61, - 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x2c, 0x20, 0x66, 0x6f, - 0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x20, 0x72, 0x75, 0x6c, 0x65, 0x73, 0x0a, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, - 0x70, 0x61, 0x72, 0x61, 0x6d, 0x20, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, - 0x20, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, - 0x69, 0x3c, 0x3d, 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, - 0x20, 0x20, 0x69, 0x66, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x61, - 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, - 0x6e, 0x64, 0x28, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x2c, 0x27, 0x5b, 0x25, - 0x28, 0x2c, 0x22, 0x5d, 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, - 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x22, 0x5e, 0x5b, 0x25, 0x61, - 0x5f, 0x7e, 0x5d, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x20, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x6c, - 0x69, 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x27, 0x20, 0x27, 0x0a, 0x20, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, - 0x3d, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x61, 0x72, - 0x67, 0x5b, 0x69, 0x5d, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x61, 0x72, - 0x67, 0x5b, 0x69, 0x5d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, - 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x72, - 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x2d, 0x31, 0x2c, 0x2d, 0x31, 0x29, 0x0a, - 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, - 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, - 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x72, 0x67, - 0x5b, 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x5d, 0x2c, 0x22, 0x5b, 0x25, 0x2f, - 0x25, 0x29, 0x25, 0x3b, 0x25, 0x7b, 0x25, 0x7d, 0x5d, 0x24, 0x22, 0x29, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x5f, 0x63, 0x6f, 0x6e, - 0x74, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, - 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x27, 0x5c, 0x6e, - 0x27, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, - 0x0a, 0x2d, 0x2d, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x6c, - 0x69, 0x6e, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x28, 0x2e, 0x2e, 0x2e, - 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, - 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x69, 0x3c, 0x3d, 0x61, - 0x72, 0x67, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x69, 0x66, - 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, - 0x6f, 0x74, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x5f, - 0x63, 0x6f, 0x6e, 0x74, 0x2c, 0x27, 0x5b, 0x25, 0x28, 0x2c, 0x22, 0x5d, - 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x72, 0x67, 0x5b, - 0x69, 0x5d, 0x2c, 0x22, 0x5e, 0x5b, 0x25, 0x61, 0x5f, 0x7e, 0x5d, 0x22, - 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x20, - 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, 0x27, 0x20, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x29, 0x0a, 0x20, 0x20, 0x69, - 0x66, 0x20, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x20, 0x7e, 0x3d, 0x20, - 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, - 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, - 0x62, 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x2d, 0x31, 0x2c, - 0x2d, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, - 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, - 0x28, 0x61, 0x72, 0x67, 0x5b, 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x5d, 0x2c, - 0x22, 0x5b, 0x25, 0x2f, 0x25, 0x29, 0x25, 0x3b, 0x25, 0x7b, 0x25, 0x7d, - 0x5d, 0x24, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, - 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x77, 0x72, - 0x69, 0x74, 0x65, 0x28, 0x27, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, - 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, - 0x73, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x6e, 0x61, 0x6d, - 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x67, 0x65, 0x74, 0x5f, - 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, - 0x68, 0x6f, 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x20, 0x61, 0x6e, - 0x64, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, + 0x73, 0x2c, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x62, 0x65, 0x67, + 0x69, 0x6e, 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x29, 0x0a, 0x09, 0x09, 0x74, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, + 0x75, 0x62, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x22, + 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x74, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, + 0x22, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x2e, 0x6e, 0x20, 0x3d, + 0x20, 0x72, 0x65, 0x74, 0x2e, 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x09, + 0x09, 0x72, 0x65, 0x74, 0x5b, 0x72, 0x65, 0x74, 0x2e, 0x6e, 0x5d, 0x20, + 0x3d, 0x20, 0x74, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x77, + 0x68, 0x69, 0x6c, 0x65, 0x20, 0x6f, 0x66, 0x73, 0x20, 0x3c, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x6c, 0x65, 0x6e, 0x28, 0x73, + 0x29, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x73, 0x75, 0x62, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x6f, 0x66, + 0x73, 0x2c, 0x20, 0x2d, 0x31, 0x29, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x75, 0x62, + 0x2c, 0x20, 0x22, 0x5e, 0x22, 0x2e, 0x2e, 0x70, 0x61, 0x74, 0x29, 0x0a, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x61, 0x64, 0x64, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x28, 0x6f, 0x66, 0x73, 0x2d, 0x31, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x6f, + 0x66, 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, 0x2b, 0x65, 0x0a, 0x09, + 0x09, 0x09, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x62, 0x65, 0x67, 0x69, + 0x6e, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, 0x0a, 0x09, 0x09, 0x65, 0x6c, + 0x73, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x6f, 0x66, 0x73, + 0x2c, 0x20, 0x6f, 0x66, 0x73, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, + 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x28, 0x22, + 0x20, 0x6f, 0x72, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x3d, 0x20, + 0x22, 0x3c, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, + 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x68, 0x61, + 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x28, 0x22, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x20, 0x3d, 0x20, 0x22, 0x5e, + 0x25, 0x62, 0x28, 0x29, 0x22, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x3d, 0x3d, + 0x20, 0x22, 0x3c, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x20, 0x3d, 0x20, 0x22, 0x5e, 0x25, 0x62, 0x3c, 0x3e, + 0x22, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x62, + 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x75, 0x62, 0x2c, 0x20, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, + 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x75, 0x6e, 0x74, 0x65, 0x72, + 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x3f, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, 0x20, + 0x3d, 0x20, 0x6f, 0x66, 0x73, 0x2b, 0x31, 0x0a, 0x09, 0x09, 0x09, 0x09, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x6f, 0x66, + 0x73, 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, 0x20, 0x2b, 0x20, 0x65, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x09, 0x09, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x6f, 0x66, 0x73, + 0x20, 0x3d, 0x20, 0x6f, 0x66, 0x73, 0x2b, 0x31, 0x0a, 0x09, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x61, 0x64, 0x64, 0x5f, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x28, 0x6f, 0x66, 0x73, 0x29, 0x0a, 0x09, 0x2d, 0x2d, 0x69, + 0x66, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x6e, 0x20, 0x3d, 0x3d, 0x20, 0x30, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x72, + 0x65, 0x74, 0x2e, 0x6e, 0x3d, 0x31, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x72, + 0x65, 0x74, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, + 0x2d, 0x2d, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x65, 0x6e, + 0x61, 0x74, 0x65, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x20, + 0x6f, 0x66, 0x20, 0x61, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6f, 0x6e, 0x63, + 0x61, 0x74, 0x20, 0x28, 0x74, 0x2c, 0x66, 0x2c, 0x6c, 0x2c, 0x6a, 0x73, + 0x74, 0x72, 0x29, 0x0a, 0x09, 0x6a, 0x73, 0x74, 0x72, 0x20, 0x3d, 0x20, + 0x6a, 0x73, 0x74, 0x72, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x20, 0x22, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x27, + 0x27, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x66, + 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x69, 0x3c, 0x3d, 0x6c, + 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x2e, + 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, + 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x69, 0x20, 0x3c, + 0x3d, 0x20, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x73, 0x20, 0x3d, + 0x20, 0x73, 0x2e, 0x2e, 0x6a, 0x73, 0x74, 0x72, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x73, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, + 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x65, 0x6e, 0x61, 0x74, 0x65, 0x20, + 0x61, 0x6c, 0x6c, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, + 0x72, 0x73, 0x2c, 0x20, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, + 0x67, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x72, 0x75, 0x6c, + 0x65, 0x73, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x20, + 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x20, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, + 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x69, 0x3c, 0x3d, 0x61, 0x72, 0x67, + 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x5f, + 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x5f, 0x63, 0x6f, + 0x6e, 0x74, 0x2c, 0x27, 0x5b, 0x25, 0x28, 0x2c, 0x22, 0x5d, 0x27, 0x29, + 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, + 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, + 0x2c, 0x22, 0x5e, 0x5b, 0x25, 0x61, 0x5f, 0x7e, 0x5d, 0x22, 0x29, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x69, + 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x2e, 0x2e, + 0x20, 0x27, 0x20, 0x27, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x6c, 0x69, 0x6e, 0x65, + 0x20, 0x2e, 0x2e, 0x20, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x20, 0x7e, + 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x73, 0x75, 0x62, 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x2d, + 0x31, 0x2c, 0x2d, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, + 0x6e, 0x64, 0x28, 0x61, 0x72, 0x67, 0x5b, 0x61, 0x72, 0x67, 0x2e, 0x6e, + 0x5d, 0x2c, 0x22, 0x5b, 0x25, 0x2f, 0x25, 0x29, 0x25, 0x3b, 0x25, 0x7b, + 0x25, 0x7d, 0x5d, 0x24, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x3d, 0x6e, 0x69, 0x6c, 0x20, + 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, + 0x2e, 0x2e, 0x20, 0x27, 0x5c, 0x6e, 0x27, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x69, 0x6e, + 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x20, 0x28, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, + 0x65, 0x20, 0x69, 0x3c, 0x3d, 0x61, 0x72, 0x67, 0x2e, 0x6e, 0x20, 0x64, + 0x6f, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x72, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x2c, 0x27, + 0x5b, 0x25, 0x28, 0x2c, 0x22, 0x5d, 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, 0x5d, 0x2c, 0x22, 0x5e, 0x5b, + 0x25, 0x61, 0x5f, 0x7e, 0x5d, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x20, 0x20, 0x20, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, + 0x27, 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, 0x61, 0x72, 0x67, 0x5b, 0x69, + 0x5d, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x61, 0x72, 0x67, 0x5b, + 0x69, 0x5d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x72, 0x67, 0x5b, + 0x69, 0x5d, 0x2c, 0x2d, 0x31, 0x2c, 0x2d, 0x31, 0x29, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, + 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, + 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x72, 0x67, 0x5b, 0x61, + 0x72, 0x67, 0x2e, 0x6e, 0x5d, 0x2c, 0x22, 0x5b, 0x25, 0x2f, 0x25, 0x29, + 0x25, 0x3b, 0x25, 0x7b, 0x25, 0x7d, 0x5d, 0x24, 0x22, 0x29, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x3d, + 0x6e, 0x69, 0x6c, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, 0x27, 0x5c, + 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, + 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, + 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x28, 0x70, 0x74, 0x79, 0x70, + 0x65, 0x2c, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x5f, 0x68, - 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x6e, 0x61, - 0x6d, 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, - 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, - 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x74, 0x79, 0x70, - 0x65, 0x2c, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x65, 0x6e, + 0x6f, 0x6f, 0x6b, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x67, 0x65, 0x74, 0x5f, + 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, + 0x68, 0x6f, 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x74, + 0x79, 0x70, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, + 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, + 0x6b, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x6e, 0x61, 0x6d, + 0x65, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, + 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x64, + 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x20, 0x73, 0x65, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x09, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x67, 0x65, 0x74, + 0x5f, 0x22, 0x2e, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x73, + 0x65, 0x74, 0x5f, 0x22, 0x2e, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x70, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x71, 0x74, 0x22, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x20, 0x73, 0x65, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, + 0x22, 0x73, 0x65, 0x74, 0x22, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x75, 0x70, 0x70, 0x65, 0x72, 0x28, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x20, 0x31, 0x2c, 0x20, 0x31, 0x29, 0x29, 0x2e, 0x2e, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x20, 0x32, 0x2c, 0x20, 0x2d, 0x31, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, - 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, - 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, - 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x73, 0x65, 0x74, 0x5f, - 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, - 0x6e, 0x20, 0x22, 0x67, 0x65, 0x74, 0x5f, 0x22, 0x2e, 0x2e, 0x6e, 0x61, - 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x73, 0x65, 0x74, 0x5f, 0x22, 0x2e, 0x2e, + 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, + 0x64, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x09, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, - 0x69, 0x66, 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, - 0x22, 0x71, 0x74, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, - 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x73, 0x65, 0x74, 0x4e, 0x61, - 0x6d, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x73, 0x65, 0x74, 0x22, 0x2e, - 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x75, 0x70, 0x70, 0x65, - 0x72, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, - 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x29, - 0x29, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, - 0x62, 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x32, 0x2c, 0x20, 0x2d, - 0x31, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, - 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6f, - 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x6e, - 0x61, 0x6d, 0x65, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x09, - 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x68, 0x6f, 0x6f, 0x6b, 0x73, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x72, 0x69, - 0x67, 0x68, 0x74, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x70, 0x72, - 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x24, 0x5b, 0x69, 0x63, 0x68, 0x6c, 0x5d, 0x66, 0x69, 0x6c, 0x65, - 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x73, 0x2c, - 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x62, 0x65, - 0x66, 0x6f, 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, - 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6e, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, - 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, - 0x65, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x63, 0x6b, 0x61, - 0x67, 0x65, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x61, 0x73, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, - 0x65, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, - 0x70, 0x72, 0x65, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x68, - 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x29, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x70, - 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x68, 0x61, 0x73, 0x20, 0x61, 0x6c, - 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, - 0x63, 0x6f, 0x64, 0x65, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, - 0x65, 0x20, 0x70, 0x6b, 0x67, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x6f, - 0x72, 0x20, 0x65, 0x76, 0x65, 0x72, 0x79, 0x20, 0x24, 0x69, 0x66, 0x69, - 0x6c, 0x65, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, - 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x61, 0x20, - 0x74, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x63, 0x61, 0x6c, 0x6c, - 0x65, 0x64, 0x20, 0x27, 0x63, 0x6f, 0x64, 0x65, 0x27, 0x20, 0x69, 0x6e, - 0x73, 0x69, 0x64, 0x65, 0x2c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, - 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, - 0x61, 0x6e, 0x79, 0x20, 0x65, 0x78, 0x74, 0x72, 0x61, 0x20, 0x61, 0x72, - 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x70, - 0x61, 0x73, 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x24, 0x69, 0x66, - 0x69, 0x6c, 0x65, 0x2e, 0x20, 0x6e, 0x6f, 0x20, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, - 0x65, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, - 0x74, 0x2c, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x2c, - 0x20, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x61, 0x66, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x68, + 0x6f, 0x6f, 0x6b, 0x73, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, + 0x6c, 0x65, 0x64, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, - 0x6e, 0x67, 0x20, 0x61, 0x6e, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, - 0x74, 0x68, 0x61, 0x74, 0x27, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x63, - 0x6f, 0x64, 0x65, 0x20, 0x28, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x27, 0x24, - 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x27, 0x2c, 0x20, 0x63, - 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2c, 0x20, 0x65, 0x74, 0x63, - 0x29, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x72, 0x69, 0x67, - 0x68, 0x74, 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x70, 0x61, - 0x72, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x63, - 0x74, 0x75, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x0a, 0x2d, - 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, 0x6f, 0x62, 0x6a, 0x65, - 0x63, 0x74, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x6c, 0x6c, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x6f, 0x6e, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x27, 0x63, 0x6f, 0x64, 0x65, 0x27, 0x20, 0x6b, - 0x65, 0x79, 0x2e, 0x20, 0x6e, 0x6f, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, - 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x70, 0x61, 0x72, 0x73, - 0x65, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, - 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, - 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x62, 0x65, 0x66, 0x6f, - 0x72, 0x65, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74, 0x69, 0x6e, 0x67, 0x20, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x5f, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, - 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, - 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x61, 0x66, 0x74, - 0x65, 0x72, 0x20, 0x77, 0x72, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, - 0x6c, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x2e, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, - 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, - 0x6b, 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, - 0x72, 0x6f, 0x6d, 0x20, 0x27, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, - 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, - 0x73, 0x27, 0x20, 0x74, 0x6f, 0x20, 0x67, 0x65, 0x74, 0x20, 0x74, 0x68, - 0x65, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x20, 0x74, 0x6f, - 0x20, 0x72, 0x65, 0x74, 0x72, 0x69, 0x65, 0x76, 0x65, 0x20, 0x61, 0x20, - 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x0a, 0x2d, 0x2d, 0x20, - 0x61, 0x63, 0x63, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x6f, - 0x20, 0x69, 0x74, 0x73, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, - 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, - 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, - 0x6f, 0x64, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x72, 0x6f, - 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, - 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, - 0x6f, 0x6d, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, - 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x64, 0x6f, 0x70, 0x61, 0x72, 0x73, - 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x20, - 0x70, 0x61, 0x72, 0x73, 0x65, 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x2c, 0x20, 0x6f, 0x72, - 0x20, 0x61, 0x20, 0x73, 0x75, 0x62, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, - 0x72, 0x73, 0x65, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x29, - 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, - 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, - 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x63, 0x6c, - 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, - 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x62, 0x65, 0x66, - 0x6f, 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x6c, 0x6c, - 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, - 0x70, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x68, 0x6f, 0x6f, - 0x6b, 0x28, 0x66, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, - 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, - 0x6d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x2c, - 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, - 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x20, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x63, 0x61, 0x6c, 0x6c, - 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x66, 0x29, 0x0a, 0x0a, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, - 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x20, 0x63, 0x6f, 0x64, - 0x65, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, - 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x68, 0x6f, + 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x24, 0x5b, 0x69, 0x63, 0x68, + 0x6c, 0x5d, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, + 0x74, 0x69, 0x76, 0x65, 0x73, 0x2c, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x69, + 0x67, 0x68, 0x74, 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x70, + 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6e, + 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, + 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x74, 0x68, 0x65, + 0x20, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, 0x6f, 0x62, 0x6a, + 0x65, 0x63, 0x74, 0x20, 0x61, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x70, 0x72, 0x6f, + 0x63, 0x65, 0x73, 0x73, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x29, + 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x70, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x20, + 0x68, 0x61, 0x73, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, + 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x66, + 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x6b, 0x67, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, + 0x6c, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x65, 0x76, 0x65, 0x72, + 0x79, 0x20, 0x24, 0x69, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x64, 0x69, 0x72, + 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, + 0x6b, 0x65, 0x73, 0x20, 0x61, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x20, + 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x27, 0x63, 0x6f, + 0x64, 0x65, 0x27, 0x20, 0x69, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x2c, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x65, 0x78, + 0x74, 0x72, 0x61, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, + 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x70, 0x61, 0x73, 0x73, 0x65, 0x64, 0x20, + 0x74, 0x6f, 0x20, 0x24, 0x69, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x20, 0x6e, + 0x6f, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x5f, 0x66, 0x69, 0x6c, 0x65, + 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x74, 0x2c, 0x20, 0x66, 0x69, 0x6c, + 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, + 0x6c, 0x65, 0x64, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x70, 0x72, + 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6e, 0x79, + 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x61, 0x74, 0x27, 0x73, + 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x28, 0x6c, + 0x69, 0x6b, 0x65, 0x20, 0x27, 0x24, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, + 0x6e, 0x67, 0x27, 0x2c, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, + 0x73, 0x2c, 0x20, 0x65, 0x74, 0x63, 0x29, 0x0a, 0x2d, 0x2d, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x62, 0x65, 0x66, + 0x6f, 0x72, 0x65, 0x20, 0x70, 0x61, 0x72, 0x73, 0x69, 0x6e, 0x67, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x61, 0x63, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x63, + 0x6f, 0x64, 0x65, 0x2e, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x6b, 0x65, + 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, + 0x65, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x77, 0x69, 0x74, + 0x68, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, + 0x64, 0x65, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x27, 0x63, + 0x6f, 0x64, 0x65, 0x27, 0x20, 0x6b, 0x65, 0x79, 0x2e, 0x20, 0x6e, 0x6f, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, + 0x72, 0x65, 0x70, 0x61, 0x72, 0x73, 0x65, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, + 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, + 0x64, 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x73, 0x74, 0x61, + 0x72, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, + 0x65, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x68, 0x6f, 0x6f, + 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, + 0x65, 0x64, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x77, 0x72, 0x69, + 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x68, 0x65, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2e, 0x0a, 0x2d, 0x2d, 0x20, + 0x74, 0x61, 0x6b, 0x65, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x50, 0x61, + 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x6f, + 0x73, 0x74, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x29, 0x0a, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, + 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x27, 0x67, + 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, + 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x27, 0x20, 0x74, 0x6f, 0x20, + 0x67, 0x65, 0x74, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x72, 0x65, 0x74, 0x72, 0x69, + 0x65, 0x76, 0x65, 0x20, 0x61, 0x20, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, + 0x74, 0x79, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x63, 0x63, 0x6f, 0x72, 0x64, + 0x69, 0x6e, 0x67, 0x20, 0x74, 0x6f, 0x20, 0x69, 0x74, 0x73, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, + 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x5f, 0x68, 0x6f, + 0x6f, 0x6b, 0x28, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, - 0x6c, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x20, 0x61, 0x6e, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, - 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x2e, 0x2e, - 0x2e, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, - 0x28, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, - 0x2d, 0x20, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x20, 0x70, 0x75, 0x73, - 0x68, 0x65, 0x72, 0x73, 0x0a, 0x0a, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, - 0x7b, 0x7d, 0x0a, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x65, - 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x74, - 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, - 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, + 0x6c, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x43, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, + 0x64, 0x6f, 0x70, 0x61, 0x72, 0x73, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, + 0x62, 0x65, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x61, 0x72, 0x73, 0x65, 0x64, + 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, + 0x69, 0x6c, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x20, 0x73, 0x75, 0x62, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x72, 0x73, 0x65, 0x72, 0x5f, 0x68, + 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x66, + 0x72, 0x6f, 0x6d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, + 0x65, 0x2c, 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, + 0x73, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x5f, 0x63, 0x61, + 0x6c, 0x6c, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x66, 0x29, 0x0a, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, + 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x73, 0x75, + 0x70, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x6f, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x6f, 0x73, + 0x74, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, + 0x66, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, + 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x62, 0x65, 0x66, 0x6f, 0x72, + 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, + 0x65, 0x72, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x69, 0x73, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, + 0x74, 0x65, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x70, 0x61, 0x63, + 0x6b, 0x61, 0x67, 0x65, 0x29, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x74, 0x6f, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x61, 0x6e, 0x20, 0x65, + 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x68, + 0x6f, 0x6f, 0x6b, 0x28, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x28, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x75, 0x73, 0x74, + 0x6f, 0x6d, 0x20, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x73, 0x0a, 0x0a, + 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x69, 0x73, + 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, + 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x3d, + 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, + 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, + 0x7d, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x69, 0x73, 0x5f, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, + 0x7d, 0x0a, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x74, 0x6f, 0x5f, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, + 0x7d, 0x0a, 0x0a, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, + 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x66, 0x75, 0x6e, + 0x63, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, + 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, + 0x74, 0x5d, 0x0a, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x69, 0x66, + 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, 0x5b, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x75, + 0x6e, 0x63, 0x73, 0x5b, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, + 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x62, 0x74, 0x79, 0x70, 0x65, 0x5d, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x62, 0x61, 0x73, - 0x65, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x5f, 0x62, 0x61, 0x73, - 0x65, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, - 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, - 0x74, 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, 0x29, 0x0a, 0x0a, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, - 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, - 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x0a, 0x0a, 0x09, 0x77, - 0x68, 0x69, 0x6c, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x64, - 0x6f, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, - 0x5b, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x5d, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x73, 0x5b, 0x63, 0x6c, - 0x61, 0x73, 0x73, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x0a, 0x09, 0x09, - 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, - 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, - 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, - 0x62, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, + 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x73, + 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, + 0x2c, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x70, 0x75, 0x73, 0x68, + 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x29, 0x20, + 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, + 0x73, 0x68, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x70, 0x75, 0x73, 0x68, - 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, - 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, - 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, 0x73, - 0x65, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x75, 0x73, 0x65, 0x72, - 0x74, 0x79, 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, - 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, - 0x74, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, - 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x5b, 0x74, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, - 0x68, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, - 0x61, 0x73, 0x65, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, - 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x73, - 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, - 0x0a, 0x09, 0x69, 0x66, 0x20, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, - 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x69, 0x73, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x0a, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x69, - 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, - 0x74, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, - 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, - 0x73, 0x65, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, - 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a + 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x6f, 0x72, + 0x20, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, 0x61, 0x73, 0x65, + 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x74, 0x6f, + 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x29, 0x20, + 0x6f, 0x72, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, + 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x67, 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x5f, + 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x22, 0x20, 0x2e, 0x2e, + 0x20, 0x74, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x6f, 0x72, 0x20, + 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, + 0x74, 0x2c, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x69, 0x73, 0x5f, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x29, 0x20, 0x6f, + 0x72, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x75, + 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x22, 0x0a, 0x65, 0x6e, 0x64, + 0x0a }; -unsigned int lua_basic_lua_len = 9031; +unsigned int lua_basic_lua_len = 9049; diff --git a/lib/tolua++/src/bin/declaration_lua.h b/lib/tolua++/src/bin/declaration_lua.h index 0e3486604..28deb4f60 100644 --- a/lib/tolua++/src/bin/declaration_lua.h +++ b/lib/tolua++/src/bin/declaration_lua.h @@ -476,724 +476,758 @@ static const unsigned char lua_declaration_lua[] = { 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, 0x30, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x27, 0x0a, 0x20, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x27, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x27, 0x2e, - 0x2e, 0x74, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, - 0x2c, 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, 0x2e, 0x2e, 0x27, 0x2c, 0x26, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x27, 0x0a, - 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x69, 0x73, 0x65, 0x6e, - 0x75, 0x6d, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, - 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x72, 0x65, 0x74, + 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x69, 0x73, 0x65, + 0x6e, 0x75, 0x6d, 0x74, 0x79, 0x70, 0x65, 0x28, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x6e, 0x69, + 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, 0x2e, 0x2e, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x27, 0x0a, - 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, - 0x67, 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, - 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x20, - 0x6f, 0x72, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, - 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, - 0x20, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x28, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x6e, 0x69, 0x6c, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, - 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, 0x26, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x20, 0x7c, - 0x7c, 0x20, 0x21, 0x27, 0x2e, 0x2e, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, - 0x63, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, + 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x27, 0x2e, 0x2e, + 0x74, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, - 0x22, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, - 0x65, 0x2e, 0x2e, 0x27, 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, - 0x2e, 0x2e, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, - 0x72, 0x72, 0x29, 0x29, 0x27, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, - 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x21, 0x27, - 0x2e, 0x2e, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2e, 0x2e, 0x27, - 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, - 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, 0x22, 0x27, 0x2e, 0x2e, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, - 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, 0x2e, 0x2e, 0x27, 0x2c, - 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x27, - 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x62, 0x75, 0x69, 0x6c, 0x64, - 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, - 0x28, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x20, 0x63, 0x70, 0x6c, 0x75, 0x73, - 0x70, 0x6c, 0x75, 0x73, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, - 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, - 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x3d, 0x3d, - 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, - 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x20, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, 0x27, - 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x6f, 0x64, 0x0a, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, - 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x63, 0x74, 0x79, 0x70, - 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, - 0x74, 0x25, 0x73, 0x2b, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x0a, 0x20, 0x69, - 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, - 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, - 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x27, 0x2c, 0x27, 0x27, 0x29, - 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, - 0x74, 0x65, 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x6d, 0x6f, - 0x64, 0x69, 0x66, 0x69, 0x65, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, - 0x72, 0x72, 0x61, 0x79, 0x73, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, - 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x7e, - 0x3d, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, - 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x79, 0x70, 0x65, - 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, - 0x20, 0x27, 0x2a, 0x27, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x69, - 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, - 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x22, 0x20, - 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x74, - 0x79, 0x70, 0x65, 0x2c, 0x70, 0x74, 0x72, 0x29, 0x0a, 0x20, 0x69, 0x66, - 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, - 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, - 0x65, 0x2c, 0x27, 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, - 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, - 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, - 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, - 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, - 0x72, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x7e, - 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, 0x2e, 0x2e, 0x27, 0x2c, 0x26, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x27, 0x0a, 0x20, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, + 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x20, 0x6f, + 0x72, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, + 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x28, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x6e, + 0x69, 0x6c, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, + 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, 0x26, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x20, 0x7c, 0x7c, + 0x20, 0x21, 0x27, 0x2e, 0x2e, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, + 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, 0x22, + 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x2e, 0x2e, 0x27, 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, 0x2e, + 0x2e, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, + 0x72, 0x29, 0x29, 0x27, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x21, 0x27, 0x2e, + 0x2e, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2e, 0x2e, 0x27, 0x28, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, + 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, 0x22, 0x27, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, 0x22, + 0x2c, 0x27, 0x2e, 0x2e, 0x64, 0x65, 0x66, 0x2e, 0x2e, 0x27, 0x2c, 0x26, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x27, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x64, + 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, + 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x20, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, + 0x6c, 0x75, 0x73, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x3d, 0x3d, 0x6e, + 0x69, 0x6c, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x69, + 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x20, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x6f, 0x64, 0x0a, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x63, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x25, 0x73, 0x2b, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x0a, 0x20, 0x69, 0x66, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, + 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, 0x6f, + 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x20, + 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, + 0x65, 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x6d, 0x6f, 0x64, + 0x69, 0x66, 0x69, 0x65, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x72, + 0x72, 0x61, 0x79, 0x73, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x7e, 0x3d, + 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x69, + 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, + 0x27, 0x2a, 0x27, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x69, 0x6e, + 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x22, 0x20, 0x22, + 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x74, 0x79, + 0x70, 0x65, 0x2c, 0x70, 0x74, 0x72, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, + 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, - 0x2c, 0x27, 0x5b, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, - 0x6d, 0x2c, 0x27, 0x5d, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, - 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x63, 0x70, 0x6c, 0x75, 0x73, - 0x70, 0x6c, 0x75, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x2c, 0x27, 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, - 0x27, 0x20, 0x3d, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, - 0x65, 0x77, 0x5f, 0x64, 0x69, 0x6d, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, - 0x65, 0x2c, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x2c, 0x20, 0x27, 0x2e, 0x2e, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x2e, 0x2e, 0x27, 0x29, - 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, + 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, + 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x7e, 0x3d, + 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, - 0x27, 0x20, 0x3d, 0x20, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x2c, - 0x70, 0x74, 0x72, 0x2c, 0x27, 0x2a, 0x29, 0x27, 0x2c, 0x0a, 0x09, 0x09, - 0x27, 0x6d, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x28, 0x28, 0x27, 0x2c, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x2c, 0x27, 0x29, 0x2a, 0x73, - 0x69, 0x7a, 0x65, 0x6f, 0x66, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, - 0x2c, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, - 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, - 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, - 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x69, 0x6e, - 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, - 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x20, 0x3d, - 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x20, 0x3d, - 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, - 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, - 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x20, 0x27, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x53, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, - 0x65, 0x0a, 0x20, 0x20, 0x09, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, - 0x28, 0x22, 0x74, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, 0x2e, 0x74, 0x6f, - 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x74, 0x29, 0x2e, 0x2e, 0x22, - 0x2c, 0x20, 0x70, 0x74, 0x72, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, 0x2e, - 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x70, 0x74, 0x72, 0x29, 0x29, 0x0a, 0x20, 0x20, 0x09, 0x69, - 0x66, 0x20, 0x74, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, - 0x65, 0x72, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, - 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x20, 0x22, 0x25, 0x2a, 0x22, 0x29, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x74, 0x20, 0x3d, - 0x20, 0x27, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, 0x74, 0x61, 0x27, 0x0a, - 0x20, 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, - 0x6f, 0x74, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x74, 0x72, - 0x3d, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x69, - 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, - 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x2a, - 0x27, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x69, 0x6e, 0x65, + 0x27, 0x5b, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, + 0x2c, 0x27, 0x5d, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, + 0x6c, 0x75, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, + 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, + 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, + 0x20, 0x3d, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, + 0x77, 0x5f, 0x64, 0x69, 0x6d, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x2c, 0x20, 0x27, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x2e, 0x2e, 0x27, 0x29, 0x3b, + 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6c, + 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, + 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, + 0x20, 0x3d, 0x20, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x70, + 0x74, 0x72, 0x2c, 0x27, 0x2a, 0x29, 0x27, 0x2c, 0x0a, 0x09, 0x09, 0x27, + 0x6d, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x28, 0x28, 0x27, 0x2c, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x2c, 0x27, 0x29, 0x2a, 0x73, 0x69, + 0x7a, 0x65, 0x6f, 0x66, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x2c, + 0x70, 0x74, 0x72, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, + 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x74, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, + 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, - 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x28, 0x28, 0x27, - 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x74, 0x79, - 0x70, 0x65, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, - 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x69, 0x6e, + 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x20, 0x3d, 0x20, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x20, 0x3d, 0x3d, + 0x20, 0x27, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, + 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, + 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x20, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x53, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x0a, 0x20, 0x20, 0x09, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, + 0x22, 0x74, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, 0x2e, 0x74, 0x6f, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x74, 0x29, 0x2e, 0x2e, 0x22, 0x2c, + 0x20, 0x70, 0x74, 0x72, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, 0x2e, 0x74, + 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x70, 0x74, 0x72, 0x29, 0x29, 0x0a, 0x20, 0x20, 0x09, 0x69, 0x66, + 0x20, 0x74, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x70, 0x74, 0x72, 0x2c, 0x20, 0x22, 0x25, 0x2a, 0x22, 0x29, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x74, 0x20, 0x3d, 0x20, + 0x27, 0x75, 0x73, 0x65, 0x72, 0x64, 0x61, 0x74, 0x61, 0x27, 0x0a, 0x20, + 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x74, 0x72, 0x3d, + 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x2a, 0x27, - 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x69, 0x6e, 0x65, + 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x20, + 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, + 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x28, 0x28, 0x27, 0x2c, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x74, 0x79, 0x70, + 0x65, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x74, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, - 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x29, 0x20, 0x27, - 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x69, 0x73, 0x65, 0x6e, 0x75, 0x6d, - 0x28, 0x6e, 0x63, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, - 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, - 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x28, 0x69, 0x6e, 0x74, 0x29, 0x20, 0x27, - 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x64, 0x65, 0x66, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x69, - 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, 0x7e, - 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, - 0x64, 0x65, 0x66, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, - 0x65, 0x66, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x28, 0x70, 0x74, 0x72, - 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x26, - 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x74, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x64, 0x65, 0x66, - 0x20, 0x3d, 0x20, 0x22, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x26, - 0x28, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x74, 0x79, - 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x29, 0x22, 0x2e, 0x2e, 0x64, 0x65, 0x66, - 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x69, 0x66, 0x20, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, - 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, - 0x2c, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x27, 0x2e, - 0x2e, 0x74, 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, - 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x27, 0x2c, - 0x64, 0x65, 0x66, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, - 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, - 0x65, 0x74, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x6c, - 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, - 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x74, - 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, - 0x2c, 0x27, 0x2c, 0x27, 0x2c, 0x64, 0x65, 0x66, 0x2c, 0x27, 0x29, 0x29, - 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, - 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x0a, 0x66, 0x75, - 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, - 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, - 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, 0x20, 0x28, 0x6e, 0x61, 0x72, - 0x67, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, - 0x64, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x3d, 0x3d, 0x6e, 0x69, - 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, - 0x5f, 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, - 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x64, - 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x6e, - 0x61, 0x72, 0x67, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, 0x29, 0x0a, 0x09, - 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6c, - 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x62, 0x75, 0x69, - 0x6c, 0x64, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x66, 0x61, 0x6c, 0x73, 0x65, - 0x29, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, - 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x2a, 0x27, 0x29, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x20, + 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, + 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x27, 0x29, 0x20, 0x27, 0x29, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x69, 0x73, 0x65, 0x6e, 0x75, 0x6d, 0x28, + 0x6e, 0x63, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, + 0x6e, 0x63, 0x61, 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, + 0x6e, 0x65, 0x2c, 0x27, 0x28, 0x69, 0x6e, 0x74, 0x29, 0x20, 0x27, 0x29, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x64, 0x65, 0x66, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x69, 0x66, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, 0x7e, 0x3d, + 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x64, + 0x65, 0x66, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, + 0x66, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x28, 0x70, 0x74, 0x72, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x26, 0x27, + 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x74, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x64, 0x65, 0x66, 0x20, + 0x3d, 0x20, 0x22, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x26, 0x28, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x2e, 0x2e, 0x22, 0x29, 0x22, 0x2e, 0x2e, 0x64, 0x65, 0x66, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, + 0x74, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, + 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x27, 0x2e, 0x2e, + 0x74, 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x27, 0x2c, 0x64, + 0x65, 0x66, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, + 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, + 0x74, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x6c, 0x69, + 0x6e, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x74, 0x6f, + 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, + 0x27, 0x2c, 0x27, 0x2c, 0x64, 0x65, 0x66, 0x2c, 0x27, 0x29, 0x29, 0x3b, + 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, 0x20, + 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, + 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x64, + 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, 0x20, 0x28, 0x6e, 0x61, 0x72, 0x67, + 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, + 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, 0x5f, + 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, 0x6e, + 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x64, 0x65, + 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x6e, 0x61, + 0x72, 0x67, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, 0x29, 0x0a, 0x09, 0x09, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6c, 0x73, + 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x29, - 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x47, 0x65, 0x74, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, - 0x65, 0x74, 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, - 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x3a, 0x67, 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x28, 0x6e, - 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, - 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, - 0x7b, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, - 0x4c, 0x55, 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, - 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x64, 0x65, 0x66, 0x3b, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x64, 0x65, 0x66, 0x7e, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x20, 0x64, 0x65, 0x66, 0x3d, 0x31, 0x20, 0x65, 0x6c, 0x73, 0x65, - 0x20, 0x64, 0x65, 0x66, 0x3d, 0x30, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x69, - 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, - 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x28, 0x74, 0x29, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x21, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x27, 0x2e, 0x2e, 0x74, - 0x2e, 0x2e, 0x27, 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, - 0x27, 0x2c, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, - 0x2c, 0x27, 0x2c, 0x27, 0x2c, 0x64, 0x65, 0x66, 0x2c, 0x27, 0x2c, 0x26, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x29, 0x27, - 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x20, - 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, - 0x20, 0x69, 0x66, 0x20, 0x28, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x61, 0x72, - 0x72, 0x61, 0x79, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, - 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x22, 0x27, 0x2c, - 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x22, 0x2c, 0x27, 0x2c, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x2c, 0x27, 0x2c, 0x27, 0x2c, 0x64, - 0x65, 0x66, 0x2c, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x65, 0x72, 0x72, 0x29, 0x29, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x20, 0x20, 0x20, 0x20, 0x67, 0x6f, 0x74, 0x6f, 0x20, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3b, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, - 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, - 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, - 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7b, 0x27, 0x29, + 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x62, 0x75, 0x69, 0x6c, 0x64, + 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, + 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x29, 0x29, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x47, 0x65, 0x74, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, + 0x74, 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, + 0x67, 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x28, 0x6e, 0x61, + 0x72, 0x67, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7b, + 0x27, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, + 0x55, 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x64, + 0x65, 0x66, 0x3b, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x64, 0x65, 0x66, 0x7e, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x64, 0x65, 0x66, 0x3d, 0x31, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, + 0x64, 0x65, 0x66, 0x3d, 0x30, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x73, + 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x28, 0x74, 0x29, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x21, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x27, 0x2e, 0x2e, 0x74, 0x2e, + 0x2e, 0x27, 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, + 0x2c, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x2c, + 0x27, 0x2c, 0x27, 0x2c, 0x64, 0x65, 0x66, 0x2c, 0x27, 0x2c, 0x26, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x29, 0x27, 0x29, + 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x20, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x28, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, + 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x61, 0x72, 0x72, + 0x61, 0x79, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, + 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x22, 0x27, 0x2c, 0x74, + 0x79, 0x70, 0x65, 0x2c, 0x27, 0x22, 0x2c, 0x27, 0x2c, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x2c, 0x27, 0x2c, 0x27, 0x2c, 0x64, 0x65, + 0x66, 0x2c, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, + 0x72, 0x72, 0x29, 0x29, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, - 0x20, 0x20, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x69, 0x3b, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x67, 0x6f, 0x74, 0x6f, 0x20, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, - 0x20, 0x20, 0x66, 0x6f, 0x72, 0x28, 0x69, 0x3d, 0x30, 0x3b, 0x20, 0x69, - 0x3c, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, - 0x2e, 0x2e, 0x27, 0x3b, 0x69, 0x2b, 0x2b, 0x29, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x69, - 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, - 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x74, 0x72, - 0x20, 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x7e, 0x3d, 0x27, 0x27, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, - 0x2a, 0x27, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x5b, 0x69, - 0x5d, 0x20, 0x3d, 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, - 0x6e, 0x6f, 0x74, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x74, - 0x72, 0x3d, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x2a, 0x27, 0x29, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x28, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, - 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x74, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x29, 0x20, - 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x64, - 0x65, 0x66, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, 0x7e, 0x3d, 0x20, - 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x64, 0x65, 0x66, 0x20, - 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x66, 0x69, - 0x65, 0x6c, 0x64, 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x2e, 0x27, 0x28, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, - 0x67, 0x2c, 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x27, 0x2c, 0x64, 0x65, - 0x66, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, - 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x66, - 0x69, 0x65, 0x6c, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, - 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, - 0x61, 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x27, 0x2c, - 0x64, 0x65, 0x66, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x20, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7d, 0x27, - 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x47, 0x65, 0x74, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, - 0x65, 0x74, 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, - 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x3a, 0x73, 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x28, 0x6e, - 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, - 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, - 0x74, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, - 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, - 0x75, 0x62, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, - 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x27, - 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x20, 0x20, 0x7b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x69, - 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x72, 0x28, 0x69, 0x3d, 0x30, - 0x3b, 0x20, 0x69, 0x3c, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x64, 0x69, 0x6d, 0x2e, 0x2e, 0x27, 0x3b, 0x69, 0x2b, 0x2b, 0x29, 0x27, - 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, - 0x63, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, - 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, - 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x66, 0x69, 0x65, 0x6c, - 0x64, 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, - 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x28, 0x27, 0x2c, 0x63, 0x74, 0x2c, - 0x27, 0x29, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x2c, 0x27, 0x5b, 0x69, 0x5d, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, - 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, + 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7b, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x20, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x69, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, - 0x7b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, - 0x5f, 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, - 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x76, 0x6f, 0x69, - 0x64, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, - 0x20, 0x3d, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, - 0x77, 0x28, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x29, - 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, - 0x2c, 0x27, 0x5b, 0x69, 0x5d, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, - 0x73, 0x68, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, - 0x79, 0x70, 0x65, 0x5f, 0x61, 0x6e, 0x64, 0x5f, 0x74, 0x61, 0x6b, 0x65, - 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x28, 0x74, 0x6f, + 0x20, 0x66, 0x6f, 0x72, 0x28, 0x69, 0x3d, 0x30, 0x3b, 0x20, 0x69, 0x3c, + 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x2e, + 0x2e, 0x27, 0x3b, 0x69, 0x2b, 0x2b, 0x29, 0x27, 0x29, 0x0a, 0x20, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x73, + 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, + 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x74, 0x72, 0x20, + 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x7e, 0x3d, 0x27, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, 0x2a, + 0x27, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x5b, 0x69, 0x5d, + 0x20, 0x3d, 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x74, 0x72, + 0x3d, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x2a, 0x27, 0x29, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x28, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x74, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x29, 0x20, 0x27, + 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x64, 0x65, + 0x66, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, 0x7e, 0x3d, 0x20, 0x27, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x64, 0x65, 0x66, 0x20, 0x3d, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x65, 0x66, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x66, 0x69, 0x65, + 0x6c, 0x64, 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, - 0x2c, 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x74, 0x6f, 0x6c, 0x75, 0x61, - 0x5f, 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, - 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6c, - 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, - 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x6f, 0x62, 0x6a, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x63, 0x6f, 0x70, 0x79, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, - 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x26, 0x27, 0x2c, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x5b, 0x69, - 0x5d, 0x2c, 0x73, 0x69, 0x7a, 0x65, 0x6f, 0x66, 0x28, 0x27, 0x2c, 0x74, - 0x79, 0x70, 0x65, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, - 0x73, 0x68, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, - 0x79, 0x70, 0x65, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, - 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x69, 0x2b, 0x31, - 0x2c, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x2c, 0x22, - 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, - 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, - 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x20, - 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x66, 0x69, 0x65, 0x6c, 0x64, - 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, - 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, - 0x29, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, - 0x2c, 0x27, 0x5b, 0x69, 0x5d, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x79, 0x70, - 0x65, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7d, 0x27, - 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, 0x64, 0x79, 0x6e, 0x61, - 0x6d, 0x69, 0x63, 0x61, 0x6c, 0x6c, 0x79, 0x20, 0x61, 0x6c, 0x6c, 0x6f, - 0x63, 0x61, 0x74, 0x65, 0x64, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x0a, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, - 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x3a, 0x66, 0x72, 0x65, 0x65, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, - 0x28, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, - 0x64, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x3d, 0x3d, 0x6e, 0x69, - 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, - 0x5f, 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, - 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x20, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x64, - 0x65, 0x6c, 0x65, 0x74, 0x65, 0x5f, 0x64, 0x69, 0x6d, 0x28, 0x27, 0x2c, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x29, - 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x23, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, - 0x66, 0x72, 0x65, 0x65, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, - 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, - 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x50, 0x61, 0x73, - 0x73, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0a, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, - 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x3a, 0x70, 0x61, 0x73, 0x73, 0x70, 0x61, 0x72, 0x20, 0x28, 0x29, - 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, - 0x72, 0x3d, 0x3d, 0x27, 0x26, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, - 0x6f, 0x74, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x2a, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, - 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x72, 0x65, 0x74, 0x3d, 0x3d, 0x27, 0x2a, - 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x26, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, - 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x52, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, + 0x2c, 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x27, 0x2c, 0x64, 0x65, 0x66, + 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x74, 0x6f, 0x66, 0x69, + 0x65, 0x6c, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x28, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, + 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x27, 0x2c, 0x64, + 0x65, 0x66, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7d, 0x27, 0x29, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x47, 0x65, 0x74, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, - 0x72, 0x65, 0x74, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x28, 0x29, 0x0a, - 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x72, 0x65, 0x74, - 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x63, 0x74, - 0x20, 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, - 0x69, 0x66, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x7e, 0x3d, - 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x27, 0x2e, 0x2e, 0x74, - 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, - 0x28, 0x27, 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x27, 0x2e, 0x2e, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x29, - 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, - 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x75, 0x73, 0x68, - 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, - 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, - 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, - 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, - 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x27, 0x2e, 0x2e, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x2c, - 0x22, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, - 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x31, - 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, - 0x6e, 0x20, 0x30, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, - 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, - 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x0a, - 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, - 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, - 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x20, 0x74, - 0x3a, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x28, - 0x29, 0x0a, 0x20, 0x74, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x6e, 0x61, - 0x6d, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x74, 0x3a, 0x63, 0x68, 0x65, 0x63, - 0x6b, 0x74, 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x66, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x6e, 0x64, - 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, - 0x20, 0x6f, 0x72, 0x20, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x20, - 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x69, 0x73, 0x65, 0x6e, 0x75, - 0x6d, 0x28, 0x66, 0x74, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x74, 0x2e, 0x74, 0x79, 0x70, - 0x65, 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, - 0x65, 0x64, 0x65, 0x66, 0x28, 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, - 0x66, 0x74, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x69, - 0x66, 0x20, 0x74, 0x2e, 0x6b, 0x69, 0x6e, 0x64, 0x3d, 0x3d, 0x22, 0x76, - 0x61, 0x72, 0x22, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x28, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x74, 0x2e, 0x6d, - 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, - 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x25, 0x73, 0x22, 0x29, 0x20, - 0x6f, 0x72, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, - 0x6e, 0x64, 0x28, 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, - 0x79, 0x24, 0x22, 0x29, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, - 0x09, 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2e, 0x6d, - 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, - 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x22, 0x2c, 0x20, 0x22, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, - 0x79, 0x5f, 0x5f, 0x22, 0x2e, 0x2e, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, - 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, - 0x29, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, - 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, 0x78, 0x70, 0x65, 0x63, 0x74, - 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x2e, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x68, 0x65, 0x20, 0x6b, 0x69, 0x6e, - 0x64, 0x20, 0x6f, 0x66, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x61, 0x6e, 0x20, 0x62, 0x65, 0x20, - 0x22, 0x76, 0x61, 0x72, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x66, 0x75, - 0x6e, 0x63, 0x22, 0x2e, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x28, 0x73, 0x2c, 0x6b, 0x69, 0x6e, 0x64, 0x2c, 0x69, 0x73, - 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x29, 0x0a, - 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, - 0x74, 0x65, 0x20, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x20, 0x69, 0x66, - 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, - 0x65, 0x64, 0x0a, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, - 0x28, 0x73, 0x2c, 0x22, 0x25, 0x73, 0x2a, 0x3d, 0x25, 0x73, 0x2a, 0x22, - 0x2c, 0x22, 0x3d, 0x22, 0x29, 0x0a, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, - 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x3c, - 0x22, 0x2c, 0x20, 0x22, 0x3c, 0x22, 0x29, 0x0a, 0x0a, 0x20, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x64, 0x65, 0x66, 0x62, 0x2c, 0x74, 0x6d, 0x70, - 0x64, 0x65, 0x66, 0x0a, 0x20, 0x64, 0x65, 0x66, 0x62, 0x2c, 0x5f, 0x2c, - 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, - 0x22, 0x28, 0x3d, 0x2e, 0x2a, 0x29, 0x24, 0x22, 0x29, 0x0a, 0x20, 0x69, - 0x66, 0x20, 0x64, 0x65, 0x66, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x20, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x3d, 0x2e, - 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6c, - 0x73, 0x65, 0x0a, 0x20, 0x09, 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, 0x20, - 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, - 0x66, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x76, - 0x61, 0x72, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x2d, - 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x66, 0x6f, 0x72, 0x6d, 0x3a, 0x20, 0x76, 0x6f, 0x69, 0x64, 0x0a, 0x20, - 0x20, 0x69, 0x66, 0x20, 0x73, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, - 0x6f, 0x72, 0x20, 0x73, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, - 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x74, 0x79, 0x70, 0x65, 0x20, - 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x2c, 0x20, 0x6b, 0x69, - 0x6e, 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x2c, 0x20, 0x69, + 0x73, 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x28, 0x6e, 0x61, + 0x72, 0x67, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x25, 0x73, 0x2b, 0x27, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, + 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x20, 0x7b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x69, 0x3b, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x72, 0x28, 0x69, 0x3d, 0x30, 0x3b, + 0x20, 0x69, 0x3c, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, + 0x69, 0x6d, 0x2e, 0x2e, 0x27, 0x3b, 0x69, 0x2b, 0x2b, 0x29, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x63, + 0x74, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, + 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x66, 0x69, 0x65, 0x6c, 0x64, + 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, + 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x28, 0x27, 0x2c, 0x63, 0x74, 0x2c, 0x27, + 0x29, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x27, 0x5b, 0x69, 0x5d, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7b, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, 0x5f, + 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, 0x6e, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x76, 0x6f, 0x69, 0x64, + 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x20, + 0x3d, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, 0x77, + 0x28, 0x28, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x29, 0x28, + 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x27, 0x5b, 0x69, 0x5d, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, + 0x68, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, + 0x70, 0x65, 0x5f, 0x61, 0x6e, 0x64, 0x5f, 0x74, 0x61, 0x6b, 0x65, 0x6f, + 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x28, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, + 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x2c, + 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6c, 0x73, + 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x76, + 0x6f, 0x69, 0x64, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, + 0x62, 0x6a, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x63, + 0x6f, 0x70, 0x79, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x26, 0x27, 0x2c, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x5b, 0x69, 0x5d, + 0x2c, 0x73, 0x69, 0x7a, 0x65, 0x6f, 0x66, 0x28, 0x27, 0x2c, 0x74, 0x79, + 0x70, 0x65, 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, + 0x68, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, + 0x70, 0x65, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, + 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, 0x2c, 0x69, 0x2b, 0x31, 0x2c, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, + 0x2c, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x75, + 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2c, 0x6e, 0x61, 0x72, 0x67, 0x2c, 0x27, + 0x2c, 0x69, 0x2b, 0x31, 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, + 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x27, 0x5b, 0x69, 0x5d, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7d, 0x27, 0x29, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, 0x64, 0x79, 0x6e, 0x61, 0x6d, + 0x69, 0x63, 0x61, 0x6c, 0x6c, 0x79, 0x20, 0x61, 0x6c, 0x6c, 0x6f, 0x63, + 0x61, 0x74, 0x65, 0x64, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x3a, 0x66, 0x72, 0x65, 0x65, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x28, + 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x64, + 0x69, 0x6d, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x64, 0x69, 0x6d, 0x29, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, 0x5f, + 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, 0x6e, + 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x20, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x64, 0x65, + 0x6c, 0x65, 0x74, 0x65, 0x5f, 0x64, 0x69, 0x6d, 0x28, 0x27, 0x2c, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x29, 0x3b, + 0x27, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x23, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x66, + 0x72, 0x65, 0x65, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, + 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x50, 0x61, 0x73, 0x73, + 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x3a, 0x70, 0x61, 0x73, 0x73, 0x70, 0x61, 0x72, 0x20, 0x28, 0x29, 0x0a, + 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, + 0x3d, 0x3d, 0x27, 0x26, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x2a, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, + 0x65, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x72, 0x65, 0x74, 0x3d, 0x3d, 0x27, 0x2a, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x26, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x52, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, + 0x65, 0x72, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, + 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x72, + 0x65, 0x74, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x28, 0x29, 0x0a, 0x20, + 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x72, 0x65, 0x74, 0x20, + 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x63, 0x74, 0x20, + 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x7e, 0x3d, 0x27, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x27, 0x2e, 0x2e, 0x74, 0x2e, + 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, + 0x27, 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x27, 0x2e, 0x2e, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x29, 0x3b, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x75, 0x73, 0x68, 0x5f, + 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, + 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x20, 0x20, 0x27, 0x2c, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, + 0x63, 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x27, 0x2e, 0x2e, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x2c, 0x22, + 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, + 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x31, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x30, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x49, + 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x0a, 0x20, + 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, + 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x63, 0x6c, + 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x20, 0x74, 0x3a, + 0x62, 0x75, 0x69, 0x6c, 0x64, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x28, 0x29, + 0x0a, 0x20, 0x74, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x6e, 0x61, 0x6d, + 0x65, 0x28, 0x29, 0x0a, 0x20, 0x74, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x74, 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x66, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x74, + 0x79, 0x70, 0x65, 0x28, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, + 0x6f, 0x72, 0x20, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x69, 0x73, 0x65, 0x6e, 0x75, 0x6d, + 0x28, 0x66, 0x74, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x74, + 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, 0x65, + 0x64, 0x65, 0x66, 0x28, 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x66, + 0x74, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x69, 0x66, + 0x20, 0x74, 0x2e, 0x6b, 0x69, 0x6e, 0x64, 0x3d, 0x3d, 0x22, 0x76, 0x61, + 0x72, 0x22, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x28, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x74, 0x2e, 0x6d, 0x6f, + 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x72, + 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x25, 0x73, 0x22, 0x29, 0x20, 0x6f, + 0x72, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, + 0x24, 0x22, 0x29, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, + 0x74, 0x2e, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2e, 0x6d, 0x6f, + 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x72, + 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x22, 0x2c, 0x20, 0x22, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, + 0x5f, 0x5f, 0x22, 0x2e, 0x2e, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x29, + 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, + 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, 0x78, 0x70, 0x65, 0x63, 0x74, 0x73, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, + 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, + 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x68, 0x65, 0x20, 0x6b, 0x69, 0x6e, 0x64, + 0x20, 0x6f, 0x66, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x61, 0x6e, 0x20, 0x62, 0x65, 0x20, 0x22, + 0x76, 0x61, 0x72, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x66, 0x75, 0x6e, + 0x63, 0x22, 0x2e, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x28, 0x73, 0x2c, 0x6b, 0x69, 0x6e, 0x64, 0x2c, 0x69, 0x73, 0x5f, + 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x29, 0x0a, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, + 0x65, 0x20, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x20, 0x69, 0x66, 0x20, + 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x20, 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, + 0x64, 0x0a, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x22, 0x25, 0x73, 0x2a, 0x3d, 0x25, 0x73, 0x2a, 0x22, 0x2c, + 0x22, 0x3d, 0x22, 0x29, 0x0a, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x73, + 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x3c, 0x22, + 0x2c, 0x20, 0x22, 0x3c, 0x22, 0x29, 0x0a, 0x0a, 0x20, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x64, 0x65, 0x66, 0x62, 0x2c, 0x74, 0x6d, 0x70, 0x64, + 0x65, 0x66, 0x0a, 0x20, 0x64, 0x65, 0x66, 0x62, 0x2c, 0x5f, 0x2c, 0x74, + 0x6d, 0x70, 0x64, 0x65, 0x66, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, 0x22, + 0x28, 0x3d, 0x2e, 0x2a, 0x29, 0x24, 0x22, 0x29, 0x0a, 0x20, 0x69, 0x66, + 0x20, 0x64, 0x65, 0x66, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, + 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x20, 0x09, 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, 0x20, 0x3d, + 0x20, 0x27, 0x27, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, + 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x76, 0x61, + 0x72, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x2d, 0x2d, + 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, + 0x6f, 0x72, 0x6d, 0x3a, 0x20, 0x76, 0x6f, 0x69, 0x64, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x73, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x6f, + 0x72, 0x20, 0x73, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, + 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x2c, 0x20, 0x6b, 0x69, 0x6e, + 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x2c, 0x20, 0x69, 0x73, + 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, 0x3d, + 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, + 0x72, 0x7d, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x3a, 0x20, 0x6d, + 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x2a, 0x26, 0x20, 0x6e, 0x61, + 0x6d, 0x65, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, + 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x27, 0x25, 0x2a, 0x25, 0x73, + 0x2a, 0x26, 0x27, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, + 0x20, 0x3d, 0x3d, 0x20, 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, 0x20, + 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, 0x69, + 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x3a, 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, + 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, 0x2a, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, + 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, + 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, + 0x25, 0x73, 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x2e, 0x2e, 0x74, 0x6d, 0x70, + 0x64, 0x65, 0x66, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x70, 0x74, 0x72, 0x20, + 0x3d, 0x20, 0x27, 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, + 0x74, 0x20, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, + 0x2d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x62, + 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, + 0x65, 0x28, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x20, 0x74, 0x62, + 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x2c, 0x0a, 0x20, 0x20, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x6d, 0x5b, 0x6d, 0x2e, + 0x6e, 0x5d, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x3d, + 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x6d, 0x2c, 0x31, 0x2c, + 0x6d, 0x2e, 0x6e, 0x2d, 0x31, 0x29, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, - 0x65, 0x72, 0x7d, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, - 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x3a, 0x20, - 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x2a, 0x26, 0x20, 0x6e, - 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, - 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, - 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x27, 0x25, 0x2a, 0x25, - 0x73, 0x2a, 0x26, 0x27, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, - 0x6e, 0x20, 0x3d, 0x3d, 0x20, 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x20, 0x20, 0x69, 0x66, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, - 0x20, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x20, 0x20, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, - 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x29, 0x0a, - 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, + 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, + 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, 0x0a, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x3a, + 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x2a, 0x2a, 0x20, + 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, + 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, + 0x28, 0x73, 0x2c, 0x27, 0x25, 0x2a, 0x25, 0x73, 0x2a, 0x25, 0x2a, 0x27, + 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x20, 0x3d, 0x3d, + 0x20, 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x69, 0x66, + 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x66, 0x75, + 0x6e, 0x63, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, + 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, 0x69, 0x6e, 0x76, 0x61, + 0x6c, 0x69, 0x64, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, + 0x3a, 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, 0x5b, + 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, 0x20, + 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, + 0x6e, 0x73, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x2b, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, + 0x74, 0x5b, 0x32, 0x5d, 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, + 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, + 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, + 0x20, 0x27, 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, + 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, 0x6d, + 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x20, 0x74, 0x62, 0x2c, 0x20, 0x74, + 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x3d, 0x20, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, + 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x63, 0x6f, + 0x6e, 0x63, 0x61, 0x74, 0x28, 0x6d, 0x2c, 0x31, 0x2c, 0x6d, 0x2e, 0x6e, + 0x2d, 0x31, 0x29, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x73, 0x5f, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, 0x3d, 0x20, 0x69, + 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x2c, + 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x20, 0x6b, + 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x3a, 0x20, 0x6d, 0x6f, + 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x26, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x0a, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, + 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x27, + 0x26, 0x27, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x20, + 0x3d, 0x3d, 0x20, 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, 0x20, + 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, + 0x25, 0x73, 0x25, 0x73, 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, - 0x74, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, - 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, - 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, - 0x27, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, - 0x65, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x2e, 0x2e, 0x74, 0x6d, - 0x70, 0x64, 0x65, 0x66, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x70, 0x74, 0x72, - 0x20, 0x3d, 0x20, 0x27, 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x72, - 0x65, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x2c, 0x0a, 0x20, 0x20, + 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x74, + 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, + 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x0a, 0x20, 0x20, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x32, 0x5d, + 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, 0x2c, 0x0a, 0x20, 0x20, + 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x2c, 0x0a, + 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, + 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, + 0x6c, 0x61, 0x74, 0x65, 0x28, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, + 0x20, 0x74, 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x2c, + 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x6d, + 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x6f, + 0x64, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x6d, + 0x2c, 0x31, 0x2c, 0x6d, 0x2e, 0x6e, 0x2d, 0x31, 0x29, 0x2c, 0x0a, 0x20, + 0x20, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, + 0x65, 0x72, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, + 0x6d, 0x65, 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, + 0x6e, 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x7d, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, + 0x72, 0x6d, 0x3a, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, + 0x2a, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x73, 0x31, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x22, 0x28, 0x25, 0x62, 0x5c, 0x5b, 0x5c, 0x5d, 0x29, 0x22, + 0x2c, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x6e, + 0x29, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x6e, 0x2c, 0x27, 0x25, 0x2a, 0x27, 0x2c, 0x27, 0x5c, 0x31, + 0x27, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x29, 0x0a, 0x20, 0x74, 0x20, 0x3d, + 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x73, 0x28, 0x73, 0x31, 0x2c, 0x27, 0x25, 0x2a, 0x27, 0x29, + 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x20, 0x3d, 0x3d, 0x20, + 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x74, 0x5b, 0x32, + 0x5d, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x32, + 0x5d, 0x2c, 0x27, 0x5c, 0x31, 0x27, 0x2c, 0x27, 0x25, 0x2a, 0x27, 0x29, + 0x20, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x20, + 0x2a, 0x20, 0x69, 0x6e, 0x20, 0x64, 0x69, 0x6d, 0x65, 0x6e, 0x73, 0x69, + 0x6f, 0x6e, 0x20, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, 0x5b, + 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, 0x20, + 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, + 0x6e, 0x73, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x2b, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, + 0x74, 0x5b, 0x32, 0x5d, 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, + 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, + 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x20, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x20, 0x74, 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x2c, 0x0a, 0x20, - 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x6d, 0x5b, 0x6d, - 0x2e, 0x6e, 0x5d, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x20, - 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x6d, 0x2c, 0x31, - 0x2c, 0x6d, 0x2e, 0x6e, 0x2d, 0x31, 0x29, 0x2c, 0x0a, 0x20, 0x20, 0x20, - 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, - 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, - 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, 0x64, - 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, 0x0a, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, - 0x65, 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, - 0x3a, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x2a, 0x2a, - 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, - 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x73, 0x28, 0x73, 0x2c, 0x27, 0x25, 0x2a, 0x25, 0x73, 0x2a, 0x25, 0x2a, - 0x27, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x20, 0x3d, - 0x3d, 0x20, 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x69, - 0x66, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x66, - 0x75, 0x6e, 0x63, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, - 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, 0x69, 0x6e, 0x76, - 0x61, 0x6c, 0x69, 0x64, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x79, 0x70, - 0x65, 0x3a, 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x29, 0x0a, 0x20, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, - 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, - 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, - 0x65, 0x6e, 0x73, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, - 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, - 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, - 0x66, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, - 0x27, 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x20, - 0x3d, 0x20, 0x27, 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x2d, 0x2d, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, - 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, - 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x20, 0x74, 0x62, 0x2c, 0x20, - 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x74, - 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, - 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x63, - 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x6d, 0x2c, 0x31, 0x2c, 0x6d, 0x2e, - 0x6e, 0x2d, 0x31, 0x29, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x73, 0x5f, + 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, + 0x61, 0x74, 0x28, 0x6d, 0x2c, 0x31, 0x2c, 0x6d, 0x2e, 0x6e, 0x2d, 0x31, + 0x29, 0x20, 0x20, 0x20, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, 0x0a, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x64, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x76, 0x61, 0x72, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x3a, 0x20, 0x6d, - 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x26, 0x20, 0x6e, 0x61, 0x6d, - 0x65, 0x0a, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, - 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, - 0x27, 0x26, 0x27, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, - 0x20, 0x3d, 0x3d, 0x20, 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, - 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, - 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, - 0x27, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, - 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, - 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, - 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x0a, 0x20, - 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x32, - 0x5d, 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, 0x2c, 0x0a, 0x20, - 0x20, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x2c, - 0x0a, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, - 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, - 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, - 0x2c, 0x20, 0x74, 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, - 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, - 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, - 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, - 0x6d, 0x2c, 0x31, 0x2c, 0x6d, 0x2e, 0x6e, 0x2d, 0x31, 0x29, 0x2c, 0x0a, - 0x20, 0x20, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, - 0x74, 0x65, 0x72, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, - 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, - 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, - 0x20, 0x7d, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, - 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, - 0x6f, 0x72, 0x6d, 0x3a, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, - 0x65, 0x2a, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x73, 0x31, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, - 0x28, 0x73, 0x2c, 0x22, 0x28, 0x25, 0x62, 0x5c, 0x5b, 0x5c, 0x5d, 0x29, - 0x22, 0x2c, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, - 0x6e, 0x29, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x67, 0x73, - 0x75, 0x62, 0x28, 0x6e, 0x2c, 0x27, 0x25, 0x2a, 0x27, 0x2c, 0x27, 0x5c, - 0x31, 0x27, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x29, 0x0a, 0x20, 0x74, 0x20, - 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, - 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x31, 0x2c, 0x27, 0x25, 0x2a, 0x27, - 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x20, 0x3d, 0x3d, - 0x20, 0x32, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x74, 0x5b, - 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, - 0x32, 0x5d, 0x2c, 0x27, 0x5c, 0x31, 0x27, 0x2c, 0x27, 0x25, 0x2a, 0x27, - 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x65, - 0x20, 0x2a, 0x20, 0x69, 0x6e, 0x20, 0x64, 0x69, 0x6d, 0x65, 0x6e, 0x73, - 0x69, 0x6f, 0x6e, 0x20, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, - 0x6f, 0x6e, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x6d, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, - 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x27, 0x29, - 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x20, 0x3d, - 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, - 0x65, 0x6e, 0x73, 0x28, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x27, 0x25, 0x73, - 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, - 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, - 0x66, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, - 0x27, 0x2a, 0x27, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, - 0x20, 0x3d, 0x20, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x0a, 0x20, + 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, + 0x69, 0x74, 0x28, 0x73, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x27, + 0x29, 0x0a, 0x20, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, + 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, + 0x2c, 0x27, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x76, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x66, + 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x5b, 0x74, 0x2e, + 0x6e, 0x5d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x76, 0x20, 0x3d, + 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x76, 0x61, 0x72, 0x6e, + 0x61, 0x6d, 0x65, 0x28, 0x29, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x76, + 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x74, 0x2e, 0x6e, 0x5d, 0x3b, 0x20, 0x74, + 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x74, 0x2e, 0x6e, 0x2d, 0x31, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, + 0x76, 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, - 0x61, 0x74, 0x65, 0x28, 0x6d, 0x5b, 0x6d, 0x2e, 0x6e, 0x5d, 0x2c, 0x20, + 0x61, 0x74, 0x65, 0x28, 0x74, 0x5b, 0x74, 0x2e, 0x6e, 0x5d, 0x2c, 0x20, 0x74, 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x2c, 0x0a, - 0x20, 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, - 0x63, 0x61, 0x74, 0x28, 0x6d, 0x2c, 0x31, 0x2c, 0x6d, 0x2e, 0x6e, 0x2d, - 0x31, 0x29, 0x20, 0x20, 0x20, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x73, - 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, 0x3d, + 0x20, 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x5b, + 0x74, 0x2e, 0x6e, 0x5d, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x6f, 0x64, + 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x74, 0x2c, + 0x31, 0x2c, 0x74, 0x2e, 0x6e, 0x2d, 0x31, 0x29, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, - 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, - 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, 0x0a, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6b, 0x69, 0x6e, 0x64, - 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x76, 0x61, 0x72, 0x27, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, + 0x72, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, + 0x65, 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, + 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, + 0x0a, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x2d, 0x2d, 0x20, 0x6b, + 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x66, 0x75, 0x6e, 0x63, + 0x22, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x3a, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, @@ -1201,64 +1235,31 @@ static const unsigned char lua_declaration_lua[] = { 0x27, 0x29, 0x0a, 0x20, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x27, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, - 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x5b, 0x74, - 0x2e, 0x6e, 0x5d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x76, 0x20, - 0x3d, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x76, 0x61, 0x72, - 0x6e, 0x61, 0x6d, 0x65, 0x28, 0x29, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, - 0x76, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x74, 0x2e, 0x6e, 0x5d, 0x3b, 0x20, - 0x74, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x74, 0x2e, 0x6e, 0x2d, 0x31, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, - 0x20, 0x76, 0x2e, 0x2e, 0x74, 0x6d, 0x70, 0x64, 0x65, 0x66, 0x2c, 0x0a, - 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, - 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, - 0x6c, 0x61, 0x74, 0x65, 0x28, 0x74, 0x5b, 0x74, 0x2e, 0x6e, 0x5d, 0x2c, - 0x20, 0x74, 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, 0x29, 0x2c, - 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, - 0x5b, 0x74, 0x2e, 0x6e, 0x5d, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x6f, - 0x64, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x74, - 0x2c, 0x31, 0x2c, 0x74, 0x2e, 0x6e, 0x2d, 0x31, 0x29, 0x2c, 0x0a, 0x20, - 0x20, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, - 0x65, 0x72, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, - 0x6d, 0x65, 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, - 0x6e, 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, - 0x7d, 0x0a, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x2d, 0x2d, 0x20, - 0x6b, 0x69, 0x6e, 0x64, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x66, 0x75, 0x6e, - 0x63, 0x22, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, - 0x63, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x3a, - 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6e, 0x61, - 0x6d, 0x65, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x74, 0x20, 0x3d, 0x20, 0x73, - 0x70, 0x6c, 0x69, 0x74, 0x28, 0x73, 0x2c, 0x27, 0x25, 0x73, 0x25, 0x73, - 0x2a, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, - 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, - 0x28, 0x73, 0x2c, 0x27, 0x25, 0x73, 0x2b, 0x27, 0x29, 0x0a, 0x20, 0x20, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x20, 0x3d, 0x20, 0x74, 0x5b, - 0x74, 0x2e, 0x6e, 0x5d, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x6c, 0x61, 0x73, - 0x74, 0x20, 0x77, 0x6f, 0x72, 0x64, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, - 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, - 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x74, 0x70, 0x2c, 0x6d, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, - 0x2e, 0x6e, 0x3e, 0x31, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, - 0x20, 0x74, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x74, 0x2e, 0x6e, 0x2d, - 0x31, 0x5d, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x64, 0x20, 0x3d, 0x20, 0x63, - 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x74, 0x2c, 0x31, 0x2c, 0x74, 0x2e, - 0x6e, 0x2d, 0x32, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, - 0x20, 0x2d, 0x2d, 0x69, 0x66, 0x20, 0x74, 0x70, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x20, 0x74, 0x70, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, - 0x6c, 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, - 0x74, 0x70, 0x2c, 0x20, 0x74, 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, - 0x6c, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, - 0x65, 0x20, 0x3d, 0x20, 0x76, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, - 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x70, 0x2c, 0x0a, 0x20, 0x20, 0x20, - 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x6d, 0x64, 0x2c, 0x0a, 0x20, 0x20, - 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, - 0x72, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, - 0x65, 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, - 0x64, 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, - 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x74, + 0x2e, 0x6e, 0x5d, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x6c, 0x61, 0x73, 0x74, + 0x20, 0x77, 0x6f, 0x72, 0x64, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, + 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x61, + 0x6d, 0x65, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, + 0x70, 0x2c, 0x6d, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, + 0x6e, 0x3e, 0x31, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, + 0x74, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x74, 0x2e, 0x6e, 0x2d, 0x31, + 0x5d, 0x0a, 0x20, 0x20, 0x20, 0x6d, 0x64, 0x20, 0x3d, 0x20, 0x63, 0x6f, + 0x6e, 0x63, 0x61, 0x74, 0x28, 0x74, 0x2c, 0x31, 0x2c, 0x74, 0x2e, 0x6e, + 0x2d, 0x32, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x2d, 0x2d, 0x69, 0x66, 0x20, 0x74, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x74, 0x70, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, + 0x64, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, 0x74, + 0x70, 0x2c, 0x20, 0x74, 0x62, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x70, 0x6c, + 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x5f, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x3d, 0x20, 0x76, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x74, 0x70, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6d, + 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x6d, 0x64, 0x2c, 0x0a, 0x20, 0x20, 0x20, + 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, + 0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, + 0x74, 0x65, 0x72, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x6b, 0x69, 0x6e, 0x64, + 0x20, 0x3d, 0x20, 0x6b, 0x69, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x7d, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a }; -unsigned int lua_declaration_lua_len = 15132; +unsigned int lua_declaration_lua_len = 15143; diff --git a/lib/tolua++/src/bin/enumerate_lua.h b/lib/tolua++/src/bin/enumerate_lua.h index cd5bdda83..d23c9624a 100644 --- a/lib/tolua++/src/bin/enumerate_lua.h +++ b/lib/tolua++/src/bin/enumerate_lua.h @@ -112,186 +112,184 @@ static const unsigned char lua_enumerate_lua[] = { 0x74, 0x79, 0x70, 0x65, 0x2c, 0x22, 0x3a, 0x3a, 0x22, 0x2c, 0x22, 0x5f, 0x22, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x20, 0x4c, 0x2c, 0x20, 0x69, - 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, - 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, 0x2a, 0x20, 0x74, 0x79, 0x70, 0x65, - 0x2c, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x2a, 0x20, - 0x65, 0x72, 0x72, 0x29, 0x3b, 0x22, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, - 0x0a, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x3d, 0x20, - 0x7b, 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x63, 0x6f, 0x64, - 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, - 0x6c, 0x61, 0x73, 0x73, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, - 0x65, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x28, 0x29, - 0x0a, 0x09, 0x69, 0x66, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, - 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, 0x6d, - 0x73, 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x5d, - 0x20, 0x3d, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x09, 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x3d, - 0x20, 0x31, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x22, 0x69, 0x6e, 0x74, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, - 0x73, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, - 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x3a, 0x3a, 0x22, 0x2c, 0x22, 0x5f, 0x22, - 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x28, 0x6c, 0x75, 0x61, 0x5f, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x20, 0x4c, 0x2c, 0x20, 0x69, 0x6e, - 0x74, 0x20, 0x6c, 0x6f, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, - 0x63, 0x68, 0x61, 0x72, 0x20, 0x2a, 0x20, 0x74, 0x79, 0x70, 0x65, 0x2c, - 0x20, 0x69, 0x6e, 0x74, 0x20, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x2a, 0x20, 0x65, - 0x72, 0x72, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x22, 0x7b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x69, 0x66, 0x20, 0x28, 0x21, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x6e, 0x75, 0x6d, 0x62, 0x65, - 0x72, 0x28, 0x4c, 0x2c, 0x6c, 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x2c, 0x65, - 0x72, 0x72, 0x29, 0x29, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x30, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x22, 0x6c, 0x75, 0x61, 0x5f, 0x4e, 0x75, 0x6d, 0x62, 0x65, - 0x72, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x4c, - 0x2c, 0x6c, 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x29, 0x3b, 0x22, 0x29, 0x0a, - 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3e, 0x3d, 0x20, - 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x69, - 0x6e, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2e, 0x30, 0x20, 0x26, 0x26, 0x20, - 0x76, 0x61, 0x6c, 0x20, 0x3c, 0x3d, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x2e, 0x2e, 0x20, 0x22, - 0x2e, 0x30, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x22, 0x7d, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, - 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x49, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, - 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x20, 0x5f, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, - 0x65, 0x20, 0x28, 0x74, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, - 0x29, 0x0a, 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, - 0x62, 0x6c, 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x45, - 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x29, 0x0a, 0x20, 0x61, - 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x61, 0x70, - 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x75, 0x6d, 0x28, 0x74, 0x29, 0x0a, - 0x09, 0x20, 0x69, 0x66, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, - 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, - 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x09, 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, - 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, - 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x65, - 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x63, 0x75, 0x72, - 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x29, - 0x0a, 0x09, 0x09, 0x09, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x28, - 0x22, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x22, 0x2e, - 0x2e, 0x6e, 0x73, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, - 0x2e, 0x2e, 0x22, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, - 0x3c, 0x61, 0x6e, 0x6f, 0x6e, 0x79, 0x6d, 0x6f, 0x75, 0x73, 0x20, 0x65, - 0x6e, 0x75, 0x6d, 0x3e, 0x20, 0x69, 0x73, 0x20, 0x64, 0x65, 0x63, 0x6c, - 0x61, 0x72, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20, 0x72, 0x65, 0x61, 0x64, - 0x2d, 0x6f, 0x6e, 0x6c, 0x79, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x56, - 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x22, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x6f, 0x6e, 0x6c, 0x79, 0x20, - 0x69, 0x6e, 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, - 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, - 0x61, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, - 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, - 0x75, 0x72, 0x72, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x70, 0x61, 0x72, - 0x65, 0x6e, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x74, - 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x70, 0x61, - 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x6d, 0x65, - 0x6d, 0x62, 0x65, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x0a, - 0x09, 0x09, 0x74, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x61, - 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x74, 0x3a, 0x63, 0x68, - 0x65, 0x63, 0x6b, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, - 0x63, 0x63, 0x65, 0x73, 0x73, 0x28, 0x29, 0x0a, 0x09, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, - 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, - 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, - 0x78, 0x70, 0x65, 0x63, 0x74, 0x73, 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, - 0x74, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x65, 0x6e, 0x75, - 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x0a, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x45, 0x6e, 0x75, - 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x28, 0x6e, 0x2c, 0x62, 0x2c, - 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x62, 0x20, - 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, - 0x62, 0x28, 0x62, 0x2c, 0x20, 0x22, 0x2c, 0x5b, 0x25, 0x73, 0x5c, 0x6e, - 0x5d, 0x2a, 0x7d, 0x22, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x7d, 0x22, 0x29, - 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, - 0x65, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x0a, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, - 0x6c, 0x69, 0x74, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x62, - 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x27, 0x2c, 0x27, 0x29, 0x20, - 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, - 0x20, 0x62, 0x72, 0x61, 0x63, 0x65, 0x73, 0x0a, 0x09, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, - 0x7d, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x30, - 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, 0x69, 0x5d, - 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x74, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, - 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x3d, 0x27, 0x29, 0x20, 0x20, 0x2d, 0x2d, - 0x20, 0x64, 0x69, 0x73, 0x63, 0x61, 0x72, 0x64, 0x20, 0x69, 0x6e, 0x69, - 0x74, 0x69, 0x61, 0x6c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x09, - 0x09, 0x65, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x65, 0x2e, 0x6e, 0x20, 0x2b, - 0x20, 0x31, 0x0a, 0x09, 0x09, 0x65, 0x5b, 0x65, 0x2e, 0x6e, 0x5d, 0x20, - 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x74, 0x74, - 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, - 0x65, 0x72, 0x28, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x29, 0x0a, 0x09, 0x09, - 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x3d, 0x20, - 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, - 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x20, 0x0a, 0x20, 0x20, 0x09, - 0x09, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, - 0x32, 0x5d, 0x20, 0x2b, 0x20, 0x31, 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x64, - 0x76, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65, - 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, - 0x3e, 0x20, 0x6d, 0x61, 0x78, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x09, 0x09, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, - 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, - 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3c, 0x20, 0x6d, 0x69, 0x6e, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x69, 0x6e, - 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x0a, 0x09, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, - 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x73, 0x65, - 0x74, 0x20, 0x6c, 0x75, 0x61, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x0a, - 0x09, 0x69, 0x20, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x65, 0x2e, 0x6c, - 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x67, - 0x65, 0x74, 0x63, 0x75, 0x72, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, - 0x61, 0x63, 0x65, 0x28, 0x29, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, - 0x20, 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, - 0x69, 0x74, 0x28, 0x65, 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x40, 0x27, 0x29, - 0x0a, 0x09, 0x09, 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x5b, - 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, - 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, - 0x09, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, - 0x79, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x28, 0x74, 0x5b, - 0x31, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, - 0x65, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x20, - 0x3d, 0x20, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x5b, - 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, - 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x20, 0x6e, 0x73, 0x2e, 0x2e, - 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x5d, 0x20, 0x3d, 0x20, 0x28, 0x6e, 0x73, - 0x2e, 0x2e, 0x65, 0x5b, 0x69, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x20, - 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, - 0x65, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x6e, 0x0a, 0x09, - 0x65, 0x2e, 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x6d, 0x69, 0x6e, 0x0a, - 0x09, 0x65, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x6d, 0x61, 0x78, - 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x5f, 0x65, 0x6e, 0x75, - 0x6d, 0x73, 0x5b, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x09, - 0x54, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, 0x22, 0x69, 0x6e, 0x74, - 0x20, 0x22, 0x2e, 0x2e, 0x6e, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x45, 0x6e, 0x75, - 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, 0x65, 0x2c, 0x20, 0x76, 0x61, - 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a + 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x2c, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x64, + 0x65, 0x66, 0x2c, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x45, 0x72, + 0x72, 0x6f, 0x72, 0x2a, 0x20, 0x65, 0x72, 0x72, 0x29, 0x3b, 0x22, 0x29, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, + 0x6c, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, + 0x77, 0x72, 0x69, 0x74, 0x65, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, + 0x74, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x45, 0x6e, 0x75, + 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, + 0x64, 0x65, 0x20, 0x28, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x5f, 0x67, + 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x3d, 0x3d, 0x20, 0x6e, 0x69, 0x6c, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x5f, 0x67, 0x6c, 0x6f, + 0x62, 0x61, 0x6c, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, + 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x69, 0x6e, 0x74, 0x20, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x3a, 0x3a, + 0x22, 0x2c, 0x22, 0x5f, 0x22, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, + 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x20, + 0x4c, 0x2c, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x2c, 0x20, 0x69, + 0x6e, 0x74, 0x20, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x2a, 0x20, 0x65, 0x72, 0x72, + 0x29, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x22, 0x7b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x22, 0x69, 0x66, 0x20, 0x28, 0x21, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x69, 0x73, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, + 0x4c, 0x2c, 0x6c, 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x2c, 0x65, 0x72, 0x72, + 0x29, 0x29, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x30, 0x3b, + 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x22, 0x6c, 0x75, 0x61, 0x5f, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, + 0x76, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x4c, 0x2c, 0x6c, + 0x6f, 0x2c, 0x64, 0x65, 0x66, 0x29, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x20, 0x3e, 0x3d, 0x20, 0x22, 0x20, + 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x69, 0x6e, 0x20, + 0x2e, 0x2e, 0x20, 0x22, 0x2e, 0x30, 0x20, 0x26, 0x26, 0x20, 0x76, 0x61, + 0x6c, 0x20, 0x3c, 0x3d, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2e, 0x30, + 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x22, 0x7d, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, + 0x6e, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, + 0x74, 0x6f, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x5f, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, + 0x28, 0x74, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, + 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, + 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x45, 0x6e, 0x75, + 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x29, 0x0a, 0x20, 0x61, 0x70, 0x70, + 0x65, 0x6e, 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x61, 0x70, 0x70, 0x65, + 0x6e, 0x64, 0x65, 0x6e, 0x75, 0x6d, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x20, + 0x69, 0x66, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, + 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x69, 0x66, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, 0x3d, + 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, + 0x73, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x63, 0x75, 0x72, 0x72, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x29, 0x0a, 0x09, + 0x09, 0x09, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x28, 0x22, 0x56, + 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x22, 0x2e, 0x2e, 0x6e, + 0x73, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, + 0x22, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3c, 0x61, + 0x6e, 0x6f, 0x6e, 0x79, 0x6d, 0x6f, 0x75, 0x73, 0x20, 0x65, 0x6e, 0x75, + 0x6d, 0x3e, 0x20, 0x69, 0x73, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, + 0x65, 0x64, 0x20, 0x61, 0x73, 0x20, 0x72, 0x65, 0x61, 0x64, 0x2d, 0x6f, + 0x6e, 0x6c, 0x79, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x56, 0x61, 0x72, + 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x72, 0x65, 0x61, 0x64, 0x6f, 0x6e, 0x6c, 0x79, 0x20, 0x69, 0x6e, + 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, + 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x09, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, + 0x72, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6e, + 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x74, 0x2e, 0x61, + 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x6d, 0x65, 0x6d, 0x62, + 0x65, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x0a, 0x09, 0x09, + 0x74, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, + 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x74, 0x3a, 0x63, 0x68, 0x65, 0x63, + 0x6b, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, 0x63, + 0x65, 0x73, 0x73, 0x28, 0x29, 0x0a, 0x09, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x72, + 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, 0x78, 0x70, + 0x65, 0x63, 0x74, 0x73, 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, + 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x65, + 0x72, 0x61, 0x74, 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x45, 0x6e, 0x75, 0x6d, 0x65, + 0x72, 0x61, 0x74, 0x65, 0x20, 0x28, 0x6e, 0x2c, 0x62, 0x2c, 0x76, 0x61, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x62, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, + 0x62, 0x2c, 0x20, 0x22, 0x2c, 0x5b, 0x25, 0x73, 0x5c, 0x6e, 0x5d, 0x2a, + 0x7d, 0x22, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x7d, 0x22, 0x29, 0x20, 0x2d, + 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x20, + 0x6c, 0x61, 0x73, 0x74, 0x20, 0x27, 0x2c, 0x27, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, + 0x74, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x62, 0x2c, 0x32, + 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x27, 0x2c, 0x27, 0x29, 0x20, 0x2d, 0x2d, + 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x62, + 0x72, 0x61, 0x63, 0x65, 0x73, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x69, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, 0x7d, 0x0a, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x30, 0x0a, 0x09, + 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x64, + 0x6f, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x74, + 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x74, 0x5b, 0x69, + 0x5d, 0x2c, 0x27, 0x3d, 0x27, 0x29, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x64, + 0x69, 0x73, 0x63, 0x61, 0x72, 0x64, 0x20, 0x69, 0x6e, 0x69, 0x74, 0x69, + 0x61, 0x6c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x09, 0x09, 0x65, + 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x65, 0x2e, 0x6e, 0x20, 0x2b, 0x20, 0x31, + 0x0a, 0x09, 0x09, 0x65, 0x5b, 0x65, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, + 0x74, 0x74, 0x5b, 0x31, 0x5d, 0x0a, 0x09, 0x09, 0x74, 0x74, 0x5b, 0x32, + 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x28, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, + 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x3d, 0x20, 0x6e, 0x69, + 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x74, + 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x20, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, + 0x20, 0x2b, 0x20, 0x31, 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x64, 0x76, 0x61, + 0x6e, 0x63, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x65, + 0x63, 0x74, 0x65, 0x64, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x09, + 0x09, 0x69, 0x66, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3e, 0x20, + 0x6d, 0x61, 0x78, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, + 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x3c, 0x20, 0x6d, 0x69, 0x6e, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x69, 0x6e, 0x20, 0x3d, + 0x20, 0x74, 0x74, 0x5b, 0x32, 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x73, 0x65, 0x74, 0x20, + 0x6c, 0x75, 0x61, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x0a, 0x09, 0x69, + 0x20, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x65, 0x2e, 0x6c, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, + 0x63, 0x75, 0x72, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, + 0x65, 0x28, 0x29, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x65, + 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, + 0x28, 0x65, 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x40, 0x27, 0x29, 0x0a, 0x09, + 0x09, 0x65, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x5b, 0x31, 0x5d, + 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x74, 0x5b, + 0x32, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x74, + 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x72, + 0x65, 0x6e, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x28, 0x74, 0x5b, 0x31, 0x5d, + 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x2e, + 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, + 0x74, 0x5b, 0x32, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x5b, 0x31, 0x5d, + 0x0a, 0x09, 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x65, + 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x20, 0x6e, 0x73, 0x2e, 0x2e, 0x65, 0x5b, + 0x69, 0x5d, 0x20, 0x5d, 0x20, 0x3d, 0x20, 0x28, 0x6e, 0x73, 0x2e, 0x2e, + 0x65, 0x5b, 0x69, 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, + 0x69, 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x6e, 0x0a, 0x09, 0x65, 0x2e, + 0x6d, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x6d, 0x69, 0x6e, 0x0a, 0x09, 0x65, + 0x2e, 0x6d, 0x61, 0x78, 0x20, 0x3d, 0x20, 0x6d, 0x61, 0x78, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x6e, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, + 0x5b, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, + 0x09, 0x54, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, 0x22, 0x69, 0x6e, + 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x6e, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x45, 0x6e, + 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, 0x65, 0x2c, 0x20, 0x76, + 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a }; -unsigned int lua_enumerate_lua_len = 3528; +unsigned int lua_enumerate_lua_len = 3493; diff --git a/lib/tolua++/src/bin/function_lua.h b/lib/tolua++/src/bin/function_lua.h index 544a6f8a8..bcb0bfca2 100644 --- a/lib/tolua++/src/bin/function_lua.h +++ b/lib/tolua++/src/bin/function_lua.h @@ -130,1081 +130,1081 @@ static const unsigned char lua_function_lua[] = { 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x69, 0x73, 0x65, 0x6e, - 0x75, 0x6d, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, - 0x5b, 0x69, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6d, 0x69, 0x74, - 0x65, 0x6e, 0x75, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x74, 0x79, 0x70, - 0x65, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, - 0x69, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, - 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, - 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x66, 0x6c, - 0x61, 0x67, 0x73, 0x2e, 0x70, 0x75, 0x72, 0x65, 0x5f, 0x76, 0x69, 0x72, - 0x74, 0x75, 0x61, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, - 0x09, 0x2d, 0x2d, 0x20, 0x6e, 0x6f, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, - 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x63, - 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, - 0x70, 0x75, 0x72, 0x65, 0x20, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, - 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x0a, 0x20, 0x09, 0x09, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, 0x09, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, - 0x64, 0x3a, 0x20, 0x6e, 0x65, 0x77, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x6f, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x22, 0x2c, - 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2c, 0x22, 0x20, 0x2a, 0x2f, 0x22, 0x29, - 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x6d, 0x65, 0x74, 0x68, - 0x6f, 0x64, 0x3a, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, - 0x6d, 0x65, 0x2c, 0x22, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x75, 0x6d, 0x74, 0x79, 0x70, 0x65, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x65, 0x6d, 0x69, 0x74, 0x65, 0x6e, 0x75, 0x6d, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, + 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, + 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x20, 0x09, + 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, + 0x74, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x2e, 0x70, 0x75, 0x72, 0x65, + 0x5f, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x6e, 0x6f, 0x20, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x66, + 0x6f, 0x72, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x20, 0x77, + 0x69, 0x74, 0x68, 0x20, 0x70, 0x75, 0x72, 0x65, 0x20, 0x76, 0x69, 0x72, + 0x74, 0x75, 0x61, 0x6c, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, + 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, + 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x6d, + 0x65, 0x74, 0x68, 0x6f, 0x64, 0x3a, 0x20, 0x6e, 0x65, 0x77, 0x5f, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x22, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2c, 0x22, 0x20, - 0x2a, 0x2f, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, - 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x3a, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x2c, 0x22, 0x20, 0x2a, 0x2f, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x22, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, - 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, - 0x45, 0x5f, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, - 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x22, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x22, 0x5c, 0x6e, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x69, 0x6e, - 0x74, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, - 0x65, 0x2e, 0x2e, 0x22, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x2c, - 0x22, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, - 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x22, 0x29, 0x0a, - 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x22, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, - 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, - 0x45, 0x5f, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, - 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x22, 0x5c, 0x6e, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, - 0x69, 0x6e, 0x74, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, - 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, + 0x2a, 0x2f, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, + 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x3a, 0x22, 0x2c, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x20, 0x6f, 0x66, 0x20, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x22, 0x2c, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x2c, 0x22, 0x20, 0x2a, 0x2f, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x2f, 0x2a, 0x20, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x20, 0x2a, 0x2f, 0x22, 0x29, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, + 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x23, 0x69, 0x66, 0x6e, + 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, + 0x53, 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x5f, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x22, 0x5c, 0x6e, 0x73, 0x74, 0x61, 0x74, 0x69, + 0x63, 0x20, 0x69, 0x6e, 0x74, 0x22, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x5f, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x22, 0x2c, 0x22, 0x28, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, - 0x29, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x7b, 0x22, 0x29, 0x0a, 0x0a, 0x20, - 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x74, 0x79, 0x70, - 0x65, 0x73, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, - 0x6f, 0x61, 0x64, 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, - 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, - 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, 0x27, 0x29, - 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x45, 0x72, - 0x72, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, - 0x72, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x20, 0x69, 0x66, 0x20, 0x28, 0x5c, 0x6e, 0x27, 0x29, 0x0a, - 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x73, 0x65, - 0x6c, 0x66, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, - 0x72, 0x67, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, - 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, - 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, - 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, - 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, - 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, - 0x77, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, - 0x7e, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x09, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x27, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x75, 0x73, 0x65, 0x72, 0x74, 0x61, - 0x62, 0x6c, 0x65, 0x27, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x79, 0x70, 0x65, - 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, - 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x74, 0x79, 0x70, 0x65, - 0x20, 0x3d, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x22, 0x2e, - 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x21, 0x27, 0x2e, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x2e, - 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x31, - 0x2c, 0x22, 0x27, 0x2e, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, - 0x22, 0x2c, 0x30, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, - 0x72, 0x72, 0x29, 0x20, 0x7c, 0x7c, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, - 0x6b, 0x20, 0x61, 0x72, 0x67, 0x73, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, - 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, - 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, - 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, - 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x74, 0x79, - 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x74, - 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x62, 0x74, 0x79, 0x70, 0x65, - 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x20, 0x27, 0x2e, - 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, - 0x5d, 0x3a, 0x6f, 0x75, 0x74, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x74, 0x79, - 0x70, 0x65, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x2e, 0x2e, 0x27, 0x20, - 0x7c, 0x7c, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x74, 0x79, 0x70, - 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x6e, 0x61, - 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, 0x0a, - 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, - 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, - 0x63, 0x6b, 0x20, 0x65, 0x6e, 0x64, 0x20, 0x6f, 0x66, 0x20, 0x6c, 0x69, - 0x73, 0x74, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x21, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x69, 0x73, 0x6e, 0x6f, 0x6f, 0x62, 0x6a, 0x28, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, 0x61, 0x72, 0x67, 0x2e, - 0x2e, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, - 0x72, 0x29, 0x5c, 0x6e, 0x20, 0x29, 0x27, 0x29, 0x0a, 0x09, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x67, 0x6f, 0x74, 0x6f, - 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, - 0x72, 0x3b, 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x27, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, - 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, - 0x64, 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, - 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, - 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x7b, - 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x63, 0x6c, - 0x61, 0x72, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2c, 0x20, 0x69, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x73, 0x65, 0x0a, 0x20, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x0a, 0x20, 0x69, - 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, 0x73, 0x65, - 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, - 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x7e, - 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, - 0x74, 0x61, 0x74, 0x69, 0x63, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6f, - 0x6e, 0x73, 0x74, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, - 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x2a, 0x27, - 0x2c, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x20, 0x3d, 0x20, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x28, 0x27, - 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x2c, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, - 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x2a, 0x29, 0x20, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x5f, 0x66, - 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x74, 0x6f, - 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, - 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x31, 0x2c, 0x30, 0x29, 0x3b, - 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, - 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, - 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, - 0x64, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x27, 0x5e, 0x25, - 0x73, 0x2a, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x25, 0x73, 0x25, 0x73, - 0x2a, 0x28, 0x2e, 0x2a, 0x29, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, - 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x0a, - 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, - 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, - 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, - 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, - 0x0a, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, - 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, - 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, - 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x74, 0x79, - 0x70, 0x65, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x73, 0x74, 0x61, 0x74, - 0x65, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x20, - 0x6e, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, - 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, - 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, - 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, 0x20, - 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, - 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x7e, 0x3d, - 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, - 0x61, 0x74, 0x69, 0x63, 0x3d, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, - 0x55, 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, - 0x27, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x21, 0x73, 0x65, 0x6c, 0x66, - 0x29, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x6f, - 0x72, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x27, - 0x2e, 0x2e, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x72, 0x72, - 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x22, 0x69, 0x6e, 0x76, - 0x61, 0x6c, 0x69, 0x64, 0x20, 0x5c, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x5c, - 0x27, 0x20, 0x69, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x5c, 0x27, 0x25, 0x73, 0x5c, 0x27, 0x22, 0x2c, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x2e, 0x2e, 0x27, - 0x22, 0x2c, 0x20, 0x4e, 0x55, 0x4c, 0x4c, 0x29, 0x3b, 0x27, 0x29, 0x3b, - 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, - 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x20, - 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, - 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x0a, 0x20, 0x69, 0x66, - 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, - 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, - 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x29, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x23, 0x69, 0x66, 0x6e, + 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, + 0x53, 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x5c, 0x6e, 0x73, 0x74, 0x61, + 0x74, 0x69, 0x63, 0x20, 0x69, 0x6e, 0x74, 0x22, 0x2c, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x22, 0x28, 0x6c, 0x75, + 0x61, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2a, 0x20, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x53, 0x29, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x22, 0x7b, 0x22, + 0x29, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x73, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, + 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x3c, 0x20, 0x30, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, + 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, + 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x65, 0x72, 0x72, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x69, 0x66, 0x20, 0x28, 0x5c, + 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, + 0x6b, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6e, 0x61, + 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x6e, 0x61, + 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, + 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x73, 0x5f, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x69, + 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, + 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x74, + 0x61, 0x74, 0x69, 0x63, 0x7e, 0x3d, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, + 0x20, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x75, 0x73, + 0x65, 0x72, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x27, 0x0a, 0x09, 0x09, 0x09, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, + 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x20, 0x22, 0x2e, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x20, 0x21, 0x27, 0x2e, 0x2e, 0x66, + 0x75, 0x6e, 0x63, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x53, 0x2c, 0x31, 0x2c, 0x22, 0x27, 0x2e, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x2e, 0x2e, 0x27, 0x22, 0x2c, 0x30, 0x2c, 0x26, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x20, 0x7c, 0x7c, 0x5c, 0x6e, + 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x61, 0x72, 0x67, 0x73, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, - 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, - 0x5b, 0x69, 0x5d, 0x3a, 0x67, 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, - 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x61, - 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, 0x0a, - 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, - 0x70, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x68, 0x6f, 0x6f, - 0x6b, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, 0x0a, 0x0a, 0x20, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x6f, 0x75, 0x74, 0x73, 0x69, 0x64, 0x65, 0x22, 0x29, - 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x66, 0x75, - 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, - 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x64, 0x65, 0x6c, - 0x65, 0x74, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x4d, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x28, - 0x73, 0x65, 0x6c, 0x66, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6c, - 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, - 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, - 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, - 0x72, 0x26, 0x5b, 0x5d, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, - 0x20, 0x69, 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x31, - 0x27, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x66, - 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x69, - 0x6c, 0x69, 0x74, 0x79, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x35, 0x20, 0x3f, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x3e, - 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x5b, 0x5d, 0x28, 0x27, - 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, - 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x2d, 0x31, 0x29, 0x20, - 0x3d, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, - 0x73, 0x5b, 0x32, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x3b, - 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, - 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, - 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x3e, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, - 0x6f, 0x72, 0x5b, 0x5d, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, - 0x2c, 0x27, 0x29, 0x20, 0x3d, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, + 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, + 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x62, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x62, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x61, + 0x74, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, + 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x6f, 0x75, 0x74, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, + 0x2e, 0x2e, 0x27, 0x20, 0x7c, 0x7c, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x62, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x73, 0x74, + 0x61, 0x74, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, + 0x20, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, + 0x67, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x65, 0x6e, 0x64, 0x20, 0x6f, + 0x66, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x20, 0x21, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x69, 0x73, 0x6e, 0x6f, 0x6f, 0x62, 0x6a, 0x28, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x6e, + 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x27, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x5c, 0x6e, 0x20, 0x29, 0x27, 0x29, + 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x67, 0x6f, 0x74, 0x6f, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6c, + 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3b, 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, + 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x7b, 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, + 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2c, 0x20, 0x69, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x73, + 0x65, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, 0x72, + 0x67, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, + 0x65, 0x6c, 0x73, 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x7e, 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x3d, 0x3d, 0x6e, + 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x2c, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x27, 0x2a, 0x27, 0x2c, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x20, 0x3d, + 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6f, + 0x6e, 0x73, 0x74, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x2a, 0x29, + 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, + 0x74, 0x5f, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, + 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x74, 0x6f, 0x5f, 0x66, 0x75, 0x6e, 0x63, + 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x31, + 0x2c, 0x30, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x69, 0x66, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, + 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, + 0x2c, 0x27, 0x5e, 0x25, 0x73, 0x2a, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, + 0x25, 0x73, 0x25, 0x73, 0x2a, 0x28, 0x2e, 0x2a, 0x29, 0x27, 0x29, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x63, + 0x6c, 0x61, 0x72, 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, + 0x65, 0x72, 0x73, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, + 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x64, 0x65, 0x63, + 0x6c, 0x61, 0x72, 0x65, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, + 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22, + 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, + 0x61, 0x72, 0x67, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x7e, 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x3d, 0x3d, 0x6e, 0x69, + 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, + 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, + 0x53, 0x45, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x21, + 0x73, 0x65, 0x6c, 0x66, 0x29, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x53, 0x2c, 0x22, 0x27, 0x2e, 0x2e, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x5f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, + 0x22, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x5c, 0x27, 0x73, + 0x65, 0x6c, 0x66, 0x5c, 0x27, 0x20, 0x69, 0x6e, 0x20, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5c, 0x27, 0x25, 0x73, 0x5c, 0x27, + 0x22, 0x2c, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x29, 0x2e, 0x2e, 0x27, 0x22, 0x2c, 0x20, 0x4e, 0x55, 0x4c, 0x4c, 0x29, + 0x3b, 0x27, 0x29, 0x3b, 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, + 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, + 0x67, 0x65, 0x74, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x65, 0x6c, + 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, + 0x0a, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, + 0x6c, 0x73, 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, + 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x67, 0x65, 0x74, 0x61, + 0x72, 0x72, 0x61, 0x79, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, + 0x20, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, + 0x67, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, + 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x70, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6c, 0x6c, + 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, 0x0a, + 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x75, 0x74, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, + 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x75, 0x74, 0x73, 0x69, + 0x64, 0x65, 0x22, 0x29, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, + 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, + 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, + 0x27, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x20, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x64, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, 0x3b, 0x27, 0x29, + 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6f, 0x70, 0x65, + 0x72, 0x61, 0x74, 0x6f, 0x72, 0x26, 0x5b, 0x5d, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, + 0x73, 0x5b, 0x27, 0x31, 0x27, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, + 0x2d, 0x2d, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x61, + 0x74, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x20, 0x77, 0x69, 0x74, + 0x68, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x35, 0x20, 0x3f, 0x0a, 0x09, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2d, 0x3e, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, + 0x5b, 0x5d, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, + 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, + 0x2d, 0x31, 0x29, 0x20, 0x3d, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x32, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x2c, 0x27, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7b, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, - 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, - 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x20, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, - 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x28, - 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x29, 0x20, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, - 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x6e, 0x65, 0x77, 0x28, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x29, 0x28, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, - 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x75, - 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, - 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x63, 0x6c, - 0x61, 0x73, 0x73, 0x2e, 0x2e, 0x27, 0x3a, 0x3a, 0x27, 0x2e, 0x2e, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, - 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, - 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, - 0x28, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x20, - 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x61, 0x73, - 0x74, 0x5f, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x09, 0x2d, 0x2d, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, - 0x5f, 0x63, 0x61, 0x73, 0x74, 0x3c, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, + 0x65, 0x2c, 0x27, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x3e, 0x6f, 0x70, + 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x5b, 0x5d, 0x28, 0x27, 0x2c, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x29, 0x20, 0x3d, 0x20, 0x27, 0x2c, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x32, 0x5d, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x3b, 0x27, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7b, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, - 0x27, 0x20, 0x3e, 0x28, 0x2a, 0x73, 0x65, 0x6c, 0x66, 0x27, 0x29, 0x0a, - 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x65, - 0x6c, 0x66, 0x2d, 0x3e, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, - 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x28, - 0x27, 0x29, 0x0a, 0x09, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, - 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x65, 0x6c, - 0x66, 0x2d, 0x3e, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, - 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, - 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, - 0x27, 0x28, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x20, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, 0x64, - 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, - 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x27, 0x29, 0x0a, 0x09, - 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, - 0x5b, 0x31, 0x5d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x2c, - 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x0a, - 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, - 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, - 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, - 0x5b, 0x69, 0x5d, 0x3a, 0x70, 0x61, 0x73, 0x73, 0x70, 0x61, 0x72, 0x28, - 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, - 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, - 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, - 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x5b, 0x5d, 0x27, 0x20, - 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x31, - 0x27, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x2d, 0x31, 0x29, 0x3b, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x63, - 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, 0x77, - 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x20, 0x2d, - 0x2d, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x20, 0x4d, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x6e, 0x65, 0x77, 0x28, 0x0a, 0x09, 0x65, 0x6c, 0x73, - 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x0a, - 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, - 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, - 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, - 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, - 0x6e, 0x72, 0x65, 0x74, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x20, 0x20, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x63, 0x74, 0x20, 0x3d, - 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, - 0x66, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x6e, 0x65, - 0x77, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x09, - 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x61, 0x73, 0x74, - 0x5f, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x20, 0x61, 0x6e, - 0x64, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, 0x72, 0x61, 0x77, - 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x20, 0x20, 0x20, 0x27, 0x2c, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5f, - 0x72, 0x61, 0x77, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5b, 0x74, 0x5d, 0x2c, - 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x27, - 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x72, 0x65, 0x74, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x09, - 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x27, 0x2e, 0x2e, 0x74, 0x2e, - 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, - 0x27, 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x74, 0x6f, 0x6c, 0x75, 0x61, - 0x5f, 0x72, 0x65, 0x74, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x74, - 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, - 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x5f, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, - 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x22, 0x2c, - 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, - 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, - 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, - 0x77, 0x6e, 0x65, 0x64, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x74, 0x72, - 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, - 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x75, - 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, - 0x74, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7b, 0x27, - 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, 0x66, 0x20, 0x5f, 0x5f, - 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, 0x73, 0x5c, 0x6e, 0x27, + 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x20, 0x3d, + 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x28, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, + 0x6f, 0x64, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2c, 0x27, 0x29, + 0x20, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, + 0x6e, 0x65, 0x77, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x4d, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, 0x77, 0x28, 0x28, 0x27, 0x2c, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x27, 0x29, 0x28, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, + 0x61, 0x74, 0x69, 0x63, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, + 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x2e, 0x27, 0x3a, 0x3a, + 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, + 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x09, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x63, 0x61, 0x73, 0x74, 0x5f, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, + 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x09, + 0x2d, 0x2d, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x74, + 0x61, 0x74, 0x69, 0x63, 0x5f, 0x63, 0x61, 0x73, 0x74, 0x3c, 0x27, 0x2c, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x70, 0x74, 0x72, 0x2c, 0x27, 0x20, 0x3e, 0x28, 0x2a, 0x73, 0x65, 0x6c, + 0x66, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x28, 0x27, 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x3e, 0x6f, 0x70, 0x65, 0x72, + 0x61, 0x74, 0x6f, 0x72, 0x20, 0x27, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6d, 0x6f, 0x64, 0x2c, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x73, 0x65, 0x6c, 0x66, 0x2d, 0x3e, 0x27, 0x2e, 0x2e, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, + 0x0a, 0x09, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x27, 0x28, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x75, 0x74, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x61, + 0x74, 0x69, 0x63, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x73, 0x65, 0x6c, 0x66, + 0x27, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x77, + 0x72, 0x69, 0x74, 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, + 0x65, 0x72, 0x73, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, + 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x70, 0x61, 0x73, 0x73, + 0x70, 0x61, 0x72, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, + 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, + 0x5b, 0x5d, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6c, 0x61, 0x67, + 0x73, 0x5b, 0x27, 0x31, 0x27, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x2d, 0x31, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, + 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x29, 0x29, 0x3b, + 0x27, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x20, + 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, 0x77, 0x28, 0x0a, + 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x2d, + 0x2d, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x73, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, + 0x74, 0x20, 0x3d, 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x2b, 0x20, 0x31, + 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, + 0x63, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x7e, 0x3d, + 0x20, 0x22, 0x6e, 0x65, 0x77, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x20, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x63, 0x61, 0x73, 0x74, 0x5f, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, + 0x72, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, + 0x5f, 0x72, 0x61, 0x77, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5b, 0x74, 0x5d, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x5f, 0x62, 0x61, + 0x73, 0x69, 0x63, 0x5f, 0x72, 0x61, 0x77, 0x5f, 0x70, 0x75, 0x73, 0x68, + 0x5b, 0x74, 0x5d, 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x53, 0x2c, 0x28, 0x27, 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x29, 0x3b, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x20, 0x20, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x27, + 0x2e, 0x2e, 0x74, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x53, 0x2c, 0x28, 0x27, 0x2c, 0x63, 0x74, 0x2c, 0x27, 0x29, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x29, 0x3b, 0x27, 0x29, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, + 0x65, 0x0a, 0x09, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x5f, 0x74, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x25, + 0x73, 0x2b, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, 0x3d, 0x20, + 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x22, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x22, 0x29, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, + 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x75, + 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x67, 0x65, + 0x74, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, + 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x20, 0x20, 0x7b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x64, 0x65, + 0x66, 0x20, 0x5f, 0x5f, 0x63, 0x70, 0x6c, 0x75, 0x73, 0x70, 0x6c, 0x75, + 0x73, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x76, + 0x6f, 0x69, 0x64, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, + 0x62, 0x6a, 0x20, 0x3d, 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x6e, 0x65, 0x77, 0x28, 0x28, 0x27, 0x2c, 0x6e, 0x65, 0x77, 0x5f, 0x74, + 0x2c, 0x27, 0x29, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, + 0x74, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, + 0x27, 0x2c, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, + 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x74, 0x6f, + 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, 0x2c, 0x74, + 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, + 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, + 0x74, 0x65, 0x72, 0x5f, 0x67, 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x53, 0x2c, 0x6c, 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, + 0x70, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x20, 0x3d, - 0x20, 0x4d, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x65, 0x77, 0x28, - 0x28, 0x27, 0x2c, 0x6e, 0x65, 0x77, 0x5f, 0x74, 0x2c, 0x27, 0x29, 0x28, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x29, 0x29, 0x3b, - 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, 0x75, - 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, - 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, 0x29, - 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, - 0x67, 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x6c, - 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, 0x28, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x23, 0x65, 0x6c, 0x73, 0x65, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, - 0x20, 0x20, 0x20, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x20, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x20, 0x3d, 0x20, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x63, 0x6f, 0x70, 0x79, 0x28, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x26, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x2c, 0x73, 0x69, - 0x7a, 0x65, 0x6f, 0x66, 0x28, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x29, 0x29, - 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, - 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x74, 0x6f, 0x6c, 0x75, 0x61, - 0x5f, 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, - 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, - 0x5f, 0x67, 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, - 0x6c, 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, 0x28, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x20, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, - 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x26, 0x27, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, 0x70, 0x75, - 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, 0x74, 0x6f, - 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, - 0x29, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, 0x2c, - 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x20, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x27, 0x2c, - 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, 0x27, 0x28, + 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x63, 0x6f, 0x70, 0x79, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, 0x6f, 0x69, - 0x64, 0x2a, 0x29, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x74, - 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, - 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x20, - 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, - 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x67, - 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x6c, 0x75, - 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, 0x28, 0x74, 0x6f, 0x6c, - 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, - 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, - 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x6e, - 0x72, 0x65, 0x74, 0x20, 0x2b, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, - 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x72, 0x65, 0x74, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, - 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, - 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x7d, - 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x73, 0x65, 0x74, - 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x65, 0x6c, 0x65, 0x6d, 0x65, - 0x6e, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x0a, 0x20, 0x20, - 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, 0x20, 0x65, 0x6c, 0x73, - 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, 0x20, 0x65, 0x6e, 0x64, - 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, - 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, - 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, + 0x64, 0x2a, 0x29, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, + 0x74, 0x2c, 0x73, 0x69, 0x7a, 0x65, 0x6f, 0x66, 0x28, 0x27, 0x2c, 0x74, + 0x2c, 0x27, 0x29, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, + 0x20, 0x27, 0x2c, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, + 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6f, 0x62, 0x6a, 0x2c, 0x22, 0x27, 0x2c, + 0x74, 0x2c, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, + 0x20, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, + 0x73, 0x74, 0x65, 0x72, 0x5f, 0x67, 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x53, 0x2c, 0x6c, 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, + 0x6f, 0x70, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5c, + 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x27, + 0x26, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, + 0x27, 0x2c, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x2c, + 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x28, 0x76, + 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x72, 0x65, 0x74, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x0a, 0x09, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x20, 0x20, 0x27, 0x2c, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x66, 0x75, 0x6e, + 0x63, 0x2c, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, + 0x28, 0x76, 0x6f, 0x69, 0x64, 0x2a, 0x29, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x72, 0x65, 0x74, 0x2c, 0x22, 0x27, 0x2c, 0x74, 0x2c, 0x27, 0x22, + 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x77, + 0x6e, 0x65, 0x64, 0x20, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x20, 0x20, 0x20, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, + 0x65, 0x72, 0x5f, 0x67, 0x63, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x53, 0x2c, 0x6c, 0x75, 0x61, 0x5f, 0x67, 0x65, 0x74, 0x74, 0x6f, 0x70, + 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x29, 0x3b, 0x27, + 0x29, 0x0a, 0x09, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, - 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x73, 0x65, - 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x6e, 0x61, 0x72, 0x67, 0x29, - 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, - 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, - 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x20, 0x2d, - 0x2d, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x64, 0x79, 0x6e, 0x61, 0x6d, - 0x69, 0x63, 0x61, 0x6c, 0x6c, 0x79, 0x20, 0x61, 0x6c, 0x6c, 0x6f, 0x63, - 0x61, 0x74, 0x65, 0x64, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x0a, 0x20, - 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, - 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, - 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, - 0x31, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, - 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x66, 0x72, 0x65, 0x65, - 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, - 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x63, 0x61, 0x6c, - 0x6c, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, - 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, - 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x27, 0x2e, 0x2e, - 0x6e, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x27, 0x3b, 0x27, 0x29, 0x0a, 0x0a, - 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x6f, 0x76, 0x65, - 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x65, 0x64, 0x20, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x72, 0x20, 0x67, 0x65, 0x6e, 0x65, - 0x72, 0x61, 0x74, 0x65, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x0a, 0x09, - 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x20, - 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x69, 0x66, 0x6e, - 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x52, 0x45, - 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3a, 0x5c, 0x6e, 0x27, + 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, 0x74, + 0x20, 0x3d, 0x20, 0x6e, 0x72, 0x65, 0x74, 0x20, 0x2b, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x72, + 0x65, 0x74, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, + 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x27, 0x20, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, + 0x20, 0x73, 0x65, 0x74, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x65, + 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x73, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x32, + 0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x3d, 0x31, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x77, + 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, + 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, + 0x5d, 0x3a, 0x73, 0x65, 0x74, 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x6e, + 0x61, 0x72, 0x67, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x72, + 0x67, 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x72, 0x67, 0x2b, 0x31, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x64, + 0x79, 0x6e, 0x61, 0x6d, 0x69, 0x63, 0x61, 0x6c, 0x6c, 0x79, 0x20, 0x61, + 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x65, 0x64, 0x20, 0x61, 0x72, 0x72, + 0x61, 0x79, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x31, 0x5d, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x76, 0x6f, 0x69, 0x64, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x77, 0x68, 0x69, + 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, + 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, + 0x66, 0x72, 0x65, 0x65, 0x61, 0x72, 0x72, 0x61, 0x79, 0x28, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, + 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x70, 0x6f, 0x73, 0x74, + 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x29, 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x28, 0x27, 0x20, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x27, 0x2e, 0x2e, 0x6e, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x27, 0x3b, + 0x27, 0x29, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x61, 0x6c, 0x6c, + 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x65, 0x64, 0x20, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x72, 0x20, + 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x65, 0x72, 0x72, + 0x6f, 0x72, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, + 0x6f, 0x61, 0x64, 0x20, 0x3c, 0x20, 0x30, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, + 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, + 0x41, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, - 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x6f, 0x72, - 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x27, 0x2e, - 0x2e, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x65, 0x72, 0x72, 0x6f, - 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x22, 0x23, 0x66, 0x65, 0x72, - 0x72, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x5c, 0x27, 0x25, 0x73, 0x5c, 0x27, 0x2e, 0x22, - 0x2c, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, - 0x29, 0x2e, 0x2e, 0x27, 0x22, 0x2c, 0x26, 0x74, 0x6f, 0x6c, 0x75, 0x61, - 0x5f, 0x65, 0x72, 0x72, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, - 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x30, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, - 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, - 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x09, 0x09, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x22, - 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x0a, 0x09, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3a, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, - 0x75, 0x74, 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x27, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x31, 0x2c, 0x2d, - 0x33, 0x29, 0x2e, 0x2e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x28, 0x22, - 0x25, 0x30, 0x32, 0x64, 0x22, 0x2c, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, - 0x61, 0x64, 0x29, 0x2e, 0x2e, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x2e, - 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x29, 0x3b, - 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x28, 0x27, 0x7d, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, - 0x20, 0x2f, 0x2f, 0x23, 0x69, 0x66, 0x6e, 0x64, 0x65, 0x66, 0x20, 0x54, - 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, 0x45, - 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x28, 0x27, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x20, - 0x72, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x20, 0x63, 0x61, - 0x6c, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x20, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, - 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x63, 0x6c, - 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, 0x6e, 0x65, 0x77, 0x27, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, - 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x73, - 0x65, 0x6c, 0x66, 0x3a, 0x73, 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x28, - 0x31, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, - 0x65, 0x72, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, - 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x72, - 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x20, 0x28, 0x70, 0x72, 0x65, - 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, - 0x65, 0x6c, 0x66, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, 0x70, 0x75, - 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x28, - 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x09, - 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, - 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, - 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, - 0x74, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x2e, 0x70, 0x75, 0x72, 0x65, - 0x5f, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x6e, 0x6f, 0x20, 0x63, - 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x66, - 0x6f, 0x72, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x20, 0x77, - 0x69, 0x74, 0x68, 0x20, 0x70, 0x75, 0x72, 0x65, 0x20, 0x76, 0x69, 0x72, - 0x74, 0x75, 0x61, 0x6c, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, - 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, - 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x27, 0x2e, 0x2e, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, - 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, - 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x20, - 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, 0x75, - 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x6e, 0x65, 0x77, 0x5f, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x5f, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x20, - 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, - 0x2e, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, - 0x2c, 0x22, 0x2e, 0x63, 0x61, 0x6c, 0x6c, 0x22, 0x2c, 0x27, 0x2e, 0x2e, - 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, - 0x27, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x29, 0x3b, 0x27, 0x29, 0x0a, - 0x09, 0x20, 0x20, 0x2d, 0x2d, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, - 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x73, 0x65, 0x74, 0x5f, - 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x28, 0x74, - 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, 0x2e, 0x2e, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x5f, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x2c, 0x20, 0x22, 0x27, 0x2e, 0x2e, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x74, - 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, 0x22, 0x29, 0x3b, 0x27, 0x29, 0x0a, - 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, - 0x2d, 0x20, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x6d, 0x65, 0x74, 0x68, - 0x6f, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, - 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x3a, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x28, 0x69, 0x64, 0x65, - 0x6e, 0x74, 0x2c, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x29, 0x0a, 0x20, 0x70, - 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, - 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x7b, 0x22, 0x29, - 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, - 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6d, 0x6f, 0x64, 0x20, 0x20, 0x3d, 0x20, - 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6d, 0x6f, 0x64, + 0x75, 0x74, 0x28, 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, + 0x72, 0x72, 0x6f, 0x72, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, + 0x2c, 0x22, 0x27, 0x2e, 0x2e, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, + 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x22, + 0x23, 0x66, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5c, 0x27, 0x25, 0x73, + 0x5c, 0x27, 0x2e, 0x22, 0x2c, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, + 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x2e, 0x2e, 0x27, 0x22, 0x2c, 0x26, 0x74, + 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x65, 0x72, 0x72, 0x29, 0x3b, 0x27, 0x29, + 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x30, 0x3b, 0x27, 0x29, 0x0a, + 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, + 0x6e, 0x64, 0x69, 0x66, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6c, + 0x73, 0x65, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, + 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, + 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x3d, 0x20, 0x22, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x28, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6c, 0x65, + 0x72, 0x72, 0x6f, 0x72, 0x3a, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x09, 0x09, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x27, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x31, 0x2c, 0x2d, 0x33, 0x29, 0x2e, 0x2e, 0x66, 0x6f, 0x72, 0x6d, + 0x61, 0x74, 0x28, 0x22, 0x25, 0x30, 0x32, 0x64, 0x22, 0x2c, 0x6f, 0x76, + 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x29, 0x2e, 0x2e, 0x5f, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x2e, 0x2e, 0x27, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x53, 0x29, 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x7d, 0x27, 0x29, + 0x0a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x23, 0x65, + 0x6e, 0x64, 0x69, 0x66, 0x20, 0x2f, 0x2f, 0x23, 0x69, 0x66, 0x6e, 0x64, + 0x65, 0x66, 0x20, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x44, 0x49, 0x53, + 0x41, 0x42, 0x4c, 0x45, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x20, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x28, 0x27, 0x5c, 0x6e, 0x27, 0x29, 0x0a, 0x0a, + 0x09, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, + 0x65, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x77, 0x72, + 0x69, 0x74, 0x65, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6f, + 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x3d, 0x27, + 0x6e, 0x65, 0x77, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x0a, 0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x73, 0x75, 0x70, 0x63, + 0x6f, 0x64, 0x65, 0x28, 0x31, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x72, 0x65, + 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x3a, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x20, + 0x28, 0x70, 0x72, 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x63, 0x68, 0x65, 0x63, + 0x6b, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, 0x63, + 0x65, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, + 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, + 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x2e, + 0x70, 0x75, 0x72, 0x65, 0x5f, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x2d, 0x2d, 0x20, + 0x6e, 0x6f, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, + 0x6f, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x65, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x70, 0x75, 0x72, 0x65, + 0x20, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x6d, 0x65, 0x74, + 0x68, 0x6f, 0x64, 0x73, 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x0a, 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, + 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, + 0x65, 0x2e, 0x2e, 0x27, 0x22, 0x2c, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x29, 0x3b, + 0x27, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x65, + 0x77, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x20, 0x6f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, + 0x6e, 0x65, 0x77, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0x2c, 0x27, + 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, + 0x2e, 0x2e, 0x27, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x29, 0x3b, 0x27, + 0x29, 0x0a, 0x09, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x28, + 0x70, 0x72, 0x65, 0x2e, 0x2e, 0x27, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x22, 0x2e, 0x63, 0x61, 0x6c, 0x6c, 0x22, + 0x2c, 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, + 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x09, 0x20, 0x20, 0x2d, 0x2d, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x28, 0x27, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x73, 0x65, 0x74, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x65, 0x76, 0x65, + 0x6e, 0x74, 0x28, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x53, 0x2c, 0x27, + 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, + 0x2e, 0x2e, 0x27, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x2c, 0x20, 0x22, + 0x27, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x27, 0x22, 0x29, + 0x3b, 0x27, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x20, + 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, + 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2c, 0x63, 0x6c, 0x6f, 0x73, 0x65, + 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, + 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x7b, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6d, 0x6f, 0x64, + 0x20, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6d, 0x6f, 0x64, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, + 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, + 0x2e, 0x2e, 0x22, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x27, + 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x27, - 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, - 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x70, 0x74, 0x72, 0x20, - 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x70, 0x74, 0x72, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, + 0x70, 0x74, 0x72, 0x20, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x2e, 0x2e, 0x22, 0x27, 0x2c, + 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, + 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, - 0x2e, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, - 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, + 0x2e, 0x22, 0x20, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, + 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, + 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, + 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, + 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, + 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, - 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6c, + 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, - 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, + 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, - 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x63, 0x6f, 0x6e, - 0x73, 0x74, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x2e, 0x2e, 0x22, 0x27, 0x2c, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6c, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, - 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x63, 0x6e, 0x61, 0x6d, 0x65, - 0x20, 0x3d, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, - 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, - 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, - 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, - 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x27, 0x2c, 0x22, 0x29, 0x0a, 0x20, - 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, - 0x2e, 0x22, 0x20, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x22, - 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, - 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x61, 0x72, 0x67, 0x73, 0x20, + 0x3d, 0x20, 0x7b, 0x22, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, + 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, + 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x20, 0x22, + 0x2c, 0x22, 0x2c, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, + 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x70, 0x72, + 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, + 0x20, 0x7d, 0x22, 0x29, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x7d, 0x22, 0x2e, 0x2e, + 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x69, 0x66, 0x20, + 0x69, 0x74, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x61, + 0x6e, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x62, 0x79, 0x20, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, + 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, + 0x74, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x20, + 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, + 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, + 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x69, 0x73, 0x62, 0x61, 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x74, 0x72, 0x3d, 0x3d, 0x27, 0x27, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x22, + 0x25, 0x73, 0x2a, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x22, + 0x2c, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x20, 0x74, 0x5b, 0x74, 0x79, 0x70, + 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x5f, 0x22, 0x20, 0x2e, 0x2e, + 0x20, 0x63, 0x6c, 0x65, 0x61, 0x6e, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, + 0x61, 0x74, 0x65, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x20, + 0x72, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, + 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, - 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, - 0x69, 0x5d, 0x3a, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, - 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x20, 0x22, 0x2c, 0x22, 0x2c, 0x22, - 0x29, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, - 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, - 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2e, 0x2e, 0x22, 0x20, 0x7d, 0x22, 0x29, - 0x0a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x69, 0x64, 0x65, 0x6e, - 0x74, 0x2e, 0x2e, 0x22, 0x7d, 0x22, 0x2e, 0x2e, 0x63, 0x6c, 0x6f, 0x73, - 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, - 0x68, 0x65, 0x63, 0x6b, 0x20, 0x69, 0x66, 0x20, 0x69, 0x74, 0x20, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x6f, 0x62, - 0x6a, 0x65, 0x63, 0x74, 0x20, 0x62, 0x79, 0x20, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, - 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x63, 0x6f, 0x6c, 0x6c, - 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x20, 0x3d, 0x20, 0x66, 0x61, - 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, - 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, - 0x61, 0x6e, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x69, 0x73, 0x62, 0x61, - 0x73, 0x69, 0x63, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, - 0x65, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x70, 0x74, 0x72, 0x3d, 0x3d, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, - 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x65, 0x6c, - 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x22, 0x25, 0x73, 0x2a, 0x63, - 0x6f, 0x6e, 0x73, 0x74, 0x25, 0x73, 0x2b, 0x22, 0x2c, 0x22, 0x22, 0x29, - 0x0a, 0x09, 0x20, 0x74, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, 0x3d, - 0x20, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6c, - 0x65, 0x63, 0x74, 0x5f, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x63, 0x6c, 0x65, - 0x61, 0x6e, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x28, - 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x20, 0x72, 0x20, 0x3d, 0x20, - 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x09, 0x77, 0x68, - 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, - 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x72, 0x20, - 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x5b, - 0x69, 0x5d, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x63, 0x6f, - 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, 0x20, - 0x6f, 0x72, 0x20, 0x72, 0x0a, 0x09, 0x09, 0x69, 0x20, 0x3d, 0x20, 0x69, - 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x72, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, - 0x2d, 0x20, 0x64, 0x65, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x65, 0x20, - 0x6c, 0x75, 0x61, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, - 0x61, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, - 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x3a, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x28, - 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x65, - 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x3a, 0x6f, 0x76, - 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, - 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, - 0x72, 0x61, 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, 0x70, - 0x61, 0x72, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, - 0x6e, 0x73, 0x20, 0x74, 0x72, 0x75, 0x65, 0x20, 0x69, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, - 0x20, 0x68, 0x61, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x6f, 0x62, 0x6a, 0x65, - 0x63, 0x74, 0x20, 0x61, 0x73, 0x20, 0x69, 0x74, 0x73, 0x20, 0x64, 0x65, + 0x09, 0x09, 0x72, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x61, + 0x72, 0x67, 0x73, 0x5b, 0x69, 0x5d, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, + 0x72, 0x65, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x28, 0x74, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x72, 0x0a, 0x09, 0x09, 0x69, + 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x74, 0x65, 0x72, 0x6d, + 0x69, 0x6e, 0x65, 0x20, 0x6c, 0x75, 0x61, 0x20, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x76, + 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, + 0x61, 0x64, 0x20, 0x28, 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, + 0x74, 0x3a, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, + 0x63, 0x74, 0x28, 0x70, 0x61, 0x72, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x20, 0x74, 0x72, 0x75, 0x65, 0x20, + 0x69, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, + 0x65, 0x74, 0x65, 0x72, 0x20, 0x68, 0x61, 0x73, 0x20, 0x61, 0x6e, 0x20, + 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x61, 0x73, 0x20, 0x69, 0x74, + 0x73, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, + 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x27, 0x3d, 0x27, 0x29, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, + 0x61, 0x6c, 0x73, 0x65, 0x20, 0x65, 0x6e, 0x64, 0x20, 0x2d, 0x2d, 0x20, + 0x69, 0x74, 0x20, 0x68, 0x61, 0x73, 0x20, 0x6e, 0x6f, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, - 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, - 0x2c, 0x20, 0x27, 0x3d, 0x27, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, - 0x20, 0x65, 0x6e, 0x64, 0x20, 0x2d, 0x2d, 0x20, 0x69, 0x74, 0x20, 0x68, - 0x61, 0x73, 0x20, 0x6e, 0x6f, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, - 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x64, 0x65, 0x66, 0x20, - 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, - 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x3d, 0x28, 0x2e, 0x2a, - 0x29, 0x24, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, - 0x72, 0x2c, 0x20, 0x22, 0x7c, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x20, 0x6f, - 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x0a, 0x0a, 0x09, 0x09, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, - 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, + 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, + 0x64, 0x65, 0x66, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, + 0x3d, 0x28, 0x2e, 0x2a, 0x29, 0x24, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x7c, 0x22, 0x29, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x20, 0x6c, 0x69, + 0x73, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x0a, + 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, + 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x69, 0x66, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, + 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x25, 0x2a, 0x22, 0x29, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x69, 0x74, 0x27, 0x73, + 0x20, 0x61, 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x20, 0x77, + 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, + 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x0a, 0x0a, 0x09, 0x09, 0x69, + 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x27, 0x3d, 0x25, 0x73, 0x2a, + 0x6e, 0x65, 0x77, 0x27, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, - 0x2c, 0x20, 0x22, 0x25, 0x2a, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x2c, 0x20, 0x22, 0x25, 0x28, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, 0x69, 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, - 0x61, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x0a, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, - 0x72, 0x2c, 0x20, 0x27, 0x3d, 0x25, 0x73, 0x2a, 0x6e, 0x65, 0x77, 0x27, + 0x61, 0x6e, 0x20, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x20, + 0x61, 0x73, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x2e, 0x2e, 0x20, 0x69, + 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x69, 0x64, + 0x3f, 0x0a, 0x09, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, + 0x65, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, + 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, 0x27, 0x4e, + 0x55, 0x4c, 0x4c, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x6f, 0x6d, 0x65, + 0x74, 0x68, 0x69, 0x6e, 0x67, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x5b, + 0x25, 0x28, 0x26, 0x5d, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, + 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, + 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, + 0x69, 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, + 0x63, 0x74, 0x6f, 0x72, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x28, 0x6d, + 0x6f, 0x73, 0x74, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x6c, 0x79, 0x20, 0x66, + 0x6f, 0x72, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x72, + 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x29, 0x0a, 0x0a, 0x09, + 0x2d, 0x2d, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x26, + 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, + 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, + 0x69, 0x6e, 0x64, 0x28, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x22, 0x3a, 0x22, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, - 0x66, 0x69, 0x6e, 0x64, 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x25, - 0x28, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x2d, 0x2d, 0x20, - 0x69, 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x6e, 0x20, 0x69, - 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x61, 0x73, 0x20, 0x64, - 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, - 0x65, 0x74, 0x65, 0x72, 0x2e, 0x2e, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, - 0x61, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x3f, 0x0a, 0x09, 0x09, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x6e, 0x65, 0x77, 0x25, 0x73, 0x2b, 0x22, 0x29, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x09, 0x2d, + 0x2d, 0x20, 0x69, 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, 0x72, 0x65, 0x66, + 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, + 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x73, + 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6c, 0x69, 0x6b, + 0x65, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x3a, 0x3a, 0x6d, 0x65, 0x6d, + 0x62, 0x65, 0x72, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x27, 0x6e, 0x65, 0x77, + 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x27, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, - 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x20, 0x2d, 0x2d, - 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, 0x27, 0x4e, 0x55, 0x4c, 0x4c, 0x27, - 0x20, 0x6f, 0x72, 0x20, 0x73, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x69, 0x6e, - 0x67, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x09, 0x69, 0x66, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, - 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x5b, 0x25, 0x28, 0x26, 0x5d, - 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, 0x65, - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, - 0x6e, 0x64, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, - 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x69, 0x73, 0x20, 0x61, - 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, - 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x28, 0x6d, 0x6f, 0x73, 0x74, 0x20, - 0x6c, 0x69, 0x6b, 0x65, 0x6c, 0x79, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, - 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, - 0x65, 0x6e, 0x63, 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x69, 0x66, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, - 0x28, 0x70, 0x61, 0x72, 0x2c, 0x20, 0x22, 0x26, 0x22, 0x29, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x69, 0x66, 0x20, + 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x20, 0x2d, 0x2d, 0x20, 0x3f, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x6c, 0x61, 0x73, 0x74, + 0x5f, 0x61, 0x72, 0x67, 0x28, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, + 0x73, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x29, + 0x20, 0x2d, 0x2d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x73, 0x20, 0x74, + 0x68, 0x65, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, + 0x65, 0x6e, 0x74, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x5f, 0x2c, 0x5f, 0x2c, 0x73, 0x5f, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, - 0x64, 0x65, 0x66, 0x2c, 0x20, 0x22, 0x3a, 0x22, 0x29, 0x20, 0x6f, 0x72, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, - 0x28, 0x64, 0x65, 0x66, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x6e, - 0x65, 0x77, 0x25, 0x73, 0x2b, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x69, 0x74, - 0x27, 0x73, 0x20, 0x61, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, - 0x63, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x73, 0x6f, 0x6d, 0x65, 0x74, - 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x43, 0x6c, - 0x61, 0x73, 0x73, 0x3a, 0x3a, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x2c, - 0x20, 0x6f, 0x72, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x20, 0x43, 0x6c, 0x61, - 0x73, 0x73, 0x27, 0x0a, 0x09, 0x2d, 0x2d, 0x09, 0x09, 0x72, 0x65, 0x74, - 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x2d, 0x2d, - 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, 0x0a, - 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, - 0x73, 0x65, 0x20, 0x2d, 0x2d, 0x20, 0x3f, 0x0a, 0x65, 0x6e, 0x64, 0x0a, - 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x70, 0x5f, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, - 0x28, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x2c, 0x20, 0x6c, - 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x29, 0x20, 0x2d, 0x2d, 0x20, - 0x73, 0x74, 0x72, 0x69, 0x70, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x64, - 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x61, - 0x73, 0x74, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x0a, - 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, - 0x73, 0x5f, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, - 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x6c, 0x61, 0x73, 0x74, - 0x5f, 0x61, 0x72, 0x67, 0x2c, 0x20, 0x22, 0x5e, 0x28, 0x5b, 0x5e, 0x3d, - 0x5d, 0x2b, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, - 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, - 0x72, 0x67, 0x2c, 0x20, 0x22, 0x28, 0x5b, 0x25, 0x25, 0x25, 0x28, 0x25, - 0x29, 0x5d, 0x29, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x25, 0x25, 0x31, 0x22, - 0x29, 0x3b, 0x0a, 0x09, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, - 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, - 0x75, 0x62, 0x28, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x2c, - 0x20, 0x22, 0x25, 0x73, 0x2a, 0x2c, 0x25, 0x73, 0x2a, 0x22, 0x2e, 0x2e, - 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x2e, 0x2e, 0x22, 0x25, - 0x73, 0x2a, 0x25, 0x29, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, - 0x29, 0x22, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x2c, 0x20, 0x73, 0x5f, - 0x61, 0x72, 0x67, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x0a, 0x2d, - 0x2d, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x63, - 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, 0x46, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x73, - 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, - 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x63, 0x6f, - 0x6e, 0x73, 0x74, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x2e, 0x63, - 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, - 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, - 0x22, 0x23, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x27, 0x63, - 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, - 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x29, 0x0a, 0x20, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28, - 0x74, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x3a, 0x69, 0x6e, 0x63, - 0x6c, 0x61, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x20, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x28, 0x27, 0x74, - 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x69, 0x73, 0x20, 0x27, 0x2e, 0x2e, - 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x27, 0x2c, 0x20, 0x70, - 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x69, - 0x73, 0x20, 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, - 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, - 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, 0x62, - 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x3d, 0x3d, 0x20, - 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, - 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6f, 0x72, 0x69, - 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, - 0x72, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, - 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x2c, - 0x20, 0x22, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, - 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x6e, - 0x65, 0x77, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6c, 0x6e, 0x61, - 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x0a, 0x20, - 0x20, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x5f, - 0x6e, 0x65, 0x77, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x20, - 0x20, 0x20, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, + 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x2c, 0x20, 0x22, 0x5e, + 0x28, 0x5b, 0x5e, 0x3d, 0x5d, 0x2b, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x6c, + 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x6c, 0x61, + 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, 0x2c, 0x20, 0x22, 0x28, 0x5b, 0x25, + 0x25, 0x25, 0x28, 0x25, 0x29, 0x5d, 0x29, 0x22, 0x2c, 0x20, 0x22, 0x25, + 0x25, 0x25, 0x31, 0x22, 0x29, 0x3b, 0x0a, 0x09, 0x61, 0x6c, 0x6c, 0x5f, + 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x61, 0x6c, 0x6c, 0x5f, 0x61, + 0x72, 0x67, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x2c, 0x25, 0x73, + 0x2a, 0x22, 0x2e, 0x2e, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x67, + 0x2e, 0x2e, 0x22, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x25, 0x73, 0x2a, 0x24, + 0x22, 0x2c, 0x20, 0x22, 0x29, 0x22, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x61, 0x6c, 0x6c, 0x5f, 0x61, 0x72, 0x67, 0x73, + 0x2c, 0x20, 0x73, 0x5f, 0x61, 0x72, 0x67, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, + 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, + 0x6f, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x5f, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, + 0x29, 0x0a, 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, + 0x62, 0x6c, 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x0a, 0x20, 0x69, + 0x66, 0x20, 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, + 0x20, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, + 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, + 0x64, 0x20, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x73, 0x70, + 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, + 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x61, 0x70, 0x70, + 0x65, 0x6e, 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, + 0x3a, 0x69, 0x6e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x20, 0x28, 0x27, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x69, 0x73, + 0x20, 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, + 0x27, 0x2c, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x69, 0x73, 0x20, 0x27, 0x2e, 0x2e, 0x74, 0x2e, 0x70, + 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x20, 0x22, 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, + 0x20, 0x3d, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, + 0x73, 0x75, 0x62, 0x28, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, + 0x2e, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x5f, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, 0x62, + 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x3d, 0x20, 0x27, 0x6e, 0x65, 0x77, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x74, + 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x6e, 0x65, + 0x77, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x2e, 0x5f, 0x6e, 0x65, 0x77, 0x20, 0x3d, 0x20, 0x74, 0x72, + 0x75, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x70, 0x74, + 0x72, 0x20, 0x3d, 0x20, 0x27, 0x2a, 0x27, 0x0a, 0x20, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x20, 0x22, 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, + 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x7e, 0x27, 0x2e, 0x2e, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2e, 0x70, + 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, + 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, - 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x70, 0x74, 0x72, 0x20, 0x3d, 0x20, - 0x27, 0x2a, 0x27, 0x0a, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, - 0x28, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, 0x62, - 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x3d, 0x3d, 0x20, - 0x27, 0x7e, 0x27, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, - 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, - 0x74, 0x2e, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x5f, 0x6e, - 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, - 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x22, 0x25, - 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, - 0x20, 0x3d, 0x20, 0x27, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x27, 0x0a, - 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, - 0x20, 0x27, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x27, 0x0a, 0x20, 0x20, - 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x2e, 0x5f, 0x64, - 0x65, 0x6c, 0x65, 0x74, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, - 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x74, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x74, - 0x3a, 0x63, 0x66, 0x75, 0x6e, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x28, 0x22, - 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x22, 0x29, 0x2e, 0x2e, 0x74, 0x3a, 0x6f, - 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, - 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, 0x45, 0x78, 0x70, 0x65, - 0x63, 0x74, 0x73, 0x20, 0x74, 0x68, 0x72, 0x65, 0x65, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x73, 0x3a, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x72, - 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x2c, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x6f, 0x74, 0x68, 0x65, 0x72, - 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, - 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, - 0x6e, 0x74, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x2c, 0x20, 0x61, 0x6e, 0x64, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x20, 0x72, - 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x0a, - 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, - 0x74, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x20, - 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x0a, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x28, 0x64, 0x2c, 0x61, 0x2c, 0x63, 0x29, 0x0a, 0x20, 0x2d, - 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, - 0x70, 0x6c, 0x69, 0x74, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, - 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x27, 0x2c, 0x27, 0x29, - 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, - 0x65, 0x20, 0x62, 0x72, 0x61, 0x63, 0x65, 0x73, 0x0a, 0x20, 0x2d, 0x2d, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, - 0x6c, 0x69, 0x74, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x28, 0x73, + 0x2c, 0x20, 0x22, 0x25, 0x62, 0x3c, 0x3e, 0x22, 0x2c, 0x20, 0x22, 0x22, + 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, + 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x64, 0x65, 0x6c, 0x65, + 0x74, 0x65, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x6c, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, + 0x27, 0x0a, 0x20, 0x20, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, + 0x74, 0x2e, 0x5f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x20, 0x3d, 0x20, + 0x74, 0x72, 0x75, 0x65, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x74, 0x2e, 0x63, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x3d, 0x20, 0x74, 0x3a, 0x63, 0x66, 0x75, 0x6e, 0x63, 0x6e, 0x61, + 0x6d, 0x65, 0x28, 0x22, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x22, 0x29, 0x2e, + 0x2e, 0x74, 0x3a, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x28, + 0x74, 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, + 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x0a, 0x2d, 0x2d, 0x20, + 0x45, 0x78, 0x70, 0x65, 0x63, 0x74, 0x73, 0x20, 0x74, 0x68, 0x72, 0x65, + 0x65, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x3a, 0x20, 0x6f, + 0x6e, 0x65, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, + 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x6f, + 0x74, 0x68, 0x65, 0x72, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, + 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x72, + 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x69, 0x73, 0x74, 0x2c, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x68, 0x69, + 0x72, 0x64, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, + 0x69, 0x6e, 0x67, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x22, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x65, 0x6d, + 0x70, 0x74, 0x79, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x46, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x64, 0x2c, 0x61, 0x2c, 0x63, + 0x29, 0x0a, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, + 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x73, 0x74, 0x72, + 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x2c, + 0x27, 0x2c, 0x27, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x65, 0x6c, 0x69, 0x6d, + 0x69, 0x6e, 0x61, 0x74, 0x65, 0x20, 0x62, 0x72, 0x61, 0x63, 0x65, 0x73, + 0x0a, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, + 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x70, 0x61, 0x72, 0x61, + 0x6d, 0x73, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, + 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, + 0x6e, 0x6f, 0x74, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x57, + 0x27, 0x5d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x2c, 0x20, 0x22, 0x25, + 0x2e, 0x25, 0x2e, 0x25, 0x2e, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x22, 0x29, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x77, 0x61, 0x72, + 0x6e, 0x69, 0x6e, 0x67, 0x28, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x76, 0x61, 0x72, + 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, + 0x6e, 0x74, 0x73, 0x20, 0x28, 0x60, 0x2e, 0x2e, 0x2e, 0x27, 0x29, 0x20, + 0x61, 0x72, 0x65, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x75, 0x70, 0x70, + 0x6f, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x49, 0x67, 0x6e, 0x6f, 0x72, + 0x69, 0x6e, 0x67, 0x20, 0x22, 0x2e, 0x2e, 0x64, 0x2e, 0x2e, 0x61, 0x2e, + 0x2e, 0x63, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, + 0x3d, 0x30, 0x7d, 0x0a, 0x0a, 0x20, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x61, + 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x25, 0x28, 0x25, 0x29, + 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x31, 0x22, + 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x73, + 0x74, 0x72, 0x69, 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, - 0x29, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, - 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x57, 0x27, 0x5d, 0x20, 0x61, - 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, - 0x6e, 0x64, 0x28, 0x61, 0x2c, 0x20, 0x22, 0x25, 0x2e, 0x25, 0x2e, 0x25, - 0x2e, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, - 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, - 0x28, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, - 0x77, 0x69, 0x74, 0x68, 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, - 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x20, - 0x28, 0x60, 0x2e, 0x2e, 0x2e, 0x27, 0x29, 0x20, 0x61, 0x72, 0x65, 0x20, - 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, - 0x64, 0x2e, 0x20, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x69, 0x6e, 0x67, 0x20, - 0x22, 0x2e, 0x2e, 0x64, 0x2e, 0x2e, 0x61, 0x2e, 0x2e, 0x63, 0x29, 0x0a, - 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, - 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x20, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, 0x30, 0x7d, 0x0a, - 0x0a, 0x20, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, - 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x20, 0x22, 0x25, - 0x73, 0x2a, 0x28, 0x5b, 0x25, 0x28, 0x25, 0x29, 0x5d, 0x29, 0x25, 0x73, - 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x31, 0x22, 0x29, 0x0a, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, 0x69, 0x70, - 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, - 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, - 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x3b, 0x0a, - 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, - 0x61, 0x2c, 0x31, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x20, 0x31, 0x2c, 0x20, - 0x2d, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x6c, 0x65, 0x6e, - 0x28, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x2b, 0x31, 0x29, 0x29, 0x0a, 0x09, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, - 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x2c, 0x22, 0x2c, - 0x20, 0x31, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x2d, 0x31, 0x29, 0x0a, - 0x0a, 0x09, 0x09, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x22, 0x28, 0x22, 0x2e, - 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, - 0x28, 0x6e, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x2c, 0x25, 0x73, - 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x2e, 0x2e, 0x27, 0x29, - 0x27, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x73, + 0x29, 0x29, 0x3b, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x74, 0x72, + 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x31, 0x2c, 0x2d, 0x32, 0x29, 0x2c, + 0x20, 0x31, 0x2c, 0x20, 0x2d, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x6c, 0x65, 0x6e, 0x28, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x2b, 0x31, + 0x29, 0x29, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, + 0x73, 0x20, 0x3d, 0x20, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, + 0x22, 0x2c, 0x22, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, + 0x2d, 0x31, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6e, 0x73, 0x20, 0x3d, 0x20, + 0x22, 0x28, 0x22, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x67, 0x73, 0x75, 0x62, 0x28, 0x6e, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, + 0x2a, 0x2c, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, + 0x2e, 0x2e, 0x27, 0x29, 0x27, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6e, 0x73, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, + 0x61, 0x75, 0x6c, 0x74, 0x73, 0x28, 0x6e, 0x73, 0x29, 0x0a, 0x0a, 0x09, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x46, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x20, 0x6e, + 0x73, 0x2c, 0x20, 0x63, 0x29, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, + 0x69, 0x3d, 0x31, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, + 0x09, 0x09, 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, + 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, + 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, + 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, + 0x20, 0x3d, 0x20, 0x6c, 0x2e, 0x6e, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x6c, + 0x5b, 0x6c, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, + 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x5b, 0x69, 0x5d, + 0x2c, 0x27, 0x76, 0x61, 0x72, 0x27, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, + 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, + 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x29, + 0x0a, 0x20, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x6c, + 0x0a, 0x20, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x63, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x46, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x66, 0x29, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x70, + 0x2c, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2c, 0x20, 0x6c, 0x61, 0x73, + 0x74, 0x29, 0x0a, 0x0a, 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x3d, + 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x31, 0x0a, + 0x09, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x6c, 0x61, 0x73, 0x74, + 0x20, 0x6f, 0x72, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x67, 0x65, + 0x74, 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6c, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, + 0x22, 0x22, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x6f, + 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x66, 0x6f, 0x72, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x72, 0x73, + 0x74, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, + 0x09, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, + 0x6c, 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, + 0x09, 0x6c, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x70, 0x0a, + 0x09, 0x09, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, + 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, + 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x73, 0x28, 0x73, 0x2c, 0x20, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, + 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x09, 0x66, 0x6f, 0x72, + 0x20, 0x69, 0x3d, 0x74, 0x2e, 0x6e, 0x2c, 0x31, 0x2c, 0x2d, 0x31, 0x20, + 0x64, 0x6f, 0x0a, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, + 0x74, 0x5b, 0x69, 0x5d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x0a, 0x09, + 0x09, 0x09, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, + 0x75, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x2d, + 0x2d, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x09, 0x74, 0x5b, 0x69, 0x5d, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, + 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, + 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x2d, + 0x2d, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, + 0x69, 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, - 0x73, 0x28, 0x6e, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x46, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x20, 0x6e, 0x73, 0x2c, 0x20, 0x63, - 0x29, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, 0x2c, - 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x09, 0x74, - 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, - 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, - 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, 0x69, 0x5d, 0x20, - 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x6c, - 0x2e, 0x6e, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x6c, 0x5b, 0x6c, 0x2e, 0x6e, - 0x5d, 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x27, 0x76, 0x61, - 0x72, 0x27, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x69, - 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x44, - 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, - 0x2c, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x29, 0x0a, 0x20, 0x66, 0x2e, - 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x6c, 0x0a, 0x20, 0x66, 0x2e, - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x63, 0x0a, 0x20, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x46, 0x75, 0x6e, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x28, 0x66, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6a, 0x6f, 0x69, - 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x70, 0x2c, 0x20, 0x66, 0x69, - 0x72, 0x73, 0x74, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x0a, 0x0a, - 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x72, - 0x73, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x31, 0x0a, 0x09, 0x6c, 0x61, 0x73, - 0x74, 0x20, 0x3d, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x6f, 0x72, 0x20, - 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x67, 0x65, 0x74, 0x6e, 0x28, 0x74, - 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x73, 0x65, - 0x70, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x3d, - 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, - 0x69, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2c, 0x6c, 0x61, - 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, - 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x6c, 0x73, 0x65, 0x70, - 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, 0x09, 0x6c, 0x73, 0x65, - 0x70, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x70, 0x0a, 0x09, 0x09, 0x6c, 0x6f, - 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, - 0x6f, 0x6f, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, - 0x65, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x70, - 0x61, 0x72, 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, - 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, - 0x20, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, - 0x73, 0x65, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x61, - 0x73, 0x74, 0x0a, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x74, - 0x2e, 0x6e, 0x2c, 0x31, 0x2c, 0x2d, 0x31, 0x20, 0x64, 0x6f, 0x0a, 0x0a, - 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x70, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, - 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, 0x74, 0x5b, 0x69, 0x5d, - 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6c, 0x61, - 0x73, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x0a, 0x09, 0x09, 0x09, 0x73, 0x74, - 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x09, - 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x69, 0x66, 0x20, - 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x09, 0x2d, 0x2d, 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, - 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, - 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x65, 0x6e, 0x64, + 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x28, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, + 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x29, + 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, + 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, + 0x2c, 0x20, 0x22, 0x2c, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x73, 0x65, 0x70, 0x2c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, + 0x20, 0x22, 0x22, 0x2c, 0x22, 0x22, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, + 0x69, 0x3d, 0x31, 0x2c, 0x74, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x09, + 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, + 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, + 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, + 0x74, 0x2e, 0x2e, 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, + 0x0a, 0x09, 0x09, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x2c, 0x22, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, 0x69, 0x70, 0x2c, 0x6c, - 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, - 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, - 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x73, 0x28, 0x73, 0x29, - 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, - 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, - 0x25, 0x28, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x73, 0x20, - 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, - 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x29, 0x24, 0x22, 0x2c, 0x20, - 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, - 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, - 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x2c, - 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x65, - 0x70, 0x2c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x2c, - 0x22, 0x22, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, 0x2c, - 0x74, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x74, 0x5b, 0x69, - 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, - 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, - 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, - 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x73, - 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, 0x09, 0x73, - 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x2c, 0x22, 0x0a, 0x09, 0x65, 0x6e, - 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, - 0x28, 0x22, 0x2e, 0x2e, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x22, 0x29, 0x22, - 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a + 0x72, 0x6e, 0x20, 0x22, 0x28, 0x22, 0x2e, 0x2e, 0x72, 0x65, 0x74, 0x2e, + 0x2e, 0x22, 0x29, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a }; -unsigned int lua_function_lua_len = 14479; +unsigned int lua_function_lua_len = 14483; diff --git a/lib/tolua++/src/bin/lua/basic.lua b/lib/tolua++/src/bin/lua/basic.lua index b5788f2be..425cb6861 100644 --- a/lib/tolua++/src/bin/lua/basic.lua +++ b/lib/tolua++/src/bin/lua/basic.lua @@ -66,6 +66,8 @@ _global_enums = {} -- List of auto renaming _renaming = {} + +_enums = {} function appendrenaming (s) local b,e,old,new = strfind(s,"%s*(.-)%s*@%s*(.-)%s*$") if not b then @@ -146,7 +148,7 @@ function typevar(type) end -- is enum -function isenum (type) +function isenumtype (type) return _enums[type] end diff --git a/lib/tolua++/src/bin/lua/declaration.lua b/lib/tolua++/src/bin/lua/declaration.lua index 5a2adfed9..26ceeba22 100644 --- a/lib/tolua++/src/bin/lua/declaration.lua +++ b/lib/tolua++/src/bin/lua/declaration.lua @@ -227,10 +227,10 @@ function classDeclaration:outchecktype (narg) --else return '!tolua_istable(tolua_S,'..narg..',0,&tolua_err)' --end + elseif isenumtype(self.type) ~= nil then + return '!tolua_is'..self.type..'(tolua_S,'..narg..','..def..',&tolua_err)' elseif t then return '!tolua_is'..t..'(tolua_S,'..narg..','..def..',&tolua_err)' - elseif isenum(self.type) then - return '!tolua_is'..self.type..'(tolua_S,'..narg..','..def..',&tolua_err)' else local is_func = get_is_function(self.type) if self.ptr == '&' or self.ptr == '' then diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index ef3a9574c..09b22a094 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -49,7 +49,7 @@ function classEnumerate:print (ident,close) end function emitenumprototype(type) - output("int tolua_is" .. string.gsub(type,"::","_") .. " (lua_State* L, int lo, const char * type, int def, tolua_Error* err);") + output("int tolua_is" .. string.gsub(type,"::","_") .. " (lua_State* L, int lo, int def, tolua_Error* err);") end _global_output_enums = {} @@ -58,7 +58,7 @@ _global_output_enums = {} function classEnumerate:supcode () if _global_output_enums[self.name] == nil then _global_output_enums[self.name] = 1 - output("int tolua_is" .. string.gsub(self.name,"::","_") .. " (lua_State* L, int lo, const char * type, int def, tolua_Error* err)") + output("int tolua_is" .. string.gsub(self.name,"::","_") .. " (lua_State* L, int lo, int def, tolua_Error* err)") output("{") output("if (!tolua_isnumber(L,lo,def,err)) return 0;") output("lua_Number val = tolua_tonumber(L,lo,def);") @@ -134,7 +134,7 @@ function Enumerate (n,b,varname) e.min = min e.max = max if n ~= "" then - _enums[n] = 1 + _enums[n] = true Typedef("int "..n) end return _Enumerate(e, varname) diff --git a/lib/tolua++/src/bin/lua/function.lua b/lib/tolua++/src/bin/lua/function.lua index ad1ab4225..3b6b53c5e 100644 --- a/lib/tolua++/src/bin/lua/function.lua +++ b/lib/tolua++/src/bin/lua/function.lua @@ -58,7 +58,7 @@ function classFunction:supcode (local_constructor) if self.args[1].type ~= 'void' then local i=1 while self.args[i] do - if isenum(self.args[i].type) then + if isenumtype(self.args[i].type) then emitenumprototype(self.args[i].type) end i = i+1 -- cgit v1.2.3 From 20fc7d6aea1831da215beaa8f892557a2b8244d8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Mar 2014 22:40:59 +0100 Subject: Updated the tolua++ executable for Win builds. --- src/Bindings/tolua++.exe | Bin 484864 -> 185856 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/src/Bindings/tolua++.exe b/src/Bindings/tolua++.exe index e5cec6d78..86ab1d70f 100644 Binary files a/src/Bindings/tolua++.exe and b/src/Bindings/tolua++.exe differ -- cgit v1.2.3 From c9163d39f74302fc943e6c9b3b8442061a5f089e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 21 Mar 2014 22:53:46 +0100 Subject: Implemented faster upscaling using templates. Fixes #819. --- src/Generating/BioGen.cpp | 16 ++++++------- src/Generating/CompoGen.cpp | 4 ++-- src/Generating/HeiGen.cpp | 2 +- src/Generating/Noise3DGenerator.cpp | 2 +- src/Generating/StructGen.cpp | 4 ++-- src/LinearUpscale.h | 46 +++++++++++++++++++------------------ 6 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 967deba6a..32a687201 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -371,8 +371,8 @@ void cBioGenDistortedVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::B Distort(BaseX + x * 4, BaseZ + z * 4, DistortX[4 * x][4 * z], DistortZ[4 * x][4 * z]); } - LinearUpscale2DArrayInPlace(&DistortX[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); - LinearUpscale2DArrayInPlace(&DistortZ[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); + LinearUpscale2DArrayInPlace(&DistortX[0][0]); + LinearUpscale2DArrayInPlace(&DistortZ[0][0]); for (int z = 0; z < cChunkDef::Width; z++) { @@ -477,8 +477,8 @@ void cBioGenMultiStepMap::DecideOceanLandMushroom(int a_ChunkX, int a_ChunkZ, cC { Distort(BaseX + x * 4, BaseZ + z * 4, DistortX[4 * x][4 * z], DistortZ[4 * x][4 * z], DistortSize); } - LinearUpscale2DArrayInPlace(&DistortX[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); - LinearUpscale2DArrayInPlace(&DistortZ[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); + LinearUpscale2DArrayInPlace(&DistortX[0][0]); + LinearUpscale2DArrayInPlace(&DistortZ[0][0]); // Prepare a 9x9 area of neighboring cell seeds // (assuming that 7x7 cell area is larger than a chunk being generated) @@ -651,8 +651,8 @@ void cBioGenMultiStepMap::BuildTemperatureHumidityMaps(int a_ChunkX, int a_Chunk HumidityMap[x + 17 * z] = NoiseH; } // for x } // for z - LinearUpscale2DArrayInPlace(TemperatureMap, 17, 17, 8, 8); - LinearUpscale2DArrayInPlace(HumidityMap, 17, 17, 8, 8); + LinearUpscale2DArrayInPlace<17, 17, 8, 8>(TemperatureMap); + LinearUpscale2DArrayInPlace<17, 17, 8, 8>(HumidityMap); // Re-map into integral values in [0 .. 255] range: for (size_t idx = 0; idx < ARRAYCOUNT(a_TemperatureMap); idx++) @@ -778,8 +778,8 @@ void cBioGenTwoLevel::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap DistortZ[4 * x][4 * z] = BlockZ + (int)(64 * NoiseZ); } - LinearUpscale2DArrayInPlace(&DistortX[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); - LinearUpscale2DArrayInPlace(&DistortZ[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); + LinearUpscale2DArrayInPlace(&DistortX[0][0]); + LinearUpscale2DArrayInPlace(&DistortZ[0][0]); // Apply distortion to each block coord, then query the voronoi maps for biome group and biome index and choose biome based on that: for (int z = 0; z < cChunkDef::Width; z++) diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp index 60356fe46..578bb2481 100644 --- a/src/Generating/CompoGen.cpp +++ b/src/Generating/CompoGen.cpp @@ -566,7 +566,7 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc) m_Noise2.IntNoise3DInt(BaseX + INTERPOL_X * x, 0, BaseZ + INTERPOL_Z * z) / 256; } // for x, z - FloorLo[] - LinearUpscale2DArrayInPlace(FloorLo, 17, 17, INTERPOL_X, INTERPOL_Z); + LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorLo); // Interpolate segments: for (int Segment = 0; Segment < MaxHeight; Segment += SEGMENT_HEIGHT) @@ -579,7 +579,7 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc) m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / 256; } // for x, z - FloorLo[] - LinearUpscale2DArrayInPlace(FloorHi, 17, 17, INTERPOL_X, INTERPOL_Z); + LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorHi); // Interpolate between FloorLo and FloorHi: for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp index 10710b4a1..3621421c2 100644 --- a/src/Generating/HeiGen.cpp +++ b/src/Generating/HeiGen.cpp @@ -428,7 +428,7 @@ void cHeiGenBiomal::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMa Height[x + 17 * z] = GetHeightAt(x, z, a_ChunkX, a_ChunkZ, Biomes); } } - LinearUpscale2DArrayInPlace(Height, 17, 17, STEPX, STEPZ); + LinearUpscale2DArrayInPlace<17, 17, STEPX, STEPZ>(Height); // Copy into the heightmap for (int z = 0; z < cChunkDef::Width; z++) diff --git a/src/Generating/Noise3DGenerator.cpp b/src/Generating/Noise3DGenerator.cpp index afa40c647..15a588d45 100644 --- a/src/Generating/Noise3DGenerator.cpp +++ b/src/Generating/Noise3DGenerator.cpp @@ -420,7 +420,7 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ) } } // Linear-interpolate this XZ floor: - LinearUpscale2DArrayInPlace(CurFloor, 17, 17, UPSCALE_X, UPSCALE_Z); + LinearUpscale2DArrayInPlace<17, 17, UPSCALE_X, UPSCALE_Z>(CurFloor); } // Finish the 3D linear interpolation by interpolating between each XZ-floors on the Y axis diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index 3cc8a09c3..db9d5578c 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -578,7 +578,7 @@ void cStructGenDirectOverhangs::GenFinish(cChunkDesc & a_ChunkDesc) m_Noise2.IntNoise3DInt(BaseX + INTERPOL_X * x, BaseY, BaseZ + INTERPOL_Z * z) / 256; } // for x, z - FloorLo[] - LinearUpscale2DArrayInPlace(FloorLo, 17, 17, INTERPOL_X, INTERPOL_Z); + LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorLo); // Interpolate segments: for (int Segment = BaseY; Segment < MaxHeight; Segment += SEGMENT_HEIGHT) @@ -591,7 +591,7 @@ void cStructGenDirectOverhangs::GenFinish(cChunkDesc & a_ChunkDesc) m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / 256; } // for x, z - FloorLo[] - LinearUpscale2DArrayInPlace(FloorHi, 17, 17, INTERPOL_X, INTERPOL_Z); + LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorHi); // Interpolate between FloorLo and FloorHi: for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) diff --git a/src/LinearUpscale.h b/src/LinearUpscale.h index b337b3219..0b04408cf 100644 --- a/src/LinearUpscale.h +++ b/src/LinearUpscale.h @@ -18,7 +18,7 @@ Therefore, there is no cpp file. InPlace upscaling works on a single array and assumes that the values to work on have already been interspersed into the array to the cell boundaries. -Specifically, a_Array[x * a_AnchorStepX + y * a_AnchorStepY] contains the anchor value. +Specifically, a_Array[x * AnchorStepX + y * AnchorStepY] contains the anchor value. Regular upscaling takes two arrays and "moves" the input from src to dst; src is expected packed. */ @@ -29,46 +29,48 @@ Regular upscaling takes two arrays and "moves" the input from src to dst; src is /** Linearly interpolates values in the array between the equidistant anchor points (upscales). Works in-place (input is already present at the correct output coords) +Uses templates to make it possible for the compiler to further optimizer the loops */ -template void LinearUpscale2DArrayInPlace( - TYPE * a_Array, - int a_SizeX, int a_SizeY, // Dimensions of the array - int a_AnchorStepX, int a_AnchorStepY // Distances between the anchor points in each direction -) +template< + int SizeX, int SizeY, // Dimensions of the array + int AnchorStepX, int AnchorStepY, + typename TYPE +> +void LinearUpscale2DArrayInPlace(TYPE * a_Array) { // First interpolate columns where the anchor points are: - int LastYCell = a_SizeY - a_AnchorStepY; - for (int y = 0; y < LastYCell; y += a_AnchorStepY) + int LastYCell = SizeY - AnchorStepY; + for (int y = 0; y < LastYCell; y += AnchorStepY) { - int Idx = a_SizeX * y; - for (int x = 0; x < a_SizeX; x += a_AnchorStepX) + int Idx = SizeX * y; + for (int x = 0; x < SizeX; x += AnchorStepX) { TYPE StartValue = a_Array[Idx]; - TYPE EndValue = a_Array[Idx + a_SizeX * a_AnchorStepY]; + TYPE EndValue = a_Array[Idx + SizeX * AnchorStepY]; TYPE Diff = EndValue - StartValue; - for (int CellY = 1; CellY < a_AnchorStepY; CellY++) + for (int CellY = 1; CellY < AnchorStepY; CellY++) { - a_Array[Idx + a_SizeX * CellY] = StartValue + Diff * CellY / a_AnchorStepY; + a_Array[Idx + SizeX * CellY] = StartValue + Diff * CellY / AnchorStepY; } // for CellY - Idx += a_AnchorStepX; + Idx += AnchorStepX; } // for x } // for y // Now interpolate in rows, each row has values in the anchor columns - int LastXCell = a_SizeX - a_AnchorStepX; - for (int y = 0; y < a_SizeY; y++) + int LastXCell = SizeX - AnchorStepX; + for (int y = 0; y < SizeY; y++) { - int Idx = a_SizeX * y; - for (int x = 0; x < LastXCell; x += a_AnchorStepX) + int Idx = SizeX * y; + for (int x = 0; x < LastXCell; x += AnchorStepX) { TYPE StartValue = a_Array[Idx]; - TYPE EndValue = a_Array[Idx + a_AnchorStepX]; + TYPE EndValue = a_Array[Idx + AnchorStepX]; TYPE Diff = EndValue - StartValue; - for (int CellX = 1; CellX < a_AnchorStepX; CellX++) + for (int CellX = 1; CellX < AnchorStepX; CellX++) { - a_Array[Idx + CellX] = StartValue + CellX * Diff / a_AnchorStepX; + a_Array[Idx + CellX] = StartValue + CellX * Diff / AnchorStepX; } // for CellY - Idx += a_AnchorStepX; + Idx += AnchorStepX; } } } -- cgit v1.2.3 From 830a9c3bb46485f9d961078cff6c7055f4e9d569 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 22 Mar 2014 08:16:07 -0700 Subject: FIrst attempt at adding override support to tolua --- lib/tolua++/src/bin/lua/container.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/tolua++/src/bin/lua/container.lua b/lib/tolua++/src/bin/lua/container.lua index 2d11db7df..97e7b58fd 100644 --- a/lib/tolua++/src/bin/lua/container.lua +++ b/lib/tolua++/src/bin/lua/container.lua @@ -606,14 +606,15 @@ function classContainer:doparse (s) -- try function do --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w])%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*") - local b,e,decl,arg,const,virt = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)%s*(=?%s*0?)%s*;%s*") + local b,e,decl,arg,const,virt = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)%s*o?v?e?r?i?d?e?%s*(=?%s*0?)%s*;%s*") + warning("trace" .. b .. "," .. e "," .. decl) if not b then -- try function with template - b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w]%b<>)%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*") + b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w]%b<>)%s*(%b())%s*(c?o?n?s?t?)%s*o?v?e?r?i?d?e?%s*=?%s*0?%s*;%s*") end if not b then -- try a single letter function name - b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*;%s*") + b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*o?v?e?r?i?d?e?%s*;%s*") end if not b then -- try function pointer @@ -636,11 +637,11 @@ function classContainer:doparse (s) -- try inline function do - local b,e,decl,arg,const = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)[^;{]*%b{}%s*;?%s*") + local b,e,decl,arg,const = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)%s*o?v?e?r?i?d?e?[^;{]*%b{}%s*;?%s*") --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w>])%s*(%b())%s*(c?o?n?s?t?)[^;]*%b{}%s*;?%s*") if not b then -- try a single letter function name - b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?).-%b{}%s*;?%s*") + b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*o?v?e?r?i?d?e?.-%b{}%s*;?%s*") end if b then _curr_code = strsub(s,b,e) -- cgit v1.2.3 From 0cfb12f0d11b40d48974177f01494758ed800ff9 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 22 Mar 2014 08:30:49 -0700 Subject: Added Additonal check for xxd existance --- lib/tolua++/CMakeLists.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/tolua++/CMakeLists.txt b/lib/tolua++/CMakeLists.txt index 75a301a53..7e7498411 100644 --- a/lib/tolua++/CMakeLists.txt +++ b/lib/tolua++/CMakeLists.txt @@ -7,25 +7,28 @@ include_directories ("${PROJECT_SOURCE_DIR}/include/") include_directories ("${PROJECT_SOURCE_DIR}/../") include_directories ("${PROJECT_SOURCE_DIR}") -if(UNIX) +find_program(XXD_EXECUTABLE xxd) + +if(NOT XXD_EXECUTABLE STREQUAL "xxd-NOTFOUND") add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h - COMMAND xxd -i lua/basic.lua | sed 's/unsigned char/static const unsigned char/g' >basic_lua.h + COMMAND ${XXD_EXECUTABLE} -i lua/basic.lua | sed 's/unsigned char/static const unsigned char/g' >basic_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/basic.lua) add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h - COMMAND xxd -i lua/enumerate.lua | sed 's/unsigned char/static const unsigned char/g' >enumerate_lua.h + COMMAND ${XXD_EXECUTABLE} -i lua/enumerate.lua | sed 's/unsigned char/static const unsigned char/g' >enumerate_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/enumerate.lua) add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h - COMMAND xxd -i lua/function.lua | sed 's/unsigned char/static const unsigned char/g' >function_lua.h + COMMAND ${XXD_EXECUTABLE} -i lua/function.lua | sed 's/unsigned char/static const unsigned char/g' >function_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/function.lua) add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/declaration_lua.h - COMMAND xxd -i lua/declaration.lua | sed 's/unsigned char/static const unsigned char/g' >declaration_lua.h + COMMAND ${XXD_EXECUTABLE} -i lua/declaration.lua | sed 's/unsigned char/static const unsigned char/g' >declaration_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/declaration.lua) set_property(SOURCE src/bin/toluabind.c APPEND PROPERTY OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h ${PROJECT_SOURCE_DIR}/src/bin/declaration_lua.h) - message(hello) +else() + message("xxd not found, changes to tolua scripts will be ignored") endif() -- cgit v1.2.3 From 5653997bcc1f04936f07d220999b8339661cbbb7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 22 Mar 2014 08:43:54 -0700 Subject: Added override specifier to functions declared in cWorld --- src/World.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/World.h b/src/World.h index 46aece18f..b85171e4e 100644 --- a/src/World.h +++ b/src/World.h @@ -126,15 +126,15 @@ public: int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; } - virtual Int64 GetWorldAge (void) const { return m_WorldAge; } // override, cannot specify due to tolua - virtual Int64 GetTimeOfDay(void) const { return m_TimeOfDay; } // override, cannot specify due to tolua + virtual Int64 GetWorldAge (void) const override { return m_WorldAge; } + virtual Int64 GetTimeOfDay(void) const override { return m_TimeOfDay; } void SetTicksUntilWeatherChange(int a_WeatherInterval) { m_WeatherInterval = a_WeatherInterval; } - virtual void SetTimeOfDay(Int64 a_TimeOfDay) // override, cannot specify due to tolua + virtual void SetTimeOfDay(Int64 a_TimeOfDay) override { m_TimeOfDay = a_TimeOfDay; m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0; @@ -430,10 +430,10 @@ public: // tolua_begin /** Spawns item pickups for each item in the list. May compress pickups if too many entities: */ - virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false); // override; cannot specify it here due to tolua + virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false) override; /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified: */ - virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false); // override; cannot specify it here due to tolua + virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false) override; /** Spawns an falling block entity at the given position. It returns the UniqueID of the spawned falling block. */ int SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta); @@ -457,7 +457,7 @@ public: // tolua_begin bool DigBlock (int a_X, int a_Y, int a_Z); - virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player); // override, cannot specify due to tolua + virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player) override; double GetSpawnX(void) const { return m_SpawnX; } double GetSpawnY(void) const { return m_SpawnY; } @@ -508,7 +508,7 @@ public: | esWitherBirth | TBD | | esPlugin | void * | */ - virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); // tolua_export // override, cannot specify due to tolua + virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData) override; // tolua_export /** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */ bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Exported in ManualBindings.cpp @@ -707,7 +707,7 @@ public: bool IsBlockDirectlyWatered(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */ - virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType); // tolua_export // override, cannot specify due to tolua + virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) override; // tolua_export int SpawnMobFinalize(cMonster* a_Monster); /** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise */ -- cgit v1.2.3 From fd8e5bf551db4c138b8c2ebe8e464c85603c0ef2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 23 Mar 2014 20:54:37 +0100 Subject: Updated the ToLua windows executable. --- src/Bindings/tolua++.exe | Bin 185856 -> 200192 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/src/Bindings/tolua++.exe b/src/Bindings/tolua++.exe index 86ab1d70f..1e3cc7789 100644 Binary files a/src/Bindings/tolua++.exe and b/src/Bindings/tolua++.exe differ -- cgit v1.2.3 From 83d0c6d6a7358bc18176d4e5432d635f9ffdfd55 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 23 Mar 2014 20:37:23 +0000 Subject: Fixed bad cmake document interpretation Docs say: "If nothing is found, the result will be -NOTFOUND" --- lib/tolua++/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tolua++/CMakeLists.txt b/lib/tolua++/CMakeLists.txt index 7e7498411..e5c8ce3e8 100644 --- a/lib/tolua++/CMakeLists.txt +++ b/lib/tolua++/CMakeLists.txt @@ -9,7 +9,7 @@ include_directories ("${PROJECT_SOURCE_DIR}") find_program(XXD_EXECUTABLE xxd) -if(NOT XXD_EXECUTABLE STREQUAL "xxd-NOTFOUND") +if(NOT XXD_EXECUTABLE STREQUAL "XXD_EXECUTABLE-NOTFOUND") add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h COMMAND ${XXD_EXECUTABLE} -i lua/basic.lua | sed 's/unsigned char/static const unsigned char/g' >basic_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ -- cgit v1.2.3 From f622f4317c76aa287649da965456562a32bce41b Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 23 Mar 2014 22:32:45 +0000 Subject: Implemented lilypad placement --- src/Blocks/BlockHandler.cpp | 2 ++ src/Blocks/BlockLilypad.h | 84 +++++++++++++++++++++++++++++++++++++++++++++ src/ClientHandle.cpp | 12 ++++--- src/Items/ItemBucket.h | 8 ++--- 4 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 src/Blocks/BlockLilypad.h diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 4f74e2f45..7fd8c183c 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -41,6 +41,7 @@ #include "BlockIce.h" #include "BlockLadder.h" #include "BlockLeaves.h" +#include "BlockLilypad.h" #include "BlockNewLeaves.h" #include "BlockLever.h" #include "BlockMelon.h" @@ -142,6 +143,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_LAPIS_ORE: return new cBlockOreHandler (a_BlockType); case E_BLOCK_LAVA: return new cBlockLavaHandler (a_BlockType); case E_BLOCK_LEAVES: return new cBlockLeavesHandler (a_BlockType); + case E_BLOCK_LILY_PAD: return new cBlockLilypadHandler (a_BlockType); case E_BLOCK_LIT_FURNACE: return new cBlockFurnaceHandler (a_BlockType); case E_BLOCK_LOG: return new cBlockSidewaysHandler (a_BlockType); case E_BLOCK_MELON: return new cBlockMelonHandler (a_BlockType); diff --git a/src/Blocks/BlockLilypad.h b/src/Blocks/BlockLilypad.h new file mode 100644 index 000000000..3db280d80 --- /dev/null +++ b/src/Blocks/BlockLilypad.h @@ -0,0 +1,84 @@ + +#pragma once + +#include "BlockHandler.h" +#include "../Entities/Player.h" +#include "Vector3.h" +#include "../LineBlockTracer.h" + + + + + +class cBlockLilypadHandler : + public cBlockHandler +{ + typedef cBlockHandler super; + +public: + cBlockLilypadHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + + } + + virtual bool GetPlacementBlockTypeMeta( + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + if (a_BlockFace > 0) + { + return false; + } + + class cCallbacks : + public cBlockTracer::cCallbacks + { + public: + cCallbacks(void) : + m_HasHitFluid(false) + { + } + + virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override + { + if (IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType)) + { + if ((a_BlockMeta != 0) || (a_EntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is for AddFaceDir below + { + return false; + } + m_HasHitFluid = true; + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, (eBlockFace)a_EntryFace); + m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); + return true; + } + return false; + } + + Vector3i m_Pos; + bool m_HasHitFluid; + + } Callbacks; + + cLineBlockTracer Tracer(*a_Player->GetWorld(), Callbacks); + Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector()); + Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5); + + Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z); + + if (Callbacks.m_HasHitFluid) + { + a_Player->GetWorld()->SetBlock(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z, E_BLOCK_LILY_PAD, 0); + } + + return false; + } +}; + + + + diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 46c10ae82..2c47faa65 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -988,7 +988,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Equipped.m_ItemType); - if (ItemHandler->IsPlaceable() && (a_BlockFace > -1)) + if (ItemHandler->IsPlaceable() && ((a_BlockFace > -1) || (Equipped.m_ItemType == E_BLOCK_LILY_PAD))) { HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); } @@ -1026,7 +1026,8 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler) { - if (a_BlockFace < 0) + BLOCKTYPE EquippedBlock = (BLOCKTYPE)(m_Player->GetEquippedItem().m_ItemType); + if ((a_BlockFace < 0) && (EquippedBlock != E_BLOCK_LILY_PAD)) { // Clicked in air return; @@ -1036,7 +1037,6 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e BLOCKTYPE ClickedBlock; NIBBLETYPE ClickedBlockMeta; - BLOCKTYPE EquippedBlock = (BLOCKTYPE)(m_Player->GetEquippedItem().m_ItemType); NIBBLETYPE EquippedBlockDamage = (NIBBLETYPE)(m_Player->GetEquippedItem().m_ItemDamage); if ((a_BlockY < 0) || (a_BlockY >= cChunkDef::Height)) @@ -1085,7 +1085,10 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e } else { - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); + if (EquippedBlock != E_BLOCK_LILY_PAD) + { + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); + } if ((a_BlockY < 0) || (a_BlockY >= cChunkDef::Height)) { @@ -1106,6 +1109,7 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e else { if ( + (EquippedBlock != E_BLOCK_LILY_PAD) && !BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision() && !BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision(m_Player, PlaceMeta) ) diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 72cb8fa0a..68c89dd85 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -172,12 +172,12 @@ public: virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override { - if (a_BlockMeta != 0) // Even if it was a water block it would not be a source. - { - return false; - } if (IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType)) { + if (a_BlockMeta != 0) // GetBlockFromTrace is called for scooping up fluids; the hit block should be a source + { + return false; + } m_HasHitFluid = true; m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); return true; -- cgit v1.2.3 From 2343b0dfbe12f6db76de1b4ed03cd902975d77b3 Mon Sep 17 00:00:00 2001 From: narroo Date: Sun, 23 Mar 2014 22:11:01 -0400 Subject: Added MetaRotate/Mirror Support for a number of classes. --- src/Blocks/BlockChest.h | 4 +- src/Blocks/BlockDoor.cpp | 75 +++++++++++++++++++++ src/Blocks/BlockDoor.h | 66 ++---------------- src/Blocks/BlockFurnace.h | 8 +-- src/Blocks/BlockHopper.h | 21 +++++- src/Blocks/BlockLadder.h | 4 +- src/Blocks/BlockLever.h | 37 +++++++++- src/Blocks/BlockPumpkin.h | 6 +- src/Blocks/BlockRail.h | 135 +++++++++++++++++++++++++++++++++++++ src/Blocks/BlockRedstoneRepeater.h | 6 +- src/Blocks/BlockSlab.h | 11 ++- src/Blocks/BlockTrapdoor.h | 6 +- 12 files changed, 295 insertions(+), 84 deletions(-) diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 30588d8fc..890b5b933 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -11,11 +11,11 @@ class cBlockChestHandler : - public cMetaRotater + public cMetaRotater { public: cBlockChestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index 4e38ef334..c027daed2 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -110,3 +110,78 @@ const char * cBlockDoorHandler::GetStepSound(void) + +NIBBLETYPE cBlockDoorHandler::MetaRotateCCW(NIBBLETYPE a_Meta) +{ + if (a_Meta & 0x08) + { + return a_Meta; + } + else + { + return super::MetaRotateCCW(a_Meta); + } +} + + + +NIBBLETYPE cBlockDoorHandler::MetaRotateCW(NIBBLETYPE a_Meta) +{ + if (a_Meta & 0x08) + { + return a_Meta; + } + else + { + return super::MetaRotateCW(a_Meta); + } +} + + + +NIBBLETYPE cBlockDoorHandler::MetaMirrorXY(NIBBLETYPE a_Meta) +{ + // Top bit (0x08) contains door panel type (Top/Bottom panel) Only Bottom panels contain position data + // Return a_Meta if panel is a top panel (0x08 bit is set to 1) + LOG("Test MirrorXY"); + if (a_Meta & 0x08) return a_Meta; + + // Holds open/closed meta data. 0x0C == 1100. + NIBBLETYPE OtherMeta = a_Meta & 0x0C; + + // Mirrors according to a table. 0x03 == 0011. + switch (a_Meta & 0x03) + { + case 0x03: return 0x01 + OtherMeta; // South -> North + case 0x01: return 0x03 + OtherMeta; // North -> South + } + + // Not Facing North or South; No change. + return a_Meta; +} + + + +NIBBLETYPE cBlockDoorHandler::MetaMirrorYZ(NIBBLETYPE a_Meta) +{ + // Top bit (0x08) contains door panel type (Top/Bottom panel) Only Bottom panels contain position data + // Return a_Meta if panel is a top panel (0x08 bit is set to 1) + LOG("Test MirrorYZ"); + if (a_Meta & 0x08) return a_Meta; + + // Holds open/closed meta data. 0x0C == 1100. + NIBBLETYPE OtherMeta = a_Meta & 0x0C; + + // Mirrors according to a table. 0x03 == 0011. + switch (a_Meta & 0x03) + { + case 0x00: return 0x02 + OtherMeta; // West -> East + case 0x02: return 0x00 + OtherMeta; // East -> West + } + + // Not Facing North or South; No change. + return a_Meta; +} + + + diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 981774c17..066e1ab28 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -21,6 +21,10 @@ public: virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override; virtual const char * GetStepSound(void) override; + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override; + virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override; + virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override; + virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override; virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, @@ -142,14 +146,14 @@ public: static void ChangeDoor(cChunkInterface & a_ChunkInterface, int a_X, int a_Y, int a_Z) { NIBBLETYPE OldMetaData = a_ChunkInterface.GetBlockMeta(a_X, a_Y, a_Z); - + a_ChunkInterface.SetBlockMeta(a_X, a_Y, a_Z, ChangeStateMetaData(OldMetaData)); - + if (OldMetaData & 8) { // Current block is top of the door BLOCKTYPE BottomBlock = a_ChunkInterface.GetBlock(a_X, a_Y - 1, a_Z); - NIBBLETYPE BottomMeta = a_ChunkInterface.GetBlockMeta(a_X, a_Y - 1, a_Z); + NIBBLETYPE BottomMeta = a_ChunkInterface.GetBlockMeta(a_X, a_Y - 1, a_Z); if (IsDoor(BottomBlock) && !(BottomMeta & 8)) { @@ -168,62 +172,6 @@ public: } } } - - - virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override - { - if (a_Meta & 0x08) - { - return a_Meta; - } - else - { - return super::MetaRotateCCW(a_Meta); - } - } - - - - virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override - { - if (a_Meta & 0x08) - { - return a_Meta; - } - else - { - return super::MetaRotateCW(a_Meta); - } - } - - - - virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override - { - if (a_Meta & 0x08) - { - return a_Meta; - } - else - { - return super::MetaMirrorXY(a_Meta); - } - } - - - - virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override - { - if (a_Meta & 0x08) - { - return a_Meta; - } - else - { - return super::MetaMirrorYZ(a_Meta); - } - } - } ; diff --git a/src/Blocks/BlockFurnace.h b/src/Blocks/BlockFurnace.h index 27ef2689f..c7f8ff8d2 100644 --- a/src/Blocks/BlockFurnace.h +++ b/src/Blocks/BlockFurnace.h @@ -4,17 +4,17 @@ #include "BlockEntity.h" #include "../World.h" #include "../Piston.h" - +#include "MetaRotater.h" class cBlockFurnaceHandler : - public cBlockEntityHandler + public cMetaRotater { public: - cBlockFurnaceHandler(BLOCKTYPE a_BlockType) : - cBlockEntityHandler(a_BlockType) + cBlockFurnaceHandler(BLOCKTYPE a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockHopper.h b/src/Blocks/BlockHopper.h index 59b84aa0e..610296529 100644 --- a/src/Blocks/BlockHopper.h +++ b/src/Blocks/BlockHopper.h @@ -3,16 +3,16 @@ // Declares the cBlockHopperHandler class representing the handler for the Hopper block - +#include "MetaRotator.h" class cBlockHopperHandler : - public cBlockEntityHandler + public cMetaRotater { public: cBlockHopperHandler(BLOCKTYPE a_BlockType) - : cBlockEntityHandler(a_BlockType) + : cMetaRotater(a_BlockType) { } @@ -39,6 +39,21 @@ public: } return true; } + + + virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override + { + // Bit 0x08 is a flag. Lowest three bits are position. 0x08 == 1000 + NIBBLETYPE OtherMeta = a_Meta & 0x08; + // Mirrors defined by by a table. (Source, mincraft.gamepedia.com) 0x07 == 0111 + switch (a_Meta & 0x07) + { + case 0x00: return 0x01 + OtherMeta; // Down -> Up + case 0x01: return 0x00 + OtherMeta; // Up -> Down + } + // Not Facing Up or Down; No change. + return a_Meta; + } } ; diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h index a3e9edc6b..12408759e 100644 --- a/src/Blocks/BlockLadder.h +++ b/src/Blocks/BlockLadder.h @@ -9,11 +9,11 @@ class cBlockLadderHandler : - public cBlockHandler + public cMetaRotater { public: cBlockLadderHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index ef6e102cd..ad2ae29e5 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -1,17 +1,18 @@ #pragma once #include "BlockHandler.h" - +#include "MetaRotator.h" class cBlockLeverHandler : - public cBlockHandler + public cMetaRotator { + typedef cMetaRotator super; public: cBlockLeverHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotator(a_BlockType) { } @@ -104,6 +105,36 @@ public: return (a_RelY > 0) && cBlockInfo::IsSolid(BlockIsOn); } + + + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override + { + switch (a_Meta) + { + case 0x00: return 0x07; // Ceiling rotation + case 0x07: return 0x00; + + case 0x05: return 0x06; // Ground rotation + case 0x06: return 0x05; + + default: return super::MetaRotateCCW(a_Meta); // Wall Rotation + } + } + + + virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override + { + switch (a_Meta) + { + case 0x00: return 0x07; // Ceiling rotation + case 0x07: return 0x00; + + case 0x05: return 0x06; // Ground rotation + case 0x06: return 0x05; + + default: return super::MetaRotateCCW(a_Meta); // Wall Rotation + } + } } ; diff --git a/src/Blocks/BlockPumpkin.h b/src/Blocks/BlockPumpkin.h index 349f52605..ac2b9817a 100644 --- a/src/Blocks/BlockPumpkin.h +++ b/src/Blocks/BlockPumpkin.h @@ -1,16 +1,16 @@ #pragma once #include "BlockHandler.h" - +#include "MetaRotator.h" class cBlockPumpkinHandler : - public cBlockHandler + public cMetaRotator { public: cBlockPumpkinHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 07e9814cd..f56ec7152 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -434,6 +434,141 @@ public: } return true; } + + + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override + { + // Bit 0x08 is a flag when a_Meta is in the range 0x00--0x05 and 0x0A--0x0F. + // Bit 0x08 specifies direction when a_Meta is in the range 0x06-0x09. + if ((a_Meta < 0x06) || (a_Meta > 0x09)) + { + // Save powered rail flag. + NIBBLETYPE OtherMeta = a_Meta & 0x08; + // Rotates according to table; 0x07 == 0111. + // Rails can either be flat (North/South) or Ascending (Asc. East) + switch (a_Meta & 0x07) + { + case 0x00: return 0x01 + OtherMeta; // North/South -> East/West + case 0x01: return 0x00 + OtherMeta; // East/West -> North/South + + case 0x02: return 0x04 + OtherMeta; // Asc. East -> Asc. North + case 0x04: return 0x03 + OtherMeta; // Asc. North -> Asc. West + case 0x03: return 0x05 + OtherMeta; // Asc. West -> Asc. South + case 0x05: return 0x02 + OtherMeta; // Asc. South -> Asc. East + } + } + else + { + switch (a_Meta) + { + // Corner Directions + case 0x06: return 0x09; // Northwest Cnr. -> Southwest Cnr. + case 0x07: return 0x06; // Northeast Cnr. -> Northwest Cnr. + case 0x08: return 0x07; // Southeast Cnr. -> Northeast Cnr. + case 0x09: return 0x08; // Southwest Cnr. -> Southeast Cnr. + } + } + // To avoid a compiler warning; + return a_Meta; + } + + + virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override + { + // Bit 0x08 is a flag for value in the range 0x00--0x05 and specifies direction for values withint 0x006--0x09. + if ((a_Meta < 0x06) || (a_Meta > 0x09)) + { + // Save powered rail flag. + NIBBLETYPE OtherMeta = a_Meta & 0x08; + // Rotates according to table; 0x07 == 0111. + // Rails can either be flat (North/South) or Ascending (Asc. East) + switch (a_Meta & 0x07) + { + case 0x00: return 0x01 + OtherMeta; // North/South -> East/West + case 0x01: return 0x00 + OtherMeta; // East/West -> North/South + + case 0x02: return 0x05 + OtherMeta; // Asc. East -> Asc. South + case 0x05: return 0x03 + OtherMeta; // Asc. South -> Asc. West + case 0x03: return 0x04 + OtherMeta; // Asc. West -> Asc. North + case 0x04: return 0x02 + OtherMeta; // Asc. North -> Asc. East + } + } + else + { + switch (a_Meta) + { + // Corner Directions + case 0x06: return 0x07; // Northwest Cnr. -> Northeast Cnr. + case 0x07: return 0x08; // Northeast Cnr. -> Southeast Cnr. + case 0x08: return 0x09; // Southeast Cnr. -> Southwest Cnr. + case 0x09: return 0x06; // Southwest Cnr. -> Northwest Cnr. + } + } + // To avoid a compiler warning; + return a_Meta; + } + + + virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override + { + // Bit 0x08 is a flag for value in the range 0x00--0x05 and specifies direction for values withint 0x006--0x09. + if ((a_Meta < 0x06) || (a_Meta > 0x09)) + { + // Save powered rail flag. + NIBBLETYPE OtherMeta = a_Meta & 0x08; + // Mirrors according to table; 0x07 == 0111. + // Rails can either be flat (North/South) or Ascending (Asc. East) + switch (a_Meta & 0x07) + { + case 0x05: return 0x04 + OtherMeta; // Asc. South -> Asc. North + case 0x04: return 0x05 + OtherMeta; // Asc. North -> Asc. South + } + } + else + { + switch (a_Meta) + { + // Corner Directions + case 0x06: return 0x09; // Northwest Cnr. -> Southwest Cnr. + case 0x07: return 0x08; // Northeast Cnr. -> Southeast Cnr. + case 0x08: return 0x07; // Southeast Cnr. -> Northeast Cnr. + case 0x09: return 0x06; // Southwest Cnr. -> Northwest Cnr. + } + } + // To avoid a compiler warning; + return a_Meta; + } + + + virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override + { + // Bit 0x08 is a flag for value in the range 0x00--0x05 and specifies direction for values withint 0x006--0x09. + if ((a_Meta < 0x06) || (a_Meta > 0x09)) + { + // Save powered rail flag. + NIBBLETYPE OtherMeta = a_Meta & 0x08; + // Mirrors according to table; 0x07 == 0111. + // Rails can either be flat (North/South) or Ascending (Asc. East) + switch (a_Meta & 0x07) + { + case 0x02: return 0x03 + OtherMeta; // Asc. East -> Asc. West + case 0x03: return 0x02 + OtherMeta; // Asc. West -> Asc. East + } + } + else + { + switch (a_Meta) + { + // Corner Directions + case 0x06: return 0x07; // Northwest Cnr. -> Northeast Cnr. + case 0x07: return 0x06; // Northeast Cnr. -> Northwest Cnr. + case 0x08: return 0x09; // Southeast Cnr. -> Southwest Cnr. + case 0x09: return 0x08; // Southwest Cnr. -> Southeast Cnr. + } + } + // To avoid a compiler warning; + return a_Meta; + } } ; diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h index 1e2a86949..fe6cd21b9 100644 --- a/src/Blocks/BlockRedstoneRepeater.h +++ b/src/Blocks/BlockRedstoneRepeater.h @@ -3,17 +3,17 @@ #include "BlockHandler.h" #include "Chunk.h" - +#include "MetaRotator.h" class cBlockRedstoneRepeaterHandler : - public cBlockHandler + public cMetaRotator { public: cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index 7cd2c97b2..b18bf7ef3 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -14,8 +14,6 @@ - - class cBlockSlabHandler : public cBlockHandler { @@ -184,6 +182,15 @@ public: ASSERT(!"Unhandled double slab type!"); return ""; } + + + virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override + { + NIBBLETYPE OtherMeta = a_Meta & 0x07; // Contains unrelate meta data. + + // 8th bit is up/down. 1 right-side-up, 0 is up-side-down. + return (a_Meta & 0x08) ? 0x00 + OtherMeta : 0x01 + OtherMeta; + } } ; diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 9bae92c4d..6a36ab874 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -2,17 +2,17 @@ #pragma once #include "BlockHandler.h" - +#include "MetaRotator.h" class cBlockTrapdoorHandler : - public cBlockHandler + public cMetaRotator { public: cBlockTrapdoorHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotator(a_BlockType) { } -- cgit v1.2.3 From 6b77dc74ade3d8088da09d26c1b701d92ef28e9e Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 24 Mar 2014 12:29:19 +0200 Subject: Wither invulnerability --- src/Blocks/BlockMobHead.h | 14 +++++++++ src/Mobs/Monster.cpp | 1 + src/Mobs/Wither.cpp | 52 ++++++++++++++++++++++++++++++++- src/Mobs/Wither.h | 14 +++++++++ src/World.h | 2 +- src/WorldStorage/MapSerializer.cpp | 6 +++- src/WorldStorage/NBTChunkSerializer.cpp | 8 ++++- src/WorldStorage/WSSAnvil.cpp | 8 ++++- 8 files changed, 100 insertions(+), 5 deletions(-) diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index 2b128f13b..6aa01f986 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -21,6 +21,18 @@ public: { a_Pickups.push_back(cItem(E_ITEM_HEAD, 1, 0)); } + + bool TrySpawnWither(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + { + if (a_BlockY < 2) + { + return false; + } + + // TODO 2014-03-24 xdot + + return false; + } virtual void OnPlacedByPlayer( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, @@ -62,6 +74,8 @@ public: cWorld * World = (cWorld *) &a_WorldInterface; World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback); a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); + + TrySpawnWither(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); } } ; diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 16d6aed1f..d3e0f1c26 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -758,6 +758,7 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type) case mtSquid: return mfWater; case mtVillager: return mfPassive; case mtWitch: return mfHostile; + case mtWither: return mfHostile; case mtWolf: return mfHostile; case mtZombie: return mfHostile; case mtZombiePigman: return mfHostile; diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index c46e0beab..0e42194ac 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -2,14 +2,64 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Wither.h" +#include "../World.h" cWither::cWither(void) : - super("Wither", mtWither, "mob.wither.hurt", "mob.wither.death", 0.9, 4.0) + super("Wither", mtWither, "mob.wither.hurt", "mob.wither.death", 0.9, 4.0), + m_InvulnerableTicks(220) { + SetMaxHealth(300); + + SetHealth(GetMaxHealth() / 3); +} + + + + + +void cWither::DoTakeDamage(TakeDamageInfo & a_TDI) +{ + if (a_TDI.DamageType == dtDrowning) + { + return; + } + + if (m_InvulnerableTicks > 0) + { + return; + } + + super::DoTakeDamage(a_TDI); +} + + + + + +void cWither::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + + if (m_InvulnerableTicks > 0) + { + unsigned int NewTicks = m_InvulnerableTicks - 1; + + if (NewTicks == 0) + { + m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this); + } + + m_InvulnerableTicks = NewTicks; + + if ((NewTicks % 10) == 0) + { + Heal(10); + } + } } diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index 56effc6bb..df3a57798 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -16,8 +16,22 @@ public: cWither(void); CLASS_PROTODEF(cWither); + + unsigned int GetNumInvulnerableTicks(void) const { return m_InvulnerableTicks; } + + void SetNumInvulnerableTicks(unsigned int a_Ticks) { m_InvulnerableTicks = a_Ticks; } + // Override functions virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + + virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + +private: + + /** The number of ticks of invulnerability left after being initially created. Zero once invulnerability has expired. */ + unsigned int m_InvulnerableTicks; } ; diff --git a/src/World.h b/src/World.h index 46aece18f..79fcc5616 100644 --- a/src/World.h +++ b/src/World.h @@ -505,7 +505,7 @@ public: | esGhastFireball | cGhastFireball * | | esWitherSkullBlack | TBD | | esWitherSkullBlue | TBD | - | esWitherBirth | TBD | + | esWitherBirth | cWither * | | esPlugin | void * | */ virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); // tolua_export // override, cannot specify due to tolua diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp index a4a0aab57..df72d1cc9 100644 --- a/src/WorldStorage/MapSerializer.cpp +++ b/src/WorldStorage/MapSerializer.cpp @@ -141,7 +141,11 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT) { eDimension Dimension = (eDimension) a_NBT.GetByte(CurrLine); - ASSERT(Dimension == m_Map->m_World->GetDimension()); + if (Dimension != m_Map->m_World->GetDimension()) + { + // TODO 2014-03-20 xdot: We should store nether maps in nether worlds, e.t.c. + return false; + } } CurrLine = a_NBT.FindChildByName(Data, "width"); diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index acca96ba8..f9cca1495 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -43,6 +43,7 @@ #include "../Mobs/Slime.h" #include "../Mobs/Skeleton.h" #include "../Mobs/Villager.h" +#include "../Mobs/Wither.h" #include "../Mobs/Wolf.h" #include "../Mobs/Zombie.h" @@ -422,7 +423,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) case cMonster::mtSquid: EntityClass = "Squid"; break; case cMonster::mtVillager: EntityClass = "Villager"; break; case cMonster::mtWitch: EntityClass = "Witch"; break; - case cMonster::mtWither: EntityClass = "Wither"; break; + case cMonster::mtWither: EntityClass = "WitherBoss"; break; case cMonster::mtWolf: EntityClass = "Wolf"; break; case cMonster::mtZombie: EntityClass = "Zombie"; break; case cMonster::mtZombiePigman: EntityClass = "PigZombie"; break; @@ -501,6 +502,11 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) m_Writer.AddInt("Profession", ((const cVillager *)a_Monster)->GetVilType()); break; } + case cMonster::mtWither: + { + m_Writer.AddInt("Invul", ((const cWither *)a_Monster)->GetNumInvulnerableTicks()); + break; + } case cMonster::mtWolf: { m_Writer.AddString("Owner", ((const cWolf *)a_Monster)->GetOwner()); diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 7a2366755..2516ac07a 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1238,7 +1238,7 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a { LoadWitchFromNBT(a_Entities, a_NBT, a_EntityTagIdx); } - else if (strncmp(a_IDTag, "Wither", a_IDTagLength) == 0) + else if (strncmp(a_IDTag, "WitherBoss", a_IDTagLength) == 0) { LoadWitherFromNBT(a_Entities, a_NBT, a_EntityTagIdx); } @@ -2250,6 +2250,12 @@ void cWSSAnvil::LoadWitherFromNBT(cEntityList & a_Entities, const cParsedNBT & a return; } + int CurrLine = a_NBT.FindChildByName(a_TagIdx, "Invul"); + if (CurrLine > 0) + { + Monster->SetNumInvulnerableTicks(a_NBT.GetInt(CurrLine)); + } + a_Entities.push_back(Monster.release()); } -- cgit v1.2.3 From a6414d334834692c1d8b573b1e90c464d4d4469c Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 24 Mar 2014 19:52:35 +0100 Subject: Add log pickups. --- src/Blocks/BlockSideways.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Blocks/BlockSideways.h b/src/Blocks/BlockSideways.h index 69c0a7230..d67c3aa24 100644 --- a/src/Blocks/BlockSideways.h +++ b/src/Blocks/BlockSideways.h @@ -29,7 +29,13 @@ public: return true; } - + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + a_Pickups.Add(m_BlockType, 1, a_BlockMeta & 0x3); + } + + inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace, NIBBLETYPE a_WoodMeta) { switch (a_BlockFace) -- cgit v1.2.3 From 4f3377bbbfa12623be61561ae75bdd9d8d5fbe8c Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 25 Mar 2014 09:10:55 +0200 Subject: Minor fixes --- src/Mobs/Villager.h | 2 +- src/Mobs/Wither.h | 5 ++--- src/World.h | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index b99ae876f..5bba4d4ba 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -29,7 +29,7 @@ public: CLASS_PROTODEF(cVillager); - // Override functions + // cEntity overrides virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void Tick (float a_Dt, cChunk & a_Chunk) override; diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index df3a57798..d09e3607a 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -21,17 +21,16 @@ public: void SetNumInvulnerableTicks(unsigned int a_Ticks) { m_InvulnerableTicks = a_Ticks; } - // Override functions + // cEntity overrides virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; - virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; private: /** The number of ticks of invulnerability left after being initially created. Zero once invulnerability has expired. */ unsigned int m_InvulnerableTicks; + } ; diff --git a/src/World.h b/src/World.h index 79fcc5616..bb2eb0b21 100644 --- a/src/World.h +++ b/src/World.h @@ -497,16 +497,16 @@ public: /** Does an explosion with the specified strength at the specified coordinate a_SourceData exact type depends on the a_Source: - | esOther | void * | - | esPrimedTNT | cTNTEntity * | - | esMonster | cMonster * | - | esBed | cVector3i * | - | esEnderCrystal | Vector3i * | - | esGhastFireball | cGhastFireball * | - | esWitherSkullBlack | TBD | - | esWitherSkullBlue | TBD | - | esWitherBirth | cWither * | - | esPlugin | void * | + | esOther | void * | + | esPrimedTNT | cTNTEntity * | + | esMonster | cMonster * | + | esBed | cVector3i * | + | esEnderCrystal | Vector3i * | + | esGhastFireball | cGhastFireball * | + | esWitherSkullBlack | TBD | + | esWitherSkullBlue | TBD | + | esWitherBirth | cMonster * | + | esPlugin | void * | */ virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); // tolua_export // override, cannot specify due to tolua -- cgit v1.2.3 From 0fe1e50ffc744d861744e4aa4905e1b4b15e10fd Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 25 Mar 2014 10:32:58 +0200 Subject: Protocol: Wither metadata --- src/Blocks/BlockMobHead.h | 82 ++++++++++++++++++++++++++++++++++++++++++-- src/Mobs/Wither.cpp | 16 +++++++++ src/Mobs/Wither.h | 3 ++ src/Protocol/Protocol125.cpp | 8 +++++ src/Protocol/Protocol17x.cpp | 10 ++++++ 5 files changed, 116 insertions(+), 3 deletions(-) diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index 6aa01f986..9935c2496 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -22,14 +22,90 @@ public: a_Pickups.push_back(cItem(E_ITEM_HEAD, 1, 0)); } - bool TrySpawnWither(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + bool TrySpawnWither(cChunkInterface & a_ChunkInterface, cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) { if (a_BlockY < 2) { return false; } + + class cCallback : public cMobHeadCallback + { + bool m_IsWither; + + virtual bool Item (cMobHeadEntity * a_MobHeadEntity) + { + m_IsWither = (a_MobHeadEntity->GetType() == SKULL_TYPE_WITHER); + + return false; + } + + public: + cCallback () : m_IsWither(false) {} + + bool IsWither(void) const { return m_IsWither; } + + void Reset(void) { m_IsWither = false; } + } CallbackA, CallbackB; + + BLOCKTYPE BlockY1 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); + BLOCKTYPE BlockY2 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 2, a_BlockZ); + + if ((BlockY1 != E_BLOCK_SOULSAND) || (BlockY2 != E_BLOCK_SOULSAND)) + { + return false; + } - // TODO 2014-03-24 xdot + a_World->DoWithMobHeadAt(a_BlockX - 1, a_BlockY, a_BlockZ, CallbackA); + a_World->DoWithMobHeadAt(a_BlockX + 1, a_BlockY, a_BlockZ, CallbackB); + + BLOCKTYPE Block1 = a_ChunkInterface.GetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ); + BLOCKTYPE Block2 = a_ChunkInterface.GetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ); + + if ((Block1 == E_BLOCK_SOULSAND) && (Block2 == E_BLOCK_SOULSAND) && CallbackA.IsWither() && CallbackB.IsWither()) + { + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); + + // Block entities + a_World->SetBlock(a_BlockX + 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_World->SetBlock(a_BlockX - 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + + // Spawn the wither: + a_World->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither); + + return true; + } + + CallbackA.Reset(); + CallbackB.Reset(); + + a_World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ - 1, CallbackA); + a_World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ + 1, CallbackB); + + Block1 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1); + Block2 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1); + + if ((Block1 == E_BLOCK_SOULSAND) && (Block2 == E_BLOCK_SOULSAND) && CallbackA.IsWither() && CallbackB.IsWither()) + { + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); + + // Block entities + a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ + 1, E_BLOCK_AIR, 0); + a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ - 1, E_BLOCK_AIR, 0); + + // Spawn the wither: + a_World->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither); + + return true; + } return false; } @@ -75,7 +151,7 @@ public: World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback); a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); - TrySpawnWither(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + TrySpawnWither(a_ChunkInterface, World, a_BlockX, a_BlockY, a_BlockZ); } } ; diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index 0e42194ac..790f127f2 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -21,6 +21,15 @@ cWither::cWither(void) : +bool cWither::IsArmored(void) const +{ + return GetHealth() <= (GetMaxHealth() / 2); +} + + + + + void cWither::DoTakeDamage(TakeDamageInfo & a_TDI) { if (a_TDI.DamageType == dtDrowning) @@ -33,6 +42,11 @@ void cWither::DoTakeDamage(TakeDamageInfo & a_TDI) return; } + if (IsArmored() && (a_TDI.DamageType == dtRangedAttack)) + { + return; + } + super::DoTakeDamage(a_TDI); } @@ -60,6 +74,8 @@ void cWither::Tick(float a_Dt, cChunk & a_Chunk) Heal(10); } } + + m_World->BroadcastEntityMetadata(*this); } diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index d09e3607a..52666a190 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -20,6 +20,9 @@ public: unsigned int GetNumInvulnerableTicks(void) const { return m_InvulnerableTicks; } void SetNumInvulnerableTicks(unsigned int a_Ticks) { m_InvulnerableTicks = a_Ticks; } + + /** Returns whether the wither is invulnerable to arrows. */ + bool IsArmored(void) const; // cEntity overrides virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 69f4934d8..d8b340350 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1972,6 +1972,14 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteByte(((const cWitch &)a_Mob).IsAngry() ? 1 : 0); // Aggravated? Doesn't seem to do anything break; } + case cMonster::mtWither: + { + WriteByte(0x54); // Int at index 20 + WriteInt(((const cWither &)a_Mob).GetNumInvulnerableTicks()); + WriteByte(0x66); // Float at index 6 + WriteFloat((float)(a_Mob.GetHealth())); + break; + } case cMonster::mtSlime: case cMonster::mtMagmaCube: { diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 721ed349e..c678fc9a0 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2535,6 +2535,7 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity) WriteByte(Frame.GetRotation()); break; } + default: break; } } @@ -2659,6 +2660,15 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob) WriteByte(((const cWitch &)a_Mob).IsAngry() ? 1 : 0); break; } + + case cMonster::mtWither: + { + WriteByte(0x54); // Int at index 20 + WriteInt(((const cWither &)a_Mob).GetNumInvulnerableTicks()); + WriteByte(0x66); // Float at index 6 + WriteFloat((float)(a_Mob.GetHealth())); + break; + } case cMonster::mtSlime: { -- cgit v1.2.3 From ba4216641120ec2f49464ed0b136af3198d48f89 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 25 Mar 2014 11:13:27 +0200 Subject: Fixed wither summoning --- src/Blocks/BlockMobHead.h | 25 ++++++++++++++++++++++++- src/Mobs/Wither.cpp | 14 ++++++++++++-- src/Mobs/Wither.h | 1 + 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index 9935c2496..693240898 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -47,6 +47,15 @@ public: void Reset(void) { m_IsWither = false; } } CallbackA, CallbackB; + + a_World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, CallbackA); + + if (!CallbackA.IsWither()) + { + return false; + } + + CallbackA.Reset(); BLOCKTYPE BlockY1 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); BLOCKTYPE BlockY2 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 2, a_BlockZ); @@ -151,7 +160,21 @@ public: World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback); a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); - TrySpawnWither(a_ChunkInterface, World, a_BlockX, a_BlockY, a_BlockZ); + static const Vector3i Coords[] = + { + Vector3i( 0, 0, 0), + Vector3i( 1, 0, 0), + Vector3i(-1, 0, 0), + Vector3i( 0, 0, 1), + Vector3i( 0, 0, -1), + }; + for (size_t i = 0; i < ARRAYCOUNT(Coords); ++i) + { + if (TrySpawnWither(a_ChunkInterface, World, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z)) + { + break; + } + } // for i - Coords[] } } ; diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index 790f127f2..39dc6aab9 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -13,8 +13,6 @@ cWither::cWither(void) : m_InvulnerableTicks(220) { SetMaxHealth(300); - - SetHealth(GetMaxHealth() / 3); } @@ -30,6 +28,18 @@ bool cWither::IsArmored(void) const +bool cWither::Initialize(cWorld * a_World) override +{ + // Set health before BroadcastSpawnEntity() + SetHealth(GetMaxHealth() / 3); + + return super::Initialize(a_World); +} + + + + + void cWither::DoTakeDamage(TakeDamageInfo & a_TDI) { if (a_TDI.DamageType == dtDrowning) diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index 52666a190..bc78bfaad 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -25,6 +25,7 @@ public: bool IsArmored(void) const; // cEntity overrides + virtual bool Initialize(cWorld * a_World) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; -- cgit v1.2.3 From c8445cd93479d4729a180b21df1783449ce01b7e Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 25 Mar 2014 11:40:54 +0200 Subject: Fixed clang compilation --- src/Blocks/BlockMobHead.h | 29 ++++++++++++++++------------- src/Mobs/Wither.cpp | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index 693240898..e172cee69 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -160,21 +160,24 @@ public: World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback); a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); - static const Vector3i Coords[] = + if (a_BlockMeta == SKULL_TYPE_WITHER) { - Vector3i( 0, 0, 0), - Vector3i( 1, 0, 0), - Vector3i(-1, 0, 0), - Vector3i( 0, 0, 1), - Vector3i( 0, 0, -1), - }; - for (size_t i = 0; i < ARRAYCOUNT(Coords); ++i) - { - if (TrySpawnWither(a_ChunkInterface, World, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z)) + static const Vector3i Coords[] = { - break; - } - } // for i - Coords[] + Vector3i( 0, 0, 0), + Vector3i( 1, 0, 0), + Vector3i(-1, 0, 0), + Vector3i( 0, 0, 1), + Vector3i( 0, 0, -1), + }; + for (size_t i = 0; i < ARRAYCOUNT(Coords); ++i) + { + if (TrySpawnWither(a_ChunkInterface, World, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z)) + { + break; + } + } // for i - Coords[] + } } } ; diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index 39dc6aab9..8f5d28b68 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -28,7 +28,7 @@ bool cWither::IsArmored(void) const -bool cWither::Initialize(cWorld * a_World) override +bool cWither::Initialize(cWorld * a_World) { // Set health before BroadcastSpawnEntity() SetHealth(GetMaxHealth() / 3); -- cgit v1.2.3 From d77a6417f62990f5c986e03a7e226c03b5a74fb8 Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Tue, 25 Mar 2014 10:33:52 -0600 Subject: Added newlines. Without them, the files would not compile. --- src/Entities/Effects.h | 2 +- src/Entities/Floater.h | 2 +- src/OSSupport/Sleep.h | 2 +- src/OSSupport/Thread.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Entities/Effects.h b/src/Entities/Effects.h index e7611847d..baf3302fb 100644 --- a/src/Entities/Effects.h +++ b/src/Entities/Effects.h @@ -27,4 +27,4 @@ enum ENUM_ENTITY_EFFECT E_EFFECT_ABSORPTION = 22, E_EFFECT_SATURATION = 23, } ; -// tolua_end \ No newline at end of file +// tolua_end diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h index f3b51d77b..547d503f1 100644 --- a/src/Entities/Floater.h +++ b/src/Entities/Floater.h @@ -43,4 +43,4 @@ protected: // Entity IDs int m_PlayerID; int m_AttachedMobID; -} ; // tolua_export \ No newline at end of file +} ; // tolua_export diff --git a/src/OSSupport/Sleep.h b/src/OSSupport/Sleep.h index 5298c15da..0ec0adf9d 100644 --- a/src/OSSupport/Sleep.h +++ b/src/OSSupport/Sleep.h @@ -4,4 +4,4 @@ class cSleep { public: static void MilliSleep( unsigned int a_MilliSeconds ); -}; \ No newline at end of file +}; diff --git a/src/OSSupport/Thread.h b/src/OSSupport/Thread.h index 3c9316424..4153b2427 100644 --- a/src/OSSupport/Thread.h +++ b/src/OSSupport/Thread.h @@ -23,4 +23,4 @@ private: cEvent* m_StopEvent; AString m_ThreadName; -}; \ No newline at end of file +}; -- cgit v1.2.3 From 71e9133e49c238ce74de144c5ab3b3d01d29152e Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Tue, 25 Mar 2014 10:34:31 -0600 Subject: Added one more missing newline. --- src/WorldStorage/FireworksSerializer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/FireworksSerializer.h b/src/WorldStorage/FireworksSerializer.h index 5b87bafdb..cbc544a14 100644 --- a/src/WorldStorage/FireworksSerializer.h +++ b/src/WorldStorage/FireworksSerializer.h @@ -89,4 +89,4 @@ public: short m_FlightTimeInTicks; std::vector m_Colours; std::vector m_FadeColours; -}; \ No newline at end of file +}; -- cgit v1.2.3 From eb3cc729d4e367c54a47369f712831908f8da22c Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Tue, 25 Mar 2014 11:15:05 -0600 Subject: More fixes to get it to compile for me on Mac 10.9. Mostly just newline additions, but some of the unused variables were causing errors, so I wrapped them in #ifndef __APPLE__ calls, since I didn't know if they were going to be used in the future. Also had to undefine TOLUA_TEMPLATE_BIND a couple of times. --- lib/md5/md5.h | 2 +- src/Bindings/DeprecatedBindings.cpp | 1 + src/Bindings/LuaState.cpp | 1 + src/Bindings/ManualBindings.cpp | 1 + src/Bindings/ManualBindings.h | 2 +- src/Bindings/PluginLua.cpp | 5 +++++ src/Bindings/WebPlugin.cpp | 2 +- src/DeadlockDetect.cpp | 2 ++ src/Entities/Boat.cpp | 2 -- src/Entities/ExpOrb.h | 2 +- src/Group.cpp | 2 +- src/Mobs/Blaze.cpp | 2 +- src/Mobs/Blaze.h | 4 ---- src/Mobs/Skeleton.cpp | 2 +- src/OSSupport/Errors.cpp | 2 +- src/World.cpp | 3 ++- 16 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/md5/md5.h b/lib/md5/md5.h index ad5ad5384..3aa88ac22 100644 --- a/lib/md5/md5.h +++ b/lib/md5/md5.h @@ -90,4 +90,4 @@ private: std::string md5(const std::string & str); -#endif \ No newline at end of file +#endif diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp index 408b1b84a..fbc008be6 100644 --- a/src/Bindings/DeprecatedBindings.cpp +++ b/src/Bindings/DeprecatedBindings.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "DeprecatedBindings.h" +#undef TOLUA_TEMPLATE_BIND #include "tolua++/include/tolua++.h" #include "Plugin.h" diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 47380b8a7..7afae5e38 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -11,6 +11,7 @@ extern "C" #include "lua/src/lualib.h" } +#undef TOLUA_TEMPLATE_BIND #include "tolua++/include/tolua++.h" #include "Bindings.h" #include "ManualBindings.h" diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 20bbc48f2..081ea4d59 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "ManualBindings.h" +#undef TOLUA_TEMPLATE_BIND #include "tolua++/include/tolua++.h" #include "Plugin.h" diff --git a/src/Bindings/ManualBindings.h b/src/Bindings/ManualBindings.h index e6594947e..f38e26267 100644 --- a/src/Bindings/ManualBindings.h +++ b/src/Bindings/ManualBindings.h @@ -5,4 +5,4 @@ class ManualBindings { public: static void Bind( lua_State* tolua_S ); -}; \ No newline at end of file +}; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index cccbc3c93..ebabeb222 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -5,7 +5,11 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules +#ifdef __APPLE__ +#define LUA_USE_MACOSX +#else #define LUA_USE_POSIX +#endif #include "PluginLua.h" #include "../CommandOutput.h" @@ -14,6 +18,7 @@ extern "C" #include "lua/src/lualib.h" } +#undef TOLUA_TEMPLATE_BIND #include "tolua++/include/tolua++.h" diff --git a/src/Bindings/WebPlugin.cpp b/src/Bindings/WebPlugin.cpp index 3b71d553c..bf45405ba 100644 --- a/src/Bindings/WebPlugin.cpp +++ b/src/Bindings/WebPlugin.cpp @@ -110,4 +110,4 @@ AString cWebPlugin::SafeString( const AString & a_String ) RetVal.push_back( c ); } return RetVal; -} \ No newline at end of file +} diff --git a/src/DeadlockDetect.cpp b/src/DeadlockDetect.cpp index 4dc7bfde6..8e1283bba 100644 --- a/src/DeadlockDetect.cpp +++ b/src/DeadlockDetect.cpp @@ -17,7 +17,9 @@ const int CYCLE_MILLISECONDS = 100; /// When the number of cycles for the same world age hits this value, it is considered a deadlock +#ifndef __APPLE__ const int NUM_CYCLES_LIMIT = 200; // 200 = twenty seconds +#endif diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 94b24c5af..921252253 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -122,5 +122,3 @@ void cBoat::HandleSpeedFromAttachee(float a_Forward, float a_Sideways) AddSpeed(ToAddSpeed); } - - \ No newline at end of file diff --git a/src/Entities/ExpOrb.h b/src/Entities/ExpOrb.h index c1150bd03..e76274ac9 100644 --- a/src/Entities/ExpOrb.h +++ b/src/Entities/ExpOrb.h @@ -42,4 +42,4 @@ protected: /** The number of ticks that the entity has existed / timer between collect and destroy; in msec */ float m_Timer; -} ; // tolua_export \ No newline at end of file +} ; // tolua_export diff --git a/src/Group.cpp b/src/Group.cpp index 5f1f25782..9c2467144 100644 --- a/src/Group.cpp +++ b/src/Group.cpp @@ -38,4 +38,4 @@ void cGroup::InheritFrom( cGroup* a_Group ) void cGroup::ClearPermission() { m_Permissions.clear(); -} \ No newline at end of file +} diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index ac42cf40b..84ff8929b 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -53,4 +53,4 @@ void cBlaze::Attack(float a_Dt) m_AttackInterval = 0.0; // ToDo: Shoot 3 fireballs instead of 1. } -} \ No newline at end of file +} diff --git a/src/Mobs/Blaze.h b/src/Mobs/Blaze.h index cdb3a1306..5970451c7 100644 --- a/src/Mobs/Blaze.h +++ b/src/Mobs/Blaze.h @@ -20,7 +20,3 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void Attack(float a_Dt) override; } ; - - - - diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 47fcdbb26..1685f40c5 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -88,4 +88,4 @@ void cSkeleton::Attack(float a_Dt) m_World->BroadcastSpawnEntity(*Arrow); m_AttackInterval = 0.0; } -} \ No newline at end of file +} diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp index 2e05f1df1..6072b6ac6 100644 --- a/src/OSSupport/Errors.cpp +++ b/src/OSSupport/Errors.cpp @@ -22,7 +22,7 @@ AString GetOSErrorString( int a_ErrNo ) // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r(): - #if ( _GNU_SOURCE ) && !defined(ANDROID_NDK) // GNU version of strerror_r() + #if !defined(__APPLE__) && ( _GNU_SOURCE ) && !defined(ANDROID_NDK) // GNU version of strerror_r() char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) ); if( res != NULL ) diff --git a/src/World.cpp b/src/World.cpp index 3f157157a..98f6a4b5a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -59,9 +59,10 @@ - +#ifndef __APPLE__ /// Up to this many m_SpreadQueue elements are handled each world tick const int MAX_LIGHTING_SPREAD_PER_TICK = 10; +#endif const int TIME_SUNSET = 12000; const int TIME_NIGHT_START = 13187; -- cgit v1.2.3 From 2e28c09770a937b253680d7f62b9b2f4c8f4670c Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 25 Mar 2014 20:59:33 +0200 Subject: Ender crystals --- src/Entities/EnderCrystal.cpp | 56 +++++++++++++++++++++++++++++++++ src/Entities/EnderCrystal.h | 33 +++++++++++++++++++ src/Entities/Entity.h | 24 +++++++------- src/WorldStorage/NBTChunkSerializer.cpp | 13 ++++++++ src/WorldStorage/NBTChunkSerializer.h | 2 ++ src/WorldStorage/WSSAnvil.cpp | 19 +++++++++++ src/WorldStorage/WSSAnvil.h | 1 + 7 files changed, 137 insertions(+), 11 deletions(-) create mode 100644 src/Entities/EnderCrystal.cpp create mode 100644 src/Entities/EnderCrystal.h diff --git a/src/Entities/EnderCrystal.cpp b/src/Entities/EnderCrystal.cpp new file mode 100644 index 000000000..a640b236c --- /dev/null +++ b/src/Entities/EnderCrystal.cpp @@ -0,0 +1,56 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "EnderCrystal.h" +#include "ClientHandle.h" +#include "Player.h" +#include "../Chunk.h" + + + + + +cEnderCrystal::cEnderCrystal(double a_X, double a_Y, double a_Z) + : cEntity(etEnderCrystal, a_X, a_Y, a_Z, 1.0, 1.0) +{ + SetMaxHealth(5); +} + + + + + +void cEnderCrystal::SpawnOn(cClientHandle & a_ClientHandle) +{ + a_ClientHandle.SendSpawnObject(*this, 51, 0, (Byte)GetYaw(), (Byte)GetPitch()); +} + + + + + +void cEnderCrystal::Tick(float a_Dt, cChunk & a_Chunk) +{ + UNUSED(a_Dt); + + a_Chunk.SetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT, E_BLOCK_FIRE, 0); + + // No further processing (physics e.t.c.) is needed +} + + + + + +void cEnderCrystal::KilledBy(cEntity * a_Killer) +{ + super::KilledBy(a_Killer); + + m_World->DoExplosionAt(6.0, GetPosX(), GetPosY(), GetPosZ(), true, esEnderCrystal, this); + + Destroy(); +} + + + + diff --git a/src/Entities/EnderCrystal.h b/src/Entities/EnderCrystal.h new file mode 100644 index 000000000..5b86df987 --- /dev/null +++ b/src/Entities/EnderCrystal.h @@ -0,0 +1,33 @@ + +#pragma once + +#include "Entity.h" + + + + + +// tolua_begin +class cEnderCrystal : + public cEntity +{ + // tolua_end + typedef cEntity super; + +public: + CLASS_PROTODEF(cEnderCrystal); + + cEnderCrystal(double a_X, double a_Y, double a_Z); + +private: + + // cEntity overrides: + virtual void SpawnOn(cClientHandle & a_ClientHandle) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void KilledBy(cEntity * a_Killer) override; + +}; // tolua_export + + + + diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index df80093e5..e41f74b09 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -69,6 +69,7 @@ public: enum eEntityType { etEntity, // For all other types + etEnderCrystal, etPlayer, etPickup, etMonster, @@ -130,18 +131,19 @@ public: eEntityType GetEntityType(void) const { return m_EntityType; } - bool IsPlayer (void) const { return (m_EntityType == etPlayer); } - bool IsPickup (void) const { return (m_EntityType == etPickup); } - bool IsMob (void) const { return (m_EntityType == etMonster); } + bool IsEnderCrystal(void) const { return (m_EntityType == etEnderCrystal); } + bool IsPlayer (void) const { return (m_EntityType == etPlayer); } + bool IsPickup (void) const { return (m_EntityType == etPickup); } + bool IsMob (void) const { return (m_EntityType == etMonster); } bool IsFallingBlock(void) const { return (m_EntityType == etFallingBlock); } - bool IsMinecart (void) const { return (m_EntityType == etMinecart); } - bool IsBoat (void) const { return (m_EntityType == etBoat); } - bool IsTNT (void) const { return (m_EntityType == etTNT); } - bool IsProjectile (void) const { return (m_EntityType == etProjectile); } - bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); } - bool IsFloater (void) const { return (m_EntityType == etFloater); } - bool IsItemFrame (void) const { return (m_EntityType == etItemFrame); } - bool IsPainting (void) const { return (m_EntityType == etPainting); } + bool IsMinecart (void) const { return (m_EntityType == etMinecart); } + bool IsBoat (void) const { return (m_EntityType == etBoat); } + bool IsTNT (void) const { return (m_EntityType == etTNT); } + bool IsProjectile (void) const { return (m_EntityType == etProjectile); } + bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); } + bool IsFloater (void) const { return (m_EntityType == etFloater); } + bool IsItemFrame (void) const { return (m_EntityType == etItemFrame); } + bool IsPainting (void) const { return (m_EntityType == etPainting); } /// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true) virtual bool IsA(const char * a_ClassName) const; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index acca96ba8..9a14d7152 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -23,6 +23,7 @@ #include "../BlockEntities/FlowerPotEntity.h" #include "../Entities/Entity.h" +#include "../Entities/EnderCrystal.h" #include "../Entities/FallingBlock.h" #include "../Entities/Boat.h" #include "../Entities/Minecart.h" @@ -335,6 +336,17 @@ void cNBTChunkSerializer::AddBoatEntity(cBoat * a_Boat) +void cNBTChunkSerializer::AddEnderCrystalEntity(cEnderCrystal * a_EnderCrystal) +{ + m_Writer.BeginCompound(""); + AddBasicEntity(a_EnderCrystal, "EnderCrystal"); + m_Writer.EndCompound(); +} + + + + + void cNBTChunkSerializer::AddFallingBlockEntity(cFallingBlock * a_FallingBlock) { m_Writer.BeginCompound(""); @@ -729,6 +741,7 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity) switch (a_Entity->GetEntityType()) { case cEntity::etBoat: AddBoatEntity ((cBoat *) a_Entity); break; + case cEntity::etEnderCrystal: AddEnderCrystalEntity((cEnderCrystal *) a_Entity); break; case cEntity::etFallingBlock: AddFallingBlockEntity((cFallingBlock *) a_Entity); break; case cEntity::etMinecart: AddMinecartEntity ((cMinecart *) a_Entity); break; case cEntity::etMonster: AddMonsterEntity ((cMonster *) a_Entity); break; diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index c1134cd00..51d104970 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -24,6 +24,7 @@ class cChestEntity; class cCommandBlockEntity; class cDispenserEntity; class cDropperEntity; +class cEnderCrystal; class cFurnaceEntity; class cHopperEntity; class cJukeboxEntity; @@ -106,6 +107,7 @@ protected: // Entities: void AddBasicEntity (cEntity * a_Entity, const AString & a_ClassName); void AddBoatEntity (cBoat * a_Boat); + void AddEnderCrystalEntity(cEnderCrystal * a_EnderCrystal); void AddFallingBlockEntity(cFallingBlock * a_FallingBlock); void AddMinecartEntity (cMinecart * a_Minecart); void AddMonsterEntity (cMonster * a_Monster); diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 7a2366755..1214089a1 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -32,6 +32,7 @@ #include "../Mobs/IncludeAllMonsters.h" #include "../Entities/Boat.h" +#include "../Entities/EnderCrystal.h" #include "../Entities/FallingBlock.h" #include "../Entities/Minecart.h" #include "../Entities/Pickup.h" @@ -1057,6 +1058,10 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a { LoadBoatFromNBT(a_Entities, a_NBT, a_EntityTagIdx); } + else if (strncmp(a_IDTag, "EnderCrystal", a_IDTagLength) == 0) + { + LoadEnderCrystalFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + } else if (strncmp(a_IDTag, "FallingBlock", a_IDTagLength) == 0) { LoadFallingBlockFromNBT(a_Entities, a_NBT, a_EntityTagIdx); @@ -1275,6 +1280,20 @@ void cWSSAnvil::LoadBoatFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N +void cWSSAnvil::LoadEnderCrystalFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + std::auto_ptr EnderCrystal(new cEnderCrystal(0, 0, 0)); + if (!LoadEntityBaseFromNBT(*EnderCrystal.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(EnderCrystal.release()); +} + + + + + void cWSSAnvil::LoadFallingBlockFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { int TypeIdx = a_NBT.FindChildByName(a_TagIdx, "TileID"); diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 50d0e555e..1773ee882 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -148,6 +148,7 @@ protected: void LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength); void LoadBoatFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadEnderCrystalFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadFallingBlockFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadPickupFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadTNTFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); -- cgit v1.2.3 From f67ad369659307c4148f825cd3e0cdba909ab229 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 24 Mar 2014 08:15:27 +0100 Subject: InfoReg updated for multi-verb console commands. --- MCServer/Plugins/InfoReg.lua | 51 +++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/MCServer/Plugins/InfoReg.lua b/MCServer/Plugins/InfoReg.lua index b3717884a..27e63aa5b 100644 --- a/MCServer/Plugins/InfoReg.lua +++ b/MCServer/Plugins/InfoReg.lua @@ -9,16 +9,30 @@ --- Lists all the subcommands that the player has permissions for local function ListSubcommands(a_Player, a_Subcommands, a_CmdString) - a_Player:SendMessage("The " .. a_CmdString .. " command requires another verb:"); + if (a_Player == nil) then + LOGINFO("The " .. a_CmdString .. " command requires another verb:") + else + a_Player:SendMessage("The " .. a_CmdString .. " command requires another verb:") + end + + -- Enum all the subcommands: local Verbs = {}; for cmd, info in pairs(a_Subcommands) do if (a_Player:HasPermission(info.Permission or "")) then - table.insert(Verbs, a_CmdString .. " " .. cmd); + table.insert(Verbs, " " .. a_CmdString .. " " .. cmd); end end table.sort(Verbs); - for idx, verb in ipairs(Verbs) do - a_Player:SendMessage(verb); + + -- Send the list: + if (a_Player == nil) then + for idx, verb in ipairs(Verbs) do + LOGINFO(verb); + end + else + for idx, verb in ipairs(Verbs) do + a_Player:SendMessage(verb); + end end end @@ -28,6 +42,7 @@ end --- This is a generic command callback used for handling multicommands' parent commands -- For example, if there are "/gal save" and "/gal load" commands, this callback handles the "/gal" command +-- It is used for both console and in-game commands; the console version has a_Player set to nil local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_Level) local Verb = a_Split[a_Level + 1]; if (Verb == nil) then @@ -46,7 +61,11 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_ if (a_Level > 1) then -- This is a true subcommand, display the message and make MCS think the command was handled -- Otherwise we get weird behavior: for "/cmd verb" we get "unknown command /cmd" although "/cmd" is valid - a_Player:SendMessage("The " .. a_CmdString .. " command doesn't support verb " .. Verb); + if (a_Player == nil) then + LOGWARNING("The " .. a_CmdString .. " command doesn't support verb " .. Verb) + else + a_Player:SendMessage("The " .. a_CmdString .. " command doesn't support verb " .. Verb) + end return true; end -- This is a top-level command, let MCS handle the unknown message @@ -54,9 +73,11 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_ end -- Check the permission: - if not(a_Player:HasPermission(Subcommand.Permission or "")) then - a_Player:SendMessage("You don't have permission to execute this command"); - return true; + if (a_Player ~= nil) then + if not(a_Player:HasPermission(Subcommand.Permission or "")) then + a_Player:SendMessage("You don't have permission to execute this command"); + return true; + end end -- If the handler is not valid, check the next sublevel: @@ -149,21 +170,27 @@ end function RegisterPluginInfoConsoleCommands() -- A sub-function that registers all subcommands of a single command, using the command's Subcommands table -- The a_Prefix param already contains the space after the previous command - local function RegisterSubcommands(a_Prefix, a_Subcommands) + local function RegisterSubcommands(a_Prefix, a_Subcommands, a_Level) assert(a_Subcommands ~= nil); for cmd, info in pairs(a_Subcommands) do local CmdName = a_Prefix .. cmd; - cPluginManager.BindConsoleCommand(cmd, info.Handler, info.HelpString or ""); + local Handler = info.Handler + if (Handler == nil) then + Handler = function(a_Split) + return MultiCommandHandler(a_Split, nil, CmdName, info, a_Level); + end + end + cPluginManager.BindConsoleCommand(CmdName, Handler, info.HelpString or ""); -- Recursively register any subcommands: if (info.Subcommands ~= nil) then - RegisterSubcommands(a_Prefix .. cmd .. " ", info.Subcommands); + RegisterSubcommands(a_Prefix .. cmd .. " ", info.Subcommands, a_Level + 1); end end end -- Loop through all commands in the plugin info, register each: - RegisterSubcommands("", g_PluginInfo.ConsoleCommands); + RegisterSubcommands("", g_PluginInfo.ConsoleCommands, 1); end -- cgit v1.2.3 From 0984cf9deb4b60e119adeac56c5d891d2a7cbec6 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 25 Mar 2014 21:33:23 +0100 Subject: Added Vector3::Move(const Vector3 &). --- src/Vector3.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Vector3.h b/src/Vector3.h index ba4abe3eb..a00e14508 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -121,6 +121,13 @@ public: z += a_Z; } + inline void Move(const Vector3 & a_Diff) + { + x += a_Diff.x; + y += a_Diff.y; + z += a_Diff.z; + } + // tolua_end inline void operator += (const Vector3 & a_Rhs) -- cgit v1.2.3 From 87e0bd54b426bafb6b267725b0e1a94511a38f4e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 25 Mar 2014 21:59:25 +0100 Subject: BlockArea: Switched internal coords to Vector3i. --- src/BlockArea.cpp | 324 ++++++++++++--------------- src/BlockArea.h | 36 +-- src/Generating/ChunkDesc.cpp | 6 +- src/WorldStorage/SchematicFileSerializer.cpp | 10 +- 4 files changed, 176 insertions(+), 200 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 406e18a3b..692b006d5 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -162,13 +162,6 @@ static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBB // cBlockArea: cBlockArea::cBlockArea(void) : - m_OriginX(0), - m_OriginY(0), - m_OriginZ(0), - m_SizeX(0), - m_SizeY(0), - m_SizeZ(0), - m_WEOffset(0, 0, 0), m_BlockTypes(NULL), m_BlockMetas(NULL), m_BlockLight(NULL), @@ -195,12 +188,8 @@ void cBlockArea::Clear(void) delete[] m_BlockMetas; m_BlockMetas = NULL; delete[] m_BlockLight; m_BlockLight = NULL; delete[] m_BlockSkyLight; m_BlockSkyLight = NULL; - m_OriginX = 0; - m_OriginY = 0; - m_OriginZ = 0; - m_SizeX = 0; - m_SizeY = 0; - m_SizeZ = 0; + m_Origin.Set(0, 0, 0); + m_Size.Set(0, 0, 0); } @@ -243,12 +232,8 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) m_BlockSkyLight[i] = 0x0f; } } - m_SizeX = a_SizeX; - m_SizeY = a_SizeY; - m_SizeZ = a_SizeZ; - m_OriginX = 0; - m_OriginY = 0; - m_OriginZ = 0; + m_Size.Set(a_SizeX, a_SizeY, a_SizeZ); + m_Origin.Set(0, 0, 0); } @@ -275,9 +260,7 @@ void cBlockArea::SetWEOffset(const Vector3i & a_Offset) void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ) { - m_OriginX = a_OriginX; - m_OriginY = a_OriginY; - m_OriginZ = a_OriginZ; + m_Origin.Set(a_OriginX, a_OriginY, a_OriginZ); } @@ -286,7 +269,7 @@ void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ) void cBlockArea::SetOrigin(const Vector3i & a_Origin) { - SetOrigin(a_Origin.x, a_Origin.y, a_Origin.z); + m_Origin.Set(a_Origin.x, a_Origin.y, a_Origin.z); } @@ -342,9 +325,7 @@ bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinB { return false; } - m_OriginX = a_MinBlockX; - m_OriginY = a_MinBlockY; - m_OriginZ = a_MinBlockZ; + m_Origin.Set(a_MinBlockX, a_MinBlockY, a_MinBlockZ); cChunkReader Reader(*this); // Convert block coords to chunks coords: @@ -408,10 +389,10 @@ bool cBlockArea::Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_Min LOGWARNING("%s: MinBlockY less than zero, adjusting to zero", __FUNCTION__); a_MinBlockY = 0; } - else if (a_MinBlockY > cChunkDef::Height - m_SizeY) + else if (a_MinBlockY > cChunkDef::Height - m_Size.y) { LOGWARNING("%s: MinBlockY + m_SizeY more than chunk height, adjusting to chunk height", __FUNCTION__); - a_MinBlockY = cChunkDef::Height - m_SizeY; + a_MinBlockY = cChunkDef::Height - m_Size.y; } return a_ForEachChunkProvider->WriteBlockArea(*this, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes); @@ -443,10 +424,8 @@ void cBlockArea::CopyTo(cBlockArea & a_Into) const } a_Into.Clear(); - a_Into.SetSize(m_SizeX, m_SizeY, m_SizeZ, GetDataTypes()); - a_Into.m_OriginX = m_OriginX; - a_Into.m_OriginY = m_OriginY; - a_Into.m_OriginZ = m_OriginZ; + a_Into.SetSize(m_Size.x, m_Size.y, m_Size.z, GetDataTypes()); + a_Into.m_Origin = m_Origin; int BlockCount = GetBlockCount(); if (HasBlockTypes()) { @@ -487,9 +466,9 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName) LOGWARNING("cBlockArea: Cannot open file \"%s\" for raw dump", a_FileName.c_str()); return; } - UInt32 SizeX = ntohl(m_SizeX); - UInt32 SizeY = ntohl(m_SizeY); - UInt32 SizeZ = ntohl(m_SizeZ); + UInt32 SizeX = ntohl(m_Size.x); + UInt32 SizeY = ntohl(m_Size.y); + UInt32 SizeZ = ntohl(m_Size.z); f.Write(&SizeX, 4); f.Write(&SizeY, 4); f.Write(&SizeZ, 4); @@ -532,13 +511,13 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName) void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ) { if ( - (a_AddMinX + a_SubMaxX >= m_SizeX) || - (a_AddMinY + a_SubMaxY >= m_SizeY) || - (a_AddMinZ + a_SubMaxZ >= m_SizeZ) + (a_AddMinX + a_SubMaxX >= m_Size.x) || + (a_AddMinY + a_SubMaxY >= m_Size.y) || + (a_AddMinZ + a_SubMaxZ >= m_Size.z) ) { LOGWARNING("cBlockArea:Crop called with more croping than the dimensions: %d x %d x %d with cropping %d, %d and %d", - m_SizeX, m_SizeY, m_SizeZ, + m_Size.x, m_Size.y, m_Size.z, a_AddMinX + a_SubMaxX, a_AddMinY + a_SubMaxY, a_AddMinZ + a_SubMaxZ ); return; @@ -560,12 +539,10 @@ void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY { CropNibbles(m_BlockSkyLight, a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ); } - m_OriginX += a_AddMinX; - m_OriginY += a_AddMinY; - m_OriginZ += a_AddMinZ; - m_SizeX -= a_AddMinX + a_SubMaxX; - m_SizeY -= a_AddMinY + a_SubMaxY; - m_SizeZ -= a_AddMinZ + a_SubMaxZ; + m_Origin.Move(a_AddMinX, a_AddMinY, a_AddMinZ); + m_Size.x -= a_AddMinX + a_SubMaxX; + m_Size.y -= a_AddMinY + a_SubMaxY; + m_Size.z -= a_AddMinZ + a_SubMaxZ; } @@ -590,12 +567,10 @@ void cBlockArea::Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMa { ExpandNibbles(m_BlockSkyLight, a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ); } - m_OriginX -= a_SubMinX; - m_OriginY -= a_SubMinY; - m_OriginZ -= a_SubMinZ; - m_SizeX += a_SubMinX + a_AddMaxX; - m_SizeY += a_SubMinY + a_AddMaxY; - m_SizeZ += a_SubMinZ + a_AddMaxZ; + m_Origin.Move(-a_SubMinX, -a_SubMinY, -a_SubMinZ); + m_Size.x += a_SubMinX + a_AddMaxX; + m_Size.y += a_SubMinY + a_AddMaxY; + m_Size.z += a_SubMinZ + a_AddMaxZ; } @@ -645,7 +620,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R SrcOffX, SrcOffY, SrcOffZ, DstOffX, DstOffY, DstOffZ, a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_SizeX, m_SizeY, m_SizeZ, + m_Size.x, m_Size.y, m_Size.z, MergeCombinatorOverwrite ); break; @@ -660,7 +635,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R SrcOffX, SrcOffY, SrcOffZ, DstOffX, DstOffY, DstOffZ, a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_SizeX, m_SizeY, m_SizeZ, + m_Size.x, m_Size.y, m_Size.z, MergeCombinatorFillAir ); break; @@ -675,7 +650,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R SrcOffX, SrcOffY, SrcOffZ, DstOffX, DstOffY, DstOffZ, a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_SizeX, m_SizeY, m_SizeZ, + m_Size.x, m_Size.y, m_Size.z, MergeCombinatorImprint ); break; @@ -690,7 +665,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R SrcOffX, SrcOffY, SrcOffZ, DstOffX, DstOffY, DstOffZ, a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_SizeX, m_SizeY, m_SizeZ, + m_Size.x, m_Size.y, m_Size.z, MergeCombinatorLake ); break; @@ -982,17 +957,17 @@ void cBlockArea::RotateCCW(void) } // We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time: - BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; - NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int x = 0; x < m_SizeX; x++) + BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()]; + NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()]; + for (int x = 0; x < m_Size.x; x++) { - int NewZ = m_SizeX - x - 1; - for (int z = 0; z < m_SizeZ; z++) + int NewZ = m_Size.x - x - 1; + for (int z = 0; z < m_Size.z; z++) { int NewX = z; - for (int y = 0; y < m_SizeY; y++) + for (int y = 0; y < m_Size.y; y++) { - int NewIdx = NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ; + int NewIdx = NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z; int OldIdx = MakeIndex(x, y, z); NewTypes[NewIdx] = m_BlockTypes[OldIdx]; NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCCW(m_BlockMetas[OldIdx]); @@ -1004,7 +979,7 @@ void cBlockArea::RotateCCW(void) delete[] NewTypes; delete[] NewMetas; - std::swap(m_SizeX, m_SizeZ); + std::swap(m_Size.x, m_Size.z); } @@ -1027,17 +1002,17 @@ void cBlockArea::RotateCW(void) } // We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time: - BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; - NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int x = 0; x < m_SizeX; x++) + BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()]; + NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()]; + for (int x = 0; x < m_Size.x; x++) { int NewZ = x; - for (int z = 0; z < m_SizeZ; z++) + for (int z = 0; z < m_Size.z; z++) { - int NewX = m_SizeZ - z - 1; - for (int y = 0; y < m_SizeY; y++) + int NewX = m_Size.z - z - 1; + for (int y = 0; y < m_Size.y; y++) { - int NewIdx = NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ; + int NewIdx = NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z; int OldIdx = MakeIndex(x, y, z); NewTypes[NewIdx] = m_BlockTypes[OldIdx]; NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCW(m_BlockMetas[OldIdx]); @@ -1049,7 +1024,7 @@ void cBlockArea::RotateCW(void) delete[] NewTypes; delete[] NewMetas; - std::swap(m_SizeX, m_SizeZ); + std::swap(m_Size.x, m_Size.z); } @@ -1072,13 +1047,13 @@ void cBlockArea::MirrorXY(void) } // We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time: - int HalfZ = m_SizeZ / 2; - int MaxZ = m_SizeZ - 1; - for (int y = 0; y < m_SizeY; y++) + int HalfZ = m_Size.z / 2; + int MaxZ = m_Size.z - 1; + for (int y = 0; y < m_Size.y; y++) { for (int z = 0; z < HalfZ; z++) { - for (int x = 0; x < m_SizeX; x++) + for (int x = 0; x < m_Size.x; x++) { int Idx1 = MakeIndex(x, y, z); int Idx2 = MakeIndex(x, y, MaxZ - z); @@ -1112,13 +1087,13 @@ void cBlockArea::MirrorXZ(void) } // We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time: - int HalfY = m_SizeY / 2; - int MaxY = m_SizeY - 1; + int HalfY = m_Size.y / 2; + int MaxY = m_Size.y - 1; for (int y = 0; y < HalfY; y++) { - for (int z = 0; z < m_SizeZ; z++) + for (int z = 0; z < m_Size.z; z++) { - for (int x = 0; x < m_SizeX; x++) + for (int x = 0; x < m_Size.x; x++) { int Idx1 = MakeIndex(x, y, z); int Idx2 = MakeIndex(x, MaxY - y, z); @@ -1152,11 +1127,11 @@ void cBlockArea::MirrorYZ(void) } // We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time: - int HalfX = m_SizeX / 2; - int MaxX = m_SizeX - 1; - for (int y = 0; y < m_SizeY; y++) + int HalfX = m_Size.x / 2; + int MaxX = m_Size.x - 1; + for (int y = 0; y < m_Size.y; y++) { - for (int z = 0; z < m_SizeZ; z++) + for (int z = 0; z < m_Size.z; z++) { for (int x = 0; x < HalfX; x++) { @@ -1180,16 +1155,16 @@ void cBlockArea::RotateCCWNoMeta(void) { if (HasBlockTypes()) { - BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int x = 0; x < m_SizeX; x++) + BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()]; + for (int x = 0; x < m_Size.x; x++) { - int NewZ = m_SizeX - x - 1; - for (int z = 0; z < m_SizeZ; z++) + int NewZ = m_Size.x - x - 1; + for (int z = 0; z < m_Size.z; z++) { int NewX = z; - for (int y = 0; y < m_SizeY; y++) + for (int y = 0; y < m_Size.y; y++) { - NewTypes[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockTypes[MakeIndex(x, y, z)]; + NewTypes[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockTypes[MakeIndex(x, y, z)]; } // for y } // for z } // for x @@ -1198,23 +1173,23 @@ void cBlockArea::RotateCCWNoMeta(void) } if (HasBlockMetas()) { - NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int x = 0; x < m_SizeX; x++) + NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()]; + for (int x = 0; x < m_Size.x; x++) { - int NewZ = m_SizeX - x - 1; - for (int z = 0; z < m_SizeZ; z++) + int NewZ = m_Size.x - x - 1; + for (int z = 0; z < m_Size.z; z++) { int NewX = z; - for (int y = 0; y < m_SizeY; y++) + for (int y = 0; y < m_Size.y; y++) { - NewMetas[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockMetas[MakeIndex(x, y, z)]; + NewMetas[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockMetas[MakeIndex(x, y, z)]; } // for y } // for z } // for x std::swap(m_BlockMetas, NewMetas); delete[] NewMetas; } - std::swap(m_SizeX, m_SizeZ); + std::swap(m_Size.x, m_Size.z); } @@ -1225,16 +1200,16 @@ void cBlockArea::RotateCWNoMeta(void) { if (HasBlockTypes()) { - BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int z = 0; z < m_SizeZ; z++) + BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()]; + for (int z = 0; z < m_Size.z; z++) { - int NewX = m_SizeZ - z - 1; - for (int x = 0; x < m_SizeX; x++) + int NewX = m_Size.z - z - 1; + for (int x = 0; x < m_Size.x; x++) { int NewZ = x; - for (int y = 0; y < m_SizeY; y++) + for (int y = 0; y < m_Size.y; y++) { - NewTypes[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockTypes[MakeIndex(x, y, z)]; + NewTypes[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockTypes[MakeIndex(x, y, z)]; } // for y } // for x } // for z @@ -1243,23 +1218,23 @@ void cBlockArea::RotateCWNoMeta(void) } if (HasBlockMetas()) { - NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int z = 0; z < m_SizeZ; z++) + NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()]; + for (int z = 0; z < m_Size.z; z++) { - int NewX = m_SizeZ - z - 1; - for (int x = 0; x < m_SizeX; x++) + int NewX = m_Size.z - z - 1; + for (int x = 0; x < m_Size.x; x++) { int NewZ = x; - for (int y = 0; y < m_SizeY; y++) + for (int y = 0; y < m_Size.y; y++) { - NewMetas[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockMetas[MakeIndex(x, y, z)]; + NewMetas[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockMetas[MakeIndex(x, y, z)]; } // for y } // for x } // for z std::swap(m_BlockMetas, NewMetas); delete[] NewMetas; } - std::swap(m_SizeX, m_SizeZ); + std::swap(m_Size.x, m_Size.z); } @@ -1268,15 +1243,15 @@ void cBlockArea::RotateCWNoMeta(void) void cBlockArea::MirrorXYNoMeta(void) { - int HalfZ = m_SizeZ / 2; - int MaxZ = m_SizeZ - 1; + int HalfZ = m_Size.z / 2; + int MaxZ = m_Size.z - 1; if (HasBlockTypes()) { - for (int y = 0; y < m_SizeY; y++) + for (int y = 0; y < m_Size.y; y++) { for (int z = 0; z < HalfZ; z++) { - for (int x = 0; x < m_SizeX; x++) + for (int x = 0; x < m_Size.x; x++) { std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, y, MaxZ - z)]); } // for x @@ -1286,11 +1261,11 @@ void cBlockArea::MirrorXYNoMeta(void) if (HasBlockMetas()) { - for (int y = 0; y < m_SizeY; y++) + for (int y = 0; y < m_Size.y; y++) { for (int z = 0; z < HalfZ; z++) { - for (int x = 0; x < m_SizeX; x++) + for (int x = 0; x < m_Size.x; x++) { std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, y, MaxZ - z)]); } // for x @@ -1305,15 +1280,15 @@ void cBlockArea::MirrorXYNoMeta(void) void cBlockArea::MirrorXZNoMeta(void) { - int HalfY = m_SizeY / 2; - int MaxY = m_SizeY - 1; + int HalfY = m_Size.y / 2; + int MaxY = m_Size.y - 1; if (HasBlockTypes()) { for (int y = 0; y < HalfY; y++) { - for (int z = 0; z < m_SizeZ; z++) + for (int z = 0; z < m_Size.z; z++) { - for (int x = 0; x < m_SizeX; x++) + for (int x = 0; x < m_Size.x; x++) { std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, MaxY - y, z)]); } // for x @@ -1325,9 +1300,9 @@ void cBlockArea::MirrorXZNoMeta(void) { for (int y = 0; y < HalfY; y++) { - for (int z = 0; z < m_SizeZ; z++) + for (int z = 0; z < m_Size.z; z++) { - for (int x = 0; x < m_SizeX; x++) + for (int x = 0; x < m_Size.x; x++) { std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, MaxY - y, z)]); } // for x @@ -1342,13 +1317,13 @@ void cBlockArea::MirrorXZNoMeta(void) void cBlockArea::MirrorYZNoMeta(void) { - int HalfX = m_SizeX / 2; - int MaxX = m_SizeX - 1; + int HalfX = m_Size.x / 2; + int MaxX = m_Size.x - 1; if (HasBlockTypes()) { - for (int y = 0; y < m_SizeY; y++) + for (int y = 0; y < m_Size.y; y++) { - for (int z = 0; z < m_SizeZ; z++) + for (int z = 0; z < m_Size.z; z++) { for (int x = 0; x < HalfX; x++) { @@ -1360,9 +1335,9 @@ void cBlockArea::MirrorYZNoMeta(void) if (HasBlockMetas()) { - for (int y = 0; y < m_SizeY; y++) + for (int y = 0; y < m_Size.y; y++) { - for (int z = 0; z < m_SizeZ; z++) + for (int z = 0; z < m_Size.z; z++) { for (int x = 0; x < HalfX; x++) { @@ -1393,7 +1368,7 @@ void cBlockArea::SetRelBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a void cBlockArea::SetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType) { - SetRelBlockType(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_BlockType); + SetRelBlockType(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType); } @@ -1470,7 +1445,7 @@ BLOCKTYPE cBlockArea::GetRelBlockType(int a_RelX, int a_RelY, int a_RelZ) const BLOCKTYPE cBlockArea::GetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ) const { - return GetRelBlockType(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ); + return GetRelBlockType(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z); } @@ -1533,7 +1508,7 @@ NIBBLETYPE cBlockArea::GetBlockSkyLight(int a_BlockX, int a_BlockY, int a_BlockZ void cBlockArea::SetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { - SetRelBlockTypeMeta(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_BlockType, a_BlockMeta); + SetRelBlockTypeMeta(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType, a_BlockMeta); } @@ -1567,7 +1542,7 @@ void cBlockArea::SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, B void cBlockArea::GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const { - return GetRelBlockTypeMeta(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_BlockType, a_BlockMeta); + return GetRelBlockTypeMeta(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType, a_BlockMeta); } @@ -1670,9 +1645,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) return false; } } - m_SizeX = a_SizeX; - m_SizeY = a_SizeY; - m_SizeZ = a_SizeZ; + m_Size.Set(a_SizeX, a_SizeY, a_SizeZ); return true; } @@ -1683,13 +1656,13 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) int cBlockArea::MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const { ASSERT(a_RelX >= 0); - ASSERT(a_RelX < m_SizeX); + ASSERT(a_RelX < m_Size.x); ASSERT(a_RelY >= 0); - ASSERT(a_RelY < m_SizeY); + ASSERT(a_RelY < m_Size.y); ASSERT(a_RelZ >= 0); - ASSERT(a_RelZ < m_SizeZ); + ASSERT(a_RelZ < m_Size.z); - return a_RelX + a_RelZ * m_SizeX + a_RelY * m_SizeX * m_SizeZ; + return a_RelX + a_RelZ * m_Size.x + a_RelY * m_Size.x * m_Size.z; } @@ -1712,7 +1685,7 @@ void cBlockArea::SetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_V void cBlockArea::SetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array) { - SetRelNibble(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_Value, a_Array); + SetRelNibble(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_Value, a_Array); } @@ -1735,7 +1708,7 @@ NIBBLETYPE cBlockArea::GetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETY NIBBLETYPE cBlockArea::GetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE * a_Array) const { - return GetRelNibble(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_Array); + return GetRelNibble(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_Array); } @@ -1748,9 +1721,7 @@ NIBBLETYPE cBlockArea::GetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBL cBlockArea::cChunkReader::cChunkReader(cBlockArea & a_Area) : m_Area(a_Area), - m_OriginX(a_Area.m_OriginX), - m_OriginY(a_Area.m_OriginY), - m_OriginZ(a_Area.m_OriginZ) + m_Origin(a_Area.m_Origin.x, a_Area.m_Origin.y, a_Area.m_Origin.z) { } @@ -1760,8 +1731,8 @@ cBlockArea::cChunkReader::cChunkReader(cBlockArea & a_Area) : void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLETYPE * a_ChunkSrc) { - int SizeY = m_Area.m_SizeY; - int MinY = m_OriginY; + int SizeY = m_Area.m_Size.y; + int MinY = m_Origin.y; // SizeX, SizeZ are the dmensions of the block data to copy from the current chunk (size of the geometric union) // OffX, OffZ are the offsets of the current chunk data from the area origin @@ -1770,7 +1741,7 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET int SizeZ = cChunkDef::Width; int OffX, OffZ; int BaseX, BaseZ; - OffX = m_CurrentChunkX * cChunkDef::Width - m_OriginX; + OffX = m_CurrentChunkX * cChunkDef::Width - m_Origin.x; if (OffX < 0) { BaseX = -OffX; @@ -1781,7 +1752,7 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET { BaseX = 0; } - OffZ = m_CurrentChunkZ * cChunkDef::Width - m_OriginZ; + OffZ = m_CurrentChunkZ * cChunkDef::Width - m_Origin.z; if (OffZ < 0) { BaseZ = -OffZ; @@ -1793,13 +1764,13 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET BaseZ = 0; } // If the chunk extends beyond the area in the X or Z axis, cut off the Size: - if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_OriginX + m_Area.m_SizeX) + if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_Origin.x + m_Area.m_Size.x) { - SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_OriginX + m_Area.m_SizeX); + SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_Origin.x + m_Area.m_Size.x); } - if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_OriginZ + m_Area.m_SizeZ) + if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_Origin.z + m_Area.m_Size.z) { - SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_OriginZ + m_Area.m_SizeZ); + SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_Origin.z + m_Area.m_Size.z); } for (int y = 0; y < SizeY; y++) @@ -1843,8 +1814,8 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes) return; } - int SizeY = m_Area.m_SizeY; - int MinY = m_OriginY; + int SizeY = m_Area.m_Size.y; + int MinY = m_Origin.y; // SizeX, SizeZ are the dmensions of the block data to copy from the current chunk (size of the geometric union) // OffX, OffZ are the offsets of the current chunk data from the area origin @@ -1853,7 +1824,7 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes) int SizeZ = cChunkDef::Width; int OffX, OffZ; int BaseX, BaseZ; - OffX = m_CurrentChunkX * cChunkDef::Width - m_OriginX; + OffX = m_CurrentChunkX * cChunkDef::Width - m_Origin.x; if (OffX < 0) { BaseX = -OffX; @@ -1864,7 +1835,7 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes) { BaseX = 0; } - OffZ = m_CurrentChunkZ * cChunkDef::Width - m_OriginZ; + OffZ = m_CurrentChunkZ * cChunkDef::Width - m_Origin.z; if (OffZ < 0) { BaseZ = -OffZ; @@ -1876,13 +1847,13 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes) BaseZ = 0; } // If the chunk extends beyond the area in the X or Z axis, cut off the Size: - if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_OriginX + m_Area.m_SizeX) + if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_Origin.x + m_Area.m_Size.x) { - SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_OriginX + m_Area.m_SizeX); + SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_Origin.x + m_Area.m_Size.x); } - if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_OriginZ + m_Area.m_SizeZ) + if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_Origin.z + m_Area.m_Size.z) { - SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_OriginZ + m_Area.m_SizeZ); + SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_Origin.z + m_Area.m_Size.z); } for (int y = 0; y < SizeY; y++) @@ -2002,21 +1973,21 @@ void cBlockArea::CropNibbles(NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX void cBlockArea::ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ) { - int NewSizeX = m_SizeX + a_SubMinX + a_AddMaxX; - int NewSizeY = m_SizeY + a_SubMinY + a_AddMaxY; - int NewSizeZ = m_SizeZ + a_SubMinZ + a_AddMaxZ; + int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX; + int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY; + int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ; int BlockCount = NewSizeX * NewSizeY * NewSizeZ; BLOCKTYPE * NewBlockTypes = new BLOCKTYPE[BlockCount]; memset(NewBlockTypes, 0, BlockCount * sizeof(BLOCKTYPE)); int OldIndex = 0; - for (int y = 0; y < m_SizeY; y++) + for (int y = 0; y < m_Size.y; y++) { - int IndexBaseY = (y + a_SubMinY) * m_SizeX * m_SizeZ; - for (int z = 0; z < m_SizeZ; z++) + int IndexBaseY = (y + a_SubMinY) * m_Size.x * m_Size.z; + for (int z = 0; z < m_Size.z; z++) { - int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_SizeX; + int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_Size.x; int idx = IndexBaseZ + a_SubMinX; - for (int x = 0; x < m_SizeX; x++) + for (int x = 0; x < m_Size.x; x++) { NewBlockTypes[idx++] = m_BlockTypes[OldIndex++]; } // for x @@ -2032,21 +2003,21 @@ void cBlockArea::ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, i void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ) { - int NewSizeX = m_SizeX + a_SubMinX + a_AddMaxX; - int NewSizeY = m_SizeY + a_SubMinY + a_AddMaxY; - int NewSizeZ = m_SizeZ + a_SubMinZ + a_AddMaxZ; + int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX; + int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY; + int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ; int BlockCount = NewSizeX * NewSizeY * NewSizeZ; NIBBLETYPE * NewNibbles = new NIBBLETYPE[BlockCount]; memset(NewNibbles, 0, BlockCount * sizeof(NIBBLETYPE)); int OldIndex = 0; - for (int y = 0; y < m_SizeY; y++) + for (int y = 0; y < m_Size.y; y++) { - int IndexBaseY = (y + a_SubMinY) * m_SizeX * m_SizeZ; - for (int z = 0; z < m_SizeZ; z++) + int IndexBaseY = (y + a_SubMinY) * m_Size.x * m_Size.z; + for (int z = 0; z < m_Size.z; z++) { - int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_SizeX; + int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_Size.x; int idx = IndexBaseZ + a_SubMinX; - for (int x = 0; x < m_SizeX; x++) + for (int x = 0; x < m_Size.x; x++) { NewNibbles[idx++] = a_Array[OldIndex++]; } // for x @@ -2057,6 +2028,9 @@ void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMa } + + + void cBlockArea::RelSetData( int a_RelX, int a_RelY, int a_RelZ, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, diff --git a/src/BlockArea.h b/src/BlockArea.h index e0e8fe972..22d55e2c9 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -43,6 +43,8 @@ public: baSkyLight = 8, } ; + /** The per-block strategy to use when merging another block area into this object. + See the Merge function for the description of these */ enum eMergeStrategy { msOverwrite, @@ -232,18 +234,24 @@ public: void GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; + // GetSize() is already exported manually to return 3 numbers, can't auto-export + const Vector3i & GetSize(void) const { return m_Size; } + + // GetOrigin() is already exported manually to return 3 numbers, can't auto-export + const Vector3i & GetOrigin(void) const { return m_Origin; } + // tolua_begin - int GetSizeX(void) const { return m_SizeX; } - int GetSizeY(void) const { return m_SizeY; } - int GetSizeZ(void) const { return m_SizeZ; } + int GetSizeX(void) const { return m_Size.x; } + int GetSizeY(void) const { return m_Size.y; } + int GetSizeZ(void) const { return m_Size.z; } /** Returns the volume of the area, as number of blocks */ - int GetVolume(void) const { return m_SizeX * m_SizeY * m_SizeZ; } + int GetVolume(void) const { return m_Size.x * m_Size.y * m_Size.z; } - int GetOriginX(void) const { return m_OriginX; } - int GetOriginY(void) const { return m_OriginY; } - int GetOriginZ(void) const { return m_OriginZ; } + int GetOriginX(void) const { return m_Origin.x; } + int GetOriginY(void) const { return m_Origin.y; } + int GetOriginZ(void) const { return m_Origin.z; } /** Returns the datatypes that are stored in the object (bitmask of baXXX values) */ int GetDataTypes(void) const; @@ -261,7 +269,7 @@ public: NIBBLETYPE * GetBlockMetas (void) const { return m_BlockMetas; } // NOTE: one byte per block! NIBBLETYPE * GetBlockLight (void) const { return m_BlockLight; } // NOTE: one byte per block! NIBBLETYPE * GetBlockSkyLight(void) const { return m_BlockSkyLight; } // NOTE: one byte per block! - int GetBlockCount(void) const { return m_SizeX * m_SizeY * m_SizeZ; } + int GetBlockCount(void) const { return m_Size.x * m_Size.y * m_Size.z; } int MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const; protected: @@ -276,9 +284,7 @@ protected: protected: cBlockArea & m_Area; - int m_OriginX; - int m_OriginY; - int m_OriginZ; + Vector3i m_Origin; int m_CurrentChunkX; int m_CurrentChunkZ; @@ -295,12 +301,8 @@ protected: typedef NIBBLETYPE * NIBBLEARRAY; - int m_OriginX; - int m_OriginY; - int m_OriginZ; - int m_SizeX; - int m_SizeY; - int m_SizeZ; + Vector3i m_Origin; + Vector3i m_Size; /** An extra data value sometimes stored in the .schematic file. Used mainly by the WorldEdit plugin. cBlockArea doesn't use this value in any way. */ diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp index 308fbe423..7711723fc 100644 --- a/src/Generating/ChunkDesc.cpp +++ b/src/Generating/ChunkDesc.cpp @@ -343,9 +343,9 @@ void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX int SizeY = a_MaxRelY - a_MinRelY; int SizeZ = a_MaxRelZ - a_MinRelZ; a_Dest.Clear(); - a_Dest.m_OriginX = m_ChunkX * cChunkDef::Width + a_MinRelX; - a_Dest.m_OriginY = a_MinRelY; - a_Dest.m_OriginZ = m_ChunkZ * cChunkDef::Width + a_MinRelZ; + a_Dest.m_Origin.x = m_ChunkX * cChunkDef::Width + a_MinRelX; + a_Dest.m_Origin.y = a_MinRelY; + a_Dest.m_Origin.z = m_ChunkZ * cChunkDef::Width + a_MinRelZ; a_Dest.SetSize(SizeX, SizeY, SizeZ, cBlockArea::baTypes | cBlockArea::baMetas); for (int y = 0; y < SizeY; y++) diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp index ef67fdb13..d8531d965 100644 --- a/src/WorldStorage/SchematicFileSerializer.cpp +++ b/src/WorldStorage/SchematicFileSerializer.cpp @@ -197,7 +197,7 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP } // Copy the block types and metas: - int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ; + int NumBytes = a_BlockArea.GetBlockCount(); if (a_NBT.GetDataLength(TBlockTypes) < NumBytes) { LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.", @@ -209,7 +209,7 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP if (AreMetasPresent) { - int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ; + int NumBytes = a_BlockArea.GetBlockCount(); if (a_NBT.GetDataLength(TBlockMetas) < NumBytes) { LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.", @@ -230,9 +230,9 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockArea) { cFastNBTWriter Writer("Schematic"); - Writer.AddShort("Width", a_BlockArea.m_SizeX); - Writer.AddShort("Height", a_BlockArea.m_SizeY); - Writer.AddShort("Length", a_BlockArea.m_SizeZ); + Writer.AddShort("Width", a_BlockArea.m_Size.x); + Writer.AddShort("Height", a_BlockArea.m_Size.y); + Writer.AddShort("Length", a_BlockArea.m_Size.z); Writer.AddString("Materials", "Alpha"); if (a_BlockArea.HasBlockTypes()) { -- cgit v1.2.3 From 87de5960785e0e007eaee0a8dbb77c64e20e7c8c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 25 Mar 2014 22:05:45 +0100 Subject: BlockArea: Create() can take the size as Vector3i, too. --- src/BlockArea.cpp | 9 +++++++++ src/BlockArea.h | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 692b006d5..f6d54e41c 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -240,6 +240,15 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) +void cBlockArea::Create(const Vector3i & a_Size, int a_DataTypes) +{ + Create(a_Size.x, a_Size.y, a_Size.z, a_DataTypes); +} + + + + + void cBlockArea::SetWEOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) { m_WEOffset.Set(a_OffsetX, a_OffsetY, a_OffsetZ); diff --git a/src/BlockArea.h b/src/BlockArea.h index 22d55e2c9..d28325d7d 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -59,12 +59,18 @@ public: /** Clears the data stored to reclaim memory */ void Clear(void); - /** Creates a new area of the specified size and contents. - Origin is set to all zeroes. + /** Creates a new area of the specified size and contents. + Origin is set to all zeroes. BlockTypes are set to air, block metas to zero, blocklights to zero and skylights to full light. */ void Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes = baTypes | baMetas); + /** Creates a new area of the specified size and contents. + Origin is set to all zeroes. + BlockTypes are set to air, block metas to zero, blocklights to zero and skylights to full light. + */ + void Create(const Vector3i & a_Size, int a_DataTypes = baTypes | baMetas); + /** Resets the origin. No other changes are made, contents are untouched. */ void SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ); -- cgit v1.2.3 From 37778e5f82f02eb417642390a36587a970e5479c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 25 Mar 2014 22:10:53 +0100 Subject: Added a basic cPrefab class. Can be defined in the source by GalExport's cpp output. --- src/Generating/Prefab.cpp | 139 ++++++++++++++++++++++++++++++++++++++++++++++ src/Generating/Prefab.h | 83 +++++++++++++++++++++++++++ 2 files changed, 222 insertions(+) create mode 100644 src/Generating/Prefab.cpp create mode 100644 src/Generating/Prefab.h diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp new file mode 100644 index 000000000..824800119 --- /dev/null +++ b/src/Generating/Prefab.cpp @@ -0,0 +1,139 @@ + +// Prefab.cpp + +/* +Implements the cPrefab class, representing a cPiece descendant for the cPieceGenerator that +uses a prefabricate in a cBlockArea for drawing itself. +*/ + +#include "Globals.h" +#include "Prefab.h" +#include "../WorldStorage/SchematicFileSerializer.h" + + + + + +cPrefab::cPrefab(const cPrefab::sDef & a_Def) : + m_Size(a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ), + m_HitBox(0, 0, 0, a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ), + m_AllowedRotations(7), // TODO: All rotations allowed (not in the definition yet) + m_MergeStrategy(cBlockArea::msImprint) +{ + m_BlockArea.Create(m_Size); + CharMap cm; + ParseCharMap(cm, a_Def.m_CharMap); + ParseBlockImage(cm, a_Def.m_Image); +} + + + + + +void cPrefab::Draw(cBlockArea & a_Dest, const cPlacedPiece * a_Placement) +{ + Vector3i Placement = a_Placement->GetCoords(); + Placement.Move(a_Dest.GetOrigin() * (-1)); + a_Dest.Merge(m_BlockArea, Placement, m_MergeStrategy); + +} + + + + + +void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef) +{ + // Initialize the charmap to all-invalid values: + for (size_t i = 0; i < ARRAYCOUNT(a_CharMapOut); i++) + { + a_CharMapOut[i] = -1; + } + + // Process the lines in the definition: + AStringVector Lines = StringSplitAndTrim(a_CharMapDef, "\n"); + for (AStringVector::const_iterator itr = Lines.begin(), end = Lines.end(); itr != end; ++itr) + { + AStringVector CharDef = StringSplitAndTrim(*itr, ":"); + size_t NumElements = CharDef.size(); + if ((NumElements < 2) || CharDef[0].empty() || CharDef[1].empty()) + { + LOGWARNING("Bad prefab CharMap definition line: \"%s\", skipping.", itr->c_str()); + continue; + } + unsigned char Src = (unsigned char)CharDef[0][0]; + BLOCKTYPE BlockType = (BLOCKTYPE)atoi(CharDef[1].c_str()); + NIBBLETYPE BlockMeta = 0; + if ((NumElements >= 3) && !CharDef[2].empty()) + { + BlockMeta = (NIBBLETYPE)atoi(CharDef[2].c_str()); + ASSERT((BlockMeta >= 0) && (BlockMeta <= 15)); + } + ASSERT(a_CharMapOut[Src] == -1); // Any duplicates letter-wise? + a_CharMapOut[Src] = (BlockType << 4) | BlockMeta; + } // for itr - Lines[] +} + + + + + +void cPrefab::ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockImage) +{ + // Map each letter in the a_BlockImage (from the in-source definition) to real blocktype / blockmeta: + for (int y = 0; y < m_Size.y; y++) + { + for (int z = 0; z < m_Size.z; z++) + { + const unsigned char * BlockImage = (const unsigned char *)a_BlockImage + y * m_Size.x * m_Size.z + z * m_Size.x; + for (int x = 0; x < m_Size.x; x++) + { + int MappedValue = a_CharMap[BlockImage[x]]; + ASSERT(MappedValue != -1); // Using a letter not defined in the CharMap? + BLOCKTYPE BlockType = MappedValue >> 4; + NIBBLETYPE BlockMeta = MappedValue & 0x0f; + m_BlockArea.SetRelBlockTypeMeta(x, y, z, BlockType, BlockMeta); + } + } + } +} + + + + + +cPiece::cConnectors cPrefab::GetConnectors(void) const +{ + return m_Connectors; +} + + + + + +Vector3i cPrefab::GetSize(void) const +{ + return m_Size; +} + + + + + +cCuboid cPrefab::GetHitBox(void) const +{ + return m_HitBox; +} + + + + + +bool cPrefab::CanRotateCCW(int a_NumRotations) const +{ + return ((m_AllowedRotations & (1 << (a_NumRotations % 4))) != 0); +} + + + + diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h new file mode 100644 index 000000000..6596b906b --- /dev/null +++ b/src/Generating/Prefab.h @@ -0,0 +1,83 @@ + +// Prefab.h + +/* +Declares the cPrefab class, representing a cPiece descendant for the cPieceGenerator that +uses a prefabricate in a cBlockArea for drawing itself. +The class can be constructed from data that is stored directly in the executable, in a sPrefabDef structure +declared in this file as well; the Gallery server exports areas in this format. +*/ + + + + + +#pragma once + +#include "PieceGenerator.h" +#include "../BlockArea.h" + + + + + + +class cPrefab : + public cPiece +{ +public: + struct sDef + { + int m_SizeX; + int m_SizeY; + int m_SizeZ; + const char * m_CharMap; + const char * m_Image; + // TODO: Connectors + }; + + cPrefab(const sDef & a_Def); + + /** Draws the prefab into the specified block area, according to the placement stored in the PlacedPiece. */ + void Draw(cBlockArea & a_Dest, const cPlacedPiece * a_Placement); + +protected: + /** Maps letters in the sDef::m_Image onto a number, BlockType * 16 | BlockMeta */ + typedef int CharMap[256]; + + + /** The cBlockArea that contains the block definitions for the prefab */ + cBlockArea m_BlockArea; + + /** The size of the prefab */ + Vector3i m_Size; + + /** The hitbox of the prefab. In first version is the same as the m_BlockArea dimensions */ + cCuboid m_HitBox; + + /** The connectors through which the piece connects to other pieces */ + cConnectors m_Connectors; + + /** Bitmask, bit N set -> N rotations CCW supported */ + int m_AllowedRotations; + + /** The merge strategy to use when drawing the prefab into a block area */ + cBlockArea::eMergeStrategy m_MergeStrategy; + + + // cPiece overrides: + virtual cConnectors GetConnectors(void) const override; + virtual Vector3i GetSize(void) const override; + virtual cCuboid GetHitBox(void) const override; + virtual bool CanRotateCCW(int a_NumRotations) const override; + + /** Parses the CharMap in the definition into a CharMap binary data used for translating the definition into BlockArea. */ + void ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef); + + /** Parses the Image in the definition into m_BlockArea's block types and metas, using the specified CharMap. */ + void ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockImage); +}; + + + + -- cgit v1.2.3 From e1285eb84f357c3111f5c7382c94bccc7068c660 Mon Sep 17 00:00:00 2001 From: narroo Date: Tue, 25 Mar 2014 17:17:05 -0400 Subject: Changed Rotater to Rotator. Added partial sign post rotation support. --- src/Blocks/BlockSign.h | 12 +++++ src/Blocks/MetaRotater.h | 120 ----------------------------------------------- src/Blocks/MetaRotator.h | 120 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 120 deletions(-) delete mode 100644 src/Blocks/MetaRotater.h create mode 100644 src/Blocks/MetaRotator.h diff --git a/src/Blocks/BlockSign.h b/src/Blocks/BlockSign.h index cd0c02a40..82d9a2fcc 100644 --- a/src/Blocks/BlockSign.h +++ b/src/Blocks/BlockSign.h @@ -71,6 +71,18 @@ public: { a_Player->GetClientHandle()->SendEditSign(a_BlockX, a_BlockY, a_BlockZ); } + + + virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override + { + return ++a_Meta; + } + + + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override + { + return --a_Meta; + } } ; diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h deleted file mode 100644 index dde88e6db..000000000 --- a/src/Blocks/MetaRotater.h +++ /dev/null @@ -1,120 +0,0 @@ -// MetaRotater.h - -// Provides a mixin for rotations and reflections - -#pragma once - -// MSVC generates warnings for the templated AssertIfNotMatched parameter conditions, so disable it: -#ifdef _MSC_VER - #pragma warning(disable: 4127) // Conditional expression is constant -#endif - - - - - -/* -Provides a mixin for rotations and reflections following the standard pattern of apply mask then use case. - -Usage: -Inherit from this class providing your base class as Base, the BitMask for the direction bits in bitmask and the masked value for the directions in North, East, South, West. There is also an aptional parameter AssertIfNotMatched. Set this if it is invalid for a block to exist in any other state. -*/ - -template -class cMetaRotater : public Base -{ -public: - - cMetaRotater(BLOCKTYPE a_BlockType) : - Base(a_BlockType) - {} - - virtual ~cMetaRotater() {} - - virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override; - virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override; - virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override; - virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override; -}; - - - - - -template -NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) -{ - NIBBLETYPE OtherMeta = a_Meta & (~BitMask); - switch (a_Meta & BitMask) - { - case South: return West | OtherMeta; - case West: return North | OtherMeta; - case North: return East | OtherMeta; - case East: return South | OtherMeta; - } - if (AssertIfNotMatched) - { - ASSERT(!"Invalid Meta value"); - } - return a_Meta; -} - - - - - -template -NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) -{ - NIBBLETYPE OtherMeta = a_Meta & (~BitMask); - switch (a_Meta & BitMask) - { - case South: return East | OtherMeta; - case East: return North | OtherMeta; - case North: return West | OtherMeta; - case West: return South | OtherMeta; - } - if (AssertIfNotMatched) - { - ASSERT(!"Invalid Meta value"); - } - return a_Meta; -} - - - - - -template -NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) -{ - NIBBLETYPE OtherMeta = a_Meta & (~BitMask); - switch (a_Meta & BitMask) - { - case South: return North | OtherMeta; - case North: return South | OtherMeta; - } - // Not Facing North or South; No change. - return a_Meta; -} - - - - - -template -NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) -{ - NIBBLETYPE OtherMeta = a_Meta & (~BitMask); - switch (a_Meta & BitMask) - { - case West: return East | OtherMeta; - case East: return West | OtherMeta; - } - // Not Facing East or West; No change. - return a_Meta; -} - - - - diff --git a/src/Blocks/MetaRotator.h b/src/Blocks/MetaRotator.h new file mode 100644 index 000000000..dde88e6db --- /dev/null +++ b/src/Blocks/MetaRotator.h @@ -0,0 +1,120 @@ +// MetaRotater.h + +// Provides a mixin for rotations and reflections + +#pragma once + +// MSVC generates warnings for the templated AssertIfNotMatched parameter conditions, so disable it: +#ifdef _MSC_VER + #pragma warning(disable: 4127) // Conditional expression is constant +#endif + + + + + +/* +Provides a mixin for rotations and reflections following the standard pattern of apply mask then use case. + +Usage: +Inherit from this class providing your base class as Base, the BitMask for the direction bits in bitmask and the masked value for the directions in North, East, South, West. There is also an aptional parameter AssertIfNotMatched. Set this if it is invalid for a block to exist in any other state. +*/ + +template +class cMetaRotater : public Base +{ +public: + + cMetaRotater(BLOCKTYPE a_BlockType) : + Base(a_BlockType) + {} + + virtual ~cMetaRotater() {} + + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override; + virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override; + virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override; + virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override; +}; + + + + + +template +NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) +{ + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) + { + case South: return West | OtherMeta; + case West: return North | OtherMeta; + case North: return East | OtherMeta; + case East: return South | OtherMeta; + } + if (AssertIfNotMatched) + { + ASSERT(!"Invalid Meta value"); + } + return a_Meta; +} + + + + + +template +NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) +{ + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) + { + case South: return East | OtherMeta; + case East: return North | OtherMeta; + case North: return West | OtherMeta; + case West: return South | OtherMeta; + } + if (AssertIfNotMatched) + { + ASSERT(!"Invalid Meta value"); + } + return a_Meta; +} + + + + + +template +NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) +{ + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) + { + case South: return North | OtherMeta; + case North: return South | OtherMeta; + } + // Not Facing North or South; No change. + return a_Meta; +} + + + + + +template +NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) +{ + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) + { + case West: return East | OtherMeta; + case East: return West | OtherMeta; + } + // Not Facing East or West; No change. + return a_Meta; +} + + + + -- cgit v1.2.3 From 3df4f8609dc2e28c2328ddf448fa53f5483f4262 Mon Sep 17 00:00:00 2001 From: narroo Date: Tue, 25 Mar 2014 17:26:13 -0400 Subject: Fixed spelling; Rotater to Rotator. --- src/Blocks/BlockBed.h | 6 +++--- src/Blocks/BlockButton.h | 6 +++--- src/Blocks/BlockChest.h | 6 +++--- src/Blocks/BlockComparator.h | 6 +++--- src/Blocks/BlockDoor.h | 6 +++--- src/Blocks/BlockDropSpenser.h | 6 +++--- src/Blocks/BlockEnderchest.h | 6 +++--- src/Blocks/BlockFenceGate.h | 6 +++--- src/Blocks/BlockFurnace.h | 6 +++--- src/Blocks/BlockHopper.h | 4 ++-- src/Blocks/BlockLadder.h | 4 ++-- src/Blocks/BlockStairs.h | 6 +++--- src/Blocks/BlockTorch.h | 6 +++--- src/Blocks/BlockVine.h | 2 +- src/Blocks/MetaRotator.h | 16 ++++++++-------- 15 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 6daa94730..92804aaac 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -4,7 +4,7 @@ #include "BlockHandler.h" #include "ChunkInterface.h" #include "WorldInterface.h" -#include "MetaRotater.h" +#include "MetaRotator.h" #include "../Entities/Player.h" @@ -12,11 +12,11 @@ class cBlockBedHandler : - public cMetaRotater + public cMetaRotator { public: cBlockBedHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 740cbe3c4..4b2f6f618 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -2,17 +2,17 @@ #include "BlockHandler.h" #include "Chunk.h" -#include "MetaRotater.h" +#include "MetaRotator.h" class cBlockButtonHandler : - public cMetaRotater + public cMetaRotator { public: cBlockButtonHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 890b5b933..a1ded4c26 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -4,18 +4,18 @@ #include "BlockEntity.h" #include "../BlockArea.h" #include "../Entities/Player.h" -#include "MetaRotater.h" +#include "MetaRotator.h" class cBlockChestHandler : - public cMetaRotater + public cMetaRotator { public: cBlockChestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index e570ff302..4dd05366d 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -3,18 +3,18 @@ #include "BlockHandler.h" #include "BlockRedstoneRepeater.h" -#include "MetaRotater.h" +#include "MetaRotator.h" class cBlockComparatorHandler : - public cMetaRotater + public cMetaRotator { public: cBlockComparatorHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 066e1ab28..797fe484c 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -4,15 +4,15 @@ #include "BlockHandler.h" #include "../Entities/Player.h" #include "Chunk.h" -#include "MetaRotater.h" +#include "MetaRotator.h" class cBlockDoorHandler : - public cMetaRotater + public cMetaRotator { - typedef cMetaRotater super; + typedef cMetaRotator super; public: cBlockDoorHandler(BLOCKTYPE a_BlockType); diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index 7e0ad0e55..88b61a418 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -6,18 +6,18 @@ #pragma once #include "../Piston.h" -#include "MetaRotater.h" +#include "MetaRotator.h" class cBlockDropSpenserHandler : - public cMetaRotater + public cMetaRotator { public: cBlockDropSpenserHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index 97cf484fb..67955f8ce 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -2,17 +2,17 @@ #pragma once #include "BlockEntity.h" -#include "MetaRotater.h" +#include "MetaRotator.h" class cBlockEnderchestHandler : - public cMetaRotater + public cMetaRotator { public: cBlockEnderchestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index e3162bbd6..e202c6610 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -2,17 +2,17 @@ #pragma once #include "BlockHandler.h" -#include "MetaRotater.h" +#include "MetaRotator.h" class cBlockFenceGateHandler : - public cMetaRotater + public cMetaRotator { public: cBlockFenceGateHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockFurnace.h b/src/Blocks/BlockFurnace.h index c7f8ff8d2..a7a807957 100644 --- a/src/Blocks/BlockFurnace.h +++ b/src/Blocks/BlockFurnace.h @@ -4,17 +4,17 @@ #include "BlockEntity.h" #include "../World.h" #include "../Piston.h" -#include "MetaRotater.h" +#include "MetaRotator.h" class cBlockFurnaceHandler : - public cMetaRotater + public cMetaRotator { public: cBlockFurnaceHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockHopper.h b/src/Blocks/BlockHopper.h index 610296529..a882bb077 100644 --- a/src/Blocks/BlockHopper.h +++ b/src/Blocks/BlockHopper.h @@ -8,11 +8,11 @@ class cBlockHopperHandler : - public cMetaRotater + public cMetaRotator { public: cBlockHopperHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h index 12408759e..a605edf3f 100644 --- a/src/Blocks/BlockLadder.h +++ b/src/Blocks/BlockLadder.h @@ -9,11 +9,11 @@ class cBlockLadderHandler : - public cMetaRotater + public cMetaRotator { public: cBlockLadderHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index ea8405597..1072b7e71 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -2,17 +2,17 @@ #pragma once #include "BlockHandler.h" -#include "MetaRotater.h" +#include "MetaRotator.h" class cBlockStairsHandler : - public cMetaRotater + public cMetaRotator { public: cBlockStairsHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index d32c77629..8ddec8de1 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -2,17 +2,17 @@ #include "BlockHandler.h" #include "../Chunk.h" -#include "MetaRotater.h" +#include "MetaRotator.h" class cBlockTorchHandler : - public cMetaRotater + public cMetaRotator { public: cBlockTorchHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotator(a_BlockType) { } diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index 708583e70..0b57acc7b 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -1,7 +1,7 @@ #pragma once #include "BlockHandler.h" -#include "MetaRotater.h" +#include "MetaRotator.h" diff --git a/src/Blocks/MetaRotator.h b/src/Blocks/MetaRotator.h index dde88e6db..899c583e1 100644 --- a/src/Blocks/MetaRotator.h +++ b/src/Blocks/MetaRotator.h @@ -1,4 +1,4 @@ -// MetaRotater.h +// MetaRotator.h // Provides a mixin for rotations and reflections @@ -21,15 +21,15 @@ Inherit from this class providing your base class as Base, the BitMask for the d */ template -class cMetaRotater : public Base +class cMetaRotator : public Base { public: - cMetaRotater(BLOCKTYPE a_BlockType) : + cMetaRotator(BLOCKTYPE a_BlockType) : Base(a_BlockType) {} - virtual ~cMetaRotater() {} + virtual ~cMetaRotator() {} virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override; virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override; @@ -42,7 +42,7 @@ public: template -NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) +NIBBLETYPE cMetaRotator::MetaRotateCW(NIBBLETYPE a_Meta) { NIBBLETYPE OtherMeta = a_Meta & (~BitMask); switch (a_Meta & BitMask) @@ -64,7 +64,7 @@ NIBBLETYPE cMetaRotater -NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) +NIBBLETYPE cMetaRotator::MetaRotateCCW(NIBBLETYPE a_Meta) { NIBBLETYPE OtherMeta = a_Meta & (~BitMask); switch (a_Meta & BitMask) @@ -86,7 +86,7 @@ NIBBLETYPE cMetaRotater -NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) +NIBBLETYPE cMetaRotator::MetaMirrorXY(NIBBLETYPE a_Meta) { NIBBLETYPE OtherMeta = a_Meta & (~BitMask); switch (a_Meta & BitMask) @@ -103,7 +103,7 @@ NIBBLETYPE cMetaRotater -NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) +NIBBLETYPE cMetaRotator::MetaMirrorYZ(NIBBLETYPE a_Meta) { NIBBLETYPE OtherMeta = a_Meta & (~BitMask); switch (a_Meta & BitMask) -- cgit v1.2.3 From d5c7fc6bd65bfabf8d95b6f2c4cbdf5dd2b447b7 Mon Sep 17 00:00:00 2001 From: narroo Date: Tue, 25 Mar 2014 17:35:48 -0400 Subject: Added a comment about the behavior of doors under mirros. Simply put, the current implementation of MetaMirror causes glitchy behavior. The door class itself needs to be edited. (I've got an idea on that....) --- src/Blocks/BlockDoor.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index c027daed2..100f48e6c 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -143,7 +143,10 @@ NIBBLETYPE cBlockDoorHandler::MetaMirrorXY(NIBBLETYPE a_Meta) { // Top bit (0x08) contains door panel type (Top/Bottom panel) Only Bottom panels contain position data // Return a_Meta if panel is a top panel (0x08 bit is set to 1) - LOG("Test MirrorXY"); + + // Note: Currently, you can not properly mirror the hinges on a double door. The orientation of the door is stored + // in only the bottom tile while the hinge position is in the top tile. This function only operates on one tile at a time, + // so the function can only see either the hinge position or orientation, but not both, at any given time. if (a_Meta & 0x08) return a_Meta; // Holds open/closed meta data. 0x0C == 1100. @@ -166,7 +169,10 @@ NIBBLETYPE cBlockDoorHandler::MetaMirrorYZ(NIBBLETYPE a_Meta) { // Top bit (0x08) contains door panel type (Top/Bottom panel) Only Bottom panels contain position data // Return a_Meta if panel is a top panel (0x08 bit is set to 1) - LOG("Test MirrorYZ"); + + // Note: Currently, you can not properly mirror the hinges on a double door. The orientation of the door is stored + // in only the bottom tile while the hinge position is in the top tile. This function only operates on one tile at a time, + // so the function can only see either the hinge position or orientation, but not both, at any given time. if (a_Meta & 0x08) return a_Meta; // Holds open/closed meta data. 0x0C == 1100. -- cgit v1.2.3 From 9032ff96c7c6db4264eedda95de7ea55f155bc47 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 25 Mar 2014 23:35:50 +0100 Subject: Removed unused constants. DeadlockDetect reads the value from the ini file, and world lighting has a separate queue now. --- src/DeadlockDetect.cpp | 5 +---- src/World.cpp | 3 --- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/DeadlockDetect.cpp b/src/DeadlockDetect.cpp index 4dc7bfde6..322084dc4 100644 --- a/src/DeadlockDetect.cpp +++ b/src/DeadlockDetect.cpp @@ -7,7 +7,7 @@ #include "DeadlockDetect.h" #include "Root.h" #include "World.h" -# include +#include @@ -16,9 +16,6 @@ /// Number of milliseconds per cycle const int CYCLE_MILLISECONDS = 100; -/// When the number of cycles for the same world age hits this value, it is considered a deadlock -const int NUM_CYCLES_LIMIT = 200; // 200 = twenty seconds - diff --git a/src/World.cpp b/src/World.cpp index 3f157157a..e39a605bb 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -60,9 +60,6 @@ -/// Up to this many m_SpreadQueue elements are handled each world tick -const int MAX_LIGHTING_SPREAD_PER_TICK = 10; - const int TIME_SUNSET = 12000; const int TIME_NIGHT_START = 13187; const int TIME_NIGHT_END = 22812; -- cgit v1.2.3 From 1b00b62a4b8f27e14e31e251020321e41a284b21 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 25 Mar 2014 23:49:58 +0100 Subject: Ignoring the default GalExports folder. --- MCServer/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/MCServer/.gitignore b/MCServer/.gitignore index 64f062ef7..69826ef06 100644 --- a/MCServer/.gitignore +++ b/MCServer/.gitignore @@ -6,6 +6,7 @@ MCServer MCServer_debug CommLogs/ +GalExports/ logs players world* -- cgit v1.2.3 From 90415ff79886f63cacced59f202228ddac69765a Mon Sep 17 00:00:00 2001 From: narroo Date: Wed, 26 Mar 2014 08:54:17 -0400 Subject: Fixed Minor typos. --- src/Blocks/BlockDoor.cpp | 7 +++++-- src/Blocks/BlockRail.h | 12 ++++++------ src/Blocks/BlockSlab.h | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index 100f48e6c..479c68153 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -146,7 +146,8 @@ NIBBLETYPE cBlockDoorHandler::MetaMirrorXY(NIBBLETYPE a_Meta) // Note: Currently, you can not properly mirror the hinges on a double door. The orientation of the door is stored // in only the bottom tile while the hinge position is in the top tile. This function only operates on one tile at a time, - // so the function can only see either the hinge position or orientation, but not both, at any given time. + // so the function can only see either the hinge position or orientation, but not both, at any given time. The class itself + // needs extra datamembers. if (a_Meta & 0x08) return a_Meta; // Holds open/closed meta data. 0x0C == 1100. @@ -172,7 +173,9 @@ NIBBLETYPE cBlockDoorHandler::MetaMirrorYZ(NIBBLETYPE a_Meta) // Note: Currently, you can not properly mirror the hinges on a double door. The orientation of the door is stored // in only the bottom tile while the hinge position is in the top tile. This function only operates on one tile at a time, - // so the function can only see either the hinge position or orientation, but not both, at any given time. + // so the function can only see either the hinge position or orientation, but not both, at any given time.The class itself + // needs extra datamembers. + if (a_Meta & 0x08) return a_Meta; // Holds open/closed meta data. 0x0C == 1100. diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index f56ec7152..477707a91 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -453,8 +453,8 @@ public: case 0x02: return 0x04 + OtherMeta; // Asc. East -> Asc. North case 0x04: return 0x03 + OtherMeta; // Asc. North -> Asc. West - case 0x03: return 0x05 + OtherMeta; // Asc. West -> Asc. South - case 0x05: return 0x02 + OtherMeta; // Asc. South -> Asc. East + case 0x03: return 0x05 + OtherMeta; // Asc. West -> Asc. South + case 0x05: return 0x02 + OtherMeta; // Asc. South -> Asc. East } } else @@ -489,8 +489,8 @@ public: case 0x02: return 0x05 + OtherMeta; // Asc. East -> Asc. South case 0x05: return 0x03 + OtherMeta; // Asc. South -> Asc. West - case 0x03: return 0x04 + OtherMeta; // Asc. West -> Asc. North - case 0x04: return 0x02 + OtherMeta; // Asc. North -> Asc. East + case 0x03: return 0x04 + OtherMeta; // Asc. West -> Asc. North + case 0x04: return 0x02 + OtherMeta; // Asc. North -> Asc. East } } else @@ -521,7 +521,7 @@ public: switch (a_Meta & 0x07) { case 0x05: return 0x04 + OtherMeta; // Asc. South -> Asc. North - case 0x04: return 0x05 + OtherMeta; // Asc. North -> Asc. South + case 0x04: return 0x05 + OtherMeta; // Asc. North -> Asc. South } } else @@ -552,7 +552,7 @@ public: switch (a_Meta & 0x07) { case 0x02: return 0x03 + OtherMeta; // Asc. East -> Asc. West - case 0x03: return 0x02 + OtherMeta; // Asc. West -> Asc. East + case 0x03: return 0x02 + OtherMeta; // Asc. West -> Asc. East } } else diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index b18bf7ef3..77e8b8e55 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -186,7 +186,7 @@ public: virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override { - NIBBLETYPE OtherMeta = a_Meta & 0x07; // Contains unrelate meta data. + NIBBLETYPE OtherMeta = a_Meta & 0x07; // Contains unrelated meta data. // 8th bit is up/down. 1 right-side-up, 0 is up-side-down. return (a_Meta & 0x08) ? 0x00 + OtherMeta : 0x01 + OtherMeta; -- cgit v1.2.3 From 6553c8ff447a1e006095dc7e5aad76b37c410038 Mon Sep 17 00:00:00 2001 From: narroo Date: Wed, 26 Mar 2014 13:25:10 -0400 Subject: Altered the rotates for cBlockSignHandler. The functions as a whole is still unfinished though; no wall sign or mirroring support yet. --- src/Blocks/BlockSign.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Blocks/BlockSign.h b/src/Blocks/BlockSign.h index 82d9a2fcc..24346b930 100644 --- a/src/Blocks/BlockSign.h +++ b/src/Blocks/BlockSign.h @@ -75,13 +75,13 @@ public: virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override { - return ++a_Meta; + return (++a_Meta) & 0x0F; } virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override { - return --a_Meta; + return (--a_Meta) & 0x0F; } } ; -- cgit v1.2.3 From 8c2c4f2463fcc429d336019fa0fd39098eb7d97f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 26 Mar 2014 22:01:01 +0100 Subject: Prefabs support connectors, rotations and merge strategy. --- src/Generating/Prefab.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++-- src/Generating/Prefab.h | 10 +++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 824800119..ded4f6c41 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -17,13 +17,14 @@ uses a prefabricate in a cBlockArea for drawing itself. cPrefab::cPrefab(const cPrefab::sDef & a_Def) : m_Size(a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ), m_HitBox(0, 0, 0, a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ), - m_AllowedRotations(7), // TODO: All rotations allowed (not in the definition yet) - m_MergeStrategy(cBlockArea::msImprint) + m_AllowedRotations(a_Def.m_AllowedRotations), + m_MergeStrategy(a_Def.m_MergeStrategy) { m_BlockArea.Create(m_Size); CharMap cm; ParseCharMap(cm, a_Def.m_CharMap); ParseBlockImage(cm, a_Def.m_Image); + ParseConnectors(a_Def.m_Connectors); } @@ -42,6 +43,22 @@ void cPrefab::Draw(cBlockArea & a_Dest, const cPlacedPiece * a_Placement) +bool cPrefab::HasConnectorType(int a_ConnectorType) const +{ + for (cConnectors::const_iterator itr = m_Connectors.begin(), end = m_Connectors.end(); itr != end; ++itr) + { + if (itr->m_Type == a_ConnectorType) + { + return true; + } + } // for itr - m_Connectors[] + return false; +} + + + + + void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef) { // Initialize the charmap to all-invalid values: @@ -102,6 +119,50 @@ void cPrefab::ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockIma +void cPrefab::ParseConnectors(const char * a_ConnectorsDef) +{ + AStringVector Lines = StringSplitAndTrim(a_ConnectorsDef, "\n"); + for (AStringVector::const_iterator itr = Lines.begin(), end = Lines.end(); itr != end; ++itr) + { + if (itr->empty()) + { + continue; + } + // Split into components: "Type: X, Y, Z: Face": + AStringVector Defs = StringSplitAndTrim(*itr, ":"); + if (Defs.size() != 3) + { + LOGWARNING("Bad prefab Connector definition line: \"%s\", skipping.", itr->c_str()); + continue; + } + AStringVector Coords = StringSplitAndTrim(Defs[1], ","); + if (Coords.size() != 3) + { + LOGWARNING("Bad prefab Connector coords definition: \"%s\", skipping.", Defs[1].c_str()); + continue; + } + + // Check that the BlockFace is within range: + int BlockFace = atoi(Defs[2].c_str()); + if ((BlockFace < 0) || (BlockFace >= 6)) + { + LOGWARNING("Bad prefab Connector Blockface: \"%s\", skipping.", Defs[2].c_str()); + continue; + } + + // Add the connector: + m_Connectors.push_back(cPiece::cConnector( + atoi(Coords[0].c_str()), atoi(Coords[1].c_str()), atoi(Coords[2].c_str()), // Connector pos + atoi(Defs[0].c_str()), // Connector type + (eBlockFace)BlockFace + )); + } // for itr - Lines[] +} + + + + + cPiece::cConnectors cPrefab::GetConnectors(void) const { return m_Connectors; diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index 6596b906b..3733166ab 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -33,13 +33,18 @@ public: int m_SizeZ; const char * m_CharMap; const char * m_Image; - // TODO: Connectors + const char * m_Connectors; + int m_AllowedRotations; + cBlockArea::eMergeStrategy m_MergeStrategy; }; cPrefab(const sDef & a_Def); /** Draws the prefab into the specified block area, according to the placement stored in the PlacedPiece. */ void Draw(cBlockArea & a_Dest, const cPlacedPiece * a_Placement); + + /** Returns true if the prefab has any connector of the specified type. */ + bool HasConnectorType(int a_ConnectorType) const; protected: /** Maps letters in the sDef::m_Image onto a number, BlockType * 16 | BlockMeta */ @@ -76,6 +81,9 @@ protected: /** Parses the Image in the definition into m_BlockArea's block types and metas, using the specified CharMap. */ void ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockImage); + + /** Parses the connectors definition text into m_Connectors member. */ + void ParseConnectors(const char * a_ConnectorsDef); }; -- cgit v1.2.3 From bbebb3a2cdbd888e63e4a40b1bcc730105c11377 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 27 Mar 2014 18:13:52 +0100 Subject: Fixed chunk neighbor-getting for long distances. This fixes a server hang when teleporting to coords too far away. --- src/Chunk.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 957d7d575..bd4cb9937 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -2510,6 +2510,17 @@ cChunk * cChunk::GetNeighborChunk(int a_BlockX, int a_BlockZ) cChunk * cChunk::GetRelNeighborChunk(int a_RelX, int a_RelZ) { + // If the relative coords are too far away, use the parent's chunk lookup instead: + if ((a_RelX < 128) || (a_RelX > 128) || (a_RelZ < -128) || (a_RelZ > 128)) + { + int BlockX = m_PosX * cChunkDef::Width + a_RelX; + int BlockZ = m_PosZ * cChunkDef::Width + a_RelZ; + int BlockY, ChunkX, ChunkZ; + AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); + return m_ChunkMap->GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + } + + // Walk the neighbors: bool ReturnThis = true; if (a_RelX < 0) { -- cgit v1.2.3 From 7b585290fccd3dc074b1f9feef0af754ab3dd632 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 27 Mar 2014 23:03:57 +0100 Subject: cPrefab can draw itself into a cChunkDesc. --- src/Generating/Prefab.cpp | 11 +++++++---- src/Generating/Prefab.h | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index ded4f6c41..145c875a1 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -9,6 +9,7 @@ uses a prefabricate in a cBlockArea for drawing itself. #include "Globals.h" #include "Prefab.h" #include "../WorldStorage/SchematicFileSerializer.h" +#include "ChunkDesc.h" @@ -16,7 +17,7 @@ uses a prefabricate in a cBlockArea for drawing itself. cPrefab::cPrefab(const cPrefab::sDef & a_Def) : m_Size(a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ), - m_HitBox(0, 0, 0, a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ), + m_HitBox(0, 0, 0, a_Def.m_SizeX - 1, a_Def.m_SizeY - 1, a_Def.m_SizeZ - 1), m_AllowedRotations(a_Def.m_AllowedRotations), m_MergeStrategy(a_Def.m_MergeStrategy) { @@ -31,11 +32,13 @@ cPrefab::cPrefab(const cPrefab::sDef & a_Def) : -void cPrefab::Draw(cBlockArea & a_Dest, const cPlacedPiece * a_Placement) +void cPrefab::Draw(cChunkDesc & a_Dest, const cPlacedPiece * a_Placement) const { Vector3i Placement = a_Placement->GetCoords(); - Placement.Move(a_Dest.GetOrigin() * (-1)); - a_Dest.Merge(m_BlockArea, Placement, m_MergeStrategy); + int ChunkStartX = a_Dest.GetChunkX() * cChunkDef::Width; + int ChunkStartZ = a_Dest.GetChunkZ() * cChunkDef::Width; + Placement.Move(-ChunkStartX, 0, -ChunkStartZ); + a_Dest.WriteBlockArea(m_BlockArea, Placement.x, Placement.y, Placement.z, m_MergeStrategy); } diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index 3733166ab..ec95c909b 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -40,8 +40,8 @@ public: cPrefab(const sDef & a_Def); - /** Draws the prefab into the specified block area, according to the placement stored in the PlacedPiece. */ - void Draw(cBlockArea & a_Dest, const cPlacedPiece * a_Placement); + /** Draws the prefab into the specified chunk, according to the placement stored in the PlacedPiece. */ + void Draw(cChunkDesc & a_Dest, const cPlacedPiece * a_Placement) const; /** Returns true if the prefab has any connector of the specified type. */ bool HasConnectorType(int a_ConnectorType) const; -- cgit v1.2.3 From 7089c5e2671d2bf7781ab2eab7129bb5bd25b1a1 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 14:01:22 +0100 Subject: Add new leaves to all classes. --- src/Blocks/BlockLeaves.h | 2 +- src/ChunkMap.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index a6d3373c1..954b993d6 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -87,7 +87,7 @@ public: return; } - if ((Meta & 0x8) != 0) + if ((Meta & 0x8) == 0) { // These leaves have been checked for decay lately and nothing around them changed return; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index e695f0ab2..da5dd90e4 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1384,6 +1384,13 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks) } break; } + case E_BLOCK_NEW_LEAVES: + { + if (itr->BlockType == E_BLOCK_NEW_LOG) + { + Chunk->SetBlock(itr->x, itr->y, itr->z, itr->BlockType, itr->BlockMeta); + } + } } } // for itr - a_Blocks[] } -- cgit v1.2.3 From c4a8336e847d2f4731dd9d899d6af200631f8aef Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 14:38:41 +0100 Subject: Add HOOK_BLOCK_SPREAD --- src/Bindings/Plugin.h | 1 + src/Bindings/PluginLua.cpp | 21 +++++++++++++++++++++ src/Bindings/PluginLua.h | 1 + src/Bindings/PluginManager.cpp | 21 +++++++++++++++++++++ src/Bindings/PluginManager.h | 2 ++ src/Simulator/FireSimulator.cpp | 14 +++++++++++--- 6 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 949e4693a..4c6d5a938 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -46,6 +46,7 @@ public: * On all these functions, return true if you want to override default behavior and not call other plugins on that callback. * You can also return false, so default behavior is used. **/ + virtual bool OnBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) = 0; virtual bool OnBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) = 0; virtual bool OnChat (cPlayer * a_Player, AString & a_Message) = 0; virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index cccbc3c93..cefeb4996 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -195,6 +195,26 @@ void cPluginLua::Tick(float a_Dt) +bool cPluginLua::OnBlockSpread(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +{ + cCSLock Lock(m_CriticalSection); + bool res = false; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_BLOCK_SPREAD]; + for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) + { + m_LuaState.Call((int)(**itr), a_World, a_BlockX, a_BlockY, a_BlockZ, cLuaState::Return, res); + if (res) + { + return true; + } + } + return false; +} + + + + + bool cPluginLua::OnBlockToPickups(cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) { cCSLock Lock(m_CriticalSection); @@ -1430,6 +1450,7 @@ const char * cPluginLua::GetHookFnName(int a_HookType) { switch (a_HookType) { + case cPluginManager::HOOK_BLOCK_SPREAD: return "OnBlockSpread"; case cPluginManager::HOOK_BLOCK_TO_PICKUPS: return "OnBlockToPickups"; case cPluginManager::HOOK_CHAT: return "OnChat"; case cPluginManager::HOOK_CHUNK_AVAILABLE: return "OnChunkAvailable"; diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index a177f5288..5c2c9e57f 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -69,6 +69,7 @@ public: virtual void Tick(float a_Dt) override; + virtual bool OnBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual bool OnBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) override; virtual bool OnChat (cPlayer * a_Player, AString & a_Message) override; virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index b9cf160c4..142b4b5ad 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -205,6 +205,27 @@ void cPluginManager::Tick(float a_Dt) +bool cPluginManager::CallHookBlockSpread(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +{ + HookMap::iterator Plugins = m_Hooks.find(HOOK_BLOCK_SPREAD); + if (Plugins == m_Hooks.end()) + { + return false; + } + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnBlockSpread(a_World, a_BlockX, a_BlockY, a_BlockZ)) + { + return true; + } + } + return false; +} + + + + + bool cPluginManager::CallHookBlockToPickups( cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 44bc5a8d7..18d34a50d 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -58,6 +58,7 @@ public: // tolua_export // tolua_begin enum PluginHook { + HOOK_BLOCK_SPREAD, HOOK_BLOCK_TO_PICKUPS, HOOK_CHAT, HOOK_CHUNK_AVAILABLE, @@ -154,6 +155,7 @@ public: // tolua_export unsigned int GetNumPlugins() const; // tolua_export // Calls for individual hooks. Each returns false if the action is to continue or true if the plugin wants to abort + bool CallHookBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ); bool CallHookBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups); bool CallHookChat (cPlayer * a_Player, AString & a_Message); bool CallHookChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ); diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index 26712e6e6..871a1ec5c 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -6,6 +6,8 @@ #include "../BlockID.h" #include "../Defines.h" #include "../Chunk.h" +#include "Root.h" +#include "PluginManager.h" @@ -315,9 +317,15 @@ void cFireSimulator::TrySpreadFire(cChunk * a_Chunk, int a_RelX, int a_RelY, int */ if (CanStartFireInBlock(a_Chunk, x, y, z)) { - FLOG("FS: Starting new fire at {%d, %d, %d}.", - x + a_Chunk->GetPosX() * cChunkDef::Width, y, z + a_Chunk->GetPosZ() * cChunkDef::Width - ); + int a_PosX = x + a_Chunk->GetPosX() * cChunkDef::Width; + int a_PosZ = z + a_Chunk->GetPosZ() * cChunkDef::Width; + + if (cRoot::Get()->GetPluginManager()->CallHookBlockSpread(&m_World, a_PosX, y, a_PosZ)) + { + return; + } + + FLOG("FS: Starting new fire at {%d, %d, %d}.", a_PosX, y, a_PosZ); a_Chunk->UnboundedRelSetBlock(x, y, z, E_BLOCK_FIRE, 0); } } // for y -- cgit v1.2.3 From 3774b1be6445257a28677fbdce17bab58c168df9 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 16:06:03 +0100 Subject: Add SpreadSource --- src/Bindings/Plugin.h | 2 +- src/Bindings/PluginLua.cpp | 4 ++-- src/Bindings/PluginLua.h | 2 +- src/Bindings/PluginManager.cpp | 4 ++-- src/Bindings/PluginManager.h | 2 +- src/BlockID.h | 13 +++++++++++++ src/Blocks/BlockDirt.h | 5 ++++- src/Blocks/BlockMushroom.h | 3 +++ src/Blocks/BlockMycelium.h | 2 ++ src/Blocks/BlockVine.h | 5 ++++- src/Simulator/FireSimulator.cpp | 2 +- 11 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 4c6d5a938..057fa0304 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -46,7 +46,7 @@ public: * On all these functions, return true if you want to override default behavior and not call other plugins on that callback. * You can also return false, so default behavior is used. **/ - virtual bool OnBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) = 0; + virtual bool OnBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source) = 0; virtual bool OnBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) = 0; virtual bool OnChat (cPlayer * a_Player, AString & a_Message) = 0; virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index cefeb4996..4f0e13f12 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -195,14 +195,14 @@ void cPluginLua::Tick(float a_Dt) -bool cPluginLua::OnBlockSpread(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +bool cPluginLua::OnBlockSpread(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source) { cCSLock Lock(m_CriticalSection); bool res = false; cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_BLOCK_SPREAD]; for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) { - m_LuaState.Call((int)(**itr), a_World, a_BlockX, a_BlockY, a_BlockZ, cLuaState::Return, res); + m_LuaState.Call((int)(**itr), a_World, a_BlockX, a_BlockY, a_BlockZ, a_Source, cLuaState::Return, res); if (res) { return true; diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index 5c2c9e57f..f51056186 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -69,7 +69,7 @@ public: virtual void Tick(float a_Dt) override; - virtual bool OnBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual bool OnBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source) override; virtual bool OnBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) override; virtual bool OnChat (cPlayer * a_Player, AString & a_Message) override; virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 142b4b5ad..7d346c522 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -205,7 +205,7 @@ void cPluginManager::Tick(float a_Dt) -bool cPluginManager::CallHookBlockSpread(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +bool cPluginManager::CallHookBlockSpread(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source) { HookMap::iterator Plugins = m_Hooks.find(HOOK_BLOCK_SPREAD); if (Plugins == m_Hooks.end()) @@ -214,7 +214,7 @@ bool cPluginManager::CallHookBlockSpread(cWorld * a_World, int a_BlockX, int a_B } for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) { - if ((*itr)->OnBlockSpread(a_World, a_BlockX, a_BlockY, a_BlockZ)) + if ((*itr)->OnBlockSpread(a_World, a_BlockX, a_BlockY, a_BlockZ, a_Source)) { return true; } diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 18d34a50d..03f19e831 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -155,7 +155,7 @@ public: // tolua_export unsigned int GetNumPlugins() const; // tolua_export // Calls for individual hooks. Each returns false if the action is to continue or true if the plugin wants to abort - bool CallHookBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ); + bool CallHookBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source); bool CallHookBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups); bool CallHookChat (cPlayer * a_Player, AString & a_Message); bool CallHookChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ); diff --git a/src/BlockID.h b/src/BlockID.h index 8adefcfba..a1a445da4 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -866,6 +866,19 @@ enum eShrapnelLevel slAll } ; + + + + +enum eSpreadSource +{ + esFireSpread, + esGrassSpread, + esMushroomSpread, + esMycelSpread, + esVineSpread, +} ; + // tolua_end diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index 544424a04..6240e5e3f 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -79,7 +79,10 @@ public: Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta); if ((cBlockInfo::IsOneHitDig(AboveDest) || cBlockInfo::IsTransparent(AboveDest)) && !IsBlockWater(AboveDest)) { - Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0); + if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, BlockX * cChunkDef::Width, BlockY, BlockZ * cChunkDef::Width, esGrassSpread)) + { + Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0); + } } } // for i - repeat twice } diff --git a/src/Blocks/BlockMushroom.h b/src/Blocks/BlockMushroom.h index c30c1a401..135d418d7 100644 --- a/src/Blocks/BlockMushroom.h +++ b/src/Blocks/BlockMushroom.h @@ -17,6 +17,9 @@ public: } + // TODO: Add Mushroom Spread + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { // Reset meta to 0 diff --git a/src/Blocks/BlockMycelium.h b/src/Blocks/BlockMycelium.h index 7f897c72a..2a8ef5fca 100644 --- a/src/Blocks/BlockMycelium.h +++ b/src/Blocks/BlockMycelium.h @@ -16,6 +16,8 @@ public: { } + // TODO: Add Mycel Spread + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { a_Pickups.push_back(cItem(E_BLOCK_DIRT, 1, 0)); diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index 8041d9359..9d84b720e 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -175,7 +175,10 @@ public: a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY - 1, a_RelZ, Block); if (Block == E_BLOCK_AIR) { - a_Chunk.UnboundedRelSetBlock(a_RelX, a_RelY - 1, a_RelZ, E_BLOCK_VINES, a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); + if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, a_RelX * cChunkDef::Width, a_RelY - 1, a_RelZ * cChunkDef::Width, esVineSpread)) + { + a_Chunk.UnboundedRelSetBlock(a_RelX, a_RelY - 1, a_RelZ, E_BLOCK_VINES, a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); + } } } diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index 871a1ec5c..932ccf6bd 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -320,7 +320,7 @@ void cFireSimulator::TrySpreadFire(cChunk * a_Chunk, int a_RelX, int a_RelY, int int a_PosX = x + a_Chunk->GetPosX() * cChunkDef::Width; int a_PosZ = z + a_Chunk->GetPosZ() * cChunkDef::Width; - if (cRoot::Get()->GetPluginManager()->CallHookBlockSpread(&m_World, a_PosX, y, a_PosZ)) + if (cRoot::Get()->GetPluginManager()->CallHookBlockSpread(&m_World, a_PosX, y, a_PosZ, esFireSpread)) { return; } -- cgit v1.2.3 From 54d55b31ef9b17673212184ac523f6f2a964338d Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 16:12:16 +0100 Subject: Add documentation for new Block spread --- MCServer/Plugins/APIDump/APIDesc.lua | 9 ++++++ MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua | 40 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 74e7bf860..92b57865f 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1826,6 +1826,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); }, Constants = { + HOOK_BLOCK_SPREAD = { Notes = "Called when a block spreads based on world conditions" }, HOOK_BLOCK_TO_PICKUPS = { Notes = "Called when a block has been dug and is being converted to pickups. The server has provided the default pickups and the plugins may modify them." }, HOOK_CHAT = { Notes = "Called when a client sends a chat message that is not a command. The plugin may modify the chat message" }, HOOK_CHUNK_AVAILABLE = { Notes = "Called when a chunk is loaded or generated and becomes available in the {{cWorld|world}}." }, @@ -2767,6 +2768,14 @@ end data provided with the explosions, such as the exploding {{cCreeper|creeper}} entity or the {{Vector3i|coords}} of the exploding bed. ]], + }, + SpreadSource = + { + Include = "^es.*", + TextBefore = [[ + These constants are used to differentiate the various sources of spreads. They are used in + the {{OnBlockSpread|HOOK_BLOCK_SPREAD}} hook. + ]], } }, }, -- Globals diff --git a/MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua b/MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua new file mode 100644 index 000000000..1dde55f36 --- /dev/null +++ b/MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua @@ -0,0 +1,40 @@ +return +{ + HOOK_BLOCK_SPREAD = + { + CalledWhen = "Called when a block spreads based on world conditions", + DefaultFnName = "OnBlockSpread", -- also used as pagename + Desc = [[ + This hook is called when a block spreads.

    +

    + The explosion carries with it the type of its source - whether it's a creeper exploding, or TNT, + etc. It also carries the identification of the actual source. The exact type of the identification + depends on the source kind: + + + + + + + +
    SourceNotes
    esFireSpreadFire spreading
    esGrassSpreadGrass spreading
    esMushroomSpreadMushroom spreading
    esMycelSpreadMycel spreading
    esVineSpreadVine spreading

    + ]], + Params = + { + { Name = "World", Type = "{{cWorld}}", Notes = "The world in which the block resides" }, + { Name = "BlockX", Type = "number", Notes = "X-coord of the block" }, + { Name = "BlockY", Type = "number", Notes = "Y-coord of the block" }, + { Name = "BlockZ", Type = "number", Notes = "Z-coord of the block" }, + { Name = "Source", Type = "eSpreadSource", Notes = "Source of the spread. See the table above." }, + }, + Returns = [[ + If the function returns false or no value, the next plugin's callback is called, and finally + MCServer will process the spread. If the function + returns true, no other callback is called for this event and the spread will not occur. + ]], + }, -- HOOK_BLOCK_SPREAD +} + + + + -- cgit v1.2.3 From 09794e65bb8d752148250c40c710c08d0acf7ff8 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 16:15:22 +0100 Subject: Wrong if in BlockLeaves --- src/Blocks/BlockLeaves.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 954b993d6..a6d3373c1 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -87,7 +87,7 @@ public: return; } - if ((Meta & 0x8) == 0) + if ((Meta & 0x8) != 0) { // These leaves have been checked for decay lately and nothing around them changed return; -- cgit v1.2.3 From 9c461124866cd16d04206f49da6650a2219de50f Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 22:28:12 +0100 Subject: Change SpreadSource prefix to ss --- src/BlockID.h | 10 +++++----- src/Blocks/BlockDirt.h | 2 +- src/Blocks/BlockVine.h | 2 +- src/Simulator/FireSimulator.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index a1a445da4..2fec512e2 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -872,11 +872,11 @@ enum eShrapnelLevel enum eSpreadSource { - esFireSpread, - esGrassSpread, - esMushroomSpread, - esMycelSpread, - esVineSpread, + ssFireSpread, + ssGrassSpread, + ssMushroomSpread, + ssMycelSpread, + ssVineSpread, } ; // tolua_end diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index 6240e5e3f..a1ab74257 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -79,7 +79,7 @@ public: Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta); if ((cBlockInfo::IsOneHitDig(AboveDest) || cBlockInfo::IsTransparent(AboveDest)) && !IsBlockWater(AboveDest)) { - if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, BlockX * cChunkDef::Width, BlockY, BlockZ * cChunkDef::Width, esGrassSpread)) + if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, BlockX * cChunkDef::Width, BlockY, BlockZ * cChunkDef::Width, ssGrassSpread)) { Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0); } diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index 9d84b720e..d096c81a8 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -175,7 +175,7 @@ public: a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY - 1, a_RelZ, Block); if (Block == E_BLOCK_AIR) { - if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, a_RelX * cChunkDef::Width, a_RelY - 1, a_RelZ * cChunkDef::Width, esVineSpread)) + if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, a_RelX * cChunkDef::Width, a_RelY - 1, a_RelZ * cChunkDef::Width, ssVineSpread)) { a_Chunk.UnboundedRelSetBlock(a_RelX, a_RelY - 1, a_RelZ, E_BLOCK_VINES, a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); } diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index 932ccf6bd..e4d4a540d 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -320,7 +320,7 @@ void cFireSimulator::TrySpreadFire(cChunk * a_Chunk, int a_RelX, int a_RelY, int int a_PosX = x + a_Chunk->GetPosX() * cChunkDef::Width; int a_PosZ = z + a_Chunk->GetPosZ() * cChunkDef::Width; - if (cRoot::Get()->GetPluginManager()->CallHookBlockSpread(&m_World, a_PosX, y, a_PosZ, esFireSpread)) + if (cRoot::Get()->GetPluginManager()->CallHookBlockSpread(&m_World, a_PosX, y, a_PosZ, ssFireSpread)) { return; } -- cgit v1.2.3 From 9ac3e3405a92d458bf3d09d0ec0f60031d31823d Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 16 Mar 2014 22:28:53 +0100 Subject: Change SpreadSource documentation --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 92b57865f..f8ad74226 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2771,7 +2771,7 @@ end }, SpreadSource = { - Include = "^es.*", + Include = "^ss.*", TextBefore = [[ These constants are used to differentiate the various sources of spreads. They are used in the {{OnBlockSpread|HOOK_BLOCK_SPREAD}} hook. diff --git a/MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua b/MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua index 1dde55f36..a2f7d7ef9 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua @@ -12,11 +12,11 @@ return depends on the source kind: - - - - - + + + + +
    SourceNotes
    esFireSpreadFire spreading
    esGrassSpreadGrass spreading
    esMushroomSpreadMushroom spreading
    esMycelSpreadMycel spreading
    esVineSpreadVine spreading
    ssFireSpreadFire spreading
    ssGrassSpreadGrass spreading
    ssMushroomSpreadMushroom spreading
    ssMycelSpreadMycel spreading
    ssVineSpreadVine spreading

    ]], Params = -- cgit v1.2.3 From 327b70e769bd3bb826320027a1b7d56f6e386a6b Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 24 Mar 2014 20:01:57 +0100 Subject: Change documentation text --- MCServer/Plugins/APIDump/APIDesc.lua | 4 ++-- MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index f8ad74226..01f000182 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2773,8 +2773,8 @@ end { Include = "^ss.*", TextBefore = [[ - These constants are used to differentiate the various sources of spreads. They are used in - the {{OnBlockSpread|HOOK_BLOCK_SPREAD}} hook. + These constants are used to differentiate the various sources of spreads, such as grass growing. + They are used in the {{OnBlockSpread|HOOK_BLOCK_SPREAD}} hook. ]], } }, diff --git a/MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua b/MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua index a2f7d7ef9..ed0b5f46f 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua @@ -7,8 +7,8 @@ return Desc = [[ This hook is called when a block spreads.

    - The explosion carries with it the type of its source - whether it's a creeper exploding, or TNT, - etc. It also carries the identification of the actual source. The exact type of the identification + The spread carries with it the type of its source - whether it's a block spreads. + It also carries the identification of the actual source. The exact type of the identification depends on the source kind: -- cgit v1.2.3 From 8301f479bba4c12579d56c2274b85033a336057c Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 27 Mar 2014 23:21:04 +0100 Subject: Fix merge conflicts --- src/ChunkMap.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index da5dd90e4..e695f0ab2 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1384,13 +1384,6 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks) } break; } - case E_BLOCK_NEW_LEAVES: - { - if (itr->BlockType == E_BLOCK_NEW_LOG) - { - Chunk->SetBlock(itr->x, itr->y, itr->z, itr->BlockType, itr->BlockMeta); - } - } } } // for itr - a_Blocks[] } -- cgit v1.2.3 From 7cc44d4d8b6b6142ab45f955890a92e395604142 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 13:34:32 +0100 Subject: Debuggers: Deactivated the chunk generator callback. --- MCServer/Plugins/Debuggers/Debuggers.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index fe3efa306..2cb014875 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -27,11 +27,13 @@ function Initialize(Plugin) PM:AddHook(cPluginManager.HOOK_CHAT, OnChat); PM:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY, OnPlayerRightClickingEntity); PM:AddHook(cPluginManager.HOOK_WORLD_TICK, OnWorldTick); - PM:AddHook(cPluginManager.HOOK_CHUNK_GENERATED, OnChunkGenerated); PM:AddHook(cPluginManager.HOOK_PLUGINS_LOADED, OnPluginsLoaded); PM:AddHook(cPluginManager.HOOK_PLUGIN_MESSAGE, OnPluginMessage); PM:AddHook(cPluginManager.HOOK_PLAYER_JOINED, OnPlayerJoined) + -- _X: Disabled so that the normal operation doesn't interfere with anything + -- PM:AddHook(cPluginManager.HOOK_CHUNK_GENERATED, OnChunkGenerated); + PM:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "- Shows a list of all the loaded entities"); PM:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "- Kills all the loaded entities"); PM:BindCommand("/wool", "debuggers", HandleWoolCmd, "- Sets all your armor to blue wool"); -- cgit v1.2.3 From a2c4def518b0021a7575c9a9517f4f824369fe6d Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 28 Mar 2014 14:59:40 +0100 Subject: Add missing ChunkDesc import. --- src/Generating/Prefab.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index ec95c909b..c80de21b2 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -16,7 +16,7 @@ declared in this file as well; the Gallery server exports areas in this format. #include "PieceGenerator.h" #include "../BlockArea.h" - +#include "ChunkDesc.h" -- cgit v1.2.3 From 910e770a18520a96a5823b24b4b6a41068499414 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 16:36:33 +0100 Subject: Fixed Prefab's rotations. --- src/Generating/Prefab.cpp | 32 ++++++++++++++++++++++++++++---- src/Generating/Prefab.h | 14 +++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 145c875a1..1af1faec1 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -21,11 +21,33 @@ cPrefab::cPrefab(const cPrefab::sDef & a_Def) : m_AllowedRotations(a_Def.m_AllowedRotations), m_MergeStrategy(a_Def.m_MergeStrategy) { - m_BlockArea.Create(m_Size); + m_BlockArea[0].Create(m_Size); CharMap cm; ParseCharMap(cm, a_Def.m_CharMap); ParseBlockImage(cm, a_Def.m_Image); ParseConnectors(a_Def.m_Connectors); + + // 1 CCW rotation: + if ((m_AllowedRotations & 0x01) != 0) + { + m_BlockArea[1].CopyFrom(m_BlockArea[0]); + m_BlockArea[1].RotateCCW(); + } + + // 2 rotations are the same as mirroring twice; mirroring is faster because it has no reallocations + if ((m_AllowedRotations & 0x02) != 0) + { + m_BlockArea[2].CopyFrom(m_BlockArea[0]); + m_BlockArea[2].MirrorXY(); + m_BlockArea[2].MirrorYZ(); + } + + // 3 CCW rotations = 1 CW rotation: + if ((m_AllowedRotations & 0x04) != 0) + { + m_BlockArea[3].CopyFrom(m_BlockArea[0]); + m_BlockArea[3].RotateCW(); + } } @@ -38,7 +60,7 @@ void cPrefab::Draw(cChunkDesc & a_Dest, const cPlacedPiece * a_Placement) const int ChunkStartX = a_Dest.GetChunkX() * cChunkDef::Width; int ChunkStartZ = a_Dest.GetChunkZ() * cChunkDef::Width; Placement.Move(-ChunkStartX, 0, -ChunkStartZ); - a_Dest.WriteBlockArea(m_BlockArea, Placement.x, Placement.y, Placement.z, m_MergeStrategy); + a_Dest.WriteBlockArea(m_BlockArea[a_Placement->GetNumCCWRotations()], Placement.x, Placement.y, Placement.z, m_MergeStrategy); } @@ -112,7 +134,7 @@ void cPrefab::ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockIma ASSERT(MappedValue != -1); // Using a letter not defined in the CharMap? BLOCKTYPE BlockType = MappedValue >> 4; NIBBLETYPE BlockMeta = MappedValue & 0x0f; - m_BlockArea.SetRelBlockTypeMeta(x, y, z, BlockType, BlockMeta); + m_BlockArea[0].SetRelBlockTypeMeta(x, y, z, BlockType, BlockMeta); } } } @@ -195,7 +217,9 @@ cCuboid cPrefab::GetHitBox(void) const bool cPrefab::CanRotateCCW(int a_NumRotations) const { - return ((m_AllowedRotations & (1 << (a_NumRotations % 4))) != 0); + // Either zero rotations + // Or the proper bit in m_AllowedRotations is set + return (a_NumRotations == 0) || ((m_AllowedRotations & (1 << ((a_NumRotations + 3) % 4))) != 0); } diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index ec95c909b..d6ab5658f 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -22,6 +22,13 @@ declared in this file as well; the Gallery server exports areas in this format. +// fwd: +class cChunkDesc; + + + + + class cPrefab : public cPiece { @@ -51,8 +58,9 @@ protected: typedef int CharMap[256]; - /** The cBlockArea that contains the block definitions for the prefab */ - cBlockArea m_BlockArea; + /** The cBlockArea that contains the block definitions for the prefab. + The index identifies the number of CCW rotations applied (0 = no rotation, 1 = 1 CCW rotation, ...). */ + cBlockArea m_BlockArea[4]; /** The size of the prefab */ Vector3i m_Size; @@ -79,7 +87,7 @@ protected: /** Parses the CharMap in the definition into a CharMap binary data used for translating the definition into BlockArea. */ void ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef); - /** Parses the Image in the definition into m_BlockArea's block types and metas, using the specified CharMap. */ + /** Parses the Image in the definition into m_BlockArea[0]'s block types and metas, using the specified CharMap. */ void ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockImage); /** Parses the connectors definition text into m_Connectors member. */ -- cgit v1.2.3 From 5b7215ec24c2b835a0f1342cf1479f757084d1e2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 16:42:32 +0100 Subject: Initial NetherFortGen import. Simple fortresses of 2 different rooms will generate. --- src/CMakeLists.txt | 27 +-- src/Generating/ComposableGenerator.cpp | 17 +- src/Generating/MineShafts.cpp | 2 +- src/Generating/NetherFortGen.cpp | 265 +++++++++++++++++++++++ src/Generating/NetherFortGen.h | 86 ++++++++ src/Generating/Prefabs/CMakeLists.txt | 13 ++ src/Generating/Prefabs/NetherFortPrefabs.cpp | 303 +++++++++++++++++++++++++++ src/Generating/Prefabs/NetherFortPrefabs.h | 15 ++ 8 files changed, 713 insertions(+), 15 deletions(-) create mode 100644 src/Generating/NetherFortGen.cpp create mode 100644 src/Generating/NetherFortGen.h create mode 100644 src/Generating/Prefabs/CMakeLists.txt create mode 100644 src/Generating/Prefabs/NetherFortPrefabs.cpp create mode 100644 src/Generating/Prefabs/NetherFortPrefabs.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 448dc4b70..ca874517e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,14 +6,14 @@ include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/jsoncpp/include") include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/polarssl/include") set(FOLDERS OSSupport HTTPServer Items Blocks Protocol Generating) -set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities) +set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities Generating/Prefabs) if (NOT MSVC) - #Bindings needs to reference other folders so are done here + # Bindings need to reference other folders, so they are done here instead - #lib dependecies are not included + # lib dependencies are not included set(BINDING_DEPENDECIES tolua @@ -104,7 +104,6 @@ if (NOT MSVC) Bindings/PluginLua Bindings/PluginManager Bindings/WebPlugin - Bindings/WebPlugin ) target_link_libraries(Bindings lua sqlite tolualib) @@ -138,6 +137,7 @@ if (NOT MSVC) else () + # MSVC-specific handling: Put all files into one project, separate by the folders: # Generate the Bindings if they don't exist: if (NOT EXISTS "${PROJECT_SOURCE_DIR}/Bindings/Bindings.cpp") @@ -149,6 +149,14 @@ else () ) endif() + # Get all files in this folder: + file(GLOB_RECURSE SOURCE + "*.cpp" + "*.h" + "*.pkg" + ) + source_group("" FILES ${SOURCE}) + # Add all subfolders as solution-folders: list(APPEND FOLDERS "Resources") list(APPEND FOLDERS "Bindings") @@ -159,23 +167,16 @@ else () "${PATH}/*.rc" "${PATH}/*.pkg" ) - source_group("${PATH}" FILES ${FOLDER_FILES}) + string(REPLACE "/" "\\" PROJECT_PATH ${PATH}) + source_group("${PROJECT_PATH}" FILES ${FOLDER_FILES}) endfunction(includefolder) foreach(folder ${FOLDERS}) includefolder(${folder}) endforeach(folder) - file(GLOB_RECURSE SOURCE - "*.cpp" - "*.h" - "*.pkg" - ) - include_directories("${PROJECT_SOURCE_DIR}") - source_group("" FILES ${SOURCE}) - # Precompiled headers (1st part) SET_SOURCE_FILES_PROPERTIES( Globals.cpp PROPERTIES COMPILE_FLAGS "/Yc\"Globals.h\"" diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 6c00b5905..339f5709a 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -21,6 +21,7 @@ #include "DistortedHeightmap.h" #include "EndGen.h" #include "MineShafts.h" +#include "NetherFortGen.h" #include "Noise3DGenerator.h" #include "POCPieceGenerator.h" #include "Ravines.h" @@ -191,9 +192,11 @@ void cComposableGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a m_HeightGen->GenHeightMap(a_ChunkX, a_ChunkZ, a_ChunkDesc.GetHeightMap()); } + bool ShouldUpdateHeightmap = false; if (a_ChunkDesc.IsUsingDefaultComposition()) { m_CompositionGen->ComposeTerrain(a_ChunkDesc); + ShouldUpdateHeightmap = true; } if (a_ChunkDesc.IsUsingDefaultFinish()) @@ -202,6 +205,12 @@ void cComposableGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a { (*itr)->GenFinish(a_ChunkDesc); } // for itr - m_FinishGens[] + ShouldUpdateHeightmap = true; + } + + if (ShouldUpdateHeightmap) + { + a_ChunkDesc.UpdateHeightmap(); } } @@ -349,7 +358,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) int ChanceCrossing = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCrossing", 200); int ChanceStaircase = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceStaircase", 200); m_FinishGens.push_back(new cStructGenMineShafts( - Seed, GridSize, MaxSystemSize, + Seed, GridSize, MaxSystemSize, ChanceCorridor, ChanceCrossing, ChanceStaircase )); } @@ -361,6 +370,12 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) { m_FinishGens.push_back(new cFinishGenNetherClumpFoliage(Seed)); } + else if (NoCaseCompare(*itr, "NetherForts") == 0) + { + int GridSize = a_IniFile.GetValueSetI("Generator", "NetherFortsGridSize", 512); + int MaxDepth = a_IniFile.GetValueSetI("Generator", "NetherFortsMaxDepth", 6); + m_FinishGens.push_back(new cNetherFortGen(Seed, GridSize, MaxDepth)); + } else if (NoCaseCompare(*itr, "OreNests") == 0) { m_FinishGens.push_back(new cStructGenOreNests(Seed)); diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp index 28dc37567..231295c3f 100644 --- a/src/Generating/MineShafts.cpp +++ b/src/Generating/MineShafts.cpp @@ -1340,7 +1340,7 @@ void cStructGenMineShafts::GetMineShaftSystemsForChunk( BaseX -= NEIGHBORHOOD_SIZE / 2; BaseZ -= NEIGHBORHOOD_SIZE / 2; - // Walk the cache, move each cave system that we want into a_Caves: + // Walk the cache, move each cave system that we want into a_Mineshafts: int StartX = BaseX * m_GridSize; int EndX = (BaseX + NEIGHBORHOOD_SIZE + 1) * m_GridSize; int StartZ = BaseZ * m_GridSize; diff --git a/src/Generating/NetherFortGen.cpp b/src/Generating/NetherFortGen.cpp new file mode 100644 index 000000000..25658da46 --- /dev/null +++ b/src/Generating/NetherFortGen.cpp @@ -0,0 +1,265 @@ + +// NetherFortGen.cpp + +// Implements the cNetherFortGen class representing the nether fortress generator + +#include "Globals.h" +#include "NetherFortGen.h" +#include "Prefabs/NetherFortPrefabs.h" + + + + + +static const int NEIGHBORHOOD_SIZE = 3; + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cNetherFortGen::cNetherFort: + +class cNetherFortGen::cNetherFort +{ +public: + cNetherFortGen & m_ParentGen; + int m_BlockX, m_BlockZ; + int m_GridSize; + int m_Seed; + cPlacedPieces m_Pieces; + + cNetherFort(cNetherFortGen & a_ParentGen, int a_BlockX, int a_BlockZ, int a_GridSize, int a_MaxDepth, int a_Seed) : + m_ParentGen(a_ParentGen), + m_BlockX(a_BlockX), + m_BlockZ(a_BlockZ), + m_GridSize(a_GridSize), + m_Seed(a_Seed) + { + // TODO: Proper Y-coord placement + int BlockY = 64; + + // Generate pieces: + cBFSPieceGenerator pg(m_ParentGen, a_Seed); + pg.PlacePieces(a_BlockX, BlockY, a_BlockZ, a_MaxDepth, m_Pieces); + } + + + /** Carves the system into the chunk data */ + void ProcessChunk(cChunkDesc & a_Chunk) + { + for (cPlacedPieces::const_iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) + { + const cPrefab & Prefab = (const cPrefab &)((*itr)->GetPiece()); + Prefab.Draw(a_Chunk, *itr); + } // for itr - m_PlacedPieces[] + } +}; + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cNetherFortGen: + +cNetherFortGen::cNetherFortGen(int a_Seed, int a_GridSize, int a_MaxDepth) : + m_Seed(a_Seed), + m_Noise(a_Seed), + m_GridSize(a_GridSize), + m_MaxDepth(a_MaxDepth) +{ + // Initialize the prefabs: + for (size_t i = 0; i < g_NetherFortPrefabs1Count; i++) + { + cPrefab * Prefab = new cPrefab(g_NetherFortPrefabs1[i]); + m_AllPieces.push_back(Prefab); + if (Prefab->HasConnectorType(0)) + { + m_OuterPieces.push_back(Prefab); + } + if (Prefab->HasConnectorType(1)) + { + m_InnerPieces.push_back(Prefab); + } + } + + // Initialize the starting piece prefabs: + for (size_t i = 0; i < g_NetherFortStartingPrefabs1Count; i++) + { + m_StartingPieces.push_back(new cPrefab(g_NetherFortStartingPrefabs1[i])); + } + + // DEBUG: Try one round of placement: + cPlacedPieces Pieces; + cBFSPieceGenerator pg(*this, a_Seed); + pg.PlacePieces(0, 64, 0, a_MaxDepth, Pieces); +} + + + + + +cNetherFortGen::~cNetherFortGen() +{ + ClearCache(); + for (cPieces::iterator itr = m_AllPieces.begin(), end = m_AllPieces.end(); itr != end; ++itr) + { + delete *itr; + } // for itr - m_AllPieces[] + m_AllPieces.clear(); +} + + + + + +void cNetherFortGen::ClearCache(void) +{ + // TODO +} + + + + + +void cNetherFortGen::GetFortsForChunk(int a_ChunkX, int a_ChunkZ, cNetherForts & a_Forts) +{ + int BaseX = a_ChunkX * cChunkDef::Width / m_GridSize; + int BaseZ = a_ChunkZ * cChunkDef::Width / m_GridSize; + if (BaseX < 0) + { + --BaseX; + } + if (BaseZ < 0) + { + --BaseZ; + } + BaseX -= NEIGHBORHOOD_SIZE / 2; + BaseZ -= NEIGHBORHOOD_SIZE / 2; + + // Walk the cache, move each cave system that we want into a_Forts: + int StartX = BaseX * m_GridSize; + int EndX = (BaseX + NEIGHBORHOOD_SIZE + 1) * m_GridSize; + int StartZ = BaseZ * m_GridSize; + int EndZ = (BaseZ + NEIGHBORHOOD_SIZE + 1) * m_GridSize; + for (cNetherForts::iterator itr = m_Cache.begin(), end = m_Cache.end(); itr != end;) + { + if ( + ((*itr)->m_BlockX >= StartX) && ((*itr)->m_BlockX < EndX) && + ((*itr)->m_BlockZ >= StartZ) && ((*itr)->m_BlockZ < EndZ) + ) + { + // want + a_Forts.push_back(*itr); + itr = m_Cache.erase(itr); + } + else + { + // don't want + ++itr; + } + } // for itr - m_Cache[] + + // Create those forts that haven't been in the cache: + for (int x = 0; x < NEIGHBORHOOD_SIZE; x++) + { + int RealX = (BaseX + x) * m_GridSize; + for (int z = 0; z < NEIGHBORHOOD_SIZE; z++) + { + int RealZ = (BaseZ + z) * m_GridSize; + bool Found = false; + for (cNetherForts::const_iterator itr = a_Forts.begin(), end = a_Forts.end(); itr != end; ++itr) + { + if (((*itr)->m_BlockX == RealX) && ((*itr)->m_BlockZ == RealZ)) + { + Found = true; + break; + } + } // for itr - a_Mineshafts + if (!Found) + { + a_Forts.push_back(new cNetherFort(*this, RealX, RealZ, m_GridSize, m_MaxDepth, m_Seed)); + } + } // for z + } // for x + + // Copy a_Forts into m_Cache to the beginning: + cNetherForts FortsCopy (a_Forts); + m_Cache.splice(m_Cache.begin(), FortsCopy, FortsCopy.begin(), FortsCopy.end()); + + // Trim the cache if it's too long: + if (m_Cache.size() > 100) + { + cNetherForts::iterator itr = m_Cache.begin(); + std::advance(itr, 100); + for (cNetherForts::iterator end = m_Cache.end(); itr != end; ++itr) + { + delete *itr; + } + itr = m_Cache.begin(); + std::advance(itr, 100); + m_Cache.erase(itr, m_Cache.end()); + } +} + + + + + +void cNetherFortGen::GenFinish(cChunkDesc & a_ChunkDesc) +{ + int ChunkX = a_ChunkDesc.GetChunkX(); + int ChunkZ = a_ChunkDesc.GetChunkZ(); + cNetherForts Forts; + GetFortsForChunk(ChunkX, ChunkZ, Forts); + for (cNetherForts::const_iterator itr = Forts.begin(); itr != Forts.end(); ++itr) + { + (*itr)->ProcessChunk(a_ChunkDesc); + } // for itr - Forts[] +} + + + + + +cPieces cNetherFortGen::GetPiecesWithConnector(int a_ConnectorType) +{ + switch (a_ConnectorType) + { + case 0: return m_OuterPieces; + case 1: return m_InnerPieces; + default: return cPieces(); + } +} + + + + + +cPieces cNetherFortGen::GetStartingPieces(void) +{ + return m_StartingPieces; +} + + + + + +void cNetherFortGen::PiecePlaced(const cPiece & a_Piece) +{ + UNUSED(a_Piece); +} + + + + + +void cNetherFortGen::Reset(void) +{ + // Nothing needed +} + + + + diff --git a/src/Generating/NetherFortGen.h b/src/Generating/NetherFortGen.h new file mode 100644 index 000000000..10ba01396 --- /dev/null +++ b/src/Generating/NetherFortGen.h @@ -0,0 +1,86 @@ + +// NetherFortGen.h + +// Declares the cNetherFortGen class representing the nether fortress generator + + + + + +#pragma once + +#include "ComposableGenerator.h" +#include "PieceGenerator.h" + + + + + +class cNetherFortGen : + public cFinishGen, + public cPiecePool +{ +public: + cNetherFortGen(int a_Seed, int a_GridSize, int a_MaxDepth); + + virtual ~cNetherFortGen(); + +protected: + class cNetherFort; // fwd: NetherFortGen.cpp + typedef std::list cNetherForts; + + + /** The seed used for generating*/ + int m_Seed; + + /** The noise used for generating */ + cNoise m_Noise; + + /** Average spacing between the fortresses*/ + int m_GridSize; + + /** Maximum depth of the piece-generator tree */ + int m_MaxDepth; + + /** Cache of the most recently used systems. MoveToFront used. */ + cNetherForts m_Cache; + + /** All the pieces that are allowed for building. + This is the list that's used for memory allocation and deallocation for the pieces. */ + cPieces m_AllPieces; + + /** The pieces that are used as starting pieces. + This list is not shared and the pieces need deallocation. */ + cPieces m_StartingPieces; + + /** The pieces that have an "outer" connector. + The pieces are copies out of m_AllPieces and shouldn't be ever delete-d. */ + cPieces m_OuterPieces; + + /** The pieces that have an "inner" connector. + The pieces are copies out of m_AllPieces and shouldn't be ever delete-d. */ + cPieces m_InnerPieces; + + + /** Clears everything from the cache. + Also invalidates the forst returned by GetFortsForChunk(). */ + void ClearCache(void); + + /** Returns all forts that *may* intersect the given chunk. + The returned forts live within m_Cache.They are valid until the next call + to this function (which may delete some of the pointers). */ + void GetFortsForChunk(int a_ChunkX, int a_ChunkZ, cNetherForts & a_Forts); + + // cFinishGen overrides: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; + + // cPiecePool overrides: + virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override; + virtual cPieces GetStartingPieces(void) override; + virtual void PiecePlaced(const cPiece & a_Piece) override; + virtual void Reset(void) override; +} ; + + + + diff --git a/src/Generating/Prefabs/CMakeLists.txt b/src/Generating/Prefabs/CMakeLists.txt new file mode 100644 index 000000000..1e60447e7 --- /dev/null +++ b/src/Generating/Prefabs/CMakeLists.txt @@ -0,0 +1,13 @@ + +cmake_minimum_required (VERSION 2.6) +project (MCServer) + +include_directories ("${PROJECT_SOURCE_DIR}/../../") + +file(GLOB SOURCE + "*.cpp" +) + +add_library(Generating_Prefabs ${SOURCE}) + +target_link_libraries(Generating_Prefabs OSSupport iniFile Blocks) diff --git a/src/Generating/Prefabs/NetherFortPrefabs.cpp b/src/Generating/Prefabs/NetherFortPrefabs.cpp new file mode 100644 index 000000000..ea3a298c0 --- /dev/null +++ b/src/Generating/Prefabs/NetherFortPrefabs.cpp @@ -0,0 +1,303 @@ + +// NetherFortPrefabs.cpp + +// Defines all the prefabs for nether forts + +#include "Globals.h" +#include "NetherFortPrefabs.h" + + + + + +/* +The nether fortress has two types of connectors, Outer and Inner. Outer is Type 0, Inner is Type 1. +*/ + + + + + +const cPrefab::sDef g_NetherFortPrefabs1[] = +{ + // BalconyCorridor: + // The data has been exported from gallery Nether, area index 37, ID 288 + { + // Size: + 13, 7, 9, // SizeX = 13, SizeY = 7, SizeZ = 9 + + // Block definitions: + "a:112: 0\n" /* netherbrick */ + "b: 0: 0\n" /* air */ + "c:114: 4\n" /* netherbrickstairs */ + "d:114: 7\n" /* netherbrickstairs */ + "e:114: 5\n" /* netherbrickstairs */ + "f: 44: 6\n" /* step */ + "g:113: 0\n" /* netherbrickfence */ + "h:114: 2\n" /* netherbrickstairs */ + "i:114: 3\n" /* netherbrickstairs */ + "j:114: 0\n" /* netherbrickstairs */ + "k:114: 1\n" /* netherbrickstairs */, + + // Block data: + // Level 1 + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "bbbbaaaaabbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + + // Level 2 + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaabaaabaaaa" + "bbcdaaaaadebb" + "bbbcdddddebbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + + // Level 3 + "aaaaaaaaaaaaa" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "aaaabfffbaaaa" + "bbaaaaaaaaabb" + "bbaaaaaaaaabb" + "bbaaaaaaaaabb" + "bbaaaaaaaaabb" + + // Level 4 + "agagagagagaga" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "agaabbbbbaaga" + "bbaaabbbaaabb" + "bbgbbbbbbbgbb" + "bbgbbbbbbbgbb" + "bbgggggggggbb" + + // Level 5 + "agagagagagaga" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "agaabbbbbaaga" + "bbaaabbbaaabb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + + // Level 6 + "agagagagagaga" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "agaabbbbbaaga" + "bbaaabbbaaabb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + + // Level 7 + "hhhhhhhhhhhhh" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "iijaaaaaaaiii" + "bbjiiiiiiikbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb", + + // Connections: + "1: 0, 2, 2: 4\n" /* Type 1, BLOCK_FACE_XM */ + "1: 12, 2, 2: 5\n" /* Type 1, BLOCK_FACE_XP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msImprint, + }, +} ; // g_NetherFortPrefabs1 + + + + + +const cPrefab::sDef g_NetherFortStartingPrefabs1[] = +{ + // CentralRoom: + // The data has been exported from gallery Nether, area index 22, ID 164 + { + // Size: + 13, 9, 13, // SizeX = 13, SizeY = 9, SizeZ = 13 + + // Block definitions: + "a:112: 0\n" /* netherbrick */ + "b: 0: 0\n" /* air */ + "c: 10: 0\n" /* lava */ + "d:113: 0\n" /* netherbrickfence */, + + // Block data: + // Level 1 + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 2 + "aaaaabbbaaaaa" + "aaaaabbbaaaaa" + "aabbbbbbbbbaa" + "aabbbbbbbbbaa" + "aabbbbbbbbbaa" + "aabbbaaabbbaa" + "aabbbacabbbaa" + "aabbbaaabbbaa" + "aabbbbbbbbbaa" + "aabbbbbbbbbaa" + "aabbbbbbbbbaa" + "aaaaabbbaaaaa" + "aaaaabbbaaaaa" + + // Level 3 + "aaaaabbbaaaaa" + "aaadabbbadaaa" + "aabbbbbbbbbaa" + "adbbbbbbbbbda" + "aabbbbbbbbbaa" + "adbbbbbbbbbda" + "aabbbbbbbbbaa" + "adbbbbbbbbbda" + "aabbbbbbbbbaa" + "adbbbbbbbbbda" + "aabbbbbbbbbaa" + "aaadabbbadaaa" + "aaaaabbbaaaaa" + + // Level 4 + "aaaaabbbaaaaa" + "aaadabbbadaaa" + "aabbbbbbbbbaa" + "adbbbbbbbbbda" + "aabbbbbbbbbaa" + "adbbbbbbbbbda" + "aabbbbbbbbbaa" + "adbbbbbbbbbda" + "aabbbbbbbbbaa" + "adbbbbbbbbbda" + "aabbbbbbbbbaa" + "aaadabbbadaaa" + "aaaaabbbaaaaa" + + // Level 5 + "adadabbbadada" + "daaaabbbaaaad" + "aabbbbbbbbbaa" + "dabbbbbbbbbad" + "aabbbbbbbbbaa" + "dabbbbbbbbbad" + "aabbbbbbbbbaa" + "dabbbbbbbbbad" + "aabbbbbbbbbaa" + "dabbbbbbbbbad" + "aabbbbbbbbbaa" + "daaaabbbaaaad" + "adadabbbadada" + + // Level 6 + "adadaaaaadada" + "daaaaaaaaaaad" + "aabbbbbbbbbaa" + "dabbbbbbbbbad" + "aabbbbbbbbbaa" + "dabbbbbbbbbad" + "aabbbbbbbbbaa" + "dabbbbbbbbbad" + "aabbbbbbbbbaa" + "dabbbbbbbbbad" + "aabbbbbbbbbaa" + "daaaaaaaaaaad" + "adadaaaaadada" + + // Level 7 + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 8 + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 9 + "dadadadadadad" + "abbbbbbbbbbba" + "dbbbbbbbbbbbd" + "abbbbbbbbbbba" + "dbbbbbbbbbbbd" + "abbbbbbbbbbba" + "dbbbbbbbbbbbd" + "abbbbbbbbbbba" + "dbbbbbbbbbbbd" + "abbbbbbbbbbba" + "dbbbbbbbbbbbd" + "abbbbbbbbbbba" + "dadadadadadad", + + // Connections: + "0: 6, 1, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ + "1: 6, 1, 12: 3\n" /* Type 1, BLOCK_FACE_ZP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msImprint, + }, +} ; // g_NetherFortStartingPrefabs1 + +const size_t g_NetherFortPrefabs1Count = ARRAYCOUNT(g_NetherFortPrefabs1); +const size_t g_NetherFortStartingPrefabs1Count = ARRAYCOUNT(g_NetherFortStartingPrefabs1); + + + + diff --git a/src/Generating/Prefabs/NetherFortPrefabs.h b/src/Generating/Prefabs/NetherFortPrefabs.h new file mode 100644 index 000000000..37a91689d --- /dev/null +++ b/src/Generating/Prefabs/NetherFortPrefabs.h @@ -0,0 +1,15 @@ + +// NetherFortPrefabs.h + +// Declares the data used for nether fortress prefabs + +#include "../Prefab.h" + + + + + +extern const cPrefab::sDef g_NetherFortPrefabs1[]; +extern const cPrefab::sDef g_NetherFortStartingPrefabs1[]; +extern const size_t g_NetherFortPrefabs1Count; +extern const size_t g_NetherFortStartingPrefabs1Count; -- cgit v1.2.3 From 1802234b4ab58d1afc258a40341e54484c045899 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 16:44:12 +0100 Subject: Fixed compilation after last PR merge. --- src/Simulator/FireSimulator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index e4d4a540d..470dfc791 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -7,7 +7,7 @@ #include "../Defines.h" #include "../Chunk.h" #include "Root.h" -#include "PluginManager.h" +#include "../Bindings/PluginManager.h" -- cgit v1.2.3 From ae0954f1d443822f7f6693f0dd42d5601a50f835 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 17:05:43 +0100 Subject: Sponged the netherfort balcony prefab. This is a preparation for the msSpongePrint merge strategy, used for imprinting most prefabs. It will carve out even air, but will ignore sponge blocks. --- src/Generating/Prefabs/NetherFortPrefabs.cpp | 61 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/src/Generating/Prefabs/NetherFortPrefabs.cpp b/src/Generating/Prefabs/NetherFortPrefabs.cpp index ea3a298c0..29df15c1f 100644 --- a/src/Generating/Prefabs/NetherFortPrefabs.cpp +++ b/src/Generating/Prefabs/NetherFortPrefabs.cpp @@ -28,7 +28,7 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = // Block definitions: "a:112: 0\n" /* netherbrick */ - "b: 0: 0\n" /* air */ + "b: 19: 0\n" /* sponge */ "c:114: 4\n" /* netherbrickstairs */ "d:114: 7\n" /* netherbrickstairs */ "e:114: 5\n" /* netherbrickstairs */ @@ -37,7 +37,8 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "h:114: 2\n" /* netherbrickstairs */ "i:114: 3\n" /* netherbrickstairs */ "j:114: 0\n" /* netherbrickstairs */ - "k:114: 1\n" /* netherbrickstairs */, + "k:114: 1\n" /* netherbrickstairs */ + "l: 0: 0\n" /* air */, // Block data: // Level 1 @@ -56,7 +57,7 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "aaaaaaaaaaaaa" "aaaaaaaaaaaaa" "aaaaaaaaaaaaa" - "aaaabaaabaaaa" + "aaaalaaalaaaa" "bbcdaaaaadebb" "bbbcdddddebbb" "bbbbbbbbbbbbb" @@ -64,10 +65,10 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = // Level 3 "aaaaaaaaaaaaa" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "aaaabfffbaaaa" + "lllllllllllll" + "lllllllllllll" + "lllllllllllll" + "aaaalffflaaaa" "bbaaaaaaaaabb" "bbaaaaaaaaabb" "bbaaaaaaaaabb" @@ -75,36 +76,36 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = // Level 4 "agagagagagaga" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "agaabbbbbaaga" - "bbaaabbbaaabb" - "bbgbbbbbbbgbb" - "bbgbbbbbbbgbb" + "lllllllllllll" + "lllllllllllll" + "lllllllllllll" + "agaalllllaaga" + "bbaaalllaaabb" + "bbglllllllgbb" + "bbglllllllgbb" "bbgggggggggbb" // Level 5 "agagagagagaga" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "agaabbbbbaaga" - "bbaaabbbaaabb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" + "lllllllllllll" + "lllllllllllll" + "lllllllllllll" + "agaalllllaaga" + "bbaaalllaaabb" + "bblllllllllbb" + "bblllllllllbb" + "bblllllllllbb" // Level 6 "agagagagagaga" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "agaabbbbbaaga" - "bbaaabbbaaabb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" + "lllllllllllll" + "lllllllllllll" + "lllllllllllll" + "agaalllllaaga" + "bbaaalllaaabb" + "bblllllllllbb" + "bblllllllllbb" + "bblllllllllbb" // Level 7 "hhhhhhhhhhhhh" -- cgit v1.2.3 From 3c84a995a90122279cdb2f8cd60491e4d33c297f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 17:09:47 +0100 Subject: Fixed a memory leak in NetherFortGen. --- src/Generating/NetherFortGen.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Generating/NetherFortGen.cpp b/src/Generating/NetherFortGen.cpp index 25658da46..d111c7cee 100644 --- a/src/Generating/NetherFortGen.cpp +++ b/src/Generating/NetherFortGen.cpp @@ -29,6 +29,7 @@ public: int m_Seed; cPlacedPieces m_Pieces; + cNetherFort(cNetherFortGen & a_ParentGen, int a_BlockX, int a_BlockZ, int a_GridSize, int a_MaxDepth, int a_Seed) : m_ParentGen(a_ParentGen), m_BlockX(a_BlockX), @@ -43,6 +44,12 @@ public: cBFSPieceGenerator pg(m_ParentGen, a_Seed); pg.PlacePieces(a_BlockX, BlockY, a_BlockZ, a_MaxDepth, m_Pieces); } + + + ~cNetherFort() + { + cPieceGenerator::FreePieces(m_Pieces); + } /** Carves the system into the chunk data */ -- cgit v1.2.3 From 113343d336e28613f344aa43cf654baa177463f6 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 17:35:05 +0100 Subject: NetherFort: Added BalconyTee2 prefab. --- src/Generating/Prefabs/NetherFortPrefabs.cpp | 187 ++++++++++++++++++++++----- 1 file changed, 158 insertions(+), 29 deletions(-) diff --git a/src/Generating/Prefabs/NetherFortPrefabs.cpp b/src/Generating/Prefabs/NetherFortPrefabs.cpp index 29df15c1f..6d6b11cdd 100644 --- a/src/Generating/Prefabs/NetherFortPrefabs.cpp +++ b/src/Generating/Prefabs/NetherFortPrefabs.cpp @@ -20,6 +20,7 @@ The nether fortress has two types of connectors, Outer and Inner. Outer is Type const cPrefab::sDef g_NetherFortPrefabs1[] = { + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // BalconyCorridor: // The data has been exported from gallery Nether, area index 37, ID 288 { @@ -38,7 +39,7 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "i:114: 3\n" /* netherbrickstairs */ "j:114: 0\n" /* netherbrickstairs */ "k:114: 1\n" /* netherbrickstairs */ - "l: 0: 0\n" /* air */, + ".: 0: 0\n" /* air */, // Block data: // Level 1 @@ -57,7 +58,7 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "aaaaaaaaaaaaa" "aaaaaaaaaaaaa" "aaaaaaaaaaaaa" - "aaaalaaalaaaa" + "aaaa.aaa.aaaa" "bbcdaaaaadebb" "bbbcdddddebbb" "bbbbbbbbbbbbb" @@ -65,10 +66,10 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = // Level 3 "aaaaaaaaaaaaa" - "lllllllllllll" - "lllllllllllll" - "lllllllllllll" - "aaaalffflaaaa" + "............." + "............." + "............." + "aaaa.fff.aaaa" "bbaaaaaaaaabb" "bbaaaaaaaaabb" "bbaaaaaaaaabb" @@ -76,36 +77,36 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = // Level 4 "agagagagagaga" - "lllllllllllll" - "lllllllllllll" - "lllllllllllll" - "agaalllllaaga" - "bbaaalllaaabb" - "bbglllllllgbb" - "bbglllllllgbb" + "............." + "............." + "............." + "agaa.....aaga" + "bbaaa...aaabb" + "bbg.......gbb" + "bbg.......gbb" "bbgggggggggbb" // Level 5 "agagagagagaga" - "lllllllllllll" - "lllllllllllll" - "lllllllllllll" - "agaalllllaaga" - "bbaaalllaaabb" - "bblllllllllbb" - "bblllllllllbb" - "bblllllllllbb" + "............." + "............." + "............." + "agaa.....aaga" + "bbaaa...aaabb" + "bb.........bb" + "bb.........bb" + "bb.........bb" // Level 6 "agagagagagaga" - "lllllllllllll" - "lllllllllllll" - "lllllllllllll" - "agaalllllaaga" - "bbaaalllaaabb" - "bblllllllllbb" - "bblllllllllbb" - "bblllllllllbb" + "............." + "............." + "............." + "agaa.....aaga" + "bbaaa...aaabb" + "bb.........bb" + "bb.........bb" + "bb.........bb" // Level 7 "hhhhhhhhhhhhh" @@ -125,9 +126,136 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = // AllowedRotations: 7, /* 1, 2, 3 CCW rotations */ + // Merge strategy: + cBlockArea::msImprint, + }, // BalconyCorridor + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // BalconyTee2: + // The data has been exported from gallery Nether, area index 38, ID 289 + { + // Size: + 13, 7, 11, // SizeX = 13, SizeY = 7, SizeZ = 11 + + // Block definitions: + "a: 19: 0\n" /* sponge */ + "b:112: 0\n" /* netherbrick */ + "c:114: 4\n" /* netherbrickstairs */ + "d:114: 7\n" /* netherbrickstairs */ + "e:114: 5\n" /* netherbrickstairs */ + "f: 44: 6\n" /* step */ + "g:113: 0\n" /* netherbrickfence */ + "h:114: 0\n" /* netherbrickstairs */ + "i:114: 1\n" /* netherbrickstairs */ + "j:114: 2\n" /* netherbrickstairs */ + "k:114: 3\n" /* netherbrickstairs */ + ".: 0: 0\n" /* air */, + + // Block data: + // Level 1 + "aaaabbbbbaaaa" + "aaaabbbbbaaaa" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "aaaabbbbbaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 2 + "aaaabbbbbaaaa" + "aaaabbbbbaaaa" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbb.bbb.bbbb" + "aacdbbbbbdeaa" + "aaacdddddeaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 3 + "aaaab...baaaa" + "aaaab...baaaa" + "bbbbb...bbbbb" + "............." + "............." + "............." + "bbbb.fff.bbbb" + "aabbbbbbbbbaa" + "aabbbbbbbbbaa" + "aabbbbbbbbbaa" + "aabbbbbbbbbaa" + + // Level 4 + "aaaab...baaaa" + "aaaag...gaaaa" + "bgbgb...bgbgb" + "............." + "............." + "............." + "bgbb.....bbgb" + "aabbb...bbbaa" + "aag.......gaa" + "aag.......gaa" + "aagggggggggaa" + + // Level 5 + "aaaab...baaaa" + "aaaag...gaaaa" + "bgbgb...bgbgb" + "............." + "............." + "............." + "bgbb.....bbgb" + "aabbb...bbbaa" + "aa.........aa" + "aa.........aa" + "aa.........aa" + + // Level 6 + "aaaab...baaaa" + "aaaag...gaaaa" + "bgbgb...bgbgb" + "............." + "............." + "............." + "bgbb.....bbgb" + "aabbb...bbbaa" + "aa.........aa" + "aa.........aa" + "aa.........aa" + + // Level 7 + "aaaahbbbiaaaa" + "aaaahbbbiaaaa" + "jjjjjbbbjjjjj" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "bbbbbbbbbbbbb" + "kkhbbbbbbbkkk" + "aahkkkkkkkiaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa", + + // Connections: + "1: 0, 2, 4: 4\n" /* Type 1, BLOCK_FACE_XM */ + "1: 12, 2, 4: 5\n" /* Type 1, BLOCK_FACE_XP */ + "1: 6, 2, 0: 2\n" /* Type 1, BLOCK_FACE_ZM */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + // Merge strategy: cBlockArea::msImprint, }, + } ; // g_NetherFortPrefabs1 @@ -136,6 +264,7 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = const cPrefab::sDef g_NetherFortStartingPrefabs1[] = { + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // CentralRoom: // The data has been exported from gallery Nether, area index 22, ID 164 { -- cgit v1.2.3 From 8557549cfac260867112be96e24b2c0e059db47e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 18:03:37 +0100 Subject: Implemented the msSpongePrint merge strategy. Similar to msImprint, but allows prefabs to carve out air pockets, too. The sponge block is used as the NOP block. --- MCServer/Plugins/APIDump/APIDesc.lua | 24 +++++++++++++++--- src/BlockArea.cpp | 38 +++++++++++++++++++++++++--- src/BlockArea.h | 13 ++++++++-- src/Generating/Prefabs/NetherFortPrefabs.cpp | 6 ++--- 4 files changed, 68 insertions(+), 13 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 01f000182..6f8a14421 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -258,12 +258,11 @@ g_APIDesc =

    -

    - Special strategies: -

    +

    Special strategies

    +

    For each strategy, evaluate the table rows from top downwards, the first match wins.

    - msLake (evaluate top-down, first match wins): + msLake - used for merging areas with lava and water lakes, in the appropriate generator.

    SourceNotes
    @@ -293,6 +292,23 @@ g_APIDesc =
    area block Notes A * A Everything else is left as it is
    + + +

    + msSpongePrint - used for most prefab-generators to merge the prefabs. Similar to + msImprint, but uses the sponge block as the NOP block instead, so that the prefabs may carve out air + pockets, too. +

    + + + + + + + + + +
    area block Notes
    this Src result
    A sponge A Sponge is the NOP block
    * B B Everything else overwrites anything
    ]], }, -- Merge strategies }, -- AdditionalInfo diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index f6d54e41c..2b950378a 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -54,7 +54,7 @@ template void InternalMergeBlocks( /// Combinator used for cBlockArea::msOverwrite merging -static void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static inline void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { a_DstType = a_SrcType; a_DstMeta = a_SrcMeta; @@ -65,7 +65,7 @@ static void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, /// Combinator used for cBlockArea::msFillAir merging -static void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static inline void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if (a_DstType == E_BLOCK_AIR) { @@ -80,7 +80,7 @@ static void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, N /// Combinator used for cBlockArea::msImprint merging -static void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static inline void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if (a_SrcType != E_BLOCK_AIR) { @@ -95,7 +95,7 @@ static void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, N /// Combinator used for cBlockArea::msLake merging -static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static inline void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { // Sponge is the NOP block if (a_SrcType == E_BLOCK_SPONGE) @@ -158,6 +158,21 @@ static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBB +/** Combinator used for cBlockArea::msSpongePrint merging */ +static inline void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +{ + // Sponge overwrites nothing, everything else overwrites anything + if (a_SrcType != E_BLOCK_SPONGE) + { + a_DstType = a_SrcType; + a_DstMeta = a_SrcMeta; + } +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cBlockArea: @@ -680,6 +695,21 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R break; } // case msLake + case msSpongePrint: + { + InternalMergeBlocks( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z, + MergeCombinatorSpongePrint + ); + break; + } // case msSpongePrint + default: { LOGWARNING("Unknown block area merge strategy: %d", a_Strategy); diff --git a/src/BlockArea.h b/src/BlockArea.h index d28325d7d..d37f0d182 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -51,6 +51,7 @@ public: msFillAir, msImprint, msLake, + msSpongePrint, } ; cBlockArea(void); @@ -127,8 +128,8 @@ public: - msFillAir overwrites only those blocks that were air - msImprint overwrites with only those blocks that are non-air - Special strategies: - msLake (evaluate top-down, first match wins): + Special strategies (evaluate top-down, first match wins): + msLake: | area block | | | this | Src | result | +----------+--------+--------+ @@ -143,6 +144,14 @@ public: | mycelium | stone | stone | ... and mycelium | A | stone | A | ... but nothing else | A | * | A | Everything else is left as it is + + msSpongePrint: + Used for most generators, it allows carving out air pockets, too, and uses the Sponge as the NOP block + | area block | | + | this | Src | result | + +----------+--------+--------+ + | A | sponge | A | Sponge is the NOP block + | * | B | B | Everything else overwrites anything */ void Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy); diff --git a/src/Generating/Prefabs/NetherFortPrefabs.cpp b/src/Generating/Prefabs/NetherFortPrefabs.cpp index 6d6b11cdd..31eaa5078 100644 --- a/src/Generating/Prefabs/NetherFortPrefabs.cpp +++ b/src/Generating/Prefabs/NetherFortPrefabs.cpp @@ -127,7 +127,7 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = 7, /* 1, 2, 3 CCW rotations */ // Merge strategy: - cBlockArea::msImprint, + cBlockArea::msSpongePrint, }, // BalconyCorridor @@ -253,7 +253,7 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = 7, /* 1, 2, 3 CCW rotations */ // Merge strategy: - cBlockArea::msImprint, + cBlockArea::msSpongePrint, }, } ; // g_NetherFortPrefabs1 @@ -421,7 +421,7 @@ const cPrefab::sDef g_NetherFortStartingPrefabs1[] = 7, /* 1, 2, 3 CCW rotations */ // Merge strategy: - cBlockArea::msImprint, + cBlockArea::msSpongePrint, }, } ; // g_NetherFortStartingPrefabs1 -- cgit v1.2.3 From 773ce7fde692e86531e1e92f42776e316b793d83 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 21:35:45 +0100 Subject: Fixed non-virtual destructors warnings. --- src/Bindings/PluginManager.h | 2 ++ src/Blocks/BroadcastInterface.h | 3 ++- src/Blocks/WorldInterface.h | 3 ++- src/ForEachChunkProvider.h | 2 ++ src/Globals.h | 10 +++++++-- src/HTTPServer/HTTPServer.h | 4 +++- src/Inventory.h | 2 ++ src/ItemGrid.h | 46 +++++++++++++++++++++-------------------- src/OSSupport/ListenThread.h | 20 ++++++++++-------- src/RCONServer.h | 2 +- src/UI/WindowOwner.h | 4 ++++ 11 files changed, 61 insertions(+), 37 deletions(-) diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 03f19e831..7895be959 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -128,6 +128,8 @@ public: // tolua_export class cCommandEnumCallback { public: + virtual ~cCommandEnumCallback() {} + /** Called for each command; return true to abort enumeration For console commands, a_Permission is not used (set to empty string) */ diff --git a/src/Blocks/BroadcastInterface.h b/src/Blocks/BroadcastInterface.h index 01966ffbd..b1b450690 100644 --- a/src/Blocks/BroadcastInterface.h +++ b/src/Blocks/BroadcastInterface.h @@ -4,7 +4,8 @@ class cBroadcastInterface { public: - + virtual ~cBroadcastInterface() {} + virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0; virtual void BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL) = 0; virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) = 0; diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index 580339d32..bfbb053d9 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -9,7 +9,8 @@ class cItems; class cWorldInterface { public: - + virtual ~cWorldInterface() {} + virtual Int64 GetTimeOfDay(void) const = 0; virtual Int64 GetWorldAge(void) const = 0; diff --git a/src/ForEachChunkProvider.h b/src/ForEachChunkProvider.h index 6017173ee..7a6e8c5c6 100644 --- a/src/ForEachChunkProvider.h +++ b/src/ForEachChunkProvider.h @@ -24,6 +24,8 @@ class cBlockArea; class cForEachChunkProvider { public: + virtual ~cForEachChunkProvider() {} + /** Calls the callback for each chunk in the specified range. */ virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) = 0; diff --git a/src/Globals.h b/src/Globals.h index 3e62832b7..a1cee5c2f 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -264,11 +264,17 @@ template class SizeChecker; #define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0)) #endif -/// A generic interface used mainly in ForEach() functions + + + + +/** A generic interface used mainly in ForEach() functions */ template class cItemCallback { public: - /// Called for each item in the internal list; return true to stop the loop, or false to continue enumerating + virtual ~cItemCallback() {} + + /** Called for each item in the internal list; return true to stop the loop, or false to continue enumerating */ virtual bool Item(Type * a_Type) = 0; } ; diff --git a/src/HTTPServer/HTTPServer.h b/src/HTTPServer/HTTPServer.h index 24baf8c95..383abb4b6 100644 --- a/src/HTTPServer/HTTPServer.h +++ b/src/HTTPServer/HTTPServer.h @@ -37,6 +37,8 @@ public: class cCallbacks { public: + virtual ~cCallbacks() {} + /** Called when a new request arrives over a connection and its headers have been parsed. The request body needn't have arrived yet. */ @@ -50,7 +52,7 @@ public: } ; cHTTPServer(void); - ~cHTTPServer(); + virtual ~cHTTPServer(); /// Initializes the server on the specified ports bool Initialize(const AString & a_PortsIPv4, const AString & a_PortsIPv6); diff --git a/src/Inventory.h b/src/Inventory.h index fd2089a13..1ad7c4776 100644 --- a/src/Inventory.h +++ b/src/Inventory.h @@ -52,6 +52,8 @@ public: cInventory(cPlayer & a_Owner); + virtual ~cInventory() {} + // tolua_begin /// Removes all items from the entire inventory diff --git a/src/ItemGrid.h b/src/ItemGrid.h index b344e3daf..c34d5e9e2 100644 --- a/src/ItemGrid.h +++ b/src/ItemGrid.h @@ -20,11 +20,13 @@ class cItemGrid public: // tolua_end - /// This class is used as a callback for when a slot changes + /** This class is used as a callback for when a slot changes */ class cListener { public: - /// Called whenever a slot changes + virtual ~cListener() {} + + /** Called whenever a slot changes */ virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) = 0; } ; typedef std::vector cListeners; @@ -38,12 +40,12 @@ public: int GetHeight (void) const { return m_Height; } int GetNumSlots(void) const { return m_NumSlots; } - /// Converts XY coords into slot number; returns -1 on invalid coords + /** Converts XY coords into slot number; returns -1 on invalid coords */ int GetSlotNum(int a_X, int a_Y) const; // tolua_end - /// Converts slot number into XY coords; sets coords to -1 on invalid slot number. Exported in ManualBindings.cpp + /** Converts slot number into XY coords; sets coords to -1 on invalid slot number. Exported in ManualBindings.cpp */ void GetSlotCoords(int a_SlotNum, int & a_X, int & a_Y) const; // tolua_begin @@ -62,16 +64,16 @@ public: void EmptySlot(int a_X, int a_Y); void EmptySlot(int a_SlotNum); - /// Returns true if the specified slot is empty or the slot doesn't exist + /** Returns true if the specified slot is empty or the slot doesn't exist */ bool IsSlotEmpty(int a_SlotNum) const; - /// Returns true if the specified slot is empty or the slot doesn't exist + /** Returns true if the specified slot is empty or the slot doesn't exist */ bool IsSlotEmpty(int a_X, int a_Y) const; - /// Sets all items as empty + /** Sets all items as empty */ void Clear(void); - /// Returns number of items out of a_ItemStack that can fit in the storage + /** Returns number of items out of a_ItemStack that can fit in the storage */ int HowManyCanFit(const cItem & a_ItemStack, bool a_AllowNewStacks = true); /** Adds as many items out of a_ItemStack as can fit. @@ -117,37 +119,37 @@ public: */ cItem RemoveOneItem(int a_X, int a_Y); - /// Returns the number of items of type a_Item that are stored + /** Returns the number of items of type a_Item that are stored */ int HowManyItems(const cItem & a_Item); - /// Returns true if there are at least as many items of type a_ItemStack as in a_ItemStack + /** Returns true if there are at least as many items of type a_ItemStack as in a_ItemStack */ bool HasItems(const cItem & a_ItemStack); - /// Returns the index of the first empty slot; -1 if all full + /** Returns the index of the first empty slot; -1 if all full */ int GetFirstEmptySlot(void) const; - /// Returns the index of the first non-empty slot; -1 if all empty + /** Returns the index of the first non-empty slot; -1 if all empty */ int GetFirstUsedSlot(void) const; - /// Returns the index of the last empty slot; -1 if all full + /** Returns the index of the last empty slot; -1 if all full */ int GetLastEmptySlot(void) const; - /// Returns the index of the last used slot; -1 if all empty + /** Returns the index of the last used slot; -1 if all empty */ int GetLastUsedSlot(void) const; - /// Returns the index of the first empty slot following a_StartFrom (a_StartFrom is not checked) + /** Returns the index of the first empty slot following a_StartFrom (a_StartFrom is not checked) */ int GetNextEmptySlot(int a_StartFrom) const; - /// Returns the index of the first used slot following a_StartFrom (a_StartFrom is not checked) + /** Returns the index of the first used slot following a_StartFrom (a_StartFrom is not checked) */ int GetNextUsedSlot(int a_StartFrom) const; - /// Copies the contents into a cItems object; preserves the original a_Items contents + /** Copies the contents into a cItems object; preserves the original a_Items contents */ void CopyToItems(cItems & a_Items) const; - /// Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact) + /** Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact) */ bool DamageItem(int a_SlotNum, short a_Amount); - /// Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact) + /** Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact) */ bool DamageItem(int a_X, int a_Y, short a_Amount); // tolua_end @@ -159,10 +161,10 @@ public: */ void GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, size_t a_CountLootProbabs, int a_NumSlots, int a_Seed); - /// Adds a callback that gets called whenever a slot changes. Must not be called from within the listener callback! + /** Adds a callback that gets called whenever a slot changes. Must not be called from within the listener callback! */ void AddListener(cListener & a_Listener); - /// Removes a slot-change-callback. Must not be called from within the listener callback! + /** Removes a slot-change-callback. Must not be called from within the listener callback! */ void RemoveListener(cListener & a_Listener); // tolua_begin @@ -177,7 +179,7 @@ protected: cCriticalSection m_CSListeners; ///< CS that guards the m_Listeners against multi-thread access bool m_IsInTriggerListeners; ///< Set to true while TriggerListeners is running, to detect attempts to manipulate listener list while triggerring - /// Calls all m_Listeners for the specified slot number + /** Calls all m_Listeners for the specified slot number */ void TriggerListeners(int a_SlotNum); /** Adds up to a_Num items out of a_ItemStack, as many as can fit, in specified slot diff --git a/src/OSSupport/ListenThread.h b/src/OSSupport/ListenThread.h index 4e337d814..b2d806c82 100644 --- a/src/OSSupport/ListenThread.h +++ b/src/OSSupport/ListenThread.h @@ -29,43 +29,45 @@ class cListenThread : typedef cIsThread super; public: - /// Used as the callback for connection events + /** Used as the callback for connection events */ class cCallback { public: - /// This callback is called whenever a socket connection is accepted + virtual ~cCallback() {} + + /** This callback is called whenever a socket connection is accepted */ virtual void OnConnectionAccepted(cSocket & a_Socket) = 0; } ; cListenThread(cCallback & a_Callback, cSocket::eFamily a_Family, const AString & a_ServiceName = ""); ~cListenThread(); - /// Creates all the sockets, returns trus if successful, false if not. + /** Creates all the sockets, returns trus if successful, false if not. */ bool Initialize(const AString & a_PortsString); bool Start(void); void Stop(void); - /// Call before Initialize() to set the "reuse" flag on the sockets + /** Call before Initialize() to set the "reuse" flag on the sockets */ void SetReuseAddr(bool a_Reuse = true); protected: typedef std::vector cSockets; - /// The callback which to notify of incoming connections + /** The callback which to notify of incoming connections */ cCallback & m_Callback; - /// Socket address family to use + /** Socket address family to use */ cSocket::eFamily m_Family; - /// Sockets that are being monitored + /** Sockets that are being monitored */ cSockets m_Sockets; - /// If set to true, the SO_REUSEADDR socket option is set to true + /** If set to true, the SO_REUSEADDR socket option is set to true */ bool m_ShouldReuseAddr; - /// Name of the service that's listening on the ports; for logging purposes only + /** Name of the service that's listening on the ports; for logging purposes only */ AString m_ServiceName; diff --git a/src/RCONServer.h b/src/RCONServer.h index 0e89800a2..88aac4b5f 100644 --- a/src/RCONServer.h +++ b/src/RCONServer.h @@ -29,7 +29,7 @@ class cRCONServer : { public: cRCONServer(cServer & a_Server); - ~cRCONServer(); + virtual ~cRCONServer(); void Initialize(cIniFile & a_IniFile); diff --git a/src/UI/WindowOwner.h b/src/UI/WindowOwner.h index d41abf66d..e3c73edc4 100644 --- a/src/UI/WindowOwner.h +++ b/src/UI/WindowOwner.h @@ -33,6 +33,10 @@ public: { } + virtual ~cWindowOwner() + { + } + void CloseWindow(void) { m_Window = NULL; -- cgit v1.2.3 From 0f1087b7d51d998ac311c16588c599938934f2bd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 22:04:59 +0100 Subject: Added Prefabs to *nix builds. --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca874517e..30e9dbfd4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -232,7 +232,7 @@ endif () if (NOT MSVC) target_link_libraries(${EXECUTABLE} OSSupport HTTPServer Bindings Items Blocks) - target_link_libraries(${EXECUTABLE} Protocol Generating WorldStorage) + target_link_libraries(${EXECUTABLE} Protocol Generating Generating_Prefabs WorldStorage) target_link_libraries(${EXECUTABLE} Mobs Entities Simulator UI BlockEntities) endif () if (WIN32) -- cgit v1.2.3 From efc89b2c430c94de03bdb519470d7cb6c3b5d661 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 28 Mar 2014 22:22:29 +0100 Subject: Add tall flower handler. --- src/Blocks/BlockBigFlower.h | 97 +++++++++++++++++++++++++++++++++++++++++++++ src/Blocks/BlockHandler.cpp | 2 + 2 files changed, 99 insertions(+) create mode 100644 src/Blocks/BlockBigFlower.h diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h new file mode 100644 index 000000000..46f16c4a2 --- /dev/null +++ b/src/Blocks/BlockBigFlower.h @@ -0,0 +1,97 @@ + +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockBigFlowerHandler : + public cBlockHandler +{ +public: + typedef cBlockHandler super; + + cBlockBigFlowerHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + + virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ) override + { + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + if (Meta & 0x8) + { + super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, a_BlockY - 1, a_BlockZ); + } + else + { + super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, a_BlockY, a_BlockZ); + } + } + + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + NIBBLETYPE Meta = a_BlockMeta & 0x7; + + if ((Meta == 2) || (Meta == 3)) + { + return; + } + + a_Pickups.push_back(cItem(E_BLOCK_BIG_FLOWER, 1, Meta)); + } + + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + { + return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); + } + + + virtual void OnPlacedByPlayer( + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta + ) override + { + int Meta = (((int)floor(a_Player->GetYaw() * 4.0 / 360.0 + 0.5) & 0x3) + 2) % 4; + a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, 0x8 | Meta); + } + + + virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override + { + NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + + if (OldMeta & 0x8) + { + // Was upper part of door + if (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) == m_BlockType) + { + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); + } + } + else + { + // Was lower part + if (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ) == m_BlockType) + { + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, E_BLOCK_AIR, 0); + } + } + } + + + virtual const char * GetStepSound(void) override + { + return "step.grass"; + } +} ; + + + + diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 4f74e2f45..09e00e77d 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -8,6 +8,7 @@ #include "../Chunk.h" #include "BlockAnvil.h" #include "BlockBed.h" +#include "BlockBigFlower.h" #include "BlockBrewingStand.h" #include "BlockButton.h" #include "BlockCactus.h" @@ -89,6 +90,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_ACTIVATOR_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_ANVIL: return new cBlockAnvilHandler (a_BlockType); case E_BLOCK_BED: return new cBlockBedHandler (a_BlockType); + case E_BLOCK_BIG_FLOWER: return new cBlockBigFlowerHandler (a_BlockType); case E_BLOCK_BIRCH_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_BREWING_STAND: return new cBlockBrewingStandHandler (a_BlockType); case E_BLOCK_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); -- cgit v1.2.3 From f2f6096ee5b92b21924348975c923f74dd23786b Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 28 Mar 2014 22:24:54 +0100 Subject: door -> flower --- src/Blocks/BlockBigFlower.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h index 46f16c4a2..fabc4c4ed 100644 --- a/src/Blocks/BlockBigFlower.h +++ b/src/Blocks/BlockBigFlower.h @@ -69,7 +69,7 @@ public: if (OldMeta & 0x8) { - // Was upper part of door + // Was upper part of flower if (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) == m_BlockType) { a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0); -- cgit v1.2.3 From a78bacac3cb915a82b73bf8fe0ccc0a153190df9 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 28 Mar 2014 23:14:58 +0100 Subject: Add tallgrass drop to big flowers. Add tallgrass drop, when a players break a tallgrass with the shear. --- src/Blocks/BlockBigFlower.h | 43 ++++++++++++++++++++++++++++++++++++++++--- src/Blocks/BlockTallGrass.h | 24 +++++++++++++++++++----- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h index fabc4c4ed..194a79a67 100644 --- a/src/Blocks/BlockBigFlower.h +++ b/src/Blocks/BlockBigFlower.h @@ -44,10 +44,47 @@ public: a_Pickups.push_back(cItem(E_BLOCK_BIG_FLOWER, 1, Meta)); } - + + + virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override + { + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + if (Meta & 0x8) + { + Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ); + } + + NIBBLETYPE FlowerMeta = Meta & 0x7; + if (!a_Player->IsGameModeCreative()) + { + if (((FlowerMeta == 2) || (FlowerMeta == 3)) && (a_Player->GetEquippedItem().m_ItemType == E_ITEM_SHEARS)) + { + MTRand r1; + if (r1.randInt(10) == 5) + { + cItems Pickups; + if (FlowerMeta == 2) + { + Pickups.Add(E_BLOCK_TALL_GRASS, 2, 1); + } + else if (FlowerMeta == 3) + { + Pickups.Add(E_BLOCK_TALL_GRASS, 2, 2); + } + a_WorldInterface.SpawnItemPickups(Pickups, a_BlockX, a_BlockY, a_BlockZ); + } + a_Player->UseEquippedItem(); + } + } + } + + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { - return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); + return ( + a_RelY > 0 + && a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR + ); } @@ -59,7 +96,7 @@ public: ) override { int Meta = (((int)floor(a_Player->GetYaw() * 4.0 / 360.0 + 0.5) & 0x3) + 2) % 4; - a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, 0x8 | Meta); + a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, 0x8 | Meta); } diff --git a/src/Blocks/BlockTallGrass.h b/src/Blocks/BlockTallGrass.h index b8af1f1da..ba1f2e0f6 100644 --- a/src/Blocks/BlockTallGrass.h +++ b/src/Blocks/BlockTallGrass.h @@ -15,14 +15,14 @@ public: : cBlockHandler(a_BlockType) { } - - + + virtual bool DoesIgnoreBuildCollision(void) override { return true; } - - + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { // Drop seeds, sometimes @@ -34,11 +34,25 @@ public: } + virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override + { + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + + if ((!a_Player->IsGameModeCreative()) && (a_Player->GetEquippedItem().m_ItemType == E_ITEM_SHEARS)) + { + cItems Pickups; + Pickups.Add(E_BLOCK_TALL_GRASS, 1, Meta); + a_WorldInterface.SpawnItemPickups(Pickups, a_BlockX, a_BlockY, a_BlockZ); + } + a_Player->UseEquippedItem(); + } + + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); } - + virtual const char * GetStepSound(void) override { -- cgit v1.2.3 From 76f0d167b15de08a810a1348614e8b8c2b6f2e60 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 23:39:40 +0100 Subject: NetherFortGen: Added several more prefabs. Also extended the defauls MaxDepth value to 12. --- src/Generating/ComposableGenerator.cpp | 2 +- src/Generating/Prefabs/NetherFortPrefabs.cpp | 783 ++++++++++++++++++++++++++- 2 files changed, 783 insertions(+), 2 deletions(-) diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 339f5709a..2e886336f 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -373,7 +373,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) else if (NoCaseCompare(*itr, "NetherForts") == 0) { int GridSize = a_IniFile.GetValueSetI("Generator", "NetherFortsGridSize", 512); - int MaxDepth = a_IniFile.GetValueSetI("Generator", "NetherFortsMaxDepth", 6); + int MaxDepth = a_IniFile.GetValueSetI("Generator", "NetherFortsMaxDepth", 12); m_FinishGens.push_back(new cNetherFortGen(Seed, GridSize, MaxDepth)); } else if (NoCaseCompare(*itr, "OreNests") == 0) diff --git a/src/Generating/Prefabs/NetherFortPrefabs.cpp b/src/Generating/Prefabs/NetherFortPrefabs.cpp index 31eaa5078..24bde1baf 100644 --- a/src/Generating/Prefabs/NetherFortPrefabs.cpp +++ b/src/Generating/Prefabs/NetherFortPrefabs.cpp @@ -254,8 +254,789 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = // Merge strategy: cBlockArea::msSpongePrint, - }, + }, // BalconyTee2 + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // BlazePlatform + // The data has been exported from gallery Nether, area index 26, ID 276 + { + // Size: + 10, 7, 7, // SizeX = 10, SizeY = 7, SizeZ = 7 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b: 52: 0\n" /* mobspawner */ + "c:113: 0\n" /* netherbrickfence */, + + // Block data: + // Level 1 + ".........." + "aaaaaaaaaa" + "aaaaaaaaaa" + "aaaaaaaaaa" + "aaaaaaaaaa" + "aaaaaaaaaa" + ".........." + + // Level 2 + ".........." + "aaaaaaaaaa" + "..aaaaaaaa" + "..aaaaaaaa" + "..aaaaaaaa" + "aaaaaaaaaa" + ".........." + + // Level 3 + "....aaaaaa" + "aaaaaaaaaa" + "...aaaaaaa" + "...aaaaaaa" + "...aaaaaaa" + "aaaaaaaaaa" + "....aaaaaa" + + // Level 4 + "....aaaaaa" + "..aaa....a" + ".........a" + "......b..a" + ".........a" + "..aaa....a" + "....aaaaaa" + + // Level 5 + "....cccccc" + "...cc....c" + ".........c" + ".........c" + ".........c" + "...cc....c" + "....cccccc" + + // Level 6 + ".........." + ".........c" + ".........c" + ".........c" + ".........c" + ".........c" + ".........." + + // Level 7 + ".........." + ".........." + ".........c" + ".........c" + ".........c" + ".........." + "..........", + + // Connections: + "0: 0, 1, 3: 4\n" /* Type 0, BLOCK_FACE_XM */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // BlazePlatform + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // BlazePlatformOverhang: + // The data has been exported from gallery Nether, area index 20, ID 162 + { + // Size: + 14, 9, 7, // SizeX = 14, SizeY = 9, SizeZ = 7 + + // Block definitions: + ".: 0: 0\n" /* 0 */ + "a:112: 0\n" /* netherbrick */ + "b:114: 5\n" /* netherbrickstairs */ + "c: 44:14\n" /* step */ + "d:114: 6\n" /* netherbrickstairs */ + "e:114: 7\n" /* netherbrickstairs */ + "f:114: 0\n" /* netherbrickstairs */ + "g:114: 4\n" /* netherbrickstairs */ + "h:113: 0\n" /* netherbrickfence */ + "i: 52: 0\n" /* mobspawner */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 1 + "mmmmmmmmmmmmmm" + "mmmmmmmmmmmmmm" + "aammmmmmmmmmmm" + "aammmmmmmmmmmm" + "aammmmmmmmmmmm" + "mmmmmmmmmmmmmm" + "mmmmmmmmmmmmmm" + + // Level 2 + "mmmmmmmmmmmmmm" + "mmmmmmmmmmmmmm" + "aabcmmmmmmmmmm" + "aabcmmmmmmmmmm" + "aabcmmmmmmmmmm" + "mmmmmmmmmmmmmm" + "mmmmmmmmmmmmmm" + + // Level 3 + "mmmmmmmmmmmmmm" + "mmmmmmmmmmmmmm" + "aaaaabmmmmmmmm" + "aaaaabmmmmmmmm" + "aaaaabmmmmmmmm" + "mmmmmmmmmmmmmm" + "mmmmmmmmmmmmmm" + + // Level 4 + "mmmmmmmmmmmmmm" + "dddddddmmmmmmm" + "aaaaaabmmmmmmm" + "aaaaaabmmmmmmm" + "aaaaaabmmmmmmm" + "eeeeeeemmmmmmm" + "mmmmmmmmmmmmmm" + + // Level 5 + "mmmmmmmmmmmmmm" + "aaaaaaadmmmmmm" + "aaaaaaabmmmmmm" + "aaaaaaabmmmmmm" + "aaaaaaabmmmmmm" + "aaaaaaaemmmmmm" + "mmmmmmmmmmmmmm" + + // Level 6 + "mmmmmmmmmmmmmm" + "aaaaaaaabddddm" + "......faaaaabm" + "......faaaaabm" + "......faaaaabm" + "aaaaaaaaabeebm" + "mmmmmmmmmmmmmm" + + // Level 7 + "mmmmmmmmgdddbm" + "......aaaaaaad" + ".......faaaaab" + ".......faaaaab" + ".......faaaaab" + "......aaaaaaae" + "mmmmmmmmgeeebm" + + // Level 8 + "mmmmmmmmaaaaam" + "......haa...aa" + ".............a" + "..........i..a" + ".............a" + "......haa...aa" + "mmmmmmmmaaaaam" + + // Level 9 + "mmmmmmmmhhhhhm" + "......hhh...hh" + ".............h" + ".............h" + ".............h" + "......hhh...hh" + "mmmmmmmmhhhhhm", + + // Connections: + "0: 0, 5, 3: 4\n" /* Type 0, BLOCK_FACE_XM */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // BlazePlatformOverhang + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // BridgeCrossing: + // The data has been exported from gallery Nether, area index 17, ID 159 + { + // Size: + 15, 8, 15, // SizeX = 15, SizeY = 8, SizeZ = 15 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:114: 7\n" /* netherbrickstairs */ + "c:114: 5\n" /* netherbrickstairs */ + "d:114: 4\n" /* netherbrickstairs */ + "e:114: 6\n" /* netherbrickstairs */ + "f: 44:14\n" /* step */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 1 + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "aammmmmmmmmmmaa" + "aammmmmmmmmmmaa" + "aammmmmmmmmmmaa" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + + // Level 2 + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + "mmmmmmbbbmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "aacmmmmmmmmmdaa" + "aacmmmmmmmmmdaa" + "aacmmmmmmmmmdaa" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmeeemmmmmm" + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + + // Level 3 + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + "mmmmmmbbbmmmmmm" + "mmmmmmfffmmmmmm" + "mmmmmmmmmmmmmmm" + "aaacfmmmmmfdaaa" + "aaacfmmmmmfdaaa" + "aaacfmmmmmfdaaa" + "mmmmmmmmmmmmmmm" + "mmmmmmfffmmmmmm" + "mmmmmmeeemmmmmm" + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + + // Level 4 + "mmmmmdaaacmmmmm" + "mmmmmdaaacmmmmm" + "mmmmmdaaacmmmmm" + "mmmmmdaaacmmmmm" + "mmmmmdaaacmmmmm" + "eeeeeeaaaeeeeee" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "bbbbbdaaacbbbbb" + "mmmmmdaaacmmmmm" + "mmmmmdaaacmmmmm" + "mmmmmdaaacmmmmm" + "mmmmmdaaacmmmmm" + "mmmmmdaaacmmmmm" + + // Level 5 + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + + // Level 6 + "mmmmma...ammmmm" + "mmmmma...ammmmm" + "mmmmma...ammmmm" + "mmmmma...ammmmm" + "mmmmma...ammmmm" + "aaaaaa...aaaaaa" + "..............." + "..............." + "..............." + "aaaaaa...aaaaaa" + "mmmmma...ammmmm" + "mmmmma...ammmmm" + "mmmmma...ammmmm" + "mmmmma...ammmmm" + "mmmmma...ammmmm" + + // Level 7 + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "..............." + "..............." + "..............." + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + + // Level 8 + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "..............." + "..............." + "..............." + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm", + + // Connections: + "0: 0, 5, 7: 4\n" /* Type 0, BLOCK_FACE_XM */ + "0: 7, 5, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ + "0: 14, 5, 7: 5\n" /* Type 0, BLOCK_FACE_XP */ + "0: 7, 5, 14: 3\n" /* Type 0, BLOCK_FACE_ZP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // BridgeCrossing + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // BridgeCrumble1: + // The data has been exported from gallery Nether, area index 19, ID 161 + { + // Size: + 9, 6, 5, // SizeX = 9, SizeY = 6, SizeZ = 5 + + // Block definitions: + ".: 19: 0\n" /* sponge */ + "a:112: 0\n" /* netherbrick */ + "b:114: 5\n" /* netherbrickstairs */ + "c: 44:14\n" /* step */ + "d:114: 6\n" /* netherbrickstairs */ + "e:114: 7\n" /* netherbrickstairs */, + + // Block data: + // Level 1 + "........." + "aa......." + "aa......." + "aa......." + "........." + + // Level 2 + "........." + "aab......" + "aab......" + "aab......" + "........." + + // Level 3 + "........." + "aaabc...." + "aaabc...." + "aaabc...." + "........." + + // Level 4 + "ddddddd.." + "aaaaaaaa." + "aaaaaaaaa" + "aaaaaaa.." + "eeeee...." + + // Level 5 + "aaaaaaaaa" + "aaaaa...." + "aaaaaa..." + "aaaaaa..." + "aaaaaaaa." + + // Level 6 + "aaaaaa..." + "........." + "........." + "........." + "aaaaaaa..", + + // Connections: + "0: 0, 5, 2: 4\n" /* Type 0, BLOCK_FACE_XM */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // BridgeCrumble1 + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // BridgeCrumble2 + // The data has been exported from gallery Nether, area index 18, ID 160 + { + // Size: + 13, 6, 5, // SizeX = 13, SizeY = 6, SizeZ = 5 + + // Block definitions: + ".: 19: 0\n" /* sponge */ + "a:112: 0\n" /* netherbrick */ + "b:114: 5\n" /* netherbrickstairs */ + "c: 44:14\n" /* step */ + "d:114: 6\n" /* netherbrickstairs */ + "e:114: 7\n" /* netherbrickstairs */, + + // Block data: + // Level 1 + "............." + "aa..........." + "aa..........." + "aa..........." + "............." + + // Level 2 + "............." + "aab.........." + "aab.........." + "aab.........." + "............." + // Level 3 + "............." + "aaabc........" + "aaabc........" + "aaabc........" + "............." + + // Level 4 + "ddddddddd...." + "aaaaaaaaaaaaa" + "aaaaaaaaa...." + "aaaaaaaaaaaa." + "eeeeeeeee...." + + // Level 5 + "aaaaaaaaaaaa." + "aaaaaaaaaa..." + "aaaaaaaaaaa.." + "aaaaaaaaa...." + "aaaaaaaaaaaaa" + + // Level 6 + "aaaaaaaaa...." + "............." + "............." + "............." + "aaaaaaaaaa...", + + // Connections: + "0: 0, 5, 2: 4\n" /* Type 0, BLOCK_FACE_XM */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // BridgeCrumble2 + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // BridgeSegment: + // The data has been exported from gallery Nether, area index 16, ID 158 + { + // Size: + 15, 8, 5, // SizeX = 15, SizeY = 8, SizeZ = 5 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:114: 5\n" /* netherbrickstairs */ + "c:114: 4\n" /* netherbrickstairs */ + "d: 44:14\n" /* step */ + "e:114: 6\n" /* netherbrickstairs */ + "f:114: 7\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 1 + "mmmmmmmmmmmmmmm" + "aammmmmmmmmmmaa" + "aammmmmmmmmmmaa" + "aammmmmmmmmmmaa" + "mmmmmmmmmmmmmmm" + + // Level 2 + "mmmmmmmmmmmmmmm" + "aabmmmmmmmmmcaa" + "aabmmmmmmmmmcaa" + "aabmmmmmmmmmcaa" + "mmmmmmmmmmmmmmm" + + // Level 3 + "mmmmmmmmmmmmmmm" + "aaabdmmmmmdcaaa" + "aaabdmmmmmdcaaa" + "aaabdmmmmmdcaaa" + "mmmmmmmmmmmmmmm" + + // Level 4 + "eeeeeeeeeeeeeee" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "fffffffffffffff" + + // Level 5 + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + + // Level 6 + "aaaaaaaaaaaaaaa" + "..............." + "..............." + "..............." + "aaaaaaaaaaaaaaa" + + // Level 7 + "mmmmmmmmmmmmmmm" + "..............." + "..............." + "..............." + "mmmmmmmmmmmmmmm" + + // Level 8 + "mmmmmmmmmmmmmmm" + "..............." + "..............." + "..............." + "mmmmmmmmmmmmmmm", + + // Connections: + "0: 0, 5, 2: 4\n" /* Type 0, BLOCK_FACE_XM */ + "0: 14, 5, 2: 5\n" /* Type 0, BLOCK_FACE_XP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // BridgeSegment + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Corridor13: + // The data has been exported from gallery Nether, area index 35, ID 286 + { + // Size: + 13, 6, 5, // SizeX = 13, SizeY = 6, SizeZ = 5 + + // Block definitions: + "a:112: 0\n" /* netherbrick */ + ".: 0: 0\n" /* air */ + "c:113: 0\n" /* netherbrickfence */ + "d:114: 2\n" /* netherbrickstairs */ + "e:114: 3\n" /* netherbrickstairs */, + + // Block data: + // Level 1 + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 2 + "aaaaaaaaaaaaa" + "............." + "............." + "............." + "aaaaaaaaaaaaa" + + // Level 3 + "acacacacacaca" + "............." + "............." + "............." + "acacacacacaca" + + // Level 4 + "acacacacacaca" + "............." + "............." + "............." + "acacacacacaca" + + // Level 5 + "acacacacacaca" + "............." + "............." + "............." + "acacacacacaca" + + // Level 6 + "ddddddddddddd" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "eeeeeeeeeeeee", + + // Connections: + "1: 0, 1, 2: 4\n" /* Type 1, BLOCK_FACE_XM */ + "1: 12, 1, 2: 5\n" /* Type 1, BLOCK_FACE_XP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // Corridor13 + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // CorridorStairs: + // The data has been exported from gallery Nether, area index 12, ID 42 + { + // Size: + 9, 13, 5, // SizeX = 9, SizeY = 13, SizeZ = 5 + + // Block definitions: + ".: 0: 0\n" /* 0 */ + "a:112: 0\n" /* netherbrick */ + "b:114: 0\n" /* netherbrickstairs */ + "c:113: 0\n" /* netherbrickfence */ + "d:114: 2\n" /* netherbrickstairs */ + "e:114: 3\n" /* netherbrickstairs */ + "f: 19: 0\n" /* sponge */, + + // Block data: + // Level 1 + "aaaaaaaaa" + "aaaaaaaaa" + "aaaaaaaaa" + "aaaaaaaaa" + "aaaaaaaaa" + + // Level 2 + "aaaaaaaaa" + ".baaaaaaa" + ".baaaaaaa" + ".baaaaaaa" + "aaaaaaaaa" + + // Level 3 + "acaaaaaaa" + "..baaaaaa" + "..baaaaaa" + "..baaaaaa" + "acaaaaaaa" + + // Level 4 + "acaaaaaaa" + "...baaaaa" + "...baaaaa" + "...baaaaa" + "acaaaaaaa" + + // Level 5 + "acacaaaaa" + "....baaaa" + "....baaaa" + "....baaaa" + "acacaaaaa" + + // Level 6 + "aaacaaaaa" + ".....baaa" + ".....baaa" + ".....baaa" + "aaacaaaaa" + + // Level 7 + "daacacaaa" + "a.....baa" + "a.....baa" + "a.....baa" + "eaacacaaa" + + // Level 8 + "fdaaacaaa" + "fa.....ba" + "fa.....ba" + "fa.....ba" + "feaaacaaa" + + // Level 9 + "ffdaacaca" + "ffa......" + "ffa......" + "ffa......" + "ffeaacaca" + + // Level 10 + "fffdaaaca" + "fffa....." + "fffa....." + "fffa....." + "fffeaaaca" + + // Level 11 + "ffffdaaca" + "ffffa...." + "ffffa...." + "ffffa...." + "ffffeaaca" + + // Level 12 + "fffffdaaa" + "fffffa..." + "fffffa..." + "fffffa..." + "fffffeaaa" + + // Level 13 + "ffffffddd" + "ffffffaaa" + "ffffffaaa" + "ffffffaaa" + "ffffffeee", + + // Connections: + "1: 0, 1, 2: 4\n" /* Type 1, BLOCK_FACE_XM */ + "1: 8, 8, 2: 5\n" /* Type 1, BLOCK_FACE_XP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // CorridorStairs } ; // g_NetherFortPrefabs1 -- cgit v1.2.3 From 283a66bcae5f26d2b5038ba0959314a687c4d8b6 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 28 Mar 2014 22:51:30 +0000 Subject: Some fixes to lilypads * Fixed placement on lava * Fixed placement on side of blocks * Fixed placement through blocks + Added washing-away of pads + Added ice as a block that fully occupies its voxel --- src/BlockInfo.cpp | 3 +- src/Blocks/BlockLilypad.h | 66 ++---------------------- src/Items/ItemHandler.cpp | 2 + src/Items/ItemLilypad.h | 106 +++++++++++++++++++++++++++++++++++++++ src/Simulator/FluidSimulator.cpp | 1 + 5 files changed, 116 insertions(+), 62 deletions(-) create mode 100644 src/Items/ItemLilypad.h diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index 7d438ba3e..6fb5aa5b3 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -365,7 +365,7 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_WOODEN_SLAB ].m_IsSolid = false; - // Torch placeable blocks: + // Blocks that fully occupy their voxel - used as a guide for torch placeable blocks, amongst other things: ms_Info[E_BLOCK_NEW_LOG ].m_FullyOccupiesVoxel = true; ms_Info[E_BLOCK_BEDROCK ].m_FullyOccupiesVoxel = true; ms_Info[E_BLOCK_BLOCK_OF_COAL ].m_FullyOccupiesVoxel = true; @@ -397,6 +397,7 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_HAY_BALE ].m_FullyOccupiesVoxel = true; ms_Info[E_BLOCK_HUGE_BROWN_MUSHROOM ].m_FullyOccupiesVoxel = true; ms_Info[E_BLOCK_HUGE_RED_MUSHROOM ].m_FullyOccupiesVoxel = true; + ms_Info[E_BLOCK_ICE ].m_FullyOccupiesVoxel = true; ms_Info[E_BLOCK_IRON_BLOCK ].m_FullyOccupiesVoxel = true; ms_Info[E_BLOCK_IRON_ORE ].m_FullyOccupiesVoxel = true; ms_Info[E_BLOCK_JACK_O_LANTERN ].m_FullyOccupiesVoxel = true; diff --git a/src/Blocks/BlockLilypad.h b/src/Blocks/BlockLilypad.h index 3db280d80..2dd4ec768 100644 --- a/src/Blocks/BlockLilypad.h +++ b/src/Blocks/BlockLilypad.h @@ -2,10 +2,7 @@ #pragma once #include "BlockHandler.h" -#include "../Entities/Player.h" -#include "Vector3.h" -#include "../LineBlockTracer.h" - +#include "Entities/Pickup.h" @@ -13,69 +10,16 @@ class cBlockLilypadHandler : public cBlockHandler { - typedef cBlockHandler super; - public: cBlockLilypadHandler(BLOCKTYPE a_BlockType) : cBlockHandler(a_BlockType) { - } - - virtual bool GetPlacementBlockTypeMeta( - cChunkInterface & a_ChunkInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, - int a_CursorX, int a_CursorY, int a_CursorZ, - BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta - ) override + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { - if (a_BlockFace > 0) - { - return false; - } - - class cCallbacks : - public cBlockTracer::cCallbacks - { - public: - cCallbacks(void) : - m_HasHitFluid(false) - { - } - - virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override - { - if (IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType)) - { - if ((a_BlockMeta != 0) || (a_EntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is for AddFaceDir below - { - return false; - } - m_HasHitFluid = true; - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, (eBlockFace)a_EntryFace); - m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); - return true; - } - return false; - } - - Vector3i m_Pos; - bool m_HasHitFluid; - - } Callbacks; - - cLineBlockTracer Tracer(*a_Player->GetWorld(), Callbacks); - Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector()); - Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5); - - Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z); - - if (Callbacks.m_HasHitFluid) - { - a_Player->GetWorld()->SetBlock(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z, E_BLOCK_LILY_PAD, 0); - } - - return false; + // Reset meta to zero + a_Pickups.push_back(cItem(E_BLOCK_LILY_PAD, 1, 0)); } }; diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 454fabdd7..337b3a83c 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -27,6 +27,7 @@ #include "ItemHoe.h" #include "ItemLeaves.h" #include "ItemLighter.h" +#include "ItemLilypad.h" #include "ItemMap.h" #include "ItemMinecart.h" #include "ItemNetherWart.h" @@ -115,6 +116,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_FISHING_ROD: return new cItemFishingRodHandler(a_ItemType); case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType); case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType); + case E_BLOCK_LILY_PAD: return new cItemLilypadHandler(a_ItemType); case E_ITEM_MAP: return new cItemMapHandler(); case E_ITEM_ITEM_FRAME: return new cItemItemFrameHandler(a_ItemType); case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType); diff --git a/src/Items/ItemLilypad.h b/src/Items/ItemLilypad.h new file mode 100644 index 000000000..8496b9f31 --- /dev/null +++ b/src/Items/ItemLilypad.h @@ -0,0 +1,106 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../Entities/Player.h" +#include "Vector3.h" +#include "../LineBlockTracer.h" +#include "BlockInfo.h" + + + + + +class cItemLilypadHandler : + public cItemHandler +{ + typedef cItemHandler super; + +public: + cItemLilypadHandler(BLOCKTYPE a_BlockType) + : cItemHandler(a_BlockType) + { + + } + + virtual bool IsPlaceable(void) override + { + return false; // Set as not placeable so OnItemUse is called + } + + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override + { + if (a_BlockFace > BLOCK_FACE_NONE) + { + // Clicked on the side of a submerged block; vanilla allows placement, so should we + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); + a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LILY_PAD, 0); + if (!a_Player->IsGameModeCreative()) + a_Player->GetInventory().RemoveOneEquippedItem(); + return true; + } + + class cCallbacks : + public cBlockTracer::cCallbacks + { + public: + cCallbacks(cWorld * a_World) : + m_HasHitFluid(false), + m_World(a_World) + { + } + + virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override + { + if (IsBlockWater(a_BlockType)) + { + if ((a_BlockMeta != 0) || (a_EntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is clicking whilst submerged + { + return false; + } + a_EntryFace = BLOCK_FACE_YP; // Always place pad at top of water block + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, (eBlockFace)a_EntryFace); + BLOCKTYPE Block = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + if ( + !IsBlockWater(Block) && + cBlockInfo::FullyOccupiesVoxel(Block) + ) + { + // Can't place lilypad on air/in another block! + return true; + } + m_HasHitFluid = true; + m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); + return true; + } + return false; + } + + Vector3i m_Pos; + bool m_HasHitFluid; + cWorld * m_World; + + }; + + cCallbacks Callbacks(a_World); + cLineBlockTracer Tracer(*a_Player->GetWorld(), Callbacks); + Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector()); + Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5); + + Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z); + + if (Callbacks.m_HasHitFluid) + { + a_World->SetBlock(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z, E_BLOCK_LILY_PAD, 0); + if (!a_Player->IsGameModeCreative()) + a_Player->GetInventory().RemoveOneEquippedItem(); + return true; + } + + return false; + } +}; + + + + diff --git a/src/Simulator/FluidSimulator.cpp b/src/Simulator/FluidSimulator.cpp index 61c93ed73..7779573d7 100644 --- a/src/Simulator/FluidSimulator.cpp +++ b/src/Simulator/FluidSimulator.cpp @@ -36,6 +36,7 @@ bool cFluidSimulator::CanWashAway(BLOCKTYPE a_BlockType) case E_BLOCK_COBWEB: case E_BLOCK_CROPS: case E_BLOCK_DEAD_BUSH: + case E_BLOCK_LILY_PAD: case E_BLOCK_RAIL: case E_BLOCK_REDSTONE_TORCH_OFF: case E_BLOCK_REDSTONE_TORCH_ON: -- cgit v1.2.3 From 8ece214920cc9cbec2c04cfa046b451a2553e279 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 28 Mar 2014 22:51:39 +0000 Subject: Fixed a potential crash --- src/Chunk.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 957d7d575..ea961733f 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -884,7 +884,7 @@ void cChunk::ApplyWeatherToTop() FastSetBlock(X, Height, Z, E_BLOCK_SNOW, TopMeta - 1); } } - else if (cBlockInfo::IsSnowable(TopBlock)) + else if (cBlockInfo::IsSnowable(TopBlock) && (Height + 1 < cChunkDef::Height)) { SetBlock(X, Height + 1, Z, E_BLOCK_SNOW, 0); } -- cgit v1.2.3 From aee1f8f9d13c501a53e3636596c09dbce0f289bb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 28 Mar 2014 22:52:04 +0000 Subject: Fixed block interaction rate check --- src/ClientHandle.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 2c47faa65..443c248b0 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -941,6 +941,8 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e } return; } + + m_NumBlockChangeInteractionsThisTick++; if (!CheckBlockInteractionsRate()) { @@ -1053,8 +1055,8 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e cBlockSlabHandler::IsAnySlabType(EquippedBlock) && // Is the player placing another slab? ((ClickedBlockMeta & 0x07) == EquippedBlockDamage) && // Is it the same slab type? ( - (a_BlockFace == BLOCK_FACE_TOP) || // Clicking the top of a bottom slab - (a_BlockFace == BLOCK_FACE_BOTTOM) // Clicking the bottom of a top slab + (a_BlockFace == BLOCK_FACE_TOP) || // Clicking the top of a bottom slab + (a_BlockFace == BLOCK_FACE_BOTTOM) // Clicking the bottom of a top slab ) ) { -- cgit v1.2.3 From 79aa082b048ba1c4a0407d1faa8fb96a33dd4415 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 28 Mar 2014 22:52:23 +0000 Subject: Fixed infinite minecart items --- src/Items/ItemMinecart.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Items/ItemMinecart.h b/src/Items/ItemMinecart.h index bcaa5635a..bf6f70eed 100644 --- a/src/Items/ItemMinecart.h +++ b/src/Items/ItemMinecart.h @@ -72,6 +72,9 @@ public: } } // switch (m_ItemType) Minecart->Initialize(a_World); + + if (!a_Player->IsGameModeCreative()) + a_Player->GetInventory().RemoveOneEquippedItem(); return true; } -- cgit v1.2.3 From 6eacf1aa922b9dd2193a835e6a45ddf71fbbb729 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 28 Mar 2014 23:07:50 +0000 Subject: Fixed a minor ini key duplication bug --- src/Root.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Root.cpp b/src/Root.cpp index 3555afb45..ba4398b35 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -304,6 +304,7 @@ void cRoot::LoadWorlds(cIniFile & IniFile) { if (IniFile.GetKeyComment("Worlds", 0) != " World=secondworld") { + IniFile.DeleteKeyComment("Worlds", 0); IniFile.AddKeyComment("Worlds", " World=secondworld"); } } -- cgit v1.2.3 From 6dea7993f2a563a8b3a0746feeb2174922631526 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 28 Mar 2014 23:25:11 +0000 Subject: Fixed #721 and FS439 --- src/Entities/Player.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 863aaa799..646aad50f 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1489,6 +1489,7 @@ bool cPlayer::MoveToWorld(const char * a_WorldName) // Add player to all the necessary parts of the new world SetWorld(World); + m_ClientHandle->StreamChunks(); World->AddEntity(this); World->AddPlayer(this); -- cgit v1.2.3 From 519bd0b989fb931fd0925bad6a5cb1a9e223d85f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 28 Mar 2014 23:51:52 +0000 Subject: Curly brackets --- src/Items/ItemLilypad.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Items/ItemLilypad.h b/src/Items/ItemLilypad.h index 8496b9f31..5a29abe94 100644 --- a/src/Items/ItemLilypad.h +++ b/src/Items/ItemLilypad.h @@ -1,4 +1,3 @@ - #pragma once #include "ItemHandler.h" @@ -36,7 +35,9 @@ public: AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LILY_PAD, 0); if (!a_Player->IsGameModeCreative()) + { a_Player->GetInventory().RemoveOneEquippedItem(); + } return true; } @@ -93,7 +94,9 @@ public: { a_World->SetBlock(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z, E_BLOCK_LILY_PAD, 0); if (!a_Player->IsGameModeCreative()) + { a_Player->GetInventory().RemoveOneEquippedItem(); + } return true; } -- cgit v1.2.3 From fb16554322e3995f065135b481fffd58a5b2551e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 29 Mar 2014 01:21:56 +0000 Subject: Fixed players not updating after world change Addendum to 6dea7993f2a563a8b3a0746feeb2174922631526 --- src/ClientHandle.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 46c10ae82..eb05ebdb7 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1606,10 +1606,8 @@ void cClientHandle::MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket) m_Protocol->SendUnloadChunk(itr->m_ChunkX, itr->m_ChunkZ); } // for itr - Chunks[] - // Do NOT stream new chunks, the new world runs its own tick thread and may deadlock - // Instead, the chunks will be streamed when the client is moved to the new world's Tick list, - // by setting state to csAuthenticated - m_State = csAuthenticated; + // StreamChunks() called in cPlayer::MoveToWorld() after new world has been set + // Meanwhile here, we set last streamed values to bogus ones so everything is resent m_LastStreamedChunkX = 0x7fffffff; m_LastStreamedChunkZ = 0x7fffffff; m_HasSentPlayerChunk = false; -- cgit v1.2.3 From aefabfcafa1103b0bea80b40508748635def67a0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 29 Mar 2014 10:25:40 +0000 Subject: Removed leftover clienthandle code --- src/ClientHandle.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 443c248b0..27c6b1226 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -933,7 +933,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType); BlockHandler->OnCancelRightClick(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); - if (a_BlockFace != BLOCK_FACE_NONE) + if (a_BlockFace > BLOCK_FACE_NONE) { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); @@ -962,7 +962,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e ); // Let's send the current world block to the client, so that it can immediately "let the user know" that they haven't placed the block - if (a_BlockFace > -1) + if (a_BlockFace > BLOCK_FACE_NONE) { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); @@ -990,7 +990,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Equipped.m_ItemType); - if (ItemHandler->IsPlaceable() && ((a_BlockFace > -1) || (Equipped.m_ItemType == E_BLOCK_LILY_PAD))) + if (ItemHandler->IsPlaceable() && (a_BlockFace > BLOCK_FACE_NONE)) { HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); } @@ -1029,7 +1029,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler) { BLOCKTYPE EquippedBlock = (BLOCKTYPE)(m_Player->GetEquippedItem().m_ItemType); - if ((a_BlockFace < 0) && (EquippedBlock != E_BLOCK_LILY_PAD)) + if (a_BlockFace < 0) { // Clicked in air return; @@ -1087,10 +1087,7 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e } else { - if (EquippedBlock != E_BLOCK_LILY_PAD) - { - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); - } + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); if ((a_BlockY < 0) || (a_BlockY >= cChunkDef::Height)) { @@ -1111,7 +1108,6 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e else { if ( - (EquippedBlock != E_BLOCK_LILY_PAD) && !BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision() && !BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision(m_Player, PlaceMeta) ) @@ -1144,7 +1140,7 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e // The actual block placement: World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); - if (m_Player->GetGameMode() != gmCreative) + if (!m_Player->IsGameModeCreative()) { m_Player->GetInventory().RemoveOneEquippedItem(); } -- cgit v1.2.3 From 0f6688fe9e2df97a6979be452efa789245acfadb Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 29 Mar 2014 12:24:26 +0100 Subject: Updated the android files --- Android/jni/Android.mk | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Android/jni/Android.mk b/Android/jni/Android.mk index 3542e588b..ce142d446 100644 --- a/Android/jni/Android.mk +++ b/Android/jni/Android.mk @@ -5,7 +5,7 @@ LOCAL_MODULE := mcserver -LOCAL_SRC_FILES := $(shell find ../CryptoPP ../lua ../jsoncpp ../zlib ../src ../tolua++ ../iniFile ../expat ../md5 ../sqlite ../luaexpat '(' -name '*.cpp' -o -name '*.c' ')') +LOCAL_SRC_FILES := $(shell find ../lib/polarssl ../lib/lua ../lib/jsoncpp ../lib/zlib ../src ../lib/tolua++ ../lib/iniFile ../lib/expat ../lib/md5 ../lib/sqlite ../lib/luaexpat '(' -name '*.cpp' -o -name '*.c' ')') LOCAL_SRC_FILES := $(filter-out %SquirrelFunctions.cpp %SquirrelBindings.cpp %cPlugin_Squirrel.cpp %cSquirrelCommandBinder.cpp %minigzip.c %lua.c %tolua.c %toluabind.c %LeakFinder.cpp %StackWalker.cpp %example.c,$(LOCAL_SRC_FILES)) LOCAL_SRC_FILES := $(patsubst %.cpp,../%.cpp,$(LOCAL_SRC_FILES)) LOCAL_SRC_FILES := $(patsubst %.c,../%.c,$(LOCAL_SRC_FILES)) @@ -24,17 +24,17 @@ LOCAL_C_INCLUDES := ../src \ ../src/packets \ ../src/items \ ../src/blocks \ - ../tolua++/src/lib \ - ../lua/src \ - ../zlib-1.2.7 \ - ../iniFile \ - ../tolua++/include \ - ../jsoncpp/include \ - ../jsoncpp/src/lib_json \ - ../expat/ \ - ../md5/ \ - ../sqlite/ \ - ../luaexpat/ \ + ../lib/tolua++/src/lib \ + ../lib/lua/src \ + ../lib/zlib-1.2.7 \ + ../lib/iniFile \ + ../lib/tolua++/include \ + ../lib/jsoncpp/include \ + ../lib/jsoncpp/src/lib_json \ + ../lib/expat/ \ + ../lib/md5/ \ + ../lib/sqlite/ \ + ../lib/luaexpat/ \ .. \ -- cgit v1.2.3 From 736c7950a2b56d2f5296b4cc3695857dced65d51 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 29 Mar 2014 13:11:49 +0100 Subject: Add "a_RelY < cChunkDef::Height" to BlockBigFlower --- src/Blocks/BlockBigFlower.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h index 194a79a67..98d6502ab 100644 --- a/src/Blocks/BlockBigFlower.h +++ b/src/Blocks/BlockBigFlower.h @@ -84,6 +84,7 @@ public: return ( a_RelY > 0 && a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR + && a_RelY < cChunkDef::Height ); } -- cgit v1.2.3 From 515e4bdb13de8fc749fb3f0910beb18974895d6c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 29 Mar 2014 13:18:26 +0000 Subject: Compare for inequality in FACE_NONE checks --- src/ClientHandle.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 27c6b1226..37672b7f0 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -933,7 +933,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType); BlockHandler->OnCancelRightClick(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); - if (a_BlockFace > BLOCK_FACE_NONE) + if (a_BlockFace != BLOCK_FACE_NONE) { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); @@ -962,7 +962,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e ); // Let's send the current world block to the client, so that it can immediately "let the user know" that they haven't placed the block - if (a_BlockFace > BLOCK_FACE_NONE) + if (a_BlockFace != BLOCK_FACE_NONE) { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); @@ -990,7 +990,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Equipped.m_ItemType); - if (ItemHandler->IsPlaceable() && (a_BlockFace > BLOCK_FACE_NONE)) + if (ItemHandler->IsPlaceable() && (a_BlockFace != BLOCK_FACE_NONE)) { HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); } -- cgit v1.2.3 From 4492bd58f1dc93e5c5d6c1b9ff64d7ed44accee3 Mon Sep 17 00:00:00 2001 From: narroo Date: Sat, 29 Mar 2014 10:00:44 -0400 Subject: Added in MetaMirrorXY and MetaMirrorYZ to cBlockSignHandler. --- src/Blocks/BlockSign.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Blocks/BlockSign.h b/src/Blocks/BlockSign.h index 24346b930..6c0becfd6 100644 --- a/src/Blocks/BlockSign.h +++ b/src/Blocks/BlockSign.h @@ -83,6 +83,25 @@ public: { return (--a_Meta) & 0x0F; } + + virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override + { + // Mirrors signs over the XY plane (North-South Mirroring) + + // There are 16 meta values which correspond to different directions. + // These values are equated to angles on a circle; 0x08 = 180 degrees. + return (a_Meta < 0x08) ? 0x08 + a_Meta : 0x08 - a_Meta; + } + + + virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override + { + // Mirrors signs over the YZ plane (East-West Mirroring) + + // There are 16 meta values which correspond to different directions. + // These values are equated to angles on a circle; 0x10 = 360 degrees. + return 0x10 - a_Meta; + } } ; -- cgit v1.2.3 From 339d55511127981335193d07037719a4b26c4600 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 29 Mar 2014 15:26:41 +0100 Subject: Added HOOK_PROJECTILE_HIT_ENTITY --- src/Bindings/Plugin.h | 1 + src/Bindings/PluginLua.cpp | 20 ++++++++++++++++++++ src/Bindings/PluginLua.h | 1 + src/Bindings/PluginManager.cpp | 21 +++++++++++++++++++++ src/Bindings/PluginManager.h | 5 +++++ src/Entities/ProjectileEntity.cpp | 6 ++++++ 6 files changed, 54 insertions(+) diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 057fa0304..75b04d12f 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -90,6 +90,7 @@ public: virtual bool OnPluginsLoaded (void) = 0; virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0; virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0; + virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) = 0; virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) = 0; virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) = 0; virtual bool OnSpawningEntity (cWorld & a_World, cEntity & a_Entity) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 4f0e13f12..d4e4b3ee8 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -1108,6 +1108,26 @@ bool cPluginLua::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a +bool cPluginLua::OnProjectileHitEntity(cProjectileEntity & a_Projectile, cEntity & a_HitEntity) +{ + cCSLock Lock(m_CriticalSection); + bool res = false; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PROJECTILE_HIT_ENTITY]; + for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) + { + m_LuaState.Call((int)(**itr), &a_Projectile, &a_HitEntity, cLuaState::Return, res); + if (res) + { + return true; + } + } + return false; +} + + + + + bool cPluginLua::OnSpawnedEntity(cWorld & a_World, cEntity & a_Entity) { cCSLock Lock(m_CriticalSection); diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index f51056186..1533b1a66 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -113,6 +113,7 @@ public: virtual bool OnPluginsLoaded (void) override; virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; + virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) override; virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) override; virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) override; virtual bool OnSpawningEntity (cWorld & a_World, cEntity & a_Entity) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 7d346c522..aa2c09a3d 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -1154,6 +1154,27 @@ bool cPluginManager::CallHookPreCrafting(const cPlayer * a_Player, const cCrafti +bool cPluginManager::CallHookProjectileHitEntity(cProjectileEntity & a_Projectile, cEntity & a_HitEntity) +{ + HookMap::iterator Plugins = m_Hooks.find(HOOK_PROJECTILE_HIT_ENTITY); + if (Plugins == m_Hooks.end()) + { + return false; + } + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnProjectileHitEntity(a_Projectile, a_HitEntity)) + { + return true; + } + } + return false; +} + + + + + bool cPluginManager::CallHookSpawnedEntity(cWorld & a_World, cEntity & a_Entity) { HookMap::iterator Plugins = m_Hooks.find(HOOK_SPAWNED_ENTITY); diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 7895be959..c5071ee83 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -18,6 +18,9 @@ class cChunkDesc; // fwd: Entities/Entity.h class cEntity; +// fwd: Entities/ProjectileEntity.h +class cProjectileEntity; + // fwd: Mobs/Monster.h class cMonster; @@ -102,6 +105,7 @@ public: // tolua_export HOOK_PLUGINS_LOADED, HOOK_POST_CRAFTING, HOOK_PRE_CRAFTING, + HOOK_PROJECTILE_HIT_ENTITY, HOOK_SPAWNED_ENTITY, HOOK_SPAWNED_MONSTER, HOOK_SPAWNING_ENTITY, @@ -201,6 +205,7 @@ public: // tolua_export bool CallHookPluginsLoaded (void); bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); + bool CallHookProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity); bool CallHookSpawnedEntity (cWorld & a_World, cEntity & a_Entity); bool CallHookSpawnedMonster (cWorld & a_World, cMonster & a_Monster); bool CallHookSpawningEntity (cWorld & a_World, cEntity & a_Entity); diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index f4ab825f2..bc359e1da 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -4,6 +4,7 @@ // Implements the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types #include "Globals.h" +#include "../Bindings/PluginManager.h" #include "ProjectileEntity.h" #include "../ClientHandle.h" #include "Player.h" @@ -148,6 +149,11 @@ public: // TODO: Some entities don't interact with the projectiles (pickups, falling blocks) // TODO: Allow plugins to interfere about which entities can be hit + if (cPluginManager::Get()->CallHookProjectileHitEntity(*m_Projectile, *a_Entity)) + { + // A plugin disagreed. + return false; + } if (LineCoeff < m_MinCoeff) { -- cgit v1.2.3 From a6ef40cb6efa1b8da549c81c7e1137d523240c17 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 29 Mar 2014 15:43:03 +0100 Subject: Fixed error when the hook gets called. --- src/Bindings/LuaState.cpp | 12 ++++++++++++ src/Bindings/LuaState.h | 2 ++ src/Entities/ProjectileEntity.cpp | 1 - 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 47380b8a7..13eb17f7d 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -479,6 +479,18 @@ void cLuaState::Push(cEntity * a_Entity) +void cLuaState::Push(cProjectileEntity * a_ProjectileEntity) +{ + ASSERT(IsValid()); + + tolua_pushusertype(m_LuaState, a_ProjectileEntity, "cProjectileEntity"); + m_NumCurrentFunctionArgs += 1; +} + + + + + void cLuaState::Push(cMonster * a_Monster) { ASSERT(IsValid()); diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index f0047b362..b9ca2f29b 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -38,6 +38,7 @@ extern "C" class cWorld; class cPlayer; class cEntity; +class cProjectileEntity; class cMonster; class cItem; class cItems; @@ -183,6 +184,7 @@ public: void Push(cPlayer * a_Player); void Push(const cPlayer * a_Player); void Push(cEntity * a_Entity); + void Push(cProjectileEntity * a_ProjectileEntity); void Push(cMonster * a_Monster); void Push(cItem * a_Item); void Push(cItems * a_Items); diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index bc359e1da..07cb34f35 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -148,7 +148,6 @@ public: } // TODO: Some entities don't interact with the projectiles (pickups, falling blocks) - // TODO: Allow plugins to interfere about which entities can be hit if (cPluginManager::Get()->CallHookProjectileHitEntity(*m_Projectile, *a_Entity)) { // A plugin disagreed. -- cgit v1.2.3 From ec4638a228edcf4c745088838e972ea07edc7cba Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 29 Mar 2014 16:00:45 +0100 Subject: Added HOOK_PROJECTILE_HIT_BLOCK. --- src/Bindings/Plugin.h | 1 + src/Bindings/PluginLua.cpp | 20 ++++++++++++++++++++ src/Bindings/PluginLua.h | 1 + src/Bindings/PluginManager.cpp | 21 +++++++++++++++++++++ src/Bindings/PluginManager.h | 2 ++ src/Entities/ProjectileEntity.cpp | 5 +++++ 6 files changed, 50 insertions(+) diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 75b04d12f..df0bd4dcc 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -90,6 +90,7 @@ public: virtual bool OnPluginsLoaded (void) = 0; virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0; virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0; + virtual bool OnProjectileHitBlock (cProjectileEntity & a_Projectile) = 0; virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) = 0; virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) = 0; virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index d4e4b3ee8..7e69e0f4b 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -1108,6 +1108,26 @@ bool cPluginLua::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a +bool cPluginLua::OnProjectileHitBlock(cProjectileEntity & a_Projectile) +{ + cCSLock Lock(m_CriticalSection); + bool res = false; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PROJECTILE_HIT_BLOCK]; + for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) + { + m_LuaState.Call((int)(**itr), &a_Projectile, cLuaState::Return, res); + if (res) + { + return true; + } + } + return false; +} + + + + + bool cPluginLua::OnProjectileHitEntity(cProjectileEntity & a_Projectile, cEntity & a_HitEntity) { cCSLock Lock(m_CriticalSection); diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index 1533b1a66..59542d23a 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -113,6 +113,7 @@ public: virtual bool OnPluginsLoaded (void) override; virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; + virtual bool OnProjectileHitBlock (cProjectileEntity & a_Projectile) override; virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) override; virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) override; virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index aa2c09a3d..6a5356c0b 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -1154,6 +1154,27 @@ bool cPluginManager::CallHookPreCrafting(const cPlayer * a_Player, const cCrafti +bool cPluginManager::CallHookProjectileHitBlock(cProjectileEntity & a_Projectile) +{ + HookMap::iterator Plugins = m_Hooks.find(HOOK_PROJECTILE_HIT_BLOCK); + if (Plugins == m_Hooks.end()) + { + return false; + } + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnProjectileHitBlock(a_Projectile)) + { + return true; + } + } + return false; +} + + + + + bool cPluginManager::CallHookProjectileHitEntity(cProjectileEntity & a_Projectile, cEntity & a_HitEntity) { HookMap::iterator Plugins = m_Hooks.find(HOOK_PROJECTILE_HIT_ENTITY); diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index c5071ee83..512bc1351 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -105,6 +105,7 @@ public: // tolua_export HOOK_PLUGINS_LOADED, HOOK_POST_CRAFTING, HOOK_PRE_CRAFTING, + HOOK_PROJECTILE_HIT_BLOCK, HOOK_PROJECTILE_HIT_ENTITY, HOOK_SPAWNED_ENTITY, HOOK_SPAWNED_MONSTER, @@ -205,6 +206,7 @@ public: // tolua_export bool CallHookPluginsLoaded (void); bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); + bool CallHookProjectileHitBlock (cProjectileEntity & a_Projectile); bool CallHookProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity); bool CallHookSpawnedEntity (cWorld & a_World, cEntity & a_Entity); bool CallHookSpawnedMonster (cWorld & a_World, cMonster & a_Monster); diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 07cb34f35..b724c9c55 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -67,6 +67,11 @@ protected: eBlockFace Face; if (bb.CalcLineIntersection(Line1, Line2, LineCoeff, Face)) { + if (cPluginManager::Get()->CallHookProjectileHitBlock(*m_Projectile)) + { + return true; + } + Vector3d Intersection = Line1 + m_Projectile->GetSpeed() * LineCoeff; m_Projectile->OnHitSolidBlock(Intersection, Face); return true; -- cgit v1.2.3 From 379d403443e5ecf3e66cf151391f5a8c4bd4d5c6 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 29 Mar 2014 16:08:39 +0100 Subject: Documented both hooks. --- .../Plugins/APIDump/Hooks/OnProjectileHitBlock.lua | 24 +++++++++++++++++++++ .../APIDump/Hooks/OnProjectileHitEntity.lua | 25 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 MCServer/Plugins/APIDump/Hooks/OnProjectileHitBlock.lua create mode 100644 MCServer/Plugins/APIDump/Hooks/OnProjectileHitEntity.lua diff --git a/MCServer/Plugins/APIDump/Hooks/OnProjectileHitBlock.lua b/MCServer/Plugins/APIDump/Hooks/OnProjectileHitBlock.lua new file mode 100644 index 000000000..1588d420c --- /dev/null +++ b/MCServer/Plugins/APIDump/Hooks/OnProjectileHitBlock.lua @@ -0,0 +1,24 @@ +return +{ + HOOK_PROJECTILE_HIT_BLOCK = + { + CalledWhen = "A projectile hits a solid block.", + DefaultFnName = "OnProjectileHitBlock", -- also used as pagename + Desc = [[ + This hook is called when a {{cProjectileEntity|projectile}} hits a solid block.. + ]], + Params = + { + { Name = "ProjectileEntity", Type = "{{cProjectileEntity}}", Notes = "The projectile that hit an entity." }, + }, + Returns = [[ + If the function returns false or no value, the next plugin's callback is called. If the function + returns true, no other callback is called for this event and the projectile flies through block.. + ]], + }, -- HOOK_PROJECTILE_HIT_BLOCK +} + + + + + diff --git a/MCServer/Plugins/APIDump/Hooks/OnProjectileHitEntity.lua b/MCServer/Plugins/APIDump/Hooks/OnProjectileHitEntity.lua new file mode 100644 index 000000000..dd949fb46 --- /dev/null +++ b/MCServer/Plugins/APIDump/Hooks/OnProjectileHitEntity.lua @@ -0,0 +1,25 @@ +return +{ + HOOK_PROJECTILE_HIT_ENTITY = + { + CalledWhen = "A projectile hits another entity.", + DefaultFnName = "OnProjectileHitEntity", -- also used as pagename + Desc = [[ + This hook is called when a {{cProjectileEntity|projectile}} hits another entity. + ]], + Params = + { + { Name = "ProjectileEntity", Type = "{{cProjectileEntity}}", Notes = "The projectile that hit an entity." }, + { Name = "Entity", Type = "{{cEntity}}", Notes = "The entity wich was hit." }, + }, + Returns = [[ + If the function returns false or no value, the next plugin's callback is called. If the function + returns true, no other callback is called for this event and the projectile flies through the entity. + ]], + }, -- HOOK_PROJECTILE_HIT_ENTITY +} + + + + + -- cgit v1.2.3 From 98a12127ceaa0834bfea66fa6f9e381b1f8f4357 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 29 Mar 2014 17:05:24 +0100 Subject: Fixed the OnProjectileHitBlock hook not stopping projectiles. --- src/Entities/ProjectileEntity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index b724c9c55..a9735a53c 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -69,7 +69,7 @@ protected: { if (cPluginManager::Get()->CallHookProjectileHitBlock(*m_Projectile)) { - return true; + return false; } Vector3d Intersection = Line1 + m_Projectile->GetSpeed() * LineCoeff; -- cgit v1.2.3 From 782c111b815b3a49a340e1f1133e1c15ac76e551 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 29 Mar 2014 22:29:34 +0100 Subject: Renamed lua dll for tolua++.exe. Fixes #843. --- src/Bindings/lua5.1.dll | Bin 167424 -> 0 bytes src/Bindings/lua51.dll | Bin 0 -> 167424 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/Bindings/lua5.1.dll create mode 100644 src/Bindings/lua51.dll diff --git a/src/Bindings/lua5.1.dll b/src/Bindings/lua5.1.dll deleted file mode 100644 index 515cf8b30..000000000 Binary files a/src/Bindings/lua5.1.dll and /dev/null differ diff --git a/src/Bindings/lua51.dll b/src/Bindings/lua51.dll new file mode 100644 index 000000000..515cf8b30 Binary files /dev/null and b/src/Bindings/lua51.dll differ -- cgit v1.2.3 From d64d9145d1d84caaf21a906d5924c3855988fa33 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 29 Mar 2014 22:56:16 +0100 Subject: cPrefab now uses a struct for block type definition in CharMap. As suggested by worktycho in 7b585290fccd3dc074b1f9feef0af754ab3dd632, instead of packing the two values into a single int, they're packed into a struct. Also added a test code for the prefab parsing in SELF_TEST. --- src/Generating/Prefab.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++---- src/Generating/Prefab.h | 9 +++- 2 files changed, 102 insertions(+), 10 deletions(-) diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 1af1faec1..a9e0a839d 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -15,6 +15,92 @@ uses a prefabricate in a cBlockArea for drawing itself. +#ifdef SELF_TEST + +// Create one static prefab to test the parser: +static const cPrefab::sDef g_TestPrefabDef = +{ + // Size: + 7, 6, 7, // SizeX = 7, SizeY = 6, SizeZ = 7 + + // Block definitions: + ".: 0: 0\n" /* 0 */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */, + + // Block data: + // Level 1 + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + + // Level 2 + "aa...aa" + "a.....a" + "......." + "......." + "......." + "a.....a" + "aa...aa" + + // Level 3 + "aa...aa" + "a.....a" + "......." + "......." + "......." + "a.....a" + "aa...aa" + + // Level 4 + "aa...aa" + "a.....a" + "......." + "......." + "......." + "a.....a" + "aa...aa" + + // Level 5 + "aabbbaa" + "a.....a" + "b.....b" + "b.....b" + "b.....b" + "a.....a" + "aabbbaa" + + // Level 6 + "aaaaaaa" + "a.....a" + "a.....a" + "a.....a" + "a.....a" + "a.....a" + "aaaaaaa", + + // Connections: + "0: 0, 3, 2: 4\n" + "0: 2, 3, 0: 2\n", + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msImprint +}; + +static cPrefab g_TestPrefab(g_TestPrefabDef); +#endif + + + + + cPrefab::cPrefab(const cPrefab::sDef & a_Def) : m_Size(a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ), m_HitBox(0, 0, 0, a_Def.m_SizeX - 1, a_Def.m_SizeY - 1, a_Def.m_SizeZ - 1), @@ -89,7 +175,8 @@ void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef) // Initialize the charmap to all-invalid values: for (size_t i = 0; i < ARRAYCOUNT(a_CharMapOut); i++) { - a_CharMapOut[i] = -1; + a_CharMapOut[i].m_BlockType = 0; + a_CharMapOut[i].m_BlockMeta = 16; // Mark unassigned entries with a meta that is impossible otherwise } // Process the lines in the definition: @@ -104,15 +191,15 @@ void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef) continue; } unsigned char Src = (unsigned char)CharDef[0][0]; - BLOCKTYPE BlockType = (BLOCKTYPE)atoi(CharDef[1].c_str()); + ASSERT(a_CharMapOut[Src].m_BlockMeta == 16); // This letter has not been assigned yet? + a_CharMapOut[Src].m_BlockType = (BLOCKTYPE)atoi(CharDef[1].c_str()); NIBBLETYPE BlockMeta = 0; if ((NumElements >= 3) && !CharDef[2].empty()) { BlockMeta = (NIBBLETYPE)atoi(CharDef[2].c_str()); ASSERT((BlockMeta >= 0) && (BlockMeta <= 15)); } - ASSERT(a_CharMapOut[Src] == -1); // Any duplicates letter-wise? - a_CharMapOut[Src] = (BlockType << 4) | BlockMeta; + a_CharMapOut[Src].m_BlockMeta = BlockMeta; } // for itr - Lines[] } @@ -130,11 +217,9 @@ void cPrefab::ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockIma const unsigned char * BlockImage = (const unsigned char *)a_BlockImage + y * m_Size.x * m_Size.z + z * m_Size.x; for (int x = 0; x < m_Size.x; x++) { - int MappedValue = a_CharMap[BlockImage[x]]; - ASSERT(MappedValue != -1); // Using a letter not defined in the CharMap? - BLOCKTYPE BlockType = MappedValue >> 4; - NIBBLETYPE BlockMeta = MappedValue & 0x0f; - m_BlockArea[0].SetRelBlockTypeMeta(x, y, z, BlockType, BlockMeta); + const sBlockTypeDef & MappedValue = a_CharMap[BlockImage[x]]; + ASSERT(MappedValue.m_BlockMeta != 16); // Using a letter not defined in the CharMap? + m_BlockArea[0].SetRelBlockTypeMeta(x, y, z, MappedValue.m_BlockType, MappedValue.m_BlockMeta); } } } diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index 0b254c03b..04c4f09da 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -53,8 +53,15 @@ public: bool HasConnectorType(int a_ConnectorType) const; protected: + /** Packs complete definition of a single block, for per-letter assignment. */ + struct sBlockTypeDef + { + BLOCKTYPE m_BlockType; + NIBBLETYPE m_BlockMeta; + }; + /** Maps letters in the sDef::m_Image onto a number, BlockType * 16 | BlockMeta */ - typedef int CharMap[256]; + typedef sBlockTypeDef CharMap[256]; /** The cBlockArea that contains the block definitions for the prefab. -- cgit v1.2.3 From 597bdd9f8010c455c1c4ce83dc2ed5e227666a1c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 30 Mar 2014 00:12:19 +0100 Subject: NetherForts have a minimum number of pieces. The fort will generate a different image if it has less than the minimum; the max depth affects the minimum number of pieces. --- src/Generating/NetherFortGen.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Generating/NetherFortGen.cpp b/src/Generating/NetherFortGen.cpp index d111c7cee..09c992e22 100644 --- a/src/Generating/NetherFortGen.cpp +++ b/src/Generating/NetherFortGen.cpp @@ -41,8 +41,11 @@ public: int BlockY = 64; // Generate pieces: - cBFSPieceGenerator pg(m_ParentGen, a_Seed); - pg.PlacePieces(a_BlockX, BlockY, a_BlockZ, a_MaxDepth, m_Pieces); + for (int i = 0; m_Pieces.size() < (size_t)(a_MaxDepth * a_MaxDepth / 16 + a_MaxDepth); i++) + { + cBFSPieceGenerator pg(m_ParentGen, a_Seed + 1); + pg.PlacePieces(a_BlockX, BlockY, a_BlockZ, a_MaxDepth, m_Pieces); + } } -- cgit v1.2.3 From 475fc4b1ab76955dc1e3625e75549dc86f0ca860 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 30 Mar 2014 00:12:54 +0100 Subject: Fixed chest rotator. --- src/Blocks/BlockChest.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 30588d8fc..7abf01301 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -11,11 +11,11 @@ class cBlockChestHandler : - public cMetaRotater + public cMetaRotater { public: cBlockChestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } -- cgit v1.2.3 From 6b29edc1582940a08c0d28822a4ea4c95c55d2e0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 30 Mar 2014 00:20:06 +0100 Subject: Re-fixed nether fort piece count check. --- src/Generating/NetherFortGen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generating/NetherFortGen.cpp b/src/Generating/NetherFortGen.cpp index 09c992e22..02779a8a3 100644 --- a/src/Generating/NetherFortGen.cpp +++ b/src/Generating/NetherFortGen.cpp @@ -41,9 +41,9 @@ public: int BlockY = 64; // Generate pieces: - for (int i = 0; m_Pieces.size() < (size_t)(a_MaxDepth * a_MaxDepth / 16 + a_MaxDepth); i++) + for (int i = 0; m_Pieces.size() < (size_t)(a_MaxDepth * a_MaxDepth / 8 + a_MaxDepth); i++) { - cBFSPieceGenerator pg(m_ParentGen, a_Seed + 1); + cBFSPieceGenerator pg(m_ParentGen, a_Seed + i); pg.PlacePieces(a_BlockX, BlockY, a_BlockZ, a_MaxDepth, m_Pieces); } } -- cgit v1.2.3 From 3eb531a8c81fa4df014dc32b1aba42508910b481 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 30 Mar 2014 00:20:28 +0100 Subject: Added asserts for critical data in cPrefab. --- src/Generating/Prefab.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index a9e0a839d..131b6acb2 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -172,6 +172,8 @@ bool cPrefab::HasConnectorType(int a_ConnectorType) const void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef) { + ASSERT(a_CharMapDef != NULL); + // Initialize the charmap to all-invalid values: for (size_t i = 0; i < ARRAYCOUNT(a_CharMapOut); i++) { @@ -231,6 +233,8 @@ void cPrefab::ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockIma void cPrefab::ParseConnectors(const char * a_ConnectorsDef) { + ASSERT(a_ConnectorsDef != NULL); + AStringVector Lines = StringSplitAndTrim(a_ConnectorsDef, "\n"); for (AStringVector::const_iterator itr = Lines.begin(), end = Lines.end(); itr != end; ++itr) { -- cgit v1.2.3 From ceabb372f083c9f45ab1c05154c780c5092961ec Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 30 Mar 2014 00:33:59 +0100 Subject: Added all current NetherFort prefabs. --- src/Generating/Prefabs/NetherFortPrefabs.cpp | 1628 +++++++++++++++++++++++++- 1 file changed, 1586 insertions(+), 42 deletions(-) diff --git a/src/Generating/Prefabs/NetherFortPrefabs.cpp b/src/Generating/Prefabs/NetherFortPrefabs.cpp index 24bde1baf..5e8685e32 100644 --- a/src/Generating/Prefabs/NetherFortPrefabs.cpp +++ b/src/Generating/Prefabs/NetherFortPrefabs.cpp @@ -353,7 +353,7 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = 14, 9, 7, // SizeX = 14, SizeY = 9, SizeZ = 7 // Block definitions: - ".: 0: 0\n" /* 0 */ + ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ "b:114: 5\n" /* netherbrickstairs */ "c: 44:14\n" /* step */ @@ -850,6 +850,200 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = }, // BridgeSegment + // BridgeTee: + // The data has been exported from gallery Nether, area index 39, ID 290 + { + // Size: + 15, 8, 10, // SizeX = 15, SizeY = 8, SizeZ = 10 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:114: 5\n" /* netherbrickstairs */ + "c:114: 4\n" /* netherbrickstairs */ + "d:114: 6\n" /* netherbrickstairs */ + "e: 44:14\n" /* step */ + "f:114: 7\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 1 + "mmmmmmmmmmmmmmm" + "aammmmmmmmmmmaa" + "aammmmmmmmmmmaa" + "aammmmmmmmmmmaa" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + + // Level 2 + "mmmmmmmmmmmmmmm" + "aabmmmmmmmmmcaa" + "aabmmmmmmmmmcaa" + "aabmmmmmmmmmcaa" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmm" + "mmmmmmdddmmmmmm" + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + + // Level 3 + "mmmmmmmmmmmmmmm" + "aaabemmmmmecaaa" + "aaabemmmmmecaaa" + "aaabemmmmmecaaa" + "mmmmmmmmmmmmmmm" + "mmmmmmeeemmmmmm" + "mmmmmmdddmmmmmm" + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + "mmmmmmaaammmmmm" + + // Level 4 + "ddddddddddddddd" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "fffffcaaabfffff" + "mmmmmcaaabmmmmm" + "mmmmmcaaabmmmmm" + "mmmmmcaaabmmmmm" + "mmmmmcaaabmmmmm" + "mmmmmcaaabmmmmm" + + // Level 5 + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + "mmmmmaaaaammmmm" + + // Level 6 + "aaaaaaaaaaaaaaa" + "..............." + "..............." + "..............." + "aaaaaa...aaaaaa" + "mmmmma...ammmmm" + "mmmmma...ammmmm" + "mmmmma...ammmmm" + "mmmmma...ammmmm" + "mmmmma...ammmmm" + + // Level 7 + "mmmmmmmmmmmmmmm" + "..............." + "..............." + "..............." + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + + // Level 8 + "mmmmmmmmmmmmmmm" + "..............." + "..............." + "..............." + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm" + "mmmmmm...mmmmmm", + + // Connections: + "0: 0, 5, 2: 4\n" /* Type 0, BLOCK_FACE_XM */ + "0: 14, 5, 2: 5\n" /* Type 0, BLOCK_FACE_XP */ + "0: 7, 5, 9: 3\n" /* Type 0, BLOCK_FACE_ZP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // BridgeTee + + + // Corridor11: + // The data has been exported from gallery Nether, area index 36, ID 287 + { + // Size: + 11, 6, 5, // SizeX = 11, SizeY = 6, SizeZ = 5 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "c:114: 2\n" /* netherbrickstairs */ + "d:114: 3\n" /* netherbrickstairs */, + + // Block data: + // Level 1 + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaaaaaaaa" + + // Level 2 + "aaaaaaaaaaa" + "..........." + "..........." + "..........." + "aaaaaaaaaaa" + + // Level 3 + "abababababa" + "..........." + "..........." + "..........." + "abababababa" + + // Level 4 + "abababababa" + "..........." + "..........." + "..........." + "abababababa" + + // Level 5 + "abababababa" + "..........." + "..........." + "..........." + "abababababa" + + // Level 6 + "ccccccccccc" + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "ddddddddddd", + + // Connections: + "1: 0, 1, 2: 4\n" /* Type 1, BLOCK_FACE_XM */ + "1: 10, 1, 2: 5\n" /* Type 1, BLOCK_FACE_XP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // Corridor11 + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Corridor13: // The data has been exported from gallery Nether, area index 35, ID 286 @@ -919,6 +1113,221 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = }, // Corridor13 + // CorridorCorner5: + // The data has been exported from gallery Nether, area index 10, ID 40 + { + // Size: + 11, 6, 11, // SizeX = 11, SizeY = 6, SizeZ = 11 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "c:114: 2\n" /* netherbrickstairs */ + "d:114: 0\n" /* netherbrickstairs */ + "e:114: 3\n" /* netherbrickstairs */ + "f:114: 1\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 1 + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaammmmmm" + "aaaaammmmmm" + "aaaaammmmmm" + "aaaaammmmmm" + "aaaaammmmmm" + "aaaaammmmmm" + + // Level 2 + "aaaaaaaaaaa" + "a.........." + "a.........." + "a.........." + "a...aaaaaaa" + "a...ammmmmm" + "a...ammmmmm" + "a...ammmmmm" + "a...ammmmmm" + "a...ammmmmm" + "a...ammmmmm" + + // Level 3 + "abababababa" + "b.........." + "a.........." + "b.........." + "a...abababa" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + + // Level 4 + "abababababa" + "b.........." + "a.........." + "b.........." + "a...abababa" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + + // Level 5 + "abababababa" + "b.........." + "a.........." + "b.........." + "a...abababa" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + + // Level 6 + "ccccccccccc" + "daaaaaaaaaa" + "daaaaaaaaaa" + "daaaaaaaaaa" + "daaaeeeeeee" + "daaafmmmmmm" + "daaafmmmmmm" + "daaafmmmmmm" + "daaafmmmmmm" + "daaafmmmmmm" + "daaafmmmmmm", + + // Connections: + "1: 10, 1, 2: 5\n" /* Type 1, BLOCK_FACE_XP */ + "1: 2, 1, 10: 3\n" /* Type 1, BLOCK_FACE_ZP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // CorridorCorner5 + + + // CorridorCorner5: + // The data has been exported from gallery Nether, area index 10, ID 40 + { + // Size: + 11, 6, 11, // SizeX = 11, SizeY = 6, SizeZ = 11 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "c:114: 2\n" /* netherbrickstairs */ + "d:114: 0\n" /* netherbrickstairs */ + "e:114: 3\n" /* netherbrickstairs */ + "f:114: 1\n" /* netherbrickstairs */ + "g: 54: 5\n" /* chest */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 1 + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaaaaaaaa" + "aaaaammmmmm" + "aaaaammmmmm" + "aaaaammmmmm" + "aaaaammmmmm" + "aaaaammmmmm" + "aaaaammmmmm" + + // Level 2 + "aaaaaaaaaaa" + "ag........." + "a.........." + "a.........." + "a...aaaaaaa" + "a...ammmmmm" + "a...ammmmmm" + "a...ammmmmm" + "a...ammmmmm" + "a...ammmmmm" + "a...ammmmmm" + + // Level 3 + "abababababa" + "b.........." + "a.........." + "b.........." + "a...abababa" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + + // Level 4 + "abababababa" + "b.........." + "a.........." + "b.........." + "a...abababa" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + + // Level 5 + "abababababa" + "b.........." + "a.........." + "b.........." + "a...abababa" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + "b...bmmmmmm" + "a...ammmmmm" + + // Level 6 + "ccccccccccc" + "daaaaaaaaaa" + "daaaaaaaaaa" + "daaaaaaaaaa" + "daaaeeeeeee" + "daaafmmmmmm" + "daaafmmmmmm" + "daaafmmmmmm" + "daaafmmmmmm" + "daaafmmmmmm" + "daaafmmmmmm", + + // Connections: + "1: 10, 1, 2: 5\n" /* Type 1, BLOCK_FACE_XP */ + "1: 2, 1, 10: 3\n" /* Type 1, BLOCK_FACE_ZP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // CorridorCorner5Chest + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // CorridorStairs: // The data has been exported from gallery Nether, area index 12, ID 42 @@ -927,7 +1336,7 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = 9, 13, 5, // SizeX = 9, SizeY = 13, SizeZ = 5 // Block definitions: - ".: 0: 0\n" /* 0 */ + ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ "b:114: 0\n" /* netherbrickstairs */ "c:113: 0\n" /* netherbrickfence */ @@ -1037,57 +1446,1192 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = // Merge strategy: cBlockArea::msSpongePrint, }, // CorridorStairs -} ; // g_NetherFortPrefabs1 - - - -const cPrefab::sDef g_NetherFortStartingPrefabs1[] = -{ - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // CentralRoom: - // The data has been exported from gallery Nether, area index 22, ID 164 + // LavaStaircase: + // The data has been exported from gallery Nether, area index 28, ID 278 { // Size: - 13, 9, 13, // SizeX = 13, SizeY = 9, SizeZ = 13 + 15, 11, 15, // SizeX = 15, SizeY = 11, SizeZ = 15 // Block definitions: + ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ - "b: 0: 0\n" /* air */ - "c: 10: 0\n" /* lava */ - "d:113: 0\n" /* netherbrickfence */, + "b:113: 0\n" /* netherbrickfence */ + "c: 11: 0\n" /* lava */, // Block data: // Level 1 - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" // Level 2 - "aaaaabbbaaaaa" - "aaaaabbbaaaaa" - "aabbbbbbbbbaa" - "aabbbbbbbbbaa" - "aabbbbbbbbbaa" - "aabbbaaabbbaa" - "aabbbacabbbaa" - "aabbbaaabbbaa" - "aabbbbbbbbbaa" - "aabbbbbbbbbaa" - "aabbbbbbbbbaa" - "aaaaabbbaaaaa" - "aaaaabbbaaaaa" + "aaaaaaaa...aaaa" + "aaaaa.........a" + "aaaaa.........a" + "aaaaab........a" + "accca...aaaa..a" + "accca...acca..a" + "acccaaaaacca..a" + "acccccccccca..a" + "acccaaaaacca..a" + "accca...acca..a" + "accca...aaaa..a" + "aaaaab........a" + "aaaaa.........a" + "aaaaa.........a" + "aaaaaaaa...aaaa" + + // Level 3 + "aaaaaaaa...aaaa" + "aaaa..........a" + "aaaa..........a" + "aaaabb........a" + "aaaa..........a" + "a.............a" + "a.............a" + "a.............a" + "a.............a" + "a.............a" + "aaaa..........a" + "aaaabb........a" + "aaaa..........a" + "aaaa..........a" + "aaaaaaaa...aaaa" + + // Level 4 + "aaaaaaaa...aaaa" + "a.............a" + "a.............a" + "a..bb.........a" + "aaaa..........a" + "aaaa..........a" + "a.............a" + "a.............a" + "a.............a" + "aaaa..........a" + "aaaa..........a" + "a..bb.........a" + "a.............a" + "a.............a" + "aaaaaaaa...aaaa" + + // Level 5 + "aaaaaaaabbbaaaa" + "a.............a" + "a.............a" + "a..b..........a" + "a..b..........a" + "aaaa..........a" + "aaaa..........a" + "a.............a" + "aaaa..........a" + "aaaa..........a" + "a..b..........a" + "a..b..........a" + "a.............a" + "a.............a" + "aaaaaaaabbbaaaa" + + // Level 6 + "aaaaaaaaaaaaaaa" + "a.............a" + "a.............a" + "a.............a" + "a..b..........a" + "a..b..........a" + "aaaa..........a" + "aaaa..........a" + "aaaa..........a" + "a..b..........a" + "a..b..........a" + "a.............a" + "a.............a" + "a.............a" + "aaaaaaaaaaaaaaa" + + // Level 7 + "aaaaaaaaaaaaaaa" + "a.............a" + "a.............a" + "a.............a" + "a.............a" + "a..b..........a" + "...b..........a" + "...b..........a" + "...b..........a" + "a..b..........a" + "a.............a" + "a.............a" + "a.............a" + "a.............a" + "aaaaaaaaaaaaaaa" + + // Level 8 + "aababababababaa" + "a.............a" + "b.............b" + "a.............a" + "b.............b" + "a.............a" + "..............b" + "..............a" + "..............b" + "a.............a" + "b.............b" + "a.............a" + "b.............b" + "a.............a" + "aababababababaa" + + // Level 9 + "aababababababaa" + "a.............a" + "b.............b" + "a.............a" + "b.............b" + "a.............a" + "..............b" + "..............a" + "..............b" + "a.............a" + "b.............b" + "a.............a" + "b.............b" + "a.............a" + "aababababababaa" + + // Level 10 + "aababababababaa" + "a.............a" + "b.............b" + "a.............a" + "b.............b" + "a.............a" + "..............b" + "..............a" + "..............b" + "a.............a" + "b.............b" + "a.............a" + "b.............b" + "a.............a" + "aababababababaa" + + // Level 11 + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa", + + // Connections: + "1: 0, 6, 7: 4\n" /* Type 1, BLOCK_FACE_XM */ + "0: 9, 1, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ + "0: 9, 1, 14: 3\n" /* Type 0, BLOCK_FACE_ZP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // LavaStaircase + + + // LavaStaircaseBig: + // The data has been exported from gallery Nether, area index 31, ID 282 + { + // Size: + 12, 15, 15, // SizeX = 12, SizeY = 15, SizeZ = 15 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b: 10: 0\n" /* lava */ + "c:113: 0\n" /* netherbrickfence */, + + // Block data: + // Level 1 + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + + // Level 2 + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "abbbbbaaaaaa" + "abbbbbbaaaaa" + "abbbbbba...." + "abbbbbba...." + "abbbbbba...." + "abbbbbbaaaaa" + "abbbbb.aaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + + // Level 3 + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "abbbbbaaaaaa" + "abbbbbba...a" + "abbbbbba...." + "abbbbbba...." + "abbbbbba...." + "abbbbbba...a" + "abbbbb.aaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + + // Level 4 + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "abbbbbaa...a" + "abbbbbba...a" + "abbbbbba...." + "abbbbbba...." + "abbbbbba...." + "abbbbbba...a" + "abbbbbaa...a" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + + // Level 5 + "aaaaaaaaaaaa" + "aaaaa......a" + "aaaaa......a" + "aaaaacc....a" + "a.....cc...a" + "a......c...a" + "a......c...." + "a......c...." + "a......c...." + "a......c...a" + "a.....cc...a" + "aaaaacc....a" + "aaaaa......a" + "aaaaa......a" + "aaaaaaaaaaaa" + + // Level 6 + "aaaaaaaaaaaa" + "aaaa.......a" + "aaaa.......a" + "aaaacc.....a" + "aaaa.......a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "aaaa.......a" + "aaaacc.....a" + "aaaa.......a" + "aaaa.......a" + "aaaaaaaaaaaa" + + // Level 7 + "aaaaaaaaaaaa" + "a..........a" + "a..........a" + "a..cc......a" + "aaaa.......a" + "aaaa.......a" + "a..........a" + "a..........a" + "a..........a" + "aaaa.......a" + "aaaa.......a" + "a..cc......a" + "a..........a" + "a..........a" + "aaaaaaaaaaaa" + + // Level 8 + "aaaaaaaaaaaa" + "a..........a" + "a..........a" + "a..c.......a" + "a..c.......a" + "aaaa.......a" + "aaaa.......a" + "a..........a" + "aaaa.......a" + "aaaa.......a" + "a..c.......a" + "a..c.......a" + "a..........a" + "a..........a" + "aaaaaaaaaaaa" + + // Level 9 + "aaaaaaaaaaaa" + "a..........a" + "a..........a" + "a..........a" + "a..c.......a" + "a..c.......a" + "aaaa.......a" + "aaaa.......a" + "aaaa.......a" + "a..c.......a" + "a..c.......a" + "a..........a" + "a..........a" + "a..........a" + "aaaaaaaaaaaa" + + // Level 10 + "aaaaaaaaaaaa" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "a..c.......a" + "...c.......a" + "...c.......a" + "...c.......a" + "a..c.......a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "aaaaaaaaaaaa" + + // Level 11 + "aaaaaaaaaaaa" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "...........a" + "...........a" + "...........a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "aaaaaaaaaaaa" + + // Level 12 + "aaaaaaaaaaaa" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "...........a" + "...........a" + "...........a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "aaaaaaaaaaaa" + + // Level 13 + "aaaaaaaaaaaa" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "...........a" + "...........a" + "...........a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "a..........a" + "aaaaaaaaaaaa" + + // Level 14 + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + "aaaaaaaaaaaa" + + // Level 15 + "aaaaaaaaaaaa" + "abbbbbbbbbba" + "abbbbbbbbbba" + "abbbbbbbbbba" + "abbbbbbbbbba" + "abbbbbbbbbba" + "abbbbbbbbbba" + "abbbbbbbbbba" + "abbbbbbbbbba" + "abbbbbbbbbba" + "abbbbbbbbbba" + "abbbbbbbbbba" + "abbbbbbbbbba" + "abbbbbbbbbba" + "aaaaaaaaaaaa", + + // Connections: + "1: 0, 9, 7: 4\n" /* Type 1, BLOCK_FACE_XM */ + "1: 11, 1, 7: 5\n" /* Type 1, BLOCK_FACE_XP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // LavaStaircaseBig + + + // MidStaircase: + // The data has been exported from gallery Nether, area index 23, ID 165 + { + // Size: + 13, 8, 13, // SizeX = 13, SizeY = 8, SizeZ = 13 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b: 88: 0\n" /* soulsand */ + "c:115: 7\n" /* netherwartblock */ + "d:114: 3\n" /* netherbrickstairs */ + "e:114: 0\n" /* netherbrickstairs */ + "f:114: 1\n" /* netherbrickstairs */ + "g:114: 2\n" /* netherbrickstairs */ + "h: 10: 0\n" /* lava */ + "i:113: 0\n" /* netherbrickfence */, + + // Block data: + // Level 1 + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaabbbbbaaaa" + "aaaabbbbbaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaabbbbbaaaa" + "aaaabbbbbaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 2 + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaacccccaaaa" + "addecccccfdda" + "...eaaaaad..." + "...eaaaaa...." + "...eaaaaag..." + "agggcccccfgga" + "aaaacccccaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 3 + "aaaaaaaaaaaaa" + "aha.......aha" + "aaa.......aaa" + "a...........a" + "a...........a" + "....eaaaa...." + "....eaaaa...." + "....eaaaa...." + "a...........a" + "a...........a" + "aaa.......aaa" + "aha.......aha" + "aaaaaaaaaaaaa" + + // Level 4 + "aaaiiaaaiiaaa" + "a...........a" + "a...........a" + "a...........a" + "a...........a" + ".....eaaa...." + ".....eaaa...." + ".....eaaa...." + "a...........a" + "a...........a" + "a...........a" + "a...........a" + "aaaiiaaaiiaaa" + + // Level 5 + "aaaiiaaaiiaaa" + "a...........a" + "a...........a" + "a...........a" + "a...........a" + "......eaa...." + "......eaa...." + "......eaa...." + "a...........a" + "a...........a" + "a...........a" + "a...........a" + "aaaiiaaaiiaaa" + + // Level 6 + "aaaaaaaaaaaaa" + "a...........a" + "a...........a" + "a...........a" + "a...........a" + "a......ea...a" + "a......ea...a" + "a......ea...a" + "a...........a" + "a...........a" + "a...........a" + "a...........a" + "aaaaaaaaaaaaa" + + // Level 7 + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaa....eaaaa" + "aaaa....eaaaa" + "aaaa....eaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 8 + "iaiaiaiaiaiai" + "a...........a" + "i...........i" + "a...........a" + "i...........i" + "a............" + "i............" + "a............" + "i...........i" + "a...........a" + "i...........i" + "a...........a" + "iaiaiaiaiaiai", + + // Connections: + "1: 0, 1, 6: 4\n" /* Type 1, BLOCK_FACE_XM */ + "1: 12, 1, 6: 5\n" /* Type 1, BLOCK_FACE_XP */ + "1: 12, 7, 6: 5\n" /* Type 1, BLOCK_FACE_XP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // MidStaircase + + + // StairsToOpen1: + // The data has been exported from gallery Nether, area index 27, ID 277 + { + // Size: + 7, 10, 7, // SizeX = 7, SizeY = 10, SizeZ = 7 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 1 + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + + // Level 2 + "aa...aa" + "a.....a" + "a.....a" + "a.....a" + "a.....a" + "aaaaaaa" + "aaaaaaa" + + // Level 3 + "aa...aa" + "a.....a" + "b.....b" + "a.....a" + "b.....b" + "a.aaaaa" + "aabaaba" + + // Level 4 + "aa...aa" + "a.....a" + "b.....b" + "a.....a" + "b.....b" + "a..aaaa" + "aabaaba" + + // Level 5 + "aabbbaa" + "a.....a" + "b.....b" + "a.....a" + "b.....b" + "a...aaa" + "aabaaba" + + // Level 6 + "aaaaaaa" + "a.....a" + "a.....a" + "a.....a" + "a.....a" + "a....aa" + "aaaaaaa" + + // Level 7 + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "a.....a" + "aaaaaaa" + + // Level 8 + "aaaaaaa" + "a.....a" + "a......" + "a......" + "a......" + "a.....a" + "aaaaaaa" + + // Level 9 + "mmmmmmm" + "m.....m" + "m......" + "m......" + "m......" + "m.....m" + "mmmmmmm" + + // Level 10 + "mmmmmmm" + "m.....m" + "m......" + "m......" + "m......" + "m.....m" + "mmmmmmm", + + // Connections: + "0: 3, 1, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ + "0: 6, 7, 3: 5\n" /* Type 0, BLOCK_FACE_XP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // StairsToOpen1 + + + // StairsToOpen2: + // The data has been exported from gallery Nether, area index 8, ID 35 + { + // Size: + 7, 10, 7, // SizeX = 7, SizeY = 10, SizeZ = 7 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 1 + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + + // Level 2 + "aa...aa" + "a.....a" + "a.....a" + "a.....a" + "a.....a" + "aaaaaaa" + "aaaaaaa" + + // Level 3 + "aa...aa" + "a.....a" + "b.....b" + "a.....a" + "b.....b" + "a.aaaaa" + "aabaaba" + + // Level 4 + "aa...aa" + "a.....a" + "b.....b" + "a.....a" + "b.....b" + "a..aaaa" + "aabaaba" + + // Level 5 + "aabbbaa" + "a.....a" + "b.....b" + "a.....a" + "b.....b" + "a...aaa" + "aabaaba" + + // Level 6 + "aaaaaaa" + "a.....a" + "a.....a" + "a.....a" + "a.....a" + "a....aa" + "aaaaaaa" + + // Level 7 + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "a.....a" + "aaaaaaa" + + // Level 8 + "aaaaaaa" + "a.....a" + "......a" + "......a" + "......a" + "a.....a" + "aaaaaaa" + + // Level 9 + "mmmmmmm" + "m.....m" + "......m" + "......m" + "......m" + "m.....m" + "mmmmmmm" + + // Level 10 + "mmmmmmm" + "m.....m" + "......m" + "......m" + "......m" + "m.....m" + "mmmmmmm", + + // Connections: + "0: 3, 1, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ + "0: 0, 7, 3: 4\n" /* Type 0, BLOCK_FACE_XM */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // StairsToOpen2 + + + // Tee2x4: + // The data has been exported from gallery Nether, area index 40, ID 291 + { + // Size: + 13, 6, 7, // SizeX = 13, SizeY = 6, SizeZ = 7 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "c:114: 0\n" /* netherbrickstairs */ + "d:114: 1\n" /* netherbrickstairs */ + "e:114: 2\n" /* netherbrickstairs */ + "f:114: 3\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 1 + "mmmmaaaaammmm" + "mmmmaaaaammmm" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 2 + "mmmma...ammmm" + "mmmma...ammmm" + "aaaaa...aaaaa" + "............." + "............." + "............." + "aaaaaaaaaaaaa" + + // Level 3 + "mmmma...ammmm" + "mmmmb...bmmmm" + "ababa...ababa" + "............." + "............." + "............." + "ababababababa" + + // Level 4 + "mmmma...ammmm" + "mmmmb...bmmmm" + "ababa...ababa" + "............." + "............." + "............." + "ababababababa" + + // Level 5 + "mmmma...ammmm" + "mmmmb...bmmmm" + "ababa...ababa" + "............." + "............." + "............." + "ababababababa" + + // Level 6 + "mmmmcaaadmmmm" + "mmmmcaaadmmmm" + "eeeecaaadeeee" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "fffffffffffff", + + // Connections: + "1: 0, 1, 4: 4\n" /* Type 1, BLOCK_FACE_XM */ + "1: 6, 1, 0: 2\n" /* Type 1, BLOCK_FACE_ZM */ + "1: 12, 1, 4: 5\n" /* Type 1, BLOCK_FACE_XP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // Tee2x4 + + + // Tee4x4: + // The data has been exported from gallery Nether, area index 41, ID 292 + { + // Size: + 13, 6, 9, // SizeX = 13, SizeY = 6, SizeZ = 9 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "c:114: 0\n" /* netherbrickstairs */ + "d:114: 1\n" /* netherbrickstairs */ + "e:114: 2\n" /* netherbrickstairs */ + "f:114: 3\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 1 + "mmmmaaaaammmm" + "mmmmaaaaammmm" + "mmmmaaaaammmm" + "mmmmaaaaammmm" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 2 + "mmmma...ammmm" + "mmmma...ammmm" + "mmmma...ammmm" + "mmmma...ammmm" + "aaaaa...aaaaa" + "............." + "............." + "............." + "aaaaaaaaaaaaa" + + // Level 3 + "mmmma...ammmm" + "mmmmb...bmmmm" + "mmmma...ammmm" + "mmmmb...bmmmm" + "ababa...ababa" + "............." + "............." + "............." + "ababababababa" + + // Level 4 + "mmmma...ammmm" + "mmmmb...bmmmm" + "mmmma...ammmm" + "mmmmb...bmmmm" + "ababa...ababa" + "............." + "............." + "............." + "ababababababa" + + // Level 5 + "mmmma...ammmm" + "mmmmb...bmmmm" + "mmmma...ammmm" + "mmmmb...bmmmm" + "ababa...ababa" + "............." + "............." + "............." + "ababababababa" + + // Level 6 + "mmmmcaaadmmmm" + "mmmmcaaadmmmm" + "mmmmcaaadmmmm" + "mmmmcaaadmmmm" + "eeeecaaadeeee" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "fffffffffffff", + + // Connections: + "1: 0, 1, 6: 4\n" /* Type 1, BLOCK_FACE_XM */ + "1: 12, 1, 6: 5\n" /* Type 1, BLOCK_FACE_XP */ + "1: 6, 1, 0: 2\n" /* Type 1, BLOCK_FACE_ZM */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // Tee4x4 + + // Turret: + // The data has been exported from gallery Nether, area index 7, ID 34 + { + // Size: + 7, 6, 7, // SizeX = 7, SizeY = 6, SizeZ = 7 + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */, + + // Block data: + // Level 1 + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + "aaaaaaa" + + // Level 2 + "aa...aa" + "a.....a" + "......." + "......." + "......." + "a.....a" + "aa...aa" + + // Level 3 + "aa...aa" + "a.....a" + "......." + "......." + "......." + "a.....a" + "aa...aa" + + // Level 4 + "aa...aa" + "a.....a" + "......." + "......." + "......." + "a.....a" + "aa...aa" + + // Level 5 + "aabbbaa" + "a.....a" + "b.....b" + "b.....b" + "b.....b" + "a.....a" + "aabbbaa" + + // Level 6 + "aaaaaaa" + "a.....a" + "a.....a" + "a.....a" + "a.....a" + "a.....a" + "aaaaaaa", + + // Connections: + "0: 0, 1, 3: 4\n" /* Type 0, BLOCK_FACE_XM */ + "0: 3, 1, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ + "0: 6, 1, 3: 5\n" /* Type 0, BLOCK_FACE_XP */ + "0: 3, 1, 6: 3\n" /* Type 0, BLOCK_FACE_ZP */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotations */ + + // Merge strategy: + cBlockArea::msSpongePrint, + }, // Turret + +} ; // g_NetherFortPrefabs1 + + + + + +const cPrefab::sDef g_NetherFortStartingPrefabs1[] = +{ + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // CentralRoom: + // The data has been exported from gallery Nether, area index 22, ID 164 + { + // Size: + 13, 9, 13, // SizeX = 13, SizeY = 9, SizeZ = 13 + + // Block definitions: + "a:112: 0\n" /* netherbrick */ + "b: 0: 0\n" /* air */ + "c: 10: 0\n" /* lava */ + "d:113: 0\n" /* netherbrickfence */, + + // Block data: + // Level 1 + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + "aaaaaaaaaaaaa" + + // Level 2 + "aaaaabbbaaaaa" + "aaaaabbbaaaaa" + "aabbbbbbbbbaa" + "aabbbbbbbbbaa" + "aabbbbbbbbbaa" + "aabbbaaabbbaa" + "aabbbacabbbaa" + "aabbbaaabbbaa" + "aabbbbbbbbbaa" + "aabbbbbbbbbaa" + "aabbbbbbbbbaa" + "aaaaabbbaaaaa" + "aaaaabbbaaaaa" // Level 3 "aaaaabbbaaaaa" @@ -1120,7 +2664,7 @@ const cPrefab::sDef g_NetherFortStartingPrefabs1[] = "aaaaabbbaaaaa" // Level 5 - "adadabbbadada" + "adadadddadada" "daaaabbbaaaad" "aabbbbbbbbbaa" "dabbbbbbbbbad" -- cgit v1.2.3 From a87bd5788f7e3e489282b3f69e0bb0ba1ddbafd8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 30 Mar 2014 13:07:28 +0100 Subject: Another curly --- src/Items/ItemMinecart.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Items/ItemMinecart.h b/src/Items/ItemMinecart.h index bf6f70eed..25500aeb9 100644 --- a/src/Items/ItemMinecart.h +++ b/src/Items/ItemMinecart.h @@ -1,4 +1,3 @@ - // ItemMinecart.h // Declares the various minecart ItemHandlers @@ -74,7 +73,9 @@ public: Minecart->Initialize(a_World); if (!a_Player->IsGameModeCreative()) + { a_Player->GetInventory().RemoveOneEquippedItem(); + } return true; } -- cgit v1.2.3 From 451a3e97c3748bcccb2ea2aef224b53bd8cbba9b Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 30 Mar 2014 19:25:17 +0300 Subject: Apache license --- LICENSE | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 196 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 566c55b46..69b3c7390 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,199 @@ - Copyright MCServer Contributors +MCServer: A performant C++ Minecraft Server +www: http://mc-server.org/ + +Copyright 2014 MCServer Team + +------ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. -- cgit v1.2.3 From b64a1daf6cc5a80ace34d348e9f8bb4b679a7651 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 30 Mar 2014 18:47:57 +0200 Subject: APIDump: Added article: Setting up ZeroBrane Studio. Fixes #824. --- MCServer/Plugins/APIDump/APIDesc.lua | 1 + MCServer/Plugins/APIDump/SettingUpZeroBrane.html | 45 ++++++++++++++++++++++ MCServer/Plugins/APIDump/Static/zbs_logo.png | Bin 0 -> 1306 bytes MCServer/Plugins/APIDump/Static/zbs_workspace.png | Bin 0 -> 72631 bytes 4 files changed, 46 insertions(+) create mode 100644 MCServer/Plugins/APIDump/SettingUpZeroBrane.html create mode 100644 MCServer/Plugins/APIDump/Static/zbs_logo.png create mode 100644 MCServer/Plugins/APIDump/Static/zbs_workspace.png diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 01f000182..83d544173 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2845,6 +2845,7 @@ end -- No sorting is provided for these, they will be output in the same order as defined here { FileName = "Writing-a-MCServer-plugin.html", Title = "Writing a MCServer plugin" }, { FileName = "SettingUpDecoda.html", Title = "Setting up the Decoda Lua IDE" }, + { FileName = "SettingUpZeroBrane.html", Title = "Setting up the ZeroBrane Studio Lua IDE" }, { FileName = "WebWorldThreads.html", Title = "Webserver vs World threads" }, } } ; diff --git a/MCServer/Plugins/APIDump/SettingUpZeroBrane.html b/MCServer/Plugins/APIDump/SettingUpZeroBrane.html new file mode 100644 index 000000000..0fb89e49d --- /dev/null +++ b/MCServer/Plugins/APIDump/SettingUpZeroBrane.html @@ -0,0 +1,45 @@ + + + + + MCServer - Setting up ZeroBrane Studio + + + + + + + +
    +

    Setting up the ZeroBrane Studio IDE

    +

    + This article will explain how to set up ZeroBrane Studio, an IDE for writing Lua code, so that you can develop MCServer plugins with the comfort of an IDE.

    + +

    About ZeroBrane Studio

    + +

    To quickly introduce ZeroBrane Studio, it is an IDE for writing Lua code. It has the basic features expected of an IDE - it allows you to manage groups of files as a project, you can edit multiple files in a tabbed editor, the code is syntax-highlighted. Code completion, symbol browsing, and more. It also features a Lua debugger that allows you to debug your Lua code within any application that uses Lua and can load Lua packages. It is written using the multiplatform WxWidgets toolkit, and runs on multiple platforms, including Windows, Linux and MacOS.

    +

    Here's a screenshot of a default ZBS window with the debugger stepping through the code (scaled down):
    +

    +

    As you can see, you can set breakpoints in the code, inspect variables' values, view the Lua call-stacks.

    +

    ZBS is open-source, the sources are on GitHub: https://github.com/pkulchenko/ZeroBraneStudio. The project's homepage is at http://studio.zerobrane.com/. + +

    First-time setup

    +

    Since ZBS is a universal Lua IDE, you need to first set it up so that it is ready for MCS plugin development. For that, you need to download one file, mcserver.lua from the ZBS's plugin repository. Place that file in the "packages" folder inside your ZBS's folder. Note that there are other useful plugins in the repository and you may want to have a look there later on to further customize your ZBS. To install them, simply save them into the same folder.

    +

    After you download the mcserver.lua file, you need to restart ZBS in order for the plugin to load. If there are no errors, you should see two new items in the Project -> Lua Interpreter submenu: "MCServer - debug mode" and "MCServer - release mode". The only difference between the two is which filename they use to launch MCServer - mcserver_debug(.exe) for the debug option and "mcserver(.exe)" for the release option. If you built your own MCServer executable and you built it in debug mode, you should select the debug mode option. In all other cases, including if you downloaded the already-compiled MCServer executable from the internet, you should select the release mode option.

    +

    For a first time user, it might be a bit overwhelming that there are no GUI settings in the ZBS, yet the IDE is very configurable. There are two files that you edit in order to change settings, either system-wide (all users of the computer share those settings) or user-wide (the settings are only for a specific user of the computer). Those files are regular Lua sources and you can quickly locate them and edit them from within the IDE itself, select Edit -> Preferences -> Settings: XYZ from the menu, with XYZ being either System or User.

    +

    There is a documentation on most of the settings on ZBS's webpage, have a look at http://studio.zerobrane.com/documentation.html, especially the Preferences section. Personally I recommend setting editor.usetabs to true and possibly adjusting the editor.tabwidth, turn off the editor.smartindent feature and for debugging the option debugger.alloweditting should be set to true unless you feel like punishing yourself.

    + +

    Project management

    +

    ZBS works with projects, it considers all files and subfolder in a specific folder to be a project. There's no need for a special project file nor for adding individual files to the workspace, all files are added automatically. To open a MCS plugin as the project, click the triple-dot button in the Project pane, or select Project -> Project directory -> Choose... from the menu. Browse and select the MCS plugin's folder. ZBS will load all the files in the plugin's folder and you can start editting code.

    +

    Note that although ZBS allows you to work with subfolders in your plugins (and you should, especially with larger plugins), the current mcserver ZBS plugin will not be able to start debugging unless you have a file open in the editor that is at the root level of the MCS plugin's folder.

    + +

    Debugging

    +

    You are now ready to debug your code. Before doing that, though, don't forget to save your project files. If you haven't done so already, enable your plugin in the settings.ini file. If you want the program to break at a certain line, it is best to set the breakpoint before starting the program. Set the cursor on the line and hit F9 (or use menu Project -> Toggle Breakpoint) to toggle a breakpoint on that line. Finally, hit F5, or select menu Project -> Start Debugging to launch MCServer under the debugger. The MCServer window comes up and loads your plugin. If the window doesn't come up, inspect the Output pane in ZBS, there are usually two reasons for failure:

      +
    • Your code in the currently open file has a hard syntax error. These are reported as "Compilation error" in the Output pane, double-click the line to go to the error
    • +
    • ZBS cannot find the MCServer executable. Make sure you are editting a file two levels down the folder hierarchy from the MCS executable and that the MCS executable is named properly (mcserver[.exe] or mcserver_debug[.exe]). Also make sure you have selected the right Interpreter (menu Project -> Lua Interpreter).
    • +

    +

    Once running, if the execution hits a breakpoint, the ZBS window will come up and a green arrow is displayed next to the breakpoint line. You can step through the code using F10 (Step Into) and Shift+F10 (Step Over). You can also use the Watch window to inspect variable values, or simply hover your mouse over a variable to display its value in the tooltip. Use the Remote console pane to execute commands directly *inside* the MCServer's plugin context.

    +

    You can also use the Project -> Break menu item to break into the debugger as soon as possible. You can also set breakpoints while the MCS plugin is running. Note that due to the way in which the debugger is implemented, MCS may execute some more Lua code before the break / breakpoint comes into effect. If MCS is not executing any Lua code in your plugin, it will not break until the plugin code kicks in again. This may result in missed breakpoints and delays before the Break command becomes effective. Therefore it's best to set breakpoints before running the program, or while the program is waiting in another breakpoint.

    +
    + + diff --git a/MCServer/Plugins/APIDump/Static/zbs_logo.png b/MCServer/Plugins/APIDump/Static/zbs_logo.png new file mode 100644 index 000000000..c8d6d6278 Binary files /dev/null and b/MCServer/Plugins/APIDump/Static/zbs_logo.png differ diff --git a/MCServer/Plugins/APIDump/Static/zbs_workspace.png b/MCServer/Plugins/APIDump/Static/zbs_workspace.png new file mode 100644 index 000000000..9ce17e35a Binary files /dev/null and b/MCServer/Plugins/APIDump/Static/zbs_workspace.png differ -- cgit v1.2.3 From a5c0600e6c69c329fcafc2f9138b9439cf5f65ce Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 30 Mar 2014 20:02:30 +0200 Subject: Fixed a few clang warnings. --- src/Blocks/BlockPluginInterface.h | 6 ++++++ src/Item.h | 2 +- src/LightingThread.h | 6 +++--- src/World.h | 6 +++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Blocks/BlockPluginInterface.h b/src/Blocks/BlockPluginInterface.h index 7428c9a7a..3a36c40b1 100644 --- a/src/Blocks/BlockPluginInterface.h +++ b/src/Blocks/BlockPluginInterface.h @@ -1,8 +1,14 @@ #pragma once +/** This interface is used to decouple block handlers from the cPluginManager dependancy through cWorld. +The block handlers call this interface, which is then implemented by the specific classes that +the caller provides. +*/ class cBlockPluginInterface { public: + virtual ~cBlockPluginInterface() {} + virtual bool CallHookBlockToPickups(cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) = 0; }; diff --git a/src/Item.h b/src/Item.h index 4bdfb12dd..910ecb382 100644 --- a/src/Item.h +++ b/src/Item.h @@ -209,7 +209,7 @@ public: void Add (const cItem & a_Item) {push_back(a_Item); } void Delete(int a_Idx); void Clear (void) {clear(); } - int Size (void) {return size(); } + size_t Size (void) {return size(); } void Set (int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDamage); void Add (short a_ItemType, char a_ItemCount, short a_ItemDamage) diff --git a/src/LightingThread.h b/src/LightingThread.h index 198f27248..3209ad9b2 100644 --- a/src/LightingThread.h +++ b/src/LightingThread.h @@ -160,14 +160,14 @@ protected: inline void PropagateLight( NIBBLETYPE * a_Light, - int a_SrcIdx, int a_DstIdx, + unsigned int a_SrcIdx, unsigned int a_DstIdx, int & a_NumSeedsOut, unsigned char * a_IsSeedOut, unsigned int * a_SeedIdxOut ) { ASSERT(a_SrcIdx >= 0); - ASSERT(a_SrcIdx < (int)ARRAYCOUNT(m_SkyLight)); + ASSERT(a_SrcIdx < ARRAYCOUNT(m_SkyLight)); ASSERT(a_DstIdx >= 0); - ASSERT(a_DstIdx < (int)ARRAYCOUNT(m_BlockTypes)); + ASSERT(a_DstIdx < ARRAYCOUNT(m_BlockTypes)); if (a_Light[a_SrcIdx] <= a_Light[a_DstIdx] + cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx])) { diff --git a/src/World.h b/src/World.h index bb2eb0b21..b3ee94a27 100644 --- a/src/World.h +++ b/src/World.h @@ -646,9 +646,9 @@ public: // Various queues length queries (cannot be const, they lock their CS): inline int GetGeneratorQueueLength (void) { return m_Generator.GetQueueLength(); } // tolua_export - inline int GetLightingQueueLength (void) { return m_Lighting.GetQueueLength(); } // tolua_export - inline int GetStorageLoadQueueLength(void) { return m_Storage.GetLoadQueueLength(); } // tolua_export - inline int GetStorageSaveQueueLength(void) { return m_Storage.GetSaveQueueLength(); } // tolua_export + inline size_t GetLightingQueueLength (void) { return m_Lighting.GetQueueLength(); } // tolua_export + inline size_t GetStorageLoadQueueLength(void) { return m_Storage.GetLoadQueueLength(); } // tolua_export + inline size_t GetStorageSaveQueueLength(void) { return m_Storage.GetSaveQueueLength(); } // tolua_export void InitializeSpawn(void); -- cgit v1.2.3 From 8288e53c0be9f4f746a045d5ce8fca6bf6799824 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 30 Mar 2014 23:13:13 +0200 Subject: Fixed a few Clang warnings in BlockHandlers. --- src/Blocks/BlockAnvil.h | 10 +++++----- src/Blocks/BlockCauldron.h | 2 +- src/Blocks/BlockCrops.h | 12 ++++++------ src/Blocks/BlockDirt.h | 10 +++++----- src/Blocks/BlockFire.h | 22 ++++++++++++---------- src/Blocks/BlockLeaves.h | 19 ++++++++++--------- src/Blocks/BlockMobHead.h | 4 ++-- src/Blocks/BlockNetherWart.h | 15 ++++++++------- src/Blocks/BlockRail.h | 1 + src/Blocks/BlockStems.h | 3 ++- src/Blocks/BlockVine.h | 4 ++-- 11 files changed, 54 insertions(+), 48 deletions(-) diff --git a/src/Blocks/BlockAnvil.h b/src/Blocks/BlockAnvil.h index 9f5f84be0..57d10ebce 100644 --- a/src/Blocks/BlockAnvil.h +++ b/src/Blocks/BlockAnvil.h @@ -33,16 +33,16 @@ public: a_BlockType = m_BlockType; int Direction = (int)floor(a_Player->GetYaw() * 4.0 / 360.0 + 0.5) & 0x3; - int RawMeta = a_BlockMeta >> 2; + NIBBLETYPE RawMeta = a_BlockMeta >> 2; Direction++; Direction %= 4; switch (Direction) { - case 0: a_BlockMeta = 0x2 | RawMeta << 2; break; - case 1: a_BlockMeta = 0x3 | RawMeta << 2; break; - case 2: a_BlockMeta = 0x0 | RawMeta << 2; break; - case 3: a_BlockMeta = 0x1 | RawMeta << 2; break; + case 0: a_BlockMeta = 0x2 | (RawMeta << 2); break; + case 1: a_BlockMeta = 0x3 | (RawMeta << 2); break; + case 2: a_BlockMeta = 0x0 | (RawMeta << 2); break; + case 3: a_BlockMeta = 0x1 | (RawMeta << 2); break; default: { return false; diff --git a/src/Blocks/BlockCauldron.h b/src/Blocks/BlockCauldron.h index 2e1032d2b..41b79b6c3 100644 --- a/src/Blocks/BlockCauldron.h +++ b/src/Blocks/BlockCauldron.h @@ -23,7 +23,7 @@ public: virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - char Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); switch (a_Player->GetEquippedItem().m_ItemType) { case E_ITEM_WATER_BUCKET: diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index ffc2b3f8b..8606cf3f3 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -2,7 +2,7 @@ #pragma once #include "BlockHandler.h" -#include "../MersenneTwister.h" +#include "../FastRandom.h" @@ -21,7 +21,7 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_Meta) override { - MTRand rand; + cFastRandom rand; if (a_Meta == 0x7) { @@ -31,18 +31,18 @@ public: case E_BLOCK_CROPS: { a_Pickups.push_back(cItem(E_ITEM_WHEAT, 1, 0)); - a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1 + (int)(rand.randInt(2) + rand.randInt(2)) / 2, 0)); // [1 .. 3] with high preference of 2 + a_Pickups.push_back(cItem(E_ITEM_SEEDS, (char)(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2 break; } case E_BLOCK_CARROTS: { - a_Pickups.push_back(cItem(E_ITEM_CARROT, 1 + (int)(rand.randInt(2) + rand.randInt(2)) / 2, 0)); // [1 .. 3] with high preference of 2 + a_Pickups.push_back(cItem(E_ITEM_CARROT, (char)(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2 break; } case E_BLOCK_POTATOES: { - a_Pickups.push_back(cItem(E_ITEM_POTATO, 1 + (int)(rand.randInt(2) + rand.randInt(2)) / 2, 0)); // [1 .. 3] with high preference of 2 - if (rand.randInt(20) == 0) + a_Pickups.push_back(cItem(E_ITEM_POTATO, (char)(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2 + if (rand.NextInt(21) == 0) { // With a 5% chance, drop a poisonous potato as well a_Pickups.push_back(cItem(E_ITEM_POISONOUS_POTATO, 1, 0)); diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index a1ab74257..aa24b8668 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -2,7 +2,7 @@ #pragma once #include "BlockHandler.h" -#include "../MersenneTwister.h" +#include "../FastRandom.h" @@ -44,12 +44,12 @@ public: } // Grass spreads to adjacent dirt blocks: - MTRand rand; // TODO: Replace with cFastRandom + cFastRandom rand; for (int i = 0; i < 2; i++) // Pick two blocks to grow to { - int OfsX = rand.randInt(2) - 1; // [-1 .. 1] - int OfsY = rand.randInt(4) - 3; // [-3 .. 1] - int OfsZ = rand.randInt(2) - 1; // [-1 .. 1] + int OfsX = rand.NextInt(3, a_RelX) - 1; // [-1 .. 1] + int OfsY = rand.NextInt(5, a_RelY) - 3; // [-3 .. 1] + int OfsZ = rand.NextInt(3, a_RelZ) - 1; // [-1 .. 1] BLOCKTYPE DestBlock; NIBBLETYPE DestMeta; diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h index a25b87858..c8f158e7e 100644 --- a/src/Blocks/BlockFire.h +++ b/src/Blocks/BlockFire.h @@ -17,25 +17,27 @@ public: } /// Portal boundary and direction variables - int XZP, XZM, Dir; // For wont of a better name... + // 2014_03_30 _X: What are these used for? Why do we need extra variables? + int XZP, XZM; + NIBBLETYPE Dir; virtual void OnPlaced(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override { /* PORTAL FINDING ALGORITH ======================= - -Get clicked base block - -Trace upwards to find first obsidian block; aborts if anything other than obsidian or air is encountered. - Uses this value as a reference (the 'ceiling') - -For both directions (if one fails, try the other), BASE (clicked) block: - -Go in one direction, only stop if a non obsidian block is encountered (abort) OR a portal border is encountered (FindObsidianCeiling returns -1) - -If a border was encountered, go the other direction and repeat above - -Write borders to XZP and XZM, write direction portal faces to Dir - -Loop through boundary variables, and fill with portal blocks based on Dir with meta from Dir + - Get clicked base block + - Trace upwards to find first obsidian block; aborts if anything other than obsidian or air is encountered. + Uses this value as a reference (the 'ceiling') + - For both directions (if one fails, try the other), BASE (clicked) block: + - Go in one direction, only stop if a non obsidian block is encountered (abort) OR a portal border is encountered (FindObsidianCeiling returns -1) + - If a border was encountered, go the other direction and repeat above + - Write borders to XZP and XZM, write direction portal faces to Dir + - Loop through boundary variables, and fill with portal blocks based on Dir with meta from Dir */ a_BlockY--; // Because we want the block below the fire - FindAndSetPortalFrame(a_BlockX, a_BlockY, a_BlockZ, a_ChunkInterface, a_WorldInterface); // Brought to you by Aperture Science + FindAndSetPortalFrame(a_BlockX, a_BlockY, a_BlockZ, a_ChunkInterface, a_WorldInterface); } virtual void OnDigging(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index a6d3373c1..8af14686e 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -1,6 +1,6 @@ #pragma once #include "BlockHandler.h" -#include "../MersenneTwister.h" +#include "../FastRandom.h" #include "../World.h" #include "../BlockArea.h" @@ -37,16 +37,18 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { - MTRand rand; + cFastRandom rand; // Only the first 2 bits contain the display information, the others are for growing - if (rand.randInt(5) == 0) + if (rand.NextInt(6) == 0) { a_Pickups.push_back(cItem(E_BLOCK_SAPLING, 1, a_BlockMeta & 3)); } - if ((a_BlockMeta & 3) == E_META_SAPLING_APPLE) + + // 1 % chance of dropping an apple, if the leaves' type is Apple Leaves + if ((a_BlockMeta & 3) == E_META_LEAVES_APPLE) { - if (rand.rand(100) == 0) + if (rand.NextInt(101) == 0) { a_Pickups.push_back(cItem(E_ITEM_RED_APPLE, 1, 0)); } @@ -58,11 +60,10 @@ public: { cBlockHandler::OnDestroyed(a_ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); - //0.5% chance of dropping an apple + // 0.5% chance of dropping an apple, if the leaves' type is Apple Leaves: NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - //check if Oak (0x1 and 0x2 bit not set) - MTRand rand; - if(!(Meta & 3) && rand.randInt(200) == 100) + cFastRandom rand; + if (((Meta & 3) == E_META_LEAVES_APPLE) && (rand.NextInt(201) == 100)) { cItems Drops; Drops.push_back(cItem(E_ITEM_RED_APPLE, 1, 0)); diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index 6aa01f986..080843a73 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -62,8 +62,8 @@ public: } public: - cCallback (cPlayer * a_Player, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) : - m_Player(a_Player), + cCallback (cPlayer * a_CBPlayer, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) : + m_Player(a_CBPlayer), m_OldBlockMeta(a_OldBlockMeta), m_NewBlockMeta(a_NewBlockMeta) {} diff --git a/src/Blocks/BlockNetherWart.h b/src/Blocks/BlockNetherWart.h index 923180e19..812cf906f 100644 --- a/src/Blocks/BlockNetherWart.h +++ b/src/Blocks/BlockNetherWart.h @@ -2,14 +2,13 @@ #pragma once #include "BlockHandler.h" -#include "../MersenneTwister.h" +#include "../FastRandom.h" #include "../World.h" -/// Common class that takes care of carrots, potatoes and wheat class cBlockNetherWartHandler : public cBlockHandler { @@ -22,12 +21,12 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_Meta) override { - MTRand rand; + cFastRandom rand; if (a_Meta == 0x7) { - // Is fully grown, drop the entire produce: - a_Pickups.push_back(cItem(E_ITEM_NETHER_WART, 1 + (int)(rand.randInt(2) + rand.randInt(2)) / 2, 0)); + // Fully grown, drop the entire produce: + a_Pickups.push_back(cItem(E_ITEM_NETHER_WART, (char)(1 + (rand.NextInt(3) + rand.NextInt(3))) / 2, 0)); } else { @@ -35,18 +34,20 @@ public: } } + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { - NIBBLETYPE Meta = a_Chunk.GetMeta (a_RelX, a_RelY, a_RelZ); - + NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); if (Meta < 7) { a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_NETHER_WART, ++Meta); } } + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { + // Needs to be placed on top of a Soulsand block: return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_SOULSAND)); } } ; diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 477707a91..ad78d290a 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -431,6 +431,7 @@ public: } break; } + default: break; } return true; } diff --git a/src/Blocks/BlockStems.h b/src/Blocks/BlockStems.h index 705436345..b726a0901 100644 --- a/src/Blocks/BlockStems.h +++ b/src/Blocks/BlockStems.h @@ -17,9 +17,10 @@ public: { } + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { - int ItemType = (m_BlockType == E_BLOCK_MELON_STEM) ? E_ITEM_MELON_SEEDS : E_ITEM_PUMPKIN_SEEDS; + short ItemType = (m_BlockType == E_BLOCK_MELON_STEM) ? E_ITEM_MELON_SEEDS : E_ITEM_PUMPKIN_SEEDS; a_Pickups.push_back(cItem(ItemType, 1, 0)); } diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index e14218633..e796a45ae 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -83,7 +83,7 @@ public: static const struct { int x, z; - int Bit; + NIBBLETYPE Bit; } Coords[] = { { 0, 1, 1}, // south, ZP @@ -91,7 +91,7 @@ public: { 0, -1, 4}, // north, ZM { 1, 0, 8}, // east, XP } ; - int res = 0; + NIBBLETYPE res = 0; for (size_t i = 0; i < ARRAYCOUNT(Coords); i++) { BLOCKTYPE BlockType; -- cgit v1.2.3 From 43844fc0f04ffd326af4ebc9e46ec220e27d1309 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 31 Mar 2014 13:28:38 +0200 Subject: cCompositeChat has a MessageType param in the constructor. This should make it easier to use. --- src/CompositeChat.cpp | 4 ++-- src/CompositeChat.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index a917ee70f..94f8a5901 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -112,8 +112,8 @@ cCompositeChat::cCompositeChat(void) : -cCompositeChat::cCompositeChat(const AString & a_ParseText) : - m_MessageType(mtCustom) +cCompositeChat::cCompositeChat(const AString & a_ParseText, eMessageType a_MessageType) : + m_MessageType(a_MessageType) { ParseText(a_ParseText); } diff --git a/src/CompositeChat.h b/src/CompositeChat.h index 27319490d..d5f4ebb24 100644 --- a/src/CompositeChat.h +++ b/src/CompositeChat.h @@ -117,7 +117,7 @@ public: /** Creates a new chat message and parses the text into parts. Recognizes "http:" and "https:" links and @color-codes. Uses ParseText() for the actual parsing. */ - cCompositeChat(const AString & a_ParseText); + cCompositeChat(const AString & a_ParseText, eMessageType a_MessageType = mtCustom); ~cCompositeChat(); -- cgit v1.2.3 From f38a009b3cc5caf25d11496fda5caf75531127d0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 31 Mar 2014 18:25:00 +0200 Subject: APIDump: Renamed the ZBS API dump file to mcserver_api.lua. This is to avoid confusion with ZBS, where two "mcserver.lua" files were present. --- MCServer/Plugins/APIDump/main_APIDump.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua index 7455c3cd2..52199740b 100644 --- a/MCServer/Plugins/APIDump/main_APIDump.lua +++ b/MCServer/Plugins/APIDump/main_APIDump.lua @@ -1408,9 +1408,9 @@ end --- Dumps the entire API table into a file in the ZBS format local function DumpAPIZBS(a_API) LOG("Dumping ZBS API description...") - local f, err = io.open("mcserver.lua", "w") + local f, err = io.open("mcserver_api.lua", "w") if (f == nil) then - LOG("Cannot open mcserver.lua for writing, ZBS API will not be dumped. " .. err) + LOG("Cannot open mcserver_lua.lua for writing, ZBS API will not be dumped. " .. err) return end -- cgit v1.2.3 From 55d0db1606f947c1b232e6329345fe7493805dcc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 31 Mar 2014 18:34:27 +0200 Subject: APIDump: Added code completion support file to ZBS tutorial. --- MCServer/Plugins/APIDump/SettingUpZeroBrane.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/SettingUpZeroBrane.html b/MCServer/Plugins/APIDump/SettingUpZeroBrane.html index 0fb89e49d..4ebbcb6e6 100644 --- a/MCServer/Plugins/APIDump/SettingUpZeroBrane.html +++ b/MCServer/Plugins/APIDump/SettingUpZeroBrane.html @@ -25,7 +25,8 @@

    First-time setup

    Since ZBS is a universal Lua IDE, you need to first set it up so that it is ready for MCS plugin development. For that, you need to download one file, mcserver.lua from the ZBS's plugin repository. Place that file in the "packages" folder inside your ZBS's folder. Note that there are other useful plugins in the repository and you may want to have a look there later on to further customize your ZBS. To install them, simply save them into the same folder.

    -

    After you download the mcserver.lua file, you need to restart ZBS in order for the plugin to load. If there are no errors, you should see two new items in the Project -> Lua Interpreter submenu: "MCServer - debug mode" and "MCServer - release mode". The only difference between the two is which filename they use to launch MCServer - mcserver_debug(.exe) for the debug option and "mcserver(.exe)" for the release option. If you built your own MCServer executable and you built it in debug mode, you should select the debug mode option. In all other cases, including if you downloaded the already-compiled MCServer executable from the internet, you should select the release mode option.

    +

    Next you should install the code-completion support specific for MCServer. You should repeat this step from time to time, because the API evolves in time so new functions and classes are added to it quite often. You should have an APIDump plugin in your MCServer installation. Enable the APIDump plugin in the server settings, it's very cheap to keep it enabled and it doesn't cost any performance during normal gameplay. To generate the code-completion support file, enter the api command into the server console. This will create a new file, "mcserver_api.lua", next to the MCS executable. Move that file into the "api/lua" subfolder inside your ZBS's folder.

    +

    After you download the mcserver.lua file and install the completion support, you need to restart ZBS in order for the plugin to load. If there are no errors, you should see two new items in the Project -> Lua Interpreter submenu: "MCServer - debug mode" and "MCServer - release mode". The only difference between the two is which filename they use to launch MCServer - mcserver_debug(.exe) for the debug option and "mcserver(.exe)" for the release option. If you built your own MCServer executable and you built it in debug mode, you should select the debug mode option. In all other cases, including if you downloaded the already-compiled MCServer executable from the internet, you should select the release mode option.

    For a first time user, it might be a bit overwhelming that there are no GUI settings in the ZBS, yet the IDE is very configurable. There are two files that you edit in order to change settings, either system-wide (all users of the computer share those settings) or user-wide (the settings are only for a specific user of the computer). Those files are regular Lua sources and you can quickly locate them and edit them from within the IDE itself, select Edit -> Preferences -> Settings: XYZ from the menu, with XYZ being either System or User.

    There is a documentation on most of the settings on ZBS's webpage, have a look at http://studio.zerobrane.com/documentation.html, especially the Preferences section. Personally I recommend setting editor.usetabs to true and possibly adjusting the editor.tabwidth, turn off the editor.smartindent feature and for debugging the option debugger.alloweditting should be set to true unless you feel like punishing yourself.

    -- cgit v1.2.3 From c4e07631c803debf1047a5607c96d9bf5c1e5f95 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 31 Mar 2014 19:47:18 +0200 Subject: Added new merge strategy "msDifference" --- src/BlockArea.cpp | 34 ++++++++++++++++++++++++++++++++++ src/BlockArea.h | 1 + 2 files changed, 35 insertions(+) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 2b950378a..17d3cbb00 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -173,6 +173,25 @@ static inline void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a +/** Combinator used for cBlockArea::msDifference merging */ +static inline void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +{ + if ((a_DstType == a_SrcType) && (a_DstMeta == a_SrcMeta)) + { + a_DstType = E_BLOCK_AIR; + a_DstMeta = 0; + } + else + { + a_DstType = a_SrcType; + a_DstMeta = a_SrcMeta; + } +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cBlockArea: @@ -709,6 +728,21 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R ); break; } // case msSpongePrint + + case msDifference: + { + InternalMergeBlocks( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z, + MergeCombinatorDifference + ); + break; + } // case msDifference default: { diff --git a/src/BlockArea.h b/src/BlockArea.h index d37f0d182..0bb272fd9 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -52,6 +52,7 @@ public: msImprint, msLake, msSpongePrint, + msDifference, } ; cBlockArea(void); -- cgit v1.2.3 From f7df8e133b66aafcf35f0590a0ac525a7d2f9278 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 31 Mar 2014 19:58:19 +0200 Subject: Documented msDifference --- MCServer/Plugins/APIDump/APIDesc.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 6f8a14421..532b4b665 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -230,22 +230,22 @@ g_APIDesc =

    - + - + - + - + - + - +
    area blockresultarea blockresult
    this Src msOverwrite msFillAir msImprint this Src msOverwrite msFillAir msImprint msDifference
    air air air air air air air air air air air
    A air air A A A air air A A air
    air B B B B air B B B B B
    A B B A B A B B A B B
    @@ -255,6 +255,8 @@ g_APIDesc =
  • msOverwrite completely overwrites all blocks with the Src's blocks
  • msFillAir overwrites only those blocks that were air
  • msImprint overwrites with only those blocks that are non-air
  • +
  • msSpongePrint Sponge overwrites nothing, everything else overwrites anything
  • +
  • msDifference changes all the blocks wich are the same to air. Otherwise the source block gets placed.
  • -- cgit v1.2.3 From a8bc27f8728a0c1f222871cbd3f5534646e59085 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 31 Mar 2014 20:05:48 +0200 Subject: Fixed typo --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 532b4b665..1b020501c 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -256,7 +256,7 @@ g_APIDesc =
  • msFillAir overwrites only those blocks that were air
  • msImprint overwrites with only those blocks that are non-air
  • msSpongePrint Sponge overwrites nothing, everything else overwrites anything
  • -
  • msDifference changes all the blocks wich are the same to air. Otherwise the source block gets placed.
  • +
  • msDifference changes all the blocks which are the same to air. Otherwise the source block gets placed.
  • -- cgit v1.2.3 From b19022fc7ea4cb6bd1bc6f4b212478e65b5fa5a1 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 31 Mar 2014 20:13:08 +0200 Subject: Added extra table which should make it more clear what msDifference does. --- MCServer/Plugins/APIDump/APIDesc.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 1b020501c..657ac6aa6 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -247,6 +247,9 @@ g_APIDesc = A B B A B B + + A A A A B air +

    @@ -255,7 +258,6 @@ g_APIDesc =

  • msOverwrite completely overwrites all blocks with the Src's blocks
  • msFillAir overwrites only those blocks that were air
  • msImprint overwrites with only those blocks that are non-air
  • -
  • msSpongePrint Sponge overwrites nothing, everything else overwrites anything
  • msDifference changes all the blocks which are the same to air. Otherwise the source block gets placed.
  • -- cgit v1.2.3 From 0836fe9a84e59b083db368205cbf6496355378bf Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 31 Mar 2014 20:33:33 +0100 Subject: Fixed a few Y too high/low asserts --- src/Blocks/BlockFluid.h | 5 +++-- src/MobSpawner.cpp | 12 +++++++----- src/Mobs/Monster.cpp | 10 +++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index 37885e4de..361b97c60 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -93,8 +93,8 @@ public: // Check if it's fuel: BLOCKTYPE BlockType; if ( - !a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) || - !cFireSimulator::IsFuel(BlockType) + ((a_RelY + y < 0) || (a_RelY + y > cChunkDef::Height)) || + (!a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) || !cFireSimulator::IsFuel(BlockType)) ) { return false; @@ -119,6 +119,7 @@ public: for (size_t i = 0; i < ARRAYCOUNT(CrossCoords); i++) { if ( + ((RelY + CrossCoords[i].y >= 0) && (RelY + CrossCoords[i].y <= cChunkDef::Height)) && a_Chunk.UnboundedRelGetBlockType(RelX + CrossCoords[i].x, RelY + CrossCoords[i].y, RelZ + CrossCoords[i].z, BlockType) && (BlockType == E_BLOCK_AIR) ) diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index a0d0f5c54..216681b48 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -129,6 +129,11 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R BLOCKTYPE TargetBlock = E_BLOCK_AIR; if (m_AllowedTypes.find(a_MobType) != m_AllowedTypes.end() && a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, TargetBlock)) { + if ((a_RelY + 1 > cChunkDef::Height) || (a_RelY - 1 < 0)) + { + return false; + } + NIBBLETYPE BlockLight = a_Chunk->GetBlockLight(a_RelX, a_RelY, a_RelZ); NIBBLETYPE SkyLight = a_Chunk->GetSkyLight(a_RelX, a_RelY, a_RelZ); BLOCKTYPE BlockAbove = a_Chunk->GetBlock(a_RelX, a_RelY + 1, a_RelZ); @@ -212,11 +217,8 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R return false; } HaveFloor = ( - HaveFloor || - ( - a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1, a_RelZ + z, TargetBlock) && - !cBlockInfo::IsTransparent(TargetBlock) - ) + a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1 /* Checked at start of function */, a_RelZ + z, TargetBlock) && + !cBlockInfo::IsTransparent(TargetBlock) ); } } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index d3e0f1c26..83003006e 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -111,9 +111,9 @@ void cMonster::SpawnOn(cClientHandle & a_Client) void cMonster::TickPathFinding() { - int PosX = (int)floor(GetPosX()); - int PosY = (int)floor(GetPosY()); - int PosZ = (int)floor(GetPosZ()); + const int PosX = (int)floor(GetPosX()); + const int PosY = (int)floor(GetPosY()); + const int PosZ = (int)floor(GetPosZ()); m_FinalDestination.y = (double)FindFirstNonAirBlockPosition(m_FinalDestination.x, m_FinalDestination.z); @@ -133,9 +133,9 @@ void cMonster::TickPathFinding() for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) { - if ((gCrossCoords[i].x + PosX == PosX) && (gCrossCoords[i].z + PosZ == PosZ)) + if ((PosY - 1 < 0) || (PosY + 1 > cChunkDef::Height) || (PosY + 2 > cChunkDef::Height)) { - continue; + break; } if (IsCoordinateInTraversedList(Vector3i(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ))) -- cgit v1.2.3 From ee07b7ae3ec9cd283fe61aede067e7fc9e4bcb49 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 31 Mar 2014 20:34:11 +0100 Subject: Simplified and fixed slabs, fixes #835 --- src/Blocks/BlockSlab.h | 43 ++++++++++--------------------------------- src/ClientHandle.cpp | 2 +- src/ClientHandle.h | 4 ++-- 3 files changed, 13 insertions(+), 36 deletions(-) diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index 77e8b8e55..3f0fef0c7 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -11,6 +11,7 @@ #include "BlockHandler.h" #include "../Items/ItemHandler.h" +#include "Root.h" @@ -38,41 +39,9 @@ public: ) override { a_BlockType = m_BlockType; - BLOCKTYPE Type = (BLOCKTYPE) (a_Player->GetEquippedItem().m_ItemType); NIBBLETYPE Meta = (NIBBLETYPE) a_Player->GetEquippedItem().m_ItemDamage; - // HandlePlaceBlock wants a cItemHandler pointer thing, so let's give it one - cItemHandler * ItemHandler = cItemHandler::GetItemHandler(GetDoubleSlabType(Type)); - - // Check if the block at the coordinates is a slab. Eligibility for combining has already been processed in ClientHandle - if (IsAnySlabType(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))) - { - // Call the function in ClientHandle that places a block when the client sends the packet, - // so that plugins may interfere with the placement. - - if ((a_BlockFace == BLOCK_FACE_TOP) || (a_BlockFace == BLOCK_FACE_BOTTOM)) - { - // Top and bottom faces need no parameter modification - a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); - } - else - { - // The other faces need to distinguish between top and bottom cursor positions - if (a_CursorY > 7) - { - // Edit the call to use BLOCK_FACE_BOTTOM, otherwise it places incorrectly - a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_TOP, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); - } - else - { - // Edit the call to use BLOCK_FACE_TOP, otherwise it places incorrectly - a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_BOTTOM, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); - } - } - return false; // Cancel the event, because dblslabs were already placed, nothing else needed - } - - // Place the single-slab with correct metas: + // Set the correct metadata based on player equipped item (i.e. a_BlockMeta not initialised yet) switch (a_BlockFace) { case BLOCK_FACE_TOP: @@ -104,6 +73,14 @@ public: } } } // switch (a_BlockFace) + + // Check if the block at the coordinates is a single slab. Eligibility for combining has already been processed in ClientHandle + // Changed to-be-placed to a double slab if we are clicking on a single slab, as opposed to placing one for the first time + if (IsAnySlabType(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))) + { + a_BlockType = GetDoubleSlabType(m_BlockType); + } + return true; } diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 5ed5f1085..23ba4dbab 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1064,7 +1064,7 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e // If clicked top face and slab occupies the top voxel, we want a slab to be placed above it (therefore increment Y) // Else if clicked bottom face and slab occupies the bottom voxel, decrement Y for the same reason // Don't touch coordinates if anything else because a dblslab opportunity is present - if((ClickedBlockMeta & 0x08) && (a_BlockFace == BLOCK_FACE_TOP)) + if ((ClickedBlockMeta & 0x08) && (a_BlockFace == BLOCK_FACE_TOP)) { ++a_BlockY; } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 8366caa16..5496e61a7 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -230,10 +230,10 @@ public: /** Called when the player moves into a different world; queues sreaming the new chunks */ void MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket); +private: + /** Handles the block placing packet when it is a real block placement (not block-using, item-using or eating) */ void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler); - -private: /** The type used for storing the names of registered plugin channels. */ typedef std::set cChannels; -- cgit v1.2.3 From fc940b6da4fd446e718879a19790af03dadfe2f4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 31 Mar 2014 21:36:19 +0100 Subject: Realised suggestions --- src/Blocks/BlockFluid.h | 5 ++++- src/MobSpawner.cpp | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index 361b97c60..1200997ff 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -94,7 +94,10 @@ public: BLOCKTYPE BlockType; if ( ((a_RelY + y < 0) || (a_RelY + y > cChunkDef::Height)) || - (!a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) || !cFireSimulator::IsFuel(BlockType)) + ( + !a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) || + !cFireSimulator::IsFuel(BlockType) + ) ) { return false; diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index 216681b48..05da5d01c 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -205,7 +205,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R case cMonster::mtSpider: { bool CanSpawn = true; - bool HaveFloor = false; + bool HasFloor = false; for (int x = 0; x < 2; ++x) { for(int z = 0; z < 2; ++z) @@ -216,13 +216,16 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R { return false; } - HaveFloor = ( - a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1 /* Checked at start of function */, a_RelZ + z, TargetBlock) && - !cBlockInfo::IsTransparent(TargetBlock) + HasFloor = ( + HasFloor || + ( + a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1, a_RelZ + z, TargetBlock) && + !cBlockInfo::IsTransparent(TargetBlock) + ) ); } } - return CanSpawn && HaveFloor && (SkyLight <= 7) && (BlockLight <= 7); + return CanSpawn && HasFloor && (SkyLight <= 7) && (BlockLight <= 7); } case cMonster::mtCreeper: -- cgit v1.2.3 From 8126d9e66ef1ac90db2660ae357c9aa1c14c7126 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 31 Mar 2014 22:51:14 +0200 Subject: Console logging supports cCompositeChat as its parameters. --- MCServer/Plugins/Debuggers/Debuggers.lua | 9 +++++++ src/Bindings/ManualBindings.cpp | 46 +++++++++++++++++++++++--------- src/CompositeChat.cpp | 29 ++++++++++++++++++++ src/CompositeChat.h | 5 ++++ src/Protocol/Protocol125.cpp | 23 +--------------- 5 files changed, 78 insertions(+), 34 deletions(-) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 2cb014875..2619bd6c4 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -75,6 +75,15 @@ function Initialize(Plugin) -- TestPluginCalls(); TestBlockAreasString() + + --[[ + -- Test cCompositeChat usage in console-logging: + LOGINFO(cCompositeChat("This is a simple message with some @2 color formatting @4 and http://links.to .") + :AddSuggestCommandPart("(Suggested command)", "cmd") + :AddRunCommandPart("(Run command)", "cmd") + :SetMessageType(mtInfo) + ) + --]] return true end; diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 20bbc48f2..95cd5e904 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -115,10 +115,35 @@ static int tolua_StringSplitAndTrim(lua_State * tolua_S) -static int tolua_LOG(lua_State* tolua_S) +/** Retrieves the log message from the first param on the Lua stack. +Can take either a string or a cCompositeChat. +*/ +static AString GetLogMessage(lua_State * tolua_S) { - const char* str = tolua_tocppstring(tolua_S,1,0); - cMCLogger::GetInstance()->LogSimple( str, 0 ); + tolua_Error err; + if (tolua_isusertype(tolua_S, 1, "cCompositeChat", false, &err)) + { + return ((cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL))->ExtractText(); + } + else + { + size_t len = 0; + const char * str = lua_tolstring(tolua_S, 1, &len); + if (str != NULL) + { + return AString(str, len); + } + } + return ""; +} + + + + + +static int tolua_LOG(lua_State * tolua_S) +{ + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 0); return 0; } @@ -126,10 +151,9 @@ static int tolua_LOG(lua_State* tolua_S) -static int tolua_LOGINFO(lua_State* tolua_S) +static int tolua_LOGINFO(lua_State * tolua_S) { - const char* str = tolua_tocppstring(tolua_S,1,0); - cMCLogger::GetInstance()->LogSimple( str, 1 ); + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 1); return 0; } @@ -137,10 +161,9 @@ static int tolua_LOGINFO(lua_State* tolua_S) -static int tolua_LOGWARN(lua_State* tolua_S) +static int tolua_LOGWARN(lua_State * tolua_S) { - const char* str = tolua_tocppstring(tolua_S,1,0); - cMCLogger::GetInstance()->LogSimple( str, 2 ); + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 2); return 0; } @@ -148,10 +171,9 @@ static int tolua_LOGWARN(lua_State* tolua_S) -static int tolua_LOGERROR(lua_State* tolua_S) +static int tolua_LOGERROR(lua_State * tolua_S) { - const char* str = tolua_tocppstring(tolua_S,1,0); - cMCLogger::GetInstance()->LogSimple( str, 3 ); + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 3); return 0; } diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index 94f8a5901..918e4f90e 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -314,6 +314,35 @@ void cCompositeChat::UnderlineUrls(void) +AString cCompositeChat::ExtractText(void) const +{ + AString Msg; + for (cParts::const_iterator itr = m_Parts.begin(), end = m_Parts.end(); itr != end; ++itr) + { + switch ((*itr)->m_PartType) + { + case ptText: + case ptClientTranslated: + case ptRunCommand: + case ptSuggestCommand: + { + Msg.append((*itr)->m_Text); + break; + } + case ptUrl: + { + Msg.append(((cUrlPart *)(*itr))->m_Url); + break; + } + } // switch (PartType) + } // for itr - m_Parts[] + return Msg; +} + + + + + void cCompositeChat::AddStyle(AString & a_Style, const AString & a_AddStyle) { if (a_AddStyle.empty()) diff --git a/src/CompositeChat.h b/src/CompositeChat.h index d5f4ebb24..0f56cde9b 100644 --- a/src/CompositeChat.h +++ b/src/CompositeChat.h @@ -164,6 +164,11 @@ public: /** Returns the message type set previously by SetMessageType(). */ eMessageType GetMessageType(void) const { return m_MessageType; } + /** Returns the text from the parts that comprises the human-readable data. + Used for older protocols that don't support composite chat + and for console-logging. */ + AString ExtractText(void) const; + // tolua_end const cParts & GetParts(void) const { return m_Parts; } diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 69f4934d8..ea844c044 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -239,32 +239,11 @@ void cProtocol125::SendChat(const AString & a_Message) void cProtocol125::SendChat(const cCompositeChat & a_Message) { // This version doesn't support composite messages, just extract each part's text and use it: - AString Msg; - const cCompositeChat::cParts & Parts = a_Message.GetParts(); - for (cCompositeChat::cParts::const_iterator itr = Parts.begin(), end = Parts.end(); itr != end; ++itr) - { - switch ((*itr)->m_PartType) - { - case cCompositeChat::ptText: - case cCompositeChat::ptClientTranslated: - case cCompositeChat::ptRunCommand: - case cCompositeChat::ptSuggestCommand: - { - Msg.append((*itr)->m_Text); - break; - } - case cCompositeChat::ptUrl: - { - Msg.append(((cCompositeChat::cUrlPart *)(*itr))->m_Url); - break; - } - } // switch (PartType) - } // for itr - Parts[] // Send the message: cCSLock Lock(m_CSPacket); WriteByte (PACKET_CHAT); - WriteString(Msg); + WriteString(a_Message.ExtractText()); Flush(); } -- cgit v1.2.3 From 58f255032176c5e4e3a0f5e6ffea76128355ee61 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 31 Mar 2014 23:05:31 +0200 Subject: APIDump: Documented the cCompositeChat support in logging functions. --- MCServer/Plugins/APIDump/APIDesc.lua | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index eceb19bd7..b1b660bb0 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2663,11 +2663,31 @@ end ItemToFullString = {Params = "{{cItem|cItem}}", Return = "string", Notes = "Returns the string representation of the item, in the format 'ItemTypeText:ItemDamage * Count'"}, ItemToString = {Params = "{{cItem|cItem}}", Return = "string", Notes = "Returns the string representation of the item type"}, ItemTypeToString = {Params = "ItemType", Return = "string", Notes = "Returns the string representation of ItemType "}, - LOG = {Params = "string", Notes = "Logs a text into the server console using 'normal' severity (gray text) "}, - LOGERROR = {Params = "string", Notes = "Logs a text into the server console using 'error' severity (black text on red background)"}, - LOGINFO = {Params = "string", Notes = "Logs a text into the server console using 'info' severity (yellow text)"}, - LOGWARN = {Params = "string", Notes = "Logs a text into the server console using 'warning' severity (red text); OBSOLETE, use LOGWARNING() instead"}, - LOGWARNING = {Params = "string", Notes = "Logs a text into the server console using 'warning' severity (red text)"}, + LOG = + { + {Params = "string", Notes = "Logs a text into the server console using 'normal' severity (gray text) "}, + {Params = "{{cCompositeChat|CompositeChat}}", Notes = "Logs the {{cCompositeChat}}'s human-readable text into the server console using 'normal' severity (gray text) "}, + }, + LOGERROR = + { + {Params = "string", Notes = "Logs a text into the server console using 'error' severity (black text on red background)"}, + {Params = "{{cCompositeChat|CompositeChat}}", Notes = "Logs the {{cCompositeChat}}'s human-readable text into the server console using 'error' severity (black text on red background)"}, + }, + LOGINFO = + { + {Params = "string", Notes = "Logs a text into the server console using 'info' severity (yellow text)"}, + {Params = "{{cCompositeChat|CompositeChat}}", Notes = "Logs the {{cCompositeChat}}'s human-readable text into the server console using 'info' severity (yellow text)"}, + }, + LOGWARN = + { + {Params = "string", Notes = "Logs a text into the server console using 'warning' severity (red text); OBSOLETE, use LOGWARNING() instead"}, + {Params = "{{cCompositeChat|CompositeChat}}", Notes = "Logs the {{cCompositeChat}}'s human-readable text into the server console using 'warning' severity (red text); OBSOLETE, use LOGWARNING() instead"}, + }, + LOGWARNING = + { + {Params = "string", Notes = "Logs a text into the server console using 'warning' severity (red text)"}, + {Params = "{{cCompositeChat|CompositeChat}}", Notes = "Logs the {{cCompositeChat}}'s human-readable text into the server console using 'warning' severity (red text)"}, + }, MirrorBlockFaceY = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "{{Globals#BlockFaces|eBlockFace}}", Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after mirroring it around the Y axis (or rotating 180 degrees around it)." }, NoCaseCompare = {Params = "string, string", Return = "number", Notes = "Case-insensitive string comparison; returns 0 if the strings are the same"}, NormalizeAngleDegrees = { Params = "AngleDegrees", Return = "AngleDegrees", Notes = "Returns the angle, wrapped into the [-180, +180) range." }, -- cgit v1.2.3 From ef48b30baaed9c6ad1782047d4e2d60d6248ad89 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 31 Mar 2014 22:37:05 +0100 Subject: Final realisation of suggestions --- src/Mobs/Monster.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 83003006e..aa6071515 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -130,14 +130,16 @@ void cMonster::TickPathFinding() { 0, 1}, { 0,-1}, } ; + + if ((PosY - 1 < 0) || (PosY + 2 > cChunkDef::Height) /* PosY + 1 will never be true if PosY + 2 is not */) + { + // Too low/high, can't really do anything + FinishPathFinding(); + return; + } for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) { - if ((PosY - 1 < 0) || (PosY + 1 > cChunkDef::Height) || (PosY + 2 > cChunkDef::Height)) - { - break; - } - if (IsCoordinateInTraversedList(Vector3i(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ))) { continue; -- cgit v1.2.3 From 7aa6a3b86663ef28295ffb914f66a8f0359a353f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 09:32:14 +0200 Subject: LOG() API reads the LogLevel from the cCompositeChat's MessageType. --- MCServer/Plugins/APIDump/APIDesc.lua | 4 ++-- src/Bindings/ManualBindings.cpp | 17 +++++++++++++---- src/CompositeChat.cpp | 23 +++++++++++++++++++++++ src/CompositeChat.h | 4 ++++ src/MCLogger.cpp | 24 +++++++++++++++++------- src/MCLogger.h | 33 ++++++++++++++++++++++----------- 6 files changed, 81 insertions(+), 24 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index b1b660bb0..28e7744ed 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2665,8 +2665,8 @@ end ItemTypeToString = {Params = "ItemType", Return = "string", Notes = "Returns the string representation of ItemType "}, LOG = { - {Params = "string", Notes = "Logs a text into the server console using 'normal' severity (gray text) "}, - {Params = "{{cCompositeChat|CompositeChat}}", Notes = "Logs the {{cCompositeChat}}'s human-readable text into the server console using 'normal' severity (gray text) "}, + {Params = "string", Notes = "Logs a text into the server console using 'normal' severity (gray text)"}, + {Params = "{{cCompositeChat|CompositeChat}}", Notes = "Logs the {{cCompositeChat}}'s human-readable text into the server console. The severity is converted from the CompositeChat's MessageType."}, }, LOGERROR = { diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 95cd5e904..9d1a367df 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -143,7 +143,16 @@ static AString GetLogMessage(lua_State * tolua_S) static int tolua_LOG(lua_State * tolua_S) { - cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 0); + // If the param is a cCompositeChat, read the log level from it: + cMCLogger::eLogLevel LogLevel = cMCLogger::llRegular; + tolua_Error err; + if (tolua_isusertype(tolua_S, 1, "cCompositeChat", false, &err)) + { + LogLevel = cCompositeChat::MessageTypeToLogLevel(((cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL))->GetMessageType()); + } + + // Log the message: + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), LogLevel); return 0; } @@ -153,7 +162,7 @@ static int tolua_LOG(lua_State * tolua_S) static int tolua_LOGINFO(lua_State * tolua_S) { - cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 1); + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), cMCLogger::llInfo); return 0; } @@ -163,7 +172,7 @@ static int tolua_LOGINFO(lua_State * tolua_S) static int tolua_LOGWARN(lua_State * tolua_S) { - cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 2); + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), cMCLogger::llWarning); return 0; } @@ -173,7 +182,7 @@ static int tolua_LOGWARN(lua_State * tolua_S) static int tolua_LOGERROR(lua_State * tolua_S) { - cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 3); + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), cMCLogger::llError); return 0; } diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index 918e4f90e..c70ef1070 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -343,6 +343,29 @@ AString cCompositeChat::ExtractText(void) const +cMCLogger::eLogLevel cCompositeChat::MessageTypeToLogLevel(eMessageType a_MessageType) +{ + switch (a_MessageType) + { + case mtCustom: return cMCLogger::llRegular; + case mtFailure: return cMCLogger::llWarning; + case mtInformation: return cMCLogger::llInfo; + case mtSuccess: return cMCLogger::llRegular; + case mtWarning: return cMCLogger::llWarning; + case mtFatal: return cMCLogger::llError; + case mtDeath: return cMCLogger::llRegular; + case mtPrivateMessage: return cMCLogger::llRegular; + case mtJoin: return cMCLogger::llRegular; + case mtLeave: return cMCLogger::llRegular; + } + ASSERT(!"Unhandled MessageType"); + return cMCLogger::llError; +} + + + + + void cCompositeChat::AddStyle(AString & a_Style, const AString & a_AddStyle) { if (a_AddStyle.empty()) diff --git a/src/CompositeChat.h b/src/CompositeChat.h index 0f56cde9b..5b9c5f612 100644 --- a/src/CompositeChat.h +++ b/src/CompositeChat.h @@ -173,6 +173,10 @@ public: const cParts & GetParts(void) const { return m_Parts; } + /** Converts the MessageType to a LogLevel value. + Used by the logging bindings when logging a cCompositeChat object. */ + static cMCLogger::eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType); + protected: /** All the parts that */ cParts m_Parts; diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index 4f3e5dc0f..509833f37 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -93,25 +93,35 @@ void cMCLogger::InitLog(const AString & a_FileName) -void cMCLogger::LogSimple(const char* a_Text, int a_LogType /* = 0 */ ) +void cMCLogger::LogSimple(const char * a_Text, eLogLevel a_LogLevel) { - switch( a_LogType ) + switch (a_LogLevel) { - case 0: + case llRegular: + { LOG("%s", a_Text); break; - case 1: + } + case llInfo: + { LOGINFO("%s", a_Text); break; - case 2: + } + case llWarning: + { LOGWARN("%s", a_Text); break; - case 3: + } + case llError: + { LOGERROR("%s", a_Text); break; + } default: - LOG("(#%d#: %s", a_LogType, a_Text); + { + LOG("(#%d#: %s", (int)a_LogLevel, a_Text); break; + } } } diff --git a/src/MCLogger.h b/src/MCLogger.h index 996e60329..c0150c124 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -10,25 +10,36 @@ class cLog; -class cMCLogger // tolua_export -{ // tolua_export -public: // tolua_export - /// Creates a logger with the default filename, "logs/LOG_.log" +// tolua_begin +class cMCLogger +{ +public: + enum eLogLevel + { + llRegular, + llInfo, + llWarning, + llError, + }; + // tolua_end + + /** Creates a logger with the default filename, "logs/LOG_.log" */ cMCLogger(void); - /// Creates a logger with the specified filename inside "logs" folder + /** Creates a logger with the specified filename inside "logs" folder */ cMCLogger(const AString & a_FileName); // tolua_export ~cMCLogger(); // tolua_export - void Log(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); - void Info(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); - void Warn(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); - void Error(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); + void Log (const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0); + void Info (const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0); + void Warn (const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0); + void Error(const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0); - void LogSimple(const char* a_Text, int a_LogType = 0 ); // tolua_export + /** Logs the simple text message at the specified log level. */ + void LogSimple(const char * a_Text, eLogLevel a_LogLevel = llRegular); // tolua_export - static cMCLogger* GetInstance(); + static cMCLogger * GetInstance(); private: enum eColorScheme { -- cgit v1.2.3 From e610262fb10c6fafd3c3ff5f2c4f83ada9220e6d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 09:44:11 +0200 Subject: Attempt at disabling the useless clang warnings. Ref.: #846, #847 --- SetFlags.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/SetFlags.cmake b/SetFlags.cmake index bbd8254ad..d90ad8b48 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -198,6 +198,7 @@ macro(set_exe_flags) add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") + add_flags_cxx("-Wno-weak-vtables -Wno-switch-enum") endif() endif() -- cgit v1.2.3 From 7cc322332baa22475674f93b9ec76e1546d7e941 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 13:38:40 +0200 Subject: Removed an unneeded code branch. --- src/MCLogger.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index 509833f37..80fa7b173 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -117,11 +117,6 @@ void cMCLogger::LogSimple(const char * a_Text, eLogLevel a_LogLevel) LOGERROR("%s", a_Text); break; } - default: - { - LOG("(#%d#: %s", (int)a_LogLevel, a_Text); - break; - } } } -- cgit v1.2.3 From aa7552309abb6943f8ba0ac3d8013689655e74b2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 14:23:11 +0200 Subject: Simplified the anvil placement code. --- src/Blocks/BlockAnvil.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Blocks/BlockAnvil.h b/src/Blocks/BlockAnvil.h index 57d10ebce..93a796ef7 100644 --- a/src/Blocks/BlockAnvil.h +++ b/src/Blocks/BlockAnvil.h @@ -18,11 +18,13 @@ public: { } + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { a_Pickups.push_back(cItem(E_BLOCK_ANVIL, 1, a_BlockMeta >> 2)); } + virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, @@ -31,27 +33,23 @@ public: ) override { a_BlockType = m_BlockType; - - int Direction = (int)floor(a_Player->GetYaw() * 4.0 / 360.0 + 0.5) & 0x3; - NIBBLETYPE RawMeta = a_BlockMeta >> 2; - - Direction++; - Direction %= 4; + NIBBLETYPE HighBits = a_BlockMeta & 0x0c; // Only highest two bits are preserved + int Direction = (int)floor(a_Player->GetYaw() * 4.0 / 360.0 + 1.5) & 0x3; switch (Direction) { - case 0: a_BlockMeta = 0x2 | (RawMeta << 2); break; - case 1: a_BlockMeta = 0x3 | (RawMeta << 2); break; - case 2: a_BlockMeta = 0x0 | (RawMeta << 2); break; - case 3: a_BlockMeta = 0x1 | (RawMeta << 2); break; + case 0: a_BlockMeta = 0x2 | HighBits; break; + case 1: a_BlockMeta = 0x3 | HighBits; break; + case 2: a_BlockMeta = 0x0 | HighBits; break; + case 3: a_BlockMeta = 0x1 | HighBits; break; default: { return false; } } - return true; } + virtual bool IsUseable() override { return true; -- cgit v1.2.3 From 45150e97541aa8dfda7f0fdba75acf2ec616654d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 14:58:05 +0200 Subject: Fixed clang warnings in cFile. We only support 32-bit filesizes (files < 2 GiB). --- src/OSSupport/File.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 17070030f..75ea198a8 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -152,7 +152,7 @@ int cFile::Read (void * iBuffer, int iNumBytes) return -1; } - return fread(iBuffer, 1, iNumBytes, m_File); // fread() returns the portion of Count parameter actually read, so we need to send iNumBytes as Count + return (int)fread(iBuffer, 1, (size_t)iNumBytes, m_File); // fread() returns the portion of Count parameter actually read, so we need to send iNumBytes as Count } @@ -168,7 +168,7 @@ int cFile::Write(const void * iBuffer, int iNumBytes) return -1; } - int res = fwrite(iBuffer, 1, iNumBytes, m_File); // fwrite() returns the portion of Count parameter actually written, so we need to send iNumBytes as Count + int res = (int)fwrite(iBuffer, 1, (size_t)iNumBytes, m_File); // fwrite() returns the portion of Count parameter actually written, so we need to send iNumBytes as Count return res; } @@ -189,7 +189,7 @@ int cFile::Seek (int iPosition) { return -1; } - return ftell(m_File); + return (int)ftell(m_File); } @@ -206,7 +206,7 @@ int cFile::Tell (void) const return -1; } - return ftell(m_File); + return (int)ftell(m_File); } @@ -222,7 +222,7 @@ int cFile::GetSize(void) const return -1; } - int CurPos = ftell(m_File); + int CurPos = Tell(); if (CurPos < 0) { return -1; @@ -231,8 +231,8 @@ int cFile::GetSize(void) const { return -1; } - int res = ftell(m_File); - if (fseek(m_File, CurPos, SEEK_SET) != 0) + int res = Tell(); + if (fseek(m_File, (size_t)CurPos, SEEK_SET) != 0) { return -1; } @@ -255,7 +255,7 @@ int cFile::ReadRestOfFile(AString & a_Contents) int DataSize = GetSize() - Tell(); // HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly - a_Contents.assign(DataSize, '\0'); + a_Contents.assign((size_t)DataSize, '\0'); return Read((void *)a_Contents.data(), DataSize); } @@ -350,7 +350,7 @@ int cFile::GetSize(const AString & a_FileName) struct stat st; if (stat(a_FileName.c_str(), &st) == 0) { - return st.st_size; + return (int)st.st_size; } return -1; } @@ -456,7 +456,7 @@ int cFile::Printf(const char * a_Fmt, ...) va_start(args, a_Fmt); AppendVPrintf(buf, a_Fmt, args); va_end(args); - return Write(buf.c_str(), buf.length()); + return Write(buf.c_str(), (int)buf.length()); } -- cgit v1.2.3 From 42e30b6513c8f905d419dd6621ad11959eea9dc9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 14:55:46 +0200 Subject: Fixed clang warnings in BlockHandlers. --- src/Blocks/BlockMobHead.h | 2 +- src/Blocks/BlockSlab.h | 1 + src/Blocks/BlockStairs.h | 4 ++-- src/Blocks/BlockVine.h | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index 080843a73..c4f41ba34 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -70,7 +70,7 @@ public: }; cCallback Callback(a_Player, a_BlockMeta, static_cast(a_BlockFace)); - a_BlockMeta = a_BlockFace; + a_BlockMeta = (NIBBLETYPE)a_BlockFace; cWorld * World = (cWorld *) &a_WorldInterface; World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback); a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index 77e8b8e55..4f94d45f6 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -103,6 +103,7 @@ public: a_BlockMeta = Meta & 0x7; break; } } + case BLOCK_FACE_NONE: return false; } // switch (a_BlockFace) return true; } diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index 1072b7e71..09ff254a6 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -30,9 +30,7 @@ public: UNUSED(a_BlockY); UNUSED(a_BlockZ); UNUSED(a_CursorX); - UNUSED(a_CursorY); UNUSED(a_CursorZ); - UNUSED(a_BlockMeta); a_BlockType = m_BlockType; a_BlockMeta = RotationToMetaData(a_Player->GetYaw()); switch (a_BlockFace) @@ -51,10 +49,12 @@ public: } break; } + case BLOCK_FACE_NONE: return false; } return true; } + virtual const char * GetStepSound(void) override { if ( diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index e796a45ae..7bb9dc484 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -197,14 +197,14 @@ public: virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override { // Bits 2 and 4 stay, bits 1 and 3 swap - return ((a_Meta & 0x0a) | ((a_Meta & 0x01) << 2) | ((a_Meta & 0x04) >> 2)); + return (NIBBLETYPE)((a_Meta & 0x0a) | ((a_Meta & 0x01) << 2) | ((a_Meta & 0x04) >> 2)); } virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override { // Bits 1 and 3 stay, bits 2 and 4 swap - return ((a_Meta & 0x05) | ((a_Meta & 0x02) << 2) | ((a_Meta & 0x08) >> 2)); + return (NIBBLETYPE)((a_Meta & 0x05) | ((a_Meta & 0x02) << 2) | ((a_Meta & 0x08) >> 2)); } } ; -- cgit v1.2.3 From b9a090d835c9434570166b7cddcb8b6d7e2628e4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 15:00:30 +0200 Subject: Fixed clang warnings in cGZipFile. --- src/OSSupport/GZipFile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OSSupport/GZipFile.cpp b/src/OSSupport/GZipFile.cpp index b13e519e0..7a8433f4f 100644 --- a/src/OSSupport/GZipFile.cpp +++ b/src/OSSupport/GZipFile.cpp @@ -78,7 +78,7 @@ int cGZipFile::ReadRestOfFile(AString & a_Contents) while ((NumBytesRead = gzread(m_File, Buffer, sizeof(Buffer))) > 0) { TotalBytes += NumBytesRead; - a_Contents.append(Buffer, NumBytesRead); + a_Contents.append(Buffer, (size_t)NumBytesRead); } // NumBytesRead is < 0 on error return (NumBytesRead >= 0) ? TotalBytes : NumBytesRead; @@ -102,7 +102,7 @@ bool cGZipFile::Write(const char * a_Contents, int a_Size) return false; } - return (gzwrite(m_File, a_Contents, a_Size) != 0); + return (gzwrite(m_File, a_Contents, (unsigned int)a_Size) != 0); } -- cgit v1.2.3 From 2672b14c036f74548f970349aa08b6cb02600688 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 16:00:20 +0200 Subject: More cFile warning fixes. --- src/OSSupport/File.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 75ea198a8..7f0f0ad2f 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -232,7 +232,7 @@ int cFile::GetSize(void) const return -1; } int res = Tell(); - if (fseek(m_File, (size_t)CurPos, SEEK_SET) != 0) + if (fseek(m_File, (long)CurPos, SEEK_SET) != 0) { return -1; } -- cgit v1.2.3 From 0d916a3e2f8947af6bc7da6e19d23522ba014f6d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 16:10:08 +0200 Subject: Removed the exit-time-destructors flag from clang. We don't care about exit-time destructors, at least for now. --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index d90ad8b48..c5a3a0697 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -198,7 +198,7 @@ macro(set_exe_flags) add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") - add_flags_cxx("-Wno-weak-vtables -Wno-switch-enum") + add_flags_cxx("-Wno-weak-vtables -Wno-switch-enum -Wno-exit-time-destructors") endif() endif() -- cgit v1.2.3 From 1795cca5522476006d33d0c276e27a50659c867a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 16:36:00 +0200 Subject: Rewritten HTTPServer to use size_t for data lengths. --- src/HTTPServer/EnvelopeParser.cpp | 4 ++-- src/HTTPServer/EnvelopeParser.h | 29 ++++++++++++++++------------- src/HTTPServer/HTTPConnection.cpp | 14 +++++++------- src/HTTPServer/HTTPConnection.h | 4 ++-- src/HTTPServer/HTTPFormParser.cpp | 2 +- src/HTTPServer/HTTPFormParser.h | 4 ++-- src/HTTPServer/HTTPMessage.cpp | 28 ++++++++++++++-------------- src/HTTPServer/HTTPMessage.h | 14 ++++++++------ src/HTTPServer/HTTPServer.cpp | 6 +++--- src/HTTPServer/HTTPServer.h | 10 ++++++---- src/HTTPServer/MultipartParser.cpp | 8 +++----- src/HTTPServer/MultipartParser.h | 38 ++++++++++++++++++++------------------ src/HTTPServer/NameValueParser.cpp | 8 ++++---- src/HTTPServer/NameValueParser.h | 4 ++-- src/WebAdmin.cpp | 4 ++-- src/WebAdmin.h | 10 +++++----- 16 files changed, 97 insertions(+), 90 deletions(-) diff --git a/src/HTTPServer/EnvelopeParser.cpp b/src/HTTPServer/EnvelopeParser.cpp index 8dbe05f14..fd4f3836d 100644 --- a/src/HTTPServer/EnvelopeParser.cpp +++ b/src/HTTPServer/EnvelopeParser.cpp @@ -20,7 +20,7 @@ cEnvelopeParser::cEnvelopeParser(cCallbacks & a_Callbacks) : -int cEnvelopeParser::Parse(const char * a_Data, int a_Size) +size_t cEnvelopeParser::Parse(const char * a_Data, size_t a_Size) { if (!m_IsInHeaders) { @@ -55,7 +55,7 @@ int cEnvelopeParser::Parse(const char * a_Data, int a_Size) { // An error has occurred m_IsInHeaders = false; - return -1; + return AString::npos; } Last = idxCRLF + 2; idxCRLF = m_IncomingData.find("\r\n", idxCRLF + 2); diff --git a/src/HTTPServer/EnvelopeParser.h b/src/HTTPServer/EnvelopeParser.h index 6430fbebf..9b6c7f369 100644 --- a/src/HTTPServer/EnvelopeParser.h +++ b/src/HTTPServer/EnvelopeParser.h @@ -19,7 +19,9 @@ public: class cCallbacks { public: - /// Called when a full header line is parsed + virtual ~cCallbacks() {} + + /** Called when a full header line is parsed */ virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) = 0; } ; @@ -27,40 +29,41 @@ public: cEnvelopeParser(cCallbacks & a_Callbacks); /** Parses the incoming data. - Returns the number of bytes consumed from the input. The bytes not consumed are not part of the envelope header + Returns the number of bytes consumed from the input. The bytes not consumed are not part of the envelope header. + Returns AString::npos on error */ - int Parse(const char * a_Data, int a_Size); + size_t Parse(const char * a_Data, size_t a_Size); - /// Makes the parser forget everything parsed so far, so that it can be reused for parsing another datastream + /** Makes the parser forget everything parsed so far, so that it can be reused for parsing another datastream */ void Reset(void); - /// Returns true if more input is expected for the envelope header + /** Returns true if more input is expected for the envelope header */ bool IsInHeaders(void) const { return m_IsInHeaders; } - /// Sets the IsInHeaders flag; used by cMultipartParser to simplify the parser initial conditions + /** Sets the IsInHeaders flag; used by cMultipartParser to simplify the parser initial conditions */ void SetIsInHeaders(bool a_IsInHeaders) { m_IsInHeaders = a_IsInHeaders; } public: - /// Callbacks to call for the various events + /** Callbacks to call for the various events */ cCallbacks & m_Callbacks; - /// Set to true while the parser is still parsing the envelope headers. Once set to true, the parser will not consume any more data. + /** Set to true while the parser is still parsing the envelope headers. Once set to true, the parser will not consume any more data. */ bool m_IsInHeaders; - /// Buffer for the incoming data until it is parsed + /** Buffer for the incoming data until it is parsed */ AString m_IncomingData; - /// Holds the last parsed key; used for line-wrapped values + /** Holds the last parsed key; used for line-wrapped values */ AString m_LastKey; - /// Holds the last parsed value; used for line-wrapped values + /** Holds the last parsed value; used for line-wrapped values */ AString m_LastValue; - /// Notifies the callback of the key/value stored in m_LastKey/m_LastValue, then erases them + /** Notifies the callback of the key/value stored in m_LastKey/m_LastValue, then erases them */ void NotifyLast(void); - /// Parses one line of header data. Returns true if successful + /** Parses one line of header data. Returns true if successful */ bool ParseLine(const char * a_Data, size_t a_Size); } ; diff --git a/src/HTTPServer/HTTPConnection.cpp b/src/HTTPServer/HTTPConnection.cpp index 78b7ce4d9..b8635d893 100644 --- a/src/HTTPServer/HTTPConnection.cpp +++ b/src/HTTPServer/HTTPConnection.cpp @@ -67,7 +67,7 @@ void cHTTPConnection::Send(const cHTTPResponse & a_Response) -void cHTTPConnection::Send(const void * a_Data, int a_Size) +void cHTTPConnection::Send(const void * a_Data, size_t a_Size) { ASSERT(m_State == wcsSendingResp); AppendPrintf(m_OutgoingData, "%x\r\n", a_Size); @@ -155,8 +155,8 @@ void cHTTPConnection::DataReceived(const char * a_Data, int a_Size) m_CurrentRequest = new cHTTPRequest; } - int BytesConsumed = m_CurrentRequest->ParseHeaders(a_Data, a_Size); - if (BytesConsumed < 0) + size_t BytesConsumed = m_CurrentRequest->ParseHeaders(a_Data, a_Size); + if (BytesConsumed == AString::npos) { delete m_CurrentRequest; m_CurrentRequest = NULL; @@ -174,16 +174,16 @@ void cHTTPConnection::DataReceived(const char * a_Data, int a_Size) m_State = wcsRecvBody; m_HTTPServer.NewRequest(*this, *m_CurrentRequest); m_CurrentRequestBodyRemaining = m_CurrentRequest->GetContentLength(); - if (m_CurrentRequestBodyRemaining < 0) + if (m_CurrentRequestBodyRemaining == AString::npos) { // The body length was not specified in the request, assume zero m_CurrentRequestBodyRemaining = 0; } // Process the rest of the incoming data into the request body: - if (a_Size > BytesConsumed) + if (a_Size > (int)BytesConsumed) { - DataReceived(a_Data + BytesConsumed, a_Size - BytesConsumed); + DataReceived(a_Data + BytesConsumed, a_Size - (int)BytesConsumed); } else { @@ -197,7 +197,7 @@ void cHTTPConnection::DataReceived(const char * a_Data, int a_Size) ASSERT(m_CurrentRequest != NULL); if (m_CurrentRequestBodyRemaining > 0) { - int BytesToConsume = std::min(m_CurrentRequestBodyRemaining, a_Size); + size_t BytesToConsume = std::min(m_CurrentRequestBodyRemaining, (size_t)a_Size); m_HTTPServer.RequestBody(*this, *m_CurrentRequest, a_Data, BytesToConsume); m_CurrentRequestBodyRemaining -= BytesToConsume; } diff --git a/src/HTTPServer/HTTPConnection.h b/src/HTTPServer/HTTPConnection.h index 5b8103554..0ad409c51 100644 --- a/src/HTTPServer/HTTPConnection.h +++ b/src/HTTPServer/HTTPConnection.h @@ -51,7 +51,7 @@ public: void Send(const cHTTPResponse & a_Response); /** Sends the data as the response (may be called multiple times) */ - void Send(const void * a_Data, int a_Size); + void Send(const void * a_Data, size_t a_Size); /** Sends the data as the response (may be called multiple times) */ void Send(const AString & a_Data) { Send(a_Data.data(), a_Data.size()); } @@ -87,7 +87,7 @@ protected: /** Number of bytes that remain to read for the complete body of the message to be received. Valid only in wcsRecvBody */ - int m_CurrentRequestBodyRemaining; + size_t m_CurrentRequestBodyRemaining; // cSocketThreads::cCallback overrides: diff --git a/src/HTTPServer/HTTPFormParser.cpp b/src/HTTPServer/HTTPFormParser.cpp index e661ea6f9..14d97bb7d 100644 --- a/src/HTTPServer/HTTPFormParser.cpp +++ b/src/HTTPServer/HTTPFormParser.cpp @@ -243,7 +243,7 @@ void cHTTPFormParser::OnPartHeader(const AString & a_Key, const AString & a_Valu -void cHTTPFormParser::OnPartData(const char * a_Data, int a_Size) +void cHTTPFormParser::OnPartData(const char * a_Data, size_t a_Size) { if (m_CurrentPartName.empty()) { diff --git a/src/HTTPServer/HTTPFormParser.h b/src/HTTPServer/HTTPFormParser.h index a554ca5a4..b8e6d246c 100644 --- a/src/HTTPServer/HTTPFormParser.h +++ b/src/HTTPServer/HTTPFormParser.h @@ -40,7 +40,7 @@ public: virtual void OnFileStart(cHTTPFormParser & a_Parser, const AString & a_FileName) = 0; /// Called when more file data has come for the current file in the form data - virtual void OnFileData(cHTTPFormParser & a_Parser, const char * a_Data, int a_Size) = 0; + virtual void OnFileData(cHTTPFormParser & a_Parser, const char * a_Data, size_t a_Size) = 0; /// Called when the current file part has ended in the form data virtual void OnFileEnd(cHTTPFormParser & a_Parser) = 0; @@ -103,7 +103,7 @@ protected: // cMultipartParser::cCallbacks overrides: virtual void OnPartStart (void) override; virtual void OnPartHeader(const AString & a_Key, const AString & a_Value) override; - virtual void OnPartData (const char * a_Data, int a_Size) override; + virtual void OnPartData (const char * a_Data, size_t a_Size) override; virtual void OnPartEnd (void) override; } ; diff --git a/src/HTTPServer/HTTPMessage.cpp b/src/HTTPServer/HTTPMessage.cpp index 98627eb8e..4a3611050 100644 --- a/src/HTTPServer/HTTPMessage.cpp +++ b/src/HTTPServer/HTTPMessage.cpp @@ -25,7 +25,7 @@ cHTTPMessage::cHTTPMessage(eKind a_Kind) : m_Kind(a_Kind), - m_ContentLength(-1) + m_ContentLength(AString::npos) { } @@ -81,23 +81,23 @@ cHTTPRequest::cHTTPRequest(void) : -int cHTTPRequest::ParseHeaders(const char * a_Data, int a_Size) +size_t cHTTPRequest::ParseHeaders(const char * a_Data, size_t a_Size) { if (!m_IsValid) { - return -1; + return AString::npos; } if (m_Method.empty()) { // The first line hasn't been processed yet - int res = ParseRequestLine(a_Data, a_Size); - if ((res < 0) || (res == a_Size)) + size_t res = ParseRequestLine(a_Data, a_Size); + if ((res == AString::npos) || (res == a_Size)) { return res; } - int res2 = m_EnvelopeParser.Parse(a_Data + res, a_Size - res); - if (res2 < 0) + size_t res2 = m_EnvelopeParser.Parse(a_Data + res, a_Size - res); + if (res2 == AString::npos) { m_IsValid = false; return res2; @@ -107,8 +107,8 @@ int cHTTPRequest::ParseHeaders(const char * a_Data, int a_Size) if (m_EnvelopeParser.IsInHeaders()) { - int res = m_EnvelopeParser.Parse(a_Data, a_Size); - if (res < 0) + size_t res = m_EnvelopeParser.Parse(a_Data, a_Size); + if (res == AString::npos) { m_IsValid = false; } @@ -138,7 +138,7 @@ AString cHTTPRequest::GetBareURL(void) const -int cHTTPRequest::ParseRequestLine(const char * a_Data, int a_Size) +size_t cHTTPRequest::ParseRequestLine(const char * a_Data, size_t a_Size) { m_IncomingHeaderData.append(a_Data, a_Size); size_t IdxEnd = m_IncomingHeaderData.size(); @@ -158,7 +158,7 @@ int cHTTPRequest::ParseRequestLine(const char * a_Data, int a_Size) if (LineStart >= IdxEnd) { m_IsValid = false; - return -1; + return AString::npos; } int NumSpaces = 0; @@ -186,7 +186,7 @@ int cHTTPRequest::ParseRequestLine(const char * a_Data, int a_Size) { // Too many spaces in the request m_IsValid = false; - return -1; + return AString::npos; } } NumSpaces += 1; @@ -198,13 +198,13 @@ int cHTTPRequest::ParseRequestLine(const char * a_Data, int a_Size) { // LF too early, without a CR, without two preceeding spaces or too soon after the second space m_IsValid = false; - return -1; + return AString::npos; } // Check that there's HTTP/version at the end if (strncmp(a_Data + URLEnd + 1, "HTTP/1.", 7) != 0) { m_IsValid = false; - return -1; + return AString::npos; } m_Method = m_IncomingHeaderData.substr(LineStart, MethodEnd - LineStart); m_URL = m_IncomingHeaderData.substr(MethodEnd + 1, URLEnd - MethodEnd - 1); diff --git a/src/HTTPServer/HTTPMessage.h b/src/HTTPServer/HTTPMessage.h index ab3338db7..d4d96f7cb 100644 --- a/src/HTTPServer/HTTPMessage.h +++ b/src/HTTPServer/HTTPMessage.h @@ -42,7 +42,7 @@ public: void SetContentLength(int a_ContentLength) { m_ContentLength = a_ContentLength; } const AString & GetContentType (void) const { return m_ContentType; } - int GetContentLength(void) const { return m_ContentLength; } + size_t GetContentLength(void) const { return m_ContentLength; } protected: typedef std::map cNameValueMap; @@ -54,8 +54,10 @@ protected: /** Type of the content; parsed by AddHeader(), set directly by SetContentLength() */ AString m_ContentType; - /** Length of the content that is to be received. -1 when the object is created, parsed by AddHeader() or set directly by SetContentLength() */ - int m_ContentLength; + /** Length of the content that is to be received. + AString::npos when the object is created. + Parsed by AddHeader() or set directly by SetContentLength() */ + size_t m_ContentLength; } ; @@ -72,9 +74,9 @@ public: cHTTPRequest(void); /** Parses the request line and then headers from the received data. - Returns the number of bytes consumed or a negative number for error + Returns the number of bytes consumed or AString::npos number for error */ - int ParseHeaders(const char * a_Data, int a_Size); + size_t ParseHeaders(const char * a_Data, size_t a_Size); /** Returns true if the request did contain a Content-Length header */ bool HasReceivedContentLength(void) const { return (m_ContentLength >= 0); } @@ -145,7 +147,7 @@ protected: /** Parses the incoming data for the first line (RequestLine) Returns the number of bytes consumed, or -1 for an error */ - int ParseRequestLine(const char * a_Data, int a_Size); + size_t ParseRequestLine(const char * a_Data, size_t a_Size); // cEnvelopeParser::cCallbacks overrides: virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) override; diff --git a/src/HTTPServer/HTTPServer.cpp b/src/HTTPServer/HTTPServer.cpp index 4e9195a00..eaf8405a3 100644 --- a/src/HTTPServer/HTTPServer.cpp +++ b/src/HTTPServer/HTTPServer.cpp @@ -38,7 +38,7 @@ class cDebugCallbacks : } - virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) override + virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) override { UNUSED(a_Connection); @@ -100,7 +100,7 @@ class cDebugCallbacks : } - virtual void OnFileData(cHTTPFormParser & a_Parser, const char * a_Data, int a_Size) override + virtual void OnFileData(cHTTPFormParser & a_Parser, const char * a_Data, size_t a_Size) override { // TODO } @@ -242,7 +242,7 @@ void cHTTPServer::NewRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Re -void cHTTPServer::RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) +void cHTTPServer::RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) { m_Callbacks->OnRequestBody(a_Connection, a_Request, a_Data, a_Size); } diff --git a/src/HTTPServer/HTTPServer.h b/src/HTTPServer/HTTPServer.h index 383abb4b6..8eff7d879 100644 --- a/src/HTTPServer/HTTPServer.h +++ b/src/HTTPServer/HTTPServer.h @@ -44,8 +44,9 @@ public: */ virtual void OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) = 0; - /// Called when another part of request body has arrived. - virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) = 0; + /** Called when another part of request body has arrived. + May be called multiple times for a single request. */ + virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) = 0; /// Called when the request body has been fully received in previous calls to OnRequestBody() virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) = 0; @@ -90,8 +91,9 @@ protected: /// Called by cHTTPConnection when it finishes parsing the request header void NewRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request); - /// Called by cHTTPConenction when it receives more data for the request body - void RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size); + /** Called by cHTTPConenction when it receives more data for the request body. + May be called multiple times for a single request. */ + void RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size); /// Called by cHTTPConnection when it detects that the request has finished (all of its body has been received) void RequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request); diff --git a/src/HTTPServer/MultipartParser.cpp b/src/HTTPServer/MultipartParser.cpp index 14c2c00fa..309495dd7 100644 --- a/src/HTTPServer/MultipartParser.cpp +++ b/src/HTTPServer/MultipartParser.cpp @@ -97,8 +97,6 @@ cMultipartParser::cMultipartParser(const AString & a_ContentType, cCallbacks & a m_EnvelopeParser(*this), m_HasHadData(false) { - static AString s_Multipart = "multipart/"; - // Check that the content type is multipart: AString ContentType(a_ContentType); if (strncmp(ContentType.c_str(), "multipart/", 10) != 0) @@ -146,7 +144,7 @@ cMultipartParser::cMultipartParser(const AString & a_ContentType, cCallbacks & a -void cMultipartParser::Parse(const char * a_Data, int a_Size) +void cMultipartParser::Parse(const char * a_Data, size_t a_Size) { // Skip parsing if invalid if (!m_IsValid) @@ -160,8 +158,8 @@ void cMultipartParser::Parse(const char * a_Data, int a_Size) { if (m_EnvelopeParser.IsInHeaders()) { - int BytesConsumed = m_EnvelopeParser.Parse(m_IncomingData.data(), m_IncomingData.size()); - if (BytesConsumed < 0) + size_t BytesConsumed = m_EnvelopeParser.Parse(m_IncomingData.data(), m_IncomingData.size()); + if (BytesConsumed == AString::npos) { m_IsValid = false; return; diff --git a/src/HTTPServer/MultipartParser.h b/src/HTTPServer/MultipartParser.h index d853929ed..a7395c1cb 100644 --- a/src/HTTPServer/MultipartParser.h +++ b/src/HTTPServer/MultipartParser.h @@ -22,50 +22,52 @@ public: class cCallbacks { public: - /// Called when a new part starts + virtual ~cCallbacks() {} + + /** Called when a new part starts */ virtual void OnPartStart(void) = 0; - /// Called when a complete header line is received for a part + /** Called when a complete header line is received for a part */ virtual void OnPartHeader(const AString & a_Key, const AString & a_Value) = 0; - /// Called when body for a part is received - virtual void OnPartData(const char * a_Data, int a_Size) = 0; + /** Called when body for a part is received */ + virtual void OnPartData(const char * a_Data, size_t a_Size) = 0; - /// Called when the current part ends + /** Called when the current part ends */ virtual void OnPartEnd(void) = 0; } ; - /// Creates the parser, expects to find the boundary in a_ContentType + /** Creates the parser, expects to find the boundary in a_ContentType */ cMultipartParser(const AString & a_ContentType, cCallbacks & a_Callbacks); - /// Parses more incoming data - void Parse(const char * a_Data, int a_Size); + /** Parses more incoming data */ + void Parse(const char * a_Data, size_t a_Size); protected: - /// The callbacks to call for various parsing events + /** The callbacks to call for various parsing events */ cCallbacks & m_Callbacks; - /// True if the data parsed so far is valid; if false, further parsing is skipped + /** True if the data parsed so far is valid; if false, further parsing is skipped */ bool m_IsValid; - /// Parser for each part's envelope + /** Parser for each part's envelope */ cEnvelopeParser m_EnvelopeParser; - /// Buffer for the incoming data until it is parsed + /** Buffer for the incoming data until it is parsed */ AString m_IncomingData; - /// The boundary, excluding both the initial "--" and the terminating CRLF + /** The boundary, excluding both the initial "--" and the terminating CRLF */ AString m_Boundary; - /// Set to true if some data for the current part has already been signalized to m_Callbacks. Used for proper CRLF inserting. + /** Set to true if some data for the current part has already been signalized to m_Callbacks. Used for proper CRLF inserting. */ bool m_HasHadData; - /// Parse one line of incoming data. The CRLF has already been stripped from a_Data / a_Size - void ParseLine(const char * a_Data, int a_Size); + /** Parse one line of incoming data. The CRLF has already been stripped from a_Data / a_Size */ + void ParseLine(const char * a_Data, size_t a_Size); - /// Parse one line of incoming data in the headers section of a part. The CRLF has already been stripped from a_Data / a_Size - void ParseHeaderLine(const char * a_Data, int a_Size); + /** Parse one line of incoming data in the headers section of a part. The CRLF has already been stripped from a_Data / a_Size */ + void ParseHeaderLine(const char * a_Data, size_t a_Size); // cEnvelopeParser overrides: virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) override; diff --git a/src/HTTPServer/NameValueParser.cpp b/src/HTTPServer/NameValueParser.cpp index 9ea8594ae..3f6c17dda 100644 --- a/src/HTTPServer/NameValueParser.cpp +++ b/src/HTTPServer/NameValueParser.cpp @@ -24,7 +24,7 @@ public: // Now try parsing char-by-char, to debug transitions across datachunk boundaries: cNameValueParser Parser2; - for (int i = 0; i < sizeof(Data) - 1; i++) + for (size_t i = 0; i < sizeof(Data) - 1; i++) { Parser2.Parse(Data + i, 1); } @@ -82,7 +82,7 @@ cNameValueParser::cNameValueParser(bool a_AllowsKeyOnly) : -cNameValueParser::cNameValueParser(const char * a_Data, int a_Size, bool a_AllowsKeyOnly) : +cNameValueParser::cNameValueParser(const char * a_Data, size_t a_Size, bool a_AllowsKeyOnly) : m_State(psKeySpace), m_AllowsKeyOnly(a_AllowsKeyOnly) { @@ -93,12 +93,12 @@ cNameValueParser::cNameValueParser(const char * a_Data, int a_Size, bool a_Allow -void cNameValueParser::Parse(const char * a_Data, int a_Size) +void cNameValueParser::Parse(const char * a_Data, size_t a_Size) { ASSERT(m_State != psFinished); // Calling Parse() after Finish() is wrong! int Last = 0; - for (int i = 0; i < a_Size;) + for (size_t i = 0; i < a_Size;) { switch (m_State) { diff --git a/src/HTTPServer/NameValueParser.h b/src/HTTPServer/NameValueParser.h index 07dc0b942..9794614fa 100644 --- a/src/HTTPServer/NameValueParser.h +++ b/src/HTTPServer/NameValueParser.h @@ -21,10 +21,10 @@ public: cNameValueParser(bool a_AllowsKeyOnly = true); /// Creates an empty parser, then parses the data given. Doesn't call Finish(), so more data can be parsed later - cNameValueParser(const char * a_Data, int a_Size, bool a_AllowsKeyOnly = true); + cNameValueParser(const char * a_Data, size_t a_Size, bool a_AllowsKeyOnly = true); /// Parses the data given - void Parse(const char * a_Data, int a_Size); + void Parse(const char * a_Data, size_t a_Size); /// Notifies the parser that no more data will be coming. Returns true if the parser state is valid bool Finish(void); diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp index 402cd3035..cd141f7eb 100644 --- a/src/WebAdmin.cpp +++ b/src/WebAdmin.cpp @@ -490,7 +490,7 @@ void cWebAdmin::OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_ -void cWebAdmin::OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) +void cWebAdmin::OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) { UNUSED(a_Connection); cRequestData * Data = (cRequestData *)(a_Request.GetUserData()); @@ -537,7 +537,7 @@ void cWebAdmin::OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cWebAdmin::cWebadminRequestData -void cWebAdmin::cWebadminRequestData::OnBody(const char * a_Data, int a_Size) +void cWebAdmin::cWebadminRequestData::OnBody(const char * a_Data, size_t a_Size) { m_Form.Parse(a_Data, a_Size); } diff --git a/src/WebAdmin.h b/src/WebAdmin.h index a2a07a543..d5e45828f 100644 --- a/src/WebAdmin.h +++ b/src/WebAdmin.h @@ -151,7 +151,7 @@ protected: virtual ~cRequestData() {} // Force a virtual destructor in all descendants /** Called when a new chunk of body data is received */ - virtual void OnBody(const char * a_Data, int a_Size) = 0; + virtual void OnBody(const char * a_Data, size_t a_Size) = 0; } ; /** The body handler for requests in the "/webadmin" and "/~webadmin" paths */ @@ -169,14 +169,14 @@ protected: } // cRequestData overrides: - virtual void OnBody(const char * a_Data, int a_Size) override; + virtual void OnBody(const char * a_Data, size_t a_Size) override; // cHTTPFormParser::cCallbacks overrides. Files are ignored: - virtual void OnFileStart(cHTTPFormParser &, const AString & a_FileName) override + virtual void OnFileStart(cHTTPFormParser &, const AString & a_FileName) override { UNUSED(a_FileName); } - virtual void OnFileData(cHTTPFormParser &, const char * a_Data, int a_Size) override + virtual void OnFileData(cHTTPFormParser &, const char * a_Data, size_t a_Size) override { UNUSED(a_Data); UNUSED(a_Size); @@ -216,7 +216,7 @@ protected: // cHTTPServer::cCallbacks overrides: virtual void OnRequestBegun (cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override; - virtual void OnRequestBody (cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) override; + virtual void OnRequestBody (cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) override; virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override; } ; // tolua_export -- cgit v1.2.3 From 1229795ff0fd82412e780fffc9f37a2d6eed5522 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 20:50:10 +0200 Subject: cBlockArea: Added the msMask merge strategy. --- MCServer/Plugins/APIDump/APIDesc.lua | 23 ++++++++++++++++++++--- src/BlockArea.cpp | 30 ++++++++++++++++++++++++++++++ src/BlockArea.h | 9 +++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 28e7744ed..9bcd6edde 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -200,6 +200,8 @@ g_APIDesc = msFillAir = { Notes = "Dst is overwritten by Src only where Src has air blocks" }, msImprint = { Notes = "Src overwrites Dst anywhere where Dst has non-air blocks" }, msLake = { Notes = "Special mode for merging lake images" }, + msSpongePrint = { Notes = "Similar to msImprint, sponge block doesn't overwrite anything, all other blocks overwrite everything"}, + msMask = { Notes = "The blocks that are exactly the same are kept in Dst, all differing blocks are replaced by air"}, }, ConstantGroups = { @@ -293,7 +295,6 @@ g_APIDesc = -

    msSpongePrint - used for most prefab-generators to merge the prefabs. Similar to msImprint, but uses the sponge block as the NOP block instead, so that the prefabs may carve out air @@ -306,10 +307,26 @@ g_APIDesc = A sponge A Sponge is the NOP block - * B B Everything else overwrites anything + * B B Everything else overwrites anything - ]], + +

    + msMask - the blocks that are the same in the other area are kept, all the + differing blocks are replaced with air. Meta is used in the comparison, too, two blocks of the + same type but different meta are considered different and thus replaced with air. +

    + + + + + + + + + +
    area block Notes
    this Src result
    A A A Same blocks are kept
    A non-A air Differing blocks are replaced with air
    +]], }, -- Merge strategies }, -- AdditionalInfo }, -- cBlockArea diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 2b950378a..543dbe04d 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -173,6 +173,21 @@ static inline void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a +/** Combinator used for cBlockArea::msMask merging */ +static inline void MergeCombinatorMask(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +{ + // If the blocks are the same, keep the dest; otherwise replace with air + if ((a_SrcType != a_DstType) || (a_SrcMeta != a_DstMeta)) + { + a_DstType = E_BLOCK_AIR; + a_DstMeta = 0; + } +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cBlockArea: @@ -710,6 +725,21 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R break; } // case msSpongePrint + case msMask: + { + InternalMergeBlocks( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z, + MergeCombinatorMask + ); + break; + } // case msMask + default: { LOGWARNING("Unknown block area merge strategy: %d", a_Strategy); diff --git a/src/BlockArea.h b/src/BlockArea.h index d37f0d182..34a0ef926 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -52,6 +52,7 @@ public: msImprint, msLake, msSpongePrint, + msMask, } ; cBlockArea(void); @@ -152,6 +153,14 @@ public: +----------+--------+--------+ | A | sponge | A | Sponge is the NOP block | * | B | B | Everything else overwrites anything + + msMask: + Combines two areas, the blocks that are the same are kept, differing ones are reset to air + | area block | | + | this | Src | result | + +------+-------+--------+ + | A | A | A | Same blocks are kept + | A | non-A | air | Everything else is replaced with air */ void Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy); -- cgit v1.2.3 From 21e0607e49745f0a431fa045967cc45679ab22de Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 1 Apr 2014 21:12:48 +0200 Subject: APIDump: Gave msDifference it's own table. --- MCServer/Plugins/APIDump/APIDesc.lua | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 657ac6aa6..b01be6118 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -230,25 +230,25 @@ g_APIDesc =

    - + - + - + - + - + - + - +
    area blockresultarea blockresult
    this Src msOverwrite msFillAir msImprint msDifference this Src msOverwrite msFillAir msImprint
    air air air air air air air air air air air
    A air air A A air A air air A A
    air B B B B B air B B B B
    A B B A B B A B B A B
    A A A A B air A A A A A
    @@ -258,13 +258,25 @@ g_APIDesc =
  • msOverwrite completely overwrites all blocks with the Src's blocks
  • msFillAir overwrites only those blocks that were air
  • msImprint overwrites with only those blocks that are non-air
  • -
  • msDifference changes all the blocks which are the same to air. Otherwise the source block gets placed.
  • Special strategies

    For each strategy, evaluate the table rows from top downwards, the first match wins.

    - + +

    + msDifference - changes all the blocks which are the same to air. Otherwise the source block gets placed. +

    + + + + + + + +
    area block Notes
    * B B The blocks are different so we use block B
    B B Air The blocks are the same so we get air.
    + +

    msLake - used for merging areas with lava and water lakes, in the appropriate generator.

    -- cgit v1.2.3 From bcf5021feb3bbb8069b80e3b892f0c80db35a4c6 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 1 Apr 2014 22:47:39 +0200 Subject: Exported the Base64 encoding and decoding functions to Lua API. --- src/Bindings/ManualBindings.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ src/StringUtils.h | 4 ++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 9d1a367df..51b9f3e27 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -190,6 +190,50 @@ static int tolua_LOGERROR(lua_State * tolua_S) +static int tolua_Base64Encode(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if ( + !L.CheckParamString(1) || + !L.CheckParamEnd(2) + ) + { + return 0; + } + + AString Src; + L.GetStackValue(1, Src); + AString res = Base64Encode(Src); + L.Push(res); + return 1; +} + + + + + +static int tolua_Base64Decode(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if ( + !L.CheckParamString(1) || + !L.CheckParamEnd(2) + ) + { + return 0; + } + + AString Src; + L.GetStackValue(1, Src); + AString res = Base64Decode(Src); + L.Push(res); + return 1; +} + + + + + cPluginLua * GetLuaPlugin(lua_State * L) { // Get the plugin identification out of LuaState: @@ -2869,6 +2913,8 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "LOGWARN", tolua_LOGWARN); tolua_function(tolua_S, "LOGWARNING", tolua_LOGWARN); tolua_function(tolua_S, "LOGERROR", tolua_LOGERROR); + tolua_function(tolua_S, "Base64Encode", tolua_Base64Encode); + tolua_function(tolua_S, "Base64Decode", tolua_Base64Decode); tolua_beginmodule(tolua_S, "cFile"); tolua_function(tolua_S, "GetFolderContents", tolua_cFile_GetFolderContents); diff --git a/src/StringUtils.h b/src/StringUtils.h index 4feff7553..da395e5b5 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -79,10 +79,10 @@ extern AString URLDecode(const AString & a_String); // Cannot export to Lua aut extern AString ReplaceAllCharOccurrences(const AString & a_String, char a_From, char a_To); // Needn't export to Lua, since Lua doesn't have chars anyway /// Decodes a Base64-encoded string into the raw data -extern AString Base64Decode(const AString & a_Base64String); +extern AString Base64Decode(const AString & a_Base64String); // Exported manually due to embedded NULs and extra parameter /// Encodes a string into Base64 -extern AString Base64Encode(const AString & a_Input); +extern AString Base64Encode(const AString & a_Input); // Exported manually due to embedded NULs and extra parameter /// Reads two bytes from the specified memory location and interprets them as BigEndian short extern short GetBEShort(const char * a_Mem); -- cgit v1.2.3 From 3301c5be1ff9d26d3189c031eb28e5f46c9edccd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 2 Apr 2014 11:56:10 +0200 Subject: Fixed StringCompression's GZIP handling for larger strings. --- src/StringCompression.cpp | 8 +++++--- src/StringCompression.h | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/StringCompression.cpp b/src/StringCompression.cpp index 5b9a3bb0a..2a85649a1 100644 --- a/src/StringCompression.cpp +++ b/src/StringCompression.cpp @@ -53,7 +53,7 @@ int UncompressString(const char * a_Data, int a_Length, AString & a_Uncompressed -int CompressStringGZIP(const char * a_Data, int a_Length, AString & a_Compressed) +int CompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_Compressed) { // Compress a_Data into a_Compressed using GZIP; return Z_XXX error constants same as zlib's compress2() @@ -83,6 +83,7 @@ int CompressStringGZIP(const char * a_Data, int a_Length, AString & a_Compressed { // Some data has been compressed. Consume the buffer and continue compressing a_Compressed.append(Buffer, sizeof(Buffer) - strm.avail_out); + strm.next_out = (Bytef *)Buffer; strm.avail_out = sizeof(Buffer); if (strm.avail_in == 0) { @@ -116,7 +117,7 @@ int CompressStringGZIP(const char * a_Data, int a_Length, AString & a_Compressed -extern int UncompressStringGZIP(const char * a_Data, int a_Length, AString & a_Uncompressed) +extern int UncompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_Uncompressed) { // Uncompresses a_Data into a_Uncompressed using GZIP; returns Z_OK for success or Z_XXX error constants same as zlib @@ -139,13 +140,14 @@ extern int UncompressStringGZIP(const char * a_Data, int a_Length, AString & a_U for (;;) { - res = inflate(&strm, Z_FINISH); + res = inflate(&strm, Z_NO_FLUSH); switch (res) { case Z_OK: { // Some data has been uncompressed. Consume the buffer and continue uncompressing a_Uncompressed.append(Buffer, sizeof(Buffer) - strm.avail_out); + strm.next_out = (Bytef *)Buffer; strm.avail_out = sizeof(Buffer); if (strm.avail_in == 0) { diff --git a/src/StringCompression.h b/src/StringCompression.h index 3f4e12d2d..c3a9eca91 100644 --- a/src/StringCompression.h +++ b/src/StringCompression.h @@ -16,10 +16,10 @@ extern int CompressString(const char * a_Data, int a_Length, AString & a_Compres extern int UncompressString(const char * a_Data, int a_Length, AString & a_Uncompressed, int a_UncompressedSize); /// Compresses a_Data into a_Compressed using GZIP; returns Z_OK for success or Z_XXX error constants same as zlib -extern int CompressStringGZIP(const char * a_Data, int a_Length, AString & a_Compressed); +extern int CompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_Compressed); /// Uncompresses a_Data into a_Uncompressed using GZIP; returns Z_OK for success or Z_XXX error constants same as zlib -extern int UncompressStringGZIP(const char * a_Data, int a_Length, AString & a_Uncompressed); +extern int UncompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_Uncompressed); -- cgit v1.2.3 From bcd7f9669ba98f4ecb71ba728d72836ff14b3c0f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 2 Apr 2014 11:56:27 +0200 Subject: Added schematic string serializer self-test. --- src/WorldStorage/SchematicFileSerializer.cpp | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp index d8531d965..9d594a084 100644 --- a/src/WorldStorage/SchematicFileSerializer.cpp +++ b/src/WorldStorage/SchematicFileSerializer.cpp @@ -14,6 +14,39 @@ +#ifdef SELF_TEST + +static class cSchematicStringSelfTest +{ +public: + cSchematicStringSelfTest(void) + { + cBlockArea ba; + ba.Create(21, 256, 21); + ba.RelLine(0, 0, 0, 9, 8, 7, cBlockArea::baTypes | cBlockArea::baMetas, E_BLOCK_WOODEN_STAIRS, 1); + AString Schematic; + if (!cSchematicFileSerializer::SaveToSchematicString(ba, Schematic)) + { + assert_test(!"Schematic failed to save!"); + } + cBlockArea ba2; + if (!cSchematicFileSerializer::LoadFromSchematicString(ba2, Schematic)) + { + assert_test(!"Schematic failed to load!"); + } + } +} g_SelfTest; + +#endif + + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSchematicFileSerializer: + bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName) { // Un-GZip the contents: -- cgit v1.2.3 From 67d7ad86896e90b799a0479a86a6e764c7fe36da Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 2 Apr 2014 11:58:19 +0200 Subject: Debuggers: Added a Base64 API roundtrip test. --- MCServer/Plugins/Debuggers/Debuggers.lua | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 2619bd6c4..064d5d772 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -69,12 +69,13 @@ function Initialize(Plugin) LOG("Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) - -- TestBlockAreas(); - -- TestSQLiteBindings(); - -- TestExpatBindings(); - -- TestPluginCalls(); + -- TestBlockAreas() + -- TestSQLiteBindings() + -- TestExpatBindings() + -- TestPluginCalls() TestBlockAreasString() + TestStringBase64() --[[ -- Test cCompositeChat usage in console-logging: @@ -252,6 +253,24 @@ end +function TestStringBase64() + -- Create a binary string: + local s = "" + for i = 0, 255 do + s = s .. string.char(i) + end + + -- Roundtrip through Base64: + local Base64 = Base64Encode(s) + local UnBase64 = Base64Decode(Base64) + + assert(UnBase64 == s) +end + + + + + function TestSQLiteBindings() LOG("Testing SQLite bindings..."); -- cgit v1.2.3 From 93bb5369a89eeda9c456574d8a72ebcac095ddd0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 2 Apr 2014 05:06:38 -0700 Subject: Fixed Comparison to -1 in HTTPMessage.h --- src/HTTPServer/HTTPMessage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HTTPServer/HTTPMessage.h b/src/HTTPServer/HTTPMessage.h index d4d96f7cb..c2d310839 100644 --- a/src/HTTPServer/HTTPMessage.h +++ b/src/HTTPServer/HTTPMessage.h @@ -79,7 +79,7 @@ public: size_t ParseHeaders(const char * a_Data, size_t a_Size); /** Returns true if the request did contain a Content-Length header */ - bool HasReceivedContentLength(void) const { return (m_ContentLength >= 0); } + bool HasReceivedContentLength(void) const { return (m_ContentLength != AString::npos); } /** Returns the method used in the request */ const AString & GetMethod(void) const { return m_Method; } -- cgit v1.2.3 From 7ece0cc8369a7600ea8667188e83a2cb9ef6570b Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 2 Apr 2014 05:10:08 -0700 Subject: Fixed format string in HTTPConnection --- src/HTTPServer/HTTPConnection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HTTPServer/HTTPConnection.cpp b/src/HTTPServer/HTTPConnection.cpp index b8635d893..6d238f028 100644 --- a/src/HTTPServer/HTTPConnection.cpp +++ b/src/HTTPServer/HTTPConnection.cpp @@ -70,7 +70,7 @@ void cHTTPConnection::Send(const cHTTPResponse & a_Response) void cHTTPConnection::Send(const void * a_Data, size_t a_Size) { ASSERT(m_State == wcsSendingResp); - AppendPrintf(m_OutgoingData, "%x\r\n", a_Size); + AppendPrintf(m_OutgoingData, SIZE_T_FMT "\r\n", a_Size); m_OutgoingData.append((const char *)a_Data, a_Size); m_OutgoingData.append("\r\n"); m_HTTPServer.NotifyConnectionWrite(*this); -- cgit v1.2.3 From 298c0b409ac01f17968ed3ff5dd6e2e901627e04 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 2 Apr 2014 06:04:17 -0700 Subject: Fixed tolua++ override support --- lib/tolua++/CMakeLists.txt | 7 +- lib/tolua++/src/bin/function_lua.h | 285 ++++---- lib/tolua++/src/bin/lua/container.lua | 21 +- lib/tolua++/src/bin/lua/function.lua | 4 +- lib/tolua++/src/bin/toluabind.c | 1166 +-------------------------------- 5 files changed, 164 insertions(+), 1319 deletions(-) diff --git a/lib/tolua++/CMakeLists.txt b/lib/tolua++/CMakeLists.txt index 75a301a53..4df698e89 100644 --- a/lib/tolua++/CMakeLists.txt +++ b/lib/tolua++/CMakeLists.txt @@ -24,8 +24,11 @@ if(UNIX) COMMAND xxd -i lua/declaration.lua | sed 's/unsigned char/static const unsigned char/g' >declaration_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/declaration.lua) - set_property(SOURCE src/bin/toluabind.c APPEND PROPERTY OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h ${PROJECT_SOURCE_DIR}/src/bin/declaration_lua.h) - message(hello) + add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/container_lua.h + COMMAND xxd -i lua/container.lua | sed 's/unsigned char/static const unsigned char/g' >container_lua.h + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ + DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/container.lua) + set_property(SOURCE src/bin/toluabind.c APPEND PROPERTY OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h ${PROJECT_SOURCE_DIR}/src/bin/declaration_lua.h ${PROJECT_SOURCE_DIR}/src/bin/container_lua.h) endif() diff --git a/lib/tolua++/src/bin/function_lua.h b/lib/tolua++/src/bin/function_lua.h index bcb0bfca2..b34f106d2 100644 --- a/lib/tolua++/src/bin/function_lua.h +++ b/lib/tolua++/src/bin/function_lua.h @@ -990,14 +990,15 @@ static const unsigned char lua_function_lua[] = { 0x5f, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x0a, 0x20, 0x69, - 0x66, 0x20, 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, - 0x20, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x61, 0x6e, 0x64, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, - 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x65, 0x72, - 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x20, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x73, 0x70, - 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, + 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x65, 0x72, 0x72, + 0x6f, 0x72, 0x28, 0x22, 0x23, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, + 0x20, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x73, 0x70, 0x65, + 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, + 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x3a, 0x69, 0x6e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, @@ -1072,139 +1073,139 @@ static const unsigned char lua_function_lua[] = { 0x0a, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, - 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, - 0x6e, 0x6f, 0x74, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x57, - 0x27, 0x5d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, - 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x2c, 0x20, 0x22, 0x25, - 0x2e, 0x25, 0x2e, 0x25, 0x2e, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x22, 0x29, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x77, 0x61, 0x72, - 0x6e, 0x69, 0x6e, 0x67, 0x28, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x76, 0x61, 0x72, - 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, - 0x6e, 0x74, 0x73, 0x20, 0x28, 0x60, 0x2e, 0x2e, 0x2e, 0x27, 0x29, 0x20, - 0x61, 0x72, 0x65, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x75, 0x70, 0x70, - 0x6f, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x49, 0x67, 0x6e, 0x6f, 0x72, - 0x69, 0x6e, 0x67, 0x20, 0x22, 0x2e, 0x2e, 0x64, 0x2e, 0x2e, 0x61, 0x2e, - 0x2e, 0x63, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, - 0x3d, 0x30, 0x7d, 0x0a, 0x0a, 0x20, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x61, - 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x25, 0x28, 0x25, 0x29, - 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x31, 0x22, - 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x73, - 0x74, 0x72, 0x69, 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, - 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, - 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, - 0x29, 0x29, 0x3b, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, - 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x74, 0x72, - 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x31, 0x2c, 0x2d, 0x32, 0x29, 0x2c, - 0x20, 0x31, 0x2c, 0x20, 0x2d, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x6c, 0x65, 0x6e, 0x28, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x2b, 0x31, - 0x29, 0x29, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, - 0x73, 0x20, 0x3d, 0x20, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, - 0x22, 0x2c, 0x22, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, - 0x2d, 0x31, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6e, 0x73, 0x20, 0x3d, 0x20, - 0x22, 0x28, 0x22, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, - 0x67, 0x73, 0x75, 0x62, 0x28, 0x6e, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, - 0x2a, 0x2c, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, - 0x2e, 0x2e, 0x27, 0x29, 0x27, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6e, 0x73, - 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, - 0x61, 0x75, 0x6c, 0x74, 0x73, 0x28, 0x6e, 0x73, 0x29, 0x0a, 0x0a, 0x09, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x46, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x20, 0x6e, - 0x73, 0x2c, 0x20, 0x63, 0x29, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, - 0x69, 0x3d, 0x31, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, - 0x09, 0x09, 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, - 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, - 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, - 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, - 0x20, 0x3d, 0x20, 0x6c, 0x2e, 0x6e, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x6c, - 0x5b, 0x6c, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, - 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x5b, 0x69, 0x5d, - 0x2c, 0x27, 0x76, 0x61, 0x72, 0x27, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, - 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, - 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x29, - 0x0a, 0x20, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x6c, - 0x0a, 0x20, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, - 0x63, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x46, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x66, 0x29, 0x0a, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x20, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x70, - 0x2c, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2c, 0x20, 0x6c, 0x61, 0x73, - 0x74, 0x29, 0x0a, 0x0a, 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x3d, - 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x31, 0x0a, - 0x09, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x6c, 0x61, 0x73, 0x74, - 0x20, 0x6f, 0x72, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x67, 0x65, - 0x74, 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x6c, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, - 0x22, 0x22, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x6f, - 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, - 0x66, 0x6f, 0x72, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x72, 0x73, - 0x74, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, - 0x09, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, - 0x6c, 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, - 0x09, 0x6c, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x70, 0x0a, - 0x09, 0x09, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, - 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, - 0x6f, 0x74, 0x20, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, - 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, - 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x73, 0x28, 0x73, 0x2c, 0x20, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, - 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x09, 0x66, 0x6f, 0x72, - 0x20, 0x69, 0x3d, 0x74, 0x2e, 0x6e, 0x2c, 0x31, 0x2c, 0x2d, 0x31, 0x20, - 0x64, 0x6f, 0x0a, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, - 0x61, 0x72, 0x61, 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, - 0x74, 0x5b, 0x69, 0x5d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x09, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x0a, 0x09, - 0x09, 0x09, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, - 0x75, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x2d, - 0x2d, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x09, 0x74, 0x5b, 0x69, 0x5d, - 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, - 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, - 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x2d, - 0x2d, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, - 0x69, 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, - 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, - 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x28, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, - 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x29, - 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, - 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, - 0x2c, 0x20, 0x22, 0x2c, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x73, 0x65, 0x70, 0x2c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, - 0x20, 0x22, 0x22, 0x2c, 0x22, 0x22, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, - 0x69, 0x3d, 0x31, 0x2c, 0x74, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x09, - 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, - 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, - 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, - 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, - 0x74, 0x2e, 0x2e, 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, - 0x0a, 0x09, 0x09, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x2c, 0x22, - 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x22, 0x28, 0x22, 0x2e, 0x2e, 0x72, 0x65, 0x74, 0x2e, - 0x2e, 0x22, 0x29, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a + 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x57, 0x27, + 0x5d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x2c, 0x20, 0x22, 0x25, 0x2e, + 0x25, 0x2e, 0x25, 0x2e, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x22, 0x29, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x77, 0x61, 0x72, 0x6e, + 0x69, 0x6e, 0x67, 0x28, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x76, 0x61, 0x72, 0x69, + 0x61, 0x62, 0x6c, 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, + 0x74, 0x73, 0x20, 0x28, 0x60, 0x2e, 0x2e, 0x2e, 0x27, 0x29, 0x20, 0x61, + 0x72, 0x65, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, + 0x72, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x69, + 0x6e, 0x67, 0x20, 0x22, 0x2e, 0x2e, 0x64, 0x2e, 0x2e, 0x61, 0x2e, 0x2e, + 0x63, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, + 0x30, 0x7d, 0x0a, 0x0a, 0x20, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, + 0x20, 0x22, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x25, 0x28, 0x25, 0x29, 0x5d, + 0x29, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x31, 0x22, 0x29, + 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x73, 0x74, + 0x72, 0x69, 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, + 0x29, 0x3b, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x74, 0x72, 0x73, + 0x75, 0x62, 0x28, 0x61, 0x2c, 0x31, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x20, + 0x31, 0x2c, 0x20, 0x2d, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x6c, 0x65, 0x6e, 0x28, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x2b, 0x31, 0x29, + 0x29, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, + 0x20, 0x3d, 0x20, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x22, + 0x2c, 0x22, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x2d, + 0x31, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x22, + 0x28, 0x22, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, + 0x73, 0x75, 0x62, 0x28, 0x6e, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, + 0x2c, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x2e, + 0x2e, 0x27, 0x29, 0x27, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6e, 0x73, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, + 0x75, 0x6c, 0x74, 0x73, 0x28, 0x6e, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x46, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x20, 0x6e, 0x73, + 0x2c, 0x20, 0x63, 0x29, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, + 0x3d, 0x31, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x09, + 0x09, 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, + 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, + 0x22, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, + 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, 0x20, + 0x3d, 0x20, 0x6c, 0x2e, 0x6e, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x6c, 0x5b, + 0x6c, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, + 0x27, 0x76, 0x61, 0x72, 0x27, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, 0x0a, + 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, + 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x28, 0x64, 0x2c, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x29, 0x0a, + 0x20, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x6c, 0x0a, + 0x20, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x63, + 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x46, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x66, 0x29, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x70, 0x2c, + 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, + 0x29, 0x0a, 0x0a, 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x31, 0x0a, 0x09, + 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x20, + 0x6f, 0x72, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x67, 0x65, 0x74, + 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6c, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x22, + 0x22, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x6f, 0x6f, + 0x70, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x66, + 0x6f, 0x72, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, + 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, 0x09, + 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x6c, + 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, 0x09, + 0x6c, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x70, 0x0a, 0x09, + 0x09, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x72, 0x65, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, + 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, + 0x28, 0x73, 0x2c, 0x20, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, + 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, + 0x69, 0x3d, 0x74, 0x2e, 0x6e, 0x2c, 0x31, 0x2c, 0x2d, 0x31, 0x20, 0x64, + 0x6f, 0x0a, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, 0x74, + 0x5b, 0x69, 0x5d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x09, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x0a, 0x09, 0x09, + 0x09, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, + 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x2d, 0x2d, + 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, + 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x2d, 0x2d, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, 0x69, + 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x73, + 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, + 0x20, 0x22, 0x5e, 0x25, 0x28, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, + 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x29, 0x24, + 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, + 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, + 0x20, 0x22, 0x2c, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x73, 0x65, 0x70, 0x2c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, + 0x22, 0x22, 0x2c, 0x22, 0x22, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, + 0x3d, 0x31, 0x2c, 0x74, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, + 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, + 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, + 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, + 0x2e, 0x2e, 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, + 0x09, 0x09, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x2c, 0x22, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x22, 0x28, 0x22, 0x2e, 0x2e, 0x72, 0x65, 0x74, 0x2e, 0x2e, + 0x22, 0x29, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a }; -unsigned int lua_function_lua_len = 14483; +unsigned int lua_function_lua_len = 14494; diff --git a/lib/tolua++/src/bin/lua/container.lua b/lib/tolua++/src/bin/lua/container.lua index 97e7b58fd..99488479e 100644 --- a/lib/tolua++/src/bin/lua/container.lua +++ b/lib/tolua++/src/bin/lua/container.lua @@ -58,7 +58,7 @@ function classContainer:hasvar () while self[i] do if self[i]:isvariable() then return 1 - end + end i = i+1 end return 0 @@ -568,7 +568,7 @@ function classContainer:doparse (s) -- Enumerate(name,body) -- return strsub(s,e+1) -- end --- end +-- end do local b,e,body,name = strfind(s,"^%s*typedef%s+enum[^{]*(%b{})%s*([%w_][^%s]*)%s*;%s*") @@ -606,15 +606,14 @@ function classContainer:doparse (s) -- try function do --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w])%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*") - local b,e,decl,arg,const,virt = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)%s*o?v?e?r?i?d?e?%s*(=?%s*0?)%s*;%s*") - warning("trace" .. b .. "," .. e "," .. decl) + local b,e,decl,arg,const,virt = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?%s*(=?%s*0?)%s*;%s*") if not b then -- try function with template - b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w]%b<>)%s*(%b())%s*(c?o?n?s?t?)%s*o?v?e?r?i?d?e?%s*=?%s*0?%s*;%s*") + b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w]%b<>)%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?%s*=?%s*0?%s*;%s*") end if not b then -- try a single letter function name - b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*o?v?e?r?i?d?e?%s*;%s*") + b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?%s*;%s*") end if not b then -- try function pointer @@ -630,6 +629,9 @@ function classContainer:doparse (s) end end _curr_code = strsub(s,b,e) + if const == 'o' then + const = '' + end Function(decl,arg,const) return strsub(s,e+1) end @@ -637,14 +639,17 @@ function classContainer:doparse (s) -- try inline function do - local b,e,decl,arg,const = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)%s*o?v?e?r?i?d?e?[^;{]*%b{}%s*;?%s*") + local b,e,decl,arg,const = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?[^;{]*%b{}%s*;?%s*") --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w>])%s*(%b())%s*(c?o?n?s?t?)[^;]*%b{}%s*;?%s*") if not b then -- try a single letter function name - b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*o?v?e?r?i?d?e?.-%b{}%s*;?%s*") + b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?.-%b{}%s*;?%s*") end if b then _curr_code = strsub(s,b,e) + if const == 'o' then + const = '' + end Function(decl,arg,const) return strsub(s,e+1) end diff --git a/lib/tolua++/src/bin/lua/function.lua b/lib/tolua++/src/bin/lua/function.lua index 3b6b53c5e..9338e0fbc 100644 --- a/lib/tolua++/src/bin/lua/function.lua +++ b/lib/tolua++/src/bin/lua/function.lua @@ -458,9 +458,8 @@ end -- Internal constructor function _Function (t) setmetatable(t,classFunction) - if t.const ~= 'const' and t.const ~= '' then - error("#invalid 'const' specification") + error("#invalid 'const' specification: " .. t.const) end append(t) @@ -489,7 +488,6 @@ end function Function (d,a,c) --local t = split(strsub(a,2,-2),',') -- eliminate braces --local t = split_params(strsub(a,2,-2)) - if not flags['W'] and string.find(a, "%.%.%.%s*%)") then warning("Functions with variable arguments (`...') are not supported. Ignoring "..d..a..c) diff --git a/lib/tolua++/src/bin/toluabind.c b/lib/tolua++/src/bin/toluabind.c index 06b371f70..e72b4b13c 100644 --- a/lib/tolua++/src/bin/toluabind.c +++ b/lib/tolua++/src/bin/toluabind.c @@ -1013,1170 +1013,8 @@ TOLUA_API int tolua_tolua_open (lua_State* tolua_S) { /* begin embedded lua code */ int top = lua_gettop(tolua_S); - static unsigned char B[] = { - 45, 45, 32,116,111,108,117, 97, 58, 32, 99,111,110,116, 97, - 105,110,101,114, 32, 97, 98,115,116,114, 97, 99,116, 32, 99, - 108, 97,115,115, 10, 45, 45, 32, 87,114,105,116,116,101,110, - 32, 98,121, 32, 87, 97,108,100,101,109, 97,114, 32, 67,101, - 108,101,115, 10, 45, 45, 32, 84,101, 67, 71,114, 97,102, 47, - 80, 85, 67, 45, 82,105,111, 10, 45, 45, 32, 74,117,108, 32, - 49, 57, 57, 56, 10, 45, 45, 32, 36, 73,100, 58, 32, 36, 10, - 10, 45, 45, 32, 84,104,105,115, 32, 99,111,100,101, 32,105, - 115, 32,102,114,101,101, 32,115,111,102,116,119, 97,114,101, - 59, 32,121,111,117, 32, 99, 97,110, 32,114,101,100,105,115, - 116,114,105, 98,117,116,101, 32,105,116, 32, 97,110,100, 47, - 111,114, 32,109,111,100,105,102,121, 32,105,116, 46, 10, 45, - 45, 32, 84,104,101, 32,115,111,102,116,119, 97,114,101, 32, - 112,114,111,118,105,100,101,100, 32,104,101,114,101,117,110, - 100,101,114, 32,105,115, 32,111,110, 32, 97,110, 32, 34, 97, - 115, 32,105,115, 34, 32, 98, 97,115,105,115, 44, 32, 97,110, - 100, 10, 45, 45, 32,116,104,101, 32, 97,117,116,104,111,114, - 32,104, 97,115, 32,110,111, 32,111, 98,108,105,103, 97,116, - 105,111,110, 32,116,111, 32,112,114,111,118,105,100,101, 32, - 109, 97,105,110,116,101,110, 97,110, 99,101, 44, 32,115,117, - 112,112,111,114,116, 44, 32,117,112,100, 97,116,101,115, 44, - 10, 45, 45, 32,101,110,104, 97,110, 99,101,109,101,110,116, - 115, 44, 32,111,114, 32,109,111,100,105,102,105, 99, 97,116, - 105,111,110,115, 46, 10, 10, 45, 45, 32,116, 97, 98,108,101, - 32,116,111, 32,115,116,111,114,101, 32,110, 97,109,101,115, - 112, 97, 99,101,100, 32,116,121,112,101,100,101,102,115, 47, - 101,110,117,109,115, 32,105,110, 32,103,108,111, 98, 97,108, - 32,115, 99,111,112,101, 10,103,108,111, 98, 97,108, 95,116, - 121,112,101,100,101,102,115, 32, 61, 32,123,125, 10,103,108, - 111, 98, 97,108, 95,101,110,117,109,115, 32, 61, 32,123,125, - 10, 10, 45, 45, 32, 67,111,110,116, 97,105,110,101,114, 32, - 99,108, 97,115,115, 10, 45, 45, 32, 82,101,112,114,101,115, - 101,110,116,115, 32, 97, 32, 99,111,110,116, 97,105,110,101, - 114, 32,111,102, 32,102,101, 97,116,117,114,101,115, 32,116, - 111, 32, 98,101, 32, 98,111,117,110,100, 10, 45, 45, 32,116, - 111, 32,108,117, 97, 46, 10, 99,108, 97,115,115, 67,111,110, - 116, 97,105,110,101,114, 32, 61, 10,123, 10, 32, 99,117,114, - 114, 32, 61, 32,110,105,108, 44, 10,125, 10, 99,108, 97,115, - 115, 67,111,110,116, 97,105,110,101,114, 46, 95, 95,105,110, - 100,101,120, 32, 61, 32, 99,108, 97,115,115, 67,111,110,116, - 97,105,110,101,114, 10,115,101,116,109,101,116, 97,116, 97, - 98,108,101, 40, 99,108, 97,115,115, 67,111,110,116, 97,105, - 110,101,114, 44, 99,108, 97,115,115, 70,101, 97,116,117,114, - 101, 41, 10, 10, 45, 45, 32,111,117,116,112,117,116, 32,116, - 97,103,115, 10,102,117,110, 99,116,105,111,110, 32, 99,108, - 97,115,115, 67,111,110,116, 97,105,110,101,114, 58,100,101, - 99,108,116,121,112,101, 32, 40, 41, 10, 32,112,117,115,104, - 40,115,101,108,102, 41, 10, 32,108,111, 99, 97,108, 32,105, - 61, 49, 10, 32,119,104,105,108,101, 32,115,101,108,102, 91, - 105, 93, 32,100,111, 10, 32, 32,115,101,108,102, 91,105, 93, - 58,100,101, 99,108,116,121,112,101, 40, 41, 10, 32, 32,105, - 32, 61, 32,105, 43, 49, 10, 32,101,110,100, 10, 32,112,111, - 112, 40, 41, 10,101,110,100, 10, 10, 10, 45, 45, 32,119,114, - 105,116,101, 32,115,117,112,112,111,114,116, 32, 99,111,100, - 101, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97,115, - 115, 67,111,110,116, 97,105,110,101,114, 58,115,117,112, 99, - 111,100,101, 32, 40, 41, 10, 10, 9,105,102, 32,110,111,116, - 32,115,101,108,102, 58, 99,104,101, 99,107, 95,112,117, 98, - 108,105, 99, 95, 97, 99, 99,101,115,115, 40, 41, 32,116,104, - 101,110, 10, 9, 9,114,101,116,117,114,110, 10, 9,101,110, - 100, 10, 10, 32,112,117,115,104, 40,115,101,108,102, 41, 10, - 32,108,111, 99, 97,108, 32,105, 61, 49, 10, 32,119,104,105, - 108,101, 32,115,101,108,102, 91,105, 93, 32,100,111, 10, 32, - 32,105,102, 32,115,101,108,102, 91,105, 93, 58, 99,104,101, - 99,107, 95,112,117, 98,108,105, 99, 95, 97, 99, 99,101,115, - 115, 40, 41, 32,116,104,101,110, 10, 32, 32, 9,115,101,108, - 102, 91,105, 93, 58,115,117,112, 99,111,100,101, 40, 41, 10, - 32, 32,101,110,100, 10, 32, 32,105, 32, 61, 32,105, 43, 49, - 10, 32,101,110,100, 10, 32,112,111,112, 40, 41, 10,101,110, - 100, 10, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97, - 115,115, 67,111,110,116, 97,105,110,101,114, 58,104, 97,115, - 118, 97,114, 32, 40, 41, 10, 32,108,111, 99, 97,108, 32,105, - 61, 49, 10, 32,119,104,105,108,101, 32,115,101,108,102, 91, - 105, 93, 32,100,111, 10, 32, 32,105,102, 32,115,101,108,102, - 91,105, 93, 58,105,115,118, 97,114,105, 97, 98,108,101, 40, - 41, 32,116,104,101,110, 10, 9, 9, 32,114,101,116,117,114, - 110, 32, 49, 10, 9, 9,101,110,100, 10, 32, 32,105, 32, 61, - 32,105, 43, 49, 10, 32,101,110,100, 10, 9,114,101,116,117, - 114,110, 32, 48, 10,101,110,100, 10, 10, 45, 45, 32, 73,110, - 116,101,114,110, 97,108, 32, 99,111,110,116, 97,105,110,101, - 114, 32, 99,111,110,115,116,114,117, 99,116,111,114, 10,102, - 117,110, 99,116,105,111,110, 32, 95, 67,111,110,116, 97,105, - 110,101,114, 32, 40,115,101,108,102, 41, 10, 32,115,101,116, - 109,101,116, 97,116, 97, 98,108,101, 40,115,101,108,102, 44, - 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, 41, - 10, 32,115,101,108,102, 46,110, 32, 61, 32, 48, 10, 32,115, - 101,108,102, 46,116,121,112,101,100,101,102,115, 32, 61, 32, - 123,116,111,108,117, 97, 95,110, 61, 48,125, 10, 32,115,101, - 108,102, 46,117,115,101,114,116,121,112,101,115, 32, 61, 32, - 123,125, 10, 32,115,101,108,102, 46,101,110,117,109,115, 32, - 61, 32,123,116,111,108,117, 97, 95,110, 61, 48,125, 10, 32, - 115,101,108,102, 46,108,110, 97,109,101,115, 32, 61, 32,123, - 125, 10, 32,114,101,116,117,114,110, 32,115,101,108,102, 10, - 101,110,100, 10, 10, 45, 45, 32,112,117,115,104, 32, 99,111, - 110,116, 97,105,110,101,114, 10,102,117,110, 99,116,105,111, - 110, 32,112,117,115,104, 32, 40,116, 41, 10, 9,116, 46,112, - 114,111,120, 32, 61, 32, 99,108, 97,115,115, 67,111,110,116, - 97,105,110,101,114, 46, 99,117,114,114, 10, 32, 99,108, 97, - 115,115, 67,111,110,116, 97,105,110,101,114, 46, 99,117,114, - 114, 32, 61, 32,116, 10,101,110,100, 10, 10, 45, 45, 32,112, - 111,112, 32, 99,111,110,116, 97,105,110,101,114, 10,102,117, - 110, 99,116,105,111,110, 32,112,111,112, 32, 40, 41, 10, 45, - 45,112,114,105,110,116, 40, 34,110, 97,109,101, 34, 44, 99, - 108, 97,115,115, 67,111,110,116, 97,105,110,101,114, 46, 99, - 117,114,114, 46,110, 97,109,101, 41, 10, 45, 45,102,111,114, - 101, 97, 99,104, 40, 99,108, 97,115,115, 67,111,110,116, 97, - 105,110,101,114, 46, 99,117,114,114, 46,117,115,101,114,116, - 121,112,101,115, 44,112,114,105,110,116, 41, 10, 45, 45,112, - 114,105,110,116, 40, 34, 95, 95, 95, 95, 95, 95, 95, 95, 95, - 95, 95, 95, 95, 95, 34, 41, 10, 32, 99,108, 97,115,115, 67, - 111,110,116, 97,105,110,101,114, 46, 99,117,114,114, 32, 61, - 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, - 46, 99,117,114,114, 46,112,114,111,120, 10,101,110,100, 10, - 10, 45, 45, 32,103,101,116, 32, 99,117,114,114,101,110,116, - 32,110, 97,109,101,115,112, 97, 99,101, 10,102,117,110, 99, - 116,105,111,110, 32,103,101,116, 99,117,114,114,110, 97,109, - 101,115,112, 97, 99,101, 32, 40, 41, 10, 9,114,101,116,117, - 114,110, 32,103,101,116,110, 97,109,101,115,112, 97, 99,101, - 40, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, - 46, 99,117,114,114, 41, 10,101,110,100, 10, 10, 45, 45, 32, - 97,112,112,101,110,100, 32,116,111, 32, 99,117,114,114,101, - 110,116, 32, 99,111,110,116, 97,105,110,101,114, 10,102,117, - 110, 99,116,105,111,110, 32, 97,112,112,101,110,100, 32, 40, - 116, 41, 10, 32,114,101,116,117,114,110, 32, 99,108, 97,115, - 115, 67,111,110,116, 97,105,110,101,114, 46, 99,117,114,114, - 58, 97,112,112,101,110,100, 40,116, 41, 10,101,110,100, 10, - 10, 45, 45, 32, 97,112,112,101,110,100, 32,116,121,112,101, - 100,101,102, 32,116,111, 32, 99,117,114,114,101,110,116, 32, - 99,111,110,116, 97,105,110,101,114, 10,102,117,110, 99,116, - 105,111,110, 32, 97,112,112,101,110,100,116,121,112,101,100, - 101,102, 32, 40,116, 41, 10, 32,114,101,116,117,114,110, 32, - 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, 46, - 99,117,114,114, 58, 97,112,112,101,110,100,116,121,112,101, - 100,101,102, 40,116, 41, 10,101,110,100, 10, 10, 45, 45, 32, - 97,112,112,101,110,100, 32,117,115,101,114,116,121,112,101, - 32,116,111, 32, 99,117,114,114,101,110,116, 32, 99,111,110, - 116, 97,105,110,101,114, 10,102,117,110, 99,116,105,111,110, - 32, 97,112,112,101,110,100,117,115,101,114,116,121,112,101, - 32, 40,116, 41, 10, 32,114,101,116,117,114,110, 32, 99,108, - 97,115,115, 67,111,110,116, 97,105,110,101,114, 46, 99,117, - 114,114, 58, 97,112,112,101,110,100,117,115,101,114,116,121, - 112,101, 40,116, 41, 10,101,110,100, 10, 10, 45, 45, 32, 97, - 112,112,101,110,100, 32,101,110,117,109, 32,116,111, 32, 99, - 117,114,114,101,110,116, 32, 99,111,110,116, 97,105,110,101, - 114, 10,102,117,110, 99,116,105,111,110, 32, 97,112,112,101, - 110,100,101,110,117,109, 32, 40,116, 41, 10, 32,114,101,116, - 117,114,110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105, - 110,101,114, 46, 99,117,114,114, 58, 97,112,112,101,110,100, - 101,110,117,109, 40,116, 41, 10,101,110,100, 10, 10, 45, 45, - 32,115,117, 98,115,116,105,116,117,116,101, 32,116,121,112, - 101,100,101,102, 10,102,117,110, 99,116,105,111,110, 32, 97, - 112,112,108,121,116,121,112,101,100,101,102, 32, 40,109,111, - 100, 44,116,121,112,101, 41, 10, 32,114,101,116,117,114,110, - 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, - 46, 99,117,114,114, 58, 97,112,112,108,121,116,121,112,101, - 100,101,102, 40,109,111,100, 44,116,121,112,101, 41, 10,101, - 110,100, 10, 10, 45, 45, 32, 99,104,101, 99,107, 32,105,102, - 32,105,115, 32,116,121,112,101, 10,102,117,110, 99,116,105, - 111,110, 32,102,105,110,100,116,121,112,101, 32, 40,116,121, - 112,101, 41, 10, 32,108,111, 99, 97,108, 32,116, 32, 61, 32, - 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, 46, - 99,117,114,114, 58,102,105,110,100,116,121,112,101, 40,116, - 121,112,101, 41, 10, 9,114,101,116,117,114,110, 32,116, 10, - 101,110,100, 10, 10, 45, 45, 32, 99,104,101, 99,107, 32,105, - 102, 32,105,115, 32,116,121,112,101,100,101,102, 10,102,117, - 110, 99,116,105,111,110, 32,105,115,116,121,112,101,100,101, - 102, 32, 40,116,121,112,101, 41, 10, 32,114,101,116,117,114, - 110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101, - 114, 46, 99,117,114,114, 58,105,115,116,121,112,101,100,101, - 102, 40,116,121,112,101, 41, 10,101,110,100, 10, 10, 45, 45, - 32,103,101,116, 32,102,117,108,108,116,121,112,101, 32, 40, - 119,105,116,104, 32,110, 97,109,101,115,112, 97, 99,101, 41, - 10,102,117,110, 99,116,105,111,110, 32,102,117,108,108,116, - 121,112,101, 32, 40,116, 41, 10, 32,108,111, 99, 97,108, 32, - 99,117,114,114, 32, 61, 32, 32, 99,108, 97,115,115, 67,111, - 110,116, 97,105,110,101,114, 46, 99,117,114,114, 10, 9,119, - 104,105,108,101, 32, 99,117,114,114, 32,100,111, 10, 9, 32, - 105,102, 32, 99,117,114,114, 32,116,104,101,110, 10, 9, 9, - 32,105,102, 32, 99,117,114,114, 46,116,121,112,101,100,101, - 102,115, 32, 97,110,100, 32, 99,117,114,114, 46,116,121,112, - 101,100,101,102,115, 91,116, 93, 32,116,104,101,110, 10, 9, - 9, 32, 32,114,101,116,117,114,110, 32, 99,117,114,114, 46, - 116,121,112,101,100,101,102,115, 91,116, 93, 10, 9, 9, 32, - 101,108,115,101,105,102, 32, 99,117,114,114, 46,117,115,101, - 114,116,121,112,101,115, 32, 97,110,100, 32, 99,117,114,114, - 46,117,115,101,114,116,121,112,101,115, 91,116, 93, 32,116, - 104,101,110, 10, 9, 9, 32, 32,114,101,116,117,114,110, 32, - 99,117,114,114, 46,117,115,101,114,116,121,112,101,115, 91, - 116, 93, 10, 9, 9, 9,101,110,100, 10, 9, 9,101,110,100, - 10, 9, 32, 99,117,114,114, 32, 61, 32, 99,117,114,114, 46, - 112,114,111,120, 10, 9,101,110,100, 10, 9,114,101,116,117, - 114,110, 32,116, 10,101,110,100, 10, 10, 45, 45, 32, 99,104, - 101, 99,107,115, 32,105,102, 32,105,116, 32,114,101,113,117, - 105,114,101,115, 32, 99,111,108,108,101, 99,116,105,111,110, - 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, - 67,111,110,116, 97,105,110,101,114, 58,114,101,113,117,105, - 114,101, 99,111,108,108,101, 99,116,105,111,110, 32, 40,116, - 41, 10, 32,112,117,115,104, 40,115,101,108,102, 41, 10, 32, - 108,111, 99, 97,108, 32,105, 61, 49, 10, 9,108,111, 99, 97, - 108, 32,114, 32, 61, 32,102, 97,108,115,101, 10, 32,119,104, - 105,108,101, 32,115,101,108,102, 91,105, 93, 32,100,111, 10, - 32, 32,114, 32, 61, 32,115,101,108,102, 91,105, 93, 58,114, - 101,113,117,105,114,101, 99,111,108,108,101, 99,116,105,111, - 110, 40,116, 41, 32,111,114, 32,114, 10, 32, 32,105, 32, 61, - 32,105, 43, 49, 10, 32,101,110,100, 10, 9,112,111,112, 40, - 41, 10, 9,114,101,116,117,114,110, 32,114, 10,101,110,100, - 10, 10, 10, 45, 45, 32,103,101,116, 32,110, 97,109,101,115, - 97,112, 99,101, 10,102,117,110, 99,116,105,111,110, 32,103, - 101,116,110, 97,109,101,115,112, 97, 99,101, 32, 40, 99,117, - 114,114, 41, 10, 9,108,111, 99, 97,108, 32,110, 97,109,101, - 115,112, 97, 99,101, 32, 61, 32, 39, 39, 10, 9,119,104,105, - 108,101, 32, 99,117,114,114, 32,100,111, 10, 9, 32,105,102, - 32, 99,117,114,114, 32, 97,110,100, 10, 9, 9, 32, 32, 32, - 40, 32, 99,117,114,114, 46, 99,108, 97,115,115,116,121,112, - 101, 32, 61, 61, 32, 39, 99,108, 97,115,115, 39, 32,111,114, - 32, 99,117,114,114, 46, 99,108, 97,115,115,116,121,112,101, - 32, 61, 61, 32, 39,110, 97,109,101,115,112, 97, 99,101, 39, - 41, 10, 9, 9,116,104,101,110, 10, 9, 9, 32,110, 97,109, - 101,115,112, 97, 99,101, 32, 61, 32, 40, 99,117,114,114, 46, - 111,114,105,103,105,110, 97,108, 95,110, 97,109,101, 32,111, - 114, 32, 99,117,114,114, 46,110, 97,109,101, 41, 32, 46, 46, - 32, 39, 58, 58, 39, 32, 46, 46, 32,110, 97,109,101,115,112, - 97, 99,101, 10, 9, 9, 32, 45, 45,110, 97,109,101,115,112, - 97, 99,101, 32, 61, 32, 99,117,114,114, 46,110, 97,109,101, - 32, 46, 46, 32, 39, 58, 58, 39, 32, 46, 46, 32,110, 97,109, - 101,115,112, 97, 99,101, 10, 9, 9,101,110,100, 10, 9, 32, - 99,117,114,114, 32, 61, 32, 99,117,114,114, 46,112,114,111, - 120, 10, 9,101,110,100, 10, 9,114,101,116,117,114,110, 32, - 110, 97,109,101,115,112, 97, 99,101, 10,101,110,100, 10, 10, - 45, 45, 32,103,101,116, 32,110, 97,109,101,115,112, 97, 99, - 101, 32, 40,111,110,108,121, 32,110, 97,109,101,115,112, 97, - 99,101, 41, 10,102,117,110, 99,116,105,111,110, 32,103,101, - 116,111,110,108,121,110, 97,109,101,115,112, 97, 99,101, 32, - 40, 41, 10, 32,108,111, 99, 97,108, 32, 99,117,114,114, 32, - 61, 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101, - 114, 46, 99,117,114,114, 10, 9,108,111, 99, 97,108, 32,110, - 97,109,101,115,112, 97, 99,101, 32, 61, 32, 39, 39, 10, 9, - 119,104,105,108,101, 32, 99,117,114,114, 32,100,111, 10, 9, - 9,105,102, 32, 99,117,114,114, 46, 99,108, 97,115,115,116, - 121,112,101, 32, 61, 61, 32, 39, 99,108, 97,115,115, 39, 32, - 116,104,101,110, 10, 9, 9, 32,114,101,116,117,114,110, 32, - 110, 97,109,101,115,112, 97, 99,101, 10, 9, 9,101,108,115, - 101,105,102, 32, 99,117,114,114, 46, 99,108, 97,115,115,116, - 121,112,101, 32, 61, 61, 32, 39,110, 97,109,101,115,112, 97, - 99,101, 39, 32,116,104,101,110, 10, 9, 9, 32,110, 97,109, - 101,115,112, 97, 99,101, 32, 61, 32, 99,117,114,114, 46,110, - 97,109,101, 32, 46, 46, 32, 39, 58, 58, 39, 32, 46, 46, 32, - 110, 97,109,101,115,112, 97, 99,101, 10, 9, 9,101,110,100, - 10, 9, 32, 99,117,114,114, 32, 61, 32, 99,117,114,114, 46, - 112,114,111,120, 10, 9,101,110,100, 10, 9,114,101,116,117, - 114,110, 32,110, 97,109,101,115,112, 97, 99,101, 10,101,110, - 100, 10, 10, 45, 45, 32, 99,104,101, 99,107, 32,105,102, 32, - 105,115, 32,101,110,117,109, 10,102,117,110, 99,116,105,111, - 110, 32,105,115,101,110,117,109, 32, 40,116,121,112,101, 41, - 10, 32,114,101,116,117,114,110, 32, 99,108, 97,115,115, 67, - 111,110,116, 97,105,110,101,114, 46, 99,117,114,114, 58,105, - 115,101,110,117,109, 40,116,121,112,101, 41, 10,101,110,100, - 10, 10, 45, 45, 32, 97,112,112,101,110,100, 32,102,101, 97, - 116,117,114,101, 32,116,111, 32, 99,111,110,116, 97,105,110, - 101,114, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97, - 115,115, 67,111,110,116, 97,105,110,101,114, 58, 97,112,112, - 101,110,100, 32, 40,116, 41, 10, 32,115,101,108,102, 46,110, - 32, 61, 32,115,101,108,102, 46,110, 32, 43, 32, 49, 10, 32, - 115,101,108,102, 91,115,101,108,102, 46,110, 93, 32, 61, 32, - 116, 10, 32,116, 46,112, 97,114,101,110,116, 32, 61, 32,115, - 101,108,102, 10,101,110,100, 10, 10, 45, 45, 32, 97,112,112, - 101,110,100, 32,116,121,112,101,100,101,102, 10,102,117,110, - 99,116,105,111,110, 32, 99,108, 97,115,115, 67,111,110,116, - 97,105,110,101,114, 58, 97,112,112,101,110,100,116,121,112, - 101,100,101,102, 32, 40,116, 41, 10, 32,108,111, 99, 97,108, - 32,110, 97,109,101,115,112, 97, 99,101, 32, 61, 32,103,101, - 116,110, 97,109,101,115,112, 97, 99,101, 40, 99,108, 97,115, - 115, 67,111,110,116, 97,105,110,101,114, 46, 99,117,114,114, - 41, 10, 32,115,101,108,102, 46,116,121,112,101,100,101,102, - 115, 46,116,111,108,117, 97, 95,110, 32, 61, 32,115,101,108, - 102, 46,116,121,112,101,100,101,102,115, 46,116,111,108,117, - 97, 95,110, 32, 43, 32, 49, 10, 32,115,101,108,102, 46,116, - 121,112,101,100,101,102,115, 91,115,101,108,102, 46,116,121, - 112,101,100,101,102,115, 46,116,111,108,117, 97, 95,110, 93, - 32, 61, 32,116, 10, 9,115,101,108,102, 46,116,121,112,101, - 100,101,102,115, 91,116, 46,117,116,121,112,101, 93, 32, 61, - 32,110, 97,109,101,115,112, 97, 99,101, 32, 46, 46, 32,116, - 46,117,116,121,112,101, 10, 9,103,108,111, 98, 97,108, 95, - 116,121,112,101,100,101,102,115, 91,110, 97,109,101,115,112, - 97, 99,101, 46, 46,116, 46,117,116,121,112,101, 93, 32, 61, - 32,116, 10, 9,116, 46,102,116,121,112,101, 32, 61, 32,102, - 105,110,100,116,121,112,101, 40,116, 46,116,121,112,101, 41, - 32,111,114, 32,116, 46,116,121,112,101, 10, 9, 45, 45,112, - 114,105,110,116, 40, 34, 97,112,112,101,110,100,105,110,103, - 32,116,121,112,101,100,101,102, 32, 34, 46, 46,116, 46,117, - 116,121,112,101, 46, 46, 34, 32, 97,115, 32, 34, 46, 46,110, - 97,109,101,115,112, 97, 99,101, 46, 46,116, 46,117,116,121, - 112,101, 46, 46, 34, 32,119,105,116,104, 32,102,116,121,112, - 101, 32, 34, 46, 46,116, 46,102,116,121,112,101, 41, 10, 9, - 97,112,112,101,110,100, 95,103,108,111, 98, 97,108, 95,116, - 121,112,101, 40,110, 97,109,101,115,112, 97, 99,101, 46, 46, - 116, 46,117,116,121,112,101, 41, 10, 9,105,102, 32,116, 46, - 102,116,121,112,101, 32, 97,110,100, 32,105,115,101,110,117, - 109, 40,116, 46,102,116,121,112,101, 41, 32,116,104,101,110, - 10, 10, 9, 9,103,108,111, 98, 97,108, 95,101,110,117,109, - 115, 91,110, 97,109,101,115,112, 97, 99,101, 46, 46,116, 46, - 117,116,121,112,101, 93, 32, 61, 32,116,114,117,101, 10, 9, - 101,110,100, 10,101,110,100, 10, 10, 45, 45, 32, 97,112,112, - 101,110,100, 32,117,115,101,114,116,121,112,101, 58, 32,114, - 101,116,117,114,110, 32,102,117,108,108, 32,116,121,112,101, - 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, - 67,111,110,116, 97,105,110,101,114, 58, 97,112,112,101,110, - 100,117,115,101,114,116,121,112,101, 32, 40,116, 41, 10, 9, - 108,111, 99, 97,108, 32, 99,111,110,116, 97,105,110,101,114, - 10, 9,105,102, 32,116, 32, 61, 61, 32, 40,115,101,108,102, - 46,111,114,105,103,105,110, 97,108, 95,110, 97,109,101, 32, - 111,114, 32,115,101,108,102, 46,110, 97,109,101, 41, 32,116, - 104,101,110, 10, 9, 9, 99,111,110,116, 97,105,110,101,114, - 32, 61, 32,115,101,108,102, 46,112,114,111,120, 10, 9,101, - 108,115,101, 10, 9, 9, 99,111,110,116, 97,105,110,101,114, - 32, 61, 32,115,101,108,102, 10, 9,101,110,100, 10, 9,108, - 111, 99, 97,108, 32,102,116, 32, 61, 32,103,101,116,110, 97, - 109,101,115,112, 97, 99,101, 40, 99,111,110,116, 97,105,110, - 101,114, 41, 32, 46, 46, 32,116, 10, 9, 99,111,110,116, 97, - 105,110,101,114, 46,117,115,101,114,116,121,112,101,115, 91, - 116, 93, 32, 61, 32,102,116, 10, 9, 95,117,115,101,114,116, - 121,112,101, 91,102,116, 93, 32, 61, 32,102,116, 10, 9,114, - 101,116,117,114,110, 32,102,116, 10,101,110,100, 10, 10, 45, - 45, 32, 97,112,112,101,110,100, 32,101,110,117,109, 10,102, - 117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, 67,111, - 110,116, 97,105,110,101,114, 58, 97,112,112,101,110,100,101, - 110,117,109, 32, 40,116, 41, 10, 32,108,111, 99, 97,108, 32, - 110, 97,109,101,115,112, 97, 99,101, 32, 61, 32,103,101,116, - 110, 97,109,101,115,112, 97, 99,101, 40, 99,108, 97,115,115, - 67,111,110,116, 97,105,110,101,114, 46, 99,117,114,114, 41, - 10, 32,115,101,108,102, 46,101,110,117,109,115, 46,116,111, - 108,117, 97, 95,110, 32, 61, 32,115,101,108,102, 46,101,110, - 117,109,115, 46,116,111,108,117, 97, 95,110, 32, 43, 32, 49, - 10, 32,115,101,108,102, 46,101,110,117,109,115, 91,115,101, - 108,102, 46,101,110,117,109,115, 46,116,111,108,117, 97, 95, - 110, 93, 32, 61, 32,116, 10, 9,103,108,111, 98, 97,108, 95, - 101,110,117,109,115, 91,110, 97,109,101,115,112, 97, 99,101, - 46, 46,116, 46,110, 97,109,101, 93, 32, 61, 32,116, 10,101, - 110,100, 10, 10, 45, 45, 32,100,101,116,101,114,109,105,110, - 101, 32,108,117, 97, 32,102,117,110, 99,116,105,111,110, 32, - 110, 97,109,101, 32,111,118,101,114,108,111, 97,100, 10,102, - 117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, 67,111, - 110,116, 97,105,110,101,114, 58,111,118,101,114,108,111, 97, - 100, 32, 40,108,110, 97,109,101, 41, 10, 32,105,102, 32,110, - 111,116, 32,115,101,108,102, 46,108,110, 97,109,101,115, 91, - 108,110, 97,109,101, 93, 32,116,104,101,110, 10, 32, 32,115, - 101,108,102, 46,108,110, 97,109,101,115, 91,108,110, 97,109, - 101, 93, 32, 61, 32, 48, 10, 32,101,108,115,101, 10, 32, 32, - 115,101,108,102, 46,108,110, 97,109,101,115, 91,108,110, 97, - 109,101, 93, 32, 61, 32,115,101,108,102, 46,108,110, 97,109, - 101,115, 91,108,110, 97,109,101, 93, 32, 43, 32, 49, 10, 32, - 101,110,100, 10, 32,114,101,116,117,114,110, 32,102,111,114, - 109, 97,116, 40, 34, 37, 48, 50,100, 34, 44,115,101,108,102, - 46,108,110, 97,109,101,115, 91,108,110, 97,109,101, 93, 41, - 10,101,110,100, 10, 10, 45, 45, 32, 97,112,112,108,105,101, - 115, 32,116,121,112,101,100,101,102, 58, 32,114,101,116,117, - 114,110,115, 32,116,104,101, 32, 39,116,104,101, 32,102, 97, - 99,116,111, 39, 32,109,111,100,105,102,105,101,114, 32, 97, - 110,100, 32,116,121,112,101, 10,102,117,110, 99,116,105,111, - 110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101, - 114, 58, 97,112,112,108,121,116,121,112,101,100,101,102, 32, - 40,109,111,100, 44,116,121,112,101, 41, 10, 9,105,102, 32, - 103,108,111, 98, 97,108, 95,116,121,112,101,100,101,102,115, - 91,116,121,112,101, 93, 32,116,104,101,110, 10, 9, 9, 45, - 45,112,114,105,110,116, 40, 34,102,111,117,110,100, 32,116, - 121,112,101,100,101,102, 32, 34, 46, 46,103,108,111, 98, 97, - 108, 95,116,121,112,101,100,101,102,115, 91,116,121,112,101, - 93, 46,116,121,112,101, 41, 10, 9, 9,108,111, 99, 97,108, - 32,109,111,100, 49, 44, 32,116,121,112,101, 49, 32, 61, 32, - 103,108,111, 98, 97,108, 95,116,121,112,101,100,101,102,115, - 91,116,121,112,101, 93, 46,109,111,100, 44, 32,103,108,111, - 98, 97,108, 95,116,121,112,101,100,101,102,115, 91,116,121, - 112,101, 93, 46,102,116,121,112,101, 10, 9, 9,108,111, 99, - 97,108, 32,109,111,100, 50, 44, 32,116,121,112,101, 50, 32, - 61, 32, 97,112,112,108,121,116,121,112,101,100,101,102, 40, - 109,111,100, 46, 46, 34, 32, 34, 46, 46,109,111,100, 49, 44, - 32,116,121,112,101, 49, 41, 10, 9, 9, 45, 45,114,101,116, - 117,114,110, 32,109,111,100, 50, 32, 46, 46, 32, 39, 32, 39, - 32, 46, 46, 32,109,111,100, 49, 44, 32,116,121,112,101, 50, - 10, 9, 9,114,101,116,117,114,110, 32,109,111,100, 50, 44, - 32,116,121,112,101, 50, 10, 9,101,110,100, 10, 9,100,111, - 32,114,101,116,117,114,110, 32,109,111,100, 44,116,121,112, - 101, 32,101,110,100, 10,101,110,100, 10, 10, 45, 45, 32, 99, - 104,101, 99,107, 32,105,102, 32,105,116, 32,105,115, 32, 97, - 32,116,121,112,101,100,101,102, 10,102,117,110, 99,116,105, - 111,110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110, - 101,114, 58,105,115,116,121,112,101,100,101,102, 32, 40,116, - 121,112,101, 41, 10, 32,108,111, 99, 97,108, 32,101,110,118, - 32, 61, 32,115,101,108,102, 10, 32,119,104,105,108,101, 32, - 101,110,118, 32,100,111, 10, 32, 32,105,102, 32,101,110,118, - 46,116,121,112,101,100,101,102,115, 32,116,104,101,110, 10, - 32, 32, 32,108,111, 99, 97,108, 32,105, 61, 49, 10, 32, 32, - 32,119,104,105,108,101, 32,101,110,118, 46,116,121,112,101, - 100,101,102,115, 91,105, 93, 32,100,111, 10, 32, 32, 32, 32, - 105,102, 32,101,110,118, 46,116,121,112,101,100,101,102,115, - 91,105, 93, 46,117,116,121,112,101, 32, 61, 61, 32,116,121, - 112,101, 32,116,104,101,110, 10, 32, 32, 32, 32, 32, 32, 32, - 32, 32,114,101,116,117,114,110, 32,116,121,112,101, 10, 32, - 32, 32, 32, 32, 32, 32, 32,101,110,100, 10, 32, 32, 32, 32, - 32, 32, 32, 32,105, 32, 61, 32,105, 43, 49, 10, 32, 32, 32, - 101,110,100, 10, 32, 32,101,110,100, 10, 32, 32,101,110,118, - 32, 61, 32,101,110,118, 46,112, 97,114,101,110,116, 10, 32, - 101,110,100, 10, 32,114,101,116,117,114,110, 32,110,105,108, - 10,101,110,100, 10, 10,102,117,110, 99,116,105,111,110, 32, - 102,105,110,100, 95,101,110,117,109, 95,118, 97,114, 40,118, - 97,114, 41, 10, 10, 9,105,102, 32,116,111,110,117,109, 98, - 101,114, 40,118, 97,114, 41, 32,116,104,101,110, 32,114,101, - 116,117,114,110, 32,118, 97,114, 32,101,110,100, 10, 10, 9, - 108,111, 99, 97,108, 32, 99, 32, 61, 32, 99,108, 97,115,115, - 67,111,110,116, 97,105,110,101,114, 46, 99,117,114,114, 10, - 9,119,104,105,108,101, 32, 99, 32,100,111, 10, 9, 9,108, - 111, 99, 97,108, 32,110,115, 32, 61, 32,103,101,116,110, 97, - 109,101,115,112, 97, 99,101, 40, 99, 41, 10, 9, 9,102,111, - 114, 32,107, 44,118, 32,105,110, 32,112, 97,105,114,115, 40, - 95,103,108,111, 98, 97,108, 95,101,110,117,109,115, 41, 32, - 100,111, 10, 9, 9, 9,105,102, 32,109, 97,116, 99,104, 95, - 116,121,112,101, 40,118, 97,114, 44, 32,118, 44, 32,110,115, - 41, 32,116,104,101,110, 10, 9, 9, 9, 9,114,101,116,117, - 114,110, 32,118, 10, 9, 9, 9,101,110,100, 10, 9, 9,101, - 110,100, 10, 9, 9,105,102, 32, 99, 46, 98, 97,115,101, 32, - 97,110,100, 32, 99, 46, 98, 97,115,101, 32,126, 61, 32, 39, - 39, 32,116,104,101,110, 10, 9, 9, 9, 99, 32, 61, 32, 95, - 103,108,111, 98, 97,108, 95, 99,108, 97,115,115,101,115, 91, - 99, 58,102,105,110,100,116,121,112,101, 40, 99, 46, 98, 97, - 115,101, 41, 93, 10, 9, 9,101,108,115,101, 10, 9, 9, 9, - 99, 32, 61, 32,110,105,108, 10, 9, 9,101,110,100, 10, 9, - 101,110,100, 10, 10, 9,114,101,116,117,114,110, 32,118, 97, - 114, 10,101,110,100, 10, 10, 45, 45, 32, 99,104,101, 99,107, - 32,105,102, 32,105,115, 32, 97, 32,114,101,103,105,115,116, - 101,114,101,100, 32,116,121,112,101, 58, 32,114,101,116,117, - 114,110, 32,102,117,108,108, 32,116,121,112,101, 32,111,114, - 32,110,105,108, 10,102,117,110, 99,116,105,111,110, 32, 99, - 108, 97,115,115, 67,111,110,116, 97,105,110,101,114, 58,102, - 105,110,100,116,121,112,101, 32, 40,116, 41, 10, 10, 9,116, - 32, 61, 32,115,116,114,105,110,103, 46,103,115,117, 98, 40, - 116, 44, 32, 34, 61, 46, 42, 34, 44, 32, 34, 34, 41, 10, 9, - 105,102, 32, 95, 98, 97,115,105, 99, 91,116, 93, 32,116,104, - 101,110, 10, 9, 32,114,101,116,117,114,110, 32,116, 10, 9, - 101,110,100, 10, 10, 9,108,111, 99, 97,108, 32, 95, 44, 95, - 44,101,109, 32, 61, 32,115,116,114,105,110,103, 46,102,105, - 110,100, 40,116, 44, 32, 34, 40, 91, 38, 37, 42, 93, 41, 37, - 115, 42, 36, 34, 41, 10, 9,116, 32, 61, 32,115,116,114,105, - 110,103, 46,103,115,117, 98, 40,116, 44, 32, 34, 37,115, 42, - 40, 91, 38, 37, 42, 93, 41, 37,115, 42, 36, 34, 44, 32, 34, - 34, 41, 10, 9,112, 32, 61, 32,115,101,108,102, 10, 9,119, - 104,105,108,101, 32,112, 32, 97,110,100, 32,116,121,112,101, - 40,112, 41, 61, 61, 39,116, 97, 98,108,101, 39, 32,100,111, - 10, 9, 9,108,111, 99, 97,108, 32,115,116, 32, 61, 32,103, - 101,116,110, 97,109,101,115,112, 97, 99,101, 40,112, 41, 10, - 10, 9, 9,102,111,114, 32,105, 61, 95,103,108,111, 98, 97, - 108, 95,116,121,112,101,115, 46,110, 44, 49, 44, 45, 49, 32, - 100,111, 32, 45, 45, 32,105,110, 32,114,101,118,101,114,115, - 101, 32,111,114,100,101,114, 10, 10, 9, 9, 9,105,102, 32, - 109, 97,116, 99,104, 95,116,121,112,101, 40,116, 44, 32, 95, - 103,108,111, 98, 97,108, 95,116,121,112,101,115, 91,105, 93, - 44, 32,115,116, 41, 32,116,104,101,110, 10, 9, 9, 9, 9, - 114,101,116,117,114,110, 32, 95,103,108,111, 98, 97,108, 95, - 116,121,112,101,115, 91,105, 93, 46, 46, 40,101,109, 32,111, - 114, 32, 34, 34, 41, 10, 9, 9, 9,101,110,100, 10, 9, 9, - 101,110,100, 10, 9, 9,105,102, 32,112, 46, 98, 97,115,101, - 32, 97,110,100, 32,112, 46, 98, 97,115,101, 32,126, 61, 32, - 39, 39, 32, 97,110,100, 32,112, 46, 98, 97,115,101, 32,126, - 61, 32,116, 32,116,104,101,110, 10, 9, 9, 9, 45, 45,112, - 114,105,110,116, 40, 34,116,121,112,101, 32,105,115, 32, 34, - 46, 46,116, 46, 46, 34, 44, 32,112, 32,105,115, 32, 34, 46, - 46,112, 46, 98, 97,115,101, 46, 46, 34, 32,115,101,108,102, - 46,116,121,112,101, 32,105,115, 32, 34, 46, 46,115,101,108, - 102, 46,116,121,112,101, 46, 46, 34, 32,115,101,108,102, 46, - 110, 97,109,101, 32,105,115, 32, 34, 46, 46,115,101,108,102, - 46,110, 97,109,101, 41, 10, 9, 9, 9,112, 32, 61, 32, 95, - 103,108,111, 98, 97,108, 95, 99,108, 97,115,115,101,115, 91, - 112, 58,102,105,110,100,116,121,112,101, 40,112, 46, 98, 97, - 115,101, 41, 93, 10, 9, 9,101,108,115,101, 10, 9, 9, 9, - 112, 32, 61, 32,110,105,108, 10, 9, 9,101,110,100, 10, 9, - 101,110,100, 10, 10, 9,114,101,116,117,114,110, 32,110,105, - 108, 10,101,110,100, 10, 10,102,117,110, 99,116,105,111,110, - 32, 97,112,112,101,110,100, 95,103,108,111, 98, 97,108, 95, - 116,121,112,101, 40,116, 44, 32, 99,108, 97,115,115, 41, 10, - 9, 95,103,108,111, 98, 97,108, 95,116,121,112,101,115, 46, - 110, 32, 61, 32, 95,103,108,111, 98, 97,108, 95,116,121,112, - 101,115, 46,110, 32, 43, 49, 10, 9, 95,103,108,111, 98, 97, - 108, 95,116,121,112,101,115, 91, 95,103,108,111, 98, 97,108, - 95,116,121,112,101,115, 46,110, 93, 32, 61, 32,116, 10, 9, - 95,103,108,111, 98, 97,108, 95,116,121,112,101,115, 95,104, - 97,115,104, 91,116, 93, 32, 61, 32, 49, 10, 9,105,102, 32, - 99,108, 97,115,115, 32,116,104,101,110, 32, 97,112,112,101, - 110,100, 95, 99,108, 97,115,115, 95,116,121,112,101, 40,116, - 44, 32, 99,108, 97,115,115, 41, 32,101,110,100, 10,101,110, - 100, 10, 10,102,117,110, 99,116,105,111,110, 32, 97,112,112, - 101,110,100, 95, 99,108, 97,115,115, 95,116,121,112,101, 40, - 116, 44, 99,108, 97,115,115, 41, 10, 9,105,102, 32, 95,103, - 108,111, 98, 97,108, 95, 99,108, 97,115,115,101,115, 91,116, - 93, 32,116,104,101,110, 10, 9, 9, 99,108, 97,115,115, 46, - 102,108, 97,103,115, 32, 61, 32, 95,103,108,111, 98, 97,108, - 95, 99,108, 97,115,115,101,115, 91,116, 93, 46,102,108, 97, - 103,115, 10, 9, 9, 99,108, 97,115,115, 46,108,110, 97,109, - 101,115, 32, 61, 32, 95,103,108,111, 98, 97,108, 95, 99,108, - 97,115,115,101,115, 91,116, 93, 46,108,110, 97,109,101,115, - 10, 9, 9,105,102, 32, 95,103,108,111, 98, 97,108, 95, 99, - 108, 97,115,115,101,115, 91,116, 93, 46, 98, 97,115,101, 32, - 97,110,100, 32, 40, 95,103,108,111, 98, 97,108, 95, 99,108, - 97,115,115,101,115, 91,116, 93, 46, 98, 97,115,101, 32,126, - 61, 32, 39, 39, 41, 32,116,104,101,110, 10, 9, 9, 9, 99, - 108, 97,115,115, 46, 98, 97,115,101, 32, 61, 32, 95,103,108, - 111, 98, 97,108, 95, 99,108, 97,115,115,101,115, 91,116, 93, - 46, 98, 97,115,101, 32,111,114, 32, 99,108, 97,115,115, 46, - 98, 97,115,101, 10, 9, 9,101,110,100, 10, 9,101,110,100, - 10, 9, 95,103,108,111, 98, 97,108, 95, 99,108, 97,115,115, - 101,115, 91,116, 93, 32, 61, 32, 99,108, 97,115,115, 10, 9, - 99,108, 97,115,115, 46,102,108, 97,103,115, 32, 61, 32, 99, - 108, 97,115,115, 46,102,108, 97,103,115, 32,111,114, 32,123, - 125, 10,101,110,100, 10, 10,102,117,110, 99,116,105,111,110, - 32,109, 97,116, 99,104, 95,116,121,112,101, 40, 99,104,105, - 108,100,116,121,112,101, 44, 32,114,101,103,116,121,112,101, - 44, 32,115,116, 41, 10, 45, 45,112,114,105,110,116, 40, 34, - 102,105,110,100,116,121,112,101, 32, 34, 46, 46, 99,104,105, - 108,100,116,121,112,101, 46, 46, 34, 44, 32, 34, 46, 46,114, - 101,103,116,121,112,101, 46, 46, 34, 44, 32, 34, 46, 46,115, - 116, 41, 10, 9,108,111, 99, 97,108, 32, 98, 44,101, 32, 61, - 32,115,116,114,105,110,103, 46,102,105,110,100, 40,114,101, - 103,116,121,112,101, 44, 32, 99,104,105,108,100,116,121,112, - 101, 44, 32, 45,115,116,114,105,110,103, 46,108,101,110, 40, - 99,104,105,108,100,116,121,112,101, 41, 44, 32,116,114,117, - 101, 41, 10, 9,105,102, 32, 98, 32,116,104,101,110, 10, 10, - 9, 9,105,102, 32,101, 32, 61, 61, 32,115,116,114,105,110, - 103, 46,108,101,110, 40,114,101,103,116,121,112,101, 41, 32, - 97,110,100, 10, 9, 9, 9, 9, 40, 98, 32, 61, 61, 32, 49, - 32,111,114, 32, 40,115,116,114,105,110,103, 46,115,117, 98, - 40,114,101,103,116,121,112,101, 44, 32, 98, 45, 49, 44, 32, - 98, 45, 49, 41, 32, 61, 61, 32, 39, 58, 39, 32, 97,110,100, - 10, 9, 9, 9, 9,115,116,114,105,110,103, 46,115,117, 98, - 40,114,101,103,116,121,112,101, 44, 32, 49, 44, 32, 98, 45, - 49, 41, 32, 61, 61, 32,115,116,114,105,110,103, 46,115,117, - 98, 40,115,116, 44, 32, 49, 44, 32, 98, 45, 49, 41, 41, 41, - 32,116,104,101,110, 10, 9, 9, 9,114,101,116,117,114,110, - 32,116,114,117,101, 10, 9, 9,101,110,100, 10, 9,101,110, - 100, 10, 10, 9,114,101,116,117,114,110, 32,102, 97,108,115, - 101, 10,101,110,100, 10, 10,102,117,110, 99,116,105,111,110, - 32,102,105,110,100,116,121,112,101, 95,111,110, 95, 99,104, - 105,108,100,115, 40,115,101,108,102, 44, 32,116, 41, 10, 10, - 9,108,111, 99, 97,108, 32,116, 99,104,105,108,100, 10, 9, - 105,102, 32,115,101,108,102, 46, 99,108, 97,115,115,116,121, - 112,101, 32, 61, 61, 32, 39, 99,108, 97,115,115, 39, 32,111, - 114, 32,115,101,108,102, 46, 99,108, 97,115,115,116,121,112, - 101, 32, 61, 61, 32, 39,110, 97,109,101,115,112, 97, 99,101, - 39, 32,116,104,101,110, 10, 9, 9,102,111,114, 32,107, 44, - 118, 32,105,110, 32,105,112, 97,105,114,115, 40,115,101,108, - 102, 41, 32,100,111, 10, 9, 9, 9,105,102, 32,118, 46, 99, - 108, 97,115,115,116,121,112,101, 32, 61, 61, 32, 39, 99,108, - 97,115,115, 39, 32,111,114, 32,118, 46, 99,108, 97,115,115, - 116,121,112,101, 32, 61, 61, 32, 39,110, 97,109,101,115,112, - 97, 99,101, 39, 32,116,104,101,110, 10, 9, 9, 9, 9,105, - 102, 32,118, 46,116,121,112,101,100,101,102,115, 32, 97,110, - 100, 32,118, 46,116,121,112,101,100,101,102,115, 91,116, 93, - 32,116,104,101,110, 10, 9, 9, 9, 9, 32,114,101,116,117, - 114,110, 32,118, 46,116,121,112,101,100,101,102,115, 91,116, - 93, 10, 9, 9, 9, 9,101,108,115,101,105,102, 32,118, 46, - 117,115,101,114,116,121,112,101,115, 32, 97,110,100, 32,118, - 46,117,115,101,114,116,121,112,101,115, 91,116, 93, 32,116, - 104,101,110, 10, 9, 9, 9, 9, 32,114,101,116,117,114,110, - 32,118, 46,117,115,101,114,116,121,112,101,115, 91,116, 93, - 10, 9, 9, 9, 9,101,110,100, 10, 9, 9, 9, 9,116, 99, - 104,105,108,100, 32, 61, 32,102,105,110,100,116,121,112,101, - 95,111,110, 95, 99,104,105,108,100,115, 40,118, 44, 32,116, - 41, 10, 9, 9, 9, 9,105,102, 32,116, 99,104,105,108,100, - 32,116,104,101,110, 32,114,101,116,117,114,110, 32,116, 99, - 104,105,108,100, 32,101,110,100, 10, 9, 9, 9,101,110,100, - 10, 9, 9,101,110,100, 10, 9,101,110,100, 10, 9,114,101, - 116,117,114,110, 32,110,105,108, 10, 10,101,110,100, 10, 10, - 102,117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, 67, - 111,110,116, 97,105,110,101,114, 58,105,115,101,110,117,109, - 32, 40,116,121,112,101, 41, 10, 32,105,102, 32,103,108,111, - 98, 97,108, 95,101,110,117,109,115, 91,116,121,112,101, 93, - 32,116,104,101,110, 10, 9,114,101,116,117,114,110, 32,116, - 121,112,101, 10, 32,101,108,115,101, 10, 32, 9,114,101,116, - 117,114,110, 32,102, 97,108,115,101, 10, 32,101,110,100, 10, - 10, 32,108,111, 99, 97,108, 32, 98, 97,115,101,116,121,112, - 101, 32, 61, 32,103,115,117, 98, 40,116,121,112,101, 44, 34, - 94, 46, 42, 58, 58, 34, 44, 34, 34, 41, 10, 32,108,111, 99, - 97,108, 32,101,110,118, 32, 61, 32,115,101,108,102, 10, 32, - 119,104,105,108,101, 32,101,110,118, 32,100,111, 10, 32, 32, - 105,102, 32,101,110,118, 46,101,110,117,109,115, 32,116,104, - 101,110, 10, 32, 32, 32,108,111, 99, 97,108, 32,105, 61, 49, - 10, 32, 32, 32,119,104,105,108,101, 32,101,110,118, 46,101, - 110,117,109,115, 91,105, 93, 32,100,111, 10, 32, 32, 32, 32, - 105,102, 32,101,110,118, 46,101,110,117,109,115, 91,105, 93, - 46,110, 97,109,101, 32, 61, 61, 32, 98, 97,115,101,116,121, - 112,101, 32,116,104,101,110, 10, 32, 32, 32, 32, 32, 32, 32, - 32, 32,114,101,116,117,114,110, 32,116,114,117,101, 10, 32, - 32, 32, 32, 32, 32, 32, 32,101,110,100, 10, 32, 32, 32, 32, - 32, 32, 32, 32,105, 32, 61, 32,105, 43, 49, 10, 32, 32, 32, - 101,110,100, 10, 32, 32,101,110,100, 10, 32, 32,101,110,118, - 32, 61, 32,101,110,118, 46,112, 97,114,101,110,116, 10, 32, - 101,110,100, 10, 32,114,101,116,117,114,110, 32,102, 97,108, - 115,101, 10,101,110,100, 10, 10,109,101,116,104,111,100,105, - 115,118,105,114,116,117, 97,108, 32, 61, 32,102, 97,108,115, - 101, 32, 45, 45, 32, 97, 32,103,108,111, 98, 97,108, 10, 10, - 45, 45, 32,112, 97,114,115,101, 32, 99,104,117,110,107, 10, - 102,117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, 67, - 111,110,116, 97,105,110,101,114, 58,100,111,112, 97,114,115, - 101, 32, 40,115, 41, 10, 45, 45,112,114,105,110,116, 32, 40, - 34,112, 97,114,115,101, 32, 34, 46, 46,115, 41, 10, 10, 32, - 45, 45, 32,116,114,121, 32,116,104,101, 32,112, 97,114,115, - 101,114, 32,104,111,111,107, 10, 32,100,111, 10, 32, 9,108, - 111, 99, 97,108, 32,115,117, 98, 32, 61, 32,112, 97,114,115, - 101,114, 95,104,111,111,107, 40,115, 41, 10, 32, 9,105,102, - 32,115,117, 98, 32,116,104,101,110, 10, 32, 9, 9,114,101, - 116,117,114,110, 32,115,117, 98, 10, 32, 9,101,110,100, 10, - 32,101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, 32,116, - 104,101, 32,110,117,108,108, 32,115,116, 97,116,101,109,101, - 110,116, 10, 32,100,111, 10, 32, 9,108,111, 99, 97,108, 32, - 98, 44,101, 44, 99,111,100,101, 32, 61, 32,115,116,114,105, - 110,103, 46,102,105,110,100, 40,115, 44, 32, 34, 94, 37,115, - 42, 59, 34, 41, 10, 32, 9,105,102, 32, 98, 32,116,104,101, - 110, 10, 32, 9, 9,114,101,116,117,114,110, 32,115,116,114, - 115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, 9,101,110, - 100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, - 32,101,109,112,116,121, 32,118,101,114, 98, 97,116,105,109, - 32,108,105,110,101, 10, 32,100,111, 10, 32, 9,108,111, 99, - 97,108, 32, 98, 44,101, 44, 99,111,100,101, 32, 61, 32,115, - 116,114,105,110,103, 46,102,105,110,100, 40,115, 44, 32, 34, - 94, 37,115, 42, 36, 92,110, 34, 41, 10, 32, 9,105,102, 32, - 98, 32,116,104,101,110, 10, 32, 9, 9,114,101,116,117,114, - 110, 32,115,116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, - 10, 32, 9,101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, - 45, 32,116,114,121, 32, 76,117, 97, 32, 99,111,100,101, 10, - 32,100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44,101, - 44, 99,111,100,101, 32, 61, 32,115,116,114,102,105,110,100, - 40,115, 44, 34, 94, 37,115, 42, 40, 37, 98, 92, 49, 92, 50, - 41, 34, 41, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, - 10, 32, 32, 32, 67,111,100,101, 40,115,116,114,115,117, 98, - 40, 99,111,100,101, 44, 50, 44, 45, 50, 41, 41, 10, 32, 32, - 32,114,101,116,117,114,110, 32,115,116,114,115,117, 98, 40, - 115, 44,101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32,101, - 110,100, 10, 10, 32, 45, 45, 32,116,114,121, 32, 67, 32, 99, - 111,100,101, 10, 32,100,111, 10, 32, 32,108,111, 99, 97,108, - 32, 98, 44,101, 44, 99,111,100,101, 32, 61, 32,115,116,114, - 102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, 40, 37, 98, - 92, 51, 92, 52, 41, 34, 41, 10, 32, 32,105,102, 32, 98, 32, - 116,104,101,110, 10, 9, 99,111,100,101, 32, 61, 32, 39,123, - 39, 46, 46,115,116,114,115,117, 98, 40, 99,111,100,101, 44, - 50, 44, 45, 50, 41, 46, 46, 39, 92,110,125, 92,110, 39, 10, - 9, 86,101,114, 98, 97,116,105,109, 40, 99,111,100,101, 44, - 39,114, 39, 41, 32, 32, 32, 32, 32, 32, 32, 32, 45, 45, 32, - 118,101,114, 98, 97,116,105,109, 32, 99,111,100,101, 32,102, - 111,114, 32, 39,114, 39,101,103,105,115,116,101,114, 32,102, - 114, 97,103,109,101,110,116, 10, 9,114,101,116,117,114,110, - 32,115,116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, 10, - 32, 32,101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, - 32,116,114,121, 32, 67, 32, 99,111,100,101, 32,102,111,114, - 32,112,114,101, 97,109, 98,108,101, 32,115,101, 99,116,105, - 111,110, 10, 32,100,111, 10, 32, 9,108,111, 99, 97,108, 32, - 98, 44,101, 44, 99,111,100,101, 32, 61, 32,115,116,114,105, - 110,103, 46,102,105,110,100, 40,115, 44, 32, 34, 94, 37,115, - 42, 40, 37, 98, 92, 53, 92, 54, 41, 34, 41, 10, 32, 9,105, - 102, 32, 98, 32,116,104,101,110, 10, 32, 9, 9, 99,111,100, - 101, 32, 61, 32,115,116,114,105,110,103, 46,115,117, 98, 40, - 99,111,100,101, 44, 32, 50, 44, 32, 45, 50, 41, 46, 46, 34, - 92,110, 34, 10, 9, 9, 86,101,114, 98, 97,116,105,109, 40, - 99,111,100,101, 44, 32, 39, 39, 41, 10, 9, 9,114,101,116, - 117,114,110, 32,115,116,114,105,110,103, 46,115,117, 98, 40, - 115, 44, 32,101, 43, 49, 41, 10, 32, 9,101,110,100, 10, 32, - 101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, 32,100,101, - 102, 97,117,108,116, 95,112,114,111,112,101,114,116,121, 32, - 100,105,114,101, 99,116,105,118,101, 10, 32,100,111, 10, 32, - 9,108,111, 99, 97,108, 32, 98, 44,101, 44,112,116,121,112, - 101, 32, 61, 32,115,116,114,102,105,110,100, 40,115, 44, 32, - 34, 94, 37,115, 42, 84, 79, 76, 85, 65, 95, 80, 82, 79, 80, - 69, 82, 84, 89, 95, 84, 89, 80, 69, 37,115, 42, 37, 40, 43, - 37,115, 42, 40, 91, 94, 37, 41, 37,115, 93, 42, 41, 37,115, - 42, 37, 41, 43, 37,115, 42, 59, 63, 34, 41, 10, 32, 9,105, - 102, 32, 98, 32,116,104,101,110, 10, 32, 9, 9,105,102, 32, - 110,111,116, 32,112,116,121,112,101, 32,111,114, 32,112,116, - 121,112,101, 32, 61, 61, 32, 34, 34, 32,116,104,101,110, 10, - 32, 9, 9, 9,112,116,121,112,101, 32, 61, 32, 34,100,101, - 102, 97,117,108,116, 34, 10, 32, 9, 9,101,110,100, 10, 32, - 9, 9,115,101,108,102, 58,115,101,116, 95,112,114,111,112, - 101,114,116,121, 95,116,121,112,101, 40,112,116,121,112,101, - 41, 10, 9, 32, 9,114,101,116,117,114,110, 32,115,116,114, - 115,117, 98, 40,115, 44, 32,101, 43, 49, 41, 10, 32, 9,101, - 110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32,116,114, - 121, 32,112,114,111,116,101, 99,116,101,100, 95,100,101,115, - 116,114,117, 99,116,111,114, 32,100,105,114,101, 99,116,105, - 118,101, 10, 32,100,111, 10, 32, 9,108,111, 99, 97,108, 32, - 98, 44,101, 32, 61, 32,115,116,114,105,110,103, 46,102,105, - 110,100, 40,115, 44, 32, 34, 94, 37,115, 42, 84, 79, 76, 85, - 65, 95, 80, 82, 79, 84, 69, 67, 84, 69, 68, 95, 68, 69, 83, - 84, 82, 85, 67, 84, 79, 82, 37,115, 42, 59, 63, 34, 41, 10, - 9,105,102, 32, 98, 32,116,104,101,110, 10, 9, 9,105,102, - 32,115,101,108,102, 46,115,101,116, 95,112,114,111,116,101, - 99,116,101,100, 95,100,101,115,116,114,117, 99,116,111,114, - 32,116,104,101,110, 10, 9, 32, 9, 9,115,101,108,102, 58, - 115,101,116, 95,112,114,111,116,101, 99,116,101,100, 95,100, - 101,115,116,114,117, 99,116,111,114, 40,116,114,117,101, 41, - 10, 9, 32, 9,101,110,100, 10, 32, 9, 9,114,101,116,117, - 114,110, 32,115,116,114,115,117, 98, 40,115, 44, 32,101, 43, - 49, 41, 10, 32, 9,101,110,100, 10, 32,101,110,100, 10, 10, - 32, 45, 45, 32,116,114,121, 32, 39,101,120,116,101,114,110, - 39, 32,107,101,121,119,111,114,100, 10, 32,100,111, 10, 32, - 9,108,111, 99, 97,108, 32, 98, 44,101, 32, 61, 32,115,116, - 114,105,110,103, 46,102,105,110,100, 40,115, 44, 32, 34, 94, - 37,115, 42,101,120,116,101,114,110, 37,115, 43, 34, 41, 10, - 32, 9,105,102, 32, 98, 32,116,104,101,110, 10, 9, 9, 45, - 45, 32,100,111, 32,110,111,116,104,105,110,103, 10, 32, 9, - 9,114,101,116,117,114,110, 32,115,116,114,115,117, 98, 40, - 115, 44, 32,101, 43, 49, 41, 10, 32, 9,101,110,100, 10, 32, - 101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, 32, 39,118, - 105,114,116,117, 97,108, 39, 32,107,101,121,119,111,114,107, - 100, 10, 32,100,111, 10, 32, 9,108,111, 99, 97,108, 32, 98, - 44,101, 32, 61, 32,115,116,114,105,110,103, 46,102,105,110, - 100, 40,115, 44, 32, 34, 94, 37,115, 42,118,105,114,116,117, - 97,108, 37,115, 43, 34, 41, 10, 32, 9,105,102, 32, 98, 32, - 116,104,101,110, 10, 32, 9, 9,109,101,116,104,111,100,105, - 115,118,105,114,116,117, 97,108, 32, 61, 32,116,114,117,101, - 10, 32, 9, 9,114,101,116,117,114,110, 32,115,116,114,115, - 117, 98, 40,115, 44, 32,101, 43, 49, 41, 10, 32, 9,101,110, - 100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, - 32,108, 97, 98,101,108,115, 32, 40,112,117, 98,108,105, 99, - 44, 32,112,114,105,118, 97,116,101, 44, 32,101,116, 99, 41, - 10, 32,100,111, 10, 32, 9,108,111, 99, 97,108, 32, 98, 44, - 101, 32, 61, 32,115,116,114,105,110,103, 46,102,105,110,100, - 40,115, 44, 32, 34, 94, 37,115, 42, 37,119, 42, 37,115, 42, - 58, 91, 94, 58, 93, 34, 41, 10, 32, 9,105,102, 32, 98, 32, - 116,104,101,110, 10, 32, 9, 9,114,101,116,117,114,110, 32, - 115,116,114,115,117, 98, 40,115, 44, 32,101, 41, 32, 45, 45, - 32,112,114,101,115,101,114,118,101, 32,116,104,101, 32, 91, - 94, 58, 93, 10, 32, 9,101,110,100, 10, 32,101,110,100, 10, - 10, 32, 45, 45, 32,116,114,121, 32,109,111,100,117,108,101, - 10, 32,100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44, - 101, 44,110, 97,109,101, 44, 98,111,100,121, 32, 61, 32,115, - 116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42,109, - 111,100,117,108,101, 37,115, 37,115, 42, 40, 91, 95, 37,119, - 93, 91, 95, 37,119, 93, 42, 41, 37,115, 42, 40, 37, 98,123, - 125, 41, 37,115, 42, 34, 41, 10, 32, 32,105,102, 32, 98, 32, - 116,104,101,110, 10, 32, 32, 32, 95, 99,117,114,114, 95, 99, - 111,100,101, 32, 61, 32,115,116,114,115,117, 98, 40,115, 44, - 98, 44,101, 41, 10, 32, 32, 32, 77,111,100,117,108,101, 40, - 110, 97,109,101, 44, 98,111,100,121, 41, 10, 32, 32, 32,114, - 101,116,117,114,110, 32,115,116,114,115,117, 98, 40,115, 44, - 101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32,101,110,100, - 10, 10, 32, 45, 45, 32,116,114,121, 32,110, 97,109,101,115, - 97,112, 99,101, 10, 32,100,111, 10, 32, 32,108,111, 99, 97, - 108, 32, 98, 44,101, 44,110, 97,109,101, 44, 98,111,100,121, - 32, 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, - 37,115, 42,110, 97,109,101,115,112, 97, 99,101, 37,115, 37, - 115, 42, 40, 91, 95, 37,119, 93, 91, 95, 37,119, 93, 42, 41, - 37,115, 42, 40, 37, 98,123,125, 41, 37,115, 42, 59, 63, 34, - 41, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, 10, 32, - 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, 32, 61, 32, - 115,116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, 10, 32, - 32, 32, 78, 97,109,101,115,112, 97, 99,101, 40,110, 97,109, - 101, 44, 98,111,100,121, 41, 10, 32, 32, 32,114,101,116,117, - 114,110, 32,115,116,114,115,117, 98, 40,115, 44,101, 43, 49, - 41, 10, 32, 32,101,110,100, 10, 32,101,110,100, 10, 10, 32, - 45, 45, 32,116,114,121, 32,100,101,102,105,110,101, 10, 32, - 100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44,101, 44, - 110, 97,109,101, 32, 61, 32,115,116,114,102,105,110,100, 40, - 115, 44, 34, 94, 37,115, 42, 35,100,101,102,105,110,101, 37, - 115, 37,115, 42, 40, 91, 94, 37,115, 93, 42, 41, 91, 94, 92, - 110, 93, 42, 92,110, 37,115, 42, 34, 41, 10, 32, 32,105,102, - 32, 98, 32,116,104,101,110, 10, 32, 32, 32, 95, 99,117,114, - 114, 95, 99,111,100,101, 32, 61, 32,115,116,114,115,117, 98, - 40,115, 44, 98, 44,101, 41, 10, 32, 32, 32, 68,101,102,105, - 110,101, 40,110, 97,109,101, 41, 10, 32, 32, 32,114,101,116, - 117,114,110, 32,115,116,114,115,117, 98, 40,115, 44,101, 43, - 49, 41, 10, 32, 32,101,110,100, 10, 32,101,110,100, 10, 10, - 32, 45, 45, 32,116,114,121, 32,101,110,117,109,101,114, 97, - 116,101,115, 10, 10, 32,100,111, 10, 32, 32,108,111, 99, 97, - 108, 32, 98, 44,101, 44,110, 97,109,101, 44, 98,111,100,121, - 44,118, 97,114,110, 97,109,101, 32, 61, 32,115,116,114,102, - 105,110,100, 40,115, 44, 34, 94, 37,115, 42,101,110,117,109, - 37,115, 43, 40, 37, 83, 42, 41, 37,115, 42, 40, 37, 98,123, - 125, 41, 37,115, 42, 40, 91, 94, 37,115, 59, 93, 42, 41, 37, - 115, 42, 59, 63, 37,115, 42, 34, 41, 10, 32, 32,105,102, 32, - 98, 32,116,104,101,110, 10, 32, 32, 32, 45, 45,101,114,114, - 111,114, 40, 34, 35, 83,111,114,114,121, 44, 32,100,101, 99, - 108, 97,114, 97,116,105,111,110, 32,111,102, 32,101,110,117, - 109,115, 32, 97,110,100, 32,118, 97,114,105, 97, 98,108,101, - 115, 32,111,110, 32,116,104,101, 32,115, 97,109,101, 32,115, - 116, 97,116,101,109,101,110,116, 32,105,115, 32,110,111,116, - 32,115,117,112,112,111,114,116,101,100, 46, 92,110, 68,101, - 99,108, 97,114,101, 32,121,111,117,114, 32,118, 97,114,105, - 97, 98,108,101, 32,115,101,112, 97,114, 97,116,101,108,121, - 32, 40,101,120, 97,109,112,108,101, 58, 32, 39, 34, 46, 46, - 110, 97,109,101, 46, 46, 34, 32, 34, 46, 46,118, 97,114,110, - 97,109,101, 46, 46, 34, 59, 39, 41, 34, 41, 10, 32, 32, 32, - 95, 99,117,114,114, 95, 99,111,100,101, 32, 61, 32,115,116, - 114,115,117, 98, 40,115, 44, 98, 44,101, 41, 10, 32, 32, 32, - 69,110,117,109,101,114, 97,116,101, 40,110, 97,109,101, 44, - 98,111,100,121, 44,118, 97,114,110, 97,109,101, 41, 10, 32, - 32, 32,114,101,116,117,114,110, 32,115,116,114,115,117, 98, - 40,115, 44,101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32, - 101,110,100, 10, 10, 45, 45, 32,100,111, 10, 45, 45, 32, 32, - 108,111, 99, 97,108, 32, 98, 44,101, 44,110, 97,109,101, 44, - 98,111,100,121, 32, 61, 32,115,116,114,102,105,110,100, 40, - 115, 44, 34, 94, 37,115, 42,101,110,117,109, 37,115, 43, 40, - 37, 83, 42, 41, 37,115, 42, 40, 37, 98,123,125, 41, 37,115, - 42, 59, 63, 37,115, 42, 34, 41, 10, 45, 45, 32, 32,105,102, - 32, 98, 32,116,104,101,110, 10, 45, 45, 32, 32, 32, 95, 99, - 117,114,114, 95, 99,111,100,101, 32, 61, 32,115,116,114,115, - 117, 98, 40,115, 44, 98, 44,101, 41, 10, 45, 45, 32, 32, 32, - 69,110,117,109,101,114, 97,116,101, 40,110, 97,109,101, 44, - 98,111,100,121, 41, 10, 45, 45, 32, 32,114,101,116,117,114, - 110, 32,115,116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, - 10, 45, 45, 32, 32,101,110,100, 10, 45, 45, 32,101,110,100, - 10, 10, 32,100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, - 44,101, 44, 98,111,100,121, 44,110, 97,109,101, 32, 61, 32, - 115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, - 116,121,112,101,100,101,102, 37,115, 43,101,110,117,109, 91, - 94,123, 93, 42, 40, 37, 98,123,125, 41, 37,115, 42, 40, 91, - 37,119, 95, 93, 91, 94, 37,115, 93, 42, 41, 37,115, 42, 59, - 37,115, 42, 34, 41, 10, 32, 32,105,102, 32, 98, 32,116,104, - 101,110, 10, 32, 32, 32, 95, 99,117,114,114, 95, 99,111,100, - 101, 32, 61, 32,115,116,114,115,117, 98, 40,115, 44, 98, 44, - 101, 41, 10, 32, 32, 32, 69,110,117,109,101,114, 97,116,101, - 40,110, 97,109,101, 44, 98,111,100,121, 41, 10, 32, 32, 32, - 114,101,116,117,114,110, 32,115,116,114,115,117, 98, 40,115, - 44,101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32,101,110, - 100, 10, 10, 32, 45, 45, 32,116,114,121, 32,111,112,101,114, - 97,116,111,114, 10, 32,100,111, 10, 32, 32,108,111, 99, 97, - 108, 32, 98, 44,101, 44,100,101, 99,108, 44,107,105,110,100, - 44, 97,114,103, 44, 99,111,110,115,116, 32, 61, 32,115,116, - 114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, 40, 91, - 95, 37,119, 93, 91, 95, 37,119, 37,115, 37, 42, 38, 58, 60, - 62, 44, 93, 45, 37,115, 43,111,112,101,114, 97,116,111,114, - 41, 37,115, 42, 40, 91, 94, 37,115, 93, 91, 94, 37,115, 93, - 42, 41, 37,115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, - 99, 63,111, 63,110, 63,115, 63,116, 63, 41, 37,115, 42, 59, - 37,115, 42, 34, 41, 10, 32, 32,105,102, 32,110,111,116, 32, - 98, 32,116,104,101,110, 10, 9, 9, 32, 45, 45, 32,116,114, - 121, 32,105,110,108,105,110,101, 10, 32, 32, 32, 98, 44,101, - 44,100,101, 99,108, 44,107,105,110,100, 44, 97,114,103, 44, - 99,111,110,115,116, 32, 61, 32,115,116,114,102,105,110,100, - 40,115, 44, 34, 94, 37,115, 42, 40, 91, 95, 37,119, 93, 91, - 95, 37,119, 37,115, 37, 42, 38, 58, 60, 62, 44, 93, 45, 37, - 115, 43,111,112,101,114, 97,116,111,114, 41, 37,115, 42, 40, - 91, 94, 37,115, 93, 91, 94, 37,115, 93, 42, 41, 37,115, 42, - 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63,111, 63,110, - 63,115, 63,116, 63, 41, 91, 37,115, 92,110, 93, 42, 37, 98, - 123,125, 37,115, 42, 59, 63, 37,115, 42, 34, 41, 10, 32, 32, - 101,110,100, 10, 32, 32,105,102, 32,110,111,116, 32, 98, 32, - 116,104,101,110, 10, 32, 32, 9, 45, 45, 32,116,114,121, 32, - 99, 97,115,116, 32,111,112,101,114, 97,116,111,114, 10, 32, - 32, 9, 98, 44,101, 44,100,101, 99,108, 44,107,105,110,100, - 44, 97,114,103, 44, 99,111,110,115,116, 32, 61, 32,115,116, - 114,102,105,110,100, 40,115, 44, 32, 34, 94, 37,115, 42, 40, - 111,112,101,114, 97,116,111,114, 41, 37,115, 43, 40, 91, 37, - 119, 95, 58, 37,100, 60, 62, 37, 42, 37, 38, 37,115, 93, 43, - 41, 37,115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, - 63,111, 63,110, 63,115, 63,116, 63, 41, 34, 41, 59, 10, 32, - 32, 9,105,102, 32, 98, 32,116,104,101,110, 10, 32, 32, 9, - 9,108,111, 99, 97,108, 32, 95, 44,105,101, 32, 61, 32,115, - 116,114,105,110,103, 46,102,105,110,100, 40,115, 44, 32, 34, - 94, 37,115, 42, 37, 98,123,125, 34, 44, 32,101, 43, 49, 41, - 10, 32, 32, 9, 9,105,102, 32,105,101, 32,116,104,101,110, - 10, 32, 32, 9, 9, 9,101, 32, 61, 32,105,101, 10, 32, 32, - 9, 9,101,110,100, 10, 32, 32, 9,101,110,100, 10, 32, 32, - 101,110,100, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, - 10, 32, 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, 32, - 61, 32,115,116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, - 10, 32, 32, 32, 79,112,101,114, 97,116,111,114, 40,100,101, - 99,108, 44,107,105,110,100, 44, 97,114,103, 44, 99,111,110, - 115,116, 41, 10, 32, 32, 32,114,101,116,117,114,110, 32,115, - 116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, 32, - 101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32,116, - 114,121, 32,102,117,110, 99,116,105,111,110, 10, 32,100,111, - 10, 32, 32, 45, 45,108,111, 99, 97,108, 32, 98, 44,101, 44, - 100,101, 99,108, 44, 97,114,103, 44, 99,111,110,115,116, 32, - 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37, - 115, 42, 40, 91,126, 95, 37,119, 93, 91, 95, 64, 37,119, 37, - 115, 37, 42, 38, 58, 60, 62, 93, 42, 91, 95, 37,119, 93, 41, - 37,115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63, - 111, 63,110, 63,115, 63,116, 63, 41, 37,115, 42, 61, 63, 37, - 115, 42, 48, 63, 37,115, 42, 59, 37,115, 42, 34, 41, 10, 32, - 32,108,111, 99, 97,108, 32, 98, 44,101, 44,100,101, 99,108, - 44, 97,114,103, 44, 99,111,110,115,116, 44,118,105,114,116, - 32, 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, - 37,115, 42, 40, 91, 94, 37, 40, 92,110, 93, 43, 41, 37,115, - 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63,111, 63, - 110, 63,115, 63,116, 63, 41, 37,115, 42, 40, 61, 63, 37,115, - 42, 48, 63, 41, 37,115, 42, 59, 37,115, 42, 34, 41, 10, 32, - 32,105,102, 32,110,111,116, 32, 98, 32,116,104,101,110, 10, - 32, 32, 9, 45, 45, 32,116,114,121, 32,102,117,110, 99,116, - 105,111,110, 32,119,105,116,104, 32,116,101,109,112,108, 97, - 116,101, 10, 32, 32, 9, 98, 44,101, 44,100,101, 99,108, 44, - 97,114,103, 44, 99,111,110,115,116, 32, 61, 32,115,116,114, - 102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, 40, 91,126, - 95, 37,119, 93, 91, 95, 64, 37,119, 37,115, 37, 42, 38, 58, - 60, 62, 93, 42, 91, 95, 37,119, 93, 37, 98, 60, 62, 41, 37, - 115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63,111, - 63,110, 63,115, 63,116, 63, 41, 37,115, 42, 61, 63, 37,115, - 42, 48, 63, 37,115, 42, 59, 37,115, 42, 34, 41, 10, 32, 32, - 101,110,100, 10, 32, 32,105,102, 32,110,111,116, 32, 98, 32, - 116,104,101,110, 10, 32, 32, 32, 45, 45, 32,116,114,121, 32, - 97, 32,115,105,110,103,108,101, 32,108,101,116,116,101,114, - 32,102,117,110, 99,116,105,111,110, 32,110, 97,109,101, 10, - 32, 32, 32, 98, 44,101, 44,100,101, 99,108, 44, 97,114,103, - 44, 99,111,110,115,116, 32, 61, 32,115,116,114,102,105,110, - 100, 40,115, 44, 34, 94, 37,115, 42, 40, 91, 95, 37,119, 93, - 41, 37,115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, - 63,111, 63,110, 63,115, 63,116, 63, 41, 37,115, 42, 59, 37, - 115, 42, 34, 41, 10, 32, 32,101,110,100, 10, 32, 32,105,102, - 32,110,111,116, 32, 98, 32,116,104,101,110, 10, 32, 32, 32, - 45, 45, 32,116,114,121, 32,102,117,110, 99,116,105,111,110, - 32,112,111,105,110,116,101,114, 10, 32, 32, 32, 98, 44,101, - 44,100,101, 99,108, 44, 97,114,103, 44, 99,111,110,115,116, - 32, 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, - 37,115, 42, 40, 91, 94, 37, 40, 59, 92,110, 93, 43, 37, 98, - 40, 41, 41, 37,115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, - 59, 37,115, 42, 34, 41, 10, 32, 32, 32,105,102, 32, 98, 32, - 116,104,101,110, 10, 32, 32, 32, 32,100,101, 99,108, 32, 61, - 32,115,116,114,105,110,103, 46,103,115,117, 98, 40,100,101, - 99,108, 44, 32, 34, 37, 40, 37,115, 42, 37, 42, 40, 91, 94, - 37, 41, 93, 42, 41, 37,115, 42, 37, 41, 34, 44, 32, 34, 32, - 37, 49, 32, 34, 41, 10, 32, 32, 32,101,110,100, 10, 32, 32, - 101,110,100, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, - 10, 32, 32, 9,105,102, 32,118,105,114,116, 32, 97,110,100, - 32,115,116,114,105,110,103, 46,102,105,110,100, 40,118,105, - 114,116, 44, 32, 34, 91, 61, 48, 93, 34, 41, 32,116,104,101, - 110, 10, 32, 32, 9, 9,105,102, 32,115,101,108,102, 46,102, - 108, 97,103,115, 32,116,104,101,110, 10, 32, 32, 9, 9, 9, - 115,101,108,102, 46,102,108, 97,103,115, 46,112,117,114,101, - 95,118,105,114,116,117, 97,108, 32, 61, 32,116,114,117,101, - 10, 32, 32, 9, 9,101,110,100, 10, 32, 32, 9,101,110,100, - 10, 32, 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, 32, - 61, 32,115,116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, - 10, 32, 32, 32, 70,117,110, 99,116,105,111,110, 40,100,101, - 99,108, 44, 97,114,103, 44, 99,111,110,115,116, 41, 10, 32, - 32, 32,114,101,116,117,114,110, 32,115,116,114,115,117, 98, - 40,115, 44,101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32, - 101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, 32,105,110, - 108,105,110,101, 32,102,117,110, 99,116,105,111,110, 10, 32, - 100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44,101, 44, - 100,101, 99,108, 44, 97,114,103, 44, 99,111,110,115,116, 32, - 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37, - 115, 42, 40, 91, 94, 37, 40, 92,110, 93, 43, 41, 37,115, 42, - 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63,111, 63,110, - 63,115, 63,116, 63, 41, 91, 94, 59,123, 93, 42, 37, 98,123, - 125, 37,115, 42, 59, 63, 37,115, 42, 34, 41, 10, 32, 32, 45, - 45,108,111, 99, 97,108, 32, 98, 44,101, 44,100,101, 99,108, - 44, 97,114,103, 44, 99,111,110,115,116, 32, 61, 32,115,116, - 114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, 40, 91, - 126, 95, 37,119, 93, 91, 95, 64, 37,119, 37,115, 37, 42, 38, - 58, 60, 62, 93, 42, 91, 95, 37,119, 62, 93, 41, 37,115, 42, - 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63,111, 63,110, - 63,115, 63,116, 63, 41, 91, 94, 59, 93, 42, 37, 98,123,125, - 37,115, 42, 59, 63, 37,115, 42, 34, 41, 10, 32, 32,105,102, - 32,110,111,116, 32, 98, 32,116,104,101,110, 10, 32, 32, 32, - 45, 45, 32,116,114,121, 32, 97, 32,115,105,110,103,108,101, - 32,108,101,116,116,101,114, 32,102,117,110, 99,116,105,111, - 110, 32,110, 97,109,101, 10, 32, 32, 32, 98, 44,101, 44,100, - 101, 99,108, 44, 97,114,103, 44, 99,111,110,115,116, 32, 61, - 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, - 42, 40, 91, 95, 37,119, 93, 41, 37,115, 42, 40, 37, 98, 40, - 41, 41, 37,115, 42, 40, 99, 63,111, 63,110, 63,115, 63,116, - 63, 41, 46, 45, 37, 98,123,125, 37,115, 42, 59, 63, 37,115, - 42, 34, 41, 10, 32, 32,101,110,100, 10, 32, 32,105,102, 32, - 98, 32,116,104,101,110, 10, 32, 32, 32, 95, 99,117,114,114, - 95, 99,111,100,101, 32, 61, 32,115,116,114,115,117, 98, 40, - 115, 44, 98, 44,101, 41, 10, 32, 32, 32, 70,117,110, 99,116, - 105,111,110, 40,100,101, 99,108, 44, 97,114,103, 44, 99,111, - 110,115,116, 41, 10, 32, 32, 32,114,101,116,117,114,110, 32, - 115,116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, - 32,101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32, - 116,114,121, 32, 99,108, 97,115,115, 10, 32,100,111, 10, 9, - 32,108,111, 99, 97,108, 32, 98, 44,101, 44,110, 97,109,101, - 44, 98, 97,115,101, 44, 98,111,100,121, 10, 9, 9, 98, 97, - 115,101, 32, 61, 32, 39, 39, 32, 98,111,100,121, 32, 61, 32, - 39, 39, 10, 9, 9, 98, 44,101, 44,110, 97,109,101, 32, 61, - 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, - 42, 99,108, 97,115,115, 37,115, 42, 40, 91, 95, 37,119, 93, - 91, 95, 37,119, 64, 93, 42, 41, 37,115, 42, 59, 34, 41, 32, - 32, 45, 45, 32,100,117,109,109,121, 32, 99,108, 97,115,115, - 10, 9, 9,108,111, 99, 97,108, 32,100,117,109,109,121, 32, - 61, 32,102, 97,108,115,101, 10, 9, 9,105,102, 32,110,111, - 116, 32, 98, 32,116,104,101,110, 10, 9, 9, 9, 98, 44,101, - 44,110, 97,109,101, 32, 61, 32,115,116,114,102,105,110,100, - 40,115, 44, 34, 94, 37,115, 42,115,116,114,117, 99,116, 37, - 115, 42, 40, 91, 95, 37,119, 93, 91, 95, 37,119, 64, 93, 42, - 41, 37,115, 42, 59, 34, 41, 32, 32, 32, 32, 45, 45, 32,100, - 117,109,109,121, 32,115,116,114,117, 99,116, 10, 9, 9, 9, - 105,102, 32,110,111,116, 32, 98, 32,116,104,101,110, 10, 9, - 9, 9, 9, 98, 44,101, 44,110, 97,109,101, 44, 98, 97,115, - 101, 44, 98,111,100,121, 32, 61, 32,115,116,114,102,105,110, - 100, 40,115, 44, 34, 94, 37,115, 42, 99,108, 97,115,115, 37, - 115, 42, 40, 91, 95, 37,119, 93, 91, 95, 37,119, 64, 93, 42, - 41, 37,115, 42, 40, 91, 94,123, 93, 45, 41, 37,115, 42, 40, - 37, 98,123,125, 41, 37,115, 42, 34, 41, 10, 9, 9, 9, 9, - 105,102, 32,110,111,116, 32, 98, 32,116,104,101,110, 10, 9, - 9, 9, 9, 9, 98, 44,101, 44,110, 97,109,101, 44, 98, 97, - 115,101, 44, 98,111,100,121, 32, 61, 32,115,116,114,102,105, - 110,100, 40,115, 44, 34, 94, 37,115, 42,115,116,114,117, 99, - 116, 37,115, 43, 40, 91, 95, 37,119, 93, 91, 95, 37,119, 64, - 93, 42, 41, 37,115, 42, 40, 91, 94,123, 93, 45, 41, 37,115, - 42, 40, 37, 98,123,125, 41, 37,115, 42, 34, 41, 10, 9, 9, - 9, 9, 9,105,102, 32,110,111,116, 32, 98, 32,116,104,101, - 110, 10, 9, 9, 9, 9, 9, 9, 98, 44,101, 44,110, 97,109, - 101, 44, 98, 97,115,101, 44, 98,111,100,121, 32, 61, 32,115, - 116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42,117, - 110,105,111,110, 37,115, 42, 40, 91, 95, 37,119, 93, 91, 95, - 37,119, 64, 93, 42, 41, 37,115, 42, 40, 91, 94,123, 93, 45, - 41, 37,115, 42, 40, 37, 98,123,125, 41, 37,115, 42, 34, 41, - 10, 9, 9, 9, 9, 9, 9,105,102, 32,110,111,116, 32, 98, - 32,116,104,101,110, 10, 9, 9, 9, 9, 9, 9, 9, 98, 97, - 115,101, 32, 61, 32, 39, 39, 10, 9, 9, 9, 9, 9, 9, 9, - 98, 44,101, 44, 98,111,100,121, 44,110, 97,109,101, 32, 61, - 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, - 42,116,121,112,101,100,101,102, 37,115, 37,115, 42,115,116, - 114,117, 99,116, 37,115, 37,115, 42, 91, 95, 37,119, 93, 42, - 37,115, 42, 40, 37, 98,123,125, 41, 37,115, 42, 40, 91, 95, - 37,119, 93, 91, 95, 37,119, 64, 93, 42, 41, 37,115, 42, 59, - 34, 41, 10, 9, 9, 9, 9, 9, 9,101,110,100, 10, 9, 9, - 9, 9, 9,101,110,100, 10, 9, 9, 9, 9,101,110,100, 10, - 9, 9, 9,101,108,115,101, 32,100,117,109,109,121, 32, 61, - 32, 49, 32,101,110,100, 10, 9, 9,101,108,115,101, 32,100, - 117,109,109,121, 32, 61, 32, 49, 32,101,110,100, 10, 9, 9, - 105,102, 32, 98, 32,116,104,101,110, 10, 9, 9, 9,105,102, - 32, 98, 97,115,101, 32,126, 61, 32, 39, 39, 32,116,104,101, - 110, 10, 9, 9, 9, 9, 98, 97,115,101, 32, 61, 32,115,116, - 114,105,110,103, 46,103,115,117, 98, 40, 98, 97,115,101, 44, - 32, 34, 94, 37,115, 42, 58, 37,115, 42, 34, 44, 32, 34, 34, - 41, 10, 9, 9, 9, 9, 98, 97,115,101, 32, 61, 32,115,116, - 114,105,110,103, 46,103,115,117, 98, 40, 98, 97,115,101, 44, - 32, 34, 37,115, 42,112,117, 98,108,105, 99, 37,115, 42, 34, - 44, 32, 34, 34, 41, 10, 9, 9, 9, 9, 98, 97,115,101, 32, - 61, 32,115,112,108,105,116, 40, 98, 97,115,101, 44, 32, 34, - 44, 34, 41, 10, 9, 9, 9, 9, 45, 45,108,111, 99, 97,108, - 32, 98, 44,101, 10, 9, 9, 9, 9, 45, 45, 98, 44,101, 44, - 98, 97,115,101, 32, 61, 32,115,116,114,102,105,110,100, 40, - 98, 97,115,101, 44, 34, 46, 45, 40, 91, 95, 37,119, 93, 91, - 95, 37,119, 60, 62, 44, 58, 93, 42, 41, 36, 34, 41, 10, 9, - 9, 9,101,108,115,101, 10, 9, 9, 9, 9, 98, 97,115,101, - 32, 61, 32,123,125, 10, 9, 9, 9,101,110,100, 10, 9, 9, - 9, 95, 99,117,114,114, 95, 99,111,100,101, 32, 61, 32,115, - 116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, 10, 9, 9, - 9, 67,108, 97,115,115, 40,110, 97,109,101, 44, 98, 97,115, - 101, 44, 98,111,100,121, 41, 10, 9, 9, 9,105,102, 32,110, - 111,116, 32,100,117,109,109,121, 32,116,104,101,110, 10, 9, - 9, 9, 9,118, 97,114, 98, 44,118, 97,114,101, 44,118, 97, - 114,110, 97,109,101, 32, 61, 32,115,116,114,105,110,103, 46, - 102,105,110,100, 40,115, 44, 32, 34, 94, 37,115, 42, 40, 91, - 95, 37,119, 93, 43, 41, 37,115, 42, 59, 34, 44, 32,101, 43, - 49, 41, 10, 9, 9, 9, 9,105,102, 32,118, 97,114, 98, 32, - 116,104,101,110, 10, 9, 9, 9, 9, 9, 86, 97,114,105, 97, - 98,108,101, 40,110, 97,109,101, 46, 46, 34, 32, 34, 46, 46, - 118, 97,114,110, 97,109,101, 41, 10, 9, 9, 9, 9, 9,101, - 32, 61, 32,118, 97,114,101, 10, 9, 9, 9, 9,101,110,100, - 10, 9, 9, 9,101,110,100, 10, 9, 9, 9,114,101,116,117, - 114,110, 32,115,116,114,115,117, 98, 40,115, 44,101, 43, 49, - 41, 10, 9, 9,101,110,100, 10, 9,101,110,100, 10, 10, 32, - 45, 45, 32,116,114,121, 32,116,121,112,101,100,101,102, 10, - 32,100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44,101, - 44,116,121,112,101,115, 32, 61, 32,115,116,114,102,105,110, - 100, 40,115, 44, 34, 94, 37,115, 42,116,121,112,101,100,101, - 102, 37,115, 37,115, 42, 40, 46, 45, 41, 37,115, 42, 59, 37, - 115, 42, 34, 41, 10, 32, 32,105,102, 32, 98, 32,116,104,101, - 110, 10, 32, 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, - 32, 61, 32,115,116,114,115,117, 98, 40,115, 44, 98, 44,101, - 41, 10, 32, 32, 32, 84,121,112,101,100,101,102, 40,116,121, - 112,101,115, 41, 10, 32, 32, 32,114,101,116,117,114,110, 32, - 115,116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, - 32,101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32, - 116,114,121, 32,118, 97,114,105, 97, 98,108,101, 10, 32,100, - 111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44,101, 44,100, - 101, 99,108, 32, 61, 32,115,116,114,102,105,110,100, 40,115, - 44, 34, 94, 37,115, 42, 40, 91, 95, 37,119, 93, 91, 95, 64, - 37,115, 37,119, 37,100, 37, 42, 38, 58, 60, 62, 44, 93, 42, - 91, 95, 37,119, 37,100, 93, 41, 37,115, 42, 59, 37,115, 42, - 34, 41, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, 10, - 32, 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, 32, 61, - 32,115,116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, 10, - 10, 9,108,111, 99, 97,108, 32,108,105,115,116, 32, 61, 32, - 115,112,108,105,116, 95, 99, 95,116,111,107,101,110,115, 40, - 100,101, 99,108, 44, 32, 34, 44, 34, 41, 10, 9, 86, 97,114, - 105, 97, 98,108,101, 40,108,105,115,116, 91, 49, 93, 41, 10, - 9,105,102, 32,108,105,115,116, 46,110, 32, 62, 32, 49, 32, - 116,104,101,110, 10, 9, 9,108,111, 99, 97,108, 32, 95, 44, - 95, 44,116,121,112,101, 32, 61, 32,115,116,114,102,105,110, - 100, 40,108,105,115,116, 91, 49, 93, 44, 32, 34, 40, 46, 45, - 41, 37,115, 43, 40, 91, 94, 37,115, 93, 42, 41, 36, 34, 41, - 59, 10, 10, 9, 9,108,111, 99, 97,108, 32,105, 32, 61, 50, - 59, 10, 9, 9,119,104,105,108,101, 32,108,105,115,116, 91, - 105, 93, 32,100,111, 10, 9, 9, 9, 86, 97,114,105, 97, 98, - 108,101, 40,116,121,112,101, 46, 46, 34, 32, 34, 46, 46,108, - 105,115,116, 91,105, 93, 41, 10, 9, 9, 9,105, 61,105, 43, - 49, 10, 9, 9,101,110,100, 10, 9,101,110,100, 10, 32, 32, - 32, 45, 45, 86, 97,114,105, 97, 98,108,101, 40,100,101, 99, - 108, 41, 10, 32, 32, 32,114,101,116,117,114,110, 32,115,116, - 114,115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, 32,101, - 110,100, 10, 32,101,110,100, 10, 10, 9, 45, 45, 32,116,114, - 121, 32,115,116,114,105,110,103, 10, 32,100,111, 10, 32, 32, - 108,111, 99, 97,108, 32, 98, 44,101, 44,100,101, 99,108, 32, - 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37, - 115, 42, 40, 91, 95, 37,119, 93, 63, 91, 95, 37,115, 37,119, - 37,100, 93, 45, 99,104, 97,114, 37,115, 43, 91, 95, 64, 37, - 119, 37,100, 93, 42, 37,115, 42, 37, 91, 37,115, 42, 37, 83, - 43, 37,115, 42, 37, 93, 41, 37,115, 42, 59, 37,115, 42, 34, - 41, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, 10, 32, - 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, 32, 61, 32, - 115,116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, 10, 32, - 32, 32, 86, 97,114,105, 97, 98,108,101, 40,100,101, 99,108, - 41, 10, 32, 32, 32,114,101,116,117,114,110, 32,115,116,114, - 115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, 32,101,110, - 100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, - 32, 97,114,114, 97,121, 10, 32,100,111, 10, 32, 32,108,111, - 99, 97,108, 32, 98, 44,101, 44,100,101, 99,108, 32, 61, 32, - 115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, - 40, 91, 95, 37,119, 93, 91, 93, 91, 95, 64, 37,115, 37,119, - 37,100, 37, 42, 38, 58, 60, 62, 93, 42, 91, 93, 95, 37,119, - 37,100, 93, 41, 37,115, 42, 59, 37,115, 42, 34, 41, 10, 32, - 32,105,102, 32, 98, 32,116,104,101,110, 10, 32, 32, 32, 95, - 99,117,114,114, 95, 99,111,100,101, 32, 61, 32,115,116,114, - 115,117, 98, 40,115, 44, 98, 44,101, 41, 10, 32, 32, 32, 65, - 114,114, 97,121, 40,100,101, 99,108, 41, 10, 32, 32, 32,114, - 101,116,117,114,110, 32,115,116,114,115,117, 98, 40,115, 44, - 101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32,101,110,100, - 10, 10, 32, 45, 45, 32,110,111, 32,109, 97,116, 99,104,105, - 110,103, 10, 32,105,102, 32,103,115,117, 98, 40,115, 44, 34, - 37,115, 37,115, 42, 34, 44, 34, 34, 41, 32,126, 61, 32, 34, - 34, 32,116,104,101,110, 10, 32, 32, 95, 99,117,114,114, 95, - 99,111,100,101, 32, 61, 32,115, 10, 32, 32,101,114,114,111, - 114, 40, 34, 35,112, 97,114,115,101, 32,101,114,114,111,114, - 34, 41, 10, 32,101,108,115,101, 10, 32, 32,114,101,116,117, - 114,110, 32, 34, 34, 10, 32,101,110,100, 10, 10,101,110,100, - 10, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97,115, - 115, 67,111,110,116, 97,105,110,101,114, 58,112, 97,114,115, - 101, 32, 40,115, 41, 10, 10, 9, 45, 45,115,101,108,102, 46, - 99,117,114,114, 95,109,101,109, 98,101,114, 95, 97, 99, 99, - 101,115,115, 32, 61, 32,110,105,108, 10, 10, 32,119,104,105, - 108,101, 32,115, 32,126, 61, 32, 39, 39, 32,100,111, 10, 32, - 32,115, 32, 61, 32,115,101,108,102, 58,100,111,112, 97,114, - 115,101, 40,115, 41, 10, 32, 32,109,101,116,104,111,100,105, - 115,118,105,114,116,117, 97,108, 32, 61, 32,102, 97,108,115, - 101, 10, 32,101,110,100, 10,101,110,100, 10, 10, 10, 45, 45, - 32,112,114,111,112,101,114,116,121, 32,116,121,112,101,115, - 10, 10,102,117,110, 99,116,105,111,110, 32,103,101,116, 95, - 112,114,111,112,101,114,116,121, 95,116,121,112,101, 40, 41, - 10, 10, 9,114,101,116,117,114,110, 32, 99,108, 97,115,115, - 67,111,110,116, 97,105,110,101,114, 46, 99,117,114,114, 58, - 103,101,116, 95,112,114,111,112,101,114,116,121, 95,116,121, - 112,101, 40, 41, 10,101,110,100, 10, 10,102,117,110, 99,116, - 105,111,110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105, - 110,101,114, 58,115,101,116, 95,112,114,111,112,101,114,116, - 121, 95,116,121,112,101, 40,112,116,121,112,101, 41, 10, 9, - 112,116,121,112,101, 32, 61, 32,115,116,114,105,110,103, 46, - 103,115,117, 98, 40,112,116,121,112,101, 44, 32, 34, 94, 37, - 115, 42, 34, 44, 32, 34, 34, 41, 10, 9,112,116,121,112,101, - 32, 61, 32,115,116,114,105,110,103, 46,103,115,117, 98, 40, - 112,116,121,112,101, 44, 32, 34, 37,115, 42, 36, 34, 44, 32, - 34, 34, 41, 10, 10, 9,115,101,108,102, 46,112,114,111,112, - 101,114,116,121, 95,116,121,112,101, 32, 61, 32,112,116,121, - 112,101, 10,101,110,100, 10, 10,102,117,110, 99,116,105,111, - 110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101, - 114, 58,103,101,116, 95,112,114,111,112,101,114,116,121, 95, - 116,121,112,101, 40, 41, 10, 9,114,101,116,117,114,110, 32, - 115,101,108,102, 46,112,114,111,112,101,114,116,121, 95,116, - 121,112,101, 32,111,114, 32, 40,115,101,108,102, 46,112, 97, - 114,101,110,116, 32, 97,110,100, 32,115,101,108,102, 46,112, - 97,114,101,110,116, 58,103,101,116, 95,112,114,111,112,101, - 114,116,121, 95,116,121,112,101, 40, 41, 41, 32,111,114, 32, - 34,100,101,102, 97,117,108,116, 34, 10,101,110,100,32 - }; - tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua embedded: src/bin/lua/container.lua"); + #include "container_lua.h" + tolua_dobuffer(tolua_S,(char*)lua_container_lua,sizeof(lua_container_lua),"tolua embedded: src/bin/lua/container.lua"); lua_settop(tolua_S, top); } /* end of embedded lua code */ -- cgit v1.2.3 From 1f5a4a39f2cd9f63a7e5695689042d3c43b2e83b Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 2 Apr 2014 06:36:25 -0700 Subject: Fixed All signedness warnings in HTTPServer.cpp --- src/ClientHandle.cpp | 2 +- src/ClientHandle.h | 2 +- src/HTTPServer/HTTPConnection.cpp | 6 +++--- src/HTTPServer/HTTPConnection.h | 2 +- src/HTTPServer/HTTPFormParser.cpp | 4 ++-- src/HTTPServer/HTTPFormParser.h | 7 +++++-- src/HTTPServer/HTTPMessage.h | 2 +- src/OSSupport/SocketThreads.h | 2 +- src/RCONServer.cpp | 2 +- src/RCONServer.h | 2 +- 10 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 5ed5f1085..4513cfb38 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2633,7 +2633,7 @@ void cClientHandle::PacketError(unsigned char a_PacketType) -void cClientHandle::DataReceived(const char * a_Data, int a_Size) +void cClientHandle::DataReceived(const char * a_Data, size_t a_Size) { // Data is received from the client, store it in the buffer to be processed by the Tick thread: m_TimeSinceLastPacket = 0; diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 8366caa16..3fb653012 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -362,7 +362,7 @@ private: void HandleCommandBlockMessage(const char * a_Data, unsigned int a_Length); // cSocketThreads::cCallback overrides: - virtual void DataReceived (const char * a_Data, int a_Size) override; // Data is received from the client + virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client virtual void SocketClosed (void) override; // The socket has been closed for any reason }; // tolua_export diff --git a/src/HTTPServer/HTTPConnection.cpp b/src/HTTPServer/HTTPConnection.cpp index 6d238f028..44a3d3f88 100644 --- a/src/HTTPServer/HTTPConnection.cpp +++ b/src/HTTPServer/HTTPConnection.cpp @@ -144,7 +144,7 @@ void cHTTPConnection::Terminate(void) -void cHTTPConnection::DataReceived(const char * a_Data, int a_Size) +void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size) { switch (m_State) { @@ -181,9 +181,9 @@ void cHTTPConnection::DataReceived(const char * a_Data, int a_Size) } // Process the rest of the incoming data into the request body: - if (a_Size > (int)BytesConsumed) + if (a_Size > BytesConsumed) { - DataReceived(a_Data + BytesConsumed, a_Size - (int)BytesConsumed); + DataReceived(a_Data + BytesConsumed, a_Size - BytesConsumed); } else { diff --git a/src/HTTPServer/HTTPConnection.h b/src/HTTPServer/HTTPConnection.h index 0ad409c51..fc11f1ba6 100644 --- a/src/HTTPServer/HTTPConnection.h +++ b/src/HTTPServer/HTTPConnection.h @@ -91,7 +91,7 @@ protected: // cSocketThreads::cCallback overrides: - virtual void DataReceived (const char * a_Data, int a_Size) override; // Data is received from the client + virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client virtual void SocketClosed (void) override; // The socket has been closed for any reason } ; diff --git a/src/HTTPServer/HTTPFormParser.cpp b/src/HTTPServer/HTTPFormParser.cpp index 14d97bb7d..9ddfb82f1 100644 --- a/src/HTTPServer/HTTPFormParser.cpp +++ b/src/HTTPServer/HTTPFormParser.cpp @@ -52,7 +52,7 @@ cHTTPFormParser::cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callba -cHTTPFormParser::cHTTPFormParser(eKind a_Kind, const char * a_Data, int a_Size, cCallbacks & a_Callbacks) : +cHTTPFormParser::cHTTPFormParser(eKind a_Kind, const char * a_Data, size_t a_Size, cCallbacks & a_Callbacks) : m_Callbacks(a_Callbacks), m_Kind(a_Kind), m_IsValid(true) @@ -64,7 +64,7 @@ cHTTPFormParser::cHTTPFormParser(eKind a_Kind, const char * a_Data, int a_Size, -void cHTTPFormParser::Parse(const char * a_Data, int a_Size) +void cHTTPFormParser::Parse(const char * a_Data, size_t a_Size) { if (!m_IsValid) { diff --git a/src/HTTPServer/HTTPFormParser.h b/src/HTTPServer/HTTPFormParser.h index b8e6d246c..01d103bb8 100644 --- a/src/HTTPServer/HTTPFormParser.h +++ b/src/HTTPServer/HTTPFormParser.h @@ -36,6 +36,9 @@ public: class cCallbacks { public: + + virtual ~cCallbacks() {}; + /// Called when a new file part is encountered in the form data virtual void OnFileStart(cHTTPFormParser & a_Parser, const AString & a_FileName) = 0; @@ -51,10 +54,10 @@ public: cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callbacks); /// Creates a parser with the specified content type that reads data from a string - cHTTPFormParser(eKind a_Kind, const char * a_Data, int a_Size, cCallbacks & a_Callbacks); + cHTTPFormParser(eKind a_Kind, const char * a_Data, size_t a_Size, cCallbacks & a_Callbacks); /// Adds more data into the parser, as the request body is received - void Parse(const char * a_Data, int a_Size); + void Parse(const char * a_Data, size_t a_Size); /** Notifies that there's no more data incoming and the parser should finish its parsing. Returns true if parsing successful diff --git a/src/HTTPServer/HTTPMessage.h b/src/HTTPServer/HTTPMessage.h index c2d310839..dab942136 100644 --- a/src/HTTPServer/HTTPMessage.h +++ b/src/HTTPServer/HTTPMessage.h @@ -39,7 +39,7 @@ public: void AddHeader(const AString & a_Key, const AString & a_Value); void SetContentType (const AString & a_ContentType) { m_ContentType = a_ContentType; } - void SetContentLength(int a_ContentLength) { m_ContentLength = a_ContentLength; } + void SetContentLength(size_t a_ContentLength) { m_ContentLength = a_ContentLength; } const AString & GetContentType (void) const { return m_ContentType; } size_t GetContentLength(void) const { return m_ContentLength; } diff --git a/src/OSSupport/SocketThreads.h b/src/OSSupport/SocketThreads.h index b2eb5950f..679e374e1 100644 --- a/src/OSSupport/SocketThreads.h +++ b/src/OSSupport/SocketThreads.h @@ -64,7 +64,7 @@ public: virtual ~cCallback() {} /** Called when data is received from the remote party */ - virtual void DataReceived(const char * a_Data, int a_Size) = 0; + virtual void DataReceived(const char * a_Data, size_t a_Size) = 0; /** Called when data can be sent to remote party The function is supposed to *set* outgoing data to a_Data (overwrite) */ diff --git a/src/RCONServer.cpp b/src/RCONServer.cpp index 72f2d9ba9..d7083ff2b 100644 --- a/src/RCONServer.cpp +++ b/src/RCONServer.cpp @@ -169,7 +169,7 @@ cRCONServer::cConnection::cConnection(cRCONServer & a_RCONServer, cSocket & a_So -void cRCONServer::cConnection::DataReceived(const char * a_Data, int a_Size) +void cRCONServer::cConnection::DataReceived(const char * a_Data, size_t a_Size) { // Append data to the buffer: m_Buffer.append(a_Data, a_Size); diff --git a/src/RCONServer.h b/src/RCONServer.h index 88aac4b5f..b964852ab 100644 --- a/src/RCONServer.h +++ b/src/RCONServer.h @@ -65,7 +65,7 @@ protected: // cSocketThreads::cCallback overrides: - virtual void DataReceived(const char * a_Data, int a_Size) override; + virtual void DataReceived(const char * a_Data, size_t a_Size) override; virtual void GetOutgoingData(AString & a_Data) override; virtual void SocketClosed(void) override; -- cgit v1.2.3 From 26c3bc4076a455fd61b56c34215771bddb548e1d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 2 Apr 2014 16:39:42 +0200 Subject: Fixed more virtual destructors for interfaces. --- src/BlockTracer.h | 3 +++ src/HTTPServer/EnvelopeParser.h | 3 +++ src/HTTPServer/HTTPFormParser.h | 3 +++ src/HTTPServer/MultipartParser.h | 3 +++ 4 files changed, 12 insertions(+) diff --git a/src/BlockTracer.h b/src/BlockTracer.h index 40d80da1a..a18c8df4d 100644 --- a/src/BlockTracer.h +++ b/src/BlockTracer.h @@ -28,6 +28,9 @@ public: class cCallbacks abstract { public: + // Force a virtual destructor in descendants: + virtual ~cCallbacks() {} + /** Called on each block encountered along the path, including the first block (path start) When this callback returns true, the tracing is aborted. */ diff --git a/src/HTTPServer/EnvelopeParser.h b/src/HTTPServer/EnvelopeParser.h index 6430fbebf..866bed11d 100644 --- a/src/HTTPServer/EnvelopeParser.h +++ b/src/HTTPServer/EnvelopeParser.h @@ -19,6 +19,9 @@ public: class cCallbacks { public: + // Force a virtual destructor in descendants: + virtual ~cCallbacks() {} + /// Called when a full header line is parsed virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) = 0; } ; diff --git a/src/HTTPServer/HTTPFormParser.h b/src/HTTPServer/HTTPFormParser.h index a554ca5a4..f2a509cb8 100644 --- a/src/HTTPServer/HTTPFormParser.h +++ b/src/HTTPServer/HTTPFormParser.h @@ -36,6 +36,9 @@ public: class cCallbacks { public: + // Force a virtual destructor in descendants: + virtual ~cCallbacks() {} + /// Called when a new file part is encountered in the form data virtual void OnFileStart(cHTTPFormParser & a_Parser, const AString & a_FileName) = 0; diff --git a/src/HTTPServer/MultipartParser.h b/src/HTTPServer/MultipartParser.h index d853929ed..77695fe4a 100644 --- a/src/HTTPServer/MultipartParser.h +++ b/src/HTTPServer/MultipartParser.h @@ -22,6 +22,9 @@ public: class cCallbacks { public: + // Force a virtual destructor in descendants: + virtual ~cCallbacks() {} + /// Called when a new part starts virtual void OnPartStart(void) = 0; -- cgit v1.2.3 From 5c6d4745990a0aa90d0c6c01da65d6e8dfa32bfc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 2 Apr 2014 16:40:13 +0200 Subject: Fixed boat placement code. --- src/Items/ItemBoat.h | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index a28ec8e22..42f4ffc8f 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -39,12 +39,20 @@ public: public cBlockTracer::cCallbacks { public: - Vector3d Pos; - virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override + Vector3d m_Pos; + bool m_HasFound; + + cCallbacks(void) : + m_HasFound(false) { - if (a_BlockType != E_BLOCK_AIR) + } + + virtual bool OnNextBlock(int a_CBBlockX, int a_CBBlockY, int a_CBBlockZ, BLOCKTYPE a_CBBlockType, NIBBLETYPE a_CBBlockMeta, char a_CBEntryFace) override + { + if (a_CBBlockType != E_BLOCK_AIR) { - Pos = Vector3d(a_BlockX, a_BlockY, a_BlockZ); + m_Pos.Set(a_CBBlockX, a_CBBlockY, a_CBBlockZ); + m_HasFound = true; return true; } return false; @@ -57,15 +65,15 @@ public: Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z); - double x = Callbacks.Pos.x; - double y = Callbacks.Pos.y; - double z = Callbacks.Pos.z; - - if ((x == 0) && (y == 0) && (z == 0)) + if (!Callbacks.m_HasFound) { return false; } + double x = Callbacks.m_Pos.x; + double y = Callbacks.m_Pos.y; + double z = Callbacks.m_Pos.z; + cBoat * Boat = new cBoat(x + 0.5, y + 1, z + 0.5); Boat->Initialize(a_World); -- cgit v1.2.3 From 43af11ee3808fa9836fc9467cacd73b78118c3c2 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 2 Apr 2014 20:03:42 +0100 Subject: Removed extra brackets --- src/Blocks/BlockFluid.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index 1200997ff..1f0c3833c 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -1,4 +1,3 @@ - #pragma once #include "BlockHandler.h" @@ -94,10 +93,8 @@ public: BLOCKTYPE BlockType; if ( ((a_RelY + y < 0) || (a_RelY + y > cChunkDef::Height)) || - ( - !a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) || - !cFireSimulator::IsFuel(BlockType) - ) + !a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) || + !cFireSimulator::IsFuel(BlockType) ) { return false; -- cgit v1.2.3 From da267649a183e84280da7eadcb391952fb6a0d1d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 2 Apr 2014 20:04:41 +0100 Subject: With eXtra line! --- src/Blocks/BlockFluid.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index 1f0c3833c..d486d642d 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -1,3 +1,4 @@ + #pragma once #include "BlockHandler.h" -- cgit v1.2.3 From 12b82de502888103710c1aeae0217a3dcb640637 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 3 Apr 2014 09:26:44 +0200 Subject: Removed the bindings to set old g_BlockXXX arrays. Those were supposed to be read-only; there's no point in writing to them anyway. Also fixed MSVC type warnings in the code. --- src/Bindings/DeprecatedBindings.cpp | 362 +++++++----------------------------- 1 file changed, 65 insertions(+), 297 deletions(-) diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp index fbc008be6..d51ba2da3 100644 --- a/src/Bindings/DeprecatedBindings.cpp +++ b/src/Bindings/DeprecatedBindings.cpp @@ -21,47 +21,23 @@ #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockLightValue static int tolua_get_AllToLua_g_BlockLightValue(lua_State* tolua_S) { - int tolua_index; + int BlockType; #ifndef TOLUA_RELEASE { tolua_Error tolua_err; if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + { tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } } #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - tolua_pushnumber(tolua_S,(lua_Number)cBlockInfo::GetLightValue(tolua_index)); - return 1; -} -#endif //#ifndef TOLUA_DISABLE - - - - - -/* set function: g_BlockLightValue */ -#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockLightValue -static int tolua_set_AllToLua_g_BlockLightValue(lua_State* tolua_S) -{ - int tolua_index; - #ifndef TOLUA_RELEASE + BlockType = (int)tolua_tonumber(tolua_S, 2, 0); + if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID)) { - tolua_Error tolua_err; - if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) - tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + tolua_error(tolua_S, "array indexing out of range.", NULL); } - #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - cBlockInfo::Get(tolua_index).m_LightValue = ((unsigned char) tolua_tonumber(tolua_S,3,0)); - return 0; + tolua_pushnumber(tolua_S,(lua_Number)cBlockInfo::GetLightValue((BLOCKTYPE)BlockType)); + return 1; } #endif //#ifndef TOLUA_DISABLE @@ -73,7 +49,7 @@ static int tolua_set_AllToLua_g_BlockLightValue(lua_State* tolua_S) #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockSpreadLightFalloff static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) { - int tolua_index; + int BlockType; #ifndef TOLUA_RELEASE { tolua_Error tolua_err; @@ -81,39 +57,13 @@ static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); } #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - tolua_pushnumber(tolua_S,(lua_Number)cBlockInfo::GetSpreadLightFalloff(tolua_index)); - return 1; -} -#endif //#ifndef TOLUA_DISABLE - - - - - -/* set function: g_BlockSpreadLightFalloff */ -#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockSpreadLightFalloff -static int tolua_set_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) -{ - int tolua_index; - #ifndef TOLUA_RELEASE + BlockType = (int)tolua_tonumber(tolua_S, 2, 0); + if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID)) { - tolua_Error tolua_err; - if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) - tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + tolua_error(tolua_S, "array indexing out of range.", NULL); } - #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - cBlockInfo::Get(tolua_index).m_SpreadLightFalloff = ((unsigned char) tolua_tonumber(tolua_S,3,0)); - return 0; + tolua_pushnumber(tolua_S, (lua_Number)cBlockInfo::GetSpreadLightFalloff((BLOCKTYPE)BlockType)); + return 1; } #endif //#ifndef TOLUA_DISABLE @@ -125,7 +75,7 @@ static int tolua_set_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockTransparent static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S) { - int tolua_index; + int BlockType; #ifndef TOLUA_RELEASE { tolua_Error tolua_err; @@ -133,39 +83,13 @@ static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S) tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); } #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - tolua_pushboolean(tolua_S, cBlockInfo::IsTransparent(tolua_index)); - return 1; -} -#endif //#ifndef TOLUA_DISABLE - - - - - -/* set function: g_BlockTransparent */ -#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockTransparent -static int tolua_set_AllToLua_g_BlockTransparent(lua_State* tolua_S) -{ - int tolua_index; - #ifndef TOLUA_RELEASE + BlockType = (int)tolua_tonumber(tolua_S, 2, 0); + if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID)) { - tolua_Error tolua_err; - if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) - tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + tolua_error(tolua_S, "array indexing out of range.", NULL); } - #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - cBlockInfo::Get(tolua_index).m_Transparent = (tolua_toboolean(tolua_S,3,0) != 0); - return 0; + tolua_pushboolean(tolua_S, cBlockInfo::IsTransparent((BLOCKTYPE)BlockType)); + return 1; } #endif //#ifndef TOLUA_DISABLE @@ -177,7 +101,7 @@ static int tolua_set_AllToLua_g_BlockTransparent(lua_State* tolua_S) #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockOneHitDig static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) { - int tolua_index; + int BlockType; #ifndef TOLUA_RELEASE { tolua_Error tolua_err; @@ -185,39 +109,13 @@ static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); } #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsOneHitDig(tolua_index)); - return 1; -} -#endif //#ifndef TOLUA_DISABLE - - - - - -/* set function: g_BlockOneHitDig */ -#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockOneHitDig -static int tolua_set_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) -{ - int tolua_index; - #ifndef TOLUA_RELEASE + BlockType = (int)tolua_tonumber(tolua_S, 2, 0); + if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID)) { - tolua_Error tolua_err; - if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) - tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + tolua_error(tolua_S, "array indexing out of range.", NULL); } - #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - cBlockInfo::Get(tolua_index).m_OneHitDig = (tolua_toboolean(tolua_S,3,0) != 0); - return 0; + tolua_pushboolean(tolua_S, cBlockInfo::IsOneHitDig((BLOCKTYPE)BlockType)); + return 1; } #endif //#ifndef TOLUA_DISABLE @@ -229,7 +127,7 @@ static int tolua_set_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockPistonBreakable static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) { - int tolua_index; + int BlockType; #ifndef TOLUA_RELEASE { tolua_Error tolua_err; @@ -237,39 +135,13 @@ static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); } #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0 || tolua_index>=256) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsPistonBreakable(tolua_index)); - return 1; -} -#endif //#ifndef TOLUA_DISABLE - - - - - -/* set function: g_BlockPistonBreakable */ -#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockPistonBreakable -static int tolua_set_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) -{ - int tolua_index; - #ifndef TOLUA_RELEASE + BlockType = (int)tolua_tonumber(tolua_S, 2, 0); + if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID)) { - tolua_Error tolua_err; - if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) - tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + tolua_error(tolua_S, "array indexing out of range.", NULL); } - #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0 || tolua_index>=256) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - cBlockInfo::Get(tolua_index).m_PistonBreakable = (tolua_toboolean(tolua_S,3,0) != 0); - return 0; + tolua_pushboolean(tolua_S, cBlockInfo::IsPistonBreakable((BLOCKTYPE)BlockType)); + return 1; } #endif //#ifndef TOLUA_DISABLE @@ -281,7 +153,7 @@ static int tolua_set_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSnowable static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) { - int tolua_index; + int BlockType; #ifndef TOLUA_RELEASE { tolua_Error tolua_err; @@ -289,39 +161,13 @@ static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); } #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0 || tolua_index>=256) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsSnowable(tolua_index)); - return 1; -} -#endif //#ifndef TOLUA_DISABLE - - - - - -/* set function: g_BlockIsSnowable */ -#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSnowable -static int tolua_set_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) -{ - int tolua_index; - #ifndef TOLUA_RELEASE + BlockType = (int)tolua_tonumber(tolua_S, 2, 0); + if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID)) { - tolua_Error tolua_err; - if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) - tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + tolua_error(tolua_S, "array indexing out of range.", NULL); } - #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0 || tolua_index>=256) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - cBlockInfo::Get(tolua_index).m_IsSnowable = (tolua_toboolean(tolua_S,3,0) != 0); - return 0; + tolua_pushboolean(tolua_S, cBlockInfo::IsSnowable((BLOCKTYPE)BlockType)); + return 1; } #endif //#ifndef TOLUA_DISABLE @@ -333,7 +179,7 @@ static int tolua_set_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockRequiresSpecialTool static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) { - int tolua_index; + int BlockType; #ifndef TOLUA_RELEASE { tolua_Error tolua_err; @@ -341,39 +187,13 @@ static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); } #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0 || tolua_index>=256) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - tolua_pushboolean(tolua_S,(bool)cBlockInfo::RequiresSpecialTool(tolua_index)); - return 1; -} -#endif //#ifndef TOLUA_DISABLE - - - - - -/* set function: g_BlockRequiresSpecialTool */ -#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockRequiresSpecialTool -static int tolua_set_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) -{ - int tolua_index; - #ifndef TOLUA_RELEASE + BlockType = (int)tolua_tonumber(tolua_S, 2, 0); + if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID)) { - tolua_Error tolua_err; - if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) - tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + tolua_error(tolua_S, "array indexing out of range.", NULL); } - #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0 || tolua_index>=256) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - cBlockInfo::Get(tolua_index).m_RequiresSpecialTool = (tolua_toboolean(tolua_S,3,0) != 0); - return 0; + tolua_pushboolean(tolua_S, cBlockInfo::RequiresSpecialTool((BLOCKTYPE)BlockType)); + return 1; } #endif //#ifndef TOLUA_DISABLE @@ -385,7 +205,7 @@ static int tolua_set_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S) #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSolid static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S) { - int tolua_index; + int BlockType; #ifndef TOLUA_RELEASE { tolua_Error tolua_err; @@ -393,39 +213,13 @@ static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S) tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); } #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0 || tolua_index>=256) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsSolid(tolua_index)); - return 1; -} -#endif //#ifndef TOLUA_DISABLE - - - - - -/* set function: g_BlockIsSolid */ -#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSolid -static int tolua_set_AllToLua_g_BlockIsSolid(lua_State* tolua_S) -{ - int tolua_index; - #ifndef TOLUA_RELEASE + BlockType = (int)tolua_tonumber(tolua_S, 2, 0); + if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID)) { - tolua_Error tolua_err; - if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) - tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + tolua_error(tolua_S, "array indexing out of range.", NULL); } - #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0 || tolua_index>=256) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - cBlockInfo::Get(tolua_index).m_IsSolid = (tolua_toboolean(tolua_S,3,0) != 0); - return 0; + tolua_pushboolean(tolua_S, (bool)cBlockInfo::IsSolid((BLOCKTYPE)BlockType)); + return 1; } #endif //#ifndef TOLUA_DISABLE @@ -437,7 +231,7 @@ static int tolua_set_AllToLua_g_BlockIsSolid(lua_State* tolua_S) #ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockFullyOccupiesVoxel static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) { - int tolua_index; + int BlockType; #ifndef TOLUA_RELEASE { tolua_Error tolua_err; @@ -445,39 +239,13 @@ static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); } #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0 || tolua_index>=256) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - tolua_pushboolean(tolua_S,(bool)cBlockInfo::FullyOccupiesVoxel(tolua_index)); - return 1; -} -#endif //#ifndef TOLUA_DISABLE - - - - - -/* set function: g_BlockFullyOccupiesVoxel */ -#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockFullyOccupiesVoxel -static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) -{ - int tolua_index; - #ifndef TOLUA_RELEASE + BlockType = (int)tolua_tonumber(tolua_S, 2, 0); + if ((BlockType < 0) || (BlockType > E_BLOCK_MAX_TYPE_ID)) { - tolua_Error tolua_err; - if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) - tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + tolua_error(tolua_S, "array indexing out of range.", NULL); } - #endif - tolua_index = (int)tolua_tonumber(tolua_S,2,0); - #ifndef TOLUA_RELEASE - if (tolua_index<0 || tolua_index>=256) - tolua_error(tolua_S,"array indexing out of range.",NULL); - #endif - cBlockInfo::Get(tolua_index).m_FullyOccupiesVoxel = (tolua_toboolean(tolua_S,3,0) != 0); - return 0; + tolua_pushboolean(tolua_S, (bool)cBlockInfo::FullyOccupiesVoxel((BLOCKTYPE)BlockType)); + return 1; } #endif //#ifndef TOLUA_DISABLE @@ -489,15 +257,15 @@ void DeprecatedBindings::Bind(lua_State * tolua_S) { tolua_beginmodule(tolua_S, NULL); - tolua_array(tolua_S, "g_BlockLightValue", tolua_get_AllToLua_g_BlockLightValue, tolua_set_AllToLua_g_BlockLightValue); - tolua_array(tolua_S, "g_BlockSpreadLightFalloff", tolua_get_AllToLua_g_BlockSpreadLightFalloff, tolua_set_AllToLua_g_BlockSpreadLightFalloff); - tolua_array(tolua_S, "g_BlockTransparent", tolua_get_AllToLua_g_BlockTransparent, tolua_set_AllToLua_g_BlockTransparent); - tolua_array(tolua_S, "g_BlockOneHitDig", tolua_get_AllToLua_g_BlockOneHitDig, tolua_set_AllToLua_g_BlockOneHitDig); - tolua_array(tolua_S, "g_BlockPistonBreakable", tolua_get_AllToLua_g_BlockPistonBreakable, tolua_set_AllToLua_g_BlockPistonBreakable); - tolua_array(tolua_S, "g_BlockIsSnowable", tolua_get_AllToLua_g_BlockIsSnowable, tolua_set_AllToLua_g_BlockIsSnowable); - tolua_array(tolua_S, "g_BlockRequiresSpecialTool", tolua_get_AllToLua_g_BlockRequiresSpecialTool, tolua_set_AllToLua_g_BlockRequiresSpecialTool); - tolua_array(tolua_S, "g_BlockIsSolid", tolua_get_AllToLua_g_BlockIsSolid, tolua_set_AllToLua_g_BlockIsSolid); - tolua_array(tolua_S, "g_BlockFullyOccupiesVoxel", tolua_get_AllToLua_g_BlockFullyOccupiesVoxel, tolua_set_AllToLua_g_BlockFullyOccupiesVoxel); + tolua_array(tolua_S, "g_BlockLightValue", tolua_get_AllToLua_g_BlockLightValue, NULL); + tolua_array(tolua_S, "g_BlockSpreadLightFalloff", tolua_get_AllToLua_g_BlockSpreadLightFalloff, NULL); + tolua_array(tolua_S, "g_BlockTransparent", tolua_get_AllToLua_g_BlockTransparent, NULL); + tolua_array(tolua_S, "g_BlockOneHitDig", tolua_get_AllToLua_g_BlockOneHitDig, NULL); + tolua_array(tolua_S, "g_BlockPistonBreakable", tolua_get_AllToLua_g_BlockPistonBreakable, NULL); + tolua_array(tolua_S, "g_BlockIsSnowable", tolua_get_AllToLua_g_BlockIsSnowable, NULL); + tolua_array(tolua_S, "g_BlockRequiresSpecialTool", tolua_get_AllToLua_g_BlockRequiresSpecialTool, NULL); + tolua_array(tolua_S, "g_BlockIsSolid", tolua_get_AllToLua_g_BlockIsSolid, NULL); + tolua_array(tolua_S, "g_BlockFullyOccupiesVoxel", tolua_get_AllToLua_g_BlockFullyOccupiesVoxel, NULL); tolua_endmodule(tolua_S); } -- cgit v1.2.3 From 25529ba62f949b98ed30e905ee4921c737d7df87 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 3 Apr 2014 09:27:17 +0200 Subject: Fixed a few MSVC type warnings. --- src/BlockArea.cpp | 2 +- src/BlockEntities/CommandBlockEntity.cpp | 2 +- src/Globals.h | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 60e4f11e5..40cca8882 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -530,7 +530,7 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName) f.Write(&SizeX, 4); f.Write(&SizeY, 4); f.Write(&SizeZ, 4); - unsigned char DataTypes = GetDataTypes(); + unsigned char DataTypes = (unsigned char)GetDataTypes(); f.Write(&DataTypes, 1); int NumBlocks = GetBlockCount(); if (HasBlockTypes()) diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp index d395997a6..96ca0ac37 100644 --- a/src/BlockEntities/CommandBlockEntity.cpp +++ b/src/BlockEntities/CommandBlockEntity.cpp @@ -160,7 +160,7 @@ bool cCommandBlockEntity::LoadFromJson(const Json::Value & a_Value) m_Command = a_Value.get("Command", "").asString(); m_LastOutput = a_Value.get("LastOutput", "").asString(); - m_Result = a_Value.get("SuccessCount", 0).asInt(); + m_Result = (NIBBLETYPE)a_Value.get("SuccessCount", 0).asInt(); return true; } diff --git a/src/Globals.h b/src/Globals.h index a1cee5c2f..26a0d87a9 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -29,6 +29,9 @@ // Disabling this warning, because we know what we're doing when we're doing this: #pragma warning(disable: 4355) // 'this' used in initializer list + + // Disabled because it's useless: + #pragma warning(disable: 4512) // 'class': assignment operator could not be generated - reported for each class that has a reference-type member // 2014_01_06 xoft: Disabled this warning because MSVC is stupid and reports it in obviously wrong places // #pragma warning(3 : 4244) // Conversion from 'type1' to 'type2', possible loss of data -- cgit v1.2.3 From 1b78bef4b355c84ee86688eb4f802e5f8a8ccd78 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 2 Apr 2014 17:57:14 +0200 Subject: Removed unneeded asserts. --- src/LightingThread.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/LightingThread.h b/src/LightingThread.h index 3209ad9b2..770ae809f 100644 --- a/src/LightingThread.h +++ b/src/LightingThread.h @@ -164,9 +164,7 @@ protected: int & a_NumSeedsOut, unsigned char * a_IsSeedOut, unsigned int * a_SeedIdxOut ) { - ASSERT(a_SrcIdx >= 0); ASSERT(a_SrcIdx < ARRAYCOUNT(m_SkyLight)); - ASSERT(a_DstIdx >= 0); ASSERT(a_DstIdx < ARRAYCOUNT(m_BlockTypes)); if (a_Light[a_SrcIdx] <= a_Light[a_DstIdx] + cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx])) -- cgit v1.2.3 From e304bd08a2363f43bf845b2b370c18a60d1b66d1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 3 Apr 2014 21:44:03 +0200 Subject: Documented the units and range for entity rotations. --- MCServer/Plugins/APIDump/APIDesc.lua | 6 +++--- src/Entities/Entity.h | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 451b7364a..b0086d740 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -777,14 +777,14 @@ end
    GetMass = { Params = "", Return = "number", Notes = "Returns the mass of the entity. Currently unused." }, GetMaxHealth = { Params = "", Return = "number", Notes = "Returns the maximum number of hitpoints this entity is allowed to have." }, GetParentClass = { Params = "", Return = "string", Notes = "Returns the name of the direct parent class for this entity" }, - GetPitch = { Params = "", Return = "number", Notes = "Returns the pitch (nose-down rotation) of the entity" }, + GetPitch = { Params = "", Return = "number", Notes = "Returns the pitch (nose-down rotation) of the entity. Measured in degrees, values range from -90 to +90." }, GetPosition = { Params = "", Return = "{{Vector3d}}", Notes = "Returns the entity's pivot position as a 3D vector" }, GetPosX = { Params = "", Return = "number", Notes = "Returns the X-coord of the entity's pivot" }, GetPosY = { Params = "", Return = "number", Notes = "Returns the Y-coord of the entity's pivot" }, GetPosZ = { Params = "", Return = "number", Notes = "Returns the Z-coord of the entity's pivot" }, GetRawDamageAgainst = { Params = "ReceiverEntity", Return = "number", Notes = "Returns the raw damage that this entity's equipment would cause when attacking the ReceiverEntity. This includes this entity's weapon {{cEnchantments|enchantments}}, but excludes the receiver's armor or potion effects. See {{TakeDamageInfo}} for more information on attack damage." }, GetRoll = { Params = "", Return = "number", Notes = "Returns the roll (sideways rotation) of the entity. Currently unused." }, - GetRot = { Params = "", Return = "{{Vector3f}}", Notes = "Returns the entire rotation vector (Yaw, Pitch, Roll)" }, + GetRot = { Params = "", Return = "{{Vector3f}}", Notes = "(OBSOLETE) Returns the entire rotation vector (Yaw, Pitch, Roll)" }, GetSpeed = { Params = "", Return = "{{Vector3d}}", Notes = "Returns the complete speed vector of the entity" }, GetSpeedX = { Params = "", Return = "number", Notes = "Returns the X-part of the speed vector" }, GetSpeedY = { Params = "", Return = "number", Notes = "Returns the Y-part of the speed vector" }, @@ -792,7 +792,7 @@ end GetUniqueID = { Params = "", Return = "number", Notes = "Returns the ID that uniquely identifies the entity within the running server. Note that this ID is not persisted to the data files." }, GetWidth = { Params = "", Return = "number", Notes = "Returns the width (X and Z size) of the entity." }, GetWorld = { Params = "", Return = "{{cWorld}}", Notes = "Returns the world where the entity resides" }, - GetYaw = { Params = "", Return = "number", Notes = "Returns the yaw (direction) of the entity." }, + GetYaw = { Params = "", Return = "number", Notes = "Returns the yaw (direction) of the entity. Measured in degrees, values range from -180 to +180." }, Heal = { Params = "Hitpoints", Return = "", Notes = "Heals the specified number of hitpoints. Hitpoints is expected to be a positive number." }, IsA = { Params = "ClassName", Return = "bool", Notes = "Returns true if the entity class is a descendant of the specified class name, or the specified class itself" }, IsBoat = { Params = "", Return = "bool", Notes = "Returns true if the entity is a {{cBoat|boat}}." }, diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index e41f74b09..6e3f8292b 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -159,7 +159,7 @@ public: cWorld * GetWorld(void) const { return m_World; } - double GetHeadYaw (void) const { return m_HeadYaw; } + double GetHeadYaw (void) const { return m_HeadYaw; } // In degrees double GetHeight (void) const { return m_Height; } double GetMass (void) const { return m_Mass; } const Vector3d & GetPosition (void) const { return m_Pos; } @@ -167,9 +167,9 @@ public: double GetPosY (void) const { return m_Pos.y; } double GetPosZ (void) const { return m_Pos.z; } const Vector3d & GetRot (void) const { return m_Rot; } // OBSOLETE, use individual GetYaw(), GetPitch, GetRoll() components - double GetYaw (void) const { return m_Rot.x; } - double GetPitch (void) const { return m_Rot.y; } - double GetRoll (void) const { return m_Rot.z; } + double GetYaw (void) const { return m_Rot.x; } // In degrees, [-180, +180) + double GetPitch (void) const { return m_Rot.y; } // In degrees, [-180, +180), but normal client clips to [-90, +90] + double GetRoll (void) const { return m_Rot.z; } // In degrees, unused in current client Vector3d GetLookVector(void) const; const Vector3d & GetSpeed (void) const { return m_Speed; } double GetSpeedX (void) const { return m_Speed.x; } @@ -189,9 +189,9 @@ public: void SetPosition(double a_PosX, double a_PosY, double a_PosZ); void SetPosition(const Vector3d & a_Pos) { SetPosition(a_Pos.x, a_Pos.y, a_Pos.z); } void SetRot (const Vector3f & a_Rot); // OBSOLETE, use individual SetYaw(), SetPitch(), SetRoll() components - void SetYaw (double a_Yaw); - void SetPitch (double a_Pitch); - void SetRoll (double a_Roll); + void SetYaw (double a_Yaw); // In degrees, normalizes to [-180, +180) + void SetPitch (double a_Pitch); // In degrees, normalizes to [-180, +180) + void SetRoll (double a_Roll); // In degrees, normalizes to [-180, +180) void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ); void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } void SetSpeedX (double a_SpeedX); -- cgit v1.2.3 From e2fb507be2157194dc435e30c856ffb4e6ad4ed6 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 3 Apr 2014 21:52:50 +0200 Subject: APIDump: Added angular specifics. --- MCServer/Plugins/APIDump/APIDesc.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index b0086d740..b3b7dd11c 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -777,7 +777,7 @@ end GetMass = { Params = "", Return = "number", Notes = "Returns the mass of the entity. Currently unused." }, GetMaxHealth = { Params = "", Return = "number", Notes = "Returns the maximum number of hitpoints this entity is allowed to have." }, GetParentClass = { Params = "", Return = "string", Notes = "Returns the name of the direct parent class for this entity" }, - GetPitch = { Params = "", Return = "number", Notes = "Returns the pitch (nose-down rotation) of the entity. Measured in degrees, values range from -90 to +90." }, + GetPitch = { Params = "", Return = "number", Notes = "Returns the pitch (nose-down rotation) of the entity. Measured in degrees, normal values range from -90 to +90. +90 means looking down, 0 means looking straight ahead, -90 means looking up." }, GetPosition = { Params = "", Return = "{{Vector3d}}", Notes = "Returns the entity's pivot position as a 3D vector" }, GetPosX = { Params = "", Return = "number", Notes = "Returns the X-coord of the entity's pivot" }, GetPosY = { Params = "", Return = "number", Notes = "Returns the Y-coord of the entity's pivot" }, @@ -792,7 +792,7 @@ end GetUniqueID = { Params = "", Return = "number", Notes = "Returns the ID that uniquely identifies the entity within the running server. Note that this ID is not persisted to the data files." }, GetWidth = { Params = "", Return = "number", Notes = "Returns the width (X and Z size) of the entity." }, GetWorld = { Params = "", Return = "{{cWorld}}", Notes = "Returns the world where the entity resides" }, - GetYaw = { Params = "", Return = "number", Notes = "Returns the yaw (direction) of the entity. Measured in degrees, values range from -180 to +180." }, + GetYaw = { Params = "", Return = "number", Notes = "Returns the yaw (direction) of the entity. Measured in degrees, values range from -180 to +180. 0 means ZP, 90 means XM, -180 means ZM, -90 means XP." }, Heal = { Params = "Hitpoints", Return = "", Notes = "Heals the specified number of hitpoints. Hitpoints is expected to be a positive number." }, IsA = { Params = "ClassName", Return = "bool", Notes = "Returns true if the entity class is a descendant of the specified class name, or the specified class itself" }, IsBoat = { Params = "", Return = "bool", Notes = "Returns true if the entity is a {{cBoat|boat}}." }, -- cgit v1.2.3 From 0fb40da8776482a90a86a46760ae8c9560963a73 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 3 Apr 2014 21:53:18 +0200 Subject: Change CanBeAt() from big flower --- src/Blocks/BlockBigFlower.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h index 98d6502ab..39fd3cac8 100644 --- a/src/Blocks/BlockBigFlower.h +++ b/src/Blocks/BlockBigFlower.h @@ -81,11 +81,7 @@ public: virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { - return ( - a_RelY > 0 - && a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR - && a_RelY < cChunkDef::Height - ); + return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR) && (a_RelY < cChunkDef::Height) && ((a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_AIR) || (a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_BIG_FLOWER))); } -- cgit v1.2.3 From 446a6515029e66b1f76358dcee1ccfe59c432bdd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 08:55:48 +0200 Subject: ProtoProxy: Fixed a few Clang and MSVC warnings. --- Tools/ProtoProxy/Connection.cpp | 10 +++++++--- Tools/ProtoProxy/Connection.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index f02b503f1..d9b8e3dd1 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -387,6 +387,8 @@ bool cConnection::RelayFromServer(void) return CLIENTSEND(Buffer, res); } } + ASSERT(!"Unhandled server state while relaying from server"); + return false; } @@ -423,6 +425,8 @@ bool cConnection::RelayFromClient(void) return SERVERSEND(Buffer, res); } } + ASSERT(!"Unhandled server state while relaying from client"); + return false; } @@ -438,11 +442,11 @@ double cConnection::GetRelativeTime(void) -bool cConnection::SendData(SOCKET a_Socket, const char * a_Data, int a_Size, const char * a_Peer) +bool cConnection::SendData(SOCKET a_Socket, const char * a_Data, size_t a_Size, const char * a_Peer) { - DataLog(a_Data, a_Size, "Sending data to %s, %d bytes", a_Peer, a_Size); + DataLog(a_Data, a_Size, "Sending data to %s, %u bytes", a_Peer, (unsigned)a_Size); - int res = send(a_Socket, a_Data, a_Size, 0); + int res = send(a_Socket, a_Data, (int)a_Size, 0); if (res <= 0) { Log("%s closed the socket: %d, %d; aborting connection", a_Peer, res, SocketError); diff --git a/Tools/ProtoProxy/Connection.h b/Tools/ProtoProxy/Connection.h index 70b759d0f..9e04994b7 100644 --- a/Tools/ProtoProxy/Connection.h +++ b/Tools/ProtoProxy/Connection.h @@ -103,7 +103,7 @@ protected: double GetRelativeTime(void); /// Sends data to the specified socket. If sending fails, prints a fail message using a_Peer and returns false. - bool SendData(SOCKET a_Socket, const char * a_Data, int a_Size, const char * a_Peer); + bool SendData(SOCKET a_Socket, const char * a_Data, size_t a_Size, const char * a_Peer); /// Sends data to the specified socket. If sending fails, prints a fail message using a_Peer and returns false. bool SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a_Peer); -- cgit v1.2.3 From 402d85d896c793644681c4bb2934a7e0abb5ed8c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 09:56:57 +0200 Subject: Fixed Clang warnings in itemhandlers. --- src/Blocks/BlockSign.h | 4 ++-- src/Items/ItemEmptyMap.h | 2 +- src/Items/ItemFishingRod.h | 4 ++-- src/Items/ItemHandler.cpp | 6 +++--- src/Items/ItemLilypad.h | 23 ++++++++++++----------- src/Items/ItemMap.h | 2 +- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/Blocks/BlockSign.h b/src/Blocks/BlockSign.h index 6c0becfd6..9d6fede21 100644 --- a/src/Blocks/BlockSign.h +++ b/src/Blocks/BlockSign.h @@ -31,7 +31,7 @@ public: } - static char RotationToMetaData(double a_Rotation) + static NIBBLETYPE RotationToMetaData(double a_Rotation) { a_Rotation += 180 + (180 / 16); // So it's not aligned with axis if (a_Rotation > 360) @@ -45,7 +45,7 @@ public: } - static char DirectionToMetaData(eBlockFace a_Direction) + static NIBBLETYPE DirectionToMetaData(eBlockFace a_Direction) { switch (a_Direction) { diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index f0b1e1424..953673382 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -55,7 +55,7 @@ public: return true; } - a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, NewMap->GetID()), true, true); + a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, (short)(NewMap->GetID() & 0x7fff)), true, true); return true; } diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h index 15acbd9fe..0431b88b7 100644 --- a/src/Items/ItemFishingRod.h +++ b/src/Items/ItemFishingRod.h @@ -123,7 +123,7 @@ public: } case 2: { - Drops.Add(cItem(E_ITEM_FISHING_ROD, 1, a_World->GetTickRandomNumber(50))); // Fishing rod with durability. TODO: Enchantments on it + Drops.Add(cItem(E_ITEM_FISHING_ROD, 1, (short)a_World->GetTickRandomNumber(50))); // Fishing rod with durability. TODO: Enchantments on it break; } case 3: @@ -152,7 +152,7 @@ public: } else if (Junk <= 4) { - Drops.Add(cItem(E_ITEM_BOW, 1, a_World->GetTickRandomNumber(64))); + Drops.Add(cItem(E_ITEM_BOW, 1, (short)a_World->GetTickRandomNumber(64))); } else if (Junk <= 9) { diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 337b3a83c..1e77717e3 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -506,13 +506,13 @@ bool cItemHandler::GetPlacementBlockTypeMeta( { ASSERT(m_ItemType < 256); // Items with IDs above 255 should all be handled by specific handlers - if (m_ItemType > 256) + if (m_ItemType >= 256) { - LOGERROR("%s: Item %d has no valid block!", __FUNCTION__, m_ItemType); + LOGERROR("%s: Item %d is not eligible for direct block placement!", __FUNCTION__, m_ItemType); return false; } - cBlockHandler * BlockH = BlockHandler(m_ItemType); + cBlockHandler * BlockH = BlockHandler((BLOCKTYPE)m_ItemType); cChunkInterface ChunkInterface(a_World->GetChunkMap()); return BlockH->GetPlacementBlockTypeMeta( ChunkInterface, a_Player, diff --git a/src/Items/ItemLilypad.h b/src/Items/ItemLilypad.h index 5a29abe94..8fc1d8543 100644 --- a/src/Items/ItemLilypad.h +++ b/src/Items/ItemLilypad.h @@ -16,17 +16,19 @@ class cItemLilypadHandler : typedef cItemHandler super; public: - cItemLilypadHandler(BLOCKTYPE a_BlockType) - : cItemHandler(a_BlockType) + cItemLilypadHandler(int a_ItemType): + super(a_ItemType) { } + virtual bool IsPlaceable(void) override { return false; // Set as not placeable so OnItemUse is called } + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override { if (a_BlockFace > BLOCK_FACE_NONE) @@ -45,23 +47,22 @@ public: public cBlockTracer::cCallbacks { public: - cCallbacks(cWorld * a_World) : + cCallbacks(cWorld * a_CBWorld) : m_HasHitFluid(false), - m_World(a_World) + m_World(a_CBWorld) { } - virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override + virtual bool OnNextBlock(int a_CBBlockX, int a_CBBlockY, int a_CBBlockZ, BLOCKTYPE a_CBBlockType, NIBBLETYPE a_CBBlockMeta, char a_CBEntryFace) override { - if (IsBlockWater(a_BlockType)) + if (IsBlockWater(a_CBBlockType)) { - if ((a_BlockMeta != 0) || (a_EntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is clicking whilst submerged + if ((a_CBBlockMeta != 0) || (a_CBEntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is clicking whilst submerged { return false; } - a_EntryFace = BLOCK_FACE_YP; // Always place pad at top of water block - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, (eBlockFace)a_EntryFace); - BLOCKTYPE Block = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + AddFaceDirection(a_CBBlockX, a_CBBlockY, a_CBBlockZ, BLOCK_FACE_YP); // Always place pad at top of water block + BLOCKTYPE Block = m_World->GetBlock(a_CBBlockX, a_CBBlockY, a_CBBlockZ); if ( !IsBlockWater(Block) && cBlockInfo::FullyOccupiesVoxel(Block) @@ -71,7 +72,7 @@ public: return true; } m_HasHitFluid = true; - m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); + m_Pos.Set(a_CBBlockX, a_CBBlockY, a_CBBlockZ); return true; } return false; diff --git a/src/Items/ItemMap.h b/src/Items/ItemMap.h index e8ff9da88..056fe0fe7 100644 --- a/src/Items/ItemMap.h +++ b/src/Items/ItemMap.h @@ -29,7 +29,7 @@ public: virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item) { - cMap * Map = a_World->GetMapManager().GetMapData(a_Item.m_ItemDamage); + cMap * Map = a_World->GetMapManager().GetMapData((unsigned)a_Item.m_ItemDamage); if (Map == NULL) { -- cgit v1.2.3 From 8825d30aabbee8cb2e452dc5a17deb6f9b6892a7 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 10:13:25 +0200 Subject: Fixed some Clang warnings in protocols. --- src/ClientHandle.cpp | 4 ++-- src/ClientHandle.h | 2 +- src/Endianness.h | 31 +++++++++++++++++-------------- src/Protocol/Protocol.h | 27 ++++++++++++++++----------- src/Protocol/Protocol125.cpp | 2 +- src/Protocol/Protocol125.h | 2 +- src/Protocol/Protocol132.cpp | 2 +- src/Protocol/Protocol132.h | 2 +- src/Protocol/Protocol14x.cpp | 12 ++++++------ src/Protocol/Protocol17x.cpp | 4 ++-- src/Protocol/Protocol17x.h | 2 +- src/Protocol/ProtocolRecognizer.cpp | 2 +- src/Protocol/ProtocolRecognizer.h | 2 +- 13 files changed, 51 insertions(+), 43 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 23ba4dbab..daf2c4da8 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1532,7 +1532,7 @@ void cClientHandle::HandleTabCompletion(const AString & a_Text) -void cClientHandle::SendData(const char * a_Data, int a_Size) +void cClientHandle::SendData(const char * a_Data, size_t a_Size) { if (m_HasSentDC) { @@ -1547,7 +1547,7 @@ void cClientHandle::SendData(const char * a_Data, int a_Size) if (m_OutgoingDataOverflow.empty()) { // No queued overflow data; if this packet fits into the ringbuffer, put it in, otherwise put it in the overflow buffer: - int CanFit = m_OutgoingData.GetFreeSpace(); + size_t CanFit = m_OutgoingData.GetFreeSpace(); if (CanFit > a_Size) { CanFit = a_Size; diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 5496e61a7..d83a323f9 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -225,7 +225,7 @@ public: */ bool HandleLogin(int a_ProtocolVersion, const AString & a_Username); - void SendData(const char * a_Data, int a_Size); + void SendData(const char * a_Data, size_t a_Size); /** Called when the player moves into a different world; queues sreaming the new chunks */ void MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket); diff --git a/src/Endianness.h b/src/Endianness.h index 86eb369f5..6a2593077 100644 --- a/src/Endianness.h +++ b/src/Endianness.h @@ -1,12 +1,14 @@ #pragma once +#define ntohll(x) ((((UInt64)ntohl((u_long)x)) << 32) + ntohl(x >> 32)) + // Changes endianness -inline unsigned long long HostToNetwork8(const void* a_Value ) +inline UInt64 HostToNetwork8(const void * a_Value) { unsigned long long __HostToNetwork8; memcpy( &__HostToNetwork8, a_Value, sizeof( __HostToNetwork8 ) ); @@ -18,7 +20,7 @@ inline unsigned long long HostToNetwork8(const void* a_Value ) -inline unsigned int HostToNetwork4(const void* a_Value ) +inline UInt32 HostToNetwork4(const void* a_Value ) { unsigned int __HostToNetwork4; memcpy( &__HostToNetwork4, a_Value, sizeof( __HostToNetwork4 ) ); @@ -30,11 +32,10 @@ inline unsigned int HostToNetwork4(const void* a_Value ) -inline double NetworkToHostDouble8(const void* a_Value ) +inline double NetworkToHostDouble8(const void * a_Value) { -#define ntohll(x) ((((unsigned long long)ntohl((u_long)x)) << 32) + ntohl(x >> 32)) - unsigned long long buf = 0;//(*(unsigned long long*)a_Value); - memcpy( &buf, a_Value, 8 ); + UInt64 buf = 0; + memcpy(&buf, a_Value, 8); buf = ntohll(buf); double x; memcpy(&x, &buf, sizeof(double)); @@ -45,23 +46,25 @@ inline double NetworkToHostDouble8(const void* a_Value ) -inline long long NetworkToHostLong8(const void * a_Value ) +inline Int64 NetworkToHostLong8(const void * a_Value) { - unsigned long long buf = *(unsigned long long*)a_Value; + UInt64 buf; + memcpy(&buf, &a_Value, 8); buf = ntohll(buf); - return *reinterpret_cast(&buf); + return *reinterpret_cast(&buf); } -inline float NetworkToHostFloat4(const void* a_Value ) +inline float NetworkToHostFloat4(const void * a_Value) { - u_long buf = *(u_long*)a_Value; - buf = ntohl( buf ); - float x = 0; - memcpy( &x, &buf, sizeof(float) ); + UInt32 buf; + float x; + memcpy(&buf, &a_Value, 4); + buf = ntohl(buf); + memcpy(&x, &buf, sizeof(float)); return x; } diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index d3383bf0d..8294fa8b7 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -132,7 +132,7 @@ protected: cCriticalSection m_CSPacket; //< Each SendXYZ() function must acquire this CS in order to send the whole packet at once /// A generic data-sending routine, all outgoing packet data needs to be routed through this so that descendants may override it - virtual void SendData(const char * a_Data, int a_Size) = 0; + virtual void SendData(const char * a_Data, size_t a_Size) = 0; /// Called after writing each packet, enables descendants to flush their buffers virtual void Flush(void) {}; @@ -143,10 +143,15 @@ protected: SendData((const char *)&a_Value, 1); } + void WriteChar(char a_Value) + { + SendData(&a_Value, 1); + } + void WriteShort(short a_Value) { - a_Value = htons(a_Value); - SendData((const char *)&a_Value, 2); + u_short Value = htons((u_short)a_Value); + SendData((const char *)&Value, 2); } /* @@ -159,8 +164,8 @@ protected: void WriteInt(int a_Value) { - a_Value = htonl(a_Value); - SendData((const char *)&a_Value, 4); + u_long Value = htonl((u_long)a_Value); + SendData((const char *)&Value, 4); } void WriteUInt(unsigned int a_Value) @@ -171,19 +176,19 @@ protected: void WriteInt64 (Int64 a_Value) { - a_Value = HostToNetwork8(&a_Value); - SendData((const char *)&a_Value, 8); + UInt64 Value = HostToNetwork8(&a_Value); + SendData((const char *)Value, 8); } void WriteFloat (float a_Value) { - unsigned int val = HostToNetwork4(&a_Value); + UInt32 val = HostToNetwork4(&a_Value); SendData((const char *)&val, 4); } void WriteDouble(double a_Value) { - unsigned long long val = HostToNetwork8(&a_Value); + UInt64 val = HostToNetwork8(&a_Value); SendData((const char *)&val, 8); } @@ -191,7 +196,7 @@ protected: { AString UTF16; UTF8ToRawBEUTF16(a_Value.c_str(), a_Value.length(), UTF16); - WriteShort((unsigned short)(UTF16.size() / 2)); + WriteShort((short)(UTF16.size() / 2)); SendData(UTF16.data(), UTF16.size()); } @@ -224,7 +229,7 @@ protected: void WriteVarUTF8String(const AString & a_String) { - WriteVarInt(a_String.size()); + WriteVarInt((UInt32)a_String.size()); SendData(a_String.data(), a_String.size()); } } ; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index fe6280218..0fa5c6de7 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1156,7 +1156,7 @@ AString cProtocol125::GetAuthServerID(void) -void cProtocol125::SendData(const char * a_Data, int a_Size) +void cProtocol125::SendData(const char * a_Data, size_t a_Size) { m_Client->SendData(a_Data, a_Size); } diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index aca24c03a..08d3ebbe9 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -125,7 +125,7 @@ protected: AString m_Username; ///< Stored in ParseHandshake(), compared to Login username - virtual void SendData(const char * a_Data, int a_Size) override; + virtual void SendData(const char * a_Data, size_t a_Size) override; /// Sends the Handshake packet void SendHandshake(const AString & a_ConnectionHash); diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index be9c503ed..ce5d134ea 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -605,7 +605,7 @@ int cProtocol132::ParseTabCompletion(void) -void cProtocol132::SendData(const char * a_Data, int a_Size) +void cProtocol132::SendData(const char * a_Data, size_t a_Size) { m_DataToSend.append(a_Data, a_Size); } diff --git a/src/Protocol/Protocol132.h b/src/Protocol/Protocol132.h index 0702fbf5a..b280c8a41 100644 --- a/src/Protocol/Protocol132.h +++ b/src/Protocol/Protocol132.h @@ -87,7 +87,7 @@ protected: /// The ServerID used for session authentication; set in StartEncryption(), used in GetAuthServerID() AString m_AuthServerID; - virtual void SendData(const char * a_Data, int a_Size) override; + virtual void SendData(const char * a_Data, size_t a_Size) override; // DEBUG: virtual void Flush(void) override; diff --git a/src/Protocol/Protocol14x.cpp b/src/Protocol/Protocol14x.cpp index 232b2718e..f694af1eb 100644 --- a/src/Protocol/Protocol14x.cpp +++ b/src/Protocol/Protocol14x.cpp @@ -103,9 +103,9 @@ void cProtocol142::SendPickupSpawn(const cPickup & a_Pickup) WriteInt (a_Pickup.GetUniqueID()); WriteItem (a_Pickup.GetItem()); WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32)); - WriteByte ((char)(a_Pickup.GetSpeed().x * 8)); - WriteByte ((char)(a_Pickup.GetSpeed().y * 8)); - WriteByte ((char)(a_Pickup.GetSpeed().z * 8)); + WriteChar ((char)(a_Pickup.GetSpeed().x * 8)); + WriteChar ((char)(a_Pickup.GetSpeed().y * 8)); + WriteChar ((char)(a_Pickup.GetSpeed().z * 8)); Flush(); } @@ -119,7 +119,7 @@ void cProtocol142::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src WriteByte(PACKET_SOUND_PARTICLE_EFFECT); WriteInt (a_EffectID); WriteInt (a_SrcX); - WriteByte(a_SrcY); + WriteByte((Byte)a_SrcY); WriteInt (a_SrcZ); WriteInt (a_Data); WriteBool(0); @@ -218,7 +218,7 @@ void cProtocol146::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, cCSLock Lock(m_CSPacket); WriteByte(PACKET_SPAWN_OBJECT); WriteInt (a_Entity.GetUniqueID()); - WriteByte(a_ObjectType); + WriteChar(a_ObjectType); WriteInt ((int)(a_Entity.GetPosX() * 32)); WriteInt ((int)(a_Entity.GetPosY() * 32)); WriteInt ((int)(a_Entity.GetPosZ() * 32)); @@ -243,7 +243,7 @@ void cProtocol146::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp cCSLock Lock(m_CSPacket); WriteByte (PACKET_SPAWN_OBJECT); WriteInt (a_Vehicle.GetUniqueID()); - WriteByte (a_VehicleType); + WriteChar (a_VehicleType); WriteInt ((int)(a_Vehicle.GetPosX() * 32)); WriteInt ((int)(a_Vehicle.GetPosY() * 32)); WriteInt ((int)(a_Vehicle.GetPosZ() * 32)); diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index c678fc9a0..b987294b0 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1988,14 +1988,14 @@ void cProtocol172::WritePacket(cByteBuffer & a_Packet) -void cProtocol172::SendData(const char * a_Data, int a_Size) +void cProtocol172::SendData(const char * a_Data, size_t a_Size) { if (m_IsEncrypted) { Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks) while (a_Size > 0) { - size_t NumBytes = ((size_t)a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : (size_t)a_Size; + size_t NumBytes = (a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : a_Size; m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes); m_Client->SendData((const char *)Encrypted, NumBytes); a_Size -= NumBytes; diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 41163009e..bb6ee575a 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -287,7 +287,7 @@ protected: void WritePacket(cByteBuffer & a_Packet); /** Sends the data to the client, encrypting them if needed. */ - virtual void SendData(const char * a_Data, int a_Size) override; + virtual void SendData(const char * a_Data, size_t a_Size) override; void SendCompass(const cWorld & a_World); diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 3b9003e60..81f146370 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -794,7 +794,7 @@ AString cProtocolRecognizer::GetAuthServerID(void) -void cProtocolRecognizer::SendData(const char * a_Data, int a_Size) +void cProtocolRecognizer::SendData(const char * a_Data, size_t a_Size) { // This is used only when handling the server ping m_Client->SendData(a_Data, a_Size); diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index d7fb8fad2..072d7c2d2 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -133,7 +133,7 @@ public: virtual AString GetAuthServerID(void) override; - virtual void SendData(const char * a_Data, int a_Size) override; + virtual void SendData(const char * a_Data, size_t a_Size) override; protected: cProtocol * m_Protocol; //< The recognized protocol -- cgit v1.2.3 From 396abb5db6e46f214e27e4dba1099490bf03bb0a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 10:19:21 +0200 Subject: Fixed silly Clang's warnings in FastNBT. --- src/WorldStorage/FastNBT.h | 56 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h index 1b8b09c21..5e5af3ca3 100644 --- a/src/WorldStorage/FastNBT.h +++ b/src/WorldStorage/FastNBT.h @@ -122,33 +122,33 @@ public: int GetRoot(void) const {return 0; } /** Returns the first child of the specified tag, or -1 if none / not applicable. */ - int GetFirstChild (int a_Tag) const { return m_Tags[a_Tag].m_FirstChild; } + int GetFirstChild (int a_Tag) const { return m_Tags[(size_t)a_Tag].m_FirstChild; } /** Returns the last child of the specified tag, or -1 if none / not applicable. */ - int GetLastChild (int a_Tag) const { return m_Tags[a_Tag].m_LastChild; } + int GetLastChild (int a_Tag) const { return m_Tags[(size_t)a_Tag].m_LastChild; } /** Returns the next sibling of the specified tag, or -1 if none. */ - int GetNextSibling(int a_Tag) const { return m_Tags[a_Tag].m_NextSibling; } + int GetNextSibling(int a_Tag) const { return m_Tags[(size_t)a_Tag].m_NextSibling; } /** Returns the previous sibling of the specified tag, or -1 if none. */ - int GetPrevSibling(int a_Tag) const { return m_Tags[a_Tag].m_PrevSibling; } + int GetPrevSibling(int a_Tag) const { return m_Tags[(size_t)a_Tag].m_PrevSibling; } /** Returns the length of the tag's data, in bytes. Not valid for Compound or List tags! */ int GetDataLength (int a_Tag) const { - ASSERT(m_Tags[a_Tag].m_Type != TAG_List); - ASSERT(m_Tags[a_Tag].m_Type != TAG_Compound); - return m_Tags[a_Tag].m_DataLength; + ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_List); + ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_Compound); + return m_Tags[(size_t)a_Tag].m_DataLength; } /** Returns the data stored in this tag. Not valid for Compound or List tags! */ const char * GetData(int a_Tag) const { - ASSERT(m_Tags[a_Tag].m_Type != TAG_List); - ASSERT(m_Tags[a_Tag].m_Type != TAG_Compound); - return m_Data + m_Tags[a_Tag].m_DataStart; + ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_List); + ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_Compound); + return m_Data + m_Tags[(size_t)a_Tag].m_DataStart; } /** Returns the direct child tag of the specified name, or -1 if no such tag. */ @@ -163,47 +163,47 @@ public: /** Returns the child tag of the specified path (Name1\Name2\Name3...), or -1 if no such tag. */ int FindTagByPath(int a_Tag, const AString & a_Path) const; - eTagType GetType(int a_Tag) const { return m_Tags[a_Tag].m_Type; } + eTagType GetType(int a_Tag) const { return m_Tags[(size_t)a_Tag].m_Type; } /** Returns the children type for a List tag; undefined on other tags. If list empty, returns TAG_End. */ eTagType GetChildrenType(int a_Tag) const { - ASSERT(m_Tags[a_Tag].m_Type == TAG_List); - return (m_Tags[a_Tag].m_FirstChild < 0) ? TAG_End : m_Tags[m_Tags[a_Tag].m_FirstChild].m_Type; + ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_List); + return (m_Tags[(size_t)a_Tag].m_FirstChild < 0) ? TAG_End : m_Tags[(size_t)m_Tags[(size_t)a_Tag].m_FirstChild].m_Type; } /** Returns the value stored in a Byte tag. Not valid for any other tag type. */ inline unsigned char GetByte(int a_Tag) const { - ASSERT(m_Tags[a_Tag].m_Type == TAG_Byte); - return (unsigned char)(m_Data[m_Tags[a_Tag].m_DataStart]); + ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Byte); + return (unsigned char)(m_Data[(size_t)m_Tags[(size_t)a_Tag].m_DataStart]); } /** Returns the value stored in a Short tag. Not valid for any other tag type. */ inline Int16 GetShort(int a_Tag) const { - ASSERT(m_Tags[a_Tag].m_Type == TAG_Short); - return GetBEShort(m_Data + m_Tags[a_Tag].m_DataStart); + ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Short); + return GetBEShort(m_Data + m_Tags[(size_t)a_Tag].m_DataStart); } /** Returns the value stored in an Int tag. Not valid for any other tag type. */ inline Int32 GetInt(int a_Tag) const { - ASSERT(m_Tags[a_Tag].m_Type == TAG_Int); - return GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); + ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Int); + return GetBEInt(m_Data + m_Tags[(size_t)a_Tag].m_DataStart); } /** Returns the value stored in a Long tag. Not valid for any other tag type. */ inline Int64 GetLong(int a_Tag) const { - ASSERT(m_Tags[a_Tag].m_Type == TAG_Long); - return NetworkToHostLong8(m_Data + m_Tags[a_Tag].m_DataStart); + ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Long); + return NetworkToHostLong8(m_Data + m_Tags[(size_t)a_Tag].m_DataStart); } /** Returns the value stored in a Float tag. Not valid for any other tag type. */ inline float GetFloat(int a_Tag) const { - ASSERT(m_Tags[a_Tag].m_Type == TAG_Float); + ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Float); // Cause a compile-time error if sizeof(float) != 4 // If your platform produces a compiler error here, you'll need to add code that manually decodes 32-bit floats @@ -212,7 +212,7 @@ public: UNUSED(Check1); UNUSED(Check2); - Int32 i = GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); + Int32 i = GetBEInt(m_Data + m_Tags[(size_t)a_Tag].m_DataStart); float f; memcpy(&f, &i, sizeof(f)); return f; @@ -228,16 +228,16 @@ public: UNUSED(Check1); UNUSED(Check2); - ASSERT(m_Tags[a_Tag].m_Type == TAG_Double); - return NetworkToHostDouble8(m_Data + m_Tags[a_Tag].m_DataStart); + ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Double); + return NetworkToHostDouble8(m_Data + m_Tags[(size_t)a_Tag].m_DataStart); } /** Returns the value stored in a String tag. Not valid for any other tag type. */ inline AString GetString(int a_Tag) const { - ASSERT(m_Tags[a_Tag].m_Type == TAG_String); + ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_String); AString res; - res.assign(m_Data + m_Tags[a_Tag].m_DataStart, m_Tags[a_Tag].m_DataLength); + res.assign(m_Data + m_Tags[(size_t)a_Tag].m_DataStart, m_Tags[(size_t)a_Tag].m_DataLength); return res; } @@ -245,7 +245,7 @@ public: inline AString GetName(int a_Tag) const { AString res; - res.assign(m_Data + m_Tags[a_Tag].m_NameStart, m_Tags[a_Tag].m_NameLength); + res.assign(m_Data + m_Tags[(size_t)a_Tag].m_NameStart, m_Tags[(size_t)a_Tag].m_NameLength); return res; } -- cgit v1.2.3 From 5dee19648d8b3b068698fd1c9cb62e9038bf0e2c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 10:31:50 +0200 Subject: More Clang warning fixes in the protocols. --- src/Protocol/Protocol132.cpp | 65 +++++++++++++++++++++++++------------------- src/StringUtils.cpp | 2 +- src/StringUtils.h | 2 +- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index ce5d134ea..ce5942a5c 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -115,7 +115,7 @@ void cProtocol132::DataReceived(const char * a_Data, size_t a_Size) Byte Decrypted[512]; while (a_Size > 0) { - int NumBytes = (a_Size > (int)sizeof(Decrypted)) ? (int)sizeof(Decrypted) : a_Size; + size_t NumBytes = (a_Size > sizeof(Decrypted)) ? sizeof(Decrypted) : a_Size; m_Decryptor.ProcessData(Decrypted, (Byte *)a_Data, NumBytes); super::DataReceived((const char *)Decrypted, NumBytes); a_Size -= NumBytes; @@ -139,8 +139,8 @@ void cProtocol132::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, cha WriteInt (a_BlockX); WriteShort((short)a_BlockY); WriteInt (a_BlockZ); - WriteByte (a_Byte1); - WriteByte (a_Byte2); + WriteChar (a_Byte1); + WriteChar (a_Byte2); WriteShort(a_BlockType); Flush(); } @@ -157,7 +157,7 @@ void cProtocol132::SendBlockBreakAnim(int a_entityID, int a_BlockX, int a_BlockY WriteInt (a_BlockX); WriteInt (a_BlockY); WriteInt (a_BlockZ); - WriteByte (stage); + WriteChar (stage); Flush(); } @@ -259,7 +259,7 @@ void cProtocol132::SendLogin(const cPlayer & a_Player, const cWorld & a_World) WriteByte (PACKET_LOGIN); WriteInt (a_Player.GetUniqueID()); // EntityID of the player WriteString("default"); // Level type - WriteByte ((int)a_Player.GetGameMode()); + WriteByte ((Byte)a_Player.GetGameMode()); WriteByte ((Byte)(a_World.GetDimension())); WriteByte (2); // TODO: Difficulty WriteByte (0); // Unused, used to be world height @@ -283,8 +283,8 @@ void cProtocol132::SendPlayerSpawn(const cPlayer & a_Player) WriteInt ((int)(a_Player.GetPosX() * 32)); WriteInt ((int)(a_Player.GetPosY() * 32)); WriteInt ((int)(a_Player.GetPosZ() * 32)); - WriteByte ((char)((a_Player.GetYaw() / 360.f) * 256)); - WriteByte ((char)((a_Player.GetPitch() / 360.f) * 256)); + WriteChar ((char)((a_Player.GetYaw() / 360.f) * 256)); + WriteChar ((char)((a_Player.GetPitch() / 360.f) * 256)); WriteShort (HeldItem.IsEmpty() ? 0 : HeldItem.m_ItemType); // Player metadata: just use a default metadata value, since the client doesn't like starting without any metadata: WriteByte (0); // Index 0, byte (flags) @@ -306,7 +306,7 @@ void cProtocol132::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int WriteInt (a_SrcY); WriteInt (a_SrcZ); WriteFloat (a_Volume); - WriteByte ((char)(a_Pitch * 63.0f)); + WriteChar ((char)(a_Pitch * 63.0f)); Flush(); } @@ -320,7 +320,7 @@ void cProtocol132::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src WriteByte(PACKET_SOUND_PARTICLE_EFFECT); WriteInt (a_EffectID); WriteInt (a_SrcX); - WriteByte(a_SrcY); + WriteByte((Byte)a_SrcY); WriteInt (a_SrcZ); WriteInt (a_Data); Flush(); @@ -335,7 +335,7 @@ void cProtocol132::SendSpawnMob(const cMonster & a_Mob) cCSLock Lock(m_CSPacket); WriteByte (PACKET_SPAWN_MOB); WriteInt (a_Mob.GetUniqueID()); - WriteByte (a_Mob.GetMobType()); + WriteByte ((Byte)a_Mob.GetMobType()); WriteVectorI((Vector3i)(a_Mob.GetPosition() * 32)); WriteByte ((Byte)((a_Mob.GetYaw() / 360.f) * 256)); WriteByte ((Byte)((a_Mob.GetPitch() / 360.f) * 256)); @@ -411,12 +411,12 @@ void cProtocol132::SendWholeInventory(const cWindow & a_Window) const cInventory & Inventory = m_Client->GetPlayer()->GetInventory(); int BaseOffset = a_Window.GetNumSlots() - (cInventory::invNumSlots - cInventory::invInventoryOffset); // Number of non-inventory slots char WindowID = a_Window.GetWindowID(); - for (int i = 0; i < cInventory::invInventoryCount; i++) + for (short i = 0; i < cInventory::invInventoryCount; i++) { SendInventorySlot(WindowID, BaseOffset + i, Inventory.GetInventorySlot(i)); } // for i - Inventory[] BaseOffset += cInventory::invInventoryCount; - for (int i = 0; i < cInventory::invHotbarCount; i++) + for (short i = 0; i < cInventory::invHotbarCount; i++) { SendInventorySlot(WindowID, BaseOffset + i, Inventory.GetHotbarSlot(i)); } // for i - Hotbar[] @@ -527,21 +527,30 @@ int cProtocol132::ParseClientStatuses(void) int cProtocol132::ParseEncryptionKeyResponse(void) { + // Read the encryption key: HANDLE_PACKET_READ(ReadBEShort, short, EncKeyLength); + if (EncKeyLength > MAX_ENC_LEN) + { + LOGD("Too long encryption key"); + m_Client->Kick("Hacked client"); + return PARSE_OK; + } AString EncKey; - if (!m_ReceivedData.ReadString(EncKey, EncKeyLength)) + if (!m_ReceivedData.ReadString(EncKey, (size_t)EncKeyLength)) { return PARSE_INCOMPLETE; } + + // Read the encryption nonce: HANDLE_PACKET_READ(ReadBEShort, short, EncNonceLength); AString EncNonce; - if (!m_ReceivedData.ReadString(EncNonce, EncNonceLength)) + if (!m_ReceivedData.ReadString(EncNonce, (size_t)EncNonceLength)) { return PARSE_INCOMPLETE; } - if ((EncKeyLength > MAX_ENC_LEN) || (EncNonceLength > MAX_ENC_LEN)) + if (EncNonceLength > MAX_ENC_LEN) { - LOGD("Too long encryption"); + LOGD("Too long encryption nonce"); m_Client->Kick("Hacked client"); return PARSE_OK; } @@ -623,23 +632,23 @@ void cProtocol132::Flush(void) LOGD("Flushing empty"); return; } - const char * a_Data = m_DataToSend.data(); - int a_Size = m_DataToSend.size(); + const char * Data = m_DataToSend.data(); + size_t Size = m_DataToSend.size(); if (m_IsEncrypted) { Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks) - while (a_Size > 0) + while (Size > 0) { - int NumBytes = (a_Size > (int)sizeof(Encrypted)) ? (int)sizeof(Encrypted) : a_Size; - m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes); + size_t NumBytes = (Size > sizeof(Encrypted)) ? sizeof(Encrypted) : Size; + m_Encryptor.ProcessData(Encrypted, (Byte *)Data, NumBytes); super::SendData((const char *)Encrypted, NumBytes); - a_Size -= NumBytes; - a_Data += NumBytes; + Size -= NumBytes; + Data += NumBytes; } } else { - super::SendData(a_Data, a_Size); + super::SendData(Data, Size); } m_DataToSend.clear(); } @@ -665,7 +674,7 @@ void cProtocol132::WriteItem(const cItem & a_Item) } WriteShort(ItemType); - WriteByte (a_Item.m_ItemCount); + WriteChar (a_Item.m_ItemCount); WriteShort(a_Item.m_ItemDamage); if (a_Item.m_Enchantments.IsEmpty()) @@ -681,7 +690,7 @@ void cProtocol132::WriteItem(const cItem & a_Item) Writer.Finish(); AString Compressed; CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed); - WriteShort(Compressed.size()); + WriteShort((short)Compressed.size()); SendData(Compressed.data(), Compressed.size()); } @@ -717,8 +726,8 @@ int cProtocol132::ParseItem(cItem & a_Item) // Read the metadata AString Metadata; - Metadata.resize(MetadataLength); - if (!m_ReceivedData.ReadBuf((void *)Metadata.data(), MetadataLength)) + Metadata.resize((size_t)MetadataLength); + if (!m_ReceivedData.ReadBuf((void *)Metadata.data(), (size_t)MetadataLength)) { return PARSE_INCOMPLETE; } diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index ad622d707..f46730150 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -531,7 +531,7 @@ AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a format binary data this way: 00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcdef */ -AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_LineLength) +AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, int a_LineLength) { ASSERT(a_LineLength <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max char line[512]; diff --git a/src/StringUtils.h b/src/StringUtils.h index da395e5b5..ce24e89bc 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -64,7 +64,7 @@ extern AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16); /// Creates a nicely formatted HEX dump of the given memory block. Max a_BytesPerLine is 120 -extern AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_BytesPerLine); +extern AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, int a_BytesPerLine); /// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash extern AString EscapeString(const AString & a_Message); // tolua_export -- cgit v1.2.3 From e1f75ab6d0862d77bf91b588d54acf63fdf20c63 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 10:42:17 +0200 Subject: Fixed CreateHexDump's signedness. --- src/Protocol/Protocol.h | 2 +- src/StringUtils.cpp | 18 +++++++++--------- src/StringUtils.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 8294fa8b7..ae06f2f9e 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -216,7 +216,7 @@ protected: { // A 32-bit integer can be encoded by at most 5 bytes: unsigned char b[5]; - int idx = 0; + size_t idx = 0; do { b[idx] = (a_Value & 0x7f) | ((a_Value > 0x7f) ? 0x80 : 0x00); diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index f46730150..a69d8750f 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -531,20 +531,20 @@ AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a format binary data this way: 00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcdef */ -AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, int a_LineLength) +AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine) { - ASSERT(a_LineLength <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max + ASSERT(a_BytesPerLine <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max char line[512]; char * p; char * q; - a_Out.reserve(a_Size / a_LineLength * (18 + 6 * a_LineLength)); - for (int i = 0; i < a_Size; i += a_LineLength) + a_Out.reserve(a_Size / a_BytesPerLine * (18 + 6 * a_BytesPerLine)); + for (size_t i = 0; i < a_Size; i += a_BytesPerLine) { - int k = a_Size - i; - if (k > a_LineLength) + size_t k = a_Size - i; + if (k > a_BytesPerLine) { - k = a_LineLength; + k = a_BytesPerLine; } #ifdef _MSC_VER // MSVC provides a "secure" version of sprintf() @@ -555,8 +555,8 @@ AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, int // Remove the terminating NULL / leftover garbage in line, after the sprintf-ed value memset(line + Count, 32, sizeof(line) - Count); p = line + 10; - q = p + 2 + a_LineLength * 3 + 1; - for (int j = 0; j < k; j++) + q = p + 2 + a_BytesPerLine * 3 + 1; + for (size_t j = 0; j < k; j++) { unsigned char c = ((unsigned char *)a_Data)[i + j]; p[0] = HEX(c >> 4); diff --git a/src/StringUtils.h b/src/StringUtils.h index ce24e89bc..b69e47d3c 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -64,7 +64,7 @@ extern AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16); /// Creates a nicely formatted HEX dump of the given memory block. Max a_BytesPerLine is 120 -extern AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, int a_BytesPerLine); +extern AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine); /// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash extern AString EscapeString(const AString & a_Message); // tolua_export -- cgit v1.2.3 From 3590f97e00e570df7a18d953212f33d947f3896c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 11:19:57 +0200 Subject: Fixed CreateHexDump's format string. --- src/StringUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index a69d8750f..33b04505f 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -548,9 +548,9 @@ AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, siz } #ifdef _MSC_VER // MSVC provides a "secure" version of sprintf() - int Count = sprintf_s(line, sizeof(line), "%08x:", i); + int Count = sprintf_s(line, sizeof(line), "%08x:", (unsigned)i); #else - int Count = sprintf(line, "%08x:", i); + int Count = sprintf(line, "%08x:", (unsigned)i); #endif // Remove the terminating NULL / leftover garbage in line, after the sprintf-ed value memset(line + Count, 32, sizeof(line) - Count); -- cgit v1.2.3 From 4be894f0601fcfa182fda045b07b196e5dcd9343 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 11:47:46 +0200 Subject: More Clang warning fixes in the protocols. --- src/Protocol/ChunkDataSerializer.cpp | 4 +- src/Protocol/Protocol125.cpp | 139 ++++++++++++++++++----------------- src/Protocol/Protocol16x.cpp | 8 +- src/Protocol/Protocol17x.cpp | 2 +- src/Protocol/Protocol17x.h | 4 +- src/Protocol/ProtocolRecognizer.cpp | 6 +- 6 files changed, 82 insertions(+), 81 deletions(-) diff --git a/src/Protocol/ChunkDataSerializer.cpp b/src/Protocol/ChunkDataSerializer.cpp index 78318a5ee..ebe61631b 100644 --- a/src/Protocol/ChunkDataSerializer.cpp +++ b/src/Protocol/ChunkDataSerializer.cpp @@ -105,7 +105,7 @@ void cChunkDataSerializer::Serialize29(AString & a_Data) a_Data.append((const char *)&BitMap1, sizeof(short)); a_Data.append((const char *)&BitMap2, sizeof(short)); - Int32 CompressedSizeBE = htonl(CompressedSize); + UInt32 CompressedSizeBE = htonl((UInt32)CompressedSize); a_Data.append((const char *)&CompressedSizeBE, sizeof(CompressedSizeBE)); Int32 UnusedInt32 = 0; @@ -163,7 +163,7 @@ void cChunkDataSerializer::Serialize39(AString & a_Data) a_Data.append((const char *)&BitMap1, sizeof(short)); a_Data.append((const char *)&BitMap2, sizeof(short)); - Int32 CompressedSizeBE = htonl(CompressedSize); + UInt32 CompressedSizeBE = htonl((UInt32)CompressedSize); a_Data.append((const char *)&CompressedSizeBE, sizeof(CompressedSizeBE)); // Unlike 29, 39 doesn't have the "unused" int diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 0fa5c6de7..231ae410f 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -161,8 +161,8 @@ void cProtocol125::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, cha WriteInt (a_BlockX); WriteShort((short)a_BlockY); WriteInt (a_BlockZ); - WriteByte (a_Byte1); - WriteByte (a_Byte2); + WriteChar (a_Byte1); + WriteChar (a_Byte2); Flush(); } @@ -209,12 +209,12 @@ void cProtocol125::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV WriteByte (PACKET_MULTI_BLOCK); WriteInt (a_ChunkX); WriteInt (a_ChunkZ); - WriteShort((unsigned short)a_Changes.size()); - WriteUInt (sizeof(int) * a_Changes.size()); + WriteShort((short)a_Changes.size()); + WriteUInt ((UInt32)(sizeof(int) * a_Changes.size())); for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr) { - unsigned int Coords = itr->y | (itr->z << 8) | (itr->x << 12); - unsigned int Blocks = itr->BlockMeta | (itr->BlockType << 4); + UInt32 Coords = ((UInt32)itr->y) | ((UInt32)(itr->z << 8)) | ((UInt32)(itr->x << 12)); + UInt32 Blocks = ((UInt32)itr->BlockMeta) | ((UInt32)(itr->BlockType << 4)); WriteUInt(Coords << 16 | Blocks); } Flush(); @@ -325,8 +325,8 @@ void cProtocol125::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, in cCSLock Lock(m_CSPacket); WriteByte (PACKET_ENTITY_EFFECT); WriteInt (a_Entity.GetUniqueID()); - WriteByte (a_EffectID); - WriteByte (a_Amplifier); + WriteByte ((Byte)a_EffectID); + WriteByte ((Byte)a_Amplifier); WriteShort(a_Duration); Flush(); } @@ -357,7 +357,7 @@ void cProtocol125::SendEntityHeadLook(const cEntity & a_Entity) cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_HEAD_LOOK); WriteInt (a_Entity.GetUniqueID()); - WriteByte((char)((a_Entity.GetHeadYaw() / 360.f) * 256)); + WriteChar((char)((a_Entity.GetHeadYaw() / 360.f) * 256)); Flush(); } @@ -372,8 +372,8 @@ void cProtocol125::SendEntityLook(const cEntity & a_Entity) cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_LOOK); WriteInt (a_Entity.GetUniqueID()); - WriteByte((char)((a_Entity.GetYaw() / 360.f) * 256)); - WriteByte((char)((a_Entity.GetPitch() / 360.f) * 256)); + WriteChar((char)((a_Entity.GetYaw() / 360.f) * 256)); + WriteChar((char)((a_Entity.GetPitch() / 360.f) * 256)); Flush(); } @@ -421,9 +421,9 @@ void cProtocol125::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_REL_MOVE); WriteInt (a_Entity.GetUniqueID()); - WriteByte(a_RelX); - WriteByte(a_RelY); - WriteByte(a_RelZ); + WriteChar(a_RelX); + WriteChar(a_RelY); + WriteChar(a_RelZ); Flush(); } @@ -438,11 +438,11 @@ void cProtocol125::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_REL_MOVE_LOOK); WriteInt (a_Entity.GetUniqueID()); - WriteByte(a_RelX); - WriteByte(a_RelY); - WriteByte(a_RelZ); - WriteByte((char)((a_Entity.GetYaw() / 360.f) * 256)); - WriteByte((char)((a_Entity.GetPitch() / 360.f) * 256)); + WriteChar(a_RelX); + WriteChar(a_RelY); + WriteChar(a_RelZ); + WriteChar((char)((a_Entity.GetYaw() / 360.f) * 256)); + WriteChar((char)((a_Entity.GetPitch() / 360.f) * 256)); Flush(); } @@ -455,7 +455,7 @@ void cProtocol125::SendEntityStatus(const cEntity & a_Entity, char a_Status) cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_STATUS); WriteInt (a_Entity.GetUniqueID()); - WriteByte(a_Status); + WriteChar(a_Status); Flush(); } @@ -488,7 +488,7 @@ void cProtocol125::SendExplosion(double a_BlockX, double a_BlockY, double a_Bloc WriteDouble (a_BlockY); WriteDouble (a_BlockZ); WriteFloat (a_Radius); - WriteInt (a_BlocksAffected.size()); + WriteInt ((Int32)a_BlocksAffected.size()); int BlockX = (int)a_BlockX; int BlockY = (int)a_BlockY; int BlockZ = (int)a_BlockZ; @@ -513,7 +513,7 @@ void cProtocol125::SendGameMode(eGameMode a_GameMode) cCSLock Lock(m_CSPacket); WriteByte(PACKET_CHANGE_GAME_STATE); WriteByte(3); - WriteByte((char)a_GameMode); + WriteChar((char)a_GameMode); Flush(); } @@ -538,7 +538,7 @@ void cProtocol125::SendHealth(void) cCSLock Lock(m_CSPacket); WriteByte (PACKET_UPDATE_HEALTH); WriteShort((short)m_Client->GetPlayer()->GetHealth()); - WriteShort(m_Client->GetPlayer()->GetFoodLevel()); + WriteShort((short)m_Client->GetPlayer()->GetFoodLevel()); WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel()); Flush(); } @@ -551,7 +551,7 @@ void cProtocol125::SendInventorySlot(char a_WindowID, short a_SlotNum, const cIt { cCSLock Lock(m_CSPacket); WriteByte (PACKET_INVENTORY_SLOT); - WriteByte (a_WindowID); + WriteChar (a_WindowID); WriteShort(a_SlotNum); WriteItem (a_Item); Flush(); @@ -600,17 +600,14 @@ void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colo WriteByte (PACKET_ITEM_DATA); WriteShort(E_ITEM_MAP); - WriteShort(a_ID); - WriteShort(3 + a_Length); + WriteShort((short)a_ID); + WriteShort((short)(3 + a_Length)); WriteByte(0); - WriteByte(a_X); - WriteByte(a_Y); + WriteChar((char)a_X); + WriteChar((char)a_Y); - for (unsigned int i = 0; i < a_Length; ++i) - { - WriteByte(a_Colors[i]); - } + SendData((const char *)a_Colors, a_Length); Flush(); } @@ -625,16 +622,16 @@ void cProtocol125::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decor WriteByte (PACKET_ITEM_DATA); WriteShort(E_ITEM_MAP); - WriteShort(a_ID); - WriteShort(1 + (3 * a_Decorators.size())); + WriteShort((short)a_ID); + WriteShort((short)(1 + (3 * a_Decorators.size()))); WriteByte(1); for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it) { - WriteByte((it->GetType() << 4) | (it->GetRot() & 0xf)); - WriteByte(it->GetPixelX()); - WriteByte(it->GetPixelZ()); + WriteByte((Byte)(it->GetType() << 4) | (it->GetRot() & 0xf)); + WriteByte((Byte)it->GetPixelX()); + WriteByte((Byte)it->GetPixelZ()); } Flush(); @@ -651,7 +648,7 @@ void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) WriteByte (PACKET_PICKUP_SPAWN); WriteInt (a_Pickup.GetUniqueID()); WriteShort (a_Pickup.GetItem().m_ItemType); - WriteByte (a_Pickup.GetItem().m_ItemCount); + WriteChar (a_Pickup.GetItem().m_ItemCount); WriteShort (a_Pickup.GetItem().m_ItemDamage); WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32)); WriteByte ((char)(a_Pickup.GetSpeed().x * 8)); @@ -669,7 +666,7 @@ void cProtocol125::SendEntityAnimation(const cEntity & a_Entity, char a_Animatio cCSLock Lock(m_CSPacket); WriteByte(PACKET_ANIMATION); WriteInt (a_Entity.GetUniqueID()); - WriteByte(a_Animation); + WriteChar(a_Animation); Flush(); } @@ -763,8 +760,8 @@ void cProtocol125::SendPlayerSpawn(const cPlayer & a_Player) WriteInt ((int)(a_Player.GetPosX() * 32)); WriteInt ((int)(a_Player.GetPosY() * 32)); WriteInt ((int)(a_Player.GetPosZ() * 32)); - WriteByte ((char)((a_Player.GetYaw() / 360.f) * 256)); - WriteByte ((char)((a_Player.GetPitch() / 360.f) * 256)); + WriteChar ((char)((a_Player.GetYaw() / 360.f) * 256)); + WriteChar ((char)((a_Player.GetPitch() / 360.f) * 256)); WriteShort (HeldItem.IsEmpty() ? 0 : HeldItem.m_ItemType); Flush(); } @@ -790,9 +787,9 @@ void cProtocol125::SendPluginMessage(const AString & a_Channel, const AString & void cProtocol125::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) { cCSLock Lock(m_CSPacket); - WriteByte (PACKET_REMOVE_ENTITY_EFFECT); - WriteInt (a_Entity.GetUniqueID()); - WriteByte (a_EffectID); + WriteByte(PACKET_REMOVE_ENTITY_EFFECT); + WriteInt (a_Entity.GetUniqueID()); + WriteChar((char)a_EffectID); Flush(); } @@ -806,7 +803,7 @@ void cProtocol125::SendRespawn(void) WriteByte (PACKET_RESPAWN); WriteInt ((int)(m_Client->GetPlayer()->GetWorld()->GetDimension())); WriteByte (2); // TODO: Difficulty; 2 = Normal - WriteByte ((char)m_Client->GetPlayer()->GetGameMode()); + WriteChar ((char)m_Client->GetPlayer()->GetGameMode()); WriteShort (256); // Current world height WriteString("default"); } @@ -837,7 +834,7 @@ void cProtocol125::SendExperienceOrb(const cExpOrb & a_ExpOrb) WriteInt((int) a_ExpOrb.GetPosX()); WriteInt((int) a_ExpOrb.GetPosY()); WriteInt((int) a_ExpOrb.GetPosZ()); - WriteShort(a_ExpOrb.GetReward()); + WriteShort((short)a_ExpOrb.GetReward()); Flush(); } @@ -878,7 +875,7 @@ void cProtocol125::SendSpawnMob(const cMonster & a_Mob) cCSLock Lock(m_CSPacket); WriteByte (PACKET_SPAWN_MOB); WriteInt (a_Mob.GetUniqueID()); - WriteByte (a_Mob.GetMobType()); + WriteByte ((Byte)a_Mob.GetMobType()); WriteVectorI((Vector3i)(a_Mob.GetPosition() * 32)); WriteByte (0); WriteByte (0); @@ -903,7 +900,7 @@ void cProtocol125::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, cCSLock Lock(m_CSPacket); WriteByte(PACKET_SPAWN_OBJECT); WriteInt (a_Entity.GetUniqueID()); - WriteByte(a_ObjectType); + WriteChar(a_ObjectType); WriteInt ((int)(a_Entity.GetPosX() * 32)); WriteInt ((int)(a_Entity.GetPosY() * 32)); WriteInt ((int)(a_Entity.GetPosZ() * 32)); @@ -928,7 +925,7 @@ void cProtocol125::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp cCSLock Lock(m_CSPacket); WriteByte (PACKET_SPAWN_OBJECT); WriteInt (a_Vehicle.GetUniqueID()); - WriteByte (a_VehicleType); + WriteChar (a_VehicleType); WriteInt ((int)(a_Vehicle.GetPosX() * 32)); WriteInt ((int)(a_Vehicle.GetPosY() * 32)); WriteInt ((int)(a_Vehicle.GetPosZ() * 32)); @@ -966,8 +963,8 @@ void cProtocol125::SendTeleportEntity(const cEntity & a_Entity) WriteInt ((int)(floor(a_Entity.GetPosX() * 32))); WriteInt ((int)(floor(a_Entity.GetPosY() * 32))); WriteInt ((int)(floor(a_Entity.GetPosZ() * 32))); - WriteByte ((char)((a_Entity.GetYaw() / 360.f) * 256)); - WriteByte ((char)((a_Entity.GetPitch() / 360.f) * 256)); + WriteChar ((char)((a_Entity.GetYaw() / 360.f) * 256)); + WriteChar ((char)((a_Entity.GetPitch() / 360.f) * 256)); Flush(); } @@ -1042,7 +1039,7 @@ void cProtocol125::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_Bloc WriteInt (a_Entity.GetUniqueID()); WriteByte(0); // Unknown byte only 0 has been observed WriteInt (a_BlockX); - WriteByte(a_BlockY); + WriteByte((Byte)a_BlockY); WriteInt (a_BlockZ); Flush(); } @@ -1086,7 +1083,7 @@ void cProtocol125::SendWholeInventory(const cWindow & a_Window) cCSLock Lock(m_CSPacket); cItems Slots; a_Window.GetSlots(*(m_Client->GetPlayer()), Slots); - SendWindowSlots(a_Window.GetWindowID(), Slots.size(), &(Slots[0])); + SendWindowSlots(a_Window.GetWindowID(), (int)Slots.size(), &(Slots[0])); } @@ -1103,7 +1100,7 @@ void cProtocol125::SendWindowClose(const cWindow & a_Window) cCSLock Lock(m_CSPacket); WriteByte(PACKET_WINDOW_CLOSE); - WriteByte(a_Window.GetWindowID()); + WriteChar(a_Window.GetWindowID()); Flush(); } @@ -1120,10 +1117,10 @@ void cProtocol125::SendWindowOpen(const cWindow & a_Window) } cCSLock Lock(m_CSPacket); WriteByte (PACKET_WINDOW_OPEN); - WriteByte (a_Window.GetWindowID()); - WriteByte (a_Window.GetWindowType()); + WriteChar (a_Window.GetWindowID()); + WriteByte ((Byte)a_Window.GetWindowType()); WriteString(a_Window.GetWindowTitle()); - WriteByte (a_Window.GetNumNonInventorySlots()); + WriteByte ((Byte)a_Window.GetNumNonInventorySlots()); Flush(); } @@ -1135,7 +1132,7 @@ void cProtocol125::SendWindowProperty(const cWindow & a_Window, short a_Property { cCSLock Lock(m_CSPacket); WriteByte (PACKET_WINDOW_PROPERTY); - WriteByte (a_Window.GetWindowID()); + WriteChar (a_Window.GetWindowID()); WriteShort(a_Property); WriteShort(a_Value); Flush(); @@ -1527,7 +1524,7 @@ int cProtocol125::ParsePluginMessage(void) HANDLE_PACKET_READ(ReadBEUTF16String16, AString, ChannelName); HANDLE_PACKET_READ(ReadBEShort, short, Length); AString Data; - if (!m_ReceivedData.ReadString(Data, Length)) + if (!m_ReceivedData.ReadString(Data, (size_t)Length)) { m_ReceivedData.CheckValid(); return PARSE_INCOMPLETE; @@ -1688,7 +1685,7 @@ void cProtocol125::SendPreChunk(int a_ChunkX, int a_ChunkZ, bool a_ShouldLoad) void cProtocol125::SendWindowSlots(char a_WindowID, int a_NumItems, const cItem * a_Items) { WriteByte (PACKET_INVENTORY_WHOLE); - WriteByte (a_WindowID); + WriteChar (a_WindowID); WriteShort((short)a_NumItems); for (int j = 0; j < a_NumItems; j++) @@ -1718,7 +1715,7 @@ void cProtocol125::WriteItem(const cItem & a_Item) return; } - WriteByte (a_Item.m_ItemCount); + WriteChar (a_Item.m_ItemCount); WriteShort(a_Item.m_ItemDamage); if (cItem::IsEnchantable(a_Item.m_ItemType)) @@ -1765,7 +1762,7 @@ int cProtocol125::ParseItem(cItem & a_Item) } // TODO: Enchantment not implemented yet! - if (!m_ReceivedData.SkipRead(EnchantNumBytes)) + if (!m_ReceivedData.SkipRead((size_t)EnchantNumBytes)) { return PARSE_INCOMPLETE; } @@ -1850,7 +1847,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtCreeper: { WriteByte(0x10); - WriteByte(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1); // Blowing up? + WriteChar(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1); // Blowing up? WriteByte(0x11); WriteByte(((const cCreeper &)a_Mob).IsCharged() ? 1 : 0); // Lightning-charged? break; @@ -1920,9 +1917,9 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteByte(0x10); Byte SheepMetadata = 0; - SheepMetadata = ((const cSheep &)a_Mob).GetFurColor(); // Fur colour + SheepMetadata = (Byte)((const cSheep &)a_Mob).GetFurColor(); - if (((const cSheep &)a_Mob).IsSheared()) // Is sheared? + if (((const cSheep &)a_Mob).IsSheared()) { SheepMetadata |= 0x16; } @@ -1954,7 +1951,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - WriteInt(((const cWither &)a_Mob).GetNumInvulnerableTicks()); + WriteInt((Int32)((const cWither &)a_Mob).GetNumInvulnerableTicks()); WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; @@ -1965,11 +1962,11 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteByte(0x10); if (a_Mob.GetMobType() == cMonster::mtSlime) { - WriteByte(((const cSlime &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + WriteByte((Byte)((const cSlime &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME } else { - WriteByte(((const cMagmaCube &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + WriteByte((Byte)((const cMagmaCube &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME } break; } @@ -2008,7 +2005,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteInt(Flags); WriteByte(0x13); - WriteByte(((const cHorse &)a_Mob).GetHorseType()); // Type of horse (donkey, chestnut, etc.) + WriteByte((Byte)((const cHorse &)a_Mob).GetHorseType()); // Type of horse (donkey, chestnut, etc.) WriteByte(0x54); int Appearance = 0; @@ -2020,6 +2017,10 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteInt(((const cHorse &)a_Mob).GetHorseArmour()); // Horshey armour break; } + default: + { + break; + } } } diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index ecb24254f..bf7d9a0b1 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -119,7 +119,7 @@ void cProtocol161::SendHealth(void) cCSLock Lock(m_CSPacket); WriteByte (PACKET_UPDATE_HEALTH); WriteFloat((float)m_Client->GetPlayer()->GetHealth()); - WriteShort(m_Client->GetPlayer()->GetFoodLevel()); + WriteShort((short)m_Client->GetPlayer()->GetFoodLevel()); WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel()); Flush(); } @@ -163,10 +163,10 @@ void cProtocol161::SendWindowOpen(const cWindow & a_Window) } cCSLock Lock(m_CSPacket); WriteByte (PACKET_WINDOW_OPEN); - WriteByte (a_Window.GetWindowID()); - WriteByte (a_Window.GetWindowType()); + WriteChar (a_Window.GetWindowID()); + WriteByte ((Byte)a_Window.GetWindowType()); WriteString(a_Window.GetWindowTitle()); - WriteByte (a_Window.GetNumNonInventorySlots()); + WriteByte ((Byte)a_Window.GetNumNonInventorySlots()); WriteByte (1); // Use title if (a_Window.GetWindowType() == cWindow::wtAnimalChest) { diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index b987294b0..cbc138990 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1236,7 +1236,7 @@ void cProtocol172::SendWindowProperty(const cWindow & a_Window, short a_Property -void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) +void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size) { // Write the incoming data into the comm log file: if (g_ShouldLogCommIn) diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index bb6ee575a..91186b270 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -196,7 +196,7 @@ protected: m_Out.WriteVarUTF8String(a_Value); } - void WriteBuf(const char * a_Data, int a_Size) + void WriteBuf(const char * a_Data, size_t a_Size) { m_Out.Write(a_Data, a_Size); } @@ -243,7 +243,7 @@ protected: /** Adds the received (unencrypted) data to m_ReceivedData, parses complete packets */ - void AddReceivedData(const char * a_Data, int a_Size); + void AddReceivedData(const char * a_Data, size_t a_Size); /** Reads and handles the packet. The packet length and type have already been read. Returns true if the packet was understood, false if it was an unknown packet diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 81f146370..3f7d7b254 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -854,7 +854,7 @@ bool cProtocolRecognizer::TryRecognizeProtocol(void) // This must be a lengthed protocol, try if it has the entire initial handshake packet: m_Buffer.ResetRead(); UInt32 PacketLen; - UInt32 ReadSoFar = m_Buffer.GetReadableSpace(); + UInt32 ReadSoFar = (UInt32)m_Buffer.GetReadableSpace(); if (!m_Buffer.ReadVarInt(PacketLen)) { // Not enough bytes for the packet length, keep waiting @@ -931,7 +931,7 @@ bool cProtocolRecognizer::TryRecognizeLengthlessProtocol(void) bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRemaining) { UInt32 PacketType; - UInt32 NumBytesRead = m_Buffer.GetReadableSpace(); + UInt32 NumBytesRead = (UInt32)m_Buffer.GetReadableSpace(); if (!m_Buffer.ReadVarInt(PacketType)) { return false; @@ -962,7 +962,7 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema m_Buffer.ReadBEShort(ServerPort); m_Buffer.ReadVarInt(NextState); m_Buffer.CommitRead(); - m_Protocol = new cProtocol172(m_Client, ServerAddress, ServerPort, NextState); + m_Protocol = new cProtocol172(m_Client, ServerAddress, (UInt16)ServerPort, NextState); return true; } } -- cgit v1.2.3 From bc227299d0a1111da8bf7b61165649b2f9345e5d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 12:08:14 +0200 Subject: Fixed format string mismatch. --- src/Protocol/Protocol17x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index cbc138990..a4319df37 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1258,7 +1258,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size) AString Hex; CreateHexDump(Hex, a_Data, a_Size, 16); m_CommLogFile.Printf("Incoming data: %d (0x%x) bytes: \n%s\n", - a_Size, a_Size, Hex.c_str() + (unsigned)a_Size, (unsigned)a_Size, Hex.c_str() ); m_CommLogFile.Flush(); } -- cgit v1.2.3 From 4b4c3f2a204d353e1fa793d1a2b08838221a8616 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 12:28:38 +0200 Subject: Changed cNoise seed to signed. --- src/Noise.cpp | 2 +- src/Noise.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Noise.cpp b/src/Noise.cpp index a97ea70c6..32922c8f3 100644 --- a/src/Noise.cpp +++ b/src/Noise.cpp @@ -425,7 +425,7 @@ void cCubicCell3D::Move(int a_NewFloorX, int a_NewFloorY, int a_NewFloorZ) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cNoise: -cNoise::cNoise(unsigned int a_Seed) : +cNoise::cNoise(int a_Seed) : m_Seed(a_Seed) { } diff --git a/src/Noise.h b/src/Noise.h index ea72c64e9..62004503f 100644 --- a/src/Noise.h +++ b/src/Noise.h @@ -25,7 +25,7 @@ class cNoise { public: - cNoise(unsigned int a_Seed); + cNoise(int a_Seed); cNoise(const cNoise & a_Noise); // The following functions, if not marked INLINE, are about 20 % slower @@ -47,14 +47,14 @@ public: NOISE_DATATYPE CubicNoise3D (NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y, NOISE_DATATYPE a_Z) const; - void SetSeed(unsigned int a_Seed) { m_Seed = a_Seed; } + void SetSeed(int a_Seed) { m_Seed = a_Seed; } INLINE static NOISE_DATATYPE CubicInterpolate (NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_C, NOISE_DATATYPE a_D, NOISE_DATATYPE a_Pct); INLINE static NOISE_DATATYPE CosineInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct); INLINE static NOISE_DATATYPE LinearInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct); private: - unsigned int m_Seed; + int m_Seed; } ; -- cgit v1.2.3 From 87f39e9e287aa1a7e513036f5004ec24ac789f40 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 13:19:25 +0200 Subject: Explicit change record size. --- src/Protocol/Protocol125.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 231ae410f..bf946ef19 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -210,7 +210,7 @@ void cProtocol125::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV WriteInt (a_ChunkX); WriteInt (a_ChunkZ); WriteShort((short)a_Changes.size()); - WriteUInt ((UInt32)(sizeof(int) * a_Changes.size())); + WriteUInt ((UInt32)(4 * a_Changes.size())); for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr) { UInt32 Coords = ((UInt32)itr->y) | ((UInt32)(itr->z << 8)) | ((UInt32)(itr->x << 12)); -- cgit v1.2.3 From 1cab52f86799b98940da910e84e207b6037a5cd2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 23:06:47 +0200 Subject: Added cPlayer:SendRotation() API function. --- src/Entities/Player.cpp | 11 +++++++++++ src/Entities/Player.h | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 646aad50f..7f2e5b4c2 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1124,6 +1124,17 @@ void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) +void cPlayer::SendRotation(double a_YawDegrees, double a_PitchDegrees) +{ + SetYaw(a_YawDegrees); + SetPitch(a_PitchDegrees); + m_ClientHandle->SendPlayerMoveLook(); +} + + + + + Vector3d cPlayer::GetThrowStartPos(void) const { Vector3d res = GetEyePosition(); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index ea32dbfb9..05377a117 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -129,6 +129,12 @@ public: // tolua_begin + /** Sends the "look" packet to the player, forcing them to set their rotation to the specified values. + a_YawDegrees is clipped to range [-180, +180), + a_PitchDegrees is clipped to range [-180, +180) but the client only uses [-90, +90] + */ + void SendRotation(double a_YawDegrees, double a_PitchDegrees); + /** Returns the position where projectiles thrown by this player should start, player eye position + adjustment */ Vector3d GetThrowStartPos(void) const; -- cgit v1.2.3 From 43e3a55a70b7ec79046ea0de4f1912177ea3eb25 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 5 Apr 2014 12:09:14 +0200 Subject: Added more API documentation to cCompositeChat. --- MCServer/Plugins/APIDump/APIDesc.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index b3b7dd11c..59dd93137 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -551,7 +551,22 @@ end {{cPlayer}}:SendMessage(), {{cWorld}}:BroadcastChat() and {{cRoot}}:BroadcastChat().

    Note that most of the functions in this class are so-called modifiers - they modify the object and - then return the object itself, so that they can be chained one after another. + then return the object itself, so that they can be chained one after another. See the Chaining + example below for details.

    +

    + Each part of the composite chat message takes a "Style" parameter, this is a string that describes + the formatting. It uses the following strings, concatenated together: + + + + + + + + +
    StringStyle
    bBold text
    iItalic text
    uUnderlined text
    sStrikethrough text
    oObfuscated text
    @Xcolor X (X is 0 - 9 or a - f, same as dye meta
    + The following picture, taken from MineCraft Wiki, illustrates the color codes:

    + ]], Functions = { @@ -565,6 +580,7 @@ end AddTextPart = { Params = "Text, [Style]", Return = "self", Notes = "Adds a regular text. Chaining." }, AddUrlPart = { Params = "Text, Url, [Style]", Return = "self", Notes = "Adds a text which, when clicked, opens up a browser at the specified URL. Chaining." }, Clear = { Params = "", Return = "", Notes = "Removes all parts from this object" }, + ExtractText = { Params = "", Return = "string", Notes = "Returns the text from the parts that comprises the human-readable data. Used for older protocols that don't support composite chat and for console-logging." }, GetMessageType = { Params = "", Return = "MessageType", Notes = "Returns the MessageType (mtXXX constant) that is associated with this message. When sent to a player, the message will be formatted according to this message type and the player's settings (adding \"[INFO]\" prefix etc.)" }, ParseText = { Params = "Text", Return = "self", Notes = "Adds text, while recognizing http and https URLs and old-style formatting codes (\"@2\"). Chaining." }, SetMessageType = { Params = "MessageType", Return = "self", Notes = "Sets the MessageType (mtXXX constant) that is associated with this message. When sent to a player, the message will be formatted according to this message type and the player's settings (adding \"[INFO]\" prefix etc.) Chaining." }, -- cgit v1.2.3 From d43c5a9c474bd6e4fbd74f09cca9b9bdbbd88b71 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 5 Apr 2014 22:25:40 +0200 Subject: Removed debugging log from entity physics handling. --- src/Entities/ProjectileEntity.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index a9735a53c..e86bb48bd 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -371,13 +371,14 @@ void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) SetYawFromSpeed(); SetPitchFromSpeed(); - // DEBUG: + /* LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, speed {%.02f, %.02f, %.02f}, rot {%.02f, %.02f}", m_UniqueID, GetPosX(), GetPosY(), GetPosZ(), GetSpeedX(), GetSpeedY(), GetSpeedZ(), GetYaw(), GetPitch() ); + */ } -- cgit v1.2.3 From 22794e720883dea9f80d22ab13221cb345bdc186 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 5 Apr 2014 22:26:10 +0200 Subject: Fixed double projectile spawning. Two spawn packets were sent per projectile. --- src/World.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/World.cpp b/src/World.cpp index e39a605bb..c188fd522 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2993,7 +2993,6 @@ int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProje delete Projectile; return -1; } - BroadcastSpawnEntity(*Projectile); return Projectile->GetUniqueID(); } -- cgit v1.2.3 From 143a5e61fc8e704f3df776d089217f031bc47779 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 5 Apr 2014 22:34:05 +0200 Subject: Fixed Endiannes conversion routines for floats and doubles. This bug has been introduced in 8825d30aabbee8cb2e452dc5a17deb6f9b6892a7. This change fixes #854. --- src/Endianness.h | 4 ++-- src/Entities/Entity.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Endianness.h b/src/Endianness.h index 6a2593077..78f9a5d99 100644 --- a/src/Endianness.h +++ b/src/Endianness.h @@ -49,7 +49,7 @@ inline double NetworkToHostDouble8(const void * a_Value) inline Int64 NetworkToHostLong8(const void * a_Value) { UInt64 buf; - memcpy(&buf, &a_Value, 8); + memcpy(&buf, a_Value, 8); buf = ntohll(buf); return *reinterpret_cast(&buf); } @@ -62,7 +62,7 @@ inline float NetworkToHostFloat4(const void * a_Value) { UInt32 buf; float x; - memcpy(&buf, &a_Value, 4); + memcpy(&buf, a_Value, 4); buf = ntohl(buf); memcpy(&x, &buf, sizeof(float)); return x; diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 221cbbea7..8ef45f1a5 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1469,7 +1469,7 @@ void cEntity::SteerVehicle(float a_Forward, float a_Sideways) Vector3d cEntity::GetLookVector(void) const { Matrix4d m; - m.Init(Vector3f(), 0, m_Rot.x, -m_Rot.y); + m.Init(Vector3d(), 0, m_Rot.x, -m_Rot.y); Vector3d Look = m.Transform(Vector3d(0, 0, 1)); return Look; } -- cgit v1.2.3 From c89f7902dff3addc36135907d1b502f98d3120f3 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 6 Apr 2014 05:56:43 -0700 Subject: Added forgoten lua file --- lib/tolua++/src/bin/container_lua.h | 1476 +++++++++++++++++++++++++++++++++++ 1 file changed, 1476 insertions(+) create mode 100644 lib/tolua++/src/bin/container_lua.h diff --git a/lib/tolua++/src/bin/container_lua.h b/lib/tolua++/src/bin/container_lua.h new file mode 100644 index 000000000..4c7cf6a67 --- /dev/null +++ b/lib/tolua++/src/bin/container_lua.h @@ -0,0 +1,1476 @@ +static const unsigned char lua_container_lua[] = { + 0x2d, 0x2d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, 0x20, 0x63, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x61, 0x62, 0x73, 0x74, + 0x72, 0x61, 0x63, 0x74, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x0a, 0x2d, + 0x2d, 0x20, 0x57, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20, 0x62, 0x79, + 0x20, 0x57, 0x61, 0x6c, 0x64, 0x65, 0x6d, 0x61, 0x72, 0x20, 0x43, 0x65, + 0x6c, 0x65, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x65, 0x43, 0x47, 0x72, + 0x61, 0x66, 0x2f, 0x50, 0x55, 0x43, 0x2d, 0x52, 0x69, 0x6f, 0x0a, 0x2d, + 0x2d, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x31, 0x39, 0x39, 0x38, 0x0a, 0x2d, + 0x2d, 0x20, 0x24, 0x49, 0x64, 0x3a, 0x20, 0x24, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x69, + 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, + 0x61, 0x72, 0x65, 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61, 0x6e, + 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, + 0x65, 0x20, 0x69, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72, 0x20, + 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x20, 0x69, 0x74, 0x2e, 0x0a, 0x2d, + 0x2d, 0x20, 0x54, 0x68, 0x65, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, + 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x64, 0x20, + 0x68, 0x65, 0x72, 0x65, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x69, 0x73, + 0x20, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x20, 0x22, 0x61, 0x73, 0x20, 0x69, + 0x73, 0x22, 0x20, 0x62, 0x61, 0x73, 0x69, 0x73, 0x2c, 0x20, 0x61, 0x6e, + 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, + 0x68, 0x6f, 0x72, 0x20, 0x68, 0x61, 0x73, 0x20, 0x6e, 0x6f, 0x20, 0x6f, + 0x62, 0x6c, 0x69, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x6f, + 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x20, 0x6d, 0x61, 0x69, + 0x6e, 0x74, 0x65, 0x6e, 0x61, 0x6e, 0x63, 0x65, 0x2c, 0x20, 0x73, 0x75, + 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2c, 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x73, 0x2c, 0x0a, 0x2d, 0x2d, 0x20, 0x65, 0x6e, 0x68, 0x61, 0x6e, + 0x63, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2c, 0x20, 0x6f, 0x72, 0x20, + 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2e, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, + 0x20, 0x74, 0x6f, 0x20, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x20, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x64, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x64, 0x65, 0x66, 0x73, 0x2f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x20, + 0x69, 0x6e, 0x20, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x20, 0x73, 0x63, + 0x6f, 0x70, 0x65, 0x0a, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, + 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, + 0x0a, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x65, 0x6e, 0x75, 0x6d, + 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x52, 0x65, 0x70, 0x72, 0x65, 0x73, + 0x65, 0x6e, 0x74, 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x20, 0x6f, 0x66, 0x20, 0x66, 0x65, 0x61, 0x74, + 0x75, 0x72, 0x65, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x62, 0x65, 0x20, 0x62, + 0x6f, 0x75, 0x6e, 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x6f, 0x20, 0x6c, + 0x75, 0x61, 0x2e, 0x0a, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x3d, 0x0a, 0x7b, 0x0a, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x2c, 0x0a, + 0x7d, 0x0a, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x5f, 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78, + 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x0a, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, + 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2c, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x29, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x74, + 0x61, 0x67, 0x73, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, + 0x6e, 0x65, 0x72, 0x3a, 0x64, 0x65, 0x63, 0x6c, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x28, 0x29, 0x0a, 0x20, 0x70, 0x75, 0x73, 0x68, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, + 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x3a, 0x64, 0x65, 0x63, 0x6c, 0x74, + 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, + 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x70, 0x6f, + 0x70, 0x28, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, + 0x72, 0x74, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x73, 0x75, 0x70, 0x63, + 0x6f, 0x64, 0x65, 0x20, 0x28, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, + 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x70, 0x75, 0x73, 0x68, 0x28, 0x73, 0x65, 0x6c, + 0x66, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, + 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x69, 0x66, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x3a, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x3a, 0x73, + 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x70, 0x6f, 0x70, 0x28, 0x29, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x68, 0x61, 0x73, 0x76, 0x61, 0x72, + 0x20, 0x28, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, + 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x3a, 0x69, 0x73, + 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x29, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, + 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x30, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, + 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, 0x43, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, + 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2c, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, + 0x72, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x20, 0x3d, + 0x20, 0x30, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x64, 0x65, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x6e, 0x3d, 0x30, 0x7d, 0x0a, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, 0x20, + 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x65, + 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x6e, 0x3d, 0x30, 0x7d, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, + 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x70, 0x75, + 0x73, 0x68, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x75, + 0x73, 0x68, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x74, 0x2e, 0x70, 0x72, + 0x6f, 0x78, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, + 0x0a, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, + 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x70, 0x6f, + 0x70, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x6f, 0x70, + 0x20, 0x28, 0x29, 0x0a, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, + 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, + 0x72, 0x72, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x2d, 0x2d, 0x66, + 0x6f, 0x72, 0x65, 0x61, 0x63, 0x68, 0x28, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, + 0x72, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, + 0x2c, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x29, 0x0a, 0x2d, 0x2d, 0x70, 0x72, + 0x69, 0x6e, 0x74, 0x28, 0x22, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, + 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x22, 0x29, 0x0a, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, + 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, + 0x63, 0x75, 0x72, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x20, 0x63, 0x75, + 0x72, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, + 0x61, 0x63, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x67, 0x65, 0x74, 0x63, 0x75, 0x72, 0x72, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x28, 0x29, 0x0a, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, + 0x72, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, + 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x65, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, + 0x72, 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28, 0x74, 0x29, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, 0x70, + 0x65, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, + 0x74, 0x6f, 0x20, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x28, 0x74, 0x29, 0x0a, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, + 0x75, 0x72, 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, 0x74, 0x29, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, + 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x20, 0x74, 0x6f, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x75, 0x73, 0x65, + 0x72, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, + 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x75, 0x73, 0x65, 0x72, + 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, 0x65, + 0x6e, 0x75, 0x6d, 0x20, 0x74, 0x6f, 0x20, 0x63, 0x75, 0x72, 0x72, 0x65, + 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, + 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x75, 0x6d, 0x20, 0x28, 0x74, 0x29, + 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, + 0x63, 0x75, 0x72, 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x65, + 0x6e, 0x75, 0x6d, 0x28, 0x74, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x73, 0x75, 0x62, 0x73, 0x74, 0x69, 0x74, 0x75, 0x74, + 0x65, 0x20, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x28, 0x6d, 0x6f, 0x64, + 0x2c, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x3a, 0x61, + 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, + 0x6d, 0x6f, 0x64, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, + 0x69, 0x66, 0x20, 0x69, 0x73, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x69, 0x6e, 0x64, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, + 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x3a, 0x66, 0x69, 0x6e, 0x64, 0x74, + 0x79, 0x70, 0x65, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x69, 0x66, + 0x20, 0x69, 0x73, 0x20, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x74, + 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, + 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x2e, 0x63, 0x75, 0x72, 0x72, 0x3a, 0x69, 0x73, 0x74, 0x79, 0x70, 0x65, + 0x64, 0x65, 0x66, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x20, 0x66, 0x75, + 0x6c, 0x6c, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x77, 0x69, 0x74, 0x68, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x29, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x75, 0x6c, + 0x6c, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, + 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x0a, 0x09, 0x77, 0x68, + 0x69, 0x6c, 0x65, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x64, 0x6f, 0x0a, + 0x09, 0x20, 0x69, 0x66, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x69, 0x66, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x64, 0x65, 0x66, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, + 0x73, 0x5b, 0x74, 0x5d, 0x0a, 0x09, 0x09, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x69, 0x66, 0x20, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, + 0x74, 0x79, 0x70, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x75, + 0x72, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, + 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x75, 0x72, 0x72, + 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, 0x74, + 0x5d, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x73, 0x20, 0x69, 0x66, 0x20, 0x69, 0x74, 0x20, 0x72, 0x65, + 0x71, 0x75, 0x69, 0x72, 0x65, 0x73, 0x20, 0x63, 0x6f, 0x6c, 0x6c, 0x65, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, + 0x65, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x28, 0x74, 0x29, 0x0a, 0x20, 0x70, 0x75, 0x73, 0x68, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, + 0x3d, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x20, + 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x77, 0x68, 0x69, + 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x20, 0x64, + 0x6f, 0x0a, 0x20, 0x20, 0x72, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x5b, 0x69, 0x5d, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x63, + 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, + 0x20, 0x6f, 0x72, 0x20, 0x72, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, + 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x70, 0x6f, + 0x70, 0x28, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x72, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x67, + 0x65, 0x74, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x61, 0x70, 0x63, 0x65, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, + 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x28, + 0x63, 0x75, 0x72, 0x72, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x3d, + 0x20, 0x27, 0x27, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x63, + 0x75, 0x72, 0x72, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x20, + 0x20, 0x20, 0x28, 0x20, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, + 0x65, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, + 0x3d, 0x20, 0x28, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x6f, 0x72, 0x69, 0x67, + 0x69, 0x6e, 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x72, + 0x20, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x20, + 0x2e, 0x2e, 0x20, 0x27, 0x3a, 0x3a, 0x27, 0x20, 0x2e, 0x2e, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x09, 0x09, 0x20, + 0x2d, 0x2d, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, + 0x3d, 0x20, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x2e, 0x2e, 0x20, 0x27, 0x3a, 0x3a, 0x27, 0x20, 0x2e, 0x2e, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x20, 0x6e, 0x61, 0x6d, + 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x28, 0x6f, 0x6e, 0x6c, 0x79, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x29, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, + 0x6f, 0x6e, 0x6c, 0x79, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, + 0x65, 0x20, 0x28, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, + 0x72, 0x72, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x27, + 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x63, 0x75, 0x72, 0x72, + 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, + 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, + 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x3d, 0x20, 0x63, + 0x75, 0x72, 0x72, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x2e, 0x2e, 0x20, + 0x27, 0x3a, 0x3a, 0x27, 0x20, 0x2e, 0x2e, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x69, 0x66, 0x20, 0x69, + 0x73, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x65, 0x6e, 0x75, 0x6d, 0x20, 0x28, + 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x3a, 0x69, 0x73, + 0x65, 0x6e, 0x75, 0x6d, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, + 0x64, 0x20, 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x74, 0x6f, + 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x61, + 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, + 0x0a, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x3d, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x64, 0x65, 0x66, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x74, + 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, + 0x61, 0x63, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x6e, 0x61, 0x6d, + 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, + 0x72, 0x72, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x2e, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x6e, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x2e, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x2e, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, + 0x0a, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, + 0x65, 0x66, 0x73, 0x5b, 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x5d, + 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, + 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x0a, + 0x09, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, + 0x64, 0x65, 0x66, 0x73, 0x5b, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, + 0x63, 0x65, 0x2e, 0x2e, 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x5d, + 0x20, 0x3d, 0x20, 0x74, 0x0a, 0x09, 0x74, 0x2e, 0x66, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, + 0x28, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x6f, 0x72, 0x20, + 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x2d, 0x2d, 0x70, 0x72, + 0x69, 0x6e, 0x74, 0x28, 0x22, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x69, + 0x6e, 0x67, 0x20, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x22, + 0x2e, 0x2e, 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, + 0x20, 0x61, 0x73, 0x20, 0x22, 0x2e, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x73, + 0x70, 0x61, 0x63, 0x65, 0x2e, 0x2e, 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, + 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x66, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x22, 0x2e, 0x2e, 0x74, 0x2e, 0x66, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x5f, + 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, + 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x2e, 0x2e, 0x74, + 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, + 0x74, 0x2e, 0x66, 0x74, 0x79, 0x70, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x69, 0x73, 0x65, 0x6e, 0x75, 0x6d, 0x28, 0x74, 0x2e, 0x66, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, + 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, + 0x5b, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x2e, 0x2e, + 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x74, + 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, + 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x75, 0x6c, 0x6c, 0x20, 0x74, 0x79, + 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x75, 0x73, 0x65, + 0x72, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x74, 0x20, 0x3d, 0x3d, 0x20, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, + 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x72, + 0x6f, 0x78, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x3d, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x66, 0x74, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, + 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x63, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x29, 0x20, 0x2e, 0x2e, 0x20, + 0x74, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, 0x74, + 0x5d, 0x20, 0x3d, 0x20, 0x66, 0x74, 0x0a, 0x09, 0x5f, 0x75, 0x73, 0x65, + 0x72, 0x74, 0x79, 0x70, 0x65, 0x5b, 0x66, 0x74, 0x5d, 0x20, 0x3d, 0x20, + 0x66, 0x74, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, + 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, + 0x70, 0x65, 0x6e, 0x64, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x61, 0x70, + 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x75, 0x6d, 0x20, 0x28, 0x74, 0x29, + 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, + 0x63, 0x75, 0x72, 0x72, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x2e, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x6e, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x2e, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x20, 0x2b, + 0x20, 0x31, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x65, 0x6e, 0x75, 0x6d, + 0x73, 0x2e, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x5d, 0x20, 0x3d, + 0x20, 0x74, 0x0a, 0x09, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x65, + 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, + 0x63, 0x65, 0x2e, 0x2e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, + 0x3d, 0x20, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, + 0x64, 0x65, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x65, 0x20, 0x6c, 0x75, + 0x61, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x3a, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x28, 0x6c, + 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x5b, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x5b, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x3d, + 0x20, 0x30, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x6c, + 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x6c, 0x6e, 0x61, 0x6d, + 0x65, 0x5d, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x6d, + 0x61, 0x74, 0x28, 0x22, 0x25, 0x30, 0x32, 0x64, 0x22, 0x2c, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x6c, 0x6e, + 0x61, 0x6d, 0x65, 0x5d, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x20, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x3a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x27, 0x74, 0x68, 0x65, 0x20, + 0x66, 0x61, 0x63, 0x74, 0x6f, 0x27, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, + 0x69, 0x65, 0x72, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x3a, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, + 0x66, 0x20, 0x28, 0x6d, 0x6f, 0x64, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x74, 0x79, 0x70, + 0x65, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, + 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x22, 0x66, 0x6f, 0x75, 0x6e, 0x64, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x22, 0x2e, 0x2e, + 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x64, + 0x65, 0x66, 0x73, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6d, 0x6f, 0x64, 0x31, 0x2c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x31, 0x20, + 0x3d, 0x20, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, + 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x2e, + 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x74, 0x79, 0x70, + 0x65, 0x5d, 0x2e, 0x66, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x6f, 0x64, 0x32, 0x2c, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x32, 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, 0x6d, 0x6f, 0x64, 0x2e, + 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, 0x6d, 0x6f, 0x64, 0x31, 0x2c, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x31, 0x29, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6d, 0x6f, 0x64, 0x32, 0x20, 0x2e, + 0x2e, 0x20, 0x27, 0x20, 0x27, 0x20, 0x2e, 0x2e, 0x20, 0x6d, 0x6f, 0x64, + 0x31, 0x2c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x32, 0x0a, 0x09, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6d, 0x6f, 0x64, 0x32, 0x2c, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x32, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x64, 0x6f, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6d, 0x6f, + 0x64, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x20, 0x69, 0x66, 0x20, 0x69, 0x74, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x69, 0x73, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x65, 0x6e, 0x76, 0x20, + 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, + 0x65, 0x20, 0x65, 0x6e, 0x76, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, + 0x66, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, + 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x65, 0x6e, 0x76, 0x2e, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x69, 0x5d, 0x2e, + 0x75, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x76, 0x20, 0x3d, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, + 0x69, 0x6e, 0x64, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x5f, 0x76, 0x61, 0x72, + 0x28, 0x76, 0x61, 0x72, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x74, + 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x76, 0x61, 0x72, 0x29, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x76, 0x61, 0x72, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, + 0x63, 0x75, 0x72, 0x72, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, + 0x63, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x6e, 0x61, 0x6d, + 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x63, 0x29, 0x0a, 0x09, 0x09, + 0x66, 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x70, + 0x61, 0x69, 0x72, 0x73, 0x28, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, + 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x29, 0x20, 0x64, 0x6f, 0x0a, 0x09, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x74, + 0x79, 0x70, 0x65, 0x28, 0x76, 0x61, 0x72, 0x2c, 0x20, 0x76, 0x2c, 0x20, + 0x6e, 0x73, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x0a, 0x09, 0x09, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x09, 0x69, 0x66, 0x20, 0x63, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x63, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x7e, 0x3d, + 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x63, 0x20, 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x63, 0x3a, 0x66, 0x69, + 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, 0x63, 0x2e, 0x62, 0x61, 0x73, + 0x65, 0x29, 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x09, 0x09, 0x63, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x72, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, + 0x69, 0x66, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x72, 0x65, 0x67, 0x69, + 0x73, 0x74, 0x65, 0x72, 0x65, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3a, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x75, 0x6c, 0x6c, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x6e, 0x69, 0x6c, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x3a, 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x74, + 0x29, 0x0a, 0x0a, 0x09, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, 0x20, 0x22, + 0x3d, 0x2e, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5b, 0x74, 0x5d, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x74, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x65, 0x6d, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x28, 0x5b, 0x26, 0x25, 0x2a, 0x5d, + 0x29, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x29, 0x0a, 0x09, 0x74, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x74, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x26, 0x25, + 0x2a, 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, + 0x29, 0x0a, 0x09, 0x70, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, + 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x70, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x70, 0x29, 0x3d, 0x3d, 0x27, 0x74, + 0x61, 0x62, 0x6c, 0x65, 0x27, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x67, 0x65, + 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x70, + 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x5f, + 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, + 0x2e, 0x6e, 0x2c, 0x31, 0x2c, 0x2d, 0x31, 0x20, 0x64, 0x6f, 0x20, 0x2d, + 0x2d, 0x20, 0x69, 0x6e, 0x20, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, + 0x20, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x69, + 0x66, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x74, 0x79, 0x70, 0x65, + 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x73, 0x74, + 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, + 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x2e, + 0x28, 0x65, 0x6d, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x70, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x70, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x7e, + 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x2e, 0x62, + 0x61, 0x73, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x74, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x28, 0x22, 0x74, 0x79, 0x70, 0x65, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, + 0x2e, 0x74, 0x2e, 0x2e, 0x22, 0x2c, 0x20, 0x70, 0x20, 0x69, 0x73, 0x20, + 0x22, 0x2e, 0x2e, 0x70, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x2e, 0x22, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x69, + 0x73, 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x09, + 0x70, 0x20, 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x70, 0x3a, 0x66, 0x69, + 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, 0x70, 0x2e, 0x62, 0x61, 0x73, + 0x65, 0x29, 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x09, 0x09, 0x70, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, + 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x29, 0x0a, 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, + 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x6e, 0x20, 0x3d, 0x20, + 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x2e, 0x6e, 0x20, 0x2b, 0x31, 0x0a, 0x09, 0x5f, 0x67, 0x6c, 0x6f, + 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, 0x5f, 0x67, + 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, + 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x0a, 0x09, 0x5f, 0x67, 0x6c, 0x6f, + 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5f, 0x68, 0x61, + 0x73, 0x68, 0x5b, 0x74, 0x5d, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x5f, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, + 0x70, 0x70, 0x65, 0x6e, 0x64, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, + 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x74, 0x5d, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x5f, 0x67, + 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, + 0x73, 0x5b, 0x74, 0x5d, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x0a, 0x09, + 0x09, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x20, 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x2e, 0x6c, + 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x5f, + 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x28, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x2e, 0x62, + 0x61, 0x73, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x29, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, + 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, + 0x74, 0x5d, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x5f, 0x67, + 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, + 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x0a, 0x09, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x66, 0x6c, 0x61, 0x67, + 0x73, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x66, 0x6c, + 0x61, 0x67, 0x73, 0x20, 0x6f, 0x72, 0x20, 0x7b, 0x7d, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x63, + 0x68, 0x69, 0x6c, 0x64, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x72, 0x65, + 0x67, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x73, 0x74, 0x29, 0x0a, 0x2d, + 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x22, 0x66, 0x69, 0x6e, 0x64, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x22, 0x2e, 0x2e, 0x63, 0x68, 0x69, 0x6c, + 0x64, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x2c, 0x20, 0x22, 0x2e, + 0x2e, 0x72, 0x65, 0x67, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x2c, + 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x74, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x72, 0x65, 0x67, + 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x74, + 0x79, 0x70, 0x65, 0x2c, 0x20, 0x2d, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x6c, 0x65, 0x6e, 0x28, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x2c, 0x20, 0x74, 0x72, 0x75, 0x65, 0x29, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, + 0x09, 0x69, 0x66, 0x20, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x6c, 0x65, 0x6e, 0x28, 0x72, 0x65, 0x67, 0x74, + 0x79, 0x70, 0x65, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x28, 0x62, 0x20, 0x3d, 0x3d, 0x20, 0x31, 0x20, 0x6f, 0x72, 0x20, + 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, + 0x72, 0x65, 0x67, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x62, 0x2d, 0x31, + 0x2c, 0x20, 0x62, 0x2d, 0x31, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x3a, + 0x27, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x72, 0x65, 0x67, + 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x62, 0x2d, 0x31, + 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x73, 0x75, 0x62, 0x28, 0x73, 0x74, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x62, + 0x2d, 0x31, 0x29, 0x29, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, + 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, + 0x6c, 0x73, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, + 0x70, 0x65, 0x5f, 0x6f, 0x6e, 0x5f, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x73, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2c, 0x20, 0x74, 0x29, 0x0a, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x63, 0x68, 0x69, 0x6c, 0x64, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, + 0x63, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x66, + 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x69, 0x70, + 0x61, 0x69, 0x72, 0x73, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, 0x20, 0x64, + 0x6f, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x76, 0x2e, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x76, 0x2e, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, + 0x20, 0x27, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, + 0x20, 0x76, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x76, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, + 0x66, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x09, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x74, 0x5d, + 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, + 0x76, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x76, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, + 0x70, 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x76, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, + 0x74, 0x5d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x09, 0x09, 0x09, 0x74, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x20, 0x3d, 0x20, + 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x6f, 0x6e, 0x5f, + 0x63, 0x68, 0x69, 0x6c, 0x64, 0x73, 0x28, 0x76, 0x2c, 0x20, 0x74, 0x29, + 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x63, 0x68, 0x69, + 0x6c, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x74, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, + 0x72, 0x3a, 0x69, 0x73, 0x65, 0x6e, 0x75, 0x6d, 0x20, 0x28, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x67, 0x6c, 0x6f, 0x62, + 0x61, 0x6c, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x74, 0x79, 0x70, + 0x65, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x0a, 0x20, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x61, 0x73, 0x65, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, + 0x79, 0x70, 0x65, 0x2c, 0x22, 0x5e, 0x2e, 0x2a, 0x3a, 0x3a, 0x22, 0x2c, + 0x22, 0x22, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x65, + 0x6e, 0x76, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, 0x20, 0x77, + 0x68, 0x69, 0x6c, 0x65, 0x20, 0x65, 0x6e, 0x76, 0x20, 0x64, 0x6f, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, + 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x65, 0x6e, + 0x75, 0x6d, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, + 0x3d, 0x20, 0x62, 0x61, 0x73, 0x65, 0x74, 0x79, 0x70, 0x65, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, + 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x76, 0x20, + 0x3d, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x69, 0x73, 0x76, 0x69, 0x72, + 0x74, 0x75, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, + 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x20, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x70, 0x61, 0x72, 0x73, 0x65, 0x20, 0x63, + 0x68, 0x75, 0x6e, 0x6b, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x64, 0x6f, 0x70, 0x61, 0x72, 0x73, 0x65, + 0x20, 0x28, 0x73, 0x29, 0x0a, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x20, 0x28, 0x22, 0x70, 0x61, 0x72, 0x73, 0x65, 0x20, 0x22, 0x2e, 0x2e, + 0x73, 0x29, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x72, 0x73, 0x65, 0x72, 0x20, 0x68, + 0x6f, 0x6f, 0x6b, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x73, 0x75, 0x62, 0x20, 0x3d, 0x20, 0x70, 0x61, + 0x72, 0x73, 0x65, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x29, + 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x73, 0x75, 0x62, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x73, 0x75, 0x62, 0x0a, 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x20, 0x73, 0x74, + 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x0a, 0x20, 0x64, 0x6f, 0x0a, + 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, + 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x3b, 0x22, 0x29, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, + 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, + 0x72, 0x79, 0x20, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x20, 0x76, 0x65, 0x72, + 0x62, 0x61, 0x74, 0x69, 0x6d, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x20, + 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, + 0x2c, 0x65, 0x2c, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, + 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x24, 0x5c, 0x6e, 0x22, 0x29, 0x0a, + 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, + 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x4c, 0x75, 0x61, 0x20, + 0x63, 0x6f, 0x64, 0x65, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x63, 0x6f, 0x64, + 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x5c, 0x31, + 0x5c, 0x32, 0x29, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x43, 0x6f, 0x64, + 0x65, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x63, 0x6f, 0x64, + 0x65, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x74, 0x72, 0x79, 0x20, 0x43, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x0a, + 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x62, 0x2c, 0x65, 0x2c, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, + 0x73, 0x2a, 0x28, 0x25, 0x62, 0x5c, 0x33, 0x5c, 0x34, 0x29, 0x22, 0x29, + 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x7b, 0x27, + 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x63, 0x6f, 0x64, + 0x65, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x2e, 0x2e, 0x27, 0x5c, 0x6e, + 0x7d, 0x5c, 0x6e, 0x27, 0x0a, 0x09, 0x56, 0x65, 0x72, 0x62, 0x61, 0x74, + 0x69, 0x6d, 0x28, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x27, 0x72, 0x27, 0x29, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x76, + 0x65, 0x72, 0x62, 0x61, 0x74, 0x69, 0x6d, 0x20, 0x63, 0x6f, 0x64, 0x65, + 0x20, 0x66, 0x6f, 0x72, 0x20, 0x27, 0x72, 0x27, 0x65, 0x67, 0x69, 0x73, + 0x74, 0x65, 0x72, 0x20, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, + 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, + 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, + 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x43, 0x20, 0x63, 0x6f, 0x64, + 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x70, 0x72, 0x65, 0x61, 0x6d, 0x62, + 0x6c, 0x65, 0x20, 0x73, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, + 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, + 0x2c, 0x65, 0x2c, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, + 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x5c, 0x35, 0x5c, + 0x36, 0x29, 0x22, 0x29, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x63, 0x6f, 0x64, 0x65, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, + 0x62, 0x28, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x32, 0x2c, 0x20, 0x2d, + 0x32, 0x29, 0x2e, 0x2e, 0x22, 0x5c, 0x6e, 0x22, 0x0a, 0x09, 0x09, 0x56, + 0x65, 0x72, 0x62, 0x61, 0x74, 0x69, 0x6d, 0x28, 0x63, 0x6f, 0x64, 0x65, + 0x2c, 0x20, 0x27, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x20, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, + 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, + 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x20, 0x64, + 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x0a, 0x20, 0x64, 0x6f, + 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, + 0x2c, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, + 0x2a, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x50, 0x52, 0x4f, 0x50, 0x45, + 0x52, 0x54, 0x59, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x25, 0x73, 0x2a, 0x25, + 0x28, 0x2b, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x29, 0x25, 0x73, + 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x2b, 0x25, 0x73, 0x2a, + 0x3b, 0x3f, 0x22, 0x29, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6f, 0x72, 0x20, + 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x22, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x09, 0x70, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x3d, 0x20, 0x22, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, + 0x74, 0x22, 0x0a, 0x20, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x09, + 0x09, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x73, 0x65, 0x74, 0x5f, 0x70, 0x72, + 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, + 0x70, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x20, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x20, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, + 0x74, 0x72, 0x79, 0x20, 0x70, 0x72, 0x6f, 0x74, 0x65, 0x63, 0x74, 0x65, + 0x64, 0x5f, 0x64, 0x65, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, + 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x0a, 0x20, + 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, + 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, + 0x2a, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x50, 0x52, 0x4f, 0x54, 0x45, + 0x43, 0x54, 0x45, 0x44, 0x5f, 0x44, 0x45, 0x53, 0x54, 0x52, 0x55, 0x43, + 0x54, 0x4f, 0x52, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x22, 0x29, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x73, 0x65, 0x74, 0x5f, + 0x70, 0x72, 0x6f, 0x74, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x64, 0x65, + 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x20, 0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x73, + 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x65, 0x63, 0x74, 0x65, 0x64, + 0x5f, 0x64, 0x65, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x28, + 0x74, 0x72, 0x75, 0x65, 0x29, 0x0a, 0x09, 0x20, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x65, 0x2b, 0x31, + 0x29, 0x0a, 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x27, 0x65, + 0x78, 0x74, 0x65, 0x72, 0x6e, 0x27, 0x20, 0x6b, 0x65, 0x79, 0x77, 0x6f, + 0x72, 0x64, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, + 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x25, + 0x73, 0x2b, 0x22, 0x29, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x64, 0x6f, + 0x20, 0x6e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x0a, 0x20, 0x09, 0x09, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x20, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, + 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x27, 0x76, 0x69, 0x72, 0x74, 0x75, + 0x61, 0x6c, 0x27, 0x20, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x6b, 0x64, + 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x62, 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x25, 0x73, + 0x2b, 0x22, 0x29, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x6d, 0x65, 0x74, 0x68, 0x6f, + 0x64, 0x69, 0x73, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x3d, + 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x2c, 0x20, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, + 0x72, 0x79, 0x20, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x20, 0x28, 0x70, + 0x75, 0x62, 0x6c, 0x69, 0x63, 0x2c, 0x20, 0x70, 0x72, 0x69, 0x76, 0x61, + 0x74, 0x65, 0x2c, 0x20, 0x65, 0x74, 0x63, 0x29, 0x0a, 0x20, 0x64, 0x6f, + 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, + 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x25, + 0x77, 0x2a, 0x25, 0x73, 0x2a, 0x3a, 0x5b, 0x5e, 0x3a, 0x5d, 0x22, 0x29, + 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x65, 0x29, 0x20, + 0x2d, 0x2d, 0x20, 0x70, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x5b, 0x5e, 0x3a, 0x5d, 0x0a, 0x20, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x74, 0x72, 0x79, 0x20, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x0a, + 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, + 0x79, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x6d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, + 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, + 0x62, 0x7b, 0x7d, 0x29, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, + 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x4d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, + 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x6e, 0x61, 0x6d, + 0x65, 0x73, 0x61, 0x70, 0x63, 0x65, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, + 0x73, 0x2a, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x25, + 0x73, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, + 0x25, 0x77, 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, + 0x7d, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x22, 0x29, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, + 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x4e, 0x61, 0x6d, 0x65, 0x73, + 0x70, 0x61, 0x63, 0x65, 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, + 0x64, 0x79, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, + 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, + 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x6e, + 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x23, 0x64, 0x65, + 0x66, 0x69, 0x6e, 0x65, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, + 0x25, 0x73, 0x5d, 0x2a, 0x29, 0x5b, 0x5e, 0x5c, 0x6e, 0x5d, 0x2a, 0x5c, + 0x6e, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, + 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x44, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x28, 0x6e, + 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, + 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, + 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x73, 0x0a, + 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, + 0x64, 0x79, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, + 0x5e, 0x25, 0x73, 0x2a, 0x65, 0x6e, 0x75, 0x6d, 0x25, 0x73, 0x2b, 0x28, + 0x25, 0x53, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x73, 0x3b, 0x5d, 0x2a, + 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, + 0x23, 0x53, 0x6f, 0x72, 0x72, 0x79, 0x2c, 0x20, 0x64, 0x65, 0x63, 0x6c, + 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x65, + 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x76, 0x61, 0x72, + 0x69, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x73, 0x61, 0x6d, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, + 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x69, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x5c, 0x6e, + 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, 0x20, 0x79, 0x6f, 0x75, 0x72, + 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x73, 0x65, + 0x70, 0x61, 0x72, 0x61, 0x74, 0x65, 0x6c, 0x79, 0x20, 0x28, 0x65, 0x78, + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x3a, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x3b, 0x27, 0x29, 0x22, + 0x29, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, + 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, + 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x45, + 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, 0x6e, 0x61, 0x6d, + 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, + 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, + 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x64, 0x6f, 0x0a, 0x2d, 0x2d, + 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x65, 0x6e, 0x75, 0x6d, 0x25, 0x73, 0x2b, 0x28, 0x25, + 0x53, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, 0x29, + 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x2d, + 0x2d, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x2d, 0x2d, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, + 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x2d, 0x2d, 0x20, + 0x20, 0x20, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x29, 0x0a, 0x2d, + 0x2d, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, + 0x2d, 0x2d, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x65, + 0x6e, 0x64, 0x20, 0x0a, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x62, 0x6f, 0x64, + 0x79, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x25, 0x73, 0x2b, 0x65, 0x6e, + 0x75, 0x6d, 0x5b, 0x5e, 0x7b, 0x5d, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x25, 0x77, 0x5f, 0x5d, 0x5b, 0x5e, + 0x25, 0x73, 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, + 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, + 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, 0x6e, 0x61, + 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x74, 0x72, 0x79, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, + 0x72, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x6b, + 0x69, 0x6e, 0x64, 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, + 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x25, 0x73, 0x25, 0x2a, 0x26, 0x3a, 0x3c, + 0x3e, 0x2c, 0x5d, 0x2d, 0x25, 0x73, 0x2b, 0x6f, 0x70, 0x65, 0x72, 0x61, + 0x74, 0x6f, 0x72, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x73, + 0x5d, 0x5b, 0x5e, 0x25, 0x73, 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, + 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, 0x3f, 0x6f, + 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x25, 0x73, 0x2a, 0x3b, + 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x69, 0x6e, 0x6c, 0x69, + 0x6e, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, + 0x63, 0x6c, 0x2c, 0x6b, 0x69, 0x6e, 0x64, 0x2c, 0x61, 0x72, 0x67, 0x2c, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, + 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, + 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x25, 0x73, 0x25, + 0x2a, 0x26, 0x3a, 0x3c, 0x3e, 0x2c, 0x5d, 0x2d, 0x25, 0x73, 0x2b, 0x6f, + 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x29, 0x25, 0x73, 0x2a, 0x28, + 0x5b, 0x5e, 0x25, 0x73, 0x5d, 0x5b, 0x5e, 0x25, 0x73, 0x5d, 0x2a, 0x29, + 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, + 0x28, 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, + 0x5b, 0x25, 0x73, 0x5c, 0x6e, 0x5d, 0x2a, 0x25, 0x62, 0x7b, 0x7d, 0x25, + 0x73, 0x2a, 0x3b, 0x3f, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x2d, + 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x63, 0x61, 0x73, 0x74, 0x20, 0x6f, + 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x0a, 0x20, 0x20, 0x09, 0x62, + 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x6b, 0x69, 0x6e, 0x64, + 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, + 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, + 0x6f, 0x72, 0x29, 0x25, 0x73, 0x2b, 0x28, 0x5b, 0x25, 0x77, 0x5f, 0x3a, + 0x25, 0x64, 0x3c, 0x3e, 0x25, 0x2a, 0x25, 0x26, 0x25, 0x73, 0x5d, 0x2b, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, + 0x2a, 0x28, 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, + 0x29, 0x22, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x69, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, + 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x25, 0x62, 0x7b, 0x7d, 0x22, + 0x2c, 0x20, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x69, + 0x66, 0x20, 0x69, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x09, 0x09, 0x09, 0x65, 0x20, 0x3d, 0x20, 0x69, 0x65, 0x0a, 0x20, 0x20, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, + 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, + 0x28, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x6b, 0x69, 0x6e, 0x64, 0x2c, 0x61, + 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x29, 0x0a, 0x20, 0x20, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, + 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, + 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, + 0x6c, 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, + 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x7e, 0x5f, 0x25, 0x77, 0x5d, + 0x5b, 0x5f, 0x40, 0x25, 0x77, 0x25, 0x73, 0x25, 0x2a, 0x26, 0x3a, 0x3c, + 0x3e, 0x5d, 0x2a, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x29, 0x25, 0x73, 0x2a, + 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, 0x3f, + 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x25, 0x73, 0x2a, + 0x3d, 0x3f, 0x25, 0x73, 0x2a, 0x30, 0x3f, 0x25, 0x73, 0x2a, 0x3b, 0x25, + 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x61, 0x72, + 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x2c, 0x76, 0x69, 0x72, 0x74, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, + 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x28, 0x5c, + 0x6e, 0x5d, 0x2b, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, + 0x3f, 0x74, 0x3f, 0x29, 0x76, 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, + 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, 0x25, 0x73, 0x2a, 0x6f, 0x3f, 0x76, + 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, + 0x3f, 0x25, 0x73, 0x2a, 0x28, 0x3d, 0x3f, 0x25, 0x73, 0x2a, 0x30, 0x3f, + 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, + 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x77, 0x69, + 0x74, 0x68, 0x20, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x0a, + 0x20, 0x20, 0x09, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, + 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x7e, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, + 0x40, 0x25, 0x77, 0x25, 0x73, 0x25, 0x2a, 0x26, 0x3a, 0x3c, 0x3e, 0x5d, + 0x2a, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x25, 0x62, 0x3c, 0x3e, 0x29, 0x25, + 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, + 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x76, + 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, + 0x3f, 0x25, 0x73, 0x2a, 0x6f, 0x3f, 0x76, 0x3f, 0x65, 0x3f, 0x72, 0x3f, + 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, 0x25, 0x73, 0x2a, 0x3d, + 0x3f, 0x25, 0x73, 0x2a, 0x30, 0x3f, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, + 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, + 0x61, 0x20, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x20, 0x6c, 0x65, 0x74, + 0x74, 0x65, 0x72, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x62, 0x2c, 0x65, + 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, + 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, + 0x25, 0x77, 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, + 0x3f, 0x74, 0x3f, 0x29, 0x76, 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, + 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, 0x25, 0x73, 0x2a, 0x6f, 0x3f, 0x76, + 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, + 0x3f, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, + 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x0a, + 0x20, 0x20, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, + 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x28, 0x3b, 0x5c, 0x6e, 0x5d, + 0x2b, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, + 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x20, 0x22, 0x25, 0x28, 0x25, 0x73, + 0x2a, 0x25, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x29, 0x5d, 0x2a, 0x29, 0x25, + 0x73, 0x2a, 0x25, 0x29, 0x22, 0x2c, 0x20, 0x22, 0x20, 0x25, 0x31, 0x20, + 0x22, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x69, 0x66, 0x20, 0x76, 0x69, + 0x72, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x76, 0x69, 0x72, 0x74, 0x2c, + 0x20, 0x22, 0x5b, 0x3d, 0x30, 0x5d, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x20, 0x20, 0x09, 0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x66, + 0x6c, 0x61, 0x67, 0x73, 0x2e, 0x70, 0x75, 0x72, 0x65, 0x5f, 0x76, 0x69, + 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, + 0x0a, 0x20, 0x20, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, + 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, + 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x3d, + 0x20, 0x27, 0x6f, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x27, + 0x27, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, + 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, 0x65, 0x63, + 0x6c, 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, + 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x69, 0x6e, 0x6c, + 0x69, 0x6e, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x61, 0x72, + 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, + 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x28, 0x5c, 0x6e, 0x5d, 0x2b, 0x29, 0x25, + 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, + 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x76, + 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, + 0x3f, 0x25, 0x73, 0x2a, 0x6f, 0x3f, 0x76, 0x3f, 0x65, 0x3f, 0x72, 0x3f, + 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, 0x5b, 0x5e, 0x3b, 0x7b, + 0x5d, 0x2a, 0x25, 0x62, 0x7b, 0x7d, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x25, + 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, + 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x7e, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, + 0x40, 0x25, 0x77, 0x25, 0x73, 0x25, 0x2a, 0x26, 0x3a, 0x3c, 0x3e, 0x5d, + 0x2a, 0x5b, 0x5f, 0x25, 0x77, 0x3e, 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x28, + 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, 0x3f, 0x6f, + 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x5b, 0x5e, 0x3b, 0x5d, + 0x2a, 0x25, 0x62, 0x7b, 0x7d, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x25, 0x73, + 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x2d, + 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x61, 0x20, 0x73, 0x69, 0x6e, 0x67, + 0x6c, 0x65, 0x20, 0x6c, 0x65, 0x74, 0x74, 0x65, 0x72, 0x20, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, + 0x20, 0x20, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, + 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x29, 0x25, 0x73, + 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, + 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x76, 0x3f, + 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, + 0x25, 0x73, 0x2a, 0x6f, 0x3f, 0x76, 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, + 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, 0x2e, 0x2d, 0x25, 0x62, 0x7b, + 0x7d, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, + 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x6f, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, + 0x20, 0x27, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x20, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, + 0x65, 0x63, 0x6c, 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, + 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, + 0x65, 0x2c, 0x62, 0x61, 0x73, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x0a, + 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x20, + 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x09, 0x09, + 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, + 0x73, 0x2a, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x25, 0x73, 0x2a, 0x28, 0x5b, + 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x40, 0x5d, 0x2a, 0x29, + 0x25, 0x73, 0x2a, 0x3b, 0x22, 0x29, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x64, + 0x75, 0x6d, 0x6d, 0x79, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x0a, 0x09, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, + 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x69, + 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x09, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, + 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, + 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, + 0x77, 0x40, 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x22, 0x29, 0x20, + 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, + 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, + 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x62, 0x61, 0x73, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, + 0x5e, 0x25, 0x73, 0x2a, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x25, 0x73, 0x2a, + 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x40, 0x5d, + 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x7b, 0x5d, 0x2d, 0x29, + 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, 0x29, 0x25, 0x73, 0x2a, + 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x09, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, + 0x61, 0x73, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, + 0x73, 0x2a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x25, 0x73, 0x2b, 0x28, + 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x40, 0x5d, 0x2a, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x7b, 0x5d, 0x2d, 0x29, 0x25, + 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, 0x29, 0x25, 0x73, 0x2a, 0x22, + 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x09, 0x09, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x62, 0x61, 0x73, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x25, 0x73, 0x2a, 0x28, + 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x40, 0x5d, 0x2a, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x7b, 0x5d, 0x2d, 0x29, 0x25, + 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, 0x29, 0x25, 0x73, 0x2a, 0x22, + 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x09, 0x09, 0x09, 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, + 0x27, 0x27, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x62, 0x2c, + 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, + 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, + 0x25, 0x73, 0x25, 0x73, 0x2a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x25, + 0x73, 0x25, 0x73, 0x2a, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x2a, 0x25, 0x73, + 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, + 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x40, 0x5d, 0x2a, 0x29, + 0x25, 0x73, 0x2a, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, + 0x09, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, + 0x3d, 0x20, 0x31, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x6c, + 0x73, 0x65, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, 0x3d, 0x20, 0x31, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x62, + 0x61, 0x73, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x62, 0x61, 0x73, 0x65, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, + 0x2a, 0x3a, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x62, + 0x61, 0x73, 0x65, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x70, 0x75, 0x62, + 0x6c, 0x69, 0x63, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, + 0x0a, 0x09, 0x09, 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, + 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x62, 0x61, 0x73, 0x65, 0x2c, 0x20, + 0x22, 0x2c, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x2d, 0x2d, 0x62, 0x2c, 0x65, 0x2c, 0x62, 0x61, 0x73, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x62, 0x61, + 0x73, 0x65, 0x2c, 0x22, 0x2e, 0x2d, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, + 0x5b, 0x5f, 0x25, 0x77, 0x3c, 0x3e, 0x2c, 0x3a, 0x5d, 0x2a, 0x29, 0x24, + 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x09, 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x7d, + 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x5f, + 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, + 0x29, 0x0a, 0x09, 0x09, 0x09, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x28, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x61, 0x73, 0x65, 0x2c, 0x62, 0x6f, 0x64, + 0x79, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x76, 0x61, 0x72, 0x62, 0x2c, 0x76, 0x61, 0x72, + 0x65, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, + 0x77, 0x5d, 0x2b, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x22, 0x2c, 0x20, 0x65, + 0x2b, 0x31, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x76, + 0x61, 0x72, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x6e, + 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, + 0x65, 0x20, 0x3d, 0x20, 0x76, 0x61, 0x72, 0x65, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x74, 0x79, 0x70, 0x65, + 0x64, 0x65, 0x66, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x74, 0x79, 0x70, 0x65, 0x64, + 0x65, 0x66, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x28, 0x2e, 0x2d, 0x29, 0x25, + 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, + 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, + 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x54, 0x79, 0x70, 0x65, 0x64, 0x65, + 0x66, 0x28, 0x74, 0x79, 0x70, 0x65, 0x73, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x74, 0x72, 0x79, 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, + 0x65, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, + 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, + 0x40, 0x25, 0x73, 0x25, 0x77, 0x25, 0x64, 0x25, 0x2a, 0x26, 0x3a, 0x3c, + 0x3e, 0x2c, 0x5d, 0x2a, 0x5b, 0x5f, 0x25, 0x77, 0x25, 0x64, 0x5d, 0x29, + 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, + 0x2c, 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6c, 0x69, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, + 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x64, 0x65, + 0x63, 0x6c, 0x2c, 0x20, 0x22, 0x2c, 0x22, 0x29, 0x0a, 0x09, 0x56, 0x61, + 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x6c, 0x69, 0x73, 0x74, 0x5b, + 0x31, 0x5d, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x69, 0x73, 0x74, + 0x2e, 0x6e, 0x20, 0x3e, 0x20, 0x31, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, + 0x6e, 0x64, 0x28, 0x6c, 0x69, 0x73, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x20, + 0x22, 0x28, 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2b, 0x28, 0x5b, 0x5e, 0x25, + 0x73, 0x5d, 0x2a, 0x29, 0x24, 0x22, 0x29, 0x3b, 0x0a, 0x0a, 0x09, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x20, 0x3d, 0x32, 0x3b, 0x0a, + 0x09, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x6c, 0x69, 0x73, 0x74, + 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x09, 0x56, 0x61, + 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, 0x79, 0x70, 0x65, 0x2e, + 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, 0x6c, 0x69, 0x73, 0x74, 0x5b, 0x69, + 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x3d, 0x69, 0x2b, 0x31, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x20, 0x2d, 0x2d, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, + 0x28, 0x64, 0x65, 0x63, 0x6c, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x74, + 0x72, 0x79, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x0a, 0x20, 0x64, + 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, + 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, + 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x3f, 0x5b, 0x5f, 0x25, 0x73, 0x25, + 0x77, 0x25, 0x64, 0x5d, 0x2d, 0x63, 0x68, 0x61, 0x72, 0x25, 0x73, 0x2b, + 0x5b, 0x5f, 0x40, 0x25, 0x77, 0x25, 0x64, 0x5d, 0x2a, 0x25, 0x73, 0x2a, + 0x25, 0x5b, 0x25, 0x73, 0x2a, 0x25, 0x53, 0x2b, 0x25, 0x73, 0x2a, 0x25, + 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, + 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x56, 0x61, 0x72, + 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x64, 0x65, 0x63, 0x6c, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x61, 0x72, 0x72, 0x61, + 0x79, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, + 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5d, + 0x5b, 0x5f, 0x40, 0x25, 0x73, 0x25, 0x77, 0x25, 0x64, 0x25, 0x2a, 0x26, + 0x3a, 0x3c, 0x3e, 0x5d, 0x2a, 0x5b, 0x5d, 0x5f, 0x25, 0x77, 0x25, 0x64, + 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, + 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x41, 0x72, 0x72, + 0x61, 0x79, 0x28, 0x64, 0x65, 0x63, 0x6c, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x6e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x69, 0x6e, 0x67, + 0x0a, 0x20, 0x69, 0x66, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, + 0x22, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x20, + 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x0a, 0x20, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, + 0x22, 0x23, 0x70, 0x61, 0x72, 0x73, 0x65, 0x20, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x70, 0x61, 0x72, + 0x73, 0x65, 0x20, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x6d, 0x65, 0x6d, + 0x62, 0x65, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x3d, + 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, + 0x20, 0x73, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x64, 0x6f, 0x0a, + 0x20, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x64, + 0x6f, 0x70, 0x61, 0x72, 0x73, 0x65, 0x28, 0x73, 0x29, 0x0a, 0x20, 0x20, + 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x69, 0x73, 0x76, 0x69, 0x72, 0x74, + 0x75, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, + 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, + 0x75, 0x72, 0x72, 0x3a, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, + 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x73, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x70, + 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x70, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, + 0x75, 0x62, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x70, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, + 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, + 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, + 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, + 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6f, + 0x72, 0x20, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x3a, 0x67, 0x65, 0x74, 0x5f, 0x70, + 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, + 0x28, 0x29, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x64, 0x65, 0x66, 0x61, + 0x75, 0x6c, 0x74, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a +}; +unsigned int lua_container_lua_len = 17673; -- cgit v1.2.3 From c7f8c7eb21424d483fbb3727aa48fefd0e12122c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 6 Apr 2014 17:47:27 +0100 Subject: Updated cWorld::CreateProjectile() documentation --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 59dd93137..233bdbc46 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2216,7 +2216,7 @@ end CastThunderbolt = { Params = "X, Y, Z", Return = "", Notes = "Creates a thunderbolt at the specified coords" }, ChangeWeather = { Params = "", Return = "", Notes = "Forces the weather to change in the next game tick. Weather is changed according to the normal rules: wSunny <-> wRain <-> wStorm" }, ChunkStay = { Params = "ChunkCoordTable, OnChunkAvailable, OnAllChunksAvailable", Return = "", Notes = "Queues the specified chunks to be loaded or generated and calls the specified callbacks once they are loaded. ChunkCoordTable is an arra-table of chunk coords, each coord being a table of 2 numbers: { {Chunk1x, Chunk1z}, {Chunk2x, Chunk2z}, ...}. When any of those chunks are made available (including being available at the start of this call), the OnChunkAvailable() callback is called. When all the chunks are available, the OnAllChunksAvailable() callback is called. The function signatures are:
    function OnChunkAvailable(ChunkX, ChunkZ)\nfunction OnAllChunksAvailable()
    All return values from the callbacks are ignored." }, - CreateProjectile = { Params = "X, Y, Z, {{cProjectileEntity|ProjectileKind}}, {{cEntity|Creator}}, [{{Vector3d|Speed}}]", Return = "", Notes = "Creates a new projectile of the specified kind at the specified coords. The projectile's creator is set to Creator (may be nil). Optional speed indicates the initial speed for the projectile." }, + CreateProjectile = { Params = "X, Y, Z, {{cProjectileEntity|ProjectileKind}}, {{cEntity|Creator}}, {{cItem|Originating Item}}, [{{Vector3d|Speed}}]", Return = "", Notes = "Creates a new projectile of the specified kind at the specified coords. The projectile's creator is set to Creator (may be nil). The item that created the projectile entity, commonly the {{cPlayer|player}}'s currently equipped item, is used at present for fireworks to correctly set their entity metadata. It is not used for any other projectile. Optional speed indicates the initial speed for the projectile." }, DigBlock = { Params = "X, Y, Z", Return = "", Notes = "Replaces the specified block with air, without dropping the usual pickups for the block. Wakes up the simulators for the block and its neighbors." }, DoExplosionAt = { Params = "Force, X, Y, Z, CanCauseFire, Source, SourceData", Return = "", Notes = "Creates an explosion of the specified relative force in the specified position. If CanCauseFire is set, the explosion will set blocks on fire, too. The Source parameter specifies the source of the explosion, one of the esXXX constants. The SourceData parameter is specific to each source type, usually it provides more info about the source." }, DoWithBlockEntityAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a block entity at the specified coords, calls the CallbackFunction with the {{cBlockEntity}} parameter representing the block entity. The CallbackFunction has the following signature:
    function Callback({{cBlockEntity|BlockEntity}}, [CallbackData])
    The function returns false if there is no block entity, or if there is, it returns the bool value that the callback has returned. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." }, -- cgit v1.2.3 From f5cb81eb1bb10d7a3a6704269644a6aedd04375a Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 6 Apr 2014 11:09:33 -0700 Subject: Added support for redstone latching fixes #856 --- src/Simulator/IncrementalRedstoneSimulator.cpp | 65 +++++++++++++++++++++++++- src/Simulator/IncrementalRedstoneSimulator.h | 2 + 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 92659fab7..b59f95cfd 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -688,12 +688,13 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B bool IsOn = ((a_MyState == E_BLOCK_REDSTONE_REPEATER_ON) ? true : false); // Cache if repeater is on bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); // Cache if repeater is pwoered + bool IsLocked = IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); - if (IsSelfPowered && !IsOn) // Queue a power change if I am receiving power but not on + if (IsSelfPowered && !IsOn && !IsLocked) // Queue a power change if I am receiving power but not on { QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, true); } - else if (!IsSelfPowered && IsOn) // Queue a power change if I am not receiving power but on + else if (!IsSelfPowered && IsOn && !IsLocked) // Queue a power change if I am not receiving power but on { QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, false); } @@ -1220,6 +1221,66 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY + +bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) +{ + // Repeaters can be locked by either of their sides + + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + + switch (a_Meta) + { + // If N/S check E/W + case 0x0: + case 0x2: + { + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } + break; + } + // If E/W check N/S + case 0x1: + case 0x3: + { + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } + break; + } + } + } + + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + + switch (a_Meta) + { + // If N/S check E/W + case 0x0: + case 0x2: + { + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } + break; + } + // If E/W check N/S + case 0x1: + case 0x3: + { + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } + break; + } + } + } + return false; // Couldn't find power source behind repeater +} + + + + bool cIncrementalRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) { // Pistons cannot be powered through their front face; this function verifies that a source meets this requirement diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index 8b7363366..f93f86898 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -154,6 +154,8 @@ private: bool AreCoordsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool IsCurrentStatePowered); /** Returns if a repeater is powered */ bool IsRepeaterPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); + /** Returns if a repeater is locked */ + bool IsRepeaterLocked(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); /** Returns if a piston is powered */ bool IsPistonPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); /** Returns if a wire is powered -- cgit v1.2.3 From 7119dd293a702ebdd2c5acf199e46fb91311701d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 6 Apr 2014 22:05:44 +0200 Subject: Updated the tolua executable for Windows. --- src/Bindings/tolua++.exe | Bin 200192 -> 200704 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/src/Bindings/tolua++.exe b/src/Bindings/tolua++.exe index 1e3cc7789..ba3a6b0c7 100644 Binary files a/src/Bindings/tolua++.exe and b/src/Bindings/tolua++.exe differ -- cgit v1.2.3 From de3df0a71fbde1630775c0daa592d6f2c1ba679f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 6 Apr 2014 22:15:49 +0200 Subject: Fixed crash in protocols sending 64-bit ints. Fixes #855. --- src/Protocol/Protocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index ae06f2f9e..939170f0e 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -177,7 +177,7 @@ protected: void WriteInt64 (Int64 a_Value) { UInt64 Value = HostToNetwork8(&a_Value); - SendData((const char *)Value, 8); + SendData((const char *)&Value, 8); } void WriteFloat (float a_Value) -- cgit v1.2.3 From 95fb90eaa642b76915a117495b472d7f7e141cde Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 6 Apr 2014 22:28:41 +0200 Subject: Fixed 1.6.4 client crash on composite chat messages. --- src/Protocol/Protocol16x.cpp | 13 +++++++++++++ src/Protocol/Protocol16x.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index bf7d9a0b1..3da23a1dc 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -18,6 +18,7 @@ Implements the 1.6.x protocol classes: #include "../Entities/Entity.h" #include "../Entities/Player.h" #include "../UI/Window.h" +#include "../CompositeChat.h" @@ -89,6 +90,18 @@ void cProtocol161::SendChat(const AString & a_Message) +void cProtocol161::SendChat(const cCompositeChat & a_Message) +{ + // This protocol version doesn't support composite messages to the full + // Just extract each part's text and use it: + + super::SendChat(Printf("{\"text\":\"%s\"}", EscapeString(a_Message.ExtractText()).c_str())); +} + + + + + void cProtocol161::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) { cCSLock Lock(m_CSPacket); diff --git a/src/Protocol/Protocol16x.h b/src/Protocol/Protocol16x.h index 325e41c5a..ae1388649 100644 --- a/src/Protocol/Protocol16x.h +++ b/src/Protocol/Protocol16x.h @@ -37,6 +37,7 @@ protected: // cProtocol150 overrides: virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override; virtual void SendChat (const AString & a_Message) override; + virtual void SendChat (const cCompositeChat & a_Message) override; virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+) virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; -- cgit v1.2.3 From 176deb4b5bbbfc23e44bb4d5087c7832cad36da1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 6 Apr 2014 22:30:34 +0200 Subject: Added the generated ZBS API file to ignore list. --- MCServer/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MCServer/.gitignore b/MCServer/.gitignore index 69826ef06..32a634a03 100644 --- a/MCServer/.gitignore +++ b/MCServer/.gitignore @@ -28,3 +28,5 @@ motd.txt *.deuser *.dmp *.xml +mcserver_api.lua + -- cgit v1.2.3 From f9b2c2956efff75c71af6d3f18f615bc0cd345d4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 7 Apr 2014 08:11:56 +0200 Subject: Fixed HTTP chunked encoding. Fixes #858. --- src/HTTPServer/HTTPConnection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HTTPServer/HTTPConnection.cpp b/src/HTTPServer/HTTPConnection.cpp index 44a3d3f88..da4df0e34 100644 --- a/src/HTTPServer/HTTPConnection.cpp +++ b/src/HTTPServer/HTTPConnection.cpp @@ -70,7 +70,7 @@ void cHTTPConnection::Send(const cHTTPResponse & a_Response) void cHTTPConnection::Send(const void * a_Data, size_t a_Size) { ASSERT(m_State == wcsSendingResp); - AppendPrintf(m_OutgoingData, SIZE_T_FMT "\r\n", a_Size); + AppendPrintf(m_OutgoingData, SIZE_T_FMT_HEX "\r\n", a_Size); m_OutgoingData.append((const char *)a_Data, a_Size); m_OutgoingData.append("\r\n"); m_HTTPServer.NotifyConnectionWrite(*this); -- cgit v1.2.3 From 4082adbbade69890fb275f1807f061c8b206070e Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Mon, 7 Apr 2014 11:35:37 +0100 Subject: Fix some of the comments in the PR tycho just did. --- src/Simulator/IncrementalRedstoneSimulator.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index b59f95cfd..0c032eeab 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -1,4 +1,3 @@ - #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "IncrementalRedstoneSimulator.h" @@ -686,15 +685,15 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B { NIBBLETYPE a_Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - bool IsOn = ((a_MyState == E_BLOCK_REDSTONE_REPEATER_ON) ? true : false); // Cache if repeater is on - bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); // Cache if repeater is pwoered - bool IsLocked = IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); + bool IsOn = ((a_MyState == E_BLOCK_REDSTONE_REPEATER_ON) ? true : false); // Cache if repeater is on. + bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); // Cache if repeater is powered. + bool IsLocked = IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); // Cache if repeater is locked. - if (IsSelfPowered && !IsOn && !IsLocked) // Queue a power change if I am receiving power but not on + if (IsSelfPowered && !IsOn && !IsLocked) // Queue a power change if powered, but not on and not locked. { QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, true); } - else if (!IsSelfPowered && IsOn && !IsLocked) // Queue a power change if I am not receiving power but on + else if (!IsSelfPowered && IsOn && !IsLocked) // Queue a power change if unpowered, on, and not locked. { QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, false); } @@ -1225,7 +1224,6 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) { // Repeaters can be locked by either of their sides - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } @@ -1275,7 +1273,7 @@ bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, } } } - return false; // Couldn't find power source behind repeater + return false; // Repeater is not being powered from either side, therefore it is not locked. } -- cgit v1.2.3 From 634c4d6770605323e2992e1b381682579d698f39 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Mon, 7 Apr 2014 17:12:06 +0100 Subject: Fixed the redstone simulator. --- src/Simulator/IncrementalRedstoneSimulator.cpp | 89 ++++++++++++-------------- 1 file changed, 40 insertions(+), 49 deletions(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 0c032eeab..cab3a714a 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -1223,57 +1223,48 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) { - // Repeaters can be locked by either of their sides - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - - switch (a_Meta) - { - // If N/S check E/W - case 0x0: - case 0x2: - { - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } - break; - } - // If E/W check N/S - case 0x1: - case 0x3: - { - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } - break; - } - } + // Change checking direction according to meta rotation. + switch (m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x3) //compare my direction to my neighbor's + { + // If N/S check E/W <<<<< + + case 0x0: + case 0x2: + { + if (m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) // Is right neighbor a + { + NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX + 1, a_BlockY, a_BlockZ) & 0x3; + if (otherRepeaterDir == 0x1) { return true; } + } + + if (m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) + { + NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX -1, a_BlockY, a_BlockZ) & 0x3; + if (otherRepeaterDir == 0x3) { return true; } + } + + break; + } + + // If E/W check N/S + case 0x1: + case 0x3: + + if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1) == E_BLOCK_REDSTONE_REPEATER_ON) + { + NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ + 1) & 0x3; + if (otherRepeaterDir == 0x0) { return true; } + } + + if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ -1) == E_BLOCK_REDSTONE_REPEATER_ON) + { + NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ - 1) & 0x3; + if (otherRepeaterDir == 0x2) { return true; } + } + break; } - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - - switch (a_Meta) - { - // If N/S check E/W - case 0x0: - case 0x2: - { - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } - break; - } - // If E/W check N/S - case 0x1: - case 0x3: - { - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } - break; - } - } - } - return false; // Repeater is not being powered from either side, therefore it is not locked. + return false; } -- cgit v1.2.3 From 5374730753aa5f07dc0b565af1140abb8b694c0b Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Mon, 7 Apr 2014 17:28:16 +0100 Subject: Improved the speed a little more. --- src/Simulator/IncrementalRedstoneSimulator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index cab3a714a..08a0f42c6 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -1224,7 +1224,7 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) { // Change checking direction according to meta rotation. - switch (m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x3) //compare my direction to my neighbor's + switch (a_Meta & 0x3) //compare my direction to my neighbor's { // If N/S check E/W <<<<< -- cgit v1.2.3 From 57a474ba01ff9dcfba8e90b30d3938d60aa600e5 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Mon, 7 Apr 2014 17:37:53 +0100 Subject: Fixed some more minor issues with the redstone simulator. --- src/Simulator/IncrementalRedstoneSimulator.cpp | 73 ++++++++++++++------------ 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 08a0f42c6..f12c29211 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -683,11 +683,13 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) { + // Create a variable holding my meta to avoid multiple lookups. NIBBLETYPE a_Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - bool IsOn = ((a_MyState == E_BLOCK_REDSTONE_REPEATER_ON) ? true : false); // Cache if repeater is on. - bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); // Cache if repeater is powered. - bool IsLocked = IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); // Cache if repeater is locked. + // Do the same for being on, self powered or locked. + bool IsOn = (a_MyState == E_BLOCK_REDSTONE_REPEATER_ON); + bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta); + bool IsLocked = IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta); if (IsSelfPowered && !IsOn && !IsLocked) // Queue a power change if powered, but not on and not locked. { @@ -1151,7 +1153,8 @@ bool cIncrementalRedstoneSimulator::AreCoordsLinkedPowered(int a_BlockX, int a_B - +// IsRepeaterPowered tests if a repeater should be powered by testing for power sources behind the repeater. +// It takes the coordinates of the repeater the the meta value. bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) { // Repeaters cannot be powered by any face except their back; verify that this is true for a source @@ -1160,7 +1163,7 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - switch (a_Meta) + switch (a_Meta & 0x3) { case 0x0: { @@ -1190,7 +1193,7 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY { if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - switch (a_Meta) + switch (a_Meta & 0x3) { case 0x0: { @@ -1226,42 +1229,44 @@ bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, // Change checking direction according to meta rotation. switch (a_Meta & 0x3) //compare my direction to my neighbor's { - // If N/S check E/W <<<<< - case 0x0: - case 0x2: - { - if (m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) // Is right neighbor a - { - NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX + 1, a_BlockY, a_BlockZ) & 0x3; - if (otherRepeaterDir == 0x1) { return true; } - } + // If the repeater is facing one direction, do one thing. + case 0x0: + case 0x2: + { + if (m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) // Is right neighbor a + { + NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX + 1, a_BlockY, a_BlockZ) & 0x3; + if (otherRepeaterDir == 0x1) { return true; } + } - if (m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) - { - NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX -1, a_BlockY, a_BlockZ) & 0x3; - if (otherRepeaterDir == 0x3) { return true; } - } + if (m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_REPEATER_ON) + { + NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX -1, a_BlockY, a_BlockZ) & 0x3; + if (otherRepeaterDir == 0x3) { return true; } + } break; - } + } - // If E/W check N/S + // If another, do the other. case 0x1: case 0x3: + { + if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1) == E_BLOCK_REDSTONE_REPEATER_ON) + { + NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ + 1) & 0x3; + if (otherRepeaterDir == 0x0) { return true; } + } + + if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ -1) == E_BLOCK_REDSTONE_REPEATER_ON) + { + NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ - 1) & 0x3; + if (otherRepeaterDir == 0x2) { return true; } + } - if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1) == E_BLOCK_REDSTONE_REPEATER_ON) - { - NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ + 1) & 0x3; - if (otherRepeaterDir == 0x0) { return true; } - } - - if (m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ -1) == E_BLOCK_REDSTONE_REPEATER_ON) - { - NIBBLETYPE otherRepeaterDir = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ - 1) & 0x3; - if (otherRepeaterDir == 0x2) { return true; } - } - break; + break; + } } return false; -- cgit v1.2.3